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

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

Merge "Make attachFunctor blocking"

parents 4b1a7c20 d3d8dafc
Loading
Loading
Loading
Loading
+2 −4
Original line number Diff line number Diff line
@@ -190,12 +190,12 @@ public class ThreadedRenderer extends HardwareRenderer {

    @Override
    void detachFunctor(long functor) {
        nDetachFunctor(mNativeProxy, functor);
        // no-op, we never attach functors to need to detach them
    }

    @Override
    void attachFunctor(AttachInfo attachInfo, long functor) {
        nAttachFunctor(mNativeProxy, functor);
        invokeFunctor(functor, true);
    }

    @Override
@@ -289,8 +289,6 @@ public class ThreadedRenderer extends HardwareRenderer {
    private static native void nRunWithGlContext(long nativeProxy, Runnable runnable);
    private static native void nDestroyCanvas(long nativeProxy);

    private static native void nAttachFunctor(long nativeProxy, long functor);
    private static native void nDetachFunctor(long nativeProxy, long functor);
    private static native void nInvokeFunctor(long nativeProxy, long functor, boolean waitForCompletion);

    private static native long nCreateDisplayListLayer(long nativeProxy, int width, int height);
+0 −16
Original line number Diff line number Diff line
@@ -127,20 +127,6 @@ static void android_view_ThreadedRenderer_destroyCanvas(JNIEnv* env, jobject cla
    proxy->destroyCanvas();
}

static void android_view_ThreadedRenderer_attachFunctor(JNIEnv* env, jobject clazz,
        jlong proxyPtr, jlong functorPtr) {
    RenderProxy* proxy = reinterpret_cast<RenderProxy*>(proxyPtr);
    Functor* functor = reinterpret_cast<Functor*>(functorPtr);
    proxy->attachFunctor(functor);
}

static void android_view_ThreadedRenderer_detachFunctor(JNIEnv* env, jobject clazz,
        jlong proxyPtr, jlong functorPtr) {
    RenderProxy* proxy = reinterpret_cast<RenderProxy*>(proxyPtr);
    Functor* functor = reinterpret_cast<Functor*>(functorPtr);
    proxy->detachFunctor(functor);
}

static void android_view_ThreadedRenderer_invokeFunctor(JNIEnv* env, jobject clazz,
        jlong proxyPtr, jlong functorPtr, jboolean waitForCompletion) {
    RenderProxy* proxy = reinterpret_cast<RenderProxy*>(proxyPtr);
@@ -209,8 +195,6 @@ static JNINativeMethod gMethods[] = {
    { "nSetup", "(JII)V", (void*) android_view_ThreadedRenderer_setup },
    { "nDrawDisplayList", "(JJIIII)V", (void*) android_view_ThreadedRenderer_drawDisplayList },
    { "nDestroyCanvas", "(J)V", (void*) android_view_ThreadedRenderer_destroyCanvas },
    { "nAttachFunctor", "(JJ)V", (void*) android_view_ThreadedRenderer_attachFunctor },
    { "nDetachFunctor", "(JJ)V", (void*) android_view_ThreadedRenderer_detachFunctor },
    { "nInvokeFunctor", "(JJZ)V", (void*) android_view_ThreadedRenderer_invokeFunctor },
    { "nRunWithGlContext", "(JLjava/lang/Runnable;)V", (void*) android_view_ThreadedRenderer_runWithGlContext },
    { "nCreateDisplayListLayer", "(JII)J", (void*) android_view_ThreadedRenderer_createDisplayListLayer },
+6 −47
Original line number Diff line number Diff line
@@ -313,14 +313,11 @@ CanvasContext::CanvasContext(bool translucent)
        , mDirtyRegionsEnabled(false)
        , mOpaque(!translucent)
        , mCanvas(0)
        , mHaveNewSurface(false)
        , mInvokeFunctorsPending(false)
        , mInvokeFunctorsTask(this) {
        , mHaveNewSurface(false) {
    mGlobalContext = GlobalContext::get();
}

CanvasContext::~CanvasContext() {
    removeFunctorsTask();
    destroyCanvas();
}

@@ -432,55 +429,17 @@ void CanvasContext::drawDisplayList(RenderNode* displayList, Rect* dirty) {
    }
}

void InvokeFunctorsTask::run() {
    mContext->invokeFunctors();
}

void CanvasContext::attachFunctor(Functor* functor) {
    if (!mCanvas) return;

    mCanvas->attachFunctor(functor);
    removeFunctorsTask();
    queueFunctorsTask(0);
}

void CanvasContext::detachFunctor(Functor* functor) {
    if (!mCanvas) return;

    mCanvas->detachFunctor(functor);
}

void CanvasContext::invokeFunctor(Functor* functor) {
    ATRACE_CALL();
    DrawGlInfo::Mode mode = DrawGlInfo::kModeProcessNoContext;
    if (mGlobalContext->hasContext()) {
        requireGlContext();
        mode = DrawGlInfo::kModeProcess;
    }
    (*functor)(mode, NULL);
}

void CanvasContext::invokeFunctors() {
    mInvokeFunctorsPending = false;

    if (!mCanvas) return;

    requireSurface();
    Rect dirty;
    mCanvas->invokeFunctors(dirty);
}

void CanvasContext::removeFunctorsTask() {
    if (!mInvokeFunctorsPending) return;

    mInvokeFunctorsPending = false;
    mRenderThread.remove(&mInvokeFunctorsTask);
}

void CanvasContext::queueFunctorsTask(int delayMs) {
    if (mInvokeFunctorsPending) return;

    mInvokeFunctorsPending = true;
    mRenderThread.queueDelayed(&mInvokeFunctorsTask, delayMs);
    // TODO: Remove the dummy info in the future
    DrawGlInfo dummyInfo;
    memset(&dummyInfo, 0, sizeof(DrawGlInfo));
    (*functor)(mode, &dummyInfo);
}

bool CanvasContext::copyLayerInto(DeferredLayerUpdater* layer, SkBitmap* bitmap) {
+0 −22
Original line number Diff line number Diff line
@@ -43,17 +43,6 @@ class GlobalContext;
class CanvasContext;
class RenderThread;

class InvokeFunctorsTask : public RenderTask {
public:
    InvokeFunctorsTask(CanvasContext* context)
        : mContext(context) {}

    virtual void run();

private:
    CanvasContext* mContext;
};

// This per-renderer class manages the bridge between the global EGL context
// and the render surface.
class CanvasContext {
@@ -71,8 +60,6 @@ public:

    bool copyLayerInto(DeferredLayerUpdater* layer, SkBitmap* bitmap);

    void attachFunctor(Functor* functor);
    void detachFunctor(Functor* functor);
    void invokeFunctor(Functor* functor);

    void runWithGlContext(RenderTask* task);
@@ -85,11 +72,6 @@ private:
    void swapBuffers();
    void requireSurface();

    friend class InvokeFunctorsTask;
    void invokeFunctors();
    void removeFunctorsTask();
    void queueFunctorsTask(int delayMs = FUNCTOR_PROCESS_DELAY);

    void requireGlContext();

    GlobalContext* mGlobalContext;
@@ -100,10 +82,6 @@ private:
    bool mOpaque;
    OpenGLRenderer* mCanvas;
    bool mHaveNewSurface;

    bool mInvokeFunctorsPending;
    InvokeFunctorsTask mInvokeFunctorsTask;

};

} /* namespace renderthread */
+1 −24
Original line number Diff line number Diff line
@@ -151,36 +151,13 @@ void RenderProxy::destroyCanvas() {
    post(task);
}

CREATE_BRIDGE2(attachFunctor, CanvasContext* context, Functor* functor) {
    args->context->attachFunctor(args->functor);
    return NULL;
}

void RenderProxy::attachFunctor(Functor* functor) {
    SETUP_TASK(attachFunctor);
    args->context = mContext;
    args->functor = functor;
    post(task);
}

CREATE_BRIDGE2(detachFunctor, CanvasContext* context, Functor* functor) {
    args->context->detachFunctor(args->functor);
    return NULL;
}

void RenderProxy::detachFunctor(Functor* functor) {
    SETUP_TASK(detachFunctor);
    args->context = mContext;
    args->functor = functor;
    post(task);
}

CREATE_BRIDGE2(invokeFunctor, CanvasContext* context, Functor* functor) {
    args->context->invokeFunctor(args->functor);
    return NULL;
}

void RenderProxy::invokeFunctor(Functor* functor, bool waitForCompletion) {
    ATRACE_CALL();
    SETUP_TASK(invokeFunctor);
    args->context = mContext;
    args->functor = functor;
Loading