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 |
(...skipping 373 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
384 limit the size of the offscreen, and thus drawing may be | 384 limit the size of the offscreen, and thus drawing may be |
385 clipped to it, though that clipping is not guaranteed to | 385 clipped to it, though that clipping is not guaranteed to |
386 happen. If exact clipping is desired, use clipRect(). | 386 happen. If exact clipping is desired, use clipRect(). |
387 @param alpha This is applied to the offscreen when restore() is called. | 387 @param alpha This is applied to the offscreen when restore() is called. |
388 @param flags LayerFlags | 388 @param flags LayerFlags |
389 @return The value to pass to restoreToCount() to balance this save() | 389 @return The value to pass to restoreToCount() to balance this save() |
390 */ | 390 */ |
391 SK_ATTR_EXTERNALLY_DEPRECATED("SaveFlags use is deprecated") | 391 SK_ATTR_EXTERNALLY_DEPRECATED("SaveFlags use is deprecated") |
392 int saveLayerAlpha(const SkRect* bounds, U8CPU alpha, SaveFlags flags); | 392 int saveLayerAlpha(const SkRect* bounds, U8CPU alpha, SaveFlags flags); |
393 | 393 |
394 enum SaveLayerFlags { | |
395 kIsOpaque_SaveLayerFlag = 1 << 0, | |
396 kPreserveLCDText_SaveLayerFlag = 1 << 1, | |
397 }; | |
f(malita)
2015/12/17 19:40:49
Since we don't really refer to the SaveLayerFlags
reed1
2015/12/17 19:53:27
Done.
| |
398 | |
399 struct SaveLayerRec { | |
400 SaveLayerRec() : fBounds(nullptr), fPaint(nullptr), fSaveLayerFlags(0) { } | |
401 SaveLayerRec(const SkRect* bounds, const SkPaint* paint, uint32_t saveLa yerFlags = 0) | |
402 : fBounds(bounds) | |
403 , fPaint(paint) | |
404 , fSaveLayerFlags(saveLayerFlags) | |
405 {} | |
406 | |
407 const SkRect* fBounds; // optional | |
408 const SkPaint* fPaint; // optional | |
409 uint32_t fSaveLayerFlags; | |
410 }; | |
411 | |
412 int saveLayer(const SaveLayerRec&); | |
413 | |
394 /** This call balances a previous call to save(), and is used to remove all | 414 /** This call balances a previous call to save(), and is used to remove all |
395 modifications to the matrix/clip/drawFilter state since the last save | 415 modifications to the matrix/clip/drawFilter state since the last save |
396 call. | 416 call. |
397 It is an error to call restore() more times than save() was called. | 417 It is an error to call restore() more times than save() was called. |
398 */ | 418 */ |
399 void restore(); | 419 void restore(); |
400 | 420 |
401 /** Returns the number of matrix/clip states on the SkCanvas' private stack. | 421 /** Returns the number of matrix/clip states on the SkCanvas' private stack. |
402 This will equal # save() calls - # restore() calls + 1. The save count o n | 422 This will equal # save() calls - # restore() calls + 1. The save count o n |
403 a new canvas is 1. | 423 a new canvas is 1. |
(...skipping 809 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1213 | 1233 |
1214 // default impl defers to its device | 1234 // default impl defers to its device |
1215 virtual bool onPeekPixels(SkPixmap*); | 1235 virtual bool onPeekPixels(SkPixmap*); |
1216 virtual bool onAccessTopLayerPixels(SkPixmap*); | 1236 virtual bool onAccessTopLayerPixels(SkPixmap*); |
1217 | 1237 |
1218 // Subclass save/restore notifiers. | 1238 // Subclass save/restore notifiers. |
1219 // Overriders should call the corresponding INHERITED method up the inherita nce chain. | 1239 // Overriders should call the corresponding INHERITED method up the inherita nce chain. |
1220 // willSaveLayer()'s return value may suppress full layer allocation. | 1240 // willSaveLayer()'s return value may suppress full layer allocation. |
1221 enum SaveLayerStrategy { | 1241 enum SaveLayerStrategy { |
1222 kFullLayer_SaveLayerStrategy, | 1242 kFullLayer_SaveLayerStrategy, |
1223 kNoLayer_SaveLayerStrategy | 1243 kNoLayer_SaveLayerStrategy, |
1244 kCallLegacyMethod_SaveLayerStrategy, // TEMPORARY until we can remove legacy willSaveLayer | |
1224 }; | 1245 }; |
1225 | 1246 |
1226 virtual void willSave() {} | 1247 virtual void willSave() {} |
1248 #ifdef SK_SUPPORT_LEGACY_SAVELAYERPARAMS | |
1227 virtual SaveLayerStrategy willSaveLayer(const SkRect*, const SkPaint*, SaveF lags) { | 1249 virtual SaveLayerStrategy willSaveLayer(const SkRect*, const SkPaint*, SaveF lags) { |
1228 return kFullLayer_SaveLayerStrategy; | 1250 return kFullLayer_SaveLayerStrategy; |
1229 } | 1251 } |
1252 #endif | |
1253 virtual SaveLayerStrategy getSaveLayerStrategy(const SaveLayerRec&) { | |
1254 // returning this tells us to call the older version of this method | |
1255 return kCallLegacyMethod_SaveLayerStrategy; | |
1256 } | |
1230 virtual void willRestore() {} | 1257 virtual void willRestore() {} |
1231 virtual void didRestore() {} | 1258 virtual void didRestore() {} |
1232 virtual void didConcat(const SkMatrix&) {} | 1259 virtual void didConcat(const SkMatrix&) {} |
1233 virtual void didSetMatrix(const SkMatrix&) {} | 1260 virtual void didSetMatrix(const SkMatrix&) {} |
1234 | 1261 |
1235 virtual void onDrawDRRect(const SkRRect&, const SkRRect&, const SkPaint&); | 1262 virtual void onDrawDRRect(const SkRRect&, const SkRRect&, const SkPaint&); |
1236 | 1263 |
1237 virtual void onDrawText(const void* text, size_t byteLength, SkScalar x, | 1264 virtual void onDrawText(const void* text, size_t byteLength, SkScalar x, |
1238 SkScalar y, const SkPaint& paint); | 1265 SkScalar y, const SkPaint& paint); |
1239 | 1266 |
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1297 // Returns the canvas to be used by DrawIter. Default implementation | 1324 // Returns the canvas to be used by DrawIter. Default implementation |
1298 // returns this. Subclasses that encapsulate an indirect canvas may | 1325 // returns this. Subclasses that encapsulate an indirect canvas may |
1299 // need to overload this method. The impl must keep track of this, as it | 1326 // need to overload this method. The impl must keep track of this, as it |
1300 // is not released or deleted by the caller. | 1327 // is not released or deleted by the caller. |
1301 virtual SkCanvas* canvasForDrawIter(); | 1328 virtual SkCanvas* canvasForDrawIter(); |
1302 | 1329 |
1303 // Clip rectangle bounds. Called internally by saveLayer. | 1330 // Clip rectangle bounds. Called internally by saveLayer. |
1304 // returns false if the entire rectangle is entirely clipped out | 1331 // returns false if the entire rectangle is entirely clipped out |
1305 // If non-NULL, The imageFilter parameter will be used to expand the clip | 1332 // If non-NULL, The imageFilter parameter will be used to expand the clip |
1306 // and offscreen bounds for any margin required by the filter DAG. | 1333 // and offscreen bounds for any margin required by the filter DAG. |
1307 bool clipRectBounds(const SkRect* bounds, SaveFlags flags, | 1334 bool clipRectBounds(const SkRect* bounds, uint32_t saveLayerFlags, |
1308 SkIRect* intersection, | 1335 SkIRect* intersection, |
1309 const SkImageFilter* imageFilter = NULL); | 1336 const SkImageFilter* imageFilter = NULL); |
1310 | 1337 |
1311 private: | 1338 private: |
1339 enum PrivateSaveLayerFlags { | |
1340 kDontSaveMatrix_PrivateSaveLayerFlag = 1 << 29, | |
1341 kDontSaveClip_PrivateSaveLayerFlag = 1 << 30, | |
f(malita)
2015/12/17 19:40:49
I don't think these are needed: we don't ever get
reed1
2015/12/17 19:49:19
Meaning I don't need any of these, or I don't need
| |
1342 kDontClipToLayer_PrivateSaveLayerFlag = 1 << 31, | |
1343 }; | |
1344 | |
1345 static bool BoundsAffectsClip(uint32_t saveLayerFlags); | |
1346 static uint32_t SaveFlagsToSaveLayerFlags(SaveFlags); | |
1347 | |
1312 enum PrivateSaveFlags { | 1348 enum PrivateSaveFlags { |
1313 // These must not overlap the public flags. | 1349 // These must not overlap the public flags. |
robertphillips
2015/12/17 19:53:57
??
| |
1314 kPreserveLCDText_PrivateSaveFlag = 1 << 5, | 1350 // kPreserveLCDText_PrivateSaveFlag = 1 << 5, |
1315 }; | 1351 }; |
1316 | 1352 |
1317 enum ShaderOverrideOpacity { | 1353 enum ShaderOverrideOpacity { |
1318 kNone_ShaderOverrideOpacity, //!< there is no overriding shader ( bitmap or image) | 1354 kNone_ShaderOverrideOpacity, //!< there is no overriding shader ( bitmap or image) |
1319 kOpaque_ShaderOverrideOpacity, //!< the overriding shader is opaque | 1355 kOpaque_ShaderOverrideOpacity, //!< the overriding shader is opaque |
1320 kNotOpaque_ShaderOverrideOpacity, //!< the overriding shader may not b e opaque | 1356 kNotOpaque_ShaderOverrideOpacity, //!< the overriding shader may not b e opaque |
1321 }; | 1357 }; |
1322 | 1358 |
1323 // notify our surface (if we have one) that we are about to draw, so it | 1359 // notify our surface (if we have one) that we are about to draw, so it |
1324 // can perform copy-on-write or invalidate any cached images | 1360 // can perform copy-on-write or invalidate any cached images |
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1366 | 1402 |
1367 friend class SkDrawIter; // needs setupDrawForLayerDevice() | 1403 friend class SkDrawIter; // needs setupDrawForLayerDevice() |
1368 friend class AutoDrawLooper; | 1404 friend class AutoDrawLooper; |
1369 friend class SkLua; // needs top layer size and offset | 1405 friend class SkLua; // needs top layer size and offset |
1370 friend class SkDebugCanvas; // needs experimental fAllowSimplifyClip | 1406 friend class SkDebugCanvas; // needs experimental fAllowSimplifyClip |
1371 friend class SkSurface_Raster; // needs getDevice() | 1407 friend class SkSurface_Raster; // needs getDevice() |
1372 friend class SkRecorder; // InitFlags | 1408 friend class SkRecorder; // InitFlags |
1373 friend class SkNoSaveLayerCanvas; // InitFlags | 1409 friend class SkNoSaveLayerCanvas; // InitFlags |
1374 friend class SkPictureImageFilter; // SkCanvas(SkBaseDevice*, SkSurfaceProp s*, InitFlags) | 1410 friend class SkPictureImageFilter; // SkCanvas(SkBaseDevice*, SkSurfaceProp s*, InitFlags) |
1375 friend class SkPictureRecord; // predrawNotify (why does it need it? <reed >) | 1411 friend class SkPictureRecord; // predrawNotify (why does it need it? <reed >) |
1412 friend class SkPicturePlayback; // SaveFlagsToSaveLayerFlags | |
1376 | 1413 |
1377 enum InitFlags { | 1414 enum InitFlags { |
1378 kDefault_InitFlags = 0, | 1415 kDefault_InitFlags = 0, |
1379 kConservativeRasterClip_InitFlag = 1 << 0, | 1416 kConservativeRasterClip_InitFlag = 1 << 0, |
1380 }; | 1417 }; |
1381 SkCanvas(const SkIRect& bounds, InitFlags); | 1418 SkCanvas(const SkIRect& bounds, InitFlags); |
1382 SkCanvas(SkBaseDevice* device, InitFlags); | 1419 SkCanvas(SkBaseDevice* device, InitFlags); |
1383 | 1420 |
1384 void resetForNextPicture(const SkIRect& bounds); | 1421 void resetForNextPicture(const SkIRect& bounds); |
1385 | 1422 |
(...skipping 11 matching lines...) Expand all Loading... | |
1397 * Gets the size/origin of the top level layer in global canvas coordinates. We don't want this | 1434 * Gets the size/origin of the top level layer in global canvas coordinates. We don't want this |
1398 * to be public because it exposes decisions about layer sizes that are inte rnal to the canvas. | 1435 * to be public because it exposes decisions about layer sizes that are inte rnal to the canvas. |
1399 */ | 1436 */ |
1400 SkISize getTopLayerSize() const; | 1437 SkISize getTopLayerSize() const; |
1401 SkIPoint getTopLayerOrigin() const; | 1438 SkIPoint getTopLayerOrigin() const; |
1402 | 1439 |
1403 void internalDrawBitmapRect(const SkBitmap& bitmap, const SkRect* src, | 1440 void internalDrawBitmapRect(const SkBitmap& bitmap, const SkRect* src, |
1404 const SkRect& dst, const SkPaint* paint, | 1441 const SkRect& dst, const SkPaint* paint, |
1405 SrcRectConstraint); | 1442 SrcRectConstraint); |
1406 void internalDrawPaint(const SkPaint& paint); | 1443 void internalDrawPaint(const SkPaint& paint); |
1407 void internalSaveLayer(const SkRect* bounds, const SkPaint*, SaveFlags, Save LayerStrategy); | 1444 void internalSaveLayer(const SaveLayerRec&, SaveLayerStrategy); |
1408 void internalDrawDevice(SkBaseDevice*, int x, int y, const SkPaint*, bool is BitmapDevice); | 1445 void internalDrawDevice(SkBaseDevice*, int x, int y, const SkPaint*, bool is BitmapDevice); |
1409 | 1446 |
1410 // shared by save() and saveLayer() | 1447 // shared by save() and saveLayer() |
1411 void internalSave(); | 1448 void internalSave(); |
1412 void internalRestore(); | 1449 void internalRestore(); |
1413 static void DrawRect(const SkDraw& draw, const SkPaint& paint, | 1450 static void DrawRect(const SkDraw& draw, const SkPaint& paint, |
1414 const SkRect& r, SkScalar textSize); | 1451 const SkRect& r, SkScalar textSize); |
1415 static void DrawTextDecorations(const SkDraw& draw, const SkPaint& paint, | 1452 static void DrawTextDecorations(const SkDraw& draw, const SkPaint& paint, |
1416 const char text[], size_t byteLength, | 1453 const char text[], size_t byteLength, |
1417 SkScalar x, SkScalar y); | 1454 SkScalar x, SkScalar y); |
(...skipping 145 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1563 | 1600 |
1564 class SkCanvasClipVisitor { | 1601 class SkCanvasClipVisitor { |
1565 public: | 1602 public: |
1566 virtual ~SkCanvasClipVisitor(); | 1603 virtual ~SkCanvasClipVisitor(); |
1567 virtual void clipRect(const SkRect&, SkRegion::Op, bool antialias) = 0; | 1604 virtual void clipRect(const SkRect&, SkRegion::Op, bool antialias) = 0; |
1568 virtual void clipRRect(const SkRRect&, SkRegion::Op, bool antialias) = 0; | 1605 virtual void clipRRect(const SkRRect&, SkRegion::Op, bool antialias) = 0; |
1569 virtual void clipPath(const SkPath&, SkRegion::Op, bool antialias) = 0; | 1606 virtual void clipPath(const SkPath&, SkRegion::Op, bool antialias) = 0; |
1570 }; | 1607 }; |
1571 | 1608 |
1572 #endif | 1609 #endif |
OLD | NEW |