Flutter Engine
The Flutter Engine
Functions | Variables
TextureProxyTest.cpp File Reference
#include "include/core/SkAlphaType.h"
#include "include/core/SkBitmap.h"
#include "include/core/SkColorType.h"
#include "include/core/SkImage.h"
#include "include/core/SkImageInfo.h"
#include "include/core/SkRect.h"
#include "include/core/SkRefCnt.h"
#include "include/core/SkSize.h"
#include "include/core/SkTypes.h"
#include "include/gpu/GpuTypes.h"
#include "include/gpu/GrBackendSurface.h"
#include "include/gpu/GrDirectContext.h"
#include "include/gpu/GrRecordingContext.h"
#include "include/gpu/GrTypes.h"
#include "include/gpu/ganesh/SkImageGanesh.h"
#include "include/private/gpu/ganesh/GrTypesPriv.h"
#include "src/core/SkMessageBus.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/GrGpuResourcePriv.h"
#include "src/gpu/ganesh/GrProxyProvider.h"
#include "src/gpu/ganesh/GrRecordingContextPriv.h"
#include "src/gpu/ganesh/GrResourceCache.h"
#include "src/gpu/ganesh/GrSurface.h"
#include "src/gpu/ganesh/GrTexture.h"
#include "src/gpu/ganesh/GrTextureProxy.h"
#include "src/gpu/ganesh/SkGr.h"
#include "tests/CtsEnforcement.h"
#include "tests/Test.h"
#include "tools/gpu/ManagedBackendTexture.h"
#include <cstddef>
#include <cstdint>
#include <initializer_list>

Go to the source code of this file.

Functions

static sk_sp< GrTextureProxydeferred_tex (skiatest::Reporter *reporter, GrRecordingContext *rContext, GrProxyProvider *proxyProvider, SkBackingFit fit)
 
static sk_sp< GrTextureProxydeferred_texRT (skiatest::Reporter *reporter, GrRecordingContext *rContext, GrProxyProvider *proxyProvider, SkBackingFit fit)
 
static sk_sp< GrTextureProxywrapped (skiatest::Reporter *reporter, GrRecordingContext *rContext, GrProxyProvider *proxyProvider, SkBackingFit fit)
 
static sk_sp< GrTextureProxywrapped_with_key (skiatest::Reporter *reporter, GrRecordingContext *rContext, GrProxyProvider *proxyProvider, SkBackingFit fit)
 
static sk_sp< GrTextureProxycreate_wrapped_backend (GrDirectContext *dContext)
 
static void basic_test (GrDirectContext *dContext, skiatest::Reporter *reporter, sk_sp< GrTextureProxy > proxy, int cacheEntriesPerProxy)
 
static void invalidation_test (GrDirectContext *dContext, skiatest::Reporter *reporter, int cacheEntriesPerProxy)
 
static void invalidation_and_instantiation_test (GrDirectContext *dContext, skiatest::Reporter *reporter, int cacheEntriesPerProxy)
 
 DEF_GANESH_TEST_FOR_RENDERING_CONTEXTS (TextureProxyTest, reporter, ctxInfo, CtsEnforcement::kApiLevel_T)
 

Variables

static constexpr auto kColorType = GrColorType::kRGBA_8888
 
static constexpr auto kSize = SkISize::Make(64, 64)
 

Function Documentation

◆ basic_test()

static void basic_test ( GrDirectContext dContext,
skiatest::Reporter reporter,
sk_sp< GrTextureProxy proxy,
int  cacheEntriesPerProxy 
)
static

Definition at line 176 of file TextureProxyTest.cpp.

179 {
180 static int id = 1;
181
182 GrResourceProvider* resourceProvider = dContext->priv().resourceProvider();
183 GrProxyProvider* proxyProvider = dContext->priv().proxyProvider();
185
186 int startCacheCount = cache->getResourceCount();
187
189 if (proxy->getUniqueKey().isValid()) {
190 key = proxy->getUniqueKey();
191 } else {
193 ++id;
194
195 // Assigning the uniqueKey adds the proxy to the hash but doesn't force instantiation
197 SkAssertResult(proxyProvider->assignUniqueKeyToProxy(key, proxy.get()));
198 }
199
201 REPORTER_ASSERT(reporter, startCacheCount == cache->getResourceCount());
202
203 // setUniqueKey had better stick
205
206 // We just added it, surely we can find it
209
210 int expectedCacheCount = startCacheCount + (proxy->isInstantiated() ? 0 : cacheEntriesPerProxy);
211
212 // Once instantiated, the backing resource should have the same key
213 SkAssertResult(proxy->instantiate(resourceProvider));
214 const skgpu::UniqueKey texKey = proxy->peekSurface()->getUniqueKey();
216 REPORTER_ASSERT(reporter, key == texKey);
217
218 // An Unbudgeted-cacheable resource will not get purged when a proxy with the same key is
219 // deleted.
220 bool expectResourceToOutliveProxy = proxy->peekSurface()->resourcePriv().budgetedType() ==
222
223 // An Unbudgeted-uncacheable resource is never kept alive if it's ref cnt reaches zero even if
224 // it has a key.
225 bool expectDeletingProxyToDeleteResource =
226 proxy->peekSurface()->resourcePriv().budgetedType() ==
228
229 // deleting the proxy should delete it from the hash but not the cache
230 proxy = nullptr;
231 if (expectDeletingProxyToDeleteResource) {
232 expectedCacheCount -= cacheEntriesPerProxy;
233 }
235 REPORTER_ASSERT(reporter, expectedCacheCount == cache->getResourceCount());
236
237 // If the proxy was cached refinding it should bring it back to life
238 proxy = proxyProvider->findOrCreateProxyByUniqueKey(key);
241 REPORTER_ASSERT(reporter, expectedCacheCount == cache->getResourceCount());
242
243 // Mega-purging it should remove it from both the hash and the cache
244 proxy = nullptr;
245 cache->purgeUnlockedResources(GrPurgeResourceOptions::kAllResources);
246 if (!expectResourceToOutliveProxy) {
247 expectedCacheCount -= cacheEntriesPerProxy;
248 }
249 REPORTER_ASSERT(reporter, expectedCacheCount == cache->getResourceCount());
250
251 // If the texture was deleted then the proxy should no longer be findable. Otherwise, it should
252 // be.
253 proxy = proxyProvider->findOrCreateProxyByUniqueKey(key);
254 REPORTER_ASSERT(reporter, expectResourceToOutliveProxy ? (bool)proxy : !proxy);
255 REPORTER_ASSERT(reporter, expectedCacheCount == cache->getResourceCount());
256
257 if (expectResourceToOutliveProxy) {
258 proxy.reset();
259 skgpu::UniqueKeyInvalidatedMessage msg(texKey, dContext->priv().contextID());
261 cache->purgeAsNeeded();
262 expectedCacheCount -= cacheEntriesPerProxy;
263 proxy = proxyProvider->findOrCreateProxyByUniqueKey(key);
264 REPORTER_ASSERT(reporter, !proxy);
265 REPORTER_ASSERT(reporter, expectedCacheCount == cache->getResourceCount());
266 }
267}
reporter
Definition: FontMgrTest.cpp:39
SkAssertResult(font.textToGlyphs("Hello", 5, SkTextEncoding::kUTF8, glyphs, std::size(glyphs))==count)
void GrMakeKeyFromImageID(skgpu::UniqueKey *key, uint32_t imageID, const SkIRect &imageBounds)
Definition: SkGr.cpp:60
#define REPORTER_ASSERT(r, cond,...)
Definition: Test.h:286
uint32_t contextID() const
GrResourceProvider * resourceProvider()
GrResourceCache * getResourceCache()
GrDirectContextPriv priv()
GrBudgetedType budgetedType() const
const skgpu::UniqueKey & getUniqueKey() const
ResourcePriv resourcePriv()
int numUniqueKeyProxies_TestOnly() const
bool assignUniqueKeyToProxy(const skgpu::UniqueKey &, GrTextureProxy *)
sk_sp< GrTextureProxy > findOrCreateProxyByUniqueKey(const skgpu::UniqueKey &, UseAllocator=UseAllocator::kYes)
GrProxyProvider * proxyProvider()
GrSurface * peekSurface() const
bool isInstantiated() const
const skgpu::UniqueKey & getUniqueKey() const override
bool instantiate(GrResourceProvider *) override
static void Post(Message m)
Definition: SkMessageBus.h:130
T * get() const
Definition: SkRefCnt.h:303
void reset(T *ptr=nullptr)
Definition: SkRefCnt.h:310
bool isValid() const
Definition: ResourceKey.h:55
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
static constexpr SkIRect MakeWH(int32_t w, int32_t h)
Definition: SkRect.h:56
const uintptr_t id

◆ create_wrapped_backend()

static sk_sp< GrTextureProxy > create_wrapped_backend ( GrDirectContext dContext)
static

Definition at line 150 of file TextureProxyTest.cpp.

150 {
151 using namespace skgpu;
152
153 Protected isProtected = Protected(dContext->priv().caps()->supportsProtectedContent());
154
155 auto mbet = sk_gpu_test::ManagedBackendTexture::MakeWithoutData(
156 dContext,
157 kSize.width(),
158 kSize.height(),
162 isProtected);
163 if (!mbet) {
164 return nullptr;
165 }
166 GrProxyProvider* proxyProvider = dContext->priv().proxyProvider();
167 return proxyProvider->wrapBackendTexture(mbet->texture(),
171 mbet->refCountedCallback());
172}
@ kRead_GrIOType
Definition: GrTypesPriv.h:403
@ kBorrow_GrWrapOwnership
Definition: GrTypesPriv.h:79
static constexpr SkColorType GrColorTypeToSkColorType(GrColorType ct)
Definition: GrTypesPriv.h:589
skgpu::Protected Protected
static constexpr auto kColorType
static constexpr auto kSize
const GrCaps * caps() const
bool supportsProtectedContent() const
Definition: GrCaps.h:422
sk_sp< GrTextureProxy > wrapBackendTexture(const GrBackendTexture &, GrWrapOwnership, GrWrapCacheable, GrIOType, sk_sp< skgpu::RefCntedCallback >=nullptr)
Definition: GpuTools.h:21
Protected
Definition: GpuTypes.h:61

◆ DEF_GANESH_TEST_FOR_RENDERING_CONTEXTS()

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

Definition at line 372 of file TextureProxyTest.cpp.

375 {
376 auto direct = ctxInfo.directContext();
377 GrProxyProvider* proxyProvider = direct->priv().proxyProvider();
378 GrResourceCache* cache = direct->priv().getResourceCache();
379
381 REPORTER_ASSERT(reporter, 0 == cache->getResourceCount());
382
383 // As we transition to using attachments instead of GrTextures and GrRenderTargets individual
384 // proxy instansiations may add multiple things to the cache. There would be an entry for the
385 // GrTexture/GrRenderTarget and entries for one or more attachments.
386 int cacheEntriesPerProxy = 1;
387 // We currently only have attachments on the vulkan and metal backends
388 if (direct->backend() == GrBackend::kVulkan || direct->backend() == GrBackend::kMetal) {
389 cacheEntriesPerProxy++;
390 // If we ever have a test with multisamples this would have an additional attachment as
391 // well.
392 }
393
394 for (auto fit : { SkBackingFit::kExact, SkBackingFit::kApprox }) {
396 REPORTER_ASSERT(reporter, 0 == cache->getResourceCount());
397 basic_test(direct, reporter, create(reporter, direct, proxyProvider, fit),
398 cacheEntriesPerProxy);
399 }
400
401 REPORTER_ASSERT(reporter, 0 == cache->getResourceCount());
402 cache->purgeUnlockedResources(GrPurgeResourceOptions::kAllResources);
403 }
404
405 basic_test(direct, reporter, create_wrapped_backend(direct), cacheEntriesPerProxy);
406
407 invalidation_test(direct, reporter, cacheEntriesPerProxy);
408 invalidation_and_instantiation_test(direct, reporter, cacheEntriesPerProxy);
409}
static sk_sp< GrTextureProxy > wrapped_with_key(skiatest::Reporter *reporter, GrRecordingContext *rContext, GrProxyProvider *proxyProvider, SkBackingFit fit)
static sk_sp< GrTextureProxy > create_wrapped_backend(GrDirectContext *dContext)
static void invalidation_and_instantiation_test(GrDirectContext *dContext, skiatest::Reporter *reporter, int cacheEntriesPerProxy)
static void basic_test(GrDirectContext *dContext, skiatest::Reporter *reporter, sk_sp< GrTextureProxy > proxy, int cacheEntriesPerProxy)
static sk_sp< GrTextureProxy > deferred_tex(skiatest::Reporter *reporter, GrRecordingContext *rContext, GrProxyProvider *proxyProvider, SkBackingFit fit)
static sk_sp< GrTextureProxy > deferred_texRT(skiatest::Reporter *reporter, GrRecordingContext *rContext, GrProxyProvider *proxyProvider, SkBackingFit fit)
static void invalidation_test(GrDirectContext *dContext, skiatest::Reporter *reporter, int cacheEntriesPerProxy)
static sk_sp< GrTextureProxy > wrapped(skiatest::Reporter *reporter, GrRecordingContext *rContext, GrProxyProvider *proxyProvider, SkBackingFit fit)
Definition: create.py:1
int_closure create

◆ deferred_tex()

static sk_sp< GrTextureProxy > deferred_tex ( skiatest::Reporter reporter,
GrRecordingContext rContext,
GrProxyProvider proxyProvider,
SkBackingFit  fit 
)
static

Definition at line 60 of file TextureProxyTest.cpp.

63 {
64 using namespace skgpu;
65
66 const GrCaps* caps = rContext->priv().caps();
67
68 Protected isProtected = Protected(caps->supportsProtectedContent());
69
71
72 sk_sp<GrTextureProxy> proxy = proxyProvider->createProxy(format,
73 kSize,
75 1,
77 fit,
78 Budgeted::kYes,
79 isProtected,
80 /*label=*/{});
81 // Only budgeted & wrapped external proxies get to carry uniqueKeys
83 return proxy;
84}
Definition: GrCaps.h:57
GrBackendFormat getDefaultBackendFormat(GrColorType, GrRenderable) const
Definition: GrCaps.cpp:400
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)
GrRecordingContextPriv priv()
uint32_t uint32_t * format

◆ deferred_texRT()

static sk_sp< GrTextureProxy > deferred_texRT ( skiatest::Reporter reporter,
GrRecordingContext rContext,
GrProxyProvider proxyProvider,
SkBackingFit  fit 
)
static

Definition at line 86 of file TextureProxyTest.cpp.

89 {
90 using namespace skgpu;
91
92 const GrCaps* caps = rContext->priv().caps();
93
94 Protected isProtected = Protected(caps->supportsProtectedContent());
95
97
98 sk_sp<GrTextureProxy> proxy = proxyProvider->createProxy(format,
99 kSize,
101 1,
103 fit,
104 Budgeted::kYes,
105 isProtected,
106 /*label=*/{});
107 // Only budgeted & wrapped external proxies get to carry uniqueKeys
109 return proxy;
110}

◆ invalidation_and_instantiation_test()

static void invalidation_and_instantiation_test ( GrDirectContext dContext,
skiatest::Reporter reporter,
int  cacheEntriesPerProxy 
)
static

Definition at line 329 of file TextureProxyTest.cpp.

331 {
332 GrProxyProvider* proxyProvider = dContext->priv().proxyProvider();
333 GrResourceProvider* resourceProvider = dContext->priv().resourceProvider();
335 REPORTER_ASSERT(reporter, 0 == cache->getResourceCount());
336
339 skgpu::UniqueKey::Builder builder(&key, d, 1, nullptr);
340 builder[0] = 0;
341 builder.finish();
342
343 // Create proxy, assign unique key
344 sk_sp<GrTextureProxy> proxy = deferred_tex(reporter, dContext, proxyProvider,
346 SkAssertResult(proxyProvider->assignUniqueKeyToProxy(key, proxy.get()));
347
348 // Send an invalidation message, which will be sitting in the cache's inbox
351
353 REPORTER_ASSERT(reporter, 0 == cache->getResourceCount());
354
355 // Instantiate the proxy. This will trigger the message to be processed, so the resulting
356 // texture should *not* have the unique key on it!
357 SkAssertResult(proxy->instantiate(resourceProvider));
358
362 REPORTER_ASSERT(reporter, cacheEntriesPerProxy == cache->getResourceCount());
363
364 proxy = nullptr;
367
369 REPORTER_ASSERT(reporter, 0 == cache->getResourceCount());
370}
void purgeUnlockedResources(GrPurgeResourceOptions opts)
GrTexture * peekTexture() const
static Domain GenerateDomain()
Definition: ResourceKey.cpp:27
VULKAN_HPP_DEFAULT_DISPATCH_LOADER_DYNAMIC_STORAGE auto & d
Definition: main.cc:19

◆ invalidation_test()

static void invalidation_test ( GrDirectContext dContext,
skiatest::Reporter reporter,
int  cacheEntriesPerProxy 
)
static

Definition at line 273 of file TextureProxyTest.cpp.

275 {
276
277 GrProxyProvider* proxyProvider = dContext->priv().proxyProvider();
279 REPORTER_ASSERT(reporter, 0 == cache->getResourceCount());
280
281 sk_sp<SkImage> rasterImg;
282
283 {
285
286 SkBitmap bm;
287 bm.allocPixels(ii);
288
289 rasterImg = bm.asImage();
291 REPORTER_ASSERT(reporter, 0 == cache->getResourceCount());
292 }
293
294 // Some of our backends use buffers to do uploads that will live in our resource cache. So we
295 // need to account for those extra resources here.
296 int bufferResources = 0;
297 if (dContext->backend() == GrBackendApi::kVulkan ||
298 dContext->backend() == GrBackendApi::kDirect3D ||
299 dContext->backend() == GrBackendApi::kMetal) {
300 bufferResources = 1;
301 }
302
303 sk_sp<SkImage> textureImg = SkImages::TextureFromImage(dContext, rasterImg);
305 REPORTER_ASSERT(reporter, cacheEntriesPerProxy + bufferResources == cache->getResourceCount());
306
307 rasterImg = nullptr; // this invalidates the uniqueKey
308
309 // this forces the cache to respond to the inval msg
310 size_t maxBytes = dContext->getResourceCacheLimit();
311 dContext->setResourceCacheLimit(maxBytes-1);
312
314 REPORTER_ASSERT(reporter, cacheEntriesPerProxy + bufferResources == cache->getResourceCount());
315
316 textureImg = nullptr;
317
318 // For backends that use buffers to upload lets make sure that work has been submit and done
319 // before we try to purge all resources.
320 dContext->submit(GrSyncCpu::kYes);
323
325 REPORTER_ASSERT(reporter, 0 == cache->getResourceCount());
326}
@ kOpaque_SkAlphaType
pixel is opaque
Definition: SkAlphaType.h:28
@ kRGBA_8888_SkColorType
pixel with 8 bits for red, green, blue, alpha; in 32-bit word
Definition: SkColorType.h:24
SK_API GrBackendApi backend() const
bool submit(GrSyncCpu sync=GrSyncCpu::kNo)
size_t getResourceCacheLimit() const
void setResourceCacheLimit(size_t maxResourceBytes)
void allocPixels(const SkImageInfo &info, size_t rowBytes)
Definition: SkBitmap.cpp:258
sk_sp< SkImage > asImage() const
Definition: SkBitmap.cpp:645
SK_API sk_sp< SkImage > TextureFromImage(GrDirectContext *, const SkImage *, skgpu::Mipmapped=skgpu::Mipmapped::kNo, skgpu::Budgeted=skgpu::Budgeted::kYes)
static SkImageInfo Make(int width, int height, SkColorType ct, SkAlphaType at)

◆ wrapped()

static sk_sp< GrTextureProxy > wrapped ( skiatest::Reporter reporter,
GrRecordingContext rContext,
GrProxyProvider proxyProvider,
SkBackingFit  fit 
)
static

Definition at line 112 of file TextureProxyTest.cpp.

113 {
114 using namespace skgpu;
115
116 Protected isProtected = Protected(rContext->priv().caps()->supportsProtectedContent());
117
118 sk_sp<GrTextureProxy> proxy = proxyProvider->testingOnly_createInstantiatedProxy(
119 kSize, kColorType, GrRenderable::kNo, 1, fit, Budgeted::kYes, isProtected);
120 // Only budgeted & wrapped external proxies get to carry uniqueKeys
122 return proxy;
123}

◆ wrapped_with_key()

static sk_sp< GrTextureProxy > wrapped_with_key ( skiatest::Reporter reporter,
GrRecordingContext rContext,
GrProxyProvider proxyProvider,
SkBackingFit  fit 
)
static

Definition at line 125 of file TextureProxyTest.cpp.

128 {
129 using namespace skgpu;
130
131 Protected isProtected = Protected(rContext->priv().caps()->supportsProtectedContent());
132
133 static UniqueKey::Domain d = UniqueKey::GenerateDomain();
134 static int kUniqueKeyData = 0;
135
137
138 UniqueKey::Builder builder(&key, d, 1, nullptr);
139 builder[0] = kUniqueKeyData++;
140 builder.finish();
141
142 // Only budgeted & wrapped external proxies get to carry uniqueKeys
143 sk_sp<GrTextureProxy> proxy = proxyProvider->testingOnly_createInstantiatedProxy(
144 kSize, kColorType, GrRenderable::kNo, 1, fit, Budgeted::kYes, isProtected);
145 SkAssertResult(proxyProvider->assignUniqueKeyToProxy(key, proxy.get()));
147 return proxy;
148}

Variable Documentation

◆ kColorType

constexpr auto kColorType = GrColorType::kRGBA_8888
staticconstexpr

Definition at line 54 of file TextureProxyTest.cpp.

◆ kSize

constexpr auto kSize = SkISize::Make(64, 64)
staticconstexpr

Definition at line 55 of file TextureProxyTest.cpp.