| 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 550 | 13 #define WIDTH 330 |
| 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 spotExponent1 = SK_Scalar1; | 72 SkScalar spotExponent = SK_Scalar1; |
| 73 SkScalar spotExponent0 = SkIntToScalar(0); | 73 SkScalar cutoffAngle = SkIntToScalar(15); |
| 74 SkScalar cutoffAngleSmall = SkIntToScalar(15); | |
| 75 SkScalar cutoffAngleNone = SkIntToScalar(180); | |
| 76 SkScalar kd = SkIntToScalar(2); | 74 SkScalar kd = SkIntToScalar(2); |
| 77 SkScalar ks = SkIntToScalar(1); | 75 SkScalar ks = SkIntToScalar(1); |
| 78 SkScalar shininess = SkIntToScalar(8); | 76 SkScalar shininess = SkIntToScalar(8); |
| 79 SkScalar surfaceScale = SkIntToScalar(1); | 77 SkScalar surfaceScale = SkIntToScalar(1); |
| 80 SkColor white(0xFFFFFFFF); | 78 SkColor white(0xFFFFFFFF); |
| 81 SkPaint paint; | 79 SkPaint paint; |
| 82 | 80 |
| 83 SkImageFilter::CropRect cropRect(SkRect::MakeXYWH(20, 10, 60, 65)); | 81 SkImageFilter::CropRect cropRect(SkRect::MakeXYWH(20, 10, 60, 65)); |
| 84 SkImageFilter::CropRect fullSizeCropRect(SkRect::MakeXYWH(0, 0, 100, 100
)); | 82 SkImageFilter::CropRect fullSizeCropRect(SkRect::MakeXYWH(0, 0, 100, 100
)); |
| 85 SkAutoTUnref<SkImageFilter> noopCropped(SkOffsetImageFilter::Create(0, 0
, nullptr, &cropRect)); | 83 SkAutoTUnref<SkImageFilter> noopCropped(SkOffsetImageFilter::Create(0, 0
, nullptr, &cropRect)); |
| (...skipping 13 matching lines...) Expand all Loading... |
| 99 paint.setImageFilter(SkLightingImageFilter::CreateDistantLitDiffuse(
distantDirection, | 97 paint.setImageFilter(SkLightingImageFilter::CreateDistantLitDiffuse(
distantDirection, |
| 100
white, | 98
white, |
| 101
surfaceScale, | 99
surfaceScale, |
| 102
kd, | 100
kd, |
| 103
input, | 101
input, |
| 104
cr))->unref(); | 102
cr))->unref(); |
| 105 drawClippedBitmap(canvas, paint, 110, y); | 103 drawClippedBitmap(canvas, paint, 110, y); |
| 106 | 104 |
| 107 paint.setImageFilter(SkLightingImageFilter::CreateSpotLitDiffuse(spo
tLocation, | 105 paint.setImageFilter(SkLightingImageFilter::CreateSpotLitDiffuse(spo
tLocation, |
| 108 spo
tTarget, | 106 spo
tTarget, |
| 109 spo
tExponent1, | 107 spo
tExponent, |
| 110 cut
offAngleSmall, | 108 cut
offAngle, |
| 111 whi
te, | 109 whi
te, |
| 112 sur
faceScale, | 110 sur
faceScale, |
| 113 kd, | 111 kd, |
| 114 inp
ut, | 112 inp
ut, |
| 115 cr)
)->unref(); | 113 cr)
)->unref(); |
| 116 drawClippedBitmap(canvas, paint, 220, y); | 114 drawClippedBitmap(canvas, paint, 220, y); |
| 117 | 115 |
| 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 | |
| 140 y += 110; | 116 y += 110; |
| 141 | 117 |
| 142 paint.setImageFilter(SkLightingImageFilter::CreatePointLitSpecular(p
ointLocation, | 118 paint.setImageFilter(SkLightingImageFilter::CreatePointLitSpecular(p
ointLocation, |
| 143 w
hite, | 119 w
hite, |
| 144 s
urfaceScale, | 120 s
urfaceScale, |
| 145 k
s, | 121 k
s, |
| 146 s
hininess, | 122 s
hininess, |
| 147 i
nput, | 123 i
nput, |
| 148 c
r))->unref(); | 124 c
r))->unref(); |
| 149 drawClippedBitmap(canvas, paint, 0, y); | 125 drawClippedBitmap(canvas, paint, 0, y); |
| 150 | 126 |
| 151 paint.setImageFilter(SkLightingImageFilter::CreateDistantLitSpecular
(distantDirection, | 127 paint.setImageFilter(SkLightingImageFilter::CreateDistantLitSpecular
(distantDirection, |
| 152
white, | 128
white, |
| 153
surfaceScale, | 129
surfaceScale, |
| 154
ks, | 130
ks, |
| 155
shininess, | 131
shininess, |
| 156
input, | 132
input, |
| 157
cr))->unref(); | 133
cr))->unref(); |
| 158 drawClippedBitmap(canvas, paint, 110, y); | 134 drawClippedBitmap(canvas, paint, 110, y); |
| 159 | 135 |
| 160 paint.setImageFilter(SkLightingImageFilter::CreateSpotLitSpecular(sp
otLocation, | 136 paint.setImageFilter(SkLightingImageFilter::CreateSpotLitSpecular(sp
otLocation, |
| 161 sp
otTarget, | 137 sp
otTarget, |
| 162 sp
otExponent1, | 138 sp
otExponent, |
| 163 cu
toffAngleSmall, | 139 cu
toffAngle, |
| 164 wh
ite, | 140 wh
ite, |
| 165 su
rfaceScale, | 141 su
rfaceScale, |
| 166 ks
, | 142 ks
, |
| 167 sh
ininess, | 143 sh
ininess, |
| 168 in
put, | 144 in
put, |
| 169 cr
))->unref(); | 145 cr
))->unref(); |
| 170 drawClippedBitmap(canvas, paint, 220, y); | 146 drawClippedBitmap(canvas, paint, 220, y); |
| 171 | 147 |
| 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 | |
| 196 y += 110; | 148 y += 110; |
| 197 } | 149 } |
| 198 } | 150 } |
| 199 | 151 |
| 200 private: | 152 private: |
| 201 SkBitmap fBitmap; | 153 SkBitmap fBitmap; |
| 202 | 154 |
| 203 typedef GM INHERITED; | 155 typedef GM INHERITED; |
| 204 }; | 156 }; |
| 205 | 157 |
| 206 ////////////////////////////////////////////////////////////////////////////// | 158 ////////////////////////////////////////////////////////////////////////////// |
| 207 | 159 |
| 208 DEF_GM(return new ImageLightingGM;) | 160 DEF_GM(return new ImageLightingGM;) |
| 209 } | 161 } |
| OLD | NEW |