• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2023 Huawei Device Co., Ltd.. All rights reserved.
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 SKIA_SURFACE_H
17 #define SKIA_SURFACE_H
18 
19 #include "include/core/SkSurface.h"
20 
21 #include "draw/surface.h"
22 #include "impl_interface/surface_impl.h"
23 
24 namespace OHOS {
25 namespace Rosen {
26 namespace Drawing {
27 class SkiaSurface : public SurfaceImpl {
28 public:
29     static inline constexpr AdapterType TYPE = AdapterType::SKIA_ADAPTER;
30 
31     SkiaSurface();
32     ~SkiaSurface() override = default;
33 
GetType()34     AdapterType GetType() const override
35     {
36         return AdapterType::SKIA_ADAPTER;
37     }
38 
39     bool Bind(const Bitmap& bitmap) override;
40 #ifdef ACE_ENABLE_GPU
41     bool Bind(const Image& image) override;
42     bool Bind(const FrameBuffer& frameBuffer) override;
43 #ifdef RS_ENABLE_VK
44     static std::shared_ptr<Surface> MakeFromBackendRenderTarget(GPUContext* gpuContext, const TextureInfo& info,
45         TextureOrigin origin, ColorType colorType, std::shared_ptr<ColorSpace> colorSpace,
46         void (*deleteVkImage)(void *), void* cleanHelper);
47     static std::shared_ptr<Surface> MakeFromBackendTexture(GPUContext* gpuContext, const TextureInfo& info,
48         TextureOrigin origin, int sampleCnt, ColorType colorType,
49         std::shared_ptr<ColorSpace> colorSpace, void (*deleteVkImage)(void *), void* cleanHelper);
50 #endif
51     static std::shared_ptr<Surface> MakeRenderTarget(GPUContext* gpuContext, bool budgeted, const ImageInfo& imageInfo);
52 #endif
53     static std::shared_ptr<Surface> MakeRaster(const ImageInfo& imageInfo);
54     static std::shared_ptr<Surface> MakeRasterDirect(const ImageInfo& imageInfo, void* pixels, size_t rowBytes);
55     static std::shared_ptr<Surface> MakeRasterN32Premul(int32_t width, int32_t height);
56 
57     std::shared_ptr<Canvas> GetCanvas() const override;
58     std::shared_ptr<Image> GetImageSnapshot() const override;
59     std::shared_ptr<Image> GetImageSnapshot(const RectI& bounds) const override;
60     std::shared_ptr<Surface> MakeSurface(int width, int height) const override;
61     BackendTexture GetBackendTexture(BackendAccess access) const override;
62     void SetSkSurface(const sk_sp<SkSurface>& skSurface);
63     void FlushAndSubmit(bool syncCpu) override;
64     void Flush(FlushInfo *drawingflushInfo = nullptr) override;
65 #ifdef RS_ENABLE_VK
66     void Wait(int32_t time, const VkSemaphore& semaphore) override;
67     void SetDrawingArea(const std::vector<RectI>& rects) override;
68     void ClearDrawingArea() override;
69 #endif
70     sk_sp<SkSurface> GetSkSurface() const;
71     int Width() const override;
72     int Height() const override;
73 private:
74     sk_sp<SkSurface> skSurface_ = nullptr;
75     sk_sp<SkImage> skImage_ = nullptr;
76 };
77 } // namespace Drawing
78 } // namespace Rosen
79 } // namespace OHOS
80 #endif // SKIA_SURFACE_H
81