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