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 #include "rs_surface_frame_ohos_vulkan.h"
17 #include "platform/common/rs_log.h"
18 
19 #include "platform/common/rs_system_properties.h"
20 #include "rs_trace.h"
21 
22 namespace OHOS {
23 namespace Rosen {
24 
RSSurfaceFrameOhosVulkan(std::shared_ptr<Drawing::Surface> surface,int32_t width,int32_t height,int32_t bufferAge)25 RSSurfaceFrameOhosVulkan::RSSurfaceFrameOhosVulkan(std::shared_ptr<Drawing::Surface> surface, int32_t width,
26     int32_t height, int32_t bufferAge)
27     : surface_(surface), width_(width), height_(height), bufferAge_(bufferAge)
28 {
29 }
30 
SetDamageRegion(int32_t left,int32_t top,int32_t width,int32_t height)31 void RSSurfaceFrameOhosVulkan::SetDamageRegion(int32_t left, int32_t top, int32_t width, int32_t height)
32 {
33 #ifdef RS_ENABLE_VK
34     if (!RSSystemProperties::IsUseVulkan()) {
35         return;
36     }
37     RS_TRACE_FUNC();
38     std::vector<Drawing::RectI> rects;
39     Drawing::RectI rect = {left, top, left + width, top + height};
40     rects.push_back(rect);
41     surface_->SetDrawingArea(rects);
42 #endif
43 }
44 
SetDamageRegion(const std::vector<RectI> & rects)45 void RSSurfaceFrameOhosVulkan::SetDamageRegion(const std::vector<RectI>& rects)
46 {
47 #ifdef RS_ENABLE_VK
48     if (!RSSystemProperties::IsUseVulkan()) {
49         return;
50     }
51     RS_TRACE_FUNC();
52     std::vector<Drawing::RectI> iRects;
53     for (auto &rect : rects) {
54         Drawing::RectI iRect = {rect.GetLeft(), rect.GetTop(), rect.GetRight(), rect.GetBottom()};
55         iRects.push_back(iRect);
56     }
57     surface_->SetDrawingArea(iRects);
58 #endif
59 }
60 
GetCanvas()61 Drawing::Canvas* RSSurfaceFrameOhosVulkan::GetCanvas()
62 {
63     return surface_ != nullptr ? surface_->GetCanvas().get() : nullptr;
64 }
65 
GetSurface()66 std::shared_ptr<Drawing::Surface> RSSurfaceFrameOhosVulkan::GetSurface()
67 {
68     return surface_;
69 }
70 
GetReleaseFence() const71 int32_t RSSurfaceFrameOhosVulkan::GetReleaseFence() const
72 {
73     return releaseFence_;
74 }
75 
SetReleaseFence(const int32_t & fence)76 void RSSurfaceFrameOhosVulkan::SetReleaseFence(const int32_t& fence)
77 {
78     releaseFence_ = fence;
79 }
80 
GetBufferAge() const81 int32_t RSSurfaceFrameOhosVulkan::GetBufferAge() const
82 {
83     return bufferAge_;
84 }
85 } // namespace Rosen
86 } // namespace OHOS
87