aboutsummaryrefslogtreecommitdiffhomepage
path: root/gm/surface.cpp
diff options
context:
space:
mode:
authorGravatar reed <reed@google.com>2014-11-21 08:46:37 -0800
committerGravatar Commit bot <commit-bot@chromium.org>2014-11-21 08:46:38 -0800
commit4af267b11964d4a8acdb232ac46094c84d890e88 (patch)
treed2fe846e9bc530cd0090b74a4096851a7ed7b9ea /gm/surface.cpp
parent41d2c2e434d11e73f66c597913c29ea1fb3fa879 (diff)
add SkImage::newSurface
Diffstat (limited to 'gm/surface.cpp')
-rw-r--r--gm/surface.cpp52
1 files changed, 51 insertions, 1 deletions
diff --git a/gm/surface.cpp b/gm/surface.cpp
index dbcced2cbf..f84c5ab7e7 100644
--- a/gm/surface.cpp
+++ b/gm/surface.cpp
@@ -105,5 +105,55 @@ protected:
private:
typedef GM INHERITED;
};
-
DEF_GM( return new SurfacePropsGM )
+
+#ifdef SK_DEBUG
+static bool equal(const SkSurfaceProps& a, const SkSurfaceProps& b) {
+ return a.flags() == b.flags() && a.pixelGeometry() == b.pixelGeometry();
+}
+#endif
+
+class NewSurfaceGM : public skiagm::GM {
+public:
+ NewSurfaceGM() {}
+
+protected:
+ SkString onShortName() SK_OVERRIDE {
+ return SkString("surfacenew");
+ }
+
+ virtual SkISize onISize() SK_OVERRIDE {
+ return SkISize::Make(300, 140);
+ }
+
+ static void drawInto(SkCanvas* canvas) {
+ canvas->drawColor(SK_ColorRED);
+ }
+
+ virtual void onDraw(SkCanvas* canvas) SK_OVERRIDE {
+ SkImageInfo info = SkImageInfo::MakeN32Premul(100, 100);
+
+ SkAutoTUnref<SkSurface> surf(canvas->newSurface(info, NULL));
+ if (!surf.get()) {
+ surf.reset(SkSurface::NewRaster(info));
+ }
+ drawInto(surf->getCanvas());
+
+ SkAutoTUnref<SkImage> image(surf->newImageSnapshot());
+ canvas->drawImage(image, 10, 10, NULL);
+
+ SkAutoTUnref<SkSurface> surf2(image->newSurface(info, NULL));
+ drawInto(surf2->getCanvas());
+
+ // Assert that the props were communicated transitively through the first image
+ SkASSERT(equal(surf->props(), surf2->props()));
+
+ SkAutoTUnref<SkImage> image2(surf2->newImageSnapshot());
+ canvas->drawImage(image2, 10 + SkIntToScalar(image->width()) + 10, 10, NULL);
+ }
+
+private:
+ typedef GM INHERITED;
+};
+DEF_GM( return new NewSurfaceGM )
+