Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 1 | |
| 2 /* | |
| 3 * Copyright 2014 Google Inc. | |
| 4 * | |
| 5 * Use of this source code is governed by a BSD-style license that can be | |
| 6 * found in the LICENSE file. | |
| 7 */ | |
| 8 | |
| 9 #include "gm.h" | |
| 10 #include "SampleCode.h" | |
| 11 #include "SkBlurMaskFilter.h" | |
| 12 #include "SkColorPriv.h" | |
| 13 #include "SkCanvas.h" | |
| 14 #include "SkImageDecoder.h" | |
| 15 #include "SkRandom.h" | |
| 16 #include "SkStream.h" | |
| 17 | |
| 18 | |
|
robertphillips
2014/05/29 21:18:23
// comment - maybe include bug # ?
humper
2014/05/29 21:54:51
Done.
| |
| 19 class SubpixelTranslateView : public SampleView { | |
| 20 public: | |
|
robertphillips
2014/05/29 21:18:23
overlength ?
humper
2014/05/29 21:54:51
Done.
| |
| 21 SubpixelTranslateView(const char imageFilename[], float horizontalVelocity, float verticalVelocity) | |
| 22 : fFilename(imageFilename), | |
| 23 fHorizontalVelocity(horizontalVelocity), | |
| 24 fVerticalVelocity(verticalVelocity) { | |
| 25 SkString path(skiagm::GM::GetResourcePath()); | |
| 26 path.append("/"); | |
| 27 path.append(fFilename); | |
| 28 | |
| 29 SkImageDecoder *codec = NULL; | |
| 30 SkFILEStream stream(path.c_str()); | |
| 31 if (stream.isValid()) { | |
| 32 codec = SkImageDecoder::Factory(&stream); | |
| 33 } | |
| 34 if (codec) { | |
| 35 stream.rewind(); | |
| 36 codec->decode(&stream, &fBM, SkBitmap::kARGB_8888_Config, | |
| 37 SkImageDecoder::kDecodePixels_Mode); | |
| 38 SkDELETE(codec); | |
| 39 } else { | |
| 40 fBM.allocN32Pixels(1, 1); | |
| 41 *(fBM.getAddr32(0,0)) = 0xFF0000FF; // red == bad | |
| 42 } | |
| 43 fCurPos = SkPoint::Make(0,0); | |
| 44 fSize = 200; | |
| 45 } | |
| 46 | |
| 47 protected: | |
| 48 SkBitmap fBM; | |
| 49 SkString fFilename; | |
| 50 int fSize; | |
| 51 float fHorizontalVelocity, fVerticalVelocity; | |
| 52 | |
| 53 SkPoint fCurPos; | |
| 54 | |
| 55 // overrides from SkEventSink | |
|
robertphillips
2014/05/29 21:18:23
SK_OVERRIDE ?
humper
2014/05/29 21:54:51
Done.
| |
| 56 virtual bool onQuery(SkEvent* evt) { | |
| 57 if (SampleCode::TitleQ(*evt)) { | |
| 58 SampleCode::TitleR(evt, "SubpixelTranslate"); | |
| 59 return true; | |
| 60 } | |
| 61 return this->INHERITED::onQuery(evt); | |
| 62 } | |
| 63 | |
|
robertphillips
2014/05/29 21:18:23
SK_OVERRIDE ?
humper
2014/05/29 21:54:51
Done.
| |
| 64 virtual void onDrawContent(SkCanvas* canvas) { | |
| 65 | |
| 66 static const SkPaint::FilterLevel gLevels[] = { | |
| 67 SkPaint::kNone_FilterLevel, | |
| 68 SkPaint::kLow_FilterLevel, | |
| 69 SkPaint::kMedium_FilterLevel, | |
| 70 SkPaint::kHigh_FilterLevel | |
| 71 }; | |
| 72 | |
| 73 for (size_t i = 0; i < SK_ARRAY_COUNT(gLevels); ++i) { | |
| 74 | |
| 75 SkPaint paint; | |
| 76 paint.setFilterLevel(gLevels[i]); | |
| 77 | |
| 78 SkRect r = SkRect::MakeXYWH( fCurPos.fX + i * (fSize + 10), fCurPos. fY, fSize, fSize ); | |
| 79 | |
| 80 canvas->drawBitmapRect( fBM, r, &paint ); | |
| 81 } | |
| 82 | |
| 83 fCurPos.fX += fHorizontalVelocity; | |
| 84 fCurPos.fY += fVerticalVelocity; | |
| 85 this->inval(NULL); | |
| 86 } | |
| 87 | |
| 88 private: | |
|
robertphillips
2014/05/29 21:18:23
SampleView ?
humper
2014/05/29 21:54:51
Done.
| |
| 89 typedef SkView INHERITED; | |
| 90 }; | |
| 91 | |
| 92 ////////////////////////////////////////////////////////////////////////////// | |
| 93 | |
| 94 static SkView* MyFactory() { return new SubpixelTranslateView("mandrill_256.png" , .05, .05); } | |
| 95 static SkViewRegister reg(MyFactory); | |
| OLD | NEW |