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 #if SK_SUPPORT_GPU | 9 #if SK_SUPPORT_GPU |
10 | 10 |
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
56 , fID(id) { | 56 , fID(id) { |
57 this->registerWithCache(); | 57 this->registerWithCache(); |
58 } | 58 } |
59 | 59 |
60 virtual ~TextureResource() { this->release(); } | 60 virtual ~TextureResource() { this->release(); } |
61 | 61 |
62 virtual size_t gpuMemorySize() const SK_OVERRIDE { | 62 virtual size_t gpuMemorySize() const SK_OVERRIDE { |
63 return 100 + ((fID % 1 == 0) ? -40 : 33); | 63 return 100 + ((fID % 1 == 0) ? -40 : 33); |
64 } | 64 } |
65 | 65 |
66 static GrResourceKey ComputeKey(const GrTextureDesc& desc) { | 66 static GrResourceKey ComputeKey(const GrSurfaceDesc& desc) { |
67 GrCacheID::Key key; | 67 GrCacheID::Key key; |
68 memset(&key, 0, sizeof(key)); | 68 memset(&key, 0, sizeof(key)); |
69 key.fData32[0] = (desc.fWidth) | (desc.fHeight << 16); | 69 key.fData32[0] = (desc.fWidth) | (desc.fHeight << 16); |
70 key.fData32[1] = desc.fConfig | desc.fSampleCnt << 16; | 70 key.fData32[1] = desc.fConfig | desc.fSampleCnt << 16; |
71 key.fData32[2] = desc.fFlags; | 71 key.fData32[2] = desc.fFlags; |
72 static int gType = GrResourceKey::GenerateResourceType(); | 72 static int gType = GrResourceKey::GenerateResourceType(); |
73 static int gDomain = GrCacheID::GenerateDomain(); | 73 static int gDomain = GrCacheID::GenerateDomain(); |
74 return GrResourceKey(GrCacheID(gDomain, key), gType, 0); | 74 return GrResourceKey(GrCacheID(gDomain, key), gType, 0); |
75 } | 75 } |
76 | 76 |
77 int fID; | 77 int fID; |
78 | 78 |
79 private: | 79 private: |
80 typedef GrGpuResource INHERITED; | 80 typedef GrGpuResource INHERITED; |
81 }; | 81 }; |
82 | 82 |
83 static void get_stencil(int i, int* w, int* h, int* s) { | 83 static void get_stencil(int i, int* w, int* h, int* s) { |
84 *w = i % 1024; | 84 *w = i % 1024; |
85 *h = i * 2 % 1024; | 85 *h = i * 2 % 1024; |
86 *s = i % 1 == 0 ? 0 : 4; | 86 *s = i % 1 == 0 ? 0 : 4; |
87 } | 87 } |
88 | 88 |
89 static void get_texture_desc(int i, GrTextureDesc* desc) { | 89 static void get_texture_desc(int i, GrSurfaceDesc* desc) { |
90 desc->fFlags = kRenderTarget_GrTextureFlagBit | | 90 desc->fFlags = kRenderTarget_GrSurfaceFlag | |
91 kNoStencil_GrTextureFlagBit; | 91 kNoStencil_GrSurfaceFlag; |
92 desc->fWidth = i % 1024; | 92 desc->fWidth = i % 1024; |
93 desc->fHeight = i * 2 % 1024; | 93 desc->fHeight = i * 2 % 1024; |
94 desc->fConfig = static_cast<GrPixelConfig>(i % (kLast_GrPixelConfig + 1)); | 94 desc->fConfig = static_cast<GrPixelConfig>(i % (kLast_GrPixelConfig + 1)); |
95 desc->fSampleCnt = i % 1 == 0 ? 0 : 4; | 95 desc->fSampleCnt = i % 1 == 0 ? 0 : 4; |
96 } | 96 } |
97 | 97 |
98 static void populate_cache(GrResourceCache* cache, GrGpu* gpu, int resourceCount
) { | 98 static void populate_cache(GrResourceCache* cache, GrGpu* gpu, int resourceCount
) { |
99 for (int i = 0; i < resourceCount; ++i) { | 99 for (int i = 0; i < resourceCount; ++i) { |
100 int w, h, s; | 100 int w, h, s; |
101 get_stencil(i, &w, &h, &s); | 101 get_stencil(i, &w, &h, &s); |
102 GrResourceKey key = GrStencilBuffer::ComputeKey(w, h, s); | 102 GrResourceKey key = GrStencilBuffer::ComputeKey(w, h, s); |
103 GrGpuResource* resource = SkNEW_ARGS(StencilResource, (gpu, i)); | 103 GrGpuResource* resource = SkNEW_ARGS(StencilResource, (gpu, i)); |
104 cache->purgeAsNeeded(1, resource->gpuMemorySize()); | 104 cache->purgeAsNeeded(1, resource->gpuMemorySize()); |
105 cache->addResource(key, resource); | 105 cache->addResource(key, resource); |
106 resource->unref(); | 106 resource->unref(); |
107 } | 107 } |
108 | 108 |
109 for (int i = 0; i < resourceCount; ++i) { | 109 for (int i = 0; i < resourceCount; ++i) { |
110 GrTextureDesc desc; | 110 GrSurfaceDesc desc; |
111 get_texture_desc(i, &desc); | 111 get_texture_desc(i, &desc); |
112 GrResourceKey key = TextureResource::ComputeKey(desc); | 112 GrResourceKey key = TextureResource::ComputeKey(desc); |
113 GrGpuResource* resource = SkNEW_ARGS(TextureResource, (gpu, i)); | 113 GrGpuResource* resource = SkNEW_ARGS(TextureResource, (gpu, i)); |
114 cache->purgeAsNeeded(1, resource->gpuMemorySize()); | 114 cache->purgeAsNeeded(1, resource->gpuMemorySize()); |
115 cache->addResource(key, resource); | 115 cache->addResource(key, resource); |
116 resource->unref(); | 116 resource->unref(); |
117 } | 117 } |
118 } | 118 } |
119 | 119 |
120 static void check_cache_contents_or_die(GrResourceCache* cache, int k) { | 120 static void check_cache_contents_or_die(GrResourceCache* cache, int k) { |
121 // Benchmark find calls that succeed. | 121 // Benchmark find calls that succeed. |
122 { | 122 { |
123 GrTextureDesc desc; | 123 GrSurfaceDesc desc; |
124 get_texture_desc(k, &desc); | 124 get_texture_desc(k, &desc); |
125 GrResourceKey key = TextureResource::ComputeKey(desc); | 125 GrResourceKey key = TextureResource::ComputeKey(desc); |
126 GrGpuResource* item = cache->find(key); | 126 GrGpuResource* item = cache->find(key); |
127 if (NULL == item) { | 127 if (NULL == item) { |
128 SkFAIL("cache add does not work as expected"); | 128 SkFAIL("cache add does not work as expected"); |
129 return; | 129 return; |
130 } | 130 } |
131 if (static_cast<TextureResource*>(item)->fID != k) { | 131 if (static_cast<TextureResource*>(item)->fID != k) { |
132 SkFAIL("cache add does not work as expected"); | 132 SkFAIL("cache add does not work as expected"); |
133 return; | 133 return; |
134 } | 134 } |
135 } | 135 } |
136 { | 136 { |
137 int w, h, s; | 137 int w, h, s; |
138 get_stencil(k, &w, &h, &s); | 138 get_stencil(k, &w, &h, &s); |
139 GrResourceKey key = StencilResource::ComputeKey(w, h, s); | 139 GrResourceKey key = StencilResource::ComputeKey(w, h, s); |
140 GrGpuResource* item = cache->find(key); | 140 GrGpuResource* item = cache->find(key); |
141 if (NULL == item) { | 141 if (NULL == item) { |
142 SkFAIL("cache add does not work as expected"); | 142 SkFAIL("cache add does not work as expected"); |
143 return; | 143 return; |
144 } | 144 } |
145 if (static_cast<TextureResource*>(item)->fID != k) { | 145 if (static_cast<TextureResource*>(item)->fID != k) { |
146 SkFAIL("cache add does not work as expected"); | 146 SkFAIL("cache add does not work as expected"); |
147 return; | 147 return; |
148 } | 148 } |
149 } | 149 } |
150 | 150 |
151 // Benchmark also find calls that always fail. | 151 // Benchmark also find calls that always fail. |
152 { | 152 { |
153 GrTextureDesc desc; | 153 GrSurfaceDesc desc; |
154 get_texture_desc(k, &desc); | 154 get_texture_desc(k, &desc); |
155 desc.fHeight |= 1; | 155 desc.fHeight |= 1; |
156 GrResourceKey key = TextureResource::ComputeKey(desc); | 156 GrResourceKey key = TextureResource::ComputeKey(desc); |
157 GrGpuResource* item = cache->find(key); | 157 GrGpuResource* item = cache->find(key); |
158 if (item) { | 158 if (item) { |
159 SkFAIL("cache add does not work as expected"); | 159 SkFAIL("cache add does not work as expected"); |
160 return; | 160 return; |
161 } | 161 } |
162 } | 162 } |
163 { | 163 { |
(...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
239 } | 239 } |
240 | 240 |
241 private: | 241 private: |
242 typedef Benchmark INHERITED; | 242 typedef Benchmark INHERITED; |
243 }; | 243 }; |
244 | 244 |
245 DEF_BENCH( return new GrResourceCacheBenchAdd(); ) | 245 DEF_BENCH( return new GrResourceCacheBenchAdd(); ) |
246 DEF_BENCH( return new GrResourceCacheBenchFind(); ) | 246 DEF_BENCH( return new GrResourceCacheBenchFind(); ) |
247 | 247 |
248 #endif | 248 #endif |
OLD | NEW |