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 DRAWING_SURFACE_IMPL_H 17 #define DRAWING_SURFACE_IMPL_H 18 19 #include <vector> 20 21 #include "base_impl.h" 22 #include "image/image_info.h" 23 #include "utils/rect.h" 24 #ifdef RS_ENABLE_GL 25 #ifdef USE_M133_SKIA 26 #include "include/gpu/ganesh/gl/GrGLTypes.h" 27 #else 28 #include "include/gpu/gl/GrGLTypes.h" 29 #endif 30 #endif 31 #ifdef RS_ENABLE_VK 32 #include "vulkan/vulkan.h" 33 #endif 34 namespace OHOS { 35 namespace Rosen { 36 namespace Drawing { 37 class BackendTexture; 38 class Bitmap; 39 class Canvas; 40 class Image; 41 class Surface; 42 struct FlushInfo; 43 #ifdef RS_ENABLE_GPU 44 struct FrameBuffer; 45 #endif 46 enum class BackendAccess; 47 enum class SemaphoresSubmited; 48 49 class SurfaceImpl : public BaseImpl { 50 public: SurfaceImpl()51 SurfaceImpl() {}; ~SurfaceImpl()52 ~SurfaceImpl() override {}; 53 54 virtual bool Bind(const Bitmap& bitmap) = 0; 55 #ifdef RS_ENABLE_GPU 56 virtual bool Bind(const Image& image) = 0; 57 virtual bool Bind(const FrameBuffer& frameBuffer) = 0; 58 #endif 59 virtual std::shared_ptr<Canvas> GetCanvas() const = 0; 60 virtual std::shared_ptr<Image> GetImageSnapshot() const = 0; 61 virtual std::shared_ptr<Image> GetImageSnapshot(const RectI& bounds, bool allowRefCache = true) const = 0; 62 virtual std::shared_ptr<Surface> MakeSurface(int width, int height) const = 0; 63 virtual std::shared_ptr<Surface> MakeSurface(const ImageInfo& imageInfo) const = 0; 64 virtual BackendTexture GetBackendTexture(BackendAccess access) const = 0; 65 virtual void FlushAndSubmit(bool syncCpu) = 0; 66 virtual SemaphoresSubmited Flush(FlushInfo *drawingflushInfo = nullptr) = 0; 67 #ifdef RS_ENABLE_GL Wait(const std::vector<GrGLsync> & syncs)68 virtual void Wait(const std::vector<GrGLsync>& syncs) {}; 69 #endif 70 #ifdef RS_ENABLE_VK 71 virtual void Wait(int32_t time, const VkSemaphore& semaphore) = 0; 72 virtual void SetDrawingArea(const std::vector<RectI>& rects) = 0; 73 virtual void ClearDrawingArea() = 0; 74 #endif 75 virtual void SetHeadroom(float headroom) = 0; 76 virtual float GetHeadroom() const = 0; 77 virtual int Width() const = 0; 78 virtual int Height() const = 0; 79 }; 80 } // namespace Drawing 81 } // namespace Rosen 82 } // namespace OHOS 83 #endif // DRAWING_SURFACE_IMPL_H 84