| 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 | 11 |
| 11 #define WIDTH 330 | 12 #define WIDTH 330 |
| 12 #define HEIGHT 440 | 13 #define HEIGHT 660 |
| 13 | 14 |
| 14 namespace skiagm { | 15 namespace skiagm { |
| 15 | 16 |
| 16 class ImageLightingGM : public GM { | 17 class ImageLightingGM : public GM { |
| 17 public: | 18 public: |
| 18 ImageLightingGM() : fInitialized(false) { | 19 ImageLightingGM() : fInitialized(false) { |
| 19 this->setBGColor(0xFF000000); | 20 this->setBGColor(0xFF000000); |
| 20 } | 21 } |
| 21 | 22 |
| 22 protected: | 23 protected: |
| (...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 79 SkScalar spotExponent = SK_Scalar1; | 80 SkScalar spotExponent = SK_Scalar1; |
| 80 SkScalar cutoffAngle = SkIntToScalar(15); | 81 SkScalar cutoffAngle = SkIntToScalar(15); |
| 81 SkScalar kd = SkIntToScalar(2); | 82 SkScalar kd = SkIntToScalar(2); |
| 82 SkScalar ks = SkIntToScalar(1); | 83 SkScalar ks = SkIntToScalar(1); |
| 83 SkScalar shininess = SkIntToScalar(8); | 84 SkScalar shininess = SkIntToScalar(8); |
| 84 SkScalar surfaceScale = SkIntToScalar(1); | 85 SkScalar surfaceScale = SkIntToScalar(1); |
| 85 SkColor white(0xFFFFFFFF); | 86 SkColor white(0xFFFFFFFF); |
| 86 SkPaint paint; | 87 SkPaint paint; |
| 87 | 88 |
| 88 SkImageFilter::CropRect cropRect(SkRect::MakeXYWH(20, 10, 60, 65)); | 89 SkImageFilter::CropRect cropRect(SkRect::MakeXYWH(20, 10, 60, 65)); |
| 90 SkImageFilter::CropRect fullSizeCropRect(SkRect::MakeXYWH(0, 0, 100, 100
)); |
| 91 SkAutoTUnref<SkImageFilter> noopCropped(SkOffsetImageFilter::Create(0, 0
, NULL, &cropRect)); |
| 89 | 92 |
| 90 int y = 0; | 93 int y = 0; |
| 91 for (int i = 0; i < 2; i++) { | 94 for (int i = 0; i < 3; i++) { |
| 92 const SkImageFilter::CropRect* cr = (i == 0) ? NULL : &cropRect; | 95 const SkImageFilter::CropRect* cr = (i == 1) ? &cropRect : (i == 2)
? &fullSizeCropRect : NULL; |
| 93 paint.setImageFilter(SkLightingImageFilter::CreatePointLitDiffuse(po
intLocation, white, surfaceScale, kd, NULL, cr))->unref(); | 96 SkImageFilter* input = (i == 2) ? noopCropped.get() : NULL; |
| 97 paint.setImageFilter(SkLightingImageFilter::CreatePointLitDiffuse(po
intLocation, |
| 98 wh
ite, |
| 99 su
rfaceScale, |
| 100 kd
, |
| 101 in
put, |
| 102 cr
))->unref(); |
| 94 drawClippedBitmap(canvas, paint, 0, y); | 103 drawClippedBitmap(canvas, paint, 0, y); |
| 95 | 104 |
| 96 paint.setImageFilter(SkLightingImageFilter::CreateDistantLitDiffuse(
distantDirection, white, surfaceScale, kd, NULL, cr))->unref(); | 105 paint.setImageFilter(SkLightingImageFilter::CreateDistantLitDiffuse(
distantDirection, |
| 106
white, |
| 107
surfaceScale, |
| 108
kd, |
| 109
input, |
| 110
cr))->unref(); |
| 97 drawClippedBitmap(canvas, paint, 110, y); | 111 drawClippedBitmap(canvas, paint, 110, y); |
| 98 | 112 |
| 99 paint.setImageFilter(SkLightingImageFilter::CreateSpotLitDiffuse(spo
tLocation, spotTarget, spotExponent, cutoffAngle, white, surfaceScale, kd, NULL,
cr))->unref(); | 113 paint.setImageFilter(SkLightingImageFilter::CreateSpotLitDiffuse(spo
tLocation, |
| 114 spo
tTarget, |
| 115 spo
tExponent, |
| 116 cut
offAngle, |
| 117 whi
te, |
| 118 sur
faceScale, |
| 119 kd, |
| 120 inp
ut, |
| 121 cr)
)->unref(); |
| 100 drawClippedBitmap(canvas, paint, 220, y); | 122 drawClippedBitmap(canvas, paint, 220, y); |
| 101 | 123 |
| 102 y += 110; | 124 y += 110; |
| 103 | 125 |
| 104 paint.setImageFilter(SkLightingImageFilter::CreatePointLitSpecular(p
ointLocation, white, surfaceScale, ks, shininess, NULL, cr))->unref(); | 126 paint.setImageFilter(SkLightingImageFilter::CreatePointLitSpecular(p
ointLocation, |
| 127 w
hite, |
| 128 s
urfaceScale, |
| 129 k
s, |
| 130 s
hininess, |
| 131 i
nput, |
| 132 c
r))->unref(); |
| 105 drawClippedBitmap(canvas, paint, 0, y); | 133 drawClippedBitmap(canvas, paint, 0, y); |
| 106 | 134 |
| 107 paint.setImageFilter(SkLightingImageFilter::CreateDistantLitSpecular
(distantDirection, white, surfaceScale, ks, shininess, NULL, cr))->unref(); | 135 paint.setImageFilter(SkLightingImageFilter::CreateDistantLitSpecular
(distantDirection, |
| 136
white, |
| 137
surfaceScale, |
| 138
ks, |
| 139
shininess, |
| 140
input, |
| 141
cr))->unref(); |
| 108 drawClippedBitmap(canvas, paint, 110, y); | 142 drawClippedBitmap(canvas, paint, 110, y); |
| 109 | 143 |
| 110 paint.setImageFilter(SkLightingImageFilter::CreateSpotLitSpecular(sp
otLocation, spotTarget, spotExponent, cutoffAngle, white, surfaceScale, ks, shin
iness, NULL, cr))->unref(); | 144 paint.setImageFilter(SkLightingImageFilter::CreateSpotLitSpecular(sp
otLocation, |
| 145 sp
otTarget, |
| 146 sp
otExponent, |
| 147 cu
toffAngle, |
| 148 wh
ite, |
| 149 su
rfaceScale, |
| 150 ks
, |
| 151 sh
ininess, |
| 152 in
put, |
| 153 cr
))->unref(); |
| 111 drawClippedBitmap(canvas, paint, 220, y); | 154 drawClippedBitmap(canvas, paint, 220, y); |
| 112 | 155 |
| 113 y += 110; | 156 y += 110; |
| 114 } | 157 } |
| 115 } | 158 } |
| 116 | 159 |
| 117 private: | 160 private: |
| 118 typedef GM INHERITED; | 161 typedef GM INHERITED; |
| 119 SkBitmap fBitmap; | 162 SkBitmap fBitmap; |
| 120 bool fInitialized; | 163 bool fInitialized; |
| 121 }; | 164 }; |
| 122 | 165 |
| 123 ////////////////////////////////////////////////////////////////////////////// | 166 ////////////////////////////////////////////////////////////////////////////// |
| 124 | 167 |
| 125 static GM* MyFactory(void*) { return new ImageLightingGM; } | 168 static GM* MyFactory(void*) { return new ImageLightingGM; } |
| 126 static GMRegistry reg(MyFactory); | 169 static GMRegistry reg(MyFactory); |
| 127 | 170 |
| 128 } | 171 } |
| OLD | NEW |