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

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: Moved SkShadowType to SkCanvas Created 4 years, 4 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 /*
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
(...skipping 21 matching lines...) Expand all
32 class SkMetaData; 32 class SkMetaData;
33 class SkPath; 33 class SkPath;
34 class SkPicture; 34 class SkPicture;
35 class SkPixmap; 35 class SkPixmap;
36 class SkRasterClip; 36 class SkRasterClip;
37 class SkRRect; 37 class SkRRect;
38 struct SkRSXform; 38 struct SkRSXform;
39 class SkSurface; 39 class SkSurface;
40 class SkSurface_Base; 40 class SkSurface_Base;
41 class SkTextBlob; 41 class SkTextBlob;
42 42
robertphillips 2016/08/15 23:00:24 Would SkShadowParams be clearer? dox!
vjiaoblack 2016/08/16 14:16:40 Done.
43 struct SkShadowType {
44 SkScalar fShadowRadius;
45 SkScalar fBiasingConstant;
46 SkScalar fMinVariance;
47
48 enum BlurAlgorithm {
49 kNoBlur_BlurAlgorithm,
50 kVariance_BlurAlgorithm
51 };
52 BlurAlgorithm fBlurAlgorithm;
53 };
54
43 /** \class SkCanvas 55 /** \class SkCanvas
44 56
45 A Canvas encapsulates all of the state about drawing into a device (bitmap). 57 A Canvas encapsulates all of the state about drawing into a device (bitmap).
46 This includes a reference to the device itself, and a stack of matrix/clip 58 This includes a reference to the device itself, and a stack of matrix/clip
47 values. For any given draw call (e.g. drawRect), the geometry of the object 59 values. For any given draw call (e.g. drawRect), the geometry of the object
48 being drawn is transformed by the concatenation of all the matrices in the 60 being drawn is transformed by the concatenation of all the matrices in the
49 stack. The transformed geometry is clipped by the intersection of all of 61 stack. The transformed geometry is clipped by the intersection of all of
50 the clips in the stack. 62 the clips in the stack.
51 63
52 While the Canvas holds the state of the drawing device, the state (style) 64 While the Canvas holds the state of the drawing device, the state (style)
(...skipping 1044 matching lines...) Expand 10 before | Expand all | Expand 10 after
1097 * This is logically equivalent to 1109 * This is logically equivalent to
1098 * saveLayer(paint)/drawPicture/restore 1110 * saveLayer(paint)/drawPicture/restore
1099 */ 1111 */
1100 void drawPicture(const SkPicture*, const SkMatrix* matrix, const SkPaint* pa int); 1112 void drawPicture(const SkPicture*, const SkMatrix* matrix, const SkPaint* pa int);
1101 void drawPicture(const sk_sp<SkPicture>& picture, const SkMatrix* matrix, co nst SkPaint* paint) { 1113 void drawPicture(const sk_sp<SkPicture>& picture, const SkMatrix* matrix, co nst SkPaint* paint) {
1102 this->drawPicture(picture.get(), matrix, paint); 1114 this->drawPicture(picture.get(), matrix, paint);
1103 } 1115 }
1104 1116
1105 #ifdef SK_EXPERIMENTAL_SHADOWING 1117 #ifdef SK_EXPERIMENTAL_SHADOWING
1106 /** 1118 /**
1107 * Draw the picture into this canvas. 1119 * Draw the picture into this canvas, with shadows!
1108 * 1120 *
1109 * We will use the canvas's lights along with the picture information (draw depths of 1121 * We will use the canvas's lights along with the picture information (draw depths of
1110 * objects, etc) to first create a set of shadowmaps for the light-picture pairs, and 1122 * objects, etc) to first create a set of shadowmaps for the light-picture pairs, and
1111 * then use that set of shadowmaps to render the scene with shadows. 1123 * then use that set of shadowmaps to render the scene with shadows.
1112 * 1124 *
1113 * If matrix is non-null, apply that matrix to the CTM when drawing this pi cture. This is 1125 * If matrix is non-null, apply that matrix to the CTM when drawing this pi cture. This is
1114 * logically equivalent to 1126 * logically equivalent to
1115 * save/concat/drawPicture/restore 1127 * save/concat/drawPicture/restore
1116 * 1128 *
1117 * If paint is non-null, draw the picture into a temporary buffer, and then apply the paint's 1129 * If paint is non-null, draw the picture into a temporary buffer, and then apply the paint's
1118 * alpha/colorfilter/imagefilter/xfermode to that buffer as it is drawn to the canvas. 1130 * alpha/colorfilter/imagefilter/xfermode to that buffer as it is drawn to the canvas.
1119 * This is logically equivalent to 1131 * This is logically equivalent to
1120 * saveLayer(paint)/drawPicture/restore 1132 * saveLayer(paint)/drawPicture/restore
1121 * 1133 *
1134 * We also support using variance shadow maps for blurred shadows; the user can specify
1135 * what shadow mapping algorithm to use with sType.
1136 * - Variance Shadow Mapping works by storing both the depth and depth^2 in the shadow map.
1137 * - Then, the shadow map can be blurred, and when reading from it, the f ragment shader
1138 * can calculate the variance of the depth at a position by doing E(x^2 ) - E(x)^2.
1139 * - We can then use the depth variance and depth at a fragment to arrive at an upper bound
1140 * of the probability that the current surface is shadowed by using Che byshev's
1141 * inequality, and then use that to shade the fragment.
1142 *
1143 * - There are a few problems with VSM.
1144 * * Light Bleeding | Areas with high variance, such as near the edges of high up rects,
1145 * will cause their shadow penumbras to overwrite ot herwise solid
1146 * shadows.
1147 * * Shape Distortion | We can combat Light Bleeding by biasing the sha dow (setting
1148 * mostly shaded fragments to completely shaded) a nd increasing
1149 * the minimum allowed variance. However, this war ps and rounds
1150 * out the shape of the shadow.
1122 */ 1151 */
1123 void drawShadowedPicture(const SkPicture*, 1152 void drawShadowedPicture(const SkPicture*,
1124 const SkMatrix* matrix, 1153 const SkMatrix* matrix,
1125 const SkPaint* paint); 1154 const SkPaint* paint,
1155 const SkShadowType& sType);
1126 void drawShadowedPicture(const sk_sp<SkPicture>& picture, 1156 void drawShadowedPicture(const sk_sp<SkPicture>& picture,
1127 const SkMatrix* matrix, 1157 const SkMatrix* matrix,
1128 const SkPaint* paint) { 1158 const SkPaint* paint,
1129 this->drawShadowedPicture(picture.get(), matrix, paint); 1159 const SkShadowType& sType) {
1160 this->drawShadowedPicture(picture.get(), matrix, paint, sType);
1130 } 1161 }
1131 #endif 1162 #endif
1132 1163
1133 enum VertexMode { 1164 enum VertexMode {
1134 kTriangles_VertexMode, 1165 kTriangles_VertexMode,
1135 kTriangleStrip_VertexMode, 1166 kTriangleStrip_VertexMode,
1136 kTriangleFan_VertexMode 1167 kTriangleFan_VertexMode
1137 }; 1168 };
1138 1169
1139 /** Draw the array of vertices, interpreted as triangles (based on mode). 1170 /** Draw the array of vertices, interpreted as triangles (based on mode).
(...skipping 349 matching lines...) Expand 10 before | Expand all | Expand 10 after
1489 virtual void onClipPath(const SkPath& path, SkRegion::Op op, ClipEdgeStyle e dgeStyle); 1520 virtual void onClipPath(const SkPath& path, SkRegion::Op op, ClipEdgeStyle e dgeStyle);
1490 virtual void onClipRegion(const SkRegion& deviceRgn, SkRegion::Op op); 1521 virtual void onClipRegion(const SkRegion& deviceRgn, SkRegion::Op op);
1491 1522
1492 virtual void onDiscard(); 1523 virtual void onDiscard();
1493 1524
1494 virtual void onDrawPicture(const SkPicture*, const SkMatrix*, const SkPaint* ); 1525 virtual void onDrawPicture(const SkPicture*, const SkMatrix*, const SkPaint* );
1495 1526
1496 #ifdef SK_EXPERIMENTAL_SHADOWING 1527 #ifdef SK_EXPERIMENTAL_SHADOWING
1497 virtual void onDrawShadowedPicture(const SkPicture*, 1528 virtual void onDrawShadowedPicture(const SkPicture*,
1498 const SkMatrix*, 1529 const SkMatrix*,
1499 const SkPaint*); 1530 const SkPaint*,
1531 const SkShadowType& sType);
1500 #endif 1532 #endif
1501 1533
1502 // Returns the canvas to be used by DrawIter. Default implementation 1534 // Returns the canvas to be used by DrawIter. Default implementation
1503 // returns this. Subclasses that encapsulate an indirect canvas may 1535 // returns this. Subclasses that encapsulate an indirect canvas may
1504 // need to overload this method. The impl must keep track of this, as it 1536 // need to overload this method. The impl must keep track of this, as it
1505 // is not released or deleted by the caller. 1537 // is not released or deleted by the caller.
1506 virtual SkCanvas* canvasForDrawIter(); 1538 virtual SkCanvas* canvasForDrawIter();
1507 1539
1508 // Clip rectangle bounds. Called internally by saveLayer. 1540 // Clip rectangle bounds. Called internally by saveLayer.
1509 // returns false if the entire rectangle is entirely clipped out 1541 // returns false if the entire rectangle is entirely clipped out
(...skipping 208 matching lines...) Expand 10 before | Expand all | Expand 10 after
1718 1750
1719 class SkCanvasClipVisitor { 1751 class SkCanvasClipVisitor {
1720 public: 1752 public:
1721 virtual ~SkCanvasClipVisitor(); 1753 virtual ~SkCanvasClipVisitor();
1722 virtual void clipRect(const SkRect&, SkRegion::Op, bool antialias) = 0; 1754 virtual void clipRect(const SkRect&, SkRegion::Op, bool antialias) = 0;
1723 virtual void clipRRect(const SkRRect&, SkRegion::Op, bool antialias) = 0; 1755 virtual void clipRRect(const SkRRect&, SkRegion::Op, bool antialias) = 0;
1724 virtual void clipPath(const SkPath&, SkRegion::Op, bool antialias) = 0; 1756 virtual void clipPath(const SkPath&, SkRegion::Op, bool antialias) = 0;
1725 }; 1757 };
1726 1758
1727 #endif 1759 #endif
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698