| Index: src/core/SkCanvas.cpp.orig
|
| diff --git a/src/core/SkCanvas.cpp b/src/core/SkCanvas.cpp.orig
|
| similarity index 95%
|
| copy from src/core/SkCanvas.cpp
|
| copy to src/core/SkCanvas.cpp.orig
|
| index 8f77afe78e1ca955b668a647b046d773daa83f26..eb3fdf1bac163676c8cfd78f7c0ddc48805dd1b3 100644
|
| --- a/src/core/SkCanvas.cpp
|
| +++ b/src/core/SkCanvas.cpp.orig
|
| @@ -22,7 +22,12 @@
|
| #include "SkLatticeIter.h"
|
| #include "SkMatrixUtils.h"
|
| #include "SkMetaData.h"
|
| +<<<<<<< 21114d931c32f34c1d25c68b25f3c2bf4c1d0f07
|
| +#include "SkNormalSource.h"
|
| +#include "SkPaintFilterCanvas.h"
|
| #include "SkNx.h"
|
| +=======
|
| +>>>>>>> Made req changes; added some sliders
|
| #include "SkPaintPriv.h"
|
| #include "SkPatchUtils.h"
|
| #include "SkPicture.h"
|
| @@ -38,13 +43,14 @@
|
| #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)
|
| @@ -1611,7 +1617,6 @@ void SkCanvas::onClipRect(const SkRect& rect, SkRegion::Op op, ClipEdgeStyle edg
|
| SkPath path;
|
|
|
| path.addRect(rect);
|
| - path.setIsVolatile(true);
|
| this->SkCanvas::onClipPath(path, op, edgeStyle);
|
| }
|
|
|
| @@ -1648,7 +1653,6 @@ void SkCanvas::onClipRRect(const SkRRect& rrect, SkRegion::Op op, ClipEdgeStyle
|
|
|
| SkPath path;
|
| path.addRRect(rrect);
|
| - path.setIsVolatile(true);
|
| // call the non-virtual version
|
| this->SkCanvas::onClipPath(path, op, edgeStyle);
|
| }
|
| @@ -1705,12 +1709,7 @@ void SkCanvas::onClipPath(const SkPath& path, SkRegion::Op op, ClipEdgeStyle edg
|
| }
|
|
|
| SkPath devPath;
|
| - if (fMCRec->fMatrix.isIdentity()) {
|
| - devPath = path;
|
| - } else {
|
| - path.transform(fMCRec->fMatrix, &devPath);
|
| - devPath.setIsVolatile(true);
|
| - }
|
| + path.transform(fMCRec->fMatrix, &devPath);
|
|
|
| // Check if the transfomation, or the original path itself
|
| // made us empty. Note this can also happen if we contained NaN
|
| @@ -3163,17 +3162,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 SkShadowParams& sParams) {
|
| RETURN_ON_NULL(picture);
|
|
|
| TRACE_EVENT0("disabled-by-default-skia", "SkCanvas::drawShadowedPicture()");
|
|
|
| - this->onDrawShadowedPicture(picture, matrix, paint);
|
| + this->onDrawShadowedPicture(picture, matrix, paint, sParams);
|
| }
|
|
|
| void SkCanvas::onDrawShadowedPicture(const SkPicture* picture,
|
| const SkMatrix* matrix,
|
| - const SkPaint* paint) {
|
| + const SkPaint* paint,
|
| + const SkShadowParams& sParams) {
|
| if (!paint || paint->canComputeFastBounds()) {
|
| SkRect bounds = picture->cullRect();
|
| if (paint) {
|
| @@ -3189,6 +3190,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)
|
| @@ -3217,29 +3223,117 @@ void SkCanvas::onDrawShadowedPicture(const SkPicture* picture,
|
| // Wrap another SPFCanvas around the surface
|
| sk_sp<SkShadowPaintFilterCanvas> depthMapCanvas =
|
| sk_make_sp<SkShadowPaintFilterCanvas>(surf->getCanvas());
|
| + depthMapCanvas->setShadowType(sParams);
|
|
|
| // 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(std::move(curLight));
|
| +
|
| depthMapCanvas->drawPicture(picture);
|
| + sk_sp<SkImage> depthMap = surf->makeImageSnapshot();
|
| +
|
| +<<<<<<< 21114d931c32f34c1d25c68b25f3c2bf4c1d0f07
|
| +// curLight->light(0).setShadowMap(depthMap);
|
| +
|
| + // use another shader to perform the "shifting"
|
| +//
|
| +// sk_sp<SkShader> povDepthShader = povDepthMap->makeShader(SkShader::kClamp_TileMode,
|
| +// SkShader::kClamp_TileMode);
|
| +//
|
| +//
|
| +// sk_sp<SkShader> shadowMapShader = SkShadowMapShader::Make(povDepthShader,
|
| +// std::move(curLight),
|
| +// diffuseMap->width(),
|
| +// diffuseMap->height());
|
| +//
|
| +// SkPaint paintSmall = *paint;
|
| +// paintSmall.setShader(shadowMapShader);
|
| +
|
| + // draw this into small canvas
|
| + // blur radius 10
|
| +// SkImageInfo infoSmall = SkImageInfo::Make(shMapSize.fWidth, shMapSize.fHeight,
|
| +// kBGRA_8888_SkColorType,
|
| +// kOpaque_SkAlphaType);
|
| +// sk_sp<SkSurface> surfSmall(this->makeSurface(infoSmall));
|
| +// sk_sp<SkCanvas> depthMapCanvasSmall = sk_ref_sp(surfSmall->getCanvas());
|
| +// depthMapCanvasSmall->scale(shMapSize.fWidth / picture->cullRect().width(),
|
| +// shMapSize.fHeight / picture->cullRect().height());
|
|
|
| - fLights->light(i).setShadowMap(surf->makeImageSnapshot());
|
| - }
|
| + // povDepthMap
|
| + {
|
| + SkLights::Builder builder;
|
| + builder.add(SkLights::Light::MakeDirectional(SkColor3f::Make(1.0f, 1.0f, 1.0f),
|
| + SkVector3::Make(0.0f, 0.0f, 1.0f)));
|
|
|
| - sk_sp<SkImage> povDepthMap;
|
| - sk_sp<SkImage> diffuseMap;
|
| +// depthMapCanvasSmall->drawRect(SkRect::MakeIWH(infoSmall.width(),
|
| +// infoSmall.height()), paintSmall);
|
| +//
|
| +// sk_sp<SkImage> finalDepthMap = surfSmall->makeImageSnapshot();
|
| +//
|
| +//
|
|
|
| - // TODO: pass the depth to the shader in vertices, or uniforms
|
| - // so we don't have to render depth and color separately
|
| + // blur depth map
|
| +// SkImageInfo info2 = SkImageInfo::Make(shMapSize.fWidth, shMapSize.fHeight,
|
| +// kBGRA_8888_SkColorType,
|
| +// kOpaque_SkAlphaType);
|
| +// sk_sp<SkSurface> surf2(this->makeSurface(info2));
|
| +// sk_sp<SkCanvas> depthMapCanvas2 = sk_ref_sp(surf2->getCanvas());
|
| +
|
| +// SkPaint paint2;
|
| +
|
| +// paint2.setFilterQuality(kHigh_SkFilterQuality);
|
| +// depthMapCanvas2->scale(10.0f, 10.0f);
|
| +
|
| +
|
| +
|
| +// paint2.setImageFilter(SkBlurImageFilter::Make(4.0f, 4.0f, nullptr));
|
| +// SkRect asdf = SkRect::MakeIWH(400,400);
|
| +// SkCanvas::SaveLayerRec rec(&asdf, &paint);
|
| +// canvas->saveLayer(rec);
|
| +// paint.setImageFilter(nullptr);
|
| +
|
| +
|
| +
|
| +// depthMapCanvas2->drawImage(finalDepthMap, 0, 0, &paint2);
|
| +
|
| +
|
| + sk_sp<SkImage> depthMap2 = surf->makeImageSnapshot();
|
| +
|
| + SkPaint blurPaint;
|
| + if (sType.fBlurAlgorithm != SkShadowType::kNoBlur_BlurAlgorithm) {
|
| + blurPaint.setImageFilter(SkBlurImageFilter::Make(sType.fShadowRadius,
|
| + sType.fShadowRadius, nullptr));
|
| + }
|
| +=======
|
| + if (sParams.fShadowType == SkShadowParams::kNoBlur_BlurAlgorithm) {
|
| + fLights->light(i).setShadowMap(std::move(depthMap));
|
| + } else if (sParams.fShadowType == SkShadowParams::kVariance_BlurAlgorithm) {
|
| + // we blur the variance map
|
| + SkPaint blurPaint;
|
| + blurPaint.setImageFilter(SkBlurImageFilter::Make(sParams.fShadowRadius,
|
| + sParams.fShadowRadius, nullptr));
|
| +>>>>>>> Made req changes; added some sliders
|
| +
|
| + SkImageInfo blurInfo = SkImageInfo::Make(shMapSize.fWidth, shMapSize.fHeight,
|
| + kBGRA_8888_SkColorType,
|
| + kOpaque_SkAlphaType);
|
| +
|
| + sk_sp<SkSurface> blurSurf(this->makeSurface(blurInfo));
|
| + sk_sp<SkCanvas> blurDepthMapCanvas = sk_ref_sp(blurSurf->getCanvas());
|
| +
|
| + blurDepthMapCanvas->drawImage(std::move(depthMap), 0, 0, &blurPaint);
|
| +
|
| + fLights->light(i).setShadowMap(blurSurf->makeImageSnapshot());
|
| + }
|
| + }
|
|
|
| // povDepthMap
|
| {
|
| SkLights::Builder builder;
|
| - builder.add(SkLights::Light::MakeDirectional(SkColor3f::Make(1.0f, 1.0f, 1.0f),
|
| - SkVector3::Make(0.0f, 0.0f, 1.0f)));
|
| + builder.add(SkLights::Light(SkColor3f::Make(1.0f, 1.0f, 1.0f),
|
| + SkVector3::Make(0.0f, 0.0f, 1.0f)));
|
| sk_sp<SkLights> povLight = builder.finish();
|
|
|
| SkImageInfo info = SkImageInfo::Make(picture->cullRect().width(),
|
| @@ -3259,7 +3353,6 @@ void SkCanvas::onDrawShadowedPicture(const SkPicture* picture,
|
| depthMapCanvas->setLights(std::move(povLight));
|
|
|
| depthMapCanvas->drawPicture(picture);
|
| -
|
| povDepthMap = surf->makeImageSnapshot();
|
| }
|
|
|
| @@ -3275,20 +3368,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(),
|
| + sParams);
|
|
|
| shadowPaint.setShader(shadowShader);
|
|
|
|
|