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

Commit 9a7fa83b authored by John Reck's avatar John Reck Committed by android-build-merger
Browse files

Merge "Add a callback for when a gl functor is released" into nyc-dev am: 85cfc8c3

am: 9e06acf3

* commit '9e06acf3':
  Add a callback for when a gl functor is released

Change-Id: I4f3d272a598f45a6124a6fc64f9178f1c4d659a0
parents 92683084 9e06acf3
Loading
Loading
Loading
Loading
+21 −5
Original line number Diff line number Diff line
@@ -163,17 +163,33 @@ public class DisplayListCanvas extends Canvas {
    ///////////////////////////////////////////////////////////////////////////

    /**
     * Calls the function specified with the drawGLFunction function pointer. This is
     * functionality used by webkit for calling into their renderer from our display lists.
     * This function may return true if an invalidation is needed after the call.
     * Records the functor specified with the drawGLFunction function pointer. This is
     * functionality used by webview for calling into their renderer from our display lists.
     *
     * @param drawGLFunction A native function pointer
     */
    public void callDrawGLFunction2(long drawGLFunction) {
        nCallDrawGLFunction(mNativeCanvasWrapper, drawGLFunction);
        nCallDrawGLFunction(mNativeCanvasWrapper, drawGLFunction, null);
    }

    private static native void nCallDrawGLFunction(long renderer, long drawGLFunction);
    /**
     * Records the functor specified with the drawGLFunction function pointer. This is
     * functionality used by webview for calling into their renderer from our display lists.
     *
     * @param drawGLFunction A native function pointer
     * @param releasedCallback Called when the display list is destroyed, and thus
     * the functor is no longer referenced by this canvas's display list.
     *
     * NOTE: The callback does *not* necessarily mean that there are no longer
     * any references to the functor, just that the reference from this specific
     * canvas's display list has been released.
     */
    public void drawGLFunctor2(long drawGLFunctor, Runnable releasedCallback) {
        nCallDrawGLFunction(mNativeCanvasWrapper, drawGLFunctor, releasedCallback);
    }

    private static native void nCallDrawGLFunction(long renderer,
            long drawGLFunction, Runnable releasedCallback);

    ///////////////////////////////////////////////////////////////////////////
    // Display list
+56 −4
Original line number Diff line number Diff line
@@ -22,12 +22,12 @@

#include <android_runtime/AndroidRuntime.h>

#include <utils/Looper.h>
#include <cutils/properties.h>

#include <SkBitmap.h>
#include <SkRegion.h>


#include <Rect.h>
#include <RenderNode.h>
#include <CanvasProperty.h>
@@ -41,6 +41,52 @@ namespace android {

using namespace uirenderer;

jmethodID gRunnableMethodId;

static JNIEnv* jnienv(JavaVM* vm) {
    JNIEnv* env;
    if (vm->GetEnv(reinterpret_cast<void**>(&env), JNI_VERSION_1_6) != JNI_OK) {
        LOG_ALWAYS_FATAL("Failed to get JNIEnv for JavaVM: %p", vm);
    }
    return env;
}

class InvokeRunnableMessage : public MessageHandler {
public:
    InvokeRunnableMessage(JNIEnv* env, jobject runnable) {
        mRunnable = env->NewGlobalRef(runnable);
        env->GetJavaVM(&mVm);
    }

    virtual ~InvokeRunnableMessage() {
        jnienv(mVm)->DeleteGlobalRef(mRunnable);
    }

    virtual void handleMessage(const Message&) {
        jnienv(mVm)->CallVoidMethod(mRunnable, gRunnableMethodId);
    }

private:
    JavaVM* mVm;
    jobject mRunnable;
};

class GlFunctorReleasedCallbackBridge : public GlFunctorLifecycleListener {
public:
    GlFunctorReleasedCallbackBridge(JNIEnv* env, jobject javaCallback) {
        mLooper = Looper::getForThread();
        mMessage = new InvokeRunnableMessage(env, javaCallback);
    }

    virtual void onGlFunctorReleased(Functor* functor) override {
        mLooper->sendMessage(mMessage, 0);
    }

private:
    sp<Looper> mLooper;
    sp<InvokeRunnableMessage> mMessage;
};

// ----------------------------------------------------------------------------
// Setup
// ----------------------------------------------------------------------------
@@ -56,10 +102,12 @@ static void android_view_DisplayListCanvas_insertReorderBarrier(JNIEnv* env, job
// ----------------------------------------------------------------------------

static void android_view_DisplayListCanvas_callDrawGLFunction(JNIEnv* env, jobject clazz,
        jlong canvasPtr, jlong functorPtr) {
        jlong canvasPtr, jlong functorPtr, jobject releasedCallback) {
    Canvas* canvas = reinterpret_cast<Canvas*>(canvasPtr);
    Functor* functor = reinterpret_cast<Functor*>(functorPtr);
    canvas->callDrawGLFunction(functor);
    sp<GlFunctorReleasedCallbackBridge> bridge(new GlFunctorReleasedCallbackBridge(
            env, releasedCallback));
    canvas->callDrawGLFunction(functor, bridge.get());
}

// ----------------------------------------------------------------------------
@@ -184,7 +232,8 @@ static JNINativeMethod gMethods[] = {
    { "nIsAvailable",       "!()Z",             (void*) android_view_DisplayListCanvas_isAvailable },
    { "nInsertReorderBarrier","!(JZ)V",         (void*) android_view_DisplayListCanvas_insertReorderBarrier },

    { "nCallDrawGLFunction", "!(JJ)V",          (void*) android_view_DisplayListCanvas_callDrawGLFunction },
    { "nCallDrawGLFunction", "!(JJLjava/lang/Runnable;)V",
            (void*) android_view_DisplayListCanvas_callDrawGLFunction },

    { "nDrawRoundRect",     "!(JJJJJJJJ)V",     (void*) android_view_DisplayListCanvas_drawRoundRectProps },
    { "nDrawCircle",        "!(JJJJJ)V",        (void*) android_view_DisplayListCanvas_drawCircleProps },
@@ -207,6 +256,9 @@ static JNINativeMethod gActivityThreadMethods[] = {
};

int register_android_view_DisplayListCanvas(JNIEnv* env) {
    jclass runnableClass = FindClassOrDie(env, "java/lang/Runnable");
    gRunnableMethodId = GetMethodIDOrDie(env, runnableClass, "run", "()V");

    return RegisterMethodsOrDie(env, kClassPathName, gMethods, NELEM(gMethods));
}

+6 −0
Original line number Diff line number Diff line
@@ -73,6 +73,12 @@ void DisplayList::cleanupResources() {
        delete path;
    }

    for (auto& iter : functors) {
        if (iter.listener) {
            iter.listener->onGlFunctorReleased(iter.functor);
        }
    }

    patchResources.clear();
    pathResources.clear();
    paints.clear();
+8 −2
Original line number Diff line number Diff line
@@ -35,6 +35,7 @@
#include "Debug.h"
#include "CanvasProperty.h"
#include "DeferredDisplayList.h"
#include "GlFunctorLifecycleListener.h"
#include "Matrix.h"
#include "RenderProperties.h"

@@ -119,6 +120,11 @@ struct PushStagingFunctor {
    virtual void operator ()() {}
};

struct FunctorContainer {
    Functor* functor;
    GlFunctorLifecycleListener* listener;
};

/**
 * Data structure that holds the list of commands used in display list stream
 */
@@ -154,7 +160,7 @@ public:
    const LsaVector<NodeOpType*>& getChildren() const { return children; }

    const LsaVector<const SkBitmap*>& getBitmapResources() const { return bitmapResources; }
    const LsaVector<Functor*>& getFunctors() const { return functors; }
    const LsaVector<FunctorContainer>& getFunctors() const { return functors; }
    const LsaVector<PushStagingFunctor*>& getPushStagingFunctors() { return pushStagingFunctors; }

    size_t addChild(NodeOpType* childOp);
@@ -195,7 +201,7 @@ private:
    LsaVector< sp<VirtualLightRefBase> > referenceHolders;

    // List of functors
    LsaVector<Functor*> functors;
    LsaVector<FunctorContainer> functors;

    // List of functors that need to be notified of pushStaging. Note that this list gets nothing
    // but a callback during sync DisplayList, unlike the list of functors defined above, which
+4 −2
Original line number Diff line number Diff line
@@ -81,9 +81,11 @@ DisplayList* DisplayListCanvas::finishRecording() {
    return displayList;
}

void DisplayListCanvas::callDrawGLFunction(Functor *functor) {
void DisplayListCanvas::callDrawGLFunction(Functor* functor,
        GlFunctorLifecycleListener* listener) {
    addDrawOp(new (alloc()) DrawFunctorOp(functor));
    mDisplayList->functors.push_back(functor);
    mDisplayList->functors.push_back({functor, listener});
    mDisplayList->ref(listener);
}

SkCanvas* DisplayListCanvas::asSkCanvas() {
Loading