Index: tests/GpuLayerCacheTest.cpp |
diff --git a/tests/GpuLayerCacheTest.cpp b/tests/GpuLayerCacheTest.cpp |
index eb7d92c8e20fbcf3eb01de8cf1103d37e6a30b2a..d14711633f2db4b2f75606f6aaff5fca541a32d6 100644 |
--- a/tests/GpuLayerCacheTest.cpp |
+++ b/tests/GpuLayerCacheTest.cpp |
@@ -13,8 +13,6 @@ |
#include "SkPictureRecorder.h" |
#include "Test.h" |
-static const int kNumLayers = 5; |
- |
class TestingAccess { |
public: |
static int NumLayers(GrLayerCache* cache) { |
@@ -28,24 +26,44 @@ public: |
// Add several layers to the cache |
static void create_layers(skiatest::Reporter* reporter, |
GrLayerCache* cache, |
- const SkPicture& picture) { |
- GrCachedLayer* layers[kNumLayers]; |
+ const SkPicture& picture, |
+ int numToAdd, |
+ int idOffset) { |
+ |
+ for (int i = 0; i < numToAdd; ++i) { |
+ GrCachedLayer* layer = cache->findLayerOrCreate(&picture, idOffset+i); |
+ REPORTER_ASSERT(reporter, NULL != layer); |
+ GrCachedLayer* temp = cache->findLayer(&picture, idOffset+i); |
+ REPORTER_ASSERT(reporter, temp == layer); |
+ |
+ REPORTER_ASSERT(reporter, TestingAccess::NumLayers(cache) == idOffset + i + 1); |
+ |
+ REPORTER_ASSERT(reporter, picture.uniqueID() == layer->pictureID()); |
+ REPORTER_ASSERT(reporter, layer->layerID() == idOffset + i); |
+ REPORTER_ASSERT(reporter, NULL == layer->texture()); |
+ REPORTER_ASSERT(reporter, !layer->isAtlased()); |
+ } |
+ |
+ cache->trackPicture(&picture); |
+} |
- for (int i = 0; i < kNumLayers; ++i) { |
- layers[i] = cache->findLayerOrCreate(&picture, i); |
- REPORTER_ASSERT(reporter, NULL != layers[i]); |
- GrCachedLayer* layer = cache->findLayer(&picture, i); |
- REPORTER_ASSERT(reporter, layer == layers[i]); |
+static void lock_layer(skiatest::Reporter* reporter, |
+ GrLayerCache* cache, |
+ GrCachedLayer* layer) { |
+ // Make the layer 512x512 (so it can be atlased) |
+ GrTextureDesc desc; |
+ desc.fWidth = 512; |
+ desc.fHeight = 512; |
+ desc.fConfig = kSkia8888_GrPixelConfig; |
- REPORTER_ASSERT(reporter, TestingAccess::NumLayers(cache) == i + 1); |
+ bool foundInCache = cache->lock(layer, desc); |
+ REPORTER_ASSERT(reporter, !foundInCache); |
- REPORTER_ASSERT(reporter, picture.uniqueID() == layers[i]->pictureID()); |
- REPORTER_ASSERT(reporter, layers[i]->layerID() == i); |
- REPORTER_ASSERT(reporter, NULL == layers[i]->texture()); |
- REPORTER_ASSERT(reporter, !layers[i]->isAtlased()); |
- } |
+ foundInCache = cache->lock(layer, desc); |
+ REPORTER_ASSERT(reporter, foundInCache); |
- cache->trackPicture(&picture); |
+ REPORTER_ASSERT(reporter, NULL != layer->texture()); |
+ REPORTER_ASSERT(reporter, layer->locked()); |
} |
// This test case exercises the public API of the GrLayerCache class. |
@@ -53,6 +71,8 @@ static void create_layers(skiatest::Reporter* reporter, |
// locking & unlocking textures). |
// TODO: need to add checks on VRAM usage! |
DEF_GPUTEST(GpuLayerCache, reporter, factory) { |
+ static const int kInitialNumLayers = 5; |
+ |
for (int i= 0; i < GrContextFactory::kGLContextTypeCnt; ++i) { |
GrContextFactory::GLContextType glCtxType = (GrContextFactory::GLContextType) i; |
@@ -72,24 +92,14 @@ DEF_GPUTEST(GpuLayerCache, reporter, factory) { |
GrLayerCache cache(context); |
- create_layers(reporter, &cache, *picture); |
+ create_layers(reporter, &cache, *picture, kInitialNumLayers, 0); |
- // Lock the layers making them all 512x512 |
- GrTextureDesc desc; |
- desc.fWidth = 512; |
- desc.fHeight = 512; |
- desc.fConfig = kSkia8888_GrPixelConfig; |
- |
- for (int i = 0; i < kNumLayers; ++i) { |
+ for (int i = 0; i < kInitialNumLayers; ++i) { |
GrCachedLayer* layer = cache.findLayer(picture, i); |
REPORTER_ASSERT(reporter, NULL != layer); |
- bool foundInCache = cache.lock(layer, desc); |
- REPORTER_ASSERT(reporter, !foundInCache); |
- foundInCache = cache.lock(layer, desc); |
- REPORTER_ASSERT(reporter, foundInCache); |
+ lock_layer(reporter, &cache, layer); |
- REPORTER_ASSERT(reporter, NULL != layer->texture()); |
#if USE_ATLAS |
// The first 4 layers should be in the atlas (and thus have non-empty |
// rects) |
@@ -97,32 +107,34 @@ DEF_GPUTEST(GpuLayerCache, reporter, factory) { |
REPORTER_ASSERT(reporter, layer->isAtlased()); |
} else { |
#endif |
- REPORTER_ASSERT(reporter, !layer->isAtlased()); |
+ // The 5th layer couldn't fit in the atlas |
+ REPORTER_ASSERT(reporter, !layer->isAtlased()); |
#if USE_ATLAS |
} |
#endif |
} |
// Unlock the textures |
- for (int i = 0; i < kNumLayers; ++i) { |
+ for (int i = 0; i < kInitialNumLayers; ++i) { |
GrCachedLayer* layer = cache.findLayer(picture, i); |
REPORTER_ASSERT(reporter, NULL != layer); |
cache.unlock(layer); |
} |
- for (int i = 0; i < kNumLayers; ++i) { |
+ for (int i = 0; i < kInitialNumLayers; ++i) { |
GrCachedLayer* layer = cache.findLayer(picture, i); |
REPORTER_ASSERT(reporter, NULL != layer); |
+ REPORTER_ASSERT(reporter, !layer->locked()); |
#if USE_ATLAS |
- // The first 4 layers should be in the atlas (and thus do not |
- // currently unlock). The final layer should be unlocked. |
+ // The first 4 layers should still be in the atlas. |
if (i < 4) { |
REPORTER_ASSERT(reporter, NULL != layer->texture()); |
REPORTER_ASSERT(reporter, layer->isAtlased()); |
} else { |
#endif |
+ // The final layer should be unlocked. |
REPORTER_ASSERT(reporter, NULL == layer->texture()); |
REPORTER_ASSERT(reporter, !layer->isAtlased()); |
#if USE_ATLAS |
@@ -130,6 +142,41 @@ DEF_GPUTEST(GpuLayerCache, reporter, factory) { |
#endif |
} |
+ { |
+ // 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 = cache.findLayer(picture, kInitialNumLayers); |
+ REPORTER_ASSERT(reporter, NULL != layer); |
+ |
+ lock_layer(reporter, &cache, layer); |
+ cache.unlock(layer); |
+ } |
+ |
+ for (int i = 0; i < kInitialNumLayers+1; ++i) { |
+ GrCachedLayer* layer = cache.findLayer(picture, i); |
+#if USE_ATLAS |
+ // 3 old layers plus the new one should be in the atlas. |
+ if (1 == i || 2 == i || 3 == i || 5 == i) { |
+ REPORTER_ASSERT(reporter, NULL != layer); |
+ REPORTER_ASSERT(reporter, !layer->locked()); |
+ REPORTER_ASSERT(reporter, NULL != layer->texture()); |
+ REPORTER_ASSERT(reporter, layer->isAtlased()); |
+ } else if (4 == i) { |
+#endif |
+ // The one that was never atlased should still be around |
+ REPORTER_ASSERT(reporter, NULL != layer); |
+ |
+ REPORTER_ASSERT(reporter, NULL == layer->texture()); |
+ REPORTER_ASSERT(reporter, !layer->isAtlased()); |
+#if USE_ATLAS |
+ } else { |
+ // The one bumped out of the atlas (i.e., 0) should be gone |
+ REPORTER_ASSERT(reporter, NULL == layer); |
+ } |
+#endif |
+ } |
+ |
//-------------------------------------------------------------------- |
// Free them all SkGpuDevice-style. This will not free up the |
// atlas' texture but will eliminate all the layers. |
@@ -142,7 +189,7 @@ DEF_GPUTEST(GpuLayerCache, reporter, factory) { |
// Test out the GrContext-style purge. This should remove all the layers |
// and the atlas. |
// Re-create the layers |
- create_layers(reporter, &cache, *picture); |
+ create_layers(reporter, &cache, *picture, kInitialNumLayers, 0); |
// Free them again GrContext-style. This should free up everything. |
cache.freeAll(); |
@@ -153,7 +200,7 @@ DEF_GPUTEST(GpuLayerCache, reporter, factory) { |
//-------------------------------------------------------------------- |
// Test out the MessageBus-style purge. This will not free the atlas |
// but should eliminate the free-floating layers. |
- create_layers(reporter, &cache, *picture); |
+ create_layers(reporter, &cache, *picture, kInitialNumLayers, 0); |
picture.reset(NULL); |
cache.processDeletedPictures(); |