blob: 4fc9c6a3d3a08c693c79ae223291a46c5ef49cee [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 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),
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 Agopian0f2f5ff2012-07-31 23:09:07 -0700285void DisplayDevice::setVisibleLayersSortedByZ(const Vector< sp<LayerBase> >& 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++) {
290 if (layers[i]->isSecure()) {
291 mSecureLayerVisible = true;
292 }
293 }
294}
295
Mathias Agopian3ee454a2012-08-27 16:28:24 -0700296const Vector< sp<LayerBase> >& DisplayDevice::getVisibleLayersSortedByZ() const {
Mathias Agopian3b1d2b62012-07-11 13:48:17 -0700297 return mVisibleLayersSortedByZ;
298}
299
Mathias Agopian0f2f5ff2012-07-31 23:09:07 -0700300bool DisplayDevice::getSecureLayerVisible() const {
Mathias Agopian3b1d2b62012-07-11 13:48:17 -0700301 return mSecureLayerVisible;
302}
303
Mathias Agopiancd60f992012-08-16 16:28:27 -0700304Region DisplayDevice::getDirtyRegion(bool repaintEverything) const {
305 Region dirty;
Mathias Agopiancd60f992012-08-16 16:28:27 -0700306 if (repaintEverything) {
307 dirty.set(getBounds());
308 } else {
Mathias Agopianda8d0a52012-09-04 15:05:38 -0700309 const Transform& planeTransform(mGlobalTransform);
Mathias Agopiancd60f992012-08-16 16:28:27 -0700310 dirty = planeTransform.transform(this->dirtyRegion);
311 dirty.andSelf(getBounds());
312 }
313 return dirty;
314}
315
Mathias Agopian3b1d2b62012-07-11 13:48:17 -0700316// ----------------------------------------------------------------------------
317
Mathias Agopiand3ee2312012-08-02 14:01:42 -0700318bool DisplayDevice::canDraw() const {
319 return mScreenAcquired;
320}
321
322void DisplayDevice::releaseScreen() const {
323 mScreenAcquired = false;
324}
325
326void DisplayDevice::acquireScreen() const {
327 mScreenAcquired = true;
328}
329
330bool DisplayDevice::isScreenAcquired() const {
331 return mScreenAcquired;
332}
333
334// ----------------------------------------------------------------------------
335
Mathias Agopian28947d72012-08-08 18:51:15 -0700336void DisplayDevice::setLayerStack(uint32_t stack) {
337 mLayerStack = stack;
338 dirtyRegion.set(bounds());
339}
340
341// ----------------------------------------------------------------------------
342
Mathias Agopian0f2f5ff2012-07-31 23:09:07 -0700343status_t DisplayDevice::orientationToTransfrom(
Mathias Agopian1b031492012-06-20 17:51:20 -0700344 int orientation, int w, int h, Transform* tr)
345{
346 uint32_t flags = 0;
347 switch (orientation) {
Mathias Agopian3165cc22012-08-08 19:42:09 -0700348 case DisplayState::eOrientationDefault:
Mathias Agopian1b031492012-06-20 17:51:20 -0700349 flags = Transform::ROT_0;
350 break;
Mathias Agopian3165cc22012-08-08 19:42:09 -0700351 case DisplayState::eOrientation90:
Mathias Agopian1b031492012-06-20 17:51:20 -0700352 flags = Transform::ROT_90;
353 break;
Mathias Agopian3165cc22012-08-08 19:42:09 -0700354 case DisplayState::eOrientation180:
Mathias Agopian1b031492012-06-20 17:51:20 -0700355 flags = Transform::ROT_180;
356 break;
Mathias Agopian3165cc22012-08-08 19:42:09 -0700357 case DisplayState::eOrientation270:
Mathias Agopian1b031492012-06-20 17:51:20 -0700358 flags = Transform::ROT_270;
359 break;
360 default:
361 return BAD_VALUE;
362 }
363 tr->set(flags, w, h);
364 return NO_ERROR;
365}
366
Mathias Agopian00e8c7a2012-09-04 19:30:46 -0700367void DisplayDevice::setProjection(int orientation,
368 const Rect& viewport, const Rect& frame) {
Mathias Agopianda8d0a52012-09-04 15:05:38 -0700369 mOrientation = orientation;
Mathias Agopian00e8c7a2012-09-04 19:30:46 -0700370 mViewport = viewport;
371 mFrame = frame;
Mathias Agopianda8d0a52012-09-04 15:05:38 -0700372 updateGeometryTransform();
373}
374
Mathias Agopianda8d0a52012-09-04 15:05:38 -0700375void DisplayDevice::updateGeometryTransform() {
Mathias Agopian98a121a2012-07-24 21:08:59 -0700376 int w = mDisplayWidth;
377 int h = mDisplayHeight;
Jeff Brown6e220a62012-09-13 19:22:41 -0700378 Transform TL, TP, R, S;
Mathias Agopianda8d0a52012-09-04 15:05:38 -0700379 if (DisplayDevice::orientationToTransfrom(
380 mOrientation, w, h, &R) == NO_ERROR) {
381 dirtyRegion.set(bounds());
Mathias Agopian1b031492012-06-20 17:51:20 -0700382
Mathias Agopianda8d0a52012-09-04 15:05:38 -0700383 Rect viewport(mViewport);
384 Rect frame(mFrame);
385
386 if (!frame.isValid()) {
387 // the destination frame can be invalid if it has never been set,
388 // in that case we assume the whole display frame.
389 frame = Rect(w, h);
390 }
391
392 if (viewport.isEmpty()) {
393 // viewport can be invalid if it has never been set, in that case
394 // we assume the whole display size.
395 // it's also invalid to have an empty viewport, so we handle that
396 // case in the same way.
397 viewport = Rect(w, h);
398 if (R.getOrientation() & Transform::ROT_90) {
399 // viewport is always specified in the logical orientation
400 // of the display (ie: post-rotation).
401 swap(viewport.right, viewport.bottom);
402 }
403 }
404
405 float src_width = viewport.width();
406 float src_height = viewport.height();
407 float dst_width = frame.width();
408 float dst_height = frame.height();
Jesse Hall6360ec42012-09-12 13:49:10 -0700409 if (src_width != dst_width || src_height != dst_height) {
Mathias Agopianda8d0a52012-09-04 15:05:38 -0700410 float sx = dst_width / src_width;
411 float sy = dst_height / src_height;
412 S.set(sx, 0, 0, sy);
413 }
Jesse Hall6360ec42012-09-12 13:49:10 -0700414
Mathias Agopianda8d0a52012-09-04 15:05:38 -0700415 float src_x = viewport.left;
416 float src_y = viewport.top;
417 float dst_x = frame.left;
418 float dst_y = frame.top;
Jeff Brown6e220a62012-09-13 19:22:41 -0700419 TL.set(-src_x, -src_y);
420 TP.set(dst_x, dst_y);
Mathias Agopianda8d0a52012-09-04 15:05:38 -0700421
Jeff Brown6e220a62012-09-13 19:22:41 -0700422 // The viewport and frame are both in the logical orientation.
423 // Apply the logical translation, scale to physical size, apply the
424 // physical translation and finally rotate to the physical orientation.
425 mGlobalTransform = R * TP * S * TL;
Mathias Agopianeba8c682012-09-19 23:14:45 -0700426
427 const uint8_t type = mGlobalTransform.getType();
428 mNeedsFiltering = (!mGlobalTransform.preserveRects() ||
429 (type >= Transform::SCALE));
Mathias Agopian766dc492012-10-30 18:08:06 -0700430
431 mScissor = mGlobalTransform.transform(mViewport);
432 if (mScissor.isEmpty()) {
433 mScissor.set(getBounds());
434 }
Mathias Agopian1b031492012-06-20 17:51:20 -0700435 }
Mathias Agopian1b031492012-06-20 17:51:20 -0700436}
Mathias Agopian1d12d8a2012-09-18 01:38:00 -0700437
438void DisplayDevice::dump(String8& result, char* buffer, size_t SIZE) const {
439 const Transform& tr(mGlobalTransform);
440 snprintf(buffer, SIZE,
441 "+ DisplayDevice: %s\n"
442 " type=%x, layerStack=%u, (%4dx%4d), ANativeWindow=%p, orient=%2d (type=%08x), "
Jamie Gennisdd3cb842012-10-19 18:19:11 -0700443 "flips=%u, isSecure=%d, secureVis=%d, acquired=%d, numLayers=%u\n"
Mathias Agopian766dc492012-10-30 18:08:06 -0700444 " v:[%d,%d,%d,%d], f:[%d,%d,%d,%d], s:[%d,%d,%d,%d],"
Mathias Agopian1d12d8a2012-09-18 01:38:00 -0700445 "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 -0700446 mDisplayName.string(), mType,
Mathias Agopian1d12d8a2012-09-18 01:38:00 -0700447 mLayerStack, mDisplayWidth, mDisplayHeight, mNativeWindow.get(),
448 mOrientation, tr.getType(), getPageFlipCount(),
Jamie Gennisdd3cb842012-10-19 18:19:11 -0700449 mIsSecure, mSecureLayerVisible, mScreenAcquired, mVisibleLayersSortedByZ.size(),
Mathias Agopian1d12d8a2012-09-18 01:38:00 -0700450 mViewport.left, mViewport.top, mViewport.right, mViewport.bottom,
451 mFrame.left, mFrame.top, mFrame.right, mFrame.bottom,
Mathias Agopian766dc492012-10-30 18:08:06 -0700452 mScissor.left, mScissor.top, mScissor.right, mScissor.bottom,
Mathias Agopian1d12d8a2012-09-18 01:38:00 -0700453 tr[0][0], tr[1][0], tr[2][0],
454 tr[0][1], tr[1][1], tr[2][1],
455 tr[0][2], tr[1][2], tr[2][2]);
456
457 result.append(buffer);
458
459 String8 fbtargetDump;
460 if (mFramebufferSurface != NULL) {
461 mFramebufferSurface->dump(fbtargetDump);
462 result.append(fbtargetDump);
463 }
464}