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

Unified Diff: gm/surface.cpp

Issue 741763002: add SkImage::newSurface (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: another warning fix Created 6 years, 1 month 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
« no previous file with comments | « no previous file | include/core/SkImage.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: gm/surface.cpp
diff --git a/gm/surface.cpp b/gm/surface.cpp
index dbcced2cbfabf4d4282fd64c85d270279cbaf383..f84c5ab7e722134344b1857c9b793d2c2b3621a8 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 )
+
« no previous file with comments | « no previous file | include/core/SkImage.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698