blob: d90ab1dfed6ff34601a2fa8f5702281a97e18320 [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;
Peiyong Lindd9b2ae2018-03-01 16:22:45 -080058using android::ui::RenderIntent;
Jaesoo Lee720a7242017-01-31 15:26:18 +090059
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,
Peiyong Lindd9b2ae2018-03-01 16:22:45 -080079 bool hasWideColorGamut,
80 bool hasHdr10,
Lloyd Pique09594832018-01-22 17:48:03 -080081 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),
Yiwei Zhang7c64f172018-03-07 14:52:28 -0800101 mColorTransform(HAL_COLOR_TRANSFORM_IDENTITY),
Peiyong Lindd9b2ae2018-03-01 16:22:45 -0800102 mHasWideColorGamut(hasWideColorGamut),
103 mHasHdr10(hasHdr10)
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800104{
Courtney Goeltzenleuchter5d943892017-03-22 13:46:46 -0600105 // clang-format on
Jesse Hallffe1f192013-03-22 15:13:48 -0700106
Jesse Hallffe1f192013-03-22 15:13:48 -0700107 // initialize the display orientation transform.
108 setProjection(DisplayState::eOrientationDefault, mViewport, mFrame);
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800109}
110
Lloyd Pique09594832018-01-22 17:48:03 -0800111DisplayDevice::~DisplayDevice() = default;
Mathias Agopian92a979a2012-08-02 18:32:23 -0700112
Jesse Hall02d86562013-03-25 14:43:23 -0700113void DisplayDevice::disconnect(HWComposer& hwc) {
114 if (mHwcDisplayId >= 0) {
115 hwc.disconnectDisplay(mHwcDisplayId);
Jesse Hall02d86562013-03-25 14:43:23 -0700116 mHwcDisplayId = -1;
117 }
118}
119
Mathias Agopian92a979a2012-08-02 18:32:23 -0700120bool DisplayDevice::isValid() const {
Peiyong Lin566a3b42018-01-09 18:22:43 -0800121 return mFlinger != nullptr;
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800122}
123
Mathias Agopian0f2f5ff2012-07-31 23:09:07 -0700124int DisplayDevice::getWidth() const {
Mathias Agopiana4912602012-07-12 14:25:33 -0700125 return mDisplayWidth;
126}
127
Mathias Agopian0f2f5ff2012-07-31 23:09:07 -0700128int DisplayDevice::getHeight() const {
Mathias Agopiana4912602012-07-12 14:25:33 -0700129 return mDisplayHeight;
130}
131
Mathias Agopian9e2463e2012-09-21 18:26:16 -0700132void DisplayDevice::setDisplayName(const String8& displayName) {
133 if (!displayName.isEmpty()) {
134 // never override the name with an empty name
135 mDisplayName = displayName;
136 }
137}
138
Mathias Agopian0f2f5ff2012-07-31 23:09:07 -0700139uint32_t DisplayDevice::getPageFlipCount() const {
Mathias Agopian076b1cc2009-04-10 14:24:30 -0700140 return mPageFlipCount;
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800141}
142
Chia-I Wub02087d2017-11-09 10:19:54 -0800143void DisplayDevice::flip() const
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800144{
Mathias Agopian875d8e12013-06-07 15:35:48 -0700145 mFlinger->getRenderEngine().checkErrors();
Mathias Agopian076b1cc2009-04-10 14:24:30 -0700146 mPageFlipCount++;
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800147}
148
Dan Stoza71433162014-02-04 16:22:36 -0800149status_t DisplayDevice::beginFrame(bool mustRecompose) const {
150 return mDisplaySurface->beginFrame(mustRecompose);
Jesse Hall028dc8f2013-08-20 16:35:32 -0700151}
152
Dan Stoza9e56aa02015-11-02 13:00:03 -0800153status_t DisplayDevice::prepareFrame(HWComposer& hwc) {
154 status_t error = hwc.prepare(*this);
155 if (error != NO_ERROR) {
156 return error;
157 }
158
159 DisplaySurface::CompositionType compositionType;
160 bool hasClient = hwc.hasClientComposition(mHwcDisplayId);
161 bool hasDevice = hwc.hasDeviceComposition(mHwcDisplayId);
162 if (hasClient && hasDevice) {
163 compositionType = DisplaySurface::COMPOSITION_MIXED;
164 } else if (hasClient) {
165 compositionType = DisplaySurface::COMPOSITION_GLES;
166 } else if (hasDevice) {
167 compositionType = DisplaySurface::COMPOSITION_HWC;
168 } else {
169 // Nothing to do -- when turning the screen off we get a frame like
170 // this. Call it a HWC frame since we won't be doing any GLES work but
171 // will do a prepare/set cycle.
172 compositionType = DisplaySurface::COMPOSITION_HWC;
173 }
174 return mDisplaySurface->prepareFrame(compositionType);
175}
Jesse Hall38efe862013-04-06 23:12:29 -0700176
Mathias Agopianda27af92012-09-13 18:17:13 -0700177void DisplayDevice::swapBuffers(HWComposer& hwc) const {
Madhuri Athota88a905b2017-05-04 16:58:15 +0530178 if (hwc.hasClientComposition(mHwcDisplayId) || hwc.hasFlipClientTargetRequest(mHwcDisplayId)) {
Lloyd Pique144e1162017-12-20 16:44:52 -0800179 mSurface->swapBuffers();
Mathias Agopianda27af92012-09-13 18:17:13 -0700180 }
Mathias Agopian52e21482012-09-24 18:07:21 -0700181
Jesse Hall99c7dbb2013-03-14 14:29:29 -0700182 status_t result = mDisplaySurface->advanceFrame();
183 if (result != NO_ERROR) {
184 ALOGE("[%s] failed pushing new frame to HWC: %d",
185 mDisplayName.string(), result);
Mathias Agopian32341382012-09-25 19:16:28 -0700186 }
Mathias Agopianda27af92012-09-13 18:17:13 -0700187}
188
Dan Stoza9e56aa02015-11-02 13:00:03 -0800189void DisplayDevice::onSwapBuffersCompleted() const {
190 mDisplaySurface->onFrameCommitted();
191}
Mathias Agopianda27af92012-09-13 18:17:13 -0700192
Chia-I Wuf846a352017-11-10 09:22:52 -0800193bool DisplayDevice::makeCurrent() const {
Lloyd Pique144e1162017-12-20 16:44:52 -0800194 bool success = mFlinger->getRenderEngine().setCurrentSurface(*mSurface);
Mathias Agopian931bda12013-08-28 18:11:46 -0700195 setViewportAndProjection();
Chia-I Wuf846a352017-11-10 09:22:52 -0800196 return success;
Mathias Agopian52bbb1a2012-07-31 19:01:53 -0700197}
198
Mathias Agopian875d8e12013-06-07 15:35:48 -0700199void DisplayDevice::setViewportAndProjection() const {
200 size_t w = mDisplayWidth;
201 size_t h = mDisplayHeight;
Dan Stozac1879002014-05-22 15:59:05 -0700202 Rect sourceCrop(0, 0, w, h);
Riley Andrewsc3ebe662014-09-04 16:20:31 -0700203 mFlinger->getRenderEngine().setViewportAndProjection(w, h, sourceCrop, h,
204 false, Transform::ROT_0);
Mathias Agopianbae92d02012-09-28 01:00:47 -0700205}
206
Dan Stoza9e56aa02015-11-02 13:00:03 -0800207const sp<Fence>& DisplayDevice::getClientTargetAcquireFence() const {
208 return mDisplaySurface->getClientTargetAcquireFence();
209}
Dan Stoza9e56aa02015-11-02 13:00:03 -0800210
Mathias Agopian1b031492012-06-20 17:51:20 -0700211// ----------------------------------------------------------------------------
212
Mathias Agopian13127d82013-03-05 17:47:11 -0800213void DisplayDevice::setVisibleLayersSortedByZ(const Vector< sp<Layer> >& layers) {
Mathias Agopian3b1d2b62012-07-11 13:48:17 -0700214 mVisibleLayersSortedByZ = layers;
Mathias Agopian3b1d2b62012-07-11 13:48:17 -0700215}
216
Mathias Agopian13127d82013-03-05 17:47:11 -0800217const Vector< sp<Layer> >& DisplayDevice::getVisibleLayersSortedByZ() const {
Mathias Agopian3b1d2b62012-07-11 13:48:17 -0700218 return mVisibleLayersSortedByZ;
219}
220
Chia-I Wu83806892017-11-16 10:50:20 -0800221void DisplayDevice::setLayersNeedingFences(const Vector< sp<Layer> >& layers) {
222 mLayersNeedingFences = layers;
223}
224
225const Vector< sp<Layer> >& DisplayDevice::getLayersNeedingFences() const {
226 return mLayersNeedingFences;
227}
228
Mathias Agopiancd60f992012-08-16 16:28:27 -0700229Region DisplayDevice::getDirtyRegion(bool repaintEverything) const {
230 Region dirty;
Mathias Agopiancd60f992012-08-16 16:28:27 -0700231 if (repaintEverything) {
232 dirty.set(getBounds());
233 } else {
Mathias Agopianda8d0a52012-09-04 15:05:38 -0700234 const Transform& planeTransform(mGlobalTransform);
Mathias Agopiancd60f992012-08-16 16:28:27 -0700235 dirty = planeTransform.transform(this->dirtyRegion);
236 dirty.andSelf(getBounds());
237 }
238 return dirty;
239}
240
Mathias Agopian3b1d2b62012-07-11 13:48:17 -0700241// ----------------------------------------------------------------------------
Prashant Malani2c9b11f2014-05-25 01:36:31 -0700242void DisplayDevice::setPowerMode(int mode) {
243 mPowerMode = mode;
Mathias Agopiand3ee2312012-08-02 14:01:42 -0700244}
245
Prashant Malani2c9b11f2014-05-25 01:36:31 -0700246int DisplayDevice::getPowerMode() const {
247 return mPowerMode;
Mathias Agopiand3ee2312012-08-02 14:01:42 -0700248}
249
Prashant Malani2c9b11f2014-05-25 01:36:31 -0700250bool DisplayDevice::isDisplayOn() const {
251 return (mPowerMode != HWC_POWER_MODE_OFF);
Mathias Agopiand3ee2312012-08-02 14:01:42 -0700252}
253
254// ----------------------------------------------------------------------------
Michael Lentine6c9e34a2014-07-14 13:48:55 -0700255void DisplayDevice::setActiveConfig(int mode) {
256 mActiveConfig = mode;
257}
258
259int DisplayDevice::getActiveConfig() const {
260 return mActiveConfig;
261}
262
263// ----------------------------------------------------------------------------
Peiyong Lina52f0292018-03-14 17:26:31 -0700264void DisplayDevice::setActiveColorMode(ColorMode mode) {
Michael Wright28f24d02016-07-12 13:30:53 -0700265 mActiveColorMode = mode;
266}
267
Peiyong Lina52f0292018-03-14 17:26:31 -0700268ColorMode DisplayDevice::getActiveColorMode() const {
Michael Wright28f24d02016-07-12 13:30:53 -0700269 return mActiveColorMode;
270}
Courtney Goeltzenleuchter79d27242017-07-13 17:54:01 -0600271
Peiyong Lindd9b2ae2018-03-01 16:22:45 -0800272RenderIntent DisplayDevice::getActiveRenderIntent() const {
273 return mActiveRenderIntent;
274}
275
276void DisplayDevice::setActiveRenderIntent(RenderIntent renderIntent) {
277 mActiveRenderIntent = renderIntent;
278}
279
Yiwei Zhang7c64f172018-03-07 14:52:28 -0800280void DisplayDevice::setColorTransform(const mat4& transform) {
281 const bool isIdentity = (transform == mat4());
282 mColorTransform =
283 isIdentity ? HAL_COLOR_TRANSFORM_IDENTITY : HAL_COLOR_TRANSFORM_ARBITRARY_MATRIX;
284}
285
286android_color_transform_t DisplayDevice::getColorTransform() const {
287 return mColorTransform;
288}
289
Peiyong Lin34beb7a2018-03-28 11:57:12 -0700290void DisplayDevice::setCompositionDataSpace(ui::Dataspace dataspace) {
Peiyong Lindd9b2ae2018-03-01 16:22:45 -0800291 mCompositionDataSpace = dataspace;
Courtney Goeltzenleuchter79d27242017-07-13 17:54:01 -0600292 ANativeWindow* const window = mNativeWindow.get();
Peiyong Lin34beb7a2018-03-28 11:57:12 -0700293 native_window_set_buffers_data_space(window, static_cast<android_dataspace>(dataspace));
Courtney Goeltzenleuchter79d27242017-07-13 17:54:01 -0600294}
Michael Wright28f24d02016-07-12 13:30:53 -0700295
Peiyong Lindd9b2ae2018-03-01 16:22:45 -0800296ui::Dataspace DisplayDevice::getCompositionDataSpace() const {
297 return mCompositionDataSpace;
298}
299
Michael Wright28f24d02016-07-12 13:30:53 -0700300// ----------------------------------------------------------------------------
Mathias Agopiand3ee2312012-08-02 14:01:42 -0700301
Mathias Agopian28947d72012-08-08 18:51:15 -0700302void DisplayDevice::setLayerStack(uint32_t stack) {
303 mLayerStack = stack;
304 dirtyRegion.set(bounds());
305}
306
307// ----------------------------------------------------------------------------
308
Mathias Agopianc1c05de2013-09-17 23:45:22 -0700309uint32_t DisplayDevice::getOrientationTransform() const {
310 uint32_t transform = 0;
311 switch (mOrientation) {
312 case DisplayState::eOrientationDefault:
313 transform = Transform::ROT_0;
314 break;
315 case DisplayState::eOrientation90:
316 transform = Transform::ROT_90;
317 break;
318 case DisplayState::eOrientation180:
319 transform = Transform::ROT_180;
320 break;
321 case DisplayState::eOrientation270:
322 transform = Transform::ROT_270;
323 break;
324 }
325 return transform;
326}
327
Mathias Agopian0f2f5ff2012-07-31 23:09:07 -0700328status_t DisplayDevice::orientationToTransfrom(
Mathias Agopian1b031492012-06-20 17:51:20 -0700329 int orientation, int w, int h, Transform* tr)
330{
331 uint32_t flags = 0;
332 switch (orientation) {
Mathias Agopian3165cc22012-08-08 19:42:09 -0700333 case DisplayState::eOrientationDefault:
Mathias Agopian1b031492012-06-20 17:51:20 -0700334 flags = Transform::ROT_0;
335 break;
Mathias Agopian3165cc22012-08-08 19:42:09 -0700336 case DisplayState::eOrientation90:
Mathias Agopian1b031492012-06-20 17:51:20 -0700337 flags = Transform::ROT_90;
338 break;
Mathias Agopian3165cc22012-08-08 19:42:09 -0700339 case DisplayState::eOrientation180:
Mathias Agopian1b031492012-06-20 17:51:20 -0700340 flags = Transform::ROT_180;
341 break;
Mathias Agopian3165cc22012-08-08 19:42:09 -0700342 case DisplayState::eOrientation270:
Mathias Agopian1b031492012-06-20 17:51:20 -0700343 flags = Transform::ROT_270;
344 break;
345 default:
346 return BAD_VALUE;
347 }
348 tr->set(flags, w, h);
349 return NO_ERROR;
350}
351
Michael Lentine47e45402014-07-18 15:34:25 -0700352void DisplayDevice::setDisplaySize(const int newWidth, const int newHeight) {
353 dirtyRegion.set(getBounds());
354
Lloyd Pique144e1162017-12-20 16:44:52 -0800355 mSurface->setNativeWindow(nullptr);
Michael Lentinef2568de2014-08-20 10:51:23 -0700356
Michael Lentine47e45402014-07-18 15:34:25 -0700357 mDisplaySurface->resizeBuffers(newWidth, newHeight);
358
359 ANativeWindow* const window = mNativeWindow.get();
Lloyd Pique144e1162017-12-20 16:44:52 -0800360 mSurface->setNativeWindow(window);
361 mDisplayWidth = mSurface->queryWidth();
362 mDisplayHeight = mSurface->queryHeight();
Michael Lentine47e45402014-07-18 15:34:25 -0700363
364 LOG_FATAL_IF(mDisplayWidth != newWidth,
365 "Unable to set new width to %d", newWidth);
366 LOG_FATAL_IF(mDisplayHeight != newHeight,
367 "Unable to set new height to %d", newHeight);
368}
369
Mathias Agopian00e8c7a2012-09-04 19:30:46 -0700370void DisplayDevice::setProjection(int orientation,
Mathias Agopianf5f714a2013-02-26 16:54:05 -0800371 const Rect& newViewport, const Rect& newFrame) {
372 Rect viewport(newViewport);
373 Rect frame(newFrame);
374
375 const int w = mDisplayWidth;
376 const int h = mDisplayHeight;
377
378 Transform R;
379 DisplayDevice::orientationToTransfrom(orientation, w, h, &R);
380
381 if (!frame.isValid()) {
382 // the destination frame can be invalid if it has never been set,
383 // in that case we assume the whole display frame.
384 frame = Rect(w, h);
385 }
386
387 if (viewport.isEmpty()) {
388 // viewport can be invalid if it has never been set, in that case
389 // we assume the whole display size.
390 // it's also invalid to have an empty viewport, so we handle that
391 // case in the same way.
392 viewport = Rect(w, h);
393 if (R.getOrientation() & Transform::ROT_90) {
394 // viewport is always specified in the logical orientation
395 // of the display (ie: post-rotation).
396 swap(viewport.right, viewport.bottom);
397 }
398 }
399
400 dirtyRegion.set(getBounds());
401
402 Transform TL, TP, S;
403 float src_width = viewport.width();
404 float src_height = viewport.height();
405 float dst_width = frame.width();
406 float dst_height = frame.height();
407 if (src_width != dst_width || src_height != dst_height) {
408 float sx = dst_width / src_width;
409 float sy = dst_height / src_height;
410 S.set(sx, 0, 0, sy);
411 }
412
413 float src_x = viewport.left;
414 float src_y = viewport.top;
415 float dst_x = frame.left;
416 float dst_y = frame.top;
417 TL.set(-src_x, -src_y);
418 TP.set(dst_x, dst_y);
419
420 // The viewport and frame are both in the logical orientation.
421 // Apply the logical translation, scale to physical size, apply the
422 // physical translation and finally rotate to the physical orientation.
423 mGlobalTransform = R * TP * S * TL;
424
425 const uint8_t type = mGlobalTransform.getType();
426 mNeedsFiltering = (!mGlobalTransform.preserveRects() ||
427 (type >= Transform::SCALE));
428
429 mScissor = mGlobalTransform.transform(viewport);
430 if (mScissor.isEmpty()) {
Mathias Agopian6c7f25a2013-05-09 20:37:10 -0700431 mScissor = getBounds();
Mathias Agopianf5f714a2013-02-26 16:54:05 -0800432 }
433
Mathias Agopianda8d0a52012-09-04 15:05:38 -0700434 mOrientation = orientation;
Pablo Ceballos021623b2016-04-15 17:31:51 -0700435 if (mType == DisplayType::DISPLAY_PRIMARY) {
436 uint32_t transform = 0;
437 switch (mOrientation) {
438 case DisplayState::eOrientationDefault:
439 transform = Transform::ROT_0;
440 break;
441 case DisplayState::eOrientation90:
442 transform = Transform::ROT_90;
443 break;
444 case DisplayState::eOrientation180:
445 transform = Transform::ROT_180;
446 break;
447 case DisplayState::eOrientation270:
448 transform = Transform::ROT_270;
449 break;
450 }
451 sPrimaryDisplayOrientation = transform;
452 }
Mathias Agopian00e8c7a2012-09-04 19:30:46 -0700453 mViewport = viewport;
454 mFrame = frame;
Mathias Agopian1b031492012-06-20 17:51:20 -0700455}
Mathias Agopian1d12d8a2012-09-18 01:38:00 -0700456
Pablo Ceballos021623b2016-04-15 17:31:51 -0700457uint32_t DisplayDevice::getPrimaryDisplayOrientationTransform() {
458 return sPrimaryDisplayOrientation;
459}
460
Mathias Agopian74d211a2013-04-22 16:55:35 +0200461void DisplayDevice::dump(String8& result) const {
Mathias Agopian1d12d8a2012-09-18 01:38:00 -0700462 const Transform& tr(mGlobalTransform);
Courtney Goeltzenleuchter152279d2017-08-14 18:18:30 -0600463 ANativeWindow* const window = mNativeWindow.get();
Courtney Goeltzenleuchter0ebaac32017-04-13 12:17:03 -0600464 result.appendFormat("+ DisplayDevice: %s\n", mDisplayName.string());
465 result.appendFormat(" type=%x, hwcId=%d, layerStack=%u, (%4dx%4d), ANativeWindow=%p "
466 "(%d:%d:%d:%d), orient=%2d (type=%08x), "
467 "flips=%u, isSecure=%d, powerMode=%d, activeConfig=%d, numLayers=%zu\n",
Courtney Goeltzenleuchter152279d2017-08-14 18:18:30 -0600468 mType, mHwcDisplayId, mLayerStack, mDisplayWidth, mDisplayHeight, window,
Lloyd Pique144e1162017-12-20 16:44:52 -0800469 mSurface->queryRedSize(), mSurface->queryGreenSize(),
470 mSurface->queryBlueSize(), mSurface->queryAlphaSize(), mOrientation,
471 tr.getType(), getPageFlipCount(), mIsSecure, mPowerMode, mActiveConfig,
Courtney Goeltzenleuchter0ebaac32017-04-13 12:17:03 -0600472 mVisibleLayersSortedByZ.size());
473 result.appendFormat(" v:[%d,%d,%d,%d], f:[%d,%d,%d,%d], s:[%d,%d,%d,%d],"
474 "transform:[[%0.3f,%0.3f,%0.3f][%0.3f,%0.3f,%0.3f][%0.3f,%0.3f,%0.3f]]\n",
475 mViewport.left, mViewport.top, mViewport.right, mViewport.bottom,
476 mFrame.left, mFrame.top, mFrame.right, mFrame.bottom, mScissor.left,
477 mScissor.top, mScissor.right, mScissor.bottom, tr[0][0], tr[1][0], tr[2][0],
478 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 -0600479 auto const surface = static_cast<Surface*>(window);
Peiyong Lin34beb7a2018-03-28 11:57:12 -0700480 ui::Dataspace dataspace = surface->getBuffersDataSpace();
Peiyong Lindd9b2ae2018-03-01 16:22:45 -0800481 result.appendFormat(" wideColorGamut=%d, hdr10=%d, colorMode=%s, dataspace: %s (%d)\n",
482 mHasWideColorGamut, mHasHdr10,
Chia-I Wu1e043612018-03-01 09:45:09 -0800483 decodeColorMode(mActiveColorMode).c_str(),
Peiyong Lin34beb7a2018-03-28 11:57:12 -0700484 dataspaceDetails(static_cast<android_dataspace>(dataspace)).c_str(), dataspace);
Mathias Agopian1d12d8a2012-09-18 01:38:00 -0700485
Jesse Hall99c7dbb2013-03-14 14:29:29 -0700486 String8 surfaceDump;
Dan Stozaf10c46e2014-11-11 10:32:31 -0800487 mDisplaySurface->dumpAsString(surfaceDump);
Jesse Hall99c7dbb2013-03-14 14:29:29 -0700488 result.append(surfaceDump);
Mathias Agopian1d12d8a2012-09-18 01:38:00 -0700489}
Irvelffc9efc2016-07-27 15:16:37 -0700490
491std::atomic<int32_t> DisplayDeviceState::nextDisplayId(1);
492
493DisplayDeviceState::DisplayDeviceState(DisplayDevice::DisplayType type, bool isSecure)
494 : type(type),
495 layerStack(DisplayDevice::NO_LAYER_STACK),
496 orientation(0),
497 width(0),
498 height(0),
499 isSecure(isSecure)
500{
501 viewport.makeInvalid();
502 frame.makeInvalid();
503}
Peiyong Linfd997e02018-03-28 15:29:00 -0700504
505} // namespace android