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