Chromium Code Reviews| Index: src/core/SkCanvas.cpp |
| diff --git a/src/core/SkCanvas.cpp b/src/core/SkCanvas.cpp |
| index 24d9506bd79ca2719440e3f0f16cd09fb833f0ca..a79c1c2052e45fee26038fd0dbbd50300bb51a4d 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,38 @@ |
| #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" |
| +#include "SkShadowMapShader.h" |
| + |
| #endif |
| #define RETURN_ON_NULL(ptr) do { if (nullptr == (ptr)) return; } while (0) |
| @@ -3060,17 +3070,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, |
| + SkShadowType sType) { |
| 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, |
| + SkShadowType sType) { |
| if (!paint || paint->canComputeFastBounds()) { |
| SkRect bounds = picture->cullRect(); |
| if (paint) { |
| @@ -3086,6 +3098,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 +3131,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 paint2; |
|
jvanverth1
2016/08/12 17:39:08
Suggestion: SkPaint blurPaint;
vjiaoblack
2016/08/12 19:07:42
Done.
|
| + if (sType.fBlurAlgorithm != SkShadowType::kNoBlur_BlurAlgorithm) { |
| + paint2.setImageFilter(SkBlurImageFilter::Make(sType.fShadowRadius, |
| + sType.fShadowRadius, nullptr)); |
| + } |
| - sk_sp<SkImage> povDepthMap; |
| - sk_sp<SkImage> diffuseMap; |
| + SkImageInfo info2 = SkImageInfo::Make(shMapSize.fWidth, shMapSize.fHeight, |
|
jvanverth1
2016/08/12 17:39:08
Suggestion: rename to blurInfo, blurSurface, blurr
vjiaoblack
2016/08/12 19:07:42
Done.
|
| + kBGRA_8888_SkColorType, |
|
jvanverth1
2016/08/12 17:39:08
Nit: align just past (
vjiaoblack
2016/08/12 19:07:42
Done.
|
| + 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> surf2(this->makeSurface(info2)); |
| + sk_sp<SkCanvas> depthMapCanvas2 = sk_ref_sp(surf2->getCanvas()); |
| + |
| + depthMapCanvas2->drawImage(depthMap, 0, 0, &paint2); |
| + |
| + fLights->light(i).setShadowMap(surf2->makeImageSnapshot()); |
| + } |
| // povDepthMap |
| { |
| @@ -3156,7 +3185,6 @@ void SkCanvas::onDrawShadowedPicture(const SkPicture* picture, |
| depthMapCanvas->setLights(std::move(povLight)); |
| depthMapCanvas->drawPicture(picture); |
| - |
| povDepthMap = surf->makeImageSnapshot(); |
| } |
| @@ -3172,20 +3200,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); |