OLD | NEW |
---|---|
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 "../../src/core/SkShadowShader.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 1066 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1097 * This is logically equivalent to | 1098 * This is logically equivalent to |
1098 * saveLayer(paint)/drawPicture/restore | 1099 * saveLayer(paint)/drawPicture/restore |
1099 */ | 1100 */ |
1100 void drawPicture(const SkPicture*, const SkMatrix* matrix, const SkPaint* pa int); | 1101 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) { | 1102 void drawPicture(const sk_sp<SkPicture>& picture, const SkMatrix* matrix, co nst SkPaint* paint) { |
1102 this->drawPicture(picture.get(), matrix, paint); | 1103 this->drawPicture(picture.get(), matrix, paint); |
1103 } | 1104 } |
1104 | 1105 |
1105 #ifdef SK_EXPERIMENTAL_SHADOWING | 1106 #ifdef SK_EXPERIMENTAL_SHADOWING |
1106 /** | 1107 /** |
1107 * Draw the picture into this canvas. | 1108 * Draw the picture into this canvas, with shadows! |
1108 * | 1109 * |
1109 * We will use the canvas's lights along with the picture information (draw depths of | 1110 * 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 | 1111 * 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. | 1112 * then use that set of shadowmaps to render the scene with shadows. |
1112 * | 1113 * |
1113 * If matrix is non-null, apply that matrix to the CTM when drawing this pi cture. This is | 1114 * If matrix is non-null, apply that matrix to the CTM when drawing this pi cture. This is |
1114 * logically equivalent to | 1115 * logically equivalent to |
1115 * save/concat/drawPicture/restore | 1116 * save/concat/drawPicture/restore |
1116 * | 1117 * |
1117 * If paint is non-null, draw the picture into a temporary buffer, and then apply the paint's | 1118 * 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. | 1119 * alpha/colorfilter/imagefilter/xfermode to that buffer as it is drawn to the canvas. |
1119 * This is logically equivalent to | 1120 * This is logically equivalent to |
1120 * saveLayer(paint)/drawPicture/restore | 1121 * saveLayer(paint)/drawPicture/restore |
1121 * | 1122 * |
1123 * We also support using variance shadow maps for blurred shadows; the user can specify | |
1124 * what shadow mapping algorithm to use with sType. | |
1125 * - Variance Shadow Mapping works by storing both the depth and depth^2 in the shadow map. | |
1126 * - Then, the shadow map can be blurred, and when reading from it, the f ragment shader | |
1127 * can calculate the variance of the depth at a position by doing E(x^2 ) - E(x)^2. | |
1128 * - We can then use the depth variance and depth at a fragment to arrive at an upper bound | |
1129 * of the probability that the current surface is shadowed by using Che byshev's | |
1130 * inequality, and then use that to shade the fragment. | |
1131 * | |
1132 * - There are a few problems with VSM. | |
1133 * * Light Bleeding | Areas with high variance, such as near the edges of high up rects, | |
1134 * will cause their shadow penumbras to overwrite ot herwise solid | |
1135 * shadows. | |
1136 * * Shape Distortion | We can combat Light Bleeding by biasing the sha dow (setting | |
1137 * mostly shaded fragments to completely shaded) a nd increasing | |
1138 * the minimum allowed variance. However, this war ps and rounds | |
1139 * out the shape of the shadow. | |
1122 */ | 1140 */ |
1123 void drawShadowedPicture(const SkPicture*, | 1141 void drawShadowedPicture(const SkPicture*, |
1124 const SkMatrix* matrix, | 1142 const SkMatrix* matrix, |
1125 const SkPaint* paint); | 1143 const SkPaint* paint, |
1144 SkShadowType sType); | |
jvanverth1
2016/08/12 17:39:08
We pass a struct as const& if it's not modified.
vjiaoblack
2016/08/12 19:07:42
Done.
| |
1126 void drawShadowedPicture(const sk_sp<SkPicture>& picture, | 1145 void drawShadowedPicture(const sk_sp<SkPicture>& picture, |
1127 const SkMatrix* matrix, | 1146 const SkMatrix* matrix, |
1128 const SkPaint* paint) { | 1147 const SkPaint* paint, |
1129 this->drawShadowedPicture(picture.get(), matrix, paint); | 1148 SkShadowType sType) { |
1149 this->drawShadowedPicture(picture.get(), matrix, paint, sType); | |
1130 } | 1150 } |
1131 #endif | 1151 #endif |
1132 | 1152 |
1133 enum VertexMode { | 1153 enum VertexMode { |
1134 kTriangles_VertexMode, | 1154 kTriangles_VertexMode, |
1135 kTriangleStrip_VertexMode, | 1155 kTriangleStrip_VertexMode, |
1136 kTriangleFan_VertexMode | 1156 kTriangleFan_VertexMode |
1137 }; | 1157 }; |
1138 | 1158 |
1139 /** Draw the array of vertices, interpreted as triangles (based on mode). | 1159 /** Draw the array of vertices, interpreted as triangles (based on mode). |
(...skipping 349 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1489 virtual void onClipPath(const SkPath& path, SkRegion::Op op, ClipEdgeStyle e dgeStyle); | 1509 virtual void onClipPath(const SkPath& path, SkRegion::Op op, ClipEdgeStyle e dgeStyle); |
1490 virtual void onClipRegion(const SkRegion& deviceRgn, SkRegion::Op op); | 1510 virtual void onClipRegion(const SkRegion& deviceRgn, SkRegion::Op op); |
1491 | 1511 |
1492 virtual void onDiscard(); | 1512 virtual void onDiscard(); |
1493 | 1513 |
1494 virtual void onDrawPicture(const SkPicture*, const SkMatrix*, const SkPaint* ); | 1514 virtual void onDrawPicture(const SkPicture*, const SkMatrix*, const SkPaint* ); |
1495 | 1515 |
1496 #ifdef SK_EXPERIMENTAL_SHADOWING | 1516 #ifdef SK_EXPERIMENTAL_SHADOWING |
1497 virtual void onDrawShadowedPicture(const SkPicture*, | 1517 virtual void onDrawShadowedPicture(const SkPicture*, |
1498 const SkMatrix*, | 1518 const SkMatrix*, |
1499 const SkPaint*); | 1519 const SkPaint*, |
1520 SkShadowType sType); | |
1500 #endif | 1521 #endif |
1501 | 1522 |
1502 // Returns the canvas to be used by DrawIter. Default implementation | 1523 // Returns the canvas to be used by DrawIter. Default implementation |
1503 // returns this. Subclasses that encapsulate an indirect canvas may | 1524 // returns this. Subclasses that encapsulate an indirect canvas may |
1504 // need to overload this method. The impl must keep track of this, as it | 1525 // need to overload this method. The impl must keep track of this, as it |
1505 // is not released or deleted by the caller. | 1526 // is not released or deleted by the caller. |
1506 virtual SkCanvas* canvasForDrawIter(); | 1527 virtual SkCanvas* canvasForDrawIter(); |
1507 | 1528 |
1508 // Clip rectangle bounds. Called internally by saveLayer. | 1529 // Clip rectangle bounds. Called internally by saveLayer. |
1509 // returns false if the entire rectangle is entirely clipped out | 1530 // returns false if the entire rectangle is entirely clipped out |
(...skipping 208 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1718 | 1739 |
1719 class SkCanvasClipVisitor { | 1740 class SkCanvasClipVisitor { |
1720 public: | 1741 public: |
1721 virtual ~SkCanvasClipVisitor(); | 1742 virtual ~SkCanvasClipVisitor(); |
1722 virtual void clipRect(const SkRect&, SkRegion::Op, bool antialias) = 0; | 1743 virtual void clipRect(const SkRect&, SkRegion::Op, bool antialias) = 0; |
1723 virtual void clipRRect(const SkRRect&, SkRegion::Op, bool antialias) = 0; | 1744 virtual void clipRRect(const SkRRect&, SkRegion::Op, bool antialias) = 0; |
1724 virtual void clipPath(const SkPath&, SkRegion::Op, bool antialias) = 0; | 1745 virtual void clipPath(const SkPath&, SkRegion::Op, bool antialias) = 0; |
1725 }; | 1746 }; |
1726 | 1747 |
1727 #endif | 1748 #endif |
OLD | NEW |