Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(517)

Side by Side Diff: src/core/SkCanvas.cpp.orig

Issue 2224163005: Made shadows blurry (thru implementing variance mapping) (Closed) Base URL: https://skia.googlesource.com/skia@master
Patch Set: rebased off master again! Created 4 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 /* 1 /*
robertphillips 2016/08/23 17:19:40 rm this file
vjiaoblack 2016/08/23 18:01:21 Done.
2 * Copyright 2008 The Android Open Source Project 2 * Copyright 2008 The Android Open Source Project
3 * 3 *
4 * Use of this source code is governed by a BSD-style license that can be 4 * Use of this source code is governed by a BSD-style license that can be
5 * found in the LICENSE file. 5 * found in the LICENSE file.
6 */ 6 */
7 7
8 #include "SkBitmapDevice.h" 8 #include "SkBitmapDevice.h"
9 #include "SkCanvas.h" 9 #include "SkCanvas.h"
10 #include "SkCanvasPriv.h" 10 #include "SkCanvasPriv.h"
11 #include "SkClipStack.h" 11 #include "SkClipStack.h"
12 #include "SkColorFilter.h" 12 #include "SkColorFilter.h"
13 #include "SkDraw.h" 13 #include "SkDraw.h"
14 #include "SkDrawable.h" 14 #include "SkDrawable.h"
15 #include "SkDrawFilter.h" 15 #include "SkDrawFilter.h"
16 #include "SkDrawLooper.h" 16 #include "SkDrawLooper.h"
17 #include "SkErrorInternals.h" 17 #include "SkErrorInternals.h"
18 #include "SkImage.h" 18 #include "SkImage.h"
19 #include "SkImage_Base.h" 19 #include "SkImage_Base.h"
20 #include "SkImageFilter.h" 20 #include "SkImageFilter.h"
21 #include "SkImageFilterCache.h" 21 #include "SkImageFilterCache.h"
22 #include "SkLatticeIter.h" 22 #include "SkLatticeIter.h"
23 #include "SkMatrixUtils.h" 23 #include "SkMatrixUtils.h"
24 #include "SkMetaData.h" 24 #include "SkMetaData.h"
25 <<<<<<< 21114d931c32f34c1d25c68b25f3c2bf4c1d0f07
26 #include "SkNormalSource.h"
27 #include "SkPaintFilterCanvas.h"
25 #include "SkNx.h" 28 #include "SkNx.h"
29 =======
30 >>>>>>> Made req changes; added some sliders
26 #include "SkPaintPriv.h" 31 #include "SkPaintPriv.h"
27 #include "SkPatchUtils.h" 32 #include "SkPatchUtils.h"
28 #include "SkPicture.h" 33 #include "SkPicture.h"
29 #include "SkRasterClip.h" 34 #include "SkRasterClip.h"
30 #include "SkReadPixelsRec.h" 35 #include "SkReadPixelsRec.h"
31 #include "SkRRect.h" 36 #include "SkRRect.h"
32 #include "SkShadowPaintFilterCanvas.h" 37 #include "SkShadowPaintFilterCanvas.h"
33 #include "SkShadowShader.h" 38 #include "SkShadowShader.h"
34 #include "SkSmallAllocator.h" 39 #include "SkSmallAllocator.h"
35 #include "SkSpecialImage.h" 40 #include "SkSpecialImage.h"
36 #include "SkSurface_Base.h" 41 #include "SkSurface_Base.h"
37 #include "SkTextBlob.h" 42 #include "SkTextBlob.h"
38 #include "SkTextFormatParams.h" 43 #include "SkTextFormatParams.h"
39 #include "SkTLazy.h" 44 #include "SkTLazy.h"
40 #include "SkTraceEvent.h" 45 #include "SkTraceEvent.h"
41 46 #include "../../include/effects/SkBlurImageFilter.h"
42 #include <new> 47 #include <new>
43 48
44 #if SK_SUPPORT_GPU 49 #if SK_SUPPORT_GPU
45 #include "GrContext.h" 50 #include "GrContext.h"
46 #include "GrRenderTarget.h" 51 #include "GrRenderTarget.h"
47 #include "SkGrPriv.h" 52 #include "SkGrPriv.h"
53
48 #endif 54 #endif
49 55
50 #define RETURN_ON_NULL(ptr) do { if (nullptr == (ptr)) return; } while (0) 56 #define RETURN_ON_NULL(ptr) do { if (nullptr == (ptr)) return; } while (0)
51 57
52 //#define SK_SUPPORT_PRECHECK_CLIPRECT 58 //#define SK_SUPPORT_PRECHECK_CLIPRECT
53 59
54 /* 60 /*
55 * Return true if the drawing this rect would hit every pixels in the canvas. 61 * Return true if the drawing this rect would hit every pixels in the canvas.
56 * 62 *
57 * Returns false if 63 * Returns false if
(...skipping 1546 matching lines...) Expand 10 before | Expand all | Expand 10 after
1604 fClipStack->clipDevRect(devR, op, isAA); 1610 fClipStack->clipDevRect(devR, op, isAA);
1605 fMCRec->fRasterClip.op(devR, this->getTopLayerBounds(), op, isAA); 1611 fMCRec->fRasterClip.op(devR, this->getTopLayerBounds(), op, isAA);
1606 } else { 1612 } else {
1607 // since we're rotated or some such thing, we convert the rect to a path 1613 // since we're rotated or some such thing, we convert the rect to a path
1608 // and clip against that, since it can handle any matrix. However, to 1614 // and clip against that, since it can handle any matrix. However, to
1609 // avoid recursion in the case where we are subclassed (e.g. Pictures) 1615 // avoid recursion in the case where we are subclassed (e.g. Pictures)
1610 // we explicitly call "our" version of clipPath. 1616 // we explicitly call "our" version of clipPath.
1611 SkPath path; 1617 SkPath path;
1612 1618
1613 path.addRect(rect); 1619 path.addRect(rect);
1614 path.setIsVolatile(true);
1615 this->SkCanvas::onClipPath(path, op, edgeStyle); 1620 this->SkCanvas::onClipPath(path, op, edgeStyle);
1616 } 1621 }
1617 1622
1618 fDeviceClipBounds = qr_clip_bounds(fMCRec->fRasterClip.getBounds()); 1623 fDeviceClipBounds = qr_clip_bounds(fMCRec->fRasterClip.getBounds());
1619 } 1624 }
1620 1625
1621 void SkCanvas::clipRRect(const SkRRect& rrect, SkRegion::Op op, bool doAA) { 1626 void SkCanvas::clipRRect(const SkRRect& rrect, SkRegion::Op op, bool doAA) {
1622 this->checkForDeferredSave(); 1627 this->checkForDeferredSave();
1623 ClipEdgeStyle edgeStyle = doAA ? kSoft_ClipEdgeStyle : kHard_ClipEdgeStyle; 1628 ClipEdgeStyle edgeStyle = doAA ? kSoft_ClipEdgeStyle : kHard_ClipEdgeStyle;
1624 if (rrect.isRect()) { 1629 if (rrect.isRect()) {
(...skipping 16 matching lines...) Expand all
1641 fClipStack->clipDevRRect(transformedRRect, op, kSoft_ClipEdgeStyle == ed geStyle); 1646 fClipStack->clipDevRRect(transformedRRect, op, kSoft_ClipEdgeStyle == ed geStyle);
1642 1647
1643 fMCRec->fRasterClip.op(transformedRRect, this->getTopLayerBounds(), op, 1648 fMCRec->fRasterClip.op(transformedRRect, this->getTopLayerBounds(), op,
1644 kSoft_ClipEdgeStyle == edgeStyle); 1649 kSoft_ClipEdgeStyle == edgeStyle);
1645 fDeviceClipBounds = qr_clip_bounds(fMCRec->fRasterClip.getBounds()); 1650 fDeviceClipBounds = qr_clip_bounds(fMCRec->fRasterClip.getBounds());
1646 return; 1651 return;
1647 } 1652 }
1648 1653
1649 SkPath path; 1654 SkPath path;
1650 path.addRRect(rrect); 1655 path.addRRect(rrect);
1651 path.setIsVolatile(true);
1652 // call the non-virtual version 1656 // call the non-virtual version
1653 this->SkCanvas::onClipPath(path, op, edgeStyle); 1657 this->SkCanvas::onClipPath(path, op, edgeStyle);
1654 } 1658 }
1655 1659
1656 void SkCanvas::clipPath(const SkPath& path, SkRegion::Op op, bool doAA) { 1660 void SkCanvas::clipPath(const SkPath& path, SkRegion::Op op, bool doAA) {
1657 this->checkForDeferredSave(); 1661 this->checkForDeferredSave();
1658 ClipEdgeStyle edgeStyle = doAA ? kSoft_ClipEdgeStyle : kHard_ClipEdgeStyle; 1662 ClipEdgeStyle edgeStyle = doAA ? kSoft_ClipEdgeStyle : kHard_ClipEdgeStyle;
1659 1663
1660 if (!path.isInverseFillType() && fMCRec->fMatrix.rectStaysRect()) { 1664 if (!path.isInverseFillType() && fMCRec->fMatrix.rectStaysRect()) {
1661 SkRect r; 1665 SkRect r;
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
1698 #endif 1702 #endif
1699 1703
1700 AutoValidateClip avc(this); 1704 AutoValidateClip avc(this);
1701 1705
1702 fDeviceCMDirty = true; 1706 fDeviceCMDirty = true;
1703 if (!fAllowSoftClip) { 1707 if (!fAllowSoftClip) {
1704 edgeStyle = kHard_ClipEdgeStyle; 1708 edgeStyle = kHard_ClipEdgeStyle;
1705 } 1709 }
1706 1710
1707 SkPath devPath; 1711 SkPath devPath;
1708 if (fMCRec->fMatrix.isIdentity()) { 1712 path.transform(fMCRec->fMatrix, &devPath);
1709 devPath = path;
1710 } else {
1711 path.transform(fMCRec->fMatrix, &devPath);
1712 devPath.setIsVolatile(true);
1713 }
1714 1713
1715 // Check if the transfomation, or the original path itself 1714 // Check if the transfomation, or the original path itself
1716 // made us empty. Note this can also happen if we contained NaN 1715 // made us empty. Note this can also happen if we contained NaN
1717 // values. computing the bounds detects this, and will set our 1716 // values. computing the bounds detects this, and will set our
1718 // bounds to empty if that is the case. (see SkRect::set(pts, count)) 1717 // bounds to empty if that is the case. (see SkRect::set(pts, count))
1719 if (devPath.getBounds().isEmpty()) { 1718 if (devPath.getBounds().isEmpty()) {
1720 // resetting the path will remove any NaN or other wanky values 1719 // resetting the path will remove any NaN or other wanky values
1721 // that might upset our scan converter. 1720 // that might upset our scan converter.
1722 devPath.reset(); 1721 devPath.reset();
1723 } 1722 }
(...skipping 1432 matching lines...) Expand 10 before | Expand all | Expand 10 after
3156 } 3155 }
3157 } 3156 }
3158 3157
3159 SkAutoCanvasMatrixPaint acmp(this, matrix, paint, picture->cullRect()); 3158 SkAutoCanvasMatrixPaint acmp(this, matrix, paint, picture->cullRect());
3160 picture->playback(this); 3159 picture->playback(this);
3161 } 3160 }
3162 3161
3163 #ifdef SK_EXPERIMENTAL_SHADOWING 3162 #ifdef SK_EXPERIMENTAL_SHADOWING
3164 void SkCanvas::drawShadowedPicture(const SkPicture* picture, 3163 void SkCanvas::drawShadowedPicture(const SkPicture* picture,
3165 const SkMatrix* matrix, 3164 const SkMatrix* matrix,
3166 const SkPaint* paint) { 3165 const SkPaint* paint,
3166 const SkShadowParams& sParams) {
3167 RETURN_ON_NULL(picture); 3167 RETURN_ON_NULL(picture);
3168 3168
3169 TRACE_EVENT0("disabled-by-default-skia", "SkCanvas::drawShadowedPicture()"); 3169 TRACE_EVENT0("disabled-by-default-skia", "SkCanvas::drawShadowedPicture()");
3170 3170
3171 this->onDrawShadowedPicture(picture, matrix, paint); 3171 this->onDrawShadowedPicture(picture, matrix, paint, sParams);
3172 } 3172 }
3173 3173
3174 void SkCanvas::onDrawShadowedPicture(const SkPicture* picture, 3174 void SkCanvas::onDrawShadowedPicture(const SkPicture* picture,
3175 const SkMatrix* matrix, 3175 const SkMatrix* matrix,
3176 const SkPaint* paint) { 3176 const SkPaint* paint,
3177 const SkShadowParams& sParams) {
3177 if (!paint || paint->canComputeFastBounds()) { 3178 if (!paint || paint->canComputeFastBounds()) {
3178 SkRect bounds = picture->cullRect(); 3179 SkRect bounds = picture->cullRect();
3179 if (paint) { 3180 if (paint) {
3180 paint->computeFastBounds(bounds, &bounds); 3181 paint->computeFastBounds(bounds, &bounds);
3181 } 3182 }
3182 if (matrix) { 3183 if (matrix) {
3183 matrix->mapRect(&bounds); 3184 matrix->mapRect(&bounds);
3184 } 3185 }
3185 if (this->quickReject(bounds)) { 3186 if (this->quickReject(bounds)) {
3186 return; 3187 return;
3187 } 3188 }
3188 } 3189 }
3189 3190
3190 SkAutoCanvasMatrixPaint acmp(this, matrix, paint, picture->cullRect()); 3191 SkAutoCanvasMatrixPaint acmp(this, matrix, paint, picture->cullRect());
3191 3192
3193 sk_sp<SkImage> povDepthMap;
3194 sk_sp<SkImage> diffuseMap;
3195
3196 // TODO: pass the depth to the shader in vertices, or uniforms
3197 // so we don't have to render depth and color separately
3192 for (int i = 0; i < fLights->numLights(); ++i) { 3198 for (int i = 0; i < fLights->numLights(); ++i) {
3193 // skip over ambient lights; they don't cast shadows 3199 // skip over ambient lights; they don't cast shadows
3194 // lights that have shadow maps do not need updating (because lights are immutable) 3200 // lights that have shadow maps do not need updating (because lights are immutable)
3195 3201
3196 if (SkLights::Light::kAmbient_LightType == fLights->light(i).type() || 3202 if (SkLights::Light::kAmbient_LightType == fLights->light(i).type() ||
3197 fLights->light(i).getShadowMap() != nullptr) { 3203 fLights->light(i).getShadowMap() != nullptr) {
3198 continue; 3204 continue;
3199 } 3205 }
3200 3206
3201 // TODO: compute the correct size of the depth map from the light proper ties 3207 // TODO: compute the correct size of the depth map from the light proper ties
3202 // TODO: maybe add a kDepth_8_SkColorType 3208 // TODO: maybe add a kDepth_8_SkColorType
3203 // TODO: find actual max depth of picture 3209 // TODO: find actual max depth of picture
3204 SkISize shMapSize = SkShadowPaintFilterCanvas::ComputeDepthMapSize( 3210 SkISize shMapSize = SkShadowPaintFilterCanvas::ComputeDepthMapSize(
3205 fLights->light(i), 255, 3211 fLights->light(i), 255,
3206 picture->cullRect().width(), 3212 picture->cullRect().width(),
3207 picture->cullRect().height()); 3213 picture->cullRect().height());
3208 3214
3209 SkImageInfo info = SkImageInfo::Make(shMapSize.fWidth, shMapSize.fHeight , 3215 SkImageInfo info = SkImageInfo::Make(shMapSize.fWidth, shMapSize.fHeight ,
3210 kBGRA_8888_SkColorType, 3216 kBGRA_8888_SkColorType,
3211 kOpaque_SkAlphaType); 3217 kOpaque_SkAlphaType);
3212 3218
3213 // Create a new surface (that matches the backend of canvas) 3219 // Create a new surface (that matches the backend of canvas)
3214 // for each shadow map 3220 // for each shadow map
3215 sk_sp<SkSurface> surf(this->makeSurface(info)); 3221 sk_sp<SkSurface> surf(this->makeSurface(info));
3216 3222
3217 // Wrap another SPFCanvas around the surface 3223 // Wrap another SPFCanvas around the surface
3218 sk_sp<SkShadowPaintFilterCanvas> depthMapCanvas = 3224 sk_sp<SkShadowPaintFilterCanvas> depthMapCanvas =
3219 sk_make_sp<SkShadowPaintFilterCanvas>(surf->getCanvas()); 3225 sk_make_sp<SkShadowPaintFilterCanvas>(surf->getCanvas());
3226 depthMapCanvas->setShadowType(sParams);
3220 3227
3221 // set the depth map canvas to have the light we're drawing. 3228 // set the depth map canvas to have the light we're drawing.
3222 SkLights::Builder builder; 3229 SkLights::Builder builder;
3223 builder.add(fLights->light(i)); 3230 builder.add(fLights->light(i));
3224 sk_sp<SkLights> curLight = builder.finish(); 3231 sk_sp<SkLights> curLight = builder.finish();
3232 depthMapCanvas->setLights(std::move(curLight));
3225 3233
3226 depthMapCanvas->setLights(std::move(curLight));
3227 depthMapCanvas->drawPicture(picture); 3234 depthMapCanvas->drawPicture(picture);
3235 sk_sp<SkImage> depthMap = surf->makeImageSnapshot();
3228 3236
3229 fLights->light(i).setShadowMap(surf->makeImageSnapshot()); 3237 <<<<<<< 21114d931c32f34c1d25c68b25f3c2bf4c1d0f07
3230 } 3238 // curLight->light(0).setShadowMap(depthMap);
3231 3239
3232 sk_sp<SkImage> povDepthMap; 3240 // use another shader to perform the "shifting"
3233 sk_sp<SkImage> diffuseMap; 3241 //
3242 // sk_sp<SkShader> povDepthShader = povDepthMap->makeShader(SkShader::kCl amp_TileMode,
3243 // SkShader::kCl amp_TileMode);
3244 //
3245 //
3246 // sk_sp<SkShader> shadowMapShader = SkShadowMapShader::Make(povDepthShad er,
3247 // std::move(curLi ght),
3248 // diffuseMap->wid th(),
3249 // diffuseMap->hei ght());
3250 //
3251 // SkPaint paintSmall = *paint;
3252 // paintSmall.setShader(shadowMapShader);
3234 3253
3235 // TODO: pass the depth to the shader in vertices, or uniforms 3254 // draw this into small canvas
3236 // so we don't have to render depth and color separately 3255 // blur radius 10
3256 // SkImageInfo infoSmall = SkImageInfo::Make(shMapSize.fWidth, shMapSize. fHeight,
3257 // kBGRA_8888_SkColorType,
3258 // kOpaque_SkAlphaType);
3259 // sk_sp<SkSurface> surfSmall(this->makeSurface(infoSmall));
3260 // sk_sp<SkCanvas> depthMapCanvasSmall = sk_ref_sp(surfSmall->getCanvas() );
3261 // depthMapCanvasSmall->scale(shMapSize.fWidth / picture->cullRect().widt h(),
3262 // shMapSize.fHeight / picture->cullRect().hei ght());
3237 3263
3238 // povDepthMap 3264 // povDepthMap
3239 { 3265 {
3240 SkLights::Builder builder; 3266 SkLights::Builder builder;
3241 builder.add(SkLights::Light::MakeDirectional(SkColor3f::Make(1.0f, 1.0f, 1.0f), 3267 builder.add(SkLights::Light::MakeDirectional(SkColor3f::Make(1.0f, 1.0f, 1.0f),
3242 SkVector3::Make(0.0f, 0.0f, 1.0f))); 3268 SkVector3::Make(0.0f, 0.0f, 1.0f)));
3269
3270 // depthMapCanvasSmall->drawRect(SkRect::MakeIWH(infoSmall.width(),
3271 // infoSmall.height()), pai ntSmall);
3272 //
3273 // sk_sp<SkImage> finalDepthMap = surfSmall->makeImageSnapshot();
3274 //
3275 //
3276
3277 // blur depth map
3278 // SkImageInfo info2 = SkImageInfo::Make(shMapSize.fWidth, shMapSize.fHei ght,
3279 // kBGRA_8888_SkColorType,
3280 // kOpaque_SkAlphaType);
3281 // sk_sp<SkSurface> surf2(this->makeSurface(info2));
3282 // sk_sp<SkCanvas> depthMapCanvas2 = sk_ref_sp(surf2->getCanvas());
3283
3284 // SkPaint paint2;
3285
3286 // paint2.setFilterQuality(kHigh_SkFilterQuality);
3287 // depthMapCanvas2->scale(10.0f, 10.0f);
3288
3289
3290
3291 // paint2.setImageFilter(SkBlurImageFilter::Make(4.0f, 4.0f, nullptr));
3292 // SkRect asdf = SkRect::MakeIWH(400,400);
3293 // SkCanvas::SaveLayerRec rec(&asdf, &paint);
3294 // canvas->saveLayer(rec);
3295 // paint.setImageFilter(nullptr);
3296
3297
3298
3299 // depthMapCanvas2->drawImage(finalDepthMap, 0, 0, &paint2);
3300
3301
3302 sk_sp<SkImage> depthMap2 = surf->makeImageSnapshot();
3303
3304 SkPaint blurPaint;
3305 if (sType.fBlurAlgorithm != SkShadowType::kNoBlur_BlurAlgorithm) {
3306 blurPaint.setImageFilter(SkBlurImageFilter::Make(sType.fShadowRadius ,
3307 sType.fShadowRadius , nullptr));
3308 }
3309 =======
3310 if (sParams.fShadowType == SkShadowParams::kNoBlur_BlurAlgorithm) {
3311 fLights->light(i).setShadowMap(std::move(depthMap));
3312 } else if (sParams.fShadowType == SkShadowParams::kVariance_BlurAlgorith m) {
3313 // we blur the variance map
3314 SkPaint blurPaint;
3315 blurPaint.setImageFilter(SkBlurImageFilter::Make(sParams.fShadowRadi us,
3316 sParams.fShadowRadi us, nullptr));
3317 >>>>>>> Made req changes; added some sliders
3318
3319 SkImageInfo blurInfo = SkImageInfo::Make(shMapSize.fWidth, shMapSize .fHeight,
3320 kBGRA_8888_SkColorType,
3321 kOpaque_SkAlphaType);
3322
3323 sk_sp<SkSurface> blurSurf(this->makeSurface(blurInfo));
3324 sk_sp<SkCanvas> blurDepthMapCanvas = sk_ref_sp(blurSurf->getCanvas() );
3325
3326 blurDepthMapCanvas->drawImage(std::move(depthMap), 0, 0, &blurPaint) ;
3327
3328 fLights->light(i).setShadowMap(blurSurf->makeImageSnapshot());
3329 }
3330 }
3331
3332 // povDepthMap
3333 {
3334 SkLights::Builder builder;
3335 builder.add(SkLights::Light(SkColor3f::Make(1.0f, 1.0f, 1.0f),
3336 SkVector3::Make(0.0f, 0.0f, 1.0f)));
3243 sk_sp<SkLights> povLight = builder.finish(); 3337 sk_sp<SkLights> povLight = builder.finish();
3244 3338
3245 SkImageInfo info = SkImageInfo::Make(picture->cullRect().width(), 3339 SkImageInfo info = SkImageInfo::Make(picture->cullRect().width(),
3246 picture->cullRect().height(), 3340 picture->cullRect().height(),
3247 kBGRA_8888_SkColorType, 3341 kBGRA_8888_SkColorType,
3248 kOpaque_SkAlphaType); 3342 kOpaque_SkAlphaType);
3249 3343
3250 // Create a new surface (that matches the backend of canvas) 3344 // Create a new surface (that matches the backend of canvas)
3251 // to create the povDepthMap 3345 // to create the povDepthMap
3252 sk_sp<SkSurface> surf(this->makeSurface(info)); 3346 sk_sp<SkSurface> surf(this->makeSurface(info));
3253 3347
3254 // Wrap another SPFCanvas around the surface 3348 // Wrap another SPFCanvas around the surface
3255 sk_sp<SkShadowPaintFilterCanvas> depthMapCanvas = 3349 sk_sp<SkShadowPaintFilterCanvas> depthMapCanvas =
3256 sk_make_sp<SkShadowPaintFilterCanvas>(surf->getCanvas()); 3350 sk_make_sp<SkShadowPaintFilterCanvas>(surf->getCanvas());
3257 3351
3258 // set the depth map canvas to have the light as the user's POV 3352 // set the depth map canvas to have the light as the user's POV
3259 depthMapCanvas->setLights(std::move(povLight)); 3353 depthMapCanvas->setLights(std::move(povLight));
3260 3354
3261 depthMapCanvas->drawPicture(picture); 3355 depthMapCanvas->drawPicture(picture);
3262
3263 povDepthMap = surf->makeImageSnapshot(); 3356 povDepthMap = surf->makeImageSnapshot();
3264 } 3357 }
3265 3358
3266 // diffuseMap 3359 // diffuseMap
3267 { 3360 {
3268 SkImageInfo info = SkImageInfo::Make(picture->cullRect().width(), 3361 SkImageInfo info = SkImageInfo::Make(picture->cullRect().width(),
3269 picture->cullRect().height(), 3362 picture->cullRect().height(),
3270 kBGRA_8888_SkColorType, 3363 kBGRA_8888_SkColorType,
3271 kOpaque_SkAlphaType); 3364 kOpaque_SkAlphaType);
3272 3365
3273 sk_sp<SkSurface> surf(this->makeSurface(info)); 3366 sk_sp<SkSurface> surf(this->makeSurface(info));
3274 surf->getCanvas()->drawPicture(picture); 3367 surf->getCanvas()->drawPicture(picture);
3275 3368
3276 diffuseMap = surf->makeImageSnapshot(); 3369 diffuseMap = surf->makeImageSnapshot();
3277 } 3370 }
3278
3279 SkPaint shadowPaint; 3371 SkPaint shadowPaint;
3280 3372
3281 sk_sp<SkShader> povDepthShader = povDepthMap->makeShader(SkShader::kClamp_Ti leMode, 3373 sk_sp<SkShader> povDepthShader = povDepthMap->makeShader(SkShader::kClamp_Ti leMode,
3282 SkShader::kClamp_Ti leMode); 3374 SkShader::kClamp_Ti leMode);
3283
3284 sk_sp<SkShader> diffuseShader = diffuseMap->makeShader(SkShader::kClamp_Tile Mode, 3375 sk_sp<SkShader> diffuseShader = diffuseMap->makeShader(SkShader::kClamp_Tile Mode,
3285 SkShader::kClamp_Tile Mode); 3376 SkShader::kClamp_Tile Mode);
3286
3287 sk_sp<SkShader> shadowShader = SkShadowShader::Make(std::move(povDepthShader ), 3377 sk_sp<SkShader> shadowShader = SkShadowShader::Make(std::move(povDepthShader ),
3288 std::move(diffuseShader) , 3378 std::move(diffuseShader) ,
3289 std::move(fLights), 3379 std::move(fLights),
3290 diffuseMap->width(), 3380 diffuseMap->width(),
3291 diffuseMap->height()); 3381 diffuseMap->height(),
3382 sParams);
3292 3383
3293 shadowPaint.setShader(shadowShader); 3384 shadowPaint.setShader(shadowShader);
3294 3385
3295 this->drawRect(SkRect::MakeIWH(diffuseMap->width(), diffuseMap->height()), s hadowPaint); 3386 this->drawRect(SkRect::MakeIWH(diffuseMap->width(), diffuseMap->height()), s hadowPaint);
3296 } 3387 }
3297 #endif 3388 #endif
3298 3389
3299 /////////////////////////////////////////////////////////////////////////////// 3390 ///////////////////////////////////////////////////////////////////////////////
3300 /////////////////////////////////////////////////////////////////////////////// 3391 ///////////////////////////////////////////////////////////////////////////////
3301 3392
(...skipping 97 matching lines...) Expand 10 before | Expand all | Expand 10 after
3399 3490
3400 SkAutoCanvasMatrixPaint::~SkAutoCanvasMatrixPaint() { 3491 SkAutoCanvasMatrixPaint::~SkAutoCanvasMatrixPaint() {
3401 fCanvas->restoreToCount(fSaveCount); 3492 fCanvas->restoreToCount(fSaveCount);
3402 } 3493 }
3403 3494
3404 #ifdef SK_SUPPORT_LEGACY_NEW_SURFACE_API 3495 #ifdef SK_SUPPORT_LEGACY_NEW_SURFACE_API
3405 SkSurface* SkCanvas::newSurface(const SkImageInfo& info, const SkSurfaceProps* p rops) { 3496 SkSurface* SkCanvas::newSurface(const SkImageInfo& info, const SkSurfaceProps* p rops) {
3406 return this->makeSurface(info, props).release(); 3497 return this->makeSurface(info, props).release();
3407 } 3498 }
3408 #endif 3499 #endif
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698