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 RS_RENDER_SURFACE_H
17 #define RS_RENDER_SURFACE_H
18 
19 #include <memory>
20 
21 #include "common/rs_rect.h"
22 #include "include/core/SkCanvas.h"
23 #include "include/core/SkSurface.h"
24 
25 #ifndef ROSEN_CROSS_PLATFORM
26 #include "surface_type.h"
27 #endif
28 
29 #include "drawing_context.h"
30 #include "rs_render_surface_frame.h"
31 #include "render_context_base.h"
32 
33 namespace OHOS {
34 namespace Rosen {
35 class RSRenderSurface {
36 public:
37     explicit RSRenderSurface() = default;
38     virtual ~RSRenderSurface() = default;
39     virtual bool IsValid() const = 0;
40     virtual uint32_t GetQueueSize() const = 0;
41     virtual std::shared_ptr<RSRenderSurfaceFrame> RequestFrame(
42         int32_t width, int32_t height, uint64_t uiTimestamp = 0, bool useAFBC = true) = 0;
43     virtual bool FlushFrame(uint64_t uiTimestamp = 0) = 0;
44     virtual void SetUiTimeStamp(uint64_t uiTimestamp = 0) = 0;
45     virtual void SetDamageRegion(const std::vector<RectI>& rects) = 0;
46     virtual int32_t GetBufferAge() = 0;
47     virtual GraphicColorGamut GetColorSpace() = 0;
48     virtual void SetColorSpace(GraphicColorGamut colorSpace) = 0;
49     virtual void ClearBuffer() = 0;
50     virtual SkCanvas* GetCanvas() = 0;
51     virtual sk_sp<SkSurface> GetSurface() = 0;
SetRSRenderSurfaceFrame(const std::shared_ptr<RSRenderSurfaceFrame> & frame)52     void SetRSRenderSurfaceFrame(const std::shared_ptr<RSRenderSurfaceFrame>& frame)
53     {
54         frame_ = frame;
55     }
SetRenderContext(const std::shared_ptr<RenderContextBase> & renderContext)56     void SetRenderContext(const std::shared_ptr<RenderContextBase>& renderContext)
57     {
58         renderContext_ = renderContext;
59     }
SetDrawingContext(const std::shared_ptr<DrawingContext> & drawingContext)60     void SetDrawingContext(const std::shared_ptr<DrawingContext>& drawingContext)
61     {
62         drawingContext_ = drawingContext;
63     }
64 protected:
65     std::shared_ptr<RSRenderSurfaceFrame> frame_;
66     std::shared_ptr<RenderContextBase> renderContext_;
67     std::shared_ptr<DrawingContext> drawingContext_;
68 };
69 }
70 } // namespace Rosen
71 #endif