aboutsummaryrefslogtreecommitdiffhomepage
path: root/gm/tinybitmap.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'gm/tinybitmap.cpp')
-rw-r--r--gm/tinybitmap.cpp61
1 files changed, 61 insertions, 0 deletions
diff --git a/gm/tinybitmap.cpp b/gm/tinybitmap.cpp
new file mode 100644
index 0000000000..d309970b27
--- /dev/null
+++ b/gm/tinybitmap.cpp
@@ -0,0 +1,61 @@
+#include "gm.h"
+#include "SkColorPriv.h"
+#include "SkShader.h"
+#include "SkCanvas.h"
+#include "SkUtils.h"
+
+namespace skiagm {
+
+static SkBitmap make_bitmap() {
+ SkBitmap bm;
+
+ SkColorTable* ctable = new SkColorTable(1);
+ SkPMColor* c = ctable->lockColors();
+ c[0] = SkPackARGB32(0x80, 0x80, 0, 0);
+ ctable->unlockColors(true);
+
+ bm.setConfig(SkBitmap::kIndex8_Config, 1, 1);
+ bm.allocPixels(ctable);
+ ctable->unref();
+
+ bm.lockPixels();
+ *bm.getAddr8(0, 0) = 0;
+ bm.unlockPixels();
+ return bm;
+}
+
+class TinyBitmapGM : public GM {
+ SkBitmap fBM;
+public:
+ TinyBitmapGM() {
+ fBM = make_bitmap();
+ }
+
+protected:
+ SkString onShortName() {
+ return SkString("tinybitmap");
+ }
+
+ virtual SkISize onISize() { return make_isize(100, 100); }
+
+ virtual void onDraw(SkCanvas* canvas) {
+ canvas->drawColor(0xFFDDDDDD);
+ SkShader* s =
+ SkShader::CreateBitmapShader(fBM, SkShader::kRepeat_TileMode,
+ SkShader::kMirror_TileMode);
+ SkPaint paint;
+ paint.setAlpha(0x80);
+ paint.setShader(s)->unref();
+ canvas->drawPaint(paint);
+ }
+
+private:
+ typedef GM INHERITED;
+};
+
+//////////////////////////////////////////////////////////////////////////////
+
+static GM* MyFactory(void*) { return new TinyBitmapGM; }
+static GMRegistry reg(MyFactory);
+
+}