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

Side by Side Diff: include/core/SkCanvas.h

Issue 2224163005: Made shadows blurry (thru implementing variance mapping) (Closed) Base URL: https://skia.googlesource.com/skia@master
Patch Set: Trying different include path 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
« no previous file with comments | « gyp/core.gypi ('k') | include/private/SkRecords.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 /* 1 /*
2 * Copyright 2006 The Android Open Source Project 2 * Copyright 2006 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 #ifndef SkCanvas_DEFINED 8 #ifndef SkCanvas_DEFINED
9 #define SkCanvas_DEFINED 9 #define SkCanvas_DEFINED
10 10
11 #include "SkTypes.h" 11 #include "SkTypes.h"
12 #include "SkBitmap.h" 12 #include "SkBitmap.h"
13 #include "SkDeque.h" 13 #include "SkDeque.h"
14 #include "SkImage.h" 14 #include "SkImage.h"
15 #include "SkPaint.h" 15 #include "SkPaint.h"
16 #include "SkRefCnt.h" 16 #include "SkRefCnt.h"
17 #include "SkRegion.h" 17 #include "SkRegion.h"
18 #include "SkSurfaceProps.h" 18 #include "SkSurfaceProps.h"
19 #include "SkXfermode.h" 19 #include "SkXfermode.h"
20 #include "SkLights.h" 20 #include "SkLights.h"
21 #include "../private/SkShadowParams.h"
21 22
22 class GrContext; 23 class GrContext;
23 class GrDrawContext; 24 class GrDrawContext;
24 class SkBaseDevice; 25 class SkBaseDevice;
25 class SkCanvasClipVisitor; 26 class SkCanvasClipVisitor;
26 class SkClipStack; 27 class SkClipStack;
27 class SkData; 28 class SkData;
28 class SkDraw; 29 class SkDraw;
29 class SkDrawable; 30 class SkDrawable;
30 class SkDrawFilter; 31 class SkDrawFilter;
(...skipping 1035 matching lines...) Expand 10 before | Expand all | Expand 10 after
1066 * This is logically equivalent to 1067 * This is logically equivalent to
1067 * saveLayer(paint)/drawPicture/restore 1068 * saveLayer(paint)/drawPicture/restore
1068 */ 1069 */
1069 void drawPicture(const SkPicture*, const SkMatrix* matrix, const SkPaint* pa int); 1070 void drawPicture(const SkPicture*, const SkMatrix* matrix, const SkPaint* pa int);
1070 void drawPicture(const sk_sp<SkPicture>& picture, const SkMatrix* matrix, co nst SkPaint* paint) { 1071 void drawPicture(const sk_sp<SkPicture>& picture, const SkMatrix* matrix, co nst SkPaint* paint) {
1071 this->drawPicture(picture.get(), matrix, paint); 1072 this->drawPicture(picture.get(), matrix, paint);
1072 } 1073 }
1073 1074
1074 #ifdef SK_EXPERIMENTAL_SHADOWING 1075 #ifdef SK_EXPERIMENTAL_SHADOWING
1075 /** 1076 /**
1076 * Draw the picture into this canvas. 1077 * Draw the picture into this canvas, with shadows!
1077 * 1078 *
1078 * We will use the canvas's lights along with the picture information (draw depths of 1079 * We will use the canvas's lights along with the picture information (draw depths of
1079 * objects, etc) to first create a set of shadowmaps for the light-picture pairs, and 1080 * objects, etc) to first create a set of shadowmaps for the light-picture pairs, and
1080 * then use that set of shadowmaps to render the scene with shadows. 1081 * then use that set of shadowmaps to render the scene with shadows.
1081 * 1082 *
1082 * If matrix is non-null, apply that matrix to the CTM when drawing this pi cture. This is 1083 * If matrix is non-null, apply that matrix to the CTM when drawing this pi cture. This is
1083 * logically equivalent to 1084 * logically equivalent to
1084 * save/concat/drawPicture/restore 1085 * save/concat/drawPicture/restore
1085 * 1086 *
1086 * If paint is non-null, draw the picture into a temporary buffer, and then apply the paint's 1087 * If paint is non-null, draw the picture into a temporary buffer, and then apply the paint's
1087 * alpha/colorfilter/imagefilter/xfermode to that buffer as it is drawn to the canvas. 1088 * alpha/colorfilter/imagefilter/xfermode to that buffer as it is drawn to the canvas.
1088 * This is logically equivalent to 1089 * This is logically equivalent to
1089 * saveLayer(paint)/drawPicture/restore 1090 * saveLayer(paint)/drawPicture/restore
1090 * 1091 *
1092 * We also support using variance shadow maps for blurred shadows; the user can specify
1093 * what shadow mapping algorithm to use with params.
1094 * - Variance Shadow Mapping works by storing both the depth and depth^2 in the shadow map.
1095 * - Then, the shadow map can be blurred, and when reading from it, the f ragment shader
1096 * can calculate the variance of the depth at a position by doing E(x^2 ) - E(x)^2.
1097 * - We can then use the depth variance and depth at a fragment to arrive at an upper bound
1098 * of the probability that the current surface is shadowed by using Che byshev's
1099 * inequality, and then use that to shade the fragment.
1100 *
1101 * - There are a few problems with VSM.
1102 * * Light Bleeding | Areas with high variance, such as near the edges of high up rects,
1103 * will cause their shadow penumbras to overwrite ot herwise solid
1104 * shadows.
1105 * * Shape Distortion | We can combat Light Bleeding by biasing the sha dow (setting
1106 * mostly shaded fragments to completely shaded) a nd increasing
1107 * the minimum allowed variance. However, this war ps and rounds
1108 * out the shape of the shadow.
1091 */ 1109 */
1092 void drawShadowedPicture(const SkPicture*, 1110 void drawShadowedPicture(const SkPicture*,
1093 const SkMatrix* matrix, 1111 const SkMatrix* matrix,
1094 const SkPaint* paint); 1112 const SkPaint* paint,
1113 const SkShadowParams& params);
1095 void drawShadowedPicture(const sk_sp<SkPicture>& picture, 1114 void drawShadowedPicture(const sk_sp<SkPicture>& picture,
1096 const SkMatrix* matrix, 1115 const SkMatrix* matrix,
1097 const SkPaint* paint) { 1116 const SkPaint* paint,
1098 this->drawShadowedPicture(picture.get(), matrix, paint); 1117 const SkShadowParams& params) {
1118 this->drawShadowedPicture(picture.get(), matrix, paint, params);
1099 } 1119 }
1100 #endif 1120 #endif
1101 1121
1102 enum VertexMode { 1122 enum VertexMode {
1103 kTriangles_VertexMode, 1123 kTriangles_VertexMode,
1104 kTriangleStrip_VertexMode, 1124 kTriangleStrip_VertexMode,
1105 kTriangleFan_VertexMode 1125 kTriangleFan_VertexMode
1106 }; 1126 };
1107 1127
1108 /** Draw the array of vertices, interpreted as triangles (based on mode). 1128 /** Draw the array of vertices, interpreted as triangles (based on mode).
(...skipping 318 matching lines...) Expand 10 before | Expand all | Expand 10 after
1427 virtual void onClipPath(const SkPath& path, SkRegion::Op op, ClipEdgeStyle e dgeStyle); 1447 virtual void onClipPath(const SkPath& path, SkRegion::Op op, ClipEdgeStyle e dgeStyle);
1428 virtual void onClipRegion(const SkRegion& deviceRgn, SkRegion::Op op); 1448 virtual void onClipRegion(const SkRegion& deviceRgn, SkRegion::Op op);
1429 1449
1430 virtual void onDiscard(); 1450 virtual void onDiscard();
1431 1451
1432 virtual void onDrawPicture(const SkPicture*, const SkMatrix*, const SkPaint* ); 1452 virtual void onDrawPicture(const SkPicture*, const SkMatrix*, const SkPaint* );
1433 1453
1434 #ifdef SK_EXPERIMENTAL_SHADOWING 1454 #ifdef SK_EXPERIMENTAL_SHADOWING
1435 virtual void onDrawShadowedPicture(const SkPicture*, 1455 virtual void onDrawShadowedPicture(const SkPicture*,
1436 const SkMatrix*, 1456 const SkMatrix*,
1437 const SkPaint*); 1457 const SkPaint*,
1458 const SkShadowParams& params);
1438 #endif 1459 #endif
1439 1460
1440 // Returns the canvas to be used by DrawIter. Default implementation 1461 // Returns the canvas to be used by DrawIter. Default implementation
1441 // returns this. Subclasses that encapsulate an indirect canvas may 1462 // returns this. Subclasses that encapsulate an indirect canvas may
1442 // need to overload this method. The impl must keep track of this, as it 1463 // need to overload this method. The impl must keep track of this, as it
1443 // is not released or deleted by the caller. 1464 // is not released or deleted by the caller.
1444 virtual SkCanvas* canvasForDrawIter(); 1465 virtual SkCanvas* canvasForDrawIter();
1445 1466
1446 // Clip rectangle bounds. Called internally by saveLayer. 1467 // Clip rectangle bounds. Called internally by saveLayer.
1447 // returns false if the entire rectangle is entirely clipped out 1468 // returns false if the entire rectangle is entirely clipped out
(...skipping 238 matching lines...) Expand 10 before | Expand all | Expand 10 after
1686 1707
1687 class SkCanvasClipVisitor { 1708 class SkCanvasClipVisitor {
1688 public: 1709 public:
1689 virtual ~SkCanvasClipVisitor(); 1710 virtual ~SkCanvasClipVisitor();
1690 virtual void clipRect(const SkRect&, SkRegion::Op, bool antialias) = 0; 1711 virtual void clipRect(const SkRect&, SkRegion::Op, bool antialias) = 0;
1691 virtual void clipRRect(const SkRRect&, SkRegion::Op, bool antialias) = 0; 1712 virtual void clipRRect(const SkRRect&, SkRegion::Op, bool antialias) = 0;
1692 virtual void clipPath(const SkPath&, SkRegion::Op, bool antialias) = 0; 1713 virtual void clipPath(const SkPath&, SkRegion::Op, bool antialias) = 0;
1693 }; 1714 };
1694 1715
1695 #endif 1716 #endif
OLDNEW
« no previous file with comments | « gyp/core.gypi ('k') | include/private/SkRecords.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698