18bf80f4bSopenharmony_ci/* 28bf80f4bSopenharmony_ci * Copyright (c) 2024 Huawei Device Co., Ltd. 38bf80f4bSopenharmony_ci * Licensed under the Apache License, Version 2.0 (the "License"); 48bf80f4bSopenharmony_ci * you may not use this file except in compliance with the License. 58bf80f4bSopenharmony_ci * You may obtain a copy of the License at 68bf80f4bSopenharmony_ci * 78bf80f4bSopenharmony_ci * http://www.apache.org/licenses/LICENSE-2.0 88bf80f4bSopenharmony_ci * 98bf80f4bSopenharmony_ci * Unless required by applicable law or agreed to in writing, software 108bf80f4bSopenharmony_ci * distributed under the License is distributed on an "AS IS" BASIS, 118bf80f4bSopenharmony_ci * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 128bf80f4bSopenharmony_ci * See the License for the specific language governing permissions and 138bf80f4bSopenharmony_ci * limitations under the License. 148bf80f4bSopenharmony_ci */ 158bf80f4bSopenharmony_ci 168bf80f4bSopenharmony_ci#ifndef GLES_EGL_STATE_H 178bf80f4bSopenharmony_ci#define GLES_EGL_STATE_H 188bf80f4bSopenharmony_ci 198bf80f4bSopenharmony_ci#if RENDER_HAS_GLES_BACKEND 208bf80f4bSopenharmony_ci#include <cstdint> 218bf80f4bSopenharmony_ci 228bf80f4bSopenharmony_ci#include <base/containers/string.h> 238bf80f4bSopenharmony_ci#include <base/containers/string_view.h> 248bf80f4bSopenharmony_ci#include <render/gles/intf_device_gles.h> 258bf80f4bSopenharmony_ci#include <render/namespace.h> 268bf80f4bSopenharmony_ci 278bf80f4bSopenharmony_ciRENDER_BEGIN_NAMESPACE() 288bf80f4bSopenharmony_ciclass SwapchainGLES; 298bf80f4bSopenharmony_cistruct DeviceCreateInfo; 308bf80f4bSopenharmony_cistruct DevicePlatformData; 318bf80f4bSopenharmony_ci 328bf80f4bSopenharmony_cinamespace GlesImplementation { 338bf80f4bSopenharmony_cistruct SurfaceInfo; 348bf80f4bSopenharmony_ci} // namespace GlesImplementation 358bf80f4bSopenharmony_ci 368bf80f4bSopenharmony_cinamespace EGLHelpers { 378bf80f4bSopenharmony_ciclass EGLState { 388bf80f4bSopenharmony_cipublic: 398bf80f4bSopenharmony_ci EGLState() = default; 408bf80f4bSopenharmony_ci ~EGLState() = default; 418bf80f4bSopenharmony_ci bool CreateContext(DeviceCreateInfo const& createInfo); 428bf80f4bSopenharmony_ci bool IsValid(); 438bf80f4bSopenharmony_ci 448bf80f4bSopenharmony_ci void GlInitialize(); 458bf80f4bSopenharmony_ci void DestroyContext(); 468bf80f4bSopenharmony_ci void SetSwapInterval(uint32_t interval); 478bf80f4bSopenharmony_ci const DevicePlatformData& GetPlatformData() const; 488bf80f4bSopenharmony_ci 498bf80f4bSopenharmony_ci void SaveContext(); 508bf80f4bSopenharmony_ci void SetContext(const SwapchainGLES* swapchain); 518bf80f4bSopenharmony_ci void RestoreContext(); 528bf80f4bSopenharmony_ci void* ErrorFilter() const; 538bf80f4bSopenharmony_ci 548bf80f4bSopenharmony_ci uint32_t MajorVersion() const; 558bf80f4bSopenharmony_ci uint32_t MinorVersion() const; 568bf80f4bSopenharmony_ci 578bf80f4bSopenharmony_ci bool HasExtension(BASE_NS::string_view) const; 588bf80f4bSopenharmony_ci uintptr_t CreateSurface(uintptr_t window, uintptr_t instance) const noexcept; 598bf80f4bSopenharmony_ci void DestroySurface(uintptr_t surface) const noexcept; 608bf80f4bSopenharmony_ci bool GetSurfaceInformation( 618bf80f4bSopenharmony_ci const DevicePlatformDataGLES& plat, EGLSurface surface, GlesImplementation::SurfaceInfo& res) const; 628bf80f4bSopenharmony_ci void SwapBuffers(const SwapchainGLES& swapchain); 638bf80f4bSopenharmony_ci 648bf80f4bSopenharmony_ciprotected: 658bf80f4bSopenharmony_ci bool VerifyVersion(); 668bf80f4bSopenharmony_ci bool hasColorSpaceExt_ { false }; 678bf80f4bSopenharmony_ci bool hasConfiglessExt_ { false }; 688bf80f4bSopenharmony_ci bool hasSurfacelessExt_ { false }; 698bf80f4bSopenharmony_ci void HandleExtensions(); 708bf80f4bSopenharmony_ci BASE_NS::string cextensions_; // list of client extensions (null terminated strings) 718bf80f4bSopenharmony_ci BASE_NS::vector<BASE_NS::string_view> cextensionList_; // pointers to cextensions_ 728bf80f4bSopenharmony_ci BASE_NS::string dextensions_; // list of display extensions (null terminated strings) 738bf80f4bSopenharmony_ci BASE_NS::vector<BASE_NS::string_view> dextensionList_; // pointers to dextensions_ 748bf80f4bSopenharmony_ci 758bf80f4bSopenharmony_ci DevicePlatformDataGLES plat_; 768bf80f4bSopenharmony_ci struct ContextState { 778bf80f4bSopenharmony_ci EGLContext context = EGL_NO_CONTEXT; 788bf80f4bSopenharmony_ci EGLDisplay display = EGL_NO_DISPLAY; 798bf80f4bSopenharmony_ci EGLSurface readSurface = EGL_NO_SURFACE; 808bf80f4bSopenharmony_ci EGLSurface drawSurface = EGL_NO_SURFACE; 818bf80f4bSopenharmony_ci }; 828bf80f4bSopenharmony_ci ContextState oldContext_; 838bf80f4bSopenharmony_ci 848bf80f4bSopenharmony_ci EGLSurface dummySurface_ = EGL_NO_SURFACE; 858bf80f4bSopenharmony_ci ContextState dummyContext_; 868bf80f4bSopenharmony_ci bool vSync_ = true; 878bf80f4bSopenharmony_ci bool oldIsSet_ = false; 888bf80f4bSopenharmony_ci 898bf80f4bSopenharmony_ci void GetContext(ContextState& oldState); 908bf80f4bSopenharmony_ci void SetContext(const ContextState& newState, bool force = false); 918bf80f4bSopenharmony_ci void ChooseConfiguration(const BackendExtraGLES*); 928bf80f4bSopenharmony_ci void CreateContext(const BackendExtraGLES*); 938bf80f4bSopenharmony_ci bool IsVersionGreaterOrEqual(uint32_t major, uint32_t minor) const; 948bf80f4bSopenharmony_ci}; 958bf80f4bSopenharmony_ci} // namespace EGLHelpers 968bf80f4bSopenharmony_ciRENDER_END_NAMESPACE() 978bf80f4bSopenharmony_ci#endif 988bf80f4bSopenharmony_ci#endif // GLES_EGL_STATE_H 99