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