Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(216)

Side by Side Diff: bench/GrResourceCacheBench.cpp

Issue 858123002: Add specialized content key class for resources. (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: remove default template arg Created 5 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « no previous file | gyp/gpu.gypi » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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
(...skipping 10 matching lines...) Expand all
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)
27 : INHERITED(gpu, kCached_LifeCycle) { 27 : INHERITED(gpu, kCached_LifeCycle) {
28 this->registerWithCache(); 28 this->registerWithCache();
29 } 29 }
30 30
31 static GrResourceKey ComputeKey(int i) { 31 static void ComputeKey(int i, GrContentKey* key) {
32 GrCacheID::Key key; 32 static GrContentKey::Domain kDomain = GrContentKey::GenerateDomain();
33 memset(&key, 0, sizeof(key)); 33 GrContentKey::Builder builder(key, kDomain, 1);
34 key.fData32[0] = i; 34 builder[0] = i;
35 static int gDomain = GrCacheID::GenerateDomain();
36 return GrResourceKey(GrCacheID(gDomain, key), 0);
37 } 35 }
38 36
39
40 private: 37 private:
41 size_t onGpuMemorySize() const SK_OVERRIDE { return 100; } 38 size_t onGpuMemorySize() const SK_OVERRIDE { return 100; }
42 39
43 typedef GrGpuResource INHERITED; 40 typedef GrGpuResource INHERITED;
44 }; 41 };
45 42
46 static void populate_cache(GrGpu* gpu, int resourceCount) { 43 static void populate_cache(GrGpu* gpu, int resourceCount) {
47 for (int i = 0; i < resourceCount; ++i) { 44 for (int i = 0; i < resourceCount; ++i) {
48 GrResourceKey key = BenchResource::ComputeKey(i); 45 GrContentKey key;
46 BenchResource::ComputeKey(i, &key);
49 GrGpuResource* resource = SkNEW_ARGS(BenchResource, (gpu)); 47 GrGpuResource* resource = SkNEW_ARGS(BenchResource, (gpu));
50 resource->cacheAccess().setContentKey(key); 48 resource->cacheAccess().setContentKey(key);
51 resource->unref(); 49 resource->unref();
52 } 50 }
53 } 51 }
54 52
55 class GrResourceCacheBenchAdd : public Benchmark { 53 class GrResourceCacheBenchAdd : public Benchmark {
56 public: 54 public:
57 bool isSuitableFor(Backend backend) SK_OVERRIDE { 55 bool isSuitableFor(Backend backend) SK_OVERRIDE {
58 return backend == kNonRendering_Backend; 56 return backend == kNonRendering_Backend;
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after
120 } 118 }
121 119
122 void onDraw(const int loops, SkCanvas* canvas) SK_OVERRIDE { 120 void onDraw(const int loops, SkCanvas* canvas) SK_OVERRIDE {
123 if (!fContext) { 121 if (!fContext) {
124 return; 122 return;
125 } 123 }
126 GrResourceCache2* cache2 = fContext->getResourceCache2(); 124 GrResourceCache2* cache2 = fContext->getResourceCache2();
127 SkASSERT(CACHE_SIZE_COUNT == cache2->getResourceCount()); 125 SkASSERT(CACHE_SIZE_COUNT == cache2->getResourceCount());
128 for (int i = 0; i < loops; ++i) { 126 for (int i = 0; i < loops; ++i) {
129 for (int k = 0; k < CACHE_SIZE_COUNT; ++k) { 127 for (int k = 0; k < CACHE_SIZE_COUNT; ++k) {
130 GrResourceKey key = BenchResource::ComputeKey(k); 128 GrContentKey key;
129 BenchResource::ComputeKey(k, &key);
131 SkAutoTUnref<GrGpuResource> resource(cache2->findAndRefContentRe source(key)); 130 SkAutoTUnref<GrGpuResource> resource(cache2->findAndRefContentRe source(key));
132 SkASSERT(resource); 131 SkASSERT(resource);
133 } 132 }
134 } 133 }
135 } 134 }
136 135
137 private: 136 private:
138 SkAutoTUnref<GrContext> fContext; 137 SkAutoTUnref<GrContext> fContext;
139 typedef Benchmark INHERITED; 138 typedef Benchmark INHERITED;
140 }; 139 };
141 140
142 DEF_BENCH( return new GrResourceCacheBenchAdd(); ) 141 DEF_BENCH( return new GrResourceCacheBenchAdd(); )
143 DEF_BENCH( return new GrResourceCacheBenchFind(); ) 142 DEF_BENCH( return new GrResourceCacheBenchFind(); )
144 143
145 #endif 144 #endif
OLDNEW
« no previous file with comments | « no previous file | gyp/gpu.gypi » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698