Chromium Code Reviews| 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 | |
| 9 #include "GrContextFactory.h" | |
|
Justin Novosad
2013/04/03 14:31:26
This is OK, even when SK_SUPPORT_GPU == 0, right?
bsalomon
2013/04/03 14:35:47
Actually, no, the #include needs to be guarded. We
| |
| 8 #include "SkCanvas.h" | 10 #include "SkCanvas.h" |
| 9 #include "SkRRect.h" | 11 #include "SkRRect.h" |
| 10 #include "SkSurface.h" | 12 #include "SkSurface.h" |
| 11 #include "Test.h" | 13 #include "Test.h" |
| 12 | 14 |
| 13 #if SK_SUPPORT_GPU | |
| 14 #include "GrContextFactory.h" | |
| 15 #else | |
| 16 class GrContextFactory; | |
| 17 class GrContext; | |
| 18 #endif | |
| 19 | |
| 20 enum SurfaceType { | 15 enum SurfaceType { |
| 21 kRaster_SurfaceType, | 16 kRaster_SurfaceType, |
| 22 kGpu_SurfaceType, | 17 kGpu_SurfaceType, |
| 23 kPicture_SurfaceType | 18 kPicture_SurfaceType |
| 24 }; | 19 }; |
| 25 | 20 |
| 26 static SkSurface* createSurface(SurfaceType surfaceType, GrContext* context) { | 21 static SkSurface* createSurface(SurfaceType surfaceType, GrContext* context) { |
| 27 static const SkImage::Info imageSpec = { | 22 static const SkImage::Info imageSpec = { |
| 28 10, // width | 23 10, // width |
| 29 10, // height | 24 10, // height |
| 30 SkImage::kPMColor_ColorType, | 25 SkImage::kPMColor_ColorType, |
| 31 SkImage::kPremul_AlphaType | 26 SkImage::kPremul_AlphaType |
| 32 }; | 27 }; |
| 33 | 28 |
| 34 switch (surfaceType) { | 29 switch (surfaceType) { |
| 35 case kRaster_SurfaceType: | 30 case kRaster_SurfaceType: |
| 36 return SkSurface::NewRaster(imageSpec); | 31 return SkSurface::NewRaster(imageSpec); |
| 37 case kGpu_SurfaceType: | 32 case kGpu_SurfaceType: |
| 38 #if SK_SUPPORT_GPU | |
| 39 SkASSERT(NULL != context); | 33 SkASSERT(NULL != context); |
| 40 return SkSurface::NewRenderTarget(context, imageSpec); | 34 return SkSurface::NewRenderTarget(context, imageSpec); |
| 41 #else | |
| 42 SkASSERT(0); | |
| 43 #endif | |
| 44 case kPicture_SurfaceType: | 35 case kPicture_SurfaceType: |
| 45 return SkSurface::NewPicture(10, 10); | 36 return SkSurface::NewPicture(10, 10); |
| 46 } | 37 } |
| 47 SkASSERT(0); | 38 SkASSERT(0); |
| 48 return NULL; | 39 return NULL; |
| 49 } | 40 } |
| 50 | 41 |
| 51 static void TestSurfaceCopyOnWrite(skiatest::Reporter* reporter, SurfaceType sur faceType, | 42 static void TestSurfaceCopyOnWrite(skiatest::Reporter* reporter, SurfaceType sur faceType, |
| 52 GrContext* context) { | 43 GrContext* context) { |
| 53 // Verify that the right canvas commands trigger a copy on write | 44 // 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)) | 117 EXPECT_COPY_ON_WRITE(drawBitmapMatrix(testBitmap, testMatrix, NULL)) |
| 127 EXPECT_COPY_ON_WRITE(drawBitmapNine(testBitmap, testIRect, testRect, NULL)) | 118 EXPECT_COPY_ON_WRITE(drawBitmapNine(testBitmap, testIRect, testRect, NULL)) |
| 128 EXPECT_COPY_ON_WRITE(drawSprite(testBitmap, 0, 0, NULL)) | 119 EXPECT_COPY_ON_WRITE(drawSprite(testBitmap, 0, 0, NULL)) |
| 129 EXPECT_COPY_ON_WRITE(drawText(testText.c_str(), testText.size(), 0, 1, testP aint)) | 120 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, \ | 121 EXPECT_COPY_ON_WRITE(drawPosText(testText.c_str(), testText.size(), testPoin ts2, \ |
| 131 testPaint)) | 122 testPaint)) |
| 132 EXPECT_COPY_ON_WRITE(drawTextOnPath(testText.c_str(), testText.size(), testP ath, NULL, \ | 123 EXPECT_COPY_ON_WRITE(drawTextOnPath(testText.c_str(), testText.size(), testP ath, NULL, \ |
| 133 testPaint)) | 124 testPaint)) |
| 134 } | 125 } |
| 135 | 126 |
| 127 static void TestSurfaceWritableAfterSnapshotRelease(skiatest::Reporter* reporter , | |
| 128 SurfaceType surfaceType, | |
| 129 GrContext* context) { | |
| 130 // This test succeeds by not triggering an assertion. | |
| 131 // The test verifies that the surface remains writable (usable) after | |
| 132 // acquiring and releasing a snapshot without triggering a copy on write. | |
| 133 SkSurface* surface = createSurface(surfaceType, context); | |
| 134 SkAutoTUnref<SkSurface> aur_surface(surface); | |
| 135 SkCanvas* canvas = surface->getCanvas(); | |
| 136 canvas->clear(1); | |
| 137 surface->newImageShapshot()->unref(); // Create and destroy SkImage | |
| 138 canvas->clear(2); | |
| 139 } | |
| 140 | |
| 136 static void TestSurface(skiatest::Reporter* reporter) { | 141 static void TestSurface(skiatest::Reporter* reporter) { |
|
bsalomon
2013/04/03 14:35:47
Do we need this function anymore?
| |
| 137 TestSurfaceCopyOnWrite(reporter, kRaster_SurfaceType, NULL); | 142 TestSurfaceCopyOnWrite(reporter, kRaster_SurfaceType, NULL); |
| 138 TestSurfaceCopyOnWrite(reporter, kPicture_SurfaceType, NULL); | 143 TestSurfaceCopyOnWrite(reporter, kPicture_SurfaceType, NULL); |
| 144 TestSurfaceWritableAfterSnapshotRelease(reporter, kRaster_SurfaceType, NULL) ; | |
| 145 TestSurfaceWritableAfterSnapshotRelease(reporter, kPicture_SurfaceType, NULL ); | |
| 139 } | 146 } |
| 140 | 147 |
| 141 static void TestSurfaceGpu(skiatest::Reporter* reporter, GrContextFactory* facto ry) { | 148 static void TestSurfaceGpu(skiatest::Reporter* reporter, GrContextFactory* facto ry) { |
| 142 #if SK_SUPPORT_GPU | 149 TestSurfaceCopyOnWrite(reporter, kRaster_SurfaceType, NULL); |
| 143 GrContext* context = factory->get(GrContextFactory::kNative_GLContextType); | 150 TestSurfaceCopyOnWrite(reporter, kPicture_SurfaceType, NULL); |
| 144 TestSurfaceCopyOnWrite(reporter, kGpu_SurfaceType, context); | 151 TestSurfaceWritableAfterSnapshotRelease(reporter, kRaster_SurfaceType, NULL) ; |
| 145 #endif | 152 TestSurfaceWritableAfterSnapshotRelease(reporter, kPicture_SurfaceType, NULL ); |
| 153 if (NULL != factory) { | |
| 154 GrContext* context = factory->get(GrContextFactory::kNative_GLContextTyp e); | |
| 155 TestSurfaceCopyOnWrite(reporter, kGpu_SurfaceType, context); | |
| 156 TestSurfaceWritableAfterSnapshotRelease(reporter, kGpu_SurfaceType, cont ext); | |
| 157 } | |
| 146 } | 158 } |
| 147 | 159 |
| 148 #include "TestClassDef.h" | 160 #include "TestClassDef.h" |
| 149 DEFINE_TESTCLASS("Surface", SurfaceTestClass, TestSurface) | |
| 150 DEFINE_GPUTESTCLASS("SurfaceGpu", SurfaceGpuTestClass, TestSurfaceGpu) | 161 DEFINE_GPUTESTCLASS("SurfaceGpu", SurfaceGpuTestClass, TestSurfaceGpu) |
| OLD | NEW |