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