diff --git a/cmds/screenrecord/screenrecord.cpp b/cmds/screenrecord/screenrecord.cpp index c66dea2133..f4fb6266d2 100644 --- a/cmds/screenrecord/screenrecord.cpp +++ b/cmds/screenrecord/screenrecord.cpp @@ -41,22 +41,24 @@ #include #include +#include #include #include #include -#include +#include #include #include #include #include -#include -#include #include #include #include #include +#include +#include #include -#include +#include +#include #include "screenrecord.h" #include "Overlay.h" @@ -66,7 +68,7 @@ using android::ABuffer; using android::ALooper; using android::AMessage; using android::AString; -using android::DisplayInfo; +using android::DisplayConfig; using android::FrameOutput; using android::IBinder; using android::IGraphicBufferProducer; @@ -270,14 +272,15 @@ static status_t prepareEncoder(float displayFps, sp* pCodec, static status_t setDisplayProjection( SurfaceComposerClient::Transaction& t, const sp& dpy, - const DisplayInfo& displayInfo) { + const ui::DisplayState& displayState) { + const ui::Size& viewport = displayState.viewport; // Set the region of the layer stack we're interested in, which in our // case is "all of it". - Rect layerStackRect(displayInfo.viewportW, displayInfo.viewportH); + Rect layerStackRect(viewport); // We need to preserve the aspect ratio of the display. - float displayAspect = (float) displayInfo.viewportH / (float) displayInfo.viewportW; + float displayAspect = viewport.getHeight() / static_cast(viewport.getWidth()); // Set the way we map the output onto the display surface (which will @@ -336,15 +339,16 @@ static status_t setDisplayProjection( * Configures the virtual display. When this completes, virtual display * frames will start arriving from the buffer producer. */ -static status_t prepareVirtualDisplay(const DisplayInfo& displayInfo, +static status_t prepareVirtualDisplay( + const ui::DisplayState& displayState, const sp& bufferProducer, sp* pDisplayHandle) { sp dpy = SurfaceComposerClient::createDisplay( String8("ScreenRecorder"), false /*secure*/); SurfaceComposerClient::Transaction t; t.setDisplaySurface(dpy, bufferProducer); - setDisplayProjection(t, dpy, displayInfo); - t.setDisplayLayerStack(dpy, displayInfo.layerStack); + setDisplayProjection(t, dpy, displayState); + t.setDisplayLayerStack(dpy, displayState.layerStack); t.apply(); *pDisplayHandle = dpy; @@ -421,7 +425,6 @@ static status_t runEncoder(const sp& encoder, uint32_t debugNumFrames = 0; int64_t startWhenNsec = systemTime(CLOCK_MONOTONIC); int64_t endWhenNsec = startWhenNsec + seconds_to_nanoseconds(gTimeLimitSec); - DisplayInfo displayInfo; Vector timestamps; bool firstFrame = true; @@ -478,16 +481,16 @@ static status_t runEncoder(const sp& encoder, // // Polling for changes is inefficient and wrong, but the // useful stuff is hard to get at without a Dalvik VM. - err = SurfaceComposerClient::getDisplayInfo(display, - &displayInfo); + ui::DisplayState displayState; + err = SurfaceComposerClient::getDisplayState(display, &displayState); if (err != NO_ERROR) { - ALOGW("getDisplayInfo(main) failed: %d", err); - } else if (orientation != displayInfo.orientation) { - ALOGD("orientation changed, now %s", toCString(displayInfo.orientation)); + ALOGW("getDisplayState() failed: %d", err); + } else if (orientation != displayState.orientation) { + ALOGD("orientation changed, now %s", toCString(displayState.orientation)); SurfaceComposerClient::Transaction t; - setDisplayProjection(t, virtualDpy, displayInfo); + setDisplayProjection(t, virtualDpy, displayState); t.apply(); - orientation = displayInfo.orientation; + orientation = displayState.orientation; } } @@ -682,26 +685,34 @@ static status_t recordScreen(const char* fileName) { return NAME_NOT_FOUND; } - DisplayInfo displayInfo; - err = SurfaceComposerClient::getDisplayInfo(display, &displayInfo); + ui::DisplayState displayState; + err = SurfaceComposerClient::getDisplayState(display, &displayState); + if (err != NO_ERROR) { + fprintf(stderr, "ERROR: unable to get display state\n"); + return err; + } + + DisplayConfig displayConfig; + err = SurfaceComposerClient::getActiveDisplayConfig(display, &displayConfig); if (err != NO_ERROR) { - fprintf(stderr, "ERROR: unable to get display characteristics\n"); + fprintf(stderr, "ERROR: unable to get display config\n"); return err; } + const ui::Size& viewport = displayState.viewport; if (gVerbose) { printf("Display is %dx%d @%.2ffps (orientation=%s), layerStack=%u\n", - displayInfo.viewportW, displayInfo.viewportH, displayInfo.fps, - toCString(displayInfo.orientation), displayInfo.layerStack); + viewport.getWidth(), viewport.getHeight(), displayConfig.refreshRate, + toCString(displayState.orientation), displayState.layerStack); fflush(stdout); } // Encoder can't take odd number as config if (gVideoWidth == 0) { - gVideoWidth = floorToEven(displayInfo.viewportW); + gVideoWidth = floorToEven(viewport.getWidth()); } if (gVideoHeight == 0) { - gVideoHeight = floorToEven(displayInfo.viewportH); + gVideoHeight = floorToEven(viewport.getHeight()); } // Configure and start the encoder. @@ -709,7 +720,7 @@ static status_t recordScreen(const char* fileName) { sp frameOutput; sp encoderInputSurface; if (gOutputFormat != FORMAT_FRAMES && gOutputFormat != FORMAT_RAW_FRAMES) { - err = prepareEncoder(displayInfo.fps, &encoder, &encoderInputSurface); + err = prepareEncoder(displayConfig.refreshRate, &encoder, &encoderInputSurface); if (err != NO_ERROR && !gSizeSpecified) { // fallback is defined for landscape; swap if we're in portrait @@ -722,8 +733,7 @@ static status_t recordScreen(const char* fileName) { gVideoWidth, gVideoHeight, newWidth, newHeight); gVideoWidth = newWidth; gVideoHeight = newHeight; - err = prepareEncoder(displayInfo.fps, &encoder, - &encoderInputSurface); + err = prepareEncoder(displayConfig.refreshRate, &encoder, &encoderInputSurface); } } if (err != NO_ERROR) return err; @@ -770,7 +780,7 @@ static status_t recordScreen(const char* fileName) { // Configure virtual display. sp dpy; - err = prepareVirtualDisplay(displayInfo, bufferProducer, &dpy); + err = prepareVirtualDisplay(displayState, bufferProducer, &dpy); if (err != NO_ERROR) { if (encoder != NULL) encoder->release(); return err; @@ -853,8 +863,7 @@ static status_t recordScreen(const char* fileName) { } } else { // Main encoder loop. - err = runEncoder(encoder, muxer, rawFp, display, dpy, - displayInfo.orientation); + err = runEncoder(encoder, muxer, rawFp, display, dpy, displayState.orientation); if (err != NO_ERROR) { fprintf(stderr, "Encoder failed (err=%d)\n", err); // fall through to cleanup diff --git a/cmds/stagefright/codec.cpp b/cmds/stagefright/codec.cpp index f2d1c29f24..c26e0b90a5 100644 --- a/cmds/stagefright/codec.cpp +++ b/cmds/stagefright/codec.cpp @@ -39,7 +39,7 @@ #include #include #include -#include +#include static void usage(const char *me) { fprintf(stderr, "usage: %s [-a] use audio\n" @@ -414,11 +414,12 @@ int main(int argc, char **argv) { const sp display = SurfaceComposerClient::getInternalDisplayToken(); CHECK(display != nullptr); - DisplayInfo info; - CHECK_EQ(SurfaceComposerClient::getDisplayInfo(display, &info), NO_ERROR); + DisplayConfig config; + CHECK_EQ(SurfaceComposerClient::getActiveDisplayConfig(display, &config), NO_ERROR); - ssize_t displayWidth = info.w; - ssize_t displayHeight = info.h; + const ui::Size& resolution = config.resolution; + const ssize_t displayWidth = resolution.getWidth(); + const ssize_t displayHeight = resolution.getHeight(); ALOGV("display is %zd x %zd\n", displayWidth, displayHeight); diff --git a/cmds/stagefright/mediafilter.cpp b/cmds/stagefright/mediafilter.cpp index 66302b0488..b894545089 100644 --- a/cmds/stagefright/mediafilter.cpp +++ b/cmds/stagefright/mediafilter.cpp @@ -34,7 +34,7 @@ #include #include #include -#include +#include #include "RenderScript.h" #include "ScriptC_argbtorgba.h" @@ -751,11 +751,12 @@ int main(int argc, char **argv) { const android::sp display = SurfaceComposerClient::getInternalDisplayToken(); CHECK(display != nullptr); - DisplayInfo info; - CHECK_EQ(SurfaceComposerClient::getDisplayInfo(display, &info), NO_ERROR); + DisplayConfig config; + CHECK_EQ(SurfaceComposerClient::getActiveDisplayConfig(display, &config), NO_ERROR); - ssize_t displayWidth = info.w; - ssize_t displayHeight = info.h; + const ui::Size& resolution = config.resolution; + const ssize_t displayWidth = resolution.getWidth(); + const ssize_t displayHeight = resolution.getHeight(); ALOGV("display is %zd x %zd", displayWidth, displayHeight); diff --git a/cmds/stagefright/stream.cpp b/cmds/stagefright/stream.cpp index fe613a8dd7..5f03929ced 100644 --- a/cmds/stagefright/stream.cpp +++ b/cmds/stagefright/stream.cpp @@ -42,7 +42,7 @@ #include #include -#include +#include using namespace android; @@ -321,11 +321,12 @@ int main(int argc, char **argv) { const sp display = SurfaceComposerClient::getInternalDisplayToken(); CHECK(display != nullptr); - DisplayInfo info; - CHECK_EQ(SurfaceComposerClient::getDisplayInfo(display, &info), NO_ERROR); + DisplayConfig config; + CHECK_EQ(SurfaceComposerClient::getActiveDisplayConfig(display, &config), NO_ERROR); - ssize_t displayWidth = info.w; - ssize_t displayHeight = info.h; + const ui::Size& resolution = config.resolution; + const ssize_t displayWidth = resolution.getWidth(); + const ssize_t displayHeight = resolution.getHeight(); ALOGV("display is %zd x %zd\n", displayWidth, displayHeight);