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) || defined(NEW_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 #include "draw/surface.h" 35 #include "image/gpu_context.h" 36 37 namespace OHOS { 38 namespace Rosen { 39 class GLESRenderBackend : public IRenderBackend { 40 public: 41 GLESRenderBackend() noexcept; 42 ~GLESRenderBackend() override; 43 void InitDrawContext() override; 44 void MakeCurrent() override; 45 void SwapBuffers() override; 46 void* CreateSurface(void* window) override; 47 void SetDamageRegion(int32_t left, int32_t top, int32_t width, int32_t height) override; 48 #if defined(USE_CANVASKIT0310_SKIA) || defined(NEW_SKIA) GetGrContext()49 GrDirectContext* GetGrContext() const 50 { 51 return grContext_.get(); 52 } 53 #else GetGrContext()54 GrContext* GetGrContext() const 55 { 56 return grContext_.get(); 57 } 58 #endif 59 bool SetUpGrContext(); 60 bool SetUpDrContext(); 61 void Destroy() override; 62 void RenderFrame() override; 63 SkCanvas* AcquireSkCanvas(std::unique_ptr<SurfaceFrame>& frame) override; 64 Drawing::Canvas* AcquireDrCanvas(std::unique_ptr<SurfaceFrame>& frame) override; 65 private: 66 EGLManager* eglManager_ = nullptr; 67 #if defined(USE_CANVASKIT0310_SKIA) || defined(NEW_SKIA) 68 sk_sp<GrDirectContext> grContext_ = nullptr; 69 #else 70 sk_sp<GrContext> grContext_ = nullptr; 71 #endif 72 sk_sp<SkSurface> skSurface_ = nullptr; 73 SkSurface* pSkSurface_ = nullptr; 74 75 std::shared_ptr<Drawing::GPUContext> drGPUContext_ = nullptr; 76 std::shared_ptr<Drawing::Surface> drSurface_ = nullptr; 77 }; 78 } 79 } 80 #endif