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 : fHorizontalVelocity(horizontalVelocity), | 27 : fHorizontalVelocity(horizontalVelocity), |
28 fVerticalVelocity(verticalVelocity) { | 28 fVerticalVelocity(verticalVelocity) { |
29 SkString resourcePath = GetResourcePath(imageFilename); | 29 SkString resourcePath = GetResourcePath(imageFilename); |
30 SkImageDecoder* codec = NULL; | 30 SkImageDecoder* codec = nullptr; |
31 SkFILEStream stream(resourcePath.c_str()); | 31 SkFILEStream stream(resourcePath.c_str()); |
32 if (stream.isValid()) { | 32 if (stream.isValid()) { |
33 codec = SkImageDecoder::Factory(&stream); | 33 codec = SkImageDecoder::Factory(&stream); |
34 } | 34 } |
35 if (codec) { | 35 if (codec) { |
36 stream.rewind(); | 36 stream.rewind(); |
37 codec->decode(&stream, &fBM, kN32_SkColorType, SkImageDecoder::kDecode
Pixels_Mode); | 37 codec->decode(&stream, &fBM, kN32_SkColorType, SkImageDecoder::kDecode
Pixels_Mode); |
38 delete codec; | 38 delete codec; |
39 } else { | 39 } else { |
40 fBM.allocN32Pixels(1, 1); | 40 fBM.allocN32Pixels(1, 1); |
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
102 for (size_t i = 0; i < SK_ARRAY_COUNT(gQualitys); ++i) { | 102 for (size_t i = 0; i < SK_ARRAY_COUNT(gQualitys); ++i) { |
103 paint.setFilterQuality(gQualitys[i]); | 103 paint.setFilterQuality(gQualitys[i]); |
104 canvas->drawBitmap( fBM, fCurPos.fX + i * (fBM.width() + 10), fCurPo
s.fY + 2*(fSize + 10) + fBM.height() + 10, &paint ); | 104 canvas->drawBitmap( fBM, fCurPos.fX + i * (fBM.width() + 10), fCurPo
s.fY + 2*(fSize + 10) + fBM.height() + 10, &paint ); |
105 } | 105 } |
106 | 106 |
107 canvas->drawText( "No Scale", strlen("No Scale"), fCurPos.fX + SK_ARRAY_
COUNT(gQualitys) * (fBM.width() + 10), fCurPos.fY + 2*(fSize + 10) + fBM.height(
) + 10 + fSize/2, paint ); | 107 canvas->drawText( "No Scale", strlen("No Scale"), fCurPos.fX + SK_ARRAY_
COUNT(gQualitys) * (fBM.width() + 10), fCurPos.fY + 2*(fSize + 10) + fBM.height(
) + 10 + fSize/2, paint ); |
108 | 108 |
109 | 109 |
110 fCurPos.fX += fHorizontalVelocity; | 110 fCurPos.fX += fHorizontalVelocity; |
111 fCurPos.fY += fVerticalVelocity; | 111 fCurPos.fY += fVerticalVelocity; |
112 this->inval(NULL); | 112 this->inval(nullptr); |
113 } | 113 } |
114 | 114 |
115 private: | 115 private: |
116 typedef SampleView INHERITED; | 116 typedef SampleView INHERITED; |
117 }; | 117 }; |
118 | 118 |
119 ////////////////////////////////////////////////////////////////////////////// | 119 ////////////////////////////////////////////////////////////////////////////// |
120 | 120 |
121 static SkView* MyFactory() { return new SubpixelTranslateView("mandrill_256.png"
, .05f, .05f); } | 121 static SkView* MyFactory() { return new SubpixelTranslateView("mandrill_256.png"
, .05f, .05f); } |
122 static SkViewRegister reg(MyFactory); | 122 static SkViewRegister reg(MyFactory); |
OLD | NEW |