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

Commit 969e8c36 authored by John Reck's avatar John Reck Committed by Android (Google) Code Review
Browse files

Merge "Move updating window position off RT" into nyc-dev

parents 62dfd5fe 38f6c034
Loading
Loading
Loading
Loading
+25 −12
Original line number Diff line number Diff line
@@ -28,6 +28,7 @@
#include <DamageAccumulator.h>
#include <Matrix.h>
#include <RenderNode.h>
#include <renderthread/CanvasContext.h>
#include <TreeInfo.h>
#include <Paint.h>

@@ -487,15 +488,7 @@ static void android_view_RenderNode_requestPositionUpdates(JNIEnv* env, jobject,

        virtual void onPositionUpdated(RenderNode& node, const TreeInfo& info) override {
            if (CC_UNLIKELY(!mWeakRef || !info.updateWindowPositions)) return;
            ATRACE_NAME("Update SurfaceView position");

            JNIEnv* env = jnienv();
            jobject localref = env->NewLocalRef(mWeakRef);
            if (CC_UNLIKELY(!localref)) {
                jnienv()->DeleteWeakGlobalRef(mWeakRef);
                mWeakRef = nullptr;
                return;
            }
            Matrix4 transform;
            info.damageAccumulator->computeCurrentTransform(&transform);
            const RenderProperties& props = node.properties();
@@ -505,10 +498,13 @@ static void android_view_RenderNode_requestPositionUpdates(JNIEnv* env, jobject,
            bounds.right -= info.windowInsetLeft;
            bounds.top -= info.windowInsetTop;
            bounds.bottom -= info.windowInsetTop;
            env->CallVoidMethod(localref, gSurfaceViewPositionUpdateMethod,

            auto functor = std::bind(
                std::mem_fn(&SurfaceViewPositionUpdater::doUpdatePosition), this,
                (jlong) info.frameNumber, (jint) bounds.left, (jint) bounds.top,
                (jint) bounds.right, (jint) bounds.bottom);
            env->DeleteLocalRef(localref);

            info.canvasContext.enqueueFrameWork(std::move(functor));
        }

    private:
@@ -520,6 +516,23 @@ static void android_view_RenderNode_requestPositionUpdates(JNIEnv* env, jobject,
            return env;
        }

        void doUpdatePosition(jlong frameNumber, jint left, jint top,
                jint right, jint bottom) {
            ATRACE_NAME("Update SurfaceView position");

            JNIEnv* env = jnienv();
            jobject localref = env->NewLocalRef(mWeakRef);
            if (CC_UNLIKELY(!localref)) {
                jnienv()->DeleteWeakGlobalRef(mWeakRef);
                mWeakRef = nullptr;
                return;
            }

            env->CallVoidMethod(localref, gSurfaceViewPositionUpdateMethod,
                    frameNumber, left, top, right, bottom);
            env->DeleteLocalRef(localref);
        }

        JavaVM* mVm;
        jobject mWeakRef;
    };
+33 −0
Original line number Diff line number Diff line
@@ -484,6 +484,8 @@ void CanvasContext::draw() {
    bool drew = mCanvas->finish();
#endif

    waitOnFences();

    GL_CHECKPOINT(LOW);

    // Even if we decided to cancel the frame, from the perspective of jank
@@ -726,6 +728,37 @@ void CanvasContext::serializeDisplayListTree() {
#endif
}

void CanvasContext::waitOnFences() {
    if (mFrameFences.size()) {
        ATRACE_CALL();
        for (auto& fence : mFrameFences) {
            fence->getResult();
        }
        mFrameFences.clear();
    }
}

class CanvasContext::FuncTaskProcessor : public TaskProcessor<bool> {
public:
    FuncTaskProcessor(Caches& caches)
            : TaskProcessor<bool>(&caches.tasks) {}

    virtual void onProcess(const sp<Task<bool> >& task) override {
        FuncTask* t = static_cast<FuncTask*>(task.get());
        t->func();
        task->setResult(true);
    }
};

void CanvasContext::enqueueFrameWork(std::function<void()>&& func) {
    if (!mFrameWorkProcessor.get()) {
        mFrameWorkProcessor = new FuncTaskProcessor(Caches::getInstance());
    }
    sp<FuncTask> task(new FuncTask());
    task->func = func;
    mFrameWorkProcessor->add(task);
}

} /* namespace renderthread */
} /* namespace uirenderer */
} /* namespace android */
+18 −0
Original line number Diff line number Diff line
@@ -24,6 +24,8 @@
#include "IContextFactory.h"
#include "LayerUpdateQueue.h"
#include "RenderNode.h"
#include "thread/Task.h"
#include "thread/TaskProcessor.h"
#include "utils/RingBuffer.h"
#include "renderthread/RenderTask.h"
#include "renderthread/RenderThread.h"
@@ -41,6 +43,7 @@
#include <utils/Functor.h>
#include <gui/Surface.h>

#include <functional>
#include <set>
#include <string>
#include <vector>
@@ -159,6 +162,9 @@ public:
        }
    }

    // Used to queue up work that needs to be completed before this frame completes
    ANDROID_API void enqueueFrameWork(std::function<void()>&& func);

private:
    friend class RegisterFrameCallbackTask;
    // TODO: Replace with something better for layer & other GL object
@@ -170,6 +176,8 @@ private:

    void freePrefetechedLayers();

    void waitOnFences();

    EGLint mLastFrameWidth = 0;
    EGLint mLastFrameHeight = 0;

@@ -213,6 +221,16 @@ private:

    // Stores the bounds of the main content.
    Rect mContentDrawBounds;

    // TODO: This is really a Task<void> but that doesn't really work
    // when Future<> expects to be able to get/set a value
    struct FuncTask : public Task<bool> {
        std::function<void()> func;
    };
    class FuncTaskProcessor;

    std::vector< sp<FuncTask> > mFrameFences;
    sp<TaskProcessor<bool> > mFrameWorkProcessor;
};

} /* namespace renderthread */
+0 −5
Original line number Diff line number Diff line
@@ -33,11 +33,6 @@ public:
        mCondition.signal(mType);
    }

    void close() {
        Mutex::Autolock l(mLock);
        mOpened = false;
    }

    void wait() const {
        Mutex::Autolock l(mLock);
        while (!mOpened) {