Migrate gpu resource methods to GrDirectContext
Cut & paste job Change-Id: I92e7d1ca5fdf7a7f9961b77a6088f06ed401cc2a Reviewed-on: https://skia-review.googlesource.com/c/skia/+/325616 Auto-Submit: Adlai Holler <adlai@google.com> Commit-Queue: Robert Phillips <robertphillips@google.com> Reviewed-by: Robert Phillips <robertphillips@google.com>
This commit is contained in:
parent
01bdceb869
commit
4aa4c6014d
@ -202,7 +202,77 @@ public:
|
||||
*/
|
||||
void setResourceCacheLimit(size_t maxResourceBytes);
|
||||
|
||||
void freeGpuResources() override;
|
||||
/**
|
||||
* Frees GPU created by the context. Can be called to reduce GPU memory
|
||||
* pressure.
|
||||
*/
|
||||
void freeGpuResources();
|
||||
|
||||
/**
|
||||
* Purge GPU resources that haven't been used in the past 'msNotUsed' milliseconds or are
|
||||
* otherwise marked for deletion, regardless of whether the context is under budget.
|
||||
*/
|
||||
void performDeferredCleanup(std::chrono::milliseconds msNotUsed);
|
||||
|
||||
// Temporary compatibility API for Android.
|
||||
void purgeResourcesNotUsedInMs(std::chrono::milliseconds msNotUsed) {
|
||||
this->performDeferredCleanup(msNotUsed);
|
||||
}
|
||||
|
||||
/**
|
||||
* Purge unlocked resources from the cache until the the provided byte count has been reached
|
||||
* or we have purged all unlocked resources. The default policy is to purge in LRU order, but
|
||||
* can be overridden to prefer purging scratch resources (in LRU order) prior to purging other
|
||||
* resource types.
|
||||
*
|
||||
* @param maxBytesToPurge the desired number of bytes to be purged.
|
||||
* @param preferScratchResources If true scratch resources will be purged prior to other
|
||||
* resource types.
|
||||
*/
|
||||
void purgeUnlockedResources(size_t bytesToPurge, bool preferScratchResources);
|
||||
|
||||
/**
|
||||
* This entry point is intended for instances where an app has been backgrounded or
|
||||
* suspended.
|
||||
* If 'scratchResourcesOnly' is true all unlocked scratch resources will be purged but the
|
||||
* unlocked resources with persistent data will remain. If 'scratchResourcesOnly' is false
|
||||
* then all unlocked resources will be purged.
|
||||
* In either case, after the unlocked resources are purged a separate pass will be made to
|
||||
* ensure that resource usage is under budget (i.e., even if 'scratchResourcesOnly' is true
|
||||
* some resources with persistent data may be purged to be under budget).
|
||||
*
|
||||
* @param scratchResourcesOnly If true only unlocked scratch resources will be purged prior
|
||||
* enforcing the budget requirements.
|
||||
*/
|
||||
void purgeUnlockedResources(bool scratchResourcesOnly);
|
||||
|
||||
/**
|
||||
* Gets the maximum supported texture size.
|
||||
*/
|
||||
using GrRecordingContext::maxTextureSize;
|
||||
|
||||
/**
|
||||
* Gets the maximum supported render target size.
|
||||
*/
|
||||
using GrRecordingContext::maxRenderTargetSize;
|
||||
|
||||
/**
|
||||
* Can a SkImage be created with the given color type.
|
||||
*/
|
||||
using GrRecordingContext::colorTypeSupportedAsImage;
|
||||
|
||||
/**
|
||||
* Can a SkSurface be created with the given color type. To check whether MSAA is supported
|
||||
* use maxSurfaceSampleCountForColorType().
|
||||
*/
|
||||
using GrRecordingContext::colorTypeSupportedAsSurface;
|
||||
|
||||
/**
|
||||
* Gets the maximum supported sample count for a color type. 1 is returned if only non-MSAA
|
||||
* rendering is supported for the color type. 0 is returned if rendering to this color type
|
||||
* is not supported at all.
|
||||
*/
|
||||
using GrRecordingContext::maxSurfaceSampleCountForColorType;
|
||||
|
||||
protected:
|
||||
GrDirectContext(GrBackendApi backend, const GrContextOptions& options);
|
||||
|
@ -57,78 +57,6 @@ class SK_API GrContext : public GrRecordingContext {
|
||||
public:
|
||||
~GrContext() override;
|
||||
|
||||
/**
|
||||
* Frees GPU created by the context. Can be called to reduce GPU memory
|
||||
* pressure.
|
||||
*/
|
||||
virtual void freeGpuResources();
|
||||
|
||||
/**
|
||||
* Purge GPU resources that haven't been used in the past 'msNotUsed' milliseconds or are
|
||||
* otherwise marked for deletion, regardless of whether the context is under budget.
|
||||
*/
|
||||
void performDeferredCleanup(std::chrono::milliseconds msNotUsed);
|
||||
|
||||
// Temporary compatibility API for Android.
|
||||
void purgeResourcesNotUsedInMs(std::chrono::milliseconds msNotUsed) {
|
||||
this->performDeferredCleanup(msNotUsed);
|
||||
}
|
||||
|
||||
/**
|
||||
* Purge unlocked resources from the cache until the the provided byte count has been reached
|
||||
* or we have purged all unlocked resources. The default policy is to purge in LRU order, but
|
||||
* can be overridden to prefer purging scratch resources (in LRU order) prior to purging other
|
||||
* resource types.
|
||||
*
|
||||
* @param maxBytesToPurge the desired number of bytes to be purged.
|
||||
* @param preferScratchResources If true scratch resources will be purged prior to other
|
||||
* resource types.
|
||||
*/
|
||||
void purgeUnlockedResources(size_t bytesToPurge, bool preferScratchResources);
|
||||
|
||||
/**
|
||||
* This entry point is intended for instances where an app has been backgrounded or
|
||||
* suspended.
|
||||
* If 'scratchResourcesOnly' is true all unlocked scratch resources will be purged but the
|
||||
* unlocked resources with persistent data will remain. If 'scratchResourcesOnly' is false
|
||||
* then all unlocked resources will be purged.
|
||||
* In either case, after the unlocked resources are purged a separate pass will be made to
|
||||
* ensure that resource usage is under budget (i.e., even if 'scratchResourcesOnly' is true
|
||||
* some resources with persistent data may be purged to be under budget).
|
||||
*
|
||||
* @param scratchResourcesOnly If true only unlocked scratch resources will be purged prior
|
||||
* enforcing the budget requirements.
|
||||
*/
|
||||
void purgeUnlockedResources(bool scratchResourcesOnly);
|
||||
|
||||
/**
|
||||
* Gets the maximum supported texture size.
|
||||
*/
|
||||
using GrRecordingContext::maxTextureSize;
|
||||
|
||||
/**
|
||||
* Gets the maximum supported render target size.
|
||||
*/
|
||||
using GrRecordingContext::maxRenderTargetSize;
|
||||
|
||||
/**
|
||||
* Can a SkImage be created with the given color type.
|
||||
*/
|
||||
using GrRecordingContext::colorTypeSupportedAsImage;
|
||||
|
||||
/**
|
||||
* Can a SkSurface be created with the given color type. To check whether MSAA is supported
|
||||
* use maxSurfaceSampleCountForColorType().
|
||||
*/
|
||||
using GrRecordingContext::colorTypeSupportedAsSurface;
|
||||
|
||||
/**
|
||||
* Gets the maximum supported sample count for a color type. 1 is returned if only non-MSAA
|
||||
* rendering is supported for the color type. 0 is returned if rendering to this color type
|
||||
* is not supported at all.
|
||||
*/
|
||||
using GrRecordingContext::maxSurfaceSampleCountForColorType;
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////
|
||||
// Misc.
|
||||
|
||||
|
@ -54,74 +54,6 @@ GrContext::GrContext(sk_sp<GrContextThreadSafeProxy> proxy) : INHERITED(std::mov
|
||||
|
||||
GrContext::~GrContext() = default;
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
void GrContext::freeGpuResources() {
|
||||
ASSERT_SINGLE_OWNER
|
||||
|
||||
if (this->abandoned()) {
|
||||
return;
|
||||
}
|
||||
|
||||
// TODO: the glyph cache doesn't hold any GpuResources so this call should not be needed here.
|
||||
// Some slack in the GrTextBlob's implementation requires it though. That could be fixed.
|
||||
fStrikeCache->freeAll();
|
||||
|
||||
this->drawingManager()->freeGpuResources();
|
||||
|
||||
fResourceCache->purgeAllUnlocked();
|
||||
}
|
||||
|
||||
void GrContext::purgeUnlockedResources(bool scratchResourcesOnly) {
|
||||
ASSERT_SINGLE_OWNER
|
||||
|
||||
if (this->abandoned()) {
|
||||
return;
|
||||
}
|
||||
|
||||
fResourceCache->purgeUnlockedResources(scratchResourcesOnly);
|
||||
fResourceCache->purgeAsNeeded();
|
||||
|
||||
// The textBlob Cache doesn't actually hold any GPU resource but this is a convenient
|
||||
// place to purge stale blobs
|
||||
this->getTextBlobCache()->purgeStaleBlobs();
|
||||
}
|
||||
|
||||
void GrContext::performDeferredCleanup(std::chrono::milliseconds msNotUsed) {
|
||||
TRACE_EVENT0("skia.gpu", TRACE_FUNC);
|
||||
|
||||
ASSERT_SINGLE_OWNER
|
||||
|
||||
if (this->abandoned()) {
|
||||
return;
|
||||
}
|
||||
|
||||
this->checkAsyncWorkCompletion();
|
||||
fMappedBufferManager->process();
|
||||
auto purgeTime = GrStdSteadyClock::now() - msNotUsed;
|
||||
|
||||
fResourceCache->purgeAsNeeded();
|
||||
fResourceCache->purgeResourcesNotUsedSince(purgeTime);
|
||||
|
||||
if (auto ccpr = this->drawingManager()->getCoverageCountingPathRenderer()) {
|
||||
ccpr->purgeCacheEntriesOlderThan(this->proxyProvider(), purgeTime);
|
||||
}
|
||||
|
||||
// The textBlob Cache doesn't actually hold any GPU resource but this is a convenient
|
||||
// place to purge stale blobs
|
||||
this->getTextBlobCache()->purgeStaleBlobs();
|
||||
}
|
||||
|
||||
void GrContext::purgeUnlockedResources(size_t bytesToPurge, bool preferScratchResources) {
|
||||
ASSERT_SINGLE_OWNER
|
||||
|
||||
if (this->abandoned()) {
|
||||
return;
|
||||
}
|
||||
|
||||
fResourceCache->purgeUnlockedResources(bytesToPurge, preferScratchResources);
|
||||
}
|
||||
|
||||
size_t GrContext::ComputeImageSize(sk_sp<SkImage> image, GrMipmapped mipMapped, bool useNextPow2) {
|
||||
if (!image->isTextureBacked()) {
|
||||
return 0;
|
||||
|
@ -13,10 +13,12 @@
|
||||
#include "src/gpu/GrClientMappedBufferManager.h"
|
||||
#include "src/gpu/GrContextPriv.h"
|
||||
#include "src/gpu/GrContextThreadSafeProxyPriv.h"
|
||||
#include "src/gpu/GrDrawingManager.h"
|
||||
#include "src/gpu/GrGpu.h"
|
||||
#include "src/gpu/GrResourceProvider.h"
|
||||
#include "src/gpu/GrShaderUtils.h"
|
||||
|
||||
#include "src/gpu/ccpr/GrCoverageCountingPathRenderer.h"
|
||||
#include "src/gpu/effects/GrSkSLFP.h"
|
||||
#include "src/gpu/gl/GrGLGpu.h"
|
||||
#include "src/gpu/mock/GrMockGpu.h"
|
||||
@ -150,13 +152,25 @@ void GrDirectContext::releaseResourcesAndAbandonContext() {
|
||||
}
|
||||
|
||||
void GrDirectContext::freeGpuResources() {
|
||||
ASSERT_SINGLE_OWNER
|
||||
|
||||
if (this->abandoned()) {
|
||||
return;
|
||||
}
|
||||
|
||||
this->flushAndSubmit();
|
||||
if (fSmallPathAtlasMgr) {
|
||||
fSmallPathAtlasMgr->reset();
|
||||
}
|
||||
fAtlasManager->freeAll();
|
||||
|
||||
INHERITED::freeGpuResources();
|
||||
// TODO: the glyph cache doesn't hold any GpuResources so this call should not be needed here.
|
||||
// Some slack in the GrTextBlob's implementation requires it though. That could be fixed.
|
||||
fStrikeCache->freeAll();
|
||||
|
||||
this->drawingManager()->freeGpuResources();
|
||||
|
||||
fResourceCache->purgeAllUnlocked();
|
||||
}
|
||||
|
||||
bool GrDirectContext::init() {
|
||||
@ -266,6 +280,57 @@ void GrDirectContext::setResourceCacheLimit(size_t maxResourceBytes) {
|
||||
fResourceCache->setLimit(maxResourceBytes);
|
||||
}
|
||||
|
||||
void GrDirectContext::purgeUnlockedResources(bool scratchResourcesOnly) {
|
||||
ASSERT_SINGLE_OWNER
|
||||
|
||||
if (this->abandoned()) {
|
||||
return;
|
||||
}
|
||||
|
||||
fResourceCache->purgeUnlockedResources(scratchResourcesOnly);
|
||||
fResourceCache->purgeAsNeeded();
|
||||
|
||||
// The textBlob Cache doesn't actually hold any GPU resource but this is a convenient
|
||||
// place to purge stale blobs
|
||||
this->getTextBlobCache()->purgeStaleBlobs();
|
||||
}
|
||||
|
||||
void GrDirectContext::performDeferredCleanup(std::chrono::milliseconds msNotUsed) {
|
||||
TRACE_EVENT0("skia.gpu", TRACE_FUNC);
|
||||
|
||||
ASSERT_SINGLE_OWNER
|
||||
|
||||
if (this->abandoned()) {
|
||||
return;
|
||||
}
|
||||
|
||||
this->checkAsyncWorkCompletion();
|
||||
fMappedBufferManager->process();
|
||||
auto purgeTime = GrStdSteadyClock::now() - msNotUsed;
|
||||
|
||||
fResourceCache->purgeAsNeeded();
|
||||
fResourceCache->purgeResourcesNotUsedSince(purgeTime);
|
||||
|
||||
if (auto ccpr = this->drawingManager()->getCoverageCountingPathRenderer()) {
|
||||
ccpr->purgeCacheEntriesOlderThan(this->proxyProvider(), purgeTime);
|
||||
}
|
||||
|
||||
// The textBlob Cache doesn't actually hold any GPU resource but this is a convenient
|
||||
// place to purge stale blobs
|
||||
this->getTextBlobCache()->purgeStaleBlobs();
|
||||
}
|
||||
|
||||
void GrDirectContext::purgeUnlockedResources(size_t bytesToPurge, bool preferScratchResources) {
|
||||
ASSERT_SINGLE_OWNER
|
||||
|
||||
if (this->abandoned()) {
|
||||
return;
|
||||
}
|
||||
|
||||
fResourceCache->purgeUnlockedResources(bytesToPurge, preferScratchResources);
|
||||
}
|
||||
|
||||
|
||||
GrSmallPathAtlasMgr* GrDirectContext::onGetSmallPathAtlasMgr() {
|
||||
if (!fSmallPathAtlasMgr) {
|
||||
fSmallPathAtlasMgr = std::make_unique<GrSmallPathAtlasMgr>();
|
||||
|
Loading…
Reference in New Issue
Block a user