• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2023 Huawei Device Co., Ltd.
3  * Licensed under the Apache License, Version 2.0 (the "License");
4  * you may not use this file except in compliance with the License.
5  * You may obtain a copy of the License at
6  *
7  *     http://www.apache.org/licenses/LICENSE-2.0
8  *
9  * Unless required by applicable law or agreed to in writing, software
10  * distributed under the License is distributed on an "AS IS" BASIS,
11  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12  * See the License for the specific language governing permissions and
13  * limitations under the License.
14  */
15 
16 #ifndef GLES_EGL_STATE_H
17 #define GLES_EGL_STATE_H
18 
19 #if RENDER_HAS_GLES_BACKEND
20 #include <cstdint>
21 
22 #include <base/containers/string.h>
23 #include <base/containers/string_view.h>
24 #include <render/gles/intf_device_gles.h>
25 #include <render/namespace.h>
26 
27 RENDER_BEGIN_NAMESPACE()
28 class Swapchain;
29 struct DeviceCreateInfo;
30 struct DevicePlatformData;
31 
32 namespace GlesImplementation {
33 struct SurfaceInfo;
34 } // namespace GlesImplementation
35 
36 namespace EGLHelpers {
37 void DumpEGLSurface(EGLDisplay dpy, EGLSurface surf);
38 void DumpEGLConfig(EGLDisplay dpy, const EGLConfig& config);
39 
40 class EGLState {
41 public:
42     EGLState() = default;
43     ~EGLState() = default;
44     bool CreateContext(DeviceCreateInfo const& createInfo);
45     bool IsValid();
46 
47     void GlInitialize();
48     void DestroyContext();
49     void SetSwapInterval(uint32_t interval);
50     const DevicePlatformData& GetPlatformData() const;
51 
52     void SaveContext();
53     void SetContext(Swapchain* swapChain);
54     void RestoreContext();
55     void* ErrorFilter() const;
56 
57     uint32_t MajorVersion() const;
58     uint32_t MinorVersion() const;
59 
60     bool HasExtension(BASE_NS::string_view) const;
61     bool GetSurfaceInformation(
62         const DevicePlatformDataGLES& plat, EGLSurface surface, GlesImplementation::SurfaceInfo& res) const;
63 
64 protected:
65     bool VerifyVersion();
66     bool hasColorSpaceExt_ { false };
67     bool hasConfiglessExt_ { false };
68     bool hasSurfacelessExt_ { false };
69     void HandleExtensions();
70     BASE_NS::string cextensions_;                          // list of client extensions (null terminated strings)
71     BASE_NS::vector<BASE_NS::string_view> cextensionList_; // pointers to cextensions_
72     BASE_NS::string dextensions_;                          // list of display extensions (null terminated strings)
73     BASE_NS::vector<BASE_NS::string_view> dextensionList_; // pointers to dextensions_
74 
75     DevicePlatformDataGLES plat_;
76     struct ContextState {
77         EGLContext context = EGL_NO_CONTEXT;
78         EGLDisplay display = EGL_NO_DISPLAY;
79         EGLSurface readSurface = EGL_NO_SURFACE;
80         EGLSurface drawSurface = EGL_NO_SURFACE;
81     };
82     ContextState oldContext_;
83 
84     EGLSurface dummySurface_ = EGL_NO_SURFACE;
85     ContextState dummyContext_;
86     bool vSync_ = false;
87     bool oldIsSet_ = false;
88 
89     void GetContext(ContextState& oldState);
90     void SetContext(const ContextState& newState, bool force = false);
91     void ChooseConfiguration(const BackendExtraGLES*);
92     void CreateContext(const BackendExtraGLES*);
93     bool IsVersionGreaterOrEqual(uint32_t major, uint32_t minor) const;
94 };
95 } // namespace EGLHelpers
96 RENDER_END_NAMESPACE()
97 #endif
98 #endif // GLES_EGL_STATE_H
99