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 private: 51 void InitProducer(); 52 bool InitEgl(); 53 void ShowConfig(EGLConfig cfg); 54 55 RCI_GLES_VERSION glesVersion_; 56 RCI_PROFILE typeProfile_; 57 RCI_CONTEXT_FLAG contextFlags_; 58 RCI_SURFACE_TYPE surfaceType_; 59 int32_t width_; 60 int32_t height_; 61 RCI_PIXEL_FORMAT pixelFormat_; 62 EGLConfig *allConfigs_; 63 EGLint configCount_; 64 65 RSDisplayNode::SharedPtr displayNode_ = nullptr; 66 std::shared_ptr<RSSurfaceNode> surfaceNode_; 67 sptr<Surface> producer_; 68 69 EGLDisplay eglDisplay_; 70 71 EGLConfig config_; 72 73 struct NativeWindow* nativeWindow_ = nullptr; 74 75 EGLSurface eglSurface_ = EGL_NO_SURFACE; 76 77 EGLContext eglContext_ = EGL_NO_CONTEXT; 78 bool eglInited_ = false; 79 80 81 struct VulkanWindows { 82 std::shared_ptr<RSSurfaceNode> surfaceNode_; 83 sptr<Surface> producer_; 84 struct NativeWindow* nativeWindow_; 85 }; 86 std::map<uint64_t,struct VulkanWindows> vulkanWindows_; 87 }; 88 89 } 90 } 91 92 #endif