DisplayDevice::DisplayDevice(
const sp<SurfaceFlinger>& flinger,
DisplayType type,
+ int32_t hwcId,
bool isSecure,
const wp<IBinder>& displayToken,
const sp<DisplaySurface>& displaySurface,
EGLConfig config)
: mFlinger(flinger),
- mType(type), mHwcDisplayId(-1),
+ mType(type), mHwcDisplayId(hwcId),
mDisplayToken(displayToken),
mDisplaySurface(displaySurface),
mDisplay(EGL_NO_DISPLAY),
mOrientation()
{
mNativeWindow = new Surface(mDisplaySurface->getIGraphicBufferProducer());
- init(config);
-}
-
-DisplayDevice::~DisplayDevice() {
- if (mSurface != EGL_NO_SURFACE) {
- eglDestroySurface(mDisplay, mSurface);
- mSurface = EGL_NO_SURFACE;
- }
-}
-
-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;
-}
-
-void DisplayDevice::init(EGLConfig config)
-{
ANativeWindow* const window = mNativeWindow.get();
int format;
mViewport.makeInvalid();
mFrame.makeInvalid();
- // external displays are always considered enabled
- mScreenAcquired = (mType >= DisplayDevice::NUM_DISPLAY_TYPES);
-
- // get an h/w composer ID
- mHwcDisplayId = mFlinger->allocateHwcDisplayId(mType);
+ // virtual displays are always considered enabled
+ mScreenAcquired = (mType >= DisplayDevice::DISPLAY_VIRTUAL);
// Name the display. The name will be replaced shortly if the display
// was created with createDisplay().
setProjection(DisplayState::eOrientationDefault, mViewport, mFrame);
}
+DisplayDevice::~DisplayDevice() {
+ if (mSurface != EGL_NO_SURFACE) {
+ eglDestroySurface(mDisplay, mSurface);
+ mSurface = EGL_NO_SURFACE;
+ }
+}
+
+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;
+}
+
void DisplayDevice::setDisplayName(const String8& displayName) {
if (!displayName.isEmpty()) {
// never override the name with an empty name
DisplayDevice(
const sp<SurfaceFlinger>& flinger,
DisplayType type,
+ int32_t hwcId, // negative for non-HWC-composited displays
bool isSecure,
const wp<IBinder>& displayToken,
const sp<DisplaySurface>& displaySurface,
void dump(String8& result, char* buffer, size_t SIZE) const;
private:
- void init(EGLConfig config);
-
/*
* Constants, set during initialization
*/
namespace android {
// ---------------------------------------------------------------------------
-VirtualDisplaySurface::VirtualDisplaySurface(HWComposer& hwc, int disp,
+VirtualDisplaySurface::VirtualDisplaySurface(HWComposer& hwc, int32_t dispId,
const sp<IGraphicBufferProducer>& sink, const String8& name)
: mHwc(hwc),
- mDisplayId(disp),
- mSource(new BufferQueueInterposer(sink, name)),
+ mDisplayId(dispId),
mName(name)
-{}
+{
+ if (mDisplayId >= 0) {
+ mInterposer = new BufferQueueInterposer(sink, name);
+ mSourceProducer = mInterposer;
+ } else {
+ mSourceProducer = sink;
+ }
+}
VirtualDisplaySurface::~VirtualDisplaySurface() {
if (mAcquiredBuffer != NULL) {
- status_t result = mSource->releaseBuffer(Fence::NO_FENCE);
+ status_t result = mInterposer->releaseBuffer(Fence::NO_FENCE);
ALOGE_IF(result != NO_ERROR, "VirtualDisplaySurface \"%s\": "
"failed to release buffer: %d", mName.string(), result);
}
}
sp<IGraphicBufferProducer> VirtualDisplaySurface::getIGraphicBufferProducer() const {
- return mSource;
+ return mSourceProducer;
}
status_t VirtualDisplaySurface::compositionComplete() {
}
status_t VirtualDisplaySurface::advanceFrame() {
+ if (mInterposer == NULL)
+ return NO_ERROR;
+
Mutex::Autolock lock(mMutex);
status_t result = NO_ERROR;
}
sp<Fence> fence;
- result = mSource->acquireBuffer(&mAcquiredBuffer, &fence);
+ result = mInterposer->acquireBuffer(&mAcquiredBuffer, &fence);
if (result == BufferQueueInterposer::NO_BUFFER_AVAILABLE) {
- result = mSource->pullEmptyBuffer();
+ result = mInterposer->pullEmptyBuffer();
if (result != NO_ERROR)
return result;
- result = mSource->acquireBuffer(&mAcquiredBuffer, &fence);
+ result = mInterposer->acquireBuffer(&mAcquiredBuffer, &fence);
}
if (result != NO_ERROR)
return result;
}
void VirtualDisplaySurface::onFrameCommitted() {
+ if (mInterposer == NULL)
+ return;
+
Mutex::Autolock lock(mMutex);
if (mAcquiredBuffer != NULL) {
// fbFence signals when reads from the framebuffer are finished
String8::format("HWC done: %.21s", mName.string()),
fbFence, outFence);
- status_t result = mSource->releaseBuffer(fence);
+ status_t result = mInterposer->releaseBuffer(fence);
ALOGE_IF(result != NO_ERROR, "VirtualDisplaySurface \"%s\": "
"failed to release buffer: %d", mName.string(), result);
mAcquiredBuffer.clear();
* eglSwapBuffers doesn't immediately dequeue a buffer for the next frame,
* since we can't rely on being able to dequeue more than one buffer at a time.
*
+ * This class also has a passthrough mode, where it doesn't use a
+ * BufferQueueInterposer and never sends buffers to HWC. Instead, OpenGL ES
+ * output buffers are queued directly to the virtual display sink; this class
+ * is inactive after construction. This mode is used when the HWC doesn't
+ * support compositing for virtual displays.
+ *
* TODO(jessehall): Add a libgui test that ensures that EGL/GLES do lazy
* dequeBuffers; we've wanted to require that for other reasons anyway.
*/
class VirtualDisplaySurface : public DisplaySurface {
public:
- VirtualDisplaySurface(HWComposer& hwc, int disp,
+ VirtualDisplaySurface(HWComposer& hwc, int32_t dispId,
const sp<IGraphicBufferProducer>& sink,
const String8& name);
// immutable after construction
HWComposer& mHwc;
- int mDisplayId;
- sp<BufferQueueInterposer> mSource;
+ int32_t mDisplayId;
String8 mName;
+ // with HWC support, both of these point to the same object.
+ // otherwise, mInterposer is NULL and mSourceProducer is the sink.
+ sp<BufferQueueInterposer> mInterposer;
+ sp<IGraphicBufferProducer> mSourceProducer;
+
// mutable, must be synchronized with mMutex
Mutex mMutex;
sp<GraphicBuffer> mAcquiredBuffer;
wp<IBinder> token = mBuiltinDisplays[i];
sp<DisplayDevice> hw = new DisplayDevice(this,
- type, isSecure, token, new FramebufferSurface(*mHwc, i),
+ type, allocateHwcDisplayId(type), isSecure, token,
+ new FramebufferSurface(*mHwc, i),
mEGLConfig);
if (i > DisplayDevice::DISPLAY_PRIMARY) {
// FIXME: currently we don't get blank/unblank requests
const DisplayDeviceState& state(curr[i]);
sp<DisplaySurface> dispSurface;
+ int32_t hwcDisplayId = allocateHwcDisplayId(state.type);
if (state.isVirtualDisplay()) {
if (state.surface != NULL) {
dispSurface = new VirtualDisplaySurface(
- *mHwc, state.type, state.surface,
+ *mHwc, hwcDisplayId, state.surface,
state.displayName);
}
} else {
const wp<IBinder>& display(curr.keyAt(i));
if (dispSurface != NULL) {
sp<DisplayDevice> hw = new DisplayDevice(this,
- state.type, state.isSecure, display,
- dispSurface, mEGLConfig);
+ state.type, hwcDisplayId, state.isSecure,
+ display, dispSurface, mEGLConfig);
hw->setLayerStack(state.layerStack);
hw->setProjection(state.orientation,
state.viewport, state.frame);