Index: samplecode/SampleSubpixelTranslate.cpp |
diff --git a/samplecode/SampleSubpixelTranslate.cpp b/samplecode/SampleSubpixelTranslate.cpp |
new file mode 100644 |
index 0000000000000000000000000000000000000000..1644214b615748b4fdfa595c6897fac8db480b2b |
--- /dev/null |
+++ b/samplecode/SampleSubpixelTranslate.cpp |
@@ -0,0 +1,95 @@ |
+ |
+/* |
+ * Copyright 2014 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 "SampleCode.h" |
+#include "SkBlurMaskFilter.h" |
+#include "SkColorPriv.h" |
+#include "SkCanvas.h" |
+#include "SkImageDecoder.h" |
+#include "SkRandom.h" |
+#include "SkStream.h" |
+ |
+ |
robertphillips
2014/05/29 21:18:23
// comment - maybe include bug # ?
humper
2014/05/29 21:54:51
Done.
|
+class SubpixelTranslateView : public SampleView { |
+public: |
robertphillips
2014/05/29 21:18:23
overlength ?
humper
2014/05/29 21:54:51
Done.
|
+ SubpixelTranslateView(const char imageFilename[], float horizontalVelocity, float verticalVelocity) |
+ : fFilename(imageFilename), |
+ fHorizontalVelocity(horizontalVelocity), |
+ fVerticalVelocity(verticalVelocity) { |
+ SkString path(skiagm::GM::GetResourcePath()); |
+ path.append("/"); |
+ path.append(fFilename); |
+ |
+ SkImageDecoder *codec = NULL; |
+ SkFILEStream stream(path.c_str()); |
+ if (stream.isValid()) { |
+ codec = SkImageDecoder::Factory(&stream); |
+ } |
+ if (codec) { |
+ stream.rewind(); |
+ codec->decode(&stream, &fBM, SkBitmap::kARGB_8888_Config, |
+ SkImageDecoder::kDecodePixels_Mode); |
+ SkDELETE(codec); |
+ } else { |
+ fBM.allocN32Pixels(1, 1); |
+ *(fBM.getAddr32(0,0)) = 0xFF0000FF; // red == bad |
+ } |
+ fCurPos = SkPoint::Make(0,0); |
+ fSize = 200; |
+ } |
+ |
+protected: |
+ SkBitmap fBM; |
+ SkString fFilename; |
+ int fSize; |
+ float fHorizontalVelocity, fVerticalVelocity; |
+ |
+ SkPoint fCurPos; |
+ |
+ // overrides from SkEventSink |
robertphillips
2014/05/29 21:18:23
SK_OVERRIDE ?
humper
2014/05/29 21:54:51
Done.
|
+ virtual bool onQuery(SkEvent* evt) { |
+ if (SampleCode::TitleQ(*evt)) { |
+ SampleCode::TitleR(evt, "SubpixelTranslate"); |
+ return true; |
+ } |
+ return this->INHERITED::onQuery(evt); |
+ } |
+ |
robertphillips
2014/05/29 21:18:23
SK_OVERRIDE ?
humper
2014/05/29 21:54:51
Done.
|
+ virtual void onDrawContent(SkCanvas* canvas) { |
+ |
+ static const SkPaint::FilterLevel gLevels[] = { |
+ SkPaint::kNone_FilterLevel, |
+ SkPaint::kLow_FilterLevel, |
+ SkPaint::kMedium_FilterLevel, |
+ SkPaint::kHigh_FilterLevel |
+ }; |
+ |
+ for (size_t i = 0; i < SK_ARRAY_COUNT(gLevels); ++i) { |
+ |
+ SkPaint paint; |
+ paint.setFilterLevel(gLevels[i]); |
+ |
+ SkRect r = SkRect::MakeXYWH( fCurPos.fX + i * (fSize + 10), fCurPos.fY, fSize, fSize ); |
+ |
+ canvas->drawBitmapRect( fBM, r, &paint ); |
+ } |
+ |
+ fCurPos.fX += fHorizontalVelocity; |
+ fCurPos.fY += fVerticalVelocity; |
+ this->inval(NULL); |
+ } |
+ |
+private: |
robertphillips
2014/05/29 21:18:23
SampleView ?
humper
2014/05/29 21:54:51
Done.
|
+ typedef SkView INHERITED; |
+}; |
+ |
+////////////////////////////////////////////////////////////////////////////// |
+ |
+static SkView* MyFactory() { return new SubpixelTranslateView("mandrill_256.png", .05, .05); } |
+static SkViewRegister reg(MyFactory); |