Chromium Code Reviews| Index: src/core/SkCanvas.cpp |
| diff --git a/src/core/SkCanvas.cpp b/src/core/SkCanvas.cpp |
| index 24d9506bd79ca2719440e3f0f16cd09fb833f0ca..e6d868f20719025060b916ba3bf6512e92c9d131 100644 |
| --- a/src/core/SkCanvas.cpp |
| +++ b/src/core/SkCanvas.cpp |
| @@ -6,12 +6,14 @@ |
| */ |
| #include "SkBitmapDevice.h" |
| +#include "SkBitmapProcShader.h" |
| #include "SkCanvas.h" |
| #include "SkCanvasPriv.h" |
| #include "SkClipStack.h" |
| #include "SkColorFilter.h" |
| #include "SkDraw.h" |
| #include "SkDrawable.h" |
| +#include "GrDrawContext.h" |
| #include "SkDrawFilter.h" |
| #include "SkDrawLooper.h" |
| #include "SkErrorInternals.h" |
| @@ -20,30 +22,37 @@ |
| #include "SkImageFilter.h" |
| #include "SkImageFilterCache.h" |
| #include "SkLatticeIter.h" |
| +#include "SkLights.h" |
| +#include "SkMatrix.h" |
| #include "SkMatrixUtils.h" |
| #include "SkMetaData.h" |
| +#include "SkNormalSource.h" |
| +#include "SkPaintFilterCanvas.h" |
| #include "SkPaintPriv.h" |
| #include "SkPatchUtils.h" |
| #include "SkPicture.h" |
| +#include "SkPictureRecorder.h" |
| #include "SkRasterClip.h" |
| #include "SkReadPixelsRec.h" |
| #include "SkRRect.h" |
| #include "SkShadowPaintFilterCanvas.h" |
| -#include "SkShadowShader.h" |
| #include "SkSmallAllocator.h" |
| #include "SkSpecialImage.h" |
| +#include "SkSurface.h" |
| #include "SkSurface_Base.h" |
| #include "SkTextBlob.h" |
| #include "SkTextFormatParams.h" |
| #include "SkTLazy.h" |
| #include "SkTraceEvent.h" |
| - |
| +#include "../../include/effects/SkBlurImageFilter.h" |
| #include <new> |
| #if SK_SUPPORT_GPU |
| #include "GrContext.h" |
| #include "GrRenderTarget.h" |
| #include "SkGrPriv.h" |
| +#include "SkShadowShader.h" |
| + |
| #endif |
| #define RETURN_ON_NULL(ptr) do { if (nullptr == (ptr)) return; } while (0) |
| @@ -3060,17 +3069,19 @@ void SkCanvas::onDrawPicture(const SkPicture* picture, const SkMatrix* matrix, |
| #ifdef SK_EXPERIMENTAL_SHADOWING |
| void SkCanvas::drawShadowedPicture(const SkPicture* picture, |
| const SkMatrix* matrix, |
| - const SkPaint* paint) { |
| + const SkPaint* paint, |
| + const SkShadowType sType) { |
|
jvanverth1
2016/08/15 15:14:43
const SkShadowType& sType. By using a ref you pass
vjiaoblack
2016/08/15 17:43:30
Done.
|
| RETURN_ON_NULL(picture); |
| TRACE_EVENT0("disabled-by-default-skia", "SkCanvas::drawShadowedPicture()"); |
| - this->onDrawShadowedPicture(picture, matrix, paint); |
| + this->onDrawShadowedPicture(picture, matrix, paint, sType); |
| } |
| void SkCanvas::onDrawShadowedPicture(const SkPicture* picture, |
| const SkMatrix* matrix, |
| - const SkPaint* paint) { |
| + const SkPaint* paint, |
| + const SkShadowType sType) { |
|
jvanverth1
2016/08/15 16:37:16
const &
vjiaoblack
2016/08/15 17:43:30
Done.
|
| if (!paint || paint->canComputeFastBounds()) { |
| SkRect bounds = picture->cullRect(); |
| if (paint) { |
| @@ -3086,6 +3097,11 @@ void SkCanvas::onDrawShadowedPicture(const SkPicture* picture, |
| SkAutoCanvasMatrixPaint acmp(this, matrix, paint, picture->cullRect()); |
| + sk_sp<SkImage> povDepthMap; |
| + sk_sp<SkImage> diffuseMap; |
| + |
| + // TODO: pass the depth to the shader in vertices, or uniforms |
| + // so we don't have to render depth and color separately |
| for (int i = 0; i < fLights->numLights(); ++i) { |
| // skip over ambient lights; they don't cast shadows |
| // lights that have shadow maps do not need updating (because lights are immutable) |
| @@ -3114,23 +3130,35 @@ void SkCanvas::onDrawShadowedPicture(const SkPicture* picture, |
| // Wrap another SPFCanvas around the surface |
| sk_sp<SkShadowPaintFilterCanvas> depthMapCanvas = |
| sk_make_sp<SkShadowPaintFilterCanvas>(surf->getCanvas()); |
| + depthMapCanvas->setShadowType(sType); |
| // set the depth map canvas to have the light we're drawing. |
| SkLights::Builder builder; |
| builder.add(fLights->light(i)); |
| sk_sp<SkLights> curLight = builder.finish(); |
| + depthMapCanvas->setLights(curLight); |
| - depthMapCanvas->setLights(std::move(curLight)); |
| depthMapCanvas->drawPicture(picture); |
| + sk_sp<SkImage> depthMap = surf->makeImageSnapshot(); |
| - fLights->light(i).setShadowMap(surf->makeImageSnapshot()); |
| - } |
| + // we blur the variance map |
| + SkPaint blurPaint; |
| + if (sType.fBlurAlgorithm != SkShadowType::kNoBlur_BlurAlgorithm) { |
| + blurPaint.setImageFilter(SkBlurImageFilter::Make(sType.fShadowRadius, |
| + sType.fShadowRadius, nullptr)); |
| + } |
| - sk_sp<SkImage> povDepthMap; |
| - sk_sp<SkImage> diffuseMap; |
| + SkImageInfo blurInfo = SkImageInfo::Make(shMapSize.fWidth, shMapSize.fHeight, |
| + kBGRA_8888_SkColorType, |
| + kOpaque_SkAlphaType); |
| - // TODO: pass the depth to the shader in vertices, or uniforms |
| - // so we don't have to render depth and color separately |
| + sk_sp<SkSurface> blurSurf(this->makeSurface(blurInfo)); |
| + sk_sp<SkCanvas> blurDepthMapCanvas = sk_ref_sp(blurSurf->getCanvas()); |
| + |
| + blurDepthMapCanvas->drawImage(depthMap, 0, 0, &blurPaint); |
| + |
| + fLights->light(i).setShadowMap(blurSurf->makeImageSnapshot()); |
| + } |
| // povDepthMap |
| { |
| @@ -3156,7 +3184,6 @@ void SkCanvas::onDrawShadowedPicture(const SkPicture* picture, |
| depthMapCanvas->setLights(std::move(povLight)); |
| depthMapCanvas->drawPicture(picture); |
| - |
| povDepthMap = surf->makeImageSnapshot(); |
| } |
| @@ -3172,20 +3199,18 @@ void SkCanvas::onDrawShadowedPicture(const SkPicture* picture, |
| diffuseMap = surf->makeImageSnapshot(); |
| } |
| - |
| SkPaint shadowPaint; |
| sk_sp<SkShader> povDepthShader = povDepthMap->makeShader(SkShader::kClamp_TileMode, |
| SkShader::kClamp_TileMode); |
| - |
| sk_sp<SkShader> diffuseShader = diffuseMap->makeShader(SkShader::kClamp_TileMode, |
| SkShader::kClamp_TileMode); |
| - |
| sk_sp<SkShader> shadowShader = SkShadowShader::Make(std::move(povDepthShader), |
| std::move(diffuseShader), |
| std::move(fLights), |
| diffuseMap->width(), |
| - diffuseMap->height()); |
| + diffuseMap->height(), |
| + sType); |
| shadowPaint.setShader(shadowShader); |