Index: tests/SurfaceTest.cpp |
=================================================================== |
--- tests/SurfaceTest.cpp (revision 8437) |
+++ tests/SurfaceTest.cpp (working copy) |
@@ -5,18 +5,13 @@ |
* Use of this source code is governed by a BSD-style license that can be |
* found in the LICENSE file. |
*/ |
+ |
+#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
|
#include "SkCanvas.h" |
#include "SkRRect.h" |
#include "SkSurface.h" |
#include "Test.h" |
-#if SK_SUPPORT_GPU |
-#include "GrContextFactory.h" |
-#else |
-class GrContextFactory; |
-class GrContext; |
-#endif |
- |
enum SurfaceType { |
kRaster_SurfaceType, |
kGpu_SurfaceType, |
@@ -35,12 +30,8 @@ |
case kRaster_SurfaceType: |
return SkSurface::NewRaster(imageSpec); |
case kGpu_SurfaceType: |
-#if SK_SUPPORT_GPU |
SkASSERT(NULL != context); |
return SkSurface::NewRenderTarget(context, imageSpec); |
-#else |
- SkASSERT(0); |
-#endif |
case kPicture_SurfaceType: |
return SkSurface::NewPicture(10, 10); |
} |
@@ -133,18 +124,38 @@ |
testPaint)) |
} |
+static void TestSurfaceWritableAfterSnapshotRelease(skiatest::Reporter* reporter, |
+ SurfaceType surfaceType, |
+ GrContext* context) { |
+ // This test succeeds by not triggering an assertion. |
+ // The test verifies that the surface remains writable (usable) after |
+ // acquiring and releasing a snapshot without triggering a copy on write. |
+ SkSurface* surface = createSurface(surfaceType, context); |
+ SkAutoTUnref<SkSurface> aur_surface(surface); |
+ SkCanvas* canvas = surface->getCanvas(); |
+ canvas->clear(1); |
+ surface->newImageShapshot()->unref(); // Create and destroy SkImage |
+ canvas->clear(2); |
+} |
+ |
static void TestSurface(skiatest::Reporter* reporter) { |
bsalomon
2013/04/03 14:35:47
Do we need this function anymore?
|
TestSurfaceCopyOnWrite(reporter, kRaster_SurfaceType, NULL); |
TestSurfaceCopyOnWrite(reporter, kPicture_SurfaceType, NULL); |
+ TestSurfaceWritableAfterSnapshotRelease(reporter, kRaster_SurfaceType, NULL); |
+ TestSurfaceWritableAfterSnapshotRelease(reporter, kPicture_SurfaceType, NULL); |
} |
static void TestSurfaceGpu(skiatest::Reporter* reporter, GrContextFactory* factory) { |
-#if SK_SUPPORT_GPU |
- GrContext* context = factory->get(GrContextFactory::kNative_GLContextType); |
- TestSurfaceCopyOnWrite(reporter, kGpu_SurfaceType, context); |
-#endif |
+ TestSurfaceCopyOnWrite(reporter, kRaster_SurfaceType, NULL); |
+ TestSurfaceCopyOnWrite(reporter, kPicture_SurfaceType, NULL); |
+ TestSurfaceWritableAfterSnapshotRelease(reporter, kRaster_SurfaceType, NULL); |
+ TestSurfaceWritableAfterSnapshotRelease(reporter, kPicture_SurfaceType, NULL); |
+ if (NULL != factory) { |
+ GrContext* context = factory->get(GrContextFactory::kNative_GLContextType); |
+ TestSurfaceCopyOnWrite(reporter, kGpu_SurfaceType, context); |
+ TestSurfaceWritableAfterSnapshotRelease(reporter, kGpu_SurfaceType, context); |
+ } |
} |
#include "TestClassDef.h" |
-DEFINE_TESTCLASS("Surface", SurfaceTestClass, TestSurface) |
DEFINE_GPUTESTCLASS("SurfaceGpu", SurfaceGpuTestClass, TestSurfaceGpu) |