1 /*
2  * Copyright (c) 2021-2022 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_SURFACE_FRAME_OHOS_RASTER_H
17 #define RS_SURFACE_FRAME_OHOS_RASTER_H
18 
19 #include <surface.h>
20 
21 #include "platform/drawing/rs_surface_frame.h"
22 #include "platform/ohos/rs_surface_frame_ohos.h"
23 
24 namespace OHOS {
25 namespace Rosen {
26 
27 class RSSurfaceFrameOhosRaster : public RSSurfaceFrameOhos {
28 public:
29     RSSurfaceFrameOhosRaster(int32_t width, int32_t height);
30     ~RSSurfaceFrameOhosRaster() = default;
31 
32     Drawing::Canvas* GetCanvas() override;
33     std::shared_ptr<Drawing::Surface> GetSurface() override;
34 
GetBuffer()35     sptr<SurfaceBuffer> GetBuffer() const
36     {
37         return buffer_;
38     }
39     void SetDamageRegion(int32_t left, int32_t top, int32_t width, int32_t height) override;
40     void SetDamageRegion(const std::vector<RectI> &rects) override;
41     int32_t GetBufferAge() const override;
42     int32_t GetReleaseFence() const;
43     void SetReleaseFence(const int32_t& fence);
44     friend class RSSurfaceOhosRaster;
45 private:
46     sptr<SurfaceBuffer> buffer_;
47     int32_t releaseFence_ = -1;
48     BufferRequestConfig requestConfig_ = {
49         .width = 0x100,
50         .height = 0x100,
51         .strideAlignment = 0x8,
52         .format = GRAPHIC_PIXEL_FMT_RGBA_8888,
53         .usage = BUFFER_USAGE_CPU_READ | BUFFER_USAGE_CPU_WRITE | BUFFER_USAGE_MEM_DMA,
54         .timeout = 0,
55     };
56     BufferFlushConfig flushConfig_ = {
57         .damage = {
58             .x = 0,
59             .y = 0,
60             .w = 0x100,
61             .h = 0x100,
62         },
63     };
64 
65     void CreateSurface();
66 };
67 
68 } // namespace Rosen
69 } // namespace OHOS
70 
71 #endif // RENDER_SERVICE_BASE_PLATFORM_RS_SURFACE_FRAME_OHOS_H