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

Commit 2248f52c authored by Rachel Lee's avatar Rachel Lee
Browse files

Framework code for Attached Choreographer.

Allows a direct association of a Layer (via LayerHistory) to attached
choreographer.
The EventThread checks whether the vsync is in phase for a
choreographer.

Bug: 255838011
Test: atest AttachedChoreographerNativeTest
Change-Id: I9cb35bced5e6d4509609ad7698ab2902a31d5b98
parent ba75fbf7
Loading
Loading
Loading
Loading
+3 −2
Original line number Original line Diff line number Diff line
@@ -101,8 +101,9 @@ Choreographer* Choreographer::getForThread() {
    return gChoreographer;
    return gChoreographer;
}
}


Choreographer::Choreographer(const sp<Looper>& looper)
Choreographer::Choreographer(const sp<Looper>& looper, const sp<IBinder>& layerHandle)
      : DisplayEventDispatcher(looper, gui::ISurfaceComposer::VsyncSource::eVsyncSourceApp),
      : DisplayEventDispatcher(looper, gui::ISurfaceComposer::VsyncSource::eVsyncSourceApp, {},
                               layerHandle),
        mLooper(looper),
        mLooper(looper),
        mThreadId(std::this_thread::get_id()) {
        mThreadId(std::this_thread::get_id()) {
    std::lock_guard<std::mutex> _l(gChoreographers.lock);
    std::lock_guard<std::mutex> _l(gChoreographers.lock);
+3 −2
Original line number Original line Diff line number Diff line
@@ -37,9 +37,10 @@ static constexpr nsecs_t WAITING_FOR_VSYNC_TIMEOUT = ms2ns(300);


DisplayEventDispatcher::DisplayEventDispatcher(const sp<Looper>& looper,
DisplayEventDispatcher::DisplayEventDispatcher(const sp<Looper>& looper,
                                               gui::ISurfaceComposer::VsyncSource vsyncSource,
                                               gui::ISurfaceComposer::VsyncSource vsyncSource,
                                               EventRegistrationFlags eventRegistration)
                                               EventRegistrationFlags eventRegistration,
                                               const sp<IBinder>& layerHandle)
      : mLooper(looper),
      : mLooper(looper),
        mReceiver(vsyncSource, eventRegistration),
        mReceiver(vsyncSource, eventRegistration, layerHandle),
        mWaitingForVsync(false),
        mWaitingForVsync(false),
        mLastVsyncCount(0),
        mLastVsyncCount(0),
        mLastScheduleVsyncTime(0) {
        mLastScheduleVsyncTime(0) {
+8 −3
Original line number Original line Diff line number Diff line
@@ -14,6 +14,8 @@
 * limitations under the License.
 * limitations under the License.
 */
 */


#define LOG_TAG "DisplayEventReceiver"

#include <string.h>
#include <string.h>


#include <utils/Errors.h>
#include <utils/Errors.h>
@@ -32,7 +34,8 @@ namespace android {
// ---------------------------------------------------------------------------
// ---------------------------------------------------------------------------


DisplayEventReceiver::DisplayEventReceiver(gui::ISurfaceComposer::VsyncSource vsyncSource,
DisplayEventReceiver::DisplayEventReceiver(gui::ISurfaceComposer::VsyncSource vsyncSource,
                                           EventRegistrationFlags eventRegistration) {
                                           EventRegistrationFlags eventRegistration,
                                           const sp<IBinder>& layerHandle) {
    sp<gui::ISurfaceComposer> sf(ComposerServiceAIDL::getComposerService());
    sp<gui::ISurfaceComposer> sf(ComposerServiceAIDL::getComposerService());
    if (sf != nullptr) {
    if (sf != nullptr) {
        mEventConnection = nullptr;
        mEventConnection = nullptr;
@@ -41,8 +44,8 @@ DisplayEventReceiver::DisplayEventReceiver(gui::ISurfaceComposer::VsyncSource vs
                                                 static_cast<
                                                 static_cast<
                                                         gui::ISurfaceComposer::EventRegistration>(
                                                         gui::ISurfaceComposer::EventRegistration>(
                                                         eventRegistration.get()),
                                                         eventRegistration.get()),
                                                 &mEventConnection);
                                                 layerHandle, &mEventConnection);
        if (mEventConnection != nullptr) {
        if (status.isOk() && mEventConnection != nullptr) {
            mDataChannel = std::make_unique<gui::BitTube>();
            mDataChannel = std::make_unique<gui::BitTube>();
            status = mEventConnection->stealReceiveChannel(mDataChannel.get());
            status = mEventConnection->stealReceiveChannel(mDataChannel.get());
            if (!status.isOk()) {
            if (!status.isOk()) {
@@ -51,6 +54,8 @@ DisplayEventReceiver::DisplayEventReceiver(gui::ISurfaceComposer::VsyncSource vs
                mDataChannel.reset();
                mDataChannel.reset();
                mEventConnection.clear();
                mEventConnection.clear();
            }
            }
        } else {
            ALOGE("DisplayEventConnection creation failed: status=%s", status.toString8().c_str());
        }
        }
    }
    }
}
}
+21 −1
Original line number Original line Diff line number Diff line
@@ -26,6 +26,7 @@
#include <utils/Errors.h>
#include <utils/Errors.h>
#include <utils/KeyedVector.h>
#include <utils/KeyedVector.h>
#include <utils/Log.h>
#include <utils/Log.h>
#include <utils/Looper.h>
#include <utils/threads.h>
#include <utils/threads.h>


#include <binder/IPCThreadState.h>
#include <binder/IPCThreadState.h>
@@ -34,8 +35,9 @@
#include <ui/Rect.h>
#include <ui/Rect.h>
#include <ui/StaticDisplayInfo.h>
#include <ui/StaticDisplayInfo.h>


#include <gui/BufferQueueCore.h>
#include <gui/BLASTBufferQueue.h>
#include <gui/BLASTBufferQueue.h>
#include <gui/BufferQueueCore.h>
#include <gui/Choreographer.h>
#include <gui/ISurfaceComposer.h>
#include <gui/ISurfaceComposer.h>
#include <gui/Surface.h>
#include <gui/Surface.h>
#include <gui/SurfaceComposerClient.h>
#include <gui/SurfaceComposerClient.h>
@@ -191,6 +193,24 @@ const std::string& SurfaceControl::getName() const {
    return mName;
    return mName;
}
}


std::shared_ptr<Choreographer> SurfaceControl::getChoreographer() {
    if (mChoreographer) {
        return mChoreographer;
    }
    sp<Looper> looper = Looper::getForThread();
    if (!looper.get()) {
        ALOGE("%s: No looper prepared for thread", __func__);
        return nullptr;
    }
    mChoreographer = std::make_shared<Choreographer>(looper, getHandle());
    status_t result = mChoreographer->initialize();
    if (result != OK) {
        ALOGE("Failed to initialize choreographer");
        mChoreographer = nullptr;
    }
    return mChoreographer;
}

sp<IGraphicBufferProducer> SurfaceControl::getIGraphicBufferProducer()
sp<IGraphicBufferProducer> SurfaceControl::getIGraphicBufferProducer()
{
{
    getSurface();
    getSurface();
+7 −1
Original line number Original line Diff line number Diff line
@@ -68,9 +68,15 @@ interface ISurfaceComposer {


    /**
    /**
     * Create a display event connection
     * Create a display event connection
     *
     * layerHandle
     *     Optional binder handle representing a Layer in SF to associate the new
     *     DisplayEventConnection with. This handle can be found inside a surface control after
     *     surface creation, see ISurfaceComposerClient::createSurface. Set to null if no layer
     *     association should be made.
     */
     */
    @nullable IDisplayEventConnection createDisplayEventConnection(VsyncSource vsyncSource,
    @nullable IDisplayEventConnection createDisplayEventConnection(VsyncSource vsyncSource,
            EventRegistration eventRegistration);
            EventRegistration eventRegistration, @nullable IBinder layerHandle);


    /**
    /**
     * Create a connection with SurfaceFlinger.
     * Create a connection with SurfaceFlinger.
Loading