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 #include "SkCanvas.h" | 8 #include "SkCanvas.h" |
9 #include "SkRRect.h" | 9 #include "SkRRect.h" |
10 #include "SkSurface.h" | 10 #include "SkSurface.h" |
(...skipping 17 matching lines...) Expand all Loading... |
28 10, // width | 28 10, // width |
29 10, // height | 29 10, // height |
30 SkImage::kPMColor_ColorType, | 30 SkImage::kPMColor_ColorType, |
31 SkImage::kPremul_AlphaType | 31 SkImage::kPremul_AlphaType |
32 }; | 32 }; |
33 | 33 |
34 switch (surfaceType) { | 34 switch (surfaceType) { |
35 case kRaster_SurfaceType: | 35 case kRaster_SurfaceType: |
36 return SkSurface::NewRaster(imageSpec); | 36 return SkSurface::NewRaster(imageSpec); |
37 case kGpu_SurfaceType: | 37 case kGpu_SurfaceType: |
38 #if SK_SUPPORT_GPU | |
39 SkASSERT(NULL != context); | 38 SkASSERT(NULL != context); |
40 return SkSurface::NewRenderTarget(context, imageSpec); | 39 return SkSurface::NewRenderTarget(context, imageSpec); |
41 #else | |
42 SkASSERT(0); | |
43 #endif | |
44 case kPicture_SurfaceType: | 40 case kPicture_SurfaceType: |
45 return SkSurface::NewPicture(10, 10); | 41 return SkSurface::NewPicture(10, 10); |
46 } | 42 } |
47 SkASSERT(0); | 43 SkASSERT(0); |
48 return NULL; | 44 return NULL; |
49 } | 45 } |
50 | 46 |
51 static void TestSurfaceCopyOnWrite(skiatest::Reporter* reporter, SurfaceType sur
faceType, | 47 static void TestSurfaceCopyOnWrite(skiatest::Reporter* reporter, SurfaceType sur
faceType, |
52 GrContext* context) { | 48 GrContext* context) { |
53 // Verify that the right canvas commands trigger a copy on write | 49 // Verify that the right canvas commands trigger a copy on write |
(...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
126 EXPECT_COPY_ON_WRITE(drawBitmapMatrix(testBitmap, testMatrix, NULL)) | 122 EXPECT_COPY_ON_WRITE(drawBitmapMatrix(testBitmap, testMatrix, NULL)) |
127 EXPECT_COPY_ON_WRITE(drawBitmapNine(testBitmap, testIRect, testRect, NULL)) | 123 EXPECT_COPY_ON_WRITE(drawBitmapNine(testBitmap, testIRect, testRect, NULL)) |
128 EXPECT_COPY_ON_WRITE(drawSprite(testBitmap, 0, 0, NULL)) | 124 EXPECT_COPY_ON_WRITE(drawSprite(testBitmap, 0, 0, NULL)) |
129 EXPECT_COPY_ON_WRITE(drawText(testText.c_str(), testText.size(), 0, 1, testP
aint)) | 125 EXPECT_COPY_ON_WRITE(drawText(testText.c_str(), testText.size(), 0, 1, testP
aint)) |
130 EXPECT_COPY_ON_WRITE(drawPosText(testText.c_str(), testText.size(), testPoin
ts2, \ | 126 EXPECT_COPY_ON_WRITE(drawPosText(testText.c_str(), testText.size(), testPoin
ts2, \ |
131 testPaint)) | 127 testPaint)) |
132 EXPECT_COPY_ON_WRITE(drawTextOnPath(testText.c_str(), testText.size(), testP
ath, NULL, \ | 128 EXPECT_COPY_ON_WRITE(drawTextOnPath(testText.c_str(), testText.size(), testP
ath, NULL, \ |
133 testPaint)) | 129 testPaint)) |
134 } | 130 } |
135 | 131 |
136 static void TestSurface(skiatest::Reporter* reporter) { | 132 static void TestSurfaceWritableAfterSnapshotRelease(skiatest::Reporter* reporter
, |
| 133 SurfaceType surfaceType, |
| 134 GrContext* context) { |
| 135 // This test succeeds by not triggering an assertion. |
| 136 // The test verifies that the surface remains writable (usable) after |
| 137 // acquiring and releasing a snapshot without triggering a copy on write. |
| 138 SkSurface* surface = createSurface(surfaceType, context); |
| 139 SkAutoTUnref<SkSurface> aur_surface(surface); |
| 140 SkCanvas* canvas = surface->getCanvas(); |
| 141 canvas->clear(1); |
| 142 surface->newImageShapshot()->unref(); // Create and destroy SkImage |
| 143 canvas->clear(2); |
| 144 } |
| 145 |
| 146 static void TestSurface(skiatest::Reporter* reporter, GrContextFactory* factory)
{ |
137 TestSurfaceCopyOnWrite(reporter, kRaster_SurfaceType, NULL); | 147 TestSurfaceCopyOnWrite(reporter, kRaster_SurfaceType, NULL); |
138 TestSurfaceCopyOnWrite(reporter, kPicture_SurfaceType, NULL); | 148 TestSurfaceCopyOnWrite(reporter, kPicture_SurfaceType, NULL); |
139 } | 149 TestSurfaceWritableAfterSnapshotRelease(reporter, kRaster_SurfaceType, NULL)
; |
140 | 150 TestSurfaceWritableAfterSnapshotRelease(reporter, kPicture_SurfaceType, NULL
); |
141 static void TestSurfaceGpu(skiatest::Reporter* reporter, GrContextFactory* facto
ry) { | |
142 #if SK_SUPPORT_GPU | 151 #if SK_SUPPORT_GPU |
143 GrContext* context = factory->get(GrContextFactory::kNative_GLContextType); | 152 if (NULL != factory) { |
144 TestSurfaceCopyOnWrite(reporter, kGpu_SurfaceType, context); | 153 GrContext* context = factory->get(GrContextFactory::kNative_GLContextTyp
e); |
| 154 TestSurfaceCopyOnWrite(reporter, kGpu_SurfaceType, context); |
| 155 TestSurfaceWritableAfterSnapshotRelease(reporter, kGpu_SurfaceType, cont
ext); |
| 156 } |
145 #endif | 157 #endif |
146 } | 158 } |
147 | 159 |
148 #include "TestClassDef.h" | 160 #include "TestClassDef.h" |
149 DEFINE_TESTCLASS("Surface", SurfaceTestClass, TestSurface) | 161 DEFINE_GPUTESTCLASS("Surface", SurfaceTestClass, TestSurface) |
150 DEFINE_GPUTESTCLASS("SurfaceGpu", SurfaceGpuTestClass, TestSurfaceGpu) | |
OLD | NEW |