blob: 8cf527a6d2e354beb4a15d50e32ce77743136237 [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
Jamie Gennis1a4d8832012-08-02 20:11:05 -070030#include <gui/SurfaceTextureClient.h>
31
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -080032#include <GLES/gl.h>
Mathias Agopian076b1cc2009-04-10 14:24:30 -070033#include <EGL/egl.h>
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -080034#include <EGL/eglext.h>
35
Mathias Agopian076b1cc2009-04-10 14:24:30 -070036#include <hardware/gralloc.h>
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -080037
Mathias Agopian1b031492012-06-20 17:51:20 -070038#include "DisplayHardware/FramebufferSurface.h"
Mathias Agopian1b031492012-06-20 17:51:20 -070039#include "DisplayHardware/HWComposer.h"
40
Mathias Agopianda8d0a52012-09-04 15:05:38 -070041#include "clz.h"
Mathias Agopian0f2f5ff2012-07-31 23:09:07 -070042#include "DisplayDevice.h"
Mathias Agopian1f7bec62010-06-25 18:02:21 -070043#include "GLExtensions.h"
Mathias Agopianc7d14e22011-08-01 16:32:21 -070044#include "SurfaceFlinger.h"
Mathias Agopian921e6ac2012-07-23 23:11:29 -070045#include "LayerBase.h"
Mathias Agopian1f7bec62010-06-25 18:02:21 -070046
Mathias Agopiana4912602012-07-12 14:25:33 -070047// ----------------------------------------------------------------------------
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -080048using namespace android;
Mathias Agopiana4912602012-07-12 14:25:33 -070049// ----------------------------------------------------------------------------
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -080050
51static __attribute__((noinline))
52void checkGLErrors()
53{
Mathias Agopiancbb288b2009-09-07 16:32:45 -070054 do {
55 // there could be more than one error flag
56 GLenum error = glGetError();
57 if (error == GL_NO_ERROR)
58 break;
Steve Blocke6f43dd2012-01-06 19:20:56 +000059 ALOGE("GL error 0x%04x", int(error));
Mathias Agopiancbb288b2009-09-07 16:32:45 -070060 } while(true);
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -080061}
62
Mathias Agopiana4912602012-07-12 14:25:33 -070063// ----------------------------------------------------------------------------
64
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -080065/*
66 * Initialize the display to the specified values.
67 *
68 */
69
Mathias Agopian0f2f5ff2012-07-31 23:09:07 -070070DisplayDevice::DisplayDevice(
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -080071 const sp<SurfaceFlinger>& flinger,
Jamie Gennisdd3cb842012-10-19 18:19:11 -070072 DisplayType type,
73 bool isSecure,
74 const wp<IBinder>& displayToken,
Jamie Gennis1a4d8832012-08-02 20:11:05 -070075 const sp<ANativeWindow>& nativeWindow,
76 const sp<FramebufferSurface>& framebufferSurface,
Mathias Agopiana4912602012-07-12 14:25:33 -070077 EGLConfig config)
Mathias Agopian92a979a2012-08-02 18:32:23 -070078 : mFlinger(flinger),
Mathias Agopian3ee454a2012-08-27 16:28:24 -070079 mType(type), mHwcDisplayId(-1),
Jamie Gennis1a4d8832012-08-02 20:11:05 -070080 mNativeWindow(nativeWindow),
81 mFramebufferSurface(framebufferSurface),
Mathias Agopian92a979a2012-08-02 18:32:23 -070082 mDisplay(EGL_NO_DISPLAY),
83 mSurface(EGL_NO_SURFACE),
84 mContext(EGL_NO_CONTEXT),
Mathias Agopian92a979a2012-08-02 18:32:23 -070085 mDisplayWidth(), mDisplayHeight(), mFormat(),
86 mFlags(),
87 mPageFlipCount(),
Jamie Gennisdd3cb842012-10-19 18:19:11 -070088 mIsSecure(isSecure),
Mathias Agopian92a979a2012-08-02 18:32:23 -070089 mSecureLayerVisible(false),
90 mScreenAcquired(false),
Mathias Agopianda8d0a52012-09-04 15:05:38 -070091 mLayerStack(0),
92 mOrientation()
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -080093{
Mathias Agopiana4912602012-07-12 14:25:33 -070094 init(config);
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -080095}
96
Mathias Agopian0f2f5ff2012-07-31 23:09:07 -070097DisplayDevice::~DisplayDevice() {
Mathias Agopian92a979a2012-08-02 18:32:23 -070098 if (mSurface != EGL_NO_SURFACE) {
99 eglDestroySurface(mDisplay, mSurface);
100 mSurface = EGL_NO_SURFACE;
101 }
102}
103
104bool DisplayDevice::isValid() const {
105 return mFlinger != NULL;
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800106}
107
Mathias Agopian0f2f5ff2012-07-31 23:09:07 -0700108int DisplayDevice::getWidth() const {
Mathias Agopiana4912602012-07-12 14:25:33 -0700109 return mDisplayWidth;
110}
111
Mathias Agopian0f2f5ff2012-07-31 23:09:07 -0700112int DisplayDevice::getHeight() const {
Mathias Agopiana4912602012-07-12 14:25:33 -0700113 return mDisplayHeight;
114}
115
Mathias Agopian0f2f5ff2012-07-31 23:09:07 -0700116PixelFormat DisplayDevice::getFormat() const {
Mathias Agopiana4912602012-07-12 14:25:33 -0700117 return mFormat;
118}
119
Mathias Agopian0f2f5ff2012-07-31 23:09:07 -0700120EGLSurface DisplayDevice::getEGLSurface() const {
Mathias Agopiana4912602012-07-12 14:25:33 -0700121 return mSurface;
122}
123
Mathias Agopian0f2f5ff2012-07-31 23:09:07 -0700124void DisplayDevice::init(EGLConfig config)
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800125{
Mathias Agopiana4912602012-07-12 14:25:33 -0700126 ANativeWindow* const window = mNativeWindow.get();
127
Mathias Agopian61630912011-07-06 16:35:30 -0700128 int format;
Mathias Agopian61630912011-07-06 16:35:30 -0700129 window->query(window, NATIVE_WINDOW_FORMAT, &format);
Mathias Agopianb5dd9c02012-03-22 12:15:54 -0700130
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800131 /*
Mathias Agopiana4912602012-07-12 14:25:33 -0700132 * Create our display's surface
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800133 */
134
Mathias Agopiana4912602012-07-12 14:25:33 -0700135 EGLSurface surface;
136 EGLint w, h;
137 EGLDisplay display = eglGetDisplay(EGL_DEFAULT_DISPLAY);
138 surface = eglCreateWindowSurface(display, config, window, NULL);
Mathias Agopian1b031492012-06-20 17:51:20 -0700139 eglQuerySurface(display, surface, EGL_WIDTH, &mDisplayWidth);
140 eglQuerySurface(display, surface, EGL_HEIGHT, &mDisplayHeight);
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800141
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800142 mDisplay = display;
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800143 mSurface = surface;
Mathias Agopiana4912602012-07-12 14:25:33 -0700144 mFormat = format;
Mathias Agopian076b1cc2009-04-10 14:24:30 -0700145 mPageFlipCount = 0;
Mathias Agopianda8d0a52012-09-04 15:05:38 -0700146 mViewport.makeInvalid();
147 mFrame.makeInvalid();
Mathias Agopian1f7bec62010-06-25 18:02:21 -0700148
Mathias Agopian5f20e2d2012-08-10 18:50:38 -0700149 // external displays are always considered enabled
Mathias Agopian3ee454a2012-08-27 16:28:24 -0700150 mScreenAcquired = (mType >= DisplayDevice::NUM_DISPLAY_TYPES);
151
152 // get an h/w composer ID
153 mHwcDisplayId = mFlinger->allocateHwcDisplayId(mType);
Mathias Agopian5f20e2d2012-08-10 18:50:38 -0700154
Andy McFadden8dfa92f2012-09-17 18:27:17 -0700155 // Name the display. The name will be replaced shortly if the display
156 // was created with createDisplay().
157 switch (mType) {
158 case DISPLAY_PRIMARY:
159 mDisplayName = "Built-in Screen";
160 break;
161 case DISPLAY_EXTERNAL:
162 mDisplayName = "HDMI Screen";
163 break;
164 default:
165 mDisplayName = "Virtual Screen"; // e.g. Overlay #n
166 break;
167 }
168
Mathias Agopian98a121a2012-07-24 21:08:59 -0700169 // initialize the display orientation transform.
Mathias Agopian00e8c7a2012-09-04 19:30:46 -0700170 setProjection(DisplayState::eOrientationDefault, mViewport, mFrame);
Mathias Agopiana350ff92010-08-10 17:14:02 -0700171}
172
Mathias Agopian9e2463e2012-09-21 18:26:16 -0700173void DisplayDevice::setDisplayName(const String8& displayName) {
174 if (!displayName.isEmpty()) {
175 // never override the name with an empty name
176 mDisplayName = displayName;
177 }
178}
179
Mathias Agopian0f2f5ff2012-07-31 23:09:07 -0700180uint32_t DisplayDevice::getPageFlipCount() const {
Mathias Agopian076b1cc2009-04-10 14:24:30 -0700181 return mPageFlipCount;
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800182}
183
Mathias Agopian0f2f5ff2012-07-31 23:09:07 -0700184status_t DisplayDevice::compositionComplete() const {
Mathias Agopiana4912602012-07-12 14:25:33 -0700185 if (mFramebufferSurface == NULL) {
186 return NO_ERROR;
187 }
188 return mFramebufferSurface->compositionComplete();
Mathias Agopian74faca22009-09-17 16:18:16 -0700189}
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800190
Mathias Agopian0f2f5ff2012-07-31 23:09:07 -0700191void DisplayDevice::flip(const Region& dirty) const
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800192{
193 checkGLErrors();
194
195 EGLDisplay dpy = mDisplay;
196 EGLSurface surface = mSurface;
197
Mathias Agopian5e78e092009-06-11 17:19:54 -0700198#ifdef EGL_ANDROID_swap_rectangle
Mathias Agopiandf3ca302009-05-04 19:29:25 -0700199 if (mFlags & SWAP_RECTANGLE) {
Mathias Agopianb8a55602009-06-26 19:06:36 -0700200 const Region newDirty(dirty.intersect(bounds()));
201 const Rect b(newDirty.getBounds());
Mathias Agopiandf3ca302009-05-04 19:29:25 -0700202 eglSetSwapRectangleANDROID(dpy, surface,
203 b.left, b.top, b.width(), b.height());
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800204 }
Mathias Agopian5e78e092009-06-11 17:19:54 -0700205#endif
Mathias Agopiand8707032012-09-18 01:21:55 -0700206
Mathias Agopian076b1cc2009-04-10 14:24:30 -0700207 mPageFlipCount++;
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800208}
209
Mathias Agopianda27af92012-09-13 18:17:13 -0700210void DisplayDevice::swapBuffers(HWComposer& hwc) const {
Mathias Agopian52e21482012-09-24 18:07:21 -0700211 EGLBoolean success = EGL_TRUE;
Mathias Agopianda27af92012-09-13 18:17:13 -0700212 if (hwc.initCheck() != NO_ERROR) {
213 // no HWC, we call eglSwapBuffers()
Mathias Agopian52e21482012-09-24 18:07:21 -0700214 success = eglSwapBuffers(mDisplay, mSurface);
Mathias Agopianda27af92012-09-13 18:17:13 -0700215 } else {
Mathias Agopiand8707032012-09-18 01:21:55 -0700216 // We have a valid HWC, but not all displays can use it, in particular
217 // the virtual displays are on their own.
218 // TODO: HWC 1.2 will allow virtual displays
219 if (mType >= DisplayDevice::DISPLAY_VIRTUAL) {
220 // always call eglSwapBuffers() for virtual displays
Mathias Agopian52e21482012-09-24 18:07:21 -0700221 success = eglSwapBuffers(mDisplay, mSurface);
Mathias Agopiand8707032012-09-18 01:21:55 -0700222 } else if (hwc.supportsFramebufferTarget()) {
223 // as of hwc 1.1 we always call eglSwapBuffers if we have some
224 // GLES layers
225 if (hwc.hasGlesComposition(mType)) {
Mathias Agopian52e21482012-09-24 18:07:21 -0700226 success = eglSwapBuffers(mDisplay, mSurface);
Mathias Agopianda27af92012-09-13 18:17:13 -0700227 }
Mathias Agopiand8707032012-09-18 01:21:55 -0700228 } else {
229 // HWC doesn't have the framebuffer target, we don't call
230 // eglSwapBuffers(), since this is handled by HWComposer::commit().
Mathias Agopianda27af92012-09-13 18:17:13 -0700231 }
232 }
Mathias Agopian52e21482012-09-24 18:07:21 -0700233
Mathias Agopian32341382012-09-25 19:16:28 -0700234 if (!success) {
235 EGLint error = eglGetError();
236 if (error == EGL_CONTEXT_LOST ||
237 mType == DisplayDevice::DISPLAY_PRIMARY) {
238 LOG_ALWAYS_FATAL("eglSwapBuffers(%p, %p) failed with 0x%08x",
Mathias Agopianb8fc00b2012-10-09 16:43:50 -0700239 mDisplay, mSurface, error);
Mathias Agopian32341382012-09-25 19:16:28 -0700240 }
241 }
Mathias Agopianda27af92012-09-13 18:17:13 -0700242}
243
244void DisplayDevice::onSwapBuffersCompleted(HWComposer& hwc) const {
245 if (hwc.initCheck() == NO_ERROR) {
246 if (hwc.supportsFramebufferTarget()) {
247 int fd = hwc.getAndResetReleaseFenceFd(mType);
248 mFramebufferSurface->setReleaseFenceFd(fd);
249 }
250 }
251}
252
Mathias Agopian0f2f5ff2012-07-31 23:09:07 -0700253uint32_t DisplayDevice::getFlags() const
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800254{
255 return mFlags;
256}
257
Mathias Agopianda8d0a52012-09-04 15:05:38 -0700258EGLBoolean DisplayDevice::makeCurrent(EGLDisplay dpy,
259 const sp<const DisplayDevice>& hw, EGLContext ctx) {
260 EGLBoolean result = EGL_TRUE;
Mathias Agopian52bbb1a2012-07-31 19:01:53 -0700261 EGLSurface sur = eglGetCurrentSurface(EGL_DRAW);
Mathias Agopian42977342012-08-05 00:40:46 -0700262 if (sur != hw->mSurface) {
Mathias Agopianda8d0a52012-09-04 15:05:38 -0700263 result = eglMakeCurrent(dpy, hw->mSurface, hw->mSurface, ctx);
264 if (result == EGL_TRUE) {
Mathias Agopianbae92d02012-09-28 01:00:47 -0700265 setViewportAndProjection(hw);
Mathias Agopianda8d0a52012-09-04 15:05:38 -0700266 }
Mathias Agopian52bbb1a2012-07-31 19:01:53 -0700267 }
Mathias Agopianda8d0a52012-09-04 15:05:38 -0700268 return result;
Mathias Agopian52bbb1a2012-07-31 19:01:53 -0700269}
270
Mathias Agopianbae92d02012-09-28 01:00:47 -0700271void DisplayDevice::setViewportAndProjection(const sp<const DisplayDevice>& hw) {
272 GLsizei w = hw->mDisplayWidth;
273 GLsizei h = hw->mDisplayHeight;
274 glViewport(0, 0, w, h);
275 glMatrixMode(GL_PROJECTION);
276 glLoadIdentity();
277 // put the origin in the left-bottom corner
278 glOrthof(0, w, 0, h, 0, 1); // l=0, r=w ; b=0, t=h
Mathias Agopian135e5892012-09-30 16:43:20 -0700279 glMatrixMode(GL_MODELVIEW);
Mathias Agopianbae92d02012-09-28 01:00:47 -0700280}
281
Mathias Agopian1b031492012-06-20 17:51:20 -0700282// ----------------------------------------------------------------------------
283
Mathias Agopian0f2f5ff2012-07-31 23:09:07 -0700284void DisplayDevice::setVisibleLayersSortedByZ(const Vector< sp<LayerBase> >& layers) {
Mathias Agopian3b1d2b62012-07-11 13:48:17 -0700285 mVisibleLayersSortedByZ = layers;
Mathias Agopianef7b9c72012-08-10 15:22:19 -0700286 mSecureLayerVisible = false;
Mathias Agopian3b1d2b62012-07-11 13:48:17 -0700287 size_t count = layers.size();
288 for (size_t i=0 ; i<count ; i++) {
289 if (layers[i]->isSecure()) {
290 mSecureLayerVisible = true;
291 }
292 }
293}
294
Mathias Agopian3ee454a2012-08-27 16:28:24 -0700295const Vector< sp<LayerBase> >& DisplayDevice::getVisibleLayersSortedByZ() const {
Mathias Agopian3b1d2b62012-07-11 13:48:17 -0700296 return mVisibleLayersSortedByZ;
297}
298
Mathias Agopian0f2f5ff2012-07-31 23:09:07 -0700299bool DisplayDevice::getSecureLayerVisible() const {
Mathias Agopian3b1d2b62012-07-11 13:48:17 -0700300 return mSecureLayerVisible;
301}
302
Mathias Agopiancd60f992012-08-16 16:28:27 -0700303Region DisplayDevice::getDirtyRegion(bool repaintEverything) const {
304 Region dirty;
Mathias Agopiancd60f992012-08-16 16:28:27 -0700305 if (repaintEverything) {
306 dirty.set(getBounds());
307 } else {
Mathias Agopianda8d0a52012-09-04 15:05:38 -0700308 const Transform& planeTransform(mGlobalTransform);
Mathias Agopiancd60f992012-08-16 16:28:27 -0700309 dirty = planeTransform.transform(this->dirtyRegion);
310 dirty.andSelf(getBounds());
311 }
312 return dirty;
313}
314
Mathias Agopian3b1d2b62012-07-11 13:48:17 -0700315// ----------------------------------------------------------------------------
316
Mathias Agopiand3ee2312012-08-02 14:01:42 -0700317bool DisplayDevice::canDraw() const {
318 return mScreenAcquired;
319}
320
321void DisplayDevice::releaseScreen() const {
322 mScreenAcquired = false;
323}
324
325void DisplayDevice::acquireScreen() const {
326 mScreenAcquired = true;
327}
328
329bool DisplayDevice::isScreenAcquired() const {
330 return mScreenAcquired;
331}
332
333// ----------------------------------------------------------------------------
334
Mathias Agopian28947d72012-08-08 18:51:15 -0700335void DisplayDevice::setLayerStack(uint32_t stack) {
336 mLayerStack = stack;
337 dirtyRegion.set(bounds());
338}
339
340// ----------------------------------------------------------------------------
341
Mathias Agopian0f2f5ff2012-07-31 23:09:07 -0700342status_t DisplayDevice::orientationToTransfrom(
Mathias Agopian1b031492012-06-20 17:51:20 -0700343 int orientation, int w, int h, Transform* tr)
344{
345 uint32_t flags = 0;
346 switch (orientation) {
Mathias Agopian3165cc22012-08-08 19:42:09 -0700347 case DisplayState::eOrientationDefault:
Mathias Agopian1b031492012-06-20 17:51:20 -0700348 flags = Transform::ROT_0;
349 break;
Mathias Agopian3165cc22012-08-08 19:42:09 -0700350 case DisplayState::eOrientation90:
Mathias Agopian1b031492012-06-20 17:51:20 -0700351 flags = Transform::ROT_90;
352 break;
Mathias Agopian3165cc22012-08-08 19:42:09 -0700353 case DisplayState::eOrientation180:
Mathias Agopian1b031492012-06-20 17:51:20 -0700354 flags = Transform::ROT_180;
355 break;
Mathias Agopian3165cc22012-08-08 19:42:09 -0700356 case DisplayState::eOrientation270:
Mathias Agopian1b031492012-06-20 17:51:20 -0700357 flags = Transform::ROT_270;
358 break;
359 default:
360 return BAD_VALUE;
361 }
362 tr->set(flags, w, h);
363 return NO_ERROR;
364}
365
Mathias Agopian00e8c7a2012-09-04 19:30:46 -0700366void DisplayDevice::setProjection(int orientation,
367 const Rect& viewport, const Rect& frame) {
Mathias Agopianda8d0a52012-09-04 15:05:38 -0700368 mOrientation = orientation;
Mathias Agopian00e8c7a2012-09-04 19:30:46 -0700369 mViewport = viewport;
370 mFrame = frame;
Mathias Agopianda8d0a52012-09-04 15:05:38 -0700371 updateGeometryTransform();
372}
373
Mathias Agopianda8d0a52012-09-04 15:05:38 -0700374void DisplayDevice::updateGeometryTransform() {
Mathias Agopian98a121a2012-07-24 21:08:59 -0700375 int w = mDisplayWidth;
376 int h = mDisplayHeight;
Jeff Brown6e220a62012-09-13 19:22:41 -0700377 Transform TL, TP, R, S;
Mathias Agopianda8d0a52012-09-04 15:05:38 -0700378 if (DisplayDevice::orientationToTransfrom(
379 mOrientation, w, h, &R) == NO_ERROR) {
380 dirtyRegion.set(bounds());
Mathias Agopian1b031492012-06-20 17:51:20 -0700381
Mathias Agopianda8d0a52012-09-04 15:05:38 -0700382 Rect viewport(mViewport);
383 Rect frame(mFrame);
384
385 if (!frame.isValid()) {
386 // the destination frame can be invalid if it has never been set,
387 // in that case we assume the whole display frame.
388 frame = Rect(w, h);
389 }
390
391 if (viewport.isEmpty()) {
392 // viewport can be invalid if it has never been set, in that case
393 // we assume the whole display size.
394 // it's also invalid to have an empty viewport, so we handle that
395 // case in the same way.
396 viewport = Rect(w, h);
397 if (R.getOrientation() & Transform::ROT_90) {
398 // viewport is always specified in the logical orientation
399 // of the display (ie: post-rotation).
400 swap(viewport.right, viewport.bottom);
401 }
402 }
403
404 float src_width = viewport.width();
405 float src_height = viewport.height();
406 float dst_width = frame.width();
407 float dst_height = frame.height();
Jesse Hall6360ec42012-09-12 13:49:10 -0700408 if (src_width != dst_width || src_height != dst_height) {
Mathias Agopianda8d0a52012-09-04 15:05:38 -0700409 float sx = dst_width / src_width;
410 float sy = dst_height / src_height;
411 S.set(sx, 0, 0, sy);
412 }
Jesse Hall6360ec42012-09-12 13:49:10 -0700413
Mathias Agopianda8d0a52012-09-04 15:05:38 -0700414 float src_x = viewport.left;
415 float src_y = viewport.top;
416 float dst_x = frame.left;
417 float dst_y = frame.top;
Jeff Brown6e220a62012-09-13 19:22:41 -0700418 TL.set(-src_x, -src_y);
419 TP.set(dst_x, dst_y);
Mathias Agopianda8d0a52012-09-04 15:05:38 -0700420
Jeff Brown6e220a62012-09-13 19:22:41 -0700421 // The viewport and frame are both in the logical orientation.
422 // Apply the logical translation, scale to physical size, apply the
423 // physical translation and finally rotate to the physical orientation.
424 mGlobalTransform = R * TP * S * TL;
Mathias Agopianeba8c682012-09-19 23:14:45 -0700425
426 const uint8_t type = mGlobalTransform.getType();
427 mNeedsFiltering = (!mGlobalTransform.preserveRects() ||
428 (type >= Transform::SCALE));
Mathias Agopian766dc492012-10-30 18:08:06 -0700429
430 mScissor = mGlobalTransform.transform(mViewport);
431 if (mScissor.isEmpty()) {
432 mScissor.set(getBounds());
433 }
Mathias Agopian1b031492012-06-20 17:51:20 -0700434 }
Mathias Agopian1b031492012-06-20 17:51:20 -0700435}
Mathias Agopian1d12d8a2012-09-18 01:38:00 -0700436
437void DisplayDevice::dump(String8& result, char* buffer, size_t SIZE) const {
438 const Transform& tr(mGlobalTransform);
439 snprintf(buffer, SIZE,
440 "+ DisplayDevice: %s\n"
441 " type=%x, layerStack=%u, (%4dx%4d), ANativeWindow=%p, orient=%2d (type=%08x), "
Jamie Gennisdd3cb842012-10-19 18:19:11 -0700442 "flips=%u, isSecure=%d, secureVis=%d, acquired=%d, numLayers=%u\n"
Mathias Agopian766dc492012-10-30 18:08:06 -0700443 " v:[%d,%d,%d,%d], f:[%d,%d,%d,%d], s:[%d,%d,%d,%d],"
Mathias Agopian1d12d8a2012-09-18 01:38:00 -0700444 "transform:[[%0.3f,%0.3f,%0.3f][%0.3f,%0.3f,%0.3f][%0.3f,%0.3f,%0.3f]]\n",
Mathias Agopiand56eff22012-09-19 16:25:29 -0700445 mDisplayName.string(), mType,
Mathias Agopian1d12d8a2012-09-18 01:38:00 -0700446 mLayerStack, mDisplayWidth, mDisplayHeight, mNativeWindow.get(),
447 mOrientation, tr.getType(), getPageFlipCount(),
Jamie Gennisdd3cb842012-10-19 18:19:11 -0700448 mIsSecure, mSecureLayerVisible, mScreenAcquired, mVisibleLayersSortedByZ.size(),
Mathias Agopian1d12d8a2012-09-18 01:38:00 -0700449 mViewport.left, mViewport.top, mViewport.right, mViewport.bottom,
450 mFrame.left, mFrame.top, mFrame.right, mFrame.bottom,
Mathias Agopian766dc492012-10-30 18:08:06 -0700451 mScissor.left, mScissor.top, mScissor.right, mScissor.bottom,
Mathias Agopian1d12d8a2012-09-18 01:38:00 -0700452 tr[0][0], tr[1][0], tr[2][0],
453 tr[0][1], tr[1][1], tr[2][1],
454 tr[0][2], tr[1][2], tr[2][2]);
455
456 result.append(buffer);
457
458 String8 fbtargetDump;
459 if (mFramebufferSurface != NULL) {
460 mFramebufferSurface->dump(fbtargetDump);
461 result.append(fbtargetDump);
462 }
463}