| OLD | NEW |
| 1 | 1 |
| 2 /* | 2 /* |
| 3 * Copyright 2016 Google Inc. | 3 * Copyright 2016 Google Inc. |
| 4 * | 4 * |
| 5 * Use of this source code is governed by a BSD-style license that can be | 5 * Use of this source code is governed by a BSD-style license that can be |
| 6 * found in the LICENSE file. | 6 * found in the LICENSE file. |
| 7 */ | 7 */ |
| 8 #include "SampleCode.h" | 8 #include "SampleCode.h" |
| 9 #include "SkBlurMask.h" | 9 #include "SkBlurMask.h" |
| 10 #include "SkBlurMaskFilter.h" | 10 #include "SkBlurMaskFilter.h" |
| (...skipping 23 matching lines...) Expand all Loading... |
| 34 : fShowAmbient(true) | 34 : fShowAmbient(true) |
| 35 , fShowSpot(true) | 35 , fShowSpot(true) |
| 36 , fUseAlt(true) | 36 , fUseAlt(true) |
| 37 , fShowObject(true) {} | 37 , fShowObject(true) {} |
| 38 | 38 |
| 39 protected: | 39 protected: |
| 40 void onOnceBeforeDraw() override { | 40 void onOnceBeforeDraw() override { |
| 41 fCirclePath.addCircle(0, 0, 50); | 41 fCirclePath.addCircle(0, 0, 50); |
| 42 fRectPath.addRect(SkRect::MakeXYWH(-100, -50, 200, 100)); | 42 fRectPath.addRect(SkRect::MakeXYWH(-100, -50, 200, 100)); |
| 43 fRRPath.addRRect(SkRRect::MakeRectXY(SkRect::MakeXYWH(-100, -50, 200, 10
0), 4, 4)); | 43 fRRPath.addRRect(SkRRect::MakeRectXY(SkRect::MakeXYWH(-100, -50, 200, 10
0), 4, 4)); |
| 44 fLightPos = SkPoint3::Make(-2, -2, 6); | 44 fLightPos = SkPoint3::Make(-700, -700, 2800); |
| 45 } | 45 } |
| 46 | 46 |
| 47 // overrides from SkEventSink | 47 // overrides from SkEventSink |
| 48 bool onQuery(SkEvent* evt) override { | 48 bool onQuery(SkEvent* evt) override { |
| 49 if (SampleCode::TitleQ(*evt)) { | 49 if (SampleCode::TitleQ(*evt)) { |
| 50 SampleCode::TitleR(evt, "AndroidShadows"); | 50 SampleCode::TitleR(evt, "AndroidShadows"); |
| 51 return true; | 51 return true; |
| 52 } | 52 } |
| 53 | 53 |
| 54 SkUnichar uni; | 54 SkUnichar uni; |
| (...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 141 | 141 |
| 142 if (ambientAlpha <= 0) { | 142 if (ambientAlpha <= 0) { |
| 143 return; | 143 return; |
| 144 } | 144 } |
| 145 | 145 |
| 146 const SkScalar kHeightFactor = 1.f / 128.f; | 146 const SkScalar kHeightFactor = 1.f / 128.f; |
| 147 const SkScalar kGeomFactor = 64; | 147 const SkScalar kGeomFactor = 64; |
| 148 | 148 |
| 149 SkScalar umbraAlpha = 1 / (1 + SkMaxScalar(zValue*kHeightFactor, 0)); | 149 SkScalar umbraAlpha = 1 / (1 + SkMaxScalar(zValue*kHeightFactor, 0)); |
| 150 SkScalar radius = zValue*kHeightFactor*kGeomFactor; | 150 SkScalar radius = zValue*kHeightFactor*kGeomFactor; |
| 151 // distance to outer of edge of geometry from original shape edge |
| 152 SkScalar offset = radius*umbraAlpha; |
| 151 | 153 |
| 152 SkRect pathRect; | 154 SkRect pathRect; |
| 153 SkRRect pathRRect; | 155 SkRRect pathRRect; |
| 154 if (radius >= 64 || | 156 SkScalar scaleFactors[2]; |
| 157 if (!canvas->getTotalMatrix().getMinMaxScales(scaleFactors)) { |
| 158 return; |
| 159 } |
| 160 if (scaleFactors[0] != scaleFactors[1] || radius*scaleFactors[0] >= 64 |
| |
| 155 !((path.isOval(&pathRect) && pathRect.width() == pathRect.height())
|| | 161 !((path.isOval(&pathRect) && pathRect.width() == pathRect.height())
|| |
| 156 (path.isRRect(&pathRRect) && pathRRect.allCornersCircular()) || | 162 (path.isRRect(&pathRRect) && pathRRect.allCornersCircular()) || |
| 157 path.isRect(&pathRect))) { | 163 path.isRect(&pathRect))) { |
| 158 this->drawAmbientShadow(canvas, path, zValue, ambientAlpha); | 164 this->drawAmbientShadow(canvas, path, zValue, ambientAlpha); |
| 159 return; | 165 return; |
| 160 } | 166 } |
| 161 | 167 |
| 162 // For all of these, we outset the rect by half the radius to get our st
roke shape. | 168 // For all of these, we inset the offset rect by half the radius to get
our stroke shape. |
| 163 SkScalar halfRadius = SK_ScalarHalf*radius; | 169 SkScalar strokeOutset = offset - SK_ScalarHalf*radius; |
| 170 // Make sure we'll have a radius of at least 0.5 after xform |
| 171 if (strokeOutset*scaleFactors[0] < 0.5f) { |
| 172 strokeOutset = 0.5f / scaleFactors[0]; |
| 173 } |
| 164 if (path.isOval(nullptr)) { | 174 if (path.isOval(nullptr)) { |
| 165 pathRect.outset(halfRadius, halfRadius); | 175 pathRect.outset(strokeOutset, strokeOutset); |
| 166 pathRRect = SkRRect::MakeOval(pathRect); | 176 pathRRect = SkRRect::MakeOval(pathRect); |
| 167 } else if (path.isRect(nullptr)) { | 177 } else if (path.isRect(nullptr)) { |
| 168 pathRect.outset(halfRadius, halfRadius); | 178 pathRect.outset(strokeOutset, strokeOutset); |
| 169 pathRRect = SkRRect::MakeRectXY(pathRect, halfRadius, halfRadius); | 179 pathRRect = SkRRect::MakeRectXY(pathRect, strokeOutset, strokeOutset
); |
| 170 } else { | 180 } else { |
| 171 pathRRect.outset(halfRadius, halfRadius); | 181 pathRRect.outset(strokeOutset, strokeOutset); |
| 172 } | 182 } |
| 173 | 183 |
| 174 SkPaint paint; | 184 SkPaint paint; |
| 175 paint.setAntiAlias(true); | 185 paint.setAntiAlias(true); |
| 176 paint.setStyle(SkPaint::kStroke_Style); | 186 paint.setStyle(SkPaint::kStroke_Style); |
| 177 // we outset the stroke a little to cover up AA on the interior edge | 187 // we outset the stroke a little to cover up AA on the interior edge |
| 178 paint.setStrokeWidth(radius + 1); | 188 SkScalar pad = 0.5f; |
| 179 // handle scale of radius due to CTM | 189 paint.setStrokeWidth(radius + 2*pad); |
| 180 SkScalar maxScale = canvas->getTotalMatrix().getMaxScale(); | 190 // handle scale of radius and pad due to CTM |
| 181 radius *= maxScale; | 191 radius *= scaleFactors[0]; |
| 182 unsigned char gray = (unsigned char)(ambientAlpha*umbraAlpha*255.999f); | 192 pad *= scaleFactors[0]; |
| 183 SkASSERT(radius < 64); | 193 SkASSERT(radius < 16384); |
| 184 // Convert radius to 6.2 fixed point and place in the G component. | 194 SkASSERT(pad < 64); |
| 185 paint.setColor(SkColorSetARGB(1, gray, (unsigned char)(4.0f*radius), 0))
; | 195 // Convert radius to 14.2 fixed point and place in the R & G components. |
| 196 // Convert pad to 6.2 fixed point and place in the B component. |
| 197 uint16_t iRadius = (uint16_t)(radius*4.0f); |
| 198 unsigned char alpha = (unsigned char)(ambientAlpha*255.999f); |
| 199 paint.setColor(SkColorSetARGB(alpha, iRadius >> 8, iRadius & 0xff, |
| 200 (unsigned char)(4.0f*pad))); |
| 186 | 201 |
| 187 sk_sp<SkShader> gaussShader = SkGaussianEdgeShader::Make(); | 202 paint.setShader(SkGaussianEdgeShader::Make(true)); |
| 188 paint.setShader(gaussShader); | |
| 189 canvas->drawRRect(pathRRect, paint); | 203 canvas->drawRRect(pathRRect, paint); |
| 190 } | 204 } |
| 191 | 205 |
| 192 void drawSpotShadow(SkCanvas* canvas, const SkPath& path, SkScalar zValue, | 206 void drawSpotShadow(SkCanvas* canvas, const SkPath& path, SkScalar zValue, |
| 193 SkPoint3 lightPos, SkScalar lightWidth, SkScalar spotAlp
ha) { | 207 SkPoint3 lightPos, SkScalar lightWidth, SkScalar spotAlp
ha) { |
| 194 if (spotAlpha <= 0) { | 208 if (spotAlpha <= 0) { |
| 195 return; | 209 return; |
| 196 } | 210 } |
| 197 | 211 |
| 198 SkScalar zRatio = zValue / (lightPos.fZ - zValue); | 212 SkScalar zRatio = zValue / (lightPos.fZ - zValue); |
| 199 if (zRatio < 0.0f) { | 213 if (zRatio < 0.0f) { |
| 200 zRatio = 0.0f; | 214 zRatio = 0.0f; |
| 201 } else if (zRatio > 0.95f) { | 215 } else if (zRatio > 0.95f) { |
| 202 zRatio = 0.95f; | 216 zRatio = 0.95f; |
| 203 } | 217 } |
| 204 SkScalar radius = lightWidth*zRatio; | 218 SkScalar blurRadius = lightWidth*zRatio; |
| 205 | 219 |
| 206 // compute the transformation params | 220 // compute the transformation params |
| 207 SkPoint center = SkPoint::Make(path.getBounds().centerX(), path.getBound
s().centerY()); | 221 SkPoint center = SkPoint::Make(path.getBounds().centerX(), path.getBound
s().centerY()); |
| 208 canvas->getTotalMatrix().mapPoints(¢er, 1); | 222 SkMatrix ctmInverse; |
| 209 SkPoint offset = SkPoint::Make(-zRatio*(lightPos.fX - center.fX), | 223 if (!canvas->getTotalMatrix().invert(&ctmInverse)) { |
| 210 -zRatio*(lightPos.fY - center.fY)); | 224 return; |
| 225 } |
| 226 SkPoint lightPos2D = SkPoint::Make(lightPos.fX, lightPos.fY); |
| 227 ctmInverse.mapPoints(&lightPos2D, 1); |
| 228 SkPoint offset = SkPoint::Make(zRatio*(center.fX - lightPos2D.fX), |
| 229 zRatio*(center.fY - lightPos2D.fY)); |
| 211 SkScalar scale = lightPos.fZ / (lightPos.fZ - zValue); | 230 SkScalar scale = lightPos.fZ / (lightPos.fZ - zValue); |
| 212 if (scale < 1.0f) { | |
| 213 scale = 1.0f; | |
| 214 } else if (scale > 1024.f) { | |
| 215 scale = 1024.f; | |
| 216 } | |
| 217 | 231 |
| 218 SkAutoCanvasRestore acr(canvas, true); | 232 SkAutoCanvasRestore acr(canvas, true); |
| 219 | 233 |
| 220 SkRect occlRect; | |
| 221 GetOcclRect(path, &occlRect); | |
| 222 // apply inverse transform | |
| 223 occlRect.offset(-offset); | |
| 224 #if 0 | |
| 225 // It looks like the scale may be invalid | |
| 226 SkScalar scale = lightPos.fZ / (lightPos.fZ - zValue); | |
| 227 if (scale < 1.0f) { | |
| 228 scale = 1.0f; | |
| 229 } else if (scale > 1024.f) { | |
| 230 scale = 1024.f; | |
| 231 } | |
| 232 occlRect.fLeft /= scale; | |
| 233 occlRect.fRight /= scale; | |
| 234 occlRect.fTop /= scale; | |
| 235 occlRect.fBottom /= scale; | |
| 236 #endif | |
| 237 sk_sp<SkMaskFilter> mf = SkBlurMaskFilter::Make(kNormal_SkBlurStyle, | 234 sk_sp<SkMaskFilter> mf = SkBlurMaskFilter::Make(kNormal_SkBlurStyle, |
| 238 SkBlurMask::ConvertRadiu
sToSigma(radius), | 235 SkBlurMask::ConvertRadiu
sToSigma(blurRadius), |
| 239 occlRect, | |
| 240 SkBlurMaskFilter::kNone_
BlurFlag); | 236 SkBlurMaskFilter::kNone_
BlurFlag); |
| 241 | 237 |
| 242 SkPaint paint; | 238 SkPaint paint; |
| 243 paint.setAntiAlias(true); | 239 paint.setAntiAlias(true); |
| 244 paint.setMaskFilter(std::move(mf)); | 240 paint.setMaskFilter(std::move(mf)); |
| 245 paint.setColor(SkColorSetARGB((unsigned char)(spotAlpha*255.999f), 0, 0,
0)); | 241 paint.setColor(SkColorSetARGB((unsigned char)(spotAlpha*255.999f), 0, 0,
0)); |
| 246 | 242 |
| 247 // apply transformation to shadow | 243 // apply transformation to shadow |
| 244 canvas->scale(scale, scale); |
| 248 canvas->translate(offset.fX, offset.fY); | 245 canvas->translate(offset.fX, offset.fY); |
| 249 #if 0 | |
| 250 // It looks like the scale may be invalid | |
| 251 canvas->scale(scale, scale); | |
| 252 #endif | |
| 253 canvas->drawPath(path, paint); | 246 canvas->drawPath(path, paint); |
| 254 | |
| 255 // draw occlusion rect | |
| 256 #if DRAW_OCCL_RECT | |
| 257 SkPaint stroke; | |
| 258 stroke.setStyle(SkPaint::kStroke_Style); | |
| 259 stroke.setColor(SK_ColorRED); | |
| 260 canvas->drawRect(occlRect, stroke) | |
| 261 #endif | |
| 262 } | 247 } |
| 263 | 248 |
| 264 void drawSpotShadowAlt(SkCanvas* canvas, const SkPath& path, SkScalar zValue
, | 249 void drawSpotShadowAlt(SkCanvas* canvas, const SkPath& path, SkScalar zValue
, |
| 265 SkPoint3 lightPos, SkScalar lightWidth, SkScalar spotAlp
ha) { | 250 SkPoint3 lightPos, SkScalar lightWidth, SkScalar spotAlp
ha) { |
| 266 if (spotAlpha <= 0) { | 251 if (spotAlpha <= 0) { |
| 267 return; | 252 return; |
| 268 } | 253 } |
| 269 | 254 |
| 270 SkScalar zRatio = zValue / (lightPos.fZ - zValue); | 255 SkScalar zRatio = zValue / (lightPos.fZ - zValue); |
| 271 if (zRatio < 0.0f) { | 256 if (zRatio < 0.0f) { |
| 272 zRatio = 0.0f; | 257 zRatio = 0.0f; |
| 273 } else if (zRatio > 0.95f) { | 258 } else if (zRatio > 0.95f) { |
| 274 zRatio = 0.95f; | 259 zRatio = 0.95f; |
| 275 } | 260 } |
| 276 SkScalar radius = lightWidth*zRatio; | 261 SkScalar radius = 2.0f*lightWidth*zRatio; |
| 277 | 262 |
| 278 SkRect pathRect; | 263 SkRect pathRect; |
| 279 SkRRect pathRRect; | 264 SkRRect pathRRect; |
| 280 if (radius >= 64 || | 265 SkScalar scaleFactors[2]; |
| 266 if (!canvas->getTotalMatrix().getMinMaxScales(scaleFactors)) { |
| 267 return; |
| 268 } |
| 269 if (scaleFactors[0] != scaleFactors[1] || radius*scaleFactors[0] >= 1638
4 || |
| 281 !((path.isOval(&pathRect) && pathRect.width() == pathRect.height())
|| | 270 !((path.isOval(&pathRect) && pathRect.width() == pathRect.height())
|| |
| 282 (path.isRRect(&pathRRect) && pathRRect.allCornersCircular()) || | 271 (path.isRRect(&pathRRect) && pathRRect.allCornersCircular()) || |
| 283 path.isRect(&pathRect))) { | 272 path.isRect(&pathRect))) { |
| 284 this->drawSpotShadow(canvas, path, zValue, lightPos, lightWidth, spo
tAlpha); | 273 this->drawSpotShadow(canvas, path, zValue, lightPos, lightWidth, spo
tAlpha); |
| 285 return; | 274 return; |
| 286 } | 275 } |
| 287 | 276 |
| 288 // For all of these, we outset the rect by half the radius to get our st
roke shape. | 277 // For all of these, we need to ensure we have a rrect with radius >= 0.
5f in device space |
| 289 SkScalar halfRadius = SK_ScalarHalf*radius; | 278 SkScalar minRadius = SK_ScalarHalf/scaleFactors[0]; |
| 290 if (path.isOval(nullptr)) { | 279 if (path.isOval(nullptr)) { |
| 291 pathRect.outset(halfRadius, halfRadius); | |
| 292 pathRRect = SkRRect::MakeOval(pathRect); | 280 pathRRect = SkRRect::MakeOval(pathRect); |
| 293 } else if (path.isRect(nullptr)) { | 281 } else if (path.isRect(nullptr)) { |
| 294 pathRect.outset(halfRadius, halfRadius); | 282 pathRRect = SkRRect::MakeRectXY(pathRect, minRadius, minRadius); |
| 295 pathRRect = SkRRect::MakeRectXY(pathRect, halfRadius, halfRadius); | |
| 296 } else { | 283 } else { |
| 297 pathRRect.outset(halfRadius, halfRadius); | 284 if (pathRRect.getSimpleRadii().fX < minRadius) { |
| 285 pathRRect.setRectXY(pathRRect.rect(), minRadius, minRadius); |
| 286 } |
| 298 } | 287 } |
| 299 | 288 |
| 300 // compute the transformation params | 289 // compute the scale and translation for the shadow |
| 301 SkPoint center = SkPoint::Make(path.getBounds().centerX(), path.getBound
s().centerY()); | 290 SkScalar scale = lightPos.fZ / (lightPos.fZ - zValue); |
| 302 canvas->getTotalMatrix().mapPoints(¢er, 1); | 291 SkRRect shadowRRect; |
| 303 SkPoint offset = SkPoint::Make(-zRatio*(lightPos.fX - center.fX), | 292 pathRRect.transform(SkMatrix::MakeScale(scale, scale), &shadowRRect); |
| 304 -zRatio*(lightPos.fY - center.fY)); | 293 SkPoint center = SkPoint::Make(shadowRRect.rect().centerX(), shadowRRect
.rect().centerY()); |
| 294 SkMatrix ctmInverse; |
| 295 if (!canvas->getTotalMatrix().invert(&ctmInverse)) { |
| 296 return; |
| 297 } |
| 298 SkPoint lightPos2D = SkPoint::Make(lightPos.fX, lightPos.fY); |
| 299 ctmInverse.mapPoints(&lightPos2D, 1); |
| 300 SkPoint offset = SkPoint::Make(zRatio*(center.fX - lightPos2D.fX), |
| 301 zRatio*(center.fY - lightPos2D.fY)); |
| 305 SkAutoCanvasRestore acr(canvas, true); | 302 SkAutoCanvasRestore acr(canvas, true); |
| 306 | 303 |
| 307 SkPaint paint; | 304 SkPaint paint; |
| 308 paint.setAntiAlias(true); | 305 paint.setAntiAlias(true); |
| 309 // We outset the stroke by the length of the translation so the shadow e
xtends to | 306 // We outset the stroke by the length of the translation so the shadow e
xtends to |
| 310 // the edge of the shape. We also add 1/2 to cover up AA on the interior
edge. | 307 // the edge of the shape. We also add 1/2 to cover up AA on the interior
edge. |
| 311 SkScalar pad = offset.length() + 0.5f; | 308 SkScalar pad = offset.length() + 0.5f; |
| 312 // compute area | 309 // compute area |
| 313 SkScalar strokeWidth = radius + 2.0f*pad; | 310 SkScalar strokeWidth = radius + 2.0f*pad/scaleFactors[0]; |
| 314 SkScalar strokedArea = 2.0f*strokeWidth*(pathRRect.width() + pathRRect.h
eight()); | 311 SkScalar strokedArea = 2.0f*strokeWidth*(shadowRRect.width() + shadowRRe
ct.height()); |
| 315 SkScalar filledArea = (pathRRect.height() + radius)*(pathRRect.width() +
radius); | 312 SkScalar filledArea = (shadowRRect.height() + radius)*(shadowRRect.width
() + radius); |
| 316 // If the area of the stroked geometry is larger than the fill geometry,
or | 313 // If the area of the stroked geometry is larger than the fill geometry,
or |
| 317 // if our pad is too big to convert to 6.2 fixed point, just fill it. | 314 // if our pad is too big to convert to 6.2 fixed point, just fill it. |
| 318 if (strokedArea > filledArea || pad >= 64) { | 315 if (strokedArea > filledArea || pad >= 64) { |
| 319 pad = 0; | 316 pad = 0; |
| 320 paint.setStyle(SkPaint::kStrokeAndFill_Style); | 317 paint.setStyle(SkPaint::kStrokeAndFill_Style); |
| 321 paint.setStrokeWidth(radius); | 318 paint.setStrokeWidth(radius); |
| 322 } else { | 319 } else { |
| 323 paint.setStyle(SkPaint::kStroke_Style); | 320 paint.setStyle(SkPaint::kStroke_Style); |
| 324 paint.setStrokeWidth(strokeWidth); | 321 paint.setStrokeWidth(strokeWidth); |
| 325 } | 322 } |
| 326 sk_sp<SkShader> gaussShader = SkGaussianEdgeShader::Make(); | 323 paint.setShader(SkGaussianEdgeShader::Make(true)); |
| 327 paint.setShader(gaussShader); | |
| 328 // handle scale of radius due to CTM | 324 // handle scale of radius due to CTM |
| 329 SkScalar maxScale = canvas->getTotalMatrix().getMaxScale(); | 325 radius *= scaleFactors[0]; |
| 330 radius *= maxScale; | 326 // don't need to scale pad as it was computed from the transformed offse
t |
| 331 unsigned char gray = (unsigned char)(spotAlpha*255.999f); | 327 SkASSERT(radius < 16384); |
| 332 SkASSERT(radius < 64); | |
| 333 SkASSERT(pad < 64); | 328 SkASSERT(pad < 64); |
| 334 // Convert radius and pad to 6.2 fixed point and place in the G & B comp
onents. | 329 // Convert radius to 14.2 fixed point and place in the R & G components. |
| 335 paint.setColor(SkColorSetARGB(1, gray, (unsigned char)(radius*4.0f), | 330 // Convert pad to 6.2 fixed point and place in the B component. |
| 336 (unsigned char)(pad*4.0f))); | 331 uint16_t iRadius = (uint16_t)(radius*4.0f); |
| 332 unsigned char alpha = (unsigned char)(spotAlpha*255.999f); |
| 333 paint.setColor(SkColorSetARGB(alpha, iRadius >> 8, iRadius & 0xff, |
| 334 (unsigned char)(4.0f*pad))); |
| 337 | 335 |
| 338 // apply transformation to shadow | 336 // apply transformation to shadow |
| 339 canvas->translate(offset.fX, offset.fY); | 337 canvas->translate(offset.fX, offset.fY); |
| 340 #if 0 | 338 canvas->drawRRect(shadowRRect, paint); |
| 341 // It looks like the scale may be invalid | |
| 342 SkScalar scale = lightPos.fZ / (lightPos.fZ - zValue); | |
| 343 if (scale < 1.0f) { | |
| 344 scale = 1.0f; | |
| 345 } else if (scale > 1024.f) { | |
| 346 scale = 1024.f; | |
| 347 } | |
| 348 canvas->scale(scale, scale); | |
| 349 #endif | |
| 350 canvas->drawRRect(pathRRect, paint); | |
| 351 } | 339 } |
| 352 | 340 |
| 353 void drawShadowedPath(SkCanvas* canvas, const SkPath& path, SkScalar zValue, | 341 void drawShadowedPath(SkCanvas* canvas, const SkPath& path, SkScalar zValue, |
| 354 const SkPaint& paint, SkScalar ambientAlpha, | 342 const SkPaint& paint, SkScalar ambientAlpha, |
| 355 const SkPoint3& lightPos, SkScalar lightWidth, SkScala
r spotAlpha) { | 343 const SkPoint3& lightPos, SkScalar lightWidth, SkScala
r spotAlpha) { |
| 356 if (fShowAmbient) { | 344 if (fShowAmbient) { |
| 357 if (fUseAlt) { | 345 if (fUseAlt) { |
| 358 this->drawAmbientShadowAlt(canvas, path, zValue, ambientAlpha); | 346 this->drawAmbientShadowAlt(canvas, path, zValue, ambientAlpha); |
| 359 } else { | 347 } else { |
| 360 this->drawAmbientShadow(canvas, path, zValue, ambientAlpha); | 348 this->drawAmbientShadow(canvas, path, zValue, ambientAlpha); |
| 361 } | 349 } |
| 362 } | 350 } |
| 363 if (fShowSpot) { | 351 if (fShowSpot) { |
| 364 if (fUseAlt) { | 352 if (fUseAlt) { |
| 365 this->drawSpotShadowAlt(canvas, path, zValue, lightPos, lightWid
th, spotAlpha); | 353 this->drawSpotShadowAlt(canvas, path, zValue, lightPos, lightWid
th, spotAlpha); |
| 366 } else { | 354 } else { |
| 367 this->drawSpotShadow(canvas, path, zValue, lightPos, lightWidth,
spotAlpha); | 355 this->drawSpotShadow(canvas, path, zValue, lightPos, lightWidth,
spotAlpha); |
| 368 } | 356 } |
| 369 } | 357 } |
| 370 if (fShowObject) { | 358 if (fShowObject) { |
| 371 canvas->drawPath(path, paint); | 359 canvas->drawPath(path, paint); |
| 372 } | 360 } |
| 373 } | 361 } |
| 374 | 362 |
| 375 void onDrawContent(SkCanvas* canvas) override { | 363 void onDrawContent(SkCanvas* canvas) override { |
| 376 this->drawBG(canvas); | 364 this->drawBG(canvas); |
| 377 const SkScalar kLightWidth = 3; | 365 const SkScalar kLightWidth = 2800; |
| 378 const SkScalar kAmbientAlpha = 0.25f; | 366 const SkScalar kAmbientAlpha = 0.25f; |
| 379 const SkScalar kSpotAlpha = 0.25f; | 367 const SkScalar kSpotAlpha = 0.25f; |
| 380 | 368 |
| 381 SkPaint paint; | 369 SkPaint paint; |
| 382 paint.setAntiAlias(true); | 370 paint.setAntiAlias(true); |
| 383 | 371 |
| 384 SkPoint3 lightPos = fLightPos; | 372 SkPoint3 lightPos = fLightPos; |
| 385 | 373 |
| 386 paint.setColor(SK_ColorWHITE); | 374 paint.setColor(SK_ColorWHITE); |
| 387 canvas->translate(200, 90); | 375 canvas->translate(200, 90); |
| 388 lightPos.fX += 200; | 376 lightPos.fX += 200; |
| 389 lightPos.fY += 90; | 377 lightPos.fY += 90; |
| 390 this->drawShadowedPath(canvas, fRectPath, 5, paint, kAmbientAlpha, | 378 this->drawShadowedPath(canvas, fRectPath, 2, paint, kAmbientAlpha, |
| 391 lightPos, kLightWidth, kSpotAlpha); | 379 lightPos, kLightWidth, kSpotAlpha); |
| 392 | 380 |
| 393 paint.setColor(SK_ColorRED); | 381 paint.setColor(SK_ColorRED); |
| 394 canvas->translate(250, 0); | 382 canvas->translate(250, 0); |
| 395 lightPos.fX += 250; | 383 lightPos.fX += 250; |
| 396 this->drawShadowedPath(canvas, fRRPath, 5, paint, kAmbientAlpha, | 384 this->drawShadowedPath(canvas, fRRPath, 4, paint, kAmbientAlpha, |
| 397 lightPos, kLightWidth, kSpotAlpha); | 385 lightPos, kLightWidth, kSpotAlpha); |
| 398 | 386 |
| 399 paint.setColor(SK_ColorBLUE); | 387 paint.setColor(SK_ColorBLUE); |
| 400 canvas->translate(-250, 110); | 388 canvas->translate(-250, 110); |
| 401 lightPos.fX -= 250; | 389 lightPos.fX -= 250; |
| 402 lightPos.fY += 110; | 390 lightPos.fY += 110; |
| 403 this->drawShadowedPath(canvas, fCirclePath, 5, paint, 0.0f, | 391 this->drawShadowedPath(canvas, fCirclePath, 8, paint, 0.0f, |
| 404 lightPos, kLightWidth, 0.5f); | 392 lightPos, kLightWidth, 0.5f); |
| 405 | 393 |
| 406 paint.setColor(SK_ColorGREEN); | 394 paint.setColor(SK_ColorGREEN); |
| 407 canvas->translate(250, 0); | 395 canvas->translate(250, 0); |
| 408 lightPos.fX += 250; | 396 lightPos.fX += 250; |
| 409 this->drawShadowedPath(canvas, fRRPath, 5, paint, kAmbientAlpha, | 397 this->drawShadowedPath(canvas, fRRPath, 64, paint, kAmbientAlpha, |
| 410 lightPos, kLightWidth, kSpotAlpha); | 398 lightPos, kLightWidth, kSpotAlpha); |
| 411 } | 399 } |
| 412 | 400 |
| 413 protected: | 401 protected: |
| 414 SkView::Click* onFindClickHandler(SkScalar x, SkScalar y, unsigned modi) ove
rride { | 402 SkView::Click* onFindClickHandler(SkScalar x, SkScalar y, unsigned modi) ove
rride { |
| 415 return new SkView::Click(this); | 403 return new SkView::Click(this); |
| 416 } | 404 } |
| 417 | 405 |
| 418 bool onClick(Click *click) override { | 406 bool onClick(Click *click) override { |
| 419 SkScalar x = click->fCurr.fX; | 407 SkScalar x = click->fCurr.fX; |
| (...skipping 12 matching lines...) Expand all Loading... |
| 432 } | 420 } |
| 433 | 421 |
| 434 private: | 422 private: |
| 435 typedef SkView INHERITED; | 423 typedef SkView INHERITED; |
| 436 }; | 424 }; |
| 437 | 425 |
| 438 ////////////////////////////////////////////////////////////////////////////// | 426 ////////////////////////////////////////////////////////////////////////////// |
| 439 | 427 |
| 440 static SkView* MyFactory() { return new ShadowsView; } | 428 static SkView* MyFactory() { return new ShadowsView; } |
| 441 static SkViewRegister reg(MyFactory); | 429 static SkViewRegister reg(MyFactory); |
| OLD | NEW |