blob: bab6a710579bfb8555da99165aa602fd2dd0f8d1 [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
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -080021#include <stdlib.h>
22#include <stdio.h>
23#include <string.h>
24#include <math.h>
25
26#include <cutils/properties.h>
27
Mathias Agopian076b1cc2009-04-10 14:24:30 -070028#include <utils/RefBase.h>
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -080029#include <utils/Log.h>
30
Courtney Goeltzenleuchter152279d2017-08-14 18:18:30 -060031#include <ui/DebugUtils.h>
Mathias Agopianc666cae2012-07-25 18:56:13 -070032#include <ui/DisplayInfo.h>
Mathias Agopian076b1cc2009-04-10 14:24:30 -070033#include <ui/PixelFormat.h>
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -080034
Mathias Agopiane3c697f2013-02-14 17:11:02 -080035#include <gui/Surface.h>
Jamie Gennis1a4d8832012-08-02 20:11:05 -070036
Mathias Agopian076b1cc2009-04-10 14:24:30 -070037#include <hardware/gralloc.h>
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -080038
Jesse Hall99c7dbb2013-03-14 14:29:29 -070039#include "DisplayHardware/DisplaySurface.h"
Mathias Agopian1b031492012-06-20 17:51:20 -070040#include "DisplayHardware/HWComposer.h"
Dan Stoza9e56aa02015-11-02 13:00:03 -080041#include "DisplayHardware/HWC2.h"
Mathias Agopian875d8e12013-06-07 15:35:48 -070042#include "RenderEngine/RenderEngine.h"
Mathias Agopian1b031492012-06-20 17:51:20 -070043
Mathias Agopianda8d0a52012-09-04 15:05:38 -070044#include "clz.h"
Mathias Agopian0f2f5ff2012-07-31 23:09:07 -070045#include "DisplayDevice.h"
Mathias Agopianc7d14e22011-08-01 16:32:21 -070046#include "SurfaceFlinger.h"
Mathias Agopian13127d82013-03-05 17:47:11 -080047#include "Layer.h"
Mathias Agopian1f7bec62010-06-25 18:02:21 -070048
Jaesoo Lee720a7242017-01-31 15:26:18 +090049#include <android/hardware/configstore/1.0/ISurfaceFlingerConfigs.h>
50#include <configstore/Utils.h>
51
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;
Jaesoo Lee720a7242017-01-31 15:26:18 +090058
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -080059/*
60 * Initialize the display to the specified values.
61 *
62 */
63
Pablo Ceballos021623b2016-04-15 17:31:51 -070064uint32_t DisplayDevice::sPrimaryDisplayOrientation = 0;
65
Courtney Goeltzenleuchter5d943892017-03-22 13:46:46 -060066// clang-format off
Mathias Agopian0f2f5ff2012-07-31 23:09:07 -070067DisplayDevice::DisplayDevice(
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -080068 const sp<SurfaceFlinger>& flinger,
Jamie Gennisdd3cb842012-10-19 18:19:11 -070069 DisplayType type,
Jesse Hallffe1f192013-03-22 15:13:48 -070070 int32_t hwcId,
Jamie Gennisdd3cb842012-10-19 18:19:11 -070071 bool isSecure,
72 const wp<IBinder>& displayToken,
Lloyd Pique09594832018-01-22 17:48:03 -080073 const sp<ANativeWindow>& nativeWindow,
Jesse Hall99c7dbb2013-03-14 14:29:29 -070074 const sp<DisplaySurface>& displaySurface,
Lloyd Pique09594832018-01-22 17:48:03 -080075 std::unique_ptr<RE::Surface> renderSurface,
76 int displayWidth,
77 int displayHeight,
Chia-I Wu5c6e4632018-01-11 08:54:38 -080078 bool supportWideColor,
Lloyd Pique09594832018-01-22 17:48:03 -080079 bool supportHdr,
80 int initialPowerMode)
Jesse Hallb7a05492014-08-14 15:45:06 -070081 : lastCompositionHadVisibleLayers(false),
82 mFlinger(flinger),
Dan Stoza9e56aa02015-11-02 13:00:03 -080083 mType(type),
84 mHwcDisplayId(hwcId),
Chih-Wei Huang27e25622013-01-07 17:33:56 +080085 mDisplayToken(displayToken),
Lloyd Pique09594832018-01-22 17:48:03 -080086 mNativeWindow(nativeWindow),
Jesse Hall99c7dbb2013-03-14 14:29:29 -070087 mDisplaySurface(displaySurface),
Lloyd Pique09594832018-01-22 17:48:03 -080088 mSurface{std::move(renderSurface)},
89 mDisplayWidth(displayWidth),
90 mDisplayHeight(displayHeight),
91 mPageFlipCount(0),
Jamie Gennisdd3cb842012-10-19 18:19:11 -070092 mIsSecure(isSecure),
Jesse Hall01e29052013-02-19 16:13:35 -080093 mLayerStack(NO_LAYER_STACK),
Prashant Malani2c9b11f2014-05-25 01:36:31 -070094 mOrientation(),
Lloyd Pique09594832018-01-22 17:48:03 -080095 mViewport(Rect::INVALID_RECT),
96 mFrame(Rect::INVALID_RECT),
97 mPowerMode(initialPowerMode),
98 mActiveConfig(0),
99 mActiveColorMode(ColorMode::NATIVE),
100 mDisplayHasWideColor(supportWideColor),
101 mDisplayHasHdr(supportHdr)
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800102{
Courtney Goeltzenleuchter5d943892017-03-22 13:46:46 -0600103 // clang-format on
Jesse Hallffe1f192013-03-22 15:13:48 -0700104
Jesse Hallffe1f192013-03-22 15:13:48 -0700105 // initialize the display orientation transform.
106 setProjection(DisplayState::eOrientationDefault, mViewport, mFrame);
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800107}
108
Lloyd Pique09594832018-01-22 17:48:03 -0800109DisplayDevice::~DisplayDevice() = default;
Mathias Agopian92a979a2012-08-02 18:32:23 -0700110
Jesse Hall02d86562013-03-25 14:43:23 -0700111void DisplayDevice::disconnect(HWComposer& hwc) {
112 if (mHwcDisplayId >= 0) {
113 hwc.disconnectDisplay(mHwcDisplayId);
Jesse Hall02d86562013-03-25 14:43:23 -0700114 mHwcDisplayId = -1;
115 }
116}
117
Mathias Agopian92a979a2012-08-02 18:32:23 -0700118bool DisplayDevice::isValid() const {
Peiyong Lin566a3b42018-01-09 18:22:43 -0800119 return mFlinger != nullptr;
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800120}
121
Mathias Agopian0f2f5ff2012-07-31 23:09:07 -0700122int DisplayDevice::getWidth() const {
Mathias Agopiana4912602012-07-12 14:25:33 -0700123 return mDisplayWidth;
124}
125
Mathias Agopian0f2f5ff2012-07-31 23:09:07 -0700126int DisplayDevice::getHeight() const {
Mathias Agopiana4912602012-07-12 14:25:33 -0700127 return mDisplayHeight;
128}
129
Mathias Agopian9e2463e2012-09-21 18:26:16 -0700130void DisplayDevice::setDisplayName(const String8& displayName) {
131 if (!displayName.isEmpty()) {
132 // never override the name with an empty name
133 mDisplayName = displayName;
134 }
135}
136
Mathias Agopian0f2f5ff2012-07-31 23:09:07 -0700137uint32_t DisplayDevice::getPageFlipCount() const {
Mathias Agopian076b1cc2009-04-10 14:24:30 -0700138 return mPageFlipCount;
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800139}
140
Chia-I Wub02087d2017-11-09 10:19:54 -0800141void DisplayDevice::flip() const
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800142{
Mathias Agopian875d8e12013-06-07 15:35:48 -0700143 mFlinger->getRenderEngine().checkErrors();
Mathias Agopian076b1cc2009-04-10 14:24:30 -0700144 mPageFlipCount++;
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800145}
146
Dan Stoza71433162014-02-04 16:22:36 -0800147status_t DisplayDevice::beginFrame(bool mustRecompose) const {
148 return mDisplaySurface->beginFrame(mustRecompose);
Jesse Hall028dc8f2013-08-20 16:35:32 -0700149}
150
Dan Stoza9e56aa02015-11-02 13:00:03 -0800151status_t DisplayDevice::prepareFrame(HWComposer& hwc) {
152 status_t error = hwc.prepare(*this);
153 if (error != NO_ERROR) {
154 return error;
155 }
156
157 DisplaySurface::CompositionType compositionType;
158 bool hasClient = hwc.hasClientComposition(mHwcDisplayId);
159 bool hasDevice = hwc.hasDeviceComposition(mHwcDisplayId);
160 if (hasClient && hasDevice) {
161 compositionType = DisplaySurface::COMPOSITION_MIXED;
162 } else if (hasClient) {
163 compositionType = DisplaySurface::COMPOSITION_GLES;
164 } else if (hasDevice) {
165 compositionType = DisplaySurface::COMPOSITION_HWC;
166 } else {
167 // Nothing to do -- when turning the screen off we get a frame like
168 // this. Call it a HWC frame since we won't be doing any GLES work but
169 // will do a prepare/set cycle.
170 compositionType = DisplaySurface::COMPOSITION_HWC;
171 }
172 return mDisplaySurface->prepareFrame(compositionType);
173}
Jesse Hall38efe862013-04-06 23:12:29 -0700174
Mathias Agopianda27af92012-09-13 18:17:13 -0700175void DisplayDevice::swapBuffers(HWComposer& hwc) const {
Madhuri Athota88a905b2017-05-04 16:58:15 +0530176 if (hwc.hasClientComposition(mHwcDisplayId) || hwc.hasFlipClientTargetRequest(mHwcDisplayId)) {
Lloyd Pique144e1162017-12-20 16:44:52 -0800177 mSurface->swapBuffers();
Mathias Agopianda27af92012-09-13 18:17:13 -0700178 }
Mathias Agopian52e21482012-09-24 18:07:21 -0700179
Jesse Hall99c7dbb2013-03-14 14:29:29 -0700180 status_t result = mDisplaySurface->advanceFrame();
181 if (result != NO_ERROR) {
182 ALOGE("[%s] failed pushing new frame to HWC: %d",
183 mDisplayName.string(), result);
Mathias Agopian32341382012-09-25 19:16:28 -0700184 }
Mathias Agopianda27af92012-09-13 18:17:13 -0700185}
186
Dan Stoza9e56aa02015-11-02 13:00:03 -0800187void DisplayDevice::onSwapBuffersCompleted() const {
188 mDisplaySurface->onFrameCommitted();
189}
Mathias Agopianda27af92012-09-13 18:17:13 -0700190
Chia-I Wuf846a352017-11-10 09:22:52 -0800191bool DisplayDevice::makeCurrent() const {
Lloyd Pique144e1162017-12-20 16:44:52 -0800192 bool success = mFlinger->getRenderEngine().setCurrentSurface(*mSurface);
Mathias Agopian931bda12013-08-28 18:11:46 -0700193 setViewportAndProjection();
Chia-I Wuf846a352017-11-10 09:22:52 -0800194 return success;
Mathias Agopian52bbb1a2012-07-31 19:01:53 -0700195}
196
Mathias Agopian875d8e12013-06-07 15:35:48 -0700197void DisplayDevice::setViewportAndProjection() const {
198 size_t w = mDisplayWidth;
199 size_t h = mDisplayHeight;
Dan Stozac1879002014-05-22 15:59:05 -0700200 Rect sourceCrop(0, 0, w, h);
Riley Andrewsc3ebe662014-09-04 16:20:31 -0700201 mFlinger->getRenderEngine().setViewportAndProjection(w, h, sourceCrop, h,
202 false, Transform::ROT_0);
Mathias Agopianbae92d02012-09-28 01:00:47 -0700203}
204
Dan Stoza9e56aa02015-11-02 13:00:03 -0800205const sp<Fence>& DisplayDevice::getClientTargetAcquireFence() const {
206 return mDisplaySurface->getClientTargetAcquireFence();
207}
Dan Stoza9e56aa02015-11-02 13:00:03 -0800208
Mathias Agopian1b031492012-06-20 17:51:20 -0700209// ----------------------------------------------------------------------------
210
Mathias Agopian13127d82013-03-05 17:47:11 -0800211void DisplayDevice::setVisibleLayersSortedByZ(const Vector< sp<Layer> >& layers) {
Mathias Agopian3b1d2b62012-07-11 13:48:17 -0700212 mVisibleLayersSortedByZ = layers;
Mathias Agopian3b1d2b62012-07-11 13:48:17 -0700213}
214
Mathias Agopian13127d82013-03-05 17:47:11 -0800215const Vector< sp<Layer> >& DisplayDevice::getVisibleLayersSortedByZ() const {
Mathias Agopian3b1d2b62012-07-11 13:48:17 -0700216 return mVisibleLayersSortedByZ;
217}
218
Chia-I Wu83806892017-11-16 10:50:20 -0800219void DisplayDevice::setLayersNeedingFences(const Vector< sp<Layer> >& layers) {
220 mLayersNeedingFences = layers;
221}
222
223const Vector< sp<Layer> >& DisplayDevice::getLayersNeedingFences() const {
224 return mLayersNeedingFences;
225}
226
Mathias Agopiancd60f992012-08-16 16:28:27 -0700227Region DisplayDevice::getDirtyRegion(bool repaintEverything) const {
228 Region dirty;
Mathias Agopiancd60f992012-08-16 16:28:27 -0700229 if (repaintEverything) {
230 dirty.set(getBounds());
231 } else {
Mathias Agopianda8d0a52012-09-04 15:05:38 -0700232 const Transform& planeTransform(mGlobalTransform);
Mathias Agopiancd60f992012-08-16 16:28:27 -0700233 dirty = planeTransform.transform(this->dirtyRegion);
234 dirty.andSelf(getBounds());
235 }
236 return dirty;
237}
238
Mathias Agopian3b1d2b62012-07-11 13:48:17 -0700239// ----------------------------------------------------------------------------
Prashant Malani2c9b11f2014-05-25 01:36:31 -0700240void DisplayDevice::setPowerMode(int mode) {
241 mPowerMode = mode;
Mathias Agopiand3ee2312012-08-02 14:01:42 -0700242}
243
Prashant Malani2c9b11f2014-05-25 01:36:31 -0700244int DisplayDevice::getPowerMode() const {
245 return mPowerMode;
Mathias Agopiand3ee2312012-08-02 14:01:42 -0700246}
247
Prashant Malani2c9b11f2014-05-25 01:36:31 -0700248bool DisplayDevice::isDisplayOn() const {
249 return (mPowerMode != HWC_POWER_MODE_OFF);
Mathias Agopiand3ee2312012-08-02 14:01:42 -0700250}
251
252// ----------------------------------------------------------------------------
Michael Lentine6c9e34a2014-07-14 13:48:55 -0700253void DisplayDevice::setActiveConfig(int mode) {
254 mActiveConfig = mode;
255}
256
257int DisplayDevice::getActiveConfig() const {
258 return mActiveConfig;
259}
260
261// ----------------------------------------------------------------------------
Peiyong Lina52f0292018-03-14 17:26:31 -0700262void DisplayDevice::setActiveColorMode(ColorMode mode) {
Michael Wright28f24d02016-07-12 13:30:53 -0700263 mActiveColorMode = mode;
264}
265
Peiyong Lina52f0292018-03-14 17:26:31 -0700266ColorMode DisplayDevice::getActiveColorMode() const {
Michael Wright28f24d02016-07-12 13:30:53 -0700267 return mActiveColorMode;
268}
Courtney Goeltzenleuchter79d27242017-07-13 17:54:01 -0600269
270void DisplayDevice::setCompositionDataSpace(android_dataspace dataspace) {
271 ANativeWindow* const window = mNativeWindow.get();
272 native_window_set_buffers_data_space(window, dataspace);
273}
Michael Wright28f24d02016-07-12 13:30:53 -0700274
275// ----------------------------------------------------------------------------
Mathias Agopiand3ee2312012-08-02 14:01:42 -0700276
Mathias Agopian28947d72012-08-08 18:51:15 -0700277void DisplayDevice::setLayerStack(uint32_t stack) {
278 mLayerStack = stack;
279 dirtyRegion.set(bounds());
280}
281
282// ----------------------------------------------------------------------------
283
Mathias Agopianc1c05de2013-09-17 23:45:22 -0700284uint32_t DisplayDevice::getOrientationTransform() const {
285 uint32_t transform = 0;
286 switch (mOrientation) {
287 case DisplayState::eOrientationDefault:
288 transform = Transform::ROT_0;
289 break;
290 case DisplayState::eOrientation90:
291 transform = Transform::ROT_90;
292 break;
293 case DisplayState::eOrientation180:
294 transform = Transform::ROT_180;
295 break;
296 case DisplayState::eOrientation270:
297 transform = Transform::ROT_270;
298 break;
299 }
300 return transform;
301}
302
Mathias Agopian0f2f5ff2012-07-31 23:09:07 -0700303status_t DisplayDevice::orientationToTransfrom(
Mathias Agopian1b031492012-06-20 17:51:20 -0700304 int orientation, int w, int h, Transform* tr)
305{
306 uint32_t flags = 0;
307 switch (orientation) {
Mathias Agopian3165cc22012-08-08 19:42:09 -0700308 case DisplayState::eOrientationDefault:
Mathias Agopian1b031492012-06-20 17:51:20 -0700309 flags = Transform::ROT_0;
310 break;
Mathias Agopian3165cc22012-08-08 19:42:09 -0700311 case DisplayState::eOrientation90:
Mathias Agopian1b031492012-06-20 17:51:20 -0700312 flags = Transform::ROT_90;
313 break;
Mathias Agopian3165cc22012-08-08 19:42:09 -0700314 case DisplayState::eOrientation180:
Mathias Agopian1b031492012-06-20 17:51:20 -0700315 flags = Transform::ROT_180;
316 break;
Mathias Agopian3165cc22012-08-08 19:42:09 -0700317 case DisplayState::eOrientation270:
Mathias Agopian1b031492012-06-20 17:51:20 -0700318 flags = Transform::ROT_270;
319 break;
320 default:
321 return BAD_VALUE;
322 }
323 tr->set(flags, w, h);
324 return NO_ERROR;
325}
326
Michael Lentine47e45402014-07-18 15:34:25 -0700327void DisplayDevice::setDisplaySize(const int newWidth, const int newHeight) {
328 dirtyRegion.set(getBounds());
329
Lloyd Pique144e1162017-12-20 16:44:52 -0800330 mSurface->setNativeWindow(nullptr);
Michael Lentinef2568de2014-08-20 10:51:23 -0700331
Michael Lentine47e45402014-07-18 15:34:25 -0700332 mDisplaySurface->resizeBuffers(newWidth, newHeight);
333
334 ANativeWindow* const window = mNativeWindow.get();
Lloyd Pique144e1162017-12-20 16:44:52 -0800335 mSurface->setNativeWindow(window);
336 mDisplayWidth = mSurface->queryWidth();
337 mDisplayHeight = mSurface->queryHeight();
Michael Lentine47e45402014-07-18 15:34:25 -0700338
339 LOG_FATAL_IF(mDisplayWidth != newWidth,
340 "Unable to set new width to %d", newWidth);
341 LOG_FATAL_IF(mDisplayHeight != newHeight,
342 "Unable to set new height to %d", newHeight);
343}
344
Mathias Agopian00e8c7a2012-09-04 19:30:46 -0700345void DisplayDevice::setProjection(int orientation,
Mathias Agopianf5f714a2013-02-26 16:54:05 -0800346 const Rect& newViewport, const Rect& newFrame) {
347 Rect viewport(newViewport);
348 Rect frame(newFrame);
349
350 const int w = mDisplayWidth;
351 const int h = mDisplayHeight;
352
353 Transform R;
354 DisplayDevice::orientationToTransfrom(orientation, w, h, &R);
355
356 if (!frame.isValid()) {
357 // the destination frame can be invalid if it has never been set,
358 // in that case we assume the whole display frame.
359 frame = Rect(w, h);
360 }
361
362 if (viewport.isEmpty()) {
363 // viewport can be invalid if it has never been set, in that case
364 // we assume the whole display size.
365 // it's also invalid to have an empty viewport, so we handle that
366 // case in the same way.
367 viewport = Rect(w, h);
368 if (R.getOrientation() & Transform::ROT_90) {
369 // viewport is always specified in the logical orientation
370 // of the display (ie: post-rotation).
371 swap(viewport.right, viewport.bottom);
372 }
373 }
374
375 dirtyRegion.set(getBounds());
376
377 Transform TL, TP, S;
378 float src_width = viewport.width();
379 float src_height = viewport.height();
380 float dst_width = frame.width();
381 float dst_height = frame.height();
382 if (src_width != dst_width || src_height != dst_height) {
383 float sx = dst_width / src_width;
384 float sy = dst_height / src_height;
385 S.set(sx, 0, 0, sy);
386 }
387
388 float src_x = viewport.left;
389 float src_y = viewport.top;
390 float dst_x = frame.left;
391 float dst_y = frame.top;
392 TL.set(-src_x, -src_y);
393 TP.set(dst_x, dst_y);
394
395 // The viewport and frame are both in the logical orientation.
396 // Apply the logical translation, scale to physical size, apply the
397 // physical translation and finally rotate to the physical orientation.
398 mGlobalTransform = R * TP * S * TL;
399
400 const uint8_t type = mGlobalTransform.getType();
401 mNeedsFiltering = (!mGlobalTransform.preserveRects() ||
402 (type >= Transform::SCALE));
403
404 mScissor = mGlobalTransform.transform(viewport);
405 if (mScissor.isEmpty()) {
Mathias Agopian6c7f25a2013-05-09 20:37:10 -0700406 mScissor = getBounds();
Mathias Agopianf5f714a2013-02-26 16:54:05 -0800407 }
408
Mathias Agopianda8d0a52012-09-04 15:05:38 -0700409 mOrientation = orientation;
Pablo Ceballos021623b2016-04-15 17:31:51 -0700410 if (mType == DisplayType::DISPLAY_PRIMARY) {
411 uint32_t transform = 0;
412 switch (mOrientation) {
413 case DisplayState::eOrientationDefault:
414 transform = Transform::ROT_0;
415 break;
416 case DisplayState::eOrientation90:
417 transform = Transform::ROT_90;
418 break;
419 case DisplayState::eOrientation180:
420 transform = Transform::ROT_180;
421 break;
422 case DisplayState::eOrientation270:
423 transform = Transform::ROT_270;
424 break;
425 }
426 sPrimaryDisplayOrientation = transform;
427 }
Mathias Agopian00e8c7a2012-09-04 19:30:46 -0700428 mViewport = viewport;
429 mFrame = frame;
Mathias Agopian1b031492012-06-20 17:51:20 -0700430}
Mathias Agopian1d12d8a2012-09-18 01:38:00 -0700431
Pablo Ceballos021623b2016-04-15 17:31:51 -0700432uint32_t DisplayDevice::getPrimaryDisplayOrientationTransform() {
433 return sPrimaryDisplayOrientation;
434}
435
Mathias Agopian74d211a2013-04-22 16:55:35 +0200436void DisplayDevice::dump(String8& result) const {
Mathias Agopian1d12d8a2012-09-18 01:38:00 -0700437 const Transform& tr(mGlobalTransform);
Courtney Goeltzenleuchter152279d2017-08-14 18:18:30 -0600438 ANativeWindow* const window = mNativeWindow.get();
Courtney Goeltzenleuchter0ebaac32017-04-13 12:17:03 -0600439 result.appendFormat("+ DisplayDevice: %s\n", mDisplayName.string());
440 result.appendFormat(" type=%x, hwcId=%d, layerStack=%u, (%4dx%4d), ANativeWindow=%p "
441 "(%d:%d:%d:%d), orient=%2d (type=%08x), "
442 "flips=%u, isSecure=%d, powerMode=%d, activeConfig=%d, numLayers=%zu\n",
Courtney Goeltzenleuchter152279d2017-08-14 18:18:30 -0600443 mType, mHwcDisplayId, mLayerStack, mDisplayWidth, mDisplayHeight, window,
Lloyd Pique144e1162017-12-20 16:44:52 -0800444 mSurface->queryRedSize(), mSurface->queryGreenSize(),
445 mSurface->queryBlueSize(), mSurface->queryAlphaSize(), mOrientation,
446 tr.getType(), getPageFlipCount(), mIsSecure, mPowerMode, mActiveConfig,
Courtney Goeltzenleuchter0ebaac32017-04-13 12:17:03 -0600447 mVisibleLayersSortedByZ.size());
448 result.appendFormat(" v:[%d,%d,%d,%d], f:[%d,%d,%d,%d], s:[%d,%d,%d,%d],"
449 "transform:[[%0.3f,%0.3f,%0.3f][%0.3f,%0.3f,%0.3f][%0.3f,%0.3f,%0.3f]]\n",
450 mViewport.left, mViewport.top, mViewport.right, mViewport.bottom,
451 mFrame.left, mFrame.top, mFrame.right, mFrame.bottom, mScissor.left,
452 mScissor.top, mScissor.right, mScissor.bottom, tr[0][0], tr[1][0], tr[2][0],
453 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 -0600454 auto const surface = static_cast<Surface*>(window);
455 android_dataspace dataspace = surface->getBuffersDataSpace();
456 result.appendFormat(" dataspace: %s (%d)\n", dataspaceDetails(dataspace).c_str(), dataspace);
Mathias Agopian1d12d8a2012-09-18 01:38:00 -0700457
Jesse Hall99c7dbb2013-03-14 14:29:29 -0700458 String8 surfaceDump;
Dan Stozaf10c46e2014-11-11 10:32:31 -0800459 mDisplaySurface->dumpAsString(surfaceDump);
Jesse Hall99c7dbb2013-03-14 14:29:29 -0700460 result.append(surfaceDump);
Mathias Agopian1d12d8a2012-09-18 01:38:00 -0700461}
Irvelffc9efc2016-07-27 15:16:37 -0700462
463std::atomic<int32_t> DisplayDeviceState::nextDisplayId(1);
464
465DisplayDeviceState::DisplayDeviceState(DisplayDevice::DisplayType type, bool isSecure)
466 : type(type),
467 layerStack(DisplayDevice::NO_LAYER_STACK),
468 orientation(0),
469 width(0),
470 height(0),
471 isSecure(isSecure)
472{
473 viewport.makeInvalid();
474 frame.makeInvalid();
475}
Peiyong Linfd997e02018-03-28 15:29:00 -0700476
477} // namespace android