Give GrResourceAllocator a GrDirectContext
This allows it to access the resource cache as well as the provider,
and paves the way for memory budgeting inside the resource allocator.
Bug: skia:10877
Change-Id: I01e9c02e445494ac431b288f41006ae7360ff791
Reviewed-on: https://skia-review.googlesource.com/c/skia/+/394116
Auto-Submit: Adlai Holler <adlai@google.com>
Commit-Queue: Robert Phillips <robertphillips@google.com>
Reviewed-by: Robert Phillips <robertphillips@google.com>
diff --git a/src/gpu/GrDrawingManager.cpp b/src/gpu/GrDrawingManager.cpp
index 6d822cd..512911a 100644
--- a/src/gpu/GrDrawingManager.cpp
+++ b/src/gpu/GrDrawingManager.cpp
@@ -117,18 +117,18 @@
}
}
- auto direct = fContext->asDirectContext();
- SkASSERT(direct);
- direct->priv().clientMappedBufferManager()->process();
+ auto dContext = fContext->asDirectContext();
+ SkASSERT(dContext);
+ dContext->priv().clientMappedBufferManager()->process();
- GrGpu* gpu = direct->priv().getGpu();
+ GrGpu* gpu = dContext->priv().getGpu();
// We have a non abandoned and direct GrContext. It must have a GrGpu.
SkASSERT(gpu);
fFlushing = true;
- auto resourceProvider = direct->priv().resourceProvider();
- auto resourceCache = direct->priv().getResourceCache();
+ auto resourceProvider = dContext->priv().resourceProvider();
+ auto resourceCache = dContext->priv().getResourceCache();
// Semi-usually the GrRenderTasks are already closed at this point, but sometimes Ganesh needs
// to flush mid-draw. In that case, the SkGpuDevice's opsTasks won't be closed but need to be
@@ -205,7 +205,7 @@
bool flushed = false;
{
- GrResourceAllocator alloc(resourceProvider SkDEBUGCODE(, fDAG.count()));
+ GrResourceAllocator alloc(dContext SkDEBUGCODE(, fDAG.count()));
for (const auto& task : fDAG) {
SkASSERT(task);
task->gatherProxyIntervals(&alloc);
diff --git a/src/gpu/GrResourceAllocator.cpp b/src/gpu/GrResourceAllocator.cpp
index f5a48fa..9efdebf 100644
--- a/src/gpu/GrResourceAllocator.cpp
+++ b/src/gpu/GrResourceAllocator.cpp
@@ -7,6 +7,7 @@
#include "src/gpu/GrResourceAllocator.h"
+#include "src/gpu/GrDirectContextPriv.h"
#include "src/gpu/GrGpuResourcePriv.h"
#include "src/gpu/GrOpsTask.h"
#include "src/gpu/GrRenderTargetProxy.h"
@@ -56,7 +57,8 @@
// recycled. We don't need to assign a texture to it and no other proxy can be instantiated
// with the same texture.
if (proxy->readOnly()) {
- if (proxy->isLazy() && !proxy->priv().doLazyInstantiation(fResourceProvider)) {
+ auto resourceProvider = fDContext->priv().resourceProvider();
+ if (proxy->isLazy() && !proxy->priv().doLazyInstantiation(resourceProvider)) {
fFailedInstantiation = true;
} else {
// Since we aren't going to add an interval we won't revisit this proxy in assign(). So
@@ -262,7 +264,7 @@
// Then look in the free pool
GrScratchKey scratchKey;
- proxy->priv().computeScratchKey(*fResourceProvider->caps(), &scratchKey);
+ proxy->priv().computeScratchKey(*fDContext->priv().caps(), &scratchKey);
auto filter = [] (const Register* r) {
return true;
@@ -282,7 +284,7 @@
SkASSERT(!intvl->next());
Register* r = intvl->getRegister();
- if (r && r->isRecyclable(*fResourceProvider->caps(), intvl->proxy(), intvl->uses())) {
+ if (r && r->isRecyclable(*fDContext->priv().caps(), intvl->proxy(), intvl->uses())) {
#if GR_ALLOCATION_SPEW
SkDebugf("putting register %d back into pool\n", r->uniqueID());
#endif
@@ -337,6 +339,7 @@
// instantiating anything.
// Instantiate surfaces
+ auto resourceProvider = fDContext->priv().resourceProvider();
while (Interval* cur = fFinishedIntvls.popHead()) {
if (fFailedInstantiation) {
break;
@@ -345,12 +348,12 @@
continue;
}
if (cur->proxy()->isLazy()) {
- fFailedInstantiation = !cur->proxy()->priv().doLazyInstantiation(fResourceProvider);
+ fFailedInstantiation = !cur->proxy()->priv().doLazyInstantiation(resourceProvider);
continue;
}
Register* r = cur->getRegister();
SkASSERT(r);
- fFailedInstantiation = !r->instantiateSurface(cur->proxy(), fResourceProvider);
+ fFailedInstantiation = !r->instantiateSurface(cur->proxy(), resourceProvider);
}
return !fFailedInstantiation;
}
diff --git a/src/gpu/GrResourceAllocator.h b/src/gpu/GrResourceAllocator.h
index 286bd2a..6bc5a3b 100644
--- a/src/gpu/GrResourceAllocator.h
+++ b/src/gpu/GrResourceAllocator.h
@@ -10,15 +10,14 @@
#include "include/private/SkTHash.h"
-#include "src/gpu/GrGpuResourcePriv.h"
#include "src/gpu/GrHashMapWithCache.h"
#include "src/gpu/GrSurface.h"
-#include "src/gpu/GrSurfaceProxyPriv.h"
+#include "src/gpu/GrSurfaceProxy.h"
#include "src/core/SkArenaAlloc.h"
#include "src/core/SkTMultiMap.h"
-class GrResourceProvider;
+class GrDirectContext;
// Print out explicit allocation information
#define GR_ALLOCATION_SPEW 0
@@ -69,8 +68,8 @@
*/
class GrResourceAllocator {
public:
- GrResourceAllocator(GrResourceProvider* resourceProvider SkDEBUGCODE(, int numOpsTasks))
- : fResourceProvider(resourceProvider) {}
+ GrResourceAllocator(GrDirectContext* dContext SkDEBUGCODE(, int numOpsTasks))
+ : fDContext(dContext) {}
~GrResourceAllocator();
@@ -252,7 +251,7 @@
// Compositing use cases can create > 80 intervals.
static const int kInitialArenaSize = 128 * sizeof(Interval);
- GrResourceProvider* fResourceProvider;
+ GrDirectContext* fDContext;
FreePoolMultiMap fFreePool; // Recently created/used GrSurfaces
IntvlHash fIntvlHash; // All the intervals, hashed by proxyID
diff --git a/tests/ResourceAllocatorTest.cpp b/tests/ResourceAllocatorTest.cpp
index 41f5274..fce8433 100644
--- a/tests/ResourceAllocatorTest.cpp
+++ b/tests/ResourceAllocatorTest.cpp
@@ -58,10 +58,10 @@
// Basic test that two proxies with overlapping intervals and compatible descriptors are
// assigned different GrSurfaces.
-static void overlap_test(skiatest::Reporter* reporter, GrResourceProvider* resourceProvider,
+static void overlap_test(skiatest::Reporter* reporter, GrDirectContext* dContext,
sk_sp<GrSurfaceProxy> p1, sk_sp<GrSurfaceProxy> p2,
bool expectedResult) {
- GrResourceAllocator alloc(resourceProvider SkDEBUGCODE(, 1));
+ GrResourceAllocator alloc(dContext SkDEBUGCODE(, 1));
alloc.addInterval(p1.get(), 0, 4, GrResourceAllocator::ActualUse::kYes);
alloc.incOps();
@@ -78,10 +78,10 @@
// Test various cases when two proxies do not have overlapping intervals.
// This mainly acts as a test of the ResourceAllocator's free pool.
-static void non_overlap_test(skiatest::Reporter* reporter, GrResourceProvider* resourceProvider,
+static void non_overlap_test(skiatest::Reporter* reporter, GrDirectContext* dContext,
sk_sp<GrSurfaceProxy> p1, sk_sp<GrSurfaceProxy> p2,
bool expectedResult) {
- GrResourceAllocator alloc(resourceProvider SkDEBUGCODE(, 1));
+ GrResourceAllocator alloc(dContext SkDEBUGCODE(, 1));
alloc.incOps();
alloc.incOps();
@@ -102,10 +102,10 @@
}
DEF_GPUTEST_FOR_RENDERING_CONTEXTS(ResourceAllocatorTest, reporter, ctxInfo) {
- auto direct = ctxInfo.directContext();
- const GrCaps* caps = direct->priv().caps();
- GrProxyProvider* proxyProvider = direct->priv().proxyProvider();
- GrResourceProvider* resourceProvider = direct->priv().resourceProvider();
+ auto dContext = ctxInfo.directContext();
+ const GrCaps* caps = dContext->priv().caps();
+ GrProxyProvider* proxyProvider = dContext->priv().proxyProvider();
+ GrResourceProvider* resourceProvider = dContext->priv().resourceProvider();
struct TestCase {
ProxyParams fP1;
@@ -144,13 +144,13 @@
sk_sp<GrSurfaceProxy> p1 = make_deferred(proxyProvider, caps, test.fP1);
sk_sp<GrSurfaceProxy> p2 = make_deferred(proxyProvider, caps, test.fP2);
reporter->push(SkStringPrintf("case %d", SkToInt(i)));
- overlap_test(reporter, resourceProvider, std::move(p1), std::move(p2), test.fExpectation);
+ overlap_test(reporter, dContext, std::move(p1), std::move(p2), test.fExpectation);
reporter->pop();
}
auto beFormat = caps->getDefaultBackendFormat(GrColorType::kRGBA_8888, GrRenderable::kYes);
- int k2 = direct->priv().caps()->getRenderTargetSampleCount(2, beFormat);
- int k4 = direct->priv().caps()->getRenderTargetSampleCount(4, beFormat);
+ int k2 = caps->getRenderTargetSampleCount(2, beFormat);
+ int k4 = caps->getRenderTargetSampleCount(4, beFormat);
//--------------------------------------------------------------------------------------------
TestCase gNonOverlappingTests[] = {
@@ -197,7 +197,7 @@
}
reporter->push(SkStringPrintf("case %d", SkToInt(i)));
- non_overlap_test(reporter, resourceProvider, std::move(p1), std::move(p2),
+ non_overlap_test(reporter, dContext, std::move(p1), std::move(p2),
test.fExpectation);
reporter->pop();
}
@@ -207,11 +207,11 @@
TestCase t[1] = {
{{64, kNotRT, kRGBA, kE, 1, kNotB}, {64, kNotRT, kRGBA, kE, 1, kNotB}, kDontShare}};
- sk_sp<GrSurfaceProxy> p1 = make_backend(direct, t[0].fP1);
+ sk_sp<GrSurfaceProxy> p1 = make_backend(dContext, t[0].fP1);
sk_sp<GrSurfaceProxy> p2 = make_deferred(proxyProvider, caps, t[0].fP2);
reporter->push(SkString("wrapped case"));
- non_overlap_test(reporter, resourceProvider, std::move(p1), std::move(p2),
+ non_overlap_test(reporter, dContext, std::move(p1), std::move(p2),
t[0].fExpectation);
reporter->pop();
}