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 #ifdef RS_ENABLE_VK 45 static std::shared_ptr<Surface> MakeFromBackendRenderTarget(GPUContext* gpuContext, const TextureInfo& info, 46 TextureOrigin origin, ColorType colorType, std::shared_ptr<ColorSpace> colorSpace, 47 void (*deleteVkImage)(void *), void* cleanHelper); 48 #endif 49 static std::shared_ptr<Surface> MakeFromBackendTexture(GPUContext* gpuContext, const TextureInfo& info, 50 TextureOrigin origin, int sampleCnt, ColorType colorType, 51 std::shared_ptr<ColorSpace> colorSpace, void (*deleteVkImage)(void *), void* cleanHelper); 52 static std::shared_ptr<Surface> MakeRenderTarget(GPUContext* gpuContext, bool budgeted, const ImageInfo& imageInfo); 53 #endif 54 static std::shared_ptr<Surface> MakeRaster(const ImageInfo& imageInfo); 55 static std::shared_ptr<Surface> MakeRasterDirect(const ImageInfo& imageInfo, void* pixels, size_t rowBytes); 56 static std::shared_ptr<Surface> MakeRasterN32Premul(int32_t width, int32_t height); 57 58 std::shared_ptr<Canvas> GetCanvas() const override; 59 std::shared_ptr<Image> GetImageSnapshot() const override; 60 std::shared_ptr<Image> GetImageSnapshot(const RectI& bounds, bool allowRefCache = true) const override; 61 std::shared_ptr<Surface> MakeSurface(int width, int height) const override; 62 std::shared_ptr<Surface> MakeSurface(const ImageInfo& imageInfo) const override; 63 BackendTexture GetBackendTexture(BackendAccess access) const override; 64 void SetSkSurface(const sk_sp<SkSurface>& skSurface); 65 void FlushAndSubmit(bool syncCpu) override; 66 void Flush(FlushInfo *drawingflushInfo = nullptr) override; 67 #ifdef RS_ENABLE_GL 68 void Wait(const std::vector<GrGLsync>& syncs) override; 69 #endif 70 #ifdef RS_ENABLE_VK 71 void Wait(int32_t time, const VkSemaphore& semaphore) override; 72 void SetDrawingArea(const std::vector<RectI>& rects) override; 73 void ClearDrawingArea() override; 74 #endif 75 sk_sp<SkSurface> GetSkSurface() const; 76 int Width() const override; 77 int Height() const override; 78 private: 79 void PostSkSurfaceToTargetThread(); 80 sk_sp<SkSurface> skSurface_ = nullptr; 81 sk_sp<SkImage> skImage_ = nullptr; 82 }; 83 } // namespace Drawing 84 } // namespace Rosen 85 } // namespace OHOS 86 #endif // SKIA_SURFACE_H 87