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

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

Merge changes I5685cb9d,Ia78cd845 into main

* changes:
  Move SkiaGpuContext creation in SkiaVkRenderEngine to virtual function
  Move Ganesh flush calls from drawLayersInternal to flushAndSubmit
parents 92ea2dac 342d394c
Loading
Loading
Loading
Loading
+16 −2
Original line number Diff line number Diff line
@@ -23,6 +23,7 @@

#include <log/log_main.h>
#include <sync/sync.h>
#include <utils/Trace.h>

namespace android::renderengine::skia {

@@ -33,6 +34,12 @@ static void unref_semaphore(void* semaphore) {
    info->unref();
}

std::unique_ptr<SkiaGpuContext> GaneshVkRenderEngine::createContext(
        VulkanInterface& vulkanInterface) {
    return SkiaGpuContext::MakeVulkan_Ganesh(vulkanInterface.getGaneshBackendContext(),
                                             mSkSLCacheMonitor);
}

void GaneshVkRenderEngine::waitFence(SkiaGpuContext* context, base::borrowed_fd fenceFd) {
    if (fenceFd.get() < 0) return;

@@ -51,11 +58,18 @@ void GaneshVkRenderEngine::waitFence(SkiaGpuContext* context, base::borrowed_fd
    context->grDirectContext()->wait(1, &beSemaphore, kDeleteAfterWait);
}

base::unique_fd GaneshVkRenderEngine::flushAndSubmit(SkiaGpuContext* context) {
base::unique_fd GaneshVkRenderEngine::flushAndSubmit(SkiaGpuContext* context,
                                                     sk_sp<SkSurface> dstSurface) {
    sk_sp<GrDirectContext> grContext = context->grDirectContext();
    {
        ATRACE_NAME("flush surface");
        // TODO: Investigate feasibility of combining this "surface flush" into the "context flush"
        // below.
        context->grDirectContext()->flush(dstSurface.get());
    }

    VulkanInterface& vi = getVulkanInterface(isProtected());
    VkSemaphore semaphore = vi.createExportableSemaphore();

    GrBackendSemaphore backendSemaphore = GrBackendSemaphores::MakeVk(semaphore);

    GrFlushInfo flushInfo;
+2 −1
Original line number Diff line number Diff line
@@ -27,8 +27,9 @@ class GaneshVkRenderEngine : public SkiaVkRenderEngine {
protected:
    GaneshVkRenderEngine(const RenderEngineCreationArgs& args) : SkiaVkRenderEngine(args) {}

    std::unique_ptr<SkiaGpuContext> createContext(VulkanInterface& vulkanInterface) override;
    void waitFence(SkiaGpuContext* context, base::borrowed_fd fenceFd) override;
    base::unique_fd flushAndSubmit(SkiaGpuContext* context) override;
    base::unique_fd flushAndSubmit(SkiaGpuContext* context, sk_sp<SkSurface> dstSurface) override;
};

} // namespace android::renderengine::skia
+10 −5
Original line number Diff line number Diff line
@@ -337,8 +337,14 @@ void SkiaGLRenderEngine::waitFence(SkiaGpuContext*, base::borrowed_fd fenceFd) {
    }
}

base::unique_fd SkiaGLRenderEngine::flushAndSubmit(SkiaGpuContext* context) {
    base::unique_fd drawFence = flush();
base::unique_fd SkiaGLRenderEngine::flushAndSubmit(SkiaGpuContext* context,
                                                   sk_sp<SkSurface> dstSurface) {
    sk_sp<GrDirectContext> grContext = context->grDirectContext();
    {
        ATRACE_NAME("flush surface");
        grContext->flush(dstSurface.get());
    }
    base::unique_fd drawFence = flushGL();

    bool requireSync = drawFence.get() < 0;
    if (requireSync) {
@@ -346,8 +352,7 @@ base::unique_fd SkiaGLRenderEngine::flushAndSubmit(SkiaGpuContext* context) {
    } else {
        ATRACE_BEGIN("Submit(sync=false)");
    }
    bool success =
            context->grDirectContext()->submit(requireSync ? GrSyncCpu::kYes : GrSyncCpu::kNo);
    bool success = grContext->submit(requireSync ? GrSyncCpu::kYes : GrSyncCpu::kNo);
    ATRACE_END();
    if (!success) {
        ALOGE("Failed to flush RenderEngine commands");
@@ -394,7 +399,7 @@ bool SkiaGLRenderEngine::waitGpuFence(base::borrowed_fd fenceFd) {
    return true;
}

base::unique_fd SkiaGLRenderEngine::flush() {
base::unique_fd SkiaGLRenderEngine::flushGL() {
    ATRACE_CALL();
    if (!GLExtensions::getInstance().hasNativeFenceSync()) {
        return base::unique_fd();
+2 −2
Original line number Diff line number Diff line
@@ -63,7 +63,7 @@ protected:
    bool supportsProtectedContentImpl() const override;
    bool useProtectedContextImpl(GrProtected isProtected) override;
    void waitFence(SkiaGpuContext* context, base::borrowed_fd fenceFd) override;
    base::unique_fd flushAndSubmit(SkiaGpuContext* context) override;
    base::unique_fd flushAndSubmit(SkiaGpuContext* context, sk_sp<SkSurface> dstSurface) override;
    void appendBackendSpecificInfoToDump(std::string& result) override;

private:
@@ -71,7 +71,7 @@ private:
                       EGLSurface placeholder, EGLContext protectedContext,
                       EGLSurface protectedPlaceholder);
    bool waitGpuFence(base::borrowed_fd fenceFd);
    base::unique_fd flush();
    base::unique_fd flushGL();
    static EGLConfig chooseEglConfig(EGLDisplay display, int format, bool logConfig);
    static EGLContext createEglContext(EGLDisplay display, EGLConfig config,
                                       EGLContext shareContext,
+8 −8
Original line number Diff line number Diff line
@@ -90,7 +90,7 @@ namespace {

// Debugging settings
static const bool kPrintLayerSettings = false;
static const bool kFlushAfterEveryLayer = kPrintLayerSettings;
static const bool kGaneshFlushAfterEveryLayer = kPrintLayerSettings;
static constexpr bool kEnableLayerBrightening = true;

} // namespace
@@ -1122,21 +1122,21 @@ void SkiaRenderEngine::drawLayersInternal(
        } else {
            canvas->drawRect(bounds.rect(), paint);
        }
        if (kFlushAfterEveryLayer) {
        if (kGaneshFlushAfterEveryLayer) {
            ATRACE_NAME("flush surface");
            // No-op in Graphite. If "flushing" Skia's drawing commands after each layer is desired
            // in Graphite, then a graphite::Recording would need to be snapped and tracked for each
            // layer, which is likely possible but adds non-trivial complexity (in both bookkeeping
            // and refactoring).
            skgpu::ganesh::Flush(activeSurface);
        }
    }

    surfaceAutoSaveRestore.restore();
    mCapture->endCapture();
    {
        ATRACE_NAME("flush surface");
        LOG_ALWAYS_FATAL_IF(activeSurface != dstSurface);
        skgpu::ganesh::Flush(activeSurface);
    }

    auto drawFence = sp<Fence>::make(flushAndSubmit(context));
    LOG_ALWAYS_FATAL_IF(activeSurface != dstSurface);
    auto drawFence = sp<Fence>::make(flushAndSubmit(context, dstSurface));

    if (ATRACE_ENABLED()) {
        static gui::FenceMonitor sMonitor("RE Completion");
Loading