Index: src/core/SkCanvas.cpp |
diff --git a/src/core/SkCanvas.cpp b/src/core/SkCanvas.cpp |
index 24d9506bd79ca2719440e3f0f16cd09fb833f0ca..69caace5d361bf0095ce0859bc5fb9e40e07ed65 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" |
robertphillips
2016/08/15 23:00:25
Why do we need GrDrawContext ?
Or most of these n
vjiaoblack
2016/08/16 14:16:40
Done.
|
+#include "GrDrawContext.h" |
#include "SkDrawFilter.h" |
#include "SkDrawLooper.h" |
#include "SkErrorInternals.h" |
@@ -20,11 +22,16 @@ |
#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" |
@@ -32,18 +39,20 @@ |
#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" |
+ |
#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) { |
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) { |
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(); |
robertphillips
2016/08/15 23:00:25
why rm the std::move ?
vjiaoblack
2016/08/16 14:16:40
Done.
|
+ 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; |
robertphillips
2016/08/15 23:00:25
For no blur we shouldn't be doing the draw at all
vjiaoblack
2016/08/16 14:16:40
True.
Done.
|
+ 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); |