get rid of GraphicPlane

its functionality is now folded into DisplayHardware
there will be more changes in that area.
This commit is contained in:
Mathias Agopian 2012-06-20 17:51:20 -07:00
parent 3094df359d
commit 1b03149f35
15 changed files with 225 additions and 335 deletions

View File

@ -3,12 +3,12 @@ include $(CLEAR_VARS)
LOCAL_SRC_FILES:= \
Client.cpp \
DisplayHardware.cpp \
EventThread.cpp \
Layer.cpp \
LayerBase.cpp \
LayerDim.cpp \
LayerScreenshot.cpp \
DisplayHardware/DisplayHardware.cpp \
DisplayHardware/DisplayHardwareBase.cpp \
DisplayHardware/FramebufferSurface.cpp \
DisplayHardware/HWComposer.cpp \

View File

@ -30,14 +30,14 @@
#include <EGL/egl.h>
#include <EGL/eglext.h>
#include "DisplayHardware/DisplayHardware.h"
#include "DisplayHardware/FramebufferSurface.h"
#include <hardware/gralloc.h>
#include "DisplayHardwareBase.h"
#include "DisplayHardware/FramebufferSurface.h"
#include "DisplayHardware/DisplayHardwareBase.h"
#include "DisplayHardware/HWComposer.h"
#include "DisplayHardware.h"
#include "GLExtensions.h"
#include "HWComposer.h"
#include "SurfaceFlinger.h"
using namespace android;
@ -111,8 +111,8 @@ float DisplayHardware::getDpiX() const { return mDpiX; }
float DisplayHardware::getDpiY() const { return mDpiY; }
float DisplayHardware::getDensity() const { return mDensity; }
float DisplayHardware::getRefreshRate() const { return mRefreshRate; }
int DisplayHardware::getWidth() const { return mWidth; }
int DisplayHardware::getHeight() const { return mHeight; }
int DisplayHardware::getWidth() const { return mDisplayWidth; }
int DisplayHardware::getHeight() const { return mDisplayHeight; }
PixelFormat DisplayHardware::getFormat() const { return mFormat; }
uint32_t DisplayHardware::getMaxTextureSize() const { return mMaxTextureSize; }
@ -267,8 +267,8 @@ void DisplayHardware::init(uint32_t dpy)
*/
surface = eglCreateWindowSurface(display, config, mNativeWindow.get(), NULL);
eglQuerySurface(display, surface, EGL_WIDTH, &mWidth);
eglQuerySurface(display, surface, EGL_HEIGHT, &mHeight);
eglQuerySurface(display, surface, EGL_WIDTH, &mDisplayWidth);
eglQuerySurface(display, surface, EGL_HEIGHT, &mDisplayHeight);
if (mFlags & PARTIAL_UPDATES) {
// if we have partial updates, we definitely don't need to
@ -348,6 +348,36 @@ void DisplayHardware::init(uint32_t dpy)
if (mHwc->initCheck() == NO_ERROR) {
mHwc->setFrameBuffer(mDisplay, mSurface);
}
// initialize the display orientation transform.
// it's a constant that should come from the display driver.
int displayOrientation = ISurfaceComposer::eOrientationDefault;
char property[PROPERTY_VALUE_MAX];
if (property_get("ro.sf.hwrotation", property, NULL) > 0) {
//displayOrientation
switch (atoi(property)) {
case 90:
displayOrientation = ISurfaceComposer::eOrientation90;
break;
case 270:
displayOrientation = ISurfaceComposer::eOrientation270;
break;
}
}
w = mDisplayWidth;
h = mDisplayHeight;
DisplayHardware::orientationToTransfrom(displayOrientation, w, h,
&mDisplayTransform);
if (displayOrientation & ISurfaceComposer::eOrientationSwapMask) {
mLogicalDisplayWidth = h;
mLogicalDisplayHeight = w;
} else {
mLogicalDisplayWidth = w;
mLogicalDisplayHeight = h;
}
DisplayHardware::setOrientation(ISurfaceComposer::eOrientationDefault);
}
void DisplayHardware::setVSyncHandler(const sp<VSyncHandler>& handler) {
@ -476,3 +506,52 @@ void DisplayHardware::dump(String8& res) const
{
mNativeWindow->dump(res);
}
// ----------------------------------------------------------------------------
status_t DisplayHardware::orientationToTransfrom(
int orientation, int w, int h, Transform* tr)
{
uint32_t flags = 0;
switch (orientation) {
case ISurfaceComposer::eOrientationDefault:
flags = Transform::ROT_0;
break;
case ISurfaceComposer::eOrientation90:
flags = Transform::ROT_90;
break;
case ISurfaceComposer::eOrientation180:
flags = Transform::ROT_180;
break;
case ISurfaceComposer::eOrientation270:
flags = Transform::ROT_270;
break;
default:
return BAD_VALUE;
}
tr->set(flags, w, h);
return NO_ERROR;
}
status_t DisplayHardware::setOrientation(int orientation)
{
// If the rotation can be handled in hardware, this is where
// the magic should happen.
const int w = mLogicalDisplayWidth;
const int h = mLogicalDisplayHeight;
mUserDisplayWidth = w;
mUserDisplayHeight = h;
Transform orientationTransform;
DisplayHardware::orientationToTransfrom(orientation, w, h,
&orientationTransform);
if (orientation & ISurfaceComposer::eOrientationSwapMask) {
mUserDisplayWidth = h;
mUserDisplayHeight = w;
}
mOrientation = orientation;
mGlobalTransform = mDisplayTransform * orientationTransform;
return NO_ERROR;
}

View File

@ -28,10 +28,11 @@
#include <EGL/eglext.h>
#include "GLExtensions.h"
#include "Transform.h"
#include "DisplayHardware/DisplayHardwareBase.h"
#include "HWComposer.h"
#include "PowerHAL.h"
#include "DisplayHardware/HWComposer.h"
#include "DisplayHardware/PowerHAL.h"
namespace android {
@ -84,6 +85,11 @@ public:
nsecs_t getRefreshTimestamp() const;
void makeCurrent() const;
status_t setOrientation(int orientation);
int getOrientation() const { return mOrientation; }
const Transform& getTransform() const { return mGlobalTransform; }
int getUserWidth() const { return mUserDisplayWidth; }
int getUserHeight() const { return mUserDisplayHeight; }
void setVSyncHandler(const sp<VSyncHandler>& handler);
@ -106,14 +112,14 @@ public:
status_t compositionComplete() const;
Rect getBounds() const {
return Rect(mWidth, mHeight);
return Rect(mDisplayWidth, mDisplayHeight);
}
inline Rect bounds() const { return getBounds(); }
private:
virtual void onVSyncReceived(int dpy, nsecs_t timestamp);
void init(uint32_t displayIndex) __attribute__((noinline));
void fini() __attribute__((noinline));
void init(uint32_t displayIndex);
void fini();
sp<SurfaceFlinger> mFlinger;
EGLDisplay mDisplay;
@ -124,8 +130,8 @@ private:
float mDpiY;
float mRefreshRate;
float mDensity;
int mWidth;
int mHeight;
int mDisplayWidth;
int mDisplayHeight;
PixelFormat mFormat;
uint32_t mFlags;
mutable uint32_t mPageFlipCount;
@ -140,6 +146,18 @@ private:
PowerHAL mPowerHAL;
// this used to be in GraphicPlane
static status_t orientationToTransfrom(int orientation, int w, int h,
Transform* tr);
Transform mGlobalTransform;
Transform mDisplayTransform;
int mOrientation;
int mLogicalDisplayWidth;
int mLogicalDisplayHeight;
int mUserDisplayWidth;
int mUserDisplayHeight;
mutable Mutex mLock;
// protected by mLock

View File

@ -26,7 +26,7 @@
#include <utils/Errors.h>
#include <utils/Trace.h>
#include "DisplayHardware/DisplayHardware.h"
#include "DisplayHardware.h"
#include "EventThread.h"
#include "SurfaceFlinger.h"
@ -38,7 +38,7 @@ namespace android {
EventThread::EventThread(const sp<SurfaceFlinger>& flinger)
: mFlinger(flinger),
mHw(flinger->graphicPlane(0).editDisplayHardware()),
mHw(const_cast<DisplayHardware&>(flinger->getDefaultDisplayHardware())), // XXX: eventthread will need rework
mLastVSyncTimestamp(0),
mVSyncTimestamp(0),
mUseSoftwareVSync(false),

View File

@ -27,7 +27,7 @@
#include <utils/threads.h>
#include <utils/SortedVector.h>
#include "DisplayHardware/DisplayHardware.h"
#include "DisplayHardware.h"
// ---------------------------------------------------------------------------

View File

@ -36,13 +36,14 @@
#include <gui/Surface.h>
#include "clz.h"
#include "DisplayHardware/DisplayHardware.h"
#include "DisplayHardware/HWComposer.h"
#include "DisplayHardware.h"
#include "GLExtensions.h"
#include "Layer.h"
#include "SurfaceFlinger.h"
#include "SurfaceTextureLayer.h"
#include "DisplayHardware/HWComposer.h"
#define DEBUG_RESIZE 0
namespace android {
@ -63,7 +64,6 @@ Layer::Layer(SurfaceFlinger* flinger,
mFormat(PIXEL_FORMAT_NONE),
mGLExtensions(GLExtensions::getInstance()),
mOpaqueLayer(true),
mNeedsDithering(false),
mSecure(false),
mProtectedByApp(false)
{
@ -77,7 +77,9 @@ void Layer::onLayerDisplayed(HWComposer::HWCLayerInterface* layer) {
}
if (mFrameLatencyNeeded) {
const DisplayHardware& hw(graphicPlane(0).displayHardware());
// we need a DisplayHardware for debugging only right now
// XXX: should this be called per DisplayHardware?
const DisplayHardware& hw(mFlinger->getDefaultDisplayHardware());
mFrameStats[mFrameLatencyOffset].timestamp = mSurfaceTexture->getTimestamp();
mFrameStats[mFrameLatencyOffset].set = systemTime();
mFrameStats[mFrameLatencyOffset].vsync = hw.getRefreshTimestamp();
@ -142,8 +144,8 @@ void Layer::setName(const String8& name) {
mSurfaceTexture->setName(name);
}
void Layer::validateVisibility(const Transform& globalTransform) {
LayerBase::validateVisibility(globalTransform);
void Layer::validateVisibility(const Transform& globalTransform, const DisplayHardware& hw) {
LayerBase::validateVisibility(globalTransform, hw);
// This optimization allows the SurfaceTexture to bake in
// the rotation so hardware overlays can be used
@ -188,7 +190,8 @@ status_t Layer::setBuffers( uint32_t w, uint32_t h,
}
// the display's pixel format
const DisplayHardware& hw(graphicPlane(0).displayHardware());
// XXX: we shouldn't rely on the DisplayHardware to do this
const DisplayHardware& hw(mFlinger->getDefaultDisplayHardware());
uint32_t const maxSurfaceDims = min(
hw.getMaxTextureSize(), hw.getMaxViewportDims());
@ -199,10 +202,6 @@ status_t Layer::setBuffers( uint32_t w, uint32_t h,
return BAD_VALUE;
}
PixelFormatInfo displayInfo;
getPixelFormatInfo(hw.getFormat(), &displayInfo);
const uint32_t hwFlags = hw.getFlags();
mFormat = format;
mSecure = (flags & ISurfaceComposer::eSecure) ? true : false;
@ -214,11 +213,6 @@ status_t Layer::setBuffers( uint32_t w, uint32_t h,
mSurfaceTexture->setDefaultBufferFormat(format);
mSurfaceTexture->setConsumerUsageBits(getEffectiveUsage(0));
// we use the red index
int displayRedSize = displayInfo.getSize(PixelFormatInfo::INDEX_RED);
int layerRedsize = info.getSize(PixelFormatInfo::INDEX_RED);
mNeedsDithering = layerRedsize > displayRedSize;
return NO_ERROR;
}
@ -307,7 +301,7 @@ void Layer::setPerFrameData(HWComposer::HWCLayerInterface& layer) {
layer.setBuffer(buffer);
}
void Layer::onDraw(const Region& clip) const
void Layer::onDraw(const DisplayHardware& hw, const Region& clip) const
{
ATRACE_CALL();
@ -334,7 +328,7 @@ void Layer::onDraw(const Region& clip) const
// if not everything below us is covered, we plug the holes!
Region holes(clip.subtract(under));
if (!holes.isEmpty()) {
clearWithOpenGL(holes, 0, 0, 0, 1);
clearWithOpenGL(hw, holes, 0, 0, 0, 1);
}
return;
}
@ -370,7 +364,7 @@ void Layer::onDraw(const Region& clip) const
glEnable(GL_TEXTURE_2D);
}
drawWithOpenGL(clip);
drawWithOpenGL(hw, clip);
glDisable(GL_TEXTURE_EXTERNAL_OES);
glDisable(GL_TEXTURE_2D);
@ -730,7 +724,7 @@ void Layer::dumpStats(String8& result, char* buffer, size_t SIZE) const
{
LayerBaseClient::dumpStats(result, buffer, SIZE);
const size_t o = mFrameLatencyOffset;
const DisplayHardware& hw(graphicPlane(0).displayHardware());
const DisplayHardware& hw(mFlinger->getDefaultDisplayHardware());
const nsecs_t period = hw.getRefreshPeriod();
result.appendFormat("%lld\n", period);
for (size_t i=0 ; i<128 ; i++) {

View File

@ -66,18 +66,17 @@ public:
// LayerBase interface
virtual void setGeometry(HWComposer::HWCLayerInterface& layer);
virtual void setPerFrameData(HWComposer::HWCLayerInterface& layer);
virtual void onDraw(const Region& clip) const;
virtual void onDraw(const DisplayHardware& hw, const Region& clip) const;
virtual uint32_t doTransaction(uint32_t transactionFlags);
virtual void lockPageFlip(bool& recomputeVisibleRegions);
virtual void unlockPageFlip(const Transform& planeTransform, Region& outDirtyRegion);
virtual bool isOpaque() const;
virtual bool needsDithering() const { return mNeedsDithering; }
virtual bool isSecure() const { return mSecure; }
virtual bool isProtected() const;
virtual void onRemoved();
virtual sp<Layer> getLayer() const { return const_cast<Layer*>(this); }
virtual void setName(const String8& name);
virtual void validateVisibility(const Transform& globalTransform);
virtual void validateVisibility(const Transform& globalTransform, const DisplayHardware& hw);
// LayerBaseClient interface
virtual wp<IBinder> getSurfaceTextureBinder() const;
@ -137,7 +136,6 @@ private:
PixelFormat mFormat;
const GLExtensions& mGLExtensions;
bool mOpaqueLayer;
bool mNeedsDithering;
// page-flip thread (currently main thread)
bool mSecure; // no screenshots

View File

@ -32,7 +32,7 @@
#include "Client.h"
#include "LayerBase.h"
#include "SurfaceFlinger.h"
#include "DisplayHardware/DisplayHardware.h"
#include "DisplayHardware.h"
namespace android {
@ -50,8 +50,6 @@ LayerBase::LayerBase(SurfaceFlinger* flinger, DisplayID display)
mTransactionFlags(0),
mPremultipliedAlpha(true), mName("unnamed"), mDebug(false)
{
const DisplayHardware& hw(flinger->graphicPlane(0).displayHardware());
mFlags = hw.getFlags();
}
LayerBase::~LayerBase()
@ -66,16 +64,6 @@ String8 LayerBase::getName() const {
return mName;
}
const GraphicPlane& LayerBase::graphicPlane(int dpy) const
{
return mFlinger->graphicPlane(dpy);
}
GraphicPlane& LayerBase::graphicPlane(int dpy)
{
return mFlinger->graphicPlane(dpy);
}
void LayerBase::initStates(uint32_t w, uint32_t h, uint32_t flags)
{
uint32_t layerFlags = 0;
@ -231,12 +219,11 @@ uint32_t LayerBase::doTransaction(uint32_t flags)
return flags;
}
void LayerBase::validateVisibility(const Transform& planeTransform)
void LayerBase::validateVisibility(const Transform& planeTransform, const DisplayHardware& hw)
{
const Layer::State& s(drawingState());
const Transform tr(planeTransform * s.transform);
const bool transformed = tr.transformed();
const DisplayHardware& hw(graphicPlane(0).displayHardware());
const uint32_t hw_h = hw.getHeight();
const Rect& crop(s.active.crop);
@ -322,24 +309,21 @@ bool LayerBase::getFiltering() const
return mFiltering;
}
void LayerBase::draw(const Region& clip) const
void LayerBase::draw(const DisplayHardware& hw, const Region& clip) const
{
onDraw(clip);
onDraw(hw, clip);
}
void LayerBase::drawForSreenShot()
void LayerBase::drawForSreenShot(const DisplayHardware& hw)
{
const DisplayHardware& hw(graphicPlane(0).displayHardware());
setFiltering(true);
onDraw( Region(hw.bounds()) );
onDraw( hw, Region(hw.bounds()) );
setFiltering(false);
}
void LayerBase::clearWithOpenGL(const Region& clip, GLclampf red,
GLclampf green, GLclampf blue,
GLclampf alpha) const
void LayerBase::clearWithOpenGL(const DisplayHardware& hw, const Region& clip,
GLclampf red, GLclampf green, GLclampf blue, GLclampf alpha) const
{
const DisplayHardware& hw(graphicPlane(0).displayHardware());
const uint32_t fbHeight = hw.getHeight();
glColor4f(red,green,blue,alpha);
@ -351,14 +335,13 @@ void LayerBase::clearWithOpenGL(const Region& clip, GLclampf red,
glDrawArrays(GL_TRIANGLE_FAN, 0, mNumVertices);
}
void LayerBase::clearWithOpenGL(const Region& clip) const
void LayerBase::clearWithOpenGL(const DisplayHardware& hw, const Region& clip) const
{
clearWithOpenGL(clip,0,0,0,0);
clearWithOpenGL(hw, clip, 0,0,0,0);
}
void LayerBase::drawWithOpenGL(const Region& clip) const
void LayerBase::drawWithOpenGL(const DisplayHardware& hw, const Region& clip) const
{
const DisplayHardware& hw(graphicPlane(0).displayHardware());
const uint32_t fbHeight = hw.getHeight();
const State& s(drawingState());

View File

@ -32,7 +32,7 @@
#include <private/gui/LayerState.h>
#include "DisplayHardware/DisplayHardware.h"
#include "DisplayHardware.h"
#include "Transform.h"
namespace android {
@ -42,7 +42,6 @@ namespace android {
class Client;
class DisplayHardware;
class GraphicBuffer;
class GraphicPlane;
class Layer;
class LayerBaseClient;
class SurfaceFlinger;
@ -124,13 +123,13 @@ public:
* Typically this method is not overridden, instead implement onDraw()
* to perform the actual drawing.
*/
virtual void draw(const Region& clip) const;
virtual void drawForSreenShot();
virtual void draw(const DisplayHardware& hw, const Region& clip) const;
virtual void drawForSreenShot(const DisplayHardware& hw);
/**
* onDraw - draws the surface.
*/
virtual void onDraw(const Region& clip) const = 0;
virtual void onDraw(const DisplayHardware& hw, const Region& clip) const = 0;
/**
* initStates - called just after construction
@ -159,7 +158,7 @@ public:
/**
* validateVisibility - cache a bunch of things
*/
virtual void validateVisibility(const Transform& globalTransform);
virtual void validateVisibility(const Transform& globalTransform, const DisplayHardware& hw);
/**
* lockPageFlip - called each time the screen is redrawn and returns whether
@ -237,21 +236,17 @@ public:
int32_t getOrientation() const { return mOrientation; }
int32_t getPlaneOrientation() const { return mPlaneOrientation; }
void clearWithOpenGL(const Region& clip) const;
void clearWithOpenGL(const DisplayHardware& hw, const Region& clip) const;
protected:
const GraphicPlane& graphicPlane(int dpy) const;
GraphicPlane& graphicPlane(int dpy);
void clearWithOpenGL(const Region& clip, GLclampf r, GLclampf g,
GLclampf b, GLclampf alpha) const;
void drawWithOpenGL(const Region& clip) const;
void clearWithOpenGL(const DisplayHardware& hw, const Region& clip,
GLclampf r, GLclampf g, GLclampf b, GLclampf alpha) const;
void drawWithOpenGL(const DisplayHardware& hw, const Region& clip) const;
void setFiltering(bool filtering);
bool getFiltering() const;
sp<SurfaceFlinger> mFlinger;
uint32_t mFlags;
private:
// accessed only in the main thread

View File

@ -25,7 +25,7 @@
#include "LayerDim.h"
#include "SurfaceFlinger.h"
#include "DisplayHardware/DisplayHardware.h"
#include "DisplayHardware.h"
namespace android {
// ---------------------------------------------------------------------------
@ -40,11 +40,10 @@ LayerDim::~LayerDim()
{
}
void LayerDim::onDraw(const Region& clip) const
void LayerDim::onDraw(const DisplayHardware& hw, const Region& clip) const
{
const State& s(drawingState());
if (s.alpha>0) {
const DisplayHardware& hw(graphicPlane(0).displayHardware());
const GLfloat alpha = s.alpha/255.0f;
const uint32_t fbHeight = hw.getHeight();
glDisable(GL_TEXTURE_EXTERNAL_OES);

View File

@ -36,7 +36,7 @@ public:
const sp<Client>& client);
virtual ~LayerDim();
virtual void onDraw(const Region& clip) const;
virtual void onDraw(const DisplayHardware& hw, const Region& clip) const;
virtual bool isOpaque() const { return false; }
virtual bool isSecure() const { return false; }
virtual bool isProtectedByApp() const { return false; }

View File

@ -25,7 +25,7 @@
#include "LayerScreenshot.h"
#include "SurfaceFlinger.h"
#include "DisplayHardware/DisplayHardware.h"
#include "DisplayHardware.h"
namespace android {
@ -106,11 +106,10 @@ uint32_t LayerScreenshot::doTransaction(uint32_t flags)
return LayerBaseClient::doTransaction(flags);
}
void LayerScreenshot::onDraw(const Region& clip) const
void LayerScreenshot::onDraw(const DisplayHardware& hw, const Region& clip) const
{
const State& s(drawingState());
if (s.alpha>0) {
const DisplayHardware& hw(graphicPlane(0).displayHardware());
const GLfloat alpha = s.alpha/255.0f;
const uint32_t fbHeight = hw.getHeight();

View File

@ -43,7 +43,7 @@ public:
virtual void initStates(uint32_t w, uint32_t h, uint32_t flags);
virtual uint32_t doTransaction(uint32_t flags);
virtual void onDraw(const Region& clip) const;
virtual void onDraw(const DisplayHardware& hw, const Region& clip) const;
virtual bool isOpaque() const { return false; }
virtual bool isSecure() const { return false; }
virtual bool isProtectedByApp() const { return false; }

View File

@ -50,6 +50,7 @@
#include "clz.h"
#include "DdmConnection.h"
#include "DisplayHardware.h"
#include "Client.h"
#include "EventThread.h"
#include "GLExtensions.h"
@ -58,7 +59,6 @@
#include "LayerScreenshot.h"
#include "SurfaceFlinger.h"
#include "DisplayHardware/DisplayHardware.h"
#include "DisplayHardware/HWComposer.h"
#include <private/android_filesystem_config.h>
@ -178,19 +178,6 @@ sp<IGraphicBufferAlloc> SurfaceFlinger::createGraphicBufferAlloc()
return gba;
}
const GraphicPlane& SurfaceFlinger::graphicPlane(int dpy) const
{
ALOGE_IF(uint32_t(dpy) >= DISPLAY_COUNT, "Invalid DisplayID %d", dpy);
const GraphicPlane& plane(mGraphicPlanes[dpy]);
return plane;
}
GraphicPlane& SurfaceFlinger::graphicPlane(int dpy)
{
return const_cast<GraphicPlane&>(
const_cast<SurfaceFlinger const *>(this)->graphicPlane(dpy));
}
void SurfaceFlinger::bootFinished()
{
const nsecs_t now = systemTime();
@ -217,7 +204,7 @@ static inline uint16_t pack565(int r, int g, int b) {
status_t SurfaceFlinger::readyToRun()
{
ALOGI( "SurfaceFlinger's main thread ready to run. "
ALOGI( "SurfaceFlinger's main thread ready to run. "
"Initializing graphics H/W...");
// we only support one display currently
@ -225,9 +212,9 @@ status_t SurfaceFlinger::readyToRun()
{
// initialize the main display
GraphicPlane& plane(graphicPlane(dpy));
// TODO: initialize all displays
DisplayHardware* const hw = new DisplayHardware(this, dpy);
plane.setDisplayHardware(hw);
mDisplayHardwares[0] = hw;
}
// create the shared control-block
@ -244,8 +231,7 @@ status_t SurfaceFlinger::readyToRun()
// (other display should be initialized in the same manner, but
// asynchronously, as they could come and go. None of this is supported
// yet).
const GraphicPlane& plane(graphicPlane(dpy));
const DisplayHardware& hw = plane.displayHardware();
const DisplayHardware& hw(getDefaultDisplayHardware());
const uint32_t w = hw.getWidth();
const uint32_t h = hw.getHeight();
const uint32_t f = hw.getFormat();
@ -255,8 +241,8 @@ status_t SurfaceFlinger::readyToRun()
mServerCblk->connected |= 1<<dpy;
display_cblk_t* dcblk = mServerCblk->displays + dpy;
memset(dcblk, 0, sizeof(display_cblk_t));
dcblk->w = plane.getWidth();
dcblk->h = plane.getHeight();
dcblk->w = w; // XXX: plane.getWidth();
dcblk->h = h; // XXX: plane.getHeight();
dcblk->format = f;
dcblk->orientation = ISurfaceComposer::eOrientationDefault;
dcblk->xdpi = hw.getDpiX();
@ -373,7 +359,7 @@ sp<IDisplayEventConnection> SurfaceFlinger::createDisplayEventConnection() {
}
void SurfaceFlinger::connectDisplay(const sp<ISurfaceTexture> display) {
const DisplayHardware& hw(graphicPlane(0).displayHardware());
const DisplayHardware& hw(getDefaultDisplayHardware());
EGLSurface result = EGL_NO_SURFACE;
EGLSurface old_surface = EGL_NO_SURFACE;
sp<SurfaceTextureClient> stc;
@ -469,7 +455,8 @@ void SurfaceFlinger::onMessageReceived(int32_t what)
handleRefresh();
const DisplayHardware& hw(graphicPlane(0).displayHardware());
// TODO: iterate through all displays
const DisplayHardware& hw(getDisplayHardware(0));
// if (mDirtyRegion.isEmpty()) {
// return;
@ -477,12 +464,12 @@ void SurfaceFlinger::onMessageReceived(int32_t what)
if (CC_UNLIKELY(mHwWorkListDirty)) {
// build the h/w work list
handleWorkList();
handleWorkList(hw);
}
if (CC_LIKELY(hw.canDraw())) {
// repaint the framebuffer (if needed)
handleRepaint();
handleRepaint(hw);
// inform the h/w that we're done compositing
hw.compositionComplete();
postFramebuffer();
@ -513,7 +500,7 @@ void SurfaceFlinger::onMessageReceived(int32_t what)
const size_t count = layers.size();
for (size_t i=0 ; i<count ; ++i) {
const sp<LayerBase>& layer(layers[i]);
layer->drawForSreenShot();
layer->drawForSreenShot(hw);
}
success = eglSwapBuffers(eglGetCurrentDisplay(), externalDisplaySurface);
@ -540,13 +527,13 @@ void SurfaceFlinger::postFramebuffer()
// in that case, we need to flip anyways to not risk a deadlock with
// h/w composer.
const DisplayHardware& hw(graphicPlane(0).displayHardware());
const DisplayHardware& hw(getDefaultDisplayHardware());
const nsecs_t now = systemTime();
mDebugInSwapBuffers = now;
hw.flip(mSwapRegion);
size_t numLayers = mVisibleLayersSortedByZ.size();
HWComposer& hwc(graphicPlane(0).displayHardware().getHwComposer());
HWComposer& hwc(hw.getHwComposer());
if (hwc.initCheck() == NO_ERROR) {
HWComposer::LayerListIterator cur = hwc.begin();
const HWComposer::LayerListIterator end = hwc.end();
@ -620,19 +607,18 @@ void SurfaceFlinger::handleTransactionLocked(uint32_t transactionFlags)
// the orientation has changed, recompute all visible regions
// and invalidate everything.
const int dpy = 0;
const int dpy = 0; // TODO: should be a parameter
DisplayHardware& hw(const_cast<DisplayHardware&>(getDisplayHardware(dpy)));
const int orientation = mCurrentState.orientation;
// Currently unused: const uint32_t flags = mCurrentState.orientationFlags;
GraphicPlane& plane(graphicPlane(dpy));
plane.setOrientation(orientation);
hw.setOrientation(orientation);
// update the shared control block
const DisplayHardware& hw(plane.displayHardware());
volatile display_cblk_t* dcblk = mServerCblk->displays + dpy;
dcblk->orientation = orientation;
dcblk->w = plane.getWidth();
dcblk->h = plane.getHeight();
dcblk->w = hw.getUserWidth();
dcblk->h = hw.getUserHeight();
// FIXME: mVisibleRegionsDirty & mDirtyRegion should this be per DisplayHardware?
mVisibleRegionsDirty = true;
mDirtyRegion.set(hw.bounds());
}
@ -667,9 +653,8 @@ void SurfaceFlinger::computeVisibleRegions(
{
ATRACE_CALL();
const GraphicPlane& plane(graphicPlane(0));
const Transform& planeTransform(plane.transform());
const DisplayHardware& hw(plane.displayHardware());
const DisplayHardware& hw(getDefaultDisplayHardware()); // FIXME: we shouldn't rely on DisplayHardware here
const Transform& planeTransform(hw.getTransform());
const Region screenRegion(hw.bounds());
Region aboveOpaqueLayers;
@ -681,7 +666,7 @@ void SurfaceFlinger::computeVisibleRegions(
size_t i = currentLayers.size();
while (i--) {
const sp<LayerBase>& layer = currentLayers[i];
layer->validateVisibility(planeTransform);
layer->validateVisibility(planeTransform, hw);
// start with the whole surface at its current location
const Layer::State& s(layer->drawingState());
@ -808,7 +793,7 @@ void SurfaceFlinger::commitTransaction()
void SurfaceFlinger::handlePageFlip()
{
ATRACE_CALL();
const DisplayHardware& hw = graphicPlane(0).displayHardware();
const DisplayHardware& hw(getDefaultDisplayHardware()); // FIXME: it's a problem we need DisplayHardware here
const Region screenRegion(hw.bounds());
const LayerVector& currentLayers(mDrawingState.layersSortedByZ);
@ -859,8 +844,8 @@ bool SurfaceFlinger::lockPageFlip(const LayerVector& currentLayers)
void SurfaceFlinger::unlockPageFlip(const LayerVector& currentLayers)
{
const GraphicPlane& plane(graphicPlane(0));
const Transform& planeTransform(plane.transform());
const DisplayHardware& hw(getDefaultDisplayHardware()); // FIXME: it's a problem we need DisplayHardware here
const Transform& planeTransform(hw.getTransform());
const size_t count = currentLayers.size();
sp<LayerBase> const* layers = currentLayers.array();
for (size_t i=0 ; i<count ; i++) {
@ -886,10 +871,10 @@ void SurfaceFlinger::handleRefresh()
}
void SurfaceFlinger::handleWorkList()
void SurfaceFlinger::handleWorkList(const DisplayHardware& hw)
{
mHwWorkListDirty = false;
HWComposer& hwc(graphicPlane(0).displayHardware().getHwComposer());
HWComposer& hwc(hw.getHwComposer());
if (hwc.initCheck() == NO_ERROR) {
const Vector< sp<LayerBase> >& currentLayers(mVisibleLayersSortedByZ);
const size_t count = currentLayers.size();
@ -906,7 +891,7 @@ void SurfaceFlinger::handleWorkList()
}
}
void SurfaceFlinger::handleRepaint()
void SurfaceFlinger::handleRepaint(const DisplayHardware& hw)
{
ATRACE_CALL();
@ -914,11 +899,10 @@ void SurfaceFlinger::handleRepaint()
mSwapRegion.orSelf(mDirtyRegion);
if (CC_UNLIKELY(mDebugRegion)) {
debugFlashRegions();
debugFlashRegions(hw);
}
// set the frame buffer
const DisplayHardware& hw(graphicPlane(0).displayHardware());
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
@ -942,19 +926,17 @@ void SurfaceFlinger::handleRepaint()
}
}
setupHardwareComposer();
composeSurfaces(mDirtyRegion);
setupHardwareComposer(hw);
composeSurfaces(hw, mDirtyRegion);
// update the swap region and clear the dirty region
mSwapRegion.orSelf(mDirtyRegion);
mDirtyRegion.clear();
}
void SurfaceFlinger::setupHardwareComposer()
void SurfaceFlinger::setupHardwareComposer(const DisplayHardware& hw)
{
const DisplayHardware& hw(graphicPlane(0).displayHardware());
HWComposer& hwc(hw.getHwComposer());
HWComposer::LayerListIterator cur = hwc.begin();
const HWComposer::LayerListIterator end = hwc.end();
if (cur == end) {
@ -985,9 +967,8 @@ void SurfaceFlinger::setupHardwareComposer()
ALOGE_IF(err, "HWComposer::prepare failed (%s)", strerror(-err));
}
void SurfaceFlinger::composeSurfaces(const Region& dirty)
void SurfaceFlinger::composeSurfaces(const DisplayHardware& hw, const Region& dirty)
{
const DisplayHardware& hw(graphicPlane(0).displayHardware());
HWComposer& hwc(hw.getHwComposer());
HWComposer::LayerListIterator cur = hwc.begin();
const HWComposer::LayerListIterator end = hwc.end();
@ -1027,20 +1008,19 @@ void SurfaceFlinger::composeSurfaces(const Region& dirty)
&& layer->isOpaque()) {
// never clear the very first layer since we're
// guaranteed the FB is already cleared
layer->clearWithOpenGL(clip);
layer->clearWithOpenGL(hw, clip);
}
continue;
}
// render the layer
layer->draw(clip);
layer->draw(hw, clip);
}
}
}
}
void SurfaceFlinger::debugFlashRegions()
void SurfaceFlinger::debugFlashRegions(const DisplayHardware& hw)
{
const DisplayHardware& hw(graphicPlane(0).displayHardware());
const uint32_t flags = hw.getFlags();
const int32_t height = hw.getHeight();
if (mSwapRegion.isEmpty()) {
@ -1050,7 +1030,7 @@ void SurfaceFlinger::debugFlashRegions()
if (!(flags & DisplayHardware::SWAP_RECTANGLE)) {
const Region repaint((flags & DisplayHardware::PARTIAL_UPDATES) ?
mDirtyRegion.bounds() : hw.bounds());
composeSurfaces(repaint);
composeSurfaces(hw, repaint);
}
glDisable(GL_TEXTURE_EXTERNAL_OES);
@ -1460,7 +1440,7 @@ uint32_t SurfaceFlinger::setClientStateLocked(
void SurfaceFlinger::onScreenAcquired() {
ALOGD("Screen about to return, flinger = %p", this);
const DisplayHardware& hw(graphicPlane(0).displayHardware());
const DisplayHardware& hw(getDefaultDisplayHardware()); // XXX: this should be per DisplayHardware
hw.acquireScreen();
mEventThread->onScreenAcquired();
// this is a temporary work-around, eventually this should be called
@ -1472,7 +1452,7 @@ void SurfaceFlinger::onScreenAcquired() {
void SurfaceFlinger::onScreenReleased() {
ALOGD("About to give-up screen, flinger = %p", this);
const DisplayHardware& hw(graphicPlane(0).displayHardware());
const DisplayHardware& hw(getDefaultDisplayHardware()); // XXX: this should be per DisplayHardware
if (hw.isScreenAcquired()) {
mEventThread->onScreenReleased();
hw.releaseScreen();
@ -1671,6 +1651,7 @@ void SurfaceFlinger::dumpAllLocked(
snprintf(buffer, SIZE, "SurfaceFlinger global state:\n");
result.append(buffer);
const DisplayHardware& hw(getDefaultDisplayHardware());
const GLExtensions& extensions(GLExtensions::getInstance());
snprintf(buffer, SIZE, "GLES: %s, %s, %s\n",
extensions.getVendor(),
@ -1679,7 +1660,7 @@ void SurfaceFlinger::dumpAllLocked(
result.append(buffer);
snprintf(buffer, SIZE, "EGL : %s\n",
eglQueryString(graphicPlane(0).getEGLDisplay(),
eglQueryString(hw.getEGLDisplay(),
EGL_VERSION_HW_ANDROID));
result.append(buffer);
@ -1687,7 +1668,6 @@ void SurfaceFlinger::dumpAllLocked(
result.append(buffer);
mWormholeRegion.dump(result, "WormholeRegion");
const DisplayHardware& hw(graphicPlane(0).displayHardware());
snprintf(buffer, SIZE,
" orientation=%d, canDraw=%d\n",
mCurrentState.orientation, hw.canDraw());
@ -1838,7 +1818,7 @@ status_t SurfaceFlinger::onTransact(
return NO_ERROR;
case 1013: {
Mutex::Autolock _l(mStateLock);
const DisplayHardware& hw(graphicPlane(0).displayHardware());
const DisplayHardware& hw(getDefaultDisplayHardware());
reply->writeInt32(hw.getPageFlipCount());
}
return NO_ERROR;
@ -1848,7 +1828,7 @@ status_t SurfaceFlinger::onTransact(
}
void SurfaceFlinger::repaintEverything() {
const DisplayHardware& hw(graphicPlane(0).displayHardware());
const DisplayHardware& hw(getDefaultDisplayHardware()); // FIXME: this cannot be bound the default display
const Rect bounds(hw.getBounds());
setInvalidateRegion(Region(bounds));
signalTransaction();
@ -1884,7 +1864,7 @@ status_t SurfaceFlinger::renderScreenToTextureLocked(DisplayID dpy,
return INVALID_OPERATION;
// get screen geometry
const DisplayHardware& hw(graphicPlane(dpy).displayHardware());
const DisplayHardware& hw(getDisplayHardware(dpy));
const uint32_t hw_w = hw.getWidth();
const uint32_t hw_h = hw.getHeight();
GLfloat u = 1;
@ -1926,7 +1906,7 @@ status_t SurfaceFlinger::renderScreenToTextureLocked(DisplayID dpy,
const size_t count = layers.size();
for (size_t i=0 ; i<count ; ++i) {
const sp<LayerBase>& layer(layers[i]);
layer->drawForSreenShot();
layer->drawForSreenShot(hw);
}
hw.compositionComplete();
@ -1975,7 +1955,7 @@ public:
status_t SurfaceFlinger::electronBeamOffAnimationImplLocked()
{
// get screen geometry
const DisplayHardware& hw(graphicPlane(0).displayHardware());
const DisplayHardware& hw(getDefaultDisplayHardware());
const uint32_t hw_w = hw.getWidth();
const uint32_t hw_h = hw.getHeight();
const Region screenBounds(hw.getBounds());
@ -2157,7 +2137,7 @@ status_t SurfaceFlinger::electronBeamOnAnimationImplLocked()
// get screen geometry
const DisplayHardware& hw(graphicPlane(0).displayHardware());
const DisplayHardware& hw(getDefaultDisplayHardware());
const uint32_t hw_w = hw.getWidth();
const uint32_t hw_h = hw.getHeight();
const Region screenBounds(hw.bounds());
@ -2306,7 +2286,7 @@ status_t SurfaceFlinger::turnElectronBeamOffImplLocked(int32_t mode)
{
ATRACE_CALL();
DisplayHardware& hw(graphicPlane(0).editDisplayHardware());
DisplayHardware& hw(const_cast<DisplayHardware&>(getDefaultDisplayHardware()));
if (!hw.canDraw()) {
// we're already off
return NO_ERROR;
@ -2366,7 +2346,7 @@ status_t SurfaceFlinger::turnElectronBeamOff(int32_t mode)
status_t SurfaceFlinger::turnElectronBeamOnImplLocked(int32_t mode)
{
DisplayHardware& hw(graphicPlane(0).editDisplayHardware());
DisplayHardware& hw(const_cast<DisplayHardware&>(getDefaultDisplayHardware()));
if (hw.canDraw()) {
// we're already on
return NO_ERROR;
@ -2426,7 +2406,7 @@ status_t SurfaceFlinger::captureScreenImplLocked(DisplayID dpy,
return INVALID_OPERATION;
// get screen geometry
const DisplayHardware& hw(graphicPlane(dpy).displayHardware());
const DisplayHardware& hw(getDisplayHardware(dpy));
const uint32_t hw_w = hw.getWidth();
const uint32_t hw_h = hw.getHeight();
@ -2478,7 +2458,7 @@ status_t SurfaceFlinger::captureScreenImplLocked(DisplayID dpy,
if (!(flags & ISurfaceComposer::eLayerHidden)) {
const uint32_t z = layer->drawingState().z;
if (z >= minLayerZ && z <= maxLayerZ) {
layer->drawForSreenShot();
layer->drawForSreenShot(hw);
}
}
}
@ -2626,126 +2606,4 @@ sp<GraphicBuffer> GraphicBufferAlloc::createGraphicBuffer(uint32_t w, uint32_t h
// ---------------------------------------------------------------------------
GraphicPlane::GraphicPlane()
: mHw(0)
{
}
GraphicPlane::~GraphicPlane() {
delete mHw;
}
bool GraphicPlane::initialized() const {
return mHw ? true : false;
}
int GraphicPlane::getWidth() const {
return mWidth;
}
int GraphicPlane::getHeight() const {
return mHeight;
}
void GraphicPlane::setDisplayHardware(DisplayHardware *hw)
{
mHw = hw;
// initialize the display orientation transform.
// it's a constant that should come from the display driver.
int displayOrientation = ISurfaceComposer::eOrientationDefault;
char property[PROPERTY_VALUE_MAX];
if (property_get("ro.sf.hwrotation", property, NULL) > 0) {
//displayOrientation
switch (atoi(property)) {
case 90:
displayOrientation = ISurfaceComposer::eOrientation90;
break;
case 270:
displayOrientation = ISurfaceComposer::eOrientation270;
break;
}
}
const float w = hw->getWidth();
const float h = hw->getHeight();
GraphicPlane::orientationToTransfrom(displayOrientation, w, h,
&mDisplayTransform);
if (displayOrientation & ISurfaceComposer::eOrientationSwapMask) {
mDisplayWidth = h;
mDisplayHeight = w;
} else {
mDisplayWidth = w;
mDisplayHeight = h;
}
setOrientation(ISurfaceComposer::eOrientationDefault);
}
status_t GraphicPlane::orientationToTransfrom(
int orientation, int w, int h, Transform* tr)
{
uint32_t flags = 0;
switch (orientation) {
case ISurfaceComposer::eOrientationDefault:
flags = Transform::ROT_0;
break;
case ISurfaceComposer::eOrientation90:
flags = Transform::ROT_90;
break;
case ISurfaceComposer::eOrientation180:
flags = Transform::ROT_180;
break;
case ISurfaceComposer::eOrientation270:
flags = Transform::ROT_270;
break;
default:
return BAD_VALUE;
}
tr->set(flags, w, h);
return NO_ERROR;
}
status_t GraphicPlane::setOrientation(int orientation)
{
// If the rotation can be handled in hardware, this is where
// the magic should happen.
const DisplayHardware& hw(displayHardware());
const float w = mDisplayWidth;
const float h = mDisplayHeight;
mWidth = int(w);
mHeight = int(h);
Transform orientationTransform;
GraphicPlane::orientationToTransfrom(orientation, w, h,
&orientationTransform);
if (orientation & ISurfaceComposer::eOrientationSwapMask) {
mWidth = int(h);
mHeight = int(w);
}
mOrientation = orientation;
mGlobalTransform = mDisplayTransform * orientationTransform;
return NO_ERROR;
}
const DisplayHardware& GraphicPlane::displayHardware() const {
return *mHw;
}
DisplayHardware& GraphicPlane::editDisplayHardware() {
return *mHw;
}
const Transform& GraphicPlane::transform() const {
return mGlobalTransform;
}
EGLDisplay GraphicPlane::getEGLDisplay() const {
return mHw->getEGLDisplay();
}
// ---------------------------------------------------------------------------
}; // namespace android

View File

@ -68,44 +68,6 @@ public:
// ---------------------------------------------------------------------------
class GraphicPlane
{
public:
static status_t orientationToTransfrom(int orientation, int w, int h,
Transform* tr);
GraphicPlane();
~GraphicPlane();
bool initialized() const;
void setDisplayHardware(DisplayHardware *);
status_t setOrientation(int orientation);
int getOrientation() const { return mOrientation; }
int getWidth() const;
int getHeight() const;
const DisplayHardware& displayHardware() const;
DisplayHardware& editDisplayHardware();
const Transform& transform() const;
EGLDisplay getEGLDisplay() const;
private:
GraphicPlane(const GraphicPlane&);
GraphicPlane operator = (const GraphicPlane&);
DisplayHardware* mHw;
Transform mGlobalTransform;
Transform mDisplayTransform;
int mOrientation;
float mDisplayWidth;
float mDisplayHeight;
int mWidth;
int mHeight;
};
// ---------------------------------------------------------------------------
enum {
eTransactionNeeded = 0x01,
eTraversalNeeded = 0x02
@ -260,8 +222,13 @@ private:
virtual void onFirstRef();
public: // hack to work around gcc 4.0.3 bug
const GraphicPlane& graphicPlane(int dpy) const;
GraphicPlane& graphicPlane(int dpy);
const DisplayHardware& getDisplayHardware(DisplayID dpy) const {
return *mDisplayHardwares[dpy];
}
const DisplayHardware& getDefaultDisplayHardware() const {
return getDisplayHardware(0);
}
void signalTransaction();
void signalLayerUpdate();
@ -282,11 +249,11 @@ private:
bool lockPageFlip(const LayerVector& currentLayers);
void unlockPageFlip(const LayerVector& currentLayers);
void handleRefresh();
void handleWorkList();
void handleRepaint();
void handleWorkList(const DisplayHardware& hw);
void handleRepaint(const DisplayHardware& hw);
void postFramebuffer();
void setupHardwareComposer();
void composeSurfaces(const Region& dirty);
void setupHardwareComposer(const DisplayHardware& hw);
void composeSurfaces(const DisplayHardware& hw, const Region& dirty);
void setInvalidateRegion(const Region& reg);
@ -315,7 +282,7 @@ private:
status_t electronBeamOffAnimationImplLocked();
status_t electronBeamOnAnimationImplLocked();
void debugFlashRegions();
void debugFlashRegions(const DisplayHardware& hw);
void drawWormhole() const;
void startBootAnim();
@ -340,7 +307,7 @@ private:
Vector< sp<LayerBase> > mLayersPendingRemoval;
// protected by mStateLock (but we could use another lock)
GraphicPlane mGraphicPlanes[1];
DisplayHardware* mDisplayHardwares[1];
bool mLayersRemoved;
DefaultKeyedVector< wp<IBinder>, wp<Layer> > mLayerMap;