2017-07-18 18:49:38 +00:00
|
|
|
/*
|
|
|
|
* Copyright 2017 Google Inc.
|
|
|
|
*
|
|
|
|
* Use of this source code is governed by a BSD-style license that can be
|
|
|
|
* found in the LICENSE file.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "SkTypes.h"
|
|
|
|
|
|
|
|
#include "Test.h"
|
|
|
|
|
2017-07-21 15:38:13 +00:00
|
|
|
#include "GrContextPriv.h"
|
2018-12-07 16:15:53 +00:00
|
|
|
#include "GrDeinstantiateProxyTracker.h"
|
2017-07-21 15:38:13 +00:00
|
|
|
#include "GrGpu.h"
|
2018-01-16 13:06:32 +00:00
|
|
|
#include "GrProxyProvider.h"
|
2017-07-18 18:49:38 +00:00
|
|
|
#include "GrResourceAllocator.h"
|
2017-07-21 15:38:13 +00:00
|
|
|
#include "GrResourceProvider.h"
|
2017-07-18 18:49:38 +00:00
|
|
|
#include "GrSurfaceProxyPriv.h"
|
2017-07-21 15:38:13 +00:00
|
|
|
#include "GrTexture.h"
|
2017-07-18 18:49:38 +00:00
|
|
|
#include "GrTextureProxy.h"
|
|
|
|
|
2018-08-21 17:52:09 +00:00
|
|
|
#include "SkSurface.h"
|
|
|
|
|
2017-07-21 15:38:13 +00:00
|
|
|
struct ProxyParams {
|
|
|
|
int fSize;
|
|
|
|
bool fIsRT;
|
2018-09-25 13:31:10 +00:00
|
|
|
SkColorType fColorType;
|
2017-07-21 15:38:13 +00:00
|
|
|
SkBackingFit fFit;
|
|
|
|
int fSampleCnt;
|
|
|
|
GrSurfaceOrigin fOrigin;
|
|
|
|
// TODO: do we care about mipmapping
|
|
|
|
};
|
|
|
|
|
2018-11-16 20:43:41 +00:00
|
|
|
static GrSurfaceProxy* make_deferred(GrProxyProvider* proxyProvider, const GrCaps* caps,
|
|
|
|
const ProxyParams& p) {
|
2018-09-25 13:31:10 +00:00
|
|
|
GrColorType grCT = SkColorTypeToGrColorType(p.fColorType);
|
|
|
|
GrPixelConfig config = GrColorTypeToPixelConfig(grCT, GrSRGBEncoded::kNo);
|
|
|
|
|
2017-07-18 18:49:38 +00:00
|
|
|
GrSurfaceDesc desc;
|
2017-07-21 15:38:13 +00:00
|
|
|
desc.fFlags = p.fIsRT ? kRenderTarget_GrSurfaceFlag : kNone_GrSurfaceFlags;
|
|
|
|
desc.fWidth = p.fSize;
|
|
|
|
desc.fHeight = p.fSize;
|
2018-09-25 13:31:10 +00:00
|
|
|
desc.fConfig = config;
|
2017-07-21 15:38:13 +00:00
|
|
|
desc.fSampleCnt = p.fSampleCnt;
|
|
|
|
|
2018-11-16 20:43:41 +00:00
|
|
|
const GrBackendFormat format = caps->getBackendFormatFromColorType(p.fColorType);
|
|
|
|
|
|
|
|
auto tmp = proxyProvider->createProxy(format, desc, p.fOrigin, p.fFit, SkBudgeted::kNo);
|
2018-07-18 17:56:48 +00:00
|
|
|
if (!tmp) {
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
GrSurfaceProxy* ret = tmp.release();
|
|
|
|
|
|
|
|
// Add a read to keep the proxy around but unref it so its backing surfaces can be recycled
|
|
|
|
ret->addPendingRead();
|
|
|
|
ret->unref();
|
|
|
|
return ret;
|
2017-07-21 15:38:13 +00:00
|
|
|
}
|
|
|
|
|
2018-07-18 17:56:48 +00:00
|
|
|
static GrSurfaceProxy* make_backend(GrContext* context, const ProxyParams& p,
|
|
|
|
GrBackendTexture* backendTex) {
|
2019-02-04 18:26:26 +00:00
|
|
|
GrProxyProvider* proxyProvider = context->priv().proxyProvider();
|
|
|
|
GrGpu* gpu = context->priv().getGpu();
|
2018-01-16 13:06:32 +00:00
|
|
|
|
2018-01-22 15:48:15 +00:00
|
|
|
*backendTex = gpu->createTestingOnlyBackendTexture(nullptr, p.fSize, p.fSize,
|
2018-09-25 13:31:10 +00:00
|
|
|
p.fColorType, false,
|
2018-01-22 15:48:15 +00:00
|
|
|
GrMipMapped::kNo);
|
2018-09-25 13:31:10 +00:00
|
|
|
if (!backendTex->isValid()) {
|
|
|
|
return nullptr;
|
|
|
|
}
|
2017-12-12 18:01:25 +00:00
|
|
|
|
2018-12-06 15:00:03 +00:00
|
|
|
auto tmp = proxyProvider->wrapBackendTexture(*backendTex, p.fOrigin, kBorrow_GrWrapOwnership,
|
2019-01-24 21:03:07 +00:00
|
|
|
GrWrapCacheable::kNo, kRead_GrIOType);
|
2018-07-18 17:56:48 +00:00
|
|
|
if (!tmp) {
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
GrSurfaceProxy* ret = tmp.release();
|
|
|
|
|
|
|
|
// Add a read to keep the proxy around but unref it so its backing surfaces can be recycled
|
|
|
|
ret->addPendingRead();
|
|
|
|
ret->unref();
|
|
|
|
return ret;
|
2017-07-21 15:38:13 +00:00
|
|
|
}
|
2017-07-18 18:49:38 +00:00
|
|
|
|
2018-03-09 14:33:19 +00:00
|
|
|
static void cleanup_backend(GrContext* context, const GrBackendTexture& backendTex) {
|
2019-02-04 18:26:26 +00:00
|
|
|
context->priv().getGpu()->deleteTestingOnlyBackendTexture(backendTex);
|
2017-07-21 15:38:13 +00:00
|
|
|
}
|
2017-07-18 18:49:38 +00:00
|
|
|
|
2017-07-21 15:38:13 +00:00
|
|
|
// Basic test that two proxies with overlapping intervals and compatible descriptors are
|
|
|
|
// assigned different GrSurfaces.
|
|
|
|
static void overlap_test(skiatest::Reporter* reporter, GrResourceProvider* resourceProvider,
|
2018-07-18 17:56:48 +00:00
|
|
|
GrSurfaceProxy* p1, GrSurfaceProxy* p2, bool expectedResult) {
|
2018-12-07 16:15:53 +00:00
|
|
|
GrDeinstantiateProxyTracker deinstantiateTracker;
|
|
|
|
GrResourceAllocator alloc(resourceProvider, &deinstantiateTracker);
|
2017-07-18 18:49:38 +00:00
|
|
|
|
2018-07-18 17:56:48 +00:00
|
|
|
alloc.addInterval(p1, 0, 4);
|
|
|
|
alloc.addInterval(p2, 1, 2);
|
2017-11-16 12:52:08 +00:00
|
|
|
alloc.markEndOfOpList(0);
|
2017-07-18 18:49:38 +00:00
|
|
|
|
2017-11-16 12:52:08 +00:00
|
|
|
int startIndex, stopIndex;
|
2018-01-29 15:34:25 +00:00
|
|
|
GrResourceAllocator::AssignError error;
|
2018-11-30 18:32:23 +00:00
|
|
|
alloc.assign(&startIndex, &stopIndex, &error);
|
2018-01-29 15:34:25 +00:00
|
|
|
REPORTER_ASSERT(reporter, GrResourceAllocator::AssignError::kNoError == error);
|
2017-07-18 18:49:38 +00:00
|
|
|
|
2018-07-31 21:25:29 +00:00
|
|
|
REPORTER_ASSERT(reporter, p1->peekSurface());
|
|
|
|
REPORTER_ASSERT(reporter, p2->peekSurface());
|
2017-07-21 15:38:13 +00:00
|
|
|
bool doTheBackingStoresMatch = p1->underlyingUniqueID() == p2->underlyingUniqueID();
|
|
|
|
REPORTER_ASSERT(reporter, expectedResult == doTheBackingStoresMatch);
|
|
|
|
}
|
|
|
|
|
|
|
|
// 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,
|
2018-07-18 17:56:48 +00:00
|
|
|
GrSurfaceProxy* p1, GrSurfaceProxy* p2,
|
2017-07-21 15:38:13 +00:00
|
|
|
bool expectedResult) {
|
2018-12-07 16:15:53 +00:00
|
|
|
GrDeinstantiateProxyTracker deinstantiateTracker;
|
|
|
|
GrResourceAllocator alloc(resourceProvider, &deinstantiateTracker);
|
2017-07-21 15:38:13 +00:00
|
|
|
|
2018-07-18 17:56:48 +00:00
|
|
|
alloc.addInterval(p1, 0, 2);
|
|
|
|
alloc.addInterval(p2, 3, 5);
|
2017-11-16 12:52:08 +00:00
|
|
|
alloc.markEndOfOpList(0);
|
2017-07-21 15:38:13 +00:00
|
|
|
|
2017-11-16 12:52:08 +00:00
|
|
|
int startIndex, stopIndex;
|
2018-01-29 15:34:25 +00:00
|
|
|
GrResourceAllocator::AssignError error;
|
2018-11-30 18:32:23 +00:00
|
|
|
alloc.assign(&startIndex, &stopIndex, &error);
|
2018-01-29 15:34:25 +00:00
|
|
|
REPORTER_ASSERT(reporter, GrResourceAllocator::AssignError::kNoError == error);
|
2017-07-21 15:38:13 +00:00
|
|
|
|
2018-07-31 21:25:29 +00:00
|
|
|
REPORTER_ASSERT(reporter, p1->peekSurface());
|
|
|
|
REPORTER_ASSERT(reporter, p2->peekSurface());
|
2017-07-21 15:38:13 +00:00
|
|
|
bool doTheBackingStoresMatch = p1->underlyingUniqueID() == p2->underlyingUniqueID();
|
|
|
|
REPORTER_ASSERT(reporter, expectedResult == doTheBackingStoresMatch);
|
2017-07-18 18:49:38 +00:00
|
|
|
}
|
|
|
|
|
2018-02-07 22:08:21 +00:00
|
|
|
bool GrResourceProvider::testingOnly_setExplicitlyAllocateGPUResources(bool newValue) {
|
|
|
|
bool oldValue = fExplicitlyAllocateGPUResources;
|
|
|
|
fExplicitlyAllocateGPUResources = newValue;
|
|
|
|
return oldValue;
|
|
|
|
}
|
|
|
|
|
2017-07-21 15:38:13 +00:00
|
|
|
DEF_GPUTEST_FOR_RENDERING_CONTEXTS(ResourceAllocatorTest, reporter, ctxInfo) {
|
2019-02-04 18:26:26 +00:00
|
|
|
const GrCaps* caps = ctxInfo.grContext()->priv().caps();
|
|
|
|
GrProxyProvider* proxyProvider = ctxInfo.grContext()->priv().proxyProvider();
|
|
|
|
GrResourceProvider* resourceProvider = ctxInfo.grContext()->priv().resourceProvider();
|
2017-07-18 18:49:38 +00:00
|
|
|
|
2018-02-07 22:08:21 +00:00
|
|
|
bool orig = resourceProvider->testingOnly_setExplicitlyAllocateGPUResources(true);
|
|
|
|
|
2017-07-21 15:38:13 +00:00
|
|
|
struct TestCase {
|
|
|
|
ProxyParams fP1;
|
|
|
|
ProxyParams fP2;
|
|
|
|
bool fExpectation;
|
|
|
|
};
|
|
|
|
|
|
|
|
constexpr bool kRT = true;
|
|
|
|
constexpr bool kNotRT = false;
|
|
|
|
|
|
|
|
constexpr bool kShare = true;
|
|
|
|
constexpr bool kDontShare = false;
|
|
|
|
// Non-RT GrSurfaces are never recycled on some platforms.
|
|
|
|
bool kConditionallyShare = resourceProvider->caps()->reuseScratchTextures();
|
|
|
|
|
2018-09-25 13:31:10 +00:00
|
|
|
const SkColorType kRGBA = kRGBA_8888_SkColorType;
|
|
|
|
const SkColorType kBGRA = kBGRA_8888_SkColorType;
|
2017-07-21 15:38:13 +00:00
|
|
|
|
|
|
|
const SkBackingFit kE = SkBackingFit::kExact;
|
|
|
|
const SkBackingFit kA = SkBackingFit::kApprox;
|
|
|
|
|
|
|
|
const GrSurfaceOrigin kTL = kTopLeft_GrSurfaceOrigin;
|
|
|
|
const GrSurfaceOrigin kBL = kBottomLeft_GrSurfaceOrigin;
|
|
|
|
|
|
|
|
//--------------------------------------------------------------------------------------------
|
|
|
|
TestCase gOverlappingTests[] = {
|
|
|
|
//----------------------------------------------------------------------------------------
|
|
|
|
// Two proxies with overlapping intervals and compatible descriptors should never share
|
|
|
|
// RT version
|
|
|
|
{ { 64, kRT, kRGBA, kA, 0, kTL }, { 64, kRT, kRGBA, kA, 0, kTL }, kDontShare },
|
|
|
|
// non-RT version
|
|
|
|
{ { 64, kNotRT, kRGBA, kA, 0, kTL }, { 64, kNotRT, kRGBA, kA, 0, kTL }, kDontShare },
|
|
|
|
};
|
|
|
|
|
|
|
|
for (auto test : gOverlappingTests) {
|
2018-11-16 20:43:41 +00:00
|
|
|
GrSurfaceProxy* p1 = make_deferred(proxyProvider, caps, test.fP1);
|
|
|
|
GrSurfaceProxy* p2 = make_deferred(proxyProvider, caps, test.fP2);
|
2018-07-18 17:56:48 +00:00
|
|
|
overlap_test(reporter, resourceProvider, p1, p2, test.fExpectation);
|
|
|
|
p1->completedRead();
|
|
|
|
p2->completedRead();
|
2017-07-21 15:38:13 +00:00
|
|
|
}
|
|
|
|
|
2019-02-04 18:26:26 +00:00
|
|
|
int k2 = ctxInfo.grContext()->priv().caps()->getRenderTargetSampleCount(
|
2018-09-25 13:31:10 +00:00
|
|
|
2, kRGBA_8888_GrPixelConfig);
|
2019-02-04 18:26:26 +00:00
|
|
|
int k4 = ctxInfo.grContext()->priv().caps()->getRenderTargetSampleCount(
|
2018-09-25 13:31:10 +00:00
|
|
|
4, kRGBA_8888_GrPixelConfig);
|
2017-07-21 15:38:13 +00:00
|
|
|
|
|
|
|
//--------------------------------------------------------------------------------------------
|
|
|
|
TestCase gNonOverlappingTests[] = {
|
|
|
|
//----------------------------------------------------------------------------------------
|
|
|
|
// Two non-overlapping intervals w/ compatible proxies should share
|
|
|
|
// both same size & approx
|
|
|
|
{ { 64, kRT, kRGBA, kA, 0, kTL }, { 64, kRT, kRGBA, kA, 0, kTL }, kShare },
|
|
|
|
{ { 64, kNotRT, kRGBA, kA, 0, kTL }, { 64, kNotRT, kRGBA, kA, 0, kTL }, kConditionallyShare },
|
|
|
|
// diffs sizes but still approx
|
|
|
|
{ { 64, kRT, kRGBA, kA, 0, kTL }, { 50, kRT, kRGBA, kA, 0, kTL }, kShare },
|
|
|
|
{ { 64, kNotRT, kRGBA, kA, 0, kTL }, { 50, kNotRT, kRGBA, kA, 0, kTL }, kConditionallyShare },
|
|
|
|
// sames sizes but exact
|
|
|
|
{ { 64, kRT, kRGBA, kE, 0, kTL }, { 64, kRT, kRGBA, kE, 0, kTL }, kShare },
|
|
|
|
{ { 64, kNotRT, kRGBA, kE, 0, kTL }, { 64, kNotRT, kRGBA, kE, 0, kTL }, kConditionallyShare },
|
|
|
|
//----------------------------------------------------------------------------------------
|
|
|
|
// Two non-overlapping intervals w/ different exact sizes should not share
|
|
|
|
{ { 56, kRT, kRGBA, kE, 0, kTL }, { 54, kRT, kRGBA, kE, 0, kTL }, kDontShare },
|
|
|
|
// Two non-overlapping intervals w/ _very different_ approx sizes should not share
|
|
|
|
{ { 255, kRT, kRGBA, kA, 0, kTL }, { 127, kRT, kRGBA, kA, 0, kTL }, kDontShare },
|
|
|
|
// Two non-overlapping intervals w/ different MSAA sample counts should not share
|
|
|
|
{ { 64, kRT, kRGBA, kA, k2, kTL },{ 64, kRT, kRGBA, kA, k4, kTL}, k2 == k4 },
|
|
|
|
// Two non-overlapping intervals w/ different configs should not share
|
|
|
|
{ { 64, kRT, kRGBA, kA, 0, kTL }, { 64, kRT, kBGRA, kA, 0, kTL }, kDontShare },
|
|
|
|
// Two non-overlapping intervals w/ different RT classifications should never share
|
|
|
|
{ { 64, kRT, kRGBA, kA, 0, kTL }, { 64, kNotRT, kRGBA, kA, 0, kTL }, kDontShare },
|
|
|
|
{ { 64, kNotRT, kRGBA, kA, 0, kTL }, { 64, kRT, kRGBA, kA, 0, kTL }, kDontShare },
|
2017-08-29 12:26:54 +00:00
|
|
|
// Two non-overlapping intervals w/ different origins should share
|
|
|
|
{ { 64, kRT, kRGBA, kA, 0, kTL }, { 64, kRT, kRGBA, kA, 0, kBL }, kShare },
|
2017-07-21 15:38:13 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
for (auto test : gNonOverlappingTests) {
|
2018-11-16 20:43:41 +00:00
|
|
|
GrSurfaceProxy* p1 = make_deferred(proxyProvider, caps, test.fP1);
|
|
|
|
GrSurfaceProxy* p2 = make_deferred(proxyProvider, caps, test.fP2);
|
2018-07-18 17:56:48 +00:00
|
|
|
|
2017-07-21 15:38:13 +00:00
|
|
|
if (!p1 || !p2) {
|
|
|
|
continue; // creation can fail (i.e., for msaa4 on iOS)
|
|
|
|
}
|
2018-07-18 17:56:48 +00:00
|
|
|
|
|
|
|
non_overlap_test(reporter, resourceProvider, p1, p2, test.fExpectation);
|
|
|
|
|
|
|
|
p1->completedRead();
|
|
|
|
p2->completedRead();
|
2017-07-21 15:38:13 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
{
|
|
|
|
// Wrapped backend textures should never be reused
|
|
|
|
TestCase t[1] = {
|
|
|
|
{ { 64, kNotRT, kRGBA, kE, 0, kTL }, { 64, kNotRT, kRGBA, kE, 0, kTL }, kDontShare }
|
|
|
|
};
|
|
|
|
|
2017-12-12 18:01:25 +00:00
|
|
|
GrBackendTexture backEndTex;
|
2018-07-18 17:56:48 +00:00
|
|
|
GrSurfaceProxy* p1 = make_backend(ctxInfo.grContext(), t[0].fP1, &backEndTex);
|
2018-11-16 20:43:41 +00:00
|
|
|
GrSurfaceProxy* p2 = make_deferred(proxyProvider, caps, t[0].fP2);
|
2018-07-18 17:56:48 +00:00
|
|
|
|
|
|
|
non_overlap_test(reporter, resourceProvider, p1, p2, t[0].fExpectation);
|
|
|
|
|
|
|
|
p1->completedRead();
|
|
|
|
p2->completedRead();
|
|
|
|
|
2018-03-09 14:33:19 +00:00
|
|
|
cleanup_backend(ctxInfo.grContext(), backEndTex);
|
2017-07-21 15:38:13 +00:00
|
|
|
}
|
2018-02-07 22:08:21 +00:00
|
|
|
|
|
|
|
resourceProvider->testingOnly_setExplicitlyAllocateGPUResources(orig);
|
2017-07-18 18:49:38 +00:00
|
|
|
}
|
2018-08-21 17:52:09 +00:00
|
|
|
|
|
|
|
static void draw(GrContext* context) {
|
|
|
|
SkImageInfo ii = SkImageInfo::Make(1024, 1024, kRGBA_8888_SkColorType, kPremul_SkAlphaType);
|
|
|
|
|
|
|
|
sk_sp<SkSurface> s = SkSurface::MakeRenderTarget(context, SkBudgeted::kYes,
|
|
|
|
ii, 1, kTopLeft_GrSurfaceOrigin, nullptr);
|
|
|
|
|
|
|
|
SkCanvas* c = s->getCanvas();
|
|
|
|
|
|
|
|
c->clear(SK_ColorBLACK);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
DEF_GPUTEST_FOR_RENDERING_CONTEXTS(ResourceAllocatorStressTest, reporter, ctxInfo) {
|
|
|
|
GrContext* context = ctxInfo.grContext();
|
2019-02-04 18:26:26 +00:00
|
|
|
GrResourceProvider* resourceProvider = ctxInfo.grContext()->priv().resourceProvider();
|
2018-08-21 17:52:09 +00:00
|
|
|
|
|
|
|
int maxNum;
|
|
|
|
size_t maxBytes;
|
|
|
|
context->getResourceCacheLimits(&maxNum, &maxBytes);
|
|
|
|
|
|
|
|
bool orig = resourceProvider->testingOnly_setExplicitlyAllocateGPUResources(true);
|
|
|
|
context->setResourceCacheLimits(0, 0); // We'll always be overbudget
|
|
|
|
|
|
|
|
draw(context);
|
|
|
|
draw(context);
|
|
|
|
draw(context);
|
|
|
|
draw(context);
|
|
|
|
context->flush();
|
|
|
|
|
|
|
|
context->setResourceCacheLimits(maxNum, maxBytes);
|
|
|
|
resourceProvider->testingOnly_setExplicitlyAllocateGPUResources(orig);
|
|
|
|
}
|
2018-11-30 18:32:23 +00:00
|
|
|
|
|
|
|
sk_sp<GrSurfaceProxy> make_lazy(GrProxyProvider* proxyProvider, const GrCaps* caps,
|
|
|
|
const ProxyParams& p, bool deinstantiate) {
|
|
|
|
GrColorType grCT = SkColorTypeToGrColorType(p.fColorType);
|
|
|
|
GrPixelConfig config = GrColorTypeToPixelConfig(grCT, GrSRGBEncoded::kNo);
|
|
|
|
|
|
|
|
GrSurfaceDesc desc;
|
|
|
|
desc.fFlags = p.fIsRT ? kRenderTarget_GrSurfaceFlag : kNone_GrSurfaceFlags;
|
|
|
|
desc.fWidth = p.fSize;
|
|
|
|
desc.fHeight = p.fSize;
|
|
|
|
desc.fConfig = config;
|
|
|
|
desc.fSampleCnt = p.fSampleCnt;
|
|
|
|
|
|
|
|
SkBackingFit fit = p.fFit;
|
|
|
|
auto callback = [fit, desc](GrResourceProvider* resourceProvider) -> sk_sp<GrSurface> {
|
|
|
|
if (!resourceProvider) {
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
if (fit == SkBackingFit::kApprox) {
|
|
|
|
return resourceProvider->createApproxTexture(desc, GrResourceProvider::Flags::kNone);
|
|
|
|
} else {
|
|
|
|
return resourceProvider->createTexture(desc, SkBudgeted::kNo);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
const GrBackendFormat format = caps->getBackendFormatFromColorType(p.fColorType);
|
2018-12-07 16:15:53 +00:00
|
|
|
auto lazyType = deinstantiate ? GrSurfaceProxy::LazyInstantiationType ::kDeinstantiate
|
2018-11-30 18:32:23 +00:00
|
|
|
: GrSurfaceProxy::LazyInstantiationType ::kSingleUse;
|
|
|
|
GrInternalSurfaceFlags flags = GrInternalSurfaceFlags::kNone;
|
|
|
|
return proxyProvider->createLazyProxy(callback, format, desc, p.fOrigin, GrMipMapped::kNo,
|
|
|
|
flags, p.fFit, SkBudgeted::kNo, lazyType);
|
|
|
|
}
|
|
|
|
|
|
|
|
DEF_GPUTEST_FOR_RENDERING_CONTEXTS(LazyDeinstantiation, reporter, ctxInfo) {
|
|
|
|
GrContext* context = ctxInfo.grContext();
|
2019-02-04 18:26:26 +00:00
|
|
|
GrResourceProvider* resourceProvider = ctxInfo.grContext()->priv().resourceProvider();
|
2018-11-30 18:32:23 +00:00
|
|
|
for (auto explicitlyAllocating : {false, true}) {
|
|
|
|
resourceProvider->testingOnly_setExplicitlyAllocateGPUResources(explicitlyAllocating);
|
|
|
|
ProxyParams texParams;
|
|
|
|
texParams.fFit = SkBackingFit::kExact;
|
|
|
|
texParams.fOrigin = kTopLeft_GrSurfaceOrigin;
|
|
|
|
texParams.fColorType = kRGBA_8888_SkColorType;
|
|
|
|
texParams.fIsRT = false;
|
|
|
|
texParams.fSampleCnt = 1;
|
|
|
|
texParams.fSize = 100;
|
|
|
|
ProxyParams rtParams = texParams;
|
|
|
|
rtParams.fIsRT = true;
|
2019-02-04 18:26:26 +00:00
|
|
|
auto proxyProvider = context->priv().proxyProvider();
|
|
|
|
auto caps = context->priv().caps();
|
2018-11-30 18:32:23 +00:00
|
|
|
auto p0 = make_lazy(proxyProvider, caps, texParams, true);
|
|
|
|
auto p1 = make_lazy(proxyProvider, caps, texParams, false);
|
|
|
|
texParams.fFit = rtParams.fFit = SkBackingFit::kApprox;
|
|
|
|
auto p2 = make_lazy(proxyProvider, caps, rtParams, true);
|
|
|
|
auto p3 = make_lazy(proxyProvider, caps, rtParams, false);
|
|
|
|
|
2018-12-07 16:15:53 +00:00
|
|
|
GrDeinstantiateProxyTracker deinstantiateTracker;
|
2018-11-30 18:32:23 +00:00
|
|
|
{
|
2018-12-07 16:15:53 +00:00
|
|
|
GrResourceAllocator alloc(resourceProvider, &deinstantiateTracker);
|
2018-11-30 18:32:23 +00:00
|
|
|
alloc.addInterval(p0.get(), 0, 1);
|
|
|
|
alloc.addInterval(p1.get(), 0, 1);
|
|
|
|
alloc.addInterval(p2.get(), 0, 1);
|
|
|
|
alloc.addInterval(p3.get(), 0, 1);
|
|
|
|
alloc.markEndOfOpList(0);
|
|
|
|
int startIndex, stopIndex;
|
|
|
|
GrResourceAllocator::AssignError error;
|
|
|
|
alloc.assign(&startIndex, &stopIndex, &error);
|
|
|
|
}
|
2018-12-07 16:15:53 +00:00
|
|
|
deinstantiateTracker.deinstantiateAllProxies();
|
2018-11-30 18:32:23 +00:00
|
|
|
REPORTER_ASSERT(reporter, !p0->isInstantiated());
|
|
|
|
REPORTER_ASSERT(reporter, p1->isInstantiated());
|
|
|
|
REPORTER_ASSERT(reporter, !p2->isInstantiated());
|
|
|
|
REPORTER_ASSERT(reporter, p3->isInstantiated());
|
|
|
|
}
|
|
|
|
}
|