get rid of the shared-memory control block

Change-Id: If814060aca1d2ff2619d4adcd57296983d207f7f
This commit is contained in:
Mathias Agopian 2012-07-25 18:56:13 -07:00
parent 028508cad5
commit c666cae2d5
12 changed files with 69 additions and 210 deletions

View File

@ -35,6 +35,7 @@ namespace android {
class ComposerState;
class DisplayState;
class DisplayInfo;
class IDisplayEventConnection;
class IMemoryHeap;
@ -102,9 +103,6 @@ public:
*/
virtual sp<IGraphicBufferAlloc> createGraphicBufferAlloc() = 0;
/* retrieve the control block */
virtual sp<IMemoryHeap> getCblk() const = 0;
/* open/close transactions. requires ACCESS_SURFACE_FLINGER permission */
virtual void setTransactionState(
const Vector<ComposerState>& state,
@ -145,6 +143,10 @@ public:
/* triggers screen on and waits for it to complete */
virtual void unblank() = 0;
/* returns information about a physical screen. This is intended to be
* used by low-level native tests */
virtual status_t getDisplayInfo(DisplayID dpy, DisplayInfo* info) = 0;
/* connects to an external display */
virtual void connectDisplay(const sp<ISurfaceTexture> display) = 0;
};
@ -160,7 +162,7 @@ public:
BOOT_FINISHED = IBinder::FIRST_CALL_TRANSACTION,
CREATE_CONNECTION,
CREATE_GRAPHIC_BUFFER_ALLOC,
GET_CBLK,
GET_DISPLAY_INFO,
SET_TRANSACTION_STATE,
SET_ORIENTATION,
CAPTURE_SCREEN,

View File

@ -97,14 +97,8 @@ public:
//! Set the orientation of the given display
static int setOrientation(DisplayID dpy, int orientation, uint32_t flags);
// Query the number of displays
static ssize_t getNumberOfDisplays();
// Get information about a display
static status_t getDisplayInfo(DisplayID dpy, DisplayInfo* info);
static ssize_t getDisplayWidth(DisplayID dpy);
static ssize_t getDisplayHeight(DisplayID dpy);
static ssize_t getDisplayOrientation(DisplayID dpy);
status_t linkToComposerDeath(const sp<IBinder::DeathRecipient>& recipient,
void* cookie = NULL, uint32_t flags = 0);

View File

@ -30,7 +30,6 @@ namespace android {
class IMemoryHeap;
class ISurfaceComposer;
class surface_flinger_cblk_t;
// ---------------------------------------------------------------------------
@ -38,13 +37,10 @@ class ComposerService : public Singleton<ComposerService>
{
// these are constants
sp<ISurfaceComposer> mComposerService;
sp<IMemoryHeap> mServerCblkMemory;
surface_flinger_cblk_t volatile* mServerCblk;
ComposerService();
friend class Singleton<ComposerService>;
public:
static sp<ISurfaceComposer> getComposerService();
static surface_flinger_cblk_t const volatile * getControlBlock();
};
// ---------------------------------------------------------------------------

View File

@ -1,59 +0,0 @@
/*
* 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.
*/
#ifndef ANDROID_SF_SHARED_BUFFER_STACK_H
#define ANDROID_SF_SHARED_BUFFER_STACK_H
#include <stdint.h>
#include <sys/types.h>
#include <utils/Debug.h>
namespace android {
// ---------------------------------------------------------------------------
#define NUM_DISPLAY_MAX 4
struct display_cblk_t
{
uint16_t w;
uint16_t h;
uint8_t format;
uint8_t orientation;
uint8_t reserved[2];
float fps;
float density;
float xdpi;
float ydpi;
uint32_t pad[2];
};
struct surface_flinger_cblk_t // 4KB max
{
uint8_t connected;
uint8_t reserved[3];
uint32_t pad[7];
display_cblk_t displays[NUM_DISPLAY_MAX];
};
// ---------------------------------------------------------------------------
COMPILE_TIME_ASSERT(sizeof(surface_flinger_cblk_t) <= 4096)
// ---------------------------------------------------------------------------
}; // namespace android
#endif /* ANDROID_SF_SHARED_BUFFER_STACK_H */

View File

@ -14,7 +14,6 @@
* limitations under the License.
*/
#ifndef ANDROID_UI_DISPLAY_INFO_H
#define ANDROID_UI_DISPLAY_INFO_H
@ -26,15 +25,16 @@
namespace android {
struct DisplayInfo {
uint32_t w;
uint32_t h;
PixelFormatInfo pixelFormatInfo;
uint8_t orientation;
uint8_t reserved[3];
float fps;
float density;
float xdpi;
float ydpi;
uint32_t w;
uint32_t h;
float xdpi;
float ydpi;
float fps;
float density;
uint8_t orientation;
uint8_t reserved[3];
// TODO: this needs to go away (currently needed only by webkit)
PixelFormatInfo pixelFormatInfo;
};
/* Display orientations as defined in Surface.java and ISurfaceComposer.h. */
@ -45,8 +45,6 @@ enum {
DISPLAY_ORIENTATION_270 = 3
};
}; // namespace android
#endif // ANDROID_COMPOSER_DISPLAY_INFO_H

View File

@ -68,14 +68,6 @@ public:
return interface_cast<IGraphicBufferAlloc>(reply.readStrongBinder());
}
virtual sp<IMemoryHeap> getCblk() const
{
Parcel data, reply;
data.writeInterfaceToken(ISurfaceComposer::getInterfaceDescriptor());
remote()->transact(BnSurfaceComposer::GET_CBLK, data, &reply);
return interface_cast<IMemoryHeap>(reply.readStrongBinder());
}
virtual void setTransactionState(
const Vector<ComposerState>& state,
const Vector<DisplayState>& displays,
@ -219,6 +211,17 @@ public:
remote()->transact(BnSurfaceComposer::UNBLANK, data, &reply);
}
virtual status_t getDisplayInfo(DisplayID dpy, DisplayInfo* info)
{
Parcel data, reply;
data.writeInterfaceToken(ISurfaceComposer::getInterfaceDescriptor());
data.writeInt32(dpy);
remote()->transact(BnSurfaceComposer::GET_DISPLAY_INFO, data, &reply);
memcpy(info, reply.readInplace(sizeof(DisplayInfo)), sizeof(DisplayInfo));
return reply.readInt32();
}
virtual void connectDisplay(const sp<ISurfaceTexture> display) {
Parcel data, reply;
data.writeInterfaceToken(ISurfaceComposer::getInterfaceDescriptor());
@ -270,11 +273,6 @@ status_t BnSurfaceComposer::onTransact(
CHECK_INTERFACE(ISurfaceComposer, data, reply);
bootFinished();
} break;
case GET_CBLK: {
CHECK_INTERFACE(ISurfaceComposer, data, reply);
sp<IBinder> b = getCblk()->asBinder();
reply->writeStrongBinder(b);
} break;
case CAPTURE_SCREEN: {
CHECK_INTERFACE(ISurfaceComposer, data, reply);
DisplayID dpy = data.readInt32();
@ -326,6 +324,14 @@ status_t BnSurfaceComposer::onTransact(
CHECK_INTERFACE(ISurfaceComposer, data, reply);
unblank();
} break;
case GET_DISPLAY_INFO: {
CHECK_INTERFACE(ISurfaceComposer, data, reply);
DisplayInfo info;
DisplayID dpy = data.readInt32();
status_t result = getDisplayInfo(dpy, &info);
memcpy(reply->writeInplace(sizeof(DisplayInfo)), &info, sizeof(DisplayInfo));
reply->writeInt32(result);
} break;
case CONNECT_DISPLAY: {
CHECK_INTERFACE(ISurfaceComposer, data, reply);
sp<ISurfaceTexture> surfaceTexture =

View File

@ -38,7 +38,6 @@
#include <private/gui/ComposerService.h>
#include <private/gui/LayerState.h>
#include <private/gui/SharedBufferStack.h>
namespace android {
// ---------------------------------------------------------------------------
@ -51,27 +50,16 @@ ComposerService::ComposerService()
while (getService(name, &mComposerService) != NO_ERROR) {
usleep(250000);
}
mServerCblkMemory = mComposerService->getCblk();
mServerCblk = static_cast<surface_flinger_cblk_t volatile *>(
mServerCblkMemory->getBase());
}
sp<ISurfaceComposer> ComposerService::getComposerService() {
return ComposerService::getInstance().mComposerService;
}
surface_flinger_cblk_t const volatile * ComposerService::getControlBlock() {
return ComposerService::getInstance().mServerCblk;
}
static inline sp<ISurfaceComposer> getComposerService() {
return ComposerService::getComposerService();
}
static inline surface_flinger_cblk_t const volatile * get_cblk() {
return ComposerService::getControlBlock();
}
// ---------------------------------------------------------------------------
// NOTE: this is NOT a member function (it's a friend defined with its
@ -476,59 +464,7 @@ status_t SurfaceComposerClient::setOrientation(DisplayID dpy,
status_t SurfaceComposerClient::getDisplayInfo(
DisplayID dpy, DisplayInfo* info)
{
if (uint32_t(dpy)>=NUM_DISPLAY_MAX)
return BAD_VALUE;
volatile surface_flinger_cblk_t const * cblk = get_cblk();
volatile display_cblk_t const * dcblk = cblk->displays + dpy;
info->w = dcblk->w;
info->h = dcblk->h;
info->orientation = dcblk->orientation;
info->xdpi = dcblk->xdpi;
info->ydpi = dcblk->ydpi;
info->fps = dcblk->fps;
info->density = dcblk->density;
return getPixelFormatInfo(dcblk->format, &(info->pixelFormatInfo));
}
ssize_t SurfaceComposerClient::getDisplayWidth(DisplayID dpy)
{
if (uint32_t(dpy)>=NUM_DISPLAY_MAX)
return BAD_VALUE;
volatile surface_flinger_cblk_t const * cblk = get_cblk();
volatile display_cblk_t const * dcblk = cblk->displays + dpy;
return dcblk->w;
}
ssize_t SurfaceComposerClient::getDisplayHeight(DisplayID dpy)
{
if (uint32_t(dpy)>=NUM_DISPLAY_MAX)
return BAD_VALUE;
volatile surface_flinger_cblk_t const * cblk = get_cblk();
volatile display_cblk_t const * dcblk = cblk->displays + dpy;
return dcblk->h;
}
ssize_t SurfaceComposerClient::getDisplayOrientation(DisplayID dpy)
{
if (uint32_t(dpy)>=NUM_DISPLAY_MAX)
return BAD_VALUE;
volatile surface_flinger_cblk_t const * cblk = get_cblk();
volatile display_cblk_t const * dcblk = cblk->displays + dpy;
return dcblk->orientation;
}
ssize_t SurfaceComposerClient::getNumberOfDisplays()
{
volatile surface_flinger_cblk_t const * cblk = get_cblk();
uint32_t connected = cblk->connected;
int n = 0;
while (connected) {
if (connected&1) n++;
connected >>= 1;
}
return n;
return getComposerService()->getDisplayInfo(dpy, info);
}
// ----------------------------------------------------------------------------

View File

@ -24,6 +24,7 @@
#include <utils/RefBase.h>
#include <utils/Log.h>
#include <ui/DisplayInfo.h>
#include <ui/PixelFormat.h>
#include <GLES/gl.h>
@ -31,7 +32,6 @@
#include <EGL/eglext.h>
#include <hardware/gralloc.h>
#include <private/gui/SharedBufferStack.h>
#include "DisplayHardware/FramebufferSurface.h"
#include "DisplayHardware/DisplayHardwareBase.h"
@ -148,6 +148,19 @@ EGLSurface DisplayHardware::getEGLSurface() const {
return mSurface;
}
status_t DisplayHardware::getInfo(DisplayInfo* info) const {
info->w = getWidth();
info->h = getHeight();
info->xdpi = getDpiX();
info->ydpi = getDpiY();
info->fps = getRefreshRate();
info->density = getDensity();
info->orientation = getOrientation();
// TODO: this needs to go away (currently needed only by webkit)
getPixelFormatInfo(getFormat(), &info->pixelFormatInfo);
return NO_ERROR;
}
void DisplayHardware::init(EGLConfig config)
{
ANativeWindow* const window = mNativeWindow.get();
@ -226,17 +239,6 @@ void DisplayHardware::init(EGLConfig config)
mFormat = format;
mPageFlipCount = 0;
// initialize the shared control block
surface_flinger_cblk_t* const scblk = mFlinger->getControlBlock();
scblk->connected |= 1 << mDisplayId;
display_cblk_t* dcblk = &scblk->displays[mDisplayId];
memset(dcblk, 0, sizeof(display_cblk_t));
dcblk->format = format;
dcblk->xdpi = mDpiX;
dcblk->ydpi = mDpiY;
dcblk->fps = mRefreshRate;
dcblk->density = mDensity;
// initialize the display orientation transform.
DisplayHardware::setOrientation(ISurfaceComposer::eOrientationDefault);
}
@ -365,13 +367,5 @@ status_t DisplayHardware::setOrientation(int orientation) {
h = tmp;
}
mOrientation = orientation;
// update the shared control block
surface_flinger_cblk_t* const scblk = mFlinger->getControlBlock();
volatile display_cblk_t* dcblk = &scblk->displays[mDisplayId];
dcblk->orientation = orientation;
dcblk->w = w;
dcblk->h = h;
return NO_ERROR;
}

View File

@ -36,6 +36,7 @@
namespace android {
class DisplayInfo;
class FramebufferSurface;
class LayerBase;
class SurfaceFlinger;
@ -74,6 +75,7 @@ public:
uint32_t getFlags() const;
nsecs_t getRefreshPeriod() const;
nsecs_t getRefreshTimestamp() const;
status_t getInfo(DisplayInfo* info) const;
EGLSurface getEGLSurface() const;

View File

@ -32,6 +32,8 @@
#include <binder/MemoryHeapBase.h>
#include <binder/PermissionCache.h>
#include <ui/DisplayInfo.h>
#include <gui/IDisplayEventConnection.h>
#include <gui/BitTube.h>
#include <gui/SurfaceTextureClient.h>
@ -45,7 +47,6 @@
#include <utils/Trace.h>
#include <private/android_filesystem_config.h>
#include <private/gui/SharedBufferStack.h>
#include "clz.h"
#include "DdmConnection.h"
@ -153,11 +154,6 @@ void SurfaceFlinger::binderDied(const wp<IBinder>& who)
startBootAnim();
}
sp<IMemoryHeap> SurfaceFlinger::getCblk() const
{
return mServerHeap;
}
sp<ISurfaceComposerClient> SurfaceFlinger::createConnection()
{
sp<ISurfaceComposerClient> bclient;
@ -361,24 +357,11 @@ void SurfaceFlinger::initializeGL(EGLDisplay display, EGLSurface surface) {
ALOGI("GL_MAX_VIEWPORT_DIMS = %d x %d", mMaxViewportDims[0], mMaxViewportDims[1]);
}
surface_flinger_cblk_t* SurfaceFlinger::getControlBlock() const {
return mServerCblk;
}
status_t SurfaceFlinger::readyToRun()
{
ALOGI( "SurfaceFlinger's main thread ready to run. "
"Initializing graphics H/W...");
// create the shared control-block
mServerHeap = new MemoryHeapBase(4096,
MemoryHeapBase::READ_ONLY, "SurfaceFlinger read-only heap");
ALOGE_IF(mServerHeap==0, "can't create shared memory dealer");
mServerCblk = static_cast<surface_flinger_cblk_t*>(mServerHeap->getBase());
ALOGE_IF(mServerCblk==0, "can't get to shared control block's address");
new(mServerCblk) surface_flinger_cblk_t;
// initialize EGL
EGLDisplay display = eglGetDisplay(EGL_DEFAULT_DISPLAY);
eglInitialize(display, NULL, NULL);
@ -485,6 +468,14 @@ bool SurfaceFlinger::authenticateSurfaceTexture(
return false;
}
status_t SurfaceFlinger::getDisplayInfo(DisplayID dpy, DisplayInfo* info) {
if (uint32_t(dpy) >= 2) {
return BAD_INDEX;
}
const DisplayHardware& hw(getDefaultDisplayHardware());
return hw.getInfo(info);
}
// ----------------------------------------------------------------------------
sp<IDisplayEventConnection> SurfaceFlinger::createDisplayEventConnection() {

View File

@ -64,7 +64,6 @@ class LayerBaseClient;
class LayerDim;
class LayerScreenshot;
class SurfaceTextureClient;
struct surface_flinger_cblk_t;
// ---------------------------------------------------------------------------
@ -176,7 +175,6 @@ private:
*/
virtual sp<ISurfaceComposerClient> createConnection();
virtual sp<IGraphicBufferAlloc> createGraphicBufferAlloc();
virtual sp<IMemoryHeap> getCblk() const;
virtual void bootFinished();
virtual void setTransactionState(const Vector<ComposerState>& state,
const Vector<DisplayState>& displays, uint32_t flags);
@ -193,6 +191,7 @@ private:
virtual void blank();
// called when screen is turning back on
virtual void unblank();
virtual status_t getDisplayInfo(DisplayID dpy, DisplayInfo* info);
virtual void connectDisplay(const sp<ISurfaceTexture> display);
/* ------------------------------------------------------------------------
@ -382,8 +381,6 @@ private:
Region mInvalidateRegion;
// constant members (no synchronization needed for access)
sp<IMemoryHeap> mServerHeap;
surface_flinger_cblk_t* mServerCblk;
HWComposer* mHwc;
GLuint mWormholeTexName;
GLuint mProtectedTexName;
@ -431,8 +428,6 @@ private:
EGLSurface getExternalDisplaySurface() const;
sp<SurfaceTextureClient> mExternalDisplayNativeWindow;
EGLSurface mExternalDisplaySurface;
public:
surface_flinger_cblk_t* getControlBlock() const;
};
// ---------------------------------------------------------------------------

View File

@ -24,6 +24,7 @@
#include <private/gui/ComposerService.h>
#include <utils/String8.h>
#include <ui/DisplayInfo.h>
namespace android {
@ -92,8 +93,11 @@ protected:
mComposerClient = new SurfaceComposerClient;
ASSERT_EQ(NO_ERROR, mComposerClient->initCheck());
ssize_t displayWidth = mComposerClient->getDisplayWidth(0);
ssize_t displayHeight = mComposerClient->getDisplayHeight(0);
DisplayInfo info;
SurfaceComposerClient::getDisplayInfo(0, &info);
ssize_t displayWidth = info.w;
ssize_t displayHeight = info.h;
// Background surface
mBGSurfaceControl = mComposerClient->createSurface(