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

Side by Side Diff: tests/SurfaceTest.cpp

Issue 1276713002: SkSurface copy-on-write can yield stale GPU render targets. (Closed) Base URL: https://chromium.googlesource.com/skia.git@master
Patch Set: comment type Created 5 years, 4 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 | « src/image/SkSurface_Gpu.cpp ('k') | no next file » | 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 * 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 "SkDevice.h" 10 #include "SkDevice.h"
(...skipping 603 matching lines...) Expand 10 before | Expand all | Expand 10 after
614 SkAutoTUnref<SkImage> image(surface->newImageSnapshot()); 614 SkAutoTUnref<SkImage> image(surface->newImageSnapshot());
615 REPORTER_ASSERT(reporter, image); 615 REPORTER_ASSERT(reporter, image);
616 if (image) { 616 if (image) {
617 REPORTER_ASSERT(reporter, image->isOpaque() == SkToBool(opaq ue)); 617 REPORTER_ASSERT(reporter, image->isOpaque() == SkToBool(opaq ue));
618 } 618 }
619 } 619 }
620 } 620 }
621 } 621 }
622 } 622 }
623 623
624 static void test_backend_cow(skiatest::Reporter* reporter, SkSurface* surface,
625 SkSurface::BackendHandleAccess mode,
626 GrBackendObject (*func)(SkSurface*, SkSurface::Back endHandleAccess)) {
627 GrBackendObject obj1 = func(surface, mode);
628 SkAutoTUnref<SkImage> snap1(surface->newImageSnapshot());
629
630 GrBackendObject obj2 = func(surface, mode);
631 SkAutoTUnref<SkImage> snap2(surface->newImageSnapshot());
632
633 // If the access mode triggers CoW, then the backend objects should reflect it.
634 REPORTER_ASSERT(reporter, (obj1 == obj2) == (snap1 == snap2));
635 }
636
624 static void TestSurfaceCopyOnWrite(skiatest::Reporter* reporter, SurfaceType sur faceType, 637 static void TestSurfaceCopyOnWrite(skiatest::Reporter* reporter, SurfaceType sur faceType,
625 GrContext* context) { 638 GrContext* context) {
626 // Verify that the right canvas commands trigger a copy on write 639 // Verify that the right canvas commands trigger a copy on write
627 SkSurface* surface = create_surface(surfaceType, context); 640 SkSurface* surface = create_surface(surfaceType, context);
628 SkAutoTUnref<SkSurface> aur_surface(surface); 641 SkAutoTUnref<SkSurface> aur_surface(surface);
629 SkCanvas* canvas = surface->getCanvas(); 642 SkCanvas* canvas = surface->getCanvas();
630 643
631 const SkRect testRect = 644 const SkRect testRect =
632 SkRect::MakeXYWH(SkIntToScalar(0), SkIntToScalar(0), 645 SkRect::MakeXYWH(SkIntToScalar(0), SkIntToScalar(0),
633 SkIntToScalar(4), SkIntToScalar(5)); 646 SkIntToScalar(4), SkIntToScalar(5));
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after
692 EXPECT_COPY_ON_WRITE(drawPath(testPath, testPaint)) 705 EXPECT_COPY_ON_WRITE(drawPath(testPath, testPaint))
693 EXPECT_COPY_ON_WRITE(drawBitmap(testBitmap, 0, 0)) 706 EXPECT_COPY_ON_WRITE(drawBitmap(testBitmap, 0, 0))
694 EXPECT_COPY_ON_WRITE(drawBitmapRect(testBitmap, testRect)) 707 EXPECT_COPY_ON_WRITE(drawBitmapRect(testBitmap, testRect))
695 EXPECT_COPY_ON_WRITE(drawBitmapNine(testBitmap, testIRect, testRect, NULL)) 708 EXPECT_COPY_ON_WRITE(drawBitmapNine(testBitmap, testIRect, testRect, NULL))
696 EXPECT_COPY_ON_WRITE(drawSprite(testBitmap, 0, 0, NULL)) 709 EXPECT_COPY_ON_WRITE(drawSprite(testBitmap, 0, 0, NULL))
697 EXPECT_COPY_ON_WRITE(drawText(testText.c_str(), testText.size(), 0, 1, testP aint)) 710 EXPECT_COPY_ON_WRITE(drawText(testText.c_str(), testText.size(), 0, 1, testP aint))
698 EXPECT_COPY_ON_WRITE(drawPosText(testText.c_str(), testText.size(), testPoin ts2, \ 711 EXPECT_COPY_ON_WRITE(drawPosText(testText.c_str(), testText.size(), testPoin ts2, \
699 testPaint)) 712 testPaint))
700 EXPECT_COPY_ON_WRITE(drawTextOnPath(testText.c_str(), testText.size(), testP ath, NULL, \ 713 EXPECT_COPY_ON_WRITE(drawTextOnPath(testText.c_str(), testText.size(), testP ath, NULL, \
701 testPaint)) 714 testPaint))
715
716 const SkSurface::BackendHandleAccess accessModes[] = {
717 SkSurface::kFlushRead_BackendHandleAccess,
718 SkSurface::kFlushWrite_BackendHandleAccess,
719 SkSurface::kDiscardWrite_BackendHandleAccess,
720 };
721
722 for (auto access : accessModes) {
723 test_backend_cow(reporter, surface, access,
724 [](SkSurface* s, SkSurface::BackendHandleAccess a) -> GrBackendObject {
725 return s->getTextureHandle(a);
726 });
727
728 test_backend_cow(reporter, surface, access,
729 [](SkSurface* s, SkSurface::BackendHandleAccess a) -> GrBackendObject {
730 GrBackendObject result;
731 if (!s->getRenderTargetHandle(&result, a)) {
732 return 0;
733 }
734 return result;
735 });
736 }
702 } 737 }
703 738
704 static void TestSurfaceWritableAfterSnapshotRelease(skiatest::Reporter* reporter , 739 static void TestSurfaceWritableAfterSnapshotRelease(skiatest::Reporter* reporter ,
705 SurfaceType surfaceType, 740 SurfaceType surfaceType,
706 GrContext* context) { 741 GrContext* context) {
707 // This test succeeds by not triggering an assertion. 742 // This test succeeds by not triggering an assertion.
708 // The test verifies that the surface remains writable (usable) after 743 // The test verifies that the surface remains writable (usable) after
709 // acquiring and releasing a snapshot without triggering a copy on write. 744 // acquiring and releasing a snapshot without triggering a copy on write.
710 SkAutoTUnref<SkSurface> surface(create_surface(surfaceType, context)); 745 SkAutoTUnref<SkSurface> surface(create_surface(surfaceType, context));
711 SkCanvas* canvas = surface->getCanvas(); 746 SkCanvas* canvas = surface->getCanvas();
(...skipping 274 matching lines...) Expand 10 before | Expand all | Expand 10 after
986 test_image_color(reporter, refImg, expected1); 1021 test_image_color(reporter, refImg, expected1);
987 #endif 1022 #endif
988 test_image_color(reporter, cpyImg, expected0); 1023 test_image_color(reporter, cpyImg, expected0);
989 1024
990 // Now exercise the release proc 1025 // Now exercise the release proc
991 REPORTER_ASSERT(reporter, !releaseCtx.fIsReleased); 1026 REPORTER_ASSERT(reporter, !releaseCtx.fIsReleased);
992 refImg.reset(NULL); // force a release of the image 1027 refImg.reset(NULL); // force a release of the image
993 REPORTER_ASSERT(reporter, releaseCtx.fIsReleased); 1028 REPORTER_ASSERT(reporter, releaseCtx.fIsReleased);
994 } 1029 }
995 #endif 1030 #endif
OLDNEW
« no previous file with comments | « src/image/SkSurface_Gpu.cpp ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698