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 "SkCanvas.h" | 8 #include "SkCanvas.h" |
9 #include "SkData.h" | 9 #include "SkData.h" |
10 #include "SkDecodingImageGenerator.h" | 10 #include "SkDecodingImageGenerator.h" |
(...skipping 303 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
314 // The test verifies that the surface remains writable (usable) after | 314 // The test verifies that the surface remains writable (usable) after |
315 // acquiring and releasing a snapshot without triggering a copy on write. | 315 // acquiring and releasing a snapshot without triggering a copy on write. |
316 SkAutoTUnref<SkSurface> surface(createSurface(surfaceType, context)); | 316 SkAutoTUnref<SkSurface> surface(createSurface(surfaceType, context)); |
317 SkCanvas* canvas = surface->getCanvas(); | 317 SkCanvas* canvas = surface->getCanvas(); |
318 canvas->clear(1); | 318 canvas->clear(1); |
319 surface->newImageSnapshot()->unref(); // Create and destroy SkImage | 319 surface->newImageSnapshot()->unref(); // Create and destroy SkImage |
320 canvas->clear(2); // Must not assert internally | 320 canvas->clear(2); // Must not assert internally |
321 } | 321 } |
322 | 322 |
323 #if SK_SUPPORT_GPU | 323 #if SK_SUPPORT_GPU |
324 static void TestSurfaceInCache(skiatest::Reporter* reporter, | |
325 SurfaceType surfaceType, | |
326 GrContext* context) { | |
327 context->freeGpuResources(); | |
328 int resourceCount; | |
329 | |
330 context->getResourceCacheUsage(&resourceCount, NULL); | |
331 REPORTER_ASSERT(reporter, 0 == resourceCount); | |
332 SkAutoTUnref<SkSurface> surface(createSurface(surfaceType, context)); | |
333 // Note: the stencil buffer is always cached, so kGpu_SurfaceType uses | |
334 // one cached resource, and kGpuScratch_SurfaceType uses two. | |
335 int expectedCachedResources = surfaceType == kGpuScratch_SurfaceType ? 2 : 1
; | |
336 context->getResourceCacheUsage(&resourceCount, NULL); | |
337 REPORTER_ASSERT(reporter, expectedCachedResources == resourceCount); | |
338 | |
339 // Verify that all the cached resources are locked in cache. | |
340 context->freeGpuResources(); | |
341 context->getResourceCacheUsage(&resourceCount, NULL); | |
342 REPORTER_ASSERT(reporter, expectedCachedResources == resourceCount); | |
343 | |
344 // Verify that all the cached resources are unlocked upon surface release | |
345 surface.reset(0); | |
346 context->freeGpuResources(); | |
347 context->getResourceCacheUsage(&resourceCount, NULL); | |
348 REPORTER_ASSERT(reporter, 0 == resourceCount); | |
349 } | |
350 | |
351 static void Test_crbug263329(skiatest::Reporter* reporter, | 324 static void Test_crbug263329(skiatest::Reporter* reporter, |
352 SurfaceType surfaceType, | 325 SurfaceType surfaceType, |
353 GrContext* context) { | 326 GrContext* context) { |
354 // This is a regression test for crbug.com/263329 | 327 // This is a regression test for crbug.com/263329 |
355 // Bug was caused by onCopyOnWrite releasing the old surface texture | 328 // Bug was caused by onCopyOnWrite releasing the old surface texture |
356 // back to the scratch texture pool even though the texture is used | 329 // back to the scratch texture pool even though the texture is used |
357 // by and active SkImage_Gpu. | 330 // by and active SkImage_Gpu. |
358 SkAutoTUnref<SkSurface> surface1(createSurface(surfaceType, context)); | 331 SkAutoTUnref<SkSurface> surface1(createSurface(surfaceType, context)); |
359 SkAutoTUnref<SkSurface> surface2(createSurface(surfaceType, context)); | 332 SkAutoTUnref<SkSurface> surface2(createSurface(surfaceType, context)); |
360 SkCanvas* canvas1 = surface1->getCanvas(); | 333 SkCanvas* canvas1 = surface1->getCanvas(); |
(...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
446 #if SK_SUPPORT_GPU | 419 #if SK_SUPPORT_GPU |
447 TestGetTexture(reporter, kRaster_SurfaceType, NULL); | 420 TestGetTexture(reporter, kRaster_SurfaceType, NULL); |
448 if (factory) { | 421 if (factory) { |
449 for (int i= 0; i < GrContextFactory::kGLContextTypeCnt; ++i) { | 422 for (int i= 0; i < GrContextFactory::kGLContextTypeCnt; ++i) { |
450 GrContextFactory::GLContextType glCtxType = (GrContextFactory::GLCon
textType) i; | 423 GrContextFactory::GLContextType glCtxType = (GrContextFactory::GLCon
textType) i; |
451 if (!GrContextFactory::IsRenderingGLContext(glCtxType)) { | 424 if (!GrContextFactory::IsRenderingGLContext(glCtxType)) { |
452 continue; | 425 continue; |
453 } | 426 } |
454 GrContext* context = factory->get(glCtxType); | 427 GrContext* context = factory->get(glCtxType); |
455 if (context) { | 428 if (context) { |
456 TestSurfaceInCache(reporter, kGpu_SurfaceType, context); | |
457 TestSurfaceInCache(reporter, kGpuScratch_SurfaceType, context); | |
458 Test_crbug263329(reporter, kGpu_SurfaceType, context); | 429 Test_crbug263329(reporter, kGpu_SurfaceType, context); |
459 Test_crbug263329(reporter, kGpuScratch_SurfaceType, context); | 430 Test_crbug263329(reporter, kGpuScratch_SurfaceType, context); |
460 TestSurfaceCopyOnWrite(reporter, kGpu_SurfaceType, context); | 431 TestSurfaceCopyOnWrite(reporter, kGpu_SurfaceType, context); |
461 TestSurfaceCopyOnWrite(reporter, kGpuScratch_SurfaceType, contex
t); | 432 TestSurfaceCopyOnWrite(reporter, kGpuScratch_SurfaceType, contex
t); |
462 TestSurfaceWritableAfterSnapshotRelease(reporter, kGpu_SurfaceTy
pe, context); | 433 TestSurfaceWritableAfterSnapshotRelease(reporter, kGpu_SurfaceTy
pe, context); |
463 TestSurfaceWritableAfterSnapshotRelease(reporter, kGpuScratch_Su
rfaceType, context); | 434 TestSurfaceWritableAfterSnapshotRelease(reporter, kGpuScratch_Su
rfaceType, context); |
464 TestSurfaceNoCanvas(reporter, kGpu_SurfaceType, context, SkSurfa
ce::kDiscard_ContentChangeMode); | 435 TestSurfaceNoCanvas(reporter, kGpu_SurfaceType, context, SkSurfa
ce::kDiscard_ContentChangeMode); |
465 TestSurfaceNoCanvas(reporter, kGpuScratch_SurfaceType, context,
SkSurface::kDiscard_ContentChangeMode); | 436 TestSurfaceNoCanvas(reporter, kGpuScratch_SurfaceType, context,
SkSurface::kDiscard_ContentChangeMode); |
466 TestSurfaceNoCanvas(reporter, kGpu_SurfaceType, context, SkSurfa
ce::kRetain_ContentChangeMode); | 437 TestSurfaceNoCanvas(reporter, kGpu_SurfaceType, context, SkSurfa
ce::kRetain_ContentChangeMode); |
467 TestSurfaceNoCanvas(reporter, kGpuScratch_SurfaceType, context,
SkSurface::kRetain_ContentChangeMode); | 438 TestSurfaceNoCanvas(reporter, kGpuScratch_SurfaceType, context,
SkSurface::kRetain_ContentChangeMode); |
468 TestGetTexture(reporter, kGpu_SurfaceType, context); | 439 TestGetTexture(reporter, kGpu_SurfaceType, context); |
469 TestGetTexture(reporter, kGpuScratch_SurfaceType, context); | 440 TestGetTexture(reporter, kGpuScratch_SurfaceType, context); |
470 } | 441 } |
471 } | 442 } |
472 } | 443 } |
473 #endif | 444 #endif |
474 } | 445 } |
OLD | NEW |