Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(673)

Unified Diff: tests/SpecialSurfaceTest.cpp

Issue 1579323002: Add SkSpecialImage & SkSpecialSurface classes (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: Address code review comments Created 4 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« src/core/SkSpecialImage.h ('K') | « tests/SpecialImageTest.cpp ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: tests/SpecialSurfaceTest.cpp
diff --git a/tests/SpecialSurfaceTest.cpp b/tests/SpecialSurfaceTest.cpp
new file mode 100644
index 0000000000000000000000000000000000000000..131003af9bc09c7d2ed2e594a28df6881dc0141b
--- /dev/null
+++ b/tests/SpecialSurfaceTest.cpp
@@ -0,0 +1,88 @@
+/*
+* Copyright 2016 Google Inc.
+*
+* Use of this source code is governed by a BSD-style license that can be
+* found in the LICENSE file
+*/
+
+#include "SkCanvas.h"
+#include "SkSpecialImage.h"
+#include "SkSpecialSurface.h"
+#include "Test.h"
+
+#if SK_SUPPORT_GPU
+#include "GrContext.h"
+#include "SkGr.h"
+#endif
+
+// Both 'kSmallerSize' and 'kFullSize' need to be a non-power-of-2 to exercise
+// the gpu's loose fit behavior
+static const int kSmallerSize = 10;
+static const int kPad = 5;
+static const int kFullSize = kSmallerSize + 2 * kPad;
+
+// Exercise the public API of SkSpecialSurface (e.g., getCanvas, newImageSnapshot)
+static void test_surface(SkSpecialSurface* surf, skiatest::Reporter* reporter, int offset) {
+
+ REPORTER_ASSERT(reporter, offset == surf->activeRect().fLeft);
+ REPORTER_ASSERT(reporter, offset == surf->activeRect().fTop);
+ REPORTER_ASSERT(reporter, kSmallerSize == surf->activeRect().width());
+ REPORTER_ASSERT(reporter, kSmallerSize == surf->activeRect().height());
+
+ SkCanvas* canvas = surf->getCanvas();
+ SK_ALWAYSBREAK(canvas);
+
+ canvas->clear(SK_ColorRED);
+
+ SkAutoTUnref<SkSpecialImage> img(surf->newImageSnapshot());
+ REPORTER_ASSERT(reporter, img);
+
+ REPORTER_ASSERT(reporter, surf->activeRect() == img->activeRect());
+
+ // the canvas was invalidated by the newImageSnapshot call
+ REPORTER_ASSERT(reporter, !surf->getCanvas());
+}
+
+DEF_TEST(SpecialSurface_Raster, reporter) {
+
+ SkImageInfo info = SkImageInfo::MakeN32(kSmallerSize, kSmallerSize, kOpaque_SkAlphaType);
+ SkAutoTUnref<SkSpecialSurface> surf(SkSpecialSurface::NewRaster(info));
+
+ test_surface(surf, reporter, 0);
+}
+
+#if SK_SUPPORT_GPU
+
+DEF_GPUTEST_FOR_RENDERING_CONTEXTS(SpecialSurface_Gpu1, reporter, context) {
+ GrSurfaceDesc desc;
+ desc.fConfig = kSkia8888_GrPixelConfig;
+ desc.fFlags = kRenderTarget_GrSurfaceFlag;
+ desc.fWidth = kSmallerSize;
+ desc.fHeight = kSmallerSize;
+
+ SkAutoTUnref<SkSpecialSurface> surf(SkSpecialSurface::NewGpu(context, desc));
+
+ test_surface(surf, reporter, 0);
+}
+
+// test the more flexible factory
+DEF_GPUTEST_FOR_RENDERING_CONTEXTS(SpecialSurface_Gpu2, reporter, context) {
+ GrSurfaceDesc desc;
+ desc.fConfig = kSkia8888_GrPixelConfig;
+ desc.fFlags = kRenderTarget_GrSurfaceFlag;
+ desc.fWidth = kFullSize;
+ desc.fHeight = kFullSize;
+
+ SkAutoTUnref<GrTexture> temp(context->textureProvider()->createApproxTexture(desc));
+ SK_ALWAYSBREAK(temp);
+
+ const SkIRect activeRect = SkIRect::MakeXYWH(kPad, kPad, kSmallerSize, kSmallerSize);
+
+ SkAutoTUnref<SkSpecialSurface> surf(SkSpecialSurface::NewGpu(activeRect, temp));
+
+ test_surface(surf, reporter, kPad);
+
+ // TODO: check that the clear didn't escape the active region
+}
+
+#endif
« src/core/SkSpecialImage.h ('K') | « tests/SpecialImageTest.cpp ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698