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 OHOS_RENDER_3D_OFFSCREEN_CONTEXT_HELPER_H 17 #define OHOS_RENDER_3D_OFFSCREEN_CONTEXT_HELPER_H 18 19 #include <EGL/egl.h> 20 #include <GLES/gl.h> 21 22 namespace OHOS::Render3D { 23 class AutoRestore final { 24 public: 25 AutoRestore(); 26 ~AutoRestore(); 27 private: 28 EGLContext c_ = EGL_NO_CONTEXT; 29 EGLSurface ws_ = EGL_NO_SURFACE; 30 EGLSurface rs_ = EGL_NO_SURFACE; 31 EGLDisplay d_ = EGL_NO_DISPLAY; 32 }; 33 34 class OffScreenContextHelper final { 35 public: 36 OffScreenContextHelper() = default; 37 ~OffScreenContextHelper(); 38 EGLContext CreateOffScreenContext(EGLContext eglContext); 39 EGLContext GetOffScreenContext(); 40 void BindOffScreenContext(); 41 void DestroyOffScreenContext(); 42 43 private: 44 EGLDisplay eglDisplay_ = EGL_NO_DISPLAY; 45 EGLContext localThreadContext_ = EGL_NO_CONTEXT; 46 EGLSurface pBufferSurface_ = EGL_NO_SURFACE; 47 }; 48 } // namespace OHOS::Render3D 49 #endif // OHOS_RENDER_3D_OFFSCREEN_CONTEXT_H 50