2009-03-04 03:31:44 +00:00
|
|
|
/*
|
|
|
|
* Copyright (C) 2007 The Android Open Source Project
|
|
|
|
*
|
|
|
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
* you may not use this file except in compliance with the License.
|
|
|
|
* You may obtain a copy of the License at
|
|
|
|
*
|
|
|
|
* http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
*
|
|
|
|
* Unless required by applicable law or agreed to in writing, software
|
|
|
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
* See the License for the specific language governing permissions and
|
|
|
|
* limitations under the License.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <string.h>
|
|
|
|
#include <math.h>
|
|
|
|
|
|
|
|
#include <cutils/properties.h>
|
|
|
|
|
2009-04-10 21:24:30 +00:00
|
|
|
#include <utils/RefBase.h>
|
2009-03-04 03:31:44 +00:00
|
|
|
#include <utils/Log.h>
|
|
|
|
|
2012-07-26 01:56:13 +00:00
|
|
|
#include <ui/DisplayInfo.h>
|
2009-04-10 21:24:30 +00:00
|
|
|
#include <ui/PixelFormat.h>
|
2009-03-04 03:31:44 +00:00
|
|
|
|
2012-08-03 03:11:05 +00:00
|
|
|
#include <gui/SurfaceTextureClient.h>
|
|
|
|
|
2009-03-04 03:31:44 +00:00
|
|
|
#include <GLES/gl.h>
|
2009-04-10 21:24:30 +00:00
|
|
|
#include <EGL/egl.h>
|
2009-03-04 03:31:44 +00:00
|
|
|
#include <EGL/eglext.h>
|
|
|
|
|
2009-04-10 21:24:30 +00:00
|
|
|
#include <hardware/gralloc.h>
|
2009-03-04 03:31:44 +00:00
|
|
|
|
2012-06-21 00:51:20 +00:00
|
|
|
#include "DisplayHardware/FramebufferSurface.h"
|
|
|
|
#include "DisplayHardware/HWComposer.h"
|
|
|
|
|
2012-09-04 22:05:38 +00:00
|
|
|
#include "clz.h"
|
2012-08-01 06:09:07 +00:00
|
|
|
#include "DisplayDevice.h"
|
2010-06-26 01:02:21 +00:00
|
|
|
#include "GLExtensions.h"
|
2011-08-01 23:32:21 +00:00
|
|
|
#include "SurfaceFlinger.h"
|
2012-07-24 06:11:29 +00:00
|
|
|
#include "LayerBase.h"
|
2010-06-26 01:02:21 +00:00
|
|
|
|
2012-07-12 21:25:33 +00:00
|
|
|
// ----------------------------------------------------------------------------
|
2009-03-04 03:31:44 +00:00
|
|
|
using namespace android;
|
2012-07-12 21:25:33 +00:00
|
|
|
// ----------------------------------------------------------------------------
|
2009-03-04 03:31:44 +00:00
|
|
|
|
|
|
|
static __attribute__((noinline))
|
|
|
|
void checkGLErrors()
|
|
|
|
{
|
fix [2068105] implement queueBuffer/lockBuffer/dequeueBuffer properly
Rewrote SurfaceFlinger's buffer management from the ground-up.
The design now support an arbitrary number of buffers per surface, however the current implementation is limited to four. Currently only 2 buffers are used in practice.
The main new feature is to be able to dequeue all buffers at once (very important when there are only two).
A client can dequeue all buffers until there are none available, it can lock all buffers except the last one that is used for composition. The client will block then, until a new buffer is enqueued.
The current implementation requires that buffers are locked in the same order they are dequeued and enqueued in the same order they are locked. Only one buffer can be locked at a time.
eg. Allowed sequence: DQ, DQ, LOCK, Q, LOCK, Q
eg. Forbidden sequence: DQ, DQ, LOCK, LOCK, Q, Q
2009-09-07 23:32:45 +00:00
|
|
|
do {
|
|
|
|
// there could be more than one error flag
|
|
|
|
GLenum error = glGetError();
|
|
|
|
if (error == GL_NO_ERROR)
|
|
|
|
break;
|
2012-01-06 19:20:56 +00:00
|
|
|
ALOGE("GL error 0x%04x", int(error));
|
fix [2068105] implement queueBuffer/lockBuffer/dequeueBuffer properly
Rewrote SurfaceFlinger's buffer management from the ground-up.
The design now support an arbitrary number of buffers per surface, however the current implementation is limited to four. Currently only 2 buffers are used in practice.
The main new feature is to be able to dequeue all buffers at once (very important when there are only two).
A client can dequeue all buffers until there are none available, it can lock all buffers except the last one that is used for composition. The client will block then, until a new buffer is enqueued.
The current implementation requires that buffers are locked in the same order they are dequeued and enqueued in the same order they are locked. Only one buffer can be locked at a time.
eg. Allowed sequence: DQ, DQ, LOCK, Q, LOCK, Q
eg. Forbidden sequence: DQ, DQ, LOCK, LOCK, Q, Q
2009-09-07 23:32:45 +00:00
|
|
|
} while(true);
|
2009-03-04 03:31:44 +00:00
|
|
|
}
|
|
|
|
|
2012-07-12 21:25:33 +00:00
|
|
|
// ----------------------------------------------------------------------------
|
|
|
|
|
2009-03-04 03:31:44 +00:00
|
|
|
/*
|
|
|
|
* Initialize the display to the specified values.
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
2012-08-01 06:09:07 +00:00
|
|
|
DisplayDevice::DisplayDevice(
|
2009-03-04 03:31:44 +00:00
|
|
|
const sp<SurfaceFlinger>& flinger,
|
2012-10-20 01:19:11 +00:00
|
|
|
DisplayType type,
|
|
|
|
bool isSecure,
|
|
|
|
const wp<IBinder>& displayToken,
|
2012-08-03 03:11:05 +00:00
|
|
|
const sp<ANativeWindow>& nativeWindow,
|
|
|
|
const sp<FramebufferSurface>& framebufferSurface,
|
2012-07-12 21:25:33 +00:00
|
|
|
EGLConfig config)
|
2012-08-03 01:32:23 +00:00
|
|
|
: mFlinger(flinger),
|
2012-08-27 23:28:24 +00:00
|
|
|
mType(type), mHwcDisplayId(-1),
|
2012-08-03 03:11:05 +00:00
|
|
|
mNativeWindow(nativeWindow),
|
|
|
|
mFramebufferSurface(framebufferSurface),
|
2012-08-03 01:32:23 +00:00
|
|
|
mDisplay(EGL_NO_DISPLAY),
|
|
|
|
mSurface(EGL_NO_SURFACE),
|
|
|
|
mContext(EGL_NO_CONTEXT),
|
|
|
|
mDisplayWidth(), mDisplayHeight(), mFormat(),
|
|
|
|
mFlags(),
|
|
|
|
mPageFlipCount(),
|
2012-10-20 01:19:11 +00:00
|
|
|
mIsSecure(isSecure),
|
2012-08-03 01:32:23 +00:00
|
|
|
mSecureLayerVisible(false),
|
|
|
|
mScreenAcquired(false),
|
2012-09-04 22:05:38 +00:00
|
|
|
mLayerStack(0),
|
|
|
|
mOrientation()
|
2009-03-04 03:31:44 +00:00
|
|
|
{
|
2012-07-12 21:25:33 +00:00
|
|
|
init(config);
|
2009-03-04 03:31:44 +00:00
|
|
|
}
|
|
|
|
|
2012-08-01 06:09:07 +00:00
|
|
|
DisplayDevice::~DisplayDevice() {
|
2012-08-03 01:32:23 +00:00
|
|
|
if (mSurface != EGL_NO_SURFACE) {
|
|
|
|
eglDestroySurface(mDisplay, mSurface);
|
|
|
|
mSurface = EGL_NO_SURFACE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
bool DisplayDevice::isValid() const {
|
|
|
|
return mFlinger != NULL;
|
2009-03-04 03:31:44 +00:00
|
|
|
}
|
|
|
|
|
2012-08-01 06:09:07 +00:00
|
|
|
int DisplayDevice::getWidth() const {
|
2012-07-12 21:25:33 +00:00
|
|
|
return mDisplayWidth;
|
2011-07-06 23:35:30 +00:00
|
|
|
}
|
|
|
|
|
2012-08-01 06:09:07 +00:00
|
|
|
int DisplayDevice::getHeight() const {
|
2012-07-12 21:25:33 +00:00
|
|
|
return mDisplayHeight;
|
|
|
|
}
|
|
|
|
|
2012-08-01 06:09:07 +00:00
|
|
|
PixelFormat DisplayDevice::getFormat() const {
|
2012-07-12 21:25:33 +00:00
|
|
|
return mFormat;
|
|
|
|
}
|
|
|
|
|
2012-08-01 06:09:07 +00:00
|
|
|
EGLSurface DisplayDevice::getEGLSurface() const {
|
2012-07-12 21:25:33 +00:00
|
|
|
return mSurface;
|
|
|
|
}
|
2011-07-06 23:35:30 +00:00
|
|
|
|
2012-08-01 06:09:07 +00:00
|
|
|
void DisplayDevice::init(EGLConfig config)
|
2009-03-04 03:31:44 +00:00
|
|
|
{
|
2012-07-12 21:25:33 +00:00
|
|
|
ANativeWindow* const window = mNativeWindow.get();
|
|
|
|
|
2011-07-06 23:35:30 +00:00
|
|
|
int format;
|
|
|
|
window->query(window, NATIVE_WINDOW_FORMAT, &format);
|
2012-03-22 19:15:54 +00:00
|
|
|
|
2012-07-12 21:25:33 +00:00
|
|
|
/*
|
|
|
|
* Create our display's surface
|
2012-03-22 19:15:54 +00:00
|
|
|
*/
|
2011-11-05 01:46:11 +00:00
|
|
|
|
2010-06-26 01:02:21 +00:00
|
|
|
EGLSurface surface;
|
2012-07-12 21:25:33 +00:00
|
|
|
EGLint w, h;
|
2009-03-04 03:31:44 +00:00
|
|
|
EGLDisplay display = eglGetDisplay(EGL_DEFAULT_DISPLAY);
|
2012-07-12 21:25:33 +00:00
|
|
|
surface = eglCreateWindowSurface(display, config, window, NULL);
|
2012-06-21 00:51:20 +00:00
|
|
|
eglQuerySurface(display, surface, EGL_WIDTH, &mDisplayWidth);
|
|
|
|
eglQuerySurface(display, surface, EGL_HEIGHT, &mDisplayHeight);
|
2009-03-04 03:31:44 +00:00
|
|
|
|
2010-06-26 01:02:21 +00:00
|
|
|
mDisplay = display;
|
|
|
|
mSurface = surface;
|
2012-07-12 21:25:33 +00:00
|
|
|
mFormat = format;
|
2010-06-26 01:02:21 +00:00
|
|
|
mPageFlipCount = 0;
|
2012-09-04 22:05:38 +00:00
|
|
|
mViewport.makeInvalid();
|
|
|
|
mFrame.makeInvalid();
|
2010-06-26 01:02:21 +00:00
|
|
|
|
2012-08-11 01:50:38 +00:00
|
|
|
// external displays are always considered enabled
|
2012-08-27 23:28:24 +00:00
|
|
|
mScreenAcquired = (mType >= DisplayDevice::NUM_DISPLAY_TYPES);
|
|
|
|
|
|
|
|
// get an h/w composer ID
|
|
|
|
mHwcDisplayId = mFlinger->allocateHwcDisplayId(mType);
|
2012-08-11 01:50:38 +00:00
|
|
|
|
2012-09-18 01:27:17 +00:00
|
|
|
// Name the display. The name will be replaced shortly if the display
|
|
|
|
// was created with createDisplay().
|
|
|
|
switch (mType) {
|
|
|
|
case DISPLAY_PRIMARY:
|
|
|
|
mDisplayName = "Built-in Screen";
|
|
|
|
break;
|
|
|
|
case DISPLAY_EXTERNAL:
|
|
|
|
mDisplayName = "HDMI Screen";
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
mDisplayName = "Virtual Screen"; // e.g. Overlay #n
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2012-07-25 04:08:59 +00:00
|
|
|
// initialize the display orientation transform.
|
2012-09-05 02:30:46 +00:00
|
|
|
setProjection(DisplayState::eOrientationDefault, mViewport, mFrame);
|
2010-08-11 00:14:02 +00:00
|
|
|
}
|
|
|
|
|
2012-09-22 01:26:16 +00:00
|
|
|
void DisplayDevice::setDisplayName(const String8& displayName) {
|
|
|
|
if (!displayName.isEmpty()) {
|
|
|
|
// never override the name with an empty name
|
|
|
|
mDisplayName = displayName;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-08-01 06:09:07 +00:00
|
|
|
uint32_t DisplayDevice::getPageFlipCount() const {
|
2009-04-10 21:24:30 +00:00
|
|
|
return mPageFlipCount;
|
2009-03-04 03:31:44 +00:00
|
|
|
}
|
|
|
|
|
2012-08-01 06:09:07 +00:00
|
|
|
status_t DisplayDevice::compositionComplete() const {
|
2012-07-12 21:25:33 +00:00
|
|
|
if (mFramebufferSurface == NULL) {
|
|
|
|
return NO_ERROR;
|
|
|
|
}
|
|
|
|
return mFramebufferSurface->compositionComplete();
|
2009-09-17 23:18:16 +00:00
|
|
|
}
|
2009-03-04 03:31:44 +00:00
|
|
|
|
2012-08-01 06:09:07 +00:00
|
|
|
void DisplayDevice::flip(const Region& dirty) const
|
2009-03-04 03:31:44 +00:00
|
|
|
{
|
|
|
|
checkGLErrors();
|
|
|
|
|
|
|
|
EGLDisplay dpy = mDisplay;
|
|
|
|
EGLSurface surface = mSurface;
|
|
|
|
|
2009-06-12 00:19:54 +00:00
|
|
|
#ifdef EGL_ANDROID_swap_rectangle
|
2009-05-05 02:29:25 +00:00
|
|
|
if (mFlags & SWAP_RECTANGLE) {
|
2009-06-27 02:06:36 +00:00
|
|
|
const Region newDirty(dirty.intersect(bounds()));
|
|
|
|
const Rect b(newDirty.getBounds());
|
2009-05-05 02:29:25 +00:00
|
|
|
eglSetSwapRectangleANDROID(dpy, surface,
|
|
|
|
b.left, b.top, b.width(), b.height());
|
2009-03-04 03:31:44 +00:00
|
|
|
}
|
2009-06-12 00:19:54 +00:00
|
|
|
#endif
|
2012-09-18 08:21:55 +00:00
|
|
|
|
2009-04-10 21:24:30 +00:00
|
|
|
mPageFlipCount++;
|
2009-03-04 03:31:44 +00:00
|
|
|
}
|
|
|
|
|
2012-09-14 01:17:13 +00:00
|
|
|
void DisplayDevice::swapBuffers(HWComposer& hwc) const {
|
2012-09-25 01:07:21 +00:00
|
|
|
EGLBoolean success = EGL_TRUE;
|
2012-09-14 01:17:13 +00:00
|
|
|
if (hwc.initCheck() != NO_ERROR) {
|
|
|
|
// no HWC, we call eglSwapBuffers()
|
2012-09-25 01:07:21 +00:00
|
|
|
success = eglSwapBuffers(mDisplay, mSurface);
|
2012-09-14 01:17:13 +00:00
|
|
|
} else {
|
2012-09-18 08:21:55 +00:00
|
|
|
// We have a valid HWC, but not all displays can use it, in particular
|
|
|
|
// the virtual displays are on their own.
|
|
|
|
// TODO: HWC 1.2 will allow virtual displays
|
|
|
|
if (mType >= DisplayDevice::DISPLAY_VIRTUAL) {
|
|
|
|
// always call eglSwapBuffers() for virtual displays
|
2012-09-25 01:07:21 +00:00
|
|
|
success = eglSwapBuffers(mDisplay, mSurface);
|
2012-09-18 08:21:55 +00:00
|
|
|
} else if (hwc.supportsFramebufferTarget()) {
|
|
|
|
// as of hwc 1.1 we always call eglSwapBuffers if we have some
|
|
|
|
// GLES layers
|
|
|
|
if (hwc.hasGlesComposition(mType)) {
|
2012-09-25 01:07:21 +00:00
|
|
|
success = eglSwapBuffers(mDisplay, mSurface);
|
2012-09-14 01:17:13 +00:00
|
|
|
}
|
2012-09-18 08:21:55 +00:00
|
|
|
} else {
|
|
|
|
// HWC doesn't have the framebuffer target, we don't call
|
|
|
|
// eglSwapBuffers(), since this is handled by HWComposer::commit().
|
2012-09-14 01:17:13 +00:00
|
|
|
}
|
|
|
|
}
|
2012-09-25 01:07:21 +00:00
|
|
|
|
2012-09-26 02:16:28 +00:00
|
|
|
if (!success) {
|
|
|
|
EGLint error = eglGetError();
|
|
|
|
if (error == EGL_CONTEXT_LOST ||
|
|
|
|
mType == DisplayDevice::DISPLAY_PRIMARY) {
|
|
|
|
LOG_ALWAYS_FATAL("eglSwapBuffers(%p, %p) failed with 0x%08x",
|
2012-10-09 23:43:50 +00:00
|
|
|
mDisplay, mSurface, error);
|
2012-09-26 02:16:28 +00:00
|
|
|
}
|
|
|
|
}
|
2012-09-14 01:17:13 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void DisplayDevice::onSwapBuffersCompleted(HWComposer& hwc) const {
|
|
|
|
if (hwc.initCheck() == NO_ERROR) {
|
|
|
|
if (hwc.supportsFramebufferTarget()) {
|
|
|
|
int fd = hwc.getAndResetReleaseFenceFd(mType);
|
|
|
|
mFramebufferSurface->setReleaseFenceFd(fd);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-08-01 06:09:07 +00:00
|
|
|
uint32_t DisplayDevice::getFlags() const
|
2009-03-04 03:31:44 +00:00
|
|
|
{
|
|
|
|
return mFlags;
|
|
|
|
}
|
|
|
|
|
2012-09-04 22:05:38 +00:00
|
|
|
EGLBoolean DisplayDevice::makeCurrent(EGLDisplay dpy,
|
|
|
|
const sp<const DisplayDevice>& hw, EGLContext ctx) {
|
|
|
|
EGLBoolean result = EGL_TRUE;
|
2012-08-01 02:01:53 +00:00
|
|
|
EGLSurface sur = eglGetCurrentSurface(EGL_DRAW);
|
2012-08-05 07:40:46 +00:00
|
|
|
if (sur != hw->mSurface) {
|
2012-09-04 22:05:38 +00:00
|
|
|
result = eglMakeCurrent(dpy, hw->mSurface, hw->mSurface, ctx);
|
|
|
|
if (result == EGL_TRUE) {
|
2012-09-28 08:00:47 +00:00
|
|
|
setViewportAndProjection(hw);
|
2012-09-04 22:05:38 +00:00
|
|
|
}
|
2012-08-01 02:01:53 +00:00
|
|
|
}
|
2012-09-04 22:05:38 +00:00
|
|
|
return result;
|
2012-08-01 02:01:53 +00:00
|
|
|
}
|
|
|
|
|
2012-09-28 08:00:47 +00:00
|
|
|
void DisplayDevice::setViewportAndProjection(const sp<const DisplayDevice>& hw) {
|
|
|
|
GLsizei w = hw->mDisplayWidth;
|
|
|
|
GLsizei h = hw->mDisplayHeight;
|
|
|
|
glViewport(0, 0, w, h);
|
|
|
|
glMatrixMode(GL_PROJECTION);
|
|
|
|
glLoadIdentity();
|
|
|
|
// put the origin in the left-bottom corner
|
|
|
|
glOrthof(0, w, 0, h, 0, 1); // l=0, r=w ; b=0, t=h
|
2012-09-30 23:43:20 +00:00
|
|
|
glMatrixMode(GL_MODELVIEW);
|
2012-09-28 08:00:47 +00:00
|
|
|
}
|
|
|
|
|
2012-06-21 00:51:20 +00:00
|
|
|
// ----------------------------------------------------------------------------
|
|
|
|
|
2012-08-01 06:09:07 +00:00
|
|
|
void DisplayDevice::setVisibleLayersSortedByZ(const Vector< sp<LayerBase> >& layers) {
|
2012-07-11 20:48:17 +00:00
|
|
|
mVisibleLayersSortedByZ = layers;
|
2012-08-10 22:22:19 +00:00
|
|
|
mSecureLayerVisible = false;
|
2012-07-11 20:48:17 +00:00
|
|
|
size_t count = layers.size();
|
|
|
|
for (size_t i=0 ; i<count ; i++) {
|
|
|
|
if (layers[i]->isSecure()) {
|
|
|
|
mSecureLayerVisible = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-08-27 23:28:24 +00:00
|
|
|
const Vector< sp<LayerBase> >& DisplayDevice::getVisibleLayersSortedByZ() const {
|
2012-07-11 20:48:17 +00:00
|
|
|
return mVisibleLayersSortedByZ;
|
|
|
|
}
|
|
|
|
|
2012-08-01 06:09:07 +00:00
|
|
|
bool DisplayDevice::getSecureLayerVisible() const {
|
2012-07-11 20:48:17 +00:00
|
|
|
return mSecureLayerVisible;
|
|
|
|
}
|
|
|
|
|
2012-08-16 23:28:27 +00:00
|
|
|
Region DisplayDevice::getDirtyRegion(bool repaintEverything) const {
|
|
|
|
Region dirty;
|
|
|
|
if (repaintEverything) {
|
|
|
|
dirty.set(getBounds());
|
|
|
|
} else {
|
2012-09-04 22:05:38 +00:00
|
|
|
const Transform& planeTransform(mGlobalTransform);
|
2012-08-16 23:28:27 +00:00
|
|
|
dirty = planeTransform.transform(this->dirtyRegion);
|
|
|
|
dirty.andSelf(getBounds());
|
|
|
|
}
|
|
|
|
return dirty;
|
|
|
|
}
|
|
|
|
|
2012-07-11 20:48:17 +00:00
|
|
|
// ----------------------------------------------------------------------------
|
2012-08-02 21:01:42 +00:00
|
|
|
|
|
|
|
bool DisplayDevice::canDraw() const {
|
|
|
|
return mScreenAcquired;
|
|
|
|
}
|
|
|
|
|
|
|
|
void DisplayDevice::releaseScreen() const {
|
|
|
|
mScreenAcquired = false;
|
|
|
|
}
|
|
|
|
|
|
|
|
void DisplayDevice::acquireScreen() const {
|
|
|
|
mScreenAcquired = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool DisplayDevice::isScreenAcquired() const {
|
|
|
|
return mScreenAcquired;
|
|
|
|
}
|
|
|
|
|
|
|
|
// ----------------------------------------------------------------------------
|
2012-07-11 20:48:17 +00:00
|
|
|
|
2012-08-09 01:51:15 +00:00
|
|
|
void DisplayDevice::setLayerStack(uint32_t stack) {
|
|
|
|
mLayerStack = stack;
|
|
|
|
dirtyRegion.set(bounds());
|
|
|
|
}
|
|
|
|
|
|
|
|
// ----------------------------------------------------------------------------
|
|
|
|
|
2012-08-01 06:09:07 +00:00
|
|
|
status_t DisplayDevice::orientationToTransfrom(
|
2012-06-21 00:51:20 +00:00
|
|
|
int orientation, int w, int h, Transform* tr)
|
|
|
|
{
|
|
|
|
uint32_t flags = 0;
|
|
|
|
switch (orientation) {
|
2012-08-09 02:42:09 +00:00
|
|
|
case DisplayState::eOrientationDefault:
|
2012-06-21 00:51:20 +00:00
|
|
|
flags = Transform::ROT_0;
|
|
|
|
break;
|
2012-08-09 02:42:09 +00:00
|
|
|
case DisplayState::eOrientation90:
|
2012-06-21 00:51:20 +00:00
|
|
|
flags = Transform::ROT_90;
|
|
|
|
break;
|
2012-08-09 02:42:09 +00:00
|
|
|
case DisplayState::eOrientation180:
|
2012-06-21 00:51:20 +00:00
|
|
|
flags = Transform::ROT_180;
|
|
|
|
break;
|
2012-08-09 02:42:09 +00:00
|
|
|
case DisplayState::eOrientation270:
|
2012-06-21 00:51:20 +00:00
|
|
|
flags = Transform::ROT_270;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
return BAD_VALUE;
|
|
|
|
}
|
|
|
|
tr->set(flags, w, h);
|
|
|
|
return NO_ERROR;
|
|
|
|
}
|
|
|
|
|
2012-09-05 02:30:46 +00:00
|
|
|
void DisplayDevice::setProjection(int orientation,
|
|
|
|
const Rect& viewport, const Rect& frame) {
|
2012-09-04 22:05:38 +00:00
|
|
|
mOrientation = orientation;
|
2012-09-05 02:30:46 +00:00
|
|
|
mViewport = viewport;
|
|
|
|
mFrame = frame;
|
2012-09-04 22:05:38 +00:00
|
|
|
updateGeometryTransform();
|
|
|
|
}
|
|
|
|
|
|
|
|
void DisplayDevice::updateGeometryTransform() {
|
2012-07-25 04:08:59 +00:00
|
|
|
int w = mDisplayWidth;
|
|
|
|
int h = mDisplayHeight;
|
2012-09-14 02:22:41 +00:00
|
|
|
Transform TL, TP, R, S;
|
2012-09-04 22:05:38 +00:00
|
|
|
if (DisplayDevice::orientationToTransfrom(
|
|
|
|
mOrientation, w, h, &R) == NO_ERROR) {
|
|
|
|
dirtyRegion.set(bounds());
|
|
|
|
|
|
|
|
Rect viewport(mViewport);
|
|
|
|
Rect frame(mFrame);
|
|
|
|
|
|
|
|
if (!frame.isValid()) {
|
|
|
|
// the destination frame can be invalid if it has never been set,
|
|
|
|
// in that case we assume the whole display frame.
|
|
|
|
frame = Rect(w, h);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (viewport.isEmpty()) {
|
|
|
|
// viewport can be invalid if it has never been set, in that case
|
|
|
|
// we assume the whole display size.
|
|
|
|
// it's also invalid to have an empty viewport, so we handle that
|
|
|
|
// case in the same way.
|
|
|
|
viewport = Rect(w, h);
|
|
|
|
if (R.getOrientation() & Transform::ROT_90) {
|
|
|
|
// viewport is always specified in the logical orientation
|
|
|
|
// of the display (ie: post-rotation).
|
|
|
|
swap(viewport.right, viewport.bottom);
|
|
|
|
}
|
|
|
|
}
|
2012-06-21 00:51:20 +00:00
|
|
|
|
2012-09-04 22:05:38 +00:00
|
|
|
float src_width = viewport.width();
|
|
|
|
float src_height = viewport.height();
|
|
|
|
float dst_width = frame.width();
|
|
|
|
float dst_height = frame.height();
|
2012-09-12 20:49:10 +00:00
|
|
|
if (src_width != dst_width || src_height != dst_height) {
|
2012-09-04 22:05:38 +00:00
|
|
|
float sx = dst_width / src_width;
|
|
|
|
float sy = dst_height / src_height;
|
|
|
|
S.set(sx, 0, 0, sy);
|
|
|
|
}
|
2012-09-12 20:49:10 +00:00
|
|
|
|
2012-09-04 22:05:38 +00:00
|
|
|
float src_x = viewport.left;
|
|
|
|
float src_y = viewport.top;
|
|
|
|
float dst_x = frame.left;
|
|
|
|
float dst_y = frame.top;
|
2012-09-14 02:22:41 +00:00
|
|
|
TL.set(-src_x, -src_y);
|
|
|
|
TP.set(dst_x, dst_y);
|
|
|
|
|
|
|
|
// The viewport and frame are both in the logical orientation.
|
|
|
|
// Apply the logical translation, scale to physical size, apply the
|
|
|
|
// physical translation and finally rotate to the physical orientation.
|
|
|
|
mGlobalTransform = R * TP * S * TL;
|
2012-09-20 06:14:45 +00:00
|
|
|
|
|
|
|
const uint8_t type = mGlobalTransform.getType();
|
|
|
|
mNeedsFiltering = (!mGlobalTransform.preserveRects() ||
|
|
|
|
(type >= Transform::SCALE));
|
2012-06-21 00:51:20 +00:00
|
|
|
}
|
|
|
|
}
|
2012-09-18 08:38:00 +00:00
|
|
|
|
|
|
|
void DisplayDevice::dump(String8& result, char* buffer, size_t SIZE) const {
|
|
|
|
const Transform& tr(mGlobalTransform);
|
|
|
|
snprintf(buffer, SIZE,
|
|
|
|
"+ DisplayDevice: %s\n"
|
|
|
|
" type=%x, layerStack=%u, (%4dx%4d), ANativeWindow=%p, orient=%2d (type=%08x), "
|
2012-10-20 01:19:11 +00:00
|
|
|
"flips=%u, isSecure=%d, secureVis=%d, acquired=%d, numLayers=%u\n"
|
2012-09-18 08:38:00 +00:00
|
|
|
" v:[%d,%d,%d,%d], f:[%d,%d,%d,%d], "
|
|
|
|
"transform:[[%0.3f,%0.3f,%0.3f][%0.3f,%0.3f,%0.3f][%0.3f,%0.3f,%0.3f]]\n",
|
2012-09-19 23:25:29 +00:00
|
|
|
mDisplayName.string(), mType,
|
2012-09-18 08:38:00 +00:00
|
|
|
mLayerStack, mDisplayWidth, mDisplayHeight, mNativeWindow.get(),
|
|
|
|
mOrientation, tr.getType(), getPageFlipCount(),
|
2012-10-20 01:19:11 +00:00
|
|
|
mIsSecure, mSecureLayerVisible, mScreenAcquired, mVisibleLayersSortedByZ.size(),
|
2012-09-18 08:38:00 +00:00
|
|
|
mViewport.left, mViewport.top, mViewport.right, mViewport.bottom,
|
|
|
|
mFrame.left, mFrame.top, mFrame.right, mFrame.bottom,
|
|
|
|
tr[0][0], tr[1][0], tr[2][0],
|
|
|
|
tr[0][1], tr[1][1], tr[2][1],
|
|
|
|
tr[0][2], tr[1][2], tr[2][2]);
|
|
|
|
|
|
|
|
result.append(buffer);
|
|
|
|
|
|
|
|
String8 fbtargetDump;
|
|
|
|
if (mFramebufferSurface != NULL) {
|
|
|
|
mFramebufferSurface->dump(fbtargetDump);
|
|
|
|
result.append(fbtargetDump);
|
|
|
|
}
|
|
|
|
}
|