Naseer Ahmed | b92e73f | 2016-03-12 02:03:48 -0500 | [diff] [blame] | 1 | /* |
Dileep Marchya | f3ce11f | 2018-04-30 23:35:46 +0530 | [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> |
Sushil Chauhan | 0652158 | 2018-03-19 14:00:23 -0700 | [diff] [blame] | 34 | #include <utils/utils.h> |
Naseer Ahmed | b92e73f | 2016-03-12 02:03:48 -0500 | [diff] [blame] | 35 | #include <stdarg.h> |
| 36 | #include <sys/mman.h> |
| 37 | |
Arun Kumar K.R | 29cd658 | 2016-05-10 19:12:45 -0700 | [diff] [blame] | 38 | #include <map> |
| 39 | #include <string> |
| 40 | #include <vector> |
| 41 | |
Dileep Marchya | f3ce11f | 2018-04-30 23:35:46 +0530 | [diff] [blame] | 42 | #include "hwc_display_builtin.h" |
Naseer Ahmed | b92e73f | 2016-03-12 02:03:48 -0500 | [diff] [blame] | 43 | #include "hwc_debugger.h" |
| 44 | |
Dileep Marchya | f3ce11f | 2018-04-30 23:35:46 +0530 | [diff] [blame] | 45 | #define __CLASS__ "HWCDisplayBuiltIn" |
Naseer Ahmed | b92e73f | 2016-03-12 02:03:48 -0500 | [diff] [blame] | 46 | |
| 47 | namespace sdm { |
| 48 | |
Dileep Marchya | f3ce11f | 2018-04-30 23:35:46 +0530 | [diff] [blame] | 49 | int HWCDisplayBuiltIn::Create(CoreInterface *core_intf, BufferAllocator *buffer_allocator, |
Varun Arora | 7c8ee54 | 2018-05-01 20:58:16 -0700 | [diff] [blame] | 50 | HWCCallbacks *callbacks, HWCDisplayEventHandler *event_handler, |
Dileep Marchya | f3ce11f | 2018-04-30 23:35:46 +0530 | [diff] [blame] | 51 | qService::QService *qservice, hwc2_display_t id, int32_t sdm_id, |
| 52 | HWCDisplay **hwc_display) { |
Naseer Ahmed | b92e73f | 2016-03-12 02:03:48 -0500 | [diff] [blame] | 53 | int status = 0; |
Dileep Marchya | f3ce11f | 2018-04-30 23:35:46 +0530 | [diff] [blame] | 54 | uint32_t builtin_width = 0; |
| 55 | uint32_t builtin_height = 0; |
Naseer Ahmed | b92e73f | 2016-03-12 02:03:48 -0500 | [diff] [blame] | 56 | |
Dileep Marchya | f3ce11f | 2018-04-30 23:35:46 +0530 | [diff] [blame] | 57 | HWCDisplay *hwc_display_builtin = |
| 58 | new HWCDisplayBuiltIn(core_intf, buffer_allocator, callbacks, event_handler, qservice, id, |
| 59 | sdm_id); |
| 60 | status = hwc_display_builtin->Init(); |
Naseer Ahmed | b92e73f | 2016-03-12 02:03:48 -0500 | [diff] [blame] | 61 | if (status) { |
Dileep Marchya | f3ce11f | 2018-04-30 23:35:46 +0530 | [diff] [blame] | 62 | delete hwc_display_builtin; |
Naseer Ahmed | b92e73f | 2016-03-12 02:03:48 -0500 | [diff] [blame] | 63 | return status; |
| 64 | } |
| 65 | |
Dileep Marchya | f3ce11f | 2018-04-30 23:35:46 +0530 | [diff] [blame] | 66 | hwc_display_builtin->GetMixerResolution(&builtin_width, &builtin_height); |
Naseer Ahmed | b92e73f | 2016-03-12 02:03:48 -0500 | [diff] [blame] | 67 | int width = 0, height = 0; |
Uday Kiran Pichika | 5e656b2 | 2018-05-15 18:48:24 +0530 | [diff] [blame] | 68 | HWCDebugHandler::Get()->GetProperty(FB_WIDTH_PROP, &width); |
| 69 | HWCDebugHandler::Get()->GetProperty(FB_HEIGHT_PROP, &height); |
Naseer Ahmed | b92e73f | 2016-03-12 02:03:48 -0500 | [diff] [blame] | 70 | if (width > 0 && height > 0) { |
Dileep Marchya | f3ce11f | 2018-04-30 23:35:46 +0530 | [diff] [blame] | 71 | builtin_width = UINT32(width); |
| 72 | builtin_height = UINT32(height); |
Naseer Ahmed | b92e73f | 2016-03-12 02:03:48 -0500 | [diff] [blame] | 73 | } |
| 74 | |
Dileep Marchya | f3ce11f | 2018-04-30 23:35:46 +0530 | [diff] [blame] | 75 | status = hwc_display_builtin->SetFrameBufferResolution(builtin_width, builtin_height); |
Naseer Ahmed | b92e73f | 2016-03-12 02:03:48 -0500 | [diff] [blame] | 76 | if (status) { |
Dileep Marchya | f3ce11f | 2018-04-30 23:35:46 +0530 | [diff] [blame] | 77 | Destroy(hwc_display_builtin); |
Naseer Ahmed | b92e73f | 2016-03-12 02:03:48 -0500 | [diff] [blame] | 78 | return status; |
| 79 | } |
| 80 | |
Dileep Marchya | f3ce11f | 2018-04-30 23:35:46 +0530 | [diff] [blame] | 81 | *hwc_display = hwc_display_builtin; |
Naseer Ahmed | b92e73f | 2016-03-12 02:03:48 -0500 | [diff] [blame] | 82 | |
| 83 | return status; |
| 84 | } |
| 85 | |
Dileep Marchya | f3ce11f | 2018-04-30 23:35:46 +0530 | [diff] [blame] | 86 | void HWCDisplayBuiltIn::Destroy(HWCDisplay *hwc_display) { |
Naseer Ahmed | b92e73f | 2016-03-12 02:03:48 -0500 | [diff] [blame] | 87 | hwc_display->Deinit(); |
| 88 | delete hwc_display; |
| 89 | } |
| 90 | |
Dileep Marchya | f3ce11f | 2018-04-30 23:35:46 +0530 | [diff] [blame] | 91 | HWCDisplayBuiltIn::HWCDisplayBuiltIn(CoreInterface *core_intf, BufferAllocator *buffer_allocator, |
Varun Arora | 7c8ee54 | 2018-05-01 20:58:16 -0700 | [diff] [blame] | 92 | HWCCallbacks *callbacks, HWCDisplayEventHandler *event_handler, |
Dileep Marchya | f3ce11f | 2018-04-30 23:35:46 +0530 | [diff] [blame] | 93 | qService::QService *qservice, hwc2_display_t id, |
| 94 | int32_t sdm_id) |
| 95 | : HWCDisplay(core_intf, buffer_allocator, callbacks, event_handler, qservice, kBuiltIn, id, |
| 96 | sdm_id, true, DISPLAY_CLASS_BUILTIN), |
| 97 | buffer_allocator_(buffer_allocator), |
| 98 | cpu_hint_(NULL) { |
Naseer Ahmed | b92e73f | 2016-03-12 02:03:48 -0500 | [diff] [blame] | 99 | } |
| 100 | |
Dileep Marchya | f3ce11f | 2018-04-30 23:35:46 +0530 | [diff] [blame] | 101 | int HWCDisplayBuiltIn::Init() { |
Naseer Ahmed | b92e73f | 2016-03-12 02:03:48 -0500 | [diff] [blame] | 102 | cpu_hint_ = new CPUHint(); |
| 103 | if (cpu_hint_->Init(static_cast<HWCDebugHandler *>(HWCDebugHandler::Get())) != kErrorNone) { |
| 104 | delete cpu_hint_; |
| 105 | cpu_hint_ = NULL; |
| 106 | } |
| 107 | |
| 108 | use_metadata_refresh_rate_ = true; |
| 109 | int disable_metadata_dynfps = 0; |
Uday Kiran Pichika | 5e656b2 | 2018-05-15 18:48:24 +0530 | [diff] [blame] | 110 | HWCDebugHandler::Get()->GetProperty(DISABLE_METADATA_DYNAMIC_FPS_PROP, &disable_metadata_dynfps); |
Naseer Ahmed | b92e73f | 2016-03-12 02:03:48 -0500 | [diff] [blame] | 111 | if (disable_metadata_dynfps) { |
| 112 | use_metadata_refresh_rate_ = false; |
| 113 | } |
| 114 | |
Arun Kumar K.R | 29cd658 | 2016-05-10 19:12:45 -0700 | [diff] [blame] | 115 | int status = HWCDisplay::Init(); |
| 116 | if (status) { |
| 117 | return status; |
| 118 | } |
| 119 | color_mode_ = new HWCColorMode(display_intf_); |
Naseer Ahmed | 61f6095 | 2017-05-24 16:48:35 -0400 | [diff] [blame] | 120 | color_mode_->Init(); |
Uday Kiran Pichika | 5e656b2 | 2018-05-15 18:48:24 +0530 | [diff] [blame] | 121 | HWCDebugHandler::Get()->GetProperty(ENABLE_DEFAULT_COLOR_MODE, |
Ch Ganesh Kumar | 86c4651 | 2017-06-13 13:09:22 +0530 | [diff] [blame] | 122 | &default_mode_status_); |
Arun Kumar K.R | 29cd658 | 2016-05-10 19:12:45 -0700 | [diff] [blame] | 123 | |
Naseer Ahmed | 61f6095 | 2017-05-24 16:48:35 -0400 | [diff] [blame] | 124 | return status; |
Naseer Ahmed | b92e73f | 2016-03-12 02:03:48 -0500 | [diff] [blame] | 125 | } |
| 126 | |
Dileep Marchya | f3ce11f | 2018-04-30 23:35:46 +0530 | [diff] [blame] | 127 | void HWCDisplayBuiltIn::ProcessBootAnimCompleted() { |
Xu Yang | 340a369 | 2018-07-10 16:50:52 +0800 | [diff] [blame] | 128 | bool bootanim_exit = false; |
Naseer Ahmed | b92e73f | 2016-03-12 02:03:48 -0500 | [diff] [blame] | 129 | |
Naseer Ahmed | b92e73f | 2016-03-12 02:03:48 -0500 | [diff] [blame] | 130 | /* All other checks namely "init.svc.bootanim" or |
| 131 | * HWC_GEOMETRY_CHANGED fail in correctly identifying the |
| 132 | * exact bootup transition to homescreen |
| 133 | */ |
Naseer Ahmed | ac442ae | 2016-06-23 18:58:03 -0400 | [diff] [blame] | 134 | char property[PROPERTY_VALUE_MAX]; |
Naseer Ahmed | b92e73f | 2016-03-12 02:03:48 -0500 | [diff] [blame] | 135 | bool isEncrypted = false; |
| 136 | bool main_class_services_started = false; |
Naseer Ahmed | ac442ae | 2016-06-23 18:58:03 -0400 | [diff] [blame] | 137 | property_get("ro.crypto.state", property, "unencrypted"); |
| 138 | if (!strcmp(property, "encrypted")) { |
| 139 | property_get("ro.crypto.type", property, "block"); |
| 140 | if (!strcmp(property, "block")) { |
Naseer Ahmed | b92e73f | 2016-03-12 02:03:48 -0500 | [diff] [blame] | 141 | isEncrypted = true; |
Naseer Ahmed | ac442ae | 2016-06-23 18:58:03 -0400 | [diff] [blame] | 142 | property_get("vold.decrypt", property, ""); |
| 143 | if (!strcmp(property, "trigger_restart_framework")) { |
Naseer Ahmed | b92e73f | 2016-03-12 02:03:48 -0500 | [diff] [blame] | 144 | main_class_services_started = true; |
Naseer Ahmed | ac442ae | 2016-06-23 18:58:03 -0400 | [diff] [blame] | 145 | } |
Naseer Ahmed | b92e73f | 2016-03-12 02:03:48 -0500 | [diff] [blame] | 146 | } |
| 147 | } |
Naseer Ahmed | ac442ae | 2016-06-23 18:58:03 -0400 | [diff] [blame] | 148 | |
Xu Yang | 340a369 | 2018-07-10 16:50:52 +0800 | [diff] [blame] | 149 | property_get("service.bootanim.exit", property, "0"); |
| 150 | if (!strcmp(property, "1")) { |
| 151 | bootanim_exit = true; |
| 152 | } |
| 153 | |
Naseer Ahmed | b92e73f | 2016-03-12 02:03:48 -0500 | [diff] [blame] | 154 | if ((!isEncrypted || (isEncrypted && main_class_services_started)) && |
Xu Yang | 340a369 | 2018-07-10 16:50:52 +0800 | [diff] [blame] | 155 | bootanim_exit) { |
Xu Yang | 2a979af | 2018-05-07 17:10:49 +0800 | [diff] [blame] | 156 | DLOGI("Applying default mode for display %d", sdm_id_); |
Naseer Ahmed | b92e73f | 2016-03-12 02:03:48 -0500 | [diff] [blame] | 157 | boot_animation_completed_ = true; |
| 158 | // Applying default mode after bootanimation is finished And |
| 159 | // If Data is Encrypted, it is ready for access. |
Ch Ganesh Kumar | 5d43ff6 | 2017-10-13 19:01:47 +0530 | [diff] [blame] | 160 | if (display_intf_) { |
Naseer Ahmed | b92e73f | 2016-03-12 02:03:48 -0500 | [diff] [blame] | 161 | display_intf_->ApplyDefaultDisplayMode(); |
Ch Ganesh Kumar | 5d43ff6 | 2017-10-13 19:01:47 +0530 | [diff] [blame] | 162 | RestoreColorTransform(); |
| 163 | } |
Naseer Ahmed | b92e73f | 2016-03-12 02:03:48 -0500 | [diff] [blame] | 164 | } |
| 165 | } |
| 166 | |
Dileep Marchya | f3ce11f | 2018-04-30 23:35:46 +0530 | [diff] [blame] | 167 | HWC2::Error HWCDisplayBuiltIn::Validate(uint32_t *out_num_types, uint32_t *out_num_requests) { |
Naseer Ahmed | b92e73f | 2016-03-12 02:03:48 -0500 | [diff] [blame] | 168 | auto status = HWC2::Error::None; |
| 169 | DisplayError error = kErrorNone; |
| 170 | |
Ch Ganesh Kumar | 86c4651 | 2017-06-13 13:09:22 +0530 | [diff] [blame] | 171 | if (default_mode_status_ && !boot_animation_completed_) { |
| 172 | ProcessBootAnimCompleted(); |
| 173 | } |
| 174 | |
Naseer Ahmed | b92e73f | 2016-03-12 02:03:48 -0500 | [diff] [blame] | 175 | if (display_paused_) { |
| 176 | MarkLayersForGPUBypass(); |
| 177 | return status; |
| 178 | } |
| 179 | |
Arun Kumar K.R | 29cd658 | 2016-05-10 19:12:45 -0700 | [diff] [blame] | 180 | if (color_tranform_failed_) { |
| 181 | // Must fall back to client composition |
| 182 | MarkLayersForClientComposition(); |
| 183 | } |
| 184 | |
Naseer Ahmed | b92e73f | 2016-03-12 02:03:48 -0500 | [diff] [blame] | 185 | // Fill in the remaining blanks in the layers and add them to the SDM layerstack |
| 186 | BuildLayerStack(); |
Arun Kumar K.R | 536c7d6 | 2016-06-14 18:47:39 -0700 | [diff] [blame] | 187 | // Checks and replaces layer stack for solid fill |
| 188 | SolidFillPrepare(); |
Naseer Ahmed | b92e73f | 2016-03-12 02:03:48 -0500 | [diff] [blame] | 189 | |
Sushil Chauhan | 8008d60 | 2018-09-04 14:43:27 -0700 | [diff] [blame] | 190 | // Apply current Color Mode and Render Intent. |
| 191 | if (color_mode_->ApplyCurrentColorModeWithRenderIntent() != HWC2::Error::None) { |
| 192 | // Fallback to GPU Composition, if Color Mode can't be applied. |
| 193 | MarkLayersForClientComposition(); |
| 194 | } |
| 195 | |
Naseer Ahmed | b92e73f | 2016-03-12 02:03:48 -0500 | [diff] [blame] | 196 | bool pending_output_dump = dump_frame_count_ && dump_output_to_file_; |
| 197 | |
Sushil Chauhan | 0652158 | 2018-03-19 14:00:23 -0700 | [diff] [blame] | 198 | if (readback_buffer_queued_ || pending_output_dump) { |
| 199 | CloseFd(&output_buffer_.release_fence_fd); |
Naseer Ahmed | b92e73f | 2016-03-12 02:03:48 -0500 | [diff] [blame] | 200 | // RHS values were set in FrameCaptureAsync() called from a binder thread. They are picked up |
Sushil Chauhan | 0652158 | 2018-03-19 14:00:23 -0700 | [diff] [blame] | 201 | // here in a subsequent draw round. Readback is not allowed for any secure use case. |
| 202 | readback_configured_ = !layer_stack_.flags.secure_present; |
| 203 | if (readback_configured_) { |
Sushil Chauhan | f42d862 | 2018-09-30 23:20:37 -0700 | [diff] [blame] | 204 | DisablePartialUpdateOneFrame(); |
Sushil Chauhan | 0652158 | 2018-03-19 14:00:23 -0700 | [diff] [blame] | 205 | layer_stack_.output_buffer = &output_buffer_; |
| 206 | layer_stack_.flags.post_processed_output = post_processed_output_; |
| 207 | } |
Naseer Ahmed | b92e73f | 2016-03-12 02:03:48 -0500 | [diff] [blame] | 208 | } |
| 209 | |
Ramakant Singh | 5db0dfb | 2017-08-23 12:34:57 +0530 | [diff] [blame] | 210 | uint32_t num_updating_layers = GetUpdatingLayersCount(); |
| 211 | bool one_updating_layer = (num_updating_layers == 1); |
| 212 | if (num_updating_layers != 0) { |
| 213 | ToggleCPUHint(one_updating_layer); |
| 214 | } |
Naseer Ahmed | b92e73f | 2016-03-12 02:03:48 -0500 | [diff] [blame] | 215 | |
| 216 | uint32_t refresh_rate = GetOptimalRefreshRate(one_updating_layer); |
Anjaneya Prasad Musunuri | 4d65df7 | 2017-05-18 19:11:28 +0530 | [diff] [blame] | 217 | bool final_rate = force_refresh_rate_ ? true : false; |
| 218 | error = display_intf_->SetRefreshRate(refresh_rate, final_rate); |
Naseer Ahmed | b92e73f | 2016-03-12 02:03:48 -0500 | [diff] [blame] | 219 | if (error == kErrorNone) { |
| 220 | // On success, set current refresh rate to new refresh rate |
| 221 | current_refresh_rate_ = refresh_rate; |
| 222 | } |
| 223 | |
Naseer Ahmed | b92e73f | 2016-03-12 02:03:48 -0500 | [diff] [blame] | 224 | if (layer_set_.empty()) { |
Uday Kiran Pichika | 8d82773 | 2018-01-09 18:08:38 +0530 | [diff] [blame] | 225 | // Avoid flush for Command mode panel. |
Ramkumar Radhakrishnan | a38b760 | 2018-03-15 14:49:52 -0700 | [diff] [blame] | 226 | flush_ = !IsDisplayCommandMode(); |
| 227 | validated_ = true; |
Naseer Ahmed | b92e73f | 2016-03-12 02:03:48 -0500 | [diff] [blame] | 228 | return status; |
| 229 | } |
| 230 | |
| 231 | status = PrepareLayerStack(out_num_types, out_num_requests); |
Namit Solanki | 5b428dc | 2018-02-27 11:39:05 +0530 | [diff] [blame] | 232 | pending_commit_ = true; |
Naseer Ahmed | b92e73f | 2016-03-12 02:03:48 -0500 | [diff] [blame] | 233 | return status; |
| 234 | } |
| 235 | |
Dileep Marchya | f3ce11f | 2018-04-30 23:35:46 +0530 | [diff] [blame] | 236 | HWC2::Error HWCDisplayBuiltIn::Present(int32_t *out_retire_fence) { |
Naseer Ahmed | b92e73f | 2016-03-12 02:03:48 -0500 | [diff] [blame] | 237 | auto status = HWC2::Error::None; |
| 238 | if (display_paused_) { |
Pullakavi Srinivas | 0a1dba6 | 2018-07-02 15:49:11 +0530 | [diff] [blame] | 239 | DisplayError error = display_intf_->Flush(&layer_stack_); |
Saurabh Shah | a307e8c | 2017-09-28 18:05:40 -0700 | [diff] [blame] | 240 | validated_ = false; |
Naseer Ahmed | b92e73f | 2016-03-12 02:03:48 -0500 | [diff] [blame] | 241 | if (error != kErrorNone) { |
| 242 | DLOGE("Flush failed. Error = %d", error); |
| 243 | } |
| 244 | } else { |
| 245 | status = HWCDisplay::CommitLayerStack(); |
| 246 | if (status == HWC2::Error::None) { |
| 247 | HandleFrameOutput(); |
Arun Kumar K.R | 536c7d6 | 2016-06-14 18:47:39 -0700 | [diff] [blame] | 248 | SolidFillCommit(); |
Naseer Ahmed | b92e73f | 2016-03-12 02:03:48 -0500 | [diff] [blame] | 249 | status = HWCDisplay::PostCommitLayerStack(out_retire_fence); |
| 250 | } |
| 251 | } |
Arun Kumar K.R | 536c7d6 | 2016-06-14 18:47:39 -0700 | [diff] [blame] | 252 | |
Sushil Chauhan | 0652158 | 2018-03-19 14:00:23 -0700 | [diff] [blame] | 253 | CloseFd(&output_buffer_.acquire_fence_fd); |
Namit Solanki | 5b428dc | 2018-02-27 11:39:05 +0530 | [diff] [blame] | 254 | pending_commit_ = false; |
Naseer Ahmed | b92e73f | 2016-03-12 02:03:48 -0500 | [diff] [blame] | 255 | return status; |
| 256 | } |
| 257 | |
Dileep Marchya | f3ce11f | 2018-04-30 23:35:46 +0530 | [diff] [blame] | 258 | HWC2::Error HWCDisplayBuiltIn::GetColorModes(uint32_t *out_num_modes, ColorMode *out_modes) { |
Arun Kumar K.R | 29cd658 | 2016-05-10 19:12:45 -0700 | [diff] [blame] | 259 | if (out_modes == nullptr) { |
| 260 | *out_num_modes = color_mode_->GetColorModeCount(); |
| 261 | } else { |
| 262 | color_mode_->GetColorModes(out_num_modes, out_modes); |
| 263 | } |
| 264 | |
| 265 | return HWC2::Error::None; |
| 266 | } |
| 267 | |
Dileep Marchya | f3ce11f | 2018-04-30 23:35:46 +0530 | [diff] [blame] | 268 | HWC2::Error HWCDisplayBuiltIn::GetRenderIntents(ColorMode mode, uint32_t *out_num_intents, |
Naseer Ahmed | e7a7798 | 2018-06-04 10:56:04 -0400 | [diff] [blame] | 269 | RenderIntent *out_intents) { |
| 270 | if (out_intents == nullptr) { |
| 271 | *out_num_intents = color_mode_->GetRenderIntentCount(mode); |
| 272 | } else { |
| 273 | color_mode_->GetRenderIntents(mode, out_num_intents, out_intents); |
| 274 | } |
| 275 | return HWC2::Error::None; |
| 276 | } |
| 277 | |
Dileep Marchya | f3ce11f | 2018-04-30 23:35:46 +0530 | [diff] [blame] | 278 | HWC2::Error HWCDisplayBuiltIn::SetColorMode(ColorMode mode) { |
Naseer Ahmed | e7a7798 | 2018-06-04 10:56:04 -0400 | [diff] [blame] | 279 | return SetColorModeWithRenderIntent(mode, RenderIntent::COLORIMETRIC); |
| 280 | } |
| 281 | |
Dileep Marchya | f3ce11f | 2018-04-30 23:35:46 +0530 | [diff] [blame] | 282 | HWC2::Error HWCDisplayBuiltIn::SetColorModeWithRenderIntent(ColorMode mode, RenderIntent intent) { |
Sushil Chauhan | 8008d60 | 2018-09-04 14:43:27 -0700 | [diff] [blame] | 283 | auto status = color_mode_->CacheColorModeWithRenderIntent(mode, intent); |
Arun Kumar K.R | 29cd658 | 2016-05-10 19:12:45 -0700 | [diff] [blame] | 284 | if (status != HWC2::Error::None) { |
Naseer Ahmed | e7a7798 | 2018-06-04 10:56:04 -0400 | [diff] [blame] | 285 | DLOGE("failed for mode = %d intent = %d", mode, intent); |
Arun Kumar K.R | 29cd658 | 2016-05-10 19:12:45 -0700 | [diff] [blame] | 286 | return status; |
| 287 | } |
Arun Kumar K.R | 29cd658 | 2016-05-10 19:12:45 -0700 | [diff] [blame] | 288 | callbacks_->Refresh(HWC_DISPLAY_PRIMARY); |
Saurabh Shah | a307e8c | 2017-09-28 18:05:40 -0700 | [diff] [blame] | 289 | validated_ = false; |
Arun Kumar K.R | 29cd658 | 2016-05-10 19:12:45 -0700 | [diff] [blame] | 290 | return status; |
| 291 | } |
| 292 | |
Dileep Marchya | f3ce11f | 2018-04-30 23:35:46 +0530 | [diff] [blame] | 293 | HWC2::Error HWCDisplayBuiltIn::SetColorModeById(int32_t color_mode_id) { |
Naseer Ahmed | 6776dae | 2017-05-09 11:49:41 -0400 | [diff] [blame] | 294 | auto status = color_mode_->SetColorModeById(color_mode_id); |
| 295 | if (status != HWC2::Error::None) { |
| 296 | DLOGE("failed for mode = %d", color_mode_id); |
| 297 | return status; |
| 298 | } |
| 299 | |
| 300 | callbacks_->Refresh(HWC_DISPLAY_PRIMARY); |
Saurabh Shah | a307e8c | 2017-09-28 18:05:40 -0700 | [diff] [blame] | 301 | validated_ = false; |
Naseer Ahmed | 6776dae | 2017-05-09 11:49:41 -0400 | [diff] [blame] | 302 | |
| 303 | return status; |
| 304 | } |
| 305 | |
Dileep Marchya | f3ce11f | 2018-04-30 23:35:46 +0530 | [diff] [blame] | 306 | HWC2::Error HWCDisplayBuiltIn::RestoreColorTransform() { |
Ch Ganesh Kumar | 5d43ff6 | 2017-10-13 19:01:47 +0530 | [diff] [blame] | 307 | auto status = color_mode_->RestoreColorTransform(); |
| 308 | if (status != HWC2::Error::None) { |
| 309 | DLOGE("failed to RestoreColorTransform"); |
| 310 | return status; |
| 311 | } |
| 312 | |
| 313 | callbacks_->Refresh(HWC_DISPLAY_PRIMARY); |
| 314 | |
| 315 | return status; |
| 316 | } |
| 317 | |
Dileep Marchya | f3ce11f | 2018-04-30 23:35:46 +0530 | [diff] [blame] | 318 | HWC2::Error HWCDisplayBuiltIn::SetColorTransform(const float *matrix, |
Arun Kumar K.R | 29cd658 | 2016-05-10 19:12:45 -0700 | [diff] [blame] | 319 | android_color_transform_t hint) { |
| 320 | if (!matrix) { |
| 321 | return HWC2::Error::BadParameter; |
| 322 | } |
| 323 | |
| 324 | auto status = color_mode_->SetColorTransform(matrix, hint); |
| 325 | if (status != HWC2::Error::None) { |
| 326 | DLOGE("failed for hint = %d", hint); |
| 327 | color_tranform_failed_ = true; |
| 328 | return status; |
| 329 | } |
| 330 | |
| 331 | callbacks_->Refresh(HWC_DISPLAY_PRIMARY); |
| 332 | color_tranform_failed_ = false; |
Saurabh Shah | a307e8c | 2017-09-28 18:05:40 -0700 | [diff] [blame] | 333 | validated_ = false; |
Arun Kumar K.R | 29cd658 | 2016-05-10 19:12:45 -0700 | [diff] [blame] | 334 | |
| 335 | return status; |
| 336 | } |
| 337 | |
Dileep Marchya | f3ce11f | 2018-04-30 23:35:46 +0530 | [diff] [blame] | 338 | HWC2::Error HWCDisplayBuiltIn::SetReadbackBuffer(const native_handle_t *buffer, |
Sushil Chauhan | 0652158 | 2018-03-19 14:00:23 -0700 | [diff] [blame] | 339 | int32_t acquire_fence, |
| 340 | bool post_processed_output) { |
| 341 | const private_handle_t *handle = reinterpret_cast<const private_handle_t *>(buffer); |
| 342 | if (!handle || (handle->fd < 0)) { |
| 343 | return HWC2::Error::BadParameter; |
| 344 | } |
| 345 | |
| 346 | // Configure the output buffer as Readback buffer |
| 347 | output_buffer_.width = UINT32(handle->width); |
| 348 | output_buffer_.height = UINT32(handle->height); |
| 349 | output_buffer_.unaligned_width = UINT32(handle->unaligned_width); |
| 350 | output_buffer_.unaligned_height = UINT32(handle->unaligned_height); |
| 351 | output_buffer_.format = HWCLayer::GetSDMFormat(handle->format, handle->flags); |
| 352 | output_buffer_.planes[0].fd = handle->fd; |
| 353 | output_buffer_.planes[0].stride = UINT32(handle->width); |
| 354 | output_buffer_.acquire_fence_fd = dup(acquire_fence); |
| 355 | output_buffer_.release_fence_fd = -1; |
Sushil Chauhan | d0dc03d | 2018-09-19 07:08:40 -0700 | [diff] [blame] | 356 | output_buffer_.handle_id = handle->id; |
Sushil Chauhan | 0652158 | 2018-03-19 14:00:23 -0700 | [diff] [blame] | 357 | |
| 358 | post_processed_output_ = post_processed_output; |
| 359 | readback_buffer_queued_ = true; |
| 360 | readback_configured_ = false; |
| 361 | validated_ = false; |
| 362 | |
Sushil Chauhan | 0652158 | 2018-03-19 14:00:23 -0700 | [diff] [blame] | 363 | return HWC2::Error::None; |
| 364 | } |
| 365 | |
Dileep Marchya | f3ce11f | 2018-04-30 23:35:46 +0530 | [diff] [blame] | 366 | HWC2::Error HWCDisplayBuiltIn::GetReadbackBufferFence(int32_t *release_fence) { |
Sushil Chauhan | 0652158 | 2018-03-19 14:00:23 -0700 | [diff] [blame] | 367 | auto status = HWC2::Error::None; |
| 368 | |
| 369 | if (readback_configured_ && (output_buffer_.release_fence_fd >= 0)) { |
| 370 | *release_fence = output_buffer_.release_fence_fd; |
| 371 | } else { |
| 372 | status = HWC2::Error::Unsupported; |
| 373 | *release_fence = -1; |
| 374 | } |
| 375 | |
| 376 | post_processed_output_ = false; |
| 377 | readback_buffer_queued_ = false; |
| 378 | readback_configured_ = false; |
| 379 | output_buffer_ = {}; |
| 380 | |
| 381 | return status; |
| 382 | } |
| 383 | |
Yuchao Ma | 577f0f7 | 2018-07-09 11:20:00 +0800 | [diff] [blame] | 384 | HWC2::Error HWCDisplayBuiltIn::SetDisplayDppsAdROI(uint32_t h_start, uint32_t h_end, |
| 385 | uint32_t v_start, uint32_t v_end, |
| 386 | uint32_t factor_in, uint32_t factor_out) { |
| 387 | DisplayError error = kErrorNone; |
| 388 | DisplayDppsAd4RoiCfg dpps_ad4_roi_cfg = {}; |
| 389 | uint32_t panel_width = 0, panel_height = 0; |
| 390 | constexpr uint16_t kMaxFactorVal = 0xffff; |
| 391 | |
| 392 | if (h_start >= h_end || v_start >= v_end || factor_in > kMaxFactorVal || |
| 393 | factor_out > kMaxFactorVal) { |
| 394 | DLOGE("Invalid roi region = [%u, %u, %u, %u, %u, %u]", |
| 395 | h_start, h_end, v_start, v_end, factor_in, factor_out); |
| 396 | return HWC2::Error::BadParameter; |
| 397 | } |
| 398 | |
| 399 | GetPanelResolution(&panel_width, &panel_height); |
| 400 | |
| 401 | if (h_start >= panel_width || h_end > panel_width || |
| 402 | v_start >= panel_height || v_end > panel_height) { |
| 403 | DLOGE("Invalid roi region = [%u, %u, %u, %u], panel resolution = [%u, %u]", |
| 404 | h_start, h_end, v_start, v_end, panel_width, panel_height); |
| 405 | return HWC2::Error::BadParameter; |
| 406 | } |
| 407 | |
| 408 | dpps_ad4_roi_cfg.h_start = h_start; |
| 409 | dpps_ad4_roi_cfg.h_end = h_end; |
| 410 | dpps_ad4_roi_cfg.v_start = v_start; |
| 411 | dpps_ad4_roi_cfg.v_end = v_end; |
| 412 | dpps_ad4_roi_cfg.factor_in = factor_in; |
| 413 | dpps_ad4_roi_cfg.factor_out = factor_out; |
| 414 | |
| 415 | error = display_intf_->SetDisplayDppsAdROI(&dpps_ad4_roi_cfg); |
| 416 | if (error) |
| 417 | return HWC2::Error::BadConfig; |
| 418 | |
| 419 | callbacks_->Refresh(HWC_DISPLAY_PRIMARY); |
| 420 | |
| 421 | return HWC2::Error::None; |
| 422 | } |
| 423 | |
Dileep Marchya | f3ce11f | 2018-04-30 23:35:46 +0530 | [diff] [blame] | 424 | int HWCDisplayBuiltIn::Perform(uint32_t operation, ...) { |
Naseer Ahmed | b92e73f | 2016-03-12 02:03:48 -0500 | [diff] [blame] | 425 | va_list args; |
| 426 | va_start(args, operation); |
Arun Kumar K.R | 536c7d6 | 2016-06-14 18:47:39 -0700 | [diff] [blame] | 427 | int val = 0; |
Gopikrishnaiah Anandan | cc12306 | 2017-07-31 17:21:03 -0700 | [diff] [blame] | 428 | LayerSolidFill *solid_fill_color; |
Arun Kumar K.R | 536c7d6 | 2016-06-14 18:47:39 -0700 | [diff] [blame] | 429 | LayerRect *rect = NULL; |
| 430 | |
Naseer Ahmed | b92e73f | 2016-03-12 02:03:48 -0500 | [diff] [blame] | 431 | switch (operation) { |
| 432 | case SET_METADATA_DYN_REFRESH_RATE: |
Arun Kumar K.R | 536c7d6 | 2016-06-14 18:47:39 -0700 | [diff] [blame] | 433 | val = va_arg(args, int32_t); |
Naseer Ahmed | b92e73f | 2016-03-12 02:03:48 -0500 | [diff] [blame] | 434 | SetMetaDataRefreshRateFlag(val); |
| 435 | break; |
| 436 | case SET_BINDER_DYN_REFRESH_RATE: |
Arun Kumar K.R | 536c7d6 | 2016-06-14 18:47:39 -0700 | [diff] [blame] | 437 | val = va_arg(args, int32_t); |
Naseer Ahmed | b92e73f | 2016-03-12 02:03:48 -0500 | [diff] [blame] | 438 | ForceRefreshRate(UINT32(val)); |
| 439 | break; |
| 440 | case SET_DISPLAY_MODE: |
Arun Kumar K.R | 536c7d6 | 2016-06-14 18:47:39 -0700 | [diff] [blame] | 441 | val = va_arg(args, int32_t); |
Naseer Ahmed | b92e73f | 2016-03-12 02:03:48 -0500 | [diff] [blame] | 442 | SetDisplayMode(UINT32(val)); |
| 443 | break; |
| 444 | case SET_QDCM_SOLID_FILL_INFO: |
Gopikrishnaiah Anandan | cc12306 | 2017-07-31 17:21:03 -0700 | [diff] [blame] | 445 | solid_fill_color = va_arg(args, LayerSolidFill*); |
| 446 | SetQDCMSolidFillInfo(true, *solid_fill_color); |
Naseer Ahmed | b92e73f | 2016-03-12 02:03:48 -0500 | [diff] [blame] | 447 | break; |
| 448 | case UNSET_QDCM_SOLID_FILL_INFO: |
Gopikrishnaiah Anandan | cc12306 | 2017-07-31 17:21:03 -0700 | [diff] [blame] | 449 | solid_fill_color = va_arg(args, LayerSolidFill*); |
| 450 | SetQDCMSolidFillInfo(false, *solid_fill_color); |
Naseer Ahmed | b92e73f | 2016-03-12 02:03:48 -0500 | [diff] [blame] | 451 | break; |
Arun Kumar K.R | 536c7d6 | 2016-06-14 18:47:39 -0700 | [diff] [blame] | 452 | case SET_QDCM_SOLID_FILL_RECT: |
| 453 | rect = va_arg(args, LayerRect*); |
| 454 | solid_fill_rect_ = *rect; |
| 455 | break; |
Naseer Ahmed | b92e73f | 2016-03-12 02:03:48 -0500 | [diff] [blame] | 456 | default: |
| 457 | DLOGW("Invalid operation %d", operation); |
Arun Kumar K.R | 536c7d6 | 2016-06-14 18:47:39 -0700 | [diff] [blame] | 458 | va_end(args); |
Naseer Ahmed | b92e73f | 2016-03-12 02:03:48 -0500 | [diff] [blame] | 459 | return -EINVAL; |
| 460 | } |
Arun Kumar K.R | 536c7d6 | 2016-06-14 18:47:39 -0700 | [diff] [blame] | 461 | va_end(args); |
Saurabh Shah | a307e8c | 2017-09-28 18:05:40 -0700 | [diff] [blame] | 462 | validated_ = false; |
Naseer Ahmed | b92e73f | 2016-03-12 02:03:48 -0500 | [diff] [blame] | 463 | |
| 464 | return 0; |
| 465 | } |
| 466 | |
Dileep Marchya | f3ce11f | 2018-04-30 23:35:46 +0530 | [diff] [blame] | 467 | DisplayError HWCDisplayBuiltIn::SetDisplayMode(uint32_t mode) { |
Naseer Ahmed | b92e73f | 2016-03-12 02:03:48 -0500 | [diff] [blame] | 468 | DisplayError error = kErrorNone; |
| 469 | |
| 470 | if (display_intf_) { |
| 471 | error = display_intf_->SetDisplayMode(mode); |
Tharaga Balachandran | 04192a6 | 2018-08-29 16:23:25 -0400 | [diff] [blame] | 472 | if (error == kErrorNone) { |
| 473 | DisplayConfigFixedInfo fixed_info = {}; |
| 474 | display_intf_->GetConfig(&fixed_info); |
| 475 | is_cmd_mode_ = fixed_info.is_cmdmode; |
| 476 | partial_update_enabled_ = fixed_info.partial_update; |
| 477 | for (auto hwc_layer : layer_set_) { |
| 478 | hwc_layer->SetPartialUpdate(partial_update_enabled_); |
| 479 | } |
| 480 | client_target_->SetPartialUpdate(partial_update_enabled_); |
| 481 | } |
Naseer Ahmed | b92e73f | 2016-03-12 02:03:48 -0500 | [diff] [blame] | 482 | } |
| 483 | |
| 484 | return error; |
| 485 | } |
| 486 | |
Dileep Marchya | f3ce11f | 2018-04-30 23:35:46 +0530 | [diff] [blame] | 487 | void HWCDisplayBuiltIn::SetMetaDataRefreshRateFlag(bool enable) { |
Naseer Ahmed | b92e73f | 2016-03-12 02:03:48 -0500 | [diff] [blame] | 488 | int disable_metadata_dynfps = 0; |
| 489 | |
Uday Kiran Pichika | 5e656b2 | 2018-05-15 18:48:24 +0530 | [diff] [blame] | 490 | HWCDebugHandler::Get()->GetProperty(DISABLE_METADATA_DYNAMIC_FPS_PROP, &disable_metadata_dynfps); |
Naseer Ahmed | b92e73f | 2016-03-12 02:03:48 -0500 | [diff] [blame] | 491 | if (disable_metadata_dynfps) { |
| 492 | return; |
| 493 | } |
| 494 | use_metadata_refresh_rate_ = enable; |
| 495 | } |
| 496 | |
Dileep Marchya | f3ce11f | 2018-04-30 23:35:46 +0530 | [diff] [blame] | 497 | void HWCDisplayBuiltIn::SetQDCMSolidFillInfo(bool enable, const LayerSolidFill &color) { |
Naseer Ahmed | b92e73f | 2016-03-12 02:03:48 -0500 | [diff] [blame] | 498 | solid_fill_enable_ = enable; |
| 499 | solid_fill_color_ = color; |
| 500 | } |
| 501 | |
Dileep Marchya | f3ce11f | 2018-04-30 23:35:46 +0530 | [diff] [blame] | 502 | void HWCDisplayBuiltIn::ToggleCPUHint(bool set) { |
Naseer Ahmed | b92e73f | 2016-03-12 02:03:48 -0500 | [diff] [blame] | 503 | if (!cpu_hint_) { |
| 504 | return; |
| 505 | } |
| 506 | |
| 507 | if (set) { |
| 508 | cpu_hint_->Set(); |
| 509 | } else { |
| 510 | cpu_hint_->Reset(); |
| 511 | } |
| 512 | } |
| 513 | |
Dileep Marchya | f3ce11f | 2018-04-30 23:35:46 +0530 | [diff] [blame] | 514 | int HWCDisplayBuiltIn::HandleSecureSession(const std::bitset<kSecureMax> &secure_sessions, |
Ramkumar Radhakrishnan | a38b760 | 2018-03-15 14:49:52 -0700 | [diff] [blame] | 515 | bool *power_on_pending) { |
| 516 | if (!power_on_pending) { |
| 517 | return -EINVAL; |
Naseer Ahmed | b92e73f | 2016-03-12 02:03:48 -0500 | [diff] [blame] | 518 | } |
Ramkumar Radhakrishnan | a38b760 | 2018-03-15 14:49:52 -0700 | [diff] [blame] | 519 | |
| 520 | if (active_secure_sessions_[kSecureDisplay] != secure_sessions[kSecureDisplay]) { |
| 521 | SecureEvent secure_event = |
| 522 | secure_sessions.test(kSecureDisplay) ? kSecureDisplayStart : kSecureDisplayEnd; |
Pullakavi Srinivas | 0a1dba6 | 2018-07-02 15:49:11 +0530 | [diff] [blame] | 523 | DisplayError err = display_intf_->HandleSecureEvent(secure_event, &layer_stack_); |
Ramkumar Radhakrishnan | a38b760 | 2018-03-15 14:49:52 -0700 | [diff] [blame] | 524 | if (err != kErrorNone) { |
| 525 | DLOGE("Set secure event failed"); |
| 526 | return err; |
| 527 | } |
| 528 | |
| 529 | DLOGI("SecureDisplay state changed from %d to %d for display %d", |
| 530 | active_secure_sessions_.test(kSecureDisplay), secure_sessions.test(kSecureDisplay), |
| 531 | type_); |
| 532 | } |
| 533 | active_secure_sessions_ = secure_sessions; |
| 534 | *power_on_pending = false; |
| 535 | return 0; |
Naseer Ahmed | b92e73f | 2016-03-12 02:03:48 -0500 | [diff] [blame] | 536 | } |
| 537 | |
Dileep Marchya | f3ce11f | 2018-04-30 23:35:46 +0530 | [diff] [blame] | 538 | void HWCDisplayBuiltIn::ForceRefreshRate(uint32_t refresh_rate) { |
Naseer Ahmed | b92e73f | 2016-03-12 02:03:48 -0500 | [diff] [blame] | 539 | if ((refresh_rate && (refresh_rate < min_refresh_rate_ || refresh_rate > max_refresh_rate_)) || |
| 540 | force_refresh_rate_ == refresh_rate) { |
| 541 | // Cannot honor force refresh rate, as its beyond the range or new request is same |
| 542 | return; |
| 543 | } |
| 544 | |
| 545 | force_refresh_rate_ = refresh_rate; |
| 546 | |
| 547 | callbacks_->Refresh(HWC_DISPLAY_PRIMARY); |
| 548 | |
| 549 | return; |
| 550 | } |
| 551 | |
Dileep Marchya | f3ce11f | 2018-04-30 23:35:46 +0530 | [diff] [blame] | 552 | uint32_t HWCDisplayBuiltIn::GetOptimalRefreshRate(bool one_updating_layer) { |
Naseer Ahmed | b92e73f | 2016-03-12 02:03:48 -0500 | [diff] [blame] | 553 | if (force_refresh_rate_) { |
| 554 | return force_refresh_rate_; |
Naseer Ahmed | b92e73f | 2016-03-12 02:03:48 -0500 | [diff] [blame] | 555 | } else if (use_metadata_refresh_rate_ && one_updating_layer && metadata_refresh_rate_) { |
| 556 | return metadata_refresh_rate_; |
| 557 | } |
| 558 | |
| 559 | return max_refresh_rate_; |
| 560 | } |
| 561 | |
Dileep Marchya | f3ce11f | 2018-04-30 23:35:46 +0530 | [diff] [blame] | 562 | DisplayError HWCDisplayBuiltIn::Refresh() { |
Naseer Ahmed | b92e73f | 2016-03-12 02:03:48 -0500 | [diff] [blame] | 563 | DisplayError error = kErrorNone; |
| 564 | |
| 565 | callbacks_->Refresh(HWC_DISPLAY_PRIMARY); |
Naseer Ahmed | b92e73f | 2016-03-12 02:03:48 -0500 | [diff] [blame] | 566 | |
| 567 | return error; |
| 568 | } |
| 569 | |
Dileep Marchya | f3ce11f | 2018-04-30 23:35:46 +0530 | [diff] [blame] | 570 | void HWCDisplayBuiltIn::SetIdleTimeoutMs(uint32_t timeout_ms) { |
Naseer Ahmed | b92e73f | 2016-03-12 02:03:48 -0500 | [diff] [blame] | 571 | display_intf_->SetIdleTimeoutMs(timeout_ms); |
Saurabh Shah | a307e8c | 2017-09-28 18:05:40 -0700 | [diff] [blame] | 572 | validated_ = false; |
Naseer Ahmed | b92e73f | 2016-03-12 02:03:48 -0500 | [diff] [blame] | 573 | } |
| 574 | |
Dileep Marchya | f3ce11f | 2018-04-30 23:35:46 +0530 | [diff] [blame] | 575 | void HWCDisplayBuiltIn::HandleFrameOutput() { |
Sushil Chauhan | 0652158 | 2018-03-19 14:00:23 -0700 | [diff] [blame] | 576 | if (readback_buffer_queued_) { |
| 577 | validated_ = false; |
| 578 | } |
| 579 | |
| 580 | if (dump_output_to_file_) { |
Naseer Ahmed | b92e73f | 2016-03-12 02:03:48 -0500 | [diff] [blame] | 581 | HandleFrameDump(); |
| 582 | } |
| 583 | } |
| 584 | |
Dileep Marchya | f3ce11f | 2018-04-30 23:35:46 +0530 | [diff] [blame] | 585 | void HWCDisplayBuiltIn::HandleFrameDump() { |
Sushil Chauhan | 0652158 | 2018-03-19 14:00:23 -0700 | [diff] [blame] | 586 | if (!readback_configured_) { |
| 587 | dump_frame_count_ = 0; |
Naseer Ahmed | b92e73f | 2016-03-12 02:03:48 -0500 | [diff] [blame] | 588 | } |
| 589 | |
Sushil Chauhan | 0652158 | 2018-03-19 14:00:23 -0700 | [diff] [blame] | 590 | if (dump_frame_count_ && output_buffer_.release_fence_fd >= 0) { |
| 591 | int ret = sync_wait(output_buffer_.release_fence_fd, 1000); |
| 592 | ::close(output_buffer_.release_fence_fd); |
| 593 | output_buffer_.release_fence_fd = -1; |
| 594 | if (ret < 0) { |
| 595 | DLOGE("sync_wait error errno = %d, desc = %s", errno, strerror(errno)); |
| 596 | } else { |
Naseer Ahmed | b92e73f | 2016-03-12 02:03:48 -0500 | [diff] [blame] | 597 | DumpOutputBuffer(output_buffer_info_, output_buffer_base_, layer_stack_.retire_fence_fd); |
Sushil Chauhan | 0652158 | 2018-03-19 14:00:23 -0700 | [diff] [blame] | 598 | readback_buffer_queued_ = false; |
Sushil Chauhan | 062a7a4 | 2018-04-25 22:27:52 -0700 | [diff] [blame] | 599 | validated_ = false; |
Naseer Ahmed | b92e73f | 2016-03-12 02:03:48 -0500 | [diff] [blame] | 600 | } |
| 601 | } |
| 602 | |
| 603 | if (0 == dump_frame_count_) { |
| 604 | dump_output_to_file_ = false; |
| 605 | // Unmap and Free buffer |
| 606 | if (munmap(output_buffer_base_, output_buffer_info_.alloc_buffer_info.size) != 0) { |
| 607 | DLOGE("unmap failed with err %d", errno); |
| 608 | } |
| 609 | if (buffer_allocator_->FreeBuffer(&output_buffer_info_) != 0) { |
| 610 | DLOGE("FreeBuffer failed"); |
| 611 | } |
| 612 | |
Sushil Chauhan | 0652158 | 2018-03-19 14:00:23 -0700 | [diff] [blame] | 613 | readback_buffer_queued_ = false; |
Naseer Ahmed | b92e73f | 2016-03-12 02:03:48 -0500 | [diff] [blame] | 614 | post_processed_output_ = false; |
Sushil Chauhan | 0652158 | 2018-03-19 14:00:23 -0700 | [diff] [blame] | 615 | readback_configured_ = false; |
| 616 | |
Naseer Ahmed | b92e73f | 2016-03-12 02:03:48 -0500 | [diff] [blame] | 617 | output_buffer_ = {}; |
| 618 | output_buffer_info_ = {}; |
| 619 | output_buffer_base_ = nullptr; |
Naseer Ahmed | b92e73f | 2016-03-12 02:03:48 -0500 | [diff] [blame] | 620 | } |
| 621 | } |
| 622 | |
Sushil Chauhan | 267a619 | 2018-06-06 18:41:47 -0700 | [diff] [blame] | 623 | HWC2::Error HWCDisplayBuiltIn::SetFrameDumpConfig(uint32_t count, uint32_t bit_mask_layer_type, |
| 624 | int32_t format, bool post_processed) { |
| 625 | HWCDisplay::SetFrameDumpConfig(count, bit_mask_layer_type, format, post_processed); |
Naseer Ahmed | b92e73f | 2016-03-12 02:03:48 -0500 | [diff] [blame] | 626 | dump_output_to_file_ = bit_mask_layer_type & (1 << OUTPUT_LAYER_DUMP); |
| 627 | DLOGI("output_layer_dump_enable %d", dump_output_to_file_); |
| 628 | |
Sushil Chauhan | d0dc03d | 2018-09-19 07:08:40 -0700 | [diff] [blame] | 629 | if (!count || !dump_output_to_file_ || (output_buffer_info_.alloc_buffer_info.fd >= 0)) { |
Mathew Joseph Karimpanal | dbd64f8 | 2017-10-06 10:13:38 +0530 | [diff] [blame] | 630 | return HWC2::Error::None; |
Naseer Ahmed | b92e73f | 2016-03-12 02:03:48 -0500 | [diff] [blame] | 631 | } |
| 632 | |
| 633 | // Allocate and map output buffer |
Sushil Chauhan | 267a619 | 2018-06-06 18:41:47 -0700 | [diff] [blame] | 634 | if (post_processed) { |
| 635 | // To dump post-processed (DSPP) output, use Panel resolution. |
| 636 | GetPanelResolution(&output_buffer_info_.buffer_config.width, |
| 637 | &output_buffer_info_.buffer_config.height); |
| 638 | } else { |
| 639 | // To dump Layer Mixer output, use FrameBuffer resolution. |
| 640 | GetFrameBufferResolution(&output_buffer_info_.buffer_config.width, |
| 641 | &output_buffer_info_.buffer_config.height); |
| 642 | } |
| 643 | |
| 644 | output_buffer_info_.buffer_config.format = HWCLayer::GetSDMFormat(format, 0); |
Naseer Ahmed | b92e73f | 2016-03-12 02:03:48 -0500 | [diff] [blame] | 645 | output_buffer_info_.buffer_config.buffer_count = 1; |
| 646 | if (buffer_allocator_->AllocateBuffer(&output_buffer_info_) != 0) { |
| 647 | DLOGE("Buffer allocation failed"); |
| 648 | output_buffer_info_ = {}; |
Mathew Joseph Karimpanal | dbd64f8 | 2017-10-06 10:13:38 +0530 | [diff] [blame] | 649 | return HWC2::Error::NoResources; |
Naseer Ahmed | b92e73f | 2016-03-12 02:03:48 -0500 | [diff] [blame] | 650 | } |
| 651 | |
| 652 | void *buffer = mmap(NULL, output_buffer_info_.alloc_buffer_info.size, PROT_READ | PROT_WRITE, |
| 653 | MAP_SHARED, output_buffer_info_.alloc_buffer_info.fd, 0); |
| 654 | |
| 655 | if (buffer == MAP_FAILED) { |
| 656 | DLOGE("mmap failed with err %d", errno); |
| 657 | buffer_allocator_->FreeBuffer(&output_buffer_info_); |
| 658 | output_buffer_info_ = {}; |
Mathew Joseph Karimpanal | dbd64f8 | 2017-10-06 10:13:38 +0530 | [diff] [blame] | 659 | return HWC2::Error::NoResources; |
Naseer Ahmed | b92e73f | 2016-03-12 02:03:48 -0500 | [diff] [blame] | 660 | } |
| 661 | |
| 662 | output_buffer_base_ = buffer; |
Sushil Chauhan | 0652158 | 2018-03-19 14:00:23 -0700 | [diff] [blame] | 663 | const native_handle_t *handle = static_cast<native_handle_t *>(output_buffer_info_.private_data); |
Sushil Chauhan | 267a619 | 2018-06-06 18:41:47 -0700 | [diff] [blame] | 664 | SetReadbackBuffer(handle, -1, post_processed); |
Sushil Chauhan | 0652158 | 2018-03-19 14:00:23 -0700 | [diff] [blame] | 665 | |
Mathew Joseph Karimpanal | dbd64f8 | 2017-10-06 10:13:38 +0530 | [diff] [blame] | 666 | return HWC2::Error::None; |
Naseer Ahmed | b92e73f | 2016-03-12 02:03:48 -0500 | [diff] [blame] | 667 | } |
| 668 | |
Dileep Marchya | f3ce11f | 2018-04-30 23:35:46 +0530 | [diff] [blame] | 669 | int HWCDisplayBuiltIn::FrameCaptureAsync(const BufferInfo &output_buffer_info, |
Naseer Ahmed | b92e73f | 2016-03-12 02:03:48 -0500 | [diff] [blame] | 670 | bool post_processed_output) { |
| 671 | // Note: This function is called in context of a binder thread and a lock is already held |
| 672 | if (output_buffer_info.alloc_buffer_info.fd < 0) { |
| 673 | DLOGE("Invalid fd %d", output_buffer_info.alloc_buffer_info.fd); |
| 674 | return -1; |
| 675 | } |
| 676 | |
| 677 | auto panel_width = 0u; |
| 678 | auto panel_height = 0u; |
| 679 | auto fb_width = 0u; |
| 680 | auto fb_height = 0u; |
| 681 | |
| 682 | GetPanelResolution(&panel_width, &panel_height); |
| 683 | GetFrameBufferResolution(&fb_width, &fb_height); |
| 684 | |
Ch Ganesh Kumar | 5c4988b | 2017-06-07 15:21:02 +0530 | [diff] [blame] | 685 | if (post_processed_output && (output_buffer_info.buffer_config.width < panel_width || |
| 686 | output_buffer_info.buffer_config.height < panel_height)) { |
Naseer Ahmed | b92e73f | 2016-03-12 02:03:48 -0500 | [diff] [blame] | 687 | DLOGE("Buffer dimensions should not be less than panel resolution"); |
| 688 | return -1; |
Ch Ganesh Kumar | 5c4988b | 2017-06-07 15:21:02 +0530 | [diff] [blame] | 689 | } else if (!post_processed_output && (output_buffer_info.buffer_config.width < fb_width || |
| 690 | output_buffer_info.buffer_config.height < fb_height)) { |
Naseer Ahmed | b92e73f | 2016-03-12 02:03:48 -0500 | [diff] [blame] | 691 | DLOGE("Buffer dimensions should not be less than FB resolution"); |
| 692 | return -1; |
| 693 | } |
| 694 | |
Sushil Chauhan | 0652158 | 2018-03-19 14:00:23 -0700 | [diff] [blame] | 695 | const native_handle_t *buffer = static_cast<native_handle_t *>(output_buffer_info.private_data); |
| 696 | SetReadbackBuffer(buffer, -1, post_processed_output); |
Naseer Ahmed | b92e73f | 2016-03-12 02:03:48 -0500 | [diff] [blame] | 697 | |
| 698 | return 0; |
| 699 | } |
| 700 | |
Dileep Marchya | f3ce11f | 2018-04-30 23:35:46 +0530 | [diff] [blame] | 701 | bool HWCDisplayBuiltIn::GetFrameCaptureFence(int32_t *release_fence) { |
Sushil Chauhan | 0652158 | 2018-03-19 14:00:23 -0700 | [diff] [blame] | 702 | return (GetReadbackBufferFence(release_fence) == HWC2::Error::None); |
| 703 | } |
| 704 | |
Dileep Marchya | f3ce11f | 2018-04-30 23:35:46 +0530 | [diff] [blame] | 705 | DisplayError HWCDisplayBuiltIn::SetDetailEnhancerConfig |
Alan Kwong | 2e13633 | 2016-08-16 07:50:16 -0400 | [diff] [blame] | 706 | (const DisplayDetailEnhancerData &de_data) { |
| 707 | DisplayError error = kErrorNotSupported; |
| 708 | |
| 709 | if (display_intf_) { |
| 710 | error = display_intf_->SetDetailEnhancerData(de_data); |
Saurabh Shah | a307e8c | 2017-09-28 18:05:40 -0700 | [diff] [blame] | 711 | validated_ = false; |
Alan Kwong | 2e13633 | 2016-08-16 07:50:16 -0400 | [diff] [blame] | 712 | } |
| 713 | return error; |
| 714 | } |
| 715 | |
Dileep Marchya | f3ce11f | 2018-04-30 23:35:46 +0530 | [diff] [blame] | 716 | DisplayError HWCDisplayBuiltIn::ControlPartialUpdate(bool enable, uint32_t *pending) { |
Arun Kumar K.R | 17bbd04 | 2016-06-07 17:38:02 -0700 | [diff] [blame] | 717 | DisplayError error = kErrorNone; |
| 718 | |
| 719 | if (display_intf_) { |
| 720 | error = display_intf_->ControlPartialUpdate(enable, pending); |
Saurabh Shah | a307e8c | 2017-09-28 18:05:40 -0700 | [diff] [blame] | 721 | validated_ = false; |
Arun Kumar K.R | 17bbd04 | 2016-06-07 17:38:02 -0700 | [diff] [blame] | 722 | } |
| 723 | |
| 724 | return error; |
| 725 | } |
| 726 | |
Dileep Marchya | f3ce11f | 2018-04-30 23:35:46 +0530 | [diff] [blame] | 727 | DisplayError HWCDisplayBuiltIn::DisablePartialUpdateOneFrame() { |
Arun Kumar K.R | 17bbd04 | 2016-06-07 17:38:02 -0700 | [diff] [blame] | 728 | DisplayError error = kErrorNone; |
| 729 | |
| 730 | if (display_intf_) { |
| 731 | error = display_intf_->DisablePartialUpdateOneFrame(); |
Saurabh Shah | a307e8c | 2017-09-28 18:05:40 -0700 | [diff] [blame] | 732 | validated_ = false; |
Arun Kumar K.R | 17bbd04 | 2016-06-07 17:38:02 -0700 | [diff] [blame] | 733 | } |
| 734 | |
| 735 | return error; |
| 736 | } |
| 737 | |
| 738 | |
Dileep Marchya | f3ce11f | 2018-04-30 23:35:46 +0530 | [diff] [blame] | 739 | DisplayError HWCDisplayBuiltIn::SetMixerResolution(uint32_t width, uint32_t height) { |
Sushil Chauhan | 409e844 | 2017-06-12 17:43:25 -0700 | [diff] [blame] | 740 | DisplayError error = display_intf_->SetMixerResolution(width, height); |
Saurabh Shah | a307e8c | 2017-09-28 18:05:40 -0700 | [diff] [blame] | 741 | validated_ = false; |
Sushil Chauhan | 409e844 | 2017-06-12 17:43:25 -0700 | [diff] [blame] | 742 | return error; |
Arun Kumar K.R | 8da7f50 | 2016-06-07 17:45:50 -0700 | [diff] [blame] | 743 | } |
| 744 | |
Dileep Marchya | f3ce11f | 2018-04-30 23:35:46 +0530 | [diff] [blame] | 745 | DisplayError HWCDisplayBuiltIn::GetMixerResolution(uint32_t *width, uint32_t *height) { |
Arun Kumar K.R | 8da7f50 | 2016-06-07 17:45:50 -0700 | [diff] [blame] | 746 | return display_intf_->GetMixerResolution(width, height); |
| 747 | } |
| 748 | |
Dileep Marchya | f3ce11f | 2018-04-30 23:35:46 +0530 | [diff] [blame] | 749 | HWC2::Error HWCDisplayBuiltIn::SetQSyncMode(QSyncMode qsync_mode) { |
Sushil Chauhan | 380a59d | 2018-03-19 15:47:50 -0700 | [diff] [blame] | 750 | auto err = display_intf_->SetQSyncMode(qsync_mode); |
| 751 | if (err != kErrorNone) { |
| 752 | return HWC2::Error::Unsupported; |
| 753 | } |
| 754 | |
| 755 | return HWC2::Error::None; |
| 756 | } |
| 757 | |
Ramkumar Radhakrishnan | 4faf8a6 | 2018-11-15 17:15:37 -0800 | [diff] [blame^] | 758 | DisplayError HWCDisplayBuiltIn::ControlIdlePowerCollapse(bool enable, bool synchronous) { |
Ramkumar Radhakrishnan | f985d48 | 2018-07-23 18:10:41 -0700 | [diff] [blame] | 759 | DisplayError error = kErrorNone; |
| 760 | |
| 761 | if (display_intf_) { |
| 762 | error = display_intf_->ControlIdlePowerCollapse(enable, synchronous); |
| 763 | validated_ = false; |
| 764 | } |
Ramkumar Radhakrishnan | 4faf8a6 | 2018-11-15 17:15:37 -0800 | [diff] [blame^] | 765 | return error; |
Ramkumar Radhakrishnan | f985d48 | 2018-07-23 18:10:41 -0700 | [diff] [blame] | 766 | } |
| 767 | |
Naseer Ahmed | b92e73f | 2016-03-12 02:03:48 -0500 | [diff] [blame] | 768 | } // namespace sdm |