aboutsummaryrefslogtreecommitdiffhomepage
path: root/gm
diff options
context:
space:
mode:
authorGravatar scroggo@google.com <scroggo@google.com@2bbb7eff-a529-9590-31e7-b0007b416f81>2012-11-29 21:05:37 +0000
committerGravatar scroggo@google.com <scroggo@google.com@2bbb7eff-a529-9590-31e7-b0007b416f81>2012-11-29 21:05:37 +0000
commit9f686f3639ff87e6d28b4ffcc42feebeca90f8d8 (patch)
treea68c3806894afa297b0fee3e63367b407ba3202d /gm
parent8a98e3bd18f1a8914cbfe1461e1ff47f51286556 (diff)
Create a factory to decode an SkBitmap from an SkData.
Add a test and a GM for the factory, and a PNG file for it to decode. The PNG file is copyright-free, obtained from http://openclipart.org/detail/29213/paper-plane-by-ddoo In cmykjpeg, do not attempt to decode in the constructor, since it currently crashes on Mac (if you provide the correct resource path). Even when we fix this crash there is no need to do it in the constructor, since we create all of the gms in order to get their names (to determine whether to run them). Review URL: https://codereview.appspot.com/6847122 git-svn-id: http://skia.googlecode.com/svn/trunk@6618 2bbb7eff-a529-9590-31e7-b0007b416f81
Diffstat (limited to 'gm')
-rw-r--r--gm/cmykjpeg.cpp6
-rw-r--r--gm/factory.cpp67
-rw-r--r--gm/resources/plane.pngbin0 -> 5718 bytes
3 files changed, 71 insertions, 2 deletions
diff --git a/gm/cmykjpeg.cpp b/gm/cmykjpeg.cpp
index 94cf98f92d..692bc3e760 100644
--- a/gm/cmykjpeg.cpp
+++ b/gm/cmykjpeg.cpp
@@ -17,7 +17,10 @@ namespace skiagm {
*/
class CMYKJpegGM : public GM {
public:
- CMYKJpegGM() {
+ CMYKJpegGM() {}
+
+protected:
+ virtual void onOnceBeforeDraw() SK_OVERRIDE {
// parameters to the "decode" call
bool dither = false;
@@ -41,7 +44,6 @@ public:
}
}
-protected:
virtual SkString onShortName() {
return SkString("cmykjpeg");
}
diff --git a/gm/factory.cpp b/gm/factory.cpp
new file mode 100644
index 0000000000..88931584d8
--- /dev/null
+++ b/gm/factory.cpp
@@ -0,0 +1,67 @@
+/*
+ * Copyright 2012 Google Inc.
+ *
+ * Use of this source code is governed by a BSD-style license that can be
+ * found in the LICENSE file.
+ */
+
+#include "gm.h"
+#include "SkBitmapFactory.h"
+#include "SkCanvas.h"
+#include "SkData.h"
+#include "SkStream.h"
+
+namespace skiagm {
+
+/**
+ * Draw a PNG created by SkBitmapFactory.
+ */
+class FactoryGM : public GM {
+public:
+ FactoryGM() {}
+
+protected:
+ virtual void onOnceBeforeDraw() SK_OVERRIDE {
+ SkString filename(INHERITED::gResourcePath);
+ if (!filename.endsWith("/") && !filename.endsWith("\\")) {
+ filename.append("/");
+ }
+
+ // Copyright-free file from http://openclipart.org/detail/29213/paper-plane-by-ddoo
+ filename.append("plane.png");
+
+ SkFILEStream stream(filename.c_str());
+ if (stream.isValid()) {
+ stream.rewind();
+ size_t length = stream.getLength();
+ void* buffer = sk_malloc_throw(length);
+ stream.read(buffer, length);
+ SkAutoDataUnref data(SkData::NewFromMalloc(buffer, length));
+ SkBitmapFactory::DecodeBitmap(&fBitmap, data);
+ }
+ }
+
+ virtual SkString onShortName() {
+ return SkString("factory");
+ }
+
+ virtual SkISize onISize() {
+ return make_isize(640, 480);
+ }
+
+ virtual void onDraw(SkCanvas* canvas) {
+ canvas->drawBitmap(fBitmap, 0, 0);
+ }
+
+private:
+ SkBitmap fBitmap;
+
+ typedef GM INHERITED;
+};
+
+//////////////////////////////////////////////////////////////////////////////
+
+static GM* MyFactory(void*) { return new FactoryGM; }
+static GMRegistry reg(MyFactory);
+
+}
diff --git a/gm/resources/plane.png b/gm/resources/plane.png
new file mode 100644
index 0000000000..03585b5cb4
--- /dev/null
+++ b/gm/resources/plane.png
Binary files differ