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

Commit 13fb62b5 authored by Kevin Lubick's avatar Kevin Lubick Committed by Android (Google) Code Review
Browse files

Merge "[base] Update GrDirectContext calls to use safer API" into main

parents c6677500 cae0b21c
Loading
Loading
Loading
Loading
+2 −1
Original line number Diff line number Diff line
@@ -22,6 +22,7 @@
#include <GLES2/gl2ext.h>
#include <GLES3/gl3.h>
#include <GrDirectContext.h>
#include <GrTypes.h>
#include <SkBitmap.h>
#include <SkCanvas.h>
#include <SkImage.h>
@@ -265,7 +266,7 @@ private:
          sk_sp<SkImage> image =
              SkImages::TextureFromAHardwareBufferWithData(mGrContext.get(), bitmap.pixmap(),
                                                           ahb);
          mGrContext->submit(true);
          mGrContext->submit(GrSyncCpu::kYes);

          uploadSucceeded = (image.get() != nullptr);
        });
+10 −4
Original line number Diff line number Diff line
@@ -17,6 +17,7 @@
#include "CacheManager.h"

#include <GrContextOptions.h>
#include <GrTypes.h>
#include <SkExecutor.h>
#include <SkGraphics.h>
#include <math.h>
@@ -110,13 +111,18 @@ void CacheManager::configureContext(GrContextOptions* contextOptions, const void
    contextOptions->fPersistentCache = &cache;
}

static GrPurgeResourceOptions toSkiaEnum(bool scratchOnly) {
    return scratchOnly ? GrPurgeResourceOptions::kScratchResourcesOnly :
                         GrPurgeResourceOptions::kAllResources;
}

void CacheManager::trimMemory(TrimLevel mode) {
    if (!mGrContext) {
        return;
    }

    // flush and submit all work to the gpu and wait for it to finish
    mGrContext->flushAndSubmit(/*syncCpu=*/true);
    mGrContext->flushAndSubmit(GrSyncCpu::kYes);

    switch (mode) {
        case TrimLevel::BACKGROUND:
@@ -130,7 +136,7 @@ void CacheManager::trimMemory(TrimLevel mode) {
            // that have persistent data to be purged in LRU order.
            mGrContext->setResourceCacheLimit(mBackgroundResourceBytes);
            SkGraphics::SetFontCacheLimit(mBackgroundCpuFontCacheBytes);
            mGrContext->purgeUnlockedResources(mMemoryPolicy.purgeScratchOnly);
            mGrContext->purgeUnlockedResources(toSkiaEnum(mMemoryPolicy.purgeScratchOnly));
            mGrContext->setResourceCacheLimit(mMaxResourceBytes);
            SkGraphics::SetFontCacheLimit(mMaxCpuFontCacheBytes);
            break;
@@ -150,7 +156,7 @@ void CacheManager::trimCaches(CacheTrimLevel mode) {
        case CacheTrimLevel::ALL_CACHES:
            SkGraphics::PurgeAllCaches();
            if (mGrContext) {
                mGrContext->purgeUnlockedResources(false);
                mGrContext->purgeUnlockedResources(GrPurgeResourceOptions::kAllResources);
            }
            break;
        default:
@@ -285,7 +291,7 @@ void CacheManager::onThreadIdle() {
                ns2ms(std::clamp(frameDiffNanos, mMemoryPolicy.minimumResourceRetention,
                                 mMemoryPolicy.maximumResourceRetention));
        mGrContext->performDeferredCleanup(std::chrono::milliseconds(cleanupMillis),
                                           mMemoryPolicy.purgeScratchOnly);
                                           toSkiaEnum(mMemoryPolicy.purgeScratchOnly));
    }
}

+1 −1
Original line number Diff line number Diff line
@@ -515,7 +515,7 @@ Frame VulkanManager::dequeueNextBuffer(VulkanSurface* surface) {
                        // The following flush blocks the GPU immediately instead of waiting for
                        // other drawing ops. It seems dequeue_fence is not respected otherwise.
                        // TODO: remove the flush after finding why backendSemaphore is not working.
                        skgpu::ganesh::FlushAndSubmit(bufferInfo->skSurface);
                        skgpu::ganesh::FlushAndSubmit(bufferInfo->skSurface.get());
                    }
                }
            }