blob: 2bbe49cded7c53ecc66ec4950d8a061e930bfc8b [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
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 Agopian13127d82013-03-05 17:47:11 -080045#include "Layer.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),
Chih-Wei Huang27e25622013-01-07 17:33:56 +080080 mDisplayToken(displayToken),
Jamie Gennis1a4d8832012-08-02 20:11:05 -070081 mNativeWindow(nativeWindow),
82 mFramebufferSurface(framebufferSurface),
Mathias Agopian92a979a2012-08-02 18:32:23 -070083 mDisplay(EGL_NO_DISPLAY),
84 mSurface(EGL_NO_SURFACE),
85 mContext(EGL_NO_CONTEXT),
Mathias Agopian92a979a2012-08-02 18:32:23 -070086 mDisplayWidth(), mDisplayHeight(), mFormat(),
87 mFlags(),
88 mPageFlipCount(),
Jamie Gennisdd3cb842012-10-19 18:19:11 -070089 mIsSecure(isSecure),
Mathias Agopian92a979a2012-08-02 18:32:23 -070090 mSecureLayerVisible(false),
91 mScreenAcquired(false),
Jesse Hall01e29052013-02-19 16:13:35 -080092 mLayerStack(NO_LAYER_STACK),
Mathias Agopianda8d0a52012-09-04 15:05:38 -070093 mOrientation()
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -080094{
Mathias Agopiana4912602012-07-12 14:25:33 -070095 init(config);
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -080096}
97
Mathias Agopian0f2f5ff2012-07-31 23:09:07 -070098DisplayDevice::~DisplayDevice() {
Mathias Agopian92a979a2012-08-02 18:32:23 -070099 if (mSurface != EGL_NO_SURFACE) {
100 eglDestroySurface(mDisplay, mSurface);
101 mSurface = EGL_NO_SURFACE;
102 }
103}
104
105bool DisplayDevice::isValid() const {
106 return mFlinger != NULL;
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800107}
108
Mathias Agopian0f2f5ff2012-07-31 23:09:07 -0700109int DisplayDevice::getWidth() const {
Mathias Agopiana4912602012-07-12 14:25:33 -0700110 return mDisplayWidth;
111}
112
Mathias Agopian0f2f5ff2012-07-31 23:09:07 -0700113int DisplayDevice::getHeight() const {
Mathias Agopiana4912602012-07-12 14:25:33 -0700114 return mDisplayHeight;
115}
116
Mathias Agopian0f2f5ff2012-07-31 23:09:07 -0700117PixelFormat DisplayDevice::getFormat() const {
Mathias Agopiana4912602012-07-12 14:25:33 -0700118 return mFormat;
119}
120
Mathias Agopian0f2f5ff2012-07-31 23:09:07 -0700121EGLSurface DisplayDevice::getEGLSurface() const {
Mathias Agopiana4912602012-07-12 14:25:33 -0700122 return mSurface;
123}
124
Mathias Agopian0f2f5ff2012-07-31 23:09:07 -0700125void DisplayDevice::init(EGLConfig config)
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800126{
Mathias Agopiana4912602012-07-12 14:25:33 -0700127 ANativeWindow* const window = mNativeWindow.get();
128
Mathias Agopian61630912011-07-06 16:35:30 -0700129 int format;
Mathias Agopian61630912011-07-06 16:35:30 -0700130 window->query(window, NATIVE_WINDOW_FORMAT, &format);
Mathias Agopianb5dd9c02012-03-22 12:15:54 -0700131
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800132 /*
Mathias Agopiana4912602012-07-12 14:25:33 -0700133 * Create our display's surface
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800134 */
135
Mathias Agopiana4912602012-07-12 14:25:33 -0700136 EGLSurface surface;
137 EGLint w, h;
138 EGLDisplay display = eglGetDisplay(EGL_DEFAULT_DISPLAY);
139 surface = eglCreateWindowSurface(display, config, window, NULL);
Mathias Agopian1b031492012-06-20 17:51:20 -0700140 eglQuerySurface(display, surface, EGL_WIDTH, &mDisplayWidth);
141 eglQuerySurface(display, surface, EGL_HEIGHT, &mDisplayHeight);
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800142
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800143 mDisplay = display;
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800144 mSurface = surface;
Mathias Agopiana4912602012-07-12 14:25:33 -0700145 mFormat = format;
Mathias Agopian076b1cc2009-04-10 14:24:30 -0700146 mPageFlipCount = 0;
Mathias Agopianda8d0a52012-09-04 15:05:38 -0700147 mViewport.makeInvalid();
148 mFrame.makeInvalid();
Mathias Agopian1f7bec62010-06-25 18:02:21 -0700149
Mathias Agopian5f20e2d2012-08-10 18:50:38 -0700150 // external displays are always considered enabled
Mathias Agopian3ee454a2012-08-27 16:28:24 -0700151 mScreenAcquired = (mType >= DisplayDevice::NUM_DISPLAY_TYPES);
152
153 // get an h/w composer ID
154 mHwcDisplayId = mFlinger->allocateHwcDisplayId(mType);
Mathias Agopian5f20e2d2012-08-10 18:50:38 -0700155
Andy McFadden8dfa92f2012-09-17 18:27:17 -0700156 // Name the display. The name will be replaced shortly if the display
157 // was created with createDisplay().
158 switch (mType) {
159 case DISPLAY_PRIMARY:
160 mDisplayName = "Built-in Screen";
161 break;
162 case DISPLAY_EXTERNAL:
163 mDisplayName = "HDMI Screen";
164 break;
165 default:
166 mDisplayName = "Virtual Screen"; // e.g. Overlay #n
167 break;
168 }
169
Mathias Agopian98a121a2012-07-24 21:08:59 -0700170 // initialize the display orientation transform.
Mathias Agopian00e8c7a2012-09-04 19:30:46 -0700171 setProjection(DisplayState::eOrientationDefault, mViewport, mFrame);
Mathias Agopiana350ff92010-08-10 17:14:02 -0700172}
173
Mathias Agopian9e2463e2012-09-21 18:26:16 -0700174void DisplayDevice::setDisplayName(const String8& displayName) {
175 if (!displayName.isEmpty()) {
176 // never override the name with an empty name
177 mDisplayName = displayName;
178 }
179}
180
Mathias Agopian0f2f5ff2012-07-31 23:09:07 -0700181uint32_t DisplayDevice::getPageFlipCount() const {
Mathias Agopian076b1cc2009-04-10 14:24:30 -0700182 return mPageFlipCount;
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800183}
184
Mathias Agopian0f2f5ff2012-07-31 23:09:07 -0700185status_t DisplayDevice::compositionComplete() const {
Mathias Agopiana4912602012-07-12 14:25:33 -0700186 if (mFramebufferSurface == NULL) {
187 return NO_ERROR;
188 }
189 return mFramebufferSurface->compositionComplete();
Mathias Agopian74faca22009-09-17 16:18:16 -0700190}
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800191
Mathias Agopian0f2f5ff2012-07-31 23:09:07 -0700192void DisplayDevice::flip(const Region& dirty) const
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800193{
194 checkGLErrors();
195
196 EGLDisplay dpy = mDisplay;
197 EGLSurface surface = mSurface;
198
Jesse Hall01e29052013-02-19 16:13:35 -0800199#ifdef EGL_ANDROID_swap_rectangle
Mathias Agopiandf3ca302009-05-04 19:29:25 -0700200 if (mFlags & SWAP_RECTANGLE) {
Mathias Agopianb8a55602009-06-26 19:06:36 -0700201 const Region newDirty(dirty.intersect(bounds()));
202 const Rect b(newDirty.getBounds());
Mathias Agopiandf3ca302009-05-04 19:29:25 -0700203 eglSetSwapRectangleANDROID(dpy, surface,
204 b.left, b.top, b.width(), b.height());
Jesse Hall01e29052013-02-19 16:13:35 -0800205 }
Mathias Agopian5e78e092009-06-11 17:19:54 -0700206#endif
Mathias Agopiand8707032012-09-18 01:21:55 -0700207
Mathias Agopian076b1cc2009-04-10 14:24:30 -0700208 mPageFlipCount++;
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800209}
210
Mathias Agopianda27af92012-09-13 18:17:13 -0700211void DisplayDevice::swapBuffers(HWComposer& hwc) const {
Mathias Agopian52e21482012-09-24 18:07:21 -0700212 EGLBoolean success = EGL_TRUE;
Mathias Agopianda27af92012-09-13 18:17:13 -0700213 if (hwc.initCheck() != NO_ERROR) {
214 // no HWC, we call eglSwapBuffers()
Mathias Agopian52e21482012-09-24 18:07:21 -0700215 success = eglSwapBuffers(mDisplay, mSurface);
Mathias Agopianda27af92012-09-13 18:17:13 -0700216 } else {
Mathias Agopiand8707032012-09-18 01:21:55 -0700217 // We have a valid HWC, but not all displays can use it, in particular
218 // the virtual displays are on their own.
219 // TODO: HWC 1.2 will allow virtual displays
220 if (mType >= DisplayDevice::DISPLAY_VIRTUAL) {
221 // always call eglSwapBuffers() for virtual displays
Mathias Agopian52e21482012-09-24 18:07:21 -0700222 success = eglSwapBuffers(mDisplay, mSurface);
Mathias Agopiand8707032012-09-18 01:21:55 -0700223 } else if (hwc.supportsFramebufferTarget()) {
224 // as of hwc 1.1 we always call eglSwapBuffers if we have some
225 // GLES layers
226 if (hwc.hasGlesComposition(mType)) {
Mathias Agopian52e21482012-09-24 18:07:21 -0700227 success = eglSwapBuffers(mDisplay, mSurface);
Mathias Agopianda27af92012-09-13 18:17:13 -0700228 }
Mathias Agopiand8707032012-09-18 01:21:55 -0700229 } else {
230 // HWC doesn't have the framebuffer target, we don't call
231 // eglSwapBuffers(), since this is handled by HWComposer::commit().
Mathias Agopianda27af92012-09-13 18:17:13 -0700232 }
233 }
Mathias Agopian52e21482012-09-24 18:07:21 -0700234
Mathias Agopian32341382012-09-25 19:16:28 -0700235 if (!success) {
236 EGLint error = eglGetError();
237 if (error == EGL_CONTEXT_LOST ||
238 mType == DisplayDevice::DISPLAY_PRIMARY) {
239 LOG_ALWAYS_FATAL("eglSwapBuffers(%p, %p) failed with 0x%08x",
Mathias Agopianb8fc00b2012-10-09 16:43:50 -0700240 mDisplay, mSurface, error);
Mathias Agopian32341382012-09-25 19:16:28 -0700241 }
242 }
Mathias Agopianda27af92012-09-13 18:17:13 -0700243}
244
245void DisplayDevice::onSwapBuffersCompleted(HWComposer& hwc) const {
246 if (hwc.initCheck() == NO_ERROR) {
247 if (hwc.supportsFramebufferTarget()) {
248 int fd = hwc.getAndResetReleaseFenceFd(mType);
249 mFramebufferSurface->setReleaseFenceFd(fd);
250 }
251 }
252}
253
Mathias Agopian0f2f5ff2012-07-31 23:09:07 -0700254uint32_t DisplayDevice::getFlags() const
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800255{
256 return mFlags;
257}
258
Mathias Agopianda8d0a52012-09-04 15:05:38 -0700259EGLBoolean DisplayDevice::makeCurrent(EGLDisplay dpy,
260 const sp<const DisplayDevice>& hw, EGLContext ctx) {
261 EGLBoolean result = EGL_TRUE;
Mathias Agopian52bbb1a2012-07-31 19:01:53 -0700262 EGLSurface sur = eglGetCurrentSurface(EGL_DRAW);
Mathias Agopian42977342012-08-05 00:40:46 -0700263 if (sur != hw->mSurface) {
Mathias Agopianda8d0a52012-09-04 15:05:38 -0700264 result = eglMakeCurrent(dpy, hw->mSurface, hw->mSurface, ctx);
265 if (result == EGL_TRUE) {
Mathias Agopianbae92d02012-09-28 01:00:47 -0700266 setViewportAndProjection(hw);
Mathias Agopianda8d0a52012-09-04 15:05:38 -0700267 }
Mathias Agopian52bbb1a2012-07-31 19:01:53 -0700268 }
Mathias Agopianda8d0a52012-09-04 15:05:38 -0700269 return result;
Mathias Agopian52bbb1a2012-07-31 19:01:53 -0700270}
271
Mathias Agopianbae92d02012-09-28 01:00:47 -0700272void DisplayDevice::setViewportAndProjection(const sp<const DisplayDevice>& hw) {
273 GLsizei w = hw->mDisplayWidth;
274 GLsizei h = hw->mDisplayHeight;
275 glViewport(0, 0, w, h);
276 glMatrixMode(GL_PROJECTION);
277 glLoadIdentity();
278 // put the origin in the left-bottom corner
279 glOrthof(0, w, 0, h, 0, 1); // l=0, r=w ; b=0, t=h
Mathias Agopian135e5892012-09-30 16:43:20 -0700280 glMatrixMode(GL_MODELVIEW);
Mathias Agopianbae92d02012-09-28 01:00:47 -0700281}
282
Mathias Agopian1b031492012-06-20 17:51:20 -0700283// ----------------------------------------------------------------------------
284
Mathias Agopian13127d82013-03-05 17:47:11 -0800285void DisplayDevice::setVisibleLayersSortedByZ(const Vector< sp<Layer> >& layers) {
Mathias Agopian3b1d2b62012-07-11 13:48:17 -0700286 mVisibleLayersSortedByZ = layers;
Mathias Agopianef7b9c72012-08-10 15:22:19 -0700287 mSecureLayerVisible = false;
Mathias Agopian3b1d2b62012-07-11 13:48:17 -0700288 size_t count = layers.size();
289 for (size_t i=0 ; i<count ; i++) {
Mathias Agopian13127d82013-03-05 17:47:11 -0800290 const sp<Layer>& layer(layers[i]);
Mathias Agopianf5f714a2013-02-26 16:54:05 -0800291 if (layer->isSecure()) {
Mathias Agopian3b1d2b62012-07-11 13:48:17 -0700292 mSecureLayerVisible = true;
293 }
294 }
295}
296
Mathias Agopian13127d82013-03-05 17:47:11 -0800297const Vector< sp<Layer> >& DisplayDevice::getVisibleLayersSortedByZ() const {
Mathias Agopian3b1d2b62012-07-11 13:48:17 -0700298 return mVisibleLayersSortedByZ;
299}
300
Mathias Agopian0f2f5ff2012-07-31 23:09:07 -0700301bool DisplayDevice::getSecureLayerVisible() const {
Mathias Agopian3b1d2b62012-07-11 13:48:17 -0700302 return mSecureLayerVisible;
303}
304
Mathias Agopiancd60f992012-08-16 16:28:27 -0700305Region DisplayDevice::getDirtyRegion(bool repaintEverything) const {
306 Region dirty;
Mathias Agopiancd60f992012-08-16 16:28:27 -0700307 if (repaintEverything) {
308 dirty.set(getBounds());
309 } else {
Mathias Agopianda8d0a52012-09-04 15:05:38 -0700310 const Transform& planeTransform(mGlobalTransform);
Mathias Agopiancd60f992012-08-16 16:28:27 -0700311 dirty = planeTransform.transform(this->dirtyRegion);
312 dirty.andSelf(getBounds());
313 }
314 return dirty;
315}
316
Mathias Agopian3b1d2b62012-07-11 13:48:17 -0700317// ----------------------------------------------------------------------------
318
Mathias Agopiand3ee2312012-08-02 14:01:42 -0700319bool DisplayDevice::canDraw() const {
320 return mScreenAcquired;
321}
322
323void DisplayDevice::releaseScreen() const {
324 mScreenAcquired = false;
325}
326
327void DisplayDevice::acquireScreen() const {
328 mScreenAcquired = true;
329}
330
331bool DisplayDevice::isScreenAcquired() const {
332 return mScreenAcquired;
333}
334
335// ----------------------------------------------------------------------------
336
Mathias Agopian28947d72012-08-08 18:51:15 -0700337void DisplayDevice::setLayerStack(uint32_t stack) {
338 mLayerStack = stack;
339 dirtyRegion.set(bounds());
340}
341
342// ----------------------------------------------------------------------------
343
Mathias Agopian0f2f5ff2012-07-31 23:09:07 -0700344status_t DisplayDevice::orientationToTransfrom(
Mathias Agopian1b031492012-06-20 17:51:20 -0700345 int orientation, int w, int h, Transform* tr)
346{
347 uint32_t flags = 0;
348 switch (orientation) {
Mathias Agopian3165cc22012-08-08 19:42:09 -0700349 case DisplayState::eOrientationDefault:
Mathias Agopian1b031492012-06-20 17:51:20 -0700350 flags = Transform::ROT_0;
351 break;
Mathias Agopian3165cc22012-08-08 19:42:09 -0700352 case DisplayState::eOrientation90:
Mathias Agopian1b031492012-06-20 17:51:20 -0700353 flags = Transform::ROT_90;
354 break;
Mathias Agopian3165cc22012-08-08 19:42:09 -0700355 case DisplayState::eOrientation180:
Mathias Agopian1b031492012-06-20 17:51:20 -0700356 flags = Transform::ROT_180;
357 break;
Mathias Agopian3165cc22012-08-08 19:42:09 -0700358 case DisplayState::eOrientation270:
Mathias Agopian1b031492012-06-20 17:51:20 -0700359 flags = Transform::ROT_270;
360 break;
361 default:
362 return BAD_VALUE;
363 }
364 tr->set(flags, w, h);
365 return NO_ERROR;
366}
367
Mathias Agopian00e8c7a2012-09-04 19:30:46 -0700368void DisplayDevice::setProjection(int orientation,
Mathias Agopianf5f714a2013-02-26 16:54:05 -0800369 const Rect& newViewport, const Rect& newFrame) {
370 Rect viewport(newViewport);
371 Rect frame(newFrame);
372
373 const int w = mDisplayWidth;
374 const int h = mDisplayHeight;
375
376 Transform R;
377 DisplayDevice::orientationToTransfrom(orientation, w, h, &R);
378
379 if (!frame.isValid()) {
380 // the destination frame can be invalid if it has never been set,
381 // in that case we assume the whole display frame.
382 frame = Rect(w, h);
383 }
384
385 if (viewport.isEmpty()) {
386 // viewport can be invalid if it has never been set, in that case
387 // we assume the whole display size.
388 // it's also invalid to have an empty viewport, so we handle that
389 // case in the same way.
390 viewport = Rect(w, h);
391 if (R.getOrientation() & Transform::ROT_90) {
392 // viewport is always specified in the logical orientation
393 // of the display (ie: post-rotation).
394 swap(viewport.right, viewport.bottom);
395 }
396 }
397
398 dirtyRegion.set(getBounds());
399
400 Transform TL, TP, S;
401 float src_width = viewport.width();
402 float src_height = viewport.height();
403 float dst_width = frame.width();
404 float dst_height = frame.height();
405 if (src_width != dst_width || src_height != dst_height) {
406 float sx = dst_width / src_width;
407 float sy = dst_height / src_height;
408 S.set(sx, 0, 0, sy);
409 }
410
411 float src_x = viewport.left;
412 float src_y = viewport.top;
413 float dst_x = frame.left;
414 float dst_y = frame.top;
415 TL.set(-src_x, -src_y);
416 TP.set(dst_x, dst_y);
417
418 // The viewport and frame are both in the logical orientation.
419 // Apply the logical translation, scale to physical size, apply the
420 // physical translation and finally rotate to the physical orientation.
421 mGlobalTransform = R * TP * S * TL;
422
423 const uint8_t type = mGlobalTransform.getType();
424 mNeedsFiltering = (!mGlobalTransform.preserveRects() ||
425 (type >= Transform::SCALE));
426
427 mScissor = mGlobalTransform.transform(viewport);
428 if (mScissor.isEmpty()) {
429 mScissor.set(getBounds());
430 }
431
Mathias Agopianda8d0a52012-09-04 15:05:38 -0700432 mOrientation = orientation;
Mathias Agopian00e8c7a2012-09-04 19:30:46 -0700433 mViewport = viewport;
434 mFrame = frame;
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}