OLD | NEW |
---|---|
1 /* | 1 /* |
2 * Copyright 2013 Google Inc. | 2 * Copyright 2013 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 // Include here to ensure SK_SUPPORT_GPU is set correctly before it is examined. | 8 // Include here to ensure SK_SUPPORT_GPU is set correctly before it is examined. |
9 #include "SkTypes.h" | 9 #include "SkTypes.h" |
10 | 10 |
11 #if SK_SUPPORT_GPU | 11 #if SK_SUPPORT_GPU |
12 | 12 |
13 #include "GrContext.h" | 13 #include "GrContext.h" |
14 #include "GrContextFactory.h" | 14 #include "GrContextFactory.h" |
15 #include "gl/GrGLInterface.h" | |
15 #include "GrGpu.h" | 16 #include "GrGpu.h" |
16 #include "GrGpuResourceCacheAccess.h" | 17 #include "GrGpuResourceCacheAccess.h" |
17 #include "GrGpuResourcePriv.h" | 18 #include "GrGpuResourcePriv.h" |
18 #include "GrRenderTarget.h" | 19 #include "GrRenderTarget.h" |
19 #include "GrRenderTargetPriv.h" | 20 #include "GrRenderTargetPriv.h" |
20 #include "GrResourceCache.h" | 21 #include "GrResourceCache.h" |
22 #include "GrTest.h" | |
21 #include "SkCanvas.h" | 23 #include "SkCanvas.h" |
22 #include "SkGr.h" | 24 #include "SkGr.h" |
23 #include "SkMessageBus.h" | 25 #include "SkMessageBus.h" |
24 #include "SkSurface.h" | 26 #include "SkSurface.h" |
25 #include "Test.h" | 27 #include "Test.h" |
28 #include "../src/gpu/gl/GrGLDefines.h" | |
29 #include "../src/gpu/gl/GrGLUtil.h" | |
26 | 30 |
27 static const int gWidth = 640; | 31 static const int gWidth = 640; |
28 static const int gHeight = 480; | 32 static const int gHeight = 480; |
29 | 33 |
30 //////////////////////////////////////////////////////////////////////////////// | 34 //////////////////////////////////////////////////////////////////////////////// |
31 static void test_cache(skiatest::Reporter* reporter, GrContext* context, SkCanva s* canvas) { | 35 static void test_cache(skiatest::Reporter* reporter, GrContext* context, SkCanva s* canvas) { |
32 const SkIRect size = SkIRect::MakeWH(gWidth, gHeight); | 36 const SkIRect size = SkIRect::MakeWH(gWidth, gHeight); |
33 | 37 |
34 SkBitmap src; | 38 SkBitmap src; |
35 src.allocN32Pixels(size.width(), size.height()); | 39 src.allocN32Pixels(size.width(), size.height()); |
(...skipping 130 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
166 REPORTER_ASSERT(reporter, | 170 REPORTER_ASSERT(reporter, |
167 smallMSAART0 && smallMSAART1 && | 171 smallMSAART0 && smallMSAART1 && |
168 smallMSAART0->asRenderTarget() && | 172 smallMSAART0->asRenderTarget() && |
169 smallMSAART1->asRenderTarget() && | 173 smallMSAART1->asRenderTarget() && |
170 smallMSAART0->asRenderTarget()->renderTargetPriv().getSt encilAttachment() != | 174 smallMSAART0->asRenderTarget()->renderTargetPriv().getSt encilAttachment() != |
171 smallMSAART1->asRenderTarget()->renderTargetPriv().getSt encilAttachment()); | 175 smallMSAART1->asRenderTarget()->renderTargetPriv().getSt encilAttachment()); |
172 } | 176 } |
173 } | 177 } |
174 } | 178 } |
175 | 179 |
180 static void test_wrapped_resources(skiatest::Reporter* reporter, GrContext* cont ext) { | |
181 GrTestTarget tt; | |
182 context->getTestTarget(&tt); | |
183 | |
184 const GrGLInterface* gl = tt.glInterface(); | |
185 if (!gl) { | |
186 return; | |
187 } | |
188 | |
189 GrGLuint texIDs[2]; | |
190 static const int kW = 100; | |
191 static const int kH = 100; | |
192 GR_GL_CALL(gl, GenTextures(2, texIDs)); | |
193 GR_GL_CALL(gl, ActiveTexture(GR_GL_TEXTURE0)); | |
194 GR_GL_CALL(gl, PixelStorei(GR_GL_UNPACK_ALIGNMENT, 1)); | |
195 GR_GL_CALL(gl, BindTexture(GR_GL_TEXTURE_2D, texIDs[0])); | |
196 GR_GL_CALL(gl, TexImage2D(GR_GL_TEXTURE_2D, 0, GR_GL_RGBA, kW, kH, 0, GR_GL_ RGBA, | |
197 GR_GL_UNSIGNED_BYTE, NULL)); | |
198 GR_GL_CALL(gl, BindTexture(GR_GL_TEXTURE_2D, texIDs[1])); | |
199 GR_GL_CALL(gl, TexImage2D(GR_GL_TEXTURE_2D, 0, GR_GL_RGBA, kW, kH, 0, GR_GL_ RGBA, | |
200 GR_GL_UNSIGNED_BYTE, NULL)); | |
201 context->resetContext(); | |
202 | |
203 GrBackendTextureDesc desc; | |
204 desc.fConfig = kBGRA_8888_GrPixelConfig; | |
205 desc.fWidth = kW; | |
206 desc.fHeight = kH; | |
207 | |
208 desc.fTextureHandle = texIDs[0]; | |
209 SkAutoTUnref<GrTexture> borrowed(context->textureProvider()->wrapBackendText ure( | |
210 desc, kBorrow_GrWrapOwnership)); | |
211 | |
212 desc.fTextureHandle = texIDs[1]; | |
213 SkAutoTUnref<GrTexture> adopted(context->textureProvider()->wrapBackendTextu re( | |
214 desc, kAdopt_GrWrapOwnership)); | |
215 | |
216 REPORTER_ASSERT(reporter, SkToBool(borrowed) && SkToBool(adopted)); | |
217 if (!SkToBool(borrowed) || !SkToBool(adopted)) { | |
218 return; | |
219 } | |
220 | |
221 borrowed.reset(NULL); | |
222 adopted.reset(NULL); | |
223 | |
224 context->flush(); | |
225 | |
226 GrGLboolean borrowedIsAlive; | |
227 GrGLboolean adoptedIsAlive; | |
228 GR_GL_CALL_RET(gl, borrowedIsAlive, IsTexture(texIDs[0])); | |
229 GR_GL_CALL_RET(gl, adoptedIsAlive, IsTexture(texIDs[1])); | |
230 | |
231 REPORTER_ASSERT(reporter, borrowedIsAlive); | |
232 REPORTER_ASSERT(reporter, !adoptedIsAlive); | |
233 | |
234 context->resetContext(); | |
robertphillips
2015/06/18 14:18:49
Do we care about cleaning up borrowed?
bsalomon
2015/06/18 15:19:37
Done.
| |
235 } | |
236 | |
176 class TestResource : public GrGpuResource { | 237 class TestResource : public GrGpuResource { |
177 static const size_t kDefaultSize = 100; | 238 static const size_t kDefaultSize = 100; |
178 enum ScratchConstructor { kScratchConstructor }; | 239 enum ScratchConstructor { kScratchConstructor }; |
179 public: | 240 public: |
180 SK_DECLARE_INST_COUNT(TestResource); | 241 SK_DECLARE_INST_COUNT(TestResource); |
181 /** Property that distinctly categorizes the resource. | 242 /** Property that distinctly categorizes the resource. |
182 * For example, textures have width, height, ... */ | 243 * For example, textures have width, height, ... */ |
183 enum SimulatedProperty { kA_SimulatedProperty, kB_SimulatedProperty }; | 244 enum SimulatedProperty { kA_SimulatedProperty, kB_SimulatedProperty }; |
184 | 245 |
185 TestResource(GrGpu* gpu, size_t size, GrGpuResource::LifeCycle lifeCycle) | 246 TestResource(GrGpu* gpu, size_t size, GrGpuResource::LifeCycle lifeCycle) |
(...skipping 164 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
350 make_unique_key<0>(&uniqueKey, 0); | 411 make_unique_key<0>(&uniqueKey, 0); |
351 | 412 |
352 // Create a scratch, a unique, and a wrapped resource | 413 // Create a scratch, a unique, and a wrapped resource |
353 TestResource* scratch = | 414 TestResource* scratch = |
354 TestResource::CreateScratch(context->getGpu(), TestResource::kB_Simu latedProperty); | 415 TestResource::CreateScratch(context->getGpu(), TestResource::kB_Simu latedProperty); |
355 scratch->setSize(10); | 416 scratch->setSize(10); |
356 TestResource* unique = SkNEW_ARGS(TestResource, (context->getGpu())); | 417 TestResource* unique = SkNEW_ARGS(TestResource, (context->getGpu())); |
357 unique->setSize(11); | 418 unique->setSize(11); |
358 unique->resourcePriv().setUniqueKey(uniqueKey); | 419 unique->resourcePriv().setUniqueKey(uniqueKey); |
359 TestResource* wrapped = SkNEW_ARGS(TestResource, | 420 TestResource* wrapped = SkNEW_ARGS(TestResource, |
360 (context->getGpu(), GrGpuResource::kWrapp ed_LifeCycle)); | 421 (context->getGpu(), GrGpuResource::kBorro wed_LifeCycle)); |
361 wrapped->setSize(12); | 422 wrapped->setSize(12); |
362 TestResource* unbudgeted = SkNEW_ARGS(TestResource, | 423 TestResource* unbudgeted = SkNEW_ARGS(TestResource, |
363 (context->getGpu(), GrGpuResource::kUn cached_LifeCycle)); | 424 (context->getGpu(), GrGpuResource::kUn cached_LifeCycle)); |
364 unbudgeted->setSize(13); | 425 unbudgeted->setSize(13); |
365 | 426 |
366 // Make sure we can't add a unique key to the wrapped resource | 427 // Make sure we can't add a unique key to the wrapped resource |
367 GrUniqueKey uniqueKey2; | 428 GrUniqueKey uniqueKey2; |
368 make_unique_key<0>(&uniqueKey2, 1); | 429 make_unique_key<0>(&uniqueKey2, 1); |
369 wrapped->resourcePriv().setUniqueKey(uniqueKey2); | 430 wrapped->resourcePriv().setUniqueKey(uniqueKey2); |
370 REPORTER_ASSERT(reporter, NULL == cache->findAndRefUniqueResource(uniqueKey2 )); | 431 REPORTER_ASSERT(reporter, NULL == cache->findAndRefUniqueResource(uniqueKey2 )); |
(...skipping 17 matching lines...) Expand all Loading... | |
388 REPORTER_ASSERT(reporter, scratch->gpuMemorySize() + unique->gpuMemorySize() == | 449 REPORTER_ASSERT(reporter, scratch->gpuMemorySize() + unique->gpuMemorySize() == |
389 cache->getBudgetedResourceBytes()); | 450 cache->getBudgetedResourceBytes()); |
390 | 451 |
391 // Unreffing the wrapped resource should free it right away. | 452 // Unreffing the wrapped resource should free it right away. |
392 wrapped->unref(); | 453 wrapped->unref(); |
393 REPORTER_ASSERT(reporter, 3 == cache->getResourceCount()); | 454 REPORTER_ASSERT(reporter, 3 == cache->getResourceCount()); |
394 REPORTER_ASSERT(reporter, scratch->gpuMemorySize() + unique->gpuMemorySize() + | 455 REPORTER_ASSERT(reporter, scratch->gpuMemorySize() + unique->gpuMemorySize() + |
395 unbudgeted->gpuMemorySize() == cache->getResourceB ytes()); | 456 unbudgeted->gpuMemorySize() == cache->getResourceB ytes()); |
396 | 457 |
397 // Now try freeing the budgeted resources first | 458 // Now try freeing the budgeted resources first |
398 wrapped = SkNEW_ARGS(TestResource, (context->getGpu(), GrGpuResource::kWrapp ed_LifeCycle)); | 459 wrapped = SkNEW_ARGS(TestResource, (context->getGpu(), GrGpuResource::kBorro wed_LifeCycle)); |
399 scratch->setSize(12); | 460 scratch->setSize(12); |
400 unique->unref(); | 461 unique->unref(); |
401 cache->purgeAllUnlocked(); | 462 cache->purgeAllUnlocked(); |
402 REPORTER_ASSERT(reporter, 3 == cache->getResourceCount()); | 463 REPORTER_ASSERT(reporter, 3 == cache->getResourceCount()); |
403 REPORTER_ASSERT(reporter, scratch->gpuMemorySize() + wrapped->gpuMemorySize( ) + | 464 REPORTER_ASSERT(reporter, scratch->gpuMemorySize() + wrapped->gpuMemorySize( ) + |
404 unbudgeted->gpuMemorySize() == cache->getResourceB ytes()); | 465 unbudgeted->gpuMemorySize() == cache->getResourceB ytes()); |
405 REPORTER_ASSERT(reporter, 1 == cache->getBudgetedResourceCount()); | 466 REPORTER_ASSERT(reporter, 1 == cache->getBudgetedResourceCount()); |
406 REPORTER_ASSERT(reporter, scratch->gpuMemorySize() == cache->getBudgetedReso urceBytes()); | 467 REPORTER_ASSERT(reporter, scratch->gpuMemorySize() == cache->getBudgetedReso urceBytes()); |
407 | 468 |
408 scratch->unref(); | 469 scratch->unref(); |
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
465 REPORTER_ASSERT(reporter, 2 == cache->getBudgetedResourceCount()); | 526 REPORTER_ASSERT(reporter, 2 == cache->getBudgetedResourceCount()); |
466 REPORTER_ASSERT(reporter, 21 == cache->getBudgetedResourceBytes()); | 527 REPORTER_ASSERT(reporter, 21 == cache->getBudgetedResourceBytes()); |
467 | 528 |
468 unbudgeted->unref(); | 529 unbudgeted->unref(); |
469 REPORTER_ASSERT(reporter, 2 == cache->getResourceCount()); | 530 REPORTER_ASSERT(reporter, 2 == cache->getResourceCount()); |
470 REPORTER_ASSERT(reporter, 21 == cache->getResourceBytes()); | 531 REPORTER_ASSERT(reporter, 21 == cache->getResourceBytes()); |
471 REPORTER_ASSERT(reporter, 2 == cache->getBudgetedResourceCount()); | 532 REPORTER_ASSERT(reporter, 2 == cache->getBudgetedResourceCount()); |
472 REPORTER_ASSERT(reporter, 21 == cache->getBudgetedResourceBytes()); | 533 REPORTER_ASSERT(reporter, 21 == cache->getBudgetedResourceBytes()); |
473 | 534 |
474 wrapped = SkNEW_ARGS(TestResource, | 535 wrapped = SkNEW_ARGS(TestResource, |
475 (context->getGpu(), large, GrGpuResource::kWrapped_Life Cycle)); | 536 (context->getGpu(), large, GrGpuResource::kBorrowed_Lif eCycle)); |
476 REPORTER_ASSERT(reporter, 3 == cache->getResourceCount()); | 537 REPORTER_ASSERT(reporter, 3 == cache->getResourceCount()); |
477 REPORTER_ASSERT(reporter, 21 + large == cache->getResourceBytes()); | 538 REPORTER_ASSERT(reporter, 21 + large == cache->getResourceBytes()); |
478 REPORTER_ASSERT(reporter, 2 == cache->getBudgetedResourceCount()); | 539 REPORTER_ASSERT(reporter, 2 == cache->getBudgetedResourceCount()); |
479 REPORTER_ASSERT(reporter, 21 == cache->getBudgetedResourceBytes()); | 540 REPORTER_ASSERT(reporter, 21 == cache->getBudgetedResourceBytes()); |
480 | 541 |
481 wrapped->unref(); | 542 wrapped->unref(); |
482 REPORTER_ASSERT(reporter, 2 == cache->getResourceCount()); | 543 REPORTER_ASSERT(reporter, 2 == cache->getResourceCount()); |
483 REPORTER_ASSERT(reporter, 21 == cache->getResourceBytes()); | 544 REPORTER_ASSERT(reporter, 21 == cache->getResourceBytes()); |
484 REPORTER_ASSERT(reporter, 2 == cache->getBudgetedResourceCount()); | 545 REPORTER_ASSERT(reporter, 2 == cache->getBudgetedResourceCount()); |
485 REPORTER_ASSERT(reporter, 21 == cache->getBudgetedResourceBytes()); | 546 REPORTER_ASSERT(reporter, 21 == cache->getBudgetedResourceBytes()); |
(...skipping 700 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1186 GrSurfaceDesc desc; | 1247 GrSurfaceDesc desc; |
1187 desc.fConfig = kSkia8888_GrPixelConfig; | 1248 desc.fConfig = kSkia8888_GrPixelConfig; |
1188 desc.fFlags = kRenderTarget_GrSurfaceFlag; | 1249 desc.fFlags = kRenderTarget_GrSurfaceFlag; |
1189 desc.fWidth = gWidth; | 1250 desc.fWidth = gWidth; |
1190 desc.fHeight = gHeight; | 1251 desc.fHeight = gHeight; |
1191 SkImageInfo info = SkImageInfo::MakeN32Premul(gWidth, gHeight); | 1252 SkImageInfo info = SkImageInfo::MakeN32Premul(gWidth, gHeight); |
1192 SkAutoTUnref<SkSurface> surface(SkSurface::NewRenderTarget(context, | 1253 SkAutoTUnref<SkSurface> surface(SkSurface::NewRenderTarget(context, |
1193 SkSurface::kN o_Budgeted, info)); | 1254 SkSurface::kN o_Budgeted, info)); |
1194 test_cache(reporter, context, surface->getCanvas()); | 1255 test_cache(reporter, context, surface->getCanvas()); |
1195 test_stencil_buffers(reporter, context); | 1256 test_stencil_buffers(reporter, context); |
1257 test_wrapped_resources(reporter, context); | |
1196 } | 1258 } |
1197 | 1259 |
1198 // The below tests create their own mock contexts. | 1260 // The below tests create their own mock contexts. |
1199 test_no_key(reporter); | 1261 test_no_key(reporter); |
1200 test_budgeting(reporter); | 1262 test_budgeting(reporter); |
1201 test_unbudgeted(reporter); | 1263 test_unbudgeted(reporter); |
1202 test_unbudgeted_to_scratch(reporter); | 1264 test_unbudgeted_to_scratch(reporter); |
1203 test_duplicate_unique_key(reporter); | 1265 test_duplicate_unique_key(reporter); |
1204 test_duplicate_scratch_key(reporter); | 1266 test_duplicate_scratch_key(reporter); |
1205 test_remove_scratch_key(reporter); | 1267 test_remove_scratch_key(reporter); |
1206 test_scratch_key_consistency(reporter); | 1268 test_scratch_key_consistency(reporter); |
1207 test_purge_invalidated(reporter); | 1269 test_purge_invalidated(reporter); |
1208 test_cache_chained_purge(reporter); | 1270 test_cache_chained_purge(reporter); |
1209 test_resource_size_changed(reporter); | 1271 test_resource_size_changed(reporter); |
1210 test_timestamp_wrap(reporter); | 1272 test_timestamp_wrap(reporter); |
1211 test_flush(reporter); | 1273 test_flush(reporter); |
1212 test_large_resource_count(reporter); | 1274 test_large_resource_count(reporter); |
1213 } | 1275 } |
1214 | 1276 |
1215 #endif | 1277 #endif |
OLD | NEW |