blob: 4ebe2915eae918d7bfbe704a331d729025456164 [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
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -080017#include <stdlib.h>
18#include <stdio.h>
19#include <string.h>
20#include <math.h>
21
22#include <cutils/properties.h>
23
Mathias Agopian076b1cc2009-04-10 14:24:30 -070024#include <utils/RefBase.h>
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -080025#include <utils/Log.h>
26
Mathias Agopianc666cae2012-07-25 18:56:13 -070027#include <ui/DisplayInfo.h>
Mathias Agopian076b1cc2009-04-10 14:24:30 -070028#include <ui/PixelFormat.h>
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -080029
Mathias Agopiane3c697f2013-02-14 17:11:02 -080030#include <gui/Surface.h>
Jamie Gennis1a4d8832012-08-02 20:11:05 -070031
Mathias Agopian076b1cc2009-04-10 14:24:30 -070032#include <hardware/gralloc.h>
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -080033
Jesse Hall99c7dbb2013-03-14 14:29:29 -070034#include "DisplayHardware/DisplaySurface.h"
Mathias Agopian1b031492012-06-20 17:51:20 -070035#include "DisplayHardware/HWComposer.h"
Mathias Agopian875d8e12013-06-07 15:35:48 -070036#include "RenderEngine/RenderEngine.h"
Mathias Agopian1b031492012-06-20 17:51:20 -070037
Mathias Agopianda8d0a52012-09-04 15:05:38 -070038#include "clz.h"
Mathias Agopian0f2f5ff2012-07-31 23:09:07 -070039#include "DisplayDevice.h"
Mathias Agopianc7d14e22011-08-01 16:32:21 -070040#include "SurfaceFlinger.h"
Mathias Agopian13127d82013-03-05 17:47:11 -080041#include "Layer.h"
Mathias Agopian1f7bec62010-06-25 18:02:21 -070042
Mathias Agopiana4912602012-07-12 14:25:33 -070043// ----------------------------------------------------------------------------
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -080044using namespace android;
Mathias Agopiana4912602012-07-12 14:25:33 -070045// ----------------------------------------------------------------------------
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -080046
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -080047/*
48 * Initialize the display to the specified values.
49 *
50 */
51
Mathias Agopian0f2f5ff2012-07-31 23:09:07 -070052DisplayDevice::DisplayDevice(
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -080053 const sp<SurfaceFlinger>& flinger,
Jamie Gennisdd3cb842012-10-19 18:19:11 -070054 DisplayType type,
Jesse Hallffe1f192013-03-22 15:13:48 -070055 int32_t hwcId,
Jesse Hall19e87292013-12-23 21:02:15 -080056 int format,
Jamie Gennisdd3cb842012-10-19 18:19:11 -070057 bool isSecure,
58 const wp<IBinder>& displayToken,
Jesse Hall99c7dbb2013-03-14 14:29:29 -070059 const sp<DisplaySurface>& displaySurface,
Mathias Agopiandb89edc2013-08-02 01:40:18 -070060 const sp<IGraphicBufferProducer>& producer,
Mathias Agopiana4912602012-07-12 14:25:33 -070061 EGLConfig config)
Mathias Agopian92a979a2012-08-02 18:32:23 -070062 : mFlinger(flinger),
Jesse Hallffe1f192013-03-22 15:13:48 -070063 mType(type), mHwcDisplayId(hwcId),
Chih-Wei Huang27e25622013-01-07 17:33:56 +080064 mDisplayToken(displayToken),
Jesse Hall99c7dbb2013-03-14 14:29:29 -070065 mDisplaySurface(displaySurface),
Mathias Agopian92a979a2012-08-02 18:32:23 -070066 mDisplay(EGL_NO_DISPLAY),
67 mSurface(EGL_NO_SURFACE),
Mathias Agopian92a979a2012-08-02 18:32:23 -070068 mDisplayWidth(), mDisplayHeight(), mFormat(),
69 mFlags(),
70 mPageFlipCount(),
Jamie Gennisdd3cb842012-10-19 18:19:11 -070071 mIsSecure(isSecure),
Mathias Agopian92a979a2012-08-02 18:32:23 -070072 mSecureLayerVisible(false),
73 mScreenAcquired(false),
Jesse Hall01e29052013-02-19 16:13:35 -080074 mLayerStack(NO_LAYER_STACK),
Mathias Agopianda8d0a52012-09-04 15:05:38 -070075 mOrientation()
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -080076{
Jesse Hall83cafff2013-09-16 15:24:53 -070077 mNativeWindow = new Surface(producer, false);
Jesse Hallffe1f192013-03-22 15:13:48 -070078 ANativeWindow* const window = mNativeWindow.get();
79
Jesse Hallffe1f192013-03-22 15:13:48 -070080 /*
81 * Create our display's surface
82 */
83
84 EGLSurface surface;
85 EGLint w, h;
86 EGLDisplay display = eglGetDisplay(EGL_DEFAULT_DISPLAY);
Jesse Hall19e87292013-12-23 21:02:15 -080087 if (config == EGL_NO_CONFIG) {
88 config = RenderEngine::chooseEglConfig(display, format);
89 }
Jesse Hallffe1f192013-03-22 15:13:48 -070090 surface = eglCreateWindowSurface(display, config, window, NULL);
91 eglQuerySurface(display, surface, EGL_WIDTH, &mDisplayWidth);
92 eglQuerySurface(display, surface, EGL_HEIGHT, &mDisplayHeight);
93
John Dong4ee56962014-02-21 12:37:59 -080094 // Make sure that composition can never be stalled by a virtual display
95 // consumer that isn't processing buffers fast enough. We have to do this
96 // in two places:
97 // * Here, in case the display is composed entirely by HWC.
98 // * In makeCurrent(), using eglSwapInterval. Some EGL drivers set the
99 // window's swap interval in eglMakeCurrent, so they'll override the
100 // interval we set here.
101 if (mType >= DisplayDevice::DISPLAY_VIRTUAL)
102 window->setSwapInterval(window, 0);
103
Jesse Hallffe1f192013-03-22 15:13:48 -0700104 mDisplay = display;
105 mSurface = surface;
106 mFormat = format;
107 mPageFlipCount = 0;
108 mViewport.makeInvalid();
109 mFrame.makeInvalid();
110
111 // virtual displays are always considered enabled
112 mScreenAcquired = (mType >= DisplayDevice::DISPLAY_VIRTUAL);
113
114 // Name the display. The name will be replaced shortly if the display
115 // was created with createDisplay().
116 switch (mType) {
117 case DISPLAY_PRIMARY:
118 mDisplayName = "Built-in Screen";
119 break;
120 case DISPLAY_EXTERNAL:
121 mDisplayName = "HDMI Screen";
122 break;
123 default:
124 mDisplayName = "Virtual Screen"; // e.g. Overlay #n
125 break;
126 }
127
128 // initialize the display orientation transform.
129 setProjection(DisplayState::eOrientationDefault, mViewport, mFrame);
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800130}
131
Mathias Agopian0f2f5ff2012-07-31 23:09:07 -0700132DisplayDevice::~DisplayDevice() {
Mathias Agopian92a979a2012-08-02 18:32:23 -0700133 if (mSurface != EGL_NO_SURFACE) {
134 eglDestroySurface(mDisplay, mSurface);
135 mSurface = EGL_NO_SURFACE;
136 }
137}
138
Jesse Hall02d86562013-03-25 14:43:23 -0700139void DisplayDevice::disconnect(HWComposer& hwc) {
140 if (mHwcDisplayId >= 0) {
141 hwc.disconnectDisplay(mHwcDisplayId);
142 if (mHwcDisplayId >= DISPLAY_VIRTUAL)
143 hwc.freeDisplayId(mHwcDisplayId);
144 mHwcDisplayId = -1;
145 }
146}
147
Mathias Agopian92a979a2012-08-02 18:32:23 -0700148bool DisplayDevice::isValid() const {
149 return mFlinger != NULL;
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800150}
151
Mathias Agopian0f2f5ff2012-07-31 23:09:07 -0700152int DisplayDevice::getWidth() const {
Mathias Agopiana4912602012-07-12 14:25:33 -0700153 return mDisplayWidth;
154}
155
Mathias Agopian0f2f5ff2012-07-31 23:09:07 -0700156int DisplayDevice::getHeight() const {
Mathias Agopiana4912602012-07-12 14:25:33 -0700157 return mDisplayHeight;
158}
159
Mathias Agopian0f2f5ff2012-07-31 23:09:07 -0700160PixelFormat DisplayDevice::getFormat() const {
Mathias Agopiana4912602012-07-12 14:25:33 -0700161 return mFormat;
162}
163
Mathias Agopian0f2f5ff2012-07-31 23:09:07 -0700164EGLSurface DisplayDevice::getEGLSurface() const {
Mathias Agopiana4912602012-07-12 14:25:33 -0700165 return mSurface;
166}
167
Mathias Agopian9e2463e2012-09-21 18:26:16 -0700168void DisplayDevice::setDisplayName(const String8& displayName) {
169 if (!displayName.isEmpty()) {
170 // never override the name with an empty name
171 mDisplayName = displayName;
172 }
173}
174
Mathias Agopian0f2f5ff2012-07-31 23:09:07 -0700175uint32_t DisplayDevice::getPageFlipCount() const {
Mathias Agopian076b1cc2009-04-10 14:24:30 -0700176 return mPageFlipCount;
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800177}
178
Mathias Agopian0f2f5ff2012-07-31 23:09:07 -0700179status_t DisplayDevice::compositionComplete() const {
Jesse Hall99c7dbb2013-03-14 14:29:29 -0700180 return mDisplaySurface->compositionComplete();
Mathias Agopian74faca22009-09-17 16:18:16 -0700181}
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800182
Mathias Agopian0f2f5ff2012-07-31 23:09:07 -0700183void DisplayDevice::flip(const Region& dirty) const
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800184{
Mathias Agopian875d8e12013-06-07 15:35:48 -0700185 mFlinger->getRenderEngine().checkErrors();
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800186
187 EGLDisplay dpy = mDisplay;
188 EGLSurface surface = mSurface;
189
Jesse Hall01e29052013-02-19 16:13:35 -0800190#ifdef EGL_ANDROID_swap_rectangle
Mathias Agopiandf3ca302009-05-04 19:29:25 -0700191 if (mFlags & SWAP_RECTANGLE) {
Mathias Agopianb8a55602009-06-26 19:06:36 -0700192 const Region newDirty(dirty.intersect(bounds()));
193 const Rect b(newDirty.getBounds());
Mathias Agopiandf3ca302009-05-04 19:29:25 -0700194 eglSetSwapRectangleANDROID(dpy, surface,
195 b.left, b.top, b.width(), b.height());
Jesse Hall01e29052013-02-19 16:13:35 -0800196 }
Dan Stozac7014012014-02-14 15:03:43 -0800197#else
198 (void) dirty; // Eliminate unused parameter warning
Mathias Agopian5e78e092009-06-11 17:19:54 -0700199#endif
Mathias Agopiand8707032012-09-18 01:21:55 -0700200
Mathias Agopian076b1cc2009-04-10 14:24:30 -0700201 mPageFlipCount++;
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800202}
203
Dan Stoza71433162014-02-04 16:22:36 -0800204status_t DisplayDevice::beginFrame(bool mustRecompose) const {
205 return mDisplaySurface->beginFrame(mustRecompose);
Jesse Hall028dc8f2013-08-20 16:35:32 -0700206}
207
Jesse Hall38efe862013-04-06 23:12:29 -0700208status_t DisplayDevice::prepareFrame(const HWComposer& hwc) const {
209 DisplaySurface::CompositionType compositionType;
210 bool haveGles = hwc.hasGlesComposition(mHwcDisplayId);
211 bool haveHwc = hwc.hasHwcComposition(mHwcDisplayId);
212 if (haveGles && haveHwc) {
213 compositionType = DisplaySurface::COMPOSITION_MIXED;
214 } else if (haveGles) {
215 compositionType = DisplaySurface::COMPOSITION_GLES;
216 } else if (haveHwc) {
217 compositionType = DisplaySurface::COMPOSITION_HWC;
218 } else {
219 // Nothing to do -- when turning the screen off we get a frame like
220 // this. Call it a HWC frame since we won't be doing any GLES work but
221 // will do a prepare/set cycle.
222 compositionType = DisplaySurface::COMPOSITION_HWC;
223 }
224 return mDisplaySurface->prepareFrame(compositionType);
225}
226
Mathias Agopianda27af92012-09-13 18:17:13 -0700227void DisplayDevice::swapBuffers(HWComposer& hwc) const {
Andy McFadden22a99f02013-08-20 16:04:47 -0700228 // We need to call eglSwapBuffers() if:
229 // (1) we don't have a hardware composer, or
230 // (2) we did GLES composition this frame, and either
231 // (a) we have framebuffer target support (not present on legacy
232 // devices, where HWComposer::commit() handles things); or
233 // (b) this is a virtual display
Jesse Hall99c7dbb2013-03-14 14:29:29 -0700234 if (hwc.initCheck() != NO_ERROR ||
235 (hwc.hasGlesComposition(mHwcDisplayId) &&
Andy McFadden22a99f02013-08-20 16:04:47 -0700236 (hwc.supportsFramebufferTarget() || mType >= DISPLAY_VIRTUAL))) {
Jesse Hall99c7dbb2013-03-14 14:29:29 -0700237 EGLBoolean success = eglSwapBuffers(mDisplay, mSurface);
238 if (!success) {
239 EGLint error = eglGetError();
240 if (error == EGL_CONTEXT_LOST ||
241 mType == DisplayDevice::DISPLAY_PRIMARY) {
242 LOG_ALWAYS_FATAL("eglSwapBuffers(%p, %p) failed with 0x%08x",
243 mDisplay, mSurface, error);
244 } else {
245 ALOGE("eglSwapBuffers(%p, %p) failed with 0x%08x",
246 mDisplay, mSurface, error);
Mathias Agopianda27af92012-09-13 18:17:13 -0700247 }
248 }
249 }
Mathias Agopian52e21482012-09-24 18:07:21 -0700250
Jesse Hall99c7dbb2013-03-14 14:29:29 -0700251 status_t result = mDisplaySurface->advanceFrame();
252 if (result != NO_ERROR) {
253 ALOGE("[%s] failed pushing new frame to HWC: %d",
254 mDisplayName.string(), result);
Mathias Agopian32341382012-09-25 19:16:28 -0700255 }
Mathias Agopianda27af92012-09-13 18:17:13 -0700256}
257
258void DisplayDevice::onSwapBuffersCompleted(HWComposer& hwc) const {
259 if (hwc.initCheck() == NO_ERROR) {
Jesse Hall851cfe82013-03-20 13:44:00 -0700260 mDisplaySurface->onFrameCommitted();
Mathias Agopianda27af92012-09-13 18:17:13 -0700261 }
262}
263
Mathias Agopian0f2f5ff2012-07-31 23:09:07 -0700264uint32_t DisplayDevice::getFlags() const
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800265{
266 return mFlags;
267}
268
Mathias Agopian875d8e12013-06-07 15:35:48 -0700269EGLBoolean DisplayDevice::makeCurrent(EGLDisplay dpy, EGLContext ctx) const {
Mathias Agopianda8d0a52012-09-04 15:05:38 -0700270 EGLBoolean result = EGL_TRUE;
Mathias Agopian52bbb1a2012-07-31 19:01:53 -0700271 EGLSurface sur = eglGetCurrentSurface(EGL_DRAW);
Mathias Agopian875d8e12013-06-07 15:35:48 -0700272 if (sur != mSurface) {
273 result = eglMakeCurrent(dpy, mSurface, mSurface, ctx);
Mathias Agopianda8d0a52012-09-04 15:05:38 -0700274 if (result == EGL_TRUE) {
Jesse Hallf460f552013-08-06 17:08:53 -0700275 if (mType >= DisplayDevice::DISPLAY_VIRTUAL)
276 eglSwapInterval(dpy, 0);
Mathias Agopianda8d0a52012-09-04 15:05:38 -0700277 }
Mathias Agopian52bbb1a2012-07-31 19:01:53 -0700278 }
Mathias Agopian931bda12013-08-28 18:11:46 -0700279 setViewportAndProjection();
Mathias Agopianda8d0a52012-09-04 15:05:38 -0700280 return result;
Mathias Agopian52bbb1a2012-07-31 19:01:53 -0700281}
282
Mathias Agopian875d8e12013-06-07 15:35:48 -0700283void DisplayDevice::setViewportAndProjection() const {
284 size_t w = mDisplayWidth;
285 size_t h = mDisplayHeight;
Dan Stozac1879002014-05-22 15:59:05 -0700286 Rect sourceCrop(0, 0, w, h);
287 mFlinger->getRenderEngine().setViewportAndProjection(w, h, sourceCrop, h, false);
Mathias Agopianbae92d02012-09-28 01:00:47 -0700288}
289
Mathias Agopian1b031492012-06-20 17:51:20 -0700290// ----------------------------------------------------------------------------
291
Mathias Agopian13127d82013-03-05 17:47:11 -0800292void DisplayDevice::setVisibleLayersSortedByZ(const Vector< sp<Layer> >& layers) {
Mathias Agopian3b1d2b62012-07-11 13:48:17 -0700293 mVisibleLayersSortedByZ = layers;
Mathias Agopianef7b9c72012-08-10 15:22:19 -0700294 mSecureLayerVisible = false;
Mathias Agopian3b1d2b62012-07-11 13:48:17 -0700295 size_t count = layers.size();
296 for (size_t i=0 ; i<count ; i++) {
Mathias Agopian13127d82013-03-05 17:47:11 -0800297 const sp<Layer>& layer(layers[i]);
Mathias Agopianf5f714a2013-02-26 16:54:05 -0800298 if (layer->isSecure()) {
Mathias Agopian3b1d2b62012-07-11 13:48:17 -0700299 mSecureLayerVisible = true;
300 }
301 }
302}
303
Mathias Agopian13127d82013-03-05 17:47:11 -0800304const Vector< sp<Layer> >& DisplayDevice::getVisibleLayersSortedByZ() const {
Mathias Agopian3b1d2b62012-07-11 13:48:17 -0700305 return mVisibleLayersSortedByZ;
306}
307
Mathias Agopian0f2f5ff2012-07-31 23:09:07 -0700308bool DisplayDevice::getSecureLayerVisible() const {
Mathias Agopian3b1d2b62012-07-11 13:48:17 -0700309 return mSecureLayerVisible;
310}
311
Mathias Agopiancd60f992012-08-16 16:28:27 -0700312Region DisplayDevice::getDirtyRegion(bool repaintEverything) const {
313 Region dirty;
Mathias Agopiancd60f992012-08-16 16:28:27 -0700314 if (repaintEverything) {
315 dirty.set(getBounds());
316 } else {
Mathias Agopianda8d0a52012-09-04 15:05:38 -0700317 const Transform& planeTransform(mGlobalTransform);
Mathias Agopiancd60f992012-08-16 16:28:27 -0700318 dirty = planeTransform.transform(this->dirtyRegion);
319 dirty.andSelf(getBounds());
320 }
321 return dirty;
322}
323
Mathias Agopian3b1d2b62012-07-11 13:48:17 -0700324// ----------------------------------------------------------------------------
325
Mathias Agopiand3ee2312012-08-02 14:01:42 -0700326bool DisplayDevice::canDraw() const {
327 return mScreenAcquired;
328}
329
330void DisplayDevice::releaseScreen() const {
331 mScreenAcquired = false;
332}
333
334void DisplayDevice::acquireScreen() const {
335 mScreenAcquired = true;
336}
337
338bool DisplayDevice::isScreenAcquired() const {
339 return mScreenAcquired;
340}
341
342// ----------------------------------------------------------------------------
343
Mathias Agopian28947d72012-08-08 18:51:15 -0700344void DisplayDevice::setLayerStack(uint32_t stack) {
345 mLayerStack = stack;
346 dirtyRegion.set(bounds());
347}
348
349// ----------------------------------------------------------------------------
350
Mathias Agopianc1c05de2013-09-17 23:45:22 -0700351uint32_t DisplayDevice::getOrientationTransform() const {
352 uint32_t transform = 0;
353 switch (mOrientation) {
354 case DisplayState::eOrientationDefault:
355 transform = Transform::ROT_0;
356 break;
357 case DisplayState::eOrientation90:
358 transform = Transform::ROT_90;
359 break;
360 case DisplayState::eOrientation180:
361 transform = Transform::ROT_180;
362 break;
363 case DisplayState::eOrientation270:
364 transform = Transform::ROT_270;
365 break;
366 }
367 return transform;
368}
369
Mathias Agopian0f2f5ff2012-07-31 23:09:07 -0700370status_t DisplayDevice::orientationToTransfrom(
Mathias Agopian1b031492012-06-20 17:51:20 -0700371 int orientation, int w, int h, Transform* tr)
372{
373 uint32_t flags = 0;
374 switch (orientation) {
Mathias Agopian3165cc22012-08-08 19:42:09 -0700375 case DisplayState::eOrientationDefault:
Mathias Agopian1b031492012-06-20 17:51:20 -0700376 flags = Transform::ROT_0;
377 break;
Mathias Agopian3165cc22012-08-08 19:42:09 -0700378 case DisplayState::eOrientation90:
Mathias Agopian1b031492012-06-20 17:51:20 -0700379 flags = Transform::ROT_90;
380 break;
Mathias Agopian3165cc22012-08-08 19:42:09 -0700381 case DisplayState::eOrientation180:
Mathias Agopian1b031492012-06-20 17:51:20 -0700382 flags = Transform::ROT_180;
383 break;
Mathias Agopian3165cc22012-08-08 19:42:09 -0700384 case DisplayState::eOrientation270:
Mathias Agopian1b031492012-06-20 17:51:20 -0700385 flags = Transform::ROT_270;
386 break;
387 default:
388 return BAD_VALUE;
389 }
390 tr->set(flags, w, h);
391 return NO_ERROR;
392}
393
Mathias Agopian00e8c7a2012-09-04 19:30:46 -0700394void DisplayDevice::setProjection(int orientation,
Mathias Agopianf5f714a2013-02-26 16:54:05 -0800395 const Rect& newViewport, const Rect& newFrame) {
396 Rect viewport(newViewport);
397 Rect frame(newFrame);
398
399 const int w = mDisplayWidth;
400 const int h = mDisplayHeight;
401
402 Transform R;
403 DisplayDevice::orientationToTransfrom(orientation, w, h, &R);
404
405 if (!frame.isValid()) {
406 // the destination frame can be invalid if it has never been set,
407 // in that case we assume the whole display frame.
408 frame = Rect(w, h);
409 }
410
411 if (viewport.isEmpty()) {
412 // viewport can be invalid if it has never been set, in that case
413 // we assume the whole display size.
414 // it's also invalid to have an empty viewport, so we handle that
415 // case in the same way.
416 viewport = Rect(w, h);
417 if (R.getOrientation() & Transform::ROT_90) {
418 // viewport is always specified in the logical orientation
419 // of the display (ie: post-rotation).
420 swap(viewport.right, viewport.bottom);
421 }
422 }
423
424 dirtyRegion.set(getBounds());
425
426 Transform TL, TP, S;
427 float src_width = viewport.width();
428 float src_height = viewport.height();
429 float dst_width = frame.width();
430 float dst_height = frame.height();
431 if (src_width != dst_width || src_height != dst_height) {
432 float sx = dst_width / src_width;
433 float sy = dst_height / src_height;
434 S.set(sx, 0, 0, sy);
435 }
436
437 float src_x = viewport.left;
438 float src_y = viewport.top;
439 float dst_x = frame.left;
440 float dst_y = frame.top;
441 TL.set(-src_x, -src_y);
442 TP.set(dst_x, dst_y);
443
444 // The viewport and frame are both in the logical orientation.
445 // Apply the logical translation, scale to physical size, apply the
446 // physical translation and finally rotate to the physical orientation.
447 mGlobalTransform = R * TP * S * TL;
448
449 const uint8_t type = mGlobalTransform.getType();
450 mNeedsFiltering = (!mGlobalTransform.preserveRects() ||
451 (type >= Transform::SCALE));
452
453 mScissor = mGlobalTransform.transform(viewport);
454 if (mScissor.isEmpty()) {
Mathias Agopian6c7f25a2013-05-09 20:37:10 -0700455 mScissor = getBounds();
Mathias Agopianf5f714a2013-02-26 16:54:05 -0800456 }
457
Mathias Agopianda8d0a52012-09-04 15:05:38 -0700458 mOrientation = orientation;
Mathias Agopian00e8c7a2012-09-04 19:30:46 -0700459 mViewport = viewport;
460 mFrame = frame;
Mathias Agopian1b031492012-06-20 17:51:20 -0700461}
Mathias Agopian1d12d8a2012-09-18 01:38:00 -0700462
Mathias Agopian74d211a2013-04-22 16:55:35 +0200463void DisplayDevice::dump(String8& result) const {
Mathias Agopian1d12d8a2012-09-18 01:38:00 -0700464 const Transform& tr(mGlobalTransform);
Mathias Agopian74d211a2013-04-22 16:55:35 +0200465 result.appendFormat(
Mathias Agopian1d12d8a2012-09-18 01:38:00 -0700466 "+ DisplayDevice: %s\n"
Jesse Hall02d86562013-03-25 14:43:23 -0700467 " type=%x, hwcId=%d, layerStack=%u, (%4dx%4d), ANativeWindow=%p, orient=%2d (type=%08x), "
Greg Hackmann86efcc02014-03-07 12:44:02 -0800468 "flips=%u, isSecure=%d, secureVis=%d, acquired=%d, numLayers=%zu\n"
Mathias Agopian766dc492012-10-30 18:08:06 -0700469 " v:[%d,%d,%d,%d], f:[%d,%d,%d,%d], s:[%d,%d,%d,%d],"
Mathias Agopian1d12d8a2012-09-18 01:38:00 -0700470 "transform:[[%0.3f,%0.3f,%0.3f][%0.3f,%0.3f,%0.3f][%0.3f,%0.3f,%0.3f]]\n",
Jesse Hall02d86562013-03-25 14:43:23 -0700471 mDisplayName.string(), mType, mHwcDisplayId,
Mathias Agopian1d12d8a2012-09-18 01:38:00 -0700472 mLayerStack, mDisplayWidth, mDisplayHeight, mNativeWindow.get(),
473 mOrientation, tr.getType(), getPageFlipCount(),
Jamie Gennisdd3cb842012-10-19 18:19:11 -0700474 mIsSecure, mSecureLayerVisible, mScreenAcquired, mVisibleLayersSortedByZ.size(),
Mathias Agopian1d12d8a2012-09-18 01:38:00 -0700475 mViewport.left, mViewport.top, mViewport.right, mViewport.bottom,
476 mFrame.left, mFrame.top, mFrame.right, mFrame.bottom,
Mathias Agopian766dc492012-10-30 18:08:06 -0700477 mScissor.left, mScissor.top, mScissor.right, mScissor.bottom,
Mathias Agopian1d12d8a2012-09-18 01:38:00 -0700478 tr[0][0], tr[1][0], tr[2][0],
479 tr[0][1], tr[1][1], tr[2][1],
480 tr[0][2], tr[1][2], tr[2][2]);
481
Jesse Hall99c7dbb2013-03-14 14:29:29 -0700482 String8 surfaceDump;
483 mDisplaySurface->dump(surfaceDump);
484 result.append(surfaceDump);
Mathias Agopian1d12d8a2012-09-18 01:38:00 -0700485}