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

Commit f66f9e29 authored by Treehugger Robot's avatar Treehugger Robot Committed by Android (Google) Code Review
Browse files

Merge "Call libgui's SurfaceControl directly in hwui" into main

parents 6454e98e 55fa23d6
Loading
Loading
Loading
Loading
+1 −0
Original line number Diff line number Diff line
@@ -139,6 +139,7 @@ cc_defaults {
                "libandroidfw",
                "libcrypto",
                "libsync",
                "libgui",
                "libui",
                "aconfig_text_flags_c_lib",
                "aconfig_view_accessibility_flags_c_lib",
+24 −23
Original line number Diff line number Diff line
@@ -16,6 +16,7 @@

#include "WebViewFunctorManager.h"

#include <gui/SurfaceComposerClient.h>
#include <log/log.h>
#include <private/hwui/WebViewFunctor.h>
#include <utils/Trace.h>
@@ -43,7 +44,7 @@ public:

    static ASurfaceControl* getSurfaceControl() {
        ALOG_ASSERT(sCurrentFunctor);
        return sCurrentFunctor->getSurfaceControl();
        return reinterpret_cast<ASurfaceControl*>(sCurrentFunctor->getSurfaceControl());
    }
    static void mergeTransaction(ASurfaceTransaction* transaction) {
        ALOG_ASSERT(sCurrentFunctor);
@@ -129,12 +130,12 @@ bool WebViewFunctor::prepareRootSurfaceControl() {
    renderthread::CanvasContext* activeContext = renderthread::CanvasContext::getActiveContext();
    if (!activeContext) return false;

    ASurfaceControl* rootSurfaceControl = activeContext->getSurfaceControl();
    sp<SurfaceControl> rootSurfaceControl = activeContext->getSurfaceControl();
    if (!rootSurfaceControl) return false;

    int32_t rgid = activeContext->getSurfaceControlGenerationId();
    if (mParentSurfaceControlGenerationId != rgid) {
        reparentSurfaceControl(rootSurfaceControl);
        reparentSurfaceControl(reinterpret_cast<ASurfaceControl*>(rootSurfaceControl.get()));
        mParentSurfaceControlGenerationId = rgid;
    }

@@ -210,33 +211,35 @@ void WebViewFunctor::removeOverlays() {
    mCallbacks.removeOverlays(mFunctor, mData, currentFunctor.mergeTransaction);
    if (mSurfaceControl) {
        reparentSurfaceControl(nullptr);
        auto funcs = renderthread::RenderThread::getInstance().getASurfaceControlFunctions();
        funcs.releaseFunc(mSurfaceControl);
        mSurfaceControl = nullptr;
    }
}

ASurfaceControl* WebViewFunctor::getSurfaceControl() {
    ATRACE_NAME("WebViewFunctor::getSurfaceControl");
    if (mSurfaceControl != nullptr) return mSurfaceControl;
    if (mSurfaceControl != nullptr) {
        return reinterpret_cast<ASurfaceControl*>(mSurfaceControl.get());
    }

    renderthread::CanvasContext* activeContext = renderthread::CanvasContext::getActiveContext();
    LOG_ALWAYS_FATAL_IF(activeContext == nullptr, "Null active canvas context!");

    ASurfaceControl* rootSurfaceControl = activeContext->getSurfaceControl();
    sp<SurfaceControl> rootSurfaceControl = activeContext->getSurfaceControl();
    LOG_ALWAYS_FATAL_IF(rootSurfaceControl == nullptr, "Null root surface control!");

    auto funcs = renderthread::RenderThread::getInstance().getASurfaceControlFunctions();
    mParentSurfaceControlGenerationId = activeContext->getSurfaceControlGenerationId();
    mSurfaceControl = funcs.createFunc(rootSurfaceControl, "Webview Overlay SurfaceControl");
    ASurfaceTransaction* transaction = funcs.transactionCreateFunc();

    SurfaceComposerClient* client = rootSurfaceControl->getClient().get();
    mSurfaceControl = client->createSurface(
            String8("Webview Overlay SurfaceControl"), 0 /* width */, 0 /* height */,
            // Format is only relevant for buffer queue layers.
            PIXEL_FORMAT_UNKNOWN /* format */, ISurfaceComposerClient::eFXSurfaceBufferState,
            rootSurfaceControl->getHandle());

    activeContext->prepareSurfaceControlForWebview();
    funcs.transactionSetZOrderFunc(transaction, mSurfaceControl, -1);
    funcs.transactionSetVisibilityFunc(transaction, mSurfaceControl,
                                       ASURFACE_TRANSACTION_VISIBILITY_SHOW);
    funcs.transactionApplyFunc(transaction);
    funcs.transactionDeleteFunc(transaction);
    return mSurfaceControl;
    SurfaceComposerClient::Transaction transaction;
    transaction.setLayer(mSurfaceControl, -1).show(mSurfaceControl).apply();
    return reinterpret_cast<ASurfaceControl*>(mSurfaceControl.get());
}

void WebViewFunctor::mergeTransaction(ASurfaceTransaction* transaction) {
@@ -249,8 +252,7 @@ void WebViewFunctor::mergeTransaction(ASurfaceTransaction* transaction) {
        done = activeContext->mergeTransaction(transaction, mSurfaceControl);
    }
    if (!done) {
        auto funcs = renderthread::RenderThread::getInstance().getASurfaceControlFunctions();
        funcs.transactionApplyFunc(transaction);
        reinterpret_cast<SurfaceComposerClient::Transaction*>(transaction)->apply();
    }
}

@@ -258,11 +260,10 @@ void WebViewFunctor::reparentSurfaceControl(ASurfaceControl* parent) {
    ATRACE_NAME("WebViewFunctor::reparentSurfaceControl");
    if (mSurfaceControl == nullptr) return;

    auto funcs = renderthread::RenderThread::getInstance().getASurfaceControlFunctions();
    ASurfaceTransaction* transaction = funcs.transactionCreateFunc();
    funcs.transactionReparentFunc(transaction, mSurfaceControl, parent);
    mergeTransaction(transaction);
    funcs.transactionDeleteFunc(transaction);
    SurfaceComposerClient::Transaction transaction;
    transaction.reparent(mSurfaceControl, sp<SurfaceControl>::fromExisting(
                                                  reinterpret_cast<SurfaceControl*>(parent)));
    mergeTransaction(reinterpret_cast<ASurfaceTransaction*>(&transaction));
}

void WebViewFunctor::reportRenderingThreads(const pid_t* thread_ids, size_t size) {
+10 −3
Original line number Diff line number Diff line
@@ -25,7 +25,11 @@
#include <mutex>
#include <vector>

namespace android::uirenderer {
namespace android {

class SurfaceControl;

namespace uirenderer {

class WebViewFunctorManager;

@@ -100,7 +104,9 @@ private:
    bool mHasContext = false;
    bool mCreatedHandle = false;
    int32_t mParentSurfaceControlGenerationId = 0;
    ASurfaceControl* mSurfaceControl = nullptr;
#ifdef __ANDROID__
    sp<SurfaceControl> mSurfaceControl = nullptr;
#endif
    std::vector<pid_t> mRenderingThreads;
};

@@ -126,4 +132,5 @@ private:
    std::vector<sp<WebViewFunctor::Handle>> mActiveFunctors;
};

}  // namespace android::uirenderer
}  // namespace uirenderer
}  // namespace android
+9 −5
Original line number Diff line number Diff line
@@ -53,6 +53,7 @@
#include <src/image/SkImage_Base.h>
#include <thread/CommonPool.h>
#ifdef __ANDROID__
#include <gui/SurfaceControl.h>
#include <ui/GraphicBufferAllocator.h>
#endif
#include <utils/Color.h>
@@ -217,9 +218,11 @@ static void android_view_ThreadedRenderer_setSurface(JNIEnv* env, jobject clazz,

static void android_view_ThreadedRenderer_setSurfaceControl(JNIEnv* env, jobject clazz,
        jlong proxyPtr, jlong surfaceControlPtr) {
#ifdef __ANDROID__
    RenderProxy* proxy = reinterpret_cast<RenderProxy*>(proxyPtr);
    ASurfaceControl* surfaceControl = reinterpret_cast<ASurfaceControl*>(surfaceControlPtr);
    proxy->setSurfaceControl(surfaceControl);
    SurfaceControl* surfaceControl = reinterpret_cast<SurfaceControl*>(surfaceControlPtr);
    proxy->setSurfaceControl(sp<SurfaceControl>::fromExisting(surfaceControl));
#endif
}

static jboolean android_view_ThreadedRenderer_pause(JNIEnv* env, jobject clazz,
@@ -684,7 +687,7 @@ static void android_view_ThreadedRenderer_setFrameCompleteCallback(JNIEnv* env,

class CopyRequestAdapter : public CopyRequest {
public:
    CopyRequestAdapter(JavaVM* vm, jobject jCopyRequest, Rect srcRect)
    CopyRequestAdapter(JavaVM* vm, jobject jCopyRequest, ::android::uirenderer::Rect srcRect)
            : CopyRequest(srcRect), mRefHolder(vm, jCopyRequest) {}

    virtual SkBitmap getDestinationBitmap(int srcWidth, int srcHeight) override {
@@ -710,8 +713,9 @@ static void android_view_ThreadedRenderer_copySurfaceInto(JNIEnv* env, jobject c
                                                          jobject jCopyRequest) {
    JavaVM* vm = nullptr;
    LOG_ALWAYS_FATAL_IF(env->GetJavaVM(&vm) != JNI_OK, "Unable to get Java VM");
    auto copyRequest = std::make_shared<CopyRequestAdapter>(vm, env->NewGlobalRef(jCopyRequest),
                                                            Rect(left, top, right, bottom));
    auto copyRequest = std::make_shared<CopyRequestAdapter>(
            vm, env->NewGlobalRef(jCopyRequest),
            ::android::uirenderer::Rect(left, top, right, bottom));
    ANativeWindow* window = fromSurface(env, jsurface);
    RenderProxy::copySurfaceInto(window, std::move(copyRequest));
    ANativeWindow_release(window);
+1 −1
Original line number Diff line number Diff line
@@ -45,7 +45,7 @@ void WebViewFunctor::destroyContext() {}
void WebViewFunctor::removeOverlays() {}

ASurfaceControl* WebViewFunctor::getSurfaceControl() {
    return mSurfaceControl;
    return nullptr;
}

void WebViewFunctor::mergeTransaction(ASurfaceTransaction* transaction) {}
Loading