cmds: Use new libgui API for display info

Bug: 144601064
Test: Build
Change-Id: I39ff087d5aa6ec25c0db73c307fa4e2b84a431ee
gugelfrei
Dominik Laskowski 5 years ago
parent e1a3957f7b
commit 8e9aa353c8

@ -41,22 +41,24 @@
#include <utils/Timers.h> #include <utils/Timers.h>
#include <utils/Trace.h> #include <utils/Trace.h>
#include <gui/ISurfaceComposer.h>
#include <gui/Surface.h> #include <gui/Surface.h>
#include <gui/SurfaceComposerClient.h> #include <gui/SurfaceComposerClient.h>
#include <gui/ISurfaceComposer.h> #include <gui/ISurfaceComposer.h>
#include <ui/DisplayInfo.h> #include <media/MediaCodecBuffer.h>
#include <media/NdkMediaCodec.h> #include <media/NdkMediaCodec.h>
#include <media/NdkMediaFormatPriv.h> #include <media/NdkMediaFormatPriv.h>
#include <media/NdkMediaMuxer.h> #include <media/NdkMediaMuxer.h>
#include <media/openmax/OMX_IVCommon.h> #include <media/openmax/OMX_IVCommon.h>
#include <media/stagefright/foundation/ABuffer.h>
#include <media/stagefright/foundation/AMessage.h>
#include <media/stagefright/MediaCodec.h> #include <media/stagefright/MediaCodec.h>
#include <media/stagefright/MediaCodecConstants.h> #include <media/stagefright/MediaCodecConstants.h>
#include <media/stagefright/MediaErrors.h> #include <media/stagefright/MediaErrors.h>
#include <media/stagefright/PersistentSurface.h> #include <media/stagefright/PersistentSurface.h>
#include <media/stagefright/foundation/ABuffer.h>
#include <media/stagefright/foundation/AMessage.h>
#include <mediadrm/ICrypto.h> #include <mediadrm/ICrypto.h>
#include <media/MediaCodecBuffer.h> #include <ui/DisplayConfig.h>
#include <ui/DisplayState.h>
#include "screenrecord.h" #include "screenrecord.h"
#include "Overlay.h" #include "Overlay.h"
@ -66,7 +68,7 @@ using android::ABuffer;
using android::ALooper; using android::ALooper;
using android::AMessage; using android::AMessage;
using android::AString; using android::AString;
using android::DisplayInfo; using android::DisplayConfig;
using android::FrameOutput; using android::FrameOutput;
using android::IBinder; using android::IBinder;
using android::IGraphicBufferProducer; using android::IGraphicBufferProducer;
@ -270,14 +272,15 @@ static status_t prepareEncoder(float displayFps, sp<MediaCodec>* pCodec,
static status_t setDisplayProjection( static status_t setDisplayProjection(
SurfaceComposerClient::Transaction& t, SurfaceComposerClient::Transaction& t,
const sp<IBinder>& dpy, const sp<IBinder>& 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 // Set the region of the layer stack we're interested in, which in our
// case is "all of it". // case is "all of it".
Rect layerStackRect(displayInfo.viewportW, displayInfo.viewportH); Rect layerStackRect(viewport);
// We need to preserve the aspect ratio of the display. // We need to preserve the aspect ratio of the display.
float displayAspect = (float) displayInfo.viewportH / (float) displayInfo.viewportW; float displayAspect = viewport.getHeight() / static_cast<float>(viewport.getWidth());
// Set the way we map the output onto the display surface (which will // 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 * Configures the virtual display. When this completes, virtual display
* frames will start arriving from the buffer producer. * 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<IGraphicBufferProducer>& bufferProducer, const sp<IGraphicBufferProducer>& bufferProducer,
sp<IBinder>* pDisplayHandle) { sp<IBinder>* pDisplayHandle) {
sp<IBinder> dpy = SurfaceComposerClient::createDisplay( sp<IBinder> dpy = SurfaceComposerClient::createDisplay(
String8("ScreenRecorder"), false /*secure*/); String8("ScreenRecorder"), false /*secure*/);
SurfaceComposerClient::Transaction t; SurfaceComposerClient::Transaction t;
t.setDisplaySurface(dpy, bufferProducer); t.setDisplaySurface(dpy, bufferProducer);
setDisplayProjection(t, dpy, displayInfo); setDisplayProjection(t, dpy, displayState);
t.setDisplayLayerStack(dpy, displayInfo.layerStack); t.setDisplayLayerStack(dpy, displayState.layerStack);
t.apply(); t.apply();
*pDisplayHandle = dpy; *pDisplayHandle = dpy;
@ -421,7 +425,6 @@ static status_t runEncoder(const sp<MediaCodec>& encoder,
uint32_t debugNumFrames = 0; uint32_t debugNumFrames = 0;
int64_t startWhenNsec = systemTime(CLOCK_MONOTONIC); int64_t startWhenNsec = systemTime(CLOCK_MONOTONIC);
int64_t endWhenNsec = startWhenNsec + seconds_to_nanoseconds(gTimeLimitSec); int64_t endWhenNsec = startWhenNsec + seconds_to_nanoseconds(gTimeLimitSec);
DisplayInfo displayInfo;
Vector<int64_t> timestamps; Vector<int64_t> timestamps;
bool firstFrame = true; bool firstFrame = true;
@ -478,16 +481,16 @@ static status_t runEncoder(const sp<MediaCodec>& encoder,
// //
// Polling for changes is inefficient and wrong, but the // Polling for changes is inefficient and wrong, but the
// useful stuff is hard to get at without a Dalvik VM. // useful stuff is hard to get at without a Dalvik VM.
err = SurfaceComposerClient::getDisplayInfo(display, ui::DisplayState displayState;
&displayInfo); err = SurfaceComposerClient::getDisplayState(display, &displayState);
if (err != NO_ERROR) { if (err != NO_ERROR) {
ALOGW("getDisplayInfo(main) failed: %d", err); ALOGW("getDisplayState() failed: %d", err);
} else if (orientation != displayInfo.orientation) { } else if (orientation != displayState.orientation) {
ALOGD("orientation changed, now %s", toCString(displayInfo.orientation)); ALOGD("orientation changed, now %s", toCString(displayState.orientation));
SurfaceComposerClient::Transaction t; SurfaceComposerClient::Transaction t;
setDisplayProjection(t, virtualDpy, displayInfo); setDisplayProjection(t, virtualDpy, displayState);
t.apply(); t.apply();
orientation = displayInfo.orientation; orientation = displayState.orientation;
} }
} }
@ -682,26 +685,34 @@ static status_t recordScreen(const char* fileName) {
return NAME_NOT_FOUND; return NAME_NOT_FOUND;
} }
DisplayInfo displayInfo; ui::DisplayState displayState;
err = SurfaceComposerClient::getDisplayInfo(display, &displayInfo); 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) { if (err != NO_ERROR) {
fprintf(stderr, "ERROR: unable to get display characteristics\n"); fprintf(stderr, "ERROR: unable to get display config\n");
return err; return err;
} }
const ui::Size& viewport = displayState.viewport;
if (gVerbose) { if (gVerbose) {
printf("Display is %dx%d @%.2ffps (orientation=%s), layerStack=%u\n", printf("Display is %dx%d @%.2ffps (orientation=%s), layerStack=%u\n",
displayInfo.viewportW, displayInfo.viewportH, displayInfo.fps, viewport.getWidth(), viewport.getHeight(), displayConfig.refreshRate,
toCString(displayInfo.orientation), displayInfo.layerStack); toCString(displayState.orientation), displayState.layerStack);
fflush(stdout); fflush(stdout);
} }
// Encoder can't take odd number as config // Encoder can't take odd number as config
if (gVideoWidth == 0) { if (gVideoWidth == 0) {
gVideoWidth = floorToEven(displayInfo.viewportW); gVideoWidth = floorToEven(viewport.getWidth());
} }
if (gVideoHeight == 0) { if (gVideoHeight == 0) {
gVideoHeight = floorToEven(displayInfo.viewportH); gVideoHeight = floorToEven(viewport.getHeight());
} }
// Configure and start the encoder. // Configure and start the encoder.
@ -709,7 +720,7 @@ static status_t recordScreen(const char* fileName) {
sp<FrameOutput> frameOutput; sp<FrameOutput> frameOutput;
sp<IGraphicBufferProducer> encoderInputSurface; sp<IGraphicBufferProducer> encoderInputSurface;
if (gOutputFormat != FORMAT_FRAMES && gOutputFormat != FORMAT_RAW_FRAMES) { 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) { if (err != NO_ERROR && !gSizeSpecified) {
// fallback is defined for landscape; swap if we're in portrait // 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, gVideoHeight, newWidth, newHeight);
gVideoWidth = newWidth; gVideoWidth = newWidth;
gVideoHeight = newHeight; gVideoHeight = newHeight;
err = prepareEncoder(displayInfo.fps, &encoder, err = prepareEncoder(displayConfig.refreshRate, &encoder, &encoderInputSurface);
&encoderInputSurface);
} }
} }
if (err != NO_ERROR) return err; if (err != NO_ERROR) return err;
@ -770,7 +780,7 @@ static status_t recordScreen(const char* fileName) {
// Configure virtual display. // Configure virtual display.
sp<IBinder> dpy; sp<IBinder> dpy;
err = prepareVirtualDisplay(displayInfo, bufferProducer, &dpy); err = prepareVirtualDisplay(displayState, bufferProducer, &dpy);
if (err != NO_ERROR) { if (err != NO_ERROR) {
if (encoder != NULL) encoder->release(); if (encoder != NULL) encoder->release();
return err; return err;
@ -853,8 +863,7 @@ static status_t recordScreen(const char* fileName) {
} }
} else { } else {
// Main encoder loop. // Main encoder loop.
err = runEncoder(encoder, muxer, rawFp, display, dpy, err = runEncoder(encoder, muxer, rawFp, display, dpy, displayState.orientation);
displayInfo.orientation);
if (err != NO_ERROR) { if (err != NO_ERROR) {
fprintf(stderr, "Encoder failed (err=%d)\n", err); fprintf(stderr, "Encoder failed (err=%d)\n", err);
// fall through to cleanup // fall through to cleanup

@ -39,7 +39,7 @@
#include <gui/ISurfaceComposer.h> #include <gui/ISurfaceComposer.h>
#include <gui/SurfaceComposerClient.h> #include <gui/SurfaceComposerClient.h>
#include <gui/Surface.h> #include <gui/Surface.h>
#include <ui/DisplayInfo.h> #include <ui/DisplayConfig.h>
static void usage(const char *me) { static void usage(const char *me) {
fprintf(stderr, "usage: %s [-a] use audio\n" fprintf(stderr, "usage: %s [-a] use audio\n"
@ -414,11 +414,12 @@ int main(int argc, char **argv) {
const sp<IBinder> display = SurfaceComposerClient::getInternalDisplayToken(); const sp<IBinder> display = SurfaceComposerClient::getInternalDisplayToken();
CHECK(display != nullptr); CHECK(display != nullptr);
DisplayInfo info; DisplayConfig config;
CHECK_EQ(SurfaceComposerClient::getDisplayInfo(display, &info), NO_ERROR); CHECK_EQ(SurfaceComposerClient::getActiveDisplayConfig(display, &config), NO_ERROR);
ssize_t displayWidth = info.w; const ui::Size& resolution = config.resolution;
ssize_t displayHeight = info.h; const ssize_t displayWidth = resolution.getWidth();
const ssize_t displayHeight = resolution.getHeight();
ALOGV("display is %zd x %zd\n", displayWidth, displayHeight); ALOGV("display is %zd x %zd\n", displayWidth, displayHeight);

@ -34,7 +34,7 @@
#include <media/stagefright/NuMediaExtractor.h> #include <media/stagefright/NuMediaExtractor.h>
#include <media/stagefright/RenderScriptWrapper.h> #include <media/stagefright/RenderScriptWrapper.h>
#include <OMX_IVCommon.h> #include <OMX_IVCommon.h>
#include <ui/DisplayInfo.h> #include <ui/DisplayConfig.h>
#include "RenderScript.h" #include "RenderScript.h"
#include "ScriptC_argbtorgba.h" #include "ScriptC_argbtorgba.h"
@ -751,11 +751,12 @@ int main(int argc, char **argv) {
const android::sp<IBinder> display = SurfaceComposerClient::getInternalDisplayToken(); const android::sp<IBinder> display = SurfaceComposerClient::getInternalDisplayToken();
CHECK(display != nullptr); CHECK(display != nullptr);
DisplayInfo info; DisplayConfig config;
CHECK_EQ(SurfaceComposerClient::getDisplayInfo(display, &info), NO_ERROR); CHECK_EQ(SurfaceComposerClient::getActiveDisplayConfig(display, &config), NO_ERROR);
ssize_t displayWidth = info.w; const ui::Size& resolution = config.resolution;
ssize_t displayHeight = info.h; const ssize_t displayWidth = resolution.getWidth();
const ssize_t displayHeight = resolution.getHeight();
ALOGV("display is %zd x %zd", displayWidth, displayHeight); ALOGV("display is %zd x %zd", displayWidth, displayHeight);

@ -42,7 +42,7 @@
#include <gui/Surface.h> #include <gui/Surface.h>
#include <fcntl.h> #include <fcntl.h>
#include <ui/DisplayInfo.h> #include <ui/DisplayConfig.h>
using namespace android; using namespace android;
@ -321,11 +321,12 @@ int main(int argc, char **argv) {
const sp<IBinder> display = SurfaceComposerClient::getInternalDisplayToken(); const sp<IBinder> display = SurfaceComposerClient::getInternalDisplayToken();
CHECK(display != nullptr); CHECK(display != nullptr);
DisplayInfo info; DisplayConfig config;
CHECK_EQ(SurfaceComposerClient::getDisplayInfo(display, &info), NO_ERROR); CHECK_EQ(SurfaceComposerClient::getActiveDisplayConfig(display, &config), NO_ERROR);
ssize_t displayWidth = info.w; const ui::Size& resolution = config.resolution;
ssize_t displayHeight = info.h; const ssize_t displayWidth = resolution.getWidth();
const ssize_t displayHeight = resolution.getHeight();
ALOGV("display is %zd x %zd\n", displayWidth, displayHeight); ALOGV("display is %zd x %zd\n", displayWidth, displayHeight);

Loading…
Cancel
Save