1*0a9764feSAndroid Build Coastguard Worker /*
2*0a9764feSAndroid Build Coastguard Worker * Copyright (C) 2022 The Android Open Source Project
3*0a9764feSAndroid Build Coastguard Worker *
4*0a9764feSAndroid Build Coastguard Worker * Licensed under the Apache License, Version 2.0 (the "License");
5*0a9764feSAndroid Build Coastguard Worker * you may not use this file except in compliance with the License.
6*0a9764feSAndroid Build Coastguard Worker * You may obtain a copy of the License at
7*0a9764feSAndroid Build Coastguard Worker *
8*0a9764feSAndroid Build Coastguard Worker * http://www.apache.org/licenses/LICENSE-2.0
9*0a9764feSAndroid Build Coastguard Worker *
10*0a9764feSAndroid Build Coastguard Worker * Unless required by applicable law or agreed to in writing, software
11*0a9764feSAndroid Build Coastguard Worker * distributed under the License is distributed on an "AS IS" BASIS,
12*0a9764feSAndroid Build Coastguard Worker * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13*0a9764feSAndroid Build Coastguard Worker * See the License for the specific language governing permissions and
14*0a9764feSAndroid Build Coastguard Worker * limitations under the License.
15*0a9764feSAndroid Build Coastguard Worker */
16*0a9764feSAndroid Build Coastguard Worker
17*0a9764feSAndroid Build Coastguard Worker #define LOG_TAG "drmhwc"
18*0a9764feSAndroid Build Coastguard Worker
19*0a9764feSAndroid Build Coastguard Worker #include "HwcLayer.h"
20*0a9764feSAndroid Build Coastguard Worker
21*0a9764feSAndroid Build Coastguard Worker #include "HwcDisplay.h"
22*0a9764feSAndroid Build Coastguard Worker #include "bufferinfo/BufferInfoGetter.h"
23*0a9764feSAndroid Build Coastguard Worker #include "utils/log.h"
24*0a9764feSAndroid Build Coastguard Worker
25*0a9764feSAndroid Build Coastguard Worker namespace android {
26*0a9764feSAndroid Build Coastguard Worker
SetLayerProperties(const LayerProperties & layer_properties)27*0a9764feSAndroid Build Coastguard Worker void HwcLayer::SetLayerProperties(const LayerProperties& layer_properties) {
28*0a9764feSAndroid Build Coastguard Worker if (layer_properties.buffer) {
29*0a9764feSAndroid Build Coastguard Worker layer_data_.acquire_fence = layer_properties.buffer->acquire_fence;
30*0a9764feSAndroid Build Coastguard Worker buffer_handle_ = layer_properties.buffer->buffer_handle;
31*0a9764feSAndroid Build Coastguard Worker buffer_handle_updated_ = true;
32*0a9764feSAndroid Build Coastguard Worker }
33*0a9764feSAndroid Build Coastguard Worker if (layer_properties.blend_mode) {
34*0a9764feSAndroid Build Coastguard Worker blend_mode_ = layer_properties.blend_mode.value();
35*0a9764feSAndroid Build Coastguard Worker }
36*0a9764feSAndroid Build Coastguard Worker if (layer_properties.color_space) {
37*0a9764feSAndroid Build Coastguard Worker color_space_ = layer_properties.color_space.value();
38*0a9764feSAndroid Build Coastguard Worker }
39*0a9764feSAndroid Build Coastguard Worker if (layer_properties.sample_range) {
40*0a9764feSAndroid Build Coastguard Worker sample_range_ = layer_properties.sample_range.value();
41*0a9764feSAndroid Build Coastguard Worker }
42*0a9764feSAndroid Build Coastguard Worker if (layer_properties.composition_type) {
43*0a9764feSAndroid Build Coastguard Worker sf_type_ = layer_properties.composition_type.value();
44*0a9764feSAndroid Build Coastguard Worker }
45*0a9764feSAndroid Build Coastguard Worker if (layer_properties.display_frame) {
46*0a9764feSAndroid Build Coastguard Worker layer_data_.pi.display_frame = layer_properties.display_frame.value();
47*0a9764feSAndroid Build Coastguard Worker }
48*0a9764feSAndroid Build Coastguard Worker if (layer_properties.alpha) {
49*0a9764feSAndroid Build Coastguard Worker layer_data_.pi.alpha = std::lround(layer_properties.alpha.value() *
50*0a9764feSAndroid Build Coastguard Worker UINT16_MAX);
51*0a9764feSAndroid Build Coastguard Worker }
52*0a9764feSAndroid Build Coastguard Worker if (layer_properties.source_crop) {
53*0a9764feSAndroid Build Coastguard Worker layer_data_.pi.source_crop = layer_properties.source_crop.value();
54*0a9764feSAndroid Build Coastguard Worker }
55*0a9764feSAndroid Build Coastguard Worker if (layer_properties.transform) {
56*0a9764feSAndroid Build Coastguard Worker layer_data_.pi.transform = layer_properties.transform.value();
57*0a9764feSAndroid Build Coastguard Worker }
58*0a9764feSAndroid Build Coastguard Worker if (layer_properties.z_order) {
59*0a9764feSAndroid Build Coastguard Worker z_order_ = layer_properties.z_order.value();
60*0a9764feSAndroid Build Coastguard Worker }
61*0a9764feSAndroid Build Coastguard Worker }
62*0a9764feSAndroid Build Coastguard Worker
63*0a9764feSAndroid Build Coastguard Worker // NOLINTNEXTLINE(readability-convert-member-functions-to-static)
SetCursorPosition(int32_t,int32_t)64*0a9764feSAndroid Build Coastguard Worker HWC2::Error HwcLayer::SetCursorPosition(int32_t /*x*/, int32_t /*y*/) {
65*0a9764feSAndroid Build Coastguard Worker return HWC2::Error::None;
66*0a9764feSAndroid Build Coastguard Worker }
67*0a9764feSAndroid Build Coastguard Worker
SetLayerBlendMode(int32_t mode)68*0a9764feSAndroid Build Coastguard Worker HWC2::Error HwcLayer::SetLayerBlendMode(int32_t mode) {
69*0a9764feSAndroid Build Coastguard Worker switch (static_cast<HWC2::BlendMode>(mode)) {
70*0a9764feSAndroid Build Coastguard Worker case HWC2::BlendMode::None:
71*0a9764feSAndroid Build Coastguard Worker blend_mode_ = BufferBlendMode::kNone;
72*0a9764feSAndroid Build Coastguard Worker break;
73*0a9764feSAndroid Build Coastguard Worker case HWC2::BlendMode::Premultiplied:
74*0a9764feSAndroid Build Coastguard Worker blend_mode_ = BufferBlendMode::kPreMult;
75*0a9764feSAndroid Build Coastguard Worker break;
76*0a9764feSAndroid Build Coastguard Worker case HWC2::BlendMode::Coverage:
77*0a9764feSAndroid Build Coastguard Worker blend_mode_ = BufferBlendMode::kCoverage;
78*0a9764feSAndroid Build Coastguard Worker break;
79*0a9764feSAndroid Build Coastguard Worker default:
80*0a9764feSAndroid Build Coastguard Worker ALOGE("Unknown blending mode b=%d", mode);
81*0a9764feSAndroid Build Coastguard Worker blend_mode_ = BufferBlendMode::kUndefined;
82*0a9764feSAndroid Build Coastguard Worker break;
83*0a9764feSAndroid Build Coastguard Worker }
84*0a9764feSAndroid Build Coastguard Worker return HWC2::Error::None;
85*0a9764feSAndroid Build Coastguard Worker }
86*0a9764feSAndroid Build Coastguard Worker
87*0a9764feSAndroid Build Coastguard Worker /* Find API details at:
88*0a9764feSAndroid Build Coastguard Worker * https://cs.android.com/android/platform/superproject/+/android-11.0.0_r3:hardware/libhardware/include/hardware/hwcomposer2.h;l=2314
89*0a9764feSAndroid Build Coastguard Worker */
SetLayerBuffer(buffer_handle_t buffer,int32_t acquire_fence)90*0a9764feSAndroid Build Coastguard Worker HWC2::Error HwcLayer::SetLayerBuffer(buffer_handle_t buffer,
91*0a9764feSAndroid Build Coastguard Worker int32_t acquire_fence) {
92*0a9764feSAndroid Build Coastguard Worker layer_data_.acquire_fence = MakeSharedFd(acquire_fence);
93*0a9764feSAndroid Build Coastguard Worker buffer_handle_ = buffer;
94*0a9764feSAndroid Build Coastguard Worker buffer_handle_updated_ = true;
95*0a9764feSAndroid Build Coastguard Worker
96*0a9764feSAndroid Build Coastguard Worker return HWC2::Error::None;
97*0a9764feSAndroid Build Coastguard Worker }
98*0a9764feSAndroid Build Coastguard Worker
99*0a9764feSAndroid Build Coastguard Worker // NOLINTNEXTLINE(readability-convert-member-functions-to-static)
SetLayerColor(hwc_color_t)100*0a9764feSAndroid Build Coastguard Worker HWC2::Error HwcLayer::SetLayerColor(hwc_color_t /*color*/) {
101*0a9764feSAndroid Build Coastguard Worker // TODO(nobody): Put to client composition here?
102*0a9764feSAndroid Build Coastguard Worker return HWC2::Error::None;
103*0a9764feSAndroid Build Coastguard Worker }
104*0a9764feSAndroid Build Coastguard Worker
SetLayerCompositionType(int32_t type)105*0a9764feSAndroid Build Coastguard Worker HWC2::Error HwcLayer::SetLayerCompositionType(int32_t type) {
106*0a9764feSAndroid Build Coastguard Worker sf_type_ = static_cast<HWC2::Composition>(type);
107*0a9764feSAndroid Build Coastguard Worker return HWC2::Error::None;
108*0a9764feSAndroid Build Coastguard Worker }
109*0a9764feSAndroid Build Coastguard Worker
SetLayerDataspace(int32_t dataspace)110*0a9764feSAndroid Build Coastguard Worker HWC2::Error HwcLayer::SetLayerDataspace(int32_t dataspace) {
111*0a9764feSAndroid Build Coastguard Worker switch (dataspace & HAL_DATASPACE_STANDARD_MASK) {
112*0a9764feSAndroid Build Coastguard Worker case HAL_DATASPACE_STANDARD_BT709:
113*0a9764feSAndroid Build Coastguard Worker color_space_ = BufferColorSpace::kItuRec709;
114*0a9764feSAndroid Build Coastguard Worker break;
115*0a9764feSAndroid Build Coastguard Worker case HAL_DATASPACE_STANDARD_BT601_625:
116*0a9764feSAndroid Build Coastguard Worker case HAL_DATASPACE_STANDARD_BT601_625_UNADJUSTED:
117*0a9764feSAndroid Build Coastguard Worker case HAL_DATASPACE_STANDARD_BT601_525:
118*0a9764feSAndroid Build Coastguard Worker case HAL_DATASPACE_STANDARD_BT601_525_UNADJUSTED:
119*0a9764feSAndroid Build Coastguard Worker color_space_ = BufferColorSpace::kItuRec601;
120*0a9764feSAndroid Build Coastguard Worker break;
121*0a9764feSAndroid Build Coastguard Worker case HAL_DATASPACE_STANDARD_BT2020:
122*0a9764feSAndroid Build Coastguard Worker case HAL_DATASPACE_STANDARD_BT2020_CONSTANT_LUMINANCE:
123*0a9764feSAndroid Build Coastguard Worker color_space_ = BufferColorSpace::kItuRec2020;
124*0a9764feSAndroid Build Coastguard Worker break;
125*0a9764feSAndroid Build Coastguard Worker default:
126*0a9764feSAndroid Build Coastguard Worker color_space_ = BufferColorSpace::kUndefined;
127*0a9764feSAndroid Build Coastguard Worker }
128*0a9764feSAndroid Build Coastguard Worker
129*0a9764feSAndroid Build Coastguard Worker switch (dataspace & HAL_DATASPACE_RANGE_MASK) {
130*0a9764feSAndroid Build Coastguard Worker case HAL_DATASPACE_RANGE_FULL:
131*0a9764feSAndroid Build Coastguard Worker sample_range_ = BufferSampleRange::kFullRange;
132*0a9764feSAndroid Build Coastguard Worker break;
133*0a9764feSAndroid Build Coastguard Worker case HAL_DATASPACE_RANGE_LIMITED:
134*0a9764feSAndroid Build Coastguard Worker sample_range_ = BufferSampleRange::kLimitedRange;
135*0a9764feSAndroid Build Coastguard Worker break;
136*0a9764feSAndroid Build Coastguard Worker default:
137*0a9764feSAndroid Build Coastguard Worker sample_range_ = BufferSampleRange::kUndefined;
138*0a9764feSAndroid Build Coastguard Worker }
139*0a9764feSAndroid Build Coastguard Worker return HWC2::Error::None;
140*0a9764feSAndroid Build Coastguard Worker }
141*0a9764feSAndroid Build Coastguard Worker
SetLayerDisplayFrame(hwc_rect_t frame)142*0a9764feSAndroid Build Coastguard Worker HWC2::Error HwcLayer::SetLayerDisplayFrame(hwc_rect_t frame) {
143*0a9764feSAndroid Build Coastguard Worker layer_data_.pi.display_frame = frame;
144*0a9764feSAndroid Build Coastguard Worker return HWC2::Error::None;
145*0a9764feSAndroid Build Coastguard Worker }
146*0a9764feSAndroid Build Coastguard Worker
SetLayerPlaneAlpha(float alpha)147*0a9764feSAndroid Build Coastguard Worker HWC2::Error HwcLayer::SetLayerPlaneAlpha(float alpha) {
148*0a9764feSAndroid Build Coastguard Worker layer_data_.pi.alpha = std::lround(alpha * UINT16_MAX);
149*0a9764feSAndroid Build Coastguard Worker return HWC2::Error::None;
150*0a9764feSAndroid Build Coastguard Worker }
151*0a9764feSAndroid Build Coastguard Worker
152*0a9764feSAndroid Build Coastguard Worker // NOLINTNEXTLINE(readability-convert-member-functions-to-static)
SetLayerSidebandStream(const native_handle_t *)153*0a9764feSAndroid Build Coastguard Worker HWC2::Error HwcLayer::SetLayerSidebandStream(
154*0a9764feSAndroid Build Coastguard Worker const native_handle_t* /*stream*/) {
155*0a9764feSAndroid Build Coastguard Worker // TODO(nobody): We don't support sideband
156*0a9764feSAndroid Build Coastguard Worker return HWC2::Error::Unsupported;
157*0a9764feSAndroid Build Coastguard Worker }
158*0a9764feSAndroid Build Coastguard Worker
SetLayerSourceCrop(hwc_frect_t crop)159*0a9764feSAndroid Build Coastguard Worker HWC2::Error HwcLayer::SetLayerSourceCrop(hwc_frect_t crop) {
160*0a9764feSAndroid Build Coastguard Worker layer_data_.pi.source_crop = crop;
161*0a9764feSAndroid Build Coastguard Worker return HWC2::Error::None;
162*0a9764feSAndroid Build Coastguard Worker }
163*0a9764feSAndroid Build Coastguard Worker
164*0a9764feSAndroid Build Coastguard Worker // NOLINTNEXTLINE(readability-convert-member-functions-to-static)
SetLayerSurfaceDamage(hwc_region_t)165*0a9764feSAndroid Build Coastguard Worker HWC2::Error HwcLayer::SetLayerSurfaceDamage(hwc_region_t /*damage*/) {
166*0a9764feSAndroid Build Coastguard Worker // TODO(nobody): We don't use surface damage, marking as unsupported
167*0a9764feSAndroid Build Coastguard Worker return HWC2::Error::None;
168*0a9764feSAndroid Build Coastguard Worker }
169*0a9764feSAndroid Build Coastguard Worker
SetLayerTransform(int32_t transform)170*0a9764feSAndroid Build Coastguard Worker HWC2::Error HwcLayer::SetLayerTransform(int32_t transform) {
171*0a9764feSAndroid Build Coastguard Worker uint32_t l_transform = 0;
172*0a9764feSAndroid Build Coastguard Worker
173*0a9764feSAndroid Build Coastguard Worker // 270* and 180* cannot be combined with flips. More specifically, they
174*0a9764feSAndroid Build Coastguard Worker // already contain both horizontal and vertical flips, so those fields are
175*0a9764feSAndroid Build Coastguard Worker // redundant in this case. 90* rotation can be combined with either horizontal
176*0a9764feSAndroid Build Coastguard Worker // flip or vertical flip, so treat it differently
177*0a9764feSAndroid Build Coastguard Worker if (transform == HWC_TRANSFORM_ROT_270) {
178*0a9764feSAndroid Build Coastguard Worker l_transform = LayerTransform::kRotate270;
179*0a9764feSAndroid Build Coastguard Worker } else if (transform == HWC_TRANSFORM_ROT_180) {
180*0a9764feSAndroid Build Coastguard Worker l_transform = LayerTransform::kRotate180;
181*0a9764feSAndroid Build Coastguard Worker } else {
182*0a9764feSAndroid Build Coastguard Worker if ((transform & HWC_TRANSFORM_FLIP_H) != 0)
183*0a9764feSAndroid Build Coastguard Worker l_transform |= LayerTransform::kFlipH;
184*0a9764feSAndroid Build Coastguard Worker if ((transform & HWC_TRANSFORM_FLIP_V) != 0)
185*0a9764feSAndroid Build Coastguard Worker l_transform |= LayerTransform::kFlipV;
186*0a9764feSAndroid Build Coastguard Worker if ((transform & HWC_TRANSFORM_ROT_90) != 0)
187*0a9764feSAndroid Build Coastguard Worker l_transform |= LayerTransform::kRotate90;
188*0a9764feSAndroid Build Coastguard Worker }
189*0a9764feSAndroid Build Coastguard Worker
190*0a9764feSAndroid Build Coastguard Worker layer_data_.pi.transform = static_cast<LayerTransform>(l_transform);
191*0a9764feSAndroid Build Coastguard Worker return HWC2::Error::None;
192*0a9764feSAndroid Build Coastguard Worker }
193*0a9764feSAndroid Build Coastguard Worker
194*0a9764feSAndroid Build Coastguard Worker // NOLINTNEXTLINE(readability-convert-member-functions-to-static)
SetLayerVisibleRegion(hwc_region_t)195*0a9764feSAndroid Build Coastguard Worker HWC2::Error HwcLayer::SetLayerVisibleRegion(hwc_region_t /*visible*/) {
196*0a9764feSAndroid Build Coastguard Worker // TODO(nobody): We don't use this information, marking as unsupported
197*0a9764feSAndroid Build Coastguard Worker return HWC2::Error::None;
198*0a9764feSAndroid Build Coastguard Worker }
199*0a9764feSAndroid Build Coastguard Worker
SetLayerZOrder(uint32_t order)200*0a9764feSAndroid Build Coastguard Worker HWC2::Error HwcLayer::SetLayerZOrder(uint32_t order) {
201*0a9764feSAndroid Build Coastguard Worker z_order_ = order;
202*0a9764feSAndroid Build Coastguard Worker return HWC2::Error::None;
203*0a9764feSAndroid Build Coastguard Worker }
204*0a9764feSAndroid Build Coastguard Worker
ImportFb()205*0a9764feSAndroid Build Coastguard Worker void HwcLayer::ImportFb() {
206*0a9764feSAndroid Build Coastguard Worker if (!IsLayerUsableAsDevice() || !buffer_handle_updated_) {
207*0a9764feSAndroid Build Coastguard Worker return;
208*0a9764feSAndroid Build Coastguard Worker }
209*0a9764feSAndroid Build Coastguard Worker buffer_handle_updated_ = false;
210*0a9764feSAndroid Build Coastguard Worker
211*0a9764feSAndroid Build Coastguard Worker layer_data_.fb = {};
212*0a9764feSAndroid Build Coastguard Worker
213*0a9764feSAndroid Build Coastguard Worker auto unique_id = BufferInfoGetter::GetInstance()->GetUniqueId(buffer_handle_);
214*0a9764feSAndroid Build Coastguard Worker if (unique_id && SwChainGetBufferFromCache(*unique_id)) {
215*0a9764feSAndroid Build Coastguard Worker return;
216*0a9764feSAndroid Build Coastguard Worker }
217*0a9764feSAndroid Build Coastguard Worker
218*0a9764feSAndroid Build Coastguard Worker layer_data_.bi = BufferInfoGetter::GetInstance()->GetBoInfo(buffer_handle_);
219*0a9764feSAndroid Build Coastguard Worker if (!layer_data_.bi) {
220*0a9764feSAndroid Build Coastguard Worker ALOGW("Unable to get buffer information (0x%p)", buffer_handle_);
221*0a9764feSAndroid Build Coastguard Worker bi_get_failed_ = true;
222*0a9764feSAndroid Build Coastguard Worker return;
223*0a9764feSAndroid Build Coastguard Worker }
224*0a9764feSAndroid Build Coastguard Worker
225*0a9764feSAndroid Build Coastguard Worker layer_data_
226*0a9764feSAndroid Build Coastguard Worker .fb = parent_->GetPipe().device->GetDrmFbImporter().GetOrCreateFbId(
227*0a9764feSAndroid Build Coastguard Worker &layer_data_.bi.value());
228*0a9764feSAndroid Build Coastguard Worker
229*0a9764feSAndroid Build Coastguard Worker if (!layer_data_.fb) {
230*0a9764feSAndroid Build Coastguard Worker ALOGV("Unable to create framebuffer object for buffer 0x%p",
231*0a9764feSAndroid Build Coastguard Worker buffer_handle_);
232*0a9764feSAndroid Build Coastguard Worker fb_import_failed_ = true;
233*0a9764feSAndroid Build Coastguard Worker return;
234*0a9764feSAndroid Build Coastguard Worker }
235*0a9764feSAndroid Build Coastguard Worker
236*0a9764feSAndroid Build Coastguard Worker if (unique_id) {
237*0a9764feSAndroid Build Coastguard Worker SwChainAddCurrentBuffer(*unique_id);
238*0a9764feSAndroid Build Coastguard Worker }
239*0a9764feSAndroid Build Coastguard Worker }
240*0a9764feSAndroid Build Coastguard Worker
PopulateLayerData()241*0a9764feSAndroid Build Coastguard Worker void HwcLayer::PopulateLayerData() {
242*0a9764feSAndroid Build Coastguard Worker ImportFb();
243*0a9764feSAndroid Build Coastguard Worker
244*0a9764feSAndroid Build Coastguard Worker if (!layer_data_.bi) {
245*0a9764feSAndroid Build Coastguard Worker ALOGE("%s: Invalid state", __func__);
246*0a9764feSAndroid Build Coastguard Worker return;
247*0a9764feSAndroid Build Coastguard Worker }
248*0a9764feSAndroid Build Coastguard Worker
249*0a9764feSAndroid Build Coastguard Worker if (blend_mode_ != BufferBlendMode::kUndefined) {
250*0a9764feSAndroid Build Coastguard Worker layer_data_.bi->blend_mode = blend_mode_;
251*0a9764feSAndroid Build Coastguard Worker }
252*0a9764feSAndroid Build Coastguard Worker if (color_space_ != BufferColorSpace::kUndefined) {
253*0a9764feSAndroid Build Coastguard Worker layer_data_.bi->color_space = color_space_;
254*0a9764feSAndroid Build Coastguard Worker }
255*0a9764feSAndroid Build Coastguard Worker if (sample_range_ != BufferSampleRange::kUndefined) {
256*0a9764feSAndroid Build Coastguard Worker layer_data_.bi->sample_range = sample_range_;
257*0a9764feSAndroid Build Coastguard Worker }
258*0a9764feSAndroid Build Coastguard Worker }
259*0a9764feSAndroid Build Coastguard Worker
260*0a9764feSAndroid Build Coastguard Worker /* SwapChain Cache */
261*0a9764feSAndroid Build Coastguard Worker
SwChainGetBufferFromCache(BufferUniqueId unique_id)262*0a9764feSAndroid Build Coastguard Worker bool HwcLayer::SwChainGetBufferFromCache(BufferUniqueId unique_id) {
263*0a9764feSAndroid Build Coastguard Worker if (swchain_lookup_table_.count(unique_id) == 0) {
264*0a9764feSAndroid Build Coastguard Worker return false;
265*0a9764feSAndroid Build Coastguard Worker }
266*0a9764feSAndroid Build Coastguard Worker
267*0a9764feSAndroid Build Coastguard Worker auto seq = swchain_lookup_table_[unique_id];
268*0a9764feSAndroid Build Coastguard Worker
269*0a9764feSAndroid Build Coastguard Worker if (swchain_cache_.count(seq) == 0) {
270*0a9764feSAndroid Build Coastguard Worker return false;
271*0a9764feSAndroid Build Coastguard Worker }
272*0a9764feSAndroid Build Coastguard Worker
273*0a9764feSAndroid Build Coastguard Worker auto& el = swchain_cache_[seq];
274*0a9764feSAndroid Build Coastguard Worker if (!el.bi) {
275*0a9764feSAndroid Build Coastguard Worker return false;
276*0a9764feSAndroid Build Coastguard Worker }
277*0a9764feSAndroid Build Coastguard Worker
278*0a9764feSAndroid Build Coastguard Worker layer_data_.bi = el.bi;
279*0a9764feSAndroid Build Coastguard Worker layer_data_.fb = el.fb;
280*0a9764feSAndroid Build Coastguard Worker
281*0a9764feSAndroid Build Coastguard Worker return true;
282*0a9764feSAndroid Build Coastguard Worker }
283*0a9764feSAndroid Build Coastguard Worker
SwChainReassemble(BufferUniqueId unique_id)284*0a9764feSAndroid Build Coastguard Worker void HwcLayer::SwChainReassemble(BufferUniqueId unique_id) {
285*0a9764feSAndroid Build Coastguard Worker if (swchain_lookup_table_.count(unique_id) != 0) {
286*0a9764feSAndroid Build Coastguard Worker if (swchain_lookup_table_[unique_id] ==
287*0a9764feSAndroid Build Coastguard Worker int(swchain_lookup_table_.size()) - 1) {
288*0a9764feSAndroid Build Coastguard Worker /* Skip same buffer */
289*0a9764feSAndroid Build Coastguard Worker return;
290*0a9764feSAndroid Build Coastguard Worker }
291*0a9764feSAndroid Build Coastguard Worker if (swchain_lookup_table_[unique_id] == 0) {
292*0a9764feSAndroid Build Coastguard Worker swchain_reassembled_ = true;
293*0a9764feSAndroid Build Coastguard Worker return;
294*0a9764feSAndroid Build Coastguard Worker }
295*0a9764feSAndroid Build Coastguard Worker /* Tracking error */
296*0a9764feSAndroid Build Coastguard Worker SwChainClearCache();
297*0a9764feSAndroid Build Coastguard Worker return;
298*0a9764feSAndroid Build Coastguard Worker }
299*0a9764feSAndroid Build Coastguard Worker
300*0a9764feSAndroid Build Coastguard Worker swchain_lookup_table_[unique_id] = int(swchain_lookup_table_.size());
301*0a9764feSAndroid Build Coastguard Worker }
302*0a9764feSAndroid Build Coastguard Worker
SwChainAddCurrentBuffer(BufferUniqueId unique_id)303*0a9764feSAndroid Build Coastguard Worker void HwcLayer::SwChainAddCurrentBuffer(BufferUniqueId unique_id) {
304*0a9764feSAndroid Build Coastguard Worker if (!swchain_reassembled_) {
305*0a9764feSAndroid Build Coastguard Worker SwChainReassemble(unique_id);
306*0a9764feSAndroid Build Coastguard Worker }
307*0a9764feSAndroid Build Coastguard Worker
308*0a9764feSAndroid Build Coastguard Worker if (swchain_reassembled_) {
309*0a9764feSAndroid Build Coastguard Worker if (swchain_lookup_table_.count(unique_id) == 0) {
310*0a9764feSAndroid Build Coastguard Worker SwChainClearCache();
311*0a9764feSAndroid Build Coastguard Worker return;
312*0a9764feSAndroid Build Coastguard Worker }
313*0a9764feSAndroid Build Coastguard Worker
314*0a9764feSAndroid Build Coastguard Worker auto seq = swchain_lookup_table_[unique_id];
315*0a9764feSAndroid Build Coastguard Worker
316*0a9764feSAndroid Build Coastguard Worker if (swchain_cache_.count(seq) == 0) {
317*0a9764feSAndroid Build Coastguard Worker swchain_cache_[seq] = {};
318*0a9764feSAndroid Build Coastguard Worker }
319*0a9764feSAndroid Build Coastguard Worker
320*0a9764feSAndroid Build Coastguard Worker swchain_cache_[seq].bi = layer_data_.bi;
321*0a9764feSAndroid Build Coastguard Worker swchain_cache_[seq].fb = layer_data_.fb;
322*0a9764feSAndroid Build Coastguard Worker }
323*0a9764feSAndroid Build Coastguard Worker }
324*0a9764feSAndroid Build Coastguard Worker
SwChainClearCache()325*0a9764feSAndroid Build Coastguard Worker void HwcLayer::SwChainClearCache() {
326*0a9764feSAndroid Build Coastguard Worker swchain_cache_.clear();
327*0a9764feSAndroid Build Coastguard Worker swchain_lookup_table_.clear();
328*0a9764feSAndroid Build Coastguard Worker swchain_reassembled_ = false;
329*0a9764feSAndroid Build Coastguard Worker }
330*0a9764feSAndroid Build Coastguard Worker
331*0a9764feSAndroid Build Coastguard Worker } // namespace android