• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 #ifdef USE_M133_SKIA
27 #include "include/gpu/ganesh/GrDirectContext.h"
28 #else
29 #include "include/gpu/GrDirectContext.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;
GetGrContext()48     GrDirectContext* GetGrContext() const
49     {
50         return grContext_.get();
51     }
52     bool SetUpGrContext();
53     bool SetUpDrContext();
54     void Destroy() override;
55     void RenderFrame() override;
56     SkCanvas* AcquireSkCanvas(std::unique_ptr<SurfaceFrame>& frame) override;
57     Drawing::Canvas* AcquireDrCanvas(std::unique_ptr<SurfaceFrame>& frame) override;
58 private:
59     EGLManager* eglManager_ = nullptr;
60     sk_sp<GrDirectContext> grContext_ = nullptr;
61     sk_sp<SkSurface> skSurface_ = nullptr;
62     SkSurface* pSkSurface_ = nullptr;
63 
64     std::shared_ptr<Drawing::GPUContext> drGPUContext_ = nullptr;
65     std::shared_ptr<Drawing::Surface> drSurface_ = nullptr;
66 };
67 }
68 }
69 #endif