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 #ifdef USE_M133_SKIA 33 #include "include/gpu/ganesh/GrBackendSurface.h" 34 #include "include/gpu/ganesh/GrContextOptions.h" 35 #include "include/gpu/ganesh/GrDirectContext.h" 36 #include "include/gpu/ganesh/gl/GrGLDirectContext.h" 37 #include "include/gpu/ganesh/gl/GrGLInterface.h" 38 #else 39 #include "include/gpu/GrBackendSurface.h" 40 #include "include/gpu/GrDirectContext.h" 41 #include "include/gpu/gl/GrGLInterface.h" 42 #endif 43 44 namespace OHOS { 45 namespace Media { 46 47 class PixelMapGlContext { 48 public: 49 PixelMapGlContext(); 50 PixelMapGlContext(bool init); 51 ~PixelMapGlContext() noexcept; 52 53 // disallow copy and move 54 PixelMapGlContext(const PixelMapGlContext &) = delete; 55 void operator=(const PixelMapGlContext &) = delete; 56 PixelMapGlContext(const PixelMapGlContext &&) = delete; 57 void operator=(const PixelMapGlContext &&) = delete; 58 59 bool Init(); 60 61 void MakeCurrent(EGLSurface surface) const; 62 63 bool MakeCurrentSimple(bool needCurrent); 64 GetGrContext()65 sk_sp<GrDirectContext> GetGrContext() const 66 { 67 return grContext_; 68 } 69 GetEGLConfig()70 EGLConfig GetEGLConfig() const 71 { 72 return config_; 73 } 74 GetEGLContext()75 EGLContext GetEGLContext() const 76 { 77 return eglContext_; 78 } 79 GetEGLDisplay()80 EGLDisplay GetEGLDisplay() const 81 { 82 return eglDisplay_; 83 } 84 85 public: 86 void Clear() noexcept; 87 bool CreatePbufferSurface(); 88 bool InitEGLContext(); 89 bool InitGrContext(); 90 91 static EGLDisplay eglDisplay_; 92 static EGLConfig config_; 93 EGLContext eglContext_ = EGL_NO_CONTEXT; 94 EGLSurface pbufferSurface_ = EGL_NO_SURFACE; 95 EGLContext oldEglContext_ = EGL_NO_CONTEXT; 96 EGLSurface oldEglSurfaceRead_ = EGL_NO_SURFACE; 97 EGLSurface oldEglSurfaceDraw_ = EGL_NO_SURFACE; 98 sk_sp<GrDirectContext> grContext_; 99 }; 100 } // namespace Media 101 } // namespace OHOS 102 #endif // FRAMEWORKS_INNERKITSIMPL_EGL_IMAGE_INCLUDE_PIXEL_MAP_GL_CONTEXT_H 103