1 /*
2 * Copyright (c) 2022-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 "pipeline/rs_surface_handler.h"
17 #ifndef ROSEN_CROSS_PLATFORM
18 #include "metadata_helper.h"
19 #endif
20 #include "rs_trace.h"
21
22 namespace OHOS {
23 namespace Rosen {
~RSSurfaceHandler()24 RSSurfaceHandler::~RSSurfaceHandler() noexcept
25 {
26 }
27 #ifndef ROSEN_CROSS_PLATFORM
SetConsumer(sptr<IConsumerSurface> consumer)28 void RSSurfaceHandler::SetConsumer(sptr<IConsumerSurface> consumer)
29 {
30 consumer_ = consumer;
31 }
32 #endif
33
IncreaseAvailableBuffer()34 void RSSurfaceHandler::IncreaseAvailableBuffer()
35 {
36 bufferAvailableCount_++;
37 }
38
ReduceAvailableBuffer()39 void RSSurfaceHandler::ReduceAvailableBuffer()
40 {
41 --bufferAvailableCount_;
42 }
43
SetGlobalZOrder(float globalZOrder)44 void RSSurfaceHandler::SetGlobalZOrder(float globalZOrder)
45 {
46 globalZOrder_ = globalZOrder;
47 }
48
GetGlobalZOrder() const49 float RSSurfaceHandler::GetGlobalZOrder() const
50 {
51 return globalZOrder_;
52 }
53
54 #ifndef ROSEN_CROSS_PLATFORM
ConsumeAndUpdateBuffer(SurfaceBufferEntry buffer)55 void RSSurfaceHandler::ConsumeAndUpdateBuffer(SurfaceBufferEntry buffer)
56 {
57 ConsumeAndUpdateBufferInner(buffer);
58 }
59
ConsumeAndUpdateBufferInner(SurfaceBufferEntry & buffer)60 void RSSurfaceHandler::ConsumeAndUpdateBufferInner(SurfaceBufferEntry& buffer)
61 {
62 if (!buffer.buffer) {
63 return;
64 }
65 using namespace OHOS::HDI::Display::Graphic::Common::V1_0;
66 BufferHandleMetaRegion crop;
67 if (MetadataHelper::GetCropRectMetadata(buffer.buffer, crop) == GSERROR_OK) {
68 buffer.buffer->SetCropMetadata({crop.left, crop.top, crop.width, crop.height});
69 }
70 SetBuffer(buffer.buffer, buffer.acquireFence, buffer.damageRect, buffer.timestamp);
71 SetBufferSizeChanged(buffer.buffer);
72 SetCurrentFrameBufferConsumed();
73 RS_LOGD_IF(DEBUG_PIPELINE,
74 "RsDebug surfaceHandler(id: %{public}" PRIu64 ") buffer update, "
75 "buffer[timestamp:%{public}" PRId64 ", seq:%{public}" PRIu32 "]",
76 GetNodeId(), buffer.timestamp, buffer.buffer->GetSeqNum());
77 }
78 #endif
79 }
80 }
81