blob: e7b7fbe1916c81bece0618101c628f4bffb56dfe [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>
33#include <configstore/Utils.h>
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -080034#include <cutils/properties.h>
Peiyong Lincbc184f2018-08-22 13:24:10 -070035#include <gui/Surface.h>
36#include <hardware/gralloc.h>
37#include <renderengine/RenderEngine.h>
Alec Mouri0a9c7b82018-11-16 13:05:25 -080038#include <sync/sync.h>
39#include <system/window.h>
Courtney Goeltzenleuchter152279d2017-08-14 18:18:30 -060040#include <ui/DebugUtils.h>
Mathias Agopianc666cae2012-07-25 18:56:13 -070041#include <ui/DisplayInfo.h>
Mathias Agopian076b1cc2009-04-10 14:24:30 -070042#include <ui/PixelFormat.h>
Peiyong Lincbc184f2018-08-22 13:24:10 -070043#include <utils/Log.h>
Valerie Hau9758ae02018-10-09 16:05:09 -070044#include <utils/RefBase.h>
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -080045
Jesse Hall99c7dbb2013-03-14 14:29:29 -070046#include "DisplayHardware/DisplaySurface.h"
Mathias Agopian1b031492012-06-20 17:51:20 -070047#include "DisplayHardware/HWComposer.h"
Dan Stoza9e56aa02015-11-02 13:00:03 -080048#include "DisplayHardware/HWC2.h"
Mathias Agopianc7d14e22011-08-01 16:32:21 -070049#include "SurfaceFlinger.h"
Mathias Agopian13127d82013-03-05 17:47:11 -080050#include "Layer.h"
Mathias Agopian1f7bec62010-06-25 18:02:21 -070051
Peiyong Linfd997e02018-03-28 15:29:00 -070052namespace android {
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -080053
Jaesoo Lee720a7242017-01-31 15:26:18 +090054// retrieve triple buffer setting from configstore
55using namespace android::hardware::configstore;
56using namespace android::hardware::configstore::V1_0;
Yiwei Zhang5434a782018-12-05 18:06:32 -080057using android::base::StringAppendF;
Peiyong Linfd997e02018-03-28 15:29:00 -070058using android::ui::ColorMode;
Chia-I Wube02ec02018-05-18 10:59:36 -070059using android::ui::Dataspace;
Peiyong Lin62665892018-04-16 11:07:44 -070060using android::ui::Hdr;
Peiyong Lindd9b2ae2018-03-01 16:22:45 -080061using android::ui::RenderIntent;
Jaesoo Lee720a7242017-01-31 15:26:18 +090062
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -080063/*
64 * Initialize the display to the specified values.
65 *
66 */
67
Pablo Ceballos021623b2016-04-15 17:31:51 -070068uint32_t DisplayDevice::sPrimaryDisplayOrientation = 0;
69
Chia-I Wube02ec02018-05-18 10:59:36 -070070namespace {
71
72// ordered list of known SDR color modes
Valerie Hau9758ae02018-10-09 16:05:09 -070073const std::array<ColorMode, 3> sSdrColorModes = {
74 ColorMode::DISPLAY_BT2020,
Chia-I Wube02ec02018-05-18 10:59:36 -070075 ColorMode::DISPLAY_P3,
76 ColorMode::SRGB,
77};
78
79// ordered list of known HDR color modes
80const std::array<ColorMode, 2> sHdrColorModes = {
81 ColorMode::BT2100_PQ,
82 ColorMode::BT2100_HLG,
83};
84
85// ordered list of known SDR render intents
86const std::array<RenderIntent, 2> sSdrRenderIntents = {
87 RenderIntent::ENHANCE,
88 RenderIntent::COLORIMETRIC,
89};
90
91// ordered list of known HDR render intents
92const std::array<RenderIntent, 2> sHdrRenderIntents = {
93 RenderIntent::TONE_MAP_ENHANCE,
94 RenderIntent::TONE_MAP_COLORIMETRIC,
95};
96
97// map known color mode to dataspace
98Dataspace colorModeToDataspace(ColorMode mode) {
99 switch (mode) {
100 case ColorMode::SRGB:
Peiyong Lin14724e62018-12-05 07:27:30 -0800101 return Dataspace::V0_SRGB;
Chia-I Wube02ec02018-05-18 10:59:36 -0700102 case ColorMode::DISPLAY_P3:
103 return Dataspace::DISPLAY_P3;
Valerie Hau9758ae02018-10-09 16:05:09 -0700104 case ColorMode::DISPLAY_BT2020:
105 return Dataspace::DISPLAY_BT2020;
Chia-I Wube02ec02018-05-18 10:59:36 -0700106 case ColorMode::BT2100_HLG:
107 return Dataspace::BT2020_HLG;
108 case ColorMode::BT2100_PQ:
109 return Dataspace::BT2020_PQ;
110 default:
111 return Dataspace::UNKNOWN;
112 }
113}
114
115// Return a list of candidate color modes.
116std::vector<ColorMode> getColorModeCandidates(ColorMode mode) {
117 std::vector<ColorMode> candidates;
118
119 // add mode itself
120 candidates.push_back(mode);
121
122 // check if mode is HDR
123 bool isHdr = false;
124 for (auto hdrMode : sHdrColorModes) {
125 if (hdrMode == mode) {
126 isHdr = true;
127 break;
128 }
129 }
130
131 // add other HDR candidates when mode is HDR
132 if (isHdr) {
133 for (auto hdrMode : sHdrColorModes) {
134 if (hdrMode != mode) {
135 candidates.push_back(hdrMode);
136 }
137 }
138 }
139
140 // add other SDR candidates
141 for (auto sdrMode : sSdrColorModes) {
142 if (sdrMode != mode) {
143 candidates.push_back(sdrMode);
144 }
145 }
146
147 return candidates;
148}
149
150// Return a list of candidate render intents.
151std::vector<RenderIntent> getRenderIntentCandidates(RenderIntent intent) {
152 std::vector<RenderIntent> candidates;
153
154 // add intent itself
155 candidates.push_back(intent);
156
157 // check if intent is HDR
158 bool isHdr = false;
159 for (auto hdrIntent : sHdrRenderIntents) {
160 if (hdrIntent == intent) {
161 isHdr = true;
162 break;
163 }
164 }
165
Chia-I Wube02ec02018-05-18 10:59:36 -0700166 if (isHdr) {
Chia-I Wuc4b08bd2018-05-29 12:57:23 -0700167 // add other HDR candidates when intent is HDR
Chia-I Wube02ec02018-05-18 10:59:36 -0700168 for (auto hdrIntent : sHdrRenderIntents) {
169 if (hdrIntent != intent) {
170 candidates.push_back(hdrIntent);
171 }
172 }
Chia-I Wuc4b08bd2018-05-29 12:57:23 -0700173 } else {
174 // add other SDR candidates when intent is SDR
175 for (auto sdrIntent : sSdrRenderIntents) {
176 if (sdrIntent != intent) {
177 candidates.push_back(sdrIntent);
178 }
179 }
Chia-I Wube02ec02018-05-18 10:59:36 -0700180 }
181
182 return candidates;
183}
184
185// Return the best color mode supported by HWC.
186ColorMode getHwcColorMode(
187 const std::unordered_map<ColorMode, std::vector<RenderIntent>>& hwcColorModes,
188 ColorMode mode) {
189 std::vector<ColorMode> candidates = getColorModeCandidates(mode);
190 for (auto candidate : candidates) {
191 auto iter = hwcColorModes.find(candidate);
192 if (iter != hwcColorModes.end()) {
193 return candidate;
194 }
195 }
196
197 return ColorMode::NATIVE;
198}
199
200// Return the best render intent supported by HWC.
201RenderIntent getHwcRenderIntent(const std::vector<RenderIntent>& hwcIntents, RenderIntent intent) {
202 std::vector<RenderIntent> candidates = getRenderIntentCandidates(intent);
203 for (auto candidate : candidates) {
204 for (auto hwcIntent : hwcIntents) {
205 if (candidate == hwcIntent) {
206 return candidate;
207 }
208 }
209 }
210
211 return RenderIntent::COLORIMETRIC;
212}
213
214} // anonymous namespace
215
Lloyd Pique2eef1d22018-09-18 21:30:04 -0700216DisplayDeviceCreationArgs::DisplayDeviceCreationArgs(const sp<SurfaceFlinger>& flinger,
217 const wp<IBinder>& displayToken,
Dominik Laskowski075d3172018-05-24 15:50:06 -0700218 const std::optional<DisplayId>& displayId)
219 : flinger(flinger), displayToken(displayToken), displayId(displayId) {}
Chia-I Wube02ec02018-05-18 10:59:36 -0700220
Lloyd Pique2eef1d22018-09-18 21:30:04 -0700221DisplayDevice::DisplayDevice(DisplayDeviceCreationArgs&& args)
222 : lastCompositionHadVisibleLayers(false),
223 mFlinger(args.flinger),
Lloyd Pique2eef1d22018-09-18 21:30:04 -0700224 mDisplayToken(args.displayToken),
Dominik Laskowskie9774092018-12-11 10:04:24 -0800225 mSequenceId(args.sequenceId),
Dominik Laskowski075d3172018-05-24 15:50:06 -0700226 mId(args.displayId),
Lloyd Pique2eef1d22018-09-18 21:30:04 -0700227 mNativeWindow(args.nativeWindow),
Alec Mouri0a9c7b82018-11-16 13:05:25 -0800228 mGraphicBuffer(nullptr),
Lloyd Pique2eef1d22018-09-18 21:30:04 -0700229 mDisplaySurface(args.displaySurface),
Lloyd Pique2eef1d22018-09-18 21:30:04 -0700230 mDisplayInstallOrientation(args.displayInstallOrientation),
231 mPageFlipCount(0),
Dominik Laskowski075d3172018-05-24 15:50:06 -0700232 mIsVirtual(args.isVirtual),
Lloyd Pique2eef1d22018-09-18 21:30:04 -0700233 mIsSecure(args.isSecure),
234 mLayerStack(NO_LAYER_STACK),
235 mOrientation(),
236 mViewport(Rect::INVALID_RECT),
237 mFrame(Rect::INVALID_RECT),
238 mPowerMode(args.initialPowerMode),
239 mActiveConfig(0),
240 mColorTransform(HAL_COLOR_TRANSFORM_IDENTITY),
241 mHasWideColorGamut(args.hasWideColorGamut),
Valerie Haue9e843a2018-12-18 13:39:23 -0800242 mHasHdr10Plus(false),
Lloyd Pique2eef1d22018-09-18 21:30:04 -0700243 mHasHdr10(false),
244 mHasHLG(false),
245 mHasDolbyVision(false),
Dominik Laskowski075d3172018-05-24 15:50:06 -0700246 mSupportedPerFrameMetadata(args.supportedPerFrameMetadata),
247 mIsPrimary(args.isPrimary) {
Lloyd Pique2eef1d22018-09-18 21:30:04 -0700248 populateColorModes(args.hwcColorModes);
249
250 ALOGE_IF(!mNativeWindow, "No native window was set for display");
251 ALOGE_IF(!mDisplaySurface, "No display surface was set for display");
Lloyd Pique2eef1d22018-09-18 21:30:04 -0700252
253 std::vector<Hdr> types = args.hdrCapabilities.getSupportedHdrTypes();
Peiyong Linfb069302018-04-25 14:34:31 -0700254 for (Hdr hdrType : types) {
Peiyong Lin62665892018-04-16 11:07:44 -0700255 switch (hdrType) {
Valerie Haue9e843a2018-12-18 13:39:23 -0800256 case Hdr::HDR10_PLUS:
257 mHasHdr10Plus = true;
258 break;
Peiyong Lin62665892018-04-16 11:07:44 -0700259 case Hdr::HDR10:
260 mHasHdr10 = true;
261 break;
262 case Hdr::HLG:
263 mHasHLG = true;
264 break;
265 case Hdr::DOLBY_VISION:
266 mHasDolbyVision = true;
267 break;
268 default:
269 ALOGE("UNKNOWN HDR capability: %d", static_cast<int32_t>(hdrType));
270 }
271 }
Jesse Hallffe1f192013-03-22 15:13:48 -0700272
Lloyd Pique2eef1d22018-09-18 21:30:04 -0700273 float minLuminance = args.hdrCapabilities.getDesiredMinLuminance();
274 float maxLuminance = args.hdrCapabilities.getDesiredMaxLuminance();
275 float maxAverageLuminance = args.hdrCapabilities.getDesiredMaxAverageLuminance();
Peiyong Linfb069302018-04-25 14:34:31 -0700276
277 minLuminance = minLuminance <= 0.0 ? sDefaultMinLumiance : minLuminance;
278 maxLuminance = maxLuminance <= 0.0 ? sDefaultMaxLumiance : maxLuminance;
279 maxAverageLuminance = maxAverageLuminance <= 0.0 ? sDefaultMaxLumiance : maxAverageLuminance;
280 if (this->hasWideColorGamut()) {
281 // insert HDR10/HLG as we will force client composition for HDR10/HLG
282 // layers
283 if (!hasHDR10Support()) {
Valerie Haue9e843a2018-12-18 13:39:23 -0800284 types.push_back(Hdr::HDR10);
Peiyong Linfb069302018-04-25 14:34:31 -0700285 }
286
287 if (!hasHLGSupport()) {
Valerie Haue9e843a2018-12-18 13:39:23 -0800288 types.push_back(Hdr::HLG);
Peiyong Linfb069302018-04-25 14:34:31 -0700289 }
290 }
291 mHdrCapabilities = HdrCapabilities(types, maxLuminance, maxAverageLuminance, minLuminance);
292
Alec Mouriba013fa2018-10-16 12:43:11 -0700293 ANativeWindow* const window = mNativeWindow.get();
Alec Mouri0a9c7b82018-11-16 13:05:25 -0800294
Alec Mouri4efb6c22018-11-16 13:07:47 -0800295 int status = native_window_api_connect(window, NATIVE_WINDOW_API_EGL);
Alec Mouri0a9c7b82018-11-16 13:05:25 -0800296 ALOGE_IF(status != NO_ERROR, "Unable to connect BQ producer: %d", status);
Alec Mouri4efb6c22018-11-16 13:07:47 -0800297 status = native_window_set_buffers_format(window, HAL_PIXEL_FORMAT_RGBA_8888);
298 ALOGE_IF(status != NO_ERROR, "Unable to set BQ format to RGBA888: %d", status);
299 status = native_window_set_usage(window, GRALLOC_USAGE_HW_RENDER);
300 ALOGE_IF(status != NO_ERROR, "Unable to set BQ usage bits for GPU rendering: %d", status);
Alec Mouri0a9c7b82018-11-16 13:05:25 -0800301
Alec Mouriba013fa2018-10-16 12:43:11 -0700302 mDisplayWidth = ANativeWindow_getWidth(window);
303 mDisplayHeight = ANativeWindow_getHeight(window);
304
Jesse Hallffe1f192013-03-22 15:13:48 -0700305 // initialize the display orientation transform.
306 setProjection(DisplayState::eOrientationDefault, mViewport, mFrame);
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800307}
308
Lloyd Pique09594832018-01-22 17:48:03 -0800309DisplayDevice::~DisplayDevice() = default;
Mathias Agopian92a979a2012-08-02 18:32:23 -0700310
Jesse Hall02d86562013-03-25 14:43:23 -0700311void DisplayDevice::disconnect(HWComposer& hwc) {
Dominik Laskowski075d3172018-05-24 15:50:06 -0700312 if (mId) {
313 hwc.disconnectDisplay(*mId);
314 mId.reset();
Jesse Hall02d86562013-03-25 14:43:23 -0700315 }
316}
317
Mathias Agopian0f2f5ff2012-07-31 23:09:07 -0700318int DisplayDevice::getWidth() const {
Mathias Agopiana4912602012-07-12 14:25:33 -0700319 return mDisplayWidth;
320}
321
Mathias Agopian0f2f5ff2012-07-31 23:09:07 -0700322int DisplayDevice::getHeight() const {
Mathias Agopiana4912602012-07-12 14:25:33 -0700323 return mDisplayHeight;
324}
325
Dominik Laskowskibf170d92018-04-19 15:08:05 -0700326void DisplayDevice::setDisplayName(const std::string& displayName) {
327 if (!displayName.empty()) {
Mathias Agopian9e2463e2012-09-21 18:26:16 -0700328 // never override the name with an empty name
329 mDisplayName = displayName;
330 }
331}
332
Mathias Agopian0f2f5ff2012-07-31 23:09:07 -0700333uint32_t DisplayDevice::getPageFlipCount() const {
Mathias Agopian076b1cc2009-04-10 14:24:30 -0700334 return mPageFlipCount;
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800335}
336
Chia-I Wub02087d2017-11-09 10:19:54 -0800337void DisplayDevice::flip() const
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800338{
Mathias Agopian076b1cc2009-04-10 14:24:30 -0700339 mPageFlipCount++;
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800340}
341
Dan Stoza71433162014-02-04 16:22:36 -0800342status_t DisplayDevice::beginFrame(bool mustRecompose) const {
343 return mDisplaySurface->beginFrame(mustRecompose);
Jesse Hall028dc8f2013-08-20 16:35:32 -0700344}
345
David Sodmanfb95bcc2017-12-22 15:45:30 -0800346status_t DisplayDevice::prepareFrame(HWComposer& hwc,
347 std::vector<CompositionInfo>& compositionData) {
Dominik Laskowski075d3172018-05-24 15:50:06 -0700348 if (mId) {
349 status_t error = hwc.prepare(*mId, compositionData);
350 if (error != NO_ERROR) {
351 return error;
352 }
Dan Stoza9e56aa02015-11-02 13:00:03 -0800353 }
354
355 DisplaySurface::CompositionType compositionType;
Dominik Laskowski7e045462018-05-30 13:02:02 -0700356 bool hasClient = hwc.hasClientComposition(mId);
357 bool hasDevice = hwc.hasDeviceComposition(mId);
Dan Stoza9e56aa02015-11-02 13:00:03 -0800358 if (hasClient && hasDevice) {
359 compositionType = DisplaySurface::COMPOSITION_MIXED;
360 } else if (hasClient) {
361 compositionType = DisplaySurface::COMPOSITION_GLES;
362 } else if (hasDevice) {
363 compositionType = DisplaySurface::COMPOSITION_HWC;
364 } else {
365 // Nothing to do -- when turning the screen off we get a frame like
366 // this. Call it a HWC frame since we won't be doing any GLES work but
367 // will do a prepare/set cycle.
368 compositionType = DisplaySurface::COMPOSITION_HWC;
369 }
370 return mDisplaySurface->prepareFrame(compositionType);
371}
Jesse Hall38efe862013-04-06 23:12:29 -0700372
Peiyong Linfb530cf2018-12-15 05:07:38 +0000373void DisplayDevice::setProtected(bool useProtected) {
374 uint64_t usageFlags = GRALLOC_USAGE_HW_RENDER;
375 if (useProtected) {
376 usageFlags |= GRALLOC_USAGE_PROTECTED;
377 }
378 const int status = native_window_set_usage(mNativeWindow.get(), usageFlags);
379 ALOGE_IF(status != NO_ERROR, "Unable to set BQ usage bits for protected content: %d", status);
380}
381
Alec Mouri0a9c7b82018-11-16 13:05:25 -0800382sp<GraphicBuffer> DisplayDevice::dequeueBuffer() {
383 int fd;
384 ANativeWindowBuffer* buffer;
385
386 status_t res = mNativeWindow->dequeueBuffer(mNativeWindow.get(), &buffer, &fd);
387
388 if (res != NO_ERROR) {
389 ALOGE("ANativeWindow::dequeueBuffer failed for display [%s] with error: %d",
390 getDisplayName().c_str(), res);
391 // Return fast here as we can't do much more - any rendering we do
392 // now will just be wrong.
393 return mGraphicBuffer;
394 }
395
396 ALOGW_IF(mGraphicBuffer != nullptr, "Clobbering a non-null pointer to a buffer [%p].",
397 mGraphicBuffer->getNativeBuffer()->handle);
398 mGraphicBuffer = GraphicBuffer::from(buffer);
399
400 // Block until the buffer is ready
401 // TODO(alecmouri): it's perhaps more appropriate to block renderengine so
402 // that the gl driver can block instead.
403 if (fd >= 0) {
404 sync_wait(fd, -1);
405 close(fd);
406 }
407
408 return mGraphicBuffer;
409}
410
411void DisplayDevice::queueBuffer(HWComposer& hwc) {
Dominik Laskowski7e045462018-05-30 13:02:02 -0700412 if (hwc.hasClientComposition(mId) || hwc.hasFlipClientTargetRequest(mId)) {
Alec Mouri0a9c7b82018-11-16 13:05:25 -0800413 // hasFlipClientTargetRequest could return true even if we haven't
414 // dequeued a buffer before. Try dequeueing one if we don't have a
415 // buffer ready.
416 if (mGraphicBuffer == nullptr) {
417 ALOGI("Attempting to queue a client composited buffer without one "
418 "previously dequeued for display [%s]. Attempting to dequeue "
419 "a scratch buffer now",
420 mDisplayName.c_str());
421 // We shouldn't deadlock here, since mGraphicBuffer == nullptr only
422 // after a successful call to queueBuffer, or if dequeueBuffer has
423 // never been called.
424 dequeueBuffer();
425 }
426
427 if (mGraphicBuffer == nullptr) {
428 ALOGE("No buffer is ready for display [%s]", mDisplayName.c_str());
429 } else {
Alec Mouri0a9c7b82018-11-16 13:05:25 -0800430 status_t res = mNativeWindow->queueBuffer(mNativeWindow.get(),
Alec Mouri745163a2018-12-04 15:15:50 -0800431 mGraphicBuffer->getNativeBuffer(),
432 dup(mBufferReady));
Alec Mouri0a9c7b82018-11-16 13:05:25 -0800433 if (res != NO_ERROR) {
434 ALOGE("Error when queueing buffer for display [%s]: %d", mDisplayName.c_str(), res);
435 // We risk blocking on dequeueBuffer if the primary display failed
436 // to queue up its buffer, so crash here.
437 if (isPrimary()) {
438 LOG_ALWAYS_FATAL("ANativeWindow::queueBuffer failed with error: %d", res);
439 } else {
440 mNativeWindow->cancelBuffer(mNativeWindow.get(),
Alec Mouri745163a2018-12-04 15:15:50 -0800441 mGraphicBuffer->getNativeBuffer(),
442 dup(mBufferReady));
Alec Mouri0a9c7b82018-11-16 13:05:25 -0800443 }
444 }
Alec Mouri745163a2018-12-04 15:15:50 -0800445
446 mBufferReady.reset();
Alec Mouri0a9c7b82018-11-16 13:05:25 -0800447 mGraphicBuffer = nullptr;
448 }
Mathias Agopianda27af92012-09-13 18:17:13 -0700449 }
Mathias Agopian52e21482012-09-24 18:07:21 -0700450
Jesse Hall99c7dbb2013-03-14 14:29:29 -0700451 status_t result = mDisplaySurface->advanceFrame();
452 if (result != NO_ERROR) {
Dominik Laskowskibf170d92018-04-19 15:08:05 -0700453 ALOGE("[%s] failed pushing new frame to HWC: %d", mDisplayName.c_str(), result);
Mathias Agopian32341382012-09-25 19:16:28 -0700454 }
Mathias Agopianda27af92012-09-13 18:17:13 -0700455}
456
Alec Mouri0a9c7b82018-11-16 13:05:25 -0800457void DisplayDevice::onPresentDisplayCompleted() {
Dan Stoza9e56aa02015-11-02 13:00:03 -0800458 mDisplaySurface->onFrameCommitted();
459}
Mathias Agopianda27af92012-09-13 18:17:13 -0700460
Mathias Agopian875d8e12013-06-07 15:35:48 -0700461void DisplayDevice::setViewportAndProjection() const {
462 size_t w = mDisplayWidth;
463 size_t h = mDisplayHeight;
Dan Stozac1879002014-05-22 15:59:05 -0700464 Rect sourceCrop(0, 0, w, h);
Chia-I Wu1be50b52018-08-29 10:44:48 -0700465 mFlinger->getRenderEngine().setViewportAndProjection(w, h, sourceCrop, ui::Transform::ROT_0);
Mathias Agopianbae92d02012-09-28 01:00:47 -0700466}
467
Alec Mouri0a9c7b82018-11-16 13:05:25 -0800468void DisplayDevice::finishBuffer() {
469 mBufferReady = mFlinger->getRenderEngine().flush();
470 if (mBufferReady.get() < 0) {
471 mFlinger->getRenderEngine().finish();
472 }
473}
474
Dan Stoza9e56aa02015-11-02 13:00:03 -0800475const sp<Fence>& DisplayDevice::getClientTargetAcquireFence() const {
476 return mDisplaySurface->getClientTargetAcquireFence();
477}
Dan Stoza9e56aa02015-11-02 13:00:03 -0800478
Mathias Agopian1b031492012-06-20 17:51:20 -0700479// ----------------------------------------------------------------------------
480
Mathias Agopian13127d82013-03-05 17:47:11 -0800481void DisplayDevice::setVisibleLayersSortedByZ(const Vector< sp<Layer> >& layers) {
Mathias Agopian3b1d2b62012-07-11 13:48:17 -0700482 mVisibleLayersSortedByZ = layers;
Mathias Agopian3b1d2b62012-07-11 13:48:17 -0700483}
484
Mathias Agopian13127d82013-03-05 17:47:11 -0800485const Vector< sp<Layer> >& DisplayDevice::getVisibleLayersSortedByZ() const {
Mathias Agopian3b1d2b62012-07-11 13:48:17 -0700486 return mVisibleLayersSortedByZ;
487}
488
Chia-I Wu83806892017-11-16 10:50:20 -0800489void DisplayDevice::setLayersNeedingFences(const Vector< sp<Layer> >& layers) {
490 mLayersNeedingFences = layers;
491}
492
493const Vector< sp<Layer> >& DisplayDevice::getLayersNeedingFences() const {
494 return mLayersNeedingFences;
495}
496
Mathias Agopiancd60f992012-08-16 16:28:27 -0700497Region DisplayDevice::getDirtyRegion(bool repaintEverything) const {
498 Region dirty;
Mathias Agopiancd60f992012-08-16 16:28:27 -0700499 if (repaintEverything) {
500 dirty.set(getBounds());
501 } else {
Peiyong Linefefaac2018-08-17 12:27:51 -0700502 const ui::Transform& planeTransform(mGlobalTransform);
Mathias Agopiancd60f992012-08-16 16:28:27 -0700503 dirty = planeTransform.transform(this->dirtyRegion);
504 dirty.andSelf(getBounds());
505 }
506 return dirty;
507}
508
Mathias Agopian3b1d2b62012-07-11 13:48:17 -0700509// ----------------------------------------------------------------------------
Prashant Malani2c9b11f2014-05-25 01:36:31 -0700510void DisplayDevice::setPowerMode(int mode) {
511 mPowerMode = mode;
Mathias Agopiand3ee2312012-08-02 14:01:42 -0700512}
513
Prashant Malani2c9b11f2014-05-25 01:36:31 -0700514int DisplayDevice::getPowerMode() const {
515 return mPowerMode;
Mathias Agopiand3ee2312012-08-02 14:01:42 -0700516}
517
Dominik Laskowskieecd6592018-05-29 10:25:41 -0700518bool DisplayDevice::isPoweredOn() const {
519 return mPowerMode != HWC_POWER_MODE_OFF;
Mathias Agopiand3ee2312012-08-02 14:01:42 -0700520}
521
522// ----------------------------------------------------------------------------
Michael Lentine6c9e34a2014-07-14 13:48:55 -0700523void DisplayDevice::setActiveConfig(int mode) {
524 mActiveConfig = mode;
525}
526
527int DisplayDevice::getActiveConfig() const {
528 return mActiveConfig;
529}
530
531// ----------------------------------------------------------------------------
Peiyong Lina52f0292018-03-14 17:26:31 -0700532void DisplayDevice::setActiveColorMode(ColorMode mode) {
Michael Wright28f24d02016-07-12 13:30:53 -0700533 mActiveColorMode = mode;
534}
535
Peiyong Lina52f0292018-03-14 17:26:31 -0700536ColorMode DisplayDevice::getActiveColorMode() const {
Michael Wright28f24d02016-07-12 13:30:53 -0700537 return mActiveColorMode;
538}
Courtney Goeltzenleuchter79d27242017-07-13 17:54:01 -0600539
Peiyong Lindd9b2ae2018-03-01 16:22:45 -0800540RenderIntent DisplayDevice::getActiveRenderIntent() const {
541 return mActiveRenderIntent;
542}
543
544void DisplayDevice::setActiveRenderIntent(RenderIntent renderIntent) {
545 mActiveRenderIntent = renderIntent;
546}
547
Yiwei Zhang7c64f172018-03-07 14:52:28 -0800548void DisplayDevice::setColorTransform(const mat4& transform) {
549 const bool isIdentity = (transform == mat4());
550 mColorTransform =
551 isIdentity ? HAL_COLOR_TRANSFORM_IDENTITY : HAL_COLOR_TRANSFORM_ARBITRARY_MATRIX;
552}
553
554android_color_transform_t DisplayDevice::getColorTransform() const {
555 return mColorTransform;
556}
557
Peiyong Lin34beb7a2018-03-28 11:57:12 -0700558void DisplayDevice::setCompositionDataSpace(ui::Dataspace dataspace) {
Peiyong Lindd9b2ae2018-03-01 16:22:45 -0800559 mCompositionDataSpace = dataspace;
Courtney Goeltzenleuchter79d27242017-07-13 17:54:01 -0600560 ANativeWindow* const window = mNativeWindow.get();
Peiyong Lin34beb7a2018-03-28 11:57:12 -0700561 native_window_set_buffers_data_space(window, static_cast<android_dataspace>(dataspace));
Courtney Goeltzenleuchter79d27242017-07-13 17:54:01 -0600562}
Michael Wright28f24d02016-07-12 13:30:53 -0700563
Peiyong Lindd9b2ae2018-03-01 16:22:45 -0800564ui::Dataspace DisplayDevice::getCompositionDataSpace() const {
565 return mCompositionDataSpace;
566}
567
Michael Wright28f24d02016-07-12 13:30:53 -0700568// ----------------------------------------------------------------------------
Mathias Agopiand3ee2312012-08-02 14:01:42 -0700569
Mathias Agopian28947d72012-08-08 18:51:15 -0700570void DisplayDevice::setLayerStack(uint32_t stack) {
571 mLayerStack = stack;
572 dirtyRegion.set(bounds());
573}
574
575// ----------------------------------------------------------------------------
576
Mathias Agopianc1c05de2013-09-17 23:45:22 -0700577uint32_t DisplayDevice::getOrientationTransform() const {
578 uint32_t transform = 0;
579 switch (mOrientation) {
580 case DisplayState::eOrientationDefault:
Peiyong Linefefaac2018-08-17 12:27:51 -0700581 transform = ui::Transform::ROT_0;
Mathias Agopianc1c05de2013-09-17 23:45:22 -0700582 break;
583 case DisplayState::eOrientation90:
Peiyong Linefefaac2018-08-17 12:27:51 -0700584 transform = ui::Transform::ROT_90;
Mathias Agopianc1c05de2013-09-17 23:45:22 -0700585 break;
586 case DisplayState::eOrientation180:
Peiyong Linefefaac2018-08-17 12:27:51 -0700587 transform = ui::Transform::ROT_180;
Mathias Agopianc1c05de2013-09-17 23:45:22 -0700588 break;
589 case DisplayState::eOrientation270:
Peiyong Linefefaac2018-08-17 12:27:51 -0700590 transform = ui::Transform::ROT_270;
Mathias Agopianc1c05de2013-09-17 23:45:22 -0700591 break;
592 }
593 return transform;
594}
595
Mathias Agopian0f2f5ff2012-07-31 23:09:07 -0700596status_t DisplayDevice::orientationToTransfrom(
Peiyong Linefefaac2018-08-17 12:27:51 -0700597 int orientation, int w, int h, ui::Transform* tr)
Mathias Agopian1b031492012-06-20 17:51:20 -0700598{
599 uint32_t flags = 0;
600 switch (orientation) {
Mathias Agopian3165cc22012-08-08 19:42:09 -0700601 case DisplayState::eOrientationDefault:
Peiyong Linefefaac2018-08-17 12:27:51 -0700602 flags = ui::Transform::ROT_0;
Mathias Agopian1b031492012-06-20 17:51:20 -0700603 break;
Mathias Agopian3165cc22012-08-08 19:42:09 -0700604 case DisplayState::eOrientation90:
Peiyong Linefefaac2018-08-17 12:27:51 -0700605 flags = ui::Transform::ROT_90;
Mathias Agopian1b031492012-06-20 17:51:20 -0700606 break;
Mathias Agopian3165cc22012-08-08 19:42:09 -0700607 case DisplayState::eOrientation180:
Peiyong Linefefaac2018-08-17 12:27:51 -0700608 flags = ui::Transform::ROT_180;
Mathias Agopian1b031492012-06-20 17:51:20 -0700609 break;
Mathias Agopian3165cc22012-08-08 19:42:09 -0700610 case DisplayState::eOrientation270:
Peiyong Linefefaac2018-08-17 12:27:51 -0700611 flags = ui::Transform::ROT_270;
Mathias Agopian1b031492012-06-20 17:51:20 -0700612 break;
613 default:
614 return BAD_VALUE;
615 }
616 tr->set(flags, w, h);
617 return NO_ERROR;
618}
619
Michael Lentine47e45402014-07-18 15:34:25 -0700620void DisplayDevice::setDisplaySize(const int newWidth, const int newHeight) {
621 dirtyRegion.set(getBounds());
622
623 mDisplaySurface->resizeBuffers(newWidth, newHeight);
624
Alec Mouriba013fa2018-10-16 12:43:11 -0700625 mDisplayWidth = newWidth;
626 mDisplayHeight = newHeight;
Michael Lentine47e45402014-07-18 15:34:25 -0700627}
628
Mathias Agopian00e8c7a2012-09-04 19:30:46 -0700629void DisplayDevice::setProjection(int orientation,
Mathias Agopianf5f714a2013-02-26 16:54:05 -0800630 const Rect& newViewport, const Rect& newFrame) {
631 Rect viewport(newViewport);
632 Rect frame(newFrame);
633
634 const int w = mDisplayWidth;
635 const int h = mDisplayHeight;
636
Peiyong Linefefaac2018-08-17 12:27:51 -0700637 ui::Transform R;
Mathias Agopianf5f714a2013-02-26 16:54:05 -0800638 DisplayDevice::orientationToTransfrom(orientation, w, h, &R);
639
640 if (!frame.isValid()) {
641 // the destination frame can be invalid if it has never been set,
642 // in that case we assume the whole display frame.
643 frame = Rect(w, h);
644 }
645
646 if (viewport.isEmpty()) {
647 // viewport can be invalid if it has never been set, in that case
648 // we assume the whole display size.
649 // it's also invalid to have an empty viewport, so we handle that
650 // case in the same way.
651 viewport = Rect(w, h);
Peiyong Linefefaac2018-08-17 12:27:51 -0700652 if (R.getOrientation() & ui::Transform::ROT_90) {
Mathias Agopianf5f714a2013-02-26 16:54:05 -0800653 // viewport is always specified in the logical orientation
654 // of the display (ie: post-rotation).
Peiyong Lin3db42342018-08-16 09:15:59 -0700655 std::swap(viewport.right, viewport.bottom);
Mathias Agopianf5f714a2013-02-26 16:54:05 -0800656 }
657 }
658
659 dirtyRegion.set(getBounds());
660
Peiyong Linefefaac2018-08-17 12:27:51 -0700661 ui::Transform TL, TP, S;
Mathias Agopianf5f714a2013-02-26 16:54:05 -0800662 float src_width = viewport.width();
663 float src_height = viewport.height();
664 float dst_width = frame.width();
665 float dst_height = frame.height();
666 if (src_width != dst_width || src_height != dst_height) {
667 float sx = dst_width / src_width;
668 float sy = dst_height / src_height;
669 S.set(sx, 0, 0, sy);
670 }
671
672 float src_x = viewport.left;
673 float src_y = viewport.top;
674 float dst_x = frame.left;
675 float dst_y = frame.top;
676 TL.set(-src_x, -src_y);
677 TP.set(dst_x, dst_y);
678
Iris Chang7501ed62018-04-30 14:45:42 +0800679 // need to take care of primary display rotation for mGlobalTransform
680 // for case if the panel is not installed aligned with device orientation
Dominik Laskowski075d3172018-05-24 15:50:06 -0700681 if (isPrimary()) {
Iris Chang7501ed62018-04-30 14:45:42 +0800682 DisplayDevice::orientationToTransfrom(
Chia-I Wua02871c2018-08-27 14:38:23 -0700683 (orientation + mDisplayInstallOrientation) % (DisplayState::eOrientation270 + 1),
Iris Chang7501ed62018-04-30 14:45:42 +0800684 w, h, &R);
685 }
686
Mathias Agopianf5f714a2013-02-26 16:54:05 -0800687 // The viewport and frame are both in the logical orientation.
688 // Apply the logical translation, scale to physical size, apply the
689 // physical translation and finally rotate to the physical orientation.
690 mGlobalTransform = R * TP * S * TL;
691
692 const uint8_t type = mGlobalTransform.getType();
693 mNeedsFiltering = (!mGlobalTransform.preserveRects() ||
Peiyong Linefefaac2018-08-17 12:27:51 -0700694 (type >= ui::Transform::SCALE));
Mathias Agopianf5f714a2013-02-26 16:54:05 -0800695
696 mScissor = mGlobalTransform.transform(viewport);
697 if (mScissor.isEmpty()) {
Mathias Agopian6c7f25a2013-05-09 20:37:10 -0700698 mScissor = getBounds();
Mathias Agopianf5f714a2013-02-26 16:54:05 -0800699 }
700
Mathias Agopianda8d0a52012-09-04 15:05:38 -0700701 mOrientation = orientation;
Dominik Laskowski281644e2018-04-19 15:47:35 -0700702 if (isPrimary()) {
Pablo Ceballos021623b2016-04-15 17:31:51 -0700703 uint32_t transform = 0;
704 switch (mOrientation) {
705 case DisplayState::eOrientationDefault:
Peiyong Linefefaac2018-08-17 12:27:51 -0700706 transform = ui::Transform::ROT_0;
Pablo Ceballos021623b2016-04-15 17:31:51 -0700707 break;
708 case DisplayState::eOrientation90:
Peiyong Linefefaac2018-08-17 12:27:51 -0700709 transform = ui::Transform::ROT_90;
Pablo Ceballos021623b2016-04-15 17:31:51 -0700710 break;
711 case DisplayState::eOrientation180:
Peiyong Linefefaac2018-08-17 12:27:51 -0700712 transform = ui::Transform::ROT_180;
Pablo Ceballos021623b2016-04-15 17:31:51 -0700713 break;
714 case DisplayState::eOrientation270:
Peiyong Linefefaac2018-08-17 12:27:51 -0700715 transform = ui::Transform::ROT_270;
Pablo Ceballos021623b2016-04-15 17:31:51 -0700716 break;
717 }
718 sPrimaryDisplayOrientation = transform;
719 }
Mathias Agopian00e8c7a2012-09-04 19:30:46 -0700720 mViewport = viewport;
721 mFrame = frame;
Mathias Agopian1b031492012-06-20 17:51:20 -0700722}
Mathias Agopian1d12d8a2012-09-18 01:38:00 -0700723
Pablo Ceballos021623b2016-04-15 17:31:51 -0700724uint32_t DisplayDevice::getPrimaryDisplayOrientationTransform() {
725 return sPrimaryDisplayOrientation;
726}
727
Dominik Laskowski9b17b2c22018-11-01 14:49:03 -0700728std::string DisplayDevice::getDebugName() const {
Dominik Laskowski34157762018-10-31 13:07:19 -0700729 const auto id = mId ? to_string(*mId) + ", " : std::string();
Dominik Laskowski9b17b2c22018-11-01 14:49:03 -0700730 return base::StringPrintf("DisplayDevice{%s%s%s\"%s\"}", id.c_str(),
731 isPrimary() ? "primary, " : "", isVirtual() ? "virtual, " : "",
732 mDisplayName.c_str());
733}
734
Yiwei Zhang5434a782018-12-05 18:06:32 -0800735void DisplayDevice::dump(std::string& result) const {
Peiyong Linefefaac2018-08-17 12:27:51 -0700736 const ui::Transform& tr(mGlobalTransform);
Courtney Goeltzenleuchter152279d2017-08-14 18:18:30 -0600737 ANativeWindow* const window = mNativeWindow.get();
Yiwei Zhang5434a782018-12-05 18:06:32 -0800738 StringAppendF(&result, "+ %s\n", getDebugName().c_str());
739 StringAppendF(&result,
740 " layerStack=%u, (%4dx%4d), ANativeWindow=%p "
741 "format=%d, orient=%2d (type=%08x), flips=%u, isSecure=%d, "
742 "powerMode=%d, activeConfig=%d, numLayers=%zu\n",
743 mLayerStack, mDisplayWidth, mDisplayHeight, window,
744 ANativeWindow_getFormat(window), mOrientation, tr.getType(), getPageFlipCount(),
745 mIsSecure, mPowerMode, mActiveConfig, mVisibleLayersSortedByZ.size());
746 StringAppendF(&result,
747 " v:[%d,%d,%d,%d], f:[%d,%d,%d,%d], s:[%d,%d,%d,%d],"
748 "transform:[[%0.3f,%0.3f,%0.3f][%0.3f,%0.3f,%0.3f][%0.3f,%0.3f,%0.3f]]\n",
749 mViewport.left, mViewport.top, mViewport.right, mViewport.bottom, mFrame.left,
750 mFrame.top, mFrame.right, mFrame.bottom, mScissor.left, mScissor.top,
751 mScissor.right, mScissor.bottom, tr[0][0], tr[1][0], tr[2][0], tr[0][1], tr[1][1],
752 tr[2][1], tr[0][2], tr[1][2], tr[2][2]);
Courtney Goeltzenleuchter152279d2017-08-14 18:18:30 -0600753 auto const surface = static_cast<Surface*>(window);
Peiyong Lin34beb7a2018-03-28 11:57:12 -0700754 ui::Dataspace dataspace = surface->getBuffersDataSpace();
Valerie Haue9e843a2018-12-18 13:39:23 -0800755 StringAppendF(&result,
756 " wideColorGamut=%d, hdr10plus =%d, hdr10=%d, colorMode=%s, dataspace: %s "
757 "(%d)\n",
758 mHasWideColorGamut, mHasHdr10Plus, mHasHdr10,
759 decodeColorMode(mActiveColorMode).c_str(),
Yiwei Zhang5434a782018-12-05 18:06:32 -0800760 dataspaceDetails(static_cast<android_dataspace>(dataspace)).c_str(), dataspace);
Mathias Agopian1d12d8a2012-09-18 01:38:00 -0700761
Jesse Hall99c7dbb2013-03-14 14:29:29 -0700762 String8 surfaceDump;
Dan Stozaf10c46e2014-11-11 10:32:31 -0800763 mDisplaySurface->dumpAsString(surfaceDump);
Yiwei Zhang5434a782018-12-05 18:06:32 -0800764 result.append(surfaceDump.string(), surfaceDump.size());
Mathias Agopian1d12d8a2012-09-18 01:38:00 -0700765}
Irvelffc9efc2016-07-27 15:16:37 -0700766
Chia-I Wube02ec02018-05-18 10:59:36 -0700767// Map dataspace/intent to the best matched dataspace/colorMode/renderIntent
768// supported by HWC.
769void DisplayDevice::addColorMode(
770 const std::unordered_map<ColorMode, std::vector<RenderIntent>>& hwcColorModes,
771 const ColorMode mode, const RenderIntent intent) {
772 // find the best color mode
773 const ColorMode hwcColorMode = getHwcColorMode(hwcColorModes, mode);
774
775 // find the best render intent
776 auto iter = hwcColorModes.find(hwcColorMode);
777 const auto& hwcIntents =
778 iter != hwcColorModes.end() ? iter->second : std::vector<RenderIntent>();
779 const RenderIntent hwcIntent = getHwcRenderIntent(hwcIntents, intent);
780
781 const Dataspace dataspace = colorModeToDataspace(mode);
782 const Dataspace hwcDataspace = colorModeToDataspace(hwcColorMode);
783
Dominik Laskowski9b17b2c22018-11-01 14:49:03 -0700784 ALOGV("%s: map (%s, %s) to (%s, %s, %s)", getDebugName().c_str(),
Chia-I Wube02ec02018-05-18 10:59:36 -0700785 dataspaceDetails(static_cast<android_dataspace_t>(dataspace)).c_str(),
786 decodeRenderIntent(intent).c_str(),
787 dataspaceDetails(static_cast<android_dataspace_t>(hwcDataspace)).c_str(),
788 decodeColorMode(hwcColorMode).c_str(), decodeRenderIntent(hwcIntent).c_str());
789
790 mColorModes[getColorModeKey(dataspace, intent)] = {hwcDataspace, hwcColorMode, hwcIntent};
791}
792
793void DisplayDevice::populateColorModes(
794 const std::unordered_map<ColorMode, std::vector<RenderIntent>>& hwcColorModes) {
795 if (!hasWideColorGamut()) {
796 return;
797 }
798
Chia-I Wu0d711262018-05-21 15:19:35 -0700799 // collect all known SDR render intents
800 std::unordered_set<RenderIntent> sdrRenderIntents(sSdrRenderIntents.begin(),
801 sSdrRenderIntents.end());
802 auto iter = hwcColorModes.find(ColorMode::SRGB);
803 if (iter != hwcColorModes.end()) {
804 for (auto intent : iter->second) {
805 sdrRenderIntents.insert(intent);
806 }
807 }
808
Chia-I Wuc4b08bd2018-05-29 12:57:23 -0700809 // add all known SDR combinations
Chia-I Wu0d711262018-05-21 15:19:35 -0700810 for (auto intent : sdrRenderIntents) {
Chia-I Wube02ec02018-05-18 10:59:36 -0700811 for (auto mode : sSdrColorModes) {
812 addColorMode(hwcColorModes, mode, intent);
Peiyong Lin136fbbc2018-04-17 15:09:44 -0700813 }
814 }
Chia-I Wube02ec02018-05-18 10:59:36 -0700815
Chia-I Wuc4b08bd2018-05-29 12:57:23 -0700816 // collect all known HDR render intents
817 std::unordered_set<RenderIntent> hdrRenderIntents(sHdrRenderIntents.begin(),
818 sHdrRenderIntents.end());
819 iter = hwcColorModes.find(ColorMode::BT2100_PQ);
820 if (iter != hwcColorModes.end()) {
821 for (auto intent : iter->second) {
822 hdrRenderIntents.insert(intent);
823 }
824 }
825
826 // add all known HDR combinations
Chia-I Wube02ec02018-05-18 10:59:36 -0700827 for (auto intent : sHdrRenderIntents) {
828 for (auto mode : sHdrColorModes) {
829 addColorMode(hwcColorModes, mode, intent);
830 }
831 }
832}
833
834bool DisplayDevice::hasRenderIntent(RenderIntent intent) const {
835 // assume a render intent is supported when SRGB supports it; we should
836 // get rid of that assumption.
Peiyong Lin14724e62018-12-05 07:27:30 -0800837 auto iter = mColorModes.find(getColorModeKey(Dataspace::V0_SRGB, intent));
Chia-I Wube02ec02018-05-18 10:59:36 -0700838 return iter != mColorModes.end() && iter->second.renderIntent == intent;
839}
840
Peiyong Lindfde5112018-06-05 10:58:41 -0700841bool DisplayDevice::hasLegacyHdrSupport(Dataspace dataspace) const {
Chia-I Wube02ec02018-05-18 10:59:36 -0700842 if ((dataspace == Dataspace::BT2020_PQ && hasHDR10Support()) ||
843 (dataspace == Dataspace::BT2020_HLG && hasHLGSupport())) {
844 auto iter =
845 mColorModes.find(getColorModeKey(dataspace, RenderIntent::TONE_MAP_COLORIMETRIC));
Peiyong Lindfde5112018-06-05 10:58:41 -0700846 return iter == mColorModes.end() || iter->second.dataspace != dataspace;
Chia-I Wube02ec02018-05-18 10:59:36 -0700847 }
848
849 return false;
850}
851
852void DisplayDevice::getBestColorMode(Dataspace dataspace, RenderIntent intent,
853 Dataspace* outDataspace, ColorMode* outMode,
854 RenderIntent* outIntent) const {
855 auto iter = mColorModes.find(getColorModeKey(dataspace, intent));
856 if (iter != mColorModes.end()) {
857 *outDataspace = iter->second.dataspace;
858 *outMode = iter->second.colorMode;
859 *outIntent = iter->second.renderIntent;
860 } else {
Chia-I Wu6333af52018-10-16 13:46:36 -0700861 // this is unexpected on a WCG display
862 if (hasWideColorGamut()) {
863 ALOGE("map unknown (%s)/(%s) to default color mode",
864 dataspaceDetails(static_cast<android_dataspace_t>(dataspace)).c_str(),
865 decodeRenderIntent(intent).c_str());
866 }
Chia-I Wube02ec02018-05-18 10:59:36 -0700867
868 *outDataspace = Dataspace::UNKNOWN;
869 *outMode = ColorMode::NATIVE;
870 *outIntent = RenderIntent::COLORIMETRIC;
871 }
Peiyong Lin136fbbc2018-04-17 15:09:44 -0700872}
873
Dominik Laskowski663bd282018-04-19 15:26:54 -0700874std::atomic<int32_t> DisplayDeviceState::sNextSequenceId(1);
Peiyong Linfd997e02018-03-28 15:29:00 -0700875
876} // namespace android