OLD | NEW |
1 /* | 1 /* |
2 * Copyright 2014 Google Inc. | 2 * Copyright 2014 Google Inc. |
3 * | 3 * |
4 * Use of this source code is governed by a BSD-style license that can be | 4 * Use of this source code is governed by a BSD-style license that can be |
5 * found in the LICENSE file. | 5 * found in the LICENSE file. |
6 */ | 6 */ |
7 | 7 |
8 #if SK_SUPPORT_GPU | 8 #if SK_SUPPORT_GPU |
9 | 9 |
10 #include "GrContext.h" | 10 #include "GrContext.h" |
11 #include "GrContextFactory.h" | 11 #include "GrContextFactory.h" |
12 #include "GrLayerCache.h" | 12 #include "GrLayerCache.h" |
| 13 #include "SkPictureRecorder.h" |
13 #include "Test.h" | 14 #include "Test.h" |
14 | 15 |
15 static const int kNumLayers = 5; | 16 static const int kNumLayers = 5; |
16 | 17 |
17 class GetNumLayers { | 18 class GetNumLayers { |
18 public: | 19 public: |
19 static int NumLayers(GrLayerCache* cache) { | 20 static int NumLayers(GrLayerCache* cache) { |
20 return cache->numLayers(); | 21 return cache->numLayers(); |
21 } | 22 } |
22 }; | 23 }; |
(...skipping 24 matching lines...) Expand all Loading... |
47 // In particular it checks its interaction with the resource cache (w.r.t. | 48 // In particular it checks its interaction with the resource cache (w.r.t. |
48 // locking & unlocking textures). | 49 // locking & unlocking textures). |
49 // TODO: need to add checks on VRAM usage! | 50 // TODO: need to add checks on VRAM usage! |
50 DEF_GPUTEST(GpuLayerCache, reporter, factory) { | 51 DEF_GPUTEST(GpuLayerCache, reporter, factory) { |
51 | 52 |
52 GrContext* context = factory->get(GrContextFactory::kNative_GLContextType); | 53 GrContext* context = factory->get(GrContextFactory::kNative_GLContextType); |
53 if (NULL == context) { | 54 if (NULL == context) { |
54 return; | 55 return; |
55 } | 56 } |
56 | 57 |
57 SkPicture picture; | 58 SkPictureRecorder recorder; |
| 59 recorder.beginRecording(1, 1); |
| 60 SkAutoTUnref<const SkPicture> picture(recorder.endRecording()); |
58 | 61 |
59 GrLayerCache cache(context); | 62 GrLayerCache cache(context); |
60 | 63 |
61 create_layers(reporter, &cache, picture); | 64 create_layers(reporter, &cache, *picture); |
62 | 65 |
63 // Lock the layers making them all 512x512 | 66 // Lock the layers making them all 512x512 |
64 GrTextureDesc desc; | 67 GrTextureDesc desc; |
65 desc.fWidth = 512; | 68 desc.fWidth = 512; |
66 desc.fHeight = 512; | 69 desc.fHeight = 512; |
67 desc.fConfig = kSkia8888_GrPixelConfig; | 70 desc.fConfig = kSkia8888_GrPixelConfig; |
68 | 71 |
69 for (int i = 0; i < kNumLayers; ++i) { | 72 for (int i = 0; i < kNumLayers; ++i) { |
70 GrCachedLayer* layer = cache.findLayer(&picture, i); | 73 GrCachedLayer* layer = cache.findLayer(picture, i); |
71 REPORTER_ASSERT(reporter, NULL != layer); | 74 REPORTER_ASSERT(reporter, NULL != layer); |
72 | 75 |
73 bool foundInCache = cache.lock(layer, desc); | 76 bool foundInCache = cache.lock(layer, desc); |
74 REPORTER_ASSERT(reporter, !foundInCache); | 77 REPORTER_ASSERT(reporter, !foundInCache); |
75 foundInCache = cache.lock(layer, desc); | 78 foundInCache = cache.lock(layer, desc); |
76 REPORTER_ASSERT(reporter, foundInCache); | 79 REPORTER_ASSERT(reporter, foundInCache); |
77 | 80 |
78 REPORTER_ASSERT(reporter, NULL != layer->texture()); | 81 REPORTER_ASSERT(reporter, NULL != layer->texture()); |
79 #if USE_ATLAS | 82 #if USE_ATLAS |
80 // The first 4 layers should be in the atlas (and thus have non-empty | 83 // The first 4 layers should be in the atlas (and thus have non-empty |
81 // rects) | 84 // rects) |
82 if (i < 4) { | 85 if (i < 4) { |
83 REPORTER_ASSERT(reporter, !layer->rect().isEmpty()); | 86 REPORTER_ASSERT(reporter, !layer->rect().isEmpty()); |
84 } else { | 87 } else { |
85 #endif | 88 #endif |
86 REPORTER_ASSERT(reporter, layer->rect().isEmpty()); | 89 REPORTER_ASSERT(reporter, layer->rect().isEmpty()); |
87 #if USE_ATLAS | 90 #if USE_ATLAS |
88 } | 91 } |
89 #endif | 92 #endif |
90 } | 93 } |
91 | 94 |
92 // Unlock the textures | 95 // Unlock the textures |
93 for (int i = 0; i < kNumLayers; ++i) { | 96 for (int i = 0; i < kNumLayers; ++i) { |
94 GrCachedLayer* layer = cache.findLayer(&picture, i); | 97 GrCachedLayer* layer = cache.findLayer(picture, i); |
95 REPORTER_ASSERT(reporter, NULL != layer); | 98 REPORTER_ASSERT(reporter, NULL != layer); |
96 | 99 |
97 cache.unlock(layer); | 100 cache.unlock(layer); |
98 } | 101 } |
99 | 102 |
100 for (int i = 0; i < kNumLayers; ++i) { | 103 for (int i = 0; i < kNumLayers; ++i) { |
101 GrCachedLayer* layer = cache.findLayer(&picture, i); | 104 GrCachedLayer* layer = cache.findLayer(picture, i); |
102 REPORTER_ASSERT(reporter, NULL != layer); | 105 REPORTER_ASSERT(reporter, NULL != layer); |
103 | 106 |
104 #if USE_ATLAS | 107 #if USE_ATLAS |
105 // The first 4 layers should be in the atlas (and thus do not | 108 // The first 4 layers should be in the atlas (and thus do not |
106 // currently unlock). The final layer should be unlocked. | 109 // currently unlock). The final layer should be unlocked. |
107 if (i < 4) { | 110 if (i < 4) { |
108 REPORTER_ASSERT(reporter, NULL != layer->texture()); | 111 REPORTER_ASSERT(reporter, NULL != layer->texture()); |
109 REPORTER_ASSERT(reporter, !layer->rect().isEmpty()); | 112 REPORTER_ASSERT(reporter, !layer->rect().isEmpty()); |
110 } else { | 113 } else { |
111 #endif | 114 #endif |
112 REPORTER_ASSERT(reporter, NULL == layer->texture()); | 115 REPORTER_ASSERT(reporter, NULL == layer->texture()); |
113 REPORTER_ASSERT(reporter, layer->rect().isEmpty()); | 116 REPORTER_ASSERT(reporter, layer->rect().isEmpty()); |
114 #if USE_ATLAS | 117 #if USE_ATLAS |
115 } | 118 } |
116 #endif | 119 #endif |
117 } | 120 } |
118 | 121 |
119 // Free them all SkGpuDevice-style. This will not free up the | 122 // Free them all SkGpuDevice-style. This will not free up the |
120 // atlas' texture but will eliminate all the layers. | 123 // atlas' texture but will eliminate all the layers. |
121 cache.purge(&picture); | 124 cache.purge(picture); |
122 | 125 |
123 REPORTER_ASSERT(reporter, GetNumLayers::NumLayers(&cache) == 0); | 126 REPORTER_ASSERT(reporter, GetNumLayers::NumLayers(&cache) == 0); |
124 // TODO: add VRAM/resource cache check here | 127 // TODO: add VRAM/resource cache check here |
125 #if 0 | 128 #if 0 |
126 // Re-create the layers | 129 // Re-create the layers |
127 create_layers(reporter, &cache, picture); | 130 create_layers(reporter, &cache, picture); |
128 | 131 |
129 // Free them again GrContext-style. This should free up everything. | 132 // Free them again GrContext-style. This should free up everything. |
130 cache.freeAll(); | 133 cache.freeAll(); |
131 | 134 |
132 REPORTER_ASSERT(reporter, GetNumLayers::NumLayers(&cache) == 0); | 135 REPORTER_ASSERT(reporter, GetNumLayers::NumLayers(&cache) == 0); |
133 // TODO: add VRAM/resource cache check here | 136 // TODO: add VRAM/resource cache check here |
134 #endif | 137 #endif |
135 } | 138 } |
136 | 139 |
137 #endif | 140 #endif |
OLD | NEW |