Chromium Code Reviews| 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 267 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 278 bool writePixels(const SkImageInfo&, const void* pixels, size_t rowBytes, in t x, int y); | 278 bool writePixels(const SkImageInfo&, const void* pixels, size_t rowBytes, in t x, int y); |
| 279 | 279 |
| 280 /** | 280 /** |
| 281 * Helper for calling writePixels(info, ...) by passing its pixels and rowb ytes. If the bitmap | 281 * Helper for calling writePixels(info, ...) by passing its pixels and rowb ytes. If the bitmap |
| 282 * is just wrapping a texture, returns false and does nothing. | 282 * is just wrapping a texture, returns false and does nothing. |
| 283 */ | 283 */ |
| 284 bool writePixels(const SkBitmap& bitmap, int x, int y); | 284 bool writePixels(const SkBitmap& bitmap, int x, int y); |
| 285 | 285 |
| 286 /////////////////////////////////////////////////////////////////////////// | 286 /////////////////////////////////////////////////////////////////////////// |
| 287 | 287 |
| 288 #ifdef SK_SUPPORT_LEGACY_SAVEFLAGS | |
| 289 enum SaveFlags { | |
| 290 /** save the matrix state, restoring it on restore() */ | |
| 291 // [deprecated] kMatrix_SaveFlag = 0x01, | |
| 292 kMatrix_SaveFlag = 0x01, | |
| 293 /** save the clip state, restoring it on restore() */ | |
| 294 // [deprecated] kClip_SaveFlag = 0x02, | |
| 295 kClip_SaveFlag = 0x02, | |
| 296 /** the layer needs to support per-pixel alpha */ | |
| 297 kHasAlphaLayer_SaveFlag = 0x04, | |
| 298 /** the layer needs to support 8-bits per color component */ | |
| 299 kFullColorLayer_SaveFlag = 0x08, | |
| 300 /** | |
| 301 * the layer should clip against the bounds argument | |
| 302 * | |
| 303 * if SK_SUPPORT_LEGACY_CLIPTOLAYERFLAG is undefined, this is treated a s always on. | |
| 304 */ | |
| 305 kClipToLayer_SaveFlag = 0x10, | |
| 306 | |
| 307 // helper masks for common choices | |
| 308 // [deprecated] kMatrixClip_SaveFlag = 0x03, | |
| 309 kMatrixClip_SaveFlag = 0x03, | |
| 310 #ifdef SK_SUPPORT_LEGACY_CLIPTOLAYERFLAG | |
| 311 kARGB_NoClipLayer_SaveFlag = 0x0F, | |
| 312 #endif | |
| 313 kARGB_ClipLayer_SaveFlag = 0x1F | |
| 314 }; | |
| 315 #endif | |
| 316 | |
| 317 /** This call saves the current matrix, clip, and drawFilter, and pushes a | 288 /** This call saves the current matrix, clip, and drawFilter, and pushes a |
| 318 copy onto a private stack. Subsequent calls to translate, scale, | 289 copy onto a private stack. Subsequent calls to translate, scale, |
| 319 rotate, skew, concat or clipRect, clipPath, and setDrawFilter all | 290 rotate, skew, concat or clipRect, clipPath, and setDrawFilter all |
| 320 operate on this copy. | 291 operate on this copy. |
| 321 When the balancing call to restore() is made, the previous matrix, clip, | 292 When the balancing call to restore() is made, the previous matrix, clip, |
| 322 and drawFilter are restored. | 293 and drawFilter are restored. |
| 323 | 294 |
| 324 @return The value to pass to restoreToCount() to balance this save() | 295 @return The value to pass to restoreToCount() to balance this save() |
| 325 */ | 296 */ |
| 326 int save(); | 297 int save(); |
| (...skipping 15 matching lines...) Expand all Loading... | |
| 342 return this->saveLayer(&bounds, paint); | 313 return this->saveLayer(&bounds, paint); |
| 343 } | 314 } |
| 344 | 315 |
| 345 /** | 316 /** |
| 346 * Temporary name. | 317 * Temporary name. |
| 347 * Will allow any requests for LCD text to be respected, so the caller must be careful to | 318 * Will allow any requests for LCD text to be respected, so the caller must be careful to |
| 348 * only draw on top of opaque sections of the layer to get good results. | 319 * only draw on top of opaque sections of the layer to get good results. |
| 349 */ | 320 */ |
| 350 int saveLayerPreserveLCDTextRequests(const SkRect* bounds, const SkPaint* pa int); | 321 int saveLayerPreserveLCDTextRequests(const SkRect* bounds, const SkPaint* pa int); |
| 351 | 322 |
| 352 #ifdef SK_SUPPORT_LEGACY_SAVEFLAGS | |
| 353 /** DEPRECATED - use saveLayer(const SkRect*, const SkPaint*) instead. | |
| 354 | |
| 355 This behaves the same as saveLayer(const SkRect*, const SkPaint*), | |
| 356 but it allows fine-grained control of which state bits to be saved | |
| 357 (and subsequently restored). | |
| 358 | |
| 359 @param bounds (may be null) This rect, if non-null, is used as a hint to | |
| 360 limit the size of the offscreen, and thus drawing may be | |
| 361 clipped to it, though that clipping is not guaranteed to | |
| 362 happen. If exact clipping is desired, use clipRect(). | |
| 363 @param paint (may be null) This is copied, and is applied to the | |
| 364 offscreen when restore() is called | |
| 365 @param flags LayerFlags | |
| 366 @return The value to pass to restoreToCount() to balance this save() | |
| 367 */ | |
| 368 SK_ATTR_EXTERNALLY_DEPRECATED("SaveFlags use is deprecated") | |
| 369 int saveLayer(const SkRect* bounds, const SkPaint* paint, SaveFlags flags); | |
| 370 #endif | |
| 371 | |
| 372 /** This behaves the same as save(), but in addition it allocates an | 323 /** This behaves the same as save(), but in addition it allocates an |
| 373 offscreen bitmap. All drawing calls are directed there, and only when | 324 offscreen bitmap. All drawing calls are directed there, and only when |
| 374 the balancing call to restore() is made is that offscreen transfered to | 325 the balancing call to restore() is made is that offscreen transfered to |
| 375 the canvas (or the previous layer). | 326 the canvas (or the previous layer). |
| 376 @param bounds (may be null) This rect, if non-null, is used as a hint to | 327 @param bounds (may be null) This rect, if non-null, is used as a hint to |
| 377 limit the size of the offscreen, and thus drawing may be | 328 limit the size of the offscreen, and thus drawing may be |
| 378 clipped to it, though that clipping is not guaranteed to | 329 clipped to it, though that clipping is not guaranteed to |
| 379 happen. If exact clipping is desired, use clipRect(). | 330 happen. If exact clipping is desired, use clipRect(). |
| 380 @param alpha This is applied to the offscreen when restore() is called. | 331 @param alpha This is applied to the offscreen when restore() is called. |
| 381 @return The value to pass to restoreToCount() to balance this save() | 332 @return The value to pass to restoreToCount() to balance this save() |
| 382 */ | 333 */ |
| 383 int saveLayerAlpha(const SkRect* bounds, U8CPU alpha); | 334 int saveLayerAlpha(const SkRect* bounds, U8CPU alpha); |
| 384 | 335 |
| 385 #ifdef SK_SUPPORT_LEGACY_SAVEFLAGS | |
| 386 /** DEPRECATED - use saveLayerAlpha(const SkRect*, U8CPU) instead. | |
| 387 | |
| 388 This behaves the same as saveLayerAlpha(const SkRect*, U8CPU), | |
| 389 but it allows fine-grained control of which state bits to be saved | |
| 390 (and subsequently restored). | |
| 391 | |
| 392 @param bounds (may be null) This rect, if non-null, is used as a hint to | |
| 393 limit the size of the offscreen, and thus drawing may be | |
| 394 clipped to it, though that clipping is not guaranteed to | |
| 395 happen. If exact clipping is desired, use clipRect(). | |
| 396 @param alpha This is applied to the offscreen when restore() is called. | |
| 397 @param flags LayerFlags | |
| 398 @return The value to pass to restoreToCount() to balance this save() | |
| 399 */ | |
| 400 SK_ATTR_EXTERNALLY_DEPRECATED("SaveFlags use is deprecated") | |
| 401 int saveLayerAlpha(const SkRect* bounds, U8CPU alpha, SaveFlags flags); | |
| 402 #endif | |
| 403 | |
| 404 enum { | 336 enum { |
| 405 kIsOpaque_SaveLayerFlag = 1 << 0, | 337 kIsOpaque_SaveLayerFlag = 1 << 0, |
| 406 kPreserveLCDText_SaveLayerFlag = 1 << 1, | 338 kPreserveLCDText_SaveLayerFlag = 1 << 1, |
| 407 | 339 |
| 408 #ifdef SK_SUPPORT_LEGACY_CLIPTOLAYERFLAG | 340 #ifdef SK_SUPPORT_LEGACY_CLIPTOLAYERFLAG |
| 409 kDontClipToLayer_Legacy_SaveLayerFlag = kDontClipToLayer_PrivateSaveLaye rFlag, | 341 kDontClipToLayer_Legacy_SaveLayerFlag = kDontClipToLayer_PrivateSaveLaye rFlag, |
| 410 #endif | 342 #endif |
| 411 }; | 343 }; |
| 412 typedef uint32_t SaveLayerFlags; | 344 typedef uint32_t SaveLayerFlags; |
| 413 | 345 |
| (...skipping 941 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1355 // is not released or deleted by the caller. | 1287 // is not released or deleted by the caller. |
| 1356 virtual SkCanvas* canvasForDrawIter(); | 1288 virtual SkCanvas* canvasForDrawIter(); |
| 1357 | 1289 |
| 1358 // Clip rectangle bounds. Called internally by saveLayer. | 1290 // Clip rectangle bounds. Called internally by saveLayer. |
| 1359 // returns false if the entire rectangle is entirely clipped out | 1291 // returns false if the entire rectangle is entirely clipped out |
| 1360 // If non-NULL, The imageFilter parameter will be used to expand the clip | 1292 // If non-NULL, The imageFilter parameter will be used to expand the clip |
| 1361 // and offscreen bounds for any margin required by the filter DAG. | 1293 // and offscreen bounds for any margin required by the filter DAG. |
| 1362 bool clipRectBounds(const SkRect* bounds, SaveLayerFlags, SkIRect* intersect ion, | 1294 bool clipRectBounds(const SkRect* bounds, SaveLayerFlags, SkIRect* intersect ion, |
| 1363 const SkImageFilter* imageFilter = NULL); | 1295 const SkImageFilter* imageFilter = NULL); |
| 1364 | 1296 |
| 1365 #ifdef SK_SUPPORT_LEGACY_SAVEFLAGS | |
| 1366 // Needed by SkiaCanvasProxy in Android. Make sure that class is updated | |
| 1367 // before removing this method. | |
| 1368 static uint32_t SaveLayerFlagsToSaveFlags(SaveLayerFlags); | |
| 1369 #endif | |
| 1370 private: | 1297 private: |
| 1371 static bool BoundsAffectsClip(SaveLayerFlags); | 1298 static bool BoundsAffectsClip(SaveLayerFlags); |
| 1372 #ifdef SK_SUPPORT_LEGACY_SAVEFLAGS | |
| 1373 static uint32_t SaveFlagsToSaveLayerFlags(SaveFlags); | |
| 1374 #endif | |
| 1375 static SaveLayerFlags LegacySaveFlagsToSaveLayerFlags(uint32_t legacySaveFla gs); | 1299 static SaveLayerFlags LegacySaveFlagsToSaveLayerFlags(uint32_t legacySaveFla gs); |
|
f(malita)
2016/01/28 20:42:56
I think we can relocate this helper to SkPicturePl
| |
| 1376 | 1300 |
| 1377 enum ShaderOverrideOpacity { | 1301 enum ShaderOverrideOpacity { |
| 1378 kNone_ShaderOverrideOpacity, //!< there is no overriding shader ( bitmap or image) | 1302 kNone_ShaderOverrideOpacity, //!< there is no overriding shader ( bitmap or image) |
| 1379 kOpaque_ShaderOverrideOpacity, //!< the overriding shader is opaque | 1303 kOpaque_ShaderOverrideOpacity, //!< the overriding shader is opaque |
| 1380 kNotOpaque_ShaderOverrideOpacity, //!< the overriding shader may not b e opaque | 1304 kNotOpaque_ShaderOverrideOpacity, //!< the overriding shader may not b e opaque |
| 1381 }; | 1305 }; |
| 1382 | 1306 |
| 1383 // notify our surface (if we have one) that we are about to draw, so it | 1307 // notify our surface (if we have one) that we are about to draw, so it |
| 1384 // can perform copy-on-write or invalidate any cached images | 1308 // can perform copy-on-write or invalidate any cached images |
| 1385 void predrawNotify(bool willOverwritesEntireSurface = false); | 1309 void predrawNotify(bool willOverwritesEntireSurface = false); |
| (...skipping 175 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1561 fCanvas = NULL; | 1485 fCanvas = NULL; |
| 1562 } | 1486 } |
| 1563 } | 1487 } |
| 1564 | 1488 |
| 1565 private: | 1489 private: |
| 1566 SkCanvas* fCanvas; | 1490 SkCanvas* fCanvas; |
| 1567 int fSaveCount; | 1491 int fSaveCount; |
| 1568 }; | 1492 }; |
| 1569 #define SkAutoCanvasRestore(...) SK_REQUIRE_LOCAL_VAR(SkAutoCanvasRestore) | 1493 #define SkAutoCanvasRestore(...) SK_REQUIRE_LOCAL_VAR(SkAutoCanvasRestore) |
| 1570 | 1494 |
| 1571 #ifdef SK_SUPPORT_LEGACY_SAVEFLAGS | |
| 1572 static inline SkCanvas::SaveFlags operator|(const SkCanvas::SaveFlags lhs, | |
| 1573 const SkCanvas::SaveFlags rhs) { | |
| 1574 return static_cast<SkCanvas::SaveFlags>(static_cast<int>(lhs) | static_cast< int>(rhs)); | |
| 1575 } | |
| 1576 | |
| 1577 static inline SkCanvas::SaveFlags& operator|=(SkCanvas::SaveFlags& lhs, | |
| 1578 const SkCanvas::SaveFlags rhs) { | |
| 1579 lhs = lhs | rhs; | |
| 1580 return lhs; | |
| 1581 } | |
| 1582 #endif | |
| 1583 | |
| 1584 class SkCanvasClipVisitor { | 1495 class SkCanvasClipVisitor { |
| 1585 public: | 1496 public: |
| 1586 virtual ~SkCanvasClipVisitor(); | 1497 virtual ~SkCanvasClipVisitor(); |
| 1587 virtual void clipRect(const SkRect&, SkRegion::Op, bool antialias) = 0; | 1498 virtual void clipRect(const SkRect&, SkRegion::Op, bool antialias) = 0; |
| 1588 virtual void clipRRect(const SkRRect&, SkRegion::Op, bool antialias) = 0; | 1499 virtual void clipRRect(const SkRRect&, SkRegion::Op, bool antialias) = 0; |
| 1589 virtual void clipPath(const SkPath&, SkRegion::Op, bool antialias) = 0; | 1500 virtual void clipPath(const SkPath&, SkRegion::Op, bool antialias) = 0; |
| 1590 }; | 1501 }; |
| 1591 | 1502 |
| 1592 #endif | 1503 #endif |
| OLD | NEW |