| 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 | 21 |
| 21 class GrContext; | 22 class GrContext; |
| 22 class GrDrawContext; | 23 class GrDrawContext; |
| 23 class SkBaseDevice; | 24 class SkBaseDevice; |
| 24 class SkCanvasClipVisitor; | 25 class SkCanvasClipVisitor; |
| 25 class SkClipStack; | 26 class SkClipStack; |
| 26 class SkData; | 27 class SkData; |
| 27 class SkDraw; | 28 class SkDraw; |
| 28 class SkDrawable; | 29 class SkDrawable; |
| 29 class SkDrawFilter; | 30 class SkDrawFilter; |
| (...skipping 414 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 444 | 445 |
| 445 /** Replace the current matrix with a copy of the specified matrix. | 446 /** Replace the current matrix with a copy of the specified matrix. |
| 446 @param matrix The matrix that will be copied into the current matrix. | 447 @param matrix The matrix that will be copied into the current matrix. |
| 447 */ | 448 */ |
| 448 void setMatrix(const SkMatrix& matrix); | 449 void setMatrix(const SkMatrix& matrix); |
| 449 | 450 |
| 450 /** Helper for setMatrix(identity). Sets the current matrix to identity. | 451 /** Helper for setMatrix(identity). Sets the current matrix to identity. |
| 451 */ | 452 */ |
| 452 void resetMatrix(); | 453 void resetMatrix(); |
| 453 | 454 |
| 455 #ifdef SK_USE_SHADOWS |
| 454 /** Add the specified translation to the current draw depth of the canvas. | 456 /** Add the specified translation to the current draw depth of the canvas. |
| 455 @param z The distance to translate in Z. | 457 @param z The distance to translate in Z. |
| 456 Negative into screen, positive out of screen. | 458 Negative into screen, positive out of screen. |
| 457 Without translation, the draw depth defaults to 0. | 459 Without translation, the draw depth defaults to 0. |
| 458 */ | 460 */ |
| 459 void translateZ(SkScalar z); | 461 void translateZ(SkScalar z); |
| 460 | 462 |
| 463 /** Set the current set of lights in the canvas. |
| 464 @param lights The lights that we want the canvas to have. |
| 465 */ |
| 466 void setLights(sk_sp<SkLights> lights); |
| 467 |
| 468 /** Returns the current set of lights the canvas uses |
| 469 */ |
| 470 sk_sp<SkLights> getLights() const; |
| 471 #endif |
| 472 |
| 461 /** | 473 /** |
| 462 * Modify the current clip with the specified rectangle. | 474 * Modify the current clip with the specified rectangle. |
| 463 * @param rect The rect to combine with the current clip | 475 * @param rect The rect to combine with the current clip |
| 464 * @param op The region op to apply to the current clip | 476 * @param op The region op to apply to the current clip |
| 465 * @param doAntiAlias true if the clip should be antialiased | 477 * @param doAntiAlias true if the clip should be antialiased |
| 466 */ | 478 */ |
| 467 void clipRect(const SkRect& rect, | 479 void clipRect(const SkRect& rect, |
| 468 SkRegion::Op op = SkRegion::kIntersect_Op, | 480 SkRegion::Op op = SkRegion::kIntersect_Op, |
| 469 bool doAntiAlias = false); | 481 bool doAntiAlias = false); |
| 470 | 482 |
| (...skipping 571 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1042 * If paint is non-null, draw the picture into a temporary buffer, and then
apply the paint's | 1054 * If paint is non-null, draw the picture into a temporary buffer, and then
apply the paint's |
| 1043 * alpha/colorfilter/imagefilter/xfermode to that buffer as it is drawn to
the canvas. | 1055 * alpha/colorfilter/imagefilter/xfermode to that buffer as it is drawn to
the canvas. |
| 1044 * This is logically equivalent to | 1056 * This is logically equivalent to |
| 1045 * saveLayer(paint)/drawPicture/restore | 1057 * saveLayer(paint)/drawPicture/restore |
| 1046 */ | 1058 */ |
| 1047 void drawPicture(const SkPicture*, const SkMatrix* matrix, const SkPaint* pa
int); | 1059 void drawPicture(const SkPicture*, const SkMatrix* matrix, const SkPaint* pa
int); |
| 1048 void drawPicture(const sk_sp<SkPicture>& picture, const SkMatrix* matrix, co
nst SkPaint* paint) { | 1060 void drawPicture(const sk_sp<SkPicture>& picture, const SkMatrix* matrix, co
nst SkPaint* paint) { |
| 1049 this->drawPicture(picture.get(), matrix, paint); | 1061 this->drawPicture(picture.get(), matrix, paint); |
| 1050 } | 1062 } |
| 1051 | 1063 |
| 1064 #ifdef SK_USE_SHADOWS |
| 1065 /** |
| 1066 * Draw the picture into this canvas. |
| 1067 * |
| 1068 * We will use the canvas's lights along with the picture information (draw
depths of |
| 1069 * objects, etc) to first create a set of shadowmaps for the light-picture
pairs, and |
| 1070 * then use that set of shadowmaps to render the scene with shadows. |
| 1071 * |
| 1072 * If matrix is non-null, apply that matrix to the CTM when drawing this pi
cture. This is |
| 1073 * logically equivalent to |
| 1074 * save/concat/drawPicture/restore |
| 1075 * |
| 1076 * If paint is non-null, draw the picture into a temporary buffer, and then
apply the paint's |
| 1077 * alpha/colorfilter/imagefilter/xfermode to that buffer as it is drawn to
the canvas. |
| 1078 * This is logically equivalent to |
| 1079 * saveLayer(paint)/drawPicture/restore |
| 1080 * |
| 1081 */ |
| 1082 void drawShadowedPicture(const SkPicture*, |
| 1083 const SkMatrix* matrix, |
| 1084 const SkPaint* paint); |
| 1085 void drawShadowedPicture(const sk_sp<SkPicture>& picture, |
| 1086 const SkMatrix* matrix, |
| 1087 const SkPaint* paint) { |
| 1088 this->drawShadowedPicture(picture.get(), matrix, paint); |
| 1089 } |
| 1090 #endif |
| 1091 |
| 1052 enum VertexMode { | 1092 enum VertexMode { |
| 1053 kTriangles_VertexMode, | 1093 kTriangles_VertexMode, |
| 1054 kTriangleStrip_VertexMode, | 1094 kTriangleStrip_VertexMode, |
| 1055 kTriangleFan_VertexMode | 1095 kTriangleFan_VertexMode |
| 1056 }; | 1096 }; |
| 1057 | 1097 |
| 1058 /** Draw the array of vertices, interpreted as triangles (based on mode). | 1098 /** Draw the array of vertices, interpreted as triangles (based on mode). |
| 1059 | 1099 |
| 1060 If both textures and vertex-colors are NULL, it strokes hairlines with | 1100 If both textures and vertex-colors are NULL, it strokes hairlines with |
| 1061 the paint's color. This behavior is a useful debugging mode to visualize | 1101 the paint's color. This behavior is a useful debugging mode to visualize |
| (...skipping 198 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1260 const SkPaint* paint, | 1300 const SkPaint* paint, |
| 1261 SrcRectConstraint constraint = kStrict_SrcRectCon
straint); | 1301 SrcRectConstraint constraint = kStrict_SrcRectCon
straint); |
| 1262 | 1302 |
| 1263 // expose minimum amount of information necessary for transitional refactori
ng | 1303 // expose minimum amount of information necessary for transitional refactori
ng |
| 1264 /** | 1304 /** |
| 1265 * Returns CTM and clip bounds, translated from canvas coordinates to top la
yer coordinates. | 1305 * Returns CTM and clip bounds, translated from canvas coordinates to top la
yer coordinates. |
| 1266 */ | 1306 */ |
| 1267 void temporary_internal_describeTopLayer(SkMatrix* matrix, SkIRect* clip_bou
nds); | 1307 void temporary_internal_describeTopLayer(SkMatrix* matrix, SkIRect* clip_bou
nds); |
| 1268 | 1308 |
| 1269 protected: | 1309 protected: |
| 1310 #ifdef SK_USE_SHADOWS |
| 1270 /** Returns the current (cumulative) draw depth of the canvas. | 1311 /** Returns the current (cumulative) draw depth of the canvas. |
| 1271 */ | 1312 */ |
| 1272 SkScalar getZ() const; | 1313 SkScalar getZ() const; |
| 1273 | 1314 |
| 1315 sk_sp<SkLights> fLights; |
| 1316 #endif |
| 1317 |
| 1274 /** After calling saveLayer(), there can be any number of devices that make | 1318 /** After calling saveLayer(), there can be any number of devices that make |
| 1275 up the top-most drawing area. LayerIter can be used to iterate through | 1319 up the top-most drawing area. LayerIter can be used to iterate through |
| 1276 those devices. Note that the iterator is only valid until the next API | 1320 those devices. Note that the iterator is only valid until the next API |
| 1277 call made on the canvas. Ownership of all pointers in the iterator stays | 1321 call made on the canvas. Ownership of all pointers in the iterator stays |
| 1278 with the canvas, so none of them should be modified or deleted. | 1322 with the canvas, so none of them should be modified or deleted. |
| 1279 */ | 1323 */ |
| 1280 class LayerIter /*: SkNoncopyable*/ { | 1324 class LayerIter /*: SkNoncopyable*/ { |
| 1281 public: | 1325 public: |
| 1282 /** Initialize iterator with canvas, and set values for 1st device */ | 1326 /** Initialize iterator with canvas, and set values for 1st device */ |
| 1283 LayerIter(SkCanvas*, bool skipEmptyClips); | 1327 LayerIter(SkCanvas*, bool skipEmptyClips); |
| (...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1329 | 1373 |
| 1330 virtual void willSave() {} | 1374 virtual void willSave() {} |
| 1331 // Overriders should call the corresponding INHERITED method up the inherita
nce chain. | 1375 // Overriders should call the corresponding INHERITED method up the inherita
nce chain. |
| 1332 virtual SaveLayerStrategy getSaveLayerStrategy(const SaveLayerRec&) { | 1376 virtual SaveLayerStrategy getSaveLayerStrategy(const SaveLayerRec&) { |
| 1333 return kFullLayer_SaveLayerStrategy; | 1377 return kFullLayer_SaveLayerStrategy; |
| 1334 } | 1378 } |
| 1335 virtual void willRestore() {} | 1379 virtual void willRestore() {} |
| 1336 virtual void didRestore() {} | 1380 virtual void didRestore() {} |
| 1337 virtual void didConcat(const SkMatrix&) {} | 1381 virtual void didConcat(const SkMatrix&) {} |
| 1338 virtual void didSetMatrix(const SkMatrix&) {} | 1382 virtual void didSetMatrix(const SkMatrix&) {} |
| 1383 |
| 1384 #ifdef SK_USE_SHADOWS |
| 1339 virtual void didTranslateZ(SkScalar) {} | 1385 virtual void didTranslateZ(SkScalar) {} |
| 1386 #endif |
| 1340 | 1387 |
| 1341 virtual void onDrawAnnotation(const SkRect&, const char key[], SkData* value
); | 1388 virtual void onDrawAnnotation(const SkRect&, const char key[], SkData* value
); |
| 1342 virtual void onDrawDRRect(const SkRRect&, const SkRRect&, const SkPaint&); | 1389 virtual void onDrawDRRect(const SkRRect&, const SkRRect&, const SkPaint&); |
| 1343 | 1390 |
| 1344 virtual void onDrawText(const void* text, size_t byteLength, SkScalar x, | 1391 virtual void onDrawText(const void* text, size_t byteLength, SkScalar x, |
| 1345 SkScalar y, const SkPaint& paint); | 1392 SkScalar y, const SkPaint& paint); |
| 1346 | 1393 |
| 1347 virtual void onDrawPosText(const void* text, size_t byteLength, | 1394 virtual void onDrawPosText(const void* text, size_t byteLength, |
| 1348 const SkPoint pos[], const SkPaint& paint); | 1395 const SkPoint pos[], const SkPaint& paint); |
| 1349 | 1396 |
| (...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1396 | 1443 |
| 1397 virtual void onClipRect(const SkRect& rect, SkRegion::Op op, ClipEdgeStyle e
dgeStyle); | 1444 virtual void onClipRect(const SkRect& rect, SkRegion::Op op, ClipEdgeStyle e
dgeStyle); |
| 1398 virtual void onClipRRect(const SkRRect& rrect, SkRegion::Op op, ClipEdgeStyl
e edgeStyle); | 1445 virtual void onClipRRect(const SkRRect& rrect, SkRegion::Op op, ClipEdgeStyl
e edgeStyle); |
| 1399 virtual void onClipPath(const SkPath& path, SkRegion::Op op, ClipEdgeStyle e
dgeStyle); | 1446 virtual void onClipPath(const SkPath& path, SkRegion::Op op, ClipEdgeStyle e
dgeStyle); |
| 1400 virtual void onClipRegion(const SkRegion& deviceRgn, SkRegion::Op op); | 1447 virtual void onClipRegion(const SkRegion& deviceRgn, SkRegion::Op op); |
| 1401 | 1448 |
| 1402 virtual void onDiscard(); | 1449 virtual void onDiscard(); |
| 1403 | 1450 |
| 1404 virtual void onDrawPicture(const SkPicture*, const SkMatrix*, const SkPaint*
); | 1451 virtual void onDrawPicture(const SkPicture*, const SkMatrix*, const SkPaint*
); |
| 1405 | 1452 |
| 1453 #ifdef SK_USE_SHADOWS |
| 1454 virtual void onDrawShadowedPicture(const SkPicture*, |
| 1455 const SkMatrix*, |
| 1456 const SkPaint*); |
| 1457 #endif |
| 1458 |
| 1406 // Returns the canvas to be used by DrawIter. Default implementation | 1459 // Returns the canvas to be used by DrawIter. Default implementation |
| 1407 // returns this. Subclasses that encapsulate an indirect canvas may | 1460 // returns this. Subclasses that encapsulate an indirect canvas may |
| 1408 // need to overload this method. The impl must keep track of this, as it | 1461 // need to overload this method. The impl must keep track of this, as it |
| 1409 // is not released or deleted by the caller. | 1462 // is not released or deleted by the caller. |
| 1410 virtual SkCanvas* canvasForDrawIter(); | 1463 virtual SkCanvas* canvasForDrawIter(); |
| 1411 | 1464 |
| 1412 // Clip rectangle bounds. Called internally by saveLayer. | 1465 // Clip rectangle bounds. Called internally by saveLayer. |
| 1413 // returns false if the entire rectangle is entirely clipped out | 1466 // returns false if the entire rectangle is entirely clipped out |
| 1414 // If non-NULL, The imageFilter parameter will be used to expand the clip | 1467 // If non-NULL, The imageFilter parameter will be used to expand the clip |
| 1415 // and offscreen bounds for any margin required by the filter DAG. | 1468 // and offscreen bounds for any margin required by the filter DAG. |
| (...skipping 201 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1617 | 1670 |
| 1618 class SkCanvasClipVisitor { | 1671 class SkCanvasClipVisitor { |
| 1619 public: | 1672 public: |
| 1620 virtual ~SkCanvasClipVisitor(); | 1673 virtual ~SkCanvasClipVisitor(); |
| 1621 virtual void clipRect(const SkRect&, SkRegion::Op, bool antialias) = 0; | 1674 virtual void clipRect(const SkRect&, SkRegion::Op, bool antialias) = 0; |
| 1622 virtual void clipRRect(const SkRRect&, SkRegion::Op, bool antialias) = 0; | 1675 virtual void clipRRect(const SkRRect&, SkRegion::Op, bool antialias) = 0; |
| 1623 virtual void clipPath(const SkPath&, SkRegion::Op, bool antialias) = 0; | 1676 virtual void clipPath(const SkPath&, SkRegion::Op, bool antialias) = 0; |
| 1624 }; | 1677 }; |
| 1625 | 1678 |
| 1626 #endif | 1679 #endif |
| OLD | NEW |