1 /*
2  * Copyright (c) 2021-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 RENDER_SERVICE_BASE_DRAWING_RS_SURFACE_H
17 #define RENDER_SERVICE_BASE_DRAWING_RS_SURFACE_H
18 
19 #include <memory>
20 
21 #include "rs_surface_frame.h"
22 #include "surface_type.h"
23 
24 namespace OHOS {
25 namespace Rosen {
26 class RenderContext;
27 class RSSurfaceExt;
28 using RSSurfaceExtPtr = std::shared_ptr<RSSurfaceExt>;
29 
30 class RSSurface {
31 public:
32     RSSurface() = default;
33 
34     virtual ~RSSurface() = default;
35 
36     virtual bool IsValid() const = 0;
37 
38     virtual void SetUiTimeStamp(const std::unique_ptr<RSSurfaceFrame>& frame, uint64_t uiTimestamp = 0) = 0;
39 
40     virtual std::unique_ptr<RSSurfaceFrame> RequestFrame(
41         int32_t width, int32_t height, uint64_t uiTimestamp = 0, bool useAFBC = true, bool isProtected = false) = 0;
42 
43     virtual bool FlushFrame(std::unique_ptr<RSSurfaceFrame>& frame, uint64_t uiTimestamp = 0) = 0;
44 
45     virtual RenderContext* GetRenderContext() = 0;
46     virtual void SetRenderContext(RenderContext* context) = 0;
47     virtual GraphicColorGamut GetColorSpace() const = 0;
48     virtual void SetColorSpace(GraphicColorGamut colorSpace) = 0;
49     virtual uint32_t GetQueueSize() const = 0;
50     virtual void ClearBuffer() = 0; // clear cache only for producer
51 
52     // clear buffer for both producer and consumer and will receive OnGoBackground callback
53     virtual void ClearAllBuffer() = 0;
54     virtual void ResetBufferAge() = 0;
55 #ifdef USE_SURFACE_TEXTURE
56     virtual RSSurfaceExtPtr CreateSurfaceExt(const RSSurfaceExtConfig& config) = 0;
57     virtual RSSurfaceExtPtr GetSurfaceExt(const RSSurfaceExtConfig& config) = 0;
58 #endif
59 protected:
60 private:
61 };
62 
63 } // namespace Rosen
64 } // namespace OHOS
65 
66 #endif // RENDER_SERVICE_BASE_DRAWING_RS_SURFACE_H
67