Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 8fa50b61 authored by TreeHugger Robot's avatar TreeHugger Robot Committed by Android (Google) Code Review
Browse files

Merge "SF: Redesign API to query display information"

parents 2068b3fc 3cb3d4e3
Loading
Loading
Loading
Loading
+9 −10
Original line number Diff line number Diff line
@@ -14,13 +14,12 @@
 * limitations under the License.
 */

#include "GLHelper.h"

#include <GLES2/gl2.h>
#include <GLES2/gl2ext.h>

#include <ui/DisplayInfo.h>
#include <gui/SurfaceComposerClient.h>

#include "GLHelper.h"
#include <ui/DisplayConfig.h>

namespace android {

@@ -228,15 +227,15 @@ bool GLHelper::computeWindowScale(uint32_t w, uint32_t h, float* scale) {
        return false;
    }

    DisplayInfo info;
    status_t err = mSurfaceComposerClient->getDisplayInfo(dpy, &info);
    DisplayConfig config;
    status_t err = mSurfaceComposerClient->getActiveDisplayConfig(dpy, &config);
    if (err != NO_ERROR) {
        fprintf(stderr, "SurfaceComposer::getDisplayInfo failed: %#x\n", err);
        fprintf(stderr, "SurfaceComposer::getActiveDisplayConfig failed: %#x\n", err);
        return false;
    }

    float scaleX = float(info.w) / float(w);
    float scaleY = float(info.h) / float(h);
    float scaleX = static_cast<float>(config.resolution.getWidth()) / w;
    float scaleY = static_cast<float>(config.resolution.getHeight()) / h;
    *scale = scaleX < scaleY ? scaleX : scaleY;

    return true;
+59 −13
Original line number Diff line number Diff line
@@ -34,8 +34,10 @@

#include <system/graphics.h>

#include <ui/DisplayConfig.h>
#include <ui/DisplayInfo.h>
#include <ui/DisplayStatInfo.h>
#include <ui/DisplayState.h>
#include <ui/HdrCapabilities.h>

#include <utils/Log.h>
@@ -351,22 +353,43 @@ public:
        remote()->transact(BnSurfaceComposer::SET_POWER_MODE, data, &reply);
    }

    virtual status_t getDisplayConfigs(const sp<IBinder>& display,
            Vector<DisplayInfo>* configs)
    {
    virtual status_t getDisplayState(const sp<IBinder>& display, ui::DisplayState* state) {
        Parcel data, reply;
        data.writeInterfaceToken(ISurfaceComposer::getInterfaceDescriptor());
        data.writeStrongBinder(display);
        remote()->transact(BnSurfaceComposer::GET_DISPLAY_STATE, data, &reply);
        const status_t result = reply.readInt32();
        if (result == NO_ERROR) {
            memcpy(state, reply.readInplace(sizeof(ui::DisplayState)), sizeof(ui::DisplayState));
        }
        return result;
    }

    virtual status_t getDisplayInfo(const sp<IBinder>& display, DisplayInfo* info) {
        Parcel data, reply;
        data.writeInterfaceToken(ISurfaceComposer::getInterfaceDescriptor());
        data.writeStrongBinder(display);
        remote()->transact(BnSurfaceComposer::GET_DISPLAY_INFO, data, &reply);
        const status_t result = reply.readInt32();
        if (result == NO_ERROR) {
            memcpy(info, reply.readInplace(sizeof(DisplayInfo)), sizeof(DisplayInfo));
        }
        return result;
    }

    virtual status_t getDisplayConfigs(const sp<IBinder>& display, Vector<DisplayConfig>* configs) {
        Parcel data, reply;
        data.writeInterfaceToken(ISurfaceComposer::getInterfaceDescriptor());
        data.writeStrongBinder(display);
        remote()->transact(BnSurfaceComposer::GET_DISPLAY_CONFIGS, data, &reply);
        status_t result = reply.readInt32();
        const status_t result = reply.readInt32();
        if (result == NO_ERROR) {
            size_t numConfigs = reply.readUint32();
            const size_t numConfigs = reply.readUint32();
            configs->clear();
            configs->resize(numConfigs);
            for (size_t c = 0; c < numConfigs; ++c) {
                memcpy(&(configs->editItemAt(c)),
                        reply.readInplace(sizeof(DisplayInfo)),
                        sizeof(DisplayInfo));
                memcpy(&(configs->editItemAt(c)), reply.readInplace(sizeof(DisplayConfig)),
                       sizeof(DisplayConfig));
            }
        }
        return result;
@@ -1297,17 +1320,40 @@ status_t BnSurfaceComposer::onTransact(
            reply->writeStrongBinder(display);
            return NO_ERROR;
        }
        case GET_DISPLAY_STATE: {
            CHECK_INTERFACE(ISurfaceComposer, data, reply);
            ui::DisplayState state;
            const sp<IBinder> display = data.readStrongBinder();
            const status_t result = getDisplayState(display, &state);
            reply->writeInt32(result);
            if (result == NO_ERROR) {
                memcpy(reply->writeInplace(sizeof(ui::DisplayState)), &state,
                       sizeof(ui::DisplayState));
            }
            return NO_ERROR;
        }
        case GET_DISPLAY_INFO: {
            CHECK_INTERFACE(ISurfaceComposer, data, reply);
            DisplayInfo info;
            const sp<IBinder> display = data.readStrongBinder();
            const status_t result = getDisplayInfo(display, &info);
            reply->writeInt32(result);
            if (result == NO_ERROR) {
                memcpy(reply->writeInplace(sizeof(DisplayInfo)), &info, sizeof(DisplayInfo));
            }
            return NO_ERROR;
        }
        case GET_DISPLAY_CONFIGS: {
            CHECK_INTERFACE(ISurfaceComposer, data, reply);
            Vector<DisplayInfo> configs;
            sp<IBinder> display = data.readStrongBinder();
            status_t result = getDisplayConfigs(display, &configs);
            Vector<DisplayConfig> configs;
            const sp<IBinder> display = data.readStrongBinder();
            const status_t result = getDisplayConfigs(display, &configs);
            reply->writeInt32(result);
            if (result == NO_ERROR) {
                reply->writeUint32(static_cast<uint32_t>(configs.size()));
                for (size_t c = 0; c < configs.size(); ++c) {
                    memcpy(reply->writeInplace(sizeof(DisplayInfo)),
                            &configs[c], sizeof(DisplayInfo));
                    memcpy(reply->writeInplace(sizeof(DisplayConfig)), &configs[c],
                           sizeof(DisplayConfig));
                }
            }
            return NO_ERROR;
+16 −9
Original line number Diff line number Diff line
@@ -31,8 +31,6 @@

#include <system/graphics.h>

#include <ui/DisplayInfo.h>

#include <gui/BufferItemConsumer.h>
#include <gui/CpuConsumer.h>
#include <gui/IGraphicBufferProducer.h>
@@ -41,6 +39,7 @@
#include <gui/LayerState.h>
#include <gui/Surface.h>
#include <gui/SurfaceComposerClient.h>
#include <ui/DisplayConfig.h>

#ifndef NO_INPUT
#include <input/InputWindow.h>
@@ -1623,15 +1622,23 @@ status_t SurfaceComposerClient::injectVSync(nsecs_t when) {
    return sf->injectVSync(when);
}

status_t SurfaceComposerClient::getDisplayConfigs(
        const sp<IBinder>& display, Vector<DisplayInfo>* configs)
{
status_t SurfaceComposerClient::getDisplayState(const sp<IBinder>& display,
                                                ui::DisplayState* state) {
    return ComposerService::getComposerService()->getDisplayState(display, state);
}

status_t SurfaceComposerClient::getDisplayInfo(const sp<IBinder>& display, DisplayInfo* info) {
    return ComposerService::getComposerService()->getDisplayInfo(display, info);
}

status_t SurfaceComposerClient::getDisplayConfigs(const sp<IBinder>& display,
                                                  Vector<DisplayConfig>* configs) {
    return ComposerService::getComposerService()->getDisplayConfigs(display, configs);
}

status_t SurfaceComposerClient::getDisplayInfo(const sp<IBinder>& display,
        DisplayInfo* info) {
    Vector<DisplayInfo> configs;
status_t SurfaceComposerClient::getActiveDisplayConfig(const sp<IBinder>& display,
                                                       DisplayConfig* config) {
    Vector<DisplayConfig> configs;
    status_t result = getDisplayConfigs(display, &configs);
    if (result != NO_ERROR) {
        return result;
@@ -1643,7 +1650,7 @@ status_t SurfaceComposerClient::getDisplayInfo(const sp<IBinder>& display,
        return NAME_NOT_FOUND;
    }

    *info = configs[static_cast<size_t>(activeId)];
    *config = configs[static_cast<size_t>(activeId)];
    return NO_ERROR;
}

+31 −17
Original line number Diff line number Diff line
@@ -14,8 +14,7 @@
 * limitations under the License.
 */

#ifndef ANDROID_GUI_ISURFACE_COMPOSER_H
#define ANDROID_GUI_ISURFACE_COMPOSER_H
#pragma once

#include <stdint.h>
#include <sys/types.h>
@@ -46,13 +45,13 @@
#include <vector>

namespace android {
// ----------------------------------------------------------------------------

struct client_cache_t;
struct ComposerState;
struct DisplayState;
struct DisplayConfig;
struct DisplayInfo;
struct DisplayStatInfo;
struct DisplayState;
struct InputWindowCommands;
class LayerDebugInfo;
class HdrCapabilities;
@@ -63,6 +62,12 @@ class IRegionSamplingListener;
class Rect;
enum class FrameEvent;

namespace ui {

struct DisplayState;

} // namespace ui

/*
 * This class defines the Binder IPC interface for accessing various
 * SurfaceFlinger features.
@@ -161,10 +166,6 @@ public:
     */
    virtual void setPowerMode(const sp<IBinder>& display, int mode) = 0;

    /* returns information for each configuration of the given display
     * intended to be used to get information about built-in displays */
    virtual status_t getDisplayConfigs(const sp<IBinder>& display,
            Vector<DisplayInfo>* configs) = 0;

    /* returns display statistics for a given display
     * intended to be used by the media framework to properly schedule
@@ -172,8 +173,25 @@ public:
    virtual status_t getDisplayStats(const sp<IBinder>& display,
            DisplayStatInfo* stats) = 0;

    /* indicates which of the configurations returned by getDisplayInfo is
     * currently active */
    /**
     * Get transactional state of given display.
     */
    virtual status_t getDisplayState(const sp<IBinder>& display, ui::DisplayState*) = 0;

    /**
     * Get immutable information about given physical display.
     */
    virtual status_t getDisplayInfo(const sp<IBinder>& display, DisplayInfo*) = 0;

    /**
     * Get configurations supported by given physical display.
     */
    virtual status_t getDisplayConfigs(const sp<IBinder>& display, Vector<DisplayConfig>*) = 0;

    /**
     * Get the index into configurations returned by getDisplayConfigs,
     * corresponding to the active configuration.
     */
    virtual int getActiveConfig(const sp<IBinder>& display) = 0;

    virtual status_t getDisplayColorModes(const sp<IBinder>& display,
@@ -493,7 +511,7 @@ public:
        // Java by ActivityManagerService.
        BOOT_FINISHED = IBinder::FIRST_CALL_TRANSACTION,
        CREATE_CONNECTION,
        CREATE_GRAPHIC_BUFFER_ALLOC_UNUSED, // unused, fails permissions check
        GET_DISPLAY_INFO,
        CREATE_DISPLAY_EVENT_CONNECTION,
        CREATE_DISPLAY,
        DESTROY_DISPLAY,
@@ -503,7 +521,7 @@ public:
        GET_SUPPORTED_FRAME_TIMESTAMPS,
        GET_DISPLAY_CONFIGS,
        GET_ACTIVE_CONFIG,
        CONNECT_DISPLAY_UNUSED, // unused, fails permissions check
        GET_DISPLAY_STATE,
        CAPTURE_SCREEN,
        CAPTURE_LAYERS,
        CLEAR_ANIMATION_FRAME_STATS,
@@ -546,8 +564,4 @@ public:
            Parcel* reply, uint32_t flags = 0);
};

// ----------------------------------------------------------------------------

}; // namespace android

#endif // ANDROID_GUI_ISURFACE_COMPOSER_H
} // namespace android
+13 −20
Original line number Diff line number Diff line
@@ -14,8 +14,7 @@
 * limitations under the License.
 */

#ifndef ANDROID_GUI_SURFACE_COMPOSER_CLIENT_H
#define ANDROID_GUI_SURFACE_COMPOSER_CLIENT_H
#pragma once

#include <stdint.h>
#include <sys/types.h>
@@ -46,17 +45,12 @@

namespace android {

// ---------------------------------------------------------------------------

struct DisplayInfo;
class HdrCapabilities;
class ISurfaceComposerClient;
class IGraphicBufferProducer;
class IRegionSamplingListener;
class Region;

// ---------------------------------------------------------------------------

struct SurfaceControlStats {
    SurfaceControlStats(const sp<SurfaceControl>& sc, nsecs_t time,
                        const sp<Fence>& prevReleaseFence, uint32_t hint)
@@ -102,18 +96,21 @@ public:
    status_t linkToComposerDeath(const sp<IBinder::DeathRecipient>& recipient,
            void* cookie = nullptr, uint32_t flags = 0);

    // Get a list of supported configurations for a given display
    static status_t getDisplayConfigs(const sp<IBinder>& display,
            Vector<DisplayInfo>* configs);
    // Get transactional state of given display.
    static status_t getDisplayState(const sp<IBinder>& display, ui::DisplayState*);

    // Get immutable information about given physical display.
    static status_t getDisplayInfo(const sp<IBinder>& display, DisplayInfo*);

    // Get the DisplayInfo for the currently-active configuration
    static status_t getDisplayInfo(const sp<IBinder>& display,
            DisplayInfo* info);
    // Get configurations supported by given physical display.
    static status_t getDisplayConfigs(const sp<IBinder>& display, Vector<DisplayConfig>*);

    // Get the index of the current active configuration (relative to the list
    // returned by getDisplayInfo)
    // Get the ID of the active DisplayConfig, as getDisplayConfigs index.
    static int getActiveConfig(const sp<IBinder>& display);

    // Shorthand for getDisplayConfigs element at getActiveConfig index.
    static status_t getActiveDisplayConfig(const sp<IBinder>& display, DisplayConfig*);

    // Sets the refresh rate boundaries for display configuration.
    // For all other parameters, default configuration is used. The index for the default is
    // corresponting to the configs returned from getDisplayConfigs().
@@ -644,8 +641,4 @@ public:
    void onTransactionCompleted(ListenerStats stats) override;
};

// ---------------------------------------------------------------------------

}; // namespace android

#endif // ANDROID_GUI_SURFACE_COMPOSER_CLIENT_H
} // namespace android
Loading