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
|
|
|
|
2013-02-15 01:11:02 +00:00
|
|
|
#include <gui/Surface.h>
|
2012-08-03 03:11:05 +00:00
|
|
|
|
2009-04-10 21:24:30 +00:00
|
|
|
#include <hardware/gralloc.h>
|
2009-03-04 03:31:44 +00:00
|
|
|
|
2013-03-14 21:29:29 +00:00
|
|
|
#include "DisplayHardware/DisplaySurface.h"
|
2012-06-21 00:51:20 +00:00
|
|
|
#include "DisplayHardware/HWComposer.h"
|
2013-06-07 22:35:48 +00:00
|
|
|
#include "RenderEngine/RenderEngine.h"
|
2012-06-21 00:51:20 +00:00
|
|
|
|
2012-09-04 22:05:38 +00:00
|
|
|
#include "clz.h"
|
2012-08-01 06:09:07 +00:00
|
|
|
#include "DisplayDevice.h"
|
2011-08-01 23:32:21 +00:00
|
|
|
#include "SurfaceFlinger.h"
|
2013-03-06 01:47:11 +00:00
|
|
|
#include "Layer.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
|
|
|
|
2014-11-13 22:18:56 +00:00
|
|
|
#ifdef EGL_ANDROID_swap_rectangle
|
|
|
|
static constexpr bool kEGLAndroidSwapRectangle = true;
|
|
|
|
#else
|
|
|
|
static constexpr bool kEGLAndroidSwapRectangle = false;
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#if !defined(EGL_EGLEXT_PROTOTYPES) || !defined(EGL_ANDROID_swap_rectangle)
|
|
|
|
// Dummy implementation in case it is missing.
|
|
|
|
inline void eglSetSwapRectangleANDROID (EGLDisplay, EGLSurface, EGLint, EGLint, EGLint, EGLint) {
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
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,
|
2013-03-22 22:13:48 +00:00
|
|
|
int32_t hwcId,
|
2013-12-24 05:02:15 +00:00
|
|
|
int format,
|
2012-10-20 01:19:11 +00:00
|
|
|
bool isSecure,
|
|
|
|
const wp<IBinder>& displayToken,
|
2013-03-14 21:29:29 +00:00
|
|
|
const sp<DisplaySurface>& displaySurface,
|
2013-08-02 08:40:18 +00:00
|
|
|
const sp<IGraphicBufferProducer>& producer,
|
2012-07-12 21:25:33 +00:00
|
|
|
EGLConfig config)
|
2014-08-14 22:45:06 +00:00
|
|
|
: lastCompositionHadVisibleLayers(false),
|
|
|
|
mFlinger(flinger),
|
2013-03-22 22:13:48 +00:00
|
|
|
mType(type), mHwcDisplayId(hwcId),
|
2013-01-07 09:33:56 +00:00
|
|
|
mDisplayToken(displayToken),
|
2013-03-14 21:29:29 +00:00
|
|
|
mDisplaySurface(displaySurface),
|
2012-08-03 01:32:23 +00:00
|
|
|
mDisplay(EGL_NO_DISPLAY),
|
|
|
|
mSurface(EGL_NO_SURFACE),
|
|
|
|
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),
|
2013-02-20 00:13:35 +00:00
|
|
|
mLayerStack(NO_LAYER_STACK),
|
2014-05-25 08:36:31 +00:00
|
|
|
mOrientation(),
|
2014-07-14 20:48:55 +00:00
|
|
|
mPowerMode(HWC_POWER_MODE_OFF),
|
|
|
|
mActiveConfig(0)
|
2009-03-04 03:31:44 +00:00
|
|
|
{
|
2013-09-16 22:24:53 +00:00
|
|
|
mNativeWindow = new Surface(producer, false);
|
2012-07-12 21:25:33 +00:00
|
|
|
ANativeWindow* const window = mNativeWindow.get();
|
2015-08-21 01:18:30 +00:00
|
|
|
char property[PROPERTY_VALUE_MAX];
|
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;
|
2009-03-04 03:31:44 +00:00
|
|
|
EGLDisplay display = eglGetDisplay(EGL_DEFAULT_DISPLAY);
|
2013-12-24 05:02:15 +00:00
|
|
|
if (config == EGL_NO_CONFIG) {
|
|
|
|
config = RenderEngine::chooseEglConfig(display, format);
|
|
|
|
}
|
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
|
|
|
|
2014-02-21 20:37:59 +00:00
|
|
|
// Make sure that composition can never be stalled by a virtual display
|
|
|
|
// consumer that isn't processing buffers fast enough. We have to do this
|
|
|
|
// in two places:
|
|
|
|
// * Here, in case the display is composed entirely by HWC.
|
|
|
|
// * In makeCurrent(), using eglSwapInterval. Some EGL drivers set the
|
|
|
|
// window's swap interval in eglMakeCurrent, so they'll override the
|
|
|
|
// interval we set here.
|
|
|
|
if (mType >= DisplayDevice::DISPLAY_VIRTUAL)
|
|
|
|
window->setSwapInterval(window, 0);
|
|
|
|
|
2014-07-18 22:34:25 +00:00
|
|
|
mConfig = config;
|
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
|
|
|
|
2013-03-22 22:13:48 +00:00
|
|
|
// virtual displays are always considered enabled
|
2014-05-25 08:36:31 +00:00
|
|
|
mPowerMode = (mType >= DisplayDevice::DISPLAY_VIRTUAL) ?
|
|
|
|
HWC_POWER_MODE_NORMAL : HWC_POWER_MODE_OFF;
|
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;
|
|
|
|
}
|
|
|
|
|
2015-08-21 01:18:30 +00:00
|
|
|
mPanelInverseMounted = false;
|
|
|
|
// Check if panel is inverse mounted (contents show up HV flipped)
|
|
|
|
property_get("persist.panel.inversemounted", property, "0");
|
|
|
|
mPanelInverseMounted = !!atoi(property);
|
|
|
|
|
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
|
|
|
}
|
|
|
|
|
2013-03-22 22:13:48 +00:00
|
|
|
DisplayDevice::~DisplayDevice() {
|
|
|
|
if (mSurface != EGL_NO_SURFACE) {
|
|
|
|
eglDestroySurface(mDisplay, mSurface);
|
|
|
|
mSurface = EGL_NO_SURFACE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-03-25 21:43:23 +00:00
|
|
|
void DisplayDevice::disconnect(HWComposer& hwc) {
|
|
|
|
if (mHwcDisplayId >= 0) {
|
|
|
|
hwc.disconnectDisplay(mHwcDisplayId);
|
|
|
|
if (mHwcDisplayId >= DISPLAY_VIRTUAL)
|
|
|
|
hwc.freeDisplayId(mHwcDisplayId);
|
|
|
|
mHwcDisplayId = -1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-03-22 22:13:48 +00:00
|
|
|
bool DisplayDevice::isValid() const {
|
|
|
|
return mFlinger != NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
int DisplayDevice::getWidth() const {
|
|
|
|
return mDisplayWidth;
|
|
|
|
}
|
|
|
|
|
|
|
|
int DisplayDevice::getHeight() const {
|
|
|
|
return mDisplayHeight;
|
|
|
|
}
|
|
|
|
|
|
|
|
PixelFormat DisplayDevice::getFormat() const {
|
|
|
|
return mFormat;
|
|
|
|
}
|
|
|
|
|
|
|
|
EGLSurface DisplayDevice::getEGLSurface() const {
|
|
|
|
return mSurface;
|
|
|
|
}
|
|
|
|
|
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 {
|
2013-03-14 21:29:29 +00:00
|
|
|
return mDisplaySurface->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
|
|
|
{
|
2013-06-07 22:35:48 +00:00
|
|
|
mFlinger->getRenderEngine().checkErrors();
|
2009-03-04 03:31:44 +00:00
|
|
|
|
2014-11-13 22:18:56 +00:00
|
|
|
if (kEGLAndroidSwapRectangle) {
|
|
|
|
if (mFlags & SWAP_RECTANGLE) {
|
|
|
|
const Region newDirty(dirty.intersect(bounds()));
|
|
|
|
const Rect b(newDirty.getBounds());
|
|
|
|
eglSetSwapRectangleANDROID(mDisplay, mSurface,
|
|
|
|
b.left, b.top, b.width(), b.height());
|
|
|
|
}
|
2013-02-20 00:13:35 +00:00
|
|
|
}
|
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
|
|
|
}
|
|
|
|
|
2014-02-05 00:22:36 +00:00
|
|
|
status_t DisplayDevice::beginFrame(bool mustRecompose) const {
|
|
|
|
return mDisplaySurface->beginFrame(mustRecompose);
|
2013-08-20 23:35:32 +00:00
|
|
|
}
|
|
|
|
|
2013-04-07 06:12:29 +00:00
|
|
|
status_t DisplayDevice::prepareFrame(const HWComposer& hwc) const {
|
|
|
|
DisplaySurface::CompositionType compositionType;
|
|
|
|
bool haveGles = hwc.hasGlesComposition(mHwcDisplayId);
|
|
|
|
bool haveHwc = hwc.hasHwcComposition(mHwcDisplayId);
|
|
|
|
if (haveGles && haveHwc) {
|
|
|
|
compositionType = DisplaySurface::COMPOSITION_MIXED;
|
|
|
|
} else if (haveGles) {
|
|
|
|
compositionType = DisplaySurface::COMPOSITION_GLES;
|
|
|
|
} else if (haveHwc) {
|
|
|
|
compositionType = DisplaySurface::COMPOSITION_HWC;
|
|
|
|
} else {
|
|
|
|
// Nothing to do -- when turning the screen off we get a frame like
|
|
|
|
// this. Call it a HWC frame since we won't be doing any GLES work but
|
|
|
|
// will do a prepare/set cycle.
|
|
|
|
compositionType = DisplaySurface::COMPOSITION_HWC;
|
|
|
|
}
|
|
|
|
return mDisplaySurface->prepareFrame(compositionType);
|
|
|
|
}
|
|
|
|
|
2012-09-14 01:17:13 +00:00
|
|
|
void DisplayDevice::swapBuffers(HWComposer& hwc) const {
|
2013-08-20 23:04:47 +00:00
|
|
|
// We need to call eglSwapBuffers() if:
|
|
|
|
// (1) we don't have a hardware composer, or
|
|
|
|
// (2) we did GLES composition this frame, and either
|
|
|
|
// (a) we have framebuffer target support (not present on legacy
|
|
|
|
// devices, where HWComposer::commit() handles things); or
|
|
|
|
// (b) this is a virtual display
|
2013-03-14 21:29:29 +00:00
|
|
|
if (hwc.initCheck() != NO_ERROR ||
|
|
|
|
(hwc.hasGlesComposition(mHwcDisplayId) &&
|
2013-08-20 23:04:47 +00:00
|
|
|
(hwc.supportsFramebufferTarget() || mType >= DISPLAY_VIRTUAL))) {
|
2013-03-14 21:29:29 +00:00
|
|
|
EGLBoolean success = eglSwapBuffers(mDisplay, mSurface);
|
|
|
|
if (!success) {
|
|
|
|
EGLint error = eglGetError();
|
|
|
|
if (error == EGL_CONTEXT_LOST ||
|
|
|
|
mType == DisplayDevice::DISPLAY_PRIMARY) {
|
|
|
|
LOG_ALWAYS_FATAL("eglSwapBuffers(%p, %p) failed with 0x%08x",
|
|
|
|
mDisplay, mSurface, error);
|
|
|
|
} else {
|
|
|
|
ALOGE("eglSwapBuffers(%p, %p) failed with 0x%08x",
|
|
|
|
mDisplay, mSurface, error);
|
2012-09-14 01:17:13 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2012-09-25 01:07:21 +00:00
|
|
|
|
2013-03-14 21:29:29 +00:00
|
|
|
status_t result = mDisplaySurface->advanceFrame();
|
|
|
|
if (result != NO_ERROR) {
|
|
|
|
ALOGE("[%s] failed pushing new frame to HWC: %d",
|
|
|
|
mDisplayName.string(), result);
|
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) {
|
2013-03-20 20:44:00 +00:00
|
|
|
mDisplaySurface->onFrameCommitted();
|
2012-09-14 01:17:13 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-08-01 06:09:07 +00:00
|
|
|
uint32_t DisplayDevice::getFlags() const
|
2009-03-04 03:31:44 +00:00
|
|
|
{
|
|
|
|
return mFlags;
|
|
|
|
}
|
|
|
|
|
2013-06-07 22:35:48 +00:00
|
|
|
EGLBoolean DisplayDevice::makeCurrent(EGLDisplay dpy, EGLContext ctx) const {
|
2012-09-04 22:05:38 +00:00
|
|
|
EGLBoolean result = EGL_TRUE;
|
2012-08-01 02:01:53 +00:00
|
|
|
EGLSurface sur = eglGetCurrentSurface(EGL_DRAW);
|
2013-06-07 22:35:48 +00:00
|
|
|
if (sur != mSurface) {
|
|
|
|
result = eglMakeCurrent(dpy, mSurface, mSurface, ctx);
|
2012-09-04 22:05:38 +00:00
|
|
|
if (result == EGL_TRUE) {
|
2013-08-07 00:08:53 +00:00
|
|
|
if (mType >= DisplayDevice::DISPLAY_VIRTUAL)
|
|
|
|
eglSwapInterval(dpy, 0);
|
2012-09-04 22:05:38 +00:00
|
|
|
}
|
2012-08-01 02:01:53 +00:00
|
|
|
}
|
2013-08-29 01:11:46 +00:00
|
|
|
setViewportAndProjection();
|
2012-09-04 22:05:38 +00:00
|
|
|
return result;
|
2012-08-01 02:01:53 +00:00
|
|
|
}
|
|
|
|
|
2013-06-07 22:35:48 +00:00
|
|
|
void DisplayDevice::setViewportAndProjection() const {
|
|
|
|
size_t w = mDisplayWidth;
|
|
|
|
size_t h = mDisplayHeight;
|
2014-05-22 22:59:05 +00:00
|
|
|
Rect sourceCrop(0, 0, w, h);
|
2014-09-04 23:20:31 +00:00
|
|
|
mFlinger->getRenderEngine().setViewportAndProjection(w, h, sourceCrop, h,
|
|
|
|
false, Transform::ROT_0);
|
2012-09-28 08:00:47 +00:00
|
|
|
}
|
|
|
|
|
2012-06-21 00:51:20 +00:00
|
|
|
// ----------------------------------------------------------------------------
|
|
|
|
|
2013-03-06 01:47:11 +00:00
|
|
|
void DisplayDevice::setVisibleLayersSortedByZ(const Vector< sp<Layer> >& 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++) {
|
2013-03-06 01:47:11 +00:00
|
|
|
const sp<Layer>& layer(layers[i]);
|
2013-02-27 00:54:05 +00:00
|
|
|
if (layer->isSecure()) {
|
2012-07-11 20:48:17 +00:00
|
|
|
mSecureLayerVisible = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-03-06 01:47:11 +00:00
|
|
|
const Vector< sp<Layer> >& 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
|
|
|
// ----------------------------------------------------------------------------
|
2014-05-25 08:36:31 +00:00
|
|
|
void DisplayDevice::setPowerMode(int mode) {
|
|
|
|
mPowerMode = mode;
|
2012-08-02 21:01:42 +00:00
|
|
|
}
|
|
|
|
|
2014-05-25 08:36:31 +00:00
|
|
|
int DisplayDevice::getPowerMode() const {
|
|
|
|
return mPowerMode;
|
2012-08-02 21:01:42 +00:00
|
|
|
}
|
|
|
|
|
2014-05-25 08:36:31 +00:00
|
|
|
bool DisplayDevice::isDisplayOn() const {
|
|
|
|
return (mPowerMode != HWC_POWER_MODE_OFF);
|
2012-08-02 21:01:42 +00:00
|
|
|
}
|
|
|
|
|
2014-07-14 20:48:55 +00:00
|
|
|
// ----------------------------------------------------------------------------
|
|
|
|
void DisplayDevice::setActiveConfig(int mode) {
|
|
|
|
mActiveConfig = mode;
|
|
|
|
}
|
|
|
|
|
|
|
|
int DisplayDevice::getActiveConfig() const {
|
|
|
|
return mActiveConfig;
|
|
|
|
}
|
|
|
|
|
2012-08-02 21:01:42 +00:00
|
|
|
// ----------------------------------------------------------------------------
|
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());
|
|
|
|
}
|
|
|
|
|
|
|
|
// ----------------------------------------------------------------------------
|
|
|
|
|
2013-09-18 06:45:22 +00:00
|
|
|
uint32_t DisplayDevice::getOrientationTransform() const {
|
|
|
|
uint32_t transform = 0;
|
|
|
|
switch (mOrientation) {
|
|
|
|
case DisplayState::eOrientationDefault:
|
|
|
|
transform = Transform::ROT_0;
|
|
|
|
break;
|
|
|
|
case DisplayState::eOrientation90:
|
|
|
|
transform = Transform::ROT_90;
|
|
|
|
break;
|
|
|
|
case DisplayState::eOrientation180:
|
|
|
|
transform = Transform::ROT_180;
|
|
|
|
break;
|
|
|
|
case DisplayState::eOrientation270:
|
|
|
|
transform = Transform::ROT_270;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
return transform;
|
|
|
|
}
|
|
|
|
|
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;
|
|
|
|
}
|
2015-08-21 01:18:30 +00:00
|
|
|
|
|
|
|
if (DISPLAY_PRIMARY == mHwcDisplayId && isPanelInverseMounted()) {
|
|
|
|
flags = flags ^ Transform::ROT_180;
|
|
|
|
}
|
|
|
|
|
2012-06-21 00:51:20 +00:00
|
|
|
tr->set(flags, w, h);
|
|
|
|
return NO_ERROR;
|
|
|
|
}
|
|
|
|
|
2014-07-18 22:34:25 +00:00
|
|
|
void DisplayDevice::setDisplaySize(const int newWidth, const int newHeight) {
|
|
|
|
dirtyRegion.set(getBounds());
|
|
|
|
|
2014-08-20 17:51:23 +00:00
|
|
|
if (mSurface != EGL_NO_SURFACE) {
|
|
|
|
eglDestroySurface(mDisplay, mSurface);
|
|
|
|
mSurface = EGL_NO_SURFACE;
|
|
|
|
}
|
|
|
|
|
2014-07-18 22:34:25 +00:00
|
|
|
mDisplaySurface->resizeBuffers(newWidth, newHeight);
|
|
|
|
|
|
|
|
ANativeWindow* const window = mNativeWindow.get();
|
|
|
|
mSurface = eglCreateWindowSurface(mDisplay, mConfig, window, NULL);
|
|
|
|
eglQuerySurface(mDisplay, mSurface, EGL_WIDTH, &mDisplayWidth);
|
|
|
|
eglQuerySurface(mDisplay, mSurface, EGL_HEIGHT, &mDisplayHeight);
|
|
|
|
|
|
|
|
LOG_FATAL_IF(mDisplayWidth != newWidth,
|
|
|
|
"Unable to set new width to %d", newWidth);
|
|
|
|
LOG_FATAL_IF(mDisplayHeight != newHeight,
|
|
|
|
"Unable to set new height to %d", newHeight);
|
|
|
|
}
|
|
|
|
|
2012-09-05 02:30:46 +00:00
|
|
|
void DisplayDevice::setProjection(int orientation,
|
2013-02-27 00:54:05 +00:00
|
|
|
const Rect& newViewport, const Rect& newFrame) {
|
|
|
|
Rect viewport(newViewport);
|
|
|
|
Rect frame(newFrame);
|
2012-09-04 22:05:38 +00:00
|
|
|
|
2013-02-27 00:54:05 +00:00
|
|
|
const int w = mDisplayWidth;
|
|
|
|
const int h = mDisplayHeight;
|
2012-09-04 22:05:38 +00:00
|
|
|
|
2013-02-27 00:54:05 +00:00
|
|
|
Transform R;
|
|
|
|
DisplayDevice::orientationToTransfrom(orientation, w, h, &R);
|
2012-06-21 00:51:20 +00:00
|
|
|
|
2013-02-27 00:54:05 +00:00
|
|
|
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);
|
|
|
|
}
|
2012-09-12 20:49:10 +00:00
|
|
|
|
2013-02-27 00:54:05 +00:00
|
|
|
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-10-31 01:08:06 +00:00
|
|
|
}
|
2012-06-21 00:51:20 +00:00
|
|
|
}
|
2013-02-27 00:54:05 +00:00
|
|
|
|
|
|
|
dirtyRegion.set(getBounds());
|
|
|
|
|
|
|
|
Transform TL, TP, S;
|
|
|
|
float src_width = viewport.width();
|
|
|
|
float src_height = viewport.height();
|
|
|
|
float dst_width = frame.width();
|
|
|
|
float dst_height = frame.height();
|
|
|
|
if (src_width != dst_width || src_height != dst_height) {
|
|
|
|
float sx = dst_width / src_width;
|
|
|
|
float sy = dst_height / src_height;
|
|
|
|
S.set(sx, 0, 0, sy);
|
|
|
|
}
|
|
|
|
|
|
|
|
float src_x = viewport.left;
|
|
|
|
float src_y = viewport.top;
|
|
|
|
float dst_x = frame.left;
|
|
|
|
float dst_y = frame.top;
|
|
|
|
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;
|
|
|
|
|
|
|
|
const uint8_t type = mGlobalTransform.getType();
|
|
|
|
mNeedsFiltering = (!mGlobalTransform.preserveRects() ||
|
|
|
|
(type >= Transform::SCALE));
|
|
|
|
|
|
|
|
mScissor = mGlobalTransform.transform(viewport);
|
|
|
|
if (mScissor.isEmpty()) {
|
2013-05-10 03:37:10 +00:00
|
|
|
mScissor = getBounds();
|
2013-02-27 00:54:05 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
mOrientation = orientation;
|
|
|
|
mViewport = viewport;
|
|
|
|
mFrame = frame;
|
2012-06-21 00:51:20 +00:00
|
|
|
}
|
2012-09-18 08:38:00 +00:00
|
|
|
|
2013-04-22 14:55:35 +00:00
|
|
|
void DisplayDevice::dump(String8& result) const {
|
2012-09-18 08:38:00 +00:00
|
|
|
const Transform& tr(mGlobalTransform);
|
2013-04-22 14:55:35 +00:00
|
|
|
result.appendFormat(
|
2012-09-18 08:38:00 +00:00
|
|
|
"+ DisplayDevice: %s\n"
|
2013-03-25 21:43:23 +00:00
|
|
|
" type=%x, hwcId=%d, layerStack=%u, (%4dx%4d), ANativeWindow=%p, orient=%2d (type=%08x), "
|
2014-07-14 20:48:55 +00:00
|
|
|
"flips=%u, isSecure=%d, secureVis=%d, powerMode=%d, activeConfig=%d, numLayers=%zu\n"
|
2012-10-31 01:08:06 +00:00
|
|
|
" v:[%d,%d,%d,%d], f:[%d,%d,%d,%d], s:[%d,%d,%d,%d],"
|
2012-09-18 08:38:00 +00:00
|
|
|
"transform:[[%0.3f,%0.3f,%0.3f][%0.3f,%0.3f,%0.3f][%0.3f,%0.3f,%0.3f]]\n",
|
2013-03-25 21:43:23 +00:00
|
|
|
mDisplayName.string(), mType, mHwcDisplayId,
|
2012-09-18 08:38:00 +00:00
|
|
|
mLayerStack, mDisplayWidth, mDisplayHeight, mNativeWindow.get(),
|
|
|
|
mOrientation, tr.getType(), getPageFlipCount(),
|
2014-07-14 20:48:55 +00:00
|
|
|
mIsSecure, mSecureLayerVisible, mPowerMode, mActiveConfig,
|
|
|
|
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,
|
2012-10-31 01:08:06 +00:00
|
|
|
mScissor.left, mScissor.top, mScissor.right, mScissor.bottom,
|
2012-09-18 08:38:00 +00:00
|
|
|
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]);
|
|
|
|
|
2013-03-14 21:29:29 +00:00
|
|
|
String8 surfaceDump;
|
2014-11-11 18:32:31 +00:00
|
|
|
mDisplaySurface->dumpAsString(surfaceDump);
|
2013-03-14 21:29:29 +00:00
|
|
|
result.append(surfaceDump);
|
2012-09-18 08:38:00 +00:00
|
|
|
}
|