blob: fe0b30ba356f5b5dfb7b71dc3dcb1c341e5cf2bb [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
Mathias Agopiana4912602012-07-12 14:25:33 -070052// ----------------------------------------------------------------------------
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -080053using namespace android;
Mathias Agopiana4912602012-07-12 14:25:33 -070054// ----------------------------------------------------------------------------
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -080055
Jaesoo Lee720a7242017-01-31 15:26:18 +090056// retrieve triple buffer setting from configstore
57using namespace android::hardware::configstore;
58using namespace android::hardware::configstore::V1_0;
59
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -080060/*
61 * Initialize the display to the specified values.
62 *
63 */
64
Pablo Ceballos021623b2016-04-15 17:31:51 -070065uint32_t DisplayDevice::sPrimaryDisplayOrientation = 0;
66
Courtney Goeltzenleuchter5d943892017-03-22 13:46:46 -060067// clang-format off
Mathias Agopian0f2f5ff2012-07-31 23:09:07 -070068DisplayDevice::DisplayDevice(
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -080069 const sp<SurfaceFlinger>& flinger,
Jamie Gennisdd3cb842012-10-19 18:19:11 -070070 DisplayType type,
Jesse Hallffe1f192013-03-22 15:13:48 -070071 int32_t hwcId,
Jamie Gennisdd3cb842012-10-19 18:19:11 -070072 bool isSecure,
73 const wp<IBinder>& displayToken,
Lloyd Pique09594832018-01-22 17:48:03 -080074 const sp<ANativeWindow>& nativeWindow,
Jesse Hall99c7dbb2013-03-14 14:29:29 -070075 const sp<DisplaySurface>& displaySurface,
Lloyd Pique09594832018-01-22 17:48:03 -080076 std::unique_ptr<RE::Surface> renderSurface,
77 int displayWidth,
78 int displayHeight,
Chia-I Wu5c6e4632018-01-11 08:54:38 -080079 bool supportWideColor,
Lloyd Pique09594832018-01-22 17:48:03 -080080 bool supportHdr,
81 int initialPowerMode)
Jesse Hallb7a05492014-08-14 15:45:06 -070082 : lastCompositionHadVisibleLayers(false),
83 mFlinger(flinger),
Dan Stoza9e56aa02015-11-02 13:00:03 -080084 mType(type),
85 mHwcDisplayId(hwcId),
Chih-Wei Huang27e25622013-01-07 17:33:56 +080086 mDisplayToken(displayToken),
Lloyd Pique09594832018-01-22 17:48:03 -080087 mNativeWindow(nativeWindow),
Jesse Hall99c7dbb2013-03-14 14:29:29 -070088 mDisplaySurface(displaySurface),
Lloyd Pique09594832018-01-22 17:48:03 -080089 mSurface{std::move(renderSurface)},
90 mDisplayWidth(displayWidth),
91 mDisplayHeight(displayHeight),
92 mPageFlipCount(0),
Jamie Gennisdd3cb842012-10-19 18:19:11 -070093 mIsSecure(isSecure),
Jesse Hall01e29052013-02-19 16:13:35 -080094 mLayerStack(NO_LAYER_STACK),
Prashant Malani2c9b11f2014-05-25 01:36:31 -070095 mOrientation(),
Lloyd Pique09594832018-01-22 17:48:03 -080096 mViewport(Rect::INVALID_RECT),
97 mFrame(Rect::INVALID_RECT),
98 mPowerMode(initialPowerMode),
99 mActiveConfig(0),
100 mActiveColorMode(ColorMode::NATIVE),
101 mDisplayHasWideColor(supportWideColor),
102 mDisplayHasHdr(supportHdr)
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800103{
Courtney Goeltzenleuchter5d943892017-03-22 13:46:46 -0600104 // clang-format on
Jesse Hallffe1f192013-03-22 15:13:48 -0700105
Jesse Hallffe1f192013-03-22 15:13:48 -0700106 // initialize the display orientation transform.
107 setProjection(DisplayState::eOrientationDefault, mViewport, mFrame);
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800108}
109
Lloyd Pique09594832018-01-22 17:48:03 -0800110DisplayDevice::~DisplayDevice() = default;
Mathias Agopian92a979a2012-08-02 18:32:23 -0700111
Jesse Hall02d86562013-03-25 14:43:23 -0700112void DisplayDevice::disconnect(HWComposer& hwc) {
113 if (mHwcDisplayId >= 0) {
114 hwc.disconnectDisplay(mHwcDisplayId);
Jesse Hall02d86562013-03-25 14:43:23 -0700115 mHwcDisplayId = -1;
116 }
117}
118
Mathias Agopian92a979a2012-08-02 18:32:23 -0700119bool DisplayDevice::isValid() const {
Peiyong Lin566a3b42018-01-09 18:22:43 -0800120 return mFlinger != nullptr;
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800121}
122
Mathias Agopian0f2f5ff2012-07-31 23:09:07 -0700123int DisplayDevice::getWidth() const {
Mathias Agopiana4912602012-07-12 14:25:33 -0700124 return mDisplayWidth;
125}
126
Mathias Agopian0f2f5ff2012-07-31 23:09:07 -0700127int DisplayDevice::getHeight() const {
Mathias Agopiana4912602012-07-12 14:25:33 -0700128 return mDisplayHeight;
129}
130
Mathias Agopian9e2463e2012-09-21 18:26:16 -0700131void DisplayDevice::setDisplayName(const String8& displayName) {
132 if (!displayName.isEmpty()) {
133 // never override the name with an empty name
134 mDisplayName = displayName;
135 }
136}
137
Mathias Agopian0f2f5ff2012-07-31 23:09:07 -0700138uint32_t DisplayDevice::getPageFlipCount() const {
Mathias Agopian076b1cc2009-04-10 14:24:30 -0700139 return mPageFlipCount;
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800140}
141
Chia-I Wub02087d2017-11-09 10:19:54 -0800142void DisplayDevice::flip() const
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800143{
Mathias Agopian875d8e12013-06-07 15:35:48 -0700144 mFlinger->getRenderEngine().checkErrors();
Mathias Agopian076b1cc2009-04-10 14:24:30 -0700145 mPageFlipCount++;
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800146}
147
Dan Stoza71433162014-02-04 16:22:36 -0800148status_t DisplayDevice::beginFrame(bool mustRecompose) const {
149 return mDisplaySurface->beginFrame(mustRecompose);
Jesse Hall028dc8f2013-08-20 16:35:32 -0700150}
151
Dan Stoza9e56aa02015-11-02 13:00:03 -0800152status_t DisplayDevice::prepareFrame(HWComposer& hwc) {
153 status_t error = hwc.prepare(*this);
154 if (error != NO_ERROR) {
155 return error;
156 }
157
158 DisplaySurface::CompositionType compositionType;
159 bool hasClient = hwc.hasClientComposition(mHwcDisplayId);
160 bool hasDevice = hwc.hasDeviceComposition(mHwcDisplayId);
161 if (hasClient && hasDevice) {
162 compositionType = DisplaySurface::COMPOSITION_MIXED;
163 } else if (hasClient) {
164 compositionType = DisplaySurface::COMPOSITION_GLES;
165 } else if (hasDevice) {
166 compositionType = DisplaySurface::COMPOSITION_HWC;
167 } else {
168 // Nothing to do -- when turning the screen off we get a frame like
169 // this. Call it a HWC frame since we won't be doing any GLES work but
170 // will do a prepare/set cycle.
171 compositionType = DisplaySurface::COMPOSITION_HWC;
172 }
173 return mDisplaySurface->prepareFrame(compositionType);
174}
Jesse Hall38efe862013-04-06 23:12:29 -0700175
Mathias Agopianda27af92012-09-13 18:17:13 -0700176void DisplayDevice::swapBuffers(HWComposer& hwc) const {
Madhuri Athota88a905b2017-05-04 16:58:15 +0530177 if (hwc.hasClientComposition(mHwcDisplayId) || hwc.hasFlipClientTargetRequest(mHwcDisplayId)) {
Lloyd Pique144e1162017-12-20 16:44:52 -0800178 mSurface->swapBuffers();
Mathias Agopianda27af92012-09-13 18:17:13 -0700179 }
Mathias Agopian52e21482012-09-24 18:07:21 -0700180
Jesse Hall99c7dbb2013-03-14 14:29:29 -0700181 status_t result = mDisplaySurface->advanceFrame();
182 if (result != NO_ERROR) {
183 ALOGE("[%s] failed pushing new frame to HWC: %d",
184 mDisplayName.string(), result);
Mathias Agopian32341382012-09-25 19:16:28 -0700185 }
Mathias Agopianda27af92012-09-13 18:17:13 -0700186}
187
Dan Stoza9e56aa02015-11-02 13:00:03 -0800188void DisplayDevice::onSwapBuffersCompleted() const {
189 mDisplaySurface->onFrameCommitted();
190}
Mathias Agopianda27af92012-09-13 18:17:13 -0700191
Chia-I Wuf846a352017-11-10 09:22:52 -0800192bool DisplayDevice::makeCurrent() const {
Lloyd Pique144e1162017-12-20 16:44:52 -0800193 bool success = mFlinger->getRenderEngine().setCurrentSurface(*mSurface);
Mathias Agopian931bda12013-08-28 18:11:46 -0700194 setViewportAndProjection();
Chia-I Wuf846a352017-11-10 09:22:52 -0800195 return success;
Mathias Agopian52bbb1a2012-07-31 19:01:53 -0700196}
197
Mathias Agopian875d8e12013-06-07 15:35:48 -0700198void DisplayDevice::setViewportAndProjection() const {
199 size_t w = mDisplayWidth;
200 size_t h = mDisplayHeight;
Dan Stozac1879002014-05-22 15:59:05 -0700201 Rect sourceCrop(0, 0, w, h);
Riley Andrewsc3ebe662014-09-04 16:20:31 -0700202 mFlinger->getRenderEngine().setViewportAndProjection(w, h, sourceCrop, h,
203 false, Transform::ROT_0);
Mathias Agopianbae92d02012-09-28 01:00:47 -0700204}
205
Dan Stoza9e56aa02015-11-02 13:00:03 -0800206const sp<Fence>& DisplayDevice::getClientTargetAcquireFence() const {
207 return mDisplaySurface->getClientTargetAcquireFence();
208}
Dan Stoza9e56aa02015-11-02 13:00:03 -0800209
Mathias Agopian1b031492012-06-20 17:51:20 -0700210// ----------------------------------------------------------------------------
211
Mathias Agopian13127d82013-03-05 17:47:11 -0800212void DisplayDevice::setVisibleLayersSortedByZ(const Vector< sp<Layer> >& layers) {
Mathias Agopian3b1d2b62012-07-11 13:48:17 -0700213 mVisibleLayersSortedByZ = layers;
Mathias Agopian3b1d2b62012-07-11 13:48:17 -0700214}
215
Mathias Agopian13127d82013-03-05 17:47:11 -0800216const Vector< sp<Layer> >& DisplayDevice::getVisibleLayersSortedByZ() const {
Mathias Agopian3b1d2b62012-07-11 13:48:17 -0700217 return mVisibleLayersSortedByZ;
218}
219
Chia-I Wu83806892017-11-16 10:50:20 -0800220void DisplayDevice::setLayersNeedingFences(const Vector< sp<Layer> >& layers) {
221 mLayersNeedingFences = layers;
222}
223
224const Vector< sp<Layer> >& DisplayDevice::getLayersNeedingFences() const {
225 return mLayersNeedingFences;
226}
227
Mathias Agopiancd60f992012-08-16 16:28:27 -0700228Region DisplayDevice::getDirtyRegion(bool repaintEverything) const {
229 Region dirty;
Mathias Agopiancd60f992012-08-16 16:28:27 -0700230 if (repaintEverything) {
231 dirty.set(getBounds());
232 } else {
Mathias Agopianda8d0a52012-09-04 15:05:38 -0700233 const Transform& planeTransform(mGlobalTransform);
Mathias Agopiancd60f992012-08-16 16:28:27 -0700234 dirty = planeTransform.transform(this->dirtyRegion);
235 dirty.andSelf(getBounds());
236 }
237 return dirty;
238}
239
Mathias Agopian3b1d2b62012-07-11 13:48:17 -0700240// ----------------------------------------------------------------------------
Prashant Malani2c9b11f2014-05-25 01:36:31 -0700241void DisplayDevice::setPowerMode(int mode) {
242 mPowerMode = mode;
Mathias Agopiand3ee2312012-08-02 14:01:42 -0700243}
244
Prashant Malani2c9b11f2014-05-25 01:36:31 -0700245int DisplayDevice::getPowerMode() const {
246 return mPowerMode;
Mathias Agopiand3ee2312012-08-02 14:01:42 -0700247}
248
Prashant Malani2c9b11f2014-05-25 01:36:31 -0700249bool DisplayDevice::isDisplayOn() const {
250 return (mPowerMode != HWC_POWER_MODE_OFF);
Mathias Agopiand3ee2312012-08-02 14:01:42 -0700251}
252
253// ----------------------------------------------------------------------------
Michael Lentine6c9e34a2014-07-14 13:48:55 -0700254void DisplayDevice::setActiveConfig(int mode) {
255 mActiveConfig = mode;
256}
257
258int DisplayDevice::getActiveConfig() const {
259 return mActiveConfig;
260}
261
262// ----------------------------------------------------------------------------
Peiyong Lina52f0292018-03-14 17:26:31 -0700263void DisplayDevice::setActiveColorMode(ColorMode mode) {
Michael Wright28f24d02016-07-12 13:30:53 -0700264 mActiveColorMode = mode;
265}
266
Peiyong Lina52f0292018-03-14 17:26:31 -0700267ColorMode DisplayDevice::getActiveColorMode() const {
Michael Wright28f24d02016-07-12 13:30:53 -0700268 return mActiveColorMode;
269}
Courtney Goeltzenleuchter79d27242017-07-13 17:54:01 -0600270
271void DisplayDevice::setCompositionDataSpace(android_dataspace dataspace) {
272 ANativeWindow* const window = mNativeWindow.get();
273 native_window_set_buffers_data_space(window, dataspace);
274}
Michael Wright28f24d02016-07-12 13:30:53 -0700275
276// ----------------------------------------------------------------------------
Mathias Agopiand3ee2312012-08-02 14:01:42 -0700277
Mathias Agopian28947d72012-08-08 18:51:15 -0700278void DisplayDevice::setLayerStack(uint32_t stack) {
279 mLayerStack = stack;
280 dirtyRegion.set(bounds());
281}
282
283// ----------------------------------------------------------------------------
284
Mathias Agopianc1c05de2013-09-17 23:45:22 -0700285uint32_t DisplayDevice::getOrientationTransform() const {
286 uint32_t transform = 0;
287 switch (mOrientation) {
288 case DisplayState::eOrientationDefault:
289 transform = Transform::ROT_0;
290 break;
291 case DisplayState::eOrientation90:
292 transform = Transform::ROT_90;
293 break;
294 case DisplayState::eOrientation180:
295 transform = Transform::ROT_180;
296 break;
297 case DisplayState::eOrientation270:
298 transform = Transform::ROT_270;
299 break;
300 }
301 return transform;
302}
303
Mathias Agopian0f2f5ff2012-07-31 23:09:07 -0700304status_t DisplayDevice::orientationToTransfrom(
Mathias Agopian1b031492012-06-20 17:51:20 -0700305 int orientation, int w, int h, Transform* tr)
306{
307 uint32_t flags = 0;
308 switch (orientation) {
Mathias Agopian3165cc22012-08-08 19:42:09 -0700309 case DisplayState::eOrientationDefault:
Mathias Agopian1b031492012-06-20 17:51:20 -0700310 flags = Transform::ROT_0;
311 break;
Mathias Agopian3165cc22012-08-08 19:42:09 -0700312 case DisplayState::eOrientation90:
Mathias Agopian1b031492012-06-20 17:51:20 -0700313 flags = Transform::ROT_90;
314 break;
Mathias Agopian3165cc22012-08-08 19:42:09 -0700315 case DisplayState::eOrientation180:
Mathias Agopian1b031492012-06-20 17:51:20 -0700316 flags = Transform::ROT_180;
317 break;
Mathias Agopian3165cc22012-08-08 19:42:09 -0700318 case DisplayState::eOrientation270:
Mathias Agopian1b031492012-06-20 17:51:20 -0700319 flags = Transform::ROT_270;
320 break;
321 default:
322 return BAD_VALUE;
323 }
324 tr->set(flags, w, h);
325 return NO_ERROR;
326}
327
Michael Lentine47e45402014-07-18 15:34:25 -0700328void DisplayDevice::setDisplaySize(const int newWidth, const int newHeight) {
329 dirtyRegion.set(getBounds());
330
Lloyd Pique144e1162017-12-20 16:44:52 -0800331 mSurface->setNativeWindow(nullptr);
Michael Lentinef2568de2014-08-20 10:51:23 -0700332
Michael Lentine47e45402014-07-18 15:34:25 -0700333 mDisplaySurface->resizeBuffers(newWidth, newHeight);
334
335 ANativeWindow* const window = mNativeWindow.get();
Lloyd Pique144e1162017-12-20 16:44:52 -0800336 mSurface->setNativeWindow(window);
337 mDisplayWidth = mSurface->queryWidth();
338 mDisplayHeight = mSurface->queryHeight();
Michael Lentine47e45402014-07-18 15:34:25 -0700339
340 LOG_FATAL_IF(mDisplayWidth != newWidth,
341 "Unable to set new width to %d", newWidth);
342 LOG_FATAL_IF(mDisplayHeight != newHeight,
343 "Unable to set new height to %d", newHeight);
344}
345
Mathias Agopian00e8c7a2012-09-04 19:30:46 -0700346void DisplayDevice::setProjection(int orientation,
Mathias Agopianf5f714a2013-02-26 16:54:05 -0800347 const Rect& newViewport, const Rect& newFrame) {
348 Rect viewport(newViewport);
349 Rect frame(newFrame);
350
351 const int w = mDisplayWidth;
352 const int h = mDisplayHeight;
353
354 Transform R;
355 DisplayDevice::orientationToTransfrom(orientation, w, h, &R);
356
357 if (!frame.isValid()) {
358 // the destination frame can be invalid if it has never been set,
359 // in that case we assume the whole display frame.
360 frame = Rect(w, h);
361 }
362
363 if (viewport.isEmpty()) {
364 // viewport can be invalid if it has never been set, in that case
365 // we assume the whole display size.
366 // it's also invalid to have an empty viewport, so we handle that
367 // case in the same way.
368 viewport = Rect(w, h);
369 if (R.getOrientation() & Transform::ROT_90) {
370 // viewport is always specified in the logical orientation
371 // of the display (ie: post-rotation).
372 swap(viewport.right, viewport.bottom);
373 }
374 }
375
376 dirtyRegion.set(getBounds());
377
378 Transform TL, TP, S;
379 float src_width = viewport.width();
380 float src_height = viewport.height();
381 float dst_width = frame.width();
382 float dst_height = frame.height();
383 if (src_width != dst_width || src_height != dst_height) {
384 float sx = dst_width / src_width;
385 float sy = dst_height / src_height;
386 S.set(sx, 0, 0, sy);
387 }
388
389 float src_x = viewport.left;
390 float src_y = viewport.top;
391 float dst_x = frame.left;
392 float dst_y = frame.top;
393 TL.set(-src_x, -src_y);
394 TP.set(dst_x, dst_y);
395
396 // The viewport and frame are both in the logical orientation.
397 // Apply the logical translation, scale to physical size, apply the
398 // physical translation and finally rotate to the physical orientation.
399 mGlobalTransform = R * TP * S * TL;
400
401 const uint8_t type = mGlobalTransform.getType();
402 mNeedsFiltering = (!mGlobalTransform.preserveRects() ||
403 (type >= Transform::SCALE));
404
405 mScissor = mGlobalTransform.transform(viewport);
406 if (mScissor.isEmpty()) {
Mathias Agopian6c7f25a2013-05-09 20:37:10 -0700407 mScissor = getBounds();
Mathias Agopianf5f714a2013-02-26 16:54:05 -0800408 }
409
Mathias Agopianda8d0a52012-09-04 15:05:38 -0700410 mOrientation = orientation;
Pablo Ceballos021623b2016-04-15 17:31:51 -0700411 if (mType == DisplayType::DISPLAY_PRIMARY) {
412 uint32_t transform = 0;
413 switch (mOrientation) {
414 case DisplayState::eOrientationDefault:
415 transform = Transform::ROT_0;
416 break;
417 case DisplayState::eOrientation90:
418 transform = Transform::ROT_90;
419 break;
420 case DisplayState::eOrientation180:
421 transform = Transform::ROT_180;
422 break;
423 case DisplayState::eOrientation270:
424 transform = Transform::ROT_270;
425 break;
426 }
427 sPrimaryDisplayOrientation = transform;
428 }
Mathias Agopian00e8c7a2012-09-04 19:30:46 -0700429 mViewport = viewport;
430 mFrame = frame;
Mathias Agopian1b031492012-06-20 17:51:20 -0700431}
Mathias Agopian1d12d8a2012-09-18 01:38:00 -0700432
Pablo Ceballos021623b2016-04-15 17:31:51 -0700433uint32_t DisplayDevice::getPrimaryDisplayOrientationTransform() {
434 return sPrimaryDisplayOrientation;
435}
436
Mathias Agopian74d211a2013-04-22 16:55:35 +0200437void DisplayDevice::dump(String8& result) const {
Mathias Agopian1d12d8a2012-09-18 01:38:00 -0700438 const Transform& tr(mGlobalTransform);
Courtney Goeltzenleuchter152279d2017-08-14 18:18:30 -0600439 ANativeWindow* const window = mNativeWindow.get();
Courtney Goeltzenleuchter0ebaac32017-04-13 12:17:03 -0600440 result.appendFormat("+ DisplayDevice: %s\n", mDisplayName.string());
441 result.appendFormat(" type=%x, hwcId=%d, layerStack=%u, (%4dx%4d), ANativeWindow=%p "
442 "(%d:%d:%d:%d), orient=%2d (type=%08x), "
443 "flips=%u, isSecure=%d, powerMode=%d, activeConfig=%d, numLayers=%zu\n",
Courtney Goeltzenleuchter152279d2017-08-14 18:18:30 -0600444 mType, mHwcDisplayId, mLayerStack, mDisplayWidth, mDisplayHeight, window,
Lloyd Pique144e1162017-12-20 16:44:52 -0800445 mSurface->queryRedSize(), mSurface->queryGreenSize(),
446 mSurface->queryBlueSize(), mSurface->queryAlphaSize(), mOrientation,
447 tr.getType(), getPageFlipCount(), mIsSecure, mPowerMode, mActiveConfig,
Courtney Goeltzenleuchter0ebaac32017-04-13 12:17:03 -0600448 mVisibleLayersSortedByZ.size());
449 result.appendFormat(" v:[%d,%d,%d,%d], f:[%d,%d,%d,%d], s:[%d,%d,%d,%d],"
450 "transform:[[%0.3f,%0.3f,%0.3f][%0.3f,%0.3f,%0.3f][%0.3f,%0.3f,%0.3f]]\n",
451 mViewport.left, mViewport.top, mViewport.right, mViewport.bottom,
452 mFrame.left, mFrame.top, mFrame.right, mFrame.bottom, mScissor.left,
453 mScissor.top, mScissor.right, mScissor.bottom, tr[0][0], tr[1][0], tr[2][0],
454 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 -0600455 auto const surface = static_cast<Surface*>(window);
456 android_dataspace dataspace = surface->getBuffersDataSpace();
457 result.appendFormat(" dataspace: %s (%d)\n", dataspaceDetails(dataspace).c_str(), dataspace);
Mathias Agopian1d12d8a2012-09-18 01:38:00 -0700458
Jesse Hall99c7dbb2013-03-14 14:29:29 -0700459 String8 surfaceDump;
Dan Stozaf10c46e2014-11-11 10:32:31 -0800460 mDisplaySurface->dumpAsString(surfaceDump);
Jesse Hall99c7dbb2013-03-14 14:29:29 -0700461 result.append(surfaceDump);
Mathias Agopian1d12d8a2012-09-18 01:38:00 -0700462}
Irvelffc9efc2016-07-27 15:16:37 -0700463
464std::atomic<int32_t> DisplayDeviceState::nextDisplayId(1);
465
466DisplayDeviceState::DisplayDeviceState(DisplayDevice::DisplayType type, bool isSecure)
467 : type(type),
468 layerStack(DisplayDevice::NO_LAYER_STACK),
469 orientation(0),
470 width(0),
471 height(0),
472 isSecure(isSecure)
473{
474 viewport.makeInvalid();
475 frame.makeInvalid();
476}