2014-06-30 15:26:50 +00:00
|
|
|
/*
|
|
|
|
* Copyright 2014 Google Inc.
|
|
|
|
*
|
|
|
|
* Use of this source code is governed by a BSD-style license that can be
|
|
|
|
* found in the LICENSE file.
|
|
|
|
*/
|
|
|
|
|
2016-06-30 15:23:30 +00:00
|
|
|
// Disabling this test since it is for the layer hoister which is current disabled.
|
|
|
|
// The test fails when we add a discard to a newly created render target.
|
|
|
|
#if 0
|
|
|
|
|
2014-06-30 15:26:50 +00:00
|
|
|
#include "GrContext.h"
|
|
|
|
#include "GrLayerCache.h"
|
2015-11-09 21:51:06 +00:00
|
|
|
#include "GrResourceCache.h"
|
2014-07-13 16:00:50 +00:00
|
|
|
#include "SkPictureRecorder.h"
|
2014-06-30 15:26:50 +00:00
|
|
|
#include "Test.h"
|
|
|
|
|
2014-07-22 17:18:06 +00:00
|
|
|
class TestingAccess {
|
2014-06-30 15:26:50 +00:00
|
|
|
public:
|
2015-11-09 21:51:06 +00:00
|
|
|
static int NumPlots() {
|
|
|
|
return GrLayerCache::kNumPlotsX * GrLayerCache::kNumPlotsY;
|
|
|
|
}
|
|
|
|
static SkISize PlotSize() {
|
|
|
|
return SkISize::Make(GrLayerCache::kAtlasTextureWidth / GrLayerCache::kNumPlotsX,
|
|
|
|
GrLayerCache::kAtlasTextureHeight / GrLayerCache::kNumPlotsY);
|
|
|
|
}
|
|
|
|
|
|
|
|
static GrTexture* GetBackingTexture(GrLayerCache* cache) {
|
|
|
|
return cache->fAtlas->getTextureOrNull();
|
|
|
|
}
|
|
|
|
|
2015-08-19 16:51:00 +00:00
|
|
|
static int NumLayers(GrLayerCache* cache) {
|
2014-06-30 15:26:50 +00:00
|
|
|
return cache->numLayers();
|
|
|
|
}
|
2014-07-22 17:18:06 +00:00
|
|
|
static void Purge(GrLayerCache* cache, uint32_t pictureID) {
|
|
|
|
cache->purge(pictureID);
|
|
|
|
}
|
2014-10-10 18:38:29 +00:00
|
|
|
static int Uses(GrCachedLayer* layer) {
|
|
|
|
return layer->uses();
|
|
|
|
}
|
2014-12-01 17:09:27 +00:00
|
|
|
static GrCachedLayer* Find(GrLayerCache* cache, uint32_t pictureID,
|
2015-08-19 16:51:00 +00:00
|
|
|
const SkMatrix& initialMat,
|
|
|
|
const int* key, int keySize) {
|
2014-12-01 17:09:27 +00:00
|
|
|
return cache->findLayer(pictureID, initialMat, key, keySize);
|
|
|
|
}
|
2014-06-30 15:26:50 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
// Add several layers to the cache
|
|
|
|
static void create_layers(skiatest::Reporter* reporter,
|
|
|
|
GrLayerCache* cache,
|
2014-07-29 13:07:19 +00:00
|
|
|
const SkPicture& picture,
|
2015-08-19 16:51:00 +00:00
|
|
|
int numToAdd,
|
|
|
|
int idOffset) {
|
2014-07-29 13:07:19 +00:00
|
|
|
|
2015-08-19 16:51:00 +00:00
|
|
|
for (int i = 0; i < numToAdd; ++i) {
|
2015-11-09 21:51:06 +00:00
|
|
|
int key[1] = { idOffset+i+1 };
|
2015-08-19 16:51:00 +00:00
|
|
|
GrCachedLayer* layer = cache->findLayerOrCreate(picture.uniqueID(),
|
|
|
|
idOffset+i+1, idOffset+i+2,
|
2014-10-20 15:52:40 +00:00
|
|
|
SkIRect::MakeEmpty(),
|
2014-12-16 16:25:55 +00:00
|
|
|
SkIRect::MakeEmpty(),
|
2014-09-17 14:50:47 +00:00
|
|
|
SkMatrix::I(),
|
2015-11-09 21:51:06 +00:00
|
|
|
key, 1,
|
2015-08-27 14:41:13 +00:00
|
|
|
nullptr);
|
2014-09-05 20:34:00 +00:00
|
|
|
REPORTER_ASSERT(reporter, layer);
|
2015-08-19 16:51:00 +00:00
|
|
|
GrCachedLayer* temp = TestingAccess::Find(cache, picture.uniqueID(), SkMatrix::I(),
|
2015-11-09 21:51:06 +00:00
|
|
|
key, 1);
|
2014-07-29 13:07:19 +00:00
|
|
|
REPORTER_ASSERT(reporter, temp == layer);
|
|
|
|
|
|
|
|
REPORTER_ASSERT(reporter, TestingAccess::NumLayers(cache) == idOffset + i + 1);
|
|
|
|
|
|
|
|
REPORTER_ASSERT(reporter, picture.uniqueID() == layer->pictureID());
|
2014-07-31 18:02:38 +00:00
|
|
|
REPORTER_ASSERT(reporter, layer->start() == idOffset + i + 1);
|
|
|
|
REPORTER_ASSERT(reporter, layer->stop() == idOffset + i + 2);
|
2016-05-03 16:37:08 +00:00
|
|
|
REPORTER_ASSERT(reporter, !layer->texture());
|
|
|
|
REPORTER_ASSERT(reporter, !layer->paint());
|
2014-07-29 13:07:19 +00:00
|
|
|
REPORTER_ASSERT(reporter, !layer->isAtlased());
|
|
|
|
}
|
|
|
|
}
|
2014-06-30 15:26:50 +00:00
|
|
|
|
2014-07-29 13:07:19 +00:00
|
|
|
static void lock_layer(skiatest::Reporter* reporter,
|
|
|
|
GrLayerCache* cache,
|
|
|
|
GrCachedLayer* layer) {
|
2015-11-09 21:51:06 +00:00
|
|
|
// Make each layer big enough to consume one whole plot in the atlas
|
2014-10-28 21:33:06 +00:00
|
|
|
GrSurfaceDesc desc;
|
2015-11-09 21:51:06 +00:00
|
|
|
desc.fFlags = kRenderTarget_GrSurfaceFlag;
|
|
|
|
desc.fWidth = TestingAccess::PlotSize().fWidth;
|
|
|
|
desc.fHeight = TestingAccess::PlotSize().fHeight;
|
2014-07-29 13:07:19 +00:00
|
|
|
desc.fConfig = kSkia8888_GrPixelConfig;
|
2014-06-30 15:26:50 +00:00
|
|
|
|
2014-10-28 14:21:44 +00:00
|
|
|
bool needsRerendering;
|
|
|
|
bool inAtlas = cache->tryToAtlas(layer, desc, &needsRerendering);
|
|
|
|
if (!inAtlas) {
|
|
|
|
cache->lock(layer, desc, &needsRerendering);
|
|
|
|
}
|
2014-08-18 15:50:03 +00:00
|
|
|
REPORTER_ASSERT(reporter, needsRerendering);
|
2014-06-30 15:26:50 +00:00
|
|
|
|
2014-10-28 14:21:44 +00:00
|
|
|
cache->lock(layer, desc, &needsRerendering);
|
2014-08-18 15:50:03 +00:00
|
|
|
REPORTER_ASSERT(reporter, !needsRerendering);
|
2014-06-30 15:26:50 +00:00
|
|
|
|
2014-09-05 20:34:00 +00:00
|
|
|
REPORTER_ASSERT(reporter, layer->texture());
|
2014-07-29 13:07:19 +00:00
|
|
|
REPORTER_ASSERT(reporter, layer->locked());
|
2014-10-10 18:38:29 +00:00
|
|
|
|
|
|
|
cache->addUse(layer);
|
|
|
|
|
|
|
|
REPORTER_ASSERT(reporter, 1 == TestingAccess::Uses(layer));
|
2014-06-30 15:26:50 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// This test case exercises the public API of the GrLayerCache class.
|
|
|
|
// In particular it checks its interaction with the resource cache (w.r.t.
|
|
|
|
// locking & unlocking textures).
|
|
|
|
// TODO: need to add checks on VRAM usage!
|
2016-04-12 16:59:58 +00:00
|
|
|
DEF_GPUTEST_FOR_RENDERING_CONTEXTS(GpuLayerCache, reporter, ctxInfo) {
|
2015-11-09 21:51:06 +00:00
|
|
|
// Add one more layer than can fit in the atlas
|
|
|
|
static const int kInitialNumLayers = TestingAccess::NumPlots() + 1;
|
|
|
|
|
|
|
|
#if GR_CACHE_STATS
|
|
|
|
GrResourceCache::Stats stats;
|
|
|
|
#endif
|
2014-07-29 13:07:19 +00:00
|
|
|
|
2016-03-18 14:25:55 +00:00
|
|
|
sk_sp<SkPicture> picture;
|
2014-06-30 15:26:50 +00:00
|
|
|
|
2015-12-01 12:35:26 +00:00
|
|
|
{
|
|
|
|
SkPictureRecorder recorder;
|
|
|
|
SkCanvas* c = recorder.beginRecording(1, 1);
|
|
|
|
// Draw something, anything, to prevent an empty-picture optimization,
|
|
|
|
// which is a singleton and never purged.
|
|
|
|
c->drawRect(SkRect::MakeWH(1,1), SkPaint());
|
2016-03-18 14:25:55 +00:00
|
|
|
picture = recorder.finishRecordingAsPicture();
|
2015-12-01 12:35:26 +00:00
|
|
|
}
|
2015-11-09 21:51:06 +00:00
|
|
|
|
2016-05-11 13:33:06 +00:00
|
|
|
GrResourceCache* resourceCache = ctxInfo.grContext()->getResourceCache();
|
2014-06-30 15:26:50 +00:00
|
|
|
|
2016-05-11 13:33:06 +00:00
|
|
|
GrLayerCache cache(ctxInfo.grContext());
|
2014-06-30 15:26:50 +00:00
|
|
|
|
2015-12-01 12:35:26 +00:00
|
|
|
create_layers(reporter, &cache, *picture, kInitialNumLayers, 0);
|
2014-07-17 17:50:59 +00:00
|
|
|
|
2015-12-01 12:35:26 +00:00
|
|
|
for (int i = 0; i < kInitialNumLayers; ++i) {
|
|
|
|
int key[1] = { i + 1 };
|
|
|
|
GrCachedLayer* layer = TestingAccess::Find(&cache, picture->uniqueID(), SkMatrix::I(),
|
|
|
|
key, 1);
|
|
|
|
REPORTER_ASSERT(reporter, layer);
|
2014-06-30 15:26:50 +00:00
|
|
|
|
2015-12-01 12:35:26 +00:00
|
|
|
lock_layer(reporter, &cache, layer);
|
2014-07-17 17:50:59 +00:00
|
|
|
|
2015-11-09 21:51:06 +00:00
|
|
|
#if GR_CACHE_STATS
|
2015-12-01 12:35:26 +00:00
|
|
|
resourceCache->getStats(&stats);
|
2015-11-09 21:51:06 +00:00
|
|
|
#endif
|
|
|
|
|
2015-12-01 12:35:26 +00:00
|
|
|
// The first 4 layers should be in the atlas (and thus have non-empty rects)
|
|
|
|
if (i < TestingAccess::NumPlots()) {
|
|
|
|
REPORTER_ASSERT(reporter, layer->isAtlased());
|
2015-11-09 21:51:06 +00:00
|
|
|
#if GR_CACHE_STATS
|
2015-12-01 12:35:26 +00:00
|
|
|
REPORTER_ASSERT(reporter, 1 == stats.fTotal);
|
2015-11-09 21:51:06 +00:00
|
|
|
#endif
|
2015-12-01 12:35:26 +00:00
|
|
|
} else {
|
|
|
|
// The 5th layer couldn't fit in the atlas
|
|
|
|
REPORTER_ASSERT(reporter, !layer->isAtlased());
|
2015-11-09 21:51:06 +00:00
|
|
|
#if GR_CACHE_STATS
|
2015-12-01 12:35:26 +00:00
|
|
|
REPORTER_ASSERT(reporter, 2 == stats.fTotal);
|
2015-11-09 21:51:06 +00:00
|
|
|
#endif
|
2014-07-17 17:50:59 +00:00
|
|
|
}
|
2015-12-01 12:35:26 +00:00
|
|
|
}
|
2014-06-30 15:26:50 +00:00
|
|
|
|
2015-12-01 12:35:26 +00:00
|
|
|
// Unlock the textures
|
|
|
|
for (int i = 0; i < kInitialNumLayers; ++i) {
|
|
|
|
int key[1] = { i+1 };
|
2014-12-01 17:09:27 +00:00
|
|
|
|
2015-12-01 12:35:26 +00:00
|
|
|
GrCachedLayer* layer = TestingAccess::Find(&cache, picture->uniqueID(), SkMatrix::I(),
|
|
|
|
key, 1);
|
|
|
|
REPORTER_ASSERT(reporter, layer);
|
|
|
|
cache.removeUse(layer);
|
|
|
|
}
|
2014-06-30 15:26:50 +00:00
|
|
|
|
2015-11-09 21:51:06 +00:00
|
|
|
#if GR_CACHE_STATS
|
2015-12-01 12:35:26 +00:00
|
|
|
resourceCache->getStats(&stats);
|
|
|
|
REPORTER_ASSERT(reporter, 2 == stats.fTotal);
|
|
|
|
// The floating layer is purgeable the cache is not
|
|
|
|
REPORTER_ASSERT(reporter, 1 == stats.fNumPurgeable);
|
|
|
|
REPORTER_ASSERT(reporter, 1 == stats.fNumNonPurgeable);
|
2015-11-09 21:51:06 +00:00
|
|
|
#endif
|
|
|
|
|
2015-12-01 12:35:26 +00:00
|
|
|
for (int i = 0; i < kInitialNumLayers; ++i) {
|
|
|
|
int key[1] = { i+1 };
|
2014-12-01 17:09:27 +00:00
|
|
|
|
2015-12-01 12:35:26 +00:00
|
|
|
GrCachedLayer* layer = TestingAccess::Find(&cache, picture->uniqueID(), SkMatrix::I(),
|
|
|
|
key, 1);
|
|
|
|
REPORTER_ASSERT(reporter, layer);
|
2014-06-30 15:26:50 +00:00
|
|
|
|
2015-12-01 12:35:26 +00:00
|
|
|
// All the layers should be unlocked
|
|
|
|
REPORTER_ASSERT(reporter, !layer->locked());
|
2014-10-10 18:38:29 +00:00
|
|
|
|
2015-12-01 12:35:26 +00:00
|
|
|
// When hoisted layers aren't cached they are aggressively removed
|
|
|
|
// from the atlas
|
2014-10-29 20:56:02 +00:00
|
|
|
#if GR_CACHE_HOISTED_LAYERS
|
2015-12-01 12:35:26 +00:00
|
|
|
// The first 4 layers should still be in the atlas.
|
|
|
|
if (i < 4) {
|
|
|
|
REPORTER_ASSERT(reporter, layer->texture());
|
|
|
|
REPORTER_ASSERT(reporter, layer->isAtlased());
|
|
|
|
} else {
|
2014-10-29 20:56:02 +00:00
|
|
|
#endif
|
2015-12-01 12:35:26 +00:00
|
|
|
// The final layer should not be atlased.
|
2016-05-03 16:37:08 +00:00
|
|
|
REPORTER_ASSERT(reporter, !layer->texture());
|
2015-12-01 12:35:26 +00:00
|
|
|
REPORTER_ASSERT(reporter, !layer->isAtlased());
|
2014-10-29 20:56:02 +00:00
|
|
|
#if GR_CACHE_HOISTED_LAYERS
|
2014-07-17 17:50:59 +00:00
|
|
|
}
|
2015-12-01 12:35:26 +00:00
|
|
|
#endif
|
|
|
|
}
|
2014-06-30 15:26:50 +00:00
|
|
|
|
2015-12-01 12:35:26 +00:00
|
|
|
// Let go of the backing texture
|
|
|
|
cache.end();
|
|
|
|
REPORTER_ASSERT(reporter, nullptr == TestingAccess::GetBackingTexture(&cache));
|
2015-11-09 21:51:06 +00:00
|
|
|
|
|
|
|
#if GR_CACHE_STATS
|
2015-12-01 12:35:26 +00:00
|
|
|
resourceCache->getStats(&stats);
|
|
|
|
REPORTER_ASSERT(reporter, 2 == stats.fTotal);
|
|
|
|
// Now both the floater and the atlas are purgeable
|
|
|
|
REPORTER_ASSERT(reporter, 2 == stats.fNumPurgeable);
|
2015-11-09 21:51:06 +00:00
|
|
|
#endif
|
|
|
|
|
2015-12-01 12:35:26 +00:00
|
|
|
// re-attach to the backing texture
|
|
|
|
cache.begin();
|
|
|
|
REPORTER_ASSERT(reporter, TestingAccess::GetBackingTexture(&cache));
|
2015-11-09 21:51:06 +00:00
|
|
|
|
|
|
|
#if GR_CACHE_STATS
|
2015-12-01 12:35:26 +00:00
|
|
|
resourceCache->getStats(&stats);
|
|
|
|
REPORTER_ASSERT(reporter, 2 == stats.fTotal);
|
|
|
|
// The atlas is restored to being non-purgeable
|
|
|
|
REPORTER_ASSERT(reporter, 1 == stats.fNumPurgeable);
|
|
|
|
REPORTER_ASSERT(reporter, 1 == stats.fNumNonPurgeable);
|
2015-11-09 21:51:06 +00:00
|
|
|
#endif
|
|
|
|
|
2015-12-01 12:35:26 +00:00
|
|
|
{
|
|
|
|
int key[1] = { kInitialNumLayers+1 };
|
2014-12-01 17:09:27 +00:00
|
|
|
|
2015-12-01 12:35:26 +00:00
|
|
|
// Add an additional layer. Since all the layers are unlocked this
|
|
|
|
// will force out the first atlased layer
|
|
|
|
create_layers(reporter, &cache, *picture, 1, kInitialNumLayers);
|
|
|
|
GrCachedLayer* layer = TestingAccess::Find(&cache, picture->uniqueID(), SkMatrix::I(),
|
|
|
|
key, 1);
|
|
|
|
REPORTER_ASSERT(reporter, layer);
|
2014-07-29 13:07:19 +00:00
|
|
|
|
2015-12-01 12:35:26 +00:00
|
|
|
lock_layer(reporter, &cache, layer);
|
|
|
|
cache.removeUse(layer);
|
|
|
|
}
|
2014-07-29 13:07:19 +00:00
|
|
|
|
2015-12-01 12:35:26 +00:00
|
|
|
for (int i = 0; i < kInitialNumLayers+1; ++i) {
|
|
|
|
int key[1] = { i+1 };
|
2014-12-01 17:09:27 +00:00
|
|
|
|
2015-12-01 12:35:26 +00:00
|
|
|
GrCachedLayer* layer = TestingAccess::Find(&cache, picture->uniqueID(), SkMatrix::I(),
|
|
|
|
key, 1);
|
2014-10-29 20:56:02 +00:00
|
|
|
#if GR_CACHE_HOISTED_LAYERS
|
2015-12-01 12:35:26 +00:00
|
|
|
// 3 old layers plus the new one should be in the atlas.
|
|
|
|
if (1 == i || 2 == i || 3 == i || 5 == i) {
|
|
|
|
REPORTER_ASSERT(reporter, layer);
|
|
|
|
REPORTER_ASSERT(reporter, !layer->locked());
|
|
|
|
REPORTER_ASSERT(reporter, layer->texture());
|
|
|
|
REPORTER_ASSERT(reporter, layer->isAtlased());
|
|
|
|
} else if (4 == i) {
|
2014-10-29 20:56:02 +00:00
|
|
|
#endif
|
2015-12-01 12:35:26 +00:00
|
|
|
// The one that was never atlased should still be around
|
|
|
|
REPORTER_ASSERT(reporter, layer);
|
2014-07-29 13:07:19 +00:00
|
|
|
|
2016-05-03 16:37:08 +00:00
|
|
|
REPORTER_ASSERT(reporter, !layer->texture());
|
2015-12-01 12:35:26 +00:00
|
|
|
REPORTER_ASSERT(reporter, !layer->isAtlased());
|
2014-10-29 20:56:02 +00:00
|
|
|
#if GR_CACHE_HOISTED_LAYERS
|
2015-12-01 12:35:26 +00:00
|
|
|
} else {
|
|
|
|
// The one bumped out of the atlas (i.e., 0) should be gone
|
|
|
|
REPORTER_ASSERT(reporter, nullptr == layer);
|
2014-07-29 13:07:19 +00:00
|
|
|
}
|
2015-12-01 12:35:26 +00:00
|
|
|
#endif
|
|
|
|
}
|
2014-07-29 13:07:19 +00:00
|
|
|
|
2015-12-01 12:35:26 +00:00
|
|
|
//--------------------------------------------------------------------
|
|
|
|
// Free them all SkGpuDevice-style. This will not free up the
|
|
|
|
// atlas' texture but will eliminate all the layers.
|
|
|
|
TestingAccess::Purge(&cache, picture->uniqueID());
|
2014-06-30 15:26:50 +00:00
|
|
|
|
2015-12-01 12:35:26 +00:00
|
|
|
REPORTER_ASSERT(reporter, TestingAccess::NumLayers(&cache) == 0);
|
2015-11-09 21:51:06 +00:00
|
|
|
|
|
|
|
#if GR_CACHE_STATS
|
2015-12-01 12:35:26 +00:00
|
|
|
resourceCache->getStats(&stats);
|
|
|
|
REPORTER_ASSERT(reporter, 2 == stats.fTotal);
|
|
|
|
// Atlas isn't purgeable
|
|
|
|
REPORTER_ASSERT(reporter, 1 == stats.fNumPurgeable);
|
|
|
|
REPORTER_ASSERT(reporter, 1 == stats.fNumNonPurgeable);
|
2015-11-09 21:51:06 +00:00
|
|
|
#endif
|
2014-07-22 17:18:06 +00:00
|
|
|
|
2015-12-01 12:35:26 +00:00
|
|
|
//--------------------------------------------------------------------
|
|
|
|
// Test out the GrContext-style purge. This should remove all the layers
|
|
|
|
// and the atlas.
|
|
|
|
// Re-create the layers
|
|
|
|
create_layers(reporter, &cache, *picture, kInitialNumLayers, 0);
|
2014-06-30 15:26:50 +00:00
|
|
|
|
2015-12-01 12:35:26 +00:00
|
|
|
// Free them again GrContext-style. This should free up everything.
|
|
|
|
cache.freeAll();
|
2014-06-30 15:26:50 +00:00
|
|
|
|
2015-12-01 12:35:26 +00:00
|
|
|
REPORTER_ASSERT(reporter, TestingAccess::NumLayers(&cache) == 0);
|
2015-11-09 21:51:06 +00:00
|
|
|
|
2015-12-01 12:35:26 +00:00
|
|
|
REPORTER_ASSERT(reporter, nullptr == TestingAccess::GetBackingTexture(&cache));
|
2015-11-09 21:51:06 +00:00
|
|
|
|
|
|
|
#if GR_CACHE_STATS
|
2015-12-01 12:35:26 +00:00
|
|
|
resourceCache->getStats(&stats);
|
|
|
|
REPORTER_ASSERT(reporter, 2 == stats.fTotal);
|
|
|
|
REPORTER_ASSERT(reporter, 2 == stats.fNumPurgeable);
|
2015-11-09 21:51:06 +00:00
|
|
|
#endif
|
|
|
|
|
2015-12-01 12:35:26 +00:00
|
|
|
// Purge the resource cache ...
|
|
|
|
resourceCache->purgeAllUnlocked();
|
2015-11-09 21:51:06 +00:00
|
|
|
|
|
|
|
#if GR_CACHE_STATS
|
2015-12-01 12:35:26 +00:00
|
|
|
resourceCache->getStats(&stats);
|
|
|
|
REPORTER_ASSERT(reporter, 0 == stats.fTotal);
|
2015-11-09 21:51:06 +00:00
|
|
|
#endif
|
|
|
|
|
2015-12-01 12:35:26 +00:00
|
|
|
// and try to re-attach to the backing texture. This should fail
|
|
|
|
cache.begin();
|
|
|
|
REPORTER_ASSERT(reporter, nullptr == TestingAccess::GetBackingTexture(&cache));
|
2014-07-22 17:18:06 +00:00
|
|
|
|
2015-12-01 12:35:26 +00:00
|
|
|
//--------------------------------------------------------------------
|
|
|
|
// Test out the MessageBus-style purge. This will not free the atlas
|
|
|
|
// but should eliminate the free-floating layers.
|
|
|
|
create_layers(reporter, &cache, *picture, kInitialNumLayers, 0);
|
2014-07-22 17:18:06 +00:00
|
|
|
|
2015-12-01 12:35:26 +00:00
|
|
|
// Allocate/use the layers
|
|
|
|
for (int i = 0; i < kInitialNumLayers; ++i) {
|
|
|
|
int key[1] = { i + 1 };
|
|
|
|
GrCachedLayer* layer = TestingAccess::Find(&cache, picture->uniqueID(), SkMatrix::I(),
|
|
|
|
key, 1);
|
|
|
|
REPORTER_ASSERT(reporter, layer);
|
2015-11-09 21:51:06 +00:00
|
|
|
|
2015-12-01 12:35:26 +00:00
|
|
|
lock_layer(reporter, &cache, layer);
|
|
|
|
}
|
2015-11-09 21:51:06 +00:00
|
|
|
|
|
|
|
#if GR_CACHE_STATS
|
2015-12-01 12:35:26 +00:00
|
|
|
resourceCache->getStats(&stats);
|
|
|
|
REPORTER_ASSERT(reporter, 2 == stats.fTotal);
|
|
|
|
REPORTER_ASSERT(reporter, 2 == stats.fNumNonPurgeable);
|
2015-11-09 21:51:06 +00:00
|
|
|
#endif
|
|
|
|
|
2015-12-01 12:35:26 +00:00
|
|
|
// Unlock the textures
|
|
|
|
for (int i = 0; i < kInitialNumLayers; ++i) {
|
|
|
|
int key[1] = { i+1 };
|
2015-11-09 21:51:06 +00:00
|
|
|
|
2015-12-01 12:35:26 +00:00
|
|
|
GrCachedLayer* layer = TestingAccess::Find(&cache, picture->uniqueID(), SkMatrix::I(),
|
|
|
|
key, 1);
|
|
|
|
REPORTER_ASSERT(reporter, layer);
|
|
|
|
cache.removeUse(layer);
|
|
|
|
}
|
2015-11-09 21:51:06 +00:00
|
|
|
|
2015-12-01 12:35:26 +00:00
|
|
|
picture.reset(nullptr);
|
|
|
|
cache.processDeletedPictures();
|
2014-07-22 17:18:06 +00:00
|
|
|
|
2015-12-01 12:35:26 +00:00
|
|
|
REPORTER_ASSERT(reporter, TestingAccess::NumLayers(&cache) == 0);
|
2015-11-09 21:51:06 +00:00
|
|
|
|
|
|
|
#if GR_CACHE_STATS
|
2015-12-01 12:35:26 +00:00
|
|
|
resourceCache->getStats(&stats);
|
|
|
|
REPORTER_ASSERT(reporter, 2 == stats.fTotal);
|
|
|
|
REPORTER_ASSERT(reporter, 1 == stats.fNumPurgeable);
|
|
|
|
REPORTER_ASSERT(reporter, 1 == stats.fNumNonPurgeable);
|
2015-11-09 21:51:06 +00:00
|
|
|
#endif
|
|
|
|
|
2015-12-01 12:35:26 +00:00
|
|
|
cache.end();
|
2015-11-09 21:51:06 +00:00
|
|
|
|
|
|
|
#if GR_CACHE_STATS
|
2015-12-01 12:35:26 +00:00
|
|
|
resourceCache->getStats(&stats);
|
|
|
|
REPORTER_ASSERT(reporter, 2 == stats.fTotal);
|
|
|
|
REPORTER_ASSERT(reporter, 2 == stats.fNumPurgeable);
|
2015-11-09 21:51:06 +00:00
|
|
|
#endif
|
2014-06-30 15:26:50 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
#endif
|