Flutter Engine
The Flutter Engine
Loading...
Searching...
No Matches
Classes | Public Types | Public Member Functions | List of all members
TestHelper Class Reference

Classes

struct  Stats
 

Public Types

typedef void(TestHelper::* addAccessFP) (SkCanvas *, int wh, int id, bool failLookUp, bool failFillingIn)
 
typedef bool(TestHelper::* checkFP) (SkCanvas *, int wh, int expectedHits, int expectedMisses, int expectedNumRefs, int expectedID)
 

Public Member Functions

 TestHelper (GrDirectContext *dContext, GrThreadSafeCache::IsNewerBetter isNewerBetter=default_is_newer_better)
 
 ~TestHelper ()
 
Statsstats ()
 
int numCacheEntries () const
 
GrDirectContextdContext ()
 
SkCanvasliveCanvas ()
 
SkCanvasddlCanvas1 ()
 
sk_sp< GrDeferredDisplayListsnap1 ()
 
SkCanvasddlCanvas2 ()
 
sk_sp< GrDeferredDisplayListsnap2 ()
 
GrThreadSafeCachethreadSafeCache ()
 
const GrThreadSafeCachethreadSafeCache () const
 
void addViewAccess (SkCanvas *canvas, int wh, int id=kNoID, bool failLookup=false, bool failFillingIn=false)
 
bool checkView (SkCanvas *canvas, int wh, int expectedHits, int expectedMisses, int expectedNumRefs, int expectedID)
 
void addVertAccess (SkCanvas *canvas, int wh, int id, bool failLookup, bool failFillingIn, GrThreadSafeVertexTestOp **createdOp)
 
void addVertAccess (SkCanvas *canvas, int wh, int id=kNoID, bool failLookup=false, bool failFillingIn=false)
 
bool checkVert (SkCanvas *canvas, int wh, int expectedHits, int expectedMisses, int expectedNumRefs, int expectedID)
 
bool checkImage (skiatest::Reporter *reporter, const sk_sp< SkSurface > &s)
 
bool checkImage (skiatest::Reporter *reporter)
 
bool checkImage (skiatest::Reporter *reporter, sk_sp< GrDeferredDisplayList > ddl)
 
size_t gpuSize (int wh) const
 

Detailed Description

Definition at line 163 of file GrThreadSafeCacheTest.cpp.

Member Typedef Documentation

◆ addAccessFP

typedef void(TestHelper::* TestHelper::addAccessFP) (SkCanvas *, int wh, int id, bool failLookUp, bool failFillingIn)

Definition at line 229 of file GrThreadSafeCacheTest.cpp.

◆ checkFP

typedef bool(TestHelper::* TestHelper::checkFP) (SkCanvas *, int wh, int expectedHits, int expectedMisses, int expectedNumRefs, int expectedID)

Definition at line 231 of file GrThreadSafeCacheTest.cpp.

Constructor & Destructor Documentation

◆ TestHelper()

TestHelper::TestHelper ( GrDirectContext dContext,
GrThreadSafeCache::IsNewerBetter  isNewerBetter = default_is_newer_better 
)
inline

Definition at line 174 of file GrThreadSafeCacheTest.cpp.

176 : fDContext(dContext)
177 , fIsNewerBetter(isNewerBetter) {
179 SkAssertResult(fDst);
180
181 GrSurfaceCharacterization characterization;
182 SkAssertResult(fDst->characterize(&characterization));
183
184 fRecorder1 = std::make_unique<GrDeferredDisplayListRecorder>(characterization);
186
187 fRecorder2 = std::make_unique<GrDeferredDisplayListRecorder>(characterization);
189
191 }
static SkImageInfo default_ii(int wh)
static constexpr int kImageWH
#define SkAssertResult(cond)
Definition SkAssert.h:123
void clear(SkColor color)
Definition SkCanvas.h:1199
SkCanvas * getCanvas()
Definition SkSurface.cpp:82
bool characterize(GrSurfaceCharacterization *characterization) const
SkCanvas * ddlCanvas1()
GrDirectContext * dContext()
SkCanvas * ddlCanvas2()
constexpr SkColor4f kWhite
Definition SkColor.h:439
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)

◆ ~TestHelper()

TestHelper::~TestHelper ( )
inline

Definition at line 193 of file GrThreadSafeCacheTest.cpp.

193 {
194 fDContext->flush();
195 fDContext->submit(GrSyncCpu::kYes);
196 }
bool submit(GrSyncCpu sync=GrSyncCpu::kNo)
GrSemaphoresSubmitted flush(const GrFlushInfo &info)

Member Function Documentation

◆ addVertAccess() [1/2]

void TestHelper::addVertAccess ( SkCanvas canvas,
int  wh,
int  id,
bool  failLookup,
bool  failFillingIn,
GrThreadSafeVertexTestOp **  createdOp 
)

Definition at line 669 of file GrThreadSafeCacheTest.cpp.

672 {
673 auto rContext = canvas->recordingContext();
675
676 GrOp::Owner op = GrThreadSafeVertexTestOp::Make(rContext, &fStats,
677 wh, id,
678 failLookup, failFillingIn,
679 fIsNewerBetter);
680 if (createdOp) {
681 *createdOp = (GrThreadSafeVertexTestOp*) op.get();
682 }
683
684 sdc->addDrawOp(std::move(op));
685}
std::unique_ptr< GrOp > Owner
Definition GrOp.h:72
static DEFINE_OP_CLASS_ID GrOp::Owner Make(GrRecordingContext *rContext, TestHelper::Stats *stats, int wh, int id, bool failLookup, bool failFillingIn, GrThreadSafeCache::IsNewerBetter isNewerBetter)
virtual GrRecordingContext * recordingContext() const
SurfaceDrawContext * TopDeviceSurfaceDrawContext(const SkCanvas *canvas)
Definition GrCanvas.cpp:20

◆ addVertAccess() [2/2]

void TestHelper::addVertAccess ( SkCanvas canvas,
int  wh,
int  id = kNoID,
bool  failLookup = false,
bool  failFillingIn = false 
)
inline

Definition at line 344 of file GrThreadSafeCacheTest.cpp.

348 {
349 this->addVertAccess(canvas, wh, id, failLookup, failFillingIn, nullptr);
350 }
void addVertAccess(SkCanvas *canvas, int wh, int id, bool failLookup, bool failFillingIn, GrThreadSafeVertexTestOp **createdOp)

◆ addViewAccess()

void TestHelper::addViewAccess ( SkCanvas canvas,
int  wh,
int  id = kNoID,
bool  failLookup = false,
bool  failFillingIn = false 
)
inline

Definition at line 236 of file GrThreadSafeCacheTest.cpp.

240 {
241 auto rContext = canvas->recordingContext();
242
243 auto view = AccessCachedView(rContext, this->threadSafeCache(),
244 wh, failLookup, failFillingIn, id, &fStats);
245 SkASSERT(view);
246
248
249 sdc->drawTexture(nullptr,
250 view,
252 GrSamplerState::Filter::kNearest,
253 GrSamplerState::MipmapMode::kNone,
255 {1.0f, 1.0f, 1.0f, 1.0f},
256 SkRect::MakeWH(wh, wh),
257 SkRect::MakeWH(wh, wh),
260 SkMatrix::I(),
261 nullptr);
262 }
@ kPremul_SkAlphaType
pixel components are premultiplied by alpha
Definition SkAlphaType.h:29
#define SkASSERT(cond)
Definition SkAssert.h:116
@ kSrcOver
r = s + (1-sa)*d
@ kFast_SrcRectConstraint
sample outside bounds; faster
Definition SkCanvas.h:1543
static const SkMatrix & I()
GrThreadSafeCache * threadSafeCache()
static constexpr SkRect MakeWH(float w, float h)
Definition SkRect.h:609

◆ checkImage() [1/3]

bool TestHelper::checkImage ( skiatest::Reporter reporter)
inline

Definition at line 426 of file GrThreadSafeCacheTest.cpp.

426 {
427 return this->checkImage(reporter, fDst);
428 }
bool checkImage(skiatest::Reporter *reporter, const sk_sp< SkSurface > &s)

◆ checkImage() [2/3]

bool TestHelper::checkImage ( skiatest::Reporter reporter,
const sk_sp< SkSurface > &  s 
)
inline

Definition at line 403 of file GrThreadSafeCacheTest.cpp.

403 {
404 SkBitmap actual;
405
407
408 if (!s->readPixels(actual, 0, 0)) {
409 return false;
410 }
411
412 SkBitmap expected = create_bitmap(kImageWH);
413
414 const float tols[4] = { 0.0f, 0.0f, 0.0f, 0.0f };
415
416 auto error = std::function<ComparePixmapsErrorReporter>(
417 [reporter](int x, int y, const float diffs[4]) {
418 SkASSERT(x >= 0 && y >= 0);
419 ERRORF(reporter, "mismatch at %d, %d (%f, %f, %f %f)",
420 x, y, diffs[0], diffs[1], diffs[2], diffs[3]);
421 });
422
423 return ComparePixels(expected.pixmap(), actual.pixmap(), tols, error);
424 }
reporter
static SkBitmap create_bitmap(int wh)
bool ComparePixels(const GrCPixmap &a, const GrCPixmap &b, const float tolRGBA[4], std::function< ComparePixmapsErrorReporter > &error)
#define ERRORF(r,...)
Definition Test.h:293
void allocPixels(const SkImageInfo &info, size_t rowBytes)
Definition SkBitmap.cpp:258
const SkPixmap & pixmap() const
Definition SkBitmap.h:133
struct MyStruct s
const uint8_t uint32_t uint32_t GError ** error
double y
double x

◆ checkImage() [3/3]

bool TestHelper::checkImage ( skiatest::Reporter reporter,
sk_sp< GrDeferredDisplayList ddl 
)
inline

Definition at line 430 of file GrThreadSafeCacheTest.cpp.

430 {
431 sk_sp<SkSurface> tmp =
433 if (!tmp) {
434 return false;
435 }
436
437 if (!skgpu::ganesh::DrawDDL(tmp, std::move(ddl))) {
438 return false;
439 }
440
441 return this->checkImage(reporter, std::move(tmp));
442 }
SK_API bool DrawDDL(SkSurface *, sk_sp< const GrDeferredDisplayList > ddl)

◆ checkVert()

bool TestHelper::checkVert ( SkCanvas canvas,
int  wh,
int  expectedHits,
int  expectedMisses,
int  expectedNumRefs,
int  expectedID 
)
inline

Definition at line 352 of file GrThreadSafeCacheTest.cpp.

353 {
354 if (fStats.fCacheHits != expectedHits || fStats.fCacheMisses != expectedMisses) {
355 SkDebugf("Hits E: %d A: %d --- Misses E: %d A: %d\n",
356 expectedHits, fStats.fCacheHits, expectedMisses, fStats.fCacheMisses);
357 return false;
358 }
359
362
363 auto threadSafeCache = this->threadSafeCache();
364
365 auto [vertData, xtraData] = threadSafeCache->findVertsWithData(key);
366 if (!vertData) {
367 return false;
368 }
369
370 if (expectedID < 0) {
371 if (xtraData) {
372 return false;
373 }
374 } else {
375 if (!xtraData) {
376 return false;
377 }
378
379 const int* cachedID = static_cast<const int*>(xtraData->data());
380 if (*cachedID != expectedID) {
381 return false;
382 }
383 }
384
385 if (!vertData->refCntGreaterThan(expectedNumRefs+1) || // +1 for 'vertData's ref
386 vertData->refCntGreaterThan(expectedNumRefs+2)) {
387 return false;
388 }
389
390 {
391 auto resourceProvider = fDContext->priv().resourceProvider();
392 sk_sp<GrGpuBuffer> buffer = resourceProvider->findByUniqueKey<GrGpuBuffer>(key);
393 if (buffer) {
394 // the buffer holding the vertex data in this cache should never be discoverable
395 // in the resource cache
396 return false;
397 }
398 }
399
400 return true;
401 }
static constexpr int kNoID
static void create_vert_key(skgpu::UniqueKey *key, int wh, int id)
void SK_SPI SkDebugf(const char format[],...) SK_PRINTF_LIKE(1
GrResourceProvider * resourceProvider()
GrDirectContextPriv priv()
std::tuple< sk_sp< VertexData >, sk_sp< SkData > > findVertsWithData(const skgpu::UniqueKey &) SK_EXCLUDES(fSpinLock)
static const uint8_t buffer[]

◆ checkView()

bool TestHelper::checkView ( SkCanvas canvas,
int  wh,
int  expectedHits,
int  expectedMisses,
int  expectedNumRefs,
int  expectedID 
)
inline

Definition at line 266 of file GrThreadSafeCacheTest.cpp.

267 {
268 if (fStats.fCacheHits != expectedHits || fStats.fCacheMisses != expectedMisses) {
269 SkDebugf("Hits E: %d A: %d --- Misses E: %d A: %d\n",
270 expectedHits, fStats.fCacheHits, expectedMisses, fStats.fCacheMisses);
271 return false;
272 }
273
276
277 auto threadSafeCache = this->threadSafeCache();
278
279 auto [view, xtraData] = threadSafeCache->findWithData(key);
280 if (!view.proxy()) {
281 return false;
282 }
283
284 if (expectedID < 0) {
285 if (xtraData) {
286 return false;
287 }
288 } else {
289 if (!xtraData) {
290 return false;
291 }
292
293 const int* cachedID = static_cast<const int*>(xtraData->data());
294 if (*cachedID != expectedID) {
295 return false;
296 }
297 }
298
299 if (!view.proxy()->refCntGreaterThan(expectedNumRefs+1) || // +1 for 'view's ref
300 view.proxy()->refCntGreaterThan(expectedNumRefs+2)) {
301 return false;
302 }
303
304 if (canvas) {
305 GrRecordingContext* rContext = canvas->recordingContext();
306 GrProxyProvider* recordingProxyProvider = rContext->priv().proxyProvider();
307 sk_sp<GrTextureProxy> result = recordingProxyProvider->findProxyByUniqueKey(key);
308 if (result) {
309 // views in this cache should never appear in the recorder's cache
310 return false;
311 }
312 }
313
314 {
315 GrProxyProvider* directProxyProvider = fDContext->priv().proxyProvider();
317 if (result) {
318 // views in this cache should never appear in the main proxy cache
319 return false;
320 }
321 }
322
323 {
324 auto resourceProvider = fDContext->priv().resourceProvider();
325 sk_sp<GrSurface> surf = resourceProvider->findByUniqueKey<GrSurface>(key);
326 if (surf) {
327 // the textures backing the views in this cache should never be discoverable in the
328 // resource cache
329 return false;
330 }
331 }
332
333 return true;
334 }
static void create_view_key(skgpu::UniqueKey *key, int wh, int id)
sk_sp< GrTextureProxy > findProxyByUniqueKey(const skgpu::UniqueKey &)
GrProxyProvider * proxyProvider()
GrRecordingContextPriv priv()
SkDEBUGCODE(bool has(const skgpu::UniqueKey &) SK_EXCLUDES(fSpinLock);) GrSurfaceProxyView find(const skgpu std::tuple< GrSurfaceProxyView, sk_sp< SkData > > findWithData(const skgpu::UniqueKey &) SK_EXCLUDES(fSpinLock)
GAsyncResult * result

◆ dContext()

GrDirectContext * TestHelper::dContext ( )
inline

Definition at line 202 of file GrThreadSafeCacheTest.cpp.

202{ return fDContext; }

◆ ddlCanvas1()

SkCanvas * TestHelper::ddlCanvas1 ( )
inline

Definition at line 205 of file GrThreadSafeCacheTest.cpp.

205{ return fRecorder1 ? fRecorder1->getCanvas() : nullptr; }

◆ ddlCanvas2()

SkCanvas * TestHelper::ddlCanvas2 ( )
inline

Definition at line 215 of file GrThreadSafeCacheTest.cpp.

215{ return fRecorder2 ? fRecorder2->getCanvas() : nullptr; }

◆ gpuSize()

size_t TestHelper::gpuSize ( int  wh) const
inline

Definition at line 444 of file GrThreadSafeCacheTest.cpp.

444 {
446 GrRenderable::kNo);
447
449 {wh, wh},
450 /*colorSamplesPerPixel=*/1,
451 skgpu::Mipmapped::kNo,
452 /*binSize=*/false);
453 }
@ kRGBA_8888_SkColorType
pixel with 8 bits for red, green, blue, alpha; in 32-bit word
Definition SkColorType.h:24
SK_API GrBackendFormat defaultBackendFormat(SkColorType, GrRenderable) const
static size_t ComputeSize(const GrBackendFormat &, SkISize dimensions, int colorSamplesPerPixel, skgpu::Mipmapped, bool binSize=false)
Definition GrSurface.cpp:21
uint32_t uint32_t * format

◆ liveCanvas()

SkCanvas * TestHelper::liveCanvas ( )
inline

Definition at line 204 of file GrThreadSafeCacheTest.cpp.

204{ return fDst ? fDst->getCanvas() : nullptr; }

◆ numCacheEntries()

int TestHelper::numCacheEntries ( ) const
inline

Definition at line 200 of file GrThreadSafeCacheTest.cpp.

200{ return this->threadSafeCache()->numEntries(); }

◆ snap1()

sk_sp< GrDeferredDisplayList > TestHelper::snap1 ( )
inline

Definition at line 206 of file GrThreadSafeCacheTest.cpp.

206 {
207 if (fRecorder1) {
208 sk_sp<GrDeferredDisplayList> tmp = fRecorder1->detach();
209 fRecorder1 = nullptr;
210 return tmp;
211 }
212
213 return nullptr;
214 }

◆ snap2()

sk_sp< GrDeferredDisplayList > TestHelper::snap2 ( )
inline

Definition at line 216 of file GrThreadSafeCacheTest.cpp.

216 {
217 if (fRecorder2) {
218 sk_sp<GrDeferredDisplayList> tmp = fRecorder2->detach();
219 fRecorder2 = nullptr;
220 return tmp;
221 }
222
223 return nullptr;
224 }

◆ stats()

Stats * TestHelper::stats ( )
inline

Definition at line 198 of file GrThreadSafeCacheTest.cpp.

198{ return &fStats; }

◆ threadSafeCache() [1/2]

GrThreadSafeCache * TestHelper::threadSafeCache ( )
inline

Definition at line 226 of file GrThreadSafeCacheTest.cpp.

226{ return fDContext->priv().threadSafeCache(); }
GrThreadSafeCache * threadSafeCache()

◆ threadSafeCache() [2/2]

const GrThreadSafeCache * TestHelper::threadSafeCache ( ) const
inline

Definition at line 227 of file GrThreadSafeCacheTest.cpp.

227{ return fDContext->priv().threadSafeCache(); }

The documentation for this class was generated from the following file: