blob: 55ce4343a7563d55ec42c830e2f1cc24bc99bc07 [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;
Peiyong Linfd997e02018-03-28 15:29:00 -070057using android::ui::ColorMode;
Chia-I Wube02ec02018-05-18 10:59:36 -070058using android::ui::Dataspace;
Peiyong Lin62665892018-04-16 11:07:44 -070059using android::ui::Hdr;
Peiyong Lindd9b2ae2018-03-01 16:22:45 -080060using android::ui::RenderIntent;
Jaesoo Lee720a7242017-01-31 15:26:18 +090061
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -080062/*
63 * Initialize the display to the specified values.
64 *
65 */
66
Pablo Ceballos021623b2016-04-15 17:31:51 -070067uint32_t DisplayDevice::sPrimaryDisplayOrientation = 0;
68
Chia-I Wube02ec02018-05-18 10:59:36 -070069namespace {
70
71// ordered list of known SDR color modes
Valerie Hau9758ae02018-10-09 16:05:09 -070072const std::array<ColorMode, 3> sSdrColorModes = {
73 ColorMode::DISPLAY_BT2020,
Chia-I Wube02ec02018-05-18 10:59:36 -070074 ColorMode::DISPLAY_P3,
75 ColorMode::SRGB,
76};
77
78// ordered list of known HDR color modes
79const std::array<ColorMode, 2> sHdrColorModes = {
80 ColorMode::BT2100_PQ,
81 ColorMode::BT2100_HLG,
82};
83
84// ordered list of known SDR render intents
85const std::array<RenderIntent, 2> sSdrRenderIntents = {
86 RenderIntent::ENHANCE,
87 RenderIntent::COLORIMETRIC,
88};
89
90// ordered list of known HDR render intents
91const std::array<RenderIntent, 2> sHdrRenderIntents = {
92 RenderIntent::TONE_MAP_ENHANCE,
93 RenderIntent::TONE_MAP_COLORIMETRIC,
94};
95
96// map known color mode to dataspace
97Dataspace colorModeToDataspace(ColorMode mode) {
98 switch (mode) {
99 case ColorMode::SRGB:
100 return Dataspace::SRGB;
101 case ColorMode::DISPLAY_P3:
102 return Dataspace::DISPLAY_P3;
Valerie Hau9758ae02018-10-09 16:05:09 -0700103 case ColorMode::DISPLAY_BT2020:
104 return Dataspace::DISPLAY_BT2020;
Chia-I Wube02ec02018-05-18 10:59:36 -0700105 case ColorMode::BT2100_HLG:
106 return Dataspace::BT2020_HLG;
107 case ColorMode::BT2100_PQ:
108 return Dataspace::BT2020_PQ;
109 default:
110 return Dataspace::UNKNOWN;
111 }
112}
113
114// Return a list of candidate color modes.
115std::vector<ColorMode> getColorModeCandidates(ColorMode mode) {
116 std::vector<ColorMode> candidates;
117
118 // add mode itself
119 candidates.push_back(mode);
120
121 // check if mode is HDR
122 bool isHdr = false;
123 for (auto hdrMode : sHdrColorModes) {
124 if (hdrMode == mode) {
125 isHdr = true;
126 break;
127 }
128 }
129
130 // add other HDR candidates when mode is HDR
131 if (isHdr) {
132 for (auto hdrMode : sHdrColorModes) {
133 if (hdrMode != mode) {
134 candidates.push_back(hdrMode);
135 }
136 }
137 }
138
139 // add other SDR candidates
140 for (auto sdrMode : sSdrColorModes) {
141 if (sdrMode != mode) {
142 candidates.push_back(sdrMode);
143 }
144 }
145
146 return candidates;
147}
148
149// Return a list of candidate render intents.
150std::vector<RenderIntent> getRenderIntentCandidates(RenderIntent intent) {
151 std::vector<RenderIntent> candidates;
152
153 // add intent itself
154 candidates.push_back(intent);
155
156 // check if intent is HDR
157 bool isHdr = false;
158 for (auto hdrIntent : sHdrRenderIntents) {
159 if (hdrIntent == intent) {
160 isHdr = true;
161 break;
162 }
163 }
164
Chia-I Wube02ec02018-05-18 10:59:36 -0700165 if (isHdr) {
Chia-I Wuc4b08bd2018-05-29 12:57:23 -0700166 // add other HDR candidates when intent is HDR
Chia-I Wube02ec02018-05-18 10:59:36 -0700167 for (auto hdrIntent : sHdrRenderIntents) {
168 if (hdrIntent != intent) {
169 candidates.push_back(hdrIntent);
170 }
171 }
Chia-I Wuc4b08bd2018-05-29 12:57:23 -0700172 } else {
173 // add other SDR candidates when intent is SDR
174 for (auto sdrIntent : sSdrRenderIntents) {
175 if (sdrIntent != intent) {
176 candidates.push_back(sdrIntent);
177 }
178 }
Chia-I Wube02ec02018-05-18 10:59:36 -0700179 }
180
181 return candidates;
182}
183
184// Return the best color mode supported by HWC.
185ColorMode getHwcColorMode(
186 const std::unordered_map<ColorMode, std::vector<RenderIntent>>& hwcColorModes,
187 ColorMode mode) {
188 std::vector<ColorMode> candidates = getColorModeCandidates(mode);
189 for (auto candidate : candidates) {
190 auto iter = hwcColorModes.find(candidate);
191 if (iter != hwcColorModes.end()) {
192 return candidate;
193 }
194 }
195
196 return ColorMode::NATIVE;
197}
198
199// Return the best render intent supported by HWC.
200RenderIntent getHwcRenderIntent(const std::vector<RenderIntent>& hwcIntents, RenderIntent intent) {
201 std::vector<RenderIntent> candidates = getRenderIntentCandidates(intent);
202 for (auto candidate : candidates) {
203 for (auto hwcIntent : hwcIntents) {
204 if (candidate == hwcIntent) {
205 return candidate;
206 }
207 }
208 }
209
210 return RenderIntent::COLORIMETRIC;
211}
212
213} // anonymous namespace
214
Lloyd Pique2eef1d22018-09-18 21:30:04 -0700215DisplayDeviceCreationArgs::DisplayDeviceCreationArgs(const sp<SurfaceFlinger>& flinger,
216 const wp<IBinder>& displayToken,
Dominik Laskowski075d3172018-05-24 15:50:06 -0700217 const std::optional<DisplayId>& displayId)
218 : flinger(flinger), displayToken(displayToken), displayId(displayId) {}
Chia-I Wube02ec02018-05-18 10:59:36 -0700219
Lloyd Pique2eef1d22018-09-18 21:30:04 -0700220DisplayDevice::DisplayDevice(DisplayDeviceCreationArgs&& args)
221 : lastCompositionHadVisibleLayers(false),
222 mFlinger(args.flinger),
Lloyd Pique2eef1d22018-09-18 21:30:04 -0700223 mDisplayToken(args.displayToken),
Dominik Laskowski075d3172018-05-24 15:50:06 -0700224 mId(args.displayId),
Lloyd Pique2eef1d22018-09-18 21:30:04 -0700225 mNativeWindow(args.nativeWindow),
Alec Mouri0a9c7b82018-11-16 13:05:25 -0800226 mGraphicBuffer(nullptr),
Lloyd Pique2eef1d22018-09-18 21:30:04 -0700227 mDisplaySurface(args.displaySurface),
Alec Mouri05874642018-11-14 22:34:02 +0000228 mSurface{std::move(args.renderSurface)},
Lloyd Pique2eef1d22018-09-18 21:30:04 -0700229 mDisplayInstallOrientation(args.displayInstallOrientation),
230 mPageFlipCount(0),
Dominik Laskowski075d3172018-05-24 15:50:06 -0700231 mIsVirtual(args.isVirtual),
Lloyd Pique2eef1d22018-09-18 21:30:04 -0700232 mIsSecure(args.isSecure),
233 mLayerStack(NO_LAYER_STACK),
234 mOrientation(),
235 mViewport(Rect::INVALID_RECT),
236 mFrame(Rect::INVALID_RECT),
237 mPowerMode(args.initialPowerMode),
238 mActiveConfig(0),
239 mColorTransform(HAL_COLOR_TRANSFORM_IDENTITY),
240 mHasWideColorGamut(args.hasWideColorGamut),
241 mHasHdr10(false),
242 mHasHLG(false),
243 mHasDolbyVision(false),
Dominik Laskowski075d3172018-05-24 15:50:06 -0700244 mSupportedPerFrameMetadata(args.supportedPerFrameMetadata),
245 mIsPrimary(args.isPrimary) {
Lloyd Pique2eef1d22018-09-18 21:30:04 -0700246 populateColorModes(args.hwcColorModes);
247
248 ALOGE_IF(!mNativeWindow, "No native window was set for display");
249 ALOGE_IF(!mDisplaySurface, "No display surface was set for display");
Alec Mouri05874642018-11-14 22:34:02 +0000250 ALOGE_IF(!mSurface, "No render surface was set for display");
Lloyd Pique2eef1d22018-09-18 21:30:04 -0700251
252 std::vector<Hdr> types = args.hdrCapabilities.getSupportedHdrTypes();
Peiyong Linfb069302018-04-25 14:34:31 -0700253 for (Hdr hdrType : types) {
Peiyong Lin62665892018-04-16 11:07:44 -0700254 switch (hdrType) {
255 case Hdr::HDR10:
256 mHasHdr10 = true;
257 break;
258 case Hdr::HLG:
259 mHasHLG = true;
260 break;
261 case Hdr::DOLBY_VISION:
262 mHasDolbyVision = true;
263 break;
264 default:
265 ALOGE("UNKNOWN HDR capability: %d", static_cast<int32_t>(hdrType));
266 }
267 }
Jesse Hallffe1f192013-03-22 15:13:48 -0700268
Lloyd Pique2eef1d22018-09-18 21:30:04 -0700269 float minLuminance = args.hdrCapabilities.getDesiredMinLuminance();
270 float maxLuminance = args.hdrCapabilities.getDesiredMaxLuminance();
271 float maxAverageLuminance = args.hdrCapabilities.getDesiredMaxAverageLuminance();
Peiyong Linfb069302018-04-25 14:34:31 -0700272
273 minLuminance = minLuminance <= 0.0 ? sDefaultMinLumiance : minLuminance;
274 maxLuminance = maxLuminance <= 0.0 ? sDefaultMaxLumiance : maxLuminance;
275 maxAverageLuminance = maxAverageLuminance <= 0.0 ? sDefaultMaxLumiance : maxAverageLuminance;
276 if (this->hasWideColorGamut()) {
277 // insert HDR10/HLG as we will force client composition for HDR10/HLG
278 // layers
279 if (!hasHDR10Support()) {
280 types.push_back(Hdr::HDR10);
281 }
282
283 if (!hasHLGSupport()) {
284 types.push_back(Hdr::HLG);
285 }
286 }
287 mHdrCapabilities = HdrCapabilities(types, maxLuminance, maxAverageLuminance, minLuminance);
288
Alec Mouriba013fa2018-10-16 12:43:11 -0700289 ANativeWindow* const window = mNativeWindow.get();
Alec Mouri0a9c7b82018-11-16 13:05:25 -0800290
Alec Mouri4efb6c22018-11-16 13:07:47 -0800291 int status = native_window_api_connect(window, NATIVE_WINDOW_API_EGL);
Alec Mouri0a9c7b82018-11-16 13:05:25 -0800292 ALOGE_IF(status != NO_ERROR, "Unable to connect BQ producer: %d", status);
Alec Mouri4efb6c22018-11-16 13:07:47 -0800293 status = native_window_set_buffers_format(window, HAL_PIXEL_FORMAT_RGBA_8888);
294 ALOGE_IF(status != NO_ERROR, "Unable to set BQ format to RGBA888: %d", status);
295 status = native_window_set_usage(window, GRALLOC_USAGE_HW_RENDER);
296 ALOGE_IF(status != NO_ERROR, "Unable to set BQ usage bits for GPU rendering: %d", status);
Alec Mouri0a9c7b82018-11-16 13:05:25 -0800297
Alec Mouriba013fa2018-10-16 12:43:11 -0700298 mDisplayWidth = ANativeWindow_getWidth(window);
299 mDisplayHeight = ANativeWindow_getHeight(window);
300
Jesse Hallffe1f192013-03-22 15:13:48 -0700301 // initialize the display orientation transform.
302 setProjection(DisplayState::eOrientationDefault, mViewport, mFrame);
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800303}
304
Lloyd Pique09594832018-01-22 17:48:03 -0800305DisplayDevice::~DisplayDevice() = default;
Mathias Agopian92a979a2012-08-02 18:32:23 -0700306
Jesse Hall02d86562013-03-25 14:43:23 -0700307void DisplayDevice::disconnect(HWComposer& hwc) {
Dominik Laskowski075d3172018-05-24 15:50:06 -0700308 if (mId) {
309 hwc.disconnectDisplay(*mId);
310 mId.reset();
Jesse Hall02d86562013-03-25 14:43:23 -0700311 }
312}
313
Mathias Agopian0f2f5ff2012-07-31 23:09:07 -0700314int DisplayDevice::getWidth() const {
Mathias Agopiana4912602012-07-12 14:25:33 -0700315 return mDisplayWidth;
316}
317
Mathias Agopian0f2f5ff2012-07-31 23:09:07 -0700318int DisplayDevice::getHeight() const {
Mathias Agopiana4912602012-07-12 14:25:33 -0700319 return mDisplayHeight;
320}
321
Dominik Laskowskibf170d92018-04-19 15:08:05 -0700322void DisplayDevice::setDisplayName(const std::string& displayName) {
323 if (!displayName.empty()) {
Mathias Agopian9e2463e2012-09-21 18:26:16 -0700324 // never override the name with an empty name
325 mDisplayName = displayName;
326 }
327}
328
Mathias Agopian0f2f5ff2012-07-31 23:09:07 -0700329uint32_t DisplayDevice::getPageFlipCount() const {
Mathias Agopian076b1cc2009-04-10 14:24:30 -0700330 return mPageFlipCount;
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800331}
332
Chia-I Wub02087d2017-11-09 10:19:54 -0800333void DisplayDevice::flip() const
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800334{
Mathias Agopian076b1cc2009-04-10 14:24:30 -0700335 mPageFlipCount++;
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800336}
337
Dan Stoza71433162014-02-04 16:22:36 -0800338status_t DisplayDevice::beginFrame(bool mustRecompose) const {
339 return mDisplaySurface->beginFrame(mustRecompose);
Jesse Hall028dc8f2013-08-20 16:35:32 -0700340}
341
David Sodmanfb95bcc2017-12-22 15:45:30 -0800342status_t DisplayDevice::prepareFrame(HWComposer& hwc,
343 std::vector<CompositionInfo>& compositionData) {
Dominik Laskowski075d3172018-05-24 15:50:06 -0700344 if (mId) {
345 status_t error = hwc.prepare(*mId, compositionData);
346 if (error != NO_ERROR) {
347 return error;
348 }
Dan Stoza9e56aa02015-11-02 13:00:03 -0800349 }
350
351 DisplaySurface::CompositionType compositionType;
Dominik Laskowski7e045462018-05-30 13:02:02 -0700352 bool hasClient = hwc.hasClientComposition(mId);
353 bool hasDevice = hwc.hasDeviceComposition(mId);
Dan Stoza9e56aa02015-11-02 13:00:03 -0800354 if (hasClient && hasDevice) {
355 compositionType = DisplaySurface::COMPOSITION_MIXED;
356 } else if (hasClient) {
357 compositionType = DisplaySurface::COMPOSITION_GLES;
358 } else if (hasDevice) {
359 compositionType = DisplaySurface::COMPOSITION_HWC;
360 } else {
361 // Nothing to do -- when turning the screen off we get a frame like
362 // this. Call it a HWC frame since we won't be doing any GLES work but
363 // will do a prepare/set cycle.
364 compositionType = DisplaySurface::COMPOSITION_HWC;
365 }
366 return mDisplaySurface->prepareFrame(compositionType);
367}
Jesse Hall38efe862013-04-06 23:12:29 -0700368
Alec Mouri0a9c7b82018-11-16 13:05:25 -0800369sp<GraphicBuffer> DisplayDevice::dequeueBuffer() {
370 int fd;
371 ANativeWindowBuffer* buffer;
372
373 status_t res = mNativeWindow->dequeueBuffer(mNativeWindow.get(), &buffer, &fd);
374
375 if (res != NO_ERROR) {
376 ALOGE("ANativeWindow::dequeueBuffer failed for display [%s] with error: %d",
377 getDisplayName().c_str(), res);
378 // Return fast here as we can't do much more - any rendering we do
379 // now will just be wrong.
380 return mGraphicBuffer;
381 }
382
383 ALOGW_IF(mGraphicBuffer != nullptr, "Clobbering a non-null pointer to a buffer [%p].",
384 mGraphicBuffer->getNativeBuffer()->handle);
385 mGraphicBuffer = GraphicBuffer::from(buffer);
386
387 // Block until the buffer is ready
388 // TODO(alecmouri): it's perhaps more appropriate to block renderengine so
389 // that the gl driver can block instead.
390 if (fd >= 0) {
391 sync_wait(fd, -1);
392 close(fd);
393 }
394
395 return mGraphicBuffer;
396}
397
398void DisplayDevice::queueBuffer(HWComposer& hwc) {
Dominik Laskowski7e045462018-05-30 13:02:02 -0700399 if (hwc.hasClientComposition(mId) || hwc.hasFlipClientTargetRequest(mId)) {
Alec Mouri0a9c7b82018-11-16 13:05:25 -0800400 // hasFlipClientTargetRequest could return true even if we haven't
401 // dequeued a buffer before. Try dequeueing one if we don't have a
402 // buffer ready.
403 if (mGraphicBuffer == nullptr) {
404 ALOGI("Attempting to queue a client composited buffer without one "
405 "previously dequeued for display [%s]. Attempting to dequeue "
406 "a scratch buffer now",
407 mDisplayName.c_str());
408 // We shouldn't deadlock here, since mGraphicBuffer == nullptr only
409 // after a successful call to queueBuffer, or if dequeueBuffer has
410 // never been called.
411 dequeueBuffer();
412 }
413
414 if (mGraphicBuffer == nullptr) {
415 ALOGE("No buffer is ready for display [%s]", mDisplayName.c_str());
416 } else {
417 int fd = mBufferReady.release();
418
419 status_t res = mNativeWindow->queueBuffer(mNativeWindow.get(),
420 mGraphicBuffer->getNativeBuffer(), fd);
421 if (res != NO_ERROR) {
422 ALOGE("Error when queueing buffer for display [%s]: %d", mDisplayName.c_str(), res);
423 // We risk blocking on dequeueBuffer if the primary display failed
424 // to queue up its buffer, so crash here.
425 if (isPrimary()) {
426 LOG_ALWAYS_FATAL("ANativeWindow::queueBuffer failed with error: %d", res);
427 } else {
428 mNativeWindow->cancelBuffer(mNativeWindow.get(),
429 mGraphicBuffer->getNativeBuffer(), fd);
430 }
431 }
432 mGraphicBuffer = nullptr;
433 }
Mathias Agopianda27af92012-09-13 18:17:13 -0700434 }
Mathias Agopian52e21482012-09-24 18:07:21 -0700435
Jesse Hall99c7dbb2013-03-14 14:29:29 -0700436 status_t result = mDisplaySurface->advanceFrame();
437 if (result != NO_ERROR) {
Dominik Laskowskibf170d92018-04-19 15:08:05 -0700438 ALOGE("[%s] failed pushing new frame to HWC: %d", mDisplayName.c_str(), result);
Mathias Agopian32341382012-09-25 19:16:28 -0700439 }
Mathias Agopianda27af92012-09-13 18:17:13 -0700440}
441
Alec Mouri0a9c7b82018-11-16 13:05:25 -0800442void DisplayDevice::onPresentDisplayCompleted() {
Dan Stoza9e56aa02015-11-02 13:00:03 -0800443 mDisplaySurface->onFrameCommitted();
444}
Mathias Agopianda27af92012-09-13 18:17:13 -0700445
Alec Mouri05874642018-11-14 22:34:02 +0000446bool DisplayDevice::makeCurrent() const {
447 bool success = mFlinger->getRenderEngine().setCurrentSurface(*mSurface);
448 setViewportAndProjection();
449 return success;
450}
451
Mathias Agopian875d8e12013-06-07 15:35:48 -0700452void DisplayDevice::setViewportAndProjection() const {
453 size_t w = mDisplayWidth;
454 size_t h = mDisplayHeight;
Dan Stozac1879002014-05-22 15:59:05 -0700455 Rect sourceCrop(0, 0, w, h);
Chia-I Wu1be50b52018-08-29 10:44:48 -0700456 mFlinger->getRenderEngine().setViewportAndProjection(w, h, sourceCrop, ui::Transform::ROT_0);
Mathias Agopianbae92d02012-09-28 01:00:47 -0700457}
458
Alec Mouri0a9c7b82018-11-16 13:05:25 -0800459void DisplayDevice::finishBuffer() {
460 mBufferReady = mFlinger->getRenderEngine().flush();
461 if (mBufferReady.get() < 0) {
462 mFlinger->getRenderEngine().finish();
463 }
464}
465
Dan Stoza9e56aa02015-11-02 13:00:03 -0800466const sp<Fence>& DisplayDevice::getClientTargetAcquireFence() const {
467 return mDisplaySurface->getClientTargetAcquireFence();
468}
Dan Stoza9e56aa02015-11-02 13:00:03 -0800469
Mathias Agopian1b031492012-06-20 17:51:20 -0700470// ----------------------------------------------------------------------------
471
Mathias Agopian13127d82013-03-05 17:47:11 -0800472void DisplayDevice::setVisibleLayersSortedByZ(const Vector< sp<Layer> >& layers) {
Mathias Agopian3b1d2b62012-07-11 13:48:17 -0700473 mVisibleLayersSortedByZ = layers;
Mathias Agopian3b1d2b62012-07-11 13:48:17 -0700474}
475
Mathias Agopian13127d82013-03-05 17:47:11 -0800476const Vector< sp<Layer> >& DisplayDevice::getVisibleLayersSortedByZ() const {
Mathias Agopian3b1d2b62012-07-11 13:48:17 -0700477 return mVisibleLayersSortedByZ;
478}
479
Chia-I Wu83806892017-11-16 10:50:20 -0800480void DisplayDevice::setLayersNeedingFences(const Vector< sp<Layer> >& layers) {
481 mLayersNeedingFences = layers;
482}
483
484const Vector< sp<Layer> >& DisplayDevice::getLayersNeedingFences() const {
485 return mLayersNeedingFences;
486}
487
Mathias Agopiancd60f992012-08-16 16:28:27 -0700488Region DisplayDevice::getDirtyRegion(bool repaintEverything) const {
489 Region dirty;
Mathias Agopiancd60f992012-08-16 16:28:27 -0700490 if (repaintEverything) {
491 dirty.set(getBounds());
492 } else {
Peiyong Linefefaac2018-08-17 12:27:51 -0700493 const ui::Transform& planeTransform(mGlobalTransform);
Mathias Agopiancd60f992012-08-16 16:28:27 -0700494 dirty = planeTransform.transform(this->dirtyRegion);
495 dirty.andSelf(getBounds());
496 }
497 return dirty;
498}
499
Mathias Agopian3b1d2b62012-07-11 13:48:17 -0700500// ----------------------------------------------------------------------------
Prashant Malani2c9b11f2014-05-25 01:36:31 -0700501void DisplayDevice::setPowerMode(int mode) {
502 mPowerMode = mode;
Mathias Agopiand3ee2312012-08-02 14:01:42 -0700503}
504
Prashant Malani2c9b11f2014-05-25 01:36:31 -0700505int DisplayDevice::getPowerMode() const {
506 return mPowerMode;
Mathias Agopiand3ee2312012-08-02 14:01:42 -0700507}
508
Dominik Laskowskieecd6592018-05-29 10:25:41 -0700509bool DisplayDevice::isPoweredOn() const {
510 return mPowerMode != HWC_POWER_MODE_OFF;
Mathias Agopiand3ee2312012-08-02 14:01:42 -0700511}
512
513// ----------------------------------------------------------------------------
Michael Lentine6c9e34a2014-07-14 13:48:55 -0700514void DisplayDevice::setActiveConfig(int mode) {
515 mActiveConfig = mode;
516}
517
518int DisplayDevice::getActiveConfig() const {
519 return mActiveConfig;
520}
521
522// ----------------------------------------------------------------------------
Peiyong Lina52f0292018-03-14 17:26:31 -0700523void DisplayDevice::setActiveColorMode(ColorMode mode) {
Michael Wright28f24d02016-07-12 13:30:53 -0700524 mActiveColorMode = mode;
525}
526
Peiyong Lina52f0292018-03-14 17:26:31 -0700527ColorMode DisplayDevice::getActiveColorMode() const {
Michael Wright28f24d02016-07-12 13:30:53 -0700528 return mActiveColorMode;
529}
Courtney Goeltzenleuchter79d27242017-07-13 17:54:01 -0600530
Peiyong Lindd9b2ae2018-03-01 16:22:45 -0800531RenderIntent DisplayDevice::getActiveRenderIntent() const {
532 return mActiveRenderIntent;
533}
534
535void DisplayDevice::setActiveRenderIntent(RenderIntent renderIntent) {
536 mActiveRenderIntent = renderIntent;
537}
538
Yiwei Zhang7c64f172018-03-07 14:52:28 -0800539void DisplayDevice::setColorTransform(const mat4& transform) {
540 const bool isIdentity = (transform == mat4());
541 mColorTransform =
542 isIdentity ? HAL_COLOR_TRANSFORM_IDENTITY : HAL_COLOR_TRANSFORM_ARBITRARY_MATRIX;
543}
544
545android_color_transform_t DisplayDevice::getColorTransform() const {
546 return mColorTransform;
547}
548
Peiyong Lin34beb7a2018-03-28 11:57:12 -0700549void DisplayDevice::setCompositionDataSpace(ui::Dataspace dataspace) {
Peiyong Lindd9b2ae2018-03-01 16:22:45 -0800550 mCompositionDataSpace = dataspace;
Courtney Goeltzenleuchter79d27242017-07-13 17:54:01 -0600551 ANativeWindow* const window = mNativeWindow.get();
Peiyong Lin34beb7a2018-03-28 11:57:12 -0700552 native_window_set_buffers_data_space(window, static_cast<android_dataspace>(dataspace));
Courtney Goeltzenleuchter79d27242017-07-13 17:54:01 -0600553}
Michael Wright28f24d02016-07-12 13:30:53 -0700554
Peiyong Lindd9b2ae2018-03-01 16:22:45 -0800555ui::Dataspace DisplayDevice::getCompositionDataSpace() const {
556 return mCompositionDataSpace;
557}
558
Michael Wright28f24d02016-07-12 13:30:53 -0700559// ----------------------------------------------------------------------------
Mathias Agopiand3ee2312012-08-02 14:01:42 -0700560
Mathias Agopian28947d72012-08-08 18:51:15 -0700561void DisplayDevice::setLayerStack(uint32_t stack) {
562 mLayerStack = stack;
563 dirtyRegion.set(bounds());
564}
565
566// ----------------------------------------------------------------------------
567
Mathias Agopianc1c05de2013-09-17 23:45:22 -0700568uint32_t DisplayDevice::getOrientationTransform() const {
569 uint32_t transform = 0;
570 switch (mOrientation) {
571 case DisplayState::eOrientationDefault:
Peiyong Linefefaac2018-08-17 12:27:51 -0700572 transform = ui::Transform::ROT_0;
Mathias Agopianc1c05de2013-09-17 23:45:22 -0700573 break;
574 case DisplayState::eOrientation90:
Peiyong Linefefaac2018-08-17 12:27:51 -0700575 transform = ui::Transform::ROT_90;
Mathias Agopianc1c05de2013-09-17 23:45:22 -0700576 break;
577 case DisplayState::eOrientation180:
Peiyong Linefefaac2018-08-17 12:27:51 -0700578 transform = ui::Transform::ROT_180;
Mathias Agopianc1c05de2013-09-17 23:45:22 -0700579 break;
580 case DisplayState::eOrientation270:
Peiyong Linefefaac2018-08-17 12:27:51 -0700581 transform = ui::Transform::ROT_270;
Mathias Agopianc1c05de2013-09-17 23:45:22 -0700582 break;
583 }
584 return transform;
585}
586
Mathias Agopian0f2f5ff2012-07-31 23:09:07 -0700587status_t DisplayDevice::orientationToTransfrom(
Peiyong Linefefaac2018-08-17 12:27:51 -0700588 int orientation, int w, int h, ui::Transform* tr)
Mathias Agopian1b031492012-06-20 17:51:20 -0700589{
590 uint32_t flags = 0;
591 switch (orientation) {
Mathias Agopian3165cc22012-08-08 19:42:09 -0700592 case DisplayState::eOrientationDefault:
Peiyong Linefefaac2018-08-17 12:27:51 -0700593 flags = ui::Transform::ROT_0;
Mathias Agopian1b031492012-06-20 17:51:20 -0700594 break;
Mathias Agopian3165cc22012-08-08 19:42:09 -0700595 case DisplayState::eOrientation90:
Peiyong Linefefaac2018-08-17 12:27:51 -0700596 flags = ui::Transform::ROT_90;
Mathias Agopian1b031492012-06-20 17:51:20 -0700597 break;
Mathias Agopian3165cc22012-08-08 19:42:09 -0700598 case DisplayState::eOrientation180:
Peiyong Linefefaac2018-08-17 12:27:51 -0700599 flags = ui::Transform::ROT_180;
Mathias Agopian1b031492012-06-20 17:51:20 -0700600 break;
Mathias Agopian3165cc22012-08-08 19:42:09 -0700601 case DisplayState::eOrientation270:
Peiyong Linefefaac2018-08-17 12:27:51 -0700602 flags = ui::Transform::ROT_270;
Mathias Agopian1b031492012-06-20 17:51:20 -0700603 break;
604 default:
605 return BAD_VALUE;
606 }
607 tr->set(flags, w, h);
608 return NO_ERROR;
609}
610
Michael Lentine47e45402014-07-18 15:34:25 -0700611void DisplayDevice::setDisplaySize(const int newWidth, const int newHeight) {
612 dirtyRegion.set(getBounds());
613
Alec Mouri05874642018-11-14 22:34:02 +0000614 mSurface->setNativeWindow(nullptr);
615
Michael Lentine47e45402014-07-18 15:34:25 -0700616 mDisplaySurface->resizeBuffers(newWidth, newHeight);
617
Alec Mouri05874642018-11-14 22:34:02 +0000618 ANativeWindow* const window = mNativeWindow.get();
619 mSurface->setNativeWindow(window);
Alec Mouriba013fa2018-10-16 12:43:11 -0700620 mDisplayWidth = newWidth;
621 mDisplayHeight = newHeight;
Michael Lentine47e45402014-07-18 15:34:25 -0700622}
623
Mathias Agopian00e8c7a2012-09-04 19:30:46 -0700624void DisplayDevice::setProjection(int orientation,
Mathias Agopianf5f714a2013-02-26 16:54:05 -0800625 const Rect& newViewport, const Rect& newFrame) {
626 Rect viewport(newViewport);
627 Rect frame(newFrame);
628
629 const int w = mDisplayWidth;
630 const int h = mDisplayHeight;
631
Peiyong Linefefaac2018-08-17 12:27:51 -0700632 ui::Transform R;
Mathias Agopianf5f714a2013-02-26 16:54:05 -0800633 DisplayDevice::orientationToTransfrom(orientation, w, h, &R);
634
635 if (!frame.isValid()) {
636 // the destination frame can be invalid if it has never been set,
637 // in that case we assume the whole display frame.
638 frame = Rect(w, h);
639 }
640
641 if (viewport.isEmpty()) {
642 // viewport can be invalid if it has never been set, in that case
643 // we assume the whole display size.
644 // it's also invalid to have an empty viewport, so we handle that
645 // case in the same way.
646 viewport = Rect(w, h);
Peiyong Linefefaac2018-08-17 12:27:51 -0700647 if (R.getOrientation() & ui::Transform::ROT_90) {
Mathias Agopianf5f714a2013-02-26 16:54:05 -0800648 // viewport is always specified in the logical orientation
649 // of the display (ie: post-rotation).
Peiyong Lin3db42342018-08-16 09:15:59 -0700650 std::swap(viewport.right, viewport.bottom);
Mathias Agopianf5f714a2013-02-26 16:54:05 -0800651 }
652 }
653
654 dirtyRegion.set(getBounds());
655
Peiyong Linefefaac2018-08-17 12:27:51 -0700656 ui::Transform TL, TP, S;
Mathias Agopianf5f714a2013-02-26 16:54:05 -0800657 float src_width = viewport.width();
658 float src_height = viewport.height();
659 float dst_width = frame.width();
660 float dst_height = frame.height();
661 if (src_width != dst_width || src_height != dst_height) {
662 float sx = dst_width / src_width;
663 float sy = dst_height / src_height;
664 S.set(sx, 0, 0, sy);
665 }
666
667 float src_x = viewport.left;
668 float src_y = viewport.top;
669 float dst_x = frame.left;
670 float dst_y = frame.top;
671 TL.set(-src_x, -src_y);
672 TP.set(dst_x, dst_y);
673
Iris Chang7501ed62018-04-30 14:45:42 +0800674 // need to take care of primary display rotation for mGlobalTransform
675 // for case if the panel is not installed aligned with device orientation
Dominik Laskowski075d3172018-05-24 15:50:06 -0700676 if (isPrimary()) {
Iris Chang7501ed62018-04-30 14:45:42 +0800677 DisplayDevice::orientationToTransfrom(
Chia-I Wua02871c2018-08-27 14:38:23 -0700678 (orientation + mDisplayInstallOrientation) % (DisplayState::eOrientation270 + 1),
Iris Chang7501ed62018-04-30 14:45:42 +0800679 w, h, &R);
680 }
681
Mathias Agopianf5f714a2013-02-26 16:54:05 -0800682 // The viewport and frame are both in the logical orientation.
683 // Apply the logical translation, scale to physical size, apply the
684 // physical translation and finally rotate to the physical orientation.
685 mGlobalTransform = R * TP * S * TL;
686
687 const uint8_t type = mGlobalTransform.getType();
688 mNeedsFiltering = (!mGlobalTransform.preserveRects() ||
Peiyong Linefefaac2018-08-17 12:27:51 -0700689 (type >= ui::Transform::SCALE));
Mathias Agopianf5f714a2013-02-26 16:54:05 -0800690
691 mScissor = mGlobalTransform.transform(viewport);
692 if (mScissor.isEmpty()) {
Mathias Agopian6c7f25a2013-05-09 20:37:10 -0700693 mScissor = getBounds();
Mathias Agopianf5f714a2013-02-26 16:54:05 -0800694 }
695
Mathias Agopianda8d0a52012-09-04 15:05:38 -0700696 mOrientation = orientation;
Dominik Laskowski281644e2018-04-19 15:47:35 -0700697 if (isPrimary()) {
Pablo Ceballos021623b2016-04-15 17:31:51 -0700698 uint32_t transform = 0;
699 switch (mOrientation) {
700 case DisplayState::eOrientationDefault:
Peiyong Linefefaac2018-08-17 12:27:51 -0700701 transform = ui::Transform::ROT_0;
Pablo Ceballos021623b2016-04-15 17:31:51 -0700702 break;
703 case DisplayState::eOrientation90:
Peiyong Linefefaac2018-08-17 12:27:51 -0700704 transform = ui::Transform::ROT_90;
Pablo Ceballos021623b2016-04-15 17:31:51 -0700705 break;
706 case DisplayState::eOrientation180:
Peiyong Linefefaac2018-08-17 12:27:51 -0700707 transform = ui::Transform::ROT_180;
Pablo Ceballos021623b2016-04-15 17:31:51 -0700708 break;
709 case DisplayState::eOrientation270:
Peiyong Linefefaac2018-08-17 12:27:51 -0700710 transform = ui::Transform::ROT_270;
Pablo Ceballos021623b2016-04-15 17:31:51 -0700711 break;
712 }
713 sPrimaryDisplayOrientation = transform;
714 }
Mathias Agopian00e8c7a2012-09-04 19:30:46 -0700715 mViewport = viewport;
716 mFrame = frame;
Mathias Agopian1b031492012-06-20 17:51:20 -0700717}
Mathias Agopian1d12d8a2012-09-18 01:38:00 -0700718
Pablo Ceballos021623b2016-04-15 17:31:51 -0700719uint32_t DisplayDevice::getPrimaryDisplayOrientationTransform() {
720 return sPrimaryDisplayOrientation;
721}
722
Dominik Laskowski9b17b2c22018-11-01 14:49:03 -0700723std::string DisplayDevice::getDebugName() const {
Dominik Laskowski34157762018-10-31 13:07:19 -0700724 const auto id = mId ? to_string(*mId) + ", " : std::string();
Dominik Laskowski9b17b2c22018-11-01 14:49:03 -0700725 return base::StringPrintf("DisplayDevice{%s%s%s\"%s\"}", id.c_str(),
726 isPrimary() ? "primary, " : "", isVirtual() ? "virtual, " : "",
727 mDisplayName.c_str());
728}
729
Mathias Agopian74d211a2013-04-22 16:55:35 +0200730void DisplayDevice::dump(String8& result) const {
Peiyong Linefefaac2018-08-17 12:27:51 -0700731 const ui::Transform& tr(mGlobalTransform);
Courtney Goeltzenleuchter152279d2017-08-14 18:18:30 -0600732 ANativeWindow* const window = mNativeWindow.get();
Dominik Laskowski9b17b2c22018-11-01 14:49:03 -0700733 result.appendFormat("+ %s\n", getDebugName().c_str());
734 result.appendFormat(" layerStack=%u, (%4dx%4d), ANativeWindow=%p "
Alec Mouri05874642018-11-14 22:34:02 +0000735 "(%d:%d:%d:%d), orient=%2d (type=%08x), "
736 "flips=%u, isSecure=%d, powerMode=%d, activeConfig=%d, numLayers=%zu\n",
Dominik Laskowski9b17b2c22018-11-01 14:49:03 -0700737 mLayerStack, mDisplayWidth, mDisplayHeight, window,
Alec Mouri05874642018-11-14 22:34:02 +0000738 mSurface->queryRedSize(), mSurface->queryGreenSize(),
739 mSurface->queryBlueSize(), mSurface->queryAlphaSize(), mOrientation,
740 tr.getType(), getPageFlipCount(), mIsSecure, mPowerMode, mActiveConfig,
Courtney Goeltzenleuchter0ebaac32017-04-13 12:17:03 -0600741 mVisibleLayersSortedByZ.size());
742 result.appendFormat(" v:[%d,%d,%d,%d], f:[%d,%d,%d,%d], s:[%d,%d,%d,%d],"
743 "transform:[[%0.3f,%0.3f,%0.3f][%0.3f,%0.3f,%0.3f][%0.3f,%0.3f,%0.3f]]\n",
744 mViewport.left, mViewport.top, mViewport.right, mViewport.bottom,
745 mFrame.left, mFrame.top, mFrame.right, mFrame.bottom, mScissor.left,
746 mScissor.top, mScissor.right, mScissor.bottom, tr[0][0], tr[1][0], tr[2][0],
747 tr[0][1], tr[1][1], tr[2][1], tr[0][2], tr[1][2], tr[2][2]);
Courtney Goeltzenleuchter152279d2017-08-14 18:18:30 -0600748 auto const surface = static_cast<Surface*>(window);
Peiyong Lin34beb7a2018-03-28 11:57:12 -0700749 ui::Dataspace dataspace = surface->getBuffersDataSpace();
Peiyong Lindd9b2ae2018-03-01 16:22:45 -0800750 result.appendFormat(" wideColorGamut=%d, hdr10=%d, colorMode=%s, dataspace: %s (%d)\n",
Alec Mouri05874642018-11-14 22:34:02 +0000751 mHasWideColorGamut, mHasHdr10,
752 decodeColorMode(mActiveColorMode).c_str(),
753 dataspaceDetails(static_cast<android_dataspace>(dataspace)).c_str(), dataspace);
Mathias Agopian1d12d8a2012-09-18 01:38:00 -0700754
Jesse Hall99c7dbb2013-03-14 14:29:29 -0700755 String8 surfaceDump;
Dan Stozaf10c46e2014-11-11 10:32:31 -0800756 mDisplaySurface->dumpAsString(surfaceDump);
Jesse Hall99c7dbb2013-03-14 14:29:29 -0700757 result.append(surfaceDump);
Mathias Agopian1d12d8a2012-09-18 01:38:00 -0700758}
Irvelffc9efc2016-07-27 15:16:37 -0700759
Chia-I Wube02ec02018-05-18 10:59:36 -0700760// Map dataspace/intent to the best matched dataspace/colorMode/renderIntent
761// supported by HWC.
762void DisplayDevice::addColorMode(
763 const std::unordered_map<ColorMode, std::vector<RenderIntent>>& hwcColorModes,
764 const ColorMode mode, const RenderIntent intent) {
765 // find the best color mode
766 const ColorMode hwcColorMode = getHwcColorMode(hwcColorModes, mode);
767
768 // find the best render intent
769 auto iter = hwcColorModes.find(hwcColorMode);
770 const auto& hwcIntents =
771 iter != hwcColorModes.end() ? iter->second : std::vector<RenderIntent>();
772 const RenderIntent hwcIntent = getHwcRenderIntent(hwcIntents, intent);
773
774 const Dataspace dataspace = colorModeToDataspace(mode);
775 const Dataspace hwcDataspace = colorModeToDataspace(hwcColorMode);
776
Dominik Laskowski9b17b2c22018-11-01 14:49:03 -0700777 ALOGV("%s: map (%s, %s) to (%s, %s, %s)", getDebugName().c_str(),
Chia-I Wube02ec02018-05-18 10:59:36 -0700778 dataspaceDetails(static_cast<android_dataspace_t>(dataspace)).c_str(),
779 decodeRenderIntent(intent).c_str(),
780 dataspaceDetails(static_cast<android_dataspace_t>(hwcDataspace)).c_str(),
781 decodeColorMode(hwcColorMode).c_str(), decodeRenderIntent(hwcIntent).c_str());
782
783 mColorModes[getColorModeKey(dataspace, intent)] = {hwcDataspace, hwcColorMode, hwcIntent};
784}
785
786void DisplayDevice::populateColorModes(
787 const std::unordered_map<ColorMode, std::vector<RenderIntent>>& hwcColorModes) {
788 if (!hasWideColorGamut()) {
789 return;
790 }
791
Chia-I Wu0d711262018-05-21 15:19:35 -0700792 // collect all known SDR render intents
793 std::unordered_set<RenderIntent> sdrRenderIntents(sSdrRenderIntents.begin(),
794 sSdrRenderIntents.end());
795 auto iter = hwcColorModes.find(ColorMode::SRGB);
796 if (iter != hwcColorModes.end()) {
797 for (auto intent : iter->second) {
798 sdrRenderIntents.insert(intent);
799 }
800 }
801
Chia-I Wuc4b08bd2018-05-29 12:57:23 -0700802 // add all known SDR combinations
Chia-I Wu0d711262018-05-21 15:19:35 -0700803 for (auto intent : sdrRenderIntents) {
Chia-I Wube02ec02018-05-18 10:59:36 -0700804 for (auto mode : sSdrColorModes) {
805 addColorMode(hwcColorModes, mode, intent);
Peiyong Lin136fbbc2018-04-17 15:09:44 -0700806 }
807 }
Chia-I Wube02ec02018-05-18 10:59:36 -0700808
Chia-I Wuc4b08bd2018-05-29 12:57:23 -0700809 // collect all known HDR render intents
810 std::unordered_set<RenderIntent> hdrRenderIntents(sHdrRenderIntents.begin(),
811 sHdrRenderIntents.end());
812 iter = hwcColorModes.find(ColorMode::BT2100_PQ);
813 if (iter != hwcColorModes.end()) {
814 for (auto intent : iter->second) {
815 hdrRenderIntents.insert(intent);
816 }
817 }
818
819 // add all known HDR combinations
Chia-I Wube02ec02018-05-18 10:59:36 -0700820 for (auto intent : sHdrRenderIntents) {
821 for (auto mode : sHdrColorModes) {
822 addColorMode(hwcColorModes, mode, intent);
823 }
824 }
825}
826
827bool DisplayDevice::hasRenderIntent(RenderIntent intent) const {
828 // assume a render intent is supported when SRGB supports it; we should
829 // get rid of that assumption.
830 auto iter = mColorModes.find(getColorModeKey(Dataspace::SRGB, intent));
831 return iter != mColorModes.end() && iter->second.renderIntent == intent;
832}
833
Peiyong Lindfde5112018-06-05 10:58:41 -0700834bool DisplayDevice::hasLegacyHdrSupport(Dataspace dataspace) const {
Chia-I Wube02ec02018-05-18 10:59:36 -0700835 if ((dataspace == Dataspace::BT2020_PQ && hasHDR10Support()) ||
836 (dataspace == Dataspace::BT2020_HLG && hasHLGSupport())) {
837 auto iter =
838 mColorModes.find(getColorModeKey(dataspace, RenderIntent::TONE_MAP_COLORIMETRIC));
Peiyong Lindfde5112018-06-05 10:58:41 -0700839 return iter == mColorModes.end() || iter->second.dataspace != dataspace;
Chia-I Wube02ec02018-05-18 10:59:36 -0700840 }
841
842 return false;
843}
844
845void DisplayDevice::getBestColorMode(Dataspace dataspace, RenderIntent intent,
846 Dataspace* outDataspace, ColorMode* outMode,
847 RenderIntent* outIntent) const {
848 auto iter = mColorModes.find(getColorModeKey(dataspace, intent));
849 if (iter != mColorModes.end()) {
850 *outDataspace = iter->second.dataspace;
851 *outMode = iter->second.colorMode;
852 *outIntent = iter->second.renderIntent;
853 } else {
Chia-I Wu6333af52018-10-16 13:46:36 -0700854 // this is unexpected on a WCG display
855 if (hasWideColorGamut()) {
856 ALOGE("map unknown (%s)/(%s) to default color mode",
857 dataspaceDetails(static_cast<android_dataspace_t>(dataspace)).c_str(),
858 decodeRenderIntent(intent).c_str());
859 }
Chia-I Wube02ec02018-05-18 10:59:36 -0700860
861 *outDataspace = Dataspace::UNKNOWN;
862 *outMode = ColorMode::NATIVE;
863 *outIntent = RenderIntent::COLORIMETRIC;
864 }
Peiyong Lin136fbbc2018-04-17 15:09:44 -0700865}
866
Dominik Laskowski663bd282018-04-19 15:26:54 -0700867std::atomic<int32_t> DisplayDeviceState::sNextSequenceId(1);
Peiyong Linfd997e02018-03-28 15:29:00 -0700868
869} // namespace android