Naseer Ahmed | b92e73f | 2016-03-12 02:03:48 -0500 | [diff] [blame] | 1 | /* |
Naseer Ahmed | 61f6095 | 2017-05-24 16:48:35 -0400 | [diff] [blame] | 2 | * Copyright (c) 2014 - 2017, The Linux Foundation. All rights reserved. |
Naseer Ahmed | b92e73f | 2016-03-12 02:03:48 -0500 | [diff] [blame] | 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, |
Naseer Ahmed | d183040 | 2017-03-01 18:38:12 -0500 | [diff] [blame] | 91 | DISPLAY_CLASS_PRIMARY, buffer_allocator), |
Naseer Ahmed | b92e73f | 2016-03-12 02:03:48 -0500 | [diff] [blame] | 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_); |
Naseer Ahmed | 61f6095 | 2017-05-24 16:48:35 -0400 | [diff] [blame] | 115 | color_mode_->Init(); |
Ch Ganesh Kumar | 86c4651 | 2017-06-13 13:09:22 +0530 | [diff] [blame] | 116 | HWCDebugHandler::Get()->GetProperty("vendor.display.enable_default_color_mode", |
| 117 | &default_mode_status_); |
Arun Kumar K.R | 29cd658 | 2016-05-10 19:12:45 -0700 | [diff] [blame] | 118 | |
Naseer Ahmed | 61f6095 | 2017-05-24 16:48:35 -0400 | [diff] [blame] | 119 | return status; |
Naseer Ahmed | b92e73f | 2016-03-12 02:03:48 -0500 | [diff] [blame] | 120 | } |
| 121 | |
| 122 | void HWCDisplayPrimary::ProcessBootAnimCompleted() { |
| 123 | uint32_t numBootUpLayers = 0; |
| 124 | // TODO(user): Remove this hack |
| 125 | |
| 126 | numBootUpLayers = static_cast<uint32_t>(Debug::GetBootAnimLayerCount()); |
| 127 | |
| 128 | if (numBootUpLayers == 0) { |
| 129 | numBootUpLayers = 2; |
| 130 | } |
| 131 | /* All other checks namely "init.svc.bootanim" or |
| 132 | * HWC_GEOMETRY_CHANGED fail in correctly identifying the |
| 133 | * exact bootup transition to homescreen |
| 134 | */ |
Naseer Ahmed | ac442ae | 2016-06-23 18:58:03 -0400 | [diff] [blame] | 135 | char property[PROPERTY_VALUE_MAX]; |
Naseer Ahmed | b92e73f | 2016-03-12 02:03:48 -0500 | [diff] [blame] | 136 | bool isEncrypted = false; |
| 137 | bool main_class_services_started = false; |
Naseer Ahmed | ac442ae | 2016-06-23 18:58:03 -0400 | [diff] [blame] | 138 | property_get("ro.crypto.state", property, "unencrypted"); |
| 139 | if (!strcmp(property, "encrypted")) { |
| 140 | property_get("ro.crypto.type", property, "block"); |
| 141 | if (!strcmp(property, "block")) { |
Naseer Ahmed | b92e73f | 2016-03-12 02:03:48 -0500 | [diff] [blame] | 142 | isEncrypted = true; |
Naseer Ahmed | ac442ae | 2016-06-23 18:58:03 -0400 | [diff] [blame] | 143 | property_get("vold.decrypt", property, ""); |
| 144 | if (!strcmp(property, "trigger_restart_framework")) { |
Naseer Ahmed | b92e73f | 2016-03-12 02:03:48 -0500 | [diff] [blame] | 145 | main_class_services_started = true; |
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 | } |
| 148 | } |
Naseer Ahmed | ac442ae | 2016-06-23 18:58:03 -0400 | [diff] [blame] | 149 | |
Naseer Ahmed | b92e73f | 2016-03-12 02:03:48 -0500 | [diff] [blame] | 150 | if ((!isEncrypted || (isEncrypted && main_class_services_started)) && |
| 151 | (layer_set_.size() > numBootUpLayers)) { |
Naseer Ahmed | ac442ae | 2016-06-23 18:58:03 -0400 | [diff] [blame] | 152 | DLOGI("Applying default mode"); |
Naseer Ahmed | b92e73f | 2016-03-12 02:03:48 -0500 | [diff] [blame] | 153 | boot_animation_completed_ = true; |
| 154 | // Applying default mode after bootanimation is finished And |
| 155 | // If Data is Encrypted, it is ready for access. |
| 156 | if (display_intf_) |
| 157 | display_intf_->ApplyDefaultDisplayMode(); |
| 158 | } |
| 159 | } |
| 160 | |
| 161 | HWC2::Error HWCDisplayPrimary::Validate(uint32_t *out_num_types, uint32_t *out_num_requests) { |
| 162 | auto status = HWC2::Error::None; |
| 163 | DisplayError error = kErrorNone; |
| 164 | |
Ch Ganesh Kumar | 86c4651 | 2017-06-13 13:09:22 +0530 | [diff] [blame] | 165 | if (default_mode_status_ && !boot_animation_completed_) { |
| 166 | ProcessBootAnimCompleted(); |
| 167 | } |
| 168 | |
Naseer Ahmed | b92e73f | 2016-03-12 02:03:48 -0500 | [diff] [blame] | 169 | if (display_paused_) { |
| 170 | MarkLayersForGPUBypass(); |
| 171 | return status; |
| 172 | } |
| 173 | |
Arun Kumar K.R | 29cd658 | 2016-05-10 19:12:45 -0700 | [diff] [blame] | 174 | if (color_tranform_failed_) { |
| 175 | // Must fall back to client composition |
| 176 | MarkLayersForClientComposition(); |
| 177 | } |
| 178 | |
Naseer Ahmed | b92e73f | 2016-03-12 02:03:48 -0500 | [diff] [blame] | 179 | // Fill in the remaining blanks in the layers and add them to the SDM layerstack |
| 180 | BuildLayerStack(); |
Arun Kumar K.R | 536c7d6 | 2016-06-14 18:47:39 -0700 | [diff] [blame] | 181 | // Checks and replaces layer stack for solid fill |
| 182 | SolidFillPrepare(); |
Naseer Ahmed | b92e73f | 2016-03-12 02:03:48 -0500 | [diff] [blame] | 183 | |
| 184 | bool pending_output_dump = dump_frame_count_ && dump_output_to_file_; |
| 185 | |
| 186 | if (frame_capture_buffer_queued_ || pending_output_dump) { |
| 187 | // RHS values were set in FrameCaptureAsync() called from a binder thread. They are picked up |
| 188 | // here in a subsequent draw round. |
| 189 | layer_stack_.output_buffer = &output_buffer_; |
| 190 | layer_stack_.flags.post_processed_output = post_processed_output_; |
| 191 | } |
| 192 | |
Ramakant Singh | 5db0dfb | 2017-08-23 12:34:57 +0530 | [diff] [blame^] | 193 | uint32_t num_updating_layers = GetUpdatingLayersCount(); |
| 194 | bool one_updating_layer = (num_updating_layers == 1); |
| 195 | if (num_updating_layers != 0) { |
| 196 | ToggleCPUHint(one_updating_layer); |
| 197 | } |
Naseer Ahmed | b92e73f | 2016-03-12 02:03:48 -0500 | [diff] [blame] | 198 | |
| 199 | uint32_t refresh_rate = GetOptimalRefreshRate(one_updating_layer); |
Anjaneya Prasad Musunuri | 4d65df7 | 2017-05-18 19:11:28 +0530 | [diff] [blame] | 200 | bool final_rate = force_refresh_rate_ ? true : false; |
| 201 | error = display_intf_->SetRefreshRate(refresh_rate, final_rate); |
Naseer Ahmed | b92e73f | 2016-03-12 02:03:48 -0500 | [diff] [blame] | 202 | if (error == kErrorNone) { |
| 203 | // On success, set current refresh rate to new refresh rate |
| 204 | current_refresh_rate_ = refresh_rate; |
| 205 | } |
| 206 | |
Naseer Ahmed | b92e73f | 2016-03-12 02:03:48 -0500 | [diff] [blame] | 207 | if (layer_set_.empty()) { |
| 208 | flush_ = true; |
| 209 | return status; |
| 210 | } |
| 211 | |
| 212 | status = PrepareLayerStack(out_num_types, out_num_requests); |
| 213 | return status; |
| 214 | } |
| 215 | |
| 216 | HWC2::Error HWCDisplayPrimary::Present(int32_t *out_retire_fence) { |
| 217 | auto status = HWC2::Error::None; |
| 218 | if (display_paused_) { |
| 219 | // TODO(user): From old HWC implementation |
| 220 | // If we do not handle the frame set retireFenceFd to outbufAcquireFenceFd |
| 221 | // Revisit this when validating display_paused |
| 222 | DisplayError error = display_intf_->Flush(); |
Sushil Chauhan | 409e844 | 2017-06-12 17:43:25 -0700 | [diff] [blame] | 223 | validated_.reset(); |
Naseer Ahmed | b92e73f | 2016-03-12 02:03:48 -0500 | [diff] [blame] | 224 | if (error != kErrorNone) { |
| 225 | DLOGE("Flush failed. Error = %d", error); |
| 226 | } |
| 227 | } else { |
| 228 | status = HWCDisplay::CommitLayerStack(); |
| 229 | if (status == HWC2::Error::None) { |
| 230 | HandleFrameOutput(); |
Arun Kumar K.R | 536c7d6 | 2016-06-14 18:47:39 -0700 | [diff] [blame] | 231 | SolidFillCommit(); |
Naseer Ahmed | b92e73f | 2016-03-12 02:03:48 -0500 | [diff] [blame] | 232 | status = HWCDisplay::PostCommitLayerStack(out_retire_fence); |
| 233 | } |
| 234 | } |
Arun Kumar K.R | 536c7d6 | 2016-06-14 18:47:39 -0700 | [diff] [blame] | 235 | |
Naseer Ahmed | b92e73f | 2016-03-12 02:03:48 -0500 | [diff] [blame] | 236 | CloseAcquireFds(); |
| 237 | return status; |
| 238 | } |
| 239 | |
Arun Kumar K.R | 29cd658 | 2016-05-10 19:12:45 -0700 | [diff] [blame] | 240 | HWC2::Error HWCDisplayPrimary::GetColorModes(uint32_t *out_num_modes, |
Naseer Ahmed | eae2812 | 2016-06-27 15:47:05 -0400 | [diff] [blame] | 241 | android_color_mode_t *out_modes) { |
Arun Kumar K.R | 29cd658 | 2016-05-10 19:12:45 -0700 | [diff] [blame] | 242 | if (out_modes == nullptr) { |
| 243 | *out_num_modes = color_mode_->GetColorModeCount(); |
| 244 | } else { |
| 245 | color_mode_->GetColorModes(out_num_modes, out_modes); |
| 246 | } |
| 247 | |
| 248 | return HWC2::Error::None; |
| 249 | } |
| 250 | |
Naseer Ahmed | eae2812 | 2016-06-27 15:47:05 -0400 | [diff] [blame] | 251 | HWC2::Error HWCDisplayPrimary::SetColorMode(android_color_mode_t mode) { |
Arun Kumar K.R | 29cd658 | 2016-05-10 19:12:45 -0700 | [diff] [blame] | 252 | auto status = color_mode_->SetColorMode(mode); |
| 253 | if (status != HWC2::Error::None) { |
| 254 | DLOGE("failed for mode = %d", mode); |
| 255 | return status; |
| 256 | } |
| 257 | |
| 258 | callbacks_->Refresh(HWC_DISPLAY_PRIMARY); |
Sushil Chauhan | 409e844 | 2017-06-12 17:43:25 -0700 | [diff] [blame] | 259 | validated_.reset(); |
Arun Kumar K.R | 29cd658 | 2016-05-10 19:12:45 -0700 | [diff] [blame] | 260 | |
| 261 | return status; |
| 262 | } |
| 263 | |
Naseer Ahmed | 6776dae | 2017-05-09 11:49:41 -0400 | [diff] [blame] | 264 | HWC2::Error HWCDisplayPrimary::SetColorModeById(int32_t color_mode_id) { |
| 265 | auto status = color_mode_->SetColorModeById(color_mode_id); |
| 266 | if (status != HWC2::Error::None) { |
| 267 | DLOGE("failed for mode = %d", color_mode_id); |
| 268 | return status; |
| 269 | } |
| 270 | |
| 271 | callbacks_->Refresh(HWC_DISPLAY_PRIMARY); |
Sushil Chauhan | 409e844 | 2017-06-12 17:43:25 -0700 | [diff] [blame] | 272 | validated_.reset(); |
Naseer Ahmed | 6776dae | 2017-05-09 11:49:41 -0400 | [diff] [blame] | 273 | |
| 274 | return status; |
| 275 | } |
| 276 | |
Arun Kumar K.R | 29cd658 | 2016-05-10 19:12:45 -0700 | [diff] [blame] | 277 | HWC2::Error HWCDisplayPrimary::SetColorTransform(const float *matrix, |
| 278 | android_color_transform_t hint) { |
| 279 | if (!matrix) { |
| 280 | return HWC2::Error::BadParameter; |
| 281 | } |
| 282 | |
| 283 | auto status = color_mode_->SetColorTransform(matrix, hint); |
| 284 | if (status != HWC2::Error::None) { |
| 285 | DLOGE("failed for hint = %d", hint); |
| 286 | color_tranform_failed_ = true; |
| 287 | return status; |
| 288 | } |
| 289 | |
| 290 | callbacks_->Refresh(HWC_DISPLAY_PRIMARY); |
| 291 | color_tranform_failed_ = false; |
Sushil Chauhan | 409e844 | 2017-06-12 17:43:25 -0700 | [diff] [blame] | 292 | validated_.reset(); |
Arun Kumar K.R | 29cd658 | 2016-05-10 19:12:45 -0700 | [diff] [blame] | 293 | |
| 294 | return status; |
| 295 | } |
| 296 | |
Naseer Ahmed | b92e73f | 2016-03-12 02:03:48 -0500 | [diff] [blame] | 297 | int HWCDisplayPrimary::Perform(uint32_t operation, ...) { |
| 298 | va_list args; |
| 299 | va_start(args, operation); |
Arun Kumar K.R | 536c7d6 | 2016-06-14 18:47:39 -0700 | [diff] [blame] | 300 | int val = 0; |
| 301 | LayerRect *rect = NULL; |
| 302 | |
Naseer Ahmed | b92e73f | 2016-03-12 02:03:48 -0500 | [diff] [blame] | 303 | switch (operation) { |
| 304 | case SET_METADATA_DYN_REFRESH_RATE: |
Arun Kumar K.R | 536c7d6 | 2016-06-14 18:47:39 -0700 | [diff] [blame] | 305 | val = va_arg(args, int32_t); |
Naseer Ahmed | b92e73f | 2016-03-12 02:03:48 -0500 | [diff] [blame] | 306 | SetMetaDataRefreshRateFlag(val); |
| 307 | break; |
| 308 | case SET_BINDER_DYN_REFRESH_RATE: |
Arun Kumar K.R | 536c7d6 | 2016-06-14 18:47:39 -0700 | [diff] [blame] | 309 | val = va_arg(args, int32_t); |
Naseer Ahmed | b92e73f | 2016-03-12 02:03:48 -0500 | [diff] [blame] | 310 | ForceRefreshRate(UINT32(val)); |
| 311 | break; |
| 312 | case SET_DISPLAY_MODE: |
Arun Kumar K.R | 536c7d6 | 2016-06-14 18:47:39 -0700 | [diff] [blame] | 313 | val = va_arg(args, int32_t); |
Naseer Ahmed | b92e73f | 2016-03-12 02:03:48 -0500 | [diff] [blame] | 314 | SetDisplayMode(UINT32(val)); |
| 315 | break; |
| 316 | case SET_QDCM_SOLID_FILL_INFO: |
Arun Kumar K.R | 536c7d6 | 2016-06-14 18:47:39 -0700 | [diff] [blame] | 317 | val = va_arg(args, int32_t); |
Naseer Ahmed | b92e73f | 2016-03-12 02:03:48 -0500 | [diff] [blame] | 318 | SetQDCMSolidFillInfo(true, UINT32(val)); |
| 319 | break; |
| 320 | case UNSET_QDCM_SOLID_FILL_INFO: |
Arun Kumar K.R | 536c7d6 | 2016-06-14 18:47:39 -0700 | [diff] [blame] | 321 | val = va_arg(args, int32_t); |
Naseer Ahmed | b92e73f | 2016-03-12 02:03:48 -0500 | [diff] [blame] | 322 | SetQDCMSolidFillInfo(false, UINT32(val)); |
| 323 | break; |
Arun Kumar K.R | 536c7d6 | 2016-06-14 18:47:39 -0700 | [diff] [blame] | 324 | case SET_QDCM_SOLID_FILL_RECT: |
| 325 | rect = va_arg(args, LayerRect*); |
| 326 | solid_fill_rect_ = *rect; |
| 327 | break; |
Naseer Ahmed | b92e73f | 2016-03-12 02:03:48 -0500 | [diff] [blame] | 328 | default: |
| 329 | DLOGW("Invalid operation %d", operation); |
Arun Kumar K.R | 536c7d6 | 2016-06-14 18:47:39 -0700 | [diff] [blame] | 330 | va_end(args); |
Naseer Ahmed | b92e73f | 2016-03-12 02:03:48 -0500 | [diff] [blame] | 331 | return -EINVAL; |
| 332 | } |
Arun Kumar K.R | 536c7d6 | 2016-06-14 18:47:39 -0700 | [diff] [blame] | 333 | va_end(args); |
Sushil Chauhan | 409e844 | 2017-06-12 17:43:25 -0700 | [diff] [blame] | 334 | validated_.reset(); |
Naseer Ahmed | b92e73f | 2016-03-12 02:03:48 -0500 | [diff] [blame] | 335 | |
| 336 | return 0; |
| 337 | } |
| 338 | |
| 339 | DisplayError HWCDisplayPrimary::SetDisplayMode(uint32_t mode) { |
| 340 | DisplayError error = kErrorNone; |
| 341 | |
| 342 | if (display_intf_) { |
| 343 | error = display_intf_->SetDisplayMode(mode); |
| 344 | } |
| 345 | |
| 346 | return error; |
| 347 | } |
| 348 | |
| 349 | void HWCDisplayPrimary::SetMetaDataRefreshRateFlag(bool enable) { |
| 350 | int disable_metadata_dynfps = 0; |
| 351 | |
| 352 | HWCDebugHandler::Get()->GetProperty("persist.metadata_dynfps.disable", &disable_metadata_dynfps); |
| 353 | if (disable_metadata_dynfps) { |
| 354 | return; |
| 355 | } |
| 356 | use_metadata_refresh_rate_ = enable; |
| 357 | } |
| 358 | |
| 359 | void HWCDisplayPrimary::SetQDCMSolidFillInfo(bool enable, uint32_t color) { |
| 360 | solid_fill_enable_ = enable; |
| 361 | solid_fill_color_ = color; |
| 362 | } |
| 363 | |
| 364 | void HWCDisplayPrimary::ToggleCPUHint(bool set) { |
| 365 | if (!cpu_hint_) { |
| 366 | return; |
| 367 | } |
| 368 | |
| 369 | if (set) { |
| 370 | cpu_hint_->Set(); |
| 371 | } else { |
| 372 | cpu_hint_->Reset(); |
| 373 | } |
| 374 | } |
| 375 | |
| 376 | void HWCDisplayPrimary::SetSecureDisplay(bool secure_display_active) { |
| 377 | if (secure_display_active_ != secure_display_active) { |
| 378 | // Skip Prepare and call Flush for null commit |
| 379 | DLOGI("SecureDisplay state changed from %d to %d Needs Flush!!", secure_display_active_, |
| 380 | secure_display_active); |
| 381 | secure_display_active_ = secure_display_active; |
| 382 | skip_prepare_ = true; |
| 383 | } |
| 384 | return; |
| 385 | } |
| 386 | |
| 387 | void HWCDisplayPrimary::ForceRefreshRate(uint32_t refresh_rate) { |
| 388 | if ((refresh_rate && (refresh_rate < min_refresh_rate_ || refresh_rate > max_refresh_rate_)) || |
| 389 | force_refresh_rate_ == refresh_rate) { |
| 390 | // Cannot honor force refresh rate, as its beyond the range or new request is same |
| 391 | return; |
| 392 | } |
| 393 | |
| 394 | force_refresh_rate_ = refresh_rate; |
| 395 | |
| 396 | callbacks_->Refresh(HWC_DISPLAY_PRIMARY); |
| 397 | |
| 398 | return; |
| 399 | } |
| 400 | |
| 401 | uint32_t HWCDisplayPrimary::GetOptimalRefreshRate(bool one_updating_layer) { |
| 402 | if (force_refresh_rate_) { |
| 403 | return force_refresh_rate_; |
Naseer Ahmed | b92e73f | 2016-03-12 02:03:48 -0500 | [diff] [blame] | 404 | } else if (use_metadata_refresh_rate_ && one_updating_layer && metadata_refresh_rate_) { |
| 405 | return metadata_refresh_rate_; |
| 406 | } |
| 407 | |
| 408 | return max_refresh_rate_; |
| 409 | } |
| 410 | |
| 411 | DisplayError HWCDisplayPrimary::Refresh() { |
| 412 | DisplayError error = kErrorNone; |
| 413 | |
| 414 | callbacks_->Refresh(HWC_DISPLAY_PRIMARY); |
Naseer Ahmed | b92e73f | 2016-03-12 02:03:48 -0500 | [diff] [blame] | 415 | |
| 416 | return error; |
| 417 | } |
| 418 | |
| 419 | void HWCDisplayPrimary::SetIdleTimeoutMs(uint32_t timeout_ms) { |
| 420 | display_intf_->SetIdleTimeoutMs(timeout_ms); |
Sushil Chauhan | 409e844 | 2017-06-12 17:43:25 -0700 | [diff] [blame] | 421 | validated_.reset(); |
Naseer Ahmed | b92e73f | 2016-03-12 02:03:48 -0500 | [diff] [blame] | 422 | } |
| 423 | |
| 424 | static void SetLayerBuffer(const BufferInfo &output_buffer_info, LayerBuffer *output_buffer) { |
Ramkumar Radhakrishnan | b27735f | 2016-08-26 22:37:23 -0700 | [diff] [blame] | 425 | const BufferConfig& buffer_config = output_buffer_info.buffer_config; |
| 426 | const AllocatedBufferInfo &alloc_buffer_info = output_buffer_info.alloc_buffer_info; |
| 427 | |
| 428 | output_buffer->width = alloc_buffer_info.aligned_width; |
| 429 | output_buffer->height = alloc_buffer_info.aligned_height; |
| 430 | output_buffer->unaligned_width = buffer_config.width; |
| 431 | output_buffer->unaligned_height = buffer_config.height; |
| 432 | output_buffer->format = buffer_config.format; |
| 433 | output_buffer->planes[0].fd = alloc_buffer_info.fd; |
| 434 | output_buffer->planes[0].stride = alloc_buffer_info.stride; |
Naseer Ahmed | b92e73f | 2016-03-12 02:03:48 -0500 | [diff] [blame] | 435 | } |
| 436 | |
| 437 | void HWCDisplayPrimary::HandleFrameOutput() { |
| 438 | if (frame_capture_buffer_queued_) { |
| 439 | HandleFrameCapture(); |
| 440 | } else if (dump_output_to_file_) { |
| 441 | HandleFrameDump(); |
| 442 | } |
| 443 | } |
| 444 | |
| 445 | void HWCDisplayPrimary::HandleFrameCapture() { |
| 446 | if (output_buffer_.release_fence_fd >= 0) { |
| 447 | frame_capture_status_ = sync_wait(output_buffer_.release_fence_fd, 1000); |
| 448 | ::close(output_buffer_.release_fence_fd); |
| 449 | output_buffer_.release_fence_fd = -1; |
| 450 | } |
| 451 | |
| 452 | frame_capture_buffer_queued_ = false; |
| 453 | post_processed_output_ = false; |
| 454 | output_buffer_ = {}; |
Naseer Ahmed | b92e73f | 2016-03-12 02:03:48 -0500 | [diff] [blame] | 455 | } |
| 456 | |
| 457 | void HWCDisplayPrimary::HandleFrameDump() { |
| 458 | if (dump_frame_count_ && output_buffer_.release_fence_fd >= 0) { |
| 459 | int ret = sync_wait(output_buffer_.release_fence_fd, 1000); |
| 460 | ::close(output_buffer_.release_fence_fd); |
| 461 | output_buffer_.release_fence_fd = -1; |
| 462 | if (ret < 0) { |
| 463 | DLOGE("sync_wait error errno = %d, desc = %s", errno, strerror(errno)); |
| 464 | } else { |
| 465 | DumpOutputBuffer(output_buffer_info_, output_buffer_base_, layer_stack_.retire_fence_fd); |
| 466 | } |
| 467 | } |
| 468 | |
| 469 | if (0 == dump_frame_count_) { |
| 470 | dump_output_to_file_ = false; |
| 471 | // Unmap and Free buffer |
| 472 | if (munmap(output_buffer_base_, output_buffer_info_.alloc_buffer_info.size) != 0) { |
| 473 | DLOGE("unmap failed with err %d", errno); |
| 474 | } |
| 475 | if (buffer_allocator_->FreeBuffer(&output_buffer_info_) != 0) { |
| 476 | DLOGE("FreeBuffer failed"); |
| 477 | } |
| 478 | |
| 479 | post_processed_output_ = false; |
| 480 | output_buffer_ = {}; |
| 481 | output_buffer_info_ = {}; |
| 482 | output_buffer_base_ = nullptr; |
Naseer Ahmed | b92e73f | 2016-03-12 02:03:48 -0500 | [diff] [blame] | 483 | } |
| 484 | } |
| 485 | |
| 486 | void HWCDisplayPrimary::SetFrameDumpConfig(uint32_t count, uint32_t bit_mask_layer_type) { |
| 487 | HWCDisplay::SetFrameDumpConfig(count, bit_mask_layer_type); |
| 488 | dump_output_to_file_ = bit_mask_layer_type & (1 << OUTPUT_LAYER_DUMP); |
| 489 | DLOGI("output_layer_dump_enable %d", dump_output_to_file_); |
| 490 | |
| 491 | if (!count || !dump_output_to_file_) { |
| 492 | return; |
| 493 | } |
| 494 | |
| 495 | // Allocate and map output buffer |
| 496 | output_buffer_info_ = {}; |
| 497 | // Since we dump DSPP output use Panel resolution. |
| 498 | GetPanelResolution(&output_buffer_info_.buffer_config.width, |
| 499 | &output_buffer_info_.buffer_config.height); |
| 500 | output_buffer_info_.buffer_config.format = kFormatRGB888; |
| 501 | output_buffer_info_.buffer_config.buffer_count = 1; |
| 502 | if (buffer_allocator_->AllocateBuffer(&output_buffer_info_) != 0) { |
| 503 | DLOGE("Buffer allocation failed"); |
| 504 | output_buffer_info_ = {}; |
| 505 | return; |
| 506 | } |
| 507 | |
| 508 | void *buffer = mmap(NULL, output_buffer_info_.alloc_buffer_info.size, PROT_READ | PROT_WRITE, |
| 509 | MAP_SHARED, output_buffer_info_.alloc_buffer_info.fd, 0); |
| 510 | |
| 511 | if (buffer == MAP_FAILED) { |
| 512 | DLOGE("mmap failed with err %d", errno); |
| 513 | buffer_allocator_->FreeBuffer(&output_buffer_info_); |
| 514 | output_buffer_info_ = {}; |
| 515 | return; |
| 516 | } |
| 517 | |
| 518 | output_buffer_base_ = buffer; |
| 519 | post_processed_output_ = true; |
Arun Kumar K.R | 17bbd04 | 2016-06-07 17:38:02 -0700 | [diff] [blame] | 520 | DisablePartialUpdateOneFrame(); |
Sushil Chauhan | 409e844 | 2017-06-12 17:43:25 -0700 | [diff] [blame] | 521 | validated_.reset(); |
Naseer Ahmed | b92e73f | 2016-03-12 02:03:48 -0500 | [diff] [blame] | 522 | } |
| 523 | |
| 524 | int HWCDisplayPrimary::FrameCaptureAsync(const BufferInfo &output_buffer_info, |
| 525 | bool post_processed_output) { |
| 526 | // Note: This function is called in context of a binder thread and a lock is already held |
| 527 | if (output_buffer_info.alloc_buffer_info.fd < 0) { |
| 528 | DLOGE("Invalid fd %d", output_buffer_info.alloc_buffer_info.fd); |
| 529 | return -1; |
| 530 | } |
| 531 | |
| 532 | auto panel_width = 0u; |
| 533 | auto panel_height = 0u; |
| 534 | auto fb_width = 0u; |
| 535 | auto fb_height = 0u; |
| 536 | |
| 537 | GetPanelResolution(&panel_width, &panel_height); |
| 538 | GetFrameBufferResolution(&fb_width, &fb_height); |
| 539 | |
Ch Ganesh Kumar | 5c4988b | 2017-06-07 15:21:02 +0530 | [diff] [blame] | 540 | if (post_processed_output && (output_buffer_info.buffer_config.width < panel_width || |
| 541 | output_buffer_info.buffer_config.height < panel_height)) { |
Naseer Ahmed | b92e73f | 2016-03-12 02:03:48 -0500 | [diff] [blame] | 542 | DLOGE("Buffer dimensions should not be less than panel resolution"); |
| 543 | return -1; |
Ch Ganesh Kumar | 5c4988b | 2017-06-07 15:21:02 +0530 | [diff] [blame] | 544 | } else if (!post_processed_output && (output_buffer_info.buffer_config.width < fb_width || |
| 545 | output_buffer_info.buffer_config.height < fb_height)) { |
Naseer Ahmed | b92e73f | 2016-03-12 02:03:48 -0500 | [diff] [blame] | 546 | DLOGE("Buffer dimensions should not be less than FB resolution"); |
| 547 | return -1; |
| 548 | } |
| 549 | |
| 550 | SetLayerBuffer(output_buffer_info, &output_buffer_); |
| 551 | post_processed_output_ = post_processed_output; |
| 552 | frame_capture_buffer_queued_ = true; |
| 553 | // Status is only cleared on a new call to dump and remains valid otherwise |
| 554 | frame_capture_status_ = -EAGAIN; |
Arun Kumar K.R | 17bbd04 | 2016-06-07 17:38:02 -0700 | [diff] [blame] | 555 | DisablePartialUpdateOneFrame(); |
Naseer Ahmed | b92e73f | 2016-03-12 02:03:48 -0500 | [diff] [blame] | 556 | |
| 557 | return 0; |
| 558 | } |
| 559 | |
Alan Kwong | 2e13633 | 2016-08-16 07:50:16 -0400 | [diff] [blame] | 560 | DisplayError HWCDisplayPrimary::SetDetailEnhancerConfig |
| 561 | (const DisplayDetailEnhancerData &de_data) { |
| 562 | DisplayError error = kErrorNotSupported; |
| 563 | |
| 564 | if (display_intf_) { |
| 565 | error = display_intf_->SetDetailEnhancerData(de_data); |
Sushil Chauhan | 409e844 | 2017-06-12 17:43:25 -0700 | [diff] [blame] | 566 | validated_.reset(); |
Alan Kwong | 2e13633 | 2016-08-16 07:50:16 -0400 | [diff] [blame] | 567 | } |
| 568 | return error; |
| 569 | } |
| 570 | |
Arun Kumar K.R | 17bbd04 | 2016-06-07 17:38:02 -0700 | [diff] [blame] | 571 | DisplayError HWCDisplayPrimary::ControlPartialUpdate(bool enable, uint32_t *pending) { |
| 572 | DisplayError error = kErrorNone; |
| 573 | |
| 574 | if (display_intf_) { |
| 575 | error = display_intf_->ControlPartialUpdate(enable, pending); |
Sushil Chauhan | 409e844 | 2017-06-12 17:43:25 -0700 | [diff] [blame] | 576 | validated_.reset(); |
Arun Kumar K.R | 17bbd04 | 2016-06-07 17:38:02 -0700 | [diff] [blame] | 577 | } |
| 578 | |
| 579 | return error; |
| 580 | } |
| 581 | |
| 582 | DisplayError HWCDisplayPrimary::DisablePartialUpdateOneFrame() { |
| 583 | DisplayError error = kErrorNone; |
| 584 | |
| 585 | if (display_intf_) { |
| 586 | error = display_intf_->DisablePartialUpdateOneFrame(); |
Sushil Chauhan | 409e844 | 2017-06-12 17:43:25 -0700 | [diff] [blame] | 587 | validated_.reset(); |
Arun Kumar K.R | 17bbd04 | 2016-06-07 17:38:02 -0700 | [diff] [blame] | 588 | } |
| 589 | |
| 590 | return error; |
| 591 | } |
| 592 | |
| 593 | |
Arun Kumar K.R | 8da7f50 | 2016-06-07 17:45:50 -0700 | [diff] [blame] | 594 | DisplayError HWCDisplayPrimary::SetMixerResolution(uint32_t width, uint32_t height) { |
Sushil Chauhan | 409e844 | 2017-06-12 17:43:25 -0700 | [diff] [blame] | 595 | DisplayError error = display_intf_->SetMixerResolution(width, height); |
| 596 | validated_.reset(); |
| 597 | return error; |
Arun Kumar K.R | 8da7f50 | 2016-06-07 17:45:50 -0700 | [diff] [blame] | 598 | } |
| 599 | |
| 600 | DisplayError HWCDisplayPrimary::GetMixerResolution(uint32_t *width, uint32_t *height) { |
| 601 | return display_intf_->GetMixerResolution(width, height); |
| 602 | } |
| 603 | |
Naseer Ahmed | b92e73f | 2016-03-12 02:03:48 -0500 | [diff] [blame] | 604 | } // namespace sdm |