OLD | NEW |
1 /* | 1 /* |
2 * Copyright 2015 Google Inc. | 2 * Copyright 2015 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 #include "SkGradientShader.h" | 9 #include "SkGradientShader.h" |
10 #include "SkImage.h" | 10 #include "SkImage.h" |
(...skipping 28 matching lines...) Expand all Loading... |
39 | 39 |
40 SkISize onISize() override { | 40 SkISize onISize() override { |
41 return SkISize::Make(kCellSize*kNumCols, kCellSize*kNumRows); | 41 return SkISize::Make(kCellSize*kNumCols, kCellSize*kNumRows); |
42 } | 42 } |
43 | 43 |
44 void onOnceBeforeDraw() override { | 44 void onOnceBeforeDraw() override { |
45 fBitmap = sk_tool_utils::create_checkerboard_bitmap(kCellSize, kCellSize
, | 45 fBitmap = sk_tool_utils::create_checkerboard_bitmap(kCellSize, kCellSize
, |
46 SK_ColorBLUE, SK_Col
orYELLOW, | 46 SK_ColorBLUE, SK_Col
orYELLOW, |
47 kCellSize/10); | 47 kCellSize/10); |
48 | 48 |
49 fBitmapShader = SkShader::MakeBitmapShader(fBitmap, SkShader::kClamp_Til
eMode, | 49 fBitmapShader.reset(SkShader::CreateBitmapShader(fBitmap, |
50 SkShader::kClamp_TileMode); | 50 SkShader::kClamp_TileMo
de, |
| 51 SkShader::kClamp_TileMo
de)); |
51 SkPoint pts1[] = { | 52 SkPoint pts1[] = { |
52 { 0, 0 }, | 53 { 0, 0 }, |
53 { SkIntToScalar(kCellSize), SkIntToScalar(kCellSize) } | 54 { SkIntToScalar(kCellSize), SkIntToScalar(kCellSize) } |
54 }; | 55 }; |
55 SkPoint pts2[] = { | 56 SkPoint pts2[] = { |
56 { 0, 0 }, | 57 { 0, 0 }, |
57 { 0, SkIntToScalar(kCellSize) } | 58 { 0, SkIntToScalar(kCellSize) } |
58 }; | 59 }; |
59 static const SkColor colors[] = { | 60 static const SkColor colors[] = { |
60 SK_ColorRED, SK_ColorGREEN, SK_ColorRED, SK_ColorGREEN, SK_ColorRED | 61 SK_ColorRED, SK_ColorGREEN, SK_ColorRED, SK_ColorGREEN, SK_ColorRED |
61 }; | 62 }; |
62 static const SkScalar pos[] = { 0, 0.25f, 0.5f, 0.75f, SK_Scalar1 }; | 63 static const SkScalar pos[] = { 0, 0.25f, 0.5f, 0.75f, SK_Scalar1 }; |
63 | 64 |
64 fLinearGrad1 = SkGradientShader::MakeLinear(pts1, colors, pos, SK_ARRAY_
COUNT(colors), | 65 fLinearGrad1.reset(SkGradientShader::CreateLinear(pts1, colors, pos, |
65 SkShader::kClamp_TileMode); | 66 SK_ARRAY_COUNT(colors)
, |
66 fLinearGrad2 = SkGradientShader::MakeLinear(pts2, colors, pos, SK_ARRAY_
COUNT(colors), | 67 SkShader::kClamp_TileM
ode)); |
67 SkShader::kClamp_TileMode); | 68 fLinearGrad2.reset(SkGradientShader::CreateLinear(pts2, colors, pos, |
| 69 SK_ARRAY_COUNT(colors)
, |
| 70 SkShader::kClamp_TileM
ode)); |
68 | 71 |
69 fPerspMatrix.reset(); | 72 fPerspMatrix.reset(); |
70 fPerspMatrix.setPerspY(SK_Scalar1 / 50); | 73 fPerspMatrix.setPerspY(SK_Scalar1 / 50); |
71 | 74 |
72 fPath.moveTo(0, 0); | 75 fPath.moveTo(0, 0); |
73 fPath.lineTo(0, SkIntToScalar(kCellSize)); | 76 fPath.lineTo(0, SkIntToScalar(kCellSize)); |
74 fPath.lineTo(kCellSize/2.0f, kCellSize/2.0f); | 77 fPath.lineTo(kCellSize/2.0f, kCellSize/2.0f); |
75 fPath.lineTo(SkIntToScalar(kCellSize), SkIntToScalar(kCellSize)); | 78 fPath.lineTo(SkIntToScalar(kCellSize), SkIntToScalar(kCellSize)); |
76 fPath.lineTo(SkIntToScalar(kCellSize), 0); | 79 fPath.lineTo(SkIntToScalar(kCellSize), 0); |
77 fPath.close(); | 80 fPath.close(); |
(...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
150 this->drawRow(canvas, kHigh_SkFilterQuality); | 153 this->drawRow(canvas, kHigh_SkFilterQuality); |
151 canvas->translate(0, SkIntToScalar(kCellSize)); | 154 canvas->translate(0, SkIntToScalar(kCellSize)); |
152 } | 155 } |
153 private: | 156 private: |
154 static const int kCellSize = 50; | 157 static const int kCellSize = 50; |
155 static const int kNumRows = 4; | 158 static const int kNumRows = 4; |
156 static const int kNumCols = 6; | 159 static const int kNumCols = 6; |
157 | 160 |
158 bool fDoAA; | 161 bool fDoAA; |
159 SkPath fPath; | 162 SkPath fPath; |
160 sk_sp<SkShader> fBitmapShader; | 163 SkAutoTUnref<SkShader> fBitmapShader; |
161 sk_sp<SkShader> fLinearGrad1; | 164 SkAutoTUnref<SkShader> fLinearGrad1; |
162 sk_sp<SkShader> fLinearGrad2; | 165 SkAutoTUnref<SkShader> fLinearGrad2; |
163 SkMatrix fPerspMatrix; | 166 SkMatrix fPerspMatrix; |
164 SkAutoTUnref<SkImage> fImage; | 167 SkAutoTUnref<SkImage> fImage; |
165 SkBitmap fBitmap; | 168 SkBitmap fBitmap; |
166 | 169 |
167 typedef GM INHERITED; | 170 typedef GM INHERITED; |
168 }; | 171 }; |
169 | 172 |
170 ////////////////////////////////////////////////////////////////////////////// | 173 ////////////////////////////////////////////////////////////////////////////// |
171 | 174 |
172 DEF_GM(return new PerspShadersGM(true);) | 175 DEF_GM(return new PerspShadersGM(true);) |
173 DEF_GM(return new PerspShadersGM(false);) | 176 DEF_GM(return new PerspShadersGM(false);) |
174 } | 177 } |
OLD | NEW |