Chromium Code Reviews| Index: src/core/SkCanvas.cpp |
| diff --git a/src/core/SkCanvas.cpp b/src/core/SkCanvas.cpp |
| index d42c726c6c6a24c6ca7689bc68937ba616d1c710..137288eec18e773c4b7c8dc35c5476630c240739 100644 |
| --- a/src/core/SkCanvas.cpp |
| +++ b/src/core/SkCanvas.cpp |
| @@ -37,11 +37,14 @@ |
| #include "SkTraceEvent.h" |
| #include <new> |
|
robertphillips
2016/08/08 14:18:31
put with others
vjiaoblack
2016/08/08 15:48:32
Done.
|
| +#include <SkShadowPaintFilterCanvas.h> |
|
jvanverth1
2016/08/08 14:15:47
No <>, put up with the other Sk includes.
vjiaoblack
2016/08/08 15:48:32
Done.
|
| #if SK_SUPPORT_GPU |
| #include "GrContext.h" |
| #include "GrRenderTarget.h" |
| #include "SkGrPriv.h" |
|
robertphillips
2016/08/08 14:18:32
put with the Sk headers ?
vjiaoblack
2016/08/08 15:48:32
Done.
|
| +#include "SkShadowShader.h" |
| + |
| #endif |
| #define RETURN_ON_NULL(ptr) do { if (nullptr == (ptr)) return; } while (0) |
| @@ -3066,10 +3069,117 @@ void SkCanvas::drawShadowedPicture(const SkPicture* picture, |
| this->onDrawShadowedPicture(picture, matrix, paint); |
| } |
|
robertphillips
2016/08/08 14:18:32
put with Gr headers ?
vjiaoblack
2016/08/08 15:48:32
Done.
|
| +#include "GrDrawContext.h" |
|
jvanverth1
2016/08/08 14:15:47
This belongs at the top of the file in the SK_SUPP
robertphillips
2016/08/08 14:18:31
Need to handle matrix parameter too
vjiaoblack
2016/08/08 15:48:31
Done.
vjiaoblack
2016/08/08 15:48:32
Done.
|
| void SkCanvas::onDrawShadowedPicture(const SkPicture* picture, |
| const SkMatrix* matrix, |
| const SkPaint* paint) { |
| - this->onDrawPicture(picture, matrix, paint); |
| + 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) |
| + |
| + if (SkLights::Light::kAmbient_LightType == fLights->light(i).type() || |
| + fLights->light(i).getShadowMap() != nullptr) { |
| + continue; |
| + } |
| + |
| + // TODO: compute the correct size of the depth map from the light properties |
| + // TODO: maybe add a kDepth_8_SkColorType |
| + // TODO: find actual max depth of picture |
| + SkISize shMapSize = SkShadowPaintFilterCanvas:: |
|
robertphillips
2016/08/08 14:18:32
put the method name on the same line as its class
vjiaoblack
2016/08/08 15:48:31
Done.
|
| + ComputeDepthMapSize(fLights->light(i), 255, |
| + picture->cullRect().width(), |
| + picture->cullRect().height()); |
| + |
| + SkImageInfo info = SkImageInfo::Make(shMapSize.fWidth, shMapSize.fHeight, |
| + kBGRA_8888_SkColorType, |
| + kOpaque_SkAlphaType); |
| + |
| + // Create a new surface (that matches the backend of canvas) |
| + // for each shadow map |
| + sk_sp<SkSurface> surf(this->makeSurface(info)); |
| + |
| + // Wrap another SPFCanvas around the surface |
| + sk_sp<SkShadowPaintFilterCanvas> depthMapCanvas = |
| + sk_make_sp<SkShadowPaintFilterCanvas>(surf->getCanvas()); |
| + |
| + // 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); |
| + |
| + fLights->light(i).setShadowMap(surf->makeImageSnapshot()); |
| + } |
| + |
| + 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 |
| + |
| + // povDepthMap |
| + { |
| + SkLights::Builder builder; |
| + 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(), |
| + picture->cullRect().height(), |
| + kBGRA_8888_SkColorType, |
| + kOpaque_SkAlphaType); |
| + |
| + // Create a new surface (that matches the backend of canvas) |
| + // to create the povDepthMap |
| + sk_sp<SkSurface> surf(this->makeSurface(info)); |
| + |
| + // Wrap another SPFCanvas around the surface |
| + sk_sp<SkShadowPaintFilterCanvas> depthMapCanvas = |
| + sk_make_sp<SkShadowPaintFilterCanvas>(surf->getCanvas()); |
| + |
| + // set the depth map canvas to have the light as the user's POV |
| + depthMapCanvas->setLights(std::move(povLight)); |
| + |
| + depthMapCanvas->drawPicture(picture); |
| + |
| + povDepthMap = surf->makeImageSnapshot(); |
| + } |
| + |
| + // diffuseMap |
| + { |
| + SkImageInfo info = SkImageInfo::Make(picture->cullRect().width(), |
| + picture->cullRect().height(), |
| + kBGRA_8888_SkColorType, |
| + kOpaque_SkAlphaType); |
| + |
| + sk_sp<SkSurface> surf(this->makeSurface(info)); |
| + surf->getCanvas()->drawPicture(picture); |
| + |
| + diffuseMap = surf->makeImageSnapshot(); |
| + } |
| + |
|
robertphillips
2016/08/08 14:18:31
handle nullptr parameter here
vjiaoblack
2016/08/08 15:48:31
Done.
|
| + SkPaint paint2 = *paint; |
| + |
| + sk_sp<SkShader> povDepthShader = povDepthMap->makeShader(SkShader::kClamp_TileMode, |
|
robertphillips
2016/08/08 14:18:31
line up
vjiaoblack
2016/08/08 15:48:32
Done.
|
| + SkShader::kClamp_TileMode); |
| + |
| + sk_sp<SkShader> diffuseShader = diffuseMap->makeShader(SkShader::kClamp_TileMode, |
|
robertphillips
2016/08/08 14:18:32
line up
vjiaoblack
2016/08/08 15:48:32
Done.
|
| + SkShader::kClamp_TileMode); |
| + |
| + sk_sp<SkShader> shadowShader = SkShadowShader::Make(std::move(povDepthShader), |
| + std::move(diffuseShader), |
| + std::move(fLights), |
| + diffuseMap->width(), |
| + diffuseMap->height()); |
| + |
| + paint2.setShader(shadowShader); |
| + |
| + this->drawRect(SkRect::MakeIWH(diffuseMap->width(), diffuseMap->height()), paint2); |
|
robertphillips
2016/08/08 14:18:32
extra \ns
vjiaoblack
2016/08/08 15:48:32
Done.
|
| + |
| + |
| + |
| } |
| #endif |