Naseer Ahmed | b92e73f | 2016-03-12 02:03:48 -0500 | [diff] [blame] | 1 | /* |
Ramkumar Radhakrishnan | 525e643 | 2017-12-15 16:43:07 -0800 | [diff] [blame] | 2 | * Copyright (c) 2014-2018, The Linux Foundation. All rights reserved. |
Naseer Ahmed | b92e73f | 2016-03-12 02:03:48 -0500 | [diff] [blame] | 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 | |
Naseer Ahmed | e36f224 | 2017-12-01 15:33:56 -0500 | [diff] [blame] | 20 | #include "hwc_layers.h" |
| 21 | #include <utils/debug.h> |
Arun Kumar K.R | 3e45ac4 | 2017-03-08 19:00:02 -0800 | [diff] [blame] | 22 | #include <stdint.h> |
Gurunath Ramaswamy | f081afe | 2017-07-04 22:08:36 -0700 | [diff] [blame] | 23 | #include <utility> |
Naseer Ahmed | b92e73f | 2016-03-12 02:03:48 -0500 | [diff] [blame] | 24 | #include <cmath> |
Naseer Ahmed | e36f224 | 2017-12-01 15:33:56 -0500 | [diff] [blame] | 25 | #include <qdMetaData.h> |
Naseer Ahmed | b92e73f | 2016-03-12 02:03:48 -0500 | [diff] [blame] | 26 | |
| 27 | #define __CLASS__ "HWCLayer" |
| 28 | |
| 29 | namespace sdm { |
| 30 | |
Naseer Ahmed | b92e73f | 2016-03-12 02:03:48 -0500 | [diff] [blame] | 31 | std::atomic<hwc2_layer_t> HWCLayer::next_id_(1); |
| 32 | |
Arun Kumar K.R | 3e45ac4 | 2017-03-08 19:00:02 -0800 | [diff] [blame] | 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 | } |
Arun Kumar K.R | bc0addf | 2016-10-03 22:38:16 -0700 | [diff] [blame] | 42 | |
Arun Kumar K.R | 3e45ac4 | 2017-03-08 19:00:02 -0800 | [diff] [blame] | 43 | switch (csc) { |
Arun Kumar K.R | 0574622 | 2018-04-04 10:45:58 +0530 | [diff] [blame] | 44 | case ITU_R_601: |
| 45 | case ITU_R_601_FR: |
| 46 | // video and display driver uses 601_525 |
| 47 | color_metadata->colorPrimaries = ColorPrimaries_BT601_6_525; |
| 48 | break; |
| 49 | case ITU_R_709: |
| 50 | color_metadata->colorPrimaries = ColorPrimaries_BT709_5; |
| 51 | break; |
| 52 | case ITU_R_2020: |
| 53 | case ITU_R_2020_FR: |
| 54 | color_metadata->colorPrimaries = ColorPrimaries_BT2020; |
| 55 | break; |
| 56 | default: |
| 57 | DLOGE("Unsupported CSC: %d", csc); |
| 58 | return kErrorNotSupported; |
Arun Kumar K.R | 3e45ac4 | 2017-03-08 19:00:02 -0800 | [diff] [blame] | 59 | } |
Arun Kumar K.R | bc0addf | 2016-10-03 22:38:16 -0700 | [diff] [blame] | 60 | } |
| 61 | } |
| 62 | |
| 63 | return kErrorNone; |
| 64 | } |
| 65 | |
Arun Kumar K.R | 80e58eb | 2017-07-13 10:37:00 +0530 | [diff] [blame] | 66 | // Returns true when color primary is supported |
| 67 | bool GetColorPrimary(const int32_t &dataspace, ColorPrimaries *color_primary) { |
| 68 | auto standard = dataspace & HAL_DATASPACE_STANDARD_MASK; |
| 69 | bool supported_csc = true; |
| 70 | switch (standard) { |
| 71 | case HAL_DATASPACE_STANDARD_BT709: |
| 72 | *color_primary = ColorPrimaries_BT709_5; |
| 73 | break; |
| 74 | case HAL_DATASPACE_STANDARD_BT601_525: |
| 75 | case HAL_DATASPACE_STANDARD_BT601_525_UNADJUSTED: |
| 76 | *color_primary = ColorPrimaries_BT601_6_525; |
| 77 | break; |
| 78 | case HAL_DATASPACE_STANDARD_BT601_625: |
| 79 | case HAL_DATASPACE_STANDARD_BT601_625_UNADJUSTED: |
| 80 | *color_primary = ColorPrimaries_BT601_6_625; |
| 81 | break; |
| 82 | case HAL_DATASPACE_STANDARD_DCI_P3: |
| 83 | *color_primary = ColorPrimaries_DCIP3; |
| 84 | break; |
| 85 | case HAL_DATASPACE_STANDARD_BT2020: |
| 86 | *color_primary = ColorPrimaries_BT2020; |
| 87 | break; |
| 88 | default: |
Sushil Chauhan | 984d9f7 | 2018-05-10 12:35:59 -0700 | [diff] [blame] | 89 | DLOGV_IF(kTagClient, "Unsupported Standard Request = %d", standard); |
Arun Kumar K.R | 80e58eb | 2017-07-13 10:37:00 +0530 | [diff] [blame] | 90 | supported_csc = false; |
| 91 | } |
| 92 | return supported_csc; |
| 93 | } |
| 94 | |
| 95 | bool GetTransfer(const int32_t &dataspace, GammaTransfer *gamma_transfer) { |
| 96 | auto transfer = dataspace & HAL_DATASPACE_TRANSFER_MASK; |
| 97 | bool supported_transfer = true; |
| 98 | switch (transfer) { |
| 99 | case HAL_DATASPACE_TRANSFER_SRGB: |
| 100 | *gamma_transfer = Transfer_sRGB; |
| 101 | break; |
| 102 | case HAL_DATASPACE_TRANSFER_SMPTE_170M: |
| 103 | *gamma_transfer = Transfer_SMPTE_170M; |
| 104 | break; |
| 105 | case HAL_DATASPACE_TRANSFER_ST2084: |
| 106 | *gamma_transfer = Transfer_SMPTE_ST2084; |
| 107 | break; |
| 108 | case HAL_DATASPACE_TRANSFER_HLG: |
| 109 | *gamma_transfer = Transfer_HLG; |
| 110 | break; |
| 111 | case HAL_DATASPACE_TRANSFER_LINEAR: |
| 112 | *gamma_transfer = Transfer_Linear; |
| 113 | break; |
| 114 | case HAL_DATASPACE_TRANSFER_GAMMA2_2: |
| 115 | *gamma_transfer = Transfer_Gamma2_2; |
| 116 | break; |
Arun Kumar K.R | 84966b2 | 2018-04-09 15:50:36 +0530 | [diff] [blame] | 117 | case HAL_DATASPACE_TRANSFER_GAMMA2_8: |
| 118 | *gamma_transfer = Transfer_Gamma2_8; |
| 119 | break; |
Arun Kumar K.R | 80e58eb | 2017-07-13 10:37:00 +0530 | [diff] [blame] | 120 | default: |
Sushil Chauhan | 984d9f7 | 2018-05-10 12:35:59 -0700 | [diff] [blame] | 121 | DLOGV_IF(kTagClient, "Unsupported Transfer Request = %d", transfer); |
Arun Kumar K.R | 80e58eb | 2017-07-13 10:37:00 +0530 | [diff] [blame] | 122 | supported_transfer = false; |
| 123 | } |
| 124 | return supported_transfer; |
| 125 | } |
| 126 | |
Arun Kumar K.R | d761c1a | 2018-04-26 19:47:44 +0530 | [diff] [blame] | 127 | bool GetRange(const int32_t &dataspace, ColorRange *color_range) { |
Arun Kumar K.R | 80e58eb | 2017-07-13 10:37:00 +0530 | [diff] [blame] | 128 | auto range = dataspace & HAL_DATASPACE_RANGE_MASK; |
| 129 | switch (range) { |
| 130 | case HAL_DATASPACE_RANGE_FULL: |
| 131 | *color_range = Range_Full; |
| 132 | break; |
| 133 | case HAL_DATASPACE_RANGE_LIMITED: |
| 134 | *color_range = Range_Limited; |
| 135 | break; |
Arun Kumar K.R | d761c1a | 2018-04-26 19:47:44 +0530 | [diff] [blame] | 136 | case HAL_DATASPACE_RANGE_EXTENDED: |
| 137 | *color_range = Range_Extended; |
Arun Kumar K.R | 80e58eb | 2017-07-13 10:37:00 +0530 | [diff] [blame] | 138 | break; |
Arun Kumar K.R | d761c1a | 2018-04-26 19:47:44 +0530 | [diff] [blame] | 139 | default: |
Sushil Chauhan | 984d9f7 | 2018-05-10 12:35:59 -0700 | [diff] [blame] | 140 | DLOGV_IF(kTagClient, "Unsupported Range Request = %d", range); |
Arun Kumar K.R | d761c1a | 2018-04-26 19:47:44 +0530 | [diff] [blame] | 141 | return false; |
Arun Kumar K.R | 80e58eb | 2017-07-13 10:37:00 +0530 | [diff] [blame] | 142 | } |
Arun Kumar K.R | d761c1a | 2018-04-26 19:47:44 +0530 | [diff] [blame] | 143 | return true; |
Arun Kumar K.R | 80e58eb | 2017-07-13 10:37:00 +0530 | [diff] [blame] | 144 | } |
| 145 | |
| 146 | bool IsBT2020(const ColorPrimaries &color_primary) { |
| 147 | switch (color_primary) { |
| 148 | case ColorPrimaries_BT2020: |
| 149 | return true; |
| 150 | break; |
| 151 | default: |
| 152 | return false; |
| 153 | } |
| 154 | } |
| 155 | |
| 156 | // Retrieve ColorMetaData from android_data_space_t (STANDARD|TRANSFER|RANGE) |
| 157 | bool GetSDMColorSpace(const int32_t &dataspace, ColorMetaData *color_metadata) { |
| 158 | bool valid = false; |
| 159 | valid = GetColorPrimary(dataspace, &(color_metadata->colorPrimaries)); |
Arun Kumar K.R | d761c1a | 2018-04-26 19:47:44 +0530 | [diff] [blame] | 160 | if (valid) { |
| 161 | valid = GetTransfer(dataspace, &(color_metadata->transfer)); |
Arun Kumar K.R | 80e58eb | 2017-07-13 10:37:00 +0530 | [diff] [blame] | 162 | } |
Arun Kumar K.R | d761c1a | 2018-04-26 19:47:44 +0530 | [diff] [blame] | 163 | if (valid) { |
| 164 | valid = GetRange(dataspace, &(color_metadata->range)); |
Arun Kumar K.R | 80e58eb | 2017-07-13 10:37:00 +0530 | [diff] [blame] | 165 | } |
Arun Kumar K.R | 80e58eb | 2017-07-13 10:37:00 +0530 | [diff] [blame] | 166 | |
Arun Kumar K.R | d761c1a | 2018-04-26 19:47:44 +0530 | [diff] [blame] | 167 | return valid; |
Arun Kumar K.R | 80e58eb | 2017-07-13 10:37:00 +0530 | [diff] [blame] | 168 | } |
| 169 | |
Naseer Ahmed | b92e73f | 2016-03-12 02:03:48 -0500 | [diff] [blame] | 170 | // Layer operations |
Naseer Ahmed | 4275221 | 2017-01-27 17:32:21 -0500 | [diff] [blame] | 171 | HWCLayer::HWCLayer(hwc2_display_t display_id, HWCBufferAllocator *buf_allocator) |
| 172 | : id_(next_id_++), display_id_(display_id), buffer_allocator_(buf_allocator) { |
Naseer Ahmed | b92e73f | 2016-03-12 02:03:48 -0500 | [diff] [blame] | 173 | layer_ = new Layer(); |
Naseer Ahmed | b92e73f | 2016-03-12 02:03:48 -0500 | [diff] [blame] | 174 | // Fences are deferred, so the first time this layer is presented, return -1 |
| 175 | // TODO(user): Verify that fences are properly obtained on suspend/resume |
Ramkumar Radhakrishnan | 00698de | 2018-01-17 11:39:33 -0800 | [diff] [blame] | 176 | release_fences_.push_back(-1); |
Naseer Ahmed | b92e73f | 2016-03-12 02:03:48 -0500 | [diff] [blame] | 177 | } |
| 178 | |
| 179 | HWCLayer::~HWCLayer() { |
| 180 | // Close any fences left for this layer |
| 181 | while (!release_fences_.empty()) { |
Ramkumar Radhakrishnan | 525e643 | 2017-12-15 16:43:07 -0800 | [diff] [blame] | 182 | ::close(release_fences_.front()); |
Ramkumar Radhakrishnan | 00698de | 2018-01-17 11:39:33 -0800 | [diff] [blame] | 183 | release_fences_.pop_front(); |
Naseer Ahmed | b92e73f | 2016-03-12 02:03:48 -0500 | [diff] [blame] | 184 | } |
Naseer Ahmed | b92e73f | 2016-03-12 02:03:48 -0500 | [diff] [blame] | 185 | if (layer_) { |
Prabhanjan Kandula | 1651e59 | 2017-10-17 18:28:16 -0700 | [diff] [blame] | 186 | if (layer_->input_buffer.acquire_fence_fd >= 0) { |
Ramkumar Radhakrishnan | 525e643 | 2017-12-15 16:43:07 -0800 | [diff] [blame] | 187 | ::close(layer_->input_buffer.acquire_fence_fd); |
| 188 | } |
| 189 | if (buffer_fd_ >= 0) { |
| 190 | ::close(buffer_fd_); |
Prabhanjan Kandula | 1651e59 | 2017-10-17 18:28:16 -0700 | [diff] [blame] | 191 | } |
Naseer Ahmed | b92e73f | 2016-03-12 02:03:48 -0500 | [diff] [blame] | 192 | delete layer_; |
| 193 | } |
| 194 | } |
| 195 | |
| 196 | HWC2::Error HWCLayer::SetLayerBuffer(buffer_handle_t buffer, int32_t acquire_fence) { |
| 197 | if (!buffer) { |
Naseer Ahmed | 2f71fd0 | 2017-06-01 19:55:39 -0400 | [diff] [blame] | 198 | if (client_requested_ == HWC2::Composition::Device || |
| 199 | client_requested_ == HWC2::Composition::Cursor) { |
Ramkumar Radhakrishnan | b338690 | 2017-12-19 17:14:13 -0800 | [diff] [blame] | 200 | DLOGE("Invalid buffer handle: %p on layer: %d client requested comp type %d", buffer, id_, |
| 201 | client_requested_); |
| 202 | ::close(acquire_fence); |
Naseer Ahmed | 2f71fd0 | 2017-06-01 19:55:39 -0400 | [diff] [blame] | 203 | return HWC2::Error::BadParameter; |
| 204 | } else { |
| 205 | return HWC2::Error::None; |
| 206 | } |
Naseer Ahmed | b92e73f | 2016-03-12 02:03:48 -0500 | [diff] [blame] | 207 | } |
| 208 | |
Naseer Ahmed | e3f007a | 2016-06-07 18:13:28 -0400 | [diff] [blame] | 209 | if (acquire_fence == 0) { |
| 210 | DLOGE("acquire_fence is zero"); |
| 211 | return HWC2::Error::BadParameter; |
| 212 | } |
| 213 | |
Naseer Ahmed | b92e73f | 2016-03-12 02:03:48 -0500 | [diff] [blame] | 214 | const private_handle_t *handle = static_cast<const private_handle_t *>(buffer); |
Naseer Ahmed | 6fe11ed | 2016-08-26 21:15:44 -0400 | [diff] [blame] | 215 | |
Naseer Ahmed | 6fe11ed | 2016-08-26 21:15:44 -0400 | [diff] [blame] | 216 | if (handle->fd < 0) { |
| 217 | return HWC2::Error::BadParameter; |
Naseer Ahmed | 6fe11ed | 2016-08-26 21:15:44 -0400 | [diff] [blame] | 218 | } |
| 219 | |
Arun Kumar K.R | 9c19cdd | 2016-11-21 16:48:43 -0800 | [diff] [blame] | 220 | LayerBuffer *layer_buffer = &layer_->input_buffer; |
Ramkumar Radhakrishnan | b27735f | 2016-08-26 22:37:23 -0700 | [diff] [blame] | 221 | int aligned_width, aligned_height; |
Naseer Ahmed | 4275221 | 2017-01-27 17:32:21 -0500 | [diff] [blame] | 222 | buffer_allocator_->GetCustomWidthAndHeight(handle, &aligned_width, &aligned_height); |
Ramkumar Radhakrishnan | b27735f | 2016-08-26 22:37:23 -0700 | [diff] [blame] | 223 | |
Sushil Chauhan | 409e844 | 2017-06-12 17:43:25 -0700 | [diff] [blame] | 224 | LayerBufferFormat format = GetSDMFormat(handle->format, handle->flags); |
| 225 | if ((format != layer_buffer->format) || (UINT32(aligned_width) != layer_buffer->width) || |
| 226 | (UINT32(aligned_height) != layer_buffer->height)) { |
| 227 | // Layer buffer geometry has changed. |
| 228 | geometry_changes_ |= kBufferGeometry; |
| 229 | } |
| 230 | |
| 231 | layer_buffer->format = format; |
Ramkumar Radhakrishnan | b27735f | 2016-08-26 22:37:23 -0700 | [diff] [blame] | 232 | layer_buffer->width = UINT32(aligned_width); |
| 233 | layer_buffer->height = UINT32(aligned_height); |
Naseer Ahmed | 4275221 | 2017-01-27 17:32:21 -0500 | [diff] [blame] | 234 | layer_buffer->unaligned_width = UINT32(handle->unaligned_width); |
| 235 | layer_buffer->unaligned_height = UINT32(handle->unaligned_height); |
Ramkumar Radhakrishnan | b27735f | 2016-08-26 22:37:23 -0700 | [diff] [blame] | 236 | |
Arun Kumar K.R | 3e45ac4 | 2017-03-08 19:00:02 -0800 | [diff] [blame] | 237 | if (SetMetaData(const_cast<private_handle_t *>(handle), layer_) != kErrorNone) { |
Naseer Ahmed | b92e73f | 2016-03-12 02:03:48 -0500 | [diff] [blame] | 238 | return HWC2::Error::BadLayer; |
| 239 | } |
| 240 | |
Sushil Chauhan | 409e844 | 2017-06-12 17:43:25 -0700 | [diff] [blame] | 241 | layer_buffer->flags.video = (handle->buffer_type == BUFFER_TYPE_VIDEO) ? true : false; |
| 242 | |
Naseer Ahmed | b92e73f | 2016-03-12 02:03:48 -0500 | [diff] [blame] | 243 | // TZ Protected Buffer - L1 |
Sushil Chauhan | 409e844 | 2017-06-12 17:43:25 -0700 | [diff] [blame] | 244 | bool secure = (handle->flags & private_handle_t::PRIV_FLAGS_SECURE_BUFFER); |
| 245 | bool secure_camera = secure && (handle->flags & private_handle_t::PRIV_FLAGS_CAMERA_WRITE); |
| 246 | bool secure_display = (handle->flags & private_handle_t::PRIV_FLAGS_SECURE_DISPLAY); |
| 247 | if (secure != layer_buffer->flags.secure || secure_camera != layer_buffer->flags.secure_camera || |
| 248 | secure_display != layer_buffer->flags.secure_display) { |
| 249 | // Secure attribute of layer buffer has changed. |
| 250 | needs_validate_ = true; |
Naseer Ahmed | b92e73f | 2016-03-12 02:03:48 -0500 | [diff] [blame] | 251 | } |
Sushil Chauhan | 409e844 | 2017-06-12 17:43:25 -0700 | [diff] [blame] | 252 | |
| 253 | layer_buffer->flags.secure = secure; |
| 254 | layer_buffer->flags.secure_camera = secure_camera; |
| 255 | layer_buffer->flags.secure_display = secure_display; |
Naseer Ahmed | b92e73f | 2016-03-12 02:03:48 -0500 | [diff] [blame] | 256 | |
Prabhanjan Kandula | 1651e59 | 2017-10-17 18:28:16 -0700 | [diff] [blame] | 257 | if (layer_buffer->acquire_fence_fd >= 0) { |
Ramkumar Radhakrishnan | 525e643 | 2017-12-15 16:43:07 -0800 | [diff] [blame] | 258 | ::close(layer_buffer->acquire_fence_fd); |
Prabhanjan Kandula | 1651e59 | 2017-10-17 18:28:16 -0700 | [diff] [blame] | 259 | } |
| 260 | layer_buffer->acquire_fence_fd = acquire_fence; |
Ramkumar Radhakrishnan | 525e643 | 2017-12-15 16:43:07 -0800 | [diff] [blame] | 261 | if (buffer_fd_ >= 0) { |
| 262 | ::close(buffer_fd_); |
| 263 | } |
| 264 | buffer_fd_ = ::dup(handle->fd); |
| 265 | layer_buffer->planes[0].fd = buffer_fd_; |
Naseer Ahmed | b92e73f | 2016-03-12 02:03:48 -0500 | [diff] [blame] | 266 | layer_buffer->planes[0].offset = handle->offset; |
| 267 | layer_buffer->planes[0].stride = UINT32(handle->width); |
Naseer Ahmed | 18630d3 | 2016-10-26 16:14:19 -0400 | [diff] [blame] | 268 | layer_buffer->size = handle->size; |
Naseer Ahmed | b92e73f | 2016-03-12 02:03:48 -0500 | [diff] [blame] | 269 | layer_buffer->buffer_id = reinterpret_cast<uint64_t>(handle); |
| 270 | |
| 271 | return HWC2::Error::None; |
| 272 | } |
| 273 | |
| 274 | HWC2::Error HWCLayer::SetLayerSurfaceDamage(hwc_region_t damage) { |
Sushil Chauhan | 409e844 | 2017-06-12 17:43:25 -0700 | [diff] [blame] | 275 | // Check if there is an update in SurfaceDamage rects |
| 276 | if (layer_->dirty_regions.size() != damage.numRects) { |
| 277 | needs_validate_ = true; |
| 278 | } else { |
| 279 | for (uint32_t j = 0; j < damage.numRects; j++) { |
| 280 | LayerRect damage_rect; |
| 281 | SetRect(damage.rects[j], &damage_rect); |
| 282 | if (damage_rect != layer_->dirty_regions.at(j)) { |
| 283 | needs_validate_ = true; |
| 284 | break; |
| 285 | } |
| 286 | } |
| 287 | } |
| 288 | |
Arun Kumar K.R | 2c0ff8d | 2016-06-01 16:56:52 -0700 | [diff] [blame] | 289 | layer_->dirty_regions.clear(); |
Naseer Ahmed | 6786e5d | 2016-06-24 16:38:52 -0400 | [diff] [blame] | 290 | for (uint32_t i = 0; i < damage.numRects; i++) { |
| 291 | LayerRect rect; |
| 292 | SetRect(damage.rects[i], &rect); |
| 293 | layer_->dirty_regions.push_back(rect); |
Naseer Ahmed | b92e73f | 2016-03-12 02:03:48 -0500 | [diff] [blame] | 294 | } |
| 295 | return HWC2::Error::None; |
| 296 | } |
| 297 | |
| 298 | HWC2::Error HWCLayer::SetLayerBlendMode(HWC2::BlendMode mode) { |
Arun Kumar K.R | 3e89f79 | 2016-06-01 17:14:15 -0700 | [diff] [blame] | 299 | LayerBlending blending = kBlendingPremultiplied; |
Naseer Ahmed | b92e73f | 2016-03-12 02:03:48 -0500 | [diff] [blame] | 300 | switch (mode) { |
| 301 | case HWC2::BlendMode::Coverage: |
Arun Kumar K.R | 3e89f79 | 2016-06-01 17:14:15 -0700 | [diff] [blame] | 302 | blending = kBlendingCoverage; |
Naseer Ahmed | b92e73f | 2016-03-12 02:03:48 -0500 | [diff] [blame] | 303 | break; |
| 304 | case HWC2::BlendMode::Premultiplied: |
Arun Kumar K.R | 3e89f79 | 2016-06-01 17:14:15 -0700 | [diff] [blame] | 305 | blending = kBlendingPremultiplied; |
Naseer Ahmed | b92e73f | 2016-03-12 02:03:48 -0500 | [diff] [blame] | 306 | break; |
| 307 | case HWC2::BlendMode::None: |
Arun Kumar K.R | 3e89f79 | 2016-06-01 17:14:15 -0700 | [diff] [blame] | 308 | blending = kBlendingOpaque; |
Naseer Ahmed | b92e73f | 2016-03-12 02:03:48 -0500 | [diff] [blame] | 309 | break; |
| 310 | default: |
| 311 | return HWC2::Error::BadParameter; |
| 312 | } |
Arun Kumar K.R | 3e89f79 | 2016-06-01 17:14:15 -0700 | [diff] [blame] | 313 | |
| 314 | if (layer_->blending != blending) { |
| 315 | geometry_changes_ |= kBlendMode; |
| 316 | layer_->blending = blending; |
| 317 | } |
Naseer Ahmed | b92e73f | 2016-03-12 02:03:48 -0500 | [diff] [blame] | 318 | return HWC2::Error::None; |
| 319 | } |
| 320 | |
| 321 | HWC2::Error HWCLayer::SetLayerColor(hwc_color_t color) { |
Arun Kumar K.R | 1018d5b | 2017-06-08 13:51:05 +0530 | [diff] [blame] | 322 | if (client_requested_ != HWC2::Composition::SolidColor) { |
| 323 | return HWC2::Error::None; |
| 324 | } |
Naseer Ahmed | b92e73f | 2016-03-12 02:03:48 -0500 | [diff] [blame] | 325 | layer_->solid_fill_color = GetUint32Color(color); |
Arun Kumar K.R | 9c19cdd | 2016-11-21 16:48:43 -0800 | [diff] [blame] | 326 | layer_->input_buffer.format = kFormatARGB8888; |
Saurabh Dubey | d90a6a4 | 2017-10-24 16:28:01 +0530 | [diff] [blame] | 327 | DLOGV_IF(kTagClient, "[%" PRIu64 "][%" PRIu64 "] Layer color set to %x", display_id_, id_, |
Naseer Ahmed | 16c72b9 | 2016-07-22 20:02:31 -0400 | [diff] [blame] | 328 | layer_->solid_fill_color); |
Naseer Ahmed | b92e73f | 2016-03-12 02:03:48 -0500 | [diff] [blame] | 329 | return HWC2::Error::None; |
| 330 | } |
| 331 | |
| 332 | HWC2::Error HWCLayer::SetLayerCompositionType(HWC2::Composition type) { |
Naseer Ahmed | 34b341d | 2017-10-05 18:47:15 -0400 | [diff] [blame] | 333 | // Validation is required when the client changes the composition type |
| 334 | if (client_requested_ != type) { |
| 335 | needs_validate_ = true; |
| 336 | } |
Arun Kumar K.R | 2c0ff8d | 2016-06-01 16:56:52 -0700 | [diff] [blame] | 337 | client_requested_ = type; |
Naseer Ahmed | b92e73f | 2016-03-12 02:03:48 -0500 | [diff] [blame] | 338 | switch (type) { |
| 339 | case HWC2::Composition::Client: |
Naseer Ahmed | b92e73f | 2016-03-12 02:03:48 -0500 | [diff] [blame] | 340 | break; |
| 341 | case HWC2::Composition::Device: |
| 342 | // We try and default to this in SDM |
| 343 | break; |
| 344 | case HWC2::Composition::SolidColor: |
Naseer Ahmed | b92e73f | 2016-03-12 02:03:48 -0500 | [diff] [blame] | 345 | break; |
| 346 | case HWC2::Composition::Cursor: |
Naseer Ahmed | b92e73f | 2016-03-12 02:03:48 -0500 | [diff] [blame] | 347 | break; |
| 348 | case HWC2::Composition::Invalid: |
| 349 | return HWC2::Error::BadParameter; |
| 350 | default: |
| 351 | return HWC2::Error::Unsupported; |
| 352 | } |
Arun Kumar K.R | 3e89f79 | 2016-06-01 17:14:15 -0700 | [diff] [blame] | 353 | |
Naseer Ahmed | b92e73f | 2016-03-12 02:03:48 -0500 | [diff] [blame] | 354 | return HWC2::Error::None; |
| 355 | } |
| 356 | |
| 357 | HWC2::Error HWCLayer::SetLayerDataspace(int32_t dataspace) { |
Naseer Ahmed | 43f22bb | 2017-05-05 17:40:46 -0400 | [diff] [blame] | 358 | // Map deprecated dataspace values to appropriate |
| 359 | // new enums |
| 360 | if (dataspace & 0xffff) { |
| 361 | switch (dataspace & 0xffff) { |
| 362 | case HAL_DATASPACE_SRGB: |
| 363 | dataspace = HAL_DATASPACE_V0_SRGB; |
| 364 | break; |
| 365 | case HAL_DATASPACE_JFIF: |
| 366 | dataspace = HAL_DATASPACE_V0_JFIF; |
| 367 | break; |
| 368 | case HAL_DATASPACE_SRGB_LINEAR: |
| 369 | dataspace = HAL_DATASPACE_V0_SRGB_LINEAR; |
| 370 | break; |
| 371 | case HAL_DATASPACE_BT601_625: |
| 372 | dataspace = HAL_DATASPACE_V0_BT601_625; |
| 373 | break; |
| 374 | case HAL_DATASPACE_BT601_525: |
| 375 | dataspace = HAL_DATASPACE_V0_BT601_525; |
| 376 | break; |
| 377 | case HAL_DATASPACE_BT709: |
| 378 | dataspace = HAL_DATASPACE_V0_BT709; |
| 379 | break; |
| 380 | default: |
| 381 | // unknown legacy dataspace |
Saurabh Dubey | d90a6a4 | 2017-10-24 16:28:01 +0530 | [diff] [blame] | 382 | DLOGW_IF(kTagClient, "Unsupported dataspace type %d", dataspace); |
Naseer Ahmed | 43f22bb | 2017-05-05 17:40:46 -0400 | [diff] [blame] | 383 | } |
| 384 | } |
| 385 | |
Arun Kumar K.R | 961a28f | 2017-07-07 15:26:30 +0530 | [diff] [blame] | 386 | // cache the dataspace, to be used later to update SDM ColorMetaData |
Naseer Ahmed | ade4ee6 | 2016-10-07 17:07:38 -0400 | [diff] [blame] | 387 | if (dataspace_ != dataspace) { |
| 388 | geometry_changes_ |= kDataspace; |
| 389 | dataspace_ = dataspace; |
| 390 | } |
Naseer Ahmed | b92e73f | 2016-03-12 02:03:48 -0500 | [diff] [blame] | 391 | return HWC2::Error::None; |
| 392 | } |
| 393 | |
| 394 | HWC2::Error HWCLayer::SetLayerDisplayFrame(hwc_rect_t frame) { |
Arun Kumar K.R | 3e89f79 | 2016-06-01 17:14:15 -0700 | [diff] [blame] | 395 | LayerRect dst_rect = {}; |
Prabhanjan Kandula | 5265b05 | 2017-05-30 17:13:40 -0700 | [diff] [blame] | 396 | |
Arun Kumar K.R | 3e89f79 | 2016-06-01 17:14:15 -0700 | [diff] [blame] | 397 | SetRect(frame, &dst_rect); |
Prabhanjan Kandula | 5265b05 | 2017-05-30 17:13:40 -0700 | [diff] [blame] | 398 | if (dst_rect_ != dst_rect) { |
Arun Kumar K.R | 3e89f79 | 2016-06-01 17:14:15 -0700 | [diff] [blame] | 399 | geometry_changes_ |= kDisplayFrame; |
Prabhanjan Kandula | 5265b05 | 2017-05-30 17:13:40 -0700 | [diff] [blame] | 400 | dst_rect_ = dst_rect; |
Arun Kumar K.R | 3e89f79 | 2016-06-01 17:14:15 -0700 | [diff] [blame] | 401 | } |
Prabhanjan Kandula | 5265b05 | 2017-05-30 17:13:40 -0700 | [diff] [blame] | 402 | |
Naseer Ahmed | b92e73f | 2016-03-12 02:03:48 -0500 | [diff] [blame] | 403 | return HWC2::Error::None; |
| 404 | } |
| 405 | |
Prabhanjan Kandula | 5265b05 | 2017-05-30 17:13:40 -0700 | [diff] [blame] | 406 | void HWCLayer::ResetPerFrameData() { |
| 407 | layer_->dst_rect = dst_rect_; |
| 408 | layer_->transform = layer_transform_; |
| 409 | } |
| 410 | |
Pullakavi Srinivas | 68a166c | 2017-05-24 12:17:07 +0530 | [diff] [blame] | 411 | HWC2::Error HWCLayer::SetCursorPosition(int32_t x, int32_t y) { |
| 412 | hwc_rect_t frame = {}; |
| 413 | frame.left = x; |
| 414 | frame.top = y; |
| 415 | frame.right = x + INT(layer_->dst_rect.right - layer_->dst_rect.left); |
| 416 | frame.bottom = y + INT(layer_->dst_rect.bottom - layer_->dst_rect.top); |
| 417 | SetLayerDisplayFrame(frame); |
| 418 | |
| 419 | return HWC2::Error::None; |
| 420 | } |
| 421 | |
Naseer Ahmed | b92e73f | 2016-03-12 02:03:48 -0500 | [diff] [blame] | 422 | HWC2::Error HWCLayer::SetLayerPlaneAlpha(float alpha) { |
Varun Arora | 2c23e58 | 2017-10-10 15:07:13 -0700 | [diff] [blame] | 423 | if (alpha < 0.0f || alpha > 1.0f) { |
| 424 | return HWC2::Error::BadParameter; |
| 425 | } |
| 426 | |
| 427 | // Conversion of float alpha in range 0.0 to 1.0 similar to the HWC Adapter |
Arun Kumar K.R | 3e89f79 | 2016-06-01 17:14:15 -0700 | [diff] [blame] | 428 | uint8_t plane_alpha = static_cast<uint8_t>(std::round(255.0f * alpha)); |
Varun Arora | 2c23e58 | 2017-10-10 15:07:13 -0700 | [diff] [blame] | 429 | |
Arun Kumar K.R | 3e89f79 | 2016-06-01 17:14:15 -0700 | [diff] [blame] | 430 | if (layer_->plane_alpha != plane_alpha) { |
| 431 | geometry_changes_ |= kPlaneAlpha; |
| 432 | layer_->plane_alpha = plane_alpha; |
| 433 | } |
| 434 | |
Naseer Ahmed | b92e73f | 2016-03-12 02:03:48 -0500 | [diff] [blame] | 435 | return HWC2::Error::None; |
| 436 | } |
| 437 | |
| 438 | HWC2::Error HWCLayer::SetLayerSourceCrop(hwc_frect_t crop) { |
Arun Kumar K.R | 3e89f79 | 2016-06-01 17:14:15 -0700 | [diff] [blame] | 439 | LayerRect src_rect = {}; |
| 440 | SetRect(crop, &src_rect); |
| 441 | if (layer_->src_rect != src_rect) { |
| 442 | geometry_changes_ |= kSourceCrop; |
| 443 | layer_->src_rect = src_rect; |
| 444 | } |
| 445 | |
Naseer Ahmed | b92e73f | 2016-03-12 02:03:48 -0500 | [diff] [blame] | 446 | return HWC2::Error::None; |
| 447 | } |
| 448 | |
| 449 | HWC2::Error HWCLayer::SetLayerTransform(HWC2::Transform transform) { |
Arun Kumar K.R | 3e89f79 | 2016-06-01 17:14:15 -0700 | [diff] [blame] | 450 | LayerTransform layer_transform = {}; |
Naseer Ahmed | b92e73f | 2016-03-12 02:03:48 -0500 | [diff] [blame] | 451 | switch (transform) { |
| 452 | case HWC2::Transform::FlipH: |
Arun Kumar K.R | 3e89f79 | 2016-06-01 17:14:15 -0700 | [diff] [blame] | 453 | layer_transform.flip_horizontal = true; |
Naseer Ahmed | b92e73f | 2016-03-12 02:03:48 -0500 | [diff] [blame] | 454 | break; |
| 455 | case HWC2::Transform::FlipV: |
Arun Kumar K.R | 3e89f79 | 2016-06-01 17:14:15 -0700 | [diff] [blame] | 456 | layer_transform.flip_vertical = true; |
Naseer Ahmed | b92e73f | 2016-03-12 02:03:48 -0500 | [diff] [blame] | 457 | break; |
| 458 | case HWC2::Transform::Rotate90: |
Arun Kumar K.R | 3e89f79 | 2016-06-01 17:14:15 -0700 | [diff] [blame] | 459 | layer_transform.rotation = 90.0f; |
Naseer Ahmed | b92e73f | 2016-03-12 02:03:48 -0500 | [diff] [blame] | 460 | break; |
| 461 | case HWC2::Transform::Rotate180: |
Arun Kumar K.R | f641dff | 2016-06-16 13:20:02 -0700 | [diff] [blame] | 462 | layer_transform.flip_horizontal = true; |
| 463 | layer_transform.flip_vertical = true; |
Naseer Ahmed | b92e73f | 2016-03-12 02:03:48 -0500 | [diff] [blame] | 464 | break; |
| 465 | case HWC2::Transform::Rotate270: |
Arun Kumar K.R | f641dff | 2016-06-16 13:20:02 -0700 | [diff] [blame] | 466 | layer_transform.rotation = 90.0f; |
| 467 | layer_transform.flip_horizontal = true; |
| 468 | layer_transform.flip_vertical = true; |
Naseer Ahmed | b92e73f | 2016-03-12 02:03:48 -0500 | [diff] [blame] | 469 | break; |
| 470 | case HWC2::Transform::FlipHRotate90: |
Arun Kumar K.R | 3e89f79 | 2016-06-01 17:14:15 -0700 | [diff] [blame] | 471 | layer_transform.rotation = 90.0f; |
| 472 | layer_transform.flip_horizontal = true; |
Naseer Ahmed | b92e73f | 2016-03-12 02:03:48 -0500 | [diff] [blame] | 473 | break; |
| 474 | case HWC2::Transform::FlipVRotate90: |
Arun Kumar K.R | 3e89f79 | 2016-06-01 17:14:15 -0700 | [diff] [blame] | 475 | layer_transform.rotation = 90.0f; |
| 476 | layer_transform.flip_vertical = true; |
Naseer Ahmed | b92e73f | 2016-03-12 02:03:48 -0500 | [diff] [blame] | 477 | break; |
Arun Kumar K.R | 5f20a7a | 2016-06-17 16:03:54 -0700 | [diff] [blame] | 478 | case HWC2::Transform::None: |
Arun Kumar K.R | 5f20a7a | 2016-06-17 16:03:54 -0700 | [diff] [blame] | 479 | break; |
Varun Arora | 2c23e58 | 2017-10-10 15:07:13 -0700 | [diff] [blame] | 480 | default: |
| 481 | // bad transform |
| 482 | return HWC2::Error::BadParameter; |
Naseer Ahmed | b92e73f | 2016-03-12 02:03:48 -0500 | [diff] [blame] | 483 | } |
Arun Kumar K.R | 3e89f79 | 2016-06-01 17:14:15 -0700 | [diff] [blame] | 484 | |
Prabhanjan Kandula | 5265b05 | 2017-05-30 17:13:40 -0700 | [diff] [blame] | 485 | if (layer_transform_ != layer_transform) { |
Arun Kumar K.R | 3e89f79 | 2016-06-01 17:14:15 -0700 | [diff] [blame] | 486 | geometry_changes_ |= kTransform; |
Prabhanjan Kandula | 5265b05 | 2017-05-30 17:13:40 -0700 | [diff] [blame] | 487 | layer_transform_ = layer_transform; |
Arun Kumar K.R | 3e89f79 | 2016-06-01 17:14:15 -0700 | [diff] [blame] | 488 | } |
Prabhanjan Kandula | 5265b05 | 2017-05-30 17:13:40 -0700 | [diff] [blame] | 489 | |
Naseer Ahmed | b92e73f | 2016-03-12 02:03:48 -0500 | [diff] [blame] | 490 | return HWC2::Error::None; |
| 491 | } |
| 492 | |
| 493 | HWC2::Error HWCLayer::SetLayerVisibleRegion(hwc_region_t visible) { |
Arun Kumar K.R | 2c0ff8d | 2016-06-01 16:56:52 -0700 | [diff] [blame] | 494 | layer_->visible_regions.clear(); |
Naseer Ahmed | 6786e5d | 2016-06-24 16:38:52 -0400 | [diff] [blame] | 495 | for (uint32_t i = 0; i < visible.numRects; i++) { |
| 496 | LayerRect rect; |
| 497 | SetRect(visible.rects[i], &rect); |
| 498 | layer_->visible_regions.push_back(rect); |
Naseer Ahmed | b92e73f | 2016-03-12 02:03:48 -0500 | [diff] [blame] | 499 | } |
| 500 | |
| 501 | return HWC2::Error::None; |
| 502 | } |
| 503 | |
| 504 | HWC2::Error HWCLayer::SetLayerZOrder(uint32_t z) { |
Arun Kumar K.R | 3e89f79 | 2016-06-01 17:14:15 -0700 | [diff] [blame] | 505 | if (z_ != z) { |
| 506 | geometry_changes_ |= kZOrder; |
| 507 | z_ = z; |
| 508 | } |
Naseer Ahmed | b92e73f | 2016-03-12 02:03:48 -0500 | [diff] [blame] | 509 | return HWC2::Error::None; |
| 510 | } |
| 511 | |
| 512 | void HWCLayer::SetRect(const hwc_rect_t &source, LayerRect *target) { |
| 513 | target->left = FLOAT(source.left); |
| 514 | target->top = FLOAT(source.top); |
| 515 | target->right = FLOAT(source.right); |
| 516 | target->bottom = FLOAT(source.bottom); |
| 517 | } |
| 518 | |
| 519 | void HWCLayer::SetRect(const hwc_frect_t &source, LayerRect *target) { |
| 520 | // Recommended way of rounding as in hwcomposer2.h - SetLayerSourceCrop |
| 521 | target->left = std::ceil(source.left); |
| 522 | target->top = std::ceil(source.top); |
| 523 | target->right = std::floor(source.right); |
| 524 | target->bottom = std::floor(source.bottom); |
| 525 | } |
| 526 | |
| 527 | uint32_t HWCLayer::GetUint32Color(const hwc_color_t &source) { |
| 528 | // Returns 32 bit ARGB |
| 529 | uint32_t a = UINT32(source.a) << 24; |
| 530 | uint32_t r = UINT32(source.r) << 16; |
| 531 | uint32_t g = UINT32(source.g) << 8; |
| 532 | uint32_t b = UINT32(source.b); |
Naseer Ahmed | 16c72b9 | 2016-07-22 20:02:31 -0400 | [diff] [blame] | 533 | uint32_t color = a | r | g | b; |
Naseer Ahmed | b92e73f | 2016-03-12 02:03:48 -0500 | [diff] [blame] | 534 | return color; |
| 535 | } |
| 536 | |
| 537 | LayerBufferFormat HWCLayer::GetSDMFormat(const int32_t &source, const int flags) { |
| 538 | LayerBufferFormat format = kFormatInvalid; |
| 539 | if (flags & private_handle_t::PRIV_FLAGS_UBWC_ALIGNED) { |
| 540 | switch (source) { |
| 541 | case HAL_PIXEL_FORMAT_RGBA_8888: |
| 542 | format = kFormatRGBA8888Ubwc; |
| 543 | break; |
| 544 | case HAL_PIXEL_FORMAT_RGBX_8888: |
| 545 | format = kFormatRGBX8888Ubwc; |
| 546 | break; |
| 547 | case HAL_PIXEL_FORMAT_BGR_565: |
| 548 | format = kFormatBGR565Ubwc; |
| 549 | break; |
| 550 | case HAL_PIXEL_FORMAT_YCbCr_420_SP_VENUS: |
| 551 | case HAL_PIXEL_FORMAT_YCbCr_420_SP_VENUS_UBWC: |
| 552 | case HAL_PIXEL_FORMAT_NV12_ENCODEABLE: |
| 553 | format = kFormatYCbCr420SPVenusUbwc; |
| 554 | break; |
Saurabh Shah | 3cc87ed | 2017-10-24 14:09:35 -0700 | [diff] [blame] | 555 | case HAL_PIXEL_FORMAT_RGBA_1010102: |
| 556 | format = kFormatRGBA1010102Ubwc; |
| 557 | break; |
| 558 | case HAL_PIXEL_FORMAT_RGBX_1010102: |
| 559 | format = kFormatRGBX1010102Ubwc; |
| 560 | break; |
Arun Kumar K.R | 54885f0 | 2017-03-23 11:56:59 -0700 | [diff] [blame] | 561 | case HAL_PIXEL_FORMAT_YCbCr_420_TP10_UBWC: |
| 562 | format = kFormatYCbCr420TP10Ubwc; |
| 563 | break; |
Rohit Kulkarni | 7943ec9 | 2016-12-20 18:18:46 -0800 | [diff] [blame] | 564 | case HAL_PIXEL_FORMAT_YCbCr_420_P010_UBWC: |
| 565 | format = kFormatYCbCr420P010Ubwc; |
| 566 | break; |
Naseer Ahmed | b92e73f | 2016-03-12 02:03:48 -0500 | [diff] [blame] | 567 | default: |
| 568 | DLOGE("Unsupported format type for UBWC %d", source); |
| 569 | return kFormatInvalid; |
| 570 | } |
| 571 | return format; |
| 572 | } |
| 573 | |
| 574 | switch (source) { |
| 575 | case HAL_PIXEL_FORMAT_RGBA_8888: |
| 576 | format = kFormatRGBA8888; |
| 577 | break; |
| 578 | case HAL_PIXEL_FORMAT_RGBA_5551: |
| 579 | format = kFormatRGBA5551; |
| 580 | break; |
| 581 | case HAL_PIXEL_FORMAT_RGBA_4444: |
| 582 | format = kFormatRGBA4444; |
| 583 | break; |
| 584 | case HAL_PIXEL_FORMAT_BGRA_8888: |
| 585 | format = kFormatBGRA8888; |
| 586 | break; |
| 587 | case HAL_PIXEL_FORMAT_RGBX_8888: |
| 588 | format = kFormatRGBX8888; |
| 589 | break; |
| 590 | case HAL_PIXEL_FORMAT_BGRX_8888: |
| 591 | format = kFormatBGRX8888; |
| 592 | break; |
| 593 | case HAL_PIXEL_FORMAT_RGB_888: |
| 594 | format = kFormatRGB888; |
| 595 | break; |
Camus Wong | c106d08 | 2017-03-31 16:07:29 -0400 | [diff] [blame] | 596 | case HAL_PIXEL_FORMAT_BGR_888: |
| 597 | format = kFormatBGR888; |
| 598 | break; |
Naseer Ahmed | b92e73f | 2016-03-12 02:03:48 -0500 | [diff] [blame] | 599 | case HAL_PIXEL_FORMAT_RGB_565: |
| 600 | format = kFormatRGB565; |
| 601 | break; |
| 602 | case HAL_PIXEL_FORMAT_BGR_565: |
| 603 | format = kFormatBGR565; |
| 604 | break; |
| 605 | case HAL_PIXEL_FORMAT_NV12_ENCODEABLE: |
| 606 | case HAL_PIXEL_FORMAT_YCbCr_420_SP_VENUS: |
| 607 | format = kFormatYCbCr420SemiPlanarVenus; |
| 608 | break; |
| 609 | case HAL_PIXEL_FORMAT_YCrCb_420_SP_VENUS: |
| 610 | format = kFormatYCrCb420SemiPlanarVenus; |
| 611 | break; |
| 612 | case HAL_PIXEL_FORMAT_YCbCr_420_SP_VENUS_UBWC: |
| 613 | format = kFormatYCbCr420SPVenusUbwc; |
| 614 | break; |
| 615 | case HAL_PIXEL_FORMAT_YV12: |
| 616 | format = kFormatYCrCb420PlanarStride16; |
| 617 | break; |
| 618 | case HAL_PIXEL_FORMAT_YCrCb_420_SP: |
| 619 | format = kFormatYCrCb420SemiPlanar; |
| 620 | break; |
| 621 | case HAL_PIXEL_FORMAT_YCbCr_420_SP: |
| 622 | format = kFormatYCbCr420SemiPlanar; |
| 623 | break; |
| 624 | case HAL_PIXEL_FORMAT_YCbCr_422_SP: |
| 625 | format = kFormatYCbCr422H2V1SemiPlanar; |
| 626 | break; |
| 627 | case HAL_PIXEL_FORMAT_YCbCr_422_I: |
| 628 | format = kFormatYCbCr422H2V1Packed; |
| 629 | break; |
Camus Wong | c106d08 | 2017-03-31 16:07:29 -0400 | [diff] [blame] | 630 | case HAL_PIXEL_FORMAT_CbYCrY_422_I: |
| 631 | format = kFormatCbYCrY422H2V1Packed; |
| 632 | break; |
Naseer Ahmed | 72dea24 | 2016-05-03 19:13:07 -0400 | [diff] [blame] | 633 | case HAL_PIXEL_FORMAT_RGBA_1010102: |
| 634 | format = kFormatRGBA1010102; |
| 635 | break; |
| 636 | case HAL_PIXEL_FORMAT_ARGB_2101010: |
| 637 | format = kFormatARGB2101010; |
| 638 | break; |
| 639 | case HAL_PIXEL_FORMAT_RGBX_1010102: |
| 640 | format = kFormatRGBX1010102; |
| 641 | break; |
| 642 | case HAL_PIXEL_FORMAT_XRGB_2101010: |
| 643 | format = kFormatXRGB2101010; |
| 644 | break; |
| 645 | case HAL_PIXEL_FORMAT_BGRA_1010102: |
| 646 | format = kFormatBGRA1010102; |
| 647 | break; |
| 648 | case HAL_PIXEL_FORMAT_ABGR_2101010: |
| 649 | format = kFormatABGR2101010; |
| 650 | break; |
| 651 | case HAL_PIXEL_FORMAT_BGRX_1010102: |
| 652 | format = kFormatBGRX1010102; |
| 653 | break; |
| 654 | case HAL_PIXEL_FORMAT_XBGR_2101010: |
| 655 | format = kFormatXBGR2101010; |
| 656 | break; |
| 657 | case HAL_PIXEL_FORMAT_YCbCr_420_P010: |
| 658 | format = kFormatYCbCr420P010; |
| 659 | break; |
| 660 | case HAL_PIXEL_FORMAT_YCbCr_420_TP10_UBWC: |
| 661 | format = kFormatYCbCr420TP10Ubwc; |
| 662 | break; |
Rohit Kulkarni | 7943ec9 | 2016-12-20 18:18:46 -0800 | [diff] [blame] | 663 | case HAL_PIXEL_FORMAT_YCbCr_420_P010_UBWC: |
| 664 | format = kFormatYCbCr420P010Ubwc; |
| 665 | break; |
Mathew Joseph Karimpanal | a73082e | 2017-10-16 18:01:21 +0530 | [diff] [blame] | 666 | case HAL_PIXEL_FORMAT_YCbCr_420_P010_VENUS: |
| 667 | format = kFormatYCbCr420P010Venus; |
| 668 | break; |
Naseer Ahmed | 738da07 | 2018-01-24 14:41:46 -0500 | [diff] [blame] | 669 | case HAL_PIXEL_FORMAT_RGBA_FP16: |
| 670 | format = kFormatInvalid; |
| 671 | break; |
Naseer Ahmed | b92e73f | 2016-03-12 02:03:48 -0500 | [diff] [blame] | 672 | default: |
| 673 | DLOGW("Unsupported format type = %d", source); |
| 674 | return kFormatInvalid; |
| 675 | } |
| 676 | |
| 677 | return format; |
| 678 | } |
| 679 | |
| 680 | LayerBufferS3DFormat HWCLayer::GetS3DFormat(uint32_t s3d_format) { |
| 681 | LayerBufferS3DFormat sdm_s3d_format = kS3dFormatNone; |
| 682 | switch (s3d_format) { |
| 683 | case HAL_NO_3D: |
| 684 | sdm_s3d_format = kS3dFormatNone; |
| 685 | break; |
| 686 | case HAL_3D_SIDE_BY_SIDE_L_R: |
| 687 | sdm_s3d_format = kS3dFormatLeftRight; |
| 688 | break; |
| 689 | case HAL_3D_SIDE_BY_SIDE_R_L: |
| 690 | sdm_s3d_format = kS3dFormatRightLeft; |
| 691 | break; |
| 692 | case HAL_3D_TOP_BOTTOM: |
| 693 | sdm_s3d_format = kS3dFormatTopBottom; |
| 694 | break; |
| 695 | default: |
| 696 | DLOGW("Invalid S3D format %d", s3d_format); |
| 697 | } |
| 698 | return sdm_s3d_format; |
| 699 | } |
| 700 | |
Gurunath Ramaswamy | f081afe | 2017-07-04 22:08:36 -0700 | [diff] [blame] | 701 | void HWCLayer::GetUBWCStatsFromMetaData(UBWCStats *cr_stats, UbwcCrStatsVector *cr_vec) { |
| 702 | // TODO(user): Check if we can use UBWCStats directly |
| 703 | // in layer_buffer or copy directly to Vector |
| 704 | if (cr_stats->bDataValid) { |
| 705 | switch (cr_stats->version) { |
| 706 | case UBWC_2_0: |
| 707 | cr_vec->push_back(std::make_pair(32, cr_stats->ubwc_stats.nCRStatsTile32)); |
| 708 | cr_vec->push_back(std::make_pair(64, cr_stats->ubwc_stats.nCRStatsTile64)); |
| 709 | cr_vec->push_back(std::make_pair(96, cr_stats->ubwc_stats.nCRStatsTile96)); |
| 710 | cr_vec->push_back(std::make_pair(128, cr_stats->ubwc_stats.nCRStatsTile128)); |
| 711 | cr_vec->push_back(std::make_pair(160, cr_stats->ubwc_stats.nCRStatsTile160)); |
| 712 | cr_vec->push_back(std::make_pair(192, cr_stats->ubwc_stats.nCRStatsTile192)); |
| 713 | cr_vec->push_back(std::make_pair(256, cr_stats->ubwc_stats.nCRStatsTile256)); |
| 714 | break; |
| 715 | default: |
| 716 | DLOGW("Invalid UBWC Version %d", cr_stats->version); |
| 717 | break; |
| 718 | } // switch(cr_stats->version) |
| 719 | } // if (cr_stats->bDatvalid) |
| 720 | } |
| 721 | |
Naseer Ahmed | b92e73f | 2016-03-12 02:03:48 -0500 | [diff] [blame] | 722 | DisplayError HWCLayer::SetMetaData(const private_handle_t *pvt_handle, Layer *layer) { |
Arun Kumar K.R | 9c19cdd | 2016-11-21 16:48:43 -0800 | [diff] [blame] | 723 | LayerBuffer *layer_buffer = &layer->input_buffer; |
Arun Kumar K.R | 3e45ac4 | 2017-03-08 19:00:02 -0800 | [diff] [blame] | 724 | private_handle_t *handle = const_cast<private_handle_t *>(pvt_handle); |
| 725 | IGC_t igc = {}; |
Sushil Chauhan | 409e844 | 2017-06-12 17:43:25 -0700 | [diff] [blame] | 726 | LayerIGC layer_igc = layer_buffer->igc; |
Arun Kumar K.R | 3e45ac4 | 2017-03-08 19:00:02 -0800 | [diff] [blame] | 727 | if (getMetaData(handle, GET_IGC, &igc) == 0) { |
Sushil Chauhan | 409e844 | 2017-06-12 17:43:25 -0700 | [diff] [blame] | 728 | if (SetIGC(igc, &layer_igc) != kErrorNone) { |
Naseer Ahmed | b92e73f | 2016-03-12 02:03:48 -0500 | [diff] [blame] | 729 | return kErrorNotSupported; |
| 730 | } |
| 731 | } |
| 732 | |
Anjaneya Prasad Musunuri | d47d15b | 2017-08-03 10:57:51 +0530 | [diff] [blame] | 733 | float fps = 0; |
Sushil Chauhan | 409e844 | 2017-06-12 17:43:25 -0700 | [diff] [blame] | 734 | uint32_t frame_rate = layer->frame_rate; |
| 735 | if (getMetaData(handle, GET_REFRESH_RATE, &fps) == 0) { |
Sushil Chauhan | 0935c75 | 2018-01-19 10:58:13 -0800 | [diff] [blame] | 736 | frame_rate = (fps != 0) ? RoundToStandardFPS(fps) : layer->frame_rate; |
Naseer Ahmed | b92e73f | 2016-03-12 02:03:48 -0500 | [diff] [blame] | 737 | } |
| 738 | |
Arun Kumar K.R | 3e45ac4 | 2017-03-08 19:00:02 -0800 | [diff] [blame] | 739 | int32_t interlaced = 0; |
Sushil Chauhan | 409e844 | 2017-06-12 17:43:25 -0700 | [diff] [blame] | 740 | bool interlace = layer_buffer->flags.interlace; |
Arun Kumar K.R | 3e45ac4 | 2017-03-08 19:00:02 -0800 | [diff] [blame] | 741 | if (getMetaData(handle, GET_PP_PARAM_INTERLACED, &interlaced) == 0) { |
Sushil Chauhan | 409e844 | 2017-06-12 17:43:25 -0700 | [diff] [blame] | 742 | interlace = interlaced ? true : false; |
Naseer Ahmed | b92e73f | 2016-03-12 02:03:48 -0500 | [diff] [blame] | 743 | } |
Saurabh Dubey | d90a6a4 | 2017-10-24 16:28:01 +0530 | [diff] [blame] | 744 | if (interlace != layer_buffer->flags.interlace) { |
| 745 | DLOGI("Layer buffer interlaced metadata has changed. old=%d, new=%d", |
| 746 | layer_buffer->flags.interlace, interlace); |
| 747 | } |
Naseer Ahmed | b92e73f | 2016-03-12 02:03:48 -0500 | [diff] [blame] | 748 | |
Arun Kumar K.R | 3e45ac4 | 2017-03-08 19:00:02 -0800 | [diff] [blame] | 749 | uint32_t linear_format = 0; |
| 750 | if (getMetaData(handle, GET_LINEAR_FORMAT, &linear_format) == 0) { |
| 751 | layer_buffer->format = GetSDMFormat(INT32(linear_format), 0); |
Naseer Ahmed | b92e73f | 2016-03-12 02:03:48 -0500 | [diff] [blame] | 752 | } |
| 753 | |
Arun Kumar K.R | 3e45ac4 | 2017-03-08 19:00:02 -0800 | [diff] [blame] | 754 | uint32_t s3d = 0; |
Sushil Chauhan | 409e844 | 2017-06-12 17:43:25 -0700 | [diff] [blame] | 755 | LayerBufferS3DFormat s3d_format = layer_buffer->s3d_format; |
Arun Kumar K.R | 3e45ac4 | 2017-03-08 19:00:02 -0800 | [diff] [blame] | 756 | if (getMetaData(handle, GET_S3D_FORMAT, &s3d) == 0) { |
Sushil Chauhan | 409e844 | 2017-06-12 17:43:25 -0700 | [diff] [blame] | 757 | s3d_format = GetS3DFormat(s3d); |
| 758 | } |
| 759 | |
| 760 | if ((layer_igc != layer_buffer->igc) || (interlace != layer_buffer->flags.interlace) || |
| 761 | (frame_rate != layer->frame_rate) || (s3d_format != layer_buffer->s3d_format)) { |
| 762 | // Layer buffer metadata has changed. |
| 763 | needs_validate_ = true; |
| 764 | layer_buffer->igc = layer_igc; |
| 765 | layer->frame_rate = frame_rate; |
| 766 | layer_buffer->s3d_format = s3d_format; |
| 767 | layer_buffer->flags.interlace = interlace; |
Naseer Ahmed | b92e73f | 2016-03-12 02:03:48 -0500 | [diff] [blame] | 768 | } |
| 769 | |
Gurunath Ramaswamy | f081afe | 2017-07-04 22:08:36 -0700 | [diff] [blame] | 770 | // Check if metadata is set |
| 771 | struct UBWCStats cr_stats[NUM_UBWC_CR_STATS_LAYERS] = {}; |
| 772 | |
| 773 | for (int i = 0; i < NUM_UBWC_CR_STATS_LAYERS; i++) { |
| 774 | layer_buffer->ubwc_crstats[i].clear(); |
| 775 | } |
| 776 | |
| 777 | if (getMetaData(handle, GET_UBWC_CR_STATS_INFO, cr_stats) == 0) { |
| 778 | // Only copy top layer for now as only top field for interlaced is used |
| 779 | GetUBWCStatsFromMetaData(&cr_stats[0], &(layer_buffer->ubwc_crstats[0])); |
| 780 | } // if (getMetaData) |
| 781 | |
Ramakant Singh | ae05709 | 2017-08-31 12:34:54 +0530 | [diff] [blame] | 782 | single_buffer_ = false; |
| 783 | getMetaData(const_cast<private_handle_t *>(handle), GET_SINGLE_BUFFER_MODE, &single_buffer_); |
| 784 | |
Naseer Ahmed | b92e73f | 2016-03-12 02:03:48 -0500 | [diff] [blame] | 785 | return kErrorNone; |
| 786 | } |
| 787 | |
Naseer Ahmed | b92e73f | 2016-03-12 02:03:48 -0500 | [diff] [blame] | 788 | DisplayError HWCLayer::SetIGC(IGC_t source, LayerIGC *target) { |
| 789 | switch (source) { |
| 790 | case IGC_NotSpecified: |
| 791 | *target = kIGCNotSpecified; |
| 792 | break; |
| 793 | case IGC_sRGB: |
| 794 | *target = kIGCsRGB; |
| 795 | break; |
| 796 | default: |
| 797 | DLOGE("Unsupported IGC: %d", source); |
| 798 | return kErrorNotSupported; |
| 799 | } |
| 800 | |
| 801 | return kErrorNone; |
| 802 | } |
| 803 | |
Arun Kumar K.R | 961a28f | 2017-07-07 15:26:30 +0530 | [diff] [blame] | 804 | bool HWCLayer::ValidateAndSetCSC() { |
| 805 | if (client_requested_ != HWC2::Composition::Device && |
| 806 | client_requested_ != HWC2::Composition::Cursor) { |
| 807 | // Check the layers which are configured to Device |
Naseer Ahmed | ade4ee6 | 2016-10-07 17:07:38 -0400 | [diff] [blame] | 808 | return true; |
| 809 | } |
| 810 | |
Naseer Ahmed | ade4ee6 | 2016-10-07 17:07:38 -0400 | [diff] [blame] | 811 | LayerBuffer *layer_buffer = &layer_->input_buffer; |
Arun Kumar K.R | 961a28f | 2017-07-07 15:26:30 +0530 | [diff] [blame] | 812 | bool use_color_metadata = true; |
Arun Kumar K.R | 80e58eb | 2017-07-13 10:37:00 +0530 | [diff] [blame] | 813 | ColorMetaData csc = {}; |
Arun Kumar K.R | 961a28f | 2017-07-07 15:26:30 +0530 | [diff] [blame] | 814 | if (dataspace_ != HAL_DATASPACE_UNKNOWN) { |
Arun Kumar K.R | 80e58eb | 2017-07-13 10:37:00 +0530 | [diff] [blame] | 815 | use_color_metadata = false; |
| 816 | bool valid_csc = GetSDMColorSpace(dataspace_, &csc); |
| 817 | if (!valid_csc) { |
| 818 | return false; |
Arun Kumar K.R | 961a28f | 2017-07-07 15:26:30 +0530 | [diff] [blame] | 819 | } |
Arun Kumar K.R | 80e58eb | 2017-07-13 10:37:00 +0530 | [diff] [blame] | 820 | // if we are here here, update the sdm layer csc. |
| 821 | layer_buffer->color_metadata.transfer = csc.transfer; |
| 822 | layer_buffer->color_metadata.colorPrimaries = csc.colorPrimaries; |
| 823 | layer_buffer->color_metadata.range = csc.range; |
Arun Kumar K.R | 961a28f | 2017-07-07 15:26:30 +0530 | [diff] [blame] | 824 | } |
Arun Kumar K.R | 961a28f | 2017-07-07 15:26:30 +0530 | [diff] [blame] | 825 | |
Arun Kumar K.R | 80e58eb | 2017-07-13 10:37:00 +0530 | [diff] [blame] | 826 | if (IsBT2020(layer_buffer->color_metadata.colorPrimaries)) { |
| 827 | // android_dataspace_t doesnt support mastering display and light levels |
| 828 | // so retrieve it from metadata for BT2020(HDR) |
| 829 | use_color_metadata = true; |
| 830 | } |
| 831 | |
Arun Kumar K.R | 961a28f | 2017-07-07 15:26:30 +0530 | [diff] [blame] | 832 | if (use_color_metadata) { |
| 833 | const private_handle_t *handle = |
| 834 | reinterpret_cast<const private_handle_t *>(layer_buffer->buffer_id); |
| 835 | if (sdm::SetCSC(handle, &layer_buffer->color_metadata) != kErrorNone) { |
Naseer Ahmed | ade4ee6 | 2016-10-07 17:07:38 -0400 | [diff] [blame] | 836 | return false; |
Arun Kumar K.R | 961a28f | 2017-07-07 15:26:30 +0530 | [diff] [blame] | 837 | } |
Naseer Ahmed | ade4ee6 | 2016-10-07 17:07:38 -0400 | [diff] [blame] | 838 | } |
| 839 | |
Naseer Ahmed | ade4ee6 | 2016-10-07 17:07:38 -0400 | [diff] [blame] | 840 | return true; |
| 841 | } |
| 842 | |
| 843 | |
Naseer Ahmed | 89ff452 | 2016-05-17 11:36:27 -0400 | [diff] [blame] | 844 | uint32_t HWCLayer::RoundToStandardFPS(float fps) { |
| 845 | static const uint32_t standard_fps[4] = {24, 30, 48, 60}; |
| 846 | uint32_t frame_rate = (uint32_t)(fps); |
Naseer Ahmed | b92e73f | 2016-03-12 02:03:48 -0500 | [diff] [blame] | 847 | |
| 848 | int count = INT(sizeof(standard_fps) / sizeof(standard_fps[0])); |
| 849 | for (int i = 0; i < count; i++) { |
Naseer Ahmed | 89ff452 | 2016-05-17 11:36:27 -0400 | [diff] [blame] | 850 | if ((standard_fps[i] - frame_rate) < 2) { |
Naseer Ahmed | b92e73f | 2016-03-12 02:03:48 -0500 | [diff] [blame] | 851 | // Most likely used for video, the fps can fluctuate |
| 852 | // Ex: b/w 29 and 30 for 30 fps clip |
| 853 | return standard_fps[i]; |
| 854 | } |
| 855 | } |
| 856 | |
Naseer Ahmed | 89ff452 | 2016-05-17 11:36:27 -0400 | [diff] [blame] | 857 | return frame_rate; |
Naseer Ahmed | b92e73f | 2016-03-12 02:03:48 -0500 | [diff] [blame] | 858 | } |
| 859 | |
Arun Kumar K.R | 2c0ff8d | 2016-06-01 16:56:52 -0700 | [diff] [blame] | 860 | void HWCLayer::SetComposition(const LayerComposition &sdm_composition) { |
| 861 | auto hwc_composition = HWC2::Composition::Invalid; |
| 862 | switch (sdm_composition) { |
Naseer Ahmed | b92e73f | 2016-03-12 02:03:48 -0500 | [diff] [blame] | 863 | case kCompositionGPU: |
Arun Kumar K.R | 2c0ff8d | 2016-06-01 16:56:52 -0700 | [diff] [blame] | 864 | hwc_composition = HWC2::Composition::Client; |
Naseer Ahmed | b92e73f | 2016-03-12 02:03:48 -0500 | [diff] [blame] | 865 | break; |
Saurabh Shah | a4af3de | 2017-04-19 17:15:24 -0700 | [diff] [blame] | 866 | case kCompositionCursor: |
Arun Kumar K.R | 2c0ff8d | 2016-06-01 16:56:52 -0700 | [diff] [blame] | 867 | hwc_composition = HWC2::Composition::Cursor; |
Naseer Ahmed | b92e73f | 2016-03-12 02:03:48 -0500 | [diff] [blame] | 868 | break; |
| 869 | default: |
Arun Kumar K.R | 2c0ff8d | 2016-06-01 16:56:52 -0700 | [diff] [blame] | 870 | hwc_composition = HWC2::Composition::Device; |
Naseer Ahmed | b92e73f | 2016-03-12 02:03:48 -0500 | [diff] [blame] | 871 | break; |
| 872 | } |
| 873 | // Update solid fill composition |
Arun Kumar K.R | 2c0ff8d | 2016-06-01 16:56:52 -0700 | [diff] [blame] | 874 | if (sdm_composition == kCompositionSDE && layer_->flags.solid_fill != 0) { |
| 875 | hwc_composition = HWC2::Composition::SolidColor; |
Naseer Ahmed | b92e73f | 2016-03-12 02:03:48 -0500 | [diff] [blame] | 876 | } |
Arun Kumar K.R | 2c0ff8d | 2016-06-01 16:56:52 -0700 | [diff] [blame] | 877 | device_selected_ = hwc_composition; |
| 878 | |
| 879 | return; |
Naseer Ahmed | b92e73f | 2016-03-12 02:03:48 -0500 | [diff] [blame] | 880 | } |
Ramkumar Radhakrishnan | 00698de | 2018-01-17 11:39:33 -0800 | [diff] [blame] | 881 | |
| 882 | void HWCLayer::PushBackReleaseFence(int32_t fence) { |
| 883 | release_fences_.push_back(fence); |
Naseer Ahmed | b92e73f | 2016-03-12 02:03:48 -0500 | [diff] [blame] | 884 | } |
Ramkumar Radhakrishnan | 00698de | 2018-01-17 11:39:33 -0800 | [diff] [blame] | 885 | |
| 886 | int32_t HWCLayer::PopBackReleaseFence() { |
Naseer Ahmed | b92e73f | 2016-03-12 02:03:48 -0500 | [diff] [blame] | 887 | if (release_fences_.empty()) |
| 888 | return -1; |
Ramkumar Radhakrishnan | 00698de | 2018-01-17 11:39:33 -0800 | [diff] [blame] | 889 | |
| 890 | auto fence = release_fences_.back(); |
| 891 | release_fences_.pop_back(); |
| 892 | |
| 893 | return fence; |
| 894 | } |
| 895 | |
| 896 | int32_t HWCLayer::PopFrontReleaseFence() { |
| 897 | if (release_fences_.empty()) |
| 898 | return -1; |
| 899 | |
Naseer Ahmed | b92e73f | 2016-03-12 02:03:48 -0500 | [diff] [blame] | 900 | auto fence = release_fences_.front(); |
Ramkumar Radhakrishnan | 00698de | 2018-01-17 11:39:33 -0800 | [diff] [blame] | 901 | release_fences_.pop_front(); |
| 902 | |
Naseer Ahmed | b92e73f | 2016-03-12 02:03:48 -0500 | [diff] [blame] | 903 | return fence; |
| 904 | } |
| 905 | |
Ramakant Singh | ae05709 | 2017-08-31 12:34:54 +0530 | [diff] [blame] | 906 | bool HWCLayer::IsRotationPresent() { |
| 907 | return ((layer_->transform.rotation != 0.0f) || |
| 908 | layer_->transform.flip_horizontal || |
| 909 | layer_->transform.flip_vertical); |
| 910 | } |
| 911 | |
| 912 | bool HWCLayer::IsScalingPresent() { |
| 913 | uint32_t src_width = static_cast<uint32_t>(layer_->src_rect.right - layer_->src_rect.left); |
| 914 | uint32_t src_height = static_cast<uint32_t>(layer_->src_rect.bottom - layer_->src_rect.top); |
| 915 | uint32_t dst_width = static_cast<uint32_t>(layer_->dst_rect.right - layer_->dst_rect.left); |
| 916 | uint32_t dst_height = static_cast<uint32_t>(layer_->dst_rect.bottom - layer_->dst_rect.top); |
| 917 | |
| 918 | return ((src_width != dst_width) || (dst_height != src_height)); |
| 919 | } |
| 920 | |
Naseer Ahmed | b92e73f | 2016-03-12 02:03:48 -0500 | [diff] [blame] | 921 | } // namespace sdm |