OLD | NEW |
1 /* | 1 /* |
2 * Copyright 2012 Google Inc. | 2 * Copyright 2012 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 "SkLightingImageFilter.h" | 9 #include "SkLightingImageFilter.h" |
10 #include "SkOffsetImageFilter.h" | 10 #include "SkOffsetImageFilter.h" |
11 #include "SkPoint3.h" | 11 #include "SkPoint3.h" |
12 | 12 |
13 #define WIDTH 330 | 13 #define WIDTH 550 |
14 #define HEIGHT 660 | 14 #define HEIGHT 660 |
15 | 15 |
16 namespace skiagm { | 16 namespace skiagm { |
17 | 17 |
18 class ImageLightingGM : public GM { | 18 class ImageLightingGM : public GM { |
19 public: | 19 public: |
20 ImageLightingGM() { | 20 ImageLightingGM() { |
21 this->setBGColor(0xFF000000); | 21 this->setBGColor(0xFF000000); |
22 } | 22 } |
23 | 23 |
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
62 SkScalar elevationRad = SkDegreesToRadians(SkIntToScalar(5)); | 62 SkScalar elevationRad = SkDegreesToRadians(SkIntToScalar(5)); |
63 SkPoint3 distantDirection = SkPoint3::Make(SkScalarMul(SkScalarCos(azimu
thRad), | 63 SkPoint3 distantDirection = SkPoint3::Make(SkScalarMul(SkScalarCos(azimu
thRad), |
64 SkScalarCos(eleva
tionRad)), | 64 SkScalarCos(eleva
tionRad)), |
65 SkScalarMul(SkScalarSin(azimu
thRad), | 65 SkScalarMul(SkScalarSin(azimu
thRad), |
66 SkScalarCos(eleva
tionRad)), | 66 SkScalarCos(eleva
tionRad)), |
67 SkScalarSin(elevationRad)); | 67 SkScalarSin(elevationRad)); |
68 SkPoint3 spotLocation = SkPoint3::Make(SkIntToScalar(-10), | 68 SkPoint3 spotLocation = SkPoint3::Make(SkIntToScalar(-10), |
69 SkIntToScalar(-10), | 69 SkIntToScalar(-10), |
70 SkIntToScalar(20)); | 70 SkIntToScalar(20)); |
71 SkPoint3 spotTarget = SkPoint3::Make(SkIntToScalar(40), SkIntToScalar(40
), 0); | 71 SkPoint3 spotTarget = SkPoint3::Make(SkIntToScalar(40), SkIntToScalar(40
), 0); |
72 SkScalar spotExponent = SK_Scalar1; | 72 SkScalar spotExponent1 = SK_Scalar1; |
73 SkScalar cutoffAngle = SkIntToScalar(15); | 73 SkScalar spotExponent0 = SkIntToScalar(0); |
| 74 SkScalar cutoffAngleSmall = SkIntToScalar(15); |
| 75 SkScalar cutoffAngleNone = SkIntToScalar(180); |
74 SkScalar kd = SkIntToScalar(2); | 76 SkScalar kd = SkIntToScalar(2); |
75 SkScalar ks = SkIntToScalar(1); | 77 SkScalar ks = SkIntToScalar(1); |
76 SkScalar shininess = SkIntToScalar(8); | 78 SkScalar shininess = SkIntToScalar(8); |
77 SkScalar surfaceScale = SkIntToScalar(1); | 79 SkScalar surfaceScale = SkIntToScalar(1); |
78 SkColor white(0xFFFFFFFF); | 80 SkColor white(0xFFFFFFFF); |
79 SkPaint paint; | 81 SkPaint paint; |
80 | 82 |
81 SkImageFilter::CropRect cropRect(SkRect::MakeXYWH(20, 10, 60, 65)); | 83 SkImageFilter::CropRect cropRect(SkRect::MakeXYWH(20, 10, 60, 65)); |
82 SkImageFilter::CropRect fullSizeCropRect(SkRect::MakeXYWH(0, 0, 100, 100
)); | 84 SkImageFilter::CropRect fullSizeCropRect(SkRect::MakeXYWH(0, 0, 100, 100
)); |
83 SkAutoTUnref<SkImageFilter> noopCropped(SkOffsetImageFilter::Create(0, 0
, nullptr, &cropRect)); | 85 SkAutoTUnref<SkImageFilter> noopCropped(SkOffsetImageFilter::Create(0, 0
, nullptr, &cropRect)); |
(...skipping 13 matching lines...) Expand all Loading... |
97 paint.setImageFilter(SkLightingImageFilter::CreateDistantLitDiffuse(
distantDirection, | 99 paint.setImageFilter(SkLightingImageFilter::CreateDistantLitDiffuse(
distantDirection, |
98
white, | 100
white, |
99
surfaceScale, | 101
surfaceScale, |
100
kd, | 102
kd, |
101
input, | 103
input, |
102
cr))->unref(); | 104
cr))->unref(); |
103 drawClippedBitmap(canvas, paint, 110, y); | 105 drawClippedBitmap(canvas, paint, 110, y); |
104 | 106 |
105 paint.setImageFilter(SkLightingImageFilter::CreateSpotLitDiffuse(spo
tLocation, | 107 paint.setImageFilter(SkLightingImageFilter::CreateSpotLitDiffuse(spo
tLocation, |
106 spo
tTarget, | 108 spo
tTarget, |
107 spo
tExponent, | 109 spo
tExponent1, |
108 cut
offAngle, | 110 cut
offAngleSmall, |
109 whi
te, | 111 whi
te, |
110 sur
faceScale, | 112 sur
faceScale, |
111 kd, | 113 kd, |
112 inp
ut, | 114 inp
ut, |
113 cr)
)->unref(); | 115 cr)
)->unref(); |
114 drawClippedBitmap(canvas, paint, 220, y); | 116 drawClippedBitmap(canvas, paint, 220, y); |
115 | 117 |
| 118 paint.setImageFilter(SkLightingImageFilter::CreateSpotLitDiffuse(spo
tLocation, |
| 119 spo
tTarget, |
| 120 spo
tExponent1, |
| 121 cut
offAngleNone, |
| 122 whi
te, |
| 123 sur
faceScale, |
| 124 kd, |
| 125 inp
ut, |
| 126 cr)
)->unref(); |
| 127 drawClippedBitmap(canvas, paint, 330, y); |
| 128 |
| 129 paint.setImageFilter(SkLightingImageFilter::CreateSpotLitDiffuse(spo
tLocation, |
| 130 spo
tTarget, |
| 131 spo
tExponent0, |
| 132 cut
offAngleNone, |
| 133 whi
te, |
| 134 sur
faceScale, |
| 135 kd, |
| 136 inp
ut, |
| 137 cr)
)->unref(); |
| 138 drawClippedBitmap(canvas, paint, 440, y); |
| 139 |
116 y += 110; | 140 y += 110; |
117 | 141 |
118 paint.setImageFilter(SkLightingImageFilter::CreatePointLitSpecular(p
ointLocation, | 142 paint.setImageFilter(SkLightingImageFilter::CreatePointLitSpecular(p
ointLocation, |
119 w
hite, | 143 w
hite, |
120 s
urfaceScale, | 144 s
urfaceScale, |
121 k
s, | 145 k
s, |
122 s
hininess, | 146 s
hininess, |
123 i
nput, | 147 i
nput, |
124 c
r))->unref(); | 148 c
r))->unref(); |
125 drawClippedBitmap(canvas, paint, 0, y); | 149 drawClippedBitmap(canvas, paint, 0, y); |
126 | 150 |
127 paint.setImageFilter(SkLightingImageFilter::CreateDistantLitSpecular
(distantDirection, | 151 paint.setImageFilter(SkLightingImageFilter::CreateDistantLitSpecular
(distantDirection, |
128
white, | 152
white, |
129
surfaceScale, | 153
surfaceScale, |
130
ks, | 154
ks, |
131
shininess, | 155
shininess, |
132
input, | 156
input, |
133
cr))->unref(); | 157
cr))->unref(); |
134 drawClippedBitmap(canvas, paint, 110, y); | 158 drawClippedBitmap(canvas, paint, 110, y); |
135 | 159 |
136 paint.setImageFilter(SkLightingImageFilter::CreateSpotLitSpecular(sp
otLocation, | 160 paint.setImageFilter(SkLightingImageFilter::CreateSpotLitSpecular(sp
otLocation, |
137 sp
otTarget, | 161 sp
otTarget, |
138 sp
otExponent, | 162 sp
otExponent1, |
139 cu
toffAngle, | 163 cu
toffAngleSmall, |
140 wh
ite, | 164 wh
ite, |
141 su
rfaceScale, | 165 su
rfaceScale, |
142 ks
, | 166 ks
, |
143 sh
ininess, | 167 sh
ininess, |
144 in
put, | 168 in
put, |
145 cr
))->unref(); | 169 cr
))->unref(); |
146 drawClippedBitmap(canvas, paint, 220, y); | 170 drawClippedBitmap(canvas, paint, 220, y); |
147 | 171 |
| 172 paint.setImageFilter(SkLightingImageFilter::CreateSpotLitSpecular(sp
otLocation, |
| 173 sp
otTarget, |
| 174 sp
otExponent1, |
| 175 cu
toffAngleNone, |
| 176 wh
ite, |
| 177 su
rfaceScale, |
| 178 ks
, |
| 179 sh
ininess, |
| 180 in
put, |
| 181 cr
))->unref(); |
| 182 drawClippedBitmap(canvas, paint, 330, y); |
| 183 |
| 184 paint.setImageFilter(SkLightingImageFilter::CreateSpotLitSpecular(sp
otLocation, |
| 185 sp
otTarget, |
| 186 sp
otExponent0, |
| 187 cu
toffAngleNone, |
| 188 wh
ite, |
| 189 su
rfaceScale, |
| 190 ks
, |
| 191 sh
ininess, |
| 192 in
put, |
| 193 cr
))->unref(); |
| 194 drawClippedBitmap(canvas, paint, 440, y); |
| 195 |
148 y += 110; | 196 y += 110; |
149 } | 197 } |
150 } | 198 } |
151 | 199 |
152 private: | 200 private: |
153 SkBitmap fBitmap; | 201 SkBitmap fBitmap; |
154 | 202 |
155 typedef GM INHERITED; | 203 typedef GM INHERITED; |
156 }; | 204 }; |
157 | 205 |
158 ////////////////////////////////////////////////////////////////////////////// | 206 ////////////////////////////////////////////////////////////////////////////// |
159 | 207 |
160 DEF_GM(return new ImageLightingGM;) | 208 DEF_GM(return new ImageLightingGM;) |
161 } | 209 } |
OLD | NEW |