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