OLD | NEW |
1 /* | 1 /* |
2 * Copyright 2012 Google Inc. | 2 * Copyright 2012 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 "../src/image/SkImagePriv.h" | 8 #include "../src/image/SkImagePriv.h" |
9 #include "../src/image/SkSurface_Base.h" | 9 #include "../src/image/SkSurface_Base.h" |
10 #include "SkBitmap.h" | 10 #include "SkBitmap.h" |
(...skipping 821 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
832 SkPaint paint; | 832 SkPaint paint; |
833 // After spawning a compatible canvas: | 833 // After spawning a compatible canvas: |
834 // 1) Verify that secondary canvas is usable and does not report to the noti
fication client. | 834 // 1) Verify that secondary canvas is usable and does not report to the noti
fication client. |
835 surface->getCanvas()->drawRect(rect, paint); | 835 surface->getCanvas()->drawRect(rect, paint); |
836 REPORTER_ASSERT(reporter, notificationCounter.fStorageAllocatedChangedCount
== 0); | 836 REPORTER_ASSERT(reporter, notificationCounter.fStorageAllocatedChangedCount
== 0); |
837 // 2) Verify that original canvas is usable and still reports to the notific
ation client. | 837 // 2) Verify that original canvas is usable and still reports to the notific
ation client. |
838 canvas->drawRect(rect, paint); | 838 canvas->drawRect(rect, paint); |
839 REPORTER_ASSERT(reporter, notificationCounter.fStorageAllocatedChangedCount
== 1); | 839 REPORTER_ASSERT(reporter, notificationCounter.fStorageAllocatedChangedCount
== 1); |
840 } | 840 } |
841 | 841 |
| 842 static void TestDeferredCanvasGetCanvasSize(skiatest::Reporter* reporter) { |
| 843 SkRect rect; |
| 844 rect.setXYWH(SkIntToScalar(0), SkIntToScalar(0), SkIntToScalar(gWidth), SkIn
tToScalar(gHeight)); |
| 845 SkRect clip; |
| 846 clip.setXYWH(SkIntToScalar(0), SkIntToScalar(0), SkIntToScalar(1), SkIntToSc
alar(1)); |
| 847 |
| 848 SkPaint paint; |
| 849 SkISize size = SkISize::Make(gWidth, gHeight); |
| 850 |
| 851 SkAutoTUnref<SkSurface> surface(createSurface(0xFFFFFFFF)); |
| 852 SkAutoTUnref<SkDeferredCanvas> canvas(SkDeferredCanvas::Create(surface.get()
)); |
| 853 |
| 854 for (int i = 0; i < 2; ++i) { |
| 855 if (i == 1) { |
| 856 SkSurface* newSurface = SkSurface::NewRasterPMColor(4, 4); |
| 857 canvas->setSurface(newSurface); |
| 858 size = SkISize::Make(4, 4); |
| 859 } |
| 860 |
| 861 // verify that canvas size is correctly initialized or set |
| 862 REPORTER_ASSERT(reporter, size == canvas->getCanvasSize()); |
| 863 |
| 864 // Verify that clear, clip and draw the canvas will not change its size |
| 865 canvas->clear(0x00000000); |
| 866 canvas->clipRect(clip, SkRegion::kIntersect_Op, false); |
| 867 canvas->drawRect(rect, paint); |
| 868 REPORTER_ASSERT(reporter, size == canvas->getCanvasSize()); |
| 869 |
| 870 // Verify that flush the canvas will not change its size |
| 871 canvas->flush(); |
| 872 REPORTER_ASSERT(reporter, size == canvas->getCanvasSize()); |
| 873 |
| 874 // Verify that clear canvas with saved state will not change its size |
| 875 canvas->save(); |
| 876 canvas->clear(0xFFFFFFFF); |
| 877 REPORTER_ASSERT(reporter, size == canvas->getCanvasSize()); |
| 878 |
| 879 // Verify that restore canvas state will not change its size |
| 880 canvas->restore(); |
| 881 REPORTER_ASSERT(reporter, size == canvas->getCanvasSize()); |
| 882 |
| 883 // Verify that clear within a layer will not change canvas size |
| 884 canvas->saveLayer(&clip, &paint); |
| 885 canvas->clear(0x00000000); |
| 886 REPORTER_ASSERT(reporter, size == canvas->getCanvasSize()); |
| 887 |
| 888 // Verify that restore from a layer will not change canvas size |
| 889 canvas->restore(); |
| 890 REPORTER_ASSERT(reporter, size == canvas->getCanvasSize()); |
| 891 } |
| 892 } |
| 893 |
842 DEF_TEST(DeferredCanvas_CPU, reporter) { | 894 DEF_TEST(DeferredCanvas_CPU, reporter) { |
843 TestDeferredCanvasFlush(reporter); | 895 TestDeferredCanvasFlush(reporter); |
844 TestDeferredCanvasSilentFlush(reporter); | 896 TestDeferredCanvasSilentFlush(reporter); |
845 TestDeferredCanvasFreshFrame(reporter); | 897 TestDeferredCanvasFreshFrame(reporter); |
846 TestDeferredCanvasMemoryLimit(reporter); | 898 TestDeferredCanvasMemoryLimit(reporter); |
847 TestDeferredCanvasBitmapCaching(reporter); | 899 TestDeferredCanvasBitmapCaching(reporter); |
848 TestDeferredCanvasSkip(reporter); | 900 TestDeferredCanvasSkip(reporter); |
849 TestDeferredCanvasBitmapShaderNoLeak(reporter); | 901 TestDeferredCanvasBitmapShaderNoLeak(reporter); |
850 TestDeferredCanvasBitmapSizeThreshold(reporter); | 902 TestDeferredCanvasBitmapSizeThreshold(reporter); |
851 TestDeferredCanvasCreateCompatibleDevice(reporter); | 903 TestDeferredCanvasCreateCompatibleDevice(reporter); |
852 TestDeferredCanvasWritePixelsToSurface(reporter); | 904 TestDeferredCanvasWritePixelsToSurface(reporter); |
| 905 TestDeferredCanvasGetCanvasSize(reporter); |
853 TestDeferredCanvasSurface(reporter, NULL); | 906 TestDeferredCanvasSurface(reporter, NULL); |
854 TestDeferredCanvasSetSurface(reporter, NULL); | 907 TestDeferredCanvasSetSurface(reporter, NULL); |
855 } | 908 } |
856 | 909 |
857 DEF_GPUTEST(DeferredCanvas_GPU, reporter, factory) { | 910 DEF_GPUTEST(DeferredCanvas_GPU, reporter, factory) { |
858 if (factory != NULL) { | 911 if (factory != NULL) { |
859 TestDeferredCanvasSurface(reporter, factory); | 912 TestDeferredCanvasSurface(reporter, factory); |
860 TestDeferredCanvasSetSurface(reporter, factory); | 913 TestDeferredCanvasSetSurface(reporter, factory); |
861 } | 914 } |
862 } | 915 } |
OLD | NEW |