Use new HWC display type/count constants.

Change-Id: I774d0c68906ac6dc69268f708c30a6b0868b8816
This commit is contained in:
Jesse Hall 2013-08-16 14:28:37 -07:00
parent e048a4374c
commit 9e663de4fe
7 changed files with 48 additions and 50 deletions

View File

@ -38,6 +38,7 @@ namespace android {
class DisplayInfo; class DisplayInfo;
class DisplaySurface; class DisplaySurface;
class IGraphicBufferProducer;
class Layer; class Layer;
class SurfaceFlinger; class SurfaceFlinger;
class HWComposer; class HWComposer;
@ -56,8 +57,8 @@ public:
DISPLAY_ID_INVALID = -1, DISPLAY_ID_INVALID = -1,
DISPLAY_PRIMARY = HWC_DISPLAY_PRIMARY, DISPLAY_PRIMARY = HWC_DISPLAY_PRIMARY,
DISPLAY_EXTERNAL = HWC_DISPLAY_EXTERNAL, DISPLAY_EXTERNAL = HWC_DISPLAY_EXTERNAL,
NUM_DISPLAY_TYPES = HWC_NUM_DISPLAY_TYPES, DISPLAY_VIRTUAL = HWC_DISPLAY_VIRTUAL,
DISPLAY_VIRTUAL = HWC_NUM_DISPLAY_TYPES NUM_BUILTIN_DISPLAY_TYPES = HWC_NUM_PHYSICAL_DISPLAY_TYPES,
}; };
enum { enum {

View File

@ -48,15 +48,8 @@
namespace android { namespace android {
#ifndef HWC_DEVICE_API_VERSION_1_3
#define HWC_DEVICE_API_VERSION_1_3 HARDWARE_DEVICE_API_VERSION_2(1, 3, HWC_HEADER_VERSION)
#endif
#define MIN_HWC_HEADER_VERSION HWC_HEADER_VERSION #define MIN_HWC_HEADER_VERSION HWC_HEADER_VERSION
#define NUM_PHYSICAL_DISPLAYS HWC_NUM_DISPLAY_TYPES
#define VIRTUAL_DISPLAY_ID_BASE HWC_NUM_DISPLAY_TYPES
static uint32_t hwcApiVersion(const hwc_composer_device_1_t* hwc) { static uint32_t hwcApiVersion(const hwc_composer_device_1_t* hwc) {
uint32_t hwcVersion = hwc->common.version; uint32_t hwcVersion = hwc->common.version;
return hwcVersion & HARDWARE_API_VERSION_2_MAJ_MIN_MASK; return hwcVersion & HARDWARE_API_VERSION_2_MAJ_MIN_MASK;
@ -96,7 +89,7 @@ HWComposer::HWComposer(
mEventHandler(handler), mEventHandler(handler),
mVSyncCount(0), mDebugForceFakeVSync(false) mVSyncCount(0), mDebugForceFakeVSync(false)
{ {
for (size_t i =0 ; i<MAX_DISPLAYS ; i++) { for (size_t i =0 ; i<MAX_HWC_DISPLAYS ; i++) {
mLists[i] = 0; mLists[i] = 0;
} }
@ -127,7 +120,7 @@ HWComposer::HWComposer(
} }
// these display IDs are always reserved // these display IDs are always reserved
for (size_t i=0 ; i<NUM_PHYSICAL_DISPLAYS ; i++) { for (size_t i=0 ; i<NUM_BUILTIN_DISPLAYS ; i++) {
mAllocatedDisplayIDs.markBit(i); mAllocatedDisplayIDs.markBit(i);
} }
@ -156,10 +149,10 @@ HWComposer::HWComposer(
// hw composer version // hw composer version
if (hwcHasApiVersion(mHwc, HWC_DEVICE_API_VERSION_1_3)) { if (hwcHasApiVersion(mHwc, HWC_DEVICE_API_VERSION_1_3)) {
// 1.3 adds support for virtual displays // 1.3 adds support for virtual displays
mNumDisplays = MAX_DISPLAYS; mNumDisplays = MAX_HWC_DISPLAYS;
} else if (hwcHasApiVersion(mHwc, HWC_DEVICE_API_VERSION_1_1)) { } else if (hwcHasApiVersion(mHwc, HWC_DEVICE_API_VERSION_1_1)) {
// 1.1 adds support for multiple displays // 1.1 adds support for multiple displays
mNumDisplays = NUM_PHYSICAL_DISPLAYS; mNumDisplays = NUM_BUILTIN_DISPLAYS;
} else { } else {
mNumDisplays = 1; mNumDisplays = 1;
} }
@ -187,7 +180,7 @@ HWComposer::HWComposer(
} }
} else if (mHwc) { } else if (mHwc) {
// here we're guaranteed to have at least HWC 1.1 // here we're guaranteed to have at least HWC 1.1
for (size_t i =0 ; i<NUM_PHYSICAL_DISPLAYS ; i++) { for (size_t i =0 ; i<NUM_BUILTIN_DISPLAYS ; i++) {
queryDisplayProperties(i); queryDisplayProperties(i);
} }
} }
@ -400,7 +393,7 @@ int32_t HWComposer::allocateDisplayId() {
} }
status_t HWComposer::freeDisplayId(int32_t id) { status_t HWComposer::freeDisplayId(int32_t id) {
if (id < NUM_PHYSICAL_DISPLAYS) { if (id < NUM_BUILTIN_DISPLAYS) {
// cannot free the reserved IDs // cannot free the reserved IDs
return BAD_VALUE; return BAD_VALUE;
} }

View File

@ -64,7 +64,9 @@ public:
}; };
enum { enum {
MAX_DISPLAYS = HWC_NUM_DISPLAY_TYPES + 1 NUM_BUILTIN_DISPLAYS = HWC_NUM_PHYSICAL_DISPLAY_TYPES,
MAX_HWC_DISPLAYS = HWC_NUM_DISPLAY_TYPES,
VIRTUAL_DISPLAY_ID_BASE = HWC_DISPLAY_VIRTUAL,
}; };
HWComposer( HWComposer(
@ -75,15 +77,16 @@ public:
status_t initCheck() const; status_t initCheck() const;
// returns a display ID starting at MAX_DISPLAYS, this ID // Returns a display ID starting at VIRTUAL_DISPLAY_ID_BASE, this ID is to
// is to be used with createWorkList (and all other // be used with createWorkList (and all other methods requiring an ID
// methods requiring an ID below). // below).
// IDs below MAX_DISPLAY are pre-defined and therefore are always valid. // IDs below NUM_BUILTIN_DISPLAYS are pre-defined and therefore are
// returns a negative error code if an ID cannot be allocated // always valid.
// Returns -1 if an ID cannot be allocated
int32_t allocateDisplayId(); int32_t allocateDisplayId();
// recycles the given ID and frees the associated worklist. // Recycles the given virtual display ID and frees the associated worklist.
// IDs below MAX_DISPLAYS are not recycled // IDs below NUM_BUILTIN_DISPLAYS are not recycled.
status_t freeDisplayId(int32_t id); status_t freeDisplayId(int32_t id);
@ -333,8 +336,8 @@ private:
struct hwc_composer_device_1* mHwc; struct hwc_composer_device_1* mHwc;
// invariant: mLists[0] != NULL iff mHwc != NULL // invariant: mLists[0] != NULL iff mHwc != NULL
// mLists[i>0] can be NULL. that display is to be ignored // mLists[i>0] can be NULL. that display is to be ignored
struct hwc_display_contents_1* mLists[MAX_DISPLAYS]; struct hwc_display_contents_1* mLists[MAX_HWC_DISPLAYS];
DisplayData mDisplayData[MAX_DISPLAYS]; DisplayData mDisplayData[MAX_HWC_DISPLAYS];
size_t mNumDisplays; size_t mNumDisplays;
cb_context* mCBContext; cb_context* mCBContext;

View File

@ -41,7 +41,7 @@ EventThread::EventThread(const sp<SurfaceFlinger>& flinger)
mUseSoftwareVSync(false), mUseSoftwareVSync(false),
mDebugVsyncEnabled(false) { mDebugVsyncEnabled(false) {
for (int32_t i=0 ; i<HWC_NUM_DISPLAY_TYPES ; i++) { for (int32_t i=0 ; i<DisplayDevice::NUM_BUILTIN_DISPLAY_TYPES ; i++) {
mVSyncEvent[i].header.type = DisplayEventReceiver::DISPLAY_EVENT_VSYNC; mVSyncEvent[i].header.type = DisplayEventReceiver::DISPLAY_EVENT_VSYNC;
mVSyncEvent[i].header.id = 0; mVSyncEvent[i].header.id = 0;
mVSyncEvent[i].header.timestamp = 0; mVSyncEvent[i].header.timestamp = 0;
@ -112,11 +112,11 @@ void EventThread::onScreenAcquired() {
void EventThread::onVSyncReceived(int type, nsecs_t timestamp) { void EventThread::onVSyncReceived(int type, nsecs_t timestamp) {
ALOGE_IF(type >= HWC_NUM_DISPLAY_TYPES, ALOGE_IF(type >= DisplayDevice::NUM_BUILTIN_DISPLAY_TYPES,
"received vsync event for an invalid display (id=%d)", type); "received vsync event for an invalid display (id=%d)", type);
Mutex::Autolock _l(mLock); Mutex::Autolock _l(mLock);
if (type < HWC_NUM_DISPLAY_TYPES) { if (type < DisplayDevice::NUM_BUILTIN_DISPLAY_TYPES) {
mVSyncEvent[type].header.type = DisplayEventReceiver::DISPLAY_EVENT_VSYNC; mVSyncEvent[type].header.type = DisplayEventReceiver::DISPLAY_EVENT_VSYNC;
mVSyncEvent[type].header.id = type; mVSyncEvent[type].header.id = type;
mVSyncEvent[type].header.timestamp = timestamp; mVSyncEvent[type].header.timestamp = timestamp;
@ -126,11 +126,11 @@ void EventThread::onVSyncReceived(int type, nsecs_t timestamp) {
} }
void EventThread::onHotplugReceived(int type, bool connected) { void EventThread::onHotplugReceived(int type, bool connected) {
ALOGE_IF(type >= HWC_NUM_DISPLAY_TYPES, ALOGE_IF(type >= DisplayDevice::NUM_BUILTIN_DISPLAY_TYPES,
"received hotplug event for an invalid display (id=%d)", type); "received hotplug event for an invalid display (id=%d)", type);
Mutex::Autolock _l(mLock); Mutex::Autolock _l(mLock);
if (type < HWC_NUM_DISPLAY_TYPES) { if (type < DisplayDevice::NUM_BUILTIN_DISPLAY_TYPES) {
DisplayEventReceiver::Event event; DisplayEventReceiver::Event event;
event.header.type = DisplayEventReceiver::DISPLAY_EVENT_HOTPLUG; event.header.type = DisplayEventReceiver::DISPLAY_EVENT_HOTPLUG;
event.header.id = type; event.header.id = type;
@ -184,7 +184,7 @@ Vector< sp<EventThread::Connection> > EventThread::waitForEvent(
size_t vsyncCount = 0; size_t vsyncCount = 0;
nsecs_t timestamp = 0; nsecs_t timestamp = 0;
for (int32_t i=0 ; i<HWC_NUM_DISPLAY_TYPES ; i++) { for (int32_t i=0 ; i<DisplayDevice::NUM_BUILTIN_DISPLAY_TYPES ; i++) {
timestamp = mVSyncEvent[i].header.timestamp; timestamp = mVSyncEvent[i].header.timestamp;
if (timestamp) { if (timestamp) {
// we have a vsync event to dispatch // we have a vsync event to dispatch
@ -285,7 +285,7 @@ Vector< sp<EventThread::Connection> > EventThread::waitForEvent(
// FIXME: how do we decide which display id the fake // FIXME: how do we decide which display id the fake
// vsync came from ? // vsync came from ?
mVSyncEvent[0].header.type = DisplayEventReceiver::DISPLAY_EVENT_VSYNC; mVSyncEvent[0].header.type = DisplayEventReceiver::DISPLAY_EVENT_VSYNC;
mVSyncEvent[0].header.id = HWC_DISPLAY_PRIMARY; mVSyncEvent[0].header.id = DisplayDevice::DISPLAY_PRIMARY;
mVSyncEvent[0].header.timestamp = systemTime(SYSTEM_TIME_MONOTONIC); mVSyncEvent[0].header.timestamp = systemTime(SYSTEM_TIME_MONOTONIC);
mVSyncEvent[0].vsync.count++; mVSyncEvent[0].vsync.count++;
} }
@ -308,14 +308,16 @@ Vector< sp<EventThread::Connection> > EventThread::waitForEvent(
void EventThread::enableVSyncLocked() { void EventThread::enableVSyncLocked() {
if (!mUseSoftwareVSync) { if (!mUseSoftwareVSync) {
// never enable h/w VSYNC when screen is off // never enable h/w VSYNC when screen is off
mFlinger->eventControl(HWC_DISPLAY_PRIMARY, SurfaceFlinger::EVENT_VSYNC, true); mFlinger->eventControl(DisplayDevice::DISPLAY_PRIMARY,
SurfaceFlinger::EVENT_VSYNC, true);
mPowerHAL.vsyncHint(true); mPowerHAL.vsyncHint(true);
} }
mDebugVsyncEnabled = true; mDebugVsyncEnabled = true;
} }
void EventThread::disableVSyncLocked() { void EventThread::disableVSyncLocked() {
mFlinger->eventControl(HWC_DISPLAY_PRIMARY, SurfaceFlinger::EVENT_VSYNC, false); mFlinger->eventControl(DisplayDevice::DISPLAY_PRIMARY,
SurfaceFlinger::EVENT_VSYNC, false);
mPowerHAL.vsyncHint(false); mPowerHAL.vsyncHint(false);
mDebugVsyncEnabled = false; mDebugVsyncEnabled = false;
} }
@ -328,7 +330,7 @@ void EventThread::dump(String8& result) const {
mUseSoftwareVSync?"enabled":"disabled"); mUseSoftwareVSync?"enabled":"disabled");
result.appendFormat(" numListeners=%u,\n events-delivered: %u\n", result.appendFormat(" numListeners=%u,\n events-delivered: %u\n",
mDisplayEventConnections.size(), mDisplayEventConnections.size(),
mVSyncEvent[HWC_DISPLAY_PRIMARY].vsync.count); mVSyncEvent[DisplayDevice::DISPLAY_PRIMARY].vsync.count);
for (size_t i=0 ; i<mDisplayEventConnections.size() ; i++) { for (size_t i=0 ; i<mDisplayEventConnections.size() ; i++) {
sp<Connection> connection = sp<Connection> connection =
mDisplayEventConnections.itemAt(i).promote(); mDisplayEventConnections.itemAt(i).promote();

View File

@ -23,12 +23,11 @@
#include <gui/DisplayEventReceiver.h> #include <gui/DisplayEventReceiver.h>
#include <gui/IDisplayEventConnection.h> #include <gui/IDisplayEventConnection.h>
#include <hardware/hwcomposer_defs.h>
#include <utils/Errors.h> #include <utils/Errors.h>
#include <utils/threads.h> #include <utils/threads.h>
#include <utils/SortedVector.h> #include <utils/SortedVector.h>
#include "DisplayDevice.h"
#include "DisplayHardware/PowerHAL.h" #include "DisplayHardware/PowerHAL.h"
// --------------------------------------------------------------------------- // ---------------------------------------------------------------------------
@ -104,7 +103,7 @@ private:
// protected by mLock // protected by mLock
SortedVector< wp<Connection> > mDisplayEventConnections; SortedVector< wp<Connection> > mDisplayEventConnections;
Vector< DisplayEventReceiver::Event > mPendingEvents; Vector< DisplayEventReceiver::Event > mPendingEvents;
DisplayEventReceiver::Event mVSyncEvent[HWC_NUM_DISPLAY_TYPES]; DisplayEventReceiver::Event mVSyncEvent[DisplayDevice::NUM_BUILTIN_DISPLAY_TYPES];
bool mUseSoftwareVSync; bool mUseSoftwareVSync;
// for debugging // for debugging

View File

@ -234,7 +234,7 @@ void SurfaceFlinger::createBuiltinDisplayLocked(DisplayDevice::DisplayType type)
} }
sp<IBinder> SurfaceFlinger::getBuiltInDisplay(int32_t id) { sp<IBinder> SurfaceFlinger::getBuiltInDisplay(int32_t id) {
if (uint32_t(id) >= DisplayDevice::NUM_DISPLAY_TYPES) { if (uint32_t(id) >= DisplayDevice::NUM_BUILTIN_DISPLAY_TYPES) {
ALOGE("getDefaultDisplay: id=%d is not a valid default display id", id); ALOGE("getDefaultDisplay: id=%d is not a valid default display id", id);
return NULL; return NULL;
} }
@ -461,7 +461,7 @@ status_t SurfaceFlinger::readyToRun()
"couldn't create EGLContext"); "couldn't create EGLContext");
// initialize our non-virtual displays // initialize our non-virtual displays
for (size_t i=0 ; i<DisplayDevice::NUM_DISPLAY_TYPES ; i++) { for (size_t i=0 ; i<DisplayDevice::NUM_BUILTIN_DISPLAY_TYPES ; i++) {
DisplayDevice::DisplayType type((DisplayDevice::DisplayType)i); DisplayDevice::DisplayType type((DisplayDevice::DisplayType)i);
// set-up the displays that are already connected // set-up the displays that are already connected
if (mHwc->isConnected(i) || type==DisplayDevice::DISPLAY_PRIMARY) { if (mHwc->isConnected(i) || type==DisplayDevice::DISPLAY_PRIMARY) {
@ -511,7 +511,7 @@ status_t SurfaceFlinger::readyToRun()
} }
int32_t SurfaceFlinger::allocateHwcDisplayId(DisplayDevice::DisplayType type) { int32_t SurfaceFlinger::allocateHwcDisplayId(DisplayDevice::DisplayType type) {
return (uint32_t(type) < DisplayDevice::NUM_DISPLAY_TYPES) ? return (uint32_t(type) < DisplayDevice::NUM_BUILTIN_DISPLAY_TYPES) ?
type : mHwc->allocateDisplayId(); type : mHwc->allocateDisplayId();
} }
@ -540,7 +540,7 @@ bool SurfaceFlinger::authenticateSurfaceTexture(
status_t SurfaceFlinger::getDisplayInfo(const sp<IBinder>& display, DisplayInfo* info) { status_t SurfaceFlinger::getDisplayInfo(const sp<IBinder>& display, DisplayInfo* info) {
int32_t type = NAME_NOT_FOUND; int32_t type = NAME_NOT_FOUND;
for (int i=0 ; i<DisplayDevice::NUM_DISPLAY_TYPES ; i++) { for (int i=0 ; i<DisplayDevice::NUM_BUILTIN_DISPLAY_TYPES ; i++) {
if (display == mBuiltinDisplays[i]) { if (display == mBuiltinDisplays[i]) {
type = i; type = i;
break; break;
@ -661,7 +661,7 @@ void SurfaceFlinger::onVSyncReceived(int type, nsecs_t timestamp) {
ALOGW("WARNING: EventThread not started, ignoring vsync"); ALOGW("WARNING: EventThread not started, ignoring vsync");
return; return;
} }
if (uint32_t(type) < DisplayDevice::NUM_DISPLAY_TYPES) { if (uint32_t(type) < DisplayDevice::NUM_BUILTIN_DISPLAY_TYPES) {
// we should only receive DisplayDevice::DisplayType from the vsync callback // we should only receive DisplayDevice::DisplayType from the vsync callback
mEventThread->onVSyncReceived(type, timestamp); mEventThread->onVSyncReceived(type, timestamp);
} }
@ -676,7 +676,7 @@ void SurfaceFlinger::onHotplugReceived(int type, bool connected) {
return; return;
} }
if (uint32_t(type) < DisplayDevice::NUM_DISPLAY_TYPES) { if (uint32_t(type) < DisplayDevice::NUM_BUILTIN_DISPLAY_TYPES) {
Mutex::Autolock _l(mStateLock); Mutex::Autolock _l(mStateLock);
if (connected) { if (connected) {
createBuiltinDisplayLocked((DisplayDevice::DisplayType)type); createBuiltinDisplayLocked((DisplayDevice::DisplayType)type);
@ -1064,7 +1064,7 @@ void SurfaceFlinger::handleTransactionLocked(uint32_t transactionFlags)
sp<DisplayDevice> hw(getDisplayDevice(draw.keyAt(i))); sp<DisplayDevice> hw(getDisplayDevice(draw.keyAt(i)));
if (hw != NULL) if (hw != NULL)
hw->disconnect(getHwComposer()); hw->disconnect(getHwComposer());
if (draw[i].type < DisplayDevice::NUM_DISPLAY_TYPES) if (draw[i].type < DisplayDevice::NUM_BUILTIN_DISPLAY_TYPES)
mEventThread->onHotplugReceived(draw[i].type, false); mEventThread->onHotplugReceived(draw[i].type, false);
mDisplays.removeItem(draw.keyAt(i)); mDisplays.removeItem(draw.keyAt(i));
} else { } else {
@ -2006,7 +2006,7 @@ void SurfaceFlinger::onScreenAcquired(const sp<const DisplayDevice>& hw) {
hw->acquireScreen(); hw->acquireScreen();
int32_t type = hw->getDisplayType(); int32_t type = hw->getDisplayType();
if (type < DisplayDevice::NUM_DISPLAY_TYPES) { if (type < DisplayDevice::NUM_BUILTIN_DISPLAY_TYPES) {
// built-in display, tell the HWC // built-in display, tell the HWC
getHwComposer().acquire(type); getHwComposer().acquire(type);
@ -2028,7 +2028,7 @@ void SurfaceFlinger::onScreenReleased(const sp<const DisplayDevice>& hw) {
hw->releaseScreen(); hw->releaseScreen();
int32_t type = hw->getDisplayType(); int32_t type = hw->getDisplayType();
if (type < DisplayDevice::NUM_DISPLAY_TYPES) { if (type < DisplayDevice::NUM_BUILTIN_DISPLAY_TYPES) {
if (type == DisplayDevice::DISPLAY_PRIMARY) { if (type == DisplayDevice::DISPLAY_PRIMARY) {
// FIXME: eventthread only knows about the main display right now // FIXME: eventthread only knows about the main display right now
mEventThread->onScreenReleased(); mEventThread->onScreenReleased();
@ -2052,7 +2052,7 @@ void SurfaceFlinger::unblank(const sp<IBinder>& display) {
const sp<DisplayDevice> hw(mFlinger.getDisplayDevice(mDisplay)); const sp<DisplayDevice> hw(mFlinger.getDisplayDevice(mDisplay));
if (hw == NULL) { if (hw == NULL) {
ALOGE("Attempt to unblank null display %p", mDisplay.get()); ALOGE("Attempt to unblank null display %p", mDisplay.get());
} else if (hw->getDisplayType() >= DisplayDevice::NUM_DISPLAY_TYPES) { } else if (hw->getDisplayType() >= DisplayDevice::DISPLAY_VIRTUAL) {
ALOGW("Attempt to unblank virtual display"); ALOGW("Attempt to unblank virtual display");
} else { } else {
mFlinger.onScreenAcquired(hw); mFlinger.onScreenAcquired(hw);
@ -2075,7 +2075,7 @@ void SurfaceFlinger::blank(const sp<IBinder>& display) {
const sp<DisplayDevice> hw(mFlinger.getDisplayDevice(mDisplay)); const sp<DisplayDevice> hw(mFlinger.getDisplayDevice(mDisplay));
if (hw == NULL) { if (hw == NULL) {
ALOGE("Attempt to blank null display %p", mDisplay.get()); ALOGE("Attempt to blank null display %p", mDisplay.get());
} else if (hw->getDisplayType() >= DisplayDevice::NUM_DISPLAY_TYPES) { } else if (hw->getDisplayType() >= DisplayDevice::DISPLAY_VIRTUAL) {
ALOGW("Attempt to blank virtual display"); ALOGW("Attempt to blank virtual display");
} else { } else {
mFlinger.onScreenReleased(hw); mFlinger.onScreenReleased(hw);

View File

@ -421,7 +421,7 @@ private:
EGLConfig mEGLConfig; EGLConfig mEGLConfig;
EGLDisplay mEGLDisplay; EGLDisplay mEGLDisplay;
EGLint mEGLNativeVisualId; EGLint mEGLNativeVisualId;
sp<IBinder> mBuiltinDisplays[DisplayDevice::NUM_DISPLAY_TYPES]; sp<IBinder> mBuiltinDisplays[DisplayDevice::NUM_BUILTIN_DISPLAY_TYPES];
// Can only accessed from the main thread, these members // Can only accessed from the main thread, these members
// don't need synchronization // don't need synchronization