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