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

Commit 5e86147a authored by Treehugger Robot's avatar Treehugger Robot Committed by Gerrit Code Review
Browse files

Merge "Remove EGL Hibernation"

parents 8fee4017 199adbc1
Loading
Loading
Loading
Loading
+0 −3
Original line number Diff line number Diff line
@@ -42,9 +42,6 @@ LOCAL_CFLAGS += -DLOG_TAG=\"libEGL\"
LOCAL_CFLAGS += -DGL_GLEXT_PROTOTYPES -DEGL_EGLEXT_PROTOTYPES
LOCAL_CFLAGS += -fvisibility=hidden

ifeq ($(BOARD_ALLOW_EGL_HIBERNATION),true)
  LOCAL_CFLAGS += -DBOARD_ALLOW_EGL_HIBERNATION
endif
ifneq ($(MAX_EGL_CACHE_ENTRY_SIZE),)
  LOCAL_CFLAGS += -DMAX_EGL_CACHE_ENTRY_SIZE=$(MAX_EGL_CACHE_ENTRY_SIZE)
endif
+0 −66
Original line number Diff line number Diff line
@@ -212,8 +212,6 @@ EGLBoolean egl_display_t::initialize(EGLint *major, EGLint *minor) {
            *major = VERSION_MAJOR;
        if (minor != NULL)
            *minor = VERSION_MINOR;

        mHibernation.setDisplayValid(true);
    }

    {
@@ -262,8 +260,6 @@ EGLBoolean egl_display_t::terminate() {
            res = EGL_TRUE;
        }

        mHibernation.setDisplayValid(false);

        // Reset the extension string since it will be regenerated if we get
        // reinitialized.
        mExtensionString.setTo("");
@@ -342,16 +338,12 @@ EGLBoolean egl_display_t::makeCurrent(egl_context_t* c, egl_context_t* cur_c,
                    disp.dpy, impl_draw, impl_read, impl_ctx);
            if (result == EGL_TRUE) {
                c->onMakeCurrent(draw, read);
                if (!cur_c) {
                    mHibernation.incWakeCount(HibernationMachine::STRONG);
                }
            }
        } else {
            result = cur_c->cnx->egl.eglMakeCurrent(
                    disp.dpy, impl_draw, impl_read, impl_ctx);
            if (result == EGL_TRUE) {
                cur_c->onLooseCurrent();
                mHibernation.decWakeCount(HibernationMachine::STRONG);
            }
        }
    }
@@ -375,64 +367,6 @@ bool egl_display_t::haveExtension(const char* name, size_t nameLen) const {
    return findExtension(mExtensionString.string(), name, nameLen);
}

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

bool egl_display_t::HibernationMachine::incWakeCount(WakeRefStrength strength) {
    Mutex::Autolock _l(mLock);
    ALOGE_IF(mWakeCount < 0 || mWakeCount == INT32_MAX,
             "Invalid WakeCount (%d) on enter\n", mWakeCount);

    mWakeCount++;
    if (strength == STRONG)
        mAttemptHibernation = false;

    if (CC_UNLIKELY(mHibernating)) {
        ALOGV("Awakening\n");
        egl_connection_t* const cnx = &gEGLImpl;

        // These conditions should be guaranteed before entering hibernation;
        // we don't want to get into a state where we can't wake up.
        ALOGD_IF(!mDpyValid || !cnx->egl.eglAwakenProcessIMG,
                 "Invalid hibernation state, unable to awaken\n");

        if (!cnx->egl.eglAwakenProcessIMG()) {
            ALOGE("Failed to awaken EGL implementation\n");
            return false;
        }
        mHibernating = false;
    }
    return true;
}

void egl_display_t::HibernationMachine::decWakeCount(WakeRefStrength strength) {
    Mutex::Autolock _l(mLock);
    ALOGE_IF(mWakeCount <= 0, "Invalid WakeCount (%d) on leave\n", mWakeCount);

    mWakeCount--;
    if (strength == STRONG)
        mAttemptHibernation = true;

    if (mWakeCount == 0 && CC_UNLIKELY(mAttemptHibernation)) {
        egl_connection_t* const cnx = &gEGLImpl;
        mAttemptHibernation = false;
        if (mAllowHibernation && mDpyValid &&
                cnx->egl.eglHibernateProcessIMG &&
                cnx->egl.eglAwakenProcessIMG) {
            ALOGV("Hibernating\n");
            if (!cnx->egl.eglHibernateProcessIMG()) {
                ALOGE("Failed to hibernate EGL implementation\n");
                return;
            }
            mHibernating = true;
        }
    }
}

void egl_display_t::HibernationMachine::setDisplayValid(bool valid) {
    Mutex::Autolock _l(mLock);
    mDpyValid = valid;
}

// ----------------------------------------------------------------------------
}; // namespace android
// ----------------------------------------------------------------------------
+4 −75
Original line number Diff line number Diff line
@@ -68,20 +68,6 @@ public:
    // add reference to this object. returns true if this is a valid object.
    bool getObject(egl_object_t* object) const;

    // These notifications allow the display to keep track of how many window
    // surfaces exist, which it uses to decide whether to hibernate the
    // underlying EGL implementation. They can be called by any thread without
    // holding a lock, but must be called via egl_display_ptr to ensure
    // proper hibernate/wakeup sequencing. If a surface destruction triggers
    // hibernation, hibernation will be delayed at least until the calling
    // thread's egl_display_ptr is destroyed.
    void onWindowSurfaceCreated() {
        mHibernation.incWakeCount(HibernationMachine::STRONG);
    }
    void onWindowSurfaceDestroyed() {
        mHibernation.decWakeCount(HibernationMachine::STRONG);
    }

    static egl_display_t* get(EGLDisplay dpy);
    static EGLDisplay getFromNativeDisplay(EGLNativeDisplayType disp);

@@ -127,8 +113,6 @@ public:

private:
    friend class egl_display_ptr;
    bool enter() { return mHibernation.incWakeCount(HibernationMachine::WEAK); }
    void leave() { return mHibernation.decWakeCount(HibernationMachine::WEAK); }

            uint32_t                    refs;
            bool                        eglIsInitialized;
@@ -139,47 +123,6 @@ private:
            String8 mVersionString;
            String8 mClientApiString;
            String8 mExtensionString;

    // HibernationMachine uses its own internal mutex to protect its own data.
    // The owning egl_display_t's lock may be but is not required to be held
    // when calling HibernationMachine methods. As a result, nothing in this
    // class may call back up to egl_display_t directly or indirectly.
    class HibernationMachine {
    public:
        // STRONG refs cancel (inc) or initiate (dec) a hibernation attempt
        // the next time the wakecount reaches zero. WEAK refs don't affect
        // whether a hibernation attempt will be made. Use STRONG refs only
        // for infrequent/heavy changes that are likely to indicate the
        // EGLDisplay is entering or leaving a long-term idle state.
        enum WakeRefStrength {
            WEAK   = 0,
            STRONG = 1,
        };

        HibernationMachine(): mWakeCount(0), mHibernating(false),
                mAttemptHibernation(false), mDpyValid(false),
#if BOARD_ALLOW_EGL_HIBERNATION
                mAllowHibernation(true)
#else
                mAllowHibernation(false)
#endif
        {}
        ~HibernationMachine() {}

        bool incWakeCount(WakeRefStrength strenth);
        void decWakeCount(WakeRefStrength strenth);

        void setDisplayValid(bool valid);

    private:
        Mutex      mLock;
        int32_t    mWakeCount;
        bool       mHibernating;
        bool       mAttemptHibernation;
        bool       mDpyValid;
        const bool mAllowHibernation;
    };
    HibernationMachine mHibernation;
};

// ----------------------------------------------------------------------------
@@ -190,13 +133,7 @@ private:
// as the egl_display_ptr exists.
class egl_display_ptr {
public:
    explicit egl_display_ptr(egl_display_t* dpy): mDpy(dpy) {
        if (mDpy) {
            if (CC_UNLIKELY(!mDpy->enter())) {
                mDpy = NULL;
            }
        }
    }
    explicit egl_display_ptr(egl_display_t* dpy): mDpy(dpy) {}

    // We only really need a C++11 move constructor, not a copy constructor.
    // A move constructor would save an enter()/leave() pair on every EGL API
@@ -208,17 +145,9 @@ public:
    //     other.mDpy = NULL;
    // }
    //
    egl_display_ptr(const egl_display_ptr& other): mDpy(other.mDpy) {
        if (mDpy) {
            mDpy->enter();
        }
    }
    egl_display_ptr(const egl_display_ptr& other): mDpy(other.mDpy) {}

    ~egl_display_ptr() {
        if (mDpy) {
            mDpy->leave();
        }
    }
    ~egl_display_ptr() {}

    const egl_display_t* operator->() const { return mDpy; }
          egl_display_t* operator->()       { return mDpy; }
+1 −6
Original line number Diff line number Diff line
@@ -69,17 +69,12 @@ egl_surface_t::egl_surface_t(egl_display_t* dpy, EGLConfig config,
        egl_connection_t const* cnx) :
    egl_object_t(dpy), surface(surface), config(config), win(win), cnx(cnx),
    connected(true)
{
    if (win) {
        getDisplay()->onWindowSurfaceCreated();
    }
}
{}

egl_surface_t::~egl_surface_t() {
    ANativeWindow* const window = win.get();
    if (window != NULL) {
        disconnect();
        getDisplay()->onWindowSurfaceDestroyed();
    }
}