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

Commit 7c6278de authored by Jesse Hall's avatar Jesse Hall Committed by Android (Google) Code Review
Browse files

Merge "Use new HWC display type/count constants." into klp-dev

parents 0f05a926 9e663de4
Loading
Loading
Loading
Loading
+3 −2
Original line number Original line Diff line number Diff line
@@ -38,6 +38,7 @@ namespace android {


class DisplayInfo;
class DisplayInfo;
class DisplaySurface;
class DisplaySurface;
class IGraphicBufferProducer;
class Layer;
class Layer;
class SurfaceFlinger;
class SurfaceFlinger;
class HWComposer;
class HWComposer;
@@ -56,8 +57,8 @@ public:
        DISPLAY_ID_INVALID = -1,
        DISPLAY_ID_INVALID = -1,
        DISPLAY_PRIMARY     = HWC_DISPLAY_PRIMARY,
        DISPLAY_PRIMARY     = HWC_DISPLAY_PRIMARY,
        DISPLAY_EXTERNAL    = HWC_DISPLAY_EXTERNAL,
        DISPLAY_EXTERNAL    = HWC_DISPLAY_EXTERNAL,
        NUM_DISPLAY_TYPES   = HWC_NUM_DISPLAY_TYPES,
        DISPLAY_VIRTUAL     = HWC_DISPLAY_VIRTUAL,
        DISPLAY_VIRTUAL     = HWC_NUM_DISPLAY_TYPES
        NUM_BUILTIN_DISPLAY_TYPES = HWC_NUM_PHYSICAL_DISPLAY_TYPES,
    };
    };


    enum {
    enum {
+6 −13
Original line number Original line Diff line number Diff line
@@ -48,15 +48,8 @@


namespace android {
namespace android {


#ifndef HWC_DEVICE_API_VERSION_1_3
#define HWC_DEVICE_API_VERSION_1_3 HARDWARE_DEVICE_API_VERSION_2(1, 3, HWC_HEADER_VERSION)
#endif

#define MIN_HWC_HEADER_VERSION HWC_HEADER_VERSION
#define MIN_HWC_HEADER_VERSION HWC_HEADER_VERSION


#define NUM_PHYSICAL_DISPLAYS HWC_NUM_DISPLAY_TYPES
#define VIRTUAL_DISPLAY_ID_BASE HWC_NUM_DISPLAY_TYPES

static uint32_t hwcApiVersion(const hwc_composer_device_1_t* hwc) {
static uint32_t hwcApiVersion(const hwc_composer_device_1_t* hwc) {
    uint32_t hwcVersion = hwc->common.version;
    uint32_t hwcVersion = hwc->common.version;
    return hwcVersion & HARDWARE_API_VERSION_2_MAJ_MIN_MASK;
    return hwcVersion & HARDWARE_API_VERSION_2_MAJ_MIN_MASK;
@@ -96,7 +89,7 @@ HWComposer::HWComposer(
      mEventHandler(handler),
      mEventHandler(handler),
      mVSyncCount(0), mDebugForceFakeVSync(false)
      mVSyncCount(0), mDebugForceFakeVSync(false)
{
{
    for (size_t i =0 ; i<MAX_DISPLAYS ; i++) {
    for (size_t i =0 ; i<MAX_HWC_DISPLAYS ; i++) {
        mLists[i] = 0;
        mLists[i] = 0;
    }
    }


@@ -127,7 +120,7 @@ HWComposer::HWComposer(
    }
    }


    // these display IDs are always reserved
    // these display IDs are always reserved
    for (size_t i=0 ; i<NUM_PHYSICAL_DISPLAYS ; i++) {
    for (size_t i=0 ; i<NUM_BUILTIN_DISPLAYS ; i++) {
        mAllocatedDisplayIDs.markBit(i);
        mAllocatedDisplayIDs.markBit(i);
    }
    }


@@ -156,10 +149,10 @@ HWComposer::HWComposer(
        // hw composer version
        // hw composer version
        if (hwcHasApiVersion(mHwc, HWC_DEVICE_API_VERSION_1_3)) {
        if (hwcHasApiVersion(mHwc, HWC_DEVICE_API_VERSION_1_3)) {
            // 1.3 adds support for virtual displays
            // 1.3 adds support for virtual displays
            mNumDisplays = MAX_DISPLAYS;
            mNumDisplays = MAX_HWC_DISPLAYS;
        } else if (hwcHasApiVersion(mHwc, HWC_DEVICE_API_VERSION_1_1)) {
        } else if (hwcHasApiVersion(mHwc, HWC_DEVICE_API_VERSION_1_1)) {
            // 1.1 adds support for multiple displays
            // 1.1 adds support for multiple displays
            mNumDisplays = NUM_PHYSICAL_DISPLAYS;
            mNumDisplays = NUM_BUILTIN_DISPLAYS;
        } else {
        } else {
            mNumDisplays = 1;
            mNumDisplays = 1;
        }
        }
@@ -187,7 +180,7 @@ HWComposer::HWComposer(
        }
        }
    } else if (mHwc) {
    } else if (mHwc) {
        // here we're guaranteed to have at least HWC 1.1
        // here we're guaranteed to have at least HWC 1.1
        for (size_t i =0 ; i<NUM_PHYSICAL_DISPLAYS ; i++) {
        for (size_t i =0 ; i<NUM_BUILTIN_DISPLAYS ; i++) {
            queryDisplayProperties(i);
            queryDisplayProperties(i);
        }
        }
    }
    }
@@ -400,7 +393,7 @@ int32_t HWComposer::allocateDisplayId() {
}
}


status_t HWComposer::freeDisplayId(int32_t id) {
status_t HWComposer::freeDisplayId(int32_t id) {
    if (id < NUM_PHYSICAL_DISPLAYS) {
    if (id < NUM_BUILTIN_DISPLAYS) {
        // cannot free the reserved IDs
        // cannot free the reserved IDs
        return BAD_VALUE;
        return BAD_VALUE;
    }
    }
+13 −10
Original line number Original line Diff line number Diff line
@@ -64,7 +64,9 @@ public:
    };
    };


    enum {
    enum {
        MAX_DISPLAYS = HWC_NUM_DISPLAY_TYPES + 1
        NUM_BUILTIN_DISPLAYS = HWC_NUM_PHYSICAL_DISPLAY_TYPES,
        MAX_HWC_DISPLAYS = HWC_NUM_DISPLAY_TYPES,
        VIRTUAL_DISPLAY_ID_BASE = HWC_DISPLAY_VIRTUAL,
    };
    };


    HWComposer(
    HWComposer(
@@ -75,15 +77,16 @@ public:


    status_t initCheck() const;
    status_t initCheck() const;


    // returns a display ID starting at MAX_DISPLAYS, this ID
    // Returns a display ID starting at VIRTUAL_DISPLAY_ID_BASE, this ID is to
    // is to be used with createWorkList (and all other
    // be used with createWorkList (and all other methods requiring an ID
    // methods requiring an ID below).
    // below).
    // IDs below MAX_DISPLAY are pre-defined and therefore are always valid.
    // IDs below NUM_BUILTIN_DISPLAYS are pre-defined and therefore are
    // returns a negative error code if an ID cannot be allocated
    // always valid.
    // Returns -1 if an ID cannot be allocated
    int32_t allocateDisplayId();
    int32_t allocateDisplayId();


    // recycles the given ID and frees the associated worklist.
    // Recycles the given virtual display ID and frees the associated worklist.
    // IDs below MAX_DISPLAYS are not recycled
    // IDs below NUM_BUILTIN_DISPLAYS are not recycled.
    status_t freeDisplayId(int32_t id);
    status_t freeDisplayId(int32_t id);




@@ -333,8 +336,8 @@ private:
    struct hwc_composer_device_1*   mHwc;
    struct hwc_composer_device_1*   mHwc;
    // invariant: mLists[0] != NULL iff mHwc != NULL
    // invariant: mLists[0] != NULL iff mHwc != NULL
    // mLists[i>0] can be NULL. that display is to be ignored
    // mLists[i>0] can be NULL. that display is to be ignored
    struct hwc_display_contents_1*  mLists[MAX_DISPLAYS];
    struct hwc_display_contents_1*  mLists[MAX_HWC_DISPLAYS];
    DisplayData                     mDisplayData[MAX_DISPLAYS];
    DisplayData                     mDisplayData[MAX_HWC_DISPLAYS];
    size_t                          mNumDisplays;
    size_t                          mNumDisplays;


    cb_context*                     mCBContext;
    cb_context*                     mCBContext;
+12 −10
Original line number Original line Diff line number Diff line
@@ -41,7 +41,7 @@ EventThread::EventThread(const sp<SurfaceFlinger>& flinger)
      mUseSoftwareVSync(false),
      mUseSoftwareVSync(false),
      mDebugVsyncEnabled(false) {
      mDebugVsyncEnabled(false) {


    for (int32_t i=0 ; i<HWC_NUM_DISPLAY_TYPES ; i++) {
    for (int32_t i=0 ; i<DisplayDevice::NUM_BUILTIN_DISPLAY_TYPES ; i++) {
        mVSyncEvent[i].header.type = DisplayEventReceiver::DISPLAY_EVENT_VSYNC;
        mVSyncEvent[i].header.type = DisplayEventReceiver::DISPLAY_EVENT_VSYNC;
        mVSyncEvent[i].header.id = 0;
        mVSyncEvent[i].header.id = 0;
        mVSyncEvent[i].header.timestamp = 0;
        mVSyncEvent[i].header.timestamp = 0;
@@ -112,11 +112,11 @@ void EventThread::onScreenAcquired() {




void EventThread::onVSyncReceived(int type, nsecs_t timestamp) {
void EventThread::onVSyncReceived(int type, nsecs_t timestamp) {
    ALOGE_IF(type >= HWC_NUM_DISPLAY_TYPES,
    ALOGE_IF(type >= DisplayDevice::NUM_BUILTIN_DISPLAY_TYPES,
            "received vsync event for an invalid display (id=%d)", type);
            "received vsync event for an invalid display (id=%d)", type);


    Mutex::Autolock _l(mLock);
    Mutex::Autolock _l(mLock);
    if (type < HWC_NUM_DISPLAY_TYPES) {
    if (type < DisplayDevice::NUM_BUILTIN_DISPLAY_TYPES) {
        mVSyncEvent[type].header.type = DisplayEventReceiver::DISPLAY_EVENT_VSYNC;
        mVSyncEvent[type].header.type = DisplayEventReceiver::DISPLAY_EVENT_VSYNC;
        mVSyncEvent[type].header.id = type;
        mVSyncEvent[type].header.id = type;
        mVSyncEvent[type].header.timestamp = timestamp;
        mVSyncEvent[type].header.timestamp = timestamp;
@@ -126,11 +126,11 @@ void EventThread::onVSyncReceived(int type, nsecs_t timestamp) {
}
}


void EventThread::onHotplugReceived(int type, bool connected) {
void EventThread::onHotplugReceived(int type, bool connected) {
    ALOGE_IF(type >= HWC_NUM_DISPLAY_TYPES,
    ALOGE_IF(type >= DisplayDevice::NUM_BUILTIN_DISPLAY_TYPES,
            "received hotplug event for an invalid display (id=%d)", type);
            "received hotplug event for an invalid display (id=%d)", type);


    Mutex::Autolock _l(mLock);
    Mutex::Autolock _l(mLock);
    if (type < HWC_NUM_DISPLAY_TYPES) {
    if (type < DisplayDevice::NUM_BUILTIN_DISPLAY_TYPES) {
        DisplayEventReceiver::Event event;
        DisplayEventReceiver::Event event;
        event.header.type = DisplayEventReceiver::DISPLAY_EVENT_HOTPLUG;
        event.header.type = DisplayEventReceiver::DISPLAY_EVENT_HOTPLUG;
        event.header.id = type;
        event.header.id = type;
@@ -184,7 +184,7 @@ Vector< sp<EventThread::Connection> > EventThread::waitForEvent(


        size_t vsyncCount = 0;
        size_t vsyncCount = 0;
        nsecs_t timestamp = 0;
        nsecs_t timestamp = 0;
        for (int32_t i=0 ; i<HWC_NUM_DISPLAY_TYPES ; i++) {
        for (int32_t i=0 ; i<DisplayDevice::NUM_BUILTIN_DISPLAY_TYPES ; i++) {
            timestamp = mVSyncEvent[i].header.timestamp;
            timestamp = mVSyncEvent[i].header.timestamp;
            if (timestamp) {
            if (timestamp) {
                // we have a vsync event to dispatch
                // we have a vsync event to dispatch
@@ -285,7 +285,7 @@ Vector< sp<EventThread::Connection> > EventThread::waitForEvent(
                    // FIXME: how do we decide which display id the fake
                    // FIXME: how do we decide which display id the fake
                    // vsync came from ?
                    // vsync came from ?
                    mVSyncEvent[0].header.type = DisplayEventReceiver::DISPLAY_EVENT_VSYNC;
                    mVSyncEvent[0].header.type = DisplayEventReceiver::DISPLAY_EVENT_VSYNC;
                    mVSyncEvent[0].header.id = HWC_DISPLAY_PRIMARY;
                    mVSyncEvent[0].header.id = DisplayDevice::DISPLAY_PRIMARY;
                    mVSyncEvent[0].header.timestamp = systemTime(SYSTEM_TIME_MONOTONIC);
                    mVSyncEvent[0].header.timestamp = systemTime(SYSTEM_TIME_MONOTONIC);
                    mVSyncEvent[0].vsync.count++;
                    mVSyncEvent[0].vsync.count++;
                }
                }
@@ -308,14 +308,16 @@ Vector< sp<EventThread::Connection> > EventThread::waitForEvent(
void EventThread::enableVSyncLocked() {
void EventThread::enableVSyncLocked() {
    if (!mUseSoftwareVSync) {
    if (!mUseSoftwareVSync) {
        // never enable h/w VSYNC when screen is off
        // never enable h/w VSYNC when screen is off
        mFlinger->eventControl(HWC_DISPLAY_PRIMARY, SurfaceFlinger::EVENT_VSYNC, true);
        mFlinger->eventControl(DisplayDevice::DISPLAY_PRIMARY,
                SurfaceFlinger::EVENT_VSYNC, true);
        mPowerHAL.vsyncHint(true);
        mPowerHAL.vsyncHint(true);
    }
    }
    mDebugVsyncEnabled = true;
    mDebugVsyncEnabled = true;
}
}


void EventThread::disableVSyncLocked() {
void EventThread::disableVSyncLocked() {
    mFlinger->eventControl(HWC_DISPLAY_PRIMARY, SurfaceFlinger::EVENT_VSYNC, false);
    mFlinger->eventControl(DisplayDevice::DISPLAY_PRIMARY,
            SurfaceFlinger::EVENT_VSYNC, false);
    mPowerHAL.vsyncHint(false);
    mPowerHAL.vsyncHint(false);
    mDebugVsyncEnabled = false;
    mDebugVsyncEnabled = false;
}
}
@@ -328,7 +330,7 @@ void EventThread::dump(String8& result) const {
            mUseSoftwareVSync?"enabled":"disabled");
            mUseSoftwareVSync?"enabled":"disabled");
    result.appendFormat("  numListeners=%u,\n  events-delivered: %u\n",
    result.appendFormat("  numListeners=%u,\n  events-delivered: %u\n",
            mDisplayEventConnections.size(),
            mDisplayEventConnections.size(),
            mVSyncEvent[HWC_DISPLAY_PRIMARY].vsync.count);
            mVSyncEvent[DisplayDevice::DISPLAY_PRIMARY].vsync.count);
    for (size_t i=0 ; i<mDisplayEventConnections.size() ; i++) {
    for (size_t i=0 ; i<mDisplayEventConnections.size() ; i++) {
        sp<Connection> connection =
        sp<Connection> connection =
                mDisplayEventConnections.itemAt(i).promote();
                mDisplayEventConnections.itemAt(i).promote();
+2 −3
Original line number Original line Diff line number Diff line
@@ -23,12 +23,11 @@
#include <gui/DisplayEventReceiver.h>
#include <gui/DisplayEventReceiver.h>
#include <gui/IDisplayEventConnection.h>
#include <gui/IDisplayEventConnection.h>


#include <hardware/hwcomposer_defs.h>

#include <utils/Errors.h>
#include <utils/Errors.h>
#include <utils/threads.h>
#include <utils/threads.h>
#include <utils/SortedVector.h>
#include <utils/SortedVector.h>


#include "DisplayDevice.h"
#include "DisplayHardware/PowerHAL.h"
#include "DisplayHardware/PowerHAL.h"


// ---------------------------------------------------------------------------
// ---------------------------------------------------------------------------
@@ -104,7 +103,7 @@ private:
    // protected by mLock
    // protected by mLock
    SortedVector< wp<Connection> > mDisplayEventConnections;
    SortedVector< wp<Connection> > mDisplayEventConnections;
    Vector< DisplayEventReceiver::Event > mPendingEvents;
    Vector< DisplayEventReceiver::Event > mPendingEvents;
    DisplayEventReceiver::Event mVSyncEvent[HWC_NUM_DISPLAY_TYPES];
    DisplayEventReceiver::Event mVSyncEvent[DisplayDevice::NUM_BUILTIN_DISPLAY_TYPES];
    bool mUseSoftwareVSync;
    bool mUseSoftwareVSync;


    // for debugging
    // for debugging
Loading