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