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 FRAMEWORKS_INNERKITSIMPL_EGL_IMAGE_INCLUDE_RENDER_CONTEXT_H 17 #define FRAMEWORKS_INNERKITSIMPL_EGL_IMAGE_INCLUDE_RENDER_CONTEXT_H 18 19 #ifndef EGL_EGLEXT_PROTOTYPES 20 #define EGL_EGLEXT_PROTOTYPES 21 #endif // EGL_EGLEXT_PROTOTYPES 22 23 #include "EGL/egl.h" 24 #include "EGL/eglext.h" 25 #include "GLES/gl.h" 26 #include "GLES/glext.h" 27 #include "GLES3/gl32.h" 28 29 #include "include/core/SkCanvas.h" 30 #include "include/core/SkColorSpace.h" 31 #include "include/core/SkImageInfo.h" 32 #include "include/core/SkSurface.h" 33 #include "include/gpu/GrBackendSurface.h" 34 #include "include/gpu/GrDirectContext.h" 35 #include "include/gpu/gl/GrGLInterface.h" 36 37 namespace OHOS { 38 namespace Media { 39 class RenderContext { 40 public: 41 RenderContext(); 42 ~RenderContext() noexcept; 43 44 // disallow copy and move 45 RenderContext(const RenderContext &) = delete; 46 void operator=(const RenderContext &) = delete; 47 RenderContext(const RenderContext &&) = delete; 48 void operator=(const RenderContext &&) = delete; 49 50 bool Init(); 51 52 void MakeCurrent(EGLSurface surface) const; 53 GetGrContext()54 sk_sp<GrDirectContext> GetGrContext() const 55 { 56 return grContext_; 57 } 58 GetEGLConfig()59 EGLConfig GetEGLConfig() const 60 { 61 return config_; 62 } 63 GetEGLContext()64 EGLContext GetEGLContext() const 65 { 66 return eglContext_; 67 } 68 GetEGLDisplay()69 EGLDisplay GetEGLDisplay() const 70 { 71 return eglDisplay_; 72 } 73 74 public: 75 void Clear() noexcept; 76 bool CreatePbufferSurface(); 77 bool InitEGLContext(); 78 bool InitGrContext(); 79 80 EGLDisplay eglDisplay_ = EGL_NO_DISPLAY; 81 EGLConfig config_ = NULL; 82 EGLContext eglContext_ = EGL_NO_CONTEXT; 83 EGLSurface pbufferSurface_ = EGL_NO_SURFACE; 84 sk_sp<GrDirectContext> grContext_; 85 }; 86 } // namespace Media 87 } // namespace OHOS 88 #endif // FRAMEWORKS_INNERKITSIMPL_EGL_IMAGE_INCLUDE_RENDER_CONTEXT_H 89