From 9d4e3d2f42e93e2d12bacabe97d307d30c3c20dd Mon Sep 17 00:00:00 2001 From: Jeff Brown Date: Fri, 24 Aug 2012 20:00:51 -0700 Subject: Banish DisplayID from the SurfaceFlinger API. Use only display tokens in the API to refer to new displays. Don't require the caller to specify the display when creating a surface (since in general a surface could be shown on any display). This is intended to be a minimum change just to update the API. Note that SurfaceFlinger still uses DisplayID in a few places internally that might cause some features not to work properly when there are multiple displays (LayerScreenshot, for example). Change-Id: I3d91eec2da406eefd97bcd53655d403ad865a7e6 --- services/surfaceflinger/Client.cpp | 12 ++++---- services/surfaceflinger/Client.h | 2 +- services/surfaceflinger/SurfaceFlinger.cpp | 35 +++++++++++----------- services/surfaceflinger/SurfaceFlinger.h | 8 ++--- services/surfaceflinger/tests/Transaction_test.cpp | 13 ++++---- services/surfaceflinger/tests/resize/resize.cpp | 4 +-- .../surfaceflinger/tests/screencap/screencap.cpp | 3 +- services/surfaceflinger/tests/surface/surface.cpp | 2 +- 8 files changed, 42 insertions(+), 37 deletions(-) (limited to 'services') diff --git a/services/surfaceflinger/Client.cpp b/services/surfaceflinger/Client.cpp index d5d551e..b0f2330 100644 --- a/services/surfaceflinger/Client.cpp +++ b/services/surfaceflinger/Client.cpp @@ -111,7 +111,7 @@ status_t Client::onTransact( sp Client::createSurface( ISurfaceComposerClient::surface_data_t* params, const String8& name, - DisplayID display, uint32_t w, uint32_t h, PixelFormat format, + uint32_t w, uint32_t h, PixelFormat format, uint32_t flags) { /* @@ -125,7 +125,6 @@ sp Client::createSurface( ISurfaceComposerClient::surface_data_t* params; Client* client; const String8& name; - DisplayID display; uint32_t w, h; PixelFormat format; uint32_t flags; @@ -133,22 +132,23 @@ sp Client::createSurface( MessageCreateLayer(SurfaceFlinger* flinger, ISurfaceComposerClient::surface_data_t* params, const String8& name, Client* client, - DisplayID display, uint32_t w, uint32_t h, PixelFormat format, + uint32_t w, uint32_t h, PixelFormat format, uint32_t flags) : flinger(flinger), params(params), client(client), name(name), - display(display), w(w), h(h), format(format), flags(flags) + w(w), h(h), format(format), flags(flags) { } sp getResult() const { return result; } virtual bool handler() { + // TODO don't require display id to create a layer result = flinger->createLayer(params, name, client, - display, w, h, format, flags); + ISurfaceComposer::eDisplayIdMain, w, h, format, flags); return true; } }; sp msg = new MessageCreateLayer(mFlinger.get(), - params, name, this, display, w, h, format, flags); + params, name, this, w, h, format, flags); mFlinger->postMessageSync(msg); return static_cast( msg.get() )->getResult(); } diff --git a/services/surfaceflinger/Client.h b/services/surfaceflinger/Client.h index 9bfee72..d6c6931 100644 --- a/services/surfaceflinger/Client.h +++ b/services/surfaceflinger/Client.h @@ -54,7 +54,7 @@ private: // ISurfaceComposerClient interface virtual sp createSurface( surface_data_t* params, const String8& name, - DisplayID display, uint32_t w, uint32_t h,PixelFormat format, + uint32_t w, uint32_t h,PixelFormat format, uint32_t flags); virtual status_t destroySurface(SurfaceID surfaceId); diff --git a/services/surfaceflinger/SurfaceFlinger.cpp b/services/surfaceflinger/SurfaceFlinger.cpp index 1406deb..ed687e3 100644 --- a/services/surfaceflinger/SurfaceFlinger.cpp +++ b/services/surfaceflinger/SurfaceFlinger.cpp @@ -511,9 +511,11 @@ bool SurfaceFlinger::authenticateSurfaceTexture( return false; } -status_t SurfaceFlinger::getDisplayInfo(DisplayID dpy, DisplayInfo* info) { - // TODO: this is here only for compatibility -- should go away eventually. - if (uint32_t(dpy) >= 1) { +status_t SurfaceFlinger::getDisplayInfo(const sp& display, DisplayInfo* info) { + // TODO: this is mostly here only for compatibility + // the display size is needed but the display metrics should come from elsewhere + if (display != mDefaultDisplays[ISurfaceComposer::eDisplayIdMain]) { + // TODO: additional displays not yet supported return BAD_INDEX; } @@ -570,7 +572,7 @@ sp SurfaceFlinger::createDisplayEventConnection() { return mEventThread->createEventConnection(); } -void SurfaceFlinger::connectDisplay(const sp surface) { +void SurfaceFlinger::connectDisplay(const sp& surface) { sp token; { // scope for the lock @@ -2242,7 +2244,7 @@ status_t SurfaceFlinger::renderScreenToTextureLocked(DisplayID dpy, // --------------------------------------------------------------------------- -status_t SurfaceFlinger::captureScreenImplLocked(DisplayID dpy, +status_t SurfaceFlinger::captureScreenImplLocked(const sp& display, sp* heap, uint32_t* w, uint32_t* h, PixelFormat* f, uint32_t sw, uint32_t sh, @@ -2252,9 +2254,8 @@ status_t SurfaceFlinger::captureScreenImplLocked(DisplayID dpy, status_t result = PERMISSION_DENIED; - // only one display supported for now - if (CC_UNLIKELY(uint32_t(dpy) >= DISPLAY_COUNT)) { - ALOGE("invalid display %d", dpy); + const DisplayDeviceState& disp(mDrawingState.displays.valueFor(display)); + if (CC_UNLIKELY(disp.id < 0)) { return BAD_VALUE; } @@ -2263,7 +2264,7 @@ status_t SurfaceFlinger::captureScreenImplLocked(DisplayID dpy, } // get screen geometry - sp hw(getDisplayDevice(dpy)); + sp hw(getDisplayDevice(disp.id)); const uint32_t hw_w = hw->getWidth(); const uint32_t hw_h = hw->getHeight(); @@ -2316,6 +2317,7 @@ status_t SurfaceFlinger::captureScreenImplLocked(DisplayID dpy, glClearColor(0,0,0,1); glClear(GL_COLOR_BUFFER_BIT); + // TODO: filter the layers that are drawn based on the layer stack of the display. const LayerVector& layers(mDrawingState.layersSortedByZ); const size_t count = layers.size(); for (size_t i=0 ; i& display, sp* heap, uint32_t* width, uint32_t* height, PixelFormat* format, uint32_t sw, uint32_t sh, uint32_t minLayerZ, uint32_t maxLayerZ) { - // only one display supported for now - if (CC_UNLIKELY(uint32_t(dpy) >= DISPLAY_COUNT)) + if (CC_UNLIKELY(display == 0)) return BAD_VALUE; if (!GLExtensions::getInstance().haveFramebufferObject()) @@ -2392,7 +2393,7 @@ status_t SurfaceFlinger::captureScreen(DisplayID dpy, class MessageCaptureScreen : public MessageBase { SurfaceFlinger* flinger; - DisplayID dpy; + sp display; sp* heap; uint32_t* w; uint32_t* h; @@ -2403,11 +2404,11 @@ status_t SurfaceFlinger::captureScreen(DisplayID dpy, uint32_t maxLayerZ; status_t result; public: - MessageCaptureScreen(SurfaceFlinger* flinger, DisplayID dpy, + MessageCaptureScreen(SurfaceFlinger* flinger, const sp& display, sp* heap, uint32_t* w, uint32_t* h, PixelFormat* f, uint32_t sw, uint32_t sh, uint32_t minLayerZ, uint32_t maxLayerZ) - : flinger(flinger), dpy(dpy), + : flinger(flinger), display(display), heap(heap), w(w), h(h), f(f), sw(sw), sh(sh), minLayerZ(minLayerZ), maxLayerZ(maxLayerZ), result(PERMISSION_DENIED) @@ -2418,14 +2419,14 @@ status_t SurfaceFlinger::captureScreen(DisplayID dpy, } virtual bool handler() { Mutex::Autolock _l(flinger->mStateLock); - result = flinger->captureScreenImplLocked(dpy, + result = flinger->captureScreenImplLocked(display, heap, w, h, f, sw, sh, minLayerZ, maxLayerZ); return true; } }; sp msg = new MessageCaptureScreen(this, - dpy, heap, width, height, format, sw, sh, minLayerZ, maxLayerZ); + display, heap, width, height, format, sw, sh, minLayerZ, maxLayerZ); status_t res = postMessageSync(msg); if (res == NO_ERROR) { res = static_cast( msg.get() )->getResult(); diff --git a/services/surfaceflinger/SurfaceFlinger.h b/services/surfaceflinger/SurfaceFlinger.h index 7ad5450..653a631 100644 --- a/services/surfaceflinger/SurfaceFlinger.h +++ b/services/surfaceflinger/SurfaceFlinger.h @@ -195,7 +195,7 @@ private: virtual bool authenticateSurfaceTexture( const sp& surface) const; virtual sp createDisplayEventConnection(); - virtual status_t captureScreen(DisplayID dpy, sp* heap, + virtual status_t captureScreen(const sp& display, sp* heap, uint32_t* width, uint32_t* height, PixelFormat* format, uint32_t reqWidth, uint32_t reqHeight, uint32_t minLayerZ, uint32_t maxLayerZ); @@ -203,8 +203,8 @@ 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 display); + virtual status_t getDisplayInfo(const sp& display, DisplayInfo* info); + virtual void connectDisplay(const sp& display); /* ------------------------------------------------------------------------ * DeathRecipient interface @@ -304,7 +304,7 @@ private: void startBootAnim(); - status_t captureScreenImplLocked(DisplayID dpy, sp* heap, + status_t captureScreenImplLocked(const sp& display, sp* heap, uint32_t* width, uint32_t* height, PixelFormat* format, uint32_t reqWidth, uint32_t reqHeight, uint32_t minLayerZ, uint32_t maxLayerZ); diff --git a/services/surfaceflinger/tests/Transaction_test.cpp b/services/surfaceflinger/tests/Transaction_test.cpp index e3a98ff..0592c5b 100644 --- a/services/surfaceflinger/tests/Transaction_test.cpp +++ b/services/surfaceflinger/tests/Transaction_test.cpp @@ -57,7 +57,8 @@ public: uint32_t w=0, h=0; PixelFormat fmt=0; sp sf(ComposerService::getComposerService()); - ASSERT_EQ(NO_ERROR, sf->captureScreen(0, &heap, &w, &h, &fmt, 0, 0, + sp display(sf->getBuiltInDisplay(ISurfaceComposer::eDisplayIdMain)); + ASSERT_EQ(NO_ERROR, sf->captureScreen(display, &heap, &w, &h, &fmt, 0, 0, 0, INT_MAX)); ASSERT_TRUE(heap != NULL); ASSERT_EQ(PIXEL_FORMAT_RGBA_8888, fmt); @@ -93,15 +94,17 @@ protected: mComposerClient = new SurfaceComposerClient; ASSERT_EQ(NO_ERROR, mComposerClient->initCheck()); + sp display(SurfaceComposerClient::getBuiltInDisplay( + ISurfaceComposer::eDisplayIdMain)); DisplayInfo info; - SurfaceComposerClient::getDisplayInfo(0, &info); + SurfaceComposerClient::getDisplayInfo(display, &info); ssize_t displayWidth = info.w; ssize_t displayHeight = info.h; // Background surface mBGSurfaceControl = mComposerClient->createSurface( - String8("BG Test Surface"), 0, displayWidth, displayHeight, + String8("BG Test Surface"), displayWidth, displayHeight, PIXEL_FORMAT_RGBA_8888, 0); ASSERT_TRUE(mBGSurfaceControl != NULL); ASSERT_TRUE(mBGSurfaceControl->isValid()); @@ -109,7 +112,7 @@ protected: // Foreground surface mFGSurfaceControl = mComposerClient->createSurface( - String8("FG Test Surface"), 0, 64, 64, PIXEL_FORMAT_RGBA_8888, 0); + String8("FG Test Surface"), 64, 64, PIXEL_FORMAT_RGBA_8888, 0); ASSERT_TRUE(mFGSurfaceControl != NULL); ASSERT_TRUE(mFGSurfaceControl->isValid()); @@ -117,7 +120,7 @@ protected: // Synchronization surface mSyncSurfaceControl = mComposerClient->createSurface( - String8("Sync Test Surface"), 0, 1, 1, PIXEL_FORMAT_RGBA_8888, 0); + String8("Sync Test Surface"), 1, 1, PIXEL_FORMAT_RGBA_8888, 0); ASSERT_TRUE(mSyncSurfaceControl != NULL); ASSERT_TRUE(mSyncSurfaceControl->isValid()); diff --git a/services/surfaceflinger/tests/resize/resize.cpp b/services/surfaceflinger/tests/resize/resize.cpp index c143b3d..d61ea70 100644 --- a/services/surfaceflinger/tests/resize/resize.cpp +++ b/services/surfaceflinger/tests/resize/resize.cpp @@ -38,8 +38,8 @@ int main(int argc, char** argv) // create a client to surfaceflinger sp client = new SurfaceComposerClient(); - sp surface = client->createSurface(0, 160, 240, - PIXEL_FORMAT_RGB_565); + sp surface = client->createSurface(String8("resize"), + 160, 240, PIXEL_FORMAT_RGB_565, 0); SurfaceComposerClient::openGlobalTransaction(); diff --git a/services/surfaceflinger/tests/screencap/screencap.cpp b/services/surfaceflinger/tests/screencap/screencap.cpp index 53566e0..f842fc3 100644 --- a/services/surfaceflinger/tests/screencap/screencap.cpp +++ b/services/surfaceflinger/tests/screencap/screencap.cpp @@ -42,7 +42,8 @@ int main(int argc, char** argv) sp heap; uint32_t w, h; PixelFormat f; - status_t err = composer->captureScreen(0, &heap, &w, &h, &f, 0, 0); + sp display(composer->getBuiltInDisplay(ISurfaceComposer::eDisplayIdMain)); + status_t err = composer->captureScreen(display, &heap, &w, &h, &f, 0, 0); if (err != NO_ERROR) { fprintf(stderr, "screen capture failed: %s\n", strerror(-err)); exit(0); diff --git a/services/surfaceflinger/tests/surface/surface.cpp b/services/surfaceflinger/tests/surface/surface.cpp index a8878f7..9c41cc3 100644 --- a/services/surfaceflinger/tests/surface/surface.cpp +++ b/services/surfaceflinger/tests/surface/surface.cpp @@ -37,7 +37,7 @@ int main(int argc, char** argv) sp client = new SurfaceComposerClient(); sp surfaceControl = client->createSurface( - 0, 160, 240, PIXEL_FORMAT_RGB_565); + String8("surface"), 160, 240, PIXEL_FORMAT_RGB_565, 0); SurfaceComposerClient::openGlobalTransaction(); surfaceControl->setLayer(100000); SurfaceComposerClient::closeGlobalTransaction(); -- cgit v1.1