• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2022 Shenzhen Kaihong Digital Industry Development 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 _ROSEN_CONTEXT_IMPL_H_
17 #define _ROSEN_CONTEXT_IMPL_H_
18 
19 #include <map>
20 
21 #include "ohos_context_i.h"
22 
23 #include "ui/rs_display_node.h"
24 #include "ui/rs_surface_node.h"
25 
26 #include "EGL/egl.h"
27 #include "EGL/eglext.h"
28 #include "GLES3/gl32.h"
29 
30 namespace OHOS {
31 namespace Rosen {
32 
33 class RosenContextImpl : public OHOS::OhosContextI {
34 public:
35     RosenContextImpl();
36 
37     bool SetConfig(int32_t w,int32_t h,RCI_GLES_VERSION ver,RCI_PIXEL_FORMAT pf,RCI_SURFACE_TYPE st,RCI_PROFILE tp,RCI_CONTEXT_FLAG flags) override;
38     bool InitNativeWindow() override;
39     bool InitEglSurface() override;
40     bool InitEglContext() override;
41 
42     void MakeCurrent() override;
43     void SwapBuffer() override;
44 
45     int32_t GetAttrib(int32_t attrType) override;
46 
47     uint64_t CreateWindow(uint32_t x,uint32_t y,uint32_t width,uint32_t height) override;
48     void *GetNativeWindow(uint64_t windowId) override;
49     void DestoryWindow(uint64_t windowId) override;
50 
51     void *GetNativeWindowEx() override;
52     void OhosWindowResize(int32_t w,int32_t h) override;
EglGetConfig()53     void* EglGetConfig() override { return config_;}
54 
55 // implemented1_BEGIN
56     uint32_t OH_bindAPI(uint32_t api) override;
57     uint32_t OH_bindTexImage(void* dpy, void* surface, int32_t buffer) override;
58     uint32_t OH_chooseConfig(void* dpy, const int32_t *attrib_list, void* *configs, int32_t config_size, int32_t *num_config) override;
59     int32_t OH_clientWaitSync(void* dpy, void* sync, int32_t flags, uint64_t timeout) override;
60     int32_t OH_clientWaitSyncKHR(void* dpy, void* sync, int32_t flags, uint64_t timeout) override;
61     uint32_t OH_copyBuffers(void* dpy, void* surface, void* target) override;
62     void* OH_createContext(void* dpy, void* config, void* share_context, const int32_t *attrib_list) override;
63     void* OH_createImage(void* dpy, void* ctx, uint32_t target, void* buffer, const int *attrib_list) override;
64     void* OH_createImageKHR(void* dpy, void* ctx, uint32_t target, void* buffer, const int32_t *attrib_list) override;
65     void* OH_createPbufferFromClientBuffer(void* dpy, uint32_t buftype, void* buffer, void* config, const int32_t *attrib_list) override;
66     void* OH_createPbufferSurface(void* dpy, void* config, const int32_t *attrib_list) override;
67     void* OH_createPixmapSurface(void* dpy, void* config, void* pixmap, const int32_t *attrib_list) override;
68     void* OH_createPlatformPixmapSurface(void* dpy, void* config, void *native_pixmap, const int *attrib_list) override;
69     void* OH_createPlatformPixmapSurfaceEXT(void* dpy, void* config, void *native_pixmap, const int32_t *attrib_list) override;
70     void* OH_createPlatformWindowSurface(void* dpy, void* config, void *native_window, const int *attrib_list) override;
71     void* OH_createPlatformWindowSurfaceEXT(void* dpy, void* config, void *native_window, const int32_t *attrib_list) override;
72     void* OH_createSync(void* dpy, uint32_t type, const int *attrib_list) override;
73     void* OH_createSyncKHR(void* dpy, uint32_t type, const int32_t *attrib_list) override;
74     void* OH_createWindowSurface(void* dpy, void* config, void* win, const int32_t *attrib_list) override;
75     uint32_t OH_destroyContext(void* dpy, void* ctx) override;
76     uint32_t OH_destroyImage(void* dpy, void* image) override;
77     uint32_t OH_destroyImageKHR(void* dpy, void* image) override;
78     uint32_t OH_destroySurface(void* dpy, void* surface) override;
79     uint32_t OH_destroySync(void* dpy, void* sync) override;
80     uint32_t OH_destroySyncKHR(void* dpy, void* sync) override;
81     uint32_t OH_getConfigAttrib(void* dpy, void* config, int32_t attribute, int32_t *value) override;
82     uint32_t OH_getConfigs(void* dpy, void* *configs, int32_t config_size, int32_t *num_config) override;
83     void* OH_getCurrentContext() override;
84     void* OH_getCurrentDisplay() override;
85     void* OH_getCurrentSurface(int32_t readdraw) override;
86     void* OH_getDisplay(void* display_id) override;
87     int32_t OH_getError() override;
88     void* OH_getPlatformDisplay(uint32_t platform, void *native_display, const int *attrib_list) override;
89     void* OH_getPlatformDisplayEXT(uint32_t platform, void *native_display, const int32_t *attrib_list) override;
90     FunctionPointer OH_getProcAddress(const char *procname) override;
91     uint32_t OH_getSyncAttrib(void* dpy, void* sync, int32_t attribute, int *value) override;
92     uint32_t OH_getSyncAttribKHR(void* dpy, void* sync, int32_t attribute, int32_t *value) override;
93     uint32_t OH_initialize(void* dpy, int32_t *major, int32_t *minor) override;
94     uint32_t OH_lockSurfaceKHR(void* dpy, void* surface, const int32_t *attrib_list) override;
95     uint32_t OH_makeCurrent(void* dpy, void* draw, void* read, void* ctx) override;
96     uint32_t OH_queryAPI() override;
97     uint32_t OH_queryContext(void* dpy, void* ctx, int32_t attribute, int32_t *value) override;
98     const char* OH_queryString(void* dpy, int32_t name) override;
99     uint32_t OH_querySurface(void* dpy, void* surface, int32_t attribute, int32_t *value) override;
100     uint32_t OH_releaseTexImage(void* dpy, void* surface, int32_t buffer) override;
101     uint32_t OH_releaseThread() override;
102     uint32_t OH_setDamageRegionKHR(void* dpy, void* surface, int32_t *rects, int32_t n_rects) override;
103     uint32_t OH_signalSyncKHR(void* dpy, void* sync, uint32_t mode) override;
104     uint32_t OH_surfaceAttrib(void* dpy, void* surface, int32_t attribute, int32_t value) override;
105     uint32_t OH_swapBuffers(void* dpy, void* surface) override;
106     uint32_t OH_swapBuffersWithDamageKHR(void* dpy, void* surface, int32_t *rects, int32_t n_rects) override;
107     uint32_t OH_swapInterval(void* dpy, int32_t interval) override;
108     uint32_t OH_terminate(void* dpy) override;
109     uint32_t OH_unlockSurfaceKHR(void* dpy, void* surface) override;
110     uint32_t OH_waitClient() override;
111     uint32_t OH_waitGL() override;
112     uint32_t OH_waitNative(int32_t engine) override;
113     uint32_t OH_waitSync(void* dpy, void* sync, int32_t flags) override;
114     int32_t OH_waitSyncKHR(void* dpy, void* sync, int32_t flags) override;
115     static bool CheckIfNeedOpengl();
116 // implemented1_END
117 
118 private:
119     void InitProducer();
120     bool InitEgl();
121     void ShowConfig(EGLConfig cfg);
122 
123     RCI_GLES_VERSION glesVersion_;
124     RCI_PROFILE typeProfile_;
125     RCI_CONTEXT_FLAG contextFlags_;
126     RCI_SURFACE_TYPE surfaceType_;
127     int32_t width_;
128     int32_t height_;
129     RCI_PIXEL_FORMAT pixelFormat_;
130     EGLConfig *allConfigs_;
131     EGLint configCount_;
132 
133     RSDisplayNode::SharedPtr displayNode_ = nullptr;
134     std::shared_ptr<RSSurfaceNode> surfaceNode_;
135     sptr<Surface> producer_;
136 
137     EGLDisplay eglDisplay_;
138 
139     EGLConfig config_;
140 
141     struct NativeWindow* nativeWindow_ = nullptr;
142 
143     EGLSurface eglSurface_ = EGL_NO_SURFACE;
144 
145     EGLContext eglContext_ = EGL_NO_CONTEXT;
146     bool eglInited_ = false;
147 
148 
149     struct VulkanWindows {
150         std::shared_ptr<RSSurfaceNode> surfaceNode_;
151         sptr<Surface> producer_;
152         struct NativeWindow* nativeWindow_;
153     };
154     std::map<uint64_t,struct VulkanWindows> vulkanWindows_;
155 };
156 
157 }
158 }
159 
160 #endif
161