OLD | NEW |
1 /* | 1 /* |
2 * Copyright 2014 Google Inc. | 2 * Copyright 2014 Google Inc. |
3 * | 3 * |
4 * Use of this source code is governed by a BSD-style license that can be | 4 * Use of this source code is governed by a BSD-style license that can be |
5 * found in the LICENSE file. | 5 * found in the LICENSE file. |
6 */ | 6 */ |
7 | 7 |
8 #include "gm.h" | 8 #include "gm.h" |
9 | 9 |
10 #include "Resources.h" | 10 #include "Resources.h" |
11 #include "SampleCode.h" | 11 #include "SampleCode.h" |
12 #include "SkBlurMaskFilter.h" | 12 #include "SkBlurMaskFilter.h" |
13 #include "SkCanvas.h" | 13 #include "SkCanvas.h" |
14 #include "SkColorPriv.h" | 14 #include "SkColorPriv.h" |
15 #include "SkImageDecoder.h" | 15 #include "SkImageDecoder.h" |
16 #include "SkRandom.h" | 16 #include "SkRandom.h" |
17 #include "SkStream.h" | 17 #include "SkStream.h" |
18 | 18 |
19 // Intended to exercise pixel snapping observed with scaled images (and | 19 // Intended to exercise pixel snapping observed with scaled images (and |
20 // with non-scaled images, but for a different reason): Bug 1145 | 20 // with non-scaled images, but for a different reason): Bug 1145 |
21 | 21 |
22 class SubpixelTranslateView : public SampleView { | 22 class SubpixelTranslateView : public SampleView { |
23 public: | 23 public: |
24 SubpixelTranslateView(const char imageFilename[], | 24 SubpixelTranslateView(const char imageFilename[], |
25 float horizontalVelocity, | 25 float horizontalVelocity, |
26 float verticalVelocity) | 26 float verticalVelocity) |
27 : fFilename(imageFilename), | 27 : fHorizontalVelocity(horizontalVelocity), |
28 fHorizontalVelocity(horizontalVelocity), | |
29 fVerticalVelocity(verticalVelocity) { | 28 fVerticalVelocity(verticalVelocity) { |
30 SkString resourcePath = GetResourcePath(); | 29 SkString resourcePath = GetResourcePath(imageFilename); |
31 resourcePath.append("/"); | |
32 resourcePath.append(fFilename); | |
33 | |
34 SkImageDecoder* codec = NULL; | 30 SkImageDecoder* codec = NULL; |
35 SkFILEStream stream(resourcePath.c_str()); | 31 SkFILEStream stream(resourcePath.c_str()); |
36 if (stream.isValid()) { | 32 if (stream.isValid()) { |
37 codec = SkImageDecoder::Factory(&stream); | 33 codec = SkImageDecoder::Factory(&stream); |
38 } | 34 } |
39 if (codec) { | 35 if (codec) { |
40 stream.rewind(); | 36 stream.rewind(); |
41 codec->decode(&stream, &fBM, kN32_SkColorType, SkImageDecoder::kDecode
Pixels_Mode); | 37 codec->decode(&stream, &fBM, kN32_SkColorType, SkImageDecoder::kDecode
Pixels_Mode); |
42 SkDELETE(codec); | 38 SkDELETE(codec); |
43 } else { | 39 } else { |
44 fBM.allocN32Pixels(1, 1); | 40 fBM.allocN32Pixels(1, 1); |
45 *(fBM.getAddr32(0,0)) = 0xFF0000FF; // red == bad | 41 *(fBM.getAddr32(0,0)) = 0xFF0000FF; // red == bad |
46 } | 42 } |
47 fCurPos = SkPoint::Make(0,0); | 43 fCurPos = SkPoint::Make(0,0); |
48 fSize = 200; | 44 fSize = 200; |
49 } | 45 } |
50 | 46 |
51 protected: | 47 protected: |
52 SkBitmap fBM; | 48 SkBitmap fBM; |
53 SkString fFilename; | |
54 SkScalar fSize; | 49 SkScalar fSize; |
55 float fHorizontalVelocity, fVerticalVelocity; | 50 float fHorizontalVelocity, fVerticalVelocity; |
56 | 51 |
57 SkPoint fCurPos; | 52 SkPoint fCurPos; |
58 | 53 |
59 // overrides from SkEventSink | 54 // overrides from SkEventSink |
60 virtual bool onQuery(SkEvent* evt) SK_OVERRIDE { | 55 virtual bool onQuery(SkEvent* evt) SK_OVERRIDE { |
61 if (SampleCode::TitleQ(*evt)) { | 56 if (SampleCode::TitleQ(*evt)) { |
62 SampleCode::TitleR(evt, "SubpixelTranslate"); | 57 SampleCode::TitleR(evt, "SubpixelTranslate"); |
63 return true; | 58 return true; |
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
117 } | 112 } |
118 | 113 |
119 private: | 114 private: |
120 typedef SampleView INHERITED; | 115 typedef SampleView INHERITED; |
121 }; | 116 }; |
122 | 117 |
123 ////////////////////////////////////////////////////////////////////////////// | 118 ////////////////////////////////////////////////////////////////////////////// |
124 | 119 |
125 static SkView* MyFactory() { return new SubpixelTranslateView("mandrill_256.png"
, .05f, .05f); } | 120 static SkView* MyFactory() { return new SubpixelTranslateView("mandrill_256.png"
, .05f, .05f); } |
126 static SkViewRegister reg(MyFactory); | 121 static SkViewRegister reg(MyFactory); |
OLD | NEW |