Naseer Ahmed | b92e73f | 2016-03-12 02:03:48 -0500 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (c) 2014 - 2016, The Linux Foundation. All rights reserved. |
| 3 | * |
| 4 | * Redistribution and use in source and binary forms, with or without |
| 5 | * modification, are permitted provided that the following conditions are |
| 6 | * met: |
| 7 | * * Redistributions of source code must retain the above copyright |
| 8 | * notice, this list of conditions and the following disclaimer. |
| 9 | * * Redistributions in binary form must reproduce the above |
| 10 | * copyright notice, this list of conditions and the following |
| 11 | * disclaimer in the documentation and/or other materials provided |
| 12 | * with the distribution. |
| 13 | * * Neither the name of The Linux Foundation nor the names of its |
| 14 | * contributors may be used to endorse or promote products derived |
| 15 | * from this software without specific prior written permission. |
| 16 | * |
| 17 | * THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESS OR IMPLIED |
| 18 | * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF |
| 19 | * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT |
| 20 | * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS |
| 21 | * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR |
| 22 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF |
| 23 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR |
| 24 | * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, |
| 25 | * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE |
| 26 | * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN |
| 27 | * IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| 28 | */ |
| 29 | |
| 30 | #include <cutils/properties.h> |
| 31 | #include <sync/sync.h> |
| 32 | #include <utils/constants.h> |
| 33 | #include <utils/debug.h> |
| 34 | #include <stdarg.h> |
| 35 | #include <sys/mman.h> |
| 36 | |
Arun Kumar K.R | 29cd658 | 2016-05-10 19:12:45 -0700 | [diff] [blame] | 37 | #include <map> |
| 38 | #include <string> |
| 39 | #include <vector> |
| 40 | |
Naseer Ahmed | b92e73f | 2016-03-12 02:03:48 -0500 | [diff] [blame] | 41 | #include "hwc_display_primary.h" |
| 42 | #include "hwc_debugger.h" |
| 43 | |
| 44 | #define __CLASS__ "HWCDisplayPrimary" |
| 45 | |
| 46 | namespace sdm { |
| 47 | |
| 48 | int HWCDisplayPrimary::Create(CoreInterface *core_intf, BufferAllocator *buffer_allocator, |
| 49 | HWCCallbacks *callbacks, qService::QService *qservice, |
| 50 | HWCDisplay **hwc_display) { |
| 51 | int status = 0; |
| 52 | uint32_t primary_width = 0; |
| 53 | uint32_t primary_height = 0; |
| 54 | |
| 55 | HWCDisplay *hwc_display_primary = |
| 56 | new HWCDisplayPrimary(core_intf, buffer_allocator, callbacks, qservice); |
| 57 | status = hwc_display_primary->Init(); |
| 58 | if (status) { |
| 59 | delete hwc_display_primary; |
| 60 | return status; |
| 61 | } |
| 62 | |
Arun Kumar K.R | 8da7f50 | 2016-06-07 17:45:50 -0700 | [diff] [blame] | 63 | hwc_display_primary->GetMixerResolution(&primary_width, &primary_height); |
Naseer Ahmed | b92e73f | 2016-03-12 02:03:48 -0500 | [diff] [blame] | 64 | int width = 0, height = 0; |
| 65 | HWCDebugHandler::Get()->GetProperty("sdm.fb_size_width", &width); |
| 66 | HWCDebugHandler::Get()->GetProperty("sdm.fb_size_height", &height); |
| 67 | if (width > 0 && height > 0) { |
| 68 | primary_width = UINT32(width); |
| 69 | primary_height = UINT32(height); |
| 70 | } |
| 71 | |
| 72 | status = hwc_display_primary->SetFrameBufferResolution(primary_width, primary_height); |
| 73 | if (status) { |
| 74 | Destroy(hwc_display_primary); |
| 75 | return status; |
| 76 | } |
| 77 | |
| 78 | *hwc_display = hwc_display_primary; |
| 79 | |
| 80 | return status; |
| 81 | } |
| 82 | |
| 83 | void HWCDisplayPrimary::Destroy(HWCDisplay *hwc_display) { |
| 84 | hwc_display->Deinit(); |
| 85 | delete hwc_display; |
| 86 | } |
| 87 | |
| 88 | HWCDisplayPrimary::HWCDisplayPrimary(CoreInterface *core_intf, BufferAllocator *buffer_allocator, |
| 89 | HWCCallbacks *callbacks, qService::QService *qservice) |
| 90 | : HWCDisplay(core_intf, callbacks, kPrimary, HWC_DISPLAY_PRIMARY, true, qservice, |
| 91 | DISPLAY_CLASS_PRIMARY), |
| 92 | buffer_allocator_(buffer_allocator), |
| 93 | cpu_hint_(NULL) { |
| 94 | } |
| 95 | |
| 96 | int HWCDisplayPrimary::Init() { |
| 97 | cpu_hint_ = new CPUHint(); |
| 98 | if (cpu_hint_->Init(static_cast<HWCDebugHandler *>(HWCDebugHandler::Get())) != kErrorNone) { |
| 99 | delete cpu_hint_; |
| 100 | cpu_hint_ = NULL; |
| 101 | } |
| 102 | |
| 103 | use_metadata_refresh_rate_ = true; |
| 104 | int disable_metadata_dynfps = 0; |
| 105 | HWCDebugHandler::Get()->GetProperty("persist.metadata_dynfps.disable", &disable_metadata_dynfps); |
| 106 | if (disable_metadata_dynfps) { |
| 107 | use_metadata_refresh_rate_ = false; |
| 108 | } |
| 109 | |
Arun Kumar K.R | 29cd658 | 2016-05-10 19:12:45 -0700 | [diff] [blame] | 110 | int status = HWCDisplay::Init(); |
| 111 | if (status) { |
| 112 | return status; |
| 113 | } |
| 114 | color_mode_ = new HWCColorMode(display_intf_); |
| 115 | |
| 116 | return INT(color_mode_->Init()); |
Naseer Ahmed | b92e73f | 2016-03-12 02:03:48 -0500 | [diff] [blame] | 117 | } |
| 118 | |
| 119 | void HWCDisplayPrimary::ProcessBootAnimCompleted() { |
| 120 | uint32_t numBootUpLayers = 0; |
| 121 | // TODO(user): Remove this hack |
| 122 | |
| 123 | numBootUpLayers = static_cast<uint32_t>(Debug::GetBootAnimLayerCount()); |
| 124 | |
| 125 | if (numBootUpLayers == 0) { |
| 126 | numBootUpLayers = 2; |
| 127 | } |
| 128 | /* All other checks namely "init.svc.bootanim" or |
| 129 | * HWC_GEOMETRY_CHANGED fail in correctly identifying the |
| 130 | * exact bootup transition to homescreen |
| 131 | */ |
Naseer Ahmed | ac442ae | 2016-06-23 18:58:03 -0400 | [diff] [blame] | 132 | char property[PROPERTY_VALUE_MAX]; |
Naseer Ahmed | b92e73f | 2016-03-12 02:03:48 -0500 | [diff] [blame] | 133 | bool isEncrypted = false; |
| 134 | bool main_class_services_started = false; |
Naseer Ahmed | ac442ae | 2016-06-23 18:58:03 -0400 | [diff] [blame] | 135 | property_get("ro.crypto.state", property, "unencrypted"); |
| 136 | if (!strcmp(property, "encrypted")) { |
| 137 | property_get("ro.crypto.type", property, "block"); |
| 138 | if (!strcmp(property, "block")) { |
Naseer Ahmed | b92e73f | 2016-03-12 02:03:48 -0500 | [diff] [blame] | 139 | isEncrypted = true; |
Naseer Ahmed | ac442ae | 2016-06-23 18:58:03 -0400 | [diff] [blame] | 140 | property_get("vold.decrypt", property, ""); |
| 141 | if (!strcmp(property, "trigger_restart_framework")) { |
Naseer Ahmed | b92e73f | 2016-03-12 02:03:48 -0500 | [diff] [blame] | 142 | main_class_services_started = true; |
Naseer Ahmed | ac442ae | 2016-06-23 18:58:03 -0400 | [diff] [blame] | 143 | } |
Naseer Ahmed | b92e73f | 2016-03-12 02:03:48 -0500 | [diff] [blame] | 144 | } |
| 145 | } |
Naseer Ahmed | ac442ae | 2016-06-23 18:58:03 -0400 | [diff] [blame] | 146 | |
Naseer Ahmed | b92e73f | 2016-03-12 02:03:48 -0500 | [diff] [blame] | 147 | if ((!isEncrypted || (isEncrypted && main_class_services_started)) && |
| 148 | (layer_set_.size() > numBootUpLayers)) { |
Naseer Ahmed | ac442ae | 2016-06-23 18:58:03 -0400 | [diff] [blame] | 149 | DLOGI("Applying default mode"); |
Naseer Ahmed | b92e73f | 2016-03-12 02:03:48 -0500 | [diff] [blame] | 150 | boot_animation_completed_ = true; |
| 151 | // Applying default mode after bootanimation is finished And |
| 152 | // If Data is Encrypted, it is ready for access. |
| 153 | if (display_intf_) |
| 154 | display_intf_->ApplyDefaultDisplayMode(); |
| 155 | } |
| 156 | } |
| 157 | |
| 158 | HWC2::Error HWCDisplayPrimary::Validate(uint32_t *out_num_types, uint32_t *out_num_requests) { |
| 159 | auto status = HWC2::Error::None; |
| 160 | DisplayError error = kErrorNone; |
| 161 | |
| 162 | if (!boot_animation_completed_) |
| 163 | ProcessBootAnimCompleted(); |
| 164 | |
| 165 | if (display_paused_) { |
| 166 | MarkLayersForGPUBypass(); |
| 167 | return status; |
| 168 | } |
| 169 | |
Arun Kumar K.R | 29cd658 | 2016-05-10 19:12:45 -0700 | [diff] [blame] | 170 | if (color_tranform_failed_) { |
| 171 | // Must fall back to client composition |
| 172 | MarkLayersForClientComposition(); |
| 173 | } |
| 174 | |
Naseer Ahmed | b92e73f | 2016-03-12 02:03:48 -0500 | [diff] [blame] | 175 | // Fill in the remaining blanks in the layers and add them to the SDM layerstack |
| 176 | BuildLayerStack(); |
Arun Kumar K.R | 536c7d6 | 2016-06-14 18:47:39 -0700 | [diff] [blame^] | 177 | // Checks and replaces layer stack for solid fill |
| 178 | SolidFillPrepare(); |
Naseer Ahmed | b92e73f | 2016-03-12 02:03:48 -0500 | [diff] [blame] | 179 | |
| 180 | bool pending_output_dump = dump_frame_count_ && dump_output_to_file_; |
| 181 | |
| 182 | if (frame_capture_buffer_queued_ || pending_output_dump) { |
| 183 | // RHS values were set in FrameCaptureAsync() called from a binder thread. They are picked up |
| 184 | // here in a subsequent draw round. |
| 185 | layer_stack_.output_buffer = &output_buffer_; |
| 186 | layer_stack_.flags.post_processed_output = post_processed_output_; |
| 187 | } |
| 188 | |
| 189 | bool one_updating_layer = SingleLayerUpdating(); |
| 190 | ToggleCPUHint(one_updating_layer); |
| 191 | |
| 192 | uint32_t refresh_rate = GetOptimalRefreshRate(one_updating_layer); |
| 193 | if (current_refresh_rate_ != refresh_rate) { |
| 194 | error = display_intf_->SetRefreshRate(refresh_rate); |
| 195 | } |
| 196 | |
| 197 | if (error == kErrorNone) { |
| 198 | // On success, set current refresh rate to new refresh rate |
| 199 | current_refresh_rate_ = refresh_rate; |
| 200 | } |
| 201 | |
| 202 | if (handle_idle_timeout_) { |
| 203 | handle_idle_timeout_ = false; |
| 204 | } |
| 205 | |
Naseer Ahmed | b92e73f | 2016-03-12 02:03:48 -0500 | [diff] [blame] | 206 | if (layer_set_.empty()) { |
| 207 | flush_ = true; |
| 208 | return status; |
| 209 | } |
| 210 | |
| 211 | status = PrepareLayerStack(out_num_types, out_num_requests); |
| 212 | return status; |
| 213 | } |
| 214 | |
| 215 | HWC2::Error HWCDisplayPrimary::Present(int32_t *out_retire_fence) { |
| 216 | auto status = HWC2::Error::None; |
| 217 | if (display_paused_) { |
| 218 | // TODO(user): From old HWC implementation |
| 219 | // If we do not handle the frame set retireFenceFd to outbufAcquireFenceFd |
| 220 | // Revisit this when validating display_paused |
| 221 | DisplayError error = display_intf_->Flush(); |
| 222 | if (error != kErrorNone) { |
| 223 | DLOGE("Flush failed. Error = %d", error); |
| 224 | } |
| 225 | } else { |
| 226 | status = HWCDisplay::CommitLayerStack(); |
| 227 | if (status == HWC2::Error::None) { |
| 228 | HandleFrameOutput(); |
Arun Kumar K.R | 536c7d6 | 2016-06-14 18:47:39 -0700 | [diff] [blame^] | 229 | SolidFillCommit(); |
Naseer Ahmed | b92e73f | 2016-03-12 02:03:48 -0500 | [diff] [blame] | 230 | status = HWCDisplay::PostCommitLayerStack(out_retire_fence); |
| 231 | } |
| 232 | } |
Arun Kumar K.R | 536c7d6 | 2016-06-14 18:47:39 -0700 | [diff] [blame^] | 233 | |
Naseer Ahmed | b92e73f | 2016-03-12 02:03:48 -0500 | [diff] [blame] | 234 | CloseAcquireFds(); |
| 235 | return status; |
| 236 | } |
| 237 | |
Arun Kumar K.R | 29cd658 | 2016-05-10 19:12:45 -0700 | [diff] [blame] | 238 | HWC2::Error HWCDisplayPrimary::GetColorModes(uint32_t *out_num_modes, |
Naseer Ahmed | eae2812 | 2016-06-27 15:47:05 -0400 | [diff] [blame] | 239 | android_color_mode_t *out_modes) { |
Arun Kumar K.R | 29cd658 | 2016-05-10 19:12:45 -0700 | [diff] [blame] | 240 | if (out_modes == nullptr) { |
| 241 | *out_num_modes = color_mode_->GetColorModeCount(); |
| 242 | } else { |
| 243 | color_mode_->GetColorModes(out_num_modes, out_modes); |
| 244 | } |
| 245 | |
| 246 | return HWC2::Error::None; |
| 247 | } |
| 248 | |
Naseer Ahmed | eae2812 | 2016-06-27 15:47:05 -0400 | [diff] [blame] | 249 | HWC2::Error HWCDisplayPrimary::SetColorMode(android_color_mode_t mode) { |
Arun Kumar K.R | 29cd658 | 2016-05-10 19:12:45 -0700 | [diff] [blame] | 250 | auto status = color_mode_->SetColorMode(mode); |
| 251 | if (status != HWC2::Error::None) { |
| 252 | DLOGE("failed for mode = %d", mode); |
| 253 | return status; |
| 254 | } |
| 255 | |
| 256 | callbacks_->Refresh(HWC_DISPLAY_PRIMARY); |
| 257 | |
| 258 | return status; |
| 259 | } |
| 260 | |
| 261 | HWC2::Error HWCDisplayPrimary::SetColorTransform(const float *matrix, |
| 262 | android_color_transform_t hint) { |
| 263 | if (!matrix) { |
| 264 | return HWC2::Error::BadParameter; |
| 265 | } |
| 266 | |
| 267 | auto status = color_mode_->SetColorTransform(matrix, hint); |
| 268 | if (status != HWC2::Error::None) { |
| 269 | DLOGE("failed for hint = %d", hint); |
| 270 | color_tranform_failed_ = true; |
| 271 | return status; |
| 272 | } |
| 273 | |
| 274 | callbacks_->Refresh(HWC_DISPLAY_PRIMARY); |
| 275 | color_tranform_failed_ = false; |
| 276 | |
| 277 | return status; |
| 278 | } |
| 279 | |
Naseer Ahmed | b92e73f | 2016-03-12 02:03:48 -0500 | [diff] [blame] | 280 | int HWCDisplayPrimary::Perform(uint32_t operation, ...) { |
| 281 | va_list args; |
| 282 | va_start(args, operation); |
Arun Kumar K.R | 536c7d6 | 2016-06-14 18:47:39 -0700 | [diff] [blame^] | 283 | int val = 0; |
| 284 | LayerRect *rect = NULL; |
| 285 | |
Naseer Ahmed | b92e73f | 2016-03-12 02:03:48 -0500 | [diff] [blame] | 286 | switch (operation) { |
| 287 | case SET_METADATA_DYN_REFRESH_RATE: |
Arun Kumar K.R | 536c7d6 | 2016-06-14 18:47:39 -0700 | [diff] [blame^] | 288 | val = va_arg(args, int32_t); |
Naseer Ahmed | b92e73f | 2016-03-12 02:03:48 -0500 | [diff] [blame] | 289 | SetMetaDataRefreshRateFlag(val); |
| 290 | break; |
| 291 | case SET_BINDER_DYN_REFRESH_RATE: |
Arun Kumar K.R | 536c7d6 | 2016-06-14 18:47:39 -0700 | [diff] [blame^] | 292 | val = va_arg(args, int32_t); |
Naseer Ahmed | b92e73f | 2016-03-12 02:03:48 -0500 | [diff] [blame] | 293 | ForceRefreshRate(UINT32(val)); |
| 294 | break; |
| 295 | case SET_DISPLAY_MODE: |
Arun Kumar K.R | 536c7d6 | 2016-06-14 18:47:39 -0700 | [diff] [blame^] | 296 | val = va_arg(args, int32_t); |
Naseer Ahmed | b92e73f | 2016-03-12 02:03:48 -0500 | [diff] [blame] | 297 | SetDisplayMode(UINT32(val)); |
| 298 | break; |
| 299 | case SET_QDCM_SOLID_FILL_INFO: |
Arun Kumar K.R | 536c7d6 | 2016-06-14 18:47:39 -0700 | [diff] [blame^] | 300 | val = va_arg(args, int32_t); |
Naseer Ahmed | b92e73f | 2016-03-12 02:03:48 -0500 | [diff] [blame] | 301 | SetQDCMSolidFillInfo(true, UINT32(val)); |
| 302 | break; |
| 303 | case UNSET_QDCM_SOLID_FILL_INFO: |
Arun Kumar K.R | 536c7d6 | 2016-06-14 18:47:39 -0700 | [diff] [blame^] | 304 | val = va_arg(args, int32_t); |
Naseer Ahmed | b92e73f | 2016-03-12 02:03:48 -0500 | [diff] [blame] | 305 | SetQDCMSolidFillInfo(false, UINT32(val)); |
| 306 | break; |
Arun Kumar K.R | 536c7d6 | 2016-06-14 18:47:39 -0700 | [diff] [blame^] | 307 | case SET_QDCM_SOLID_FILL_RECT: |
| 308 | rect = va_arg(args, LayerRect*); |
| 309 | solid_fill_rect_ = *rect; |
| 310 | break; |
Naseer Ahmed | b92e73f | 2016-03-12 02:03:48 -0500 | [diff] [blame] | 311 | default: |
| 312 | DLOGW("Invalid operation %d", operation); |
Arun Kumar K.R | 536c7d6 | 2016-06-14 18:47:39 -0700 | [diff] [blame^] | 313 | va_end(args); |
Naseer Ahmed | b92e73f | 2016-03-12 02:03:48 -0500 | [diff] [blame] | 314 | return -EINVAL; |
| 315 | } |
Arun Kumar K.R | 536c7d6 | 2016-06-14 18:47:39 -0700 | [diff] [blame^] | 316 | va_end(args); |
Naseer Ahmed | b92e73f | 2016-03-12 02:03:48 -0500 | [diff] [blame] | 317 | |
| 318 | return 0; |
| 319 | } |
| 320 | |
| 321 | DisplayError HWCDisplayPrimary::SetDisplayMode(uint32_t mode) { |
| 322 | DisplayError error = kErrorNone; |
| 323 | |
| 324 | if (display_intf_) { |
| 325 | error = display_intf_->SetDisplayMode(mode); |
| 326 | } |
| 327 | |
| 328 | return error; |
| 329 | } |
| 330 | |
| 331 | void HWCDisplayPrimary::SetMetaDataRefreshRateFlag(bool enable) { |
| 332 | int disable_metadata_dynfps = 0; |
| 333 | |
| 334 | HWCDebugHandler::Get()->GetProperty("persist.metadata_dynfps.disable", &disable_metadata_dynfps); |
| 335 | if (disable_metadata_dynfps) { |
| 336 | return; |
| 337 | } |
| 338 | use_metadata_refresh_rate_ = enable; |
| 339 | } |
| 340 | |
| 341 | void HWCDisplayPrimary::SetQDCMSolidFillInfo(bool enable, uint32_t color) { |
| 342 | solid_fill_enable_ = enable; |
| 343 | solid_fill_color_ = color; |
| 344 | } |
| 345 | |
| 346 | void HWCDisplayPrimary::ToggleCPUHint(bool set) { |
| 347 | if (!cpu_hint_) { |
| 348 | return; |
| 349 | } |
| 350 | |
| 351 | if (set) { |
| 352 | cpu_hint_->Set(); |
| 353 | } else { |
| 354 | cpu_hint_->Reset(); |
| 355 | } |
| 356 | } |
| 357 | |
| 358 | void HWCDisplayPrimary::SetSecureDisplay(bool secure_display_active) { |
| 359 | if (secure_display_active_ != secure_display_active) { |
| 360 | // Skip Prepare and call Flush for null commit |
| 361 | DLOGI("SecureDisplay state changed from %d to %d Needs Flush!!", secure_display_active_, |
| 362 | secure_display_active); |
| 363 | secure_display_active_ = secure_display_active; |
| 364 | skip_prepare_ = true; |
| 365 | } |
| 366 | return; |
| 367 | } |
| 368 | |
| 369 | void HWCDisplayPrimary::ForceRefreshRate(uint32_t refresh_rate) { |
| 370 | if ((refresh_rate && (refresh_rate < min_refresh_rate_ || refresh_rate > max_refresh_rate_)) || |
| 371 | force_refresh_rate_ == refresh_rate) { |
| 372 | // Cannot honor force refresh rate, as its beyond the range or new request is same |
| 373 | return; |
| 374 | } |
| 375 | |
| 376 | force_refresh_rate_ = refresh_rate; |
| 377 | |
| 378 | callbacks_->Refresh(HWC_DISPLAY_PRIMARY); |
| 379 | |
| 380 | return; |
| 381 | } |
| 382 | |
| 383 | uint32_t HWCDisplayPrimary::GetOptimalRefreshRate(bool one_updating_layer) { |
| 384 | if (force_refresh_rate_) { |
| 385 | return force_refresh_rate_; |
| 386 | } else if (handle_idle_timeout_) { |
| 387 | return min_refresh_rate_; |
| 388 | } else if (use_metadata_refresh_rate_ && one_updating_layer && metadata_refresh_rate_) { |
| 389 | return metadata_refresh_rate_; |
| 390 | } |
| 391 | |
| 392 | return max_refresh_rate_; |
| 393 | } |
| 394 | |
| 395 | DisplayError HWCDisplayPrimary::Refresh() { |
| 396 | DisplayError error = kErrorNone; |
| 397 | |
| 398 | callbacks_->Refresh(HWC_DISPLAY_PRIMARY); |
| 399 | handle_idle_timeout_ = true; |
| 400 | |
| 401 | return error; |
| 402 | } |
| 403 | |
| 404 | void HWCDisplayPrimary::SetIdleTimeoutMs(uint32_t timeout_ms) { |
| 405 | display_intf_->SetIdleTimeoutMs(timeout_ms); |
| 406 | } |
| 407 | |
| 408 | static void SetLayerBuffer(const BufferInfo &output_buffer_info, LayerBuffer *output_buffer) { |
| 409 | output_buffer->width = output_buffer_info.buffer_config.width; |
| 410 | output_buffer->height = output_buffer_info.buffer_config.height; |
| 411 | output_buffer->format = output_buffer_info.buffer_config.format; |
| 412 | output_buffer->planes[0].fd = output_buffer_info.alloc_buffer_info.fd; |
| 413 | output_buffer->planes[0].stride = output_buffer_info.alloc_buffer_info.stride; |
| 414 | } |
| 415 | |
| 416 | void HWCDisplayPrimary::HandleFrameOutput() { |
| 417 | if (frame_capture_buffer_queued_) { |
| 418 | HandleFrameCapture(); |
| 419 | } else if (dump_output_to_file_) { |
| 420 | HandleFrameDump(); |
| 421 | } |
| 422 | } |
| 423 | |
| 424 | void HWCDisplayPrimary::HandleFrameCapture() { |
| 425 | if (output_buffer_.release_fence_fd >= 0) { |
| 426 | frame_capture_status_ = sync_wait(output_buffer_.release_fence_fd, 1000); |
| 427 | ::close(output_buffer_.release_fence_fd); |
| 428 | output_buffer_.release_fence_fd = -1; |
| 429 | } |
| 430 | |
| 431 | frame_capture_buffer_queued_ = false; |
| 432 | post_processed_output_ = false; |
| 433 | output_buffer_ = {}; |
Naseer Ahmed | b92e73f | 2016-03-12 02:03:48 -0500 | [diff] [blame] | 434 | } |
| 435 | |
| 436 | void HWCDisplayPrimary::HandleFrameDump() { |
| 437 | if (dump_frame_count_ && output_buffer_.release_fence_fd >= 0) { |
| 438 | int ret = sync_wait(output_buffer_.release_fence_fd, 1000); |
| 439 | ::close(output_buffer_.release_fence_fd); |
| 440 | output_buffer_.release_fence_fd = -1; |
| 441 | if (ret < 0) { |
| 442 | DLOGE("sync_wait error errno = %d, desc = %s", errno, strerror(errno)); |
| 443 | } else { |
| 444 | DumpOutputBuffer(output_buffer_info_, output_buffer_base_, layer_stack_.retire_fence_fd); |
| 445 | } |
| 446 | } |
| 447 | |
| 448 | if (0 == dump_frame_count_) { |
| 449 | dump_output_to_file_ = false; |
| 450 | // Unmap and Free buffer |
| 451 | if (munmap(output_buffer_base_, output_buffer_info_.alloc_buffer_info.size) != 0) { |
| 452 | DLOGE("unmap failed with err %d", errno); |
| 453 | } |
| 454 | if (buffer_allocator_->FreeBuffer(&output_buffer_info_) != 0) { |
| 455 | DLOGE("FreeBuffer failed"); |
| 456 | } |
| 457 | |
| 458 | post_processed_output_ = false; |
| 459 | output_buffer_ = {}; |
| 460 | output_buffer_info_ = {}; |
| 461 | output_buffer_base_ = nullptr; |
Naseer Ahmed | b92e73f | 2016-03-12 02:03:48 -0500 | [diff] [blame] | 462 | } |
| 463 | } |
| 464 | |
| 465 | void HWCDisplayPrimary::SetFrameDumpConfig(uint32_t count, uint32_t bit_mask_layer_type) { |
| 466 | HWCDisplay::SetFrameDumpConfig(count, bit_mask_layer_type); |
| 467 | dump_output_to_file_ = bit_mask_layer_type & (1 << OUTPUT_LAYER_DUMP); |
| 468 | DLOGI("output_layer_dump_enable %d", dump_output_to_file_); |
| 469 | |
| 470 | if (!count || !dump_output_to_file_) { |
| 471 | return; |
| 472 | } |
| 473 | |
| 474 | // Allocate and map output buffer |
| 475 | output_buffer_info_ = {}; |
| 476 | // Since we dump DSPP output use Panel resolution. |
| 477 | GetPanelResolution(&output_buffer_info_.buffer_config.width, |
| 478 | &output_buffer_info_.buffer_config.height); |
| 479 | output_buffer_info_.buffer_config.format = kFormatRGB888; |
| 480 | output_buffer_info_.buffer_config.buffer_count = 1; |
| 481 | if (buffer_allocator_->AllocateBuffer(&output_buffer_info_) != 0) { |
| 482 | DLOGE("Buffer allocation failed"); |
| 483 | output_buffer_info_ = {}; |
| 484 | return; |
| 485 | } |
| 486 | |
| 487 | void *buffer = mmap(NULL, output_buffer_info_.alloc_buffer_info.size, PROT_READ | PROT_WRITE, |
| 488 | MAP_SHARED, output_buffer_info_.alloc_buffer_info.fd, 0); |
| 489 | |
| 490 | if (buffer == MAP_FAILED) { |
| 491 | DLOGE("mmap failed with err %d", errno); |
| 492 | buffer_allocator_->FreeBuffer(&output_buffer_info_); |
| 493 | output_buffer_info_ = {}; |
| 494 | return; |
| 495 | } |
| 496 | |
| 497 | output_buffer_base_ = buffer; |
| 498 | post_processed_output_ = true; |
Arun Kumar K.R | 17bbd04 | 2016-06-07 17:38:02 -0700 | [diff] [blame] | 499 | DisablePartialUpdateOneFrame(); |
Naseer Ahmed | b92e73f | 2016-03-12 02:03:48 -0500 | [diff] [blame] | 500 | } |
| 501 | |
| 502 | int HWCDisplayPrimary::FrameCaptureAsync(const BufferInfo &output_buffer_info, |
| 503 | bool post_processed_output) { |
| 504 | // Note: This function is called in context of a binder thread and a lock is already held |
| 505 | if (output_buffer_info.alloc_buffer_info.fd < 0) { |
| 506 | DLOGE("Invalid fd %d", output_buffer_info.alloc_buffer_info.fd); |
| 507 | return -1; |
| 508 | } |
| 509 | |
| 510 | auto panel_width = 0u; |
| 511 | auto panel_height = 0u; |
| 512 | auto fb_width = 0u; |
| 513 | auto fb_height = 0u; |
| 514 | |
| 515 | GetPanelResolution(&panel_width, &panel_height); |
| 516 | GetFrameBufferResolution(&fb_width, &fb_height); |
| 517 | |
| 518 | if (post_processed_output && (output_buffer_info_.buffer_config.width < panel_width || |
| 519 | output_buffer_info_.buffer_config.height < panel_height)) { |
| 520 | DLOGE("Buffer dimensions should not be less than panel resolution"); |
| 521 | return -1; |
| 522 | } else if (!post_processed_output && (output_buffer_info_.buffer_config.width < fb_width || |
| 523 | output_buffer_info_.buffer_config.height < fb_height)) { |
| 524 | DLOGE("Buffer dimensions should not be less than FB resolution"); |
| 525 | return -1; |
| 526 | } |
| 527 | |
| 528 | SetLayerBuffer(output_buffer_info, &output_buffer_); |
| 529 | post_processed_output_ = post_processed_output; |
| 530 | frame_capture_buffer_queued_ = true; |
| 531 | // Status is only cleared on a new call to dump and remains valid otherwise |
| 532 | frame_capture_status_ = -EAGAIN; |
Arun Kumar K.R | 17bbd04 | 2016-06-07 17:38:02 -0700 | [diff] [blame] | 533 | DisablePartialUpdateOneFrame(); |
Naseer Ahmed | b92e73f | 2016-03-12 02:03:48 -0500 | [diff] [blame] | 534 | |
| 535 | return 0; |
| 536 | } |
| 537 | |
Arun Kumar K.R | 17bbd04 | 2016-06-07 17:38:02 -0700 | [diff] [blame] | 538 | DisplayError HWCDisplayPrimary::ControlPartialUpdate(bool enable, uint32_t *pending) { |
| 539 | DisplayError error = kErrorNone; |
| 540 | |
| 541 | if (display_intf_) { |
| 542 | error = display_intf_->ControlPartialUpdate(enable, pending); |
| 543 | } |
| 544 | |
| 545 | return error; |
| 546 | } |
| 547 | |
| 548 | DisplayError HWCDisplayPrimary::DisablePartialUpdateOneFrame() { |
| 549 | DisplayError error = kErrorNone; |
| 550 | |
| 551 | if (display_intf_) { |
| 552 | error = display_intf_->DisablePartialUpdateOneFrame(); |
| 553 | } |
| 554 | |
| 555 | return error; |
| 556 | } |
| 557 | |
| 558 | |
Arun Kumar K.R | 8da7f50 | 2016-06-07 17:45:50 -0700 | [diff] [blame] | 559 | DisplayError HWCDisplayPrimary::SetMixerResolution(uint32_t width, uint32_t height) { |
| 560 | return display_intf_->SetMixerResolution(width, height); |
| 561 | } |
| 562 | |
| 563 | DisplayError HWCDisplayPrimary::GetMixerResolution(uint32_t *width, uint32_t *height) { |
| 564 | return display_intf_->GetMixerResolution(width, height); |
| 565 | } |
| 566 | |
Naseer Ahmed | b92e73f | 2016-03-12 02:03:48 -0500 | [diff] [blame] | 567 | } // namespace sdm |