The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1 | /* |
| 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 Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 17 | #include <stdlib.h> |
| 18 | #include <stdio.h> |
| 19 | #include <string.h> |
| 20 | #include <math.h> |
| 21 | |
| 22 | #include <cutils/properties.h> |
| 23 | |
Mathias Agopian | 076b1cc | 2009-04-10 14:24:30 -0700 | [diff] [blame] | 24 | #include <utils/RefBase.h> |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 25 | #include <utils/Log.h> |
| 26 | |
Mathias Agopian | c666cae | 2012-07-25 18:56:13 -0700 | [diff] [blame] | 27 | #include <ui/DisplayInfo.h> |
Mathias Agopian | 076b1cc | 2009-04-10 14:24:30 -0700 | [diff] [blame] | 28 | #include <ui/PixelFormat.h> |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 29 | |
Jamie Gennis | 1a4d883 | 2012-08-02 20:11:05 -0700 | [diff] [blame] | 30 | #include <gui/SurfaceTextureClient.h> |
| 31 | |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 32 | #include <GLES/gl.h> |
Mathias Agopian | 076b1cc | 2009-04-10 14:24:30 -0700 | [diff] [blame] | 33 | #include <EGL/egl.h> |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 34 | #include <EGL/eglext.h> |
| 35 | |
Mathias Agopian | 076b1cc | 2009-04-10 14:24:30 -0700 | [diff] [blame] | 36 | #include <hardware/gralloc.h> |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 37 | |
Mathias Agopian | 1b03149 | 2012-06-20 17:51:20 -0700 | [diff] [blame] | 38 | #include "DisplayHardware/FramebufferSurface.h" |
Mathias Agopian | 1b03149 | 2012-06-20 17:51:20 -0700 | [diff] [blame] | 39 | #include "DisplayHardware/HWComposer.h" |
| 40 | |
Mathias Agopian | da8d0a5 | 2012-09-04 15:05:38 -0700 | [diff] [blame] | 41 | #include "clz.h" |
Mathias Agopian | 0f2f5ff | 2012-07-31 23:09:07 -0700 | [diff] [blame] | 42 | #include "DisplayDevice.h" |
Mathias Agopian | 1f7bec6 | 2010-06-25 18:02:21 -0700 | [diff] [blame] | 43 | #include "GLExtensions.h" |
Mathias Agopian | c7d14e2 | 2011-08-01 16:32:21 -0700 | [diff] [blame] | 44 | #include "SurfaceFlinger.h" |
Mathias Agopian | 921e6ac | 2012-07-23 23:11:29 -0700 | [diff] [blame] | 45 | #include "LayerBase.h" |
Mathias Agopian | 1f7bec6 | 2010-06-25 18:02:21 -0700 | [diff] [blame] | 46 | |
Mathias Agopian | a491260 | 2012-07-12 14:25:33 -0700 | [diff] [blame] | 47 | // ---------------------------------------------------------------------------- |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 48 | using namespace android; |
Mathias Agopian | a491260 | 2012-07-12 14:25:33 -0700 | [diff] [blame] | 49 | // ---------------------------------------------------------------------------- |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 50 | |
| 51 | static __attribute__((noinline)) |
| 52 | void checkGLErrors() |
| 53 | { |
Mathias Agopian | cbb288b | 2009-09-07 16:32:45 -0700 | [diff] [blame] | 54 | do { |
| 55 | // there could be more than one error flag |
| 56 | GLenum error = glGetError(); |
| 57 | if (error == GL_NO_ERROR) |
| 58 | break; |
Steve Block | e6f43dd | 2012-01-06 19:20:56 +0000 | [diff] [blame] | 59 | ALOGE("GL error 0x%04x", int(error)); |
Mathias Agopian | cbb288b | 2009-09-07 16:32:45 -0700 | [diff] [blame] | 60 | } while(true); |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 61 | } |
| 62 | |
Mathias Agopian | a491260 | 2012-07-12 14:25:33 -0700 | [diff] [blame] | 63 | // ---------------------------------------------------------------------------- |
| 64 | |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 65 | /* |
| 66 | * Initialize the display to the specified values. |
| 67 | * |
| 68 | */ |
| 69 | |
Mathias Agopian | 0f2f5ff | 2012-07-31 23:09:07 -0700 | [diff] [blame] | 70 | DisplayDevice::DisplayDevice( |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 71 | const sp<SurfaceFlinger>& flinger, |
Mathias Agopian | 3ee454a | 2012-08-27 16:28:24 -0700 | [diff] [blame] | 72 | DisplayType type, const wp<IBinder>& displayToken, |
Jamie Gennis | 1a4d883 | 2012-08-02 20:11:05 -0700 | [diff] [blame] | 73 | const sp<ANativeWindow>& nativeWindow, |
| 74 | const sp<FramebufferSurface>& framebufferSurface, |
Mathias Agopian | a491260 | 2012-07-12 14:25:33 -0700 | [diff] [blame] | 75 | EGLConfig config) |
Mathias Agopian | 92a979a | 2012-08-02 18:32:23 -0700 | [diff] [blame] | 76 | : mFlinger(flinger), |
Mathias Agopian | 3ee454a | 2012-08-27 16:28:24 -0700 | [diff] [blame] | 77 | mType(type), mHwcDisplayId(-1), |
Jamie Gennis | 1a4d883 | 2012-08-02 20:11:05 -0700 | [diff] [blame] | 78 | mNativeWindow(nativeWindow), |
| 79 | mFramebufferSurface(framebufferSurface), |
Mathias Agopian | 92a979a | 2012-08-02 18:32:23 -0700 | [diff] [blame] | 80 | mDisplay(EGL_NO_DISPLAY), |
| 81 | mSurface(EGL_NO_SURFACE), |
| 82 | mContext(EGL_NO_CONTEXT), |
Mathias Agopian | 92a979a | 2012-08-02 18:32:23 -0700 | [diff] [blame] | 83 | mDisplayWidth(), mDisplayHeight(), mFormat(), |
| 84 | mFlags(), |
| 85 | mPageFlipCount(), |
Mathias Agopian | 92a979a | 2012-08-02 18:32:23 -0700 | [diff] [blame] | 86 | mSecureLayerVisible(false), |
| 87 | mScreenAcquired(false), |
Mathias Agopian | da8d0a5 | 2012-09-04 15:05:38 -0700 | [diff] [blame] | 88 | mLayerStack(0), |
| 89 | mOrientation() |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 90 | { |
Mathias Agopian | a491260 | 2012-07-12 14:25:33 -0700 | [diff] [blame] | 91 | init(config); |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 92 | } |
| 93 | |
Mathias Agopian | 0f2f5ff | 2012-07-31 23:09:07 -0700 | [diff] [blame] | 94 | DisplayDevice::~DisplayDevice() { |
Mathias Agopian | 92a979a | 2012-08-02 18:32:23 -0700 | [diff] [blame] | 95 | if (mSurface != EGL_NO_SURFACE) { |
| 96 | eglDestroySurface(mDisplay, mSurface); |
| 97 | mSurface = EGL_NO_SURFACE; |
| 98 | } |
| 99 | } |
| 100 | |
| 101 | bool DisplayDevice::isValid() const { |
| 102 | return mFlinger != NULL; |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 103 | } |
| 104 | |
Mathias Agopian | 0f2f5ff | 2012-07-31 23:09:07 -0700 | [diff] [blame] | 105 | int DisplayDevice::getWidth() const { |
Mathias Agopian | a491260 | 2012-07-12 14:25:33 -0700 | [diff] [blame] | 106 | return mDisplayWidth; |
| 107 | } |
| 108 | |
Mathias Agopian | 0f2f5ff | 2012-07-31 23:09:07 -0700 | [diff] [blame] | 109 | int DisplayDevice::getHeight() const { |
Mathias Agopian | a491260 | 2012-07-12 14:25:33 -0700 | [diff] [blame] | 110 | return mDisplayHeight; |
| 111 | } |
| 112 | |
Mathias Agopian | 0f2f5ff | 2012-07-31 23:09:07 -0700 | [diff] [blame] | 113 | PixelFormat DisplayDevice::getFormat() const { |
Mathias Agopian | a491260 | 2012-07-12 14:25:33 -0700 | [diff] [blame] | 114 | return mFormat; |
| 115 | } |
| 116 | |
Mathias Agopian | 0f2f5ff | 2012-07-31 23:09:07 -0700 | [diff] [blame] | 117 | EGLSurface DisplayDevice::getEGLSurface() const { |
Mathias Agopian | a491260 | 2012-07-12 14:25:33 -0700 | [diff] [blame] | 118 | return mSurface; |
| 119 | } |
| 120 | |
Mathias Agopian | 0f2f5ff | 2012-07-31 23:09:07 -0700 | [diff] [blame] | 121 | void DisplayDevice::init(EGLConfig config) |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 122 | { |
Mathias Agopian | a491260 | 2012-07-12 14:25:33 -0700 | [diff] [blame] | 123 | ANativeWindow* const window = mNativeWindow.get(); |
| 124 | |
Mathias Agopian | 6163091 | 2011-07-06 16:35:30 -0700 | [diff] [blame] | 125 | int format; |
Mathias Agopian | 6163091 | 2011-07-06 16:35:30 -0700 | [diff] [blame] | 126 | window->query(window, NATIVE_WINDOW_FORMAT, &format); |
Mathias Agopian | b5dd9c0 | 2012-03-22 12:15:54 -0700 | [diff] [blame] | 127 | |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 128 | /* |
Mathias Agopian | a491260 | 2012-07-12 14:25:33 -0700 | [diff] [blame] | 129 | * Create our display's surface |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 130 | */ |
| 131 | |
Mathias Agopian | a491260 | 2012-07-12 14:25:33 -0700 | [diff] [blame] | 132 | EGLSurface surface; |
| 133 | EGLint w, h; |
| 134 | EGLDisplay display = eglGetDisplay(EGL_DEFAULT_DISPLAY); |
| 135 | surface = eglCreateWindowSurface(display, config, window, NULL); |
Mathias Agopian | 1b03149 | 2012-06-20 17:51:20 -0700 | [diff] [blame] | 136 | eglQuerySurface(display, surface, EGL_WIDTH, &mDisplayWidth); |
| 137 | eglQuerySurface(display, surface, EGL_HEIGHT, &mDisplayHeight); |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 138 | |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 139 | mDisplay = display; |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 140 | mSurface = surface; |
Mathias Agopian | a491260 | 2012-07-12 14:25:33 -0700 | [diff] [blame] | 141 | mFormat = format; |
Mathias Agopian | 076b1cc | 2009-04-10 14:24:30 -0700 | [diff] [blame] | 142 | mPageFlipCount = 0; |
Mathias Agopian | da8d0a5 | 2012-09-04 15:05:38 -0700 | [diff] [blame] | 143 | mViewport.makeInvalid(); |
| 144 | mFrame.makeInvalid(); |
Mathias Agopian | 1f7bec6 | 2010-06-25 18:02:21 -0700 | [diff] [blame] | 145 | |
Mathias Agopian | 5f20e2d | 2012-08-10 18:50:38 -0700 | [diff] [blame] | 146 | // external displays are always considered enabled |
Mathias Agopian | 3ee454a | 2012-08-27 16:28:24 -0700 | [diff] [blame] | 147 | mScreenAcquired = (mType >= DisplayDevice::NUM_DISPLAY_TYPES); |
| 148 | |
| 149 | // get an h/w composer ID |
| 150 | mHwcDisplayId = mFlinger->allocateHwcDisplayId(mType); |
Mathias Agopian | 5f20e2d | 2012-08-10 18:50:38 -0700 | [diff] [blame] | 151 | |
Andy McFadden | 8dfa92f | 2012-09-17 18:27:17 -0700 | [diff] [blame] | 152 | // Name the display. The name will be replaced shortly if the display |
| 153 | // was created with createDisplay(). |
| 154 | switch (mType) { |
| 155 | case DISPLAY_PRIMARY: |
| 156 | mDisplayName = "Built-in Screen"; |
| 157 | break; |
| 158 | case DISPLAY_EXTERNAL: |
| 159 | mDisplayName = "HDMI Screen"; |
| 160 | break; |
| 161 | default: |
| 162 | mDisplayName = "Virtual Screen"; // e.g. Overlay #n |
| 163 | break; |
| 164 | } |
| 165 | |
Mathias Agopian | 98a121a | 2012-07-24 21:08:59 -0700 | [diff] [blame] | 166 | // initialize the display orientation transform. |
Mathias Agopian | 00e8c7a | 2012-09-04 19:30:46 -0700 | [diff] [blame] | 167 | setProjection(DisplayState::eOrientationDefault, mViewport, mFrame); |
Mathias Agopian | a350ff9 | 2010-08-10 17:14:02 -0700 | [diff] [blame] | 168 | } |
| 169 | |
Mathias Agopian | 9e2463e | 2012-09-21 18:26:16 -0700 | [diff] [blame^] | 170 | void DisplayDevice::setDisplayName(const String8& displayName) { |
| 171 | if (!displayName.isEmpty()) { |
| 172 | // never override the name with an empty name |
| 173 | mDisplayName = displayName; |
| 174 | } |
| 175 | } |
| 176 | |
Mathias Agopian | 0f2f5ff | 2012-07-31 23:09:07 -0700 | [diff] [blame] | 177 | uint32_t DisplayDevice::getPageFlipCount() const { |
Mathias Agopian | 076b1cc | 2009-04-10 14:24:30 -0700 | [diff] [blame] | 178 | return mPageFlipCount; |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 179 | } |
| 180 | |
Mathias Agopian | 0f2f5ff | 2012-07-31 23:09:07 -0700 | [diff] [blame] | 181 | status_t DisplayDevice::compositionComplete() const { |
Mathias Agopian | a491260 | 2012-07-12 14:25:33 -0700 | [diff] [blame] | 182 | if (mFramebufferSurface == NULL) { |
| 183 | return NO_ERROR; |
| 184 | } |
| 185 | return mFramebufferSurface->compositionComplete(); |
Mathias Agopian | 74faca2 | 2009-09-17 16:18:16 -0700 | [diff] [blame] | 186 | } |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 187 | |
Mathias Agopian | 0f2f5ff | 2012-07-31 23:09:07 -0700 | [diff] [blame] | 188 | void DisplayDevice::flip(const Region& dirty) const |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 189 | { |
| 190 | checkGLErrors(); |
| 191 | |
| 192 | EGLDisplay dpy = mDisplay; |
| 193 | EGLSurface surface = mSurface; |
| 194 | |
Mathias Agopian | 5e78e09 | 2009-06-11 17:19:54 -0700 | [diff] [blame] | 195 | #ifdef EGL_ANDROID_swap_rectangle |
Mathias Agopian | df3ca30 | 2009-05-04 19:29:25 -0700 | [diff] [blame] | 196 | if (mFlags & SWAP_RECTANGLE) { |
Mathias Agopian | b8a5560 | 2009-06-26 19:06:36 -0700 | [diff] [blame] | 197 | const Region newDirty(dirty.intersect(bounds())); |
| 198 | const Rect b(newDirty.getBounds()); |
Mathias Agopian | df3ca30 | 2009-05-04 19:29:25 -0700 | [diff] [blame] | 199 | eglSetSwapRectangleANDROID(dpy, surface, |
| 200 | b.left, b.top, b.width(), b.height()); |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 201 | } |
Mathias Agopian | 5e78e09 | 2009-06-11 17:19:54 -0700 | [diff] [blame] | 202 | #endif |
Mathias Agopian | d870703 | 2012-09-18 01:21:55 -0700 | [diff] [blame] | 203 | |
Mathias Agopian | 076b1cc | 2009-04-10 14:24:30 -0700 | [diff] [blame] | 204 | mPageFlipCount++; |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 205 | } |
| 206 | |
Mathias Agopian | da27af9 | 2012-09-13 18:17:13 -0700 | [diff] [blame] | 207 | void DisplayDevice::swapBuffers(HWComposer& hwc) const { |
| 208 | if (hwc.initCheck() != NO_ERROR) { |
| 209 | // no HWC, we call eglSwapBuffers() |
| 210 | eglSwapBuffers(mDisplay, mSurface); |
| 211 | } else { |
Mathias Agopian | d870703 | 2012-09-18 01:21:55 -0700 | [diff] [blame] | 212 | // We have a valid HWC, but not all displays can use it, in particular |
| 213 | // the virtual displays are on their own. |
| 214 | // TODO: HWC 1.2 will allow virtual displays |
| 215 | if (mType >= DisplayDevice::DISPLAY_VIRTUAL) { |
| 216 | // always call eglSwapBuffers() for virtual displays |
| 217 | eglSwapBuffers(mDisplay, mSurface); |
| 218 | } else if (hwc.supportsFramebufferTarget()) { |
| 219 | // as of hwc 1.1 we always call eglSwapBuffers if we have some |
| 220 | // GLES layers |
| 221 | if (hwc.hasGlesComposition(mType)) { |
Mathias Agopian | da27af9 | 2012-09-13 18:17:13 -0700 | [diff] [blame] | 222 | eglSwapBuffers(mDisplay, mSurface); |
| 223 | } |
Mathias Agopian | d870703 | 2012-09-18 01:21:55 -0700 | [diff] [blame] | 224 | } else { |
| 225 | // HWC doesn't have the framebuffer target, we don't call |
| 226 | // eglSwapBuffers(), since this is handled by HWComposer::commit(). |
Mathias Agopian | da27af9 | 2012-09-13 18:17:13 -0700 | [diff] [blame] | 227 | } |
| 228 | } |
| 229 | } |
| 230 | |
| 231 | void DisplayDevice::onSwapBuffersCompleted(HWComposer& hwc) const { |
| 232 | if (hwc.initCheck() == NO_ERROR) { |
| 233 | if (hwc.supportsFramebufferTarget()) { |
| 234 | int fd = hwc.getAndResetReleaseFenceFd(mType); |
| 235 | mFramebufferSurface->setReleaseFenceFd(fd); |
| 236 | } |
| 237 | } |
| 238 | } |
| 239 | |
Mathias Agopian | 0f2f5ff | 2012-07-31 23:09:07 -0700 | [diff] [blame] | 240 | uint32_t DisplayDevice::getFlags() const |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 241 | { |
| 242 | return mFlags; |
| 243 | } |
| 244 | |
Mathias Agopian | da8d0a5 | 2012-09-04 15:05:38 -0700 | [diff] [blame] | 245 | EGLBoolean DisplayDevice::makeCurrent(EGLDisplay dpy, |
| 246 | const sp<const DisplayDevice>& hw, EGLContext ctx) { |
| 247 | EGLBoolean result = EGL_TRUE; |
Mathias Agopian | 52bbb1a | 2012-07-31 19:01:53 -0700 | [diff] [blame] | 248 | EGLSurface sur = eglGetCurrentSurface(EGL_DRAW); |
Mathias Agopian | 4297734 | 2012-08-05 00:40:46 -0700 | [diff] [blame] | 249 | if (sur != hw->mSurface) { |
Mathias Agopian | da8d0a5 | 2012-09-04 15:05:38 -0700 | [diff] [blame] | 250 | result = eglMakeCurrent(dpy, hw->mSurface, hw->mSurface, ctx); |
| 251 | if (result == EGL_TRUE) { |
| 252 | GLsizei w = hw->mDisplayWidth; |
| 253 | GLsizei h = hw->mDisplayHeight; |
| 254 | glViewport(0, 0, w, h); |
| 255 | glMatrixMode(GL_PROJECTION); |
| 256 | glLoadIdentity(); |
| 257 | // put the origin in the left-bottom corner |
| 258 | glOrthof(0, w, 0, h, 0, 1); // l=0, r=w ; b=0, t=h |
| 259 | } |
Mathias Agopian | 52bbb1a | 2012-07-31 19:01:53 -0700 | [diff] [blame] | 260 | } |
Mathias Agopian | da8d0a5 | 2012-09-04 15:05:38 -0700 | [diff] [blame] | 261 | return result; |
Mathias Agopian | 52bbb1a | 2012-07-31 19:01:53 -0700 | [diff] [blame] | 262 | } |
| 263 | |
Mathias Agopian | 1b03149 | 2012-06-20 17:51:20 -0700 | [diff] [blame] | 264 | // ---------------------------------------------------------------------------- |
| 265 | |
Mathias Agopian | 0f2f5ff | 2012-07-31 23:09:07 -0700 | [diff] [blame] | 266 | void DisplayDevice::setVisibleLayersSortedByZ(const Vector< sp<LayerBase> >& layers) { |
Mathias Agopian | 3b1d2b6 | 2012-07-11 13:48:17 -0700 | [diff] [blame] | 267 | mVisibleLayersSortedByZ = layers; |
Mathias Agopian | ef7b9c7 | 2012-08-10 15:22:19 -0700 | [diff] [blame] | 268 | mSecureLayerVisible = false; |
Mathias Agopian | 3b1d2b6 | 2012-07-11 13:48:17 -0700 | [diff] [blame] | 269 | size_t count = layers.size(); |
| 270 | for (size_t i=0 ; i<count ; i++) { |
| 271 | if (layers[i]->isSecure()) { |
| 272 | mSecureLayerVisible = true; |
| 273 | } |
| 274 | } |
| 275 | } |
| 276 | |
Mathias Agopian | 3ee454a | 2012-08-27 16:28:24 -0700 | [diff] [blame] | 277 | const Vector< sp<LayerBase> >& DisplayDevice::getVisibleLayersSortedByZ() const { |
Mathias Agopian | 3b1d2b6 | 2012-07-11 13:48:17 -0700 | [diff] [blame] | 278 | return mVisibleLayersSortedByZ; |
| 279 | } |
| 280 | |
Mathias Agopian | 0f2f5ff | 2012-07-31 23:09:07 -0700 | [diff] [blame] | 281 | bool DisplayDevice::getSecureLayerVisible() const { |
Mathias Agopian | 3b1d2b6 | 2012-07-11 13:48:17 -0700 | [diff] [blame] | 282 | return mSecureLayerVisible; |
| 283 | } |
| 284 | |
Mathias Agopian | cd60f99 | 2012-08-16 16:28:27 -0700 | [diff] [blame] | 285 | Region DisplayDevice::getDirtyRegion(bool repaintEverything) const { |
| 286 | Region dirty; |
Mathias Agopian | cd60f99 | 2012-08-16 16:28:27 -0700 | [diff] [blame] | 287 | if (repaintEverything) { |
| 288 | dirty.set(getBounds()); |
| 289 | } else { |
Mathias Agopian | da8d0a5 | 2012-09-04 15:05:38 -0700 | [diff] [blame] | 290 | const Transform& planeTransform(mGlobalTransform); |
Mathias Agopian | cd60f99 | 2012-08-16 16:28:27 -0700 | [diff] [blame] | 291 | dirty = planeTransform.transform(this->dirtyRegion); |
| 292 | dirty.andSelf(getBounds()); |
| 293 | } |
| 294 | return dirty; |
| 295 | } |
| 296 | |
Mathias Agopian | 3b1d2b6 | 2012-07-11 13:48:17 -0700 | [diff] [blame] | 297 | // ---------------------------------------------------------------------------- |
| 298 | |
Mathias Agopian | d3ee231 | 2012-08-02 14:01:42 -0700 | [diff] [blame] | 299 | bool DisplayDevice::canDraw() const { |
| 300 | return mScreenAcquired; |
| 301 | } |
| 302 | |
| 303 | void DisplayDevice::releaseScreen() const { |
| 304 | mScreenAcquired = false; |
| 305 | } |
| 306 | |
| 307 | void DisplayDevice::acquireScreen() const { |
| 308 | mScreenAcquired = true; |
| 309 | } |
| 310 | |
| 311 | bool DisplayDevice::isScreenAcquired() const { |
| 312 | return mScreenAcquired; |
| 313 | } |
| 314 | |
| 315 | // ---------------------------------------------------------------------------- |
| 316 | |
Mathias Agopian | 28947d7 | 2012-08-08 18:51:15 -0700 | [diff] [blame] | 317 | void DisplayDevice::setLayerStack(uint32_t stack) { |
| 318 | mLayerStack = stack; |
| 319 | dirtyRegion.set(bounds()); |
| 320 | } |
| 321 | |
| 322 | // ---------------------------------------------------------------------------- |
| 323 | |
Mathias Agopian | 0f2f5ff | 2012-07-31 23:09:07 -0700 | [diff] [blame] | 324 | status_t DisplayDevice::orientationToTransfrom( |
Mathias Agopian | 1b03149 | 2012-06-20 17:51:20 -0700 | [diff] [blame] | 325 | int orientation, int w, int h, Transform* tr) |
| 326 | { |
| 327 | uint32_t flags = 0; |
| 328 | switch (orientation) { |
Mathias Agopian | 3165cc2 | 2012-08-08 19:42:09 -0700 | [diff] [blame] | 329 | case DisplayState::eOrientationDefault: |
Mathias Agopian | 1b03149 | 2012-06-20 17:51:20 -0700 | [diff] [blame] | 330 | flags = Transform::ROT_0; |
| 331 | break; |
Mathias Agopian | 3165cc2 | 2012-08-08 19:42:09 -0700 | [diff] [blame] | 332 | case DisplayState::eOrientation90: |
Mathias Agopian | 1b03149 | 2012-06-20 17:51:20 -0700 | [diff] [blame] | 333 | flags = Transform::ROT_90; |
| 334 | break; |
Mathias Agopian | 3165cc2 | 2012-08-08 19:42:09 -0700 | [diff] [blame] | 335 | case DisplayState::eOrientation180: |
Mathias Agopian | 1b03149 | 2012-06-20 17:51:20 -0700 | [diff] [blame] | 336 | flags = Transform::ROT_180; |
| 337 | break; |
Mathias Agopian | 3165cc2 | 2012-08-08 19:42:09 -0700 | [diff] [blame] | 338 | case DisplayState::eOrientation270: |
Mathias Agopian | 1b03149 | 2012-06-20 17:51:20 -0700 | [diff] [blame] | 339 | flags = Transform::ROT_270; |
| 340 | break; |
| 341 | default: |
| 342 | return BAD_VALUE; |
| 343 | } |
| 344 | tr->set(flags, w, h); |
| 345 | return NO_ERROR; |
| 346 | } |
| 347 | |
Mathias Agopian | 00e8c7a | 2012-09-04 19:30:46 -0700 | [diff] [blame] | 348 | void DisplayDevice::setProjection(int orientation, |
| 349 | const Rect& viewport, const Rect& frame) { |
Mathias Agopian | da8d0a5 | 2012-09-04 15:05:38 -0700 | [diff] [blame] | 350 | mOrientation = orientation; |
Mathias Agopian | 00e8c7a | 2012-09-04 19:30:46 -0700 | [diff] [blame] | 351 | mViewport = viewport; |
| 352 | mFrame = frame; |
Mathias Agopian | da8d0a5 | 2012-09-04 15:05:38 -0700 | [diff] [blame] | 353 | updateGeometryTransform(); |
| 354 | } |
| 355 | |
Mathias Agopian | da8d0a5 | 2012-09-04 15:05:38 -0700 | [diff] [blame] | 356 | void DisplayDevice::updateGeometryTransform() { |
Mathias Agopian | 98a121a | 2012-07-24 21:08:59 -0700 | [diff] [blame] | 357 | int w = mDisplayWidth; |
| 358 | int h = mDisplayHeight; |
Jeff Brown | 6e220a6 | 2012-09-13 19:22:41 -0700 | [diff] [blame] | 359 | Transform TL, TP, R, S; |
Mathias Agopian | da8d0a5 | 2012-09-04 15:05:38 -0700 | [diff] [blame] | 360 | if (DisplayDevice::orientationToTransfrom( |
| 361 | mOrientation, w, h, &R) == NO_ERROR) { |
| 362 | dirtyRegion.set(bounds()); |
Mathias Agopian | 1b03149 | 2012-06-20 17:51:20 -0700 | [diff] [blame] | 363 | |
Mathias Agopian | da8d0a5 | 2012-09-04 15:05:38 -0700 | [diff] [blame] | 364 | Rect viewport(mViewport); |
| 365 | Rect frame(mFrame); |
| 366 | |
| 367 | if (!frame.isValid()) { |
| 368 | // the destination frame can be invalid if it has never been set, |
| 369 | // in that case we assume the whole display frame. |
| 370 | frame = Rect(w, h); |
| 371 | } |
| 372 | |
| 373 | if (viewport.isEmpty()) { |
| 374 | // viewport can be invalid if it has never been set, in that case |
| 375 | // we assume the whole display size. |
| 376 | // it's also invalid to have an empty viewport, so we handle that |
| 377 | // case in the same way. |
| 378 | viewport = Rect(w, h); |
| 379 | if (R.getOrientation() & Transform::ROT_90) { |
| 380 | // viewport is always specified in the logical orientation |
| 381 | // of the display (ie: post-rotation). |
| 382 | swap(viewport.right, viewport.bottom); |
| 383 | } |
| 384 | } |
| 385 | |
| 386 | float src_width = viewport.width(); |
| 387 | float src_height = viewport.height(); |
| 388 | float dst_width = frame.width(); |
| 389 | float dst_height = frame.height(); |
Jesse Hall | 6360ec4 | 2012-09-12 13:49:10 -0700 | [diff] [blame] | 390 | if (src_width != dst_width || src_height != dst_height) { |
Mathias Agopian | da8d0a5 | 2012-09-04 15:05:38 -0700 | [diff] [blame] | 391 | float sx = dst_width / src_width; |
| 392 | float sy = dst_height / src_height; |
| 393 | S.set(sx, 0, 0, sy); |
| 394 | } |
Jesse Hall | 6360ec4 | 2012-09-12 13:49:10 -0700 | [diff] [blame] | 395 | |
Mathias Agopian | da8d0a5 | 2012-09-04 15:05:38 -0700 | [diff] [blame] | 396 | float src_x = viewport.left; |
| 397 | float src_y = viewport.top; |
| 398 | float dst_x = frame.left; |
| 399 | float dst_y = frame.top; |
Jeff Brown | 6e220a6 | 2012-09-13 19:22:41 -0700 | [diff] [blame] | 400 | TL.set(-src_x, -src_y); |
| 401 | TP.set(dst_x, dst_y); |
Mathias Agopian | da8d0a5 | 2012-09-04 15:05:38 -0700 | [diff] [blame] | 402 | |
Jeff Brown | 6e220a6 | 2012-09-13 19:22:41 -0700 | [diff] [blame] | 403 | // The viewport and frame are both in the logical orientation. |
| 404 | // Apply the logical translation, scale to physical size, apply the |
| 405 | // physical translation and finally rotate to the physical orientation. |
| 406 | mGlobalTransform = R * TP * S * TL; |
Mathias Agopian | eba8c68 | 2012-09-19 23:14:45 -0700 | [diff] [blame] | 407 | |
| 408 | const uint8_t type = mGlobalTransform.getType(); |
| 409 | mNeedsFiltering = (!mGlobalTransform.preserveRects() || |
| 410 | (type >= Transform::SCALE)); |
Mathias Agopian | 1b03149 | 2012-06-20 17:51:20 -0700 | [diff] [blame] | 411 | } |
Mathias Agopian | 1b03149 | 2012-06-20 17:51:20 -0700 | [diff] [blame] | 412 | } |
Mathias Agopian | 1d12d8a | 2012-09-18 01:38:00 -0700 | [diff] [blame] | 413 | |
| 414 | void DisplayDevice::dump(String8& result, char* buffer, size_t SIZE) const { |
| 415 | const Transform& tr(mGlobalTransform); |
| 416 | snprintf(buffer, SIZE, |
| 417 | "+ DisplayDevice: %s\n" |
| 418 | " type=%x, layerStack=%u, (%4dx%4d), ANativeWindow=%p, orient=%2d (type=%08x), " |
| 419 | "flips=%u, secure=%d, acquired=%d, numLayers=%u\n" |
| 420 | " v:[%d,%d,%d,%d], f:[%d,%d,%d,%d], " |
| 421 | "transform:[[%0.3f,%0.3f,%0.3f][%0.3f,%0.3f,%0.3f][%0.3f,%0.3f,%0.3f]]\n", |
Mathias Agopian | d56eff2 | 2012-09-19 16:25:29 -0700 | [diff] [blame] | 422 | mDisplayName.string(), mType, |
Mathias Agopian | 1d12d8a | 2012-09-18 01:38:00 -0700 | [diff] [blame] | 423 | mLayerStack, mDisplayWidth, mDisplayHeight, mNativeWindow.get(), |
| 424 | mOrientation, tr.getType(), getPageFlipCount(), |
| 425 | mSecureLayerVisible, mScreenAcquired, mVisibleLayersSortedByZ.size(), |
| 426 | mViewport.left, mViewport.top, mViewport.right, mViewport.bottom, |
| 427 | mFrame.left, mFrame.top, mFrame.right, mFrame.bottom, |
| 428 | tr[0][0], tr[1][0], tr[2][0], |
| 429 | tr[0][1], tr[1][1], tr[2][1], |
| 430 | tr[0][2], tr[1][2], tr[2][2]); |
| 431 | |
| 432 | result.append(buffer); |
| 433 | |
| 434 | String8 fbtargetDump; |
| 435 | if (mFramebufferSurface != NULL) { |
| 436 | mFramebufferSurface->dump(fbtargetDump); |
| 437 | result.append(fbtargetDump); |
| 438 | } |
| 439 | } |