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 #include "include/core/SkImage.h" 21 22 #include "draw/surface.h" 23 #include "impl_interface/surface_impl.h" 24 25 namespace OHOS { 26 namespace Rosen { 27 namespace Drawing { 28 class SkiaSurface : public SurfaceImpl { 29 public: 30 static inline constexpr AdapterType TYPE = AdapterType::SKIA_ADAPTER; 31 32 SkiaSurface(); 33 ~SkiaSurface() override; 34 GetType()35 AdapterType GetType() const override 36 { 37 return AdapterType::SKIA_ADAPTER; 38 } 39 40 bool Bind(const Bitmap& bitmap) override; 41 #ifdef RS_ENABLE_GPU 42 bool Bind(const Image& image) override; 43 bool Bind(const FrameBuffer& frameBuffer) override; 44 45 #ifdef RS_ENABLE_VK 46 static std::shared_ptr<Surface> MakeFromBackendRenderTarget(GPUContext* gpuContext, const TextureInfo& info, 47 TextureOrigin origin, ColorType colorType, std::shared_ptr<ColorSpace> colorSpace, 48 void (*deleteVkImage)(void *), void* cleanHelper); 49 #endif 50 static std::shared_ptr<Surface> MakeFromBackendTexture(GPUContext* gpuContext, const TextureInfo& info, 51 TextureOrigin origin, int sampleCnt, ColorType colorType, 52 std::shared_ptr<ColorSpace> colorSpace, void (*deleteVkImage)(void *), void* cleanHelper); 53 static std::shared_ptr<Surface> MakeRenderTarget(GPUContext* gpuContext, bool budgeted, const ImageInfo& imageInfo); 54 #endif 55 static std::shared_ptr<Surface> MakeRaster(const ImageInfo& imageInfo); 56 static std::shared_ptr<Surface> MakeRasterDirect(const ImageInfo& imageInfo, void* pixels, size_t rowBytes); 57 static std::shared_ptr<Surface> MakeRasterN32Premul(int32_t width, int32_t height); 58 59 std::shared_ptr<Canvas> GetCanvas() const override; 60 std::shared_ptr<Image> GetImageSnapshot() const override; 61 std::shared_ptr<Image> GetImageSnapshot(const RectI& bounds, bool allowRefCache = true) const override; 62 std::shared_ptr<Surface> MakeSurface(int width, int height) const override; 63 std::shared_ptr<Surface> MakeSurface(const ImageInfo& imageInfo) const override; 64 BackendTexture GetBackendTexture(BackendAccess access) const override; 65 66 void SetSkSurface(const sk_sp<SkSurface>& skSurface); 67 void FlushAndSubmit(bool syncCpu) override; 68 SemaphoresSubmited Flush(FlushInfo *drawingflushInfo = nullptr) override; 69 #ifdef RS_ENABLE_GL 70 void Wait(const std::vector<GrGLsync>& syncs) override; 71 #endif 72 #ifdef RS_ENABLE_VK 73 void Wait(int32_t time, const VkSemaphore& semaphore) override; 74 void SetDrawingArea(const std::vector<RectI>& rects) override; 75 void ClearDrawingArea() override; 76 #endif 77 void SetHeadroom(float headroom) override; 78 float GetHeadroom() const override; 79 sk_sp<SkSurface> GetSkSurface() const; 80 int Width() const override; 81 int Height() const override; 82 private: 83 void PostSkSurfaceToTargetThread(); 84 sk_sp<SkSurface> skSurface_ = nullptr; 85 sk_sp<SkImage> skImage_ = nullptr; 86 }; 87 } // namespace Drawing 88 } // namespace Rosen 89 } // namespace OHOS 90 #endif // SKIA_SURFACE_H 91