Flutter Engine
The Flutter Engine
Loading...
Searching...
No Matches
Classes | Functions
ResourceAllocatorTest.cpp File Reference
#include "include/core/SkAlphaType.h"
#include "include/core/SkCanvas.h"
#include "include/core/SkColor.h"
#include "include/core/SkColorType.h"
#include "include/core/SkImageInfo.h"
#include "include/core/SkRefCnt.h"
#include "include/core/SkString.h"
#include "include/core/SkSurface.h"
#include "include/core/SkTypes.h"
#include "include/gpu/GpuTypes.h"
#include "include/gpu/GrBackendSurface.h"
#include "include/gpu/GrDirectContext.h"
#include "include/gpu/GrTypes.h"
#include "include/gpu/ganesh/SkSurfaceGanesh.h"
#include "include/private/base/SkTArray.h"
#include "include/private/base/SkTo.h"
#include "include/private/gpu/ganesh/GrTypesPriv.h"
#include "src/gpu/ResourceKey.h"
#include "src/gpu/SkBackingFit.h"
#include "src/gpu/ganesh/GrCaps.h"
#include "src/gpu/ganesh/GrDirectContextPriv.h"
#include "src/gpu/ganesh/GrProxyProvider.h"
#include "src/gpu/ganesh/GrResourceAllocator.h"
#include "src/gpu/ganesh/GrResourceCache.h"
#include "src/gpu/ganesh/GrResourceProvider.h"
#include "src/gpu/ganesh/GrSurface.h"
#include "src/gpu/ganesh/GrSurfaceProxy.h"
#include "src/gpu/ganesh/GrSurfaceProxyPriv.h"
#include "src/gpu/ganesh/GrTexture.h"
#include "src/gpu/ganesh/GrTextureProxy.h"
#include "tests/CtsEnforcement.h"
#include "tests/Test.h"
#include "tools/gpu/ManagedBackendTexture.h"
#include <array>
#include <cstddef>
#include <functional>
#include <utility>

Go to the source code of this file.

Classes

struct  Interval
 
struct  TestCase
 

Functions

static sk_sp< GrSurfaceProxymake_deferred (GrProxyProvider *proxyProvider, const GrCaps *caps, const ProxyParams &p)
 
static sk_sp< GrSurfaceProxymake_backend (GrDirectContext *dContext, const ProxyParams &p)
 
static sk_sp< GrSurfaceProxymake_fully_lazy (GrProxyProvider *proxyProvider, const GrCaps *caps, const ProxyParams &p)
 
static sk_sp< GrSurfaceProxymake_lazy (GrProxyProvider *proxyProvider, const GrCaps *caps, const ProxyParams &p)
 
static sk_sp< GrSurfaceProxymake_proxy (GrDirectContext *dContext, const ProxyParams &p)
 
static void overlap_test (skiatest::Reporter *reporter, GrDirectContext *dContext, const sk_sp< GrSurfaceProxy > &p1, const sk_sp< GrSurfaceProxy > &p2, bool expectedResult)
 
static void non_overlap_test (skiatest::Reporter *reporter, GrDirectContext *dContext, const sk_sp< GrSurfaceProxy > &p1, const sk_sp< GrSurfaceProxy > &p2, bool expectedResult)
 
 DEF_GANESH_TEST_FOR_RENDERING_CONTEXTS (ResourceAllocatorTest, reporter, ctxInfo, CtsEnforcement::kNever)
 
static void draw (GrRecordingContext *rContext)
 
 DEF_GANESH_TEST_FOR_RENDERING_CONTEXTS (ResourceAllocatorStressTest, reporter, ctxInfo, CtsEnforcement::kApiLevel_T)
 
static void memory_budget_test (skiatest::Reporter *reporter, GrDirectContext *dContext, const TestCase &test)
 
 DEF_GANESH_TEST_FOR_RENDERING_CONTEXTS (ResourceAllocatorMemoryBudgetTest, reporter, ctxInfo, CtsEnforcement::kApiLevel_T)
 

Function Documentation

◆ DEF_GANESH_TEST_FOR_RENDERING_CONTEXTS() [1/3]

DEF_GANESH_TEST_FOR_RENDERING_CONTEXTS ( ResourceAllocatorMemoryBudgetTest  ,
reporter  ,
ctxInfo  ,
CtsEnforcement::kApiLevel_T   
)

Definition at line 473 of file ResourceAllocatorTest.cpp.

476 {
477 auto dContext = ctxInfo.directContext();
478
479 constexpr bool kUnder = true;
480 constexpr bool kOver = false;
481 constexpr size_t kRGBA64Bytes = 4 * 64 * 64;
482 const ProxyParams kProxy64 = {64, kRT, kRGBA, kE, 1, kB, kDeferred};
483 const ProxyParams kProxy64NotBudgeted = {64, kRT, kRGBA, kE, 1, kNotB, kDeferred};
484 const ProxyParams kProxy64Lazy = {64, kRT, kRGBA, kE, 1, kB, kLazy};
485 const ProxyParams kProxy64FullyLazy = {64, kRT, kRGBA, kE, 1, kB, kFullyLazy};
486 const ProxyParams kProxy32Instantiated = {32, kRT, kRGBA, kE, 1, kB, kInstantiated};
487 const ProxyParams kProxy64Instantiated = {64, kRT, kRGBA, kE, 1, kB, kInstantiated};
488
489 TestCase tests[] = {
490 {"empty DAG", kUnder, 0, {}, {}, {}},
491 {"unbudgeted", kUnder, 0, {}, {}, {{kProxy64NotBudgeted, 0, 2}}},
492 {"basic", kUnder, kRGBA64Bytes, {}, {}, {{kProxy64, 0, 2}}},
493 {"basic, over", kOver, kRGBA64Bytes - 1, {}, {}, {{kProxy64, 0, 2}}},
494 {"shared", kUnder, kRGBA64Bytes, {}, {},
495 {
496 {kProxy64, 0, 2},
497 {kProxy64, 3, 5},
498 }},
499 {"retrieved from cache", kUnder, kRGBA64Bytes,
500 /* purgeable */{kProxy64Instantiated},
501 /* unpurgeable */{},
502 {
503 {kProxy64, 0, 2}
504 }},
505 {"purge 4", kUnder, kRGBA64Bytes,
506 /* purgeable */{
507 kProxy32Instantiated,
508 kProxy32Instantiated,
509 kProxy32Instantiated,
510 kProxy32Instantiated
511 },
512 /* unpurgeable */{},
513 {
514 {kProxy64, 0, 2}
515 }},
516 {"dont purge what we've reserved", kOver, kRGBA64Bytes,
517 /* purgeable */{kProxy64Instantiated},
518 /* unpurgeable */{},
519 {
520 {kProxy64, 0, 2},
521 {kProxy64, 1, 3}
522 }},
523 {"unpurgeable", kOver, kRGBA64Bytes,
524 /* purgeable */{},
525 /* unpurgeable */{kProxy64Instantiated},
526 {
527 {kProxy64, 0, 2}
528 }},
529 {"lazy", kUnder, kRGBA64Bytes,
530 /* purgeable */{},
531 /* unpurgeable */{},
532 {
533 {kProxy64Lazy, 0, 2}
534 }},
535 {"lazy, over", kOver, kRGBA64Bytes - 1,
536 /* purgeable */{},
537 /* unpurgeable */{},
538 {
539 {kProxy64Lazy, 0, 2}
540 }},
541 {"fully-lazy", kUnder, kRGBA64Bytes,
542 /* purgeable */{},
543 /* unpurgeable */{},
544 {
545 {kProxy64FullyLazy, 0, 2}
546 }},
547 {"fully-lazy, over", kOver, kRGBA64Bytes - 1,
548 /* purgeable */{},
549 /* unpurgeable */{},
550 {
551 {kProxy64FullyLazy, 0, 2}
552 }},
553 };
554 SkString match("");
555 for (size_t i = 0; i < std::size(tests); i++) {
556 TestCase& test = tests[i];
557 if (match.isEmpty() || match == SkString(test.fName)) {
558 // Create proxies
559 for (Interval& interval : test.fIntervals) {
560 interval.fProxy = make_proxy(dContext, interval.fParams);
561 }
562 reporter->push(SkString(test.fName));
563 memory_budget_test(reporter, dContext, test);
564 reporter->pop();
565 }
566 }
567}
static BlurTest tests[]
Definition BlurTest.cpp:84
static bool match(const char *needle, const char *haystack)
Definition DM.cpp:1132
reporter
static sk_sp< GrSurfaceProxy > make_proxy(GrDirectContext *dContext, const ProxyParams &p)
static void memory_budget_test(skiatest::Reporter *reporter, GrDirectContext *dContext, const TestCase &test)
@ kRGBA
Definition embedder.h:605
constexpr float kE
Definition math.h:12

◆ DEF_GANESH_TEST_FOR_RENDERING_CONTEXTS() [2/3]

DEF_GANESH_TEST_FOR_RENDERING_CONTEXTS ( ResourceAllocatorStressTest  ,
reporter  ,
ctxInfo  ,
CtsEnforcement::kApiLevel_T   
)

Definition at line 387 of file ResourceAllocatorTest.cpp.

390 {
391 auto context = ctxInfo.directContext();
392
393 size_t maxBytes = context->getResourceCacheLimit();
394
395 context->setResourceCacheLimit(0); // We'll always be overbudget
396
397 draw(context);
398 draw(context);
399 draw(context);
400 draw(context);
401 context->flushAndSubmit();
402
403 context->setResourceCacheLimit(maxBytes);
404}
static void draw(GrRecordingContext *rContext)

◆ DEF_GANESH_TEST_FOR_RENDERING_CONTEXTS() [3/3]

DEF_GANESH_TEST_FOR_RENDERING_CONTEXTS ( ResourceAllocatorTest  ,
reporter  ,
ctxInfo  ,
CtsEnforcement::kNever   
)

Definition at line 258 of file ResourceAllocatorTest.cpp.

261 {
262 auto dContext = ctxInfo.directContext();
263 const GrCaps* caps = dContext->priv().caps();
264
265 struct TestCase {
266 ProxyParams fP1;
267 ProxyParams fP2;
268 bool fExpectation;
269 };
270
271 constexpr bool kShare = true;
272 constexpr bool kDontShare = false;
273
274 // Non-RT GrSurfaces are never recycled on some platforms.
275 bool kConditionallyShare = caps->reuseScratchTextures();
276
277 static const TestCase overlappingTests[] = {
278 // Two proxies with overlapping intervals and compatible descriptors should never share
279 // RT version
280 {{64, kRT, kRGBA, kA, 1, kNotB, kDeferred},
281 {64, kRT, kRGBA, kA, 1, kNotB, kDeferred},
282 kDontShare},
283 // non-RT version
284 {{64, kNotRT, kRGBA, kA, 1, kNotB, kDeferred},
285 {64, kNotRT, kRGBA, kA, 1, kNotB, kDeferred},
286 kDontShare},
287 };
288
289 for (size_t i = 0; i < std::size(overlappingTests); i++) {
290 const TestCase& test = overlappingTests[i];
291 sk_sp<GrSurfaceProxy> p1 = make_proxy(dContext, test.fP1);
292 sk_sp<GrSurfaceProxy> p2 = make_proxy(dContext, test.fP2);
293 reporter->push(SkStringPrintf("case %d", SkToInt(i)));
294 overlap_test(reporter, dContext, std::move(p1), std::move(p2), test.fExpectation);
295 reporter->pop();
296 }
297
298 auto beFormat = caps->getDefaultBackendFormat(GrColorType::kRGBA_8888, GrRenderable::kYes);
299 int k2 = caps->getRenderTargetSampleCount(2, beFormat);
300 int k4 = caps->getRenderTargetSampleCount(4, beFormat);
301
302 // This cannot be made static as some of the members depend on non static variables like
303 // kConditionallyShare, k2, and k4.
304 const TestCase nonOverlappingTests[] = {
305 // Two non-overlapping intervals w/ compatible proxies should share
306 // both same size & approx
307 {{64, kRT, kRGBA, kA, 1, kNotB, kDeferred},
308 {64, kRT, kRGBA, kA, 1, kNotB, kDeferred},
309 kShare},
310 {{64, kNotRT, kRGBA, kA, 1, kNotB, kDeferred},
311 {64, kNotRT, kRGBA, kA, 1, kNotB, kDeferred},
312 kConditionallyShare},
313 // diffs sizes but still approx
314 {{64, kRT, kRGBA, kA, 1, kNotB, kDeferred},
315 {50, kRT, kRGBA, kA, 1, kNotB, kDeferred},
316 kShare},
317 {{64, kNotRT, kRGBA, kA, 1, kNotB, kDeferred},
318 {50, kNotRT, kRGBA, kA, 1, kNotB, kDeferred},
319 kConditionallyShare},
320 // sames sizes but exact
321 {{64, kRT, kRGBA, kE, 1, kNotB, kDeferred},
322 {64, kRT, kRGBA, kE, 1, kNotB, kDeferred},
323 kShare},
324 {{64, kNotRT, kRGBA, kE, 1, kNotB, kDeferred},
325 {64, kNotRT, kRGBA, kE, 1, kNotB, kDeferred},
326 kConditionallyShare},
327 // Two non-overlapping intervals w/ different exact sizes should not share
328 {{56, kRT, kRGBA, kE, 1, kNotB, kDeferred},
329 {54, kRT, kRGBA, kE, 1, kNotB, kDeferred},
330 kDontShare},
331 // Two non-overlapping intervals w/ _very different_ approx sizes should not share
332 {{255, kRT, kRGBA, kA, 1, kNotB, kDeferred},
333 {127, kRT, kRGBA, kA, 1, kNotB, kDeferred},
334 kDontShare},
335 // Two non-overlapping intervals w/ different MSAA sample counts should not share
336 {{64, kRT, kRGBA, kA, k2, kNotB, kDeferred},
337 {64, kRT, kRGBA, kA, k4, kNotB, kDeferred},
338 k2 == k4},
339 // Two non-overlapping intervals w/ different configs should not share
340 {{64, kRT, kRGBA, kA, 1, kNotB, kDeferred},
341 {64, kRT, kAlpha, kA, 1, kNotB, kDeferred},
342 kDontShare},
343 // Two non-overlapping intervals w/ different RT classifications should never share
344 {{64, kRT, kRGBA, kA, 1, kNotB, kDeferred},
345 {64, kNotRT, kRGBA, kA, 1, kNotB, kDeferred},
346 kDontShare},
347 {{64, kNotRT, kRGBA, kA, 1, kNotB, kDeferred},
348 {64, kRT, kRGBA, kA, 1, kNotB, kDeferred},
349 kDontShare},
350 // Two non-overlapping intervals w/ different origins should share
351 {{64, kRT, kRGBA, kA, 1, kNotB, kDeferred},
352 {64, kRT, kRGBA, kA, 1, kNotB, kDeferred},
353 kShare},
354 // Wrapped backend textures should never be reused
355 {{64, kNotRT, kRGBA, kE, 1, kNotB, kBackend},
356 {64, kNotRT, kRGBA, kE, 1, kNotB, kDeferred},
357 kDontShare}
358 };
359
360 for (size_t i = 0; i < std::size(nonOverlappingTests); i++) {
361 const TestCase& test = nonOverlappingTests[i];
362 sk_sp<GrSurfaceProxy> p1 = make_proxy(dContext, test.fP1);
363 sk_sp<GrSurfaceProxy> p2 = make_proxy(dContext, test.fP2);
364
365 if (!p1 || !p2) {
366 continue; // creation can fail (e.g., for msaa4 on iOS)
367 }
368
369 reporter->push(SkStringPrintf("case %d", SkToInt(i)));
370 non_overlap_test(reporter, dContext, std::move(p1), std::move(p2),
371 test.fExpectation);
372 reporter->pop();
373 }
374}
static const uint64_t kAlpha
static void overlap_test(skiatest::Reporter *reporter, GrDirectContext *dContext, const sk_sp< GrSurfaceProxy > &p1, const sk_sp< GrSurfaceProxy > &p2, bool expectedResult)
static void non_overlap_test(skiatest::Reporter *reporter, GrDirectContext *dContext, const sk_sp< GrSurfaceProxy > &p1, const sk_sp< GrSurfaceProxy > &p2, bool expectedResult)
SK_API SkString static SkString SkStringPrintf()
Definition SkString.h:287
constexpr int SkToInt(S x)
Definition SkTo.h:29
GrBackendFormat getDefaultBackendFormat(GrColorType, GrRenderable) const
Definition GrCaps.cpp:400
virtual int getRenderTargetSampleCount(int requestedCount, const GrBackendFormat &) const =0
bool reuseScratchTextures() const
Definition GrCaps.h:217

◆ draw()

static void draw ( GrRecordingContext rContext)
static

Definition at line 376 of file ResourceAllocatorTest.cpp.

376 {
378
380 rContext, skgpu::Budgeted::kYes, ii, 1, kTopLeft_GrSurfaceOrigin, nullptr);
381
382 SkCanvas* c = s->getCanvas();
383
385}
@ kTopLeft_GrSurfaceOrigin
Definition GrTypes.h:148
@ kPremul_SkAlphaType
pixel components are premultiplied by alpha
Definition SkAlphaType.h:29
@ kRGBA_8888_SkColorType
pixel with 8 bits for red, green, blue, alpha; in 32-bit word
Definition SkColorType.h:24
constexpr SkColor SK_ColorBLACK
Definition SkColor.h:103
void clear(SkColor color)
Definition SkCanvas.h:1199
struct MyStruct s
SK_API sk_sp< SkSurface > RenderTarget(GrRecordingContext *context, skgpu::Budgeted budgeted, const SkImageInfo &imageInfo, int sampleCount, GrSurfaceOrigin surfaceOrigin, const SkSurfaceProps *surfaceProps, bool shouldCreateWithMips=false, bool isProtected=false)
static SkImageInfo Make(int width, int height, SkColorType ct, SkAlphaType at)

◆ make_backend()

static sk_sp< GrSurfaceProxy > make_backend ( GrDirectContext dContext,
const ProxyParams &  p 
)
static

Definition at line 105 of file ResourceAllocatorTest.cpp.

105 {
106 GrProxyProvider* proxyProvider = dContext->priv().proxyProvider();
107
108 SkColorType skColorType = GrColorTypeToSkColorType(p.fColorType);
110
111 auto mbet = sk_gpu_test::ManagedBackendTexture::MakeWithoutData(
112 dContext, p.fSize, p.fSize, skColorType, skgpu::Mipmapped::kNo, GrRenderable::kNo);
113
114 if (!mbet) {
115 return nullptr;
116 }
117
118 return proxyProvider->wrapBackendTexture(mbet->texture(),
122 mbet->refCountedCallback());
123}
@ kRead_GrIOType
@ kBorrow_GrWrapOwnership
Definition GrTypesPriv.h:78
static constexpr SkColorType GrColorTypeToSkColorType(GrColorType ct)
#define SkASSERT(cond)
Definition SkAssert.h:116
SkColorType
Definition SkColorType.h:19
@ kUnknown_SkColorType
uninitialized
Definition SkColorType.h:20
GrDirectContextPriv priv()
sk_sp< GrTextureProxy > wrapBackendTexture(const GrBackendTexture &, GrWrapOwnership, GrWrapCacheable, GrIOType, sk_sp< skgpu::RefCntedCallback >=nullptr)
GrProxyProvider * proxyProvider()

◆ make_deferred()

static sk_sp< GrSurfaceProxy > make_deferred ( GrProxyProvider proxyProvider,
const GrCaps caps,
const ProxyParams &  p 
)
static

Definition at line 91 of file ResourceAllocatorTest.cpp.

92 {
93 const GrBackendFormat format = caps->getDefaultBackendFormat(p.fColorType, p.fRenderable);
94 return proxyProvider->createProxy(format,
95 {p.fSize, p.fSize},
96 p.fRenderable,
97 p.fSampleCnt,
98 skgpu::Mipmapped::kNo,
99 p.fFit,
100 p.fBudgeted,
101 GrProtected::kNo,
102 /*label=*/"ResourceAllocatorTest_Deffered");
103}
sk_sp< GrTextureProxy > createProxy(const GrBackendFormat &, SkISize dimensions, GrRenderable, int renderTargetSampleCnt, skgpu::Mipmapped, SkBackingFit, skgpu::Budgeted, GrProtected, std::string_view label, GrInternalSurfaceFlags=GrInternalSurfaceFlags::kNone, UseAllocator useAllocator=UseAllocator::kYes)
uint32_t uint32_t * format

◆ make_fully_lazy()

static sk_sp< GrSurfaceProxy > make_fully_lazy ( GrProxyProvider proxyProvider,
const GrCaps caps,
const ProxyParams &  p 
)
static

Definition at line 125 of file ResourceAllocatorTest.cpp.

126 {
127 const GrBackendFormat format = caps->getDefaultBackendFormat(p.fColorType, p.fRenderable);
128 auto cb = [p](GrResourceProvider* provider, const GrSurfaceProxy::LazySurfaceDesc& desc) {
129 auto tex = provider->createTexture({p.fSize, p.fSize},
130 desc.fFormat,
131 desc.fTextureType,
132 desc.fRenderable,
133 desc.fSampleCnt,
134 desc.fMipmapped,
135 desc.fBudgeted,
136 desc.fProtected,
137 /*label=*/"ResourceAllocatorTest_FullLazy");
138 return GrSurfaceProxy::LazyCallbackResult(std::move(tex));
139 };
140 return GrProxyProvider::MakeFullyLazyProxy(std::move(cb), format, p.fRenderable, p.fSampleCnt,
141 GrProtected::kNo, *caps,
143}
static sk_sp< GrTextureProxy > MakeFullyLazyProxy(LazyInstantiateCallback &&, const GrBackendFormat &, GrRenderable, int renderTargetSampleCnt, GrProtected, const GrCaps &, UseAllocator)
sk_sp< GrTexture > createTexture(SkISize dimensions, const GrBackendFormat &format, GrTextureType textureType, skgpu::Renderable renderable, int renderTargetSampleCnt, skgpu::Mipmapped mipmapped, skgpu::Budgeted budgeted, skgpu::Protected isProtected, std::string_view label)

◆ make_lazy()

static sk_sp< GrSurfaceProxy > make_lazy ( GrProxyProvider proxyProvider,
const GrCaps caps,
const ProxyParams &  p 
)
static

Definition at line 145 of file ResourceAllocatorTest.cpp.

146 {
147 const GrBackendFormat format = caps->getDefaultBackendFormat(p.fColorType, p.fRenderable);
148 auto cb = [](GrResourceProvider* provider, const GrSurfaceProxy::LazySurfaceDesc& desc) {
149 auto tex = provider->createTexture(desc.fDimensions,
150 desc.fFormat,
151 desc.fTextureType,
152 desc.fRenderable,
153 desc.fSampleCnt,
154 desc.fMipmapped,
155 desc.fBudgeted,
156 desc.fProtected,
157 /*label=*/"ResourceAllocatorTest_Lazy");
158 return GrSurfaceProxy::LazyCallbackResult(std::move(tex));
159 };
160 return proxyProvider->createLazyProxy(std::move(cb),
161 format,
162 {p.fSize, p.fSize},
163 skgpu::Mipmapped::kNo,
166 p.fFit,
167 p.fBudgeted,
168 GrProtected::kNo,
170 /*label=*/{});
171}
sk_sp< GrTextureProxy > createLazyProxy(LazyInstantiateCallback &&, const GrBackendFormat &, SkISize dimensions, skgpu::Mipmapped, GrMipmapStatus, GrInternalSurfaceFlags, SkBackingFit, skgpu::Budgeted, GrProtected, UseAllocator, std::string_view label)

◆ make_proxy()

static sk_sp< GrSurfaceProxy > make_proxy ( GrDirectContext dContext,
const ProxyParams &  p 
)
static

Definition at line 173 of file ResourceAllocatorTest.cpp.

173 {
174 GrProxyProvider* proxyProvider = dContext->priv().proxyProvider();
175 const GrCaps* caps = dContext->priv().caps();
177 switch (p.fKind) {
178 case ProxyParams::kDeferred:
179 proxy = make_deferred(proxyProvider, caps, p);
180 break;
181 case ProxyParams::kBackend:
182 proxy = make_backend(dContext, p);
183 break;
184 case ProxyParams::kFullyLazy:
185 proxy = make_fully_lazy(proxyProvider, caps, p);
186 break;
187 case ProxyParams::kLazy:
188 proxy = make_lazy(proxyProvider, caps, p);
189 break;
190 case ProxyParams::kInstantiated:
191 proxy = make_deferred(proxyProvider, caps, p);
192 if (proxy) {
193 auto surf = proxy->priv().createSurface(dContext->priv().resourceProvider());
194 proxy->priv().assign(std::move(surf));
195 }
196 break;
197 }
198 if (proxy && p.fUniqueKey.isValid()) {
199 SkASSERT(proxy->asTextureProxy());
200 proxyProvider->assignUniqueKeyToProxy(p.fUniqueKey, proxy->asTextureProxy());
201 }
202 return proxy;
203}
static sk_sp< GrSurfaceProxy > make_backend(GrDirectContext *dContext, const ProxyParams &p)
static sk_sp< GrSurfaceProxy > make_deferred(GrProxyProvider *proxyProvider, const GrCaps *caps, const ProxyParams &p)
static sk_sp< GrSurfaceProxy > make_lazy(GrProxyProvider *proxyProvider, const GrCaps *caps, const ProxyParams &p)
static sk_sp< GrSurfaceProxy > make_fully_lazy(GrProxyProvider *proxyProvider, const GrCaps *caps, const ProxyParams &p)
const GrCaps * caps() const
GrResourceProvider * resourceProvider()
bool assignUniqueKeyToProxy(const skgpu::UniqueKey &, GrTextureProxy *)

◆ memory_budget_test()

static void memory_budget_test ( skiatest::Reporter reporter,
GrDirectContext dContext,
const TestCase test 
)
static

Definition at line 422 of file ResourceAllocatorTest.cpp.

424 {
425 // Reset cache.
426 auto cache = dContext->priv().getResourceCache();
427 cache->releaseAll();
428 cache->setLimit(test.fBudget);
429
430 // Add purgeable entries.
431 size_t expectedPurgeableBytes = 0;
432 TArray<sk_sp<GrSurface>> purgeableSurfaces;
433 for (auto& params : test.fPurgeableResourcesInCache) {
434 SkASSERT(params.fKind == kInstantiated);
435 sk_sp<GrSurfaceProxy> proxy = make_proxy(dContext, params);
436 REPORTER_ASSERT(reporter, proxy->peekSurface());
437 expectedPurgeableBytes += proxy->gpuMemorySize();
438 purgeableSurfaces.push_back(sk_ref_sp(proxy->peekSurface()));
439 }
440 purgeableSurfaces.clear();
441 REPORTER_ASSERT(reporter, expectedPurgeableBytes == cache->getPurgeableBytes(),
442 "%zu", cache->getPurgeableBytes());
443
444 // Add unpurgeable entries.
445 size_t expectedUnpurgeableBytes = 0;
446 TArray<sk_sp<GrSurface>> unpurgeableSurfaces;
447 for (auto& params : test.fUnpurgeableResourcesInCache) {
448 SkASSERT(params.fKind == kInstantiated);
449 sk_sp<GrSurfaceProxy> proxy = make_proxy(dContext, params);
450 REPORTER_ASSERT(reporter, proxy->peekSurface());
451 expectedUnpurgeableBytes += proxy->gpuMemorySize();
452 unpurgeableSurfaces.push_back(sk_ref_sp(proxy->peekSurface()));
453 }
454
455 auto unpurgeableBytes = cache->getBudgetedResourceBytes() - cache->getPurgeableBytes();
456 REPORTER_ASSERT(reporter, expectedUnpurgeableBytes == unpurgeableBytes,
457 "%zu", unpurgeableBytes);
458
459 // Add intervals and test.
460 GrResourceAllocator alloc(dContext);
461 for (auto& interval : test.fIntervals) {
462 for (int i = interval.fStart; i <= interval.fEnd; i++) {
463 alloc.incOps();
464 }
465 alloc.addInterval(interval.fProxy.get(), interval.fStart, interval.fEnd,
468 }
469 REPORTER_ASSERT(reporter, alloc.planAssignment());
470 REPORTER_ASSERT(reporter, alloc.makeBudgetHeadroom() == test.fShouldFit);
471}
sk_sp< T > sk_ref_sp(T *obj)
Definition SkRefCnt.h:381
#define REPORTER_ASSERT(r, cond,...)
Definition Test.h:286
GrResourceCache * getResourceCache()
const EmbeddedViewParams * params
DEF_SWITCHES_START aot vmservice shared library Name of the *so containing AOT compiled Dart assets for launching the service isolate vm snapshot The VM snapshot data that will be memory mapped as read only SnapshotAssetPath must be present isolate snapshot The isolate snapshot data that will be memory mapped as read only SnapshotAssetPath must be present cache dir Path to the cache directory This is different from the persistent_cache_path in embedder which is used for Skia shader cache icu native lib Path to the library file that exports the ICU data vm service The hostname IP address on which the Dart VM Service should be served If not defaults to or::depending on whether ipv6 is specified vm service A custom Dart VM Service port The default is to pick a randomly available open port disable vm Disable the Dart VM Service The Dart VM Service is never available in release mode disable vm service Disable mDNS Dart VM Service publication Bind to the IPv6 localhost address for the Dart VM Service Ignored if vm service host is set endless trace Enable an endless trace buffer The default is a ring buffer This is useful when very old events need to viewed For during application launch Memory usage will continue to grow indefinitely however Start app with an specific route defined on the framework flutter assets Path to the Flutter assets directory enable service port Allow the VM service to fallback to automatic port selection if binding to a specified port fails trace Trace early application lifecycle Automatically switches to an endless trace buffer trace skia Filters out all Skia trace event categories except those that are specified in this comma separated list dump skp on shader Automatically dump the skp that triggers new shader compilations This is useful for writing custom ShaderWarmUp to reduce jank By this is not enabled to reduce the overhead purge persistent cache
Definition switches.h:191

◆ non_overlap_test()

static void non_overlap_test ( skiatest::Reporter reporter,
GrDirectContext dContext,
const sk_sp< GrSurfaceProxy > &  p1,
const sk_sp< GrSurfaceProxy > &  p2,
bool  expectedResult 
)
static

Definition at line 231 of file ResourceAllocatorTest.cpp.

233 {
234 GrResourceAllocator alloc(dContext);
235
236 alloc.incOps();
237 alloc.incOps();
238 alloc.incOps();
239 alloc.incOps();
240 alloc.incOps();
241 alloc.incOps();
242
243 alloc.addInterval(p1.get(), 0, 2, GrResourceAllocator::ActualUse::kYes,
245 alloc.addInterval(p2.get(), 3, 5, GrResourceAllocator::ActualUse::kYes,
247
248 REPORTER_ASSERT(reporter, alloc.planAssignment());
249 REPORTER_ASSERT(reporter, alloc.makeBudgetHeadroom());
250 REPORTER_ASSERT(reporter, alloc.assign());
251
254 bool doTheBackingStoresMatch = p1->underlyingUniqueID() == p2->underlyingUniqueID();
255 REPORTER_ASSERT(reporter, expectedResult == doTheBackingStoresMatch);
256}
UniqueID underlyingUniqueID() const
GrSurface * peekSurface() const
T * get() const
Definition SkRefCnt.h:303

◆ overlap_test()

static void overlap_test ( skiatest::Reporter reporter,
GrDirectContext dContext,
const sk_sp< GrSurfaceProxy > &  p1,
const sk_sp< GrSurfaceProxy > &  p2,
bool  expectedResult 
)
static

Definition at line 207 of file ResourceAllocatorTest.cpp.

209 {
210 GrResourceAllocator alloc(dContext);
211
212 alloc.addInterval(p1.get(), 0, 4, GrResourceAllocator::ActualUse::kYes,
214 alloc.incOps();
215 alloc.addInterval(p2.get(), 1, 2, GrResourceAllocator::ActualUse::kYes,
217 alloc.incOps();
218
219 REPORTER_ASSERT(reporter, alloc.planAssignment());
220 REPORTER_ASSERT(reporter, alloc.makeBudgetHeadroom());
221 REPORTER_ASSERT(reporter, alloc.assign());
222
225 bool doTheBackingStoresMatch = p1->underlyingUniqueID() == p2->underlyingUniqueID();
226 REPORTER_ASSERT(reporter, expectedResult == doTheBackingStoresMatch);
227}