blob: 2003fb15d9a29a5ce338306959341017f71223a6 [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),
242 mHasHdr10(false),
243 mHasHLG(false),
244 mHasDolbyVision(false),
Dominik Laskowski075d3172018-05-24 15:50:06 -0700245 mSupportedPerFrameMetadata(args.supportedPerFrameMetadata),
246 mIsPrimary(args.isPrimary) {
Lloyd Pique2eef1d22018-09-18 21:30:04 -0700247 populateColorModes(args.hwcColorModes);
248
249 ALOGE_IF(!mNativeWindow, "No native window was set for display");
250 ALOGE_IF(!mDisplaySurface, "No display 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
Peiyong Linfb530cf2018-12-15 05:07:38 +0000369void DisplayDevice::setProtected(bool useProtected) {
370 uint64_t usageFlags = GRALLOC_USAGE_HW_RENDER;
371 if (useProtected) {
372 usageFlags |= GRALLOC_USAGE_PROTECTED;
373 }
374 const int status = native_window_set_usage(mNativeWindow.get(), usageFlags);
375 ALOGE_IF(status != NO_ERROR, "Unable to set BQ usage bits for protected content: %d", status);
376}
377
Alec Mouri0a9c7b82018-11-16 13:05:25 -0800378sp<GraphicBuffer> DisplayDevice::dequeueBuffer() {
379 int fd;
380 ANativeWindowBuffer* buffer;
381
382 status_t res = mNativeWindow->dequeueBuffer(mNativeWindow.get(), &buffer, &fd);
383
384 if (res != NO_ERROR) {
385 ALOGE("ANativeWindow::dequeueBuffer failed for display [%s] with error: %d",
386 getDisplayName().c_str(), res);
387 // Return fast here as we can't do much more - any rendering we do
388 // now will just be wrong.
389 return mGraphicBuffer;
390 }
391
392 ALOGW_IF(mGraphicBuffer != nullptr, "Clobbering a non-null pointer to a buffer [%p].",
393 mGraphicBuffer->getNativeBuffer()->handle);
394 mGraphicBuffer = GraphicBuffer::from(buffer);
395
396 // Block until the buffer is ready
397 // TODO(alecmouri): it's perhaps more appropriate to block renderengine so
398 // that the gl driver can block instead.
399 if (fd >= 0) {
400 sync_wait(fd, -1);
401 close(fd);
402 }
403
404 return mGraphicBuffer;
405}
406
407void DisplayDevice::queueBuffer(HWComposer& hwc) {
Dominik Laskowski7e045462018-05-30 13:02:02 -0700408 if (hwc.hasClientComposition(mId) || hwc.hasFlipClientTargetRequest(mId)) {
Alec Mouri0a9c7b82018-11-16 13:05:25 -0800409 // hasFlipClientTargetRequest could return true even if we haven't
410 // dequeued a buffer before. Try dequeueing one if we don't have a
411 // buffer ready.
412 if (mGraphicBuffer == nullptr) {
413 ALOGI("Attempting to queue a client composited buffer without one "
414 "previously dequeued for display [%s]. Attempting to dequeue "
415 "a scratch buffer now",
416 mDisplayName.c_str());
417 // We shouldn't deadlock here, since mGraphicBuffer == nullptr only
418 // after a successful call to queueBuffer, or if dequeueBuffer has
419 // never been called.
420 dequeueBuffer();
421 }
422
423 if (mGraphicBuffer == nullptr) {
424 ALOGE("No buffer is ready for display [%s]", mDisplayName.c_str());
425 } else {
Alec Mouri0a9c7b82018-11-16 13:05:25 -0800426 status_t res = mNativeWindow->queueBuffer(mNativeWindow.get(),
Alec Mouri745163a2018-12-04 15:15:50 -0800427 mGraphicBuffer->getNativeBuffer(),
428 dup(mBufferReady));
Alec Mouri0a9c7b82018-11-16 13:05:25 -0800429 if (res != NO_ERROR) {
430 ALOGE("Error when queueing buffer for display [%s]: %d", mDisplayName.c_str(), res);
431 // We risk blocking on dequeueBuffer if the primary display failed
432 // to queue up its buffer, so crash here.
433 if (isPrimary()) {
434 LOG_ALWAYS_FATAL("ANativeWindow::queueBuffer failed with error: %d", res);
435 } else {
436 mNativeWindow->cancelBuffer(mNativeWindow.get(),
Alec Mouri745163a2018-12-04 15:15:50 -0800437 mGraphicBuffer->getNativeBuffer(),
438 dup(mBufferReady));
Alec Mouri0a9c7b82018-11-16 13:05:25 -0800439 }
440 }
Alec Mouri745163a2018-12-04 15:15:50 -0800441
442 mBufferReady.reset();
Alec Mouri0a9c7b82018-11-16 13:05:25 -0800443 mGraphicBuffer = nullptr;
444 }
Mathias Agopianda27af92012-09-13 18:17:13 -0700445 }
Mathias Agopian52e21482012-09-24 18:07:21 -0700446
Jesse Hall99c7dbb2013-03-14 14:29:29 -0700447 status_t result = mDisplaySurface->advanceFrame();
448 if (result != NO_ERROR) {
Dominik Laskowskibf170d92018-04-19 15:08:05 -0700449 ALOGE("[%s] failed pushing new frame to HWC: %d", mDisplayName.c_str(), result);
Mathias Agopian32341382012-09-25 19:16:28 -0700450 }
Mathias Agopianda27af92012-09-13 18:17:13 -0700451}
452
Alec Mouri0a9c7b82018-11-16 13:05:25 -0800453void DisplayDevice::onPresentDisplayCompleted() {
Dan Stoza9e56aa02015-11-02 13:00:03 -0800454 mDisplaySurface->onFrameCommitted();
455}
Mathias Agopianda27af92012-09-13 18:17:13 -0700456
Mathias Agopian875d8e12013-06-07 15:35:48 -0700457void DisplayDevice::setViewportAndProjection() const {
458 size_t w = mDisplayWidth;
459 size_t h = mDisplayHeight;
Dan Stozac1879002014-05-22 15:59:05 -0700460 Rect sourceCrop(0, 0, w, h);
Chia-I Wu1be50b52018-08-29 10:44:48 -0700461 mFlinger->getRenderEngine().setViewportAndProjection(w, h, sourceCrop, ui::Transform::ROT_0);
Mathias Agopianbae92d02012-09-28 01:00:47 -0700462}
463
Alec Mouri0a9c7b82018-11-16 13:05:25 -0800464void DisplayDevice::finishBuffer() {
465 mBufferReady = mFlinger->getRenderEngine().flush();
466 if (mBufferReady.get() < 0) {
467 mFlinger->getRenderEngine().finish();
468 }
469}
470
Dan Stoza9e56aa02015-11-02 13:00:03 -0800471const sp<Fence>& DisplayDevice::getClientTargetAcquireFence() const {
472 return mDisplaySurface->getClientTargetAcquireFence();
473}
Dan Stoza9e56aa02015-11-02 13:00:03 -0800474
Mathias Agopian1b031492012-06-20 17:51:20 -0700475// ----------------------------------------------------------------------------
476
Mathias Agopian13127d82013-03-05 17:47:11 -0800477void DisplayDevice::setVisibleLayersSortedByZ(const Vector< sp<Layer> >& layers) {
Mathias Agopian3b1d2b62012-07-11 13:48:17 -0700478 mVisibleLayersSortedByZ = layers;
Mathias Agopian3b1d2b62012-07-11 13:48:17 -0700479}
480
Mathias Agopian13127d82013-03-05 17:47:11 -0800481const Vector< sp<Layer> >& DisplayDevice::getVisibleLayersSortedByZ() const {
Mathias Agopian3b1d2b62012-07-11 13:48:17 -0700482 return mVisibleLayersSortedByZ;
483}
484
Chia-I Wu83806892017-11-16 10:50:20 -0800485void DisplayDevice::setLayersNeedingFences(const Vector< sp<Layer> >& layers) {
486 mLayersNeedingFences = layers;
487}
488
489const Vector< sp<Layer> >& DisplayDevice::getLayersNeedingFences() const {
490 return mLayersNeedingFences;
491}
492
Mathias Agopiancd60f992012-08-16 16:28:27 -0700493Region DisplayDevice::getDirtyRegion(bool repaintEverything) const {
494 Region dirty;
Mathias Agopiancd60f992012-08-16 16:28:27 -0700495 if (repaintEverything) {
496 dirty.set(getBounds());
497 } else {
Peiyong Linefefaac2018-08-17 12:27:51 -0700498 const ui::Transform& planeTransform(mGlobalTransform);
Mathias Agopiancd60f992012-08-16 16:28:27 -0700499 dirty = planeTransform.transform(this->dirtyRegion);
500 dirty.andSelf(getBounds());
501 }
502 return dirty;
503}
504
Mathias Agopian3b1d2b62012-07-11 13:48:17 -0700505// ----------------------------------------------------------------------------
Prashant Malani2c9b11f2014-05-25 01:36:31 -0700506void DisplayDevice::setPowerMode(int mode) {
507 mPowerMode = mode;
Mathias Agopiand3ee2312012-08-02 14:01:42 -0700508}
509
Prashant Malani2c9b11f2014-05-25 01:36:31 -0700510int DisplayDevice::getPowerMode() const {
511 return mPowerMode;
Mathias Agopiand3ee2312012-08-02 14:01:42 -0700512}
513
Dominik Laskowskieecd6592018-05-29 10:25:41 -0700514bool DisplayDevice::isPoweredOn() const {
515 return mPowerMode != HWC_POWER_MODE_OFF;
Mathias Agopiand3ee2312012-08-02 14:01:42 -0700516}
517
518// ----------------------------------------------------------------------------
Michael Lentine6c9e34a2014-07-14 13:48:55 -0700519void DisplayDevice::setActiveConfig(int mode) {
520 mActiveConfig = mode;
521}
522
523int DisplayDevice::getActiveConfig() const {
524 return mActiveConfig;
525}
526
527// ----------------------------------------------------------------------------
Peiyong Lina52f0292018-03-14 17:26:31 -0700528void DisplayDevice::setActiveColorMode(ColorMode mode) {
Michael Wright28f24d02016-07-12 13:30:53 -0700529 mActiveColorMode = mode;
530}
531
Peiyong Lina52f0292018-03-14 17:26:31 -0700532ColorMode DisplayDevice::getActiveColorMode() const {
Michael Wright28f24d02016-07-12 13:30:53 -0700533 return mActiveColorMode;
534}
Courtney Goeltzenleuchter79d27242017-07-13 17:54:01 -0600535
Peiyong Lindd9b2ae2018-03-01 16:22:45 -0800536RenderIntent DisplayDevice::getActiveRenderIntent() const {
537 return mActiveRenderIntent;
538}
539
540void DisplayDevice::setActiveRenderIntent(RenderIntent renderIntent) {
541 mActiveRenderIntent = renderIntent;
542}
543
Yiwei Zhang7c64f172018-03-07 14:52:28 -0800544void DisplayDevice::setColorTransform(const mat4& transform) {
545 const bool isIdentity = (transform == mat4());
546 mColorTransform =
547 isIdentity ? HAL_COLOR_TRANSFORM_IDENTITY : HAL_COLOR_TRANSFORM_ARBITRARY_MATRIX;
548}
549
550android_color_transform_t DisplayDevice::getColorTransform() const {
551 return mColorTransform;
552}
553
Peiyong Lin34beb7a2018-03-28 11:57:12 -0700554void DisplayDevice::setCompositionDataSpace(ui::Dataspace dataspace) {
Peiyong Lindd9b2ae2018-03-01 16:22:45 -0800555 mCompositionDataSpace = dataspace;
Courtney Goeltzenleuchter79d27242017-07-13 17:54:01 -0600556 ANativeWindow* const window = mNativeWindow.get();
Peiyong Lin34beb7a2018-03-28 11:57:12 -0700557 native_window_set_buffers_data_space(window, static_cast<android_dataspace>(dataspace));
Courtney Goeltzenleuchter79d27242017-07-13 17:54:01 -0600558}
Michael Wright28f24d02016-07-12 13:30:53 -0700559
Peiyong Lindd9b2ae2018-03-01 16:22:45 -0800560ui::Dataspace DisplayDevice::getCompositionDataSpace() const {
561 return mCompositionDataSpace;
562}
563
Michael Wright28f24d02016-07-12 13:30:53 -0700564// ----------------------------------------------------------------------------
Mathias Agopiand3ee2312012-08-02 14:01:42 -0700565
Mathias Agopian28947d72012-08-08 18:51:15 -0700566void DisplayDevice::setLayerStack(uint32_t stack) {
567 mLayerStack = stack;
568 dirtyRegion.set(bounds());
569}
570
571// ----------------------------------------------------------------------------
572
Mathias Agopianc1c05de2013-09-17 23:45:22 -0700573uint32_t DisplayDevice::getOrientationTransform() const {
574 uint32_t transform = 0;
575 switch (mOrientation) {
576 case DisplayState::eOrientationDefault:
Peiyong Linefefaac2018-08-17 12:27:51 -0700577 transform = ui::Transform::ROT_0;
Mathias Agopianc1c05de2013-09-17 23:45:22 -0700578 break;
579 case DisplayState::eOrientation90:
Peiyong Linefefaac2018-08-17 12:27:51 -0700580 transform = ui::Transform::ROT_90;
Mathias Agopianc1c05de2013-09-17 23:45:22 -0700581 break;
582 case DisplayState::eOrientation180:
Peiyong Linefefaac2018-08-17 12:27:51 -0700583 transform = ui::Transform::ROT_180;
Mathias Agopianc1c05de2013-09-17 23:45:22 -0700584 break;
585 case DisplayState::eOrientation270:
Peiyong Linefefaac2018-08-17 12:27:51 -0700586 transform = ui::Transform::ROT_270;
Mathias Agopianc1c05de2013-09-17 23:45:22 -0700587 break;
588 }
589 return transform;
590}
591
Mathias Agopian0f2f5ff2012-07-31 23:09:07 -0700592status_t DisplayDevice::orientationToTransfrom(
Peiyong Linefefaac2018-08-17 12:27:51 -0700593 int orientation, int w, int h, ui::Transform* tr)
Mathias Agopian1b031492012-06-20 17:51:20 -0700594{
595 uint32_t flags = 0;
596 switch (orientation) {
Mathias Agopian3165cc22012-08-08 19:42:09 -0700597 case DisplayState::eOrientationDefault:
Peiyong Linefefaac2018-08-17 12:27:51 -0700598 flags = ui::Transform::ROT_0;
Mathias Agopian1b031492012-06-20 17:51:20 -0700599 break;
Mathias Agopian3165cc22012-08-08 19:42:09 -0700600 case DisplayState::eOrientation90:
Peiyong Linefefaac2018-08-17 12:27:51 -0700601 flags = ui::Transform::ROT_90;
Mathias Agopian1b031492012-06-20 17:51:20 -0700602 break;
Mathias Agopian3165cc22012-08-08 19:42:09 -0700603 case DisplayState::eOrientation180:
Peiyong Linefefaac2018-08-17 12:27:51 -0700604 flags = ui::Transform::ROT_180;
Mathias Agopian1b031492012-06-20 17:51:20 -0700605 break;
Mathias Agopian3165cc22012-08-08 19:42:09 -0700606 case DisplayState::eOrientation270:
Peiyong Linefefaac2018-08-17 12:27:51 -0700607 flags = ui::Transform::ROT_270;
Mathias Agopian1b031492012-06-20 17:51:20 -0700608 break;
609 default:
610 return BAD_VALUE;
611 }
612 tr->set(flags, w, h);
613 return NO_ERROR;
614}
615
Michael Lentine47e45402014-07-18 15:34:25 -0700616void DisplayDevice::setDisplaySize(const int newWidth, const int newHeight) {
617 dirtyRegion.set(getBounds());
618
619 mDisplaySurface->resizeBuffers(newWidth, newHeight);
620
Alec Mouriba013fa2018-10-16 12:43:11 -0700621 mDisplayWidth = newWidth;
622 mDisplayHeight = newHeight;
Michael Lentine47e45402014-07-18 15:34:25 -0700623}
624
Mathias Agopian00e8c7a2012-09-04 19:30:46 -0700625void DisplayDevice::setProjection(int orientation,
Mathias Agopianf5f714a2013-02-26 16:54:05 -0800626 const Rect& newViewport, const Rect& newFrame) {
627 Rect viewport(newViewport);
628 Rect frame(newFrame);
629
630 const int w = mDisplayWidth;
631 const int h = mDisplayHeight;
632
Peiyong Linefefaac2018-08-17 12:27:51 -0700633 ui::Transform R;
Mathias Agopianf5f714a2013-02-26 16:54:05 -0800634 DisplayDevice::orientationToTransfrom(orientation, w, h, &R);
635
636 if (!frame.isValid()) {
637 // the destination frame can be invalid if it has never been set,
638 // in that case we assume the whole display frame.
639 frame = Rect(w, h);
640 }
641
642 if (viewport.isEmpty()) {
643 // viewport can be invalid if it has never been set, in that case
644 // we assume the whole display size.
645 // it's also invalid to have an empty viewport, so we handle that
646 // case in the same way.
647 viewport = Rect(w, h);
Peiyong Linefefaac2018-08-17 12:27:51 -0700648 if (R.getOrientation() & ui::Transform::ROT_90) {
Mathias Agopianf5f714a2013-02-26 16:54:05 -0800649 // viewport is always specified in the logical orientation
650 // of the display (ie: post-rotation).
Peiyong Lin3db42342018-08-16 09:15:59 -0700651 std::swap(viewport.right, viewport.bottom);
Mathias Agopianf5f714a2013-02-26 16:54:05 -0800652 }
653 }
654
655 dirtyRegion.set(getBounds());
656
Peiyong Linefefaac2018-08-17 12:27:51 -0700657 ui::Transform TL, TP, S;
Mathias Agopianf5f714a2013-02-26 16:54:05 -0800658 float src_width = viewport.width();
659 float src_height = viewport.height();
660 float dst_width = frame.width();
661 float dst_height = frame.height();
662 if (src_width != dst_width || src_height != dst_height) {
663 float sx = dst_width / src_width;
664 float sy = dst_height / src_height;
665 S.set(sx, 0, 0, sy);
666 }
667
668 float src_x = viewport.left;
669 float src_y = viewport.top;
670 float dst_x = frame.left;
671 float dst_y = frame.top;
672 TL.set(-src_x, -src_y);
673 TP.set(dst_x, dst_y);
674
Iris Chang7501ed62018-04-30 14:45:42 +0800675 // need to take care of primary display rotation for mGlobalTransform
676 // for case if the panel is not installed aligned with device orientation
Dominik Laskowski075d3172018-05-24 15:50:06 -0700677 if (isPrimary()) {
Iris Chang7501ed62018-04-30 14:45:42 +0800678 DisplayDevice::orientationToTransfrom(
Chia-I Wua02871c2018-08-27 14:38:23 -0700679 (orientation + mDisplayInstallOrientation) % (DisplayState::eOrientation270 + 1),
Iris Chang7501ed62018-04-30 14:45:42 +0800680 w, h, &R);
681 }
682
Mathias Agopianf5f714a2013-02-26 16:54:05 -0800683 // The viewport and frame are both in the logical orientation.
684 // Apply the logical translation, scale to physical size, apply the
685 // physical translation and finally rotate to the physical orientation.
686 mGlobalTransform = R * TP * S * TL;
687
688 const uint8_t type = mGlobalTransform.getType();
689 mNeedsFiltering = (!mGlobalTransform.preserveRects() ||
Peiyong Linefefaac2018-08-17 12:27:51 -0700690 (type >= ui::Transform::SCALE));
Mathias Agopianf5f714a2013-02-26 16:54:05 -0800691
692 mScissor = mGlobalTransform.transform(viewport);
693 if (mScissor.isEmpty()) {
Mathias Agopian6c7f25a2013-05-09 20:37:10 -0700694 mScissor = getBounds();
Mathias Agopianf5f714a2013-02-26 16:54:05 -0800695 }
696
Mathias Agopianda8d0a52012-09-04 15:05:38 -0700697 mOrientation = orientation;
Dominik Laskowski281644e2018-04-19 15:47:35 -0700698 if (isPrimary()) {
Pablo Ceballos021623b2016-04-15 17:31:51 -0700699 uint32_t transform = 0;
700 switch (mOrientation) {
701 case DisplayState::eOrientationDefault:
Peiyong Linefefaac2018-08-17 12:27:51 -0700702 transform = ui::Transform::ROT_0;
Pablo Ceballos021623b2016-04-15 17:31:51 -0700703 break;
704 case DisplayState::eOrientation90:
Peiyong Linefefaac2018-08-17 12:27:51 -0700705 transform = ui::Transform::ROT_90;
Pablo Ceballos021623b2016-04-15 17:31:51 -0700706 break;
707 case DisplayState::eOrientation180:
Peiyong Linefefaac2018-08-17 12:27:51 -0700708 transform = ui::Transform::ROT_180;
Pablo Ceballos021623b2016-04-15 17:31:51 -0700709 break;
710 case DisplayState::eOrientation270:
Peiyong Linefefaac2018-08-17 12:27:51 -0700711 transform = ui::Transform::ROT_270;
Pablo Ceballos021623b2016-04-15 17:31:51 -0700712 break;
713 }
714 sPrimaryDisplayOrientation = transform;
715 }
Mathias Agopian00e8c7a2012-09-04 19:30:46 -0700716 mViewport = viewport;
717 mFrame = frame;
Mathias Agopian1b031492012-06-20 17:51:20 -0700718}
Mathias Agopian1d12d8a2012-09-18 01:38:00 -0700719
Pablo Ceballos021623b2016-04-15 17:31:51 -0700720uint32_t DisplayDevice::getPrimaryDisplayOrientationTransform() {
721 return sPrimaryDisplayOrientation;
722}
723
Dominik Laskowski9b17b2c22018-11-01 14:49:03 -0700724std::string DisplayDevice::getDebugName() const {
Dominik Laskowski34157762018-10-31 13:07:19 -0700725 const auto id = mId ? to_string(*mId) + ", " : std::string();
Dominik Laskowski9b17b2c22018-11-01 14:49:03 -0700726 return base::StringPrintf("DisplayDevice{%s%s%s\"%s\"}", id.c_str(),
727 isPrimary() ? "primary, " : "", isVirtual() ? "virtual, " : "",
728 mDisplayName.c_str());
729}
730
Yiwei Zhang5434a782018-12-05 18:06:32 -0800731void DisplayDevice::dump(std::string& result) const {
Peiyong Linefefaac2018-08-17 12:27:51 -0700732 const ui::Transform& tr(mGlobalTransform);
Courtney Goeltzenleuchter152279d2017-08-14 18:18:30 -0600733 ANativeWindow* const window = mNativeWindow.get();
Yiwei Zhang5434a782018-12-05 18:06:32 -0800734 StringAppendF(&result, "+ %s\n", getDebugName().c_str());
735 StringAppendF(&result,
736 " layerStack=%u, (%4dx%4d), ANativeWindow=%p "
737 "format=%d, orient=%2d (type=%08x), flips=%u, isSecure=%d, "
738 "powerMode=%d, activeConfig=%d, numLayers=%zu\n",
739 mLayerStack, mDisplayWidth, mDisplayHeight, window,
740 ANativeWindow_getFormat(window), mOrientation, tr.getType(), getPageFlipCount(),
741 mIsSecure, mPowerMode, mActiveConfig, mVisibleLayersSortedByZ.size());
742 StringAppendF(&result,
743 " v:[%d,%d,%d,%d], f:[%d,%d,%d,%d], s:[%d,%d,%d,%d],"
744 "transform:[[%0.3f,%0.3f,%0.3f][%0.3f,%0.3f,%0.3f][%0.3f,%0.3f,%0.3f]]\n",
745 mViewport.left, mViewport.top, mViewport.right, mViewport.bottom, mFrame.left,
746 mFrame.top, mFrame.right, mFrame.bottom, mScissor.left, mScissor.top,
747 mScissor.right, mScissor.bottom, tr[0][0], tr[1][0], tr[2][0], tr[0][1], tr[1][1],
748 tr[2][1], tr[0][2], tr[1][2], tr[2][2]);
Courtney Goeltzenleuchter152279d2017-08-14 18:18:30 -0600749 auto const surface = static_cast<Surface*>(window);
Peiyong Lin34beb7a2018-03-28 11:57:12 -0700750 ui::Dataspace dataspace = surface->getBuffersDataSpace();
Yiwei Zhang5434a782018-12-05 18:06:32 -0800751 StringAppendF(&result, " wideColorGamut=%d, hdr10=%d, colorMode=%s, dataspace: %s (%d)\n",
752 mHasWideColorGamut, mHasHdr10, 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);
Yiwei Zhang5434a782018-12-05 18:06:32 -0800757 result.append(surfaceDump.string(), surfaceDump.size());
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.
Peiyong Lin14724e62018-12-05 07:27:30 -0800830 auto iter = mColorModes.find(getColorModeKey(Dataspace::V0_SRGB, intent));
Chia-I Wube02ec02018-05-18 10:59:36 -0700831 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