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

Commit 8319a7ee authored by TreeHugger Robot's avatar TreeHugger Robot Committed by Android (Google) Code Review
Browse files

Merge "Plumb new functor in native/webview"

parents c54ffd28 d6668e7c
Loading
Loading
Loading
Loading
+1 −0
Original line number Diff line number Diff line
@@ -7983,6 +7983,7 @@ package android.webkit {
    method public void callDrawGlFunction(android.graphics.Canvas, long, java.lang.Runnable);
    method public boolean canInvokeDrawGlFunctor(android.view.View);
    method public void detachDrawGlFunctor(android.view.View, long);
    method public void drawWebViewFunctor(android.graphics.Canvas, int);
    method public android.app.Application getApplication();
    method public java.lang.String getDataDirectorySuffix();
    method public java.lang.String getErrorString(android.content.Context, int);
+14 −0
Original line number Diff line number Diff line
@@ -137,6 +137,20 @@ public final class WebViewDelegate {
        ((RecordingCanvas) canvas).drawGLFunctor2(nativeDrawGLFunctor, releasedRunnable);
    }

    /**
     * Call webview draw functor. See API in draw_fn.h.
     * @param canvas a hardware accelerated canvas (see {@link Canvas#isHardwareAccelerated()}).
     * @param functor created by AwDrawFn_CreateFunctor in draw_fn.h.
     */
    public void drawWebViewFunctor(@NonNull Canvas canvas, int functor) {
        if (!(canvas instanceof RecordingCanvas)) {
            // Canvas#isHardwareAccelerated() is only true for subclasses of RecordingCanvas.
            throw new IllegalArgumentException(canvas.getClass().getName()
                    + " is not a RecordingCanvas canvas");
        }
        ((RecordingCanvas) canvas).drawWebViewFunctor(functor);
    }

    /**
     * Detaches the draw GL functor.
     *
+13 −10
Original line number Diff line number Diff line
@@ -37,7 +37,8 @@ RenderMode WebViewFunctor_queryPlatformRenderMode() {
    }
}

int WebViewFunctor_create(const WebViewFunctorCallbacks& prototype, RenderMode functorMode) {
int WebViewFunctor_create(void* data, const WebViewFunctorCallbacks& prototype,
                          RenderMode functorMode) {
    if (functorMode != RenderMode::OpenGL_ES && functorMode != RenderMode::Vulkan) {
        ALOGW("Unknown rendermode %d", (int)functorMode);
        return -1;
@@ -47,7 +48,7 @@ int WebViewFunctor_create(const WebViewFunctorCallbacks& prototype, RenderMode f
        ALOGW("Unable to map from GLES platform to a vulkan functor");
        return -1;
    }
    return WebViewFunctorManager::instance().createFunctor(prototype, functorMode);
    return WebViewFunctorManager::instance().createFunctor(data, prototype, functorMode);
}

void WebViewFunctor_release(int functor) {
@@ -56,7 +57,9 @@ void WebViewFunctor_release(int functor) {

static std::atomic_int sNextId{1};

WebViewFunctor::WebViewFunctor(const WebViewFunctorCallbacks& callbacks, RenderMode functorMode) {
WebViewFunctor::WebViewFunctor(void* data, const WebViewFunctorCallbacks& callbacks,
                               RenderMode functorMode)
        : mData(data) {
    mFunctor = sNextId++;
    mCallbacks = callbacks;
    mMode = functorMode;
@@ -66,12 +69,12 @@ WebViewFunctor::~WebViewFunctor() {
    destroyContext();

    ATRACE_NAME("WebViewFunctor::onDestroy");
    mCallbacks.onDestroyed(mFunctor);
    mCallbacks.onDestroyed(mFunctor, mData);
}

void WebViewFunctor::sync(const WebViewSyncData& syncData) const {
    ATRACE_NAME("WebViewFunctor::sync");
    mCallbacks.onSync(mFunctor, syncData);
    mCallbacks.onSync(mFunctor, mData, syncData);
}

void WebViewFunctor::drawGl(const DrawGlInfo& drawInfo) {
@@ -79,14 +82,14 @@ void WebViewFunctor::drawGl(const DrawGlInfo& drawInfo) {
    if (!mHasContext) {
        mHasContext = true;
    }
    mCallbacks.gles.draw(mFunctor, drawInfo);
    mCallbacks.gles.draw(mFunctor, mData, drawInfo);
}

void WebViewFunctor::destroyContext() {
    if (mHasContext) {
        mHasContext = false;
        ATRACE_NAME("WebViewFunctor::onContextDestroyed");
        mCallbacks.onContextDestroyed(mFunctor);
        mCallbacks.onContextDestroyed(mFunctor, mData);
    }
}

@@ -95,9 +98,9 @@ WebViewFunctorManager& WebViewFunctorManager::instance() {
    return sInstance;
}

int WebViewFunctorManager::createFunctor(const WebViewFunctorCallbacks& callbacks,
int WebViewFunctorManager::createFunctor(void* data, const WebViewFunctorCallbacks& callbacks,
                                         RenderMode functorMode) {
    auto object = std::make_unique<WebViewFunctor>(callbacks, functorMode);
    auto object = std::make_unique<WebViewFunctor>(data, callbacks, functorMode);
    int id = object->id();
    auto handle = object->createHandle();
    {
+3 −2
Original line number Diff line number Diff line
@@ -29,7 +29,7 @@ class WebViewFunctorManager;

class WebViewFunctor {
public:
    WebViewFunctor(const WebViewFunctorCallbacks& callbacks, RenderMode functorMode);
    WebViewFunctor(void* data, const WebViewFunctorCallbacks& callbacks, RenderMode functorMode);
    ~WebViewFunctor();

    class Handle : public LightRefBase<Handle> {
@@ -63,6 +63,7 @@ public:

private:
    WebViewFunctorCallbacks mCallbacks;
    void* const mData;
    int mFunctor;
    RenderMode mMode;
    bool mHasContext = false;
@@ -73,7 +74,7 @@ class WebViewFunctorManager {
public:
    static WebViewFunctorManager& instance();

    int createFunctor(const WebViewFunctorCallbacks& callbacks, RenderMode functorMode);
    int createFunctor(void* data, const WebViewFunctorCallbacks& callbacks, RenderMode functorMode);
    void releaseFunctor(int functor);
    void onContextDestroyed();
    void destroyFunctor(int functor);
+8 −7
Original line number Diff line number Diff line
@@ -17,6 +17,7 @@
#ifndef FRAMEWORKS_BASE_WEBVIEWFUNCTOR_H
#define FRAMEWORKS_BASE_WEBVIEWFUNCTOR_H

#include <cutils/compiler.h>
#include <private/hwui/DrawGlInfo.h>

namespace android::uirenderer {
@@ -27,7 +28,7 @@ enum class RenderMode {
};

// Static for the lifetime of the process
RenderMode WebViewFunctor_queryPlatformRenderMode();
ANDROID_API RenderMode WebViewFunctor_queryPlatformRenderMode();

struct WebViewSyncData {
    bool applyForceDark;
@@ -35,21 +36,21 @@ struct WebViewSyncData {

struct WebViewFunctorCallbacks {
    // kModeSync, called on RenderThread
    void (*onSync)(int functor, const WebViewSyncData& syncData);
    void (*onSync)(int functor, void* data, const WebViewSyncData& syncData);

    // Called when either the context is destroyed _or_ when the functor's last reference goes
    // away. Will always be called with an active context and always on renderthread.
    void (*onContextDestroyed)(int functor);
    void (*onContextDestroyed)(int functor, void* data);

    // Called when the last reference to the handle goes away and the handle is considered
    // irrevocably destroyed. Will always be proceeded by a call to onContextDestroyed if
    // this functor had ever been drawn.
    void (*onDestroyed)(int functor);
    void (*onDestroyed)(int functor, void* data);

    union {
        struct {
            // Called on RenderThread. initialize is guaranteed to happen before this call
            void (*draw)(int functor, const DrawGlInfo& params);
            void (*draw)(int functor, void* data, const DrawGlInfo& params);
        } gles;
        // TODO: VK support. The current DrawVkInfo is monolithic and needs to be split up for
        // what params are valid on what callbacks
@@ -70,12 +71,12 @@ struct WebViewFunctorCallbacks {
// Creates a new WebViewFunctor from the given prototype. The prototype is copied after
// this function returns. Caller retains full ownership of it.
// Returns -1 if the creation fails (such as an unsupported functorMode + platform mode combination)
int WebViewFunctor_create(const WebViewFunctorCallbacks& prototype, RenderMode functorMode);
ANDROID_API int WebViewFunctor_create(void* data, const WebViewFunctorCallbacks& prototype, RenderMode functorMode);

// May be called on any thread to signal that the functor should be destroyed.
// The functor will receive an onDestroyed when the last usage of it is released,
// and it should be considered alive & active until that point.
void WebViewFunctor_release(int functor);
ANDROID_API void WebViewFunctor_release(int functor);

}  // namespace android::uirenderer

Loading