Naseer Ahmed | b92e73f | 2016-03-12 02:03:48 -0500 | [diff] [blame] | 1 | /* |
Rajavenu Kyatham | 7338b9e | 2019-12-30 19:52:16 +0530 | [diff] [blame] | 2 | * Copyright (c) 2014-2020, 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 | |
Pullakavi Srinivas | 1ae4acb | 2019-11-18 19:33:45 +0530 | [diff] [blame] | 50 | static void SetRect(LayerRect &src_rect, GLRect *target) { |
| 51 | target->left = src_rect.left; |
| 52 | target->top = src_rect.top; |
| 53 | target->right = src_rect.right; |
| 54 | target->bottom = src_rect.bottom; |
| 55 | } |
| 56 | |
Dileep Marchya | f3ce11f | 2018-04-30 23:35:46 +0530 | [diff] [blame] | 57 | int HWCDisplayBuiltIn::Create(CoreInterface *core_intf, BufferAllocator *buffer_allocator, |
Varun Arora | 7c8ee54 | 2018-05-01 20:58:16 -0700 | [diff] [blame] | 58 | HWCCallbacks *callbacks, HWCDisplayEventHandler *event_handler, |
Dileep Marchya | f3ce11f | 2018-04-30 23:35:46 +0530 | [diff] [blame] | 59 | qService::QService *qservice, hwc2_display_t id, int32_t sdm_id, |
| 60 | HWCDisplay **hwc_display) { |
Naseer Ahmed | b92e73f | 2016-03-12 02:03:48 -0500 | [diff] [blame] | 61 | int status = 0; |
Dileep Marchya | f3ce11f | 2018-04-30 23:35:46 +0530 | [diff] [blame] | 62 | uint32_t builtin_width = 0; |
| 63 | uint32_t builtin_height = 0; |
Naseer Ahmed | b92e73f | 2016-03-12 02:03:48 -0500 | [diff] [blame] | 64 | |
Dileep Marchya | f3ce11f | 2018-04-30 23:35:46 +0530 | [diff] [blame] | 65 | HWCDisplay *hwc_display_builtin = |
| 66 | new HWCDisplayBuiltIn(core_intf, buffer_allocator, callbacks, event_handler, qservice, id, |
| 67 | sdm_id); |
| 68 | status = hwc_display_builtin->Init(); |
Naseer Ahmed | b92e73f | 2016-03-12 02:03:48 -0500 | [diff] [blame] | 69 | if (status) { |
Dileep Marchya | f3ce11f | 2018-04-30 23:35:46 +0530 | [diff] [blame] | 70 | delete hwc_display_builtin; |
Naseer Ahmed | b92e73f | 2016-03-12 02:03:48 -0500 | [diff] [blame] | 71 | return status; |
| 72 | } |
| 73 | |
Dileep Marchya | f3ce11f | 2018-04-30 23:35:46 +0530 | [diff] [blame] | 74 | hwc_display_builtin->GetMixerResolution(&builtin_width, &builtin_height); |
Naseer Ahmed | b92e73f | 2016-03-12 02:03:48 -0500 | [diff] [blame] | 75 | int width = 0, height = 0; |
Uday Kiran Pichika | 5e656b2 | 2018-05-15 18:48:24 +0530 | [diff] [blame] | 76 | HWCDebugHandler::Get()->GetProperty(FB_WIDTH_PROP, &width); |
| 77 | HWCDebugHandler::Get()->GetProperty(FB_HEIGHT_PROP, &height); |
Naseer Ahmed | b92e73f | 2016-03-12 02:03:48 -0500 | [diff] [blame] | 78 | if (width > 0 && height > 0) { |
Dileep Marchya | f3ce11f | 2018-04-30 23:35:46 +0530 | [diff] [blame] | 79 | builtin_width = UINT32(width); |
| 80 | builtin_height = UINT32(height); |
Naseer Ahmed | b92e73f | 2016-03-12 02:03:48 -0500 | [diff] [blame] | 81 | } |
| 82 | |
Dileep Marchya | f3ce11f | 2018-04-30 23:35:46 +0530 | [diff] [blame] | 83 | status = hwc_display_builtin->SetFrameBufferResolution(builtin_width, builtin_height); |
Naseer Ahmed | b92e73f | 2016-03-12 02:03:48 -0500 | [diff] [blame] | 84 | if (status) { |
Dileep Marchya | f3ce11f | 2018-04-30 23:35:46 +0530 | [diff] [blame] | 85 | Destroy(hwc_display_builtin); |
Naseer Ahmed | b92e73f | 2016-03-12 02:03:48 -0500 | [diff] [blame] | 86 | return status; |
| 87 | } |
| 88 | |
Dileep Marchya | f3ce11f | 2018-04-30 23:35:46 +0530 | [diff] [blame] | 89 | *hwc_display = hwc_display_builtin; |
Naseer Ahmed | b92e73f | 2016-03-12 02:03:48 -0500 | [diff] [blame] | 90 | |
| 91 | return status; |
| 92 | } |
| 93 | |
Dileep Marchya | f3ce11f | 2018-04-30 23:35:46 +0530 | [diff] [blame] | 94 | void HWCDisplayBuiltIn::Destroy(HWCDisplay *hwc_display) { |
Naseer Ahmed | b92e73f | 2016-03-12 02:03:48 -0500 | [diff] [blame] | 95 | hwc_display->Deinit(); |
| 96 | delete hwc_display; |
| 97 | } |
| 98 | |
Dileep Marchya | f3ce11f | 2018-04-30 23:35:46 +0530 | [diff] [blame] | 99 | HWCDisplayBuiltIn::HWCDisplayBuiltIn(CoreInterface *core_intf, BufferAllocator *buffer_allocator, |
Varun Arora | 7c8ee54 | 2018-05-01 20:58:16 -0700 | [diff] [blame] | 100 | HWCCallbacks *callbacks, HWCDisplayEventHandler *event_handler, |
Dileep Marchya | f3ce11f | 2018-04-30 23:35:46 +0530 | [diff] [blame] | 101 | qService::QService *qservice, hwc2_display_t id, |
| 102 | int32_t sdm_id) |
| 103 | : HWCDisplay(core_intf, buffer_allocator, callbacks, event_handler, qservice, kBuiltIn, id, |
Gousemoodhin Nadaf | 087c310 | 2019-01-07 19:34:56 +0530 | [diff] [blame] | 104 | sdm_id, DISPLAY_CLASS_BUILTIN), |
Dileep Marchya | f3ce11f | 2018-04-30 23:35:46 +0530 | [diff] [blame] | 105 | buffer_allocator_(buffer_allocator), |
Pullakavi Srinivas | 1ae4acb | 2019-11-18 19:33:45 +0530 | [diff] [blame] | 106 | cpu_hint_(NULL), layer_stitch_task_(*this) { |
Naseer Ahmed | b92e73f | 2016-03-12 02:03:48 -0500 | [diff] [blame] | 107 | } |
| 108 | |
Dileep Marchya | f3ce11f | 2018-04-30 23:35:46 +0530 | [diff] [blame] | 109 | int HWCDisplayBuiltIn::Init() { |
Naseer Ahmed | b92e73f | 2016-03-12 02:03:48 -0500 | [diff] [blame] | 110 | cpu_hint_ = new CPUHint(); |
| 111 | if (cpu_hint_->Init(static_cast<HWCDebugHandler *>(HWCDebugHandler::Get())) != kErrorNone) { |
| 112 | delete cpu_hint_; |
| 113 | cpu_hint_ = NULL; |
| 114 | } |
| 115 | |
| 116 | use_metadata_refresh_rate_ = true; |
| 117 | int disable_metadata_dynfps = 0; |
Uday Kiran Pichika | 5e656b2 | 2018-05-15 18:48:24 +0530 | [diff] [blame] | 118 | HWCDebugHandler::Get()->GetProperty(DISABLE_METADATA_DYNAMIC_FPS_PROP, &disable_metadata_dynfps); |
Naseer Ahmed | b92e73f | 2016-03-12 02:03:48 -0500 | [diff] [blame] | 119 | if (disable_metadata_dynfps) { |
| 120 | use_metadata_refresh_rate_ = false; |
| 121 | } |
| 122 | |
Arun Kumar K.R | 29cd658 | 2016-05-10 19:12:45 -0700 | [diff] [blame] | 123 | int status = HWCDisplay::Init(); |
| 124 | if (status) { |
| 125 | return status; |
| 126 | } |
| 127 | color_mode_ = new HWCColorMode(display_intf_); |
Naseer Ahmed | 61f6095 | 2017-05-24 16:48:35 -0400 | [diff] [blame] | 128 | color_mode_->Init(); |
Arun Kumar K.R | 29cd658 | 2016-05-10 19:12:45 -0700 | [diff] [blame] | 129 | |
Padmanabhan Komanduru | 866bf6a | 2019-03-19 14:30:48 +0530 | [diff] [blame] | 130 | int optimize_refresh = 0; |
| 131 | HWCDebugHandler::Get()->GetProperty(ENABLE_OPTIMIZE_REFRESH, &optimize_refresh); |
| 132 | enable_optimize_refresh_ = (optimize_refresh == 1); |
| 133 | if (enable_optimize_refresh_) { |
Pullakavi Srinivas | ce3692b | 2020-02-13 01:14:09 +0530 | [diff] [blame] | 134 | DLOGI("Drop redundant drawcycles %" PRIu64 , id_); |
Padmanabhan Komanduru | e74cf4f | 2019-04-25 17:38:43 -0700 | [diff] [blame] | 135 | } |
| 136 | |
Sushil Chauhan | dbd8db4 | 2020-02-28 13:07:48 -0800 | [diff] [blame] | 137 | int vsyncs = 0; |
| 138 | HWCDebugHandler::Get()->GetProperty(DEFER_FPS_FRAME_COUNT, &vsyncs); |
| 139 | if (vsyncs > 0) { |
| 140 | SetVsyncsApplyRateChange(UINT32(vsyncs)); |
| 141 | } |
| 142 | |
Mathew Joseph Karimpanal | b1c1586 | 2019-07-04 11:14:24 +0530 | [diff] [blame] | 143 | is_primary_ = display_intf_->IsPrimaryDisplay(); |
| 144 | |
Rajavenu Kyatham | f87a7a7 | 2019-12-05 16:43:07 +0530 | [diff] [blame] | 145 | if (is_primary_) { |
Padmanabhan Komanduru | b5ff0fb | 2020-02-12 18:08:04 +0530 | [diff] [blame] | 146 | int enable_bw_limits = 0; |
| 147 | HWCDebugHandler::Get()->GetProperty(ENABLE_BW_LIMITS, &enable_bw_limits); |
| 148 | enable_bw_limits_ = (enable_bw_limits == 1); |
| 149 | if (enable_bw_limits_) { |
Pullakavi Srinivas | ce3692b | 2020-02-13 01:14:09 +0530 | [diff] [blame] | 150 | DLOGI("Enable BW Limits %" PRIu64, id_); |
Padmanabhan Komanduru | b5ff0fb | 2020-02-12 18:08:04 +0530 | [diff] [blame] | 151 | } |
Pullakavi Srinivas | d32b492 | 2020-02-10 10:08:31 +0530 | [diff] [blame] | 152 | windowed_display_ = Debug::GetWindowRect(&window_rect_.left, &window_rect_.top, |
| 153 | &window_rect_.right, &window_rect_.bottom) != kErrorUndefined; |
Rajavenu Kyatham | f87a7a7 | 2019-12-05 16:43:07 +0530 | [diff] [blame] | 154 | DLOGI("Window rect : [%f %f %f %f]", window_rect_.left, window_rect_.top, |
Pullakavi Srinivas | d32b492 | 2020-02-10 10:08:31 +0530 | [diff] [blame] | 155 | window_rect_.right, window_rect_.bottom); |
Rajavenu Kyatham | f87a7a7 | 2019-12-05 16:43:07 +0530 | [diff] [blame] | 156 | } |
Pullakavi Srinivas | 7bdcc76 | 2020-03-06 12:41:36 +0530 | [diff] [blame] | 157 | |
| 158 | uint32_t config_index = 0; |
| 159 | GetActiveDisplayConfig(&config_index); |
| 160 | DisplayConfigVariableInfo attr = {}; |
| 161 | GetDisplayAttributesForConfig(INT(config_index), &attr); |
| 162 | active_refresh_rate_ = attr.fps; |
| 163 | |
| 164 | DLOGI("active_refresh_rate: %d", active_refresh_rate_); |
| 165 | |
Naseer Ahmed | 61f6095 | 2017-05-24 16:48:35 -0400 | [diff] [blame] | 166 | return status; |
Naseer Ahmed | b92e73f | 2016-03-12 02:03:48 -0500 | [diff] [blame] | 167 | } |
| 168 | |
Dileep Marchya | 5892812 | 2020-01-28 12:16:51 +0530 | [diff] [blame] | 169 | void HWCDisplayBuiltIn::Dump(std::ostringstream *os) { |
| 170 | HWCDisplay::Dump(os); |
| 171 | *os << histogram.Dump(); |
Lakshmi Narayana Kalavala | 25fe12c | 2019-12-11 20:44:55 -0800 | [diff] [blame] | 172 | } |
| 173 | |
Dileep Marchya | f3ce11f | 2018-04-30 23:35:46 +0530 | [diff] [blame] | 174 | 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] | 175 | auto status = HWC2::Error::None; |
| 176 | DisplayError error = kErrorNone; |
| 177 | |
Gurpreet Singh Dhami | a427688 | 2019-04-12 10:30:58 -0700 | [diff] [blame] | 178 | DTRACE_SCOPED(); |
| 179 | |
Mathew Joseph Karimpanal | b1c1586 | 2019-07-04 11:14:24 +0530 | [diff] [blame] | 180 | if (display_paused_ || (!is_primary_ && active_secure_sessions_[kSecureDisplay])) { |
Naseer Ahmed | b92e73f | 2016-03-12 02:03:48 -0500 | [diff] [blame] | 181 | MarkLayersForGPUBypass(); |
| 182 | return status; |
| 183 | } |
| 184 | |
Arun Kumar K.R | 29cd658 | 2016-05-10 19:12:45 -0700 | [diff] [blame] | 185 | if (color_tranform_failed_) { |
| 186 | // Must fall back to client composition |
| 187 | MarkLayersForClientComposition(); |
| 188 | } |
| 189 | |
Naseer Ahmed | b92e73f | 2016-03-12 02:03:48 -0500 | [diff] [blame] | 190 | // Fill in the remaining blanks in the layers and add them to the SDM layerstack |
| 191 | BuildLayerStack(); |
Pullakavi Srinivas | 1ae4acb | 2019-11-18 19:33:45 +0530 | [diff] [blame] | 192 | |
| 193 | // Add stitch layer to layer stack. |
| 194 | AppendStitchLayer(); |
| 195 | |
Arun Kumar K.R | 536c7d6 | 2016-06-14 18:47:39 -0700 | [diff] [blame] | 196 | // Checks and replaces layer stack for solid fill |
| 197 | SolidFillPrepare(); |
Naseer Ahmed | b92e73f | 2016-03-12 02:03:48 -0500 | [diff] [blame] | 198 | |
Sushil Chauhan | 8008d60 | 2018-09-04 14:43:27 -0700 | [diff] [blame] | 199 | // Apply current Color Mode and Render Intent. |
Xu Yang | 84e6141 | 2018-12-06 14:52:16 +0800 | [diff] [blame] | 200 | if (color_mode_->ApplyCurrentColorModeWithRenderIntent( |
| 201 | static_cast<bool>(layer_stack_.flags.hdr_present)) != HWC2::Error::None) { |
Sushil Chauhan | 8008d60 | 2018-09-04 14:43:27 -0700 | [diff] [blame] | 202 | // Fallback to GPU Composition, if Color Mode can't be applied. |
| 203 | MarkLayersForClientComposition(); |
| 204 | } |
| 205 | |
Naseer Ahmed | b92e73f | 2016-03-12 02:03:48 -0500 | [diff] [blame] | 206 | bool pending_output_dump = dump_frame_count_ && dump_output_to_file_; |
| 207 | |
Sushil Chauhan | 0652158 | 2018-03-19 14:00:23 -0700 | [diff] [blame] | 208 | if (readback_buffer_queued_ || pending_output_dump) { |
Naseer Ahmed | b92e73f | 2016-03-12 02:03:48 -0500 | [diff] [blame] | 209 | // 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] | 210 | // here in a subsequent draw round. Readback is not allowed for any secure use case. |
| 211 | readback_configured_ = !layer_stack_.flags.secure_present; |
| 212 | if (readback_configured_) { |
Sushil Chauhan | f42d862 | 2018-09-30 23:20:37 -0700 | [diff] [blame] | 213 | DisablePartialUpdateOneFrame(); |
Sushil Chauhan | 0652158 | 2018-03-19 14:00:23 -0700 | [diff] [blame] | 214 | layer_stack_.output_buffer = &output_buffer_; |
| 215 | layer_stack_.flags.post_processed_output = post_processed_output_; |
| 216 | } |
Naseer Ahmed | b92e73f | 2016-03-12 02:03:48 -0500 | [diff] [blame] | 217 | } |
| 218 | |
Ramakant Singh | 5db0dfb | 2017-08-23 12:34:57 +0530 | [diff] [blame] | 219 | uint32_t num_updating_layers = GetUpdatingLayersCount(); |
| 220 | bool one_updating_layer = (num_updating_layers == 1); |
| 221 | if (num_updating_layers != 0) { |
| 222 | ToggleCPUHint(one_updating_layer); |
| 223 | } |
Naseer Ahmed | b92e73f | 2016-03-12 02:03:48 -0500 | [diff] [blame] | 224 | |
| 225 | uint32_t refresh_rate = GetOptimalRefreshRate(one_updating_layer); |
Pullakavi Srinivas | 4619db9 | 2019-04-20 15:07:59 +0530 | [diff] [blame] | 226 | error = display_intf_->SetRefreshRate(refresh_rate, force_refresh_rate_); |
| 227 | |
| 228 | // Get the refresh rate set. |
| 229 | display_intf_->GetRefreshRate(&refresh_rate); |
| 230 | bool vsync_source = (callbacks_->GetVsyncSource() == id_); |
| 231 | |
Naseer Ahmed | b92e73f | 2016-03-12 02:03:48 -0500 | [diff] [blame] | 232 | if (error == kErrorNone) { |
Pullakavi Srinivas | 4619db9 | 2019-04-20 15:07:59 +0530 | [diff] [blame] | 233 | if (vsync_source && (current_refresh_rate_ < refresh_rate)) { |
| 234 | DTRACE_BEGIN("HWC2::Vsync::Enable"); |
| 235 | // Display is ramping up from idle. |
| 236 | // Client realizes need for resync upon change in config. |
| 237 | // Since we know config has changed, triggering vsync proactively |
| 238 | // can help in reducing pipeline delays to enable events. |
| 239 | SetVsyncEnabled(HWC2::Vsync::Enable); |
| 240 | DTRACE_END(); |
| 241 | } |
| 242 | // On success, set current refresh rate to new refresh rate. |
Naseer Ahmed | b92e73f | 2016-03-12 02:03:48 -0500 | [diff] [blame] | 243 | current_refresh_rate_ = refresh_rate; |
| 244 | } |
| 245 | |
Naseer Ahmed | b92e73f | 2016-03-12 02:03:48 -0500 | [diff] [blame] | 246 | if (layer_set_.empty()) { |
Uday Kiran Pichika | 8d82773 | 2018-01-09 18:08:38 +0530 | [diff] [blame] | 247 | // Avoid flush for Command mode panel. |
Pullakavi Srinivas | 2d55f3a | 2019-07-16 14:49:06 +0530 | [diff] [blame] | 248 | flush_ = !client_connected_; |
Ramkumar Radhakrishnan | a38b760 | 2018-03-15 14:49:52 -0700 | [diff] [blame] | 249 | validated_ = true; |
Naseer Ahmed | b92e73f | 2016-03-12 02:03:48 -0500 | [diff] [blame] | 250 | return status; |
| 251 | } |
| 252 | |
| 253 | status = PrepareLayerStack(out_num_types, out_num_requests); |
Namit Solanki | 5b428dc | 2018-02-27 11:39:05 +0530 | [diff] [blame] | 254 | pending_commit_ = true; |
Naseer Ahmed | b92e73f | 2016-03-12 02:03:48 -0500 | [diff] [blame] | 255 | return status; |
| 256 | } |
| 257 | |
Padmanabhan Komanduru | e74cf4f | 2019-04-25 17:38:43 -0700 | [diff] [blame] | 258 | HWC2::Error HWCDisplayBuiltIn::CommitLayerStack() { |
| 259 | skip_commit_ = CanSkipCommit(); |
| 260 | return HWCDisplay::CommitLayerStack(); |
| 261 | } |
| 262 | |
| 263 | bool HWCDisplayBuiltIn::CanSkipCommit() { |
| 264 | if (layer_stack_invalid_) { |
| 265 | return false; |
| 266 | } |
| 267 | |
| 268 | // Reject repeated drawcycle requests if it satisfies all conditions. |
| 269 | // 1. None of the layerstack attributes changed. |
| 270 | // 2. No new buffer latched. |
| 271 | // 3. No refresh request triggered by HWC. |
| 272 | // 4. This display is not source of vsync. |
| 273 | bool buffers_latched = false; |
| 274 | for (auto &hwc_layer : layer_set_) { |
| 275 | buffers_latched |= hwc_layer->BufferLatched(); |
| 276 | hwc_layer->ResetBufferFlip(); |
| 277 | } |
| 278 | |
Padmanabhan Komanduru | f5e6c5d | 2019-04-04 13:56:31 +0530 | [diff] [blame] | 279 | bool vsync_source = (callbacks_->GetVsyncSource() == id_); |
Padmanabhan Komanduru | 866bf6a | 2019-03-19 14:30:48 +0530 | [diff] [blame] | 280 | bool skip_commit = enable_optimize_refresh_ && !pending_commit_ && !buffers_latched && |
Padmanabhan Komanduru | f5e6c5d | 2019-04-04 13:56:31 +0530 | [diff] [blame] | 281 | !pending_refresh_ && !vsync_source; |
Padmanabhan Komanduru | e74cf4f | 2019-04-25 17:38:43 -0700 | [diff] [blame] | 282 | pending_refresh_ = false; |
| 283 | |
| 284 | return skip_commit; |
| 285 | } |
| 286 | |
Pullakavi Srinivas | 1ae4acb | 2019-11-18 19:33:45 +0530 | [diff] [blame] | 287 | HWC2::Error HWCDisplayBuiltIn::CommitStitchLayers() { |
Pullakavi Srinivas | db2b84a | 2019-11-21 14:47:35 +0530 | [diff] [blame] | 288 | if (disable_layer_stitch_) { |
Pullakavi Srinivas | 1ae4acb | 2019-11-18 19:33:45 +0530 | [diff] [blame] | 289 | return HWC2::Error::None; |
| 290 | } |
| 291 | |
Pullakavi Srinivas | db2b84a | 2019-11-21 14:47:35 +0530 | [diff] [blame] | 292 | if (!validated_ || skip_commit_) { |
Pullakavi Srinivas | 1ae4acb | 2019-11-18 19:33:45 +0530 | [diff] [blame] | 293 | return HWC2::Error::None; |
| 294 | } |
| 295 | |
| 296 | for (auto &layer : layer_stack_.layers) { |
| 297 | LayerComposition &composition = layer->composition; |
| 298 | if (composition != kCompositionStitch) { |
| 299 | continue; |
| 300 | } |
| 301 | |
Pullakavi Srinivas | db2b84a | 2019-11-21 14:47:35 +0530 | [diff] [blame] | 302 | LayerStitchContext ctx = {}; |
Pullakavi Srinivas | 1ae4acb | 2019-11-18 19:33:45 +0530 | [diff] [blame] | 303 | // Stitch target doesn't have an input fence. |
| 304 | // Render all layers at specified destination. |
| 305 | LayerBuffer &input_buffer = layer->input_buffer; |
| 306 | ctx.src_hnd = reinterpret_cast<const private_handle_t *>(input_buffer.buffer_id); |
| 307 | Layer *stitch_layer = stitch_target_->GetSDMLayer(); |
| 308 | LayerBuffer &output_buffer = stitch_layer->input_buffer; |
| 309 | ctx.dst_hnd = reinterpret_cast<const private_handle_t *>(output_buffer.buffer_id); |
Pullakavi Srinivas | f25bc4a | 2020-02-27 12:07:39 +0530 | [diff] [blame] | 310 | SetRect(layer->stitch_info.dst_rect, &ctx.dst_rect); |
| 311 | SetRect(layer->stitch_info.slice_rect, &ctx.scissor_rect); |
Rajavenu Kyatham | 7338b9e | 2019-12-30 19:52:16 +0530 | [diff] [blame] | 312 | ctx.src_acquire_fence = input_buffer.acquire_fence; |
Pullakavi Srinivas | 1ae4acb | 2019-11-18 19:33:45 +0530 | [diff] [blame] | 313 | |
| 314 | layer_stitch_task_.PerformTask(LayerStitchTaskCode::kCodeStitch, &ctx); |
| 315 | |
Rajavenu Kyatham | 7338b9e | 2019-12-30 19:52:16 +0530 | [diff] [blame] | 316 | // Merge with current fence. |
| 317 | output_buffer.acquire_fence = Fence::Merge(output_buffer.acquire_fence, ctx.release_fence); |
Pullakavi Srinivas | 1ae4acb | 2019-11-18 19:33:45 +0530 | [diff] [blame] | 318 | } |
| 319 | |
| 320 | return HWC2::Error::None; |
| 321 | } |
| 322 | |
Padmanabhan Komanduru | 6693fcb | 2019-11-22 21:06:52 +0530 | [diff] [blame] | 323 | void HWCDisplayBuiltIn::CacheAvrStatus() { |
| 324 | QSyncMode qsync_mode = kQSyncModeNone; |
| 325 | |
| 326 | DisplayError error = display_intf_->GetQSyncMode(&qsync_mode); |
| 327 | if (error != kErrorNone) { |
| 328 | return; |
| 329 | } |
| 330 | |
| 331 | bool qsync_enabled = (qsync_mode != kQSyncModeNone); |
| 332 | if (qsync_enabled_ != qsync_enabled) { |
| 333 | qsync_reconfigured_ = true; |
| 334 | qsync_enabled_ = qsync_enabled; |
| 335 | } else { |
| 336 | qsync_reconfigured_ = false; |
| 337 | } |
| 338 | } |
| 339 | |
| 340 | bool HWCDisplayBuiltIn::IsQsyncCallbackNeeded(bool *qsync_enabled, int32_t *refresh_rate, |
| 341 | int32_t *qsync_refresh_rate) { |
| 342 | if (!qsync_reconfigured_) { |
| 343 | return false; |
| 344 | } |
| 345 | |
| 346 | bool vsync_source = (callbacks_->GetVsyncSource() == id_); |
| 347 | // Qsync callback not needed if this display is not the source of vsync |
| 348 | if (!vsync_source) { |
| 349 | return false; |
| 350 | } |
| 351 | |
| 352 | *qsync_enabled = qsync_enabled_; |
| 353 | uint32_t current_rate = 0; |
| 354 | display_intf_->GetRefreshRate(¤t_rate); |
| 355 | *refresh_rate = INT32(current_rate); |
| 356 | *qsync_refresh_rate = min_refresh_rate_; |
| 357 | |
| 358 | return true; |
| 359 | } |
| 360 | |
Padmanabhan Komanduru | b5ff0fb | 2020-02-12 18:08:04 +0530 | [diff] [blame] | 361 | int HWCDisplayBuiltIn::GetBwCode(const DisplayConfigVariableInfo &attr) { |
| 362 | uint32_t min_refresh_rate = 0, max_refresh_rate = 0; |
| 363 | display_intf_->GetRefreshRateRange(&min_refresh_rate, &max_refresh_rate); |
| 364 | uint32_t fps = attr.smart_panel ? attr.fps : max_refresh_rate; |
| 365 | |
| 366 | if (fps <= 60) { |
| 367 | return kBwLow; |
| 368 | } else if (fps <= 90) { |
| 369 | return kBwMedium; |
| 370 | } else { |
| 371 | return kBwHigh; |
| 372 | } |
| 373 | } |
| 374 | |
| 375 | void HWCDisplayBuiltIn::SetBwLimitHint(bool enable) { |
| 376 | if (!enable_bw_limits_) { |
| 377 | return; |
| 378 | } |
| 379 | |
| 380 | if (!enable) { |
| 381 | thermal_bandwidth_client_cancel_request(const_cast<char*>(kDisplayBwName)); |
| 382 | curr_refresh_rate_ = 0; |
| 383 | return; |
| 384 | } |
| 385 | |
| 386 | uint32_t config_index = 0; |
| 387 | DisplayConfigVariableInfo attr = {}; |
| 388 | GetActiveDisplayConfig(&config_index); |
| 389 | GetDisplayAttributesForConfig(INT(config_index), &attr); |
| 390 | if (attr.fps != curr_refresh_rate_ || attr.smart_panel != is_smart_panel_) { |
| 391 | int bw_code = GetBwCode(attr); |
| 392 | int req_data = thermal_bandwidth_client_merge_input_info(bw_code, 0); |
| 393 | int error = thermal_bandwidth_client_request(const_cast<char*>(kDisplayBwName), req_data); |
| 394 | if (error) { |
| 395 | DLOGE("Thermal bandwidth request failed %d", error); |
| 396 | } |
| 397 | curr_refresh_rate_ = attr.fps; |
| 398 | is_smart_panel_ = attr.smart_panel; |
| 399 | } |
| 400 | } |
| 401 | |
Padmanabhan Komanduru | 5ec3a87 | 2020-04-13 14:19:16 +0530 | [diff] [blame] | 402 | void HWCDisplayBuiltIn::SetPartialUpdate(DisplayConfigFixedInfo fixed_info) { |
| 403 | partial_update_enabled_ = fixed_info.partial_update || (!fixed_info.is_cmdmode); |
| 404 | for (auto hwc_layer : layer_set_) { |
| 405 | hwc_layer->SetPartialUpdate(partial_update_enabled_); |
| 406 | } |
| 407 | client_target_->SetPartialUpdate(partial_update_enabled_); |
| 408 | } |
| 409 | |
Padmanabhan Komanduru | b5ff0fb | 2020-02-12 18:08:04 +0530 | [diff] [blame] | 410 | HWC2::Error HWCDisplayBuiltIn::SetPowerMode(HWC2::PowerMode mode, bool teardown) { |
Padmanabhan Komanduru | 5ec3a87 | 2020-04-13 14:19:16 +0530 | [diff] [blame] | 411 | DisplayConfigFixedInfo fixed_info = {}; |
| 412 | display_intf_->GetConfig(&fixed_info); |
| 413 | bool command_mode = fixed_info.is_cmdmode; |
| 414 | |
Padmanabhan Komanduru | b5ff0fb | 2020-02-12 18:08:04 +0530 | [diff] [blame] | 415 | auto status = HWCDisplay::SetPowerMode(mode, teardown); |
| 416 | if (status != HWC2::Error::None) { |
| 417 | return status; |
| 418 | } |
| 419 | |
Padmanabhan Komanduru | 5ec3a87 | 2020-04-13 14:19:16 +0530 | [diff] [blame] | 420 | display_intf_->GetConfig(&fixed_info); |
| 421 | is_cmd_mode_ = fixed_info.is_cmdmode; |
| 422 | if (is_cmd_mode_ != command_mode) { |
| 423 | SetPartialUpdate(fixed_info); |
| 424 | } |
| 425 | |
Padmanabhan Komanduru | b5ff0fb | 2020-02-12 18:08:04 +0530 | [diff] [blame] | 426 | if (mode == HWC2::PowerMode::Off) { |
| 427 | SetBwLimitHint(false); |
| 428 | } |
| 429 | |
| 430 | return HWC2::Error::None; |
| 431 | } |
| 432 | |
Dileep Marchya | ad66843 | 2019-12-02 10:44:52 +0530 | [diff] [blame] | 433 | HWC2::Error HWCDisplayBuiltIn::Present(shared_ptr<Fence> *out_retire_fence) { |
Naseer Ahmed | b92e73f | 2016-03-12 02:03:48 -0500 | [diff] [blame] | 434 | auto status = HWC2::Error::None; |
Gurpreet Singh Dhami | a427688 | 2019-04-12 10:30:58 -0700 | [diff] [blame] | 435 | |
| 436 | DTRACE_SCOPED(); |
Mathew Joseph Karimpanal | b1c1586 | 2019-07-04 11:14:24 +0530 | [diff] [blame] | 437 | |
| 438 | if (!is_primary_ && active_secure_sessions_[kSecureDisplay]) { |
Pullakavi Srinivas | 1ae4acb | 2019-11-18 19:33:45 +0530 | [diff] [blame] | 439 | return status; |
Mathew Joseph Karimpanal | b1c1586 | 2019-07-04 11:14:24 +0530 | [diff] [blame] | 440 | } else if (display_paused_) { |
Pullakavi Srinivas | 0a1dba6 | 2018-07-02 15:49:11 +0530 | [diff] [blame] | 441 | DisplayError error = display_intf_->Flush(&layer_stack_); |
Saurabh Shah | a307e8c | 2017-09-28 18:05:40 -0700 | [diff] [blame] | 442 | validated_ = false; |
Naseer Ahmed | b92e73f | 2016-03-12 02:03:48 -0500 | [diff] [blame] | 443 | if (error != kErrorNone) { |
| 444 | DLOGE("Flush failed. Error = %d", error); |
| 445 | } |
| 446 | } else { |
Padmanabhan Komanduru | 6693fcb | 2019-11-22 21:06:52 +0530 | [diff] [blame] | 447 | CacheAvrStatus(); |
Padmanabhan Komanduru | 5ec3a87 | 2020-04-13 14:19:16 +0530 | [diff] [blame] | 448 | DisplayConfigFixedInfo fixed_info = {}; |
| 449 | display_intf_->GetConfig(&fixed_info); |
| 450 | bool command_mode = fixed_info.is_cmdmode; |
Padmanabhan Komanduru | 6693fcb | 2019-11-22 21:06:52 +0530 | [diff] [blame] | 451 | |
Pullakavi Srinivas | 1ae4acb | 2019-11-18 19:33:45 +0530 | [diff] [blame] | 452 | status = CommitStitchLayers(); |
| 453 | if (status != HWC2::Error::None) { |
| 454 | DLOGE("Stitch failed: %d", status); |
| 455 | return status; |
| 456 | } |
| 457 | |
Padmanabhan Komanduru | e74cf4f | 2019-04-25 17:38:43 -0700 | [diff] [blame] | 458 | status = CommitLayerStack(); |
Naseer Ahmed | b92e73f | 2016-03-12 02:03:48 -0500 | [diff] [blame] | 459 | if (status == HWC2::Error::None) { |
| 460 | HandleFrameOutput(); |
Pullakavi Srinivas | db2b84a | 2019-11-21 14:47:35 +0530 | [diff] [blame] | 461 | PostCommitStitchLayers(); |
Naseer Ahmed | b92e73f | 2016-03-12 02:03:48 -0500 | [diff] [blame] | 462 | status = HWCDisplay::PostCommitLayerStack(out_retire_fence); |
Padmanabhan Komanduru | b5ff0fb | 2020-02-12 18:08:04 +0530 | [diff] [blame] | 463 | SetBwLimitHint(true); |
Padmanabhan Komanduru | 5ec3a87 | 2020-04-13 14:19:16 +0530 | [diff] [blame] | 464 | display_intf_->GetConfig(&fixed_info); |
| 465 | is_cmd_mode_ = fixed_info.is_cmdmode; |
| 466 | if (is_cmd_mode_ != command_mode) { |
| 467 | SetPartialUpdate(fixed_info); |
| 468 | } |
Naseer Ahmed | b92e73f | 2016-03-12 02:03:48 -0500 | [diff] [blame] | 469 | } |
| 470 | } |
Arun Kumar K.R | 536c7d6 | 2016-06-14 18:47:39 -0700 | [diff] [blame] | 471 | |
Namit Solanki | 5b428dc | 2018-02-27 11:39:05 +0530 | [diff] [blame] | 472 | pending_commit_ = false; |
Naseer Ahmed | b92e73f | 2016-03-12 02:03:48 -0500 | [diff] [blame] | 473 | return status; |
| 474 | } |
| 475 | |
Pullakavi Srinivas | db2b84a | 2019-11-21 14:47:35 +0530 | [diff] [blame] | 476 | void HWCDisplayBuiltIn::PostCommitStitchLayers() { |
| 477 | if (disable_layer_stitch_) { |
| 478 | return; |
| 479 | } |
| 480 | |
| 481 | // Close Stitch buffer acquire fence. |
| 482 | Layer *stitch_layer = stitch_target_->GetSDMLayer(); |
| 483 | LayerBuffer &output_buffer = stitch_layer->input_buffer; |
| 484 | for (auto &layer : layer_stack_.layers) { |
| 485 | LayerComposition &composition = layer->composition; |
| 486 | if (composition != kCompositionStitch) { |
| 487 | continue; |
| 488 | } |
| 489 | LayerBuffer &input_buffer = layer->input_buffer; |
Rajavenu Kyatham | 7338b9e | 2019-12-30 19:52:16 +0530 | [diff] [blame] | 490 | input_buffer.release_fence = output_buffer.acquire_fence; |
Pullakavi Srinivas | db2b84a | 2019-11-21 14:47:35 +0530 | [diff] [blame] | 491 | } |
Pullakavi Srinivas | db2b84a | 2019-11-21 14:47:35 +0530 | [diff] [blame] | 492 | } |
| 493 | |
Dileep Marchya | f3ce11f | 2018-04-30 23:35:46 +0530 | [diff] [blame] | 494 | 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] | 495 | if (out_modes == nullptr) { |
| 496 | *out_num_modes = color_mode_->GetColorModeCount(); |
| 497 | } else { |
| 498 | color_mode_->GetColorModes(out_num_modes, out_modes); |
| 499 | } |
| 500 | |
| 501 | return HWC2::Error::None; |
| 502 | } |
| 503 | |
Dileep Marchya | f3ce11f | 2018-04-30 23:35:46 +0530 | [diff] [blame] | 504 | HWC2::Error HWCDisplayBuiltIn::GetRenderIntents(ColorMode mode, uint32_t *out_num_intents, |
Naseer Ahmed | e7a7798 | 2018-06-04 10:56:04 -0400 | [diff] [blame] | 505 | RenderIntent *out_intents) { |
| 506 | if (out_intents == nullptr) { |
| 507 | *out_num_intents = color_mode_->GetRenderIntentCount(mode); |
| 508 | } else { |
| 509 | color_mode_->GetRenderIntents(mode, out_num_intents, out_intents); |
| 510 | } |
| 511 | return HWC2::Error::None; |
| 512 | } |
| 513 | |
Dileep Marchya | f3ce11f | 2018-04-30 23:35:46 +0530 | [diff] [blame] | 514 | HWC2::Error HWCDisplayBuiltIn::SetColorMode(ColorMode mode) { |
Naseer Ahmed | e7a7798 | 2018-06-04 10:56:04 -0400 | [diff] [blame] | 515 | return SetColorModeWithRenderIntent(mode, RenderIntent::COLORIMETRIC); |
| 516 | } |
| 517 | |
Dileep Marchya | f3ce11f | 2018-04-30 23:35:46 +0530 | [diff] [blame] | 518 | HWC2::Error HWCDisplayBuiltIn::SetColorModeWithRenderIntent(ColorMode mode, RenderIntent intent) { |
Sushil Chauhan | 8008d60 | 2018-09-04 14:43:27 -0700 | [diff] [blame] | 519 | auto status = color_mode_->CacheColorModeWithRenderIntent(mode, intent); |
Arun Kumar K.R | 29cd658 | 2016-05-10 19:12:45 -0700 | [diff] [blame] | 520 | if (status != HWC2::Error::None) { |
Naseer Ahmed | e7a7798 | 2018-06-04 10:56:04 -0400 | [diff] [blame] | 521 | DLOGE("failed for mode = %d intent = %d", mode, intent); |
Arun Kumar K.R | 29cd658 | 2016-05-10 19:12:45 -0700 | [diff] [blame] | 522 | return status; |
| 523 | } |
Ramkumar Radhakrishnan | 44c6436 | 2018-12-12 13:03:59 -0800 | [diff] [blame] | 524 | callbacks_->Refresh(id_); |
Saurabh Shah | a307e8c | 2017-09-28 18:05:40 -0700 | [diff] [blame] | 525 | validated_ = false; |
Arun Kumar K.R | 29cd658 | 2016-05-10 19:12:45 -0700 | [diff] [blame] | 526 | return status; |
| 527 | } |
| 528 | |
Dileep Marchya | f3ce11f | 2018-04-30 23:35:46 +0530 | [diff] [blame] | 529 | HWC2::Error HWCDisplayBuiltIn::SetColorModeById(int32_t color_mode_id) { |
Naseer Ahmed | 6776dae | 2017-05-09 11:49:41 -0400 | [diff] [blame] | 530 | auto status = color_mode_->SetColorModeById(color_mode_id); |
| 531 | if (status != HWC2::Error::None) { |
| 532 | DLOGE("failed for mode = %d", color_mode_id); |
| 533 | return status; |
| 534 | } |
| 535 | |
Ramkumar Radhakrishnan | 44c6436 | 2018-12-12 13:03:59 -0800 | [diff] [blame] | 536 | callbacks_->Refresh(id_); |
Saurabh Shah | a307e8c | 2017-09-28 18:05:40 -0700 | [diff] [blame] | 537 | validated_ = false; |
Naseer Ahmed | 6776dae | 2017-05-09 11:49:41 -0400 | [diff] [blame] | 538 | |
| 539 | return status; |
| 540 | } |
| 541 | |
Xu Yang | 84e6141 | 2018-12-06 14:52:16 +0800 | [diff] [blame] | 542 | HWC2::Error HWCDisplayBuiltIn::SetColorModeFromClientApi(int32_t color_mode_id) { |
| 543 | DisplayError error = kErrorNone; |
| 544 | std::string mode_string; |
| 545 | |
| 546 | error = display_intf_->GetColorModeName(color_mode_id, &mode_string); |
| 547 | if (error) { |
| 548 | DLOGE("Failed to get mode name for mode %d", color_mode_id); |
| 549 | return HWC2::Error::BadParameter; |
| 550 | } |
| 551 | |
| 552 | auto status = color_mode_->SetColorModeFromClientApi(mode_string); |
| 553 | if (status != HWC2::Error::None) { |
| 554 | DLOGE("Failed to set mode = %d", color_mode_id); |
| 555 | return status; |
| 556 | } |
| 557 | |
| 558 | return status; |
| 559 | } |
| 560 | |
Dileep Marchya | f3ce11f | 2018-04-30 23:35:46 +0530 | [diff] [blame] | 561 | HWC2::Error HWCDisplayBuiltIn::RestoreColorTransform() { |
Ch Ganesh Kumar | 5d43ff6 | 2017-10-13 19:01:47 +0530 | [diff] [blame] | 562 | auto status = color_mode_->RestoreColorTransform(); |
| 563 | if (status != HWC2::Error::None) { |
| 564 | DLOGE("failed to RestoreColorTransform"); |
| 565 | return status; |
| 566 | } |
| 567 | |
Ramkumar Radhakrishnan | 44c6436 | 2018-12-12 13:03:59 -0800 | [diff] [blame] | 568 | callbacks_->Refresh(id_); |
Ch Ganesh Kumar | 5d43ff6 | 2017-10-13 19:01:47 +0530 | [diff] [blame] | 569 | |
| 570 | return status; |
| 571 | } |
| 572 | |
Dileep Marchya | f3ce11f | 2018-04-30 23:35:46 +0530 | [diff] [blame] | 573 | HWC2::Error HWCDisplayBuiltIn::SetColorTransform(const float *matrix, |
Arun Kumar K.R | 29cd658 | 2016-05-10 19:12:45 -0700 | [diff] [blame] | 574 | android_color_transform_t hint) { |
| 575 | if (!matrix) { |
| 576 | return HWC2::Error::BadParameter; |
| 577 | } |
| 578 | |
| 579 | auto status = color_mode_->SetColorTransform(matrix, hint); |
| 580 | if (status != HWC2::Error::None) { |
| 581 | DLOGE("failed for hint = %d", hint); |
| 582 | color_tranform_failed_ = true; |
| 583 | return status; |
| 584 | } |
| 585 | |
Ramkumar Radhakrishnan | 44c6436 | 2018-12-12 13:03:59 -0800 | [diff] [blame] | 586 | callbacks_->Refresh(id_); |
Arun Kumar K.R | 29cd658 | 2016-05-10 19:12:45 -0700 | [diff] [blame] | 587 | color_tranform_failed_ = false; |
Saurabh Shah | a307e8c | 2017-09-28 18:05:40 -0700 | [diff] [blame] | 588 | validated_ = false; |
Arun Kumar K.R | 29cd658 | 2016-05-10 19:12:45 -0700 | [diff] [blame] | 589 | |
| 590 | return status; |
| 591 | } |
| 592 | |
Dileep Marchya | f3ce11f | 2018-04-30 23:35:46 +0530 | [diff] [blame] | 593 | HWC2::Error HWCDisplayBuiltIn::SetReadbackBuffer(const native_handle_t *buffer, |
Rajavenu Kyatham | 7338b9e | 2019-12-30 19:52:16 +0530 | [diff] [blame] | 594 | shared_ptr<Fence> acquire_fence, |
| 595 | bool post_processed_output, CWBClient client) { |
Dileep Marchya | cb2a3a9 | 2019-06-21 17:30:50 +0530 | [diff] [blame] | 596 | if (cwb_client_ != client && cwb_client_ != kCWBClientNone) { |
| 597 | DLOGE("CWB is in use with client = %d", cwb_client_); |
| 598 | return HWC2::Error::NoResources; |
| 599 | } |
| 600 | |
Sushil Chauhan | 0652158 | 2018-03-19 14:00:23 -0700 | [diff] [blame] | 601 | const private_handle_t *handle = reinterpret_cast<const private_handle_t *>(buffer); |
| 602 | if (!handle || (handle->fd < 0)) { |
| 603 | return HWC2::Error::BadParameter; |
| 604 | } |
| 605 | |
| 606 | // Configure the output buffer as Readback buffer |
| 607 | output_buffer_.width = UINT32(handle->width); |
| 608 | output_buffer_.height = UINT32(handle->height); |
| 609 | output_buffer_.unaligned_width = UINT32(handle->unaligned_width); |
| 610 | output_buffer_.unaligned_height = UINT32(handle->unaligned_height); |
| 611 | output_buffer_.format = HWCLayer::GetSDMFormat(handle->format, handle->flags); |
| 612 | output_buffer_.planes[0].fd = handle->fd; |
| 613 | output_buffer_.planes[0].stride = UINT32(handle->width); |
Rajavenu Kyatham | 7338b9e | 2019-12-30 19:52:16 +0530 | [diff] [blame] | 614 | output_buffer_.acquire_fence = acquire_fence; |
Sushil Chauhan | d0dc03d | 2018-09-19 07:08:40 -0700 | [diff] [blame] | 615 | output_buffer_.handle_id = handle->id; |
Sushil Chauhan | 0652158 | 2018-03-19 14:00:23 -0700 | [diff] [blame] | 616 | |
| 617 | post_processed_output_ = post_processed_output; |
| 618 | readback_buffer_queued_ = true; |
| 619 | readback_configured_ = false; |
| 620 | validated_ = false; |
Dileep Marchya | cb2a3a9 | 2019-06-21 17:30:50 +0530 | [diff] [blame] | 621 | cwb_client_ = client; |
Sushil Chauhan | 0652158 | 2018-03-19 14:00:23 -0700 | [diff] [blame] | 622 | |
Sushil Chauhan | 0652158 | 2018-03-19 14:00:23 -0700 | [diff] [blame] | 623 | return HWC2::Error::None; |
| 624 | } |
| 625 | |
Rajavenu Kyatham | 7338b9e | 2019-12-30 19:52:16 +0530 | [diff] [blame] | 626 | HWC2::Error HWCDisplayBuiltIn::GetReadbackBufferFence(shared_ptr<Fence> *release_fence) { |
Sushil Chauhan | 0652158 | 2018-03-19 14:00:23 -0700 | [diff] [blame] | 627 | auto status = HWC2::Error::None; |
| 628 | |
Rajavenu Kyatham | 7338b9e | 2019-12-30 19:52:16 +0530 | [diff] [blame] | 629 | if (readback_configured_ && output_buffer_.release_fence) { |
| 630 | *release_fence = output_buffer_.release_fence; |
Sushil Chauhan | 0652158 | 2018-03-19 14:00:23 -0700 | [diff] [blame] | 631 | } else { |
| 632 | status = HWC2::Error::Unsupported; |
Sushil Chauhan | 0652158 | 2018-03-19 14:00:23 -0700 | [diff] [blame] | 633 | } |
| 634 | |
| 635 | post_processed_output_ = false; |
| 636 | readback_buffer_queued_ = false; |
| 637 | readback_configured_ = false; |
| 638 | output_buffer_ = {}; |
Dileep Marchya | cb2a3a9 | 2019-06-21 17:30:50 +0530 | [diff] [blame] | 639 | cwb_client_ = kCWBClientNone; |
Sushil Chauhan | 0652158 | 2018-03-19 14:00:23 -0700 | [diff] [blame] | 640 | |
| 641 | return status; |
| 642 | } |
| 643 | |
Gurpreet Singh Dhami | 1207e46 | 2018-12-27 20:02:02 -0500 | [diff] [blame] | 644 | DisplayError HWCDisplayBuiltIn::TeardownConcurrentWriteback(void) { |
| 645 | DisplayError error = kErrorNotSupported; |
Rajavenu Kyatham | 7338b9e | 2019-12-30 19:52:16 +0530 | [diff] [blame] | 646 | if (Fence::Wait(output_buffer_.release_fence) != kErrorNone) { |
| 647 | DLOGE("sync_wait error errno = %d, desc = %s", errno, strerror(errno)); |
| 648 | return kErrorResources; |
Gurpreet Singh Dhami | 1207e46 | 2018-12-27 20:02:02 -0500 | [diff] [blame] | 649 | } |
| 650 | |
| 651 | if (display_intf_) { |
| 652 | error = display_intf_->TeardownConcurrentWriteback(); |
| 653 | } |
| 654 | |
| 655 | return error; |
| 656 | } |
| 657 | |
Yuchao Ma | 577f0f7 | 2018-07-09 11:20:00 +0800 | [diff] [blame] | 658 | HWC2::Error HWCDisplayBuiltIn::SetDisplayDppsAdROI(uint32_t h_start, uint32_t h_end, |
| 659 | uint32_t v_start, uint32_t v_end, |
| 660 | uint32_t factor_in, uint32_t factor_out) { |
| 661 | DisplayError error = kErrorNone; |
| 662 | DisplayDppsAd4RoiCfg dpps_ad4_roi_cfg = {}; |
| 663 | uint32_t panel_width = 0, panel_height = 0; |
| 664 | constexpr uint16_t kMaxFactorVal = 0xffff; |
| 665 | |
| 666 | if (h_start >= h_end || v_start >= v_end || factor_in > kMaxFactorVal || |
| 667 | factor_out > kMaxFactorVal) { |
| 668 | DLOGE("Invalid roi region = [%u, %u, %u, %u, %u, %u]", |
| 669 | h_start, h_end, v_start, v_end, factor_in, factor_out); |
| 670 | return HWC2::Error::BadParameter; |
| 671 | } |
| 672 | |
| 673 | GetPanelResolution(&panel_width, &panel_height); |
| 674 | |
| 675 | if (h_start >= panel_width || h_end > panel_width || |
| 676 | v_start >= panel_height || v_end > panel_height) { |
| 677 | DLOGE("Invalid roi region = [%u, %u, %u, %u], panel resolution = [%u, %u]", |
| 678 | h_start, h_end, v_start, v_end, panel_width, panel_height); |
| 679 | return HWC2::Error::BadParameter; |
| 680 | } |
| 681 | |
| 682 | dpps_ad4_roi_cfg.h_start = h_start; |
| 683 | dpps_ad4_roi_cfg.h_end = h_end; |
| 684 | dpps_ad4_roi_cfg.v_start = v_start; |
| 685 | dpps_ad4_roi_cfg.v_end = v_end; |
| 686 | dpps_ad4_roi_cfg.factor_in = factor_in; |
| 687 | dpps_ad4_roi_cfg.factor_out = factor_out; |
| 688 | |
| 689 | error = display_intf_->SetDisplayDppsAdROI(&dpps_ad4_roi_cfg); |
| 690 | if (error) |
| 691 | return HWC2::Error::BadConfig; |
| 692 | |
Ramkumar Radhakrishnan | 44c6436 | 2018-12-12 13:03:59 -0800 | [diff] [blame] | 693 | callbacks_->Refresh(id_); |
Yuchao Ma | 577f0f7 | 2018-07-09 11:20:00 +0800 | [diff] [blame] | 694 | |
| 695 | return HWC2::Error::None; |
| 696 | } |
| 697 | |
Xu Yang | 9dacc87 | 2018-12-25 11:04:28 +0800 | [diff] [blame] | 698 | HWC2::Error HWCDisplayBuiltIn::SetFrameTriggerMode(uint32_t mode) { |
| 699 | DisplayError error = kErrorNone; |
| 700 | FrameTriggerMode trigger_mode = kFrameTriggerDefault; |
| 701 | |
| 702 | if (mode >= kFrameTriggerMax) { |
| 703 | DLOGE("Invalid input mode %d", mode); |
| 704 | return HWC2::Error::BadParameter; |
| 705 | } |
| 706 | |
| 707 | trigger_mode = static_cast<FrameTriggerMode>(mode); |
| 708 | error = display_intf_->SetFrameTriggerMode(trigger_mode); |
| 709 | if (error) |
| 710 | return HWC2::Error::BadConfig; |
| 711 | |
| 712 | callbacks_->Refresh(HWC_DISPLAY_PRIMARY); |
| 713 | validated_ = false; |
| 714 | |
| 715 | return HWC2::Error::None; |
| 716 | } |
| 717 | |
Dileep Marchya | f3ce11f | 2018-04-30 23:35:46 +0530 | [diff] [blame] | 718 | int HWCDisplayBuiltIn::Perform(uint32_t operation, ...) { |
Naseer Ahmed | b92e73f | 2016-03-12 02:03:48 -0500 | [diff] [blame] | 719 | va_list args; |
| 720 | va_start(args, operation); |
Arun Kumar K.R | 536c7d6 | 2016-06-14 18:47:39 -0700 | [diff] [blame] | 721 | int val = 0; |
Gopikrishnaiah Anandan | cc12306 | 2017-07-31 17:21:03 -0700 | [diff] [blame] | 722 | LayerSolidFill *solid_fill_color; |
Arun Kumar K.R | 536c7d6 | 2016-06-14 18:47:39 -0700 | [diff] [blame] | 723 | LayerRect *rect = NULL; |
| 724 | |
Naseer Ahmed | b92e73f | 2016-03-12 02:03:48 -0500 | [diff] [blame] | 725 | switch (operation) { |
| 726 | case SET_METADATA_DYN_REFRESH_RATE: |
Arun Kumar K.R | 536c7d6 | 2016-06-14 18:47:39 -0700 | [diff] [blame] | 727 | val = va_arg(args, int32_t); |
Naseer Ahmed | b92e73f | 2016-03-12 02:03:48 -0500 | [diff] [blame] | 728 | SetMetaDataRefreshRateFlag(val); |
| 729 | break; |
| 730 | case SET_BINDER_DYN_REFRESH_RATE: |
Arun Kumar K.R | 536c7d6 | 2016-06-14 18:47:39 -0700 | [diff] [blame] | 731 | val = va_arg(args, int32_t); |
Naseer Ahmed | b92e73f | 2016-03-12 02:03:48 -0500 | [diff] [blame] | 732 | ForceRefreshRate(UINT32(val)); |
| 733 | break; |
| 734 | case SET_DISPLAY_MODE: |
Arun Kumar K.R | 536c7d6 | 2016-06-14 18:47:39 -0700 | [diff] [blame] | 735 | val = va_arg(args, int32_t); |
Naseer Ahmed | b92e73f | 2016-03-12 02:03:48 -0500 | [diff] [blame] | 736 | SetDisplayMode(UINT32(val)); |
| 737 | break; |
| 738 | case SET_QDCM_SOLID_FILL_INFO: |
Gopikrishnaiah Anandan | cc12306 | 2017-07-31 17:21:03 -0700 | [diff] [blame] | 739 | solid_fill_color = va_arg(args, LayerSolidFill*); |
| 740 | SetQDCMSolidFillInfo(true, *solid_fill_color); |
Naseer Ahmed | b92e73f | 2016-03-12 02:03:48 -0500 | [diff] [blame] | 741 | break; |
| 742 | case UNSET_QDCM_SOLID_FILL_INFO: |
Gopikrishnaiah Anandan | cc12306 | 2017-07-31 17:21:03 -0700 | [diff] [blame] | 743 | solid_fill_color = va_arg(args, LayerSolidFill*); |
| 744 | SetQDCMSolidFillInfo(false, *solid_fill_color); |
Naseer Ahmed | b92e73f | 2016-03-12 02:03:48 -0500 | [diff] [blame] | 745 | break; |
Arun Kumar K.R | 536c7d6 | 2016-06-14 18:47:39 -0700 | [diff] [blame] | 746 | case SET_QDCM_SOLID_FILL_RECT: |
| 747 | rect = va_arg(args, LayerRect*); |
| 748 | solid_fill_rect_ = *rect; |
| 749 | break; |
Naseer Ahmed | b92e73f | 2016-03-12 02:03:48 -0500 | [diff] [blame] | 750 | default: |
| 751 | DLOGW("Invalid operation %d", operation); |
Arun Kumar K.R | 536c7d6 | 2016-06-14 18:47:39 -0700 | [diff] [blame] | 752 | va_end(args); |
Naseer Ahmed | b92e73f | 2016-03-12 02:03:48 -0500 | [diff] [blame] | 753 | return -EINVAL; |
| 754 | } |
Arun Kumar K.R | 536c7d6 | 2016-06-14 18:47:39 -0700 | [diff] [blame] | 755 | va_end(args); |
Saurabh Shah | a307e8c | 2017-09-28 18:05:40 -0700 | [diff] [blame] | 756 | validated_ = false; |
Naseer Ahmed | b92e73f | 2016-03-12 02:03:48 -0500 | [diff] [blame] | 757 | |
| 758 | return 0; |
| 759 | } |
| 760 | |
Dileep Marchya | f3ce11f | 2018-04-30 23:35:46 +0530 | [diff] [blame] | 761 | DisplayError HWCDisplayBuiltIn::SetDisplayMode(uint32_t mode) { |
Naseer Ahmed | b92e73f | 2016-03-12 02:03:48 -0500 | [diff] [blame] | 762 | DisplayError error = kErrorNone; |
| 763 | |
| 764 | if (display_intf_) { |
| 765 | error = display_intf_->SetDisplayMode(mode); |
Tharaga Balachandran | 04192a6 | 2018-08-29 16:23:25 -0400 | [diff] [blame] | 766 | if (error == kErrorNone) { |
| 767 | DisplayConfigFixedInfo fixed_info = {}; |
| 768 | display_intf_->GetConfig(&fixed_info); |
| 769 | is_cmd_mode_ = fixed_info.is_cmdmode; |
| 770 | partial_update_enabled_ = fixed_info.partial_update; |
| 771 | for (auto hwc_layer : layer_set_) { |
| 772 | hwc_layer->SetPartialUpdate(partial_update_enabled_); |
| 773 | } |
| 774 | client_target_->SetPartialUpdate(partial_update_enabled_); |
| 775 | } |
Naseer Ahmed | b92e73f | 2016-03-12 02:03:48 -0500 | [diff] [blame] | 776 | } |
| 777 | |
| 778 | return error; |
| 779 | } |
| 780 | |
Dileep Marchya | f3ce11f | 2018-04-30 23:35:46 +0530 | [diff] [blame] | 781 | void HWCDisplayBuiltIn::SetMetaDataRefreshRateFlag(bool enable) { |
Naseer Ahmed | b92e73f | 2016-03-12 02:03:48 -0500 | [diff] [blame] | 782 | int disable_metadata_dynfps = 0; |
| 783 | |
Uday Kiran Pichika | 5e656b2 | 2018-05-15 18:48:24 +0530 | [diff] [blame] | 784 | HWCDebugHandler::Get()->GetProperty(DISABLE_METADATA_DYNAMIC_FPS_PROP, &disable_metadata_dynfps); |
Naseer Ahmed | b92e73f | 2016-03-12 02:03:48 -0500 | [diff] [blame] | 785 | if (disable_metadata_dynfps) { |
| 786 | return; |
| 787 | } |
| 788 | use_metadata_refresh_rate_ = enable; |
| 789 | } |
| 790 | |
Dileep Marchya | f3ce11f | 2018-04-30 23:35:46 +0530 | [diff] [blame] | 791 | void HWCDisplayBuiltIn::SetQDCMSolidFillInfo(bool enable, const LayerSolidFill &color) { |
Naseer Ahmed | b92e73f | 2016-03-12 02:03:48 -0500 | [diff] [blame] | 792 | solid_fill_enable_ = enable; |
| 793 | solid_fill_color_ = color; |
| 794 | } |
| 795 | |
Dileep Marchya | f3ce11f | 2018-04-30 23:35:46 +0530 | [diff] [blame] | 796 | void HWCDisplayBuiltIn::ToggleCPUHint(bool set) { |
Naseer Ahmed | b92e73f | 2016-03-12 02:03:48 -0500 | [diff] [blame] | 797 | if (!cpu_hint_) { |
| 798 | return; |
| 799 | } |
| 800 | |
| 801 | if (set) { |
| 802 | cpu_hint_->Set(); |
| 803 | } else { |
| 804 | cpu_hint_->Reset(); |
| 805 | } |
| 806 | } |
| 807 | |
Dileep Marchya | f3ce11f | 2018-04-30 23:35:46 +0530 | [diff] [blame] | 808 | int HWCDisplayBuiltIn::HandleSecureSession(const std::bitset<kSecureMax> &secure_sessions, |
Ramkumar Radhakrishnan | a38b760 | 2018-03-15 14:49:52 -0700 | [diff] [blame] | 809 | bool *power_on_pending) { |
| 810 | if (!power_on_pending) { |
| 811 | return -EINVAL; |
Naseer Ahmed | b92e73f | 2016-03-12 02:03:48 -0500 | [diff] [blame] | 812 | } |
Ramkumar Radhakrishnan | a38b760 | 2018-03-15 14:49:52 -0700 | [diff] [blame] | 813 | |
Mathew Joseph Karimpanal | b1c1586 | 2019-07-04 11:14:24 +0530 | [diff] [blame] | 814 | if (!is_primary_) { |
| 815 | return HWCDisplay::HandleSecureSession(secure_sessions, power_on_pending); |
| 816 | } |
| 817 | |
Ramkumar Radhakrishnan | 44c6436 | 2018-12-12 13:03:59 -0800 | [diff] [blame] | 818 | if (current_power_mode_ != HWC2::PowerMode::On) { |
| 819 | return 0; |
| 820 | } |
| 821 | |
Ramkumar Radhakrishnan | a38b760 | 2018-03-15 14:49:52 -0700 | [diff] [blame] | 822 | if (active_secure_sessions_[kSecureDisplay] != secure_sessions[kSecureDisplay]) { |
| 823 | SecureEvent secure_event = |
| 824 | secure_sessions.test(kSecureDisplay) ? kSecureDisplayStart : kSecureDisplayEnd; |
Pullakavi Srinivas | 0a1dba6 | 2018-07-02 15:49:11 +0530 | [diff] [blame] | 825 | DisplayError err = display_intf_->HandleSecureEvent(secure_event, &layer_stack_); |
Ramkumar Radhakrishnan | a38b760 | 2018-03-15 14:49:52 -0700 | [diff] [blame] | 826 | if (err != kErrorNone) { |
| 827 | DLOGE("Set secure event failed"); |
| 828 | return err; |
| 829 | } |
| 830 | |
Pullakavi Srinivas | ce3692b | 2020-02-13 01:14:09 +0530 | [diff] [blame] | 831 | DLOGI("SecureDisplay state changed from %d to %d for display %" PRIu64 "-%d", |
Ramkumar Radhakrishnan | a38b760 | 2018-03-15 14:49:52 -0700 | [diff] [blame] | 832 | active_secure_sessions_.test(kSecureDisplay), secure_sessions.test(kSecureDisplay), |
Mathew Joseph Karimpanal | b1c1586 | 2019-07-04 11:14:24 +0530 | [diff] [blame] | 833 | id_, type_); |
Ramkumar Radhakrishnan | a38b760 | 2018-03-15 14:49:52 -0700 | [diff] [blame] | 834 | } |
| 835 | active_secure_sessions_ = secure_sessions; |
| 836 | *power_on_pending = false; |
| 837 | return 0; |
Naseer Ahmed | b92e73f | 2016-03-12 02:03:48 -0500 | [diff] [blame] | 838 | } |
| 839 | |
Dileep Marchya | f3ce11f | 2018-04-30 23:35:46 +0530 | [diff] [blame] | 840 | void HWCDisplayBuiltIn::ForceRefreshRate(uint32_t refresh_rate) { |
Naseer Ahmed | b92e73f | 2016-03-12 02:03:48 -0500 | [diff] [blame] | 841 | if ((refresh_rate && (refresh_rate < min_refresh_rate_ || refresh_rate > max_refresh_rate_)) || |
| 842 | force_refresh_rate_ == refresh_rate) { |
| 843 | // Cannot honor force refresh rate, as its beyond the range or new request is same |
| 844 | return; |
| 845 | } |
| 846 | |
| 847 | force_refresh_rate_ = refresh_rate; |
| 848 | |
Ramkumar Radhakrishnan | 44c6436 | 2018-12-12 13:03:59 -0800 | [diff] [blame] | 849 | callbacks_->Refresh(id_); |
Naseer Ahmed | b92e73f | 2016-03-12 02:03:48 -0500 | [diff] [blame] | 850 | |
| 851 | return; |
| 852 | } |
| 853 | |
Dileep Marchya | f3ce11f | 2018-04-30 23:35:46 +0530 | [diff] [blame] | 854 | uint32_t HWCDisplayBuiltIn::GetOptimalRefreshRate(bool one_updating_layer) { |
Naseer Ahmed | b92e73f | 2016-03-12 02:03:48 -0500 | [diff] [blame] | 855 | if (force_refresh_rate_) { |
| 856 | return force_refresh_rate_; |
Naseer Ahmed | b92e73f | 2016-03-12 02:03:48 -0500 | [diff] [blame] | 857 | } else if (use_metadata_refresh_rate_ && one_updating_layer && metadata_refresh_rate_) { |
| 858 | return metadata_refresh_rate_; |
| 859 | } |
| 860 | |
Venkat Thogaru | 0fafc8f | 2020-04-22 19:49:27 +0530 | [diff] [blame] | 861 | DLOGV_IF(kTagClient, "active_refresh_rate_: %d", active_refresh_rate_); |
Pullakavi Srinivas | 7bdcc76 | 2020-03-06 12:41:36 +0530 | [diff] [blame] | 862 | return active_refresh_rate_; |
Naseer Ahmed | b92e73f | 2016-03-12 02:03:48 -0500 | [diff] [blame] | 863 | } |
| 864 | |
Dileep Marchya | f3ce11f | 2018-04-30 23:35:46 +0530 | [diff] [blame] | 865 | void HWCDisplayBuiltIn::SetIdleTimeoutMs(uint32_t timeout_ms) { |
Naseer Ahmed | b92e73f | 2016-03-12 02:03:48 -0500 | [diff] [blame] | 866 | display_intf_->SetIdleTimeoutMs(timeout_ms); |
Saurabh Shah | a307e8c | 2017-09-28 18:05:40 -0700 | [diff] [blame] | 867 | validated_ = false; |
Naseer Ahmed | b92e73f | 2016-03-12 02:03:48 -0500 | [diff] [blame] | 868 | } |
| 869 | |
Dileep Marchya | f3ce11f | 2018-04-30 23:35:46 +0530 | [diff] [blame] | 870 | void HWCDisplayBuiltIn::HandleFrameOutput() { |
Sushil Chauhan | 0652158 | 2018-03-19 14:00:23 -0700 | [diff] [blame] | 871 | if (readback_buffer_queued_) { |
| 872 | validated_ = false; |
| 873 | } |
| 874 | |
Sushil Chauhan | 1d3b90c | 2018-12-11 16:52:35 -0800 | [diff] [blame] | 875 | if (frame_capture_buffer_queued_) { |
| 876 | HandleFrameCapture(); |
| 877 | } else if (dump_output_to_file_) { |
Naseer Ahmed | b92e73f | 2016-03-12 02:03:48 -0500 | [diff] [blame] | 878 | HandleFrameDump(); |
| 879 | } |
| 880 | } |
| 881 | |
Sushil Chauhan | 1d3b90c | 2018-12-11 16:52:35 -0800 | [diff] [blame] | 882 | void HWCDisplayBuiltIn::HandleFrameCapture() { |
Rajavenu Kyatham | 7338b9e | 2019-12-30 19:52:16 +0530 | [diff] [blame] | 883 | if (readback_configured_ && output_buffer_.release_fence) { |
| 884 | frame_capture_status_ = Fence::Wait(output_buffer_.release_fence); |
Sushil Chauhan | 1d3b90c | 2018-12-11 16:52:35 -0800 | [diff] [blame] | 885 | } |
| 886 | |
| 887 | frame_capture_buffer_queued_ = false; |
| 888 | readback_buffer_queued_ = false; |
| 889 | post_processed_output_ = false; |
| 890 | readback_configured_ = false; |
| 891 | output_buffer_ = {}; |
Dileep Marchya | cb2a3a9 | 2019-06-21 17:30:50 +0530 | [diff] [blame] | 892 | cwb_client_ = kCWBClientNone; |
Sushil Chauhan | 1d3b90c | 2018-12-11 16:52:35 -0800 | [diff] [blame] | 893 | } |
| 894 | |
Dileep Marchya | f3ce11f | 2018-04-30 23:35:46 +0530 | [diff] [blame] | 895 | void HWCDisplayBuiltIn::HandleFrameDump() { |
Ramkumar Radhakrishnan | 68331fc | 2019-06-19 11:24:12 -0700 | [diff] [blame] | 896 | if (dump_frame_count_) { |
| 897 | int ret = 0; |
Rajavenu Kyatham | 7338b9e | 2019-12-30 19:52:16 +0530 | [diff] [blame] | 898 | ret = Fence::Wait(output_buffer_.release_fence); |
| 899 | if (ret != kErrorNone) { |
| 900 | DLOGE("sync_wait error errno = %d, desc = %s", errno, strerror(errno)); |
Ramkumar Radhakrishnan | 68331fc | 2019-06-19 11:24:12 -0700 | [diff] [blame] | 901 | } |
Naseer Ahmed | b92e73f | 2016-03-12 02:03:48 -0500 | [diff] [blame] | 902 | |
Ramkumar Radhakrishnan | 68331fc | 2019-06-19 11:24:12 -0700 | [diff] [blame] | 903 | if (!ret) { |
Dileep Marchya | ad66843 | 2019-12-02 10:44:52 +0530 | [diff] [blame] | 904 | DumpOutputBuffer(output_buffer_info_, output_buffer_base_, layer_stack_.retire_fence); |
| 905 | validated_ = false; |
| 906 | } |
Ramkumar Radhakrishnan | 68331fc | 2019-06-19 11:24:12 -0700 | [diff] [blame] | 907 | |
| 908 | if (0 == (dump_frame_count_ - 1)) { |
| 909 | dump_output_to_file_ = false; |
| 910 | // Unmap and Free buffer |
| 911 | if (munmap(output_buffer_base_, output_buffer_info_.alloc_buffer_info.size) != 0) { |
| 912 | DLOGE("unmap failed with err %d", errno); |
| 913 | } |
| 914 | if (buffer_allocator_->FreeBuffer(&output_buffer_info_) != 0) { |
| 915 | DLOGE("FreeBuffer failed"); |
| 916 | } |
| 917 | |
Sushil Chauhan | 0652158 | 2018-03-19 14:00:23 -0700 | [diff] [blame] | 918 | readback_buffer_queued_ = false; |
Ramkumar Radhakrishnan | 68331fc | 2019-06-19 11:24:12 -0700 | [diff] [blame] | 919 | post_processed_output_ = false; |
| 920 | readback_configured_ = false; |
Naseer Ahmed | b92e73f | 2016-03-12 02:03:48 -0500 | [diff] [blame] | 921 | |
Ramkumar Radhakrishnan | 68331fc | 2019-06-19 11:24:12 -0700 | [diff] [blame] | 922 | output_buffer_ = {}; |
| 923 | output_buffer_info_ = {}; |
| 924 | output_buffer_base_ = nullptr; |
Dileep Marchya | cb2a3a9 | 2019-06-21 17:30:50 +0530 | [diff] [blame] | 925 | cwb_client_ = kCWBClientNone; |
Naseer Ahmed | b92e73f | 2016-03-12 02:03:48 -0500 | [diff] [blame] | 926 | } |
Naseer Ahmed | b92e73f | 2016-03-12 02:03:48 -0500 | [diff] [blame] | 927 | } |
| 928 | } |
| 929 | |
Sushil Chauhan | 267a619 | 2018-06-06 18:41:47 -0700 | [diff] [blame] | 930 | HWC2::Error HWCDisplayBuiltIn::SetFrameDumpConfig(uint32_t count, uint32_t bit_mask_layer_type, |
| 931 | int32_t format, bool post_processed) { |
| 932 | HWCDisplay::SetFrameDumpConfig(count, bit_mask_layer_type, format, post_processed); |
Naseer Ahmed | b92e73f | 2016-03-12 02:03:48 -0500 | [diff] [blame] | 933 | dump_output_to_file_ = bit_mask_layer_type & (1 << OUTPUT_LAYER_DUMP); |
| 934 | DLOGI("output_layer_dump_enable %d", dump_output_to_file_); |
| 935 | |
Dileep Marchya | cb2a3a9 | 2019-06-21 17:30:50 +0530 | [diff] [blame] | 936 | if (dump_output_to_file_) { |
| 937 | if (cwb_client_ != kCWBClientNone) { |
| 938 | DLOGE("CWB is in use with client = %d", cwb_client_); |
| 939 | dump_output_to_file_ = false; |
| 940 | return HWC2::Error::NoResources; |
| 941 | } |
| 942 | } |
| 943 | |
Sushil Chauhan | d0dc03d | 2018-09-19 07:08:40 -0700 | [diff] [blame] | 944 | 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] | 945 | return HWC2::Error::None; |
Naseer Ahmed | b92e73f | 2016-03-12 02:03:48 -0500 | [diff] [blame] | 946 | } |
| 947 | |
| 948 | // Allocate and map output buffer |
Sushil Chauhan | 267a619 | 2018-06-06 18:41:47 -0700 | [diff] [blame] | 949 | if (post_processed) { |
| 950 | // To dump post-processed (DSPP) output, use Panel resolution. |
| 951 | GetPanelResolution(&output_buffer_info_.buffer_config.width, |
| 952 | &output_buffer_info_.buffer_config.height); |
| 953 | } else { |
| 954 | // To dump Layer Mixer output, use FrameBuffer resolution. |
| 955 | GetFrameBufferResolution(&output_buffer_info_.buffer_config.width, |
| 956 | &output_buffer_info_.buffer_config.height); |
| 957 | } |
| 958 | |
| 959 | output_buffer_info_.buffer_config.format = HWCLayer::GetSDMFormat(format, 0); |
Naseer Ahmed | b92e73f | 2016-03-12 02:03:48 -0500 | [diff] [blame] | 960 | output_buffer_info_.buffer_config.buffer_count = 1; |
| 961 | if (buffer_allocator_->AllocateBuffer(&output_buffer_info_) != 0) { |
| 962 | DLOGE("Buffer allocation failed"); |
| 963 | output_buffer_info_ = {}; |
Mathew Joseph Karimpanal | dbd64f8 | 2017-10-06 10:13:38 +0530 | [diff] [blame] | 964 | return HWC2::Error::NoResources; |
Naseer Ahmed | b92e73f | 2016-03-12 02:03:48 -0500 | [diff] [blame] | 965 | } |
| 966 | |
| 967 | void *buffer = mmap(NULL, output_buffer_info_.alloc_buffer_info.size, PROT_READ | PROT_WRITE, |
| 968 | MAP_SHARED, output_buffer_info_.alloc_buffer_info.fd, 0); |
| 969 | |
| 970 | if (buffer == MAP_FAILED) { |
| 971 | DLOGE("mmap failed with err %d", errno); |
| 972 | buffer_allocator_->FreeBuffer(&output_buffer_info_); |
| 973 | output_buffer_info_ = {}; |
Mathew Joseph Karimpanal | dbd64f8 | 2017-10-06 10:13:38 +0530 | [diff] [blame] | 974 | return HWC2::Error::NoResources; |
Naseer Ahmed | b92e73f | 2016-03-12 02:03:48 -0500 | [diff] [blame] | 975 | } |
| 976 | |
| 977 | output_buffer_base_ = buffer; |
Sushil Chauhan | 0652158 | 2018-03-19 14:00:23 -0700 | [diff] [blame] | 978 | const native_handle_t *handle = static_cast<native_handle_t *>(output_buffer_info_.private_data); |
Rajavenu Kyatham | 7338b9e | 2019-12-30 19:52:16 +0530 | [diff] [blame] | 979 | SetReadbackBuffer(handle, nullptr, post_processed, kCWBClientFrameDump); |
Sushil Chauhan | 0652158 | 2018-03-19 14:00:23 -0700 | [diff] [blame] | 980 | |
Mathew Joseph Karimpanal | dbd64f8 | 2017-10-06 10:13:38 +0530 | [diff] [blame] | 981 | return HWC2::Error::None; |
Naseer Ahmed | b92e73f | 2016-03-12 02:03:48 -0500 | [diff] [blame] | 982 | } |
| 983 | |
Dileep Marchya | f3ce11f | 2018-04-30 23:35:46 +0530 | [diff] [blame] | 984 | int HWCDisplayBuiltIn::FrameCaptureAsync(const BufferInfo &output_buffer_info, |
Naseer Ahmed | b92e73f | 2016-03-12 02:03:48 -0500 | [diff] [blame] | 985 | bool post_processed_output) { |
Dileep Marchya | cb2a3a9 | 2019-06-21 17:30:50 +0530 | [diff] [blame] | 986 | if (cwb_client_ != kCWBClientNone) { |
| 987 | DLOGE("CWB is in use with client = %d", cwb_client_); |
| 988 | return -1; |
| 989 | } |
| 990 | |
Naseer Ahmed | b92e73f | 2016-03-12 02:03:48 -0500 | [diff] [blame] | 991 | // Note: This function is called in context of a binder thread and a lock is already held |
| 992 | if (output_buffer_info.alloc_buffer_info.fd < 0) { |
| 993 | DLOGE("Invalid fd %d", output_buffer_info.alloc_buffer_info.fd); |
| 994 | return -1; |
| 995 | } |
| 996 | |
| 997 | auto panel_width = 0u; |
| 998 | auto panel_height = 0u; |
| 999 | auto fb_width = 0u; |
| 1000 | auto fb_height = 0u; |
| 1001 | |
| 1002 | GetPanelResolution(&panel_width, &panel_height); |
| 1003 | GetFrameBufferResolution(&fb_width, &fb_height); |
| 1004 | |
Ch Ganesh Kumar | 5c4988b | 2017-06-07 15:21:02 +0530 | [diff] [blame] | 1005 | if (post_processed_output && (output_buffer_info.buffer_config.width < panel_width || |
| 1006 | output_buffer_info.buffer_config.height < panel_height)) { |
Naseer Ahmed | b92e73f | 2016-03-12 02:03:48 -0500 | [diff] [blame] | 1007 | DLOGE("Buffer dimensions should not be less than panel resolution"); |
| 1008 | return -1; |
Ch Ganesh Kumar | 5c4988b | 2017-06-07 15:21:02 +0530 | [diff] [blame] | 1009 | } else if (!post_processed_output && (output_buffer_info.buffer_config.width < fb_width || |
| 1010 | output_buffer_info.buffer_config.height < fb_height)) { |
Naseer Ahmed | b92e73f | 2016-03-12 02:03:48 -0500 | [diff] [blame] | 1011 | DLOGE("Buffer dimensions should not be less than FB resolution"); |
| 1012 | return -1; |
| 1013 | } |
| 1014 | |
Sushil Chauhan | 0652158 | 2018-03-19 14:00:23 -0700 | [diff] [blame] | 1015 | const native_handle_t *buffer = static_cast<native_handle_t *>(output_buffer_info.private_data); |
Rajavenu Kyatham | 7338b9e | 2019-12-30 19:52:16 +0530 | [diff] [blame] | 1016 | SetReadbackBuffer(buffer, nullptr, post_processed_output, kCWBClientColor); |
Sushil Chauhan | 1d3b90c | 2018-12-11 16:52:35 -0800 | [diff] [blame] | 1017 | frame_capture_buffer_queued_ = true; |
| 1018 | frame_capture_status_ = -EAGAIN; |
Naseer Ahmed | b92e73f | 2016-03-12 02:03:48 -0500 | [diff] [blame] | 1019 | |
| 1020 | return 0; |
| 1021 | } |
| 1022 | |
Dileep Marchya | f3ce11f | 2018-04-30 23:35:46 +0530 | [diff] [blame] | 1023 | DisplayError HWCDisplayBuiltIn::SetDetailEnhancerConfig |
Alan Kwong | 2e13633 | 2016-08-16 07:50:16 -0400 | [diff] [blame] | 1024 | (const DisplayDetailEnhancerData &de_data) { |
| 1025 | DisplayError error = kErrorNotSupported; |
| 1026 | |
| 1027 | if (display_intf_) { |
| 1028 | error = display_intf_->SetDetailEnhancerData(de_data); |
Saurabh Shah | a307e8c | 2017-09-28 18:05:40 -0700 | [diff] [blame] | 1029 | validated_ = false; |
Alan Kwong | 2e13633 | 2016-08-16 07:50:16 -0400 | [diff] [blame] | 1030 | } |
| 1031 | return error; |
| 1032 | } |
| 1033 | |
Dileep Marchya | f3ce11f | 2018-04-30 23:35:46 +0530 | [diff] [blame] | 1034 | DisplayError HWCDisplayBuiltIn::ControlPartialUpdate(bool enable, uint32_t *pending) { |
Arun Kumar K.R | 17bbd04 | 2016-06-07 17:38:02 -0700 | [diff] [blame] | 1035 | DisplayError error = kErrorNone; |
| 1036 | |
| 1037 | if (display_intf_) { |
| 1038 | error = display_intf_->ControlPartialUpdate(enable, pending); |
Saurabh Shah | a307e8c | 2017-09-28 18:05:40 -0700 | [diff] [blame] | 1039 | validated_ = false; |
Arun Kumar K.R | 17bbd04 | 2016-06-07 17:38:02 -0700 | [diff] [blame] | 1040 | } |
| 1041 | |
| 1042 | return error; |
| 1043 | } |
| 1044 | |
Dileep Marchya | f3ce11f | 2018-04-30 23:35:46 +0530 | [diff] [blame] | 1045 | DisplayError HWCDisplayBuiltIn::DisablePartialUpdateOneFrame() { |
Arun Kumar K.R | 17bbd04 | 2016-06-07 17:38:02 -0700 | [diff] [blame] | 1046 | DisplayError error = kErrorNone; |
| 1047 | |
| 1048 | if (display_intf_) { |
| 1049 | error = display_intf_->DisablePartialUpdateOneFrame(); |
Saurabh Shah | a307e8c | 2017-09-28 18:05:40 -0700 | [diff] [blame] | 1050 | validated_ = false; |
Arun Kumar K.R | 17bbd04 | 2016-06-07 17:38:02 -0700 | [diff] [blame] | 1051 | } |
| 1052 | |
| 1053 | return error; |
| 1054 | } |
| 1055 | |
Lakshmi Narayana Kalavala | 25fe12c | 2019-12-11 20:44:55 -0800 | [diff] [blame] | 1056 | HWC2::Error HWCDisplayBuiltIn::SetDisplayedContentSamplingEnabledVndService(bool enabled) { |
| 1057 | std::unique_lock<decltype(sampling_mutex)> lk(sampling_mutex); |
| 1058 | vndservice_sampling_vote = enabled; |
| 1059 | if (api_sampling_vote || vndservice_sampling_vote) { |
| 1060 | histogram.start(); |
Lakshmi Narayana Kalavala | f30c229 | 2019-09-26 15:26:24 -0700 | [diff] [blame] | 1061 | display_intf_->colorSamplingOn(); |
Lakshmi Narayana Kalavala | 25fe12c | 2019-12-11 20:44:55 -0800 | [diff] [blame] | 1062 | } else { |
Lakshmi Narayana Kalavala | f30c229 | 2019-09-26 15:26:24 -0700 | [diff] [blame] | 1063 | display_intf_->colorSamplingOff(); |
Lakshmi Narayana Kalavala | 25fe12c | 2019-12-11 20:44:55 -0800 | [diff] [blame] | 1064 | histogram.stop(); |
| 1065 | } |
| 1066 | return HWC2::Error::None; |
| 1067 | } |
| 1068 | |
| 1069 | HWC2::Error HWCDisplayBuiltIn::SetDisplayedContentSamplingEnabled(int32_t enabled, |
| 1070 | uint8_t component_mask, |
| 1071 | uint64_t max_frames) { |
| 1072 | if ((enabled != HWC2_DISPLAYED_CONTENT_SAMPLING_ENABLE) && |
| 1073 | (enabled != HWC2_DISPLAYED_CONTENT_SAMPLING_DISABLE)) |
| 1074 | return HWC2::Error::BadParameter; |
| 1075 | |
| 1076 | std::unique_lock<decltype(sampling_mutex)> lk(sampling_mutex); |
| 1077 | if (enabled == HWC2_DISPLAYED_CONTENT_SAMPLING_ENABLE) { |
| 1078 | api_sampling_vote = true; |
| 1079 | } else { |
| 1080 | api_sampling_vote = false; |
| 1081 | } |
| 1082 | |
| 1083 | auto start = api_sampling_vote || vndservice_sampling_vote; |
| 1084 | if (start && max_frames == 0) { |
| 1085 | histogram.start(); |
Lakshmi Narayana Kalavala | f30c229 | 2019-09-26 15:26:24 -0700 | [diff] [blame] | 1086 | display_intf_->colorSamplingOn(); |
Lakshmi Narayana Kalavala | 25fe12c | 2019-12-11 20:44:55 -0800 | [diff] [blame] | 1087 | } else if (start) { |
| 1088 | histogram.start(max_frames); |
Lakshmi Narayana Kalavala | f30c229 | 2019-09-26 15:26:24 -0700 | [diff] [blame] | 1089 | display_intf_->colorSamplingOn(); |
Lakshmi Narayana Kalavala | 25fe12c | 2019-12-11 20:44:55 -0800 | [diff] [blame] | 1090 | } else { |
Lakshmi Narayana Kalavala | f30c229 | 2019-09-26 15:26:24 -0700 | [diff] [blame] | 1091 | display_intf_->colorSamplingOff(); |
Lakshmi Narayana Kalavala | 25fe12c | 2019-12-11 20:44:55 -0800 | [diff] [blame] | 1092 | histogram.stop(); |
| 1093 | } |
| 1094 | return HWC2::Error::None; |
| 1095 | } |
| 1096 | |
| 1097 | HWC2::Error HWCDisplayBuiltIn::GetDisplayedContentSamplingAttributes( |
| 1098 | int32_t *format, int32_t *dataspace, uint8_t *supported_components) { |
| 1099 | return histogram.getAttributes(format, dataspace, supported_components); |
| 1100 | } |
| 1101 | |
| 1102 | HWC2::Error HWCDisplayBuiltIn::GetDisplayedContentSample( |
| 1103 | uint64_t max_frames, uint64_t timestamp, uint64_t *numFrames, |
| 1104 | int32_t samples_size[NUM_HISTOGRAM_COLOR_COMPONENTS], |
| 1105 | uint64_t *samples[NUM_HISTOGRAM_COLOR_COMPONENTS]) { |
| 1106 | histogram.collect(max_frames, timestamp, samples_size, samples, numFrames); |
| 1107 | return HWC2::Error::None; |
| 1108 | } |
Arun Kumar K.R | 17bbd04 | 2016-06-07 17:38:02 -0700 | [diff] [blame] | 1109 | |
Dileep Marchya | f3ce11f | 2018-04-30 23:35:46 +0530 | [diff] [blame] | 1110 | DisplayError HWCDisplayBuiltIn::SetMixerResolution(uint32_t width, uint32_t height) { |
Sushil Chauhan | 409e844 | 2017-06-12 17:43:25 -0700 | [diff] [blame] | 1111 | DisplayError error = display_intf_->SetMixerResolution(width, height); |
Ramkumar Radhakrishnan | f7f5216 | 2019-06-06 19:40:04 -0700 | [diff] [blame] | 1112 | callbacks_->Refresh(id_); |
Saurabh Shah | a307e8c | 2017-09-28 18:05:40 -0700 | [diff] [blame] | 1113 | validated_ = false; |
Sushil Chauhan | 409e844 | 2017-06-12 17:43:25 -0700 | [diff] [blame] | 1114 | return error; |
Arun Kumar K.R | 8da7f50 | 2016-06-07 17:45:50 -0700 | [diff] [blame] | 1115 | } |
| 1116 | |
Dileep Marchya | f3ce11f | 2018-04-30 23:35:46 +0530 | [diff] [blame] | 1117 | DisplayError HWCDisplayBuiltIn::GetMixerResolution(uint32_t *width, uint32_t *height) { |
Arun Kumar K.R | 8da7f50 | 2016-06-07 17:45:50 -0700 | [diff] [blame] | 1118 | return display_intf_->GetMixerResolution(width, height); |
| 1119 | } |
| 1120 | |
Dileep Marchya | f3ce11f | 2018-04-30 23:35:46 +0530 | [diff] [blame] | 1121 | HWC2::Error HWCDisplayBuiltIn::SetQSyncMode(QSyncMode qsync_mode) { |
Pullakavi Srinivas | 2457414 | 2019-08-14 12:18:12 +0530 | [diff] [blame] | 1122 | // Client needs to ensure that config change and qsync mode change |
| 1123 | // are not triggered in the same drawcycle. |
| 1124 | if (pending_config_) { |
| 1125 | DLOGE("Failed to set qsync mode. Pending active config transition"); |
| 1126 | return HWC2::Error::Unsupported; |
| 1127 | } |
| 1128 | |
Sushil Chauhan | 380a59d | 2018-03-19 15:47:50 -0700 | [diff] [blame] | 1129 | auto err = display_intf_->SetQSyncMode(qsync_mode); |
| 1130 | if (err != kErrorNone) { |
| 1131 | return HWC2::Error::Unsupported; |
| 1132 | } |
| 1133 | |
Sushil Chauhan | ec4eb57 | 2019-02-07 13:29:42 -0800 | [diff] [blame] | 1134 | validated_ = false; |
Sushil Chauhan | 380a59d | 2018-03-19 15:47:50 -0700 | [diff] [blame] | 1135 | return HWC2::Error::None; |
| 1136 | } |
| 1137 | |
Ramkumar Radhakrishnan | 4faf8a6 | 2018-11-15 17:15:37 -0800 | [diff] [blame] | 1138 | DisplayError HWCDisplayBuiltIn::ControlIdlePowerCollapse(bool enable, bool synchronous) { |
Ramkumar Radhakrishnan | f985d48 | 2018-07-23 18:10:41 -0700 | [diff] [blame] | 1139 | DisplayError error = kErrorNone; |
| 1140 | |
| 1141 | if (display_intf_) { |
| 1142 | error = display_intf_->ControlIdlePowerCollapse(enable, synchronous); |
| 1143 | validated_ = false; |
| 1144 | } |
Ramkumar Radhakrishnan | 4faf8a6 | 2018-11-15 17:15:37 -0800 | [diff] [blame] | 1145 | return error; |
Ramkumar Radhakrishnan | f985d48 | 2018-07-23 18:10:41 -0700 | [diff] [blame] | 1146 | } |
| 1147 | |
Pullakavi Srinivas | 9189e60 | 2018-12-19 16:58:07 +0530 | [diff] [blame] | 1148 | DisplayError HWCDisplayBuiltIn::SetDynamicDSIClock(uint64_t bitclk) { |
Dileep Marchya | afa45bc | 2019-06-21 17:05:31 +0530 | [diff] [blame] | 1149 | DisablePartialUpdateOneFrame(); |
| 1150 | DisplayError error = display_intf_->SetDynamicDSIClock(bitclk); |
| 1151 | if (error != kErrorNone) { |
Pullakavi Srinivas | ce3692b | 2020-02-13 01:14:09 +0530 | [diff] [blame] | 1152 | DLOGE(" failed: Clk: %" PRIu64 " Error: %d", bitclk, error); |
Dileep Marchya | afa45bc | 2019-06-21 17:05:31 +0530 | [diff] [blame] | 1153 | return error; |
Pullakavi Srinivas | 9189e60 | 2018-12-19 16:58:07 +0530 | [diff] [blame] | 1154 | } |
| 1155 | |
| 1156 | callbacks_->Refresh(id_); |
| 1157 | validated_ = false; |
| 1158 | |
| 1159 | return kErrorNone; |
| 1160 | } |
| 1161 | |
| 1162 | DisplayError HWCDisplayBuiltIn::GetDynamicDSIClock(uint64_t *bitclk) { |
Pullakavi Srinivas | 9189e60 | 2018-12-19 16:58:07 +0530 | [diff] [blame] | 1163 | if (display_intf_) { |
| 1164 | return display_intf_->GetDynamicDSIClock(bitclk); |
| 1165 | } |
| 1166 | |
| 1167 | return kErrorNotSupported; |
| 1168 | } |
| 1169 | |
| 1170 | DisplayError HWCDisplayBuiltIn::GetSupportedDSIClock(std::vector<uint64_t> *bitclk_rates) { |
| 1171 | if (display_intf_) { |
| 1172 | return display_intf_->GetSupportedDSIClock(bitclk_rates); |
| 1173 | } |
| 1174 | |
| 1175 | return kErrorNotSupported; |
| 1176 | } |
| 1177 | |
Padmanabhan Komanduru | e74cf4f | 2019-04-25 17:38:43 -0700 | [diff] [blame] | 1178 | HWC2::Error HWCDisplayBuiltIn::UpdateDisplayId(hwc2_display_t id) { |
| 1179 | id_ = id; |
| 1180 | return HWC2::Error::None; |
| 1181 | } |
| 1182 | |
| 1183 | HWC2::Error HWCDisplayBuiltIn::SetPendingRefresh() { |
| 1184 | pending_refresh_ = true; |
| 1185 | return HWC2::Error::None; |
| 1186 | } |
| 1187 | |
Varun Arora | 75c05f0 | 2019-05-14 14:53:37 -0700 | [diff] [blame] | 1188 | HWC2::Error HWCDisplayBuiltIn::SetPanelBrightness(float brightness) { |
| 1189 | DisplayError ret = display_intf_->SetPanelBrightness(brightness); |
| 1190 | if (ret != kErrorNone) { |
| 1191 | return HWC2::Error::NoResources; |
| 1192 | } |
| 1193 | |
| 1194 | return HWC2::Error::None; |
| 1195 | } |
| 1196 | |
| 1197 | HWC2::Error HWCDisplayBuiltIn::GetPanelBrightness(float *brightness) { |
| 1198 | DisplayError ret = display_intf_->GetPanelBrightness(brightness); |
| 1199 | if (ret != kErrorNone) { |
| 1200 | return HWC2::Error::NoResources; |
| 1201 | } |
| 1202 | |
| 1203 | return HWC2::Error::None; |
| 1204 | } |
Xu Yang | 45d0abf | 2019-07-05 11:34:06 +0800 | [diff] [blame] | 1205 | |
Yuchao Ma | ada1c40 | 2019-11-12 14:47:11 +0800 | [diff] [blame] | 1206 | HWC2::Error HWCDisplayBuiltIn::GetPanelMaxBrightness(uint32_t *max_brightness_level) { |
| 1207 | DisplayError ret = display_intf_->GetPanelMaxBrightness(max_brightness_level); |
| 1208 | if (ret != kErrorNone) { |
| 1209 | return HWC2::Error::NoResources; |
| 1210 | } |
| 1211 | |
| 1212 | return HWC2::Error::None; |
| 1213 | } |
| 1214 | |
Xu Yang | 45d0abf | 2019-07-05 11:34:06 +0800 | [diff] [blame] | 1215 | HWC2::Error HWCDisplayBuiltIn::SetBLScale(uint32_t level) { |
| 1216 | DisplayError ret = display_intf_->SetBLScale(level); |
| 1217 | if (ret != kErrorNone) { |
| 1218 | return HWC2::Error::NoResources; |
| 1219 | } |
Srinivas Pullakavi | 3c4337f | 2019-07-03 11:24:31 +0530 | [diff] [blame] | 1220 | return HWC2::Error::None; |
| 1221 | } |
Xu Yang | 45d0abf | 2019-07-05 11:34:06 +0800 | [diff] [blame] | 1222 | |
Srinivas Pullakavi | 3c4337f | 2019-07-03 11:24:31 +0530 | [diff] [blame] | 1223 | HWC2::Error HWCDisplayBuiltIn::UpdatePowerMode(HWC2::PowerMode mode) { |
| 1224 | current_power_mode_ = mode; |
| 1225 | validated_ = false; |
Xu Yang | 45d0abf | 2019-07-05 11:34:06 +0800 | [diff] [blame] | 1226 | return HWC2::Error::None; |
| 1227 | } |
| 1228 | |
Rajavenu Kyatham | 7338b9e | 2019-12-30 19:52:16 +0530 | [diff] [blame] | 1229 | HWC2::Error HWCDisplayBuiltIn::SetClientTarget(buffer_handle_t target, |
| 1230 | shared_ptr<Fence> acquire_fence, |
Padmanabhan Komanduru | 9a91e9f | 2019-09-12 12:33:19 +0530 | [diff] [blame] | 1231 | int32_t dataspace, hwc_region_t damage) { |
| 1232 | HWC2::Error error = HWCDisplay::SetClientTarget(target, acquire_fence, dataspace, damage); |
| 1233 | if (error != HWC2::Error::None) { |
| 1234 | return error; |
| 1235 | } |
| 1236 | |
Pullakavi Srinivas | d32b492 | 2020-02-10 10:08:31 +0530 | [diff] [blame] | 1237 | // windowed_display and dynamic scaling are not supported. |
| 1238 | if (windowed_display_) { |
| 1239 | return HWC2::Error::None; |
| 1240 | } |
| 1241 | |
Padmanabhan Komanduru | 9a91e9f | 2019-09-12 12:33:19 +0530 | [diff] [blame] | 1242 | Layer *sdm_layer = client_target_->GetSDMLayer(); |
Padmanabhan Komanduru | a4bf606 | 2019-10-13 09:04:49 +0530 | [diff] [blame] | 1243 | uint32_t fb_width = 0, fb_height = 0; |
| 1244 | |
| 1245 | GetFrameBufferResolution(&fb_width, &fb_height); |
| 1246 | |
| 1247 | if (fb_width != sdm_layer->input_buffer.unaligned_width || |
| 1248 | fb_height != sdm_layer->input_buffer.unaligned_height) { |
| 1249 | if (SetFrameBufferConfig(sdm_layer->input_buffer.unaligned_width, |
| 1250 | sdm_layer->input_buffer.unaligned_height)) { |
| 1251 | return HWC2::Error::BadParameter; |
| 1252 | } |
| 1253 | } |
Padmanabhan Komanduru | 9a91e9f | 2019-09-12 12:33:19 +0530 | [diff] [blame] | 1254 | |
| 1255 | return HWC2::Error::None; |
| 1256 | } |
Sushil Chauhan | 1566a13 | 2019-10-02 11:59:28 -0700 | [diff] [blame] | 1257 | |
| 1258 | bool HWCDisplayBuiltIn::IsSmartPanelConfig(uint32_t config_id) { |
| 1259 | if (config_id < hwc_config_map_.size()) { |
| 1260 | uint32_t index = hwc_config_map_.at(config_id); |
| 1261 | return variable_config_map_.at(index).smart_panel; |
| 1262 | } |
| 1263 | |
| 1264 | return false; |
| 1265 | } |
| 1266 | |
Padmanabhan Komanduru | e6087e4 | 2020-04-10 10:22:57 +0530 | [diff] [blame^] | 1267 | bool HWCDisplayBuiltIn::HasSmartPanelConfig(void) { |
| 1268 | for (auto &config : variable_config_map_) { |
| 1269 | if (config.second.smart_panel) { |
| 1270 | return true; |
| 1271 | } |
| 1272 | } |
| 1273 | |
| 1274 | return false; |
| 1275 | } |
| 1276 | |
Pullakavi Srinivas | 1ae4acb | 2019-11-18 19:33:45 +0530 | [diff] [blame] | 1277 | int HWCDisplayBuiltIn::Deinit() { |
| 1278 | // Destory color convert instance. This destroys thread and underlying GL resources. |
| 1279 | if (gl_layer_stitch_) { |
| 1280 | layer_stitch_task_.PerformTask(LayerStitchTaskCode::kCodeDestroyInstance, nullptr); |
| 1281 | } |
| 1282 | |
Lakshmi Narayana Kalavala | 25fe12c | 2019-12-11 20:44:55 -0800 | [diff] [blame] | 1283 | histogram.stop(); |
Pullakavi Srinivas | 1ae4acb | 2019-11-18 19:33:45 +0530 | [diff] [blame] | 1284 | return HWCDisplay::Deinit(); |
| 1285 | } |
| 1286 | |
| 1287 | void HWCDisplayBuiltIn::OnTask(const LayerStitchTaskCode &task_code, |
| 1288 | SyncTask<LayerStitchTaskCode>::TaskContext *task_context) { |
| 1289 | switch (task_code) { |
| 1290 | case LayerStitchTaskCode::kCodeGetInstance: { |
| 1291 | gl_layer_stitch_ = GLLayerStitch::GetInstance(false /* Non-secure */); |
| 1292 | } |
| 1293 | break; |
| 1294 | case LayerStitchTaskCode::kCodeStitch: { |
| 1295 | DTRACE_SCOPED(); |
Pullakavi Srinivas | db2b84a | 2019-11-21 14:47:35 +0530 | [diff] [blame] | 1296 | LayerStitchContext* ctx = reinterpret_cast<LayerStitchContext*>(task_context); |
Pullakavi Srinivas | 1ae4acb | 2019-11-18 19:33:45 +0530 | [diff] [blame] | 1297 | gl_layer_stitch_->Blit(ctx->src_hnd, ctx->dst_hnd, ctx->src_rect, ctx->dst_rect, |
Pullakavi Srinivas | f25bc4a | 2020-02-27 12:07:39 +0530 | [diff] [blame] | 1298 | ctx->scissor_rect, ctx->src_acquire_fence, |
| 1299 | ctx->dst_acquire_fence, &(ctx->release_fence)); |
Pullakavi Srinivas | 1ae4acb | 2019-11-18 19:33:45 +0530 | [diff] [blame] | 1300 | } |
| 1301 | break; |
| 1302 | case LayerStitchTaskCode::kCodeDestroyInstance: { |
| 1303 | if (gl_layer_stitch_) { |
| 1304 | GLLayerStitch::Destroy(gl_layer_stitch_); |
| 1305 | } |
| 1306 | } |
| 1307 | break; |
| 1308 | } |
| 1309 | } |
| 1310 | |
| 1311 | bool HWCDisplayBuiltIn::InitLayerStitch() { |
| 1312 | if (!is_primary_) { |
| 1313 | // Disable on all non-primary builtins. |
| 1314 | DLOGI("Non-primary builtin."); |
Pullakavi Srinivas | 94793b4 | 2019-11-27 20:03:50 +0530 | [diff] [blame] | 1315 | disable_layer_stitch_ = true; |
Pullakavi Srinivas | 1ae4acb | 2019-11-18 19:33:45 +0530 | [diff] [blame] | 1316 | return true; |
| 1317 | } |
| 1318 | |
| 1319 | // Disable by default. |
| 1320 | int value = 1; |
| 1321 | Debug::Get()->GetProperty(DISABLE_LAYER_STITCH, &value); |
| 1322 | disable_layer_stitch_ = (value == 1); |
| 1323 | |
| 1324 | if (disable_layer_stitch_) { |
| 1325 | DLOGI("Layer Stitch Disabled !!!"); |
| 1326 | return true; |
| 1327 | } |
| 1328 | |
| 1329 | // Initialize stitch context. This will be non-secure. |
| 1330 | layer_stitch_task_.PerformTask(LayerStitchTaskCode::kCodeGetInstance, nullptr); |
| 1331 | if (gl_layer_stitch_ == nullptr) { |
| 1332 | DLOGE("Failed to get LayerStitch Instance"); |
| 1333 | return false; |
| 1334 | } |
| 1335 | |
| 1336 | if (!AllocateStitchBuffer()) { |
| 1337 | return true; |
| 1338 | } |
| 1339 | |
| 1340 | stitch_target_ = new HWCLayer(id_, static_cast<HWCBufferAllocator *>(buffer_allocator_)); |
| 1341 | |
| 1342 | // Populate buffer params and pvt handle. |
| 1343 | InitStitchTarget(); |
| 1344 | |
| 1345 | DLOGI("Created LayerStitch instance: %p", gl_layer_stitch_); |
| 1346 | |
| 1347 | return true; |
| 1348 | } |
| 1349 | |
| 1350 | bool HWCDisplayBuiltIn::AllocateStitchBuffer() { |
| 1351 | // Buffer dimensions: FB width * (1.5 * height) |
| 1352 | |
| 1353 | DisplayError error = display_intf_->GetFrameBufferConfig(&fb_config_); |
| 1354 | if (error != kErrorNone) { |
| 1355 | DLOGE("Get frame buffer config failed. Error = %d", error); |
| 1356 | return false; |
| 1357 | } |
| 1358 | |
| 1359 | BufferConfig &config = buffer_info_.buffer_config; |
| 1360 | config.width = fb_config_.x_pixels; |
| 1361 | config.height = fb_config_.y_pixels * kBufferHeightFactor; |
| 1362 | |
| 1363 | // By default UBWC is enabled and below property is global enable/disable for all |
| 1364 | // buffers allocated through gralloc , including framebuffer targets. |
| 1365 | int ubwc_disabled = 0; |
| 1366 | HWCDebugHandler::Get()->GetProperty(DISABLE_UBWC_PROP, &ubwc_disabled); |
| 1367 | config.format = ubwc_disabled ? kFormatRGBA8888 : kFormatRGBA8888Ubwc; |
| 1368 | |
| 1369 | config.gfx_client = true; |
| 1370 | |
| 1371 | // Populate default params. |
| 1372 | config.secure = false; |
| 1373 | config.cache = false; |
| 1374 | config.secure_camera = false; |
| 1375 | |
| 1376 | error = buffer_allocator_->AllocateBuffer(&buffer_info_); |
| 1377 | |
| 1378 | if (error != kErrorNone) { |
| 1379 | DLOGE("Failed to allocate buffer. Error: %d", error); |
| 1380 | return false; |
| 1381 | } |
| 1382 | |
| 1383 | return true; |
| 1384 | } |
| 1385 | |
| 1386 | void HWCDisplayBuiltIn::InitStitchTarget() { |
| 1387 | LayerBuffer buffer = {}; |
| 1388 | buffer.planes[0].fd = buffer_info_.alloc_buffer_info.fd; |
| 1389 | buffer.planes[0].offset = 0; |
| 1390 | buffer.planes[0].stride = buffer_info_.alloc_buffer_info.stride; |
| 1391 | buffer.size = buffer_info_.alloc_buffer_info.size; |
| 1392 | buffer.handle_id = buffer_info_.alloc_buffer_info.id; |
| 1393 | buffer.width = buffer_info_.alloc_buffer_info.aligned_width; |
| 1394 | buffer.height = buffer_info_.alloc_buffer_info.aligned_height; |
| 1395 | buffer.unaligned_width = fb_config_.x_pixels; |
Pullakavi Srinivas | db2b84a | 2019-11-21 14:47:35 +0530 | [diff] [blame] | 1396 | buffer.unaligned_height = fb_config_.y_pixels * kBufferHeightFactor; |
Pullakavi Srinivas | 1ae4acb | 2019-11-18 19:33:45 +0530 | [diff] [blame] | 1397 | buffer.format = buffer_info_.alloc_buffer_info.format; |
| 1398 | |
| 1399 | Layer *sdm_stitch_target = stitch_target_->GetSDMLayer(); |
| 1400 | sdm_stitch_target->composition = kCompositionStitchTarget; |
| 1401 | sdm_stitch_target->input_buffer = buffer; |
| 1402 | sdm_stitch_target->input_buffer.buffer_id = reinterpret_cast<uint64_t>(buffer_info_.private_data); |
| 1403 | } |
| 1404 | |
| 1405 | void HWCDisplayBuiltIn::AppendStitchLayer() { |
| 1406 | if (disable_layer_stitch_) { |
| 1407 | return; |
| 1408 | } |
| 1409 | |
| 1410 | // Append stitch target buffer to layer stack. |
| 1411 | Layer *sdm_stitch_target = stitch_target_->GetSDMLayer(); |
| 1412 | sdm_stitch_target->composition = kCompositionStitchTarget; |
Pullakavi Srinivas | db2b84a | 2019-11-21 14:47:35 +0530 | [diff] [blame] | 1413 | sdm_stitch_target->dst_rect = {0, 0, FLOAT(fb_config_.x_pixels), FLOAT(fb_config_.y_pixels)}; |
Pullakavi Srinivas | 1ae4acb | 2019-11-18 19:33:45 +0530 | [diff] [blame] | 1414 | layer_stack_.layers.push_back(sdm_stitch_target); |
| 1415 | } |
| 1416 | |
Lakshmi Narayana Kalavala | e0127eb | 2019-12-03 11:07:26 -0800 | [diff] [blame] | 1417 | DisplayError HWCDisplayBuiltIn::HistogramEvent(int fd, uint32_t blob_id) { |
| 1418 | histogram.notify_histogram_event(fd, blob_id); |
| 1419 | return kErrorNone; |
| 1420 | } |
Pullakavi Srinivas | db2b84a | 2019-11-21 14:47:35 +0530 | [diff] [blame] | 1421 | |
| 1422 | int HWCDisplayBuiltIn::PostInit() { |
| 1423 | auto status = InitLayerStitch(); |
| 1424 | if (!status) { |
| 1425 | DLOGW("Failed to initialize Layer Stitch context"); |
| 1426 | // Disable layer stitch. |
| 1427 | disable_layer_stitch_ = true; |
| 1428 | } |
| 1429 | |
| 1430 | return 0; |
| 1431 | } |
| 1432 | |
Venkat Thogaru | 8e9b124 | 2020-03-30 19:25:24 +0530 | [diff] [blame] | 1433 | bool HWCDisplayBuiltIn::HasReadBackBufferSupport() { |
| 1434 | DisplayConfigFixedInfo fixed_info = {}; |
| 1435 | display_intf_->GetConfig(&fixed_info); |
| 1436 | |
| 1437 | return fixed_info.readback_supported; |
| 1438 | } |
| 1439 | |
Naseer Ahmed | b92e73f | 2016-03-12 02:03:48 -0500 | [diff] [blame] | 1440 | } // namespace sdm |