blob: 70e8f622b1fa81fe5999b885e691abd20e6b77b3 [file] [log] [blame]
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -08001/*
2 * Copyright (C) 2007 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
Dan Stoza9e56aa02015-11-02 13:00:03 -080017// #define LOG_NDEBUG 0
18#undef LOG_TAG
19#define LOG_TAG "DisplayDevice"
20
Peiyong Lincbc184f2018-08-22 13:24:10 -070021#include "DisplayDevice.h"
22
Chia-I Wube02ec02018-05-18 10:59:36 -070023#include <array>
24#include <unordered_set>
25
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -080026#include <stdlib.h>
27#include <stdio.h>
28#include <string.h>
29#include <math.h>
30
Dominik Laskowski9b17b2c22018-11-01 14:49:03 -070031#include <android-base/stringprintf.h>
Peiyong Lincbc184f2018-08-22 13:24:10 -070032#include <android/hardware/configstore/1.0/ISurfaceFlingerConfigs.h>
Lloyd Pique45a165a2018-10-19 11:54:47 -070033#include <compositionengine/CompositionEngine.h>
34#include <compositionengine/Display.h>
35#include <compositionengine/DisplayCreationArgs.h>
Peiyong Lincbc184f2018-08-22 13:24:10 -070036#include <configstore/Utils.h>
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -080037#include <cutils/properties.h>
Peiyong Lincbc184f2018-08-22 13:24:10 -070038#include <gui/Surface.h>
39#include <hardware/gralloc.h>
40#include <renderengine/RenderEngine.h>
Alec Mouri0a9c7b82018-11-16 13:05:25 -080041#include <sync/sync.h>
42#include <system/window.h>
Courtney Goeltzenleuchter152279d2017-08-14 18:18:30 -060043#include <ui/DebugUtils.h>
Mathias Agopianc666cae2012-07-25 18:56:13 -070044#include <ui/DisplayInfo.h>
Mathias Agopian076b1cc2009-04-10 14:24:30 -070045#include <ui/PixelFormat.h>
Peiyong Lincbc184f2018-08-22 13:24:10 -070046#include <utils/Log.h>
Valerie Hau9758ae02018-10-09 16:05:09 -070047#include <utils/RefBase.h>
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -080048
Jesse Hall99c7dbb2013-03-14 14:29:29 -070049#include "DisplayHardware/DisplaySurface.h"
Mathias Agopian1b031492012-06-20 17:51:20 -070050#include "DisplayHardware/HWComposer.h"
Dan Stoza9e56aa02015-11-02 13:00:03 -080051#include "DisplayHardware/HWC2.h"
Mathias Agopianc7d14e22011-08-01 16:32:21 -070052#include "SurfaceFlinger.h"
Mathias Agopian13127d82013-03-05 17:47:11 -080053#include "Layer.h"
Mathias Agopian1f7bec62010-06-25 18:02:21 -070054
Peiyong Linfd997e02018-03-28 15:29:00 -070055namespace android {
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -080056
Jaesoo Lee720a7242017-01-31 15:26:18 +090057// retrieve triple buffer setting from configstore
58using namespace android::hardware::configstore;
59using namespace android::hardware::configstore::V1_0;
Yiwei Zhang5434a782018-12-05 18:06:32 -080060using android::base::StringAppendF;
Peiyong Linfd997e02018-03-28 15:29:00 -070061using android::ui::ColorMode;
Chia-I Wube02ec02018-05-18 10:59:36 -070062using android::ui::Dataspace;
Peiyong Lin62665892018-04-16 11:07:44 -070063using android::ui::Hdr;
Peiyong Lindd9b2ae2018-03-01 16:22:45 -080064using android::ui::RenderIntent;
Jaesoo Lee720a7242017-01-31 15:26:18 +090065
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -080066/*
67 * Initialize the display to the specified values.
68 *
69 */
70
Pablo Ceballos021623b2016-04-15 17:31:51 -070071uint32_t DisplayDevice::sPrimaryDisplayOrientation = 0;
72
Chia-I Wube02ec02018-05-18 10:59:36 -070073namespace {
74
75// ordered list of known SDR color modes
Valerie Hau9758ae02018-10-09 16:05:09 -070076const std::array<ColorMode, 3> sSdrColorModes = {
77 ColorMode::DISPLAY_BT2020,
Chia-I Wube02ec02018-05-18 10:59:36 -070078 ColorMode::DISPLAY_P3,
79 ColorMode::SRGB,
80};
81
82// ordered list of known HDR color modes
83const std::array<ColorMode, 2> sHdrColorModes = {
84 ColorMode::BT2100_PQ,
85 ColorMode::BT2100_HLG,
86};
87
88// ordered list of known SDR render intents
89const std::array<RenderIntent, 2> sSdrRenderIntents = {
90 RenderIntent::ENHANCE,
91 RenderIntent::COLORIMETRIC,
92};
93
94// ordered list of known HDR render intents
95const std::array<RenderIntent, 2> sHdrRenderIntents = {
96 RenderIntent::TONE_MAP_ENHANCE,
97 RenderIntent::TONE_MAP_COLORIMETRIC,
98};
99
100// map known color mode to dataspace
101Dataspace colorModeToDataspace(ColorMode mode) {
102 switch (mode) {
103 case ColorMode::SRGB:
Peiyong Lin14724e62018-12-05 07:27:30 -0800104 return Dataspace::V0_SRGB;
Chia-I Wube02ec02018-05-18 10:59:36 -0700105 case ColorMode::DISPLAY_P3:
106 return Dataspace::DISPLAY_P3;
Valerie Hau9758ae02018-10-09 16:05:09 -0700107 case ColorMode::DISPLAY_BT2020:
108 return Dataspace::DISPLAY_BT2020;
Chia-I Wube02ec02018-05-18 10:59:36 -0700109 case ColorMode::BT2100_HLG:
110 return Dataspace::BT2020_HLG;
111 case ColorMode::BT2100_PQ:
112 return Dataspace::BT2020_PQ;
113 default:
114 return Dataspace::UNKNOWN;
115 }
116}
117
118// Return a list of candidate color modes.
119std::vector<ColorMode> getColorModeCandidates(ColorMode mode) {
120 std::vector<ColorMode> candidates;
121
122 // add mode itself
123 candidates.push_back(mode);
124
125 // check if mode is HDR
126 bool isHdr = false;
127 for (auto hdrMode : sHdrColorModes) {
128 if (hdrMode == mode) {
129 isHdr = true;
130 break;
131 }
132 }
133
134 // add other HDR candidates when mode is HDR
135 if (isHdr) {
136 for (auto hdrMode : sHdrColorModes) {
137 if (hdrMode != mode) {
138 candidates.push_back(hdrMode);
139 }
140 }
141 }
142
143 // add other SDR candidates
144 for (auto sdrMode : sSdrColorModes) {
145 if (sdrMode != mode) {
146 candidates.push_back(sdrMode);
147 }
148 }
149
150 return candidates;
151}
152
153// Return a list of candidate render intents.
154std::vector<RenderIntent> getRenderIntentCandidates(RenderIntent intent) {
155 std::vector<RenderIntent> candidates;
156
157 // add intent itself
158 candidates.push_back(intent);
159
160 // check if intent is HDR
161 bool isHdr = false;
162 for (auto hdrIntent : sHdrRenderIntents) {
163 if (hdrIntent == intent) {
164 isHdr = true;
165 break;
166 }
167 }
168
Chia-I Wube02ec02018-05-18 10:59:36 -0700169 if (isHdr) {
Chia-I Wuc4b08bd2018-05-29 12:57:23 -0700170 // add other HDR candidates when intent is HDR
Chia-I Wube02ec02018-05-18 10:59:36 -0700171 for (auto hdrIntent : sHdrRenderIntents) {
172 if (hdrIntent != intent) {
173 candidates.push_back(hdrIntent);
174 }
175 }
Chia-I Wuc4b08bd2018-05-29 12:57:23 -0700176 } else {
177 // add other SDR candidates when intent is SDR
178 for (auto sdrIntent : sSdrRenderIntents) {
179 if (sdrIntent != intent) {
180 candidates.push_back(sdrIntent);
181 }
182 }
Chia-I Wube02ec02018-05-18 10:59:36 -0700183 }
184
185 return candidates;
186}
187
188// Return the best color mode supported by HWC.
189ColorMode getHwcColorMode(
190 const std::unordered_map<ColorMode, std::vector<RenderIntent>>& hwcColorModes,
191 ColorMode mode) {
192 std::vector<ColorMode> candidates = getColorModeCandidates(mode);
193 for (auto candidate : candidates) {
194 auto iter = hwcColorModes.find(candidate);
195 if (iter != hwcColorModes.end()) {
196 return candidate;
197 }
198 }
199
200 return ColorMode::NATIVE;
201}
202
203// Return the best render intent supported by HWC.
204RenderIntent getHwcRenderIntent(const std::vector<RenderIntent>& hwcIntents, RenderIntent intent) {
205 std::vector<RenderIntent> candidates = getRenderIntentCandidates(intent);
206 for (auto candidate : candidates) {
207 for (auto hwcIntent : hwcIntents) {
208 if (candidate == hwcIntent) {
209 return candidate;
210 }
211 }
212 }
213
214 return RenderIntent::COLORIMETRIC;
215}
216
217} // anonymous namespace
218
Lloyd Pique2eef1d22018-09-18 21:30:04 -0700219DisplayDeviceCreationArgs::DisplayDeviceCreationArgs(const sp<SurfaceFlinger>& flinger,
220 const wp<IBinder>& displayToken,
Dominik Laskowski075d3172018-05-24 15:50:06 -0700221 const std::optional<DisplayId>& displayId)
222 : flinger(flinger), displayToken(displayToken), displayId(displayId) {}
Chia-I Wube02ec02018-05-18 10:59:36 -0700223
Lloyd Pique2eef1d22018-09-18 21:30:04 -0700224DisplayDevice::DisplayDevice(DisplayDeviceCreationArgs&& args)
225 : lastCompositionHadVisibleLayers(false),
226 mFlinger(args.flinger),
Lloyd Pique2eef1d22018-09-18 21:30:04 -0700227 mDisplayToken(args.displayToken),
Dominik Laskowskie9774092018-12-11 10:04:24 -0800228 mSequenceId(args.sequenceId),
Lloyd Pique45a165a2018-10-19 11:54:47 -0700229 mDisplayInstallOrientation(args.displayInstallOrientation),
230 mCompositionDisplay{mFlinger->getCompositionEngine().createDisplay(
231 compositionengine::DisplayCreationArgs{args.isSecure, args.isVirtual,
232 args.displayId})},
Lloyd Pique2eef1d22018-09-18 21:30:04 -0700233 mNativeWindow(args.nativeWindow),
Alec Mouri0a9c7b82018-11-16 13:05:25 -0800234 mGraphicBuffer(nullptr),
Lloyd Pique2eef1d22018-09-18 21:30:04 -0700235 mDisplaySurface(args.displaySurface),
Lloyd Pique2eef1d22018-09-18 21:30:04 -0700236 mPageFlipCount(0),
Dominik Laskowski075d3172018-05-24 15:50:06 -0700237 mIsVirtual(args.isVirtual),
Lloyd Pique2eef1d22018-09-18 21:30:04 -0700238 mLayerStack(NO_LAYER_STACK),
239 mOrientation(),
240 mViewport(Rect::INVALID_RECT),
241 mFrame(Rect::INVALID_RECT),
242 mPowerMode(args.initialPowerMode),
243 mActiveConfig(0),
244 mColorTransform(HAL_COLOR_TRANSFORM_IDENTITY),
245 mHasWideColorGamut(args.hasWideColorGamut),
Valerie Haue9e843a2018-12-18 13:39:23 -0800246 mHasHdr10Plus(false),
Lloyd Pique2eef1d22018-09-18 21:30:04 -0700247 mHasHdr10(false),
248 mHasHLG(false),
249 mHasDolbyVision(false),
Dominik Laskowski075d3172018-05-24 15:50:06 -0700250 mSupportedPerFrameMetadata(args.supportedPerFrameMetadata),
251 mIsPrimary(args.isPrimary) {
Lloyd Pique2eef1d22018-09-18 21:30:04 -0700252 populateColorModes(args.hwcColorModes);
253
254 ALOGE_IF(!mNativeWindow, "No native window was set for display");
255 ALOGE_IF(!mDisplaySurface, "No display surface was set for display");
Lloyd Pique2eef1d22018-09-18 21:30:04 -0700256
257 std::vector<Hdr> types = args.hdrCapabilities.getSupportedHdrTypes();
Peiyong Linfb069302018-04-25 14:34:31 -0700258 for (Hdr hdrType : types) {
Peiyong Lin62665892018-04-16 11:07:44 -0700259 switch (hdrType) {
Valerie Haue9e843a2018-12-18 13:39:23 -0800260 case Hdr::HDR10_PLUS:
261 mHasHdr10Plus = true;
262 break;
Peiyong Lin62665892018-04-16 11:07:44 -0700263 case Hdr::HDR10:
264 mHasHdr10 = true;
265 break;
266 case Hdr::HLG:
267 mHasHLG = true;
268 break;
269 case Hdr::DOLBY_VISION:
270 mHasDolbyVision = true;
271 break;
272 default:
273 ALOGE("UNKNOWN HDR capability: %d", static_cast<int32_t>(hdrType));
274 }
275 }
Jesse Hallffe1f192013-03-22 15:13:48 -0700276
Lloyd Pique2eef1d22018-09-18 21:30:04 -0700277 float minLuminance = args.hdrCapabilities.getDesiredMinLuminance();
278 float maxLuminance = args.hdrCapabilities.getDesiredMaxLuminance();
279 float maxAverageLuminance = args.hdrCapabilities.getDesiredMaxAverageLuminance();
Peiyong Linfb069302018-04-25 14:34:31 -0700280
281 minLuminance = minLuminance <= 0.0 ? sDefaultMinLumiance : minLuminance;
282 maxLuminance = maxLuminance <= 0.0 ? sDefaultMaxLumiance : maxLuminance;
283 maxAverageLuminance = maxAverageLuminance <= 0.0 ? sDefaultMaxLumiance : maxAverageLuminance;
284 if (this->hasWideColorGamut()) {
285 // insert HDR10/HLG as we will force client composition for HDR10/HLG
286 // layers
287 if (!hasHDR10Support()) {
Valerie Haue9e843a2018-12-18 13:39:23 -0800288 types.push_back(Hdr::HDR10);
Peiyong Linfb069302018-04-25 14:34:31 -0700289 }
290
291 if (!hasHLGSupport()) {
Valerie Haue9e843a2018-12-18 13:39:23 -0800292 types.push_back(Hdr::HLG);
Peiyong Linfb069302018-04-25 14:34:31 -0700293 }
294 }
295 mHdrCapabilities = HdrCapabilities(types, maxLuminance, maxAverageLuminance, minLuminance);
296
Alec Mouriba013fa2018-10-16 12:43:11 -0700297 ANativeWindow* const window = mNativeWindow.get();
Alec Mouri0a9c7b82018-11-16 13:05:25 -0800298
Alec Mouri4efb6c22018-11-16 13:07:47 -0800299 int status = native_window_api_connect(window, NATIVE_WINDOW_API_EGL);
Alec Mouri0a9c7b82018-11-16 13:05:25 -0800300 ALOGE_IF(status != NO_ERROR, "Unable to connect BQ producer: %d", status);
Alec Mouri4efb6c22018-11-16 13:07:47 -0800301 status = native_window_set_buffers_format(window, HAL_PIXEL_FORMAT_RGBA_8888);
302 ALOGE_IF(status != NO_ERROR, "Unable to set BQ format to RGBA888: %d", status);
303 status = native_window_set_usage(window, GRALLOC_USAGE_HW_RENDER);
304 ALOGE_IF(status != NO_ERROR, "Unable to set BQ usage bits for GPU rendering: %d", status);
Alec Mouri0a9c7b82018-11-16 13:05:25 -0800305
Alec Mouriba013fa2018-10-16 12:43:11 -0700306 mDisplayWidth = ANativeWindow_getWidth(window);
307 mDisplayHeight = ANativeWindow_getHeight(window);
308
Jesse Hallffe1f192013-03-22 15:13:48 -0700309 // initialize the display orientation transform.
310 setProjection(DisplayState::eOrientationDefault, mViewport, mFrame);
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800311}
312
Lloyd Pique09594832018-01-22 17:48:03 -0800313DisplayDevice::~DisplayDevice() = default;
Mathias Agopian92a979a2012-08-02 18:32:23 -0700314
Lloyd Pique45a165a2018-10-19 11:54:47 -0700315void DisplayDevice::disconnect() {
316 mCompositionDisplay->disconnect();
Jesse Hall02d86562013-03-25 14:43:23 -0700317}
318
Mathias Agopian0f2f5ff2012-07-31 23:09:07 -0700319int DisplayDevice::getWidth() const {
Mathias Agopiana4912602012-07-12 14:25:33 -0700320 return mDisplayWidth;
321}
322
Mathias Agopian0f2f5ff2012-07-31 23:09:07 -0700323int DisplayDevice::getHeight() const {
Mathias Agopiana4912602012-07-12 14:25:33 -0700324 return mDisplayHeight;
325}
326
Dominik Laskowskibf170d92018-04-19 15:08:05 -0700327void DisplayDevice::setDisplayName(const std::string& displayName) {
328 if (!displayName.empty()) {
Mathias Agopian9e2463e2012-09-21 18:26:16 -0700329 // never override the name with an empty name
330 mDisplayName = displayName;
331 }
332}
333
Mathias Agopian0f2f5ff2012-07-31 23:09:07 -0700334uint32_t DisplayDevice::getPageFlipCount() const {
Mathias Agopian076b1cc2009-04-10 14:24:30 -0700335 return mPageFlipCount;
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800336}
337
Chia-I Wub02087d2017-11-09 10:19:54 -0800338void DisplayDevice::flip() const
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800339{
Mathias Agopian076b1cc2009-04-10 14:24:30 -0700340 mPageFlipCount++;
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800341}
342
Dan Stoza71433162014-02-04 16:22:36 -0800343status_t DisplayDevice::beginFrame(bool mustRecompose) const {
344 return mDisplaySurface->beginFrame(mustRecompose);
Jesse Hall028dc8f2013-08-20 16:35:32 -0700345}
346
David Sodmanfb95bcc2017-12-22 15:45:30 -0800347status_t DisplayDevice::prepareFrame(HWComposer& hwc,
348 std::vector<CompositionInfo>& compositionData) {
Lloyd Pique45a165a2018-10-19 11:54:47 -0700349 const auto id = getId();
350 if (id) {
351 status_t error = hwc.prepare(id.value(), compositionData);
Dominik Laskowski075d3172018-05-24 15:50:06 -0700352 if (error != NO_ERROR) {
353 return error;
354 }
Dan Stoza9e56aa02015-11-02 13:00:03 -0800355 }
356
357 DisplaySurface::CompositionType compositionType;
Lloyd Pique45a165a2018-10-19 11:54:47 -0700358 bool hasClient = hwc.hasClientComposition(id);
359 bool hasDevice = hwc.hasDeviceComposition(id);
Dan Stoza9e56aa02015-11-02 13:00:03 -0800360 if (hasClient && hasDevice) {
361 compositionType = DisplaySurface::COMPOSITION_MIXED;
362 } else if (hasClient) {
363 compositionType = DisplaySurface::COMPOSITION_GLES;
364 } else if (hasDevice) {
365 compositionType = DisplaySurface::COMPOSITION_HWC;
366 } else {
367 // Nothing to do -- when turning the screen off we get a frame like
368 // this. Call it a HWC frame since we won't be doing any GLES work but
369 // will do a prepare/set cycle.
370 compositionType = DisplaySurface::COMPOSITION_HWC;
371 }
372 return mDisplaySurface->prepareFrame(compositionType);
373}
Jesse Hall38efe862013-04-06 23:12:29 -0700374
Peiyong Linfb530cf2018-12-15 05:07:38 +0000375void DisplayDevice::setProtected(bool useProtected) {
376 uint64_t usageFlags = GRALLOC_USAGE_HW_RENDER;
377 if (useProtected) {
378 usageFlags |= GRALLOC_USAGE_PROTECTED;
379 }
380 const int status = native_window_set_usage(mNativeWindow.get(), usageFlags);
381 ALOGE_IF(status != NO_ERROR, "Unable to set BQ usage bits for protected content: %d", status);
382}
383
Alec Mouri0a9c7b82018-11-16 13:05:25 -0800384sp<GraphicBuffer> DisplayDevice::dequeueBuffer() {
385 int fd;
386 ANativeWindowBuffer* buffer;
387
388 status_t res = mNativeWindow->dequeueBuffer(mNativeWindow.get(), &buffer, &fd);
389
390 if (res != NO_ERROR) {
391 ALOGE("ANativeWindow::dequeueBuffer failed for display [%s] with error: %d",
392 getDisplayName().c_str(), res);
393 // Return fast here as we can't do much more - any rendering we do
394 // now will just be wrong.
395 return mGraphicBuffer;
396 }
397
398 ALOGW_IF(mGraphicBuffer != nullptr, "Clobbering a non-null pointer to a buffer [%p].",
399 mGraphicBuffer->getNativeBuffer()->handle);
400 mGraphicBuffer = GraphicBuffer::from(buffer);
401
402 // Block until the buffer is ready
403 // TODO(alecmouri): it's perhaps more appropriate to block renderengine so
404 // that the gl driver can block instead.
405 if (fd >= 0) {
406 sync_wait(fd, -1);
407 close(fd);
408 }
409
410 return mGraphicBuffer;
411}
412
413void DisplayDevice::queueBuffer(HWComposer& hwc) {
Lloyd Pique45a165a2018-10-19 11:54:47 -0700414 const auto id = getId();
415 if (hwc.hasClientComposition(id) || hwc.hasFlipClientTargetRequest(id)) {
Alec Mouri0a9c7b82018-11-16 13:05:25 -0800416 // hasFlipClientTargetRequest could return true even if we haven't
417 // dequeued a buffer before. Try dequeueing one if we don't have a
418 // buffer ready.
419 if (mGraphicBuffer == nullptr) {
420 ALOGI("Attempting to queue a client composited buffer without one "
421 "previously dequeued for display [%s]. Attempting to dequeue "
422 "a scratch buffer now",
423 mDisplayName.c_str());
424 // We shouldn't deadlock here, since mGraphicBuffer == nullptr only
425 // after a successful call to queueBuffer, or if dequeueBuffer has
426 // never been called.
427 dequeueBuffer();
428 }
429
430 if (mGraphicBuffer == nullptr) {
431 ALOGE("No buffer is ready for display [%s]", mDisplayName.c_str());
432 } else {
Alec Mouri0a9c7b82018-11-16 13:05:25 -0800433 status_t res = mNativeWindow->queueBuffer(mNativeWindow.get(),
Alec Mouri745163a2018-12-04 15:15:50 -0800434 mGraphicBuffer->getNativeBuffer(),
435 dup(mBufferReady));
Alec Mouri0a9c7b82018-11-16 13:05:25 -0800436 if (res != NO_ERROR) {
437 ALOGE("Error when queueing buffer for display [%s]: %d", mDisplayName.c_str(), res);
438 // We risk blocking on dequeueBuffer if the primary display failed
439 // to queue up its buffer, so crash here.
440 if (isPrimary()) {
441 LOG_ALWAYS_FATAL("ANativeWindow::queueBuffer failed with error: %d", res);
442 } else {
443 mNativeWindow->cancelBuffer(mNativeWindow.get(),
Alec Mouri745163a2018-12-04 15:15:50 -0800444 mGraphicBuffer->getNativeBuffer(),
445 dup(mBufferReady));
Alec Mouri0a9c7b82018-11-16 13:05:25 -0800446 }
447 }
Alec Mouri745163a2018-12-04 15:15:50 -0800448
449 mBufferReady.reset();
Alec Mouri0a9c7b82018-11-16 13:05:25 -0800450 mGraphicBuffer = nullptr;
451 }
Mathias Agopianda27af92012-09-13 18:17:13 -0700452 }
Mathias Agopian52e21482012-09-24 18:07:21 -0700453
Jesse Hall99c7dbb2013-03-14 14:29:29 -0700454 status_t result = mDisplaySurface->advanceFrame();
455 if (result != NO_ERROR) {
Dominik Laskowskibf170d92018-04-19 15:08:05 -0700456 ALOGE("[%s] failed pushing new frame to HWC: %d", mDisplayName.c_str(), result);
Mathias Agopian32341382012-09-25 19:16:28 -0700457 }
Mathias Agopianda27af92012-09-13 18:17:13 -0700458}
459
Alec Mouri0a9c7b82018-11-16 13:05:25 -0800460void DisplayDevice::onPresentDisplayCompleted() {
Dan Stoza9e56aa02015-11-02 13:00:03 -0800461 mDisplaySurface->onFrameCommitted();
462}
Mathias Agopianda27af92012-09-13 18:17:13 -0700463
Mathias Agopian875d8e12013-06-07 15:35:48 -0700464void DisplayDevice::setViewportAndProjection() const {
465 size_t w = mDisplayWidth;
466 size_t h = mDisplayHeight;
Dan Stozac1879002014-05-22 15:59:05 -0700467 Rect sourceCrop(0, 0, w, h);
Chia-I Wu1be50b52018-08-29 10:44:48 -0700468 mFlinger->getRenderEngine().setViewportAndProjection(w, h, sourceCrop, ui::Transform::ROT_0);
Mathias Agopianbae92d02012-09-28 01:00:47 -0700469}
470
Alec Mouri0a9c7b82018-11-16 13:05:25 -0800471void DisplayDevice::finishBuffer() {
472 mBufferReady = mFlinger->getRenderEngine().flush();
473 if (mBufferReady.get() < 0) {
474 mFlinger->getRenderEngine().finish();
475 }
476}
477
Dan Stoza9e56aa02015-11-02 13:00:03 -0800478const sp<Fence>& DisplayDevice::getClientTargetAcquireFence() const {
479 return mDisplaySurface->getClientTargetAcquireFence();
480}
Dan Stoza9e56aa02015-11-02 13:00:03 -0800481
Mathias Agopian1b031492012-06-20 17:51:20 -0700482// ----------------------------------------------------------------------------
483
Mathias Agopian13127d82013-03-05 17:47:11 -0800484void DisplayDevice::setVisibleLayersSortedByZ(const Vector< sp<Layer> >& layers) {
Mathias Agopian3b1d2b62012-07-11 13:48:17 -0700485 mVisibleLayersSortedByZ = layers;
Mathias Agopian3b1d2b62012-07-11 13:48:17 -0700486}
487
Mathias Agopian13127d82013-03-05 17:47:11 -0800488const Vector< sp<Layer> >& DisplayDevice::getVisibleLayersSortedByZ() const {
Mathias Agopian3b1d2b62012-07-11 13:48:17 -0700489 return mVisibleLayersSortedByZ;
490}
491
Chia-I Wu83806892017-11-16 10:50:20 -0800492void DisplayDevice::setLayersNeedingFences(const Vector< sp<Layer> >& layers) {
493 mLayersNeedingFences = layers;
494}
495
496const Vector< sp<Layer> >& DisplayDevice::getLayersNeedingFences() const {
497 return mLayersNeedingFences;
498}
499
Mathias Agopiancd60f992012-08-16 16:28:27 -0700500Region DisplayDevice::getDirtyRegion(bool repaintEverything) const {
501 Region dirty;
Mathias Agopiancd60f992012-08-16 16:28:27 -0700502 if (repaintEverything) {
503 dirty.set(getBounds());
504 } else {
Peiyong Linefefaac2018-08-17 12:27:51 -0700505 const ui::Transform& planeTransform(mGlobalTransform);
Mathias Agopiancd60f992012-08-16 16:28:27 -0700506 dirty = planeTransform.transform(this->dirtyRegion);
507 dirty.andSelf(getBounds());
508 }
509 return dirty;
510}
511
Mathias Agopian3b1d2b62012-07-11 13:48:17 -0700512// ----------------------------------------------------------------------------
Prashant Malani2c9b11f2014-05-25 01:36:31 -0700513void DisplayDevice::setPowerMode(int mode) {
514 mPowerMode = mode;
Mathias Agopiand3ee2312012-08-02 14:01:42 -0700515}
516
Prashant Malani2c9b11f2014-05-25 01:36:31 -0700517int DisplayDevice::getPowerMode() const {
518 return mPowerMode;
Mathias Agopiand3ee2312012-08-02 14:01:42 -0700519}
520
Dominik Laskowskieecd6592018-05-29 10:25:41 -0700521bool DisplayDevice::isPoweredOn() const {
522 return mPowerMode != HWC_POWER_MODE_OFF;
Mathias Agopiand3ee2312012-08-02 14:01:42 -0700523}
524
525// ----------------------------------------------------------------------------
Michael Lentine6c9e34a2014-07-14 13:48:55 -0700526void DisplayDevice::setActiveConfig(int mode) {
527 mActiveConfig = mode;
528}
529
530int DisplayDevice::getActiveConfig() const {
531 return mActiveConfig;
532}
533
534// ----------------------------------------------------------------------------
Peiyong Lina52f0292018-03-14 17:26:31 -0700535void DisplayDevice::setActiveColorMode(ColorMode mode) {
Michael Wright28f24d02016-07-12 13:30:53 -0700536 mActiveColorMode = mode;
537}
538
Peiyong Lina52f0292018-03-14 17:26:31 -0700539ColorMode DisplayDevice::getActiveColorMode() const {
Michael Wright28f24d02016-07-12 13:30:53 -0700540 return mActiveColorMode;
541}
Courtney Goeltzenleuchter79d27242017-07-13 17:54:01 -0600542
Peiyong Lindd9b2ae2018-03-01 16:22:45 -0800543RenderIntent DisplayDevice::getActiveRenderIntent() const {
544 return mActiveRenderIntent;
545}
546
547void DisplayDevice::setActiveRenderIntent(RenderIntent renderIntent) {
548 mActiveRenderIntent = renderIntent;
549}
550
Yiwei Zhang7c64f172018-03-07 14:52:28 -0800551void DisplayDevice::setColorTransform(const mat4& transform) {
552 const bool isIdentity = (transform == mat4());
553 mColorTransform =
554 isIdentity ? HAL_COLOR_TRANSFORM_IDENTITY : HAL_COLOR_TRANSFORM_ARBITRARY_MATRIX;
555}
556
557android_color_transform_t DisplayDevice::getColorTransform() const {
558 return mColorTransform;
559}
560
Peiyong Lin34beb7a2018-03-28 11:57:12 -0700561void DisplayDevice::setCompositionDataSpace(ui::Dataspace dataspace) {
Peiyong Lindd9b2ae2018-03-01 16:22:45 -0800562 mCompositionDataSpace = dataspace;
Courtney Goeltzenleuchter79d27242017-07-13 17:54:01 -0600563 ANativeWindow* const window = mNativeWindow.get();
Peiyong Lin34beb7a2018-03-28 11:57:12 -0700564 native_window_set_buffers_data_space(window, static_cast<android_dataspace>(dataspace));
Courtney Goeltzenleuchter79d27242017-07-13 17:54:01 -0600565}
Michael Wright28f24d02016-07-12 13:30:53 -0700566
Peiyong Lindd9b2ae2018-03-01 16:22:45 -0800567ui::Dataspace DisplayDevice::getCompositionDataSpace() const {
568 return mCompositionDataSpace;
569}
570
Michael Wright28f24d02016-07-12 13:30:53 -0700571// ----------------------------------------------------------------------------
Mathias Agopiand3ee2312012-08-02 14:01:42 -0700572
Mathias Agopian28947d72012-08-08 18:51:15 -0700573void DisplayDevice::setLayerStack(uint32_t stack) {
574 mLayerStack = stack;
575 dirtyRegion.set(bounds());
576}
577
578// ----------------------------------------------------------------------------
579
Mathias Agopianc1c05de2013-09-17 23:45:22 -0700580uint32_t DisplayDevice::getOrientationTransform() const {
581 uint32_t transform = 0;
582 switch (mOrientation) {
583 case DisplayState::eOrientationDefault:
Peiyong Linefefaac2018-08-17 12:27:51 -0700584 transform = ui::Transform::ROT_0;
Mathias Agopianc1c05de2013-09-17 23:45:22 -0700585 break;
586 case DisplayState::eOrientation90:
Peiyong Linefefaac2018-08-17 12:27:51 -0700587 transform = ui::Transform::ROT_90;
Mathias Agopianc1c05de2013-09-17 23:45:22 -0700588 break;
589 case DisplayState::eOrientation180:
Peiyong Linefefaac2018-08-17 12:27:51 -0700590 transform = ui::Transform::ROT_180;
Mathias Agopianc1c05de2013-09-17 23:45:22 -0700591 break;
592 case DisplayState::eOrientation270:
Peiyong Linefefaac2018-08-17 12:27:51 -0700593 transform = ui::Transform::ROT_270;
Mathias Agopianc1c05de2013-09-17 23:45:22 -0700594 break;
595 }
596 return transform;
597}
598
Mathias Agopian0f2f5ff2012-07-31 23:09:07 -0700599status_t DisplayDevice::orientationToTransfrom(
Peiyong Linefefaac2018-08-17 12:27:51 -0700600 int orientation, int w, int h, ui::Transform* tr)
Mathias Agopian1b031492012-06-20 17:51:20 -0700601{
602 uint32_t flags = 0;
603 switch (orientation) {
Mathias Agopian3165cc22012-08-08 19:42:09 -0700604 case DisplayState::eOrientationDefault:
Peiyong Linefefaac2018-08-17 12:27:51 -0700605 flags = ui::Transform::ROT_0;
Mathias Agopian1b031492012-06-20 17:51:20 -0700606 break;
Mathias Agopian3165cc22012-08-08 19:42:09 -0700607 case DisplayState::eOrientation90:
Peiyong Linefefaac2018-08-17 12:27:51 -0700608 flags = ui::Transform::ROT_90;
Mathias Agopian1b031492012-06-20 17:51:20 -0700609 break;
Mathias Agopian3165cc22012-08-08 19:42:09 -0700610 case DisplayState::eOrientation180:
Peiyong Linefefaac2018-08-17 12:27:51 -0700611 flags = ui::Transform::ROT_180;
Mathias Agopian1b031492012-06-20 17:51:20 -0700612 break;
Mathias Agopian3165cc22012-08-08 19:42:09 -0700613 case DisplayState::eOrientation270:
Peiyong Linefefaac2018-08-17 12:27:51 -0700614 flags = ui::Transform::ROT_270;
Mathias Agopian1b031492012-06-20 17:51:20 -0700615 break;
616 default:
617 return BAD_VALUE;
618 }
619 tr->set(flags, w, h);
620 return NO_ERROR;
621}
622
Michael Lentine47e45402014-07-18 15:34:25 -0700623void DisplayDevice::setDisplaySize(const int newWidth, const int newHeight) {
624 dirtyRegion.set(getBounds());
625
626 mDisplaySurface->resizeBuffers(newWidth, newHeight);
627
Alec Mouriba013fa2018-10-16 12:43:11 -0700628 mDisplayWidth = newWidth;
629 mDisplayHeight = newHeight;
Michael Lentine47e45402014-07-18 15:34:25 -0700630}
631
Mathias Agopian00e8c7a2012-09-04 19:30:46 -0700632void DisplayDevice::setProjection(int orientation,
Mathias Agopianf5f714a2013-02-26 16:54:05 -0800633 const Rect& newViewport, const Rect& newFrame) {
634 Rect viewport(newViewport);
635 Rect frame(newFrame);
636
637 const int w = mDisplayWidth;
638 const int h = mDisplayHeight;
639
Peiyong Linefefaac2018-08-17 12:27:51 -0700640 ui::Transform R;
Mathias Agopianf5f714a2013-02-26 16:54:05 -0800641 DisplayDevice::orientationToTransfrom(orientation, w, h, &R);
642
643 if (!frame.isValid()) {
644 // the destination frame can be invalid if it has never been set,
645 // in that case we assume the whole display frame.
646 frame = Rect(w, h);
647 }
648
649 if (viewport.isEmpty()) {
650 // viewport can be invalid if it has never been set, in that case
651 // we assume the whole display size.
652 // it's also invalid to have an empty viewport, so we handle that
653 // case in the same way.
654 viewport = Rect(w, h);
Peiyong Linefefaac2018-08-17 12:27:51 -0700655 if (R.getOrientation() & ui::Transform::ROT_90) {
Mathias Agopianf5f714a2013-02-26 16:54:05 -0800656 // viewport is always specified in the logical orientation
657 // of the display (ie: post-rotation).
Peiyong Lin3db42342018-08-16 09:15:59 -0700658 std::swap(viewport.right, viewport.bottom);
Mathias Agopianf5f714a2013-02-26 16:54:05 -0800659 }
660 }
661
662 dirtyRegion.set(getBounds());
663
Peiyong Linefefaac2018-08-17 12:27:51 -0700664 ui::Transform TL, TP, S;
Mathias Agopianf5f714a2013-02-26 16:54:05 -0800665 float src_width = viewport.width();
666 float src_height = viewport.height();
667 float dst_width = frame.width();
668 float dst_height = frame.height();
669 if (src_width != dst_width || src_height != dst_height) {
670 float sx = dst_width / src_width;
671 float sy = dst_height / src_height;
672 S.set(sx, 0, 0, sy);
673 }
674
675 float src_x = viewport.left;
676 float src_y = viewport.top;
677 float dst_x = frame.left;
678 float dst_y = frame.top;
679 TL.set(-src_x, -src_y);
680 TP.set(dst_x, dst_y);
681
Iris Chang7501ed62018-04-30 14:45:42 +0800682 // need to take care of primary display rotation for mGlobalTransform
683 // for case if the panel is not installed aligned with device orientation
Dominik Laskowski075d3172018-05-24 15:50:06 -0700684 if (isPrimary()) {
Iris Chang7501ed62018-04-30 14:45:42 +0800685 DisplayDevice::orientationToTransfrom(
Chia-I Wua02871c2018-08-27 14:38:23 -0700686 (orientation + mDisplayInstallOrientation) % (DisplayState::eOrientation270 + 1),
Iris Chang7501ed62018-04-30 14:45:42 +0800687 w, h, &R);
688 }
689
Mathias Agopianf5f714a2013-02-26 16:54:05 -0800690 // The viewport and frame are both in the logical orientation.
691 // Apply the logical translation, scale to physical size, apply the
692 // physical translation and finally rotate to the physical orientation.
693 mGlobalTransform = R * TP * S * TL;
694
695 const uint8_t type = mGlobalTransform.getType();
696 mNeedsFiltering = (!mGlobalTransform.preserveRects() ||
Peiyong Linefefaac2018-08-17 12:27:51 -0700697 (type >= ui::Transform::SCALE));
Mathias Agopianf5f714a2013-02-26 16:54:05 -0800698
699 mScissor = mGlobalTransform.transform(viewport);
700 if (mScissor.isEmpty()) {
Mathias Agopian6c7f25a2013-05-09 20:37:10 -0700701 mScissor = getBounds();
Mathias Agopianf5f714a2013-02-26 16:54:05 -0800702 }
703
Mathias Agopianda8d0a52012-09-04 15:05:38 -0700704 mOrientation = orientation;
Dominik Laskowski281644e2018-04-19 15:47:35 -0700705 if (isPrimary()) {
Pablo Ceballos021623b2016-04-15 17:31:51 -0700706 uint32_t transform = 0;
707 switch (mOrientation) {
708 case DisplayState::eOrientationDefault:
Peiyong Linefefaac2018-08-17 12:27:51 -0700709 transform = ui::Transform::ROT_0;
Pablo Ceballos021623b2016-04-15 17:31:51 -0700710 break;
711 case DisplayState::eOrientation90:
Peiyong Linefefaac2018-08-17 12:27:51 -0700712 transform = ui::Transform::ROT_90;
Pablo Ceballos021623b2016-04-15 17:31:51 -0700713 break;
714 case DisplayState::eOrientation180:
Peiyong Linefefaac2018-08-17 12:27:51 -0700715 transform = ui::Transform::ROT_180;
Pablo Ceballos021623b2016-04-15 17:31:51 -0700716 break;
717 case DisplayState::eOrientation270:
Peiyong Linefefaac2018-08-17 12:27:51 -0700718 transform = ui::Transform::ROT_270;
Pablo Ceballos021623b2016-04-15 17:31:51 -0700719 break;
720 }
721 sPrimaryDisplayOrientation = transform;
722 }
Mathias Agopian00e8c7a2012-09-04 19:30:46 -0700723 mViewport = viewport;
724 mFrame = frame;
Mathias Agopian1b031492012-06-20 17:51:20 -0700725}
Mathias Agopian1d12d8a2012-09-18 01:38:00 -0700726
Pablo Ceballos021623b2016-04-15 17:31:51 -0700727uint32_t DisplayDevice::getPrimaryDisplayOrientationTransform() {
728 return sPrimaryDisplayOrientation;
729}
730
Dominik Laskowski9b17b2c22018-11-01 14:49:03 -0700731std::string DisplayDevice::getDebugName() const {
Lloyd Pique45a165a2018-10-19 11:54:47 -0700732 const auto id = getId() ? to_string(*getId()) + ", " : std::string();
Dominik Laskowski9b17b2c22018-11-01 14:49:03 -0700733 return base::StringPrintf("DisplayDevice{%s%s%s\"%s\"}", id.c_str(),
734 isPrimary() ? "primary, " : "", isVirtual() ? "virtual, " : "",
735 mDisplayName.c_str());
736}
737
Yiwei Zhang5434a782018-12-05 18:06:32 -0800738void DisplayDevice::dump(std::string& result) const {
Peiyong Linefefaac2018-08-17 12:27:51 -0700739 const ui::Transform& tr(mGlobalTransform);
Courtney Goeltzenleuchter152279d2017-08-14 18:18:30 -0600740 ANativeWindow* const window = mNativeWindow.get();
Yiwei Zhang5434a782018-12-05 18:06:32 -0800741 StringAppendF(&result, "+ %s\n", getDebugName().c_str());
742 StringAppendF(&result,
743 " layerStack=%u, (%4dx%4d), ANativeWindow=%p "
744 "format=%d, orient=%2d (type=%08x), flips=%u, isSecure=%d, "
745 "powerMode=%d, activeConfig=%d, numLayers=%zu\n",
746 mLayerStack, mDisplayWidth, mDisplayHeight, window,
747 ANativeWindow_getFormat(window), mOrientation, tr.getType(), getPageFlipCount(),
Lloyd Pique45a165a2018-10-19 11:54:47 -0700748 isSecure(), mPowerMode, mActiveConfig, mVisibleLayersSortedByZ.size());
Yiwei Zhang5434a782018-12-05 18:06:32 -0800749 StringAppendF(&result,
750 " v:[%d,%d,%d,%d], f:[%d,%d,%d,%d], s:[%d,%d,%d,%d],"
751 "transform:[[%0.3f,%0.3f,%0.3f][%0.3f,%0.3f,%0.3f][%0.3f,%0.3f,%0.3f]]\n",
752 mViewport.left, mViewport.top, mViewport.right, mViewport.bottom, mFrame.left,
753 mFrame.top, mFrame.right, mFrame.bottom, mScissor.left, mScissor.top,
754 mScissor.right, mScissor.bottom, tr[0][0], tr[1][0], tr[2][0], tr[0][1], tr[1][1],
755 tr[2][1], tr[0][2], tr[1][2], tr[2][2]);
Courtney Goeltzenleuchter152279d2017-08-14 18:18:30 -0600756 auto const surface = static_cast<Surface*>(window);
Peiyong Lin34beb7a2018-03-28 11:57:12 -0700757 ui::Dataspace dataspace = surface->getBuffersDataSpace();
Valerie Haue9e843a2018-12-18 13:39:23 -0800758 StringAppendF(&result,
759 " wideColorGamut=%d, hdr10plus =%d, hdr10=%d, colorMode=%s, dataspace: %s "
760 "(%d)\n",
761 mHasWideColorGamut, mHasHdr10Plus, mHasHdr10,
762 decodeColorMode(mActiveColorMode).c_str(),
Yiwei Zhang5434a782018-12-05 18:06:32 -0800763 dataspaceDetails(static_cast<android_dataspace>(dataspace)).c_str(), dataspace);
Mathias Agopian1d12d8a2012-09-18 01:38:00 -0700764
Jesse Hall99c7dbb2013-03-14 14:29:29 -0700765 String8 surfaceDump;
Dan Stozaf10c46e2014-11-11 10:32:31 -0800766 mDisplaySurface->dumpAsString(surfaceDump);
Yiwei Zhang5434a782018-12-05 18:06:32 -0800767 result.append(surfaceDump.string(), surfaceDump.size());
Mathias Agopian1d12d8a2012-09-18 01:38:00 -0700768}
Irvelffc9efc2016-07-27 15:16:37 -0700769
Chia-I Wube02ec02018-05-18 10:59:36 -0700770// Map dataspace/intent to the best matched dataspace/colorMode/renderIntent
771// supported by HWC.
772void DisplayDevice::addColorMode(
773 const std::unordered_map<ColorMode, std::vector<RenderIntent>>& hwcColorModes,
774 const ColorMode mode, const RenderIntent intent) {
775 // find the best color mode
776 const ColorMode hwcColorMode = getHwcColorMode(hwcColorModes, mode);
777
778 // find the best render intent
779 auto iter = hwcColorModes.find(hwcColorMode);
780 const auto& hwcIntents =
781 iter != hwcColorModes.end() ? iter->second : std::vector<RenderIntent>();
782 const RenderIntent hwcIntent = getHwcRenderIntent(hwcIntents, intent);
783
784 const Dataspace dataspace = colorModeToDataspace(mode);
785 const Dataspace hwcDataspace = colorModeToDataspace(hwcColorMode);
786
Dominik Laskowski9b17b2c22018-11-01 14:49:03 -0700787 ALOGV("%s: map (%s, %s) to (%s, %s, %s)", getDebugName().c_str(),
Chia-I Wube02ec02018-05-18 10:59:36 -0700788 dataspaceDetails(static_cast<android_dataspace_t>(dataspace)).c_str(),
789 decodeRenderIntent(intent).c_str(),
790 dataspaceDetails(static_cast<android_dataspace_t>(hwcDataspace)).c_str(),
791 decodeColorMode(hwcColorMode).c_str(), decodeRenderIntent(hwcIntent).c_str());
792
793 mColorModes[getColorModeKey(dataspace, intent)] = {hwcDataspace, hwcColorMode, hwcIntent};
794}
795
796void DisplayDevice::populateColorModes(
797 const std::unordered_map<ColorMode, std::vector<RenderIntent>>& hwcColorModes) {
798 if (!hasWideColorGamut()) {
799 return;
800 }
801
Chia-I Wu0d711262018-05-21 15:19:35 -0700802 // collect all known SDR render intents
803 std::unordered_set<RenderIntent> sdrRenderIntents(sSdrRenderIntents.begin(),
804 sSdrRenderIntents.end());
805 auto iter = hwcColorModes.find(ColorMode::SRGB);
806 if (iter != hwcColorModes.end()) {
807 for (auto intent : iter->second) {
808 sdrRenderIntents.insert(intent);
809 }
810 }
811
Chia-I Wuc4b08bd2018-05-29 12:57:23 -0700812 // add all known SDR combinations
Chia-I Wu0d711262018-05-21 15:19:35 -0700813 for (auto intent : sdrRenderIntents) {
Chia-I Wube02ec02018-05-18 10:59:36 -0700814 for (auto mode : sSdrColorModes) {
815 addColorMode(hwcColorModes, mode, intent);
Peiyong Lin136fbbc2018-04-17 15:09:44 -0700816 }
817 }
Chia-I Wube02ec02018-05-18 10:59:36 -0700818
Chia-I Wuc4b08bd2018-05-29 12:57:23 -0700819 // collect all known HDR render intents
820 std::unordered_set<RenderIntent> hdrRenderIntents(sHdrRenderIntents.begin(),
821 sHdrRenderIntents.end());
822 iter = hwcColorModes.find(ColorMode::BT2100_PQ);
823 if (iter != hwcColorModes.end()) {
824 for (auto intent : iter->second) {
825 hdrRenderIntents.insert(intent);
826 }
827 }
828
829 // add all known HDR combinations
Chia-I Wube02ec02018-05-18 10:59:36 -0700830 for (auto intent : sHdrRenderIntents) {
831 for (auto mode : sHdrColorModes) {
832 addColorMode(hwcColorModes, mode, intent);
833 }
834 }
835}
836
837bool DisplayDevice::hasRenderIntent(RenderIntent intent) const {
838 // assume a render intent is supported when SRGB supports it; we should
839 // get rid of that assumption.
Peiyong Lin14724e62018-12-05 07:27:30 -0800840 auto iter = mColorModes.find(getColorModeKey(Dataspace::V0_SRGB, intent));
Chia-I Wube02ec02018-05-18 10:59:36 -0700841 return iter != mColorModes.end() && iter->second.renderIntent == intent;
842}
843
Peiyong Lindfde5112018-06-05 10:58:41 -0700844bool DisplayDevice::hasLegacyHdrSupport(Dataspace dataspace) const {
Chia-I Wube02ec02018-05-18 10:59:36 -0700845 if ((dataspace == Dataspace::BT2020_PQ && hasHDR10Support()) ||
846 (dataspace == Dataspace::BT2020_HLG && hasHLGSupport())) {
847 auto iter =
848 mColorModes.find(getColorModeKey(dataspace, RenderIntent::TONE_MAP_COLORIMETRIC));
Peiyong Lindfde5112018-06-05 10:58:41 -0700849 return iter == mColorModes.end() || iter->second.dataspace != dataspace;
Chia-I Wube02ec02018-05-18 10:59:36 -0700850 }
851
852 return false;
853}
854
855void DisplayDevice::getBestColorMode(Dataspace dataspace, RenderIntent intent,
856 Dataspace* outDataspace, ColorMode* outMode,
857 RenderIntent* outIntent) const {
858 auto iter = mColorModes.find(getColorModeKey(dataspace, intent));
859 if (iter != mColorModes.end()) {
860 *outDataspace = iter->second.dataspace;
861 *outMode = iter->second.colorMode;
862 *outIntent = iter->second.renderIntent;
863 } else {
Chia-I Wu6333af52018-10-16 13:46:36 -0700864 // this is unexpected on a WCG display
865 if (hasWideColorGamut()) {
866 ALOGE("map unknown (%s)/(%s) to default color mode",
867 dataspaceDetails(static_cast<android_dataspace_t>(dataspace)).c_str(),
868 decodeRenderIntent(intent).c_str());
869 }
Chia-I Wube02ec02018-05-18 10:59:36 -0700870
871 *outDataspace = Dataspace::UNKNOWN;
872 *outMode = ColorMode::NATIVE;
873 *outIntent = RenderIntent::COLORIMETRIC;
874 }
Peiyong Lin136fbbc2018-04-17 15:09:44 -0700875}
876
Lloyd Pique45a165a2018-10-19 11:54:47 -0700877// ----------------------------------------------------------------------------
878
879const std::optional<DisplayId>& DisplayDevice::getId() const {
880 return mCompositionDisplay->getId();
881}
882
883bool DisplayDevice::isSecure() const {
884 return mCompositionDisplay->isSecure();
885}
886
Dominik Laskowski663bd282018-04-19 15:26:54 -0700887std::atomic<int32_t> DisplayDeviceState::sNextSequenceId(1);
Peiyong Linfd997e02018-03-28 15:29:00 -0700888
889} // namespace android