1 /* 2 * Copyright (c) 2022 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 GLES_RENDER_BACKEND_H 17 #define GLES_RENDER_BACKEND_H 18 #include "include/core/SkCanvas.h" 19 #include "include/core/SkColorSpace.h" 20 #include "include/core/SkImageInfo.h" 21 #include "include/core/SkSurface.h" 22 #include "include/gpu/gl/GrGLInterface.h" 23 #include "include/gpu/GrBackendSurface.h" 24 #include "include/gpu/GrContextOptions.h" 25 26 #if defined(USE_CANVASKIT0310_SKIA) 27 #include "include/gpu/GrDirectContext.h" 28 #else 29 #include "include/gpu/GrContext.h" 30 #endif 31 32 #include "interface_render_backend.h" 33 #include "egl_manager.h" 34 35 namespace OHOS { 36 namespace Rosen { 37 class GLESRenderBackend : public IRenderBackend { 38 public: 39 GLESRenderBackend() noexcept; 40 ~GLESRenderBackend() override; 41 void InitDrawContext() override; 42 void MakeCurrent() override; 43 void SwapBuffers() override; 44 void* CreateSurface(void* window) override; 45 void SetDamageRegion(int32_t left, int32_t top, int32_t width, int32_t height) override; 46 #if defined(USE_CANVASKIT0310_SKIA) GetGrContext()47 GrDirectContext* GetGrContext() const 48 { 49 return grContext_.get(); 50 } 51 #else GetGrContext()52 GrContext* GetGrContext() const 53 { 54 return grContext_.get(); 55 } 56 #endif 57 bool SetUpGrContext(); 58 void Destroy() override; 59 void RenderFrame() override; 60 SkCanvas* AcquireCanvas(std::unique_ptr<SurfaceFrame>& frame) override; 61 private: 62 EGLManager* eglManager_ = nullptr; 63 #if defined(USE_CANVASKIT0310_SKIA) 64 sk_sp<GrDirectContext> grContext_ = nullptr; 65 #else 66 sk_sp<GrContext> grContext_ = nullptr; 67 #endif 68 sk_sp<SkSurface> skSurface_ = nullptr; 69 }; 70 } 71 } 72 #endif