| 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 "GrResourceCache2.h" | 16 #include "GrResourceCache.h" |
| 17 #include "SkCanvas.h" | 17 #include "SkCanvas.h" |
| 18 | 18 |
| 19 enum { | 19 enum { |
| 20 CACHE_SIZE_COUNT = 4096, | 20 CACHE_SIZE_COUNT = 4096, |
| 21 }; | 21 }; |
| 22 | 22 |
| 23 class BenchResource : public GrGpuResource { | 23 class BenchResource : public GrGpuResource { |
| 24 public: | 24 public: |
| 25 SK_DECLARE_INST_COUNT(BenchResource); | 25 SK_DECLARE_INST_COUNT(BenchResource); |
| 26 BenchResource (GrGpu* gpu) | 26 BenchResource (GrGpu* gpu) |
| (...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 62 } | 62 } |
| 63 | 63 |
| 64 void onDraw(const int loops, SkCanvas* canvas) SK_OVERRIDE { | 64 void onDraw(const int loops, SkCanvas* canvas) SK_OVERRIDE { |
| 65 SkAutoTUnref<GrContext> context(GrContext::CreateMockContext()); | 65 SkAutoTUnref<GrContext> context(GrContext::CreateMockContext()); |
| 66 if (NULL == context) { | 66 if (NULL == context) { |
| 67 return; | 67 return; |
| 68 } | 68 } |
| 69 // Set the cache budget to be very large so no purging occurs. | 69 // Set the cache budget to be very large so no purging occurs. |
| 70 context->setResourceCacheLimits(CACHE_SIZE_COUNT, 1 << 30); | 70 context->setResourceCacheLimits(CACHE_SIZE_COUNT, 1 << 30); |
| 71 | 71 |
| 72 GrResourceCache2* cache2 = context->getResourceCache2(); | 72 GrResourceCache* cache = context->getResourceCache(); |
| 73 | 73 |
| 74 // Make sure the cache is empty. | 74 // Make sure the cache is empty. |
| 75 cache2->purgeAllUnlocked(); | 75 cache->purgeAllUnlocked(); |
| 76 SkASSERT(0 == cache2->getResourceCount() && 0 == cache2->getResourceByte
s()); | 76 SkASSERT(0 == cache->getResourceCount() && 0 == cache->getResourceBytes(
)); |
| 77 | 77 |
| 78 GrGpu* gpu = context->getGpu(); | 78 GrGpu* gpu = context->getGpu(); |
| 79 | 79 |
| 80 for (int i = 0; i < loops; ++i) { | 80 for (int i = 0; i < loops; ++i) { |
| 81 populate_cache(gpu, CACHE_SIZE_COUNT); | 81 populate_cache(gpu, CACHE_SIZE_COUNT); |
| 82 SkASSERT(CACHE_SIZE_COUNT == cache2->getResourceCount()); | 82 SkASSERT(CACHE_SIZE_COUNT == cache->getResourceCount()); |
| 83 } | 83 } |
| 84 } | 84 } |
| 85 | 85 |
| 86 private: | 86 private: |
| 87 typedef Benchmark INHERITED; | 87 typedef Benchmark INHERITED; |
| 88 }; | 88 }; |
| 89 | 89 |
| 90 class GrResourceCacheBenchFind : public Benchmark { | 90 class GrResourceCacheBenchFind : public Benchmark { |
| 91 public: | 91 public: |
| 92 bool isSuitableFor(Backend backend) SK_OVERRIDE { | 92 bool isSuitableFor(Backend backend) SK_OVERRIDE { |
| 93 return backend == kNonRendering_Backend; | 93 return backend == kNonRendering_Backend; |
| 94 } | 94 } |
| 95 | 95 |
| 96 protected: | 96 protected: |
| 97 const char* onGetName() SK_OVERRIDE { | 97 const char* onGetName() SK_OVERRIDE { |
| 98 return "grresourcecache_find"; | 98 return "grresourcecache_find"; |
| 99 } | 99 } |
| 100 | 100 |
| 101 void onPreDraw() SK_OVERRIDE { | 101 void onPreDraw() SK_OVERRIDE { |
| 102 fContext.reset(GrContext::CreateMockContext()); | 102 fContext.reset(GrContext::CreateMockContext()); |
| 103 if (!fContext) { | 103 if (!fContext) { |
| 104 return; | 104 return; |
| 105 } | 105 } |
| 106 // Set the cache budget to be very large so no purging occurs. | 106 // Set the cache budget to be very large so no purging occurs. |
| 107 fContext->setResourceCacheLimits(CACHE_SIZE_COUNT, 1 << 30); | 107 fContext->setResourceCacheLimits(CACHE_SIZE_COUNT, 1 << 30); |
| 108 | 108 |
| 109 GrResourceCache2* cache2 = fContext->getResourceCache2(); | 109 GrResourceCache* cache = fContext->getResourceCache(); |
| 110 | 110 |
| 111 // Make sure the cache is empty. | 111 // Make sure the cache is empty. |
| 112 cache2->purgeAllUnlocked(); | 112 cache->purgeAllUnlocked(); |
| 113 SkASSERT(0 == cache2->getResourceCount() && 0 == cache2->getResourceByte
s()); | 113 SkASSERT(0 == cache->getResourceCount() && 0 == cache->getResourceBytes(
)); |
| 114 | 114 |
| 115 GrGpu* gpu = fContext->getGpu(); | 115 GrGpu* gpu = fContext->getGpu(); |
| 116 | 116 |
| 117 populate_cache(gpu, CACHE_SIZE_COUNT); | 117 populate_cache(gpu, CACHE_SIZE_COUNT); |
| 118 } | 118 } |
| 119 | 119 |
| 120 void onDraw(const int loops, SkCanvas* canvas) SK_OVERRIDE { | 120 void onDraw(const int loops, SkCanvas* canvas) SK_OVERRIDE { |
| 121 if (!fContext) { | 121 if (!fContext) { |
| 122 return; | 122 return; |
| 123 } | 123 } |
| 124 GrResourceCache2* cache2 = fContext->getResourceCache2(); | 124 GrResourceCache* cache = fContext->getResourceCache(); |
| 125 SkASSERT(CACHE_SIZE_COUNT == cache2->getResourceCount()); | 125 SkASSERT(CACHE_SIZE_COUNT == cache->getResourceCount()); |
| 126 for (int i = 0; i < loops; ++i) { | 126 for (int i = 0; i < loops; ++i) { |
| 127 for (int k = 0; k < CACHE_SIZE_COUNT; ++k) { | 127 for (int k = 0; k < CACHE_SIZE_COUNT; ++k) { |
| 128 GrContentKey key; | 128 GrContentKey key; |
| 129 BenchResource::ComputeKey(k, &key); | 129 BenchResource::ComputeKey(k, &key); |
| 130 SkAutoTUnref<GrGpuResource> resource(cache2->findAndRefContentRe
source(key)); | 130 SkAutoTUnref<GrGpuResource> resource(cache->findAndRefContentRes
ource(key)); |
| 131 SkASSERT(resource); | 131 SkASSERT(resource); |
| 132 } | 132 } |
| 133 } | 133 } |
| 134 } | 134 } |
| 135 | 135 |
| 136 private: | 136 private: |
| 137 SkAutoTUnref<GrContext> fContext; | 137 SkAutoTUnref<GrContext> fContext; |
| 138 typedef Benchmark INHERITED; | 138 typedef Benchmark INHERITED; |
| 139 }; | 139 }; |
| 140 | 140 |
| 141 DEF_BENCH( return new GrResourceCacheBenchAdd(); ) | 141 DEF_BENCH( return new GrResourceCacheBenchAdd(); ) |
| 142 DEF_BENCH( return new GrResourceCacheBenchFind(); ) | 142 DEF_BENCH( return new GrResourceCacheBenchFind(); ) |
| 143 | 143 |
| 144 #endif | 144 #endif |
| OLD | NEW |