1 /*
2 * Copyright (c) 2014-2020, The Linux Foundation. All rights reserved.
3 * Not a Contribution.
4 *
5 * Copyright 2015 The Android Open Source Project
6 *
7 * Licensed under the Apache License, Version 2.0 (the "License");
8 * you may not use this file except in compliance with the License.
9 * You may obtain a copy of the License at
10 *
11 * http://www.apache.org/licenses/LICENSE-2.0
12 *
13 * Unless required by applicable law or agreed to in writing, software
14 * distributed under the License is distributed on an "AS IS" BASIS,
15 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 * See the License for the specific language governing permissions and
17 * limitations under the License.
18 */
19
20 #include "hwc_layers.h"
21 #include <utils/debug.h>
22 #include <stdint.h>
23 #include <utility>
24 #include <cmath>
25 #include <qdMetaData.h>
26
27 #define __CLASS__ "HWCLayer"
28
29 namespace sdm {
30
31 std::atomic<hwc2_layer_t> HWCLayer::next_id_(1);
32
SetCSC(const private_handle_t * pvt_handle,ColorMetaData * color_metadata)33 DisplayError SetCSC(const private_handle_t *pvt_handle, ColorMetaData *color_metadata) {
34 if (getMetaData(const_cast<private_handle_t *>(pvt_handle), GET_COLOR_METADATA,
35 color_metadata) != 0) {
36 ColorSpace_t csc = ITU_R_601;
37 if (getMetaData(const_cast<private_handle_t *>(pvt_handle), GET_COLOR_SPACE,
38 &csc) == 0) {
39 if (csc == ITU_R_601_FR || csc == ITU_R_2020_FR) {
40 color_metadata->range = Range_Full;
41 }
42 color_metadata->transfer = Transfer_sRGB;
43
44 switch (csc) {
45 case ITU_R_601:
46 case ITU_R_601_FR:
47 // video and display driver uses 601_525
48 color_metadata->colorPrimaries = ColorPrimaries_BT601_6_525;
49 break;
50 case ITU_R_709:
51 color_metadata->colorPrimaries = ColorPrimaries_BT709_5;
52 break;
53 case ITU_R_2020:
54 case ITU_R_2020_FR:
55 color_metadata->colorPrimaries = ColorPrimaries_BT2020;
56 break;
57 default:
58 DLOGE("Unsupported CSC: %d", csc);
59 return kErrorNotSupported;
60 }
61 }
62 }
63
64 return kErrorNone;
65 }
66
67 // Returns true when color primary is supported
GetColorPrimary(const int32_t & dataspace,ColorPrimaries * color_primary)68 bool GetColorPrimary(const int32_t &dataspace, ColorPrimaries *color_primary) {
69 auto standard = dataspace & HAL_DATASPACE_STANDARD_MASK;
70 bool supported_csc = true;
71 switch (standard) {
72 case HAL_DATASPACE_STANDARD_BT709:
73 *color_primary = ColorPrimaries_BT709_5;
74 break;
75 case HAL_DATASPACE_STANDARD_BT601_525:
76 case HAL_DATASPACE_STANDARD_BT601_525_UNADJUSTED:
77 *color_primary = ColorPrimaries_BT601_6_525;
78 break;
79 case HAL_DATASPACE_STANDARD_BT601_625:
80 case HAL_DATASPACE_STANDARD_BT601_625_UNADJUSTED:
81 *color_primary = ColorPrimaries_BT601_6_625;
82 break;
83 case HAL_DATASPACE_STANDARD_DCI_P3:
84 *color_primary = ColorPrimaries_DCIP3;
85 break;
86 case HAL_DATASPACE_STANDARD_BT2020:
87 *color_primary = ColorPrimaries_BT2020;
88 break;
89 default:
90 DLOGW_IF(kTagClient, "Unsupported Standard Request = %d", standard);
91 supported_csc = false;
92 }
93 return supported_csc;
94 }
95
GetTransfer(const int32_t & dataspace,GammaTransfer * gamma_transfer)96 bool GetTransfer(const int32_t &dataspace, GammaTransfer *gamma_transfer) {
97 auto transfer = dataspace & HAL_DATASPACE_TRANSFER_MASK;
98 bool supported_transfer = true;
99 switch (transfer) {
100 case HAL_DATASPACE_TRANSFER_SRGB:
101 *gamma_transfer = Transfer_sRGB;
102 break;
103 case HAL_DATASPACE_TRANSFER_SMPTE_170M:
104 *gamma_transfer = Transfer_SMPTE_170M;
105 break;
106 case HAL_DATASPACE_TRANSFER_ST2084:
107 *gamma_transfer = Transfer_SMPTE_ST2084;
108 break;
109 case HAL_DATASPACE_TRANSFER_HLG:
110 *gamma_transfer = Transfer_HLG;
111 break;
112 case HAL_DATASPACE_TRANSFER_LINEAR:
113 *gamma_transfer = Transfer_Linear;
114 break;
115 case HAL_DATASPACE_TRANSFER_GAMMA2_2:
116 *gamma_transfer = Transfer_Gamma2_2;
117 break;
118 case HAL_DATASPACE_TRANSFER_GAMMA2_8:
119 *gamma_transfer = Transfer_Gamma2_8;
120 break;
121 default:
122 DLOGW_IF(kTagClient, "Unsupported Transfer Request = %d", transfer);
123 supported_transfer = false;
124 }
125 return supported_transfer;
126 }
127
GetRange(const int32_t & dataspace,ColorRange * color_range)128 bool GetRange(const int32_t &dataspace, ColorRange *color_range) {
129 auto range = dataspace & HAL_DATASPACE_RANGE_MASK;
130 switch (range) {
131 case HAL_DATASPACE_RANGE_FULL:
132 *color_range = Range_Full;
133 break;
134 case HAL_DATASPACE_RANGE_LIMITED:
135 *color_range = Range_Limited;
136 break;
137 case HAL_DATASPACE_RANGE_EXTENDED:
138 *color_range = Range_Extended;
139 return false;
140 default:
141 DLOGW_IF(kTagClient, "Unsupported Range Request = %d", range);
142 return false;
143 }
144 return true;
145 }
146
IsBT2020(const ColorPrimaries & color_primary)147 bool IsBT2020(const ColorPrimaries &color_primary) {
148 switch (color_primary) {
149 case ColorPrimaries_BT2020:
150 return true;
151 break;
152 default:
153 return false;
154 }
155 }
156
TranslateFromLegacyDataspace(const int32_t & legacy_ds)157 int32_t TranslateFromLegacyDataspace(const int32_t &legacy_ds) {
158 int32_t dataspace = legacy_ds;
159
160 if (dataspace & 0xffff) {
161 switch (dataspace & 0xffff) {
162 case HAL_DATASPACE_SRGB:
163 dataspace = HAL_DATASPACE_V0_SRGB;
164 break;
165 case HAL_DATASPACE_JFIF:
166 dataspace = HAL_DATASPACE_V0_JFIF;
167 break;
168 case HAL_DATASPACE_SRGB_LINEAR:
169 dataspace = HAL_DATASPACE_V0_SRGB_LINEAR;
170 break;
171 case HAL_DATASPACE_BT601_625:
172 dataspace = HAL_DATASPACE_V0_BT601_625;
173 break;
174 case HAL_DATASPACE_BT601_525:
175 dataspace = HAL_DATASPACE_V0_BT601_525;
176 break;
177 case HAL_DATASPACE_BT709:
178 dataspace = HAL_DATASPACE_V0_BT709;
179 break;
180 default:
181 // unknown legacy dataspace
182 DLOGW_IF(kTagClient, "Unsupported dataspace type %d", dataspace);
183 }
184 }
185
186 if (dataspace == HAL_DATASPACE_UNKNOWN) {
187 dataspace = HAL_DATASPACE_V0_SRGB;
188 }
189
190 return dataspace;
191 }
192
193 // Retrieve ColorMetaData from android_data_space_t (STANDARD|TRANSFER|RANGE)
GetSDMColorSpace(const int32_t & dataspace,ColorMetaData * color_metadata)194 bool GetSDMColorSpace(const int32_t &dataspace, ColorMetaData *color_metadata) {
195 bool valid = false;
196 valid = GetColorPrimary(dataspace, &(color_metadata->colorPrimaries));
197 if (valid) {
198 valid = GetTransfer(dataspace, &(color_metadata->transfer));
199 }
200 if (valid) {
201 valid = GetRange(dataspace, &(color_metadata->range));
202 }
203
204 return valid;
205 }
206
207 // Layer operations
HWCLayer(hwc2_display_t display_id,HWCBufferAllocator * buf_allocator)208 HWCLayer::HWCLayer(hwc2_display_t display_id, HWCBufferAllocator *buf_allocator)
209 : id_(next_id_++), display_id_(display_id), buffer_allocator_(buf_allocator) {
210 layer_ = new Layer();
211 // Fences are deferred, so the first time this layer is presented, return -1
212 // TODO(user): Verify that fences are properly obtained on suspend/resume
213 release_fences_.push_back(-1);
214 }
215
~HWCLayer()216 HWCLayer::~HWCLayer() {
217 // Close any fences left for this layer
218 while (!release_fences_.empty()) {
219 ::close(release_fences_.front());
220 release_fences_.pop_front();
221 }
222 if (layer_) {
223 if (layer_->input_buffer.acquire_fence_fd >= 0) {
224 ::close(layer_->input_buffer.acquire_fence_fd);
225 }
226 if (buffer_fd_ >= 0) {
227 ::close(buffer_fd_);
228 }
229 delete layer_;
230 }
231 }
232
SetLayerBuffer(buffer_handle_t buffer,int32_t acquire_fence)233 HWC2::Error HWCLayer::SetLayerBuffer(buffer_handle_t buffer, int32_t acquire_fence) {
234 if (!buffer) {
235 if (client_requested_ == HWC2::Composition::Device ||
236 client_requested_ == HWC2::Composition::Cursor) {
237 DLOGE("Invalid buffer handle: %p on layer: %d client requested comp type %d", buffer, id_,
238 client_requested_);
239 ::close(acquire_fence);
240 return HWC2::Error::BadParameter;
241 } else {
242 return HWC2::Error::None;
243 }
244 }
245
246 if (acquire_fence == 0) {
247 DLOGW("acquire_fence is zero");
248 return HWC2::Error::BadParameter;
249 }
250
251 const private_handle_t *handle = static_cast<const private_handle_t *>(buffer);
252
253 if (handle->fd < 0) {
254 return HWC2::Error::BadParameter;
255 }
256
257 LayerBuffer *layer_buffer = &layer_->input_buffer;
258 int aligned_width, aligned_height;
259 buffer_allocator_->GetCustomWidthAndHeight(handle, &aligned_width, &aligned_height);
260
261 LayerBufferFormat format = GetSDMFormat(handle->format, handle->flags);
262 if ((format != layer_buffer->format) || (UINT32(aligned_width) != layer_buffer->width) ||
263 (UINT32(aligned_height) != layer_buffer->height)) {
264 // Layer buffer geometry has changed.
265 geometry_changes_ |= kBufferGeometry;
266 }
267
268 layer_buffer->format = format;
269 layer_buffer->width = UINT32(aligned_width);
270 layer_buffer->height = UINT32(aligned_height);
271 layer_buffer->unaligned_width = UINT32(handle->unaligned_width);
272 layer_buffer->unaligned_height = UINT32(handle->unaligned_height);
273
274 layer_buffer->flags.video = (handle->buffer_type == BUFFER_TYPE_VIDEO) ? true : false;
275 if (SetMetaData(const_cast<private_handle_t *>(handle), layer_) != kErrorNone) {
276 return HWC2::Error::BadLayer;
277 }
278
279 // TZ Protected Buffer - L1
280 bool secure = (handle->flags & private_handle_t::PRIV_FLAGS_SECURE_BUFFER);
281 bool secure_camera = secure && (handle->flags & private_handle_t::PRIV_FLAGS_CAMERA_WRITE);
282 bool secure_display = (handle->flags & private_handle_t::PRIV_FLAGS_SECURE_DISPLAY);
283 if (secure != layer_buffer->flags.secure || secure_camera != layer_buffer->flags.secure_camera ||
284 secure_display != layer_buffer->flags.secure_display) {
285 // Secure attribute of layer buffer has changed.
286 layer_->update_mask.set(kSecurity);
287 }
288
289 layer_buffer->flags.secure = secure;
290 layer_buffer->flags.secure_camera = secure_camera;
291 layer_buffer->flags.secure_display = secure_display;
292
293 if (layer_buffer->acquire_fence_fd >= 0) {
294 ::close(layer_buffer->acquire_fence_fd);
295 }
296 layer_buffer->acquire_fence_fd = acquire_fence;
297 if (buffer_fd_ >= 0) {
298 ::close(buffer_fd_);
299 }
300 buffer_fd_ = ::dup(handle->fd);
301 layer_buffer->planes[0].fd = buffer_fd_;
302 layer_buffer->planes[0].offset = handle->offset;
303 layer_buffer->planes[0].stride = UINT32(handle->width);
304 layer_buffer->size = handle->size;
305 buffer_flipped_ = reinterpret_cast<uint64_t>(handle) != layer_buffer->buffer_id;
306 layer_buffer->buffer_id = reinterpret_cast<uint64_t>(handle);
307 layer_buffer->handle_id = handle->id;
308
309 return HWC2::Error::None;
310 }
311
SetLayerSurfaceDamage(hwc_region_t damage)312 HWC2::Error HWCLayer::SetLayerSurfaceDamage(hwc_region_t damage) {
313 surface_updated_ = true;
314 if ((damage.numRects == 1) && (damage.rects[0].bottom == 0) && (damage.rects[0].right == 0)) {
315 surface_updated_ = false;
316 }
317
318 if (!layer_->flags.updating && surface_updated_) {
319 layer_->update_mask.set(kSurfaceInvalidate);
320 }
321
322 if (!partial_update_enabled_) {
323 SetDirtyRegions(damage);
324 return HWC2::Error::None;
325 }
326
327 // Check if there is an update in SurfaceDamage rects.
328 if (layer_->dirty_regions.size() != damage.numRects) {
329 layer_->update_mask.set(kSurfaceInvalidate);
330 } else {
331 for (uint32_t j = 0; j < damage.numRects; j++) {
332 LayerRect damage_rect;
333 SetRect(damage.rects[j], &damage_rect);
334 if (damage_rect != layer_->dirty_regions.at(j)) {
335 layer_->update_mask.set(kSurfaceDamage);
336 break;
337 }
338 }
339 }
340
341 SetDirtyRegions(damage);
342 return HWC2::Error::None;
343 }
344
SetLayerBlendMode(HWC2::BlendMode mode)345 HWC2::Error HWCLayer::SetLayerBlendMode(HWC2::BlendMode mode) {
346 LayerBlending blending = kBlendingPremultiplied;
347 switch (mode) {
348 case HWC2::BlendMode::Coverage:
349 blending = kBlendingCoverage;
350 break;
351 case HWC2::BlendMode::Premultiplied:
352 blending = kBlendingPremultiplied;
353 break;
354 case HWC2::BlendMode::None:
355 blending = kBlendingOpaque;
356 break;
357 default:
358 return HWC2::Error::BadParameter;
359 }
360
361 if (layer_->blending != blending) {
362 geometry_changes_ |= kBlendMode;
363 layer_->blending = blending;
364 }
365 return HWC2::Error::None;
366 }
367
SetLayerColor(hwc_color_t color)368 HWC2::Error HWCLayer::SetLayerColor(hwc_color_t color) {
369 if (client_requested_ != HWC2::Composition::SolidColor) {
370 return HWC2::Error::None;
371 }
372 if (layer_->solid_fill_color != GetUint32Color(color)) {
373 layer_->solid_fill_color = GetUint32Color(color);
374 layer_->update_mask.set(kSurfaceInvalidate);
375 surface_updated_ = true;
376 } else {
377 surface_updated_ = false;
378 }
379
380 layer_->input_buffer.format = kFormatARGB8888;
381 DLOGV_IF(kTagClient, "[%" PRIu64 "][%" PRIu64 "] Layer color set to %x", display_id_, id_,
382 layer_->solid_fill_color);
383 return HWC2::Error::None;
384 }
385
SetLayerCompositionType(HWC2::Composition type)386 HWC2::Error HWCLayer::SetLayerCompositionType(HWC2::Composition type) {
387 // Validation is required when the client changes the composition type
388 if (client_requested_ != type) {
389 layer_->update_mask.set(kClientCompRequest);
390 }
391 client_requested_ = type;
392 client_requested_orig_ = type;
393 switch (type) {
394 case HWC2::Composition::Client:
395 break;
396 case HWC2::Composition::Device:
397 // We try and default to this in SDM
398 break;
399 case HWC2::Composition::SolidColor:
400 break;
401 case HWC2::Composition::Cursor:
402 break;
403 case HWC2::Composition::Invalid:
404 return HWC2::Error::BadParameter;
405 default:
406 return HWC2::Error::Unsupported;
407 }
408
409 return HWC2::Error::None;
410 }
411
SetLayerDataspace(int32_t dataspace)412 HWC2::Error HWCLayer::SetLayerDataspace(int32_t dataspace) {
413 // Map deprecated dataspace values to appropriate new enums
414 dataspace = TranslateFromLegacyDataspace(dataspace);
415
416 // cache the dataspace, to be used later to update SDM ColorMetaData
417 if (dataspace_ != dataspace) {
418 geometry_changes_ |= kDataspace;
419 dataspace_ = dataspace;
420 if (layer_->input_buffer.buffer_id) {
421 ValidateAndSetCSC(reinterpret_cast<private_handle_t *>(layer_->input_buffer.buffer_id));
422 }
423 }
424 return HWC2::Error::None;
425 }
426
SetLayerDisplayFrame(hwc_rect_t frame)427 HWC2::Error HWCLayer::SetLayerDisplayFrame(hwc_rect_t frame) {
428 LayerRect dst_rect = {};
429
430 SetRect(frame, &dst_rect);
431 if (dst_rect_ != dst_rect) {
432 geometry_changes_ |= kDisplayFrame;
433 dst_rect_ = dst_rect;
434 }
435
436 return HWC2::Error::None;
437 }
438
ResetPerFrameData()439 void HWCLayer::ResetPerFrameData() {
440 layer_->dst_rect = dst_rect_;
441 layer_->transform = layer_transform_;
442 }
443
SetCursorPosition(int32_t x,int32_t y)444 HWC2::Error HWCLayer::SetCursorPosition(int32_t x, int32_t y) {
445 hwc_rect_t frame = {};
446 frame.left = x;
447 frame.top = y;
448 frame.right = x + INT(layer_->dst_rect.right - layer_->dst_rect.left);
449 frame.bottom = y + INT(layer_->dst_rect.bottom - layer_->dst_rect.top);
450 SetLayerDisplayFrame(frame);
451
452 return HWC2::Error::None;
453 }
454
SetLayerPlaneAlpha(float alpha)455 HWC2::Error HWCLayer::SetLayerPlaneAlpha(float alpha) {
456 if (alpha < 0.0f || alpha > 1.0f) {
457 return HWC2::Error::BadParameter;
458 }
459
460 // Conversion of float alpha in range 0.0 to 1.0 similar to the HWC Adapter
461 uint8_t plane_alpha = static_cast<uint8_t>(std::round(255.0f * alpha));
462
463 if (layer_->plane_alpha != plane_alpha) {
464 geometry_changes_ |= kPlaneAlpha;
465 layer_->plane_alpha = plane_alpha;
466 }
467
468 return HWC2::Error::None;
469 }
470
SetLayerSourceCrop(hwc_frect_t crop)471 HWC2::Error HWCLayer::SetLayerSourceCrop(hwc_frect_t crop) {
472 LayerRect src_rect = {};
473 SetRect(crop, &src_rect);
474 non_integral_source_crop_ = ((crop.left != roundf(crop.left)) ||
475 (crop.top != roundf(crop.top)) ||
476 (crop.right != roundf(crop.right)) ||
477 (crop.bottom != roundf(crop.bottom)));
478 if (non_integral_source_crop_) {
479 DLOGV_IF(kTagClient, "Crop: LTRB %f %f %f %f", crop.left, crop.top, crop.right, crop.bottom);
480 }
481 if (layer_->src_rect != src_rect) {
482 geometry_changes_ |= kSourceCrop;
483 layer_->src_rect = src_rect;
484 }
485
486 return HWC2::Error::None;
487 }
488
SetLayerTransform(HWC2::Transform transform)489 HWC2::Error HWCLayer::SetLayerTransform(HWC2::Transform transform) {
490 LayerTransform layer_transform = {};
491 switch (transform) {
492 case HWC2::Transform::FlipH:
493 layer_transform.flip_horizontal = true;
494 break;
495 case HWC2::Transform::FlipV:
496 layer_transform.flip_vertical = true;
497 break;
498 case HWC2::Transform::Rotate90:
499 layer_transform.rotation = 90.0f;
500 break;
501 case HWC2::Transform::Rotate180:
502 layer_transform.flip_horizontal = true;
503 layer_transform.flip_vertical = true;
504 break;
505 case HWC2::Transform::Rotate270:
506 layer_transform.rotation = 90.0f;
507 layer_transform.flip_horizontal = true;
508 layer_transform.flip_vertical = true;
509 break;
510 case HWC2::Transform::FlipHRotate90:
511 layer_transform.rotation = 90.0f;
512 layer_transform.flip_horizontal = true;
513 break;
514 case HWC2::Transform::FlipVRotate90:
515 layer_transform.rotation = 90.0f;
516 layer_transform.flip_vertical = true;
517 break;
518 case HWC2::Transform::None:
519 break;
520 default:
521 // bad transform
522 return HWC2::Error::BadParameter;
523 }
524
525 if (layer_transform_ != layer_transform) {
526 geometry_changes_ |= kTransform;
527 layer_transform_ = layer_transform;
528 }
529
530 return HWC2::Error::None;
531 }
532
SetLayerVisibleRegion(hwc_region_t visible)533 HWC2::Error HWCLayer::SetLayerVisibleRegion(hwc_region_t visible) {
534 layer_->visible_regions.clear();
535 for (uint32_t i = 0; i < visible.numRects; i++) {
536 LayerRect rect;
537 SetRect(visible.rects[i], &rect);
538 layer_->visible_regions.push_back(rect);
539 }
540
541 return HWC2::Error::None;
542 }
543
SetLayerZOrder(uint32_t z)544 HWC2::Error HWCLayer::SetLayerZOrder(uint32_t z) {
545 if (z_ != z) {
546 geometry_changes_ |= kZOrder;
547 z_ = z;
548 }
549 return HWC2::Error::None;
550 }
551
SetLayerColorTransform(const float * matrix)552 HWC2::Error HWCLayer::SetLayerColorTransform(const float *matrix) {
553 color_transform_matrix_set_ =
554 (std::memcmp(matrix, kIdentityMatrix, sizeof(kIdentityMatrix)) != 0);
555 return HWC2::Error::None;
556 }
557
SetLayerPerFrameMetadata(uint32_t num_elements,const PerFrameMetadataKey * keys,const float * metadata)558 HWC2::Error HWCLayer::SetLayerPerFrameMetadata(uint32_t num_elements,
559 const PerFrameMetadataKey *keys,
560 const float *metadata) {
561 auto old_mastering_display = layer_->input_buffer.color_metadata.masteringDisplayInfo;
562 auto old_content_light = layer_->input_buffer.color_metadata.contentLightLevel;
563 auto &mastering_display = layer_->input_buffer.color_metadata.masteringDisplayInfo;
564 auto &content_light = layer_->input_buffer.color_metadata.contentLightLevel;
565 for (uint32_t i = 0; i < num_elements; i++) {
566 switch (keys[i]) {
567 case PerFrameMetadataKey::DISPLAY_RED_PRIMARY_X:
568 mastering_display.colorVolumeSEIEnabled = true;
569 mastering_display.primaries.rgbPrimaries[0][0] = UINT32(metadata[i] * 50000);
570 break;
571 case PerFrameMetadataKey::DISPLAY_RED_PRIMARY_Y:
572 mastering_display.primaries.rgbPrimaries[0][1] = UINT32(metadata[i] * 50000);
573 break;
574 case PerFrameMetadataKey::DISPLAY_GREEN_PRIMARY_X:
575 mastering_display.primaries.rgbPrimaries[1][0] = UINT32(metadata[i] * 50000);
576 break;
577 case PerFrameMetadataKey::DISPLAY_GREEN_PRIMARY_Y:
578 mastering_display.primaries.rgbPrimaries[1][1] = UINT32(metadata[i] * 50000);
579 break;
580 case PerFrameMetadataKey::DISPLAY_BLUE_PRIMARY_X:
581 mastering_display.primaries.rgbPrimaries[2][0] = UINT32(metadata[i] * 50000);
582 break;
583 case PerFrameMetadataKey::DISPLAY_BLUE_PRIMARY_Y:
584 mastering_display.primaries.rgbPrimaries[2][1] = UINT32(metadata[i] * 50000);
585 break;
586 case PerFrameMetadataKey::WHITE_POINT_X:
587 mastering_display.primaries.whitePoint[0] = UINT32(metadata[i] * 50000);
588 break;
589 case PerFrameMetadataKey::WHITE_POINT_Y:
590 mastering_display.primaries.whitePoint[1] = UINT32(metadata[i] * 50000);
591 break;
592 case PerFrameMetadataKey::MAX_LUMINANCE:
593 mastering_display.maxDisplayLuminance = UINT32(metadata[i]);
594 break;
595 case PerFrameMetadataKey::MIN_LUMINANCE:
596 mastering_display.minDisplayLuminance = UINT32(metadata[i] * 10000);
597 break;
598 case PerFrameMetadataKey::MAX_CONTENT_LIGHT_LEVEL:
599 content_light.lightLevelSEIEnabled = true;
600 content_light.maxContentLightLevel = UINT32(metadata[i]);
601 break;
602 case PerFrameMetadataKey::MAX_FRAME_AVERAGE_LIGHT_LEVEL:
603 content_light.minPicAverageLightLevel = UINT32(metadata[i]);
604 break;
605 default:
606 break;
607 }
608 }
609 if ((!SameConfig(&old_mastering_display, &mastering_display, UINT32(sizeof(MasteringDisplay)))) ||
610 (!SameConfig(&old_content_light, &content_light, UINT32(sizeof(ContentLightLevel))))) {
611 layer_->update_mask.set(kMetadataUpdate);
612 geometry_changes_ |= kDataspace;
613 }
614 return HWC2::Error::None;
615 }
616
SetLayerPerFrameMetadataBlobs(uint32_t num_elements,const PerFrameMetadataKey * keys,const uint32_t * sizes,const uint8_t * metadata)617 HWC2::Error HWCLayer::SetLayerPerFrameMetadataBlobs(uint32_t num_elements,
618 const PerFrameMetadataKey *keys,
619 const uint32_t *sizes,
620 const uint8_t* metadata) {
621 if (!keys || !sizes || !metadata) {
622 DLOGE("metadata or sizes or keys is null");
623 return HWC2::Error::BadParameter;
624 }
625
626 ColorMetaData &color_metadata = layer_->input_buffer.color_metadata;
627 for (uint32_t i = 0; i < num_elements; i++) {
628 switch (keys[i]) {
629 case PerFrameMetadataKey::HDR10_PLUS_SEI:
630 if (sizes[i] > HDR_DYNAMIC_META_DATA_SZ) {
631 DLOGE("Size of HDR10_PLUS_SEI = %d", sizes[i]);
632 return HWC2::Error::BadParameter;
633 }
634 // if dynamic metadata changes, store and set needs validate
635 if (!SameConfig(static_cast<const uint8_t*>(color_metadata.dynamicMetaDataPayload),
636 metadata, sizes[i])) {
637 geometry_changes_ |= kDataspace;
638 color_metadata.dynamicMetaDataValid = true;
639 color_metadata.dynamicMetaDataLen = sizes[i];
640 std::memcpy(color_metadata.dynamicMetaDataPayload, metadata, sizes[i]);
641 layer_->update_mask.set(kMetadataUpdate);
642 }
643 break;
644 default:
645 DLOGW("Invalid key = %d", keys[i]);
646 return HWC2::Error::BadParameter;
647 }
648 }
649 return HWC2::Error::None;
650 }
651
SetRect(const hwc_rect_t & source,LayerRect * target)652 void HWCLayer::SetRect(const hwc_rect_t &source, LayerRect *target) {
653 target->left = FLOAT(source.left);
654 target->top = FLOAT(source.top);
655 target->right = FLOAT(source.right);
656 target->bottom = FLOAT(source.bottom);
657 }
658
SetRect(const hwc_frect_t & source,LayerRect * target)659 void HWCLayer::SetRect(const hwc_frect_t &source, LayerRect *target) {
660 // Recommended way of rounding as in hwcomposer2.h - SetLayerSourceCrop
661 target->left = std::ceil(source.left);
662 target->top = std::ceil(source.top);
663 target->right = std::floor(source.right);
664 target->bottom = std::floor(source.bottom);
665 }
666
GetUint32Color(const hwc_color_t & source)667 uint32_t HWCLayer::GetUint32Color(const hwc_color_t &source) {
668 // Returns 32 bit ARGB
669 uint32_t a = UINT32(source.a) << 24;
670 uint32_t r = UINT32(source.r) << 16;
671 uint32_t g = UINT32(source.g) << 8;
672 uint32_t b = UINT32(source.b);
673 uint32_t color = a | r | g | b;
674 return color;
675 }
676
GetSDMFormat(const int32_t & source,const int flags)677 LayerBufferFormat HWCLayer::GetSDMFormat(const int32_t &source, const int flags) {
678 LayerBufferFormat format = kFormatInvalid;
679 if (flags & private_handle_t::PRIV_FLAGS_UBWC_ALIGNED) {
680 switch (source) {
681 case HAL_PIXEL_FORMAT_RGBA_8888:
682 format = kFormatRGBA8888Ubwc;
683 break;
684 case HAL_PIXEL_FORMAT_RGBX_8888:
685 format = kFormatRGBX8888Ubwc;
686 break;
687 case HAL_PIXEL_FORMAT_BGR_565:
688 format = kFormatBGR565Ubwc;
689 break;
690 case HAL_PIXEL_FORMAT_YCbCr_420_SP_VENUS:
691 case HAL_PIXEL_FORMAT_YCbCr_420_SP_VENUS_UBWC:
692 case HAL_PIXEL_FORMAT_NV12_ENCODEABLE:
693 format = kFormatYCbCr420SPVenusUbwc;
694 break;
695 case HAL_PIXEL_FORMAT_RGBA_1010102:
696 format = kFormatRGBA1010102Ubwc;
697 break;
698 case HAL_PIXEL_FORMAT_RGBX_1010102:
699 format = kFormatRGBX1010102Ubwc;
700 break;
701 case HAL_PIXEL_FORMAT_YCbCr_420_TP10_UBWC:
702 format = kFormatYCbCr420TP10Ubwc;
703 break;
704 case HAL_PIXEL_FORMAT_YCbCr_420_P010_UBWC:
705 format = kFormatYCbCr420P010Ubwc;
706 break;
707 default:
708 DLOGE("Unsupported format type for UBWC %d", source);
709 return kFormatInvalid;
710 }
711 return format;
712 }
713
714 switch (source) {
715 case HAL_PIXEL_FORMAT_RGBA_8888:
716 format = kFormatRGBA8888;
717 break;
718 case HAL_PIXEL_FORMAT_RGBA_5551:
719 format = kFormatRGBA5551;
720 break;
721 case HAL_PIXEL_FORMAT_RGBA_4444:
722 format = kFormatRGBA4444;
723 break;
724 case HAL_PIXEL_FORMAT_BGRA_8888:
725 format = kFormatBGRA8888;
726 break;
727 case HAL_PIXEL_FORMAT_RGBX_8888:
728 format = kFormatRGBX8888;
729 break;
730 case HAL_PIXEL_FORMAT_BGRX_8888:
731 format = kFormatBGRX8888;
732 break;
733 case HAL_PIXEL_FORMAT_RGB_888:
734 format = kFormatRGB888;
735 break;
736 case HAL_PIXEL_FORMAT_BGR_888:
737 format = kFormatBGR888;
738 break;
739 case HAL_PIXEL_FORMAT_RGB_565:
740 format = kFormatRGB565;
741 break;
742 case HAL_PIXEL_FORMAT_BGR_565:
743 format = kFormatBGR565;
744 break;
745 case HAL_PIXEL_FORMAT_NV12_ENCODEABLE:
746 case HAL_PIXEL_FORMAT_YCbCr_420_SP_VENUS:
747 format = kFormatYCbCr420SemiPlanarVenus;
748 break;
749 case HAL_PIXEL_FORMAT_YCrCb_420_SP_VENUS:
750 format = kFormatYCrCb420SemiPlanarVenus;
751 break;
752 case HAL_PIXEL_FORMAT_YCbCr_420_SP_VENUS_UBWC:
753 format = kFormatYCbCr420SPVenusUbwc;
754 break;
755 case HAL_PIXEL_FORMAT_YV12:
756 format = kFormatYCrCb420PlanarStride16;
757 break;
758 case HAL_PIXEL_FORMAT_YCrCb_420_SP:
759 case HAL_PIXEL_FORMAT_NV21_ZSL:
760 format = kFormatYCrCb420SemiPlanar;
761 break;
762 case HAL_PIXEL_FORMAT_YCbCr_420_SP:
763 format = kFormatYCbCr420SemiPlanar;
764 break;
765 case HAL_PIXEL_FORMAT_YCbCr_422_SP:
766 format = kFormatYCbCr422H2V1SemiPlanar;
767 break;
768 case HAL_PIXEL_FORMAT_YCbCr_422_I:
769 format = kFormatYCbCr422H2V1Packed;
770 break;
771 case HAL_PIXEL_FORMAT_CbYCrY_422_I:
772 format = kFormatCbYCrY422H2V1Packed;
773 break;
774 case HAL_PIXEL_FORMAT_RGBA_1010102:
775 format = kFormatRGBA1010102;
776 break;
777 case HAL_PIXEL_FORMAT_ARGB_2101010:
778 format = kFormatARGB2101010;
779 break;
780 case HAL_PIXEL_FORMAT_RGBX_1010102:
781 format = kFormatRGBX1010102;
782 break;
783 case HAL_PIXEL_FORMAT_XRGB_2101010:
784 format = kFormatXRGB2101010;
785 break;
786 case HAL_PIXEL_FORMAT_BGRA_1010102:
787 format = kFormatBGRA1010102;
788 break;
789 case HAL_PIXEL_FORMAT_ABGR_2101010:
790 format = kFormatABGR2101010;
791 break;
792 case HAL_PIXEL_FORMAT_BGRX_1010102:
793 format = kFormatBGRX1010102;
794 break;
795 case HAL_PIXEL_FORMAT_XBGR_2101010:
796 format = kFormatXBGR2101010;
797 break;
798 case HAL_PIXEL_FORMAT_YCbCr_420_P010:
799 format = kFormatYCbCr420P010;
800 break;
801 case HAL_PIXEL_FORMAT_YCbCr_420_TP10_UBWC:
802 format = kFormatYCbCr420TP10Ubwc;
803 break;
804 case HAL_PIXEL_FORMAT_YCbCr_420_P010_UBWC:
805 format = kFormatYCbCr420P010Ubwc;
806 break;
807 case HAL_PIXEL_FORMAT_YCbCr_420_P010_VENUS:
808 format = kFormatYCbCr420P010Venus;
809 break;
810 case HAL_PIXEL_FORMAT_RGBA_FP16:
811 format = kFormatInvalid;
812 break;
813 default:
814 DLOGW("Unsupported format type = %d", source);
815 return kFormatInvalid;
816 }
817
818 return format;
819 }
820
GetS3DFormat(uint32_t s3d_format)821 LayerBufferS3DFormat HWCLayer::GetS3DFormat(uint32_t s3d_format) {
822 LayerBufferS3DFormat sdm_s3d_format = kS3dFormatNone;
823 switch (s3d_format) {
824 case HAL_NO_3D:
825 sdm_s3d_format = kS3dFormatNone;
826 break;
827 case HAL_3D_SIDE_BY_SIDE_L_R:
828 sdm_s3d_format = kS3dFormatLeftRight;
829 break;
830 case HAL_3D_SIDE_BY_SIDE_R_L:
831 sdm_s3d_format = kS3dFormatRightLeft;
832 break;
833 case HAL_3D_TOP_BOTTOM:
834 sdm_s3d_format = kS3dFormatTopBottom;
835 break;
836 default:
837 DLOGW("Invalid S3D format %d", s3d_format);
838 }
839 return sdm_s3d_format;
840 }
841
GetUBWCStatsFromMetaData(UBWCStats * cr_stats,UbwcCrStatsVector * cr_vec)842 void HWCLayer::GetUBWCStatsFromMetaData(UBWCStats *cr_stats, UbwcCrStatsVector *cr_vec) {
843 // TODO(user): Check if we can use UBWCStats directly
844 // in layer_buffer or copy directly to Vector
845 if (cr_stats->bDataValid) {
846 switch (cr_stats->version) {
847 case UBWC_3_0:
848 case UBWC_2_0:
849 cr_vec->push_back(std::make_pair(32, cr_stats->ubwc_stats.nCRStatsTile32));
850 cr_vec->push_back(std::make_pair(64, cr_stats->ubwc_stats.nCRStatsTile64));
851 cr_vec->push_back(std::make_pair(96, cr_stats->ubwc_stats.nCRStatsTile96));
852 cr_vec->push_back(std::make_pair(128, cr_stats->ubwc_stats.nCRStatsTile128));
853 cr_vec->push_back(std::make_pair(160, cr_stats->ubwc_stats.nCRStatsTile160));
854 cr_vec->push_back(std::make_pair(192, cr_stats->ubwc_stats.nCRStatsTile192));
855 cr_vec->push_back(std::make_pair(256, cr_stats->ubwc_stats.nCRStatsTile256));
856 break;
857 default:
858 DLOGW("Invalid UBWC Version %d", cr_stats->version);
859 break;
860 } // switch(cr_stats->version)
861 } // if (cr_stats->bDatvalid)
862 }
863
SetMetaData(const private_handle_t * pvt_handle,Layer * layer)864 DisplayError HWCLayer::SetMetaData(const private_handle_t *pvt_handle, Layer *layer) {
865 LayerBuffer *layer_buffer = &layer->input_buffer;
866 private_handle_t *handle = const_cast<private_handle_t *>(pvt_handle);
867
868 float fps = 0;
869 uint32_t frame_rate = layer->frame_rate;
870 if (getMetaData(handle, GET_REFRESH_RATE, &fps) == 0) {
871 frame_rate = (fps != 0) ? RoundToStandardFPS(fps) : layer->frame_rate;
872 has_metadata_refresh_rate_ = true;
873 }
874
875 int32_t interlaced = 0;
876 getMetaData(handle, GET_PP_PARAM_INTERLACED, &interlaced);
877 bool interlace = interlaced ? true : false;
878
879 if (interlace != layer_buffer->flags.interlace) {
880 DLOGI("Layer buffer interlaced metadata has changed. old=%d, new=%d",
881 layer_buffer->flags.interlace, interlace);
882 }
883
884 uint32_t linear_format = 0;
885 if (getMetaData(handle, GET_LINEAR_FORMAT, &linear_format) == 0) {
886 layer_buffer->format = GetSDMFormat(INT32(linear_format), 0);
887 }
888
889 uint32_t s3d = 0;
890 LayerBufferS3DFormat s3d_format = layer_buffer->s3d_format;
891 if (getMetaData(handle, GET_S3D_FORMAT, &s3d) == 0) {
892 s3d_format = GetS3DFormat(s3d);
893 }
894
895 if ((interlace != layer_buffer->flags.interlace) ||
896 (frame_rate != layer->frame_rate) || (s3d_format != layer_buffer->s3d_format)) {
897 // Layer buffer metadata has changed.
898 layer->frame_rate = frame_rate;
899 layer_buffer->s3d_format = s3d_format;
900 layer_buffer->flags.interlace = interlace;
901 layer_->update_mask.set(kMetadataUpdate);
902 }
903
904 // Check if metadata is set
905 struct UBWCStats cr_stats[NUM_UBWC_CR_STATS_LAYERS] = {};
906
907 for (int i = 0; i < NUM_UBWC_CR_STATS_LAYERS; i++) {
908 layer_buffer->ubwc_crstats[i].clear();
909 }
910
911 if (getMetaData(handle, GET_UBWC_CR_STATS_INFO, cr_stats) == 0) {
912 // Only copy top layer for now as only top field for interlaced is used
913 GetUBWCStatsFromMetaData(&cr_stats[0], &(layer_buffer->ubwc_crstats[0]));
914 } // if (getMetaData)
915
916 uint32_t single_buffer = 0;
917 getMetaData(const_cast<private_handle_t *>(handle), GET_SINGLE_BUFFER_MODE, &single_buffer);
918 single_buffer_ = (single_buffer == 1);
919
920 // Handle colorMetaData / Dataspace handling now
921 ValidateAndSetCSC(handle);
922
923 return kErrorNone;
924 }
925
IsDataSpaceSupported()926 bool HWCLayer::IsDataSpaceSupported() {
927 if (client_requested_ != HWC2::Composition::Device &&
928 client_requested_ != HWC2::Composition::Cursor) {
929 // Layers marked for GPU can have any dataspace
930 return true;
931 }
932
933 return dataspace_supported_;
934 }
935
ValidateAndSetCSC(const private_handle_t * handle)936 void HWCLayer::ValidateAndSetCSC(const private_handle_t *handle) {
937 LayerBuffer *layer_buffer = &layer_->input_buffer;
938 bool use_color_metadata = true;
939 ColorMetaData csc = {};
940 if (dataspace_ != HAL_DATASPACE_UNKNOWN) {
941 use_color_metadata = false;
942 bool valid_csc = GetSDMColorSpace(dataspace_, &csc);
943 if (!valid_csc) {
944 dataspace_supported_ = false;
945 return;
946 }
947
948 if (layer_buffer->color_metadata.transfer != csc.transfer ||
949 layer_buffer->color_metadata.colorPrimaries != csc.colorPrimaries ||
950 layer_buffer->color_metadata.range != csc.range) {
951 // ColorMetadata updated. Needs validate.
952 layer_->update_mask.set(kMetadataUpdate);
953 // if we are here here, update the sdm layer csc.
954 layer_buffer->color_metadata.transfer = csc.transfer;
955 layer_buffer->color_metadata.colorPrimaries = csc.colorPrimaries;
956 layer_buffer->color_metadata.range = csc.range;
957 }
958 }
959
960 if (IsBT2020(layer_buffer->color_metadata.colorPrimaries)) {
961 // android_dataspace_t doesnt support mastering display and light levels
962 // so retrieve it from metadata for BT2020(HDR)
963 use_color_metadata = true;
964 }
965
966 if (use_color_metadata) {
967 ColorMetaData new_metadata = layer_buffer->color_metadata;
968 if (sdm::SetCSC(handle, &new_metadata) == kErrorNone) {
969 // If dataspace is KNOWN, overwrite the gralloc metadata CSC using the previously derived CSC
970 // from dataspace.
971 if (dataspace_ != HAL_DATASPACE_UNKNOWN) {
972 new_metadata.colorPrimaries = layer_buffer->color_metadata.colorPrimaries;
973 new_metadata.transfer = layer_buffer->color_metadata.transfer;
974 new_metadata.range = layer_buffer->color_metadata.range;
975 }
976 if ((layer_buffer->color_metadata.colorPrimaries != new_metadata.colorPrimaries) ||
977 (layer_buffer->color_metadata.transfer != new_metadata.transfer) ||
978 (layer_buffer->color_metadata.range != new_metadata.range)) {
979 layer_buffer->color_metadata.colorPrimaries = new_metadata.colorPrimaries;
980 layer_buffer->color_metadata.transfer = new_metadata.transfer;
981 layer_buffer->color_metadata.range = new_metadata.range;
982 layer_->update_mask.set(kMetadataUpdate);
983 }
984 if (layer_buffer->color_metadata.matrixCoefficients != new_metadata.matrixCoefficients) {
985 layer_buffer->color_metadata.matrixCoefficients = new_metadata.matrixCoefficients;
986 layer_->update_mask.set(kMetadataUpdate);
987 }
988 DLOGV_IF(kTagClient, "Layer id = %lld ColorVolEnabled = %d ContentLightLevelEnabled = %d "
989 "cRIEnabled = %d Dynamic Metadata valid = %d size = %d", id_,
990 new_metadata.masteringDisplayInfo.colorVolumeSEIEnabled,
991 new_metadata.contentLightLevel.lightLevelSEIEnabled,
992 new_metadata.cRI.criEnabled, new_metadata.dynamicMetaDataValid,
993 new_metadata.dynamicMetaDataLen);
994 // Read color metadata from gralloc handle if it's enabled by clients, this will override the
995 // values set using the Composer API's(SetLayerPerFrameMetaData)
996 if (new_metadata.masteringDisplayInfo.colorVolumeSEIEnabled &&
997 !SameConfig(&new_metadata.masteringDisplayInfo,
998 &layer_buffer->color_metadata.masteringDisplayInfo, UINT32(sizeof(MasteringDisplay)))) {
999 layer_buffer->color_metadata.masteringDisplayInfo = new_metadata.masteringDisplayInfo;
1000 layer_->update_mask.set(kMetadataUpdate);
1001 }
1002 if (new_metadata.contentLightLevel.lightLevelSEIEnabled &&
1003 !SameConfig(&new_metadata.contentLightLevel,
1004 &layer_buffer->color_metadata.contentLightLevel, UINT32(sizeof(ContentLightLevel)))) {
1005 layer_buffer->color_metadata.contentLightLevel = new_metadata.contentLightLevel;
1006 layer_->update_mask.set(kMetadataUpdate);
1007 }
1008 if (new_metadata.cRI.criEnabled &&
1009 !SameConfig(&new_metadata.cRI, &layer_buffer->color_metadata.cRI,
1010 UINT32(sizeof(ColorRemappingInfo)))) {
1011 layer_buffer->color_metadata.cRI = new_metadata.cRI;
1012 layer_->update_mask.set(kMetadataUpdate);
1013 }
1014 if (new_metadata.dynamicMetaDataValid &&
1015 !SameConfig(layer_buffer->color_metadata.dynamicMetaDataPayload,
1016 new_metadata.dynamicMetaDataPayload, HDR_DYNAMIC_META_DATA_SZ)) {
1017 layer_buffer->color_metadata.dynamicMetaDataValid = true;
1018 layer_buffer->color_metadata.dynamicMetaDataLen = new_metadata.dynamicMetaDataLen;
1019 std::memcpy(layer_buffer->color_metadata.dynamicMetaDataPayload,
1020 new_metadata.dynamicMetaDataPayload, new_metadata.dynamicMetaDataLen);
1021 layer_->update_mask.set(kMetadataUpdate);
1022 }
1023 } else {
1024 dataspace_supported_ = false;
1025 return;
1026 }
1027 }
1028
1029 dataspace_supported_ = true;
1030 }
1031
1032
RoundToStandardFPS(float fps)1033 uint32_t HWCLayer::RoundToStandardFPS(float fps) {
1034 static const uint32_t standard_fps[4] = {24, 30, 48, 60};
1035 uint32_t frame_rate = (uint32_t)(fps);
1036
1037 int count = INT(sizeof(standard_fps) / sizeof(standard_fps[0]));
1038 for (int i = 0; i < count; i++) {
1039 if ((standard_fps[i] - frame_rate) < 2) {
1040 // Most likely used for video, the fps can fluctuate
1041 // Ex: b/w 29 and 30 for 30 fps clip
1042 return standard_fps[i];
1043 }
1044 }
1045
1046 return frame_rate;
1047 }
1048
SetComposition(const LayerComposition & sdm_composition)1049 void HWCLayer::SetComposition(const LayerComposition &sdm_composition) {
1050 auto hwc_composition = HWC2::Composition::Invalid;
1051 switch (sdm_composition) {
1052 case kCompositionGPU:
1053 hwc_composition = HWC2::Composition::Client;
1054 break;
1055 case kCompositionCursor:
1056 hwc_composition = HWC2::Composition::Cursor;
1057 break;
1058 default:
1059 hwc_composition = HWC2::Composition::Device;
1060 break;
1061 }
1062 // Update solid fill composition
1063 if (sdm_composition == kCompositionSDE && layer_->flags.solid_fill != 0) {
1064 hwc_composition = HWC2::Composition::SolidColor;
1065 }
1066 device_selected_ = hwc_composition;
1067
1068 return;
1069 }
1070
PushBackReleaseFence(int32_t fence)1071 void HWCLayer::PushBackReleaseFence(int32_t fence) {
1072 release_fences_.push_back(fence);
1073 }
1074
PopBackReleaseFence()1075 int32_t HWCLayer::PopBackReleaseFence() {
1076 if (release_fences_.empty())
1077 return -1;
1078
1079 auto fence = release_fences_.back();
1080 release_fences_.pop_back();
1081
1082 return fence;
1083 }
1084
PopFrontReleaseFence()1085 int32_t HWCLayer::PopFrontReleaseFence() {
1086 if (release_fences_.empty())
1087 return -1;
1088
1089 auto fence = release_fences_.front();
1090 release_fences_.pop_front();
1091
1092 return fence;
1093 }
1094
IsRotationPresent()1095 bool HWCLayer::IsRotationPresent() {
1096 return ((layer_->transform.rotation != 0.0f) ||
1097 layer_->transform.flip_horizontal ||
1098 layer_->transform.flip_vertical);
1099 }
1100
IsScalingPresent()1101 bool HWCLayer::IsScalingPresent() {
1102 uint32_t src_width = static_cast<uint32_t>(layer_->src_rect.right - layer_->src_rect.left);
1103 uint32_t src_height = static_cast<uint32_t>(layer_->src_rect.bottom - layer_->src_rect.top);
1104 uint32_t dst_width = static_cast<uint32_t>(layer_->dst_rect.right - layer_->dst_rect.left);
1105 uint32_t dst_height = static_cast<uint32_t>(layer_->dst_rect.bottom - layer_->dst_rect.top);
1106
1107 return ((src_width != dst_width) || (dst_height != src_height));
1108 }
1109
SetDirtyRegions(hwc_region_t surface_damage)1110 void HWCLayer::SetDirtyRegions(hwc_region_t surface_damage) {
1111 layer_->dirty_regions.clear();
1112 for (uint32_t i = 0; i < surface_damage.numRects; i++) {
1113 LayerRect rect;
1114 SetRect(surface_damage.rects[i], &rect);
1115 layer_->dirty_regions.push_back(rect);
1116 }
1117 }
1118
SetLayerAsMask()1119 void HWCLayer::SetLayerAsMask() {
1120 layer_->input_buffer.flags.mask_layer = true;
1121 DLOGV_IF(kTagClient, " Layer Id: ""[%" PRIu64 "]", id_);
1122 }
1123
1124 } // namespace sdm
1125