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

Side by Side Diff: include/core/SkCanvas.h

Issue 1535993003: hide old SaveFlags (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: aaaaaargh Created 5 years 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
« no previous file with comments | « no previous file | src/core/SkCanvas.cpp » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 19 matching lines...) Expand all
30 class SkMetaData; 30 class SkMetaData;
31 class SkPath; 31 class SkPath;
32 class SkPicture; 32 class SkPicture;
33 class SkPixmap; 33 class SkPixmap;
34 class SkRRect; 34 class SkRRect;
35 struct SkRSXform; 35 struct SkRSXform;
36 class SkSurface; 36 class SkSurface;
37 class SkSurface_Base; 37 class SkSurface_Base;
38 class SkTextBlob; 38 class SkTextBlob;
39 39
40 /*
41 * If you want the legacy cliptolayer flag (i.e. android), then you must have t he new
42 * legacy saveflags.
43 */
44 #ifdef SK_SUPPORT_LEGACY_CLIPTOLAYERFLAG
45 #ifndef SK_SUPPORT_LEGACY_SAVEFLAGS
46 #define SK_SUPPORT_LEGACY_SAVEFLAGS
47 #endif
48 #endif
49
40 /** \class SkCanvas 50 /** \class SkCanvas
41 51
42 A Canvas encapsulates all of the state about drawing into a device (bitmap). 52 A Canvas encapsulates all of the state about drawing into a device (bitmap).
43 This includes a reference to the device itself, and a stack of matrix/clip 53 This includes a reference to the device itself, and a stack of matrix/clip
44 values. For any given draw call (e.g. drawRect), the geometry of the object 54 values. For any given draw call (e.g. drawRect), the geometry of the object
45 being drawn is transformed by the concatenation of all the matrices in the 55 being drawn is transformed by the concatenation of all the matrices in the
46 stack. The transformed geometry is clipped by the intersection of all of 56 stack. The transformed geometry is clipped by the intersection of all of
47 the clips in the stack. 57 the clips in the stack.
48 58
49 While the Canvas holds the state of the drawing device, the state (style) 59 While the Canvas holds the state of the drawing device, the state (style)
50 of the object being drawn is held by the Paint, which is provided as a 60 of the object being drawn is held by the Paint, which is provided as a
51 parameter to each of the draw() methods. The Paint holds attributes such as 61 parameter to each of the draw() methods. The Paint holds attributes such as
52 color, typeface, textSize, strokeWidth, shader (e.g. gradients, patterns), 62 color, typeface, textSize, strokeWidth, shader (e.g. gradients, patterns),
53 etc. 63 etc.
54 */ 64 */
55 class SK_API SkCanvas : public SkRefCnt { 65 class SK_API SkCanvas : public SkRefCnt {
66 enum PrivateSaveLayerFlags {
67 kDontClipToLayer_PrivateSaveLayerFlag = 1 << 31,
68 };
69
56 public: 70 public:
57 /** 71 /**
58 * Attempt to allocate raster canvas, matching the ImageInfo, that will dra w directly into the 72 * Attempt to allocate raster canvas, matching the ImageInfo, that will dra w directly into the
59 * specified pixels. To access the pixels after drawing to them, the caller should call 73 * specified pixels. To access the pixels after drawing to them, the caller should call
60 * flush() or call peekPixels(...). 74 * flush() or call peekPixels(...).
61 * 75 *
62 * On failure, return NULL. This can fail for several reasons: 76 * On failure, return NULL. This can fail for several reasons:
63 * 1. invalid ImageInfo (e.g. negative dimensions) 77 * 1. invalid ImageInfo (e.g. negative dimensions)
64 * 2. unsupported ImageInfo for a canvas 78 * 2. unsupported ImageInfo for a canvas
65 * - kUnknown_SkColorType, kIndex_8_SkColorType 79 * - kUnknown_SkColorType, kIndex_8_SkColorType
(...skipping 208 matching lines...) Expand 10 before | Expand all | Expand 10 after
274 bool writePixels(const SkImageInfo&, const void* pixels, size_t rowBytes, in t x, int y); 288 bool writePixels(const SkImageInfo&, const void* pixels, size_t rowBytes, in t x, int y);
275 289
276 /** 290 /**
277 * Helper for calling writePixels(info, ...) by passing its pixels and rowb ytes. If the bitmap 291 * Helper for calling writePixels(info, ...) by passing its pixels and rowb ytes. If the bitmap
278 * is just wrapping a texture, returns false and does nothing. 292 * is just wrapping a texture, returns false and does nothing.
279 */ 293 */
280 bool writePixels(const SkBitmap& bitmap, int x, int y); 294 bool writePixels(const SkBitmap& bitmap, int x, int y);
281 295
282 /////////////////////////////////////////////////////////////////////////// 296 ///////////////////////////////////////////////////////////////////////////
283 297
298 #ifdef SK_SUPPORT_LEGACY_SAVEFLAGS
284 enum SaveFlags { 299 enum SaveFlags {
285 /** save the matrix state, restoring it on restore() */ 300 /** save the matrix state, restoring it on restore() */
286 // [deprecated] kMatrix_SaveFlag = 0x01, 301 // [deprecated] kMatrix_SaveFlag = 0x01,
287 kMatrix_SaveFlag = 0x01, 302 kMatrix_SaveFlag = 0x01,
288 /** save the clip state, restoring it on restore() */ 303 /** save the clip state, restoring it on restore() */
289 // [deprecated] kClip_SaveFlag = 0x02, 304 // [deprecated] kClip_SaveFlag = 0x02,
290 kClip_SaveFlag = 0x02, 305 kClip_SaveFlag = 0x02,
291 /** the layer needs to support per-pixel alpha */ 306 /** the layer needs to support per-pixel alpha */
292 kHasAlphaLayer_SaveFlag = 0x04, 307 kHasAlphaLayer_SaveFlag = 0x04,
293 /** the layer needs to support 8-bits per color component */ 308 /** the layer needs to support 8-bits per color component */
294 kFullColorLayer_SaveFlag = 0x08, 309 kFullColorLayer_SaveFlag = 0x08,
295 /** 310 /**
296 * the layer should clip against the bounds argument 311 * the layer should clip against the bounds argument
297 * 312 *
298 * if SK_SUPPORT_LEGACY_CLIPTOLAYERFLAG is undefined, this is treated a s always on. 313 * if SK_SUPPORT_LEGACY_CLIPTOLAYERFLAG is undefined, this is treated a s always on.
299 */ 314 */
300 kClipToLayer_SaveFlag = 0x10, 315 kClipToLayer_SaveFlag = 0x10,
301 316
302 // helper masks for common choices 317 // helper masks for common choices
303 // [deprecated] kMatrixClip_SaveFlag = 0x03, 318 // [deprecated] kMatrixClip_SaveFlag = 0x03,
304 kMatrixClip_SaveFlag = 0x03, 319 kMatrixClip_SaveFlag = 0x03,
305 #ifdef SK_SUPPORT_LEGACY_CLIPTOLAYERFLAG 320 #ifdef SK_SUPPORT_LEGACY_CLIPTOLAYERFLAG
306 kARGB_NoClipLayer_SaveFlag = 0x0F, 321 kARGB_NoClipLayer_SaveFlag = 0x0F,
307 #endif 322 #endif
308 kARGB_ClipLayer_SaveFlag = 0x1F 323 kARGB_ClipLayer_SaveFlag = 0x1F
309 }; 324 };
325 #endif
310 326
311 /** This call saves the current matrix, clip, and drawFilter, and pushes a 327 /** This call saves the current matrix, clip, and drawFilter, and pushes a
312 copy onto a private stack. Subsequent calls to translate, scale, 328 copy onto a private stack. Subsequent calls to translate, scale,
313 rotate, skew, concat or clipRect, clipPath, and setDrawFilter all 329 rotate, skew, concat or clipRect, clipPath, and setDrawFilter all
314 operate on this copy. 330 operate on this copy.
315 When the balancing call to restore() is made, the previous matrix, clip, 331 When the balancing call to restore() is made, the previous matrix, clip,
316 and drawFilter are restored. 332 and drawFilter are restored.
317 333
318 @return The value to pass to restoreToCount() to balance this save() 334 @return The value to pass to restoreToCount() to balance this save()
319 */ 335 */
(...skipping 16 matching lines...) Expand all
336 return this->saveLayer(&bounds, paint); 352 return this->saveLayer(&bounds, paint);
337 } 353 }
338 354
339 /** 355 /**
340 * Temporary name. 356 * Temporary name.
341 * Will allow any requests for LCD text to be respected, so the caller must be careful to 357 * Will allow any requests for LCD text to be respected, so the caller must be careful to
342 * only draw on top of opaque sections of the layer to get good results. 358 * only draw on top of opaque sections of the layer to get good results.
343 */ 359 */
344 int saveLayerPreserveLCDTextRequests(const SkRect* bounds, const SkPaint* pa int); 360 int saveLayerPreserveLCDTextRequests(const SkRect* bounds, const SkPaint* pa int);
345 361
362 #ifdef SK_SUPPORT_LEGACY_SAVEFLAGS
346 /** DEPRECATED - use saveLayer(const SkRect*, const SkPaint*) instead. 363 /** DEPRECATED - use saveLayer(const SkRect*, const SkPaint*) instead.
347 364
348 This behaves the same as saveLayer(const SkRect*, const SkPaint*), 365 This behaves the same as saveLayer(const SkRect*, const SkPaint*),
349 but it allows fine-grained control of which state bits to be saved 366 but it allows fine-grained control of which state bits to be saved
350 (and subsequently restored). 367 (and subsequently restored).
351 368
352 @param bounds (may be null) This rect, if non-null, is used as a hint to 369 @param bounds (may be null) This rect, if non-null, is used as a hint to
353 limit the size of the offscreen, and thus drawing may be 370 limit the size of the offscreen, and thus drawing may be
354 clipped to it, though that clipping is not guaranteed to 371 clipped to it, though that clipping is not guaranteed to
355 happen. If exact clipping is desired, use clipRect(). 372 happen. If exact clipping is desired, use clipRect().
356 @param paint (may be null) This is copied, and is applied to the 373 @param paint (may be null) This is copied, and is applied to the
357 offscreen when restore() is called 374 offscreen when restore() is called
358 @param flags LayerFlags 375 @param flags LayerFlags
359 @return The value to pass to restoreToCount() to balance this save() 376 @return The value to pass to restoreToCount() to balance this save()
360 */ 377 */
361 SK_ATTR_EXTERNALLY_DEPRECATED("SaveFlags use is deprecated") 378 SK_ATTR_EXTERNALLY_DEPRECATED("SaveFlags use is deprecated")
362 int saveLayer(const SkRect* bounds, const SkPaint* paint, SaveFlags flags); 379 int saveLayer(const SkRect* bounds, const SkPaint* paint, SaveFlags flags);
380 #endif
363 381
364 /** This behaves the same as save(), but in addition it allocates an 382 /** This behaves the same as save(), but in addition it allocates an
365 offscreen bitmap. All drawing calls are directed there, and only when 383 offscreen bitmap. All drawing calls are directed there, and only when
366 the balancing call to restore() is made is that offscreen transfered to 384 the balancing call to restore() is made is that offscreen transfered to
367 the canvas (or the previous layer). 385 the canvas (or the previous layer).
368 @param bounds (may be null) This rect, if non-null, is used as a hint to 386 @param bounds (may be null) This rect, if non-null, is used as a hint to
369 limit the size of the offscreen, and thus drawing may be 387 limit the size of the offscreen, and thus drawing may be
370 clipped to it, though that clipping is not guaranteed to 388 clipped to it, though that clipping is not guaranteed to
371 happen. If exact clipping is desired, use clipRect(). 389 happen. If exact clipping is desired, use clipRect().
372 @param alpha This is applied to the offscreen when restore() is called. 390 @param alpha This is applied to the offscreen when restore() is called.
373 @return The value to pass to restoreToCount() to balance this save() 391 @return The value to pass to restoreToCount() to balance this save()
374 */ 392 */
375 int saveLayerAlpha(const SkRect* bounds, U8CPU alpha); 393 int saveLayerAlpha(const SkRect* bounds, U8CPU alpha);
376 394
395 #ifdef SK_SUPPORT_LEGACY_SAVEFLAGS
377 /** DEPRECATED - use saveLayerAlpha(const SkRect*, U8CPU) instead. 396 /** DEPRECATED - use saveLayerAlpha(const SkRect*, U8CPU) instead.
378 397
379 This behaves the same as saveLayerAlpha(const SkRect*, U8CPU), 398 This behaves the same as saveLayerAlpha(const SkRect*, U8CPU),
380 but it allows fine-grained control of which state bits to be saved 399 but it allows fine-grained control of which state bits to be saved
381 (and subsequently restored). 400 (and subsequently restored).
382 401
383 @param bounds (may be null) This rect, if non-null, is used as a hint to 402 @param bounds (may be null) This rect, if non-null, is used as a hint to
384 limit the size of the offscreen, and thus drawing may be 403 limit the size of the offscreen, and thus drawing may be
385 clipped to it, though that clipping is not guaranteed to 404 clipped to it, though that clipping is not guaranteed to
386 happen. If exact clipping is desired, use clipRect(). 405 happen. If exact clipping is desired, use clipRect().
387 @param alpha This is applied to the offscreen when restore() is called. 406 @param alpha This is applied to the offscreen when restore() is called.
388 @param flags LayerFlags 407 @param flags LayerFlags
389 @return The value to pass to restoreToCount() to balance this save() 408 @return The value to pass to restoreToCount() to balance this save()
390 */ 409 */
391 SK_ATTR_EXTERNALLY_DEPRECATED("SaveFlags use is deprecated") 410 SK_ATTR_EXTERNALLY_DEPRECATED("SaveFlags use is deprecated")
392 int saveLayerAlpha(const SkRect* bounds, U8CPU alpha, SaveFlags flags); 411 int saveLayerAlpha(const SkRect* bounds, U8CPU alpha, SaveFlags flags);
412 #endif
393 413
394 enum { 414 enum {
395 kIsOpaque_SaveLayerFlag = 1 << 0, 415 kIsOpaque_SaveLayerFlag = 1 << 0,
396 kPreserveLCDText_SaveLayerFlag = 1 << 1, 416 kPreserveLCDText_SaveLayerFlag = 1 << 1,
417
418 #ifdef SK_SUPPORT_LEGACY_CLIPTOLAYERFLAG
419 kDontClipToLayer_Legacy_SaveLayerFlag = kDontClipToLayer_PrivateSaveLaye rFlag,
420 #endif
397 }; 421 };
398 typedef uint32_t SaveLayerFlags; 422 typedef uint32_t SaveLayerFlags;
399 423
400 struct SaveLayerRec { 424 struct SaveLayerRec {
401 SaveLayerRec() : fBounds(nullptr), fPaint(nullptr), fSaveLayerFlags(0) { } 425 SaveLayerRec() : fBounds(nullptr), fPaint(nullptr), fSaveLayerFlags(0) { }
402 SaveLayerRec(const SkRect* bounds, const SkPaint* paint, SaveLayerFlags saveLayerFlags = 0) 426 SaveLayerRec(const SkRect* bounds, const SkPaint* paint, SaveLayerFlags saveLayerFlags = 0)
403 : fBounds(bounds) 427 : fBounds(bounds)
404 , fPaint(paint) 428 , fPaint(paint)
405 , fSaveLayerFlags(saveLayerFlags) 429 , fSaveLayerFlags(saveLayerFlags)
406 {} 430 {}
(...skipping 916 matching lines...) Expand 10 before | Expand all | Expand 10 after
1323 virtual SkCanvas* canvasForDrawIter(); 1347 virtual SkCanvas* canvasForDrawIter();
1324 1348
1325 // Clip rectangle bounds. Called internally by saveLayer. 1349 // Clip rectangle bounds. Called internally by saveLayer.
1326 // returns false if the entire rectangle is entirely clipped out 1350 // returns false if the entire rectangle is entirely clipped out
1327 // If non-NULL, The imageFilter parameter will be used to expand the clip 1351 // If non-NULL, The imageFilter parameter will be used to expand the clip
1328 // and offscreen bounds for any margin required by the filter DAG. 1352 // and offscreen bounds for any margin required by the filter DAG.
1329 bool clipRectBounds(const SkRect* bounds, SaveLayerFlags, SkIRect* intersect ion, 1353 bool clipRectBounds(const SkRect* bounds, SaveLayerFlags, SkIRect* intersect ion,
1330 const SkImageFilter* imageFilter = NULL); 1354 const SkImageFilter* imageFilter = NULL);
1331 1355
1332 private: 1356 private:
1333 enum PrivateSaveLayerFlags {
1334 kDontClipToLayer_PrivateSaveLayerFlag = 1 << 31,
1335 };
1336
1337 static bool BoundsAffectsClip(SaveLayerFlags); 1357 static bool BoundsAffectsClip(SaveLayerFlags);
1358 #ifdef SK_SUPPORT_LEGACY_SAVEFLAGS
1338 static uint32_t SaveFlagsToSaveLayerFlags(SaveFlags); 1359 static uint32_t SaveFlagsToSaveLayerFlags(SaveFlags);
1360 #endif
1361 static SaveLayerFlags LegacySaveFlagsToSaveLayerFlags(uint32_t legacySaveFla gs);
1339 1362
1340 enum ShaderOverrideOpacity { 1363 enum ShaderOverrideOpacity {
1341 kNone_ShaderOverrideOpacity, //!< there is no overriding shader ( bitmap or image) 1364 kNone_ShaderOverrideOpacity, //!< there is no overriding shader ( bitmap or image)
1342 kOpaque_ShaderOverrideOpacity, //!< the overriding shader is opaque 1365 kOpaque_ShaderOverrideOpacity, //!< the overriding shader is opaque
1343 kNotOpaque_ShaderOverrideOpacity, //!< the overriding shader may not b e opaque 1366 kNotOpaque_ShaderOverrideOpacity, //!< the overriding shader may not b e opaque
1344 }; 1367 };
1345 1368
1346 // notify our surface (if we have one) that we are about to draw, so it 1369 // notify our surface (if we have one) that we are about to draw, so it
1347 // can perform copy-on-write or invalidate any cached images 1370 // can perform copy-on-write or invalidate any cached images
1348 void predrawNotify(bool willOverwritesEntireSurface = false); 1371 void predrawNotify(bool willOverwritesEntireSurface = false);
(...skipping 218 matching lines...) Expand 10 before | Expand all | Expand 10 after
1567 // the caller must respect the restrictions associated with peekPixels(). 1590 // the caller must respect the restrictions associated with peekPixels().
1568 bool asROBitmap(SkBitmap*) const; 1591 bool asROBitmap(SkBitmap*) const;
1569 1592
1570 private: 1593 private:
1571 SkBitmap fBitmap; // used if peekPixels() fails 1594 SkBitmap fBitmap; // used if peekPixels() fails
1572 const void* fAddr; // NULL on failure 1595 const void* fAddr; // NULL on failure
1573 SkImageInfo fInfo; 1596 SkImageInfo fInfo;
1574 size_t fRowBytes; 1597 size_t fRowBytes;
1575 }; 1598 };
1576 1599
1600 #ifdef SK_SUPPORT_LEGACY_SAVEFLAGS
1577 static inline SkCanvas::SaveFlags operator|(const SkCanvas::SaveFlags lhs, 1601 static inline SkCanvas::SaveFlags operator|(const SkCanvas::SaveFlags lhs,
1578 const SkCanvas::SaveFlags rhs) { 1602 const SkCanvas::SaveFlags rhs) {
1579 return static_cast<SkCanvas::SaveFlags>(static_cast<int>(lhs) | static_cast< int>(rhs)); 1603 return static_cast<SkCanvas::SaveFlags>(static_cast<int>(lhs) | static_cast< int>(rhs));
1580 } 1604 }
1581 1605
1582 static inline SkCanvas::SaveFlags& operator|=(SkCanvas::SaveFlags& lhs, 1606 static inline SkCanvas::SaveFlags& operator|=(SkCanvas::SaveFlags& lhs,
1583 const SkCanvas::SaveFlags rhs) { 1607 const SkCanvas::SaveFlags rhs) {
1584 lhs = lhs | rhs; 1608 lhs = lhs | rhs;
1585 return lhs; 1609 return lhs;
1586 } 1610 }
1611 #endif
1587 1612
1588 class SkCanvasClipVisitor { 1613 class SkCanvasClipVisitor {
1589 public: 1614 public:
1590 virtual ~SkCanvasClipVisitor(); 1615 virtual ~SkCanvasClipVisitor();
1591 virtual void clipRect(const SkRect&, SkRegion::Op, bool antialias) = 0; 1616 virtual void clipRect(const SkRect&, SkRegion::Op, bool antialias) = 0;
1592 virtual void clipRRect(const SkRRect&, SkRegion::Op, bool antialias) = 0; 1617 virtual void clipRRect(const SkRRect&, SkRegion::Op, bool antialias) = 0;
1593 virtual void clipPath(const SkPath&, SkRegion::Op, bool antialias) = 0; 1618 virtual void clipPath(const SkPath&, SkRegion::Op, bool antialias) = 0;
1594 }; 1619 };
1595 1620
1596 #endif 1621 #endif
OLDNEW
« no previous file with comments | « no previous file | src/core/SkCanvas.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698