OLD | NEW |
1 | 1 |
2 /* | 2 /* |
3 * Copyright 2013 Google Inc. | 3 * Copyright 2013 Google Inc. |
4 * | 4 * |
5 * Use of this source code is governed by a BSD-style license that can be | 5 * Use of this source code is governed by a BSD-style license that can be |
6 * found in the LICENSE file. | 6 * found in the LICENSE file. |
7 */ | 7 */ |
8 | 8 |
9 #include "Benchmark.h" | 9 #include "Benchmark.h" |
10 | 10 |
11 #if SK_SUPPORT_GPU | 11 #if SK_SUPPORT_GPU |
12 | 12 |
13 #include "GrGpuResource.h" | 13 #include "GrGpuResource.h" |
14 #include "GrContext.h" | 14 #include "GrContext.h" |
15 #include "GrGpu.h" | 15 #include "GrGpu.h" |
| 16 #include "GrResourceCache.h" |
16 #include "GrResourceCache2.h" | 17 #include "GrResourceCache2.h" |
17 #include "GrStencilBuffer.h" | 18 #include "GrStencilBuffer.h" |
18 #include "GrTexture.h" | 19 #include "GrTexture.h" |
19 #include "GrTexturePriv.h" | 20 #include "GrTexturePriv.h" |
20 #include "SkCanvas.h" | 21 #include "SkCanvas.h" |
21 | 22 |
22 enum { | 23 enum { |
23 CACHE_SIZE_COUNT = 2048, | 24 CACHE_SIZE_COUNT = 2048, |
24 CACHE_SIZE_BYTES = 2 * 1024 * 1024, | 25 CACHE_SIZE_BYTES = 2 * 1024 * 1024, |
25 }; | 26 }; |
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
81 typedef GrGpuResource INHERITED; | 82 typedef GrGpuResource INHERITED; |
82 }; | 83 }; |
83 | 84 |
84 static void get_stencil(int i, int* w, int* h, int* s) { | 85 static void get_stencil(int i, int* w, int* h, int* s) { |
85 *w = i % 1024; | 86 *w = i % 1024; |
86 *h = i * 2 % 1024; | 87 *h = i * 2 % 1024; |
87 *s = i % 1 == 0 ? 0 : 4; | 88 *s = i % 1 == 0 ? 0 : 4; |
88 } | 89 } |
89 | 90 |
90 static void get_texture_desc(int i, GrSurfaceDesc* desc) { | 91 static void get_texture_desc(int i, GrSurfaceDesc* desc) { |
91 desc->fFlags = kRenderTarget_GrSurfaceFlag | kNoStencil_GrSurfaceFlag; | 92 desc->fFlags = kRenderTarget_GrSurfaceFlag | |
| 93 kNoStencil_GrSurfaceFlag; |
92 desc->fWidth = i % 1024; | 94 desc->fWidth = i % 1024; |
93 desc->fHeight = i * 2 % 1024; | 95 desc->fHeight = i * 2 % 1024; |
94 desc->fConfig = static_cast<GrPixelConfig>(i % (kLast_GrPixelConfig + 1)); | 96 desc->fConfig = static_cast<GrPixelConfig>(i % (kLast_GrPixelConfig + 1)); |
95 desc->fSampleCnt = ((i % 2) == 0) ? 0 : 4; | 97 desc->fSampleCnt = i % 1 == 0 ? 0 : 4; |
96 } | 98 } |
97 | 99 |
98 static void populate_cache(GrGpu* gpu, int resourceCount) { | 100 static void populate_cache(GrResourceCache* cache, GrGpu* gpu, int resourceCount
) { |
99 for (int i = 0; i < resourceCount; ++i) { | 101 for (int i = 0; i < resourceCount; ++i) { |
100 int w, h, s; | 102 int w, h, s; |
101 get_stencil(i, &w, &h, &s); | 103 get_stencil(i, &w, &h, &s); |
102 GrResourceKey key = GrStencilBuffer::ComputeKey(w, h, s); | 104 GrResourceKey key = GrStencilBuffer::ComputeKey(w, h, s); |
103 GrGpuResource* resource = SkNEW_ARGS(StencilResource, (gpu, i)); | 105 GrGpuResource* resource = SkNEW_ARGS(StencilResource, (gpu, i)); |
104 resource->cacheAccess().setContentKey(key); | 106 cache->purgeAsNeeded(1, resource->gpuMemorySize()); |
| 107 cache->addResource(key, resource); |
105 resource->unref(); | 108 resource->unref(); |
106 } | 109 } |
107 | 110 |
108 for (int i = 0; i < resourceCount; ++i) { | 111 for (int i = 0; i < resourceCount; ++i) { |
109 GrSurfaceDesc desc; | 112 GrSurfaceDesc desc; |
110 get_texture_desc(i, &desc); | 113 get_texture_desc(i, &desc); |
111 GrResourceKey key = TextureResource::ComputeKey(desc); | 114 GrResourceKey key = TextureResource::ComputeKey(desc); |
112 GrGpuResource* resource = SkNEW_ARGS(TextureResource, (gpu, i)); | 115 GrGpuResource* resource = SkNEW_ARGS(TextureResource, (gpu, i)); |
113 resource->cacheAccess().setContentKey(key); | 116 cache->purgeAsNeeded(1, resource->gpuMemorySize()); |
| 117 cache->addResource(key, resource); |
114 resource->unref(); | 118 resource->unref(); |
115 } | 119 } |
116 } | 120 } |
117 | 121 |
118 static void check_cache_contents_or_die(GrResourceCache2* cache, int k) { | 122 static void check_cache_contents_or_die(GrResourceCache2* cache, int k) { |
119 // Benchmark find calls that succeed. | 123 // Benchmark find calls that succeed. |
120 { | 124 { |
121 GrSurfaceDesc desc; | 125 GrSurfaceDesc desc; |
122 get_texture_desc(k, &desc); | 126 get_texture_desc(k, &desc); |
123 GrResourceKey key = TextureResource::ComputeKey(desc); | 127 GrResourceKey key = TextureResource::ComputeKey(desc); |
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
187 } | 191 } |
188 | 192 |
189 virtual void onDraw(const int loops, SkCanvas* canvas) SK_OVERRIDE { | 193 virtual void onDraw(const int loops, SkCanvas* canvas) SK_OVERRIDE { |
190 SkAutoTUnref<GrContext> context(GrContext::CreateMockContext()); | 194 SkAutoTUnref<GrContext> context(GrContext::CreateMockContext()); |
191 if (NULL == context) { | 195 if (NULL == context) { |
192 return; | 196 return; |
193 } | 197 } |
194 // Set the cache budget to be very large so no purging occurs. | 198 // Set the cache budget to be very large so no purging occurs. |
195 context->setResourceCacheLimits(2 * RESOURCE_COUNT, 1 << 30); | 199 context->setResourceCacheLimits(2 * RESOURCE_COUNT, 1 << 30); |
196 | 200 |
| 201 GrResourceCache* cache = context->getResourceCache(); |
197 GrResourceCache2* cache2 = context->getResourceCache2(); | 202 GrResourceCache2* cache2 = context->getResourceCache2(); |
198 | 203 |
199 // Make sure the cache is empty. | 204 // Make sure the cache is empty. |
200 cache2->purgeAllUnlocked(); | 205 cache->purgeAllUnlocked(); |
201 SkASSERT(0 == cache2->getResourceCount() && 0 == cache2->getResourceByte
s()); | 206 SkASSERT(0 == cache->getCachedResourceCount() && 0 == cache->getCachedRe
sourceBytes()); |
202 | 207 |
203 GrGpu* gpu = context->getGpu(); | 208 GrGpu* gpu = context->getGpu(); |
204 | 209 |
205 for (int i = 0; i < loops; ++i) { | 210 for (int i = 0; i < loops; ++i) { |
206 SkASSERT(0 == cache2->getResourceCount() && 0 == cache2->getResource
Bytes()); | 211 SkASSERT(0 == cache->getCachedResourceCount() && 0 == cache->getCach
edResourceBytes()); |
207 | 212 |
208 populate_cache(gpu, RESOURCE_COUNT); | 213 populate_cache(cache, gpu, RESOURCE_COUNT); |
209 | 214 |
210 // Check that cache works. | 215 // Check that cache works. |
211 for (int k = 0; k < RESOURCE_COUNT; k += 33) { | 216 for (int k = 0; k < RESOURCE_COUNT; k += 33) { |
212 check_cache_contents_or_die(cache2, k); | 217 check_cache_contents_or_die(cache2, k); |
213 } | 218 } |
214 cache2->purgeAllUnlocked(); | 219 cache->purgeAllUnlocked(); |
215 } | 220 } |
216 } | 221 } |
217 | 222 |
218 private: | 223 private: |
219 typedef Benchmark INHERITED; | 224 typedef Benchmark INHERITED; |
220 }; | 225 }; |
221 | 226 |
222 class GrResourceCacheBenchFind : public Benchmark { | 227 class GrResourceCacheBenchFind : public Benchmark { |
223 enum { | 228 enum { |
224 RESOURCE_COUNT = CACHE_SIZE_COUNT / 2, | 229 RESOURCE_COUNT = CACHE_SIZE_COUNT / 2, |
(...skipping 10 matching lines...) Expand all Loading... |
235 } | 240 } |
236 | 241 |
237 virtual void onDraw(const int loops, SkCanvas* canvas) SK_OVERRIDE { | 242 virtual void onDraw(const int loops, SkCanvas* canvas) SK_OVERRIDE { |
238 SkAutoTUnref<GrContext> context(GrContext::CreateMockContext()); | 243 SkAutoTUnref<GrContext> context(GrContext::CreateMockContext()); |
239 if (NULL == context) { | 244 if (NULL == context) { |
240 return; | 245 return; |
241 } | 246 } |
242 // Set the cache budget to be very large so no purging occurs. | 247 // Set the cache budget to be very large so no purging occurs. |
243 context->setResourceCacheLimits(2 * RESOURCE_COUNT, 1 << 30); | 248 context->setResourceCacheLimits(2 * RESOURCE_COUNT, 1 << 30); |
244 | 249 |
| 250 GrResourceCache* cache = context->getResourceCache(); |
245 GrResourceCache2* cache2 = context->getResourceCache2(); | 251 GrResourceCache2* cache2 = context->getResourceCache2(); |
246 | 252 |
247 // Make sure the cache is empty. | 253 // Make sure the cache is empty. |
248 cache2->purgeAllUnlocked(); | 254 cache->purgeAllUnlocked(); |
249 SkASSERT(0 == cache2->getResourceCount() && 0 == cache2->getResourceByte
s()); | 255 SkASSERT(0 == cache->getCachedResourceCount() && 0 == cache->getCachedRe
sourceBytes()); |
250 | 256 |
251 GrGpu* gpu = context->getGpu(); | 257 GrGpu* gpu = context->getGpu(); |
252 | 258 |
253 populate_cache(gpu, RESOURCE_COUNT); | 259 populate_cache(cache, gpu, RESOURCE_COUNT); |
254 | 260 |
255 for (int i = 0; i < loops; ++i) { | 261 for (int i = 0; i < loops; ++i) { |
256 for (int k = 0; k < RESOURCE_COUNT; ++k) { | 262 for (int k = 0; k < RESOURCE_COUNT; ++k) { |
257 check_cache_contents_or_die(cache2, k); | 263 check_cache_contents_or_die(cache2, k); |
258 } | 264 } |
259 } | 265 } |
260 } | 266 } |
261 | 267 |
262 private: | 268 private: |
263 typedef Benchmark INHERITED; | 269 typedef Benchmark INHERITED; |
264 }; | 270 }; |
265 | 271 |
266 DEF_BENCH( return new GrResourceCacheBenchAdd(); ) | 272 DEF_BENCH( return new GrResourceCacheBenchAdd(); ) |
267 DEF_BENCH( return new GrResourceCacheBenchFind(); ) | 273 DEF_BENCH( return new GrResourceCacheBenchFind(); ) |
268 | 274 |
269 #endif | 275 #endif |
OLD | NEW |