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