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