aboutsummaryrefslogtreecommitdiffhomepage
path: root/tests/SurfaceTest.cpp
diff options
context:
space:
mode:
authorGravatar reed <reed@google.com>2015-06-09 12:16:53 -0700
committerGravatar Commit bot <commit-bot@chromium.org>2015-06-09 12:16:53 -0700
commit41e010cb901c0da9066c4df562030808c9ccd7f8 (patch)
tree3bf17e946f9eadd43040ea6968adcfa5f2f882a4 /tests/SurfaceTest.cpp
parent1831f990c31bad0d84641663c96aa8eebf846ab9 (diff)
Revert[2] SkDraw and all Blitters to use pixmap instead of bitmapi
Diffstat (limited to 'tests/SurfaceTest.cpp')
-rw-r--r--tests/SurfaceTest.cpp60
1 files changed, 60 insertions, 0 deletions
diff --git a/tests/SurfaceTest.cpp b/tests/SurfaceTest.cpp
index a3ac216786..4803b68221 100644
--- a/tests/SurfaceTest.cpp
+++ b/tests/SurfaceTest.cpp
@@ -7,6 +7,7 @@
#include "SkCanvas.h"
#include "SkData.h"
+#include "SkDevice.h"
#include "SkImageEncoder.h"
#include "SkRRect.h"
#include "SkSurface.h"
@@ -350,6 +351,63 @@ static void test_canvaspeek(skiatest::Reporter* reporter,
}
}
+// For compatibility with clients that still call accessBitmap(), we need to ensure that we bump
+// the bitmap's genID when we draw to it, else they won't know it has new values. When they are
+// exclusively using surface/image, and we can hide accessBitmap from device, we can remove this
+// test.
+static void test_accessPixels(skiatest::Reporter* reporter, GrContextFactory* factory) {
+ static const struct {
+ SurfaceType fType;
+ bool fPeekShouldSucceed;
+ } gRec[] = {
+ { kRaster_SurfaceType, true },
+ { kRasterDirect_SurfaceType, true },
+#if SK_SUPPORT_GPU
+ { kGpu_SurfaceType, false },
+ { kGpuScratch_SurfaceType, false },
+#endif
+ };
+
+ int cnt;
+#if SK_SUPPORT_GPU
+ cnt = GrContextFactory::kGLContextTypeCnt;
+#else
+ cnt = 1;
+#endif
+
+ for (int i= 0; i < cnt; ++i) {
+ GrContext* context = NULL;
+#if SK_SUPPORT_GPU
+ GrContextFactory::GLContextType glCtxType = (GrContextFactory::GLContextType) i;
+ if (!GrContextFactory::IsRenderingGLContext(glCtxType)) {
+ continue;
+ }
+ context = factory->get(glCtxType);
+
+ if (NULL == context) {
+ continue;
+ }
+#endif
+ for (size_t j = 0; j < SK_ARRAY_COUNT(gRec); ++j) {
+ SkImageInfo info, requestInfo;
+
+ SkAutoTUnref<SkSurface> surface(createSurface(gRec[j].fType, context,
+ &requestInfo));
+ SkCanvas* canvas = surface->getCanvas();
+ canvas->clear(0);
+
+ SkBaseDevice* device = canvas->getDevice_just_for_deprecated_compatibility_testing();
+ SkBitmap bm = device->accessBitmap(false);
+ uint32_t genID0 = bm.getGenerationID();
+ // Now we draw something, which needs to "dirty" the genID (sorta like copy-on-write)
+ canvas->drawColor(SK_ColorBLUE);
+ // Now check that we get a different genID
+ uint32_t genID1 = bm.getGenerationID();
+ REPORTER_ASSERT(reporter, genID0 != genID1);
+ }
+ }
+}
+
static void TestSurfaceCopyOnWrite(skiatest::Reporter* reporter, SurfaceType surfaceType,
GrContext* context) {
// Verify that the right canvas commands trigger a copy on write
@@ -587,6 +645,8 @@ DEF_GPUTEST(Surface, reporter, factory) {
test_imagepeek(reporter, factory);
test_canvaspeek(reporter, factory);
+ test_accessPixels(reporter, factory);
+
#if SK_SUPPORT_GPU
TestGetTexture(reporter, kRaster_SurfaceType, NULL);
if (factory) {