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

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

Issue 239163002: WIP -- separate out Parts from SkPaint (Closed) Base URL: https://skia.googlecode.com/svn/trunk
Patch Set: Created 6 years, 8 months 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 | Annotate | Revision Log
« no previous file with comments | « no previous file | include/core/SkPaintParts.h » ('j') | include/core/SkPaintParts.h » ('J')
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 1
2 2
3 /* 3 /*
4 * Copyright 2006 The Android Open Source Project 4 * Copyright 2006 The Android Open Source Project
5 * 5 *
6 * Use of this source code is governed by a BSD-style license that can be 6 * Use of this source code is governed by a BSD-style license that can be
7 * found in the LICENSE file. 7 * found in the LICENSE file.
8 */ 8 */
9 9
10 10
11 #ifndef SkPaint_DEFINED 11 #ifndef SkPaint_DEFINED
12 #define SkPaint_DEFINED 12 #define SkPaint_DEFINED
13 13
14 #include "SkColor.h" 14 #include "SkPaintParts.h"
15 #include "SkDrawLooper.h" 15 #include "SkDrawLooper.h"
16 #include "SkMatrix.h" 16 #include "SkMatrix.h"
17 #include "SkXfermode.h" 17 #include "SkXfermode.h"
18 #ifdef SK_BUILD_FOR_ANDROID
19 #include "SkPaintOptionsAndroid.h"
20 #endif
21
22 class SkAnnotation;
23 class SkAutoGlyphCache;
24 class SkColorFilter;
25 class SkDescriptor;
26 struct SkDeviceProperties;
27 class SkReadBuffer;
28 class SkWriteBuffer;
29 struct SkGlyph;
30 struct SkRect;
31 class SkGlyphCache;
32 class SkImageFilter;
33 class SkMaskFilter;
34 class SkPath;
35 class SkPathEffect;
36 struct SkPoint;
37 class SkRasterizer;
38 class SkShader;
39 class SkTypeface;
40 18
41 typedef const SkGlyph& (*SkDrawCacheProc)(SkGlyphCache*, const char**, 19 typedef const SkGlyph& (*SkDrawCacheProc)(SkGlyphCache*, const char**,
42 SkFixed x, SkFixed y); 20 SkFixed x, SkFixed y);
43 21
44 typedef const SkGlyph& (*SkMeasureCacheProc)(SkGlyphCache*, const char**); 22 typedef const SkGlyph& (*SkMeasureCacheProc)(SkGlyphCache*, const char**);
45 23
46 #define kBicubicFilterBitmap_Flag kHighQualityFilterBitmap_Flag 24 #define kBicubicFilterBitmap_Flag kHighQualityFilterBitmap_Flag
47 25
48 /** \class SkPaint 26 /** \class SkPaint
49 27
50 The SkPaint class holds the style and color information about how to draw 28 The SkPaint class holds the style and color information about how to draw
51 geometries, text and bitmaps. 29 geometries, text and bitmaps.
52 */ 30 */
53 31
54 class SK_API SkPaint { 32 class SK_API SkPaint {
55 enum { 33 enum {
56 // DEPRECATED -- use setFilterLevel instead 34 // DEPRECATED -- use setFilterLevel instead
57 kFilterBitmap_Flag = 0x02, // temporary flag 35 kFilterBitmap_Flag = 0x02, // temporary flag
58 // DEPRECATED -- use setFilterLevel instead 36 // DEPRECATED -- use setFilterLevel instead
59 kHighQualityFilterBitmap_Flag = 0x4000, // temporary flag 37 kHighQualityFilterBitmap_Flag = 0x4000, // temporary flag
60 // DEPRECATED -- use setFilterLevel instead 38 // DEPRECATED -- use setFilterLevel instead
61 kHighQualityDownsampleBitmap_Flag = 0x8000, // temporary flag 39 kHighQualityDownsampleBitmap_Flag = 0x8000, // temporary flag
62 }; 40 };
63 public: 41 public:
64 SkPaint(); 42 SkPaint();
65 SkPaint(const SkPaint& paint); 43 SkPaint(const SkPaint& paint);
66 ~SkPaint(); 44 ~SkPaint();
67 45
46 operator const SkPaintParts& () const { return fParts; }
47
68 SkPaint& operator=(const SkPaint&); 48 SkPaint& operator=(const SkPaint&);
69 49
70 SK_API friend bool operator==(const SkPaint& a, const SkPaint& b); 50 SK_API friend bool operator==(const SkPaint& a, const SkPaint& b);
71 friend bool operator!=(const SkPaint& a, const SkPaint& b) { 51 friend bool operator!=(const SkPaint& a, const SkPaint& b) {
72 return !(a == b); 52 return !(a == b);
73 } 53 }
74 54
75 void flatten(SkWriteBuffer&) const; 55 void flatten(SkWriteBuffer&) const;
76 void unflatten(SkReadBuffer&); 56 void unflatten(SkReadBuffer&);
77 57
(...skipping 11 matching lines...) Expand all
89 subpixel glyphs, in which case TARGET_LCD or 69 subpixel glyphs, in which case TARGET_LCD or
90 TARGET_LCD_V is used> 70 TARGET_LCD_V is used>
91 */ 71 */
92 enum Hinting { 72 enum Hinting {
93 kNo_Hinting = 0, 73 kNo_Hinting = 0,
94 kSlight_Hinting = 1, 74 kSlight_Hinting = 1,
95 kNormal_Hinting = 2, //!< this is the default 75 kNormal_Hinting = 2, //!< this is the default
96 kFull_Hinting = 3 76 kFull_Hinting = 3
97 }; 77 };
98 78
99 Hinting getHinting() const { 79 Hinting getHinting() const { return (Hinting)fParts.getHinting(); }
100 return static_cast<Hinting>(fHinting);
101 }
102
103 void setHinting(Hinting hintingLevel); 80 void setHinting(Hinting hintingLevel);
104 81
105 /** Specifies the bit values that are stored in the paint's flags. 82 /** Specifies the bit values that are stored in the paint's flags.
106 */ 83 */
107 enum Flags { 84 enum Flags {
108 kAntiAlias_Flag = 0x01, //!< mask to enable antialiasing 85 kAntiAlias_Flag = 0x01, //!< mask to enable antialiasing
109 kDither_Flag = 0x04, //!< mask to enable dithering 86 kDither_Flag = 0x04, //!< mask to enable dithering
110 kUnderlineText_Flag = 0x08, //!< mask to enable underline text 87 kUnderlineText_Flag = 0x08, //!< mask to enable underline text
111 kStrikeThruText_Flag = 0x10, //!< mask to enable strike-thru text 88 kStrikeThruText_Flag = 0x10, //!< mask to enable strike-thru text
112 kFakeBoldText_Flag = 0x20, //!< mask to enable fake-bold text 89 kFakeBoldText_Flag = 0x20, //!< mask to enable fake-bold text
113 kLinearText_Flag = 0x40, //!< mask to enable linear-text 90 kLinearText_Flag = 0x40, //!< mask to enable linear-text
114 kSubpixelText_Flag = 0x80, //!< mask to enable subpixel text positi oning 91 kSubpixelText_Flag = 0x80, //!< mask to enable subpixel text positi oning
115 kDevKernText_Flag = 0x100, //!< mask to enable device kerning text 92 kDevKernText_Flag = 0x100, //!< mask to enable device kerning text
116 kLCDRenderText_Flag = 0x200, //!< mask to enable subpixel glyph rende rering 93 kLCDRenderText_Flag = 0x200, //!< mask to enable subpixel glyph rende rering
117 kEmbeddedBitmapText_Flag = 0x400, //!< mask to enable embedded bitmap st rikes 94 kEmbeddedBitmapText_Flag = 0x400, //!< mask to enable embedded bitmap st rikes
118 kAutoHinting_Flag = 0x800, //!< mask to force Freetype's autohinter 95 kAutoHinting_Flag = 0x800, //!< mask to force Freetype's autohinter
119 kVerticalText_Flag = 0x1000, 96 kVerticalText_Flag = 0x1000,
120 kGenA8FromLCD_Flag = 0x2000, // hack for GDI -- do not use if you can help it 97 kGenA8FromLCD_Flag = 0x2000, // hack for GDI -- do not use if you can help it
121 kDistanceFieldTextTEMP_Flag = 0x4000, //!< TEMPORARY mask to enable dist ance fields 98 kDistanceFieldTextTEMP_Flag = 0x4000, //!< TEMPORARY mask to enable dist ance fields
122 // currently overrides LCD and sub pixel rendering 99 // currently overrides LCD and sub pixel rendering
123 // when adding extra flags, note that the fFlags member is specified 100 // when adding extra flags, note that the fFlags member is specified
124 // with a bit-width and you'll have to expand it. 101 // with a bit-width and you'll have to expand it.
125 102
126 kAllFlags = 0xFFFF 103 kAllFlags = 0xFFFF
127 }; 104 };
128 105
129 /** Return the paint's flags. Use the Flag enum to test flag values. 106 /** Return the paint's flags. Use the Flag enum to test flag values.
130 @return the paint's flags (see enums ending in _Flag for bit masks) 107 @return the paint's flags (see enums ending in _Flag for bit masks)
131 */ 108 */
132 uint32_t getFlags() const { return fFlags; } 109 uint32_t getFlags() const { return fParts.getFlags(); }
133 110
134 /** Set the paint's flags. Use the Flag enum to specific flag values. 111 /** Set the paint's flags. Use the Flag enum to specific flag values.
135 @param flags The new flag bits for the paint (see Flags enum) 112 @param flags The new flag bits for the paint (see Flags enum)
136 */ 113 */
137 void setFlags(uint32_t flags); 114 void setFlags(uint32_t flags);
138 115
139 /** Helper for getFlags(), returning true if kAntiAlias_Flag bit is set 116 /** Helper for getFlags(), returning true if kAntiAlias_Flag bit is set
140 @return true if the antialias bit is set in the paint's flags. 117 @return true if the antialias bit is set in the paint's flags.
141 */ 118 */
142 bool isAntiAlias() const { 119 bool isAntiAlias() const {
(...skipping 208 matching lines...) Expand 10 before | Expand all | Expand 10 after
351 }; 328 };
352 enum { 329 enum {
353 kStyleCount = kStrokeAndFill_Style + 1 330 kStyleCount = kStrokeAndFill_Style + 1
354 }; 331 };
355 332
356 /** Return the paint's style, used for controlling how primitives' 333 /** Return the paint's style, used for controlling how primitives'
357 geometries are interpreted (except for drawBitmap, which always assumes 334 geometries are interpreted (except for drawBitmap, which always assumes
358 kFill_Style). 335 kFill_Style).
359 @return the paint's Style 336 @return the paint's Style
360 */ 337 */
361 Style getStyle() const { return (Style)fStyle; } 338 Style getStyle() const { return (Style)fParts.getStyle(); }
362 339
363 /** Set the paint's style, used for controlling how primitives' 340 /** Set the paint's style, used for controlling how primitives'
364 geometries are interpreted (except for drawBitmap, which always assumes 341 geometries are interpreted (except for drawBitmap, which always assumes
365 Fill). 342 Fill).
366 @param style The new style to set in the paint 343 @param style The new style to set in the paint
367 */ 344 */
368 void setStyle(Style style); 345 void setStyle(Style style);
369 346
370 /** Return the paint's color. Note that the color is a 32bit value 347 /** Return the paint's color. Note that the color is a 32bit value
371 containing alpha as well as r,g,b. This 32bit value is not 348 containing alpha as well as r,g,b. This 32bit value is not
372 premultiplied, meaning that its alpha can be any value, regardless of 349 premultiplied, meaning that its alpha can be any value, regardless of
373 the values of r,g,b. 350 the values of r,g,b.
374 @return the paint's color (and alpha). 351 @return the paint's color (and alpha).
375 */ 352 */
376 SkColor getColor() const { return fColor; } 353 SkColor getColor() const { return fParts.fColor; }
377 354
378 /** Set the paint's color. Note that the color is a 32bit value containing 355 /** Set the paint's color. Note that the color is a 32bit value containing
379 alpha as well as r,g,b. This 32bit value is not premultiplied, meaning 356 alpha as well as r,g,b. This 32bit value is not premultiplied, meaning
380 that its alpha can be any value, regardless of the values of r,g,b. 357 that its alpha can be any value, regardless of the values of r,g,b.
381 @param color The new color (including alpha) to set in the paint. 358 @param color The new color (including alpha) to set in the paint.
382 */ 359 */
383 void setColor(SkColor color); 360 void setColor(SkColor color);
384 361
385 /** Helper to getColor() that just returns the color's alpha value. 362 /** Helper to getColor() that just returns the color's alpha value.
386 @return the alpha component of the paint's color. 363 @return the alpha component of the paint's color.
387 */ 364 */
388 uint8_t getAlpha() const { return SkToU8(SkColorGetA(fColor)); } 365 uint8_t getAlpha() const { return SkToU8(SkColorGetA(this->getColor())); }
389 366
390 /** Helper to setColor(), that only assigns the color's alpha value, 367 /** Helper to setColor(), that only assigns the color's alpha value,
391 leaving its r,g,b values unchanged. 368 leaving its r,g,b values unchanged.
392 @param a set the alpha component (0..255) of the paint's color. 369 @param a set the alpha component (0..255) of the paint's color.
393 */ 370 */
394 void setAlpha(U8CPU a); 371 void setAlpha(U8CPU a);
395 372
396 /** Helper to setColor(), that takes a,r,g,b and constructs the color value 373 /** Helper to setColor(), that takes a,r,g,b and constructs the color value
397 using SkColorSetARGB() 374 using SkColorSetARGB()
398 @param a The new alpha component (0..255) of the paint's color. 375 @param a The new alpha component (0..255) of the paint's color.
399 @param r The new red component (0..255) of the paint's color. 376 @param r The new red component (0..255) of the paint's color.
400 @param g The new green component (0..255) of the paint's color. 377 @param g The new green component (0..255) of the paint's color.
401 @param b The new blue component (0..255) of the paint's color. 378 @param b The new blue component (0..255) of the paint's color.
402 */ 379 */
403 void setARGB(U8CPU a, U8CPU r, U8CPU g, U8CPU b); 380 void setARGB(U8CPU a, U8CPU r, U8CPU g, U8CPU b);
404 381
405 /** Return the width for stroking. 382 /** Return the width for stroking.
406 <p /> 383 <p />
407 A value of 0 strokes in hairline mode. 384 A value of 0 strokes in hairline mode.
408 Hairlines always draw 1-pixel wide, regardless of the matrix. 385 Hairlines always draw 1-pixel wide, regardless of the matrix.
409 @return the paint's stroke width, used whenever the paint's style is 386 @return the paint's stroke width, used whenever the paint's style is
410 Stroke or StrokeAndFill. 387 Stroke or StrokeAndFill.
411 */ 388 */
412 SkScalar getStrokeWidth() const { return fWidth; } 389 SkScalar getStrokeWidth() const { return fParts.getStrokeWidth(); }
413 390
414 /** Set the width for stroking. 391 /** Set the width for stroking.
415 Pass 0 to stroke in hairline mode. 392 Pass 0 to stroke in hairline mode.
416 Hairlines always draw 1-pixel wide, regardless of the matrix. 393 Hairlines always draw 1-pixel wide, regardless of the matrix.
417 @param width set the paint's stroke width, used whenever the paint's 394 @param width set the paint's stroke width, used whenever the paint's
418 style is Stroke or StrokeAndFill. 395 style is Stroke or StrokeAndFill.
419 */ 396 */
420 void setStrokeWidth(SkScalar width); 397 void setStrokeWidth(SkScalar width);
421 398
422 /** Return the paint's stroke miter value. This is used to control the 399 /** Return the paint's stroke miter value. This is used to control the
423 behavior of miter joins when the joins angle is sharp. 400 behavior of miter joins when the joins angle is sharp.
424 @return the paint's miter limit, used whenever the paint's style is 401 @return the paint's miter limit, used whenever the paint's style is
425 Stroke or StrokeAndFill. 402 Stroke or StrokeAndFill.
426 */ 403 */
427 SkScalar getStrokeMiter() const { return fMiterLimit; } 404 SkScalar getStrokeMiter() const { return fParts.getStrokeMiter(); }
428 405
429 /** Set the paint's stroke miter value. This is used to control the 406 /** Set the paint's stroke miter value. This is used to control the
430 behavior of miter joins when the joins angle is sharp. This value must 407 behavior of miter joins when the joins angle is sharp. This value must
431 be >= 0. 408 be >= 0.
432 @param miter set the miter limit on the paint, used whenever the 409 @param miter set the miter limit on the paint, used whenever the
433 paint's style is Stroke or StrokeAndFill. 410 paint's style is Stroke or StrokeAndFill.
434 */ 411 */
435 void setStrokeMiter(SkScalar miter); 412 void setStrokeMiter(SkScalar miter);
436 413
437 /** Cap enum specifies the settings for the paint's strokecap. This is the 414 /** Cap enum specifies the settings for the paint's strokecap. This is the
(...skipping 19 matching lines...) Expand all
457 434
458 kJoinCount, 435 kJoinCount,
459 kDefault_Join = kMiter_Join 436 kDefault_Join = kMiter_Join
460 }; 437 };
461 438
462 /** Return the paint's stroke cap type, controlling how the start and end 439 /** Return the paint's stroke cap type, controlling how the start and end
463 of stroked lines and paths are treated. 440 of stroked lines and paths are treated.
464 @return the line cap style for the paint, used whenever the paint's 441 @return the line cap style for the paint, used whenever the paint's
465 style is Stroke or StrokeAndFill. 442 style is Stroke or StrokeAndFill.
466 */ 443 */
467 Cap getStrokeCap() const { return (Cap)fCapType; } 444 Cap getStrokeCap() const { return (Cap)fParts.getStrokeCap(); }
468 445
469 /** Set the paint's stroke cap type. 446 /** Set the paint's stroke cap type.
470 @param cap set the paint's line cap style, used whenever the paint's 447 @param cap set the paint's line cap style, used whenever the paint's
471 style is Stroke or StrokeAndFill. 448 style is Stroke or StrokeAndFill.
472 */ 449 */
473 void setStrokeCap(Cap cap); 450 void setStrokeCap(Cap cap);
474 451
475 /** Return the paint's stroke join type. 452 /** Return the paint's stroke join type.
476 @return the paint's line join style, used whenever the paint's style is 453 @return the paint's line join style, used whenever the paint's style is
477 Stroke or StrokeAndFill. 454 Stroke or StrokeAndFill.
478 */ 455 */
479 Join getStrokeJoin() const { return (Join)fJoinType; } 456 Join getStrokeJoin() const { return (Join)fParts.getStrokeJoin(); }
scroggo 2014/04/15 17:21:07 Wait, are you casting from an SkPaintParts::Join t
reed1 2014/04/18 14:04:31 Temporary, to simplify all 1000+ callsites of SkPa
480 457
481 /** Set the paint's stroke join type. 458 /** Set the paint's stroke join type.
482 @param join set the paint's line join style, used whenever the paint's 459 @param join set the paint's line join style, used whenever the paint's
483 style is Stroke or StrokeAndFill. 460 style is Stroke or StrokeAndFill.
484 */ 461 */
485 void setStrokeJoin(Join join); 462 void setStrokeJoin(Join join);
486 463
487 /** 464 /**
488 * Applies any/all effects (patheffect, stroking) to src, returning the 465 * Applies any/all effects (patheffect, stroking) to src, returning the
489 * result in dst. The result is that drawing src with this paint will be 466 * result in dst. The result is that drawing src with this paint will be
490 * the same as drawing dst with a default paint (at least from the 467 * the same as drawing dst with a default paint (at least from the
491 * geometric perspective). 468 * geometric perspective).
492 * 469 *
493 * @param src input path 470 * @param src input path
494 * @param dst output path (may be the same as src) 471 * @param dst output path (may be the same as src)
495 * @param cullRect If not null, the dst path may be culled to this rect. 472 * @param cullRect If not null, the dst path may be culled to this rect.
496 * @return true if the path should be filled, or false if it should be 473 * @return true if the path should be filled, or false if it should be
497 * drawn with a hairline (width == 0) 474 * drawn with a hairline (width == 0)
498 */ 475 */
499 bool getFillPath(const SkPath& src, SkPath* dst, 476 bool getFillPath(const SkPath& src, SkPath* dst,
500 const SkRect* cullRect = NULL) const; 477 const SkRect* cullRect = NULL) const;
501 478
502 /** Get the paint's shader object. 479 /** Get the paint's shader object.
503 <p /> 480 <p />
504 The shader's reference count is not affected. 481 The shader's reference count is not affected.
505 @return the paint's shader (or NULL) 482 @return the paint's shader (or NULL)
506 */ 483 */
507 SkShader* getShader() const { return fShader; } 484 SkShader* getShader() const { return fParts.fShader; }
508 485
509 /** Set or clear the shader object. 486 /** Set or clear the shader object.
510 * Shaders specify the source color(s) for what is being drawn. If a paint 487 * Shaders specify the source color(s) for what is being drawn. If a paint
511 * has no shader, then the paint's color is used. If the paint has a 488 * has no shader, then the paint's color is used. If the paint has a
512 * shader, then the shader's color(s) are use instead, but they are 489 * shader, then the shader's color(s) are use instead, but they are
513 * modulated by the paint's alpha. This makes it easy to create a shader 490 * modulated by the paint's alpha. This makes it easy to create a shader
514 * once (e.g. bitmap tiling or gradient) and then change its transparency 491 * once (e.g. bitmap tiling or gradient) and then change its transparency
515 * w/o having to modify the original shader... only the paint's alpha needs 492 * w/o having to modify the original shader... only the paint's alpha needs
516 * to be modified. 493 * to be modified.
517 * 494 *
518 * There is an exception to this only-respect-paint's-alpha rule: If the sh ader only generates 495 * There is an exception to this only-respect-paint's-alpha rule: If the sh ader only generates
519 * alpha (e.g. SkShader::CreateBitmapShader(bitmap, ...) where bitmap's col ortype is kAlpha_8) 496 * alpha (e.g. SkShader::CreateBitmapShader(bitmap, ...) where bitmap's col ortype is kAlpha_8)
520 * then the shader will use the paint's entire color to "colorize" its outp ut (modulating the 497 * then the shader will use the paint's entire color to "colorize" its outp ut (modulating the
521 * bitmap's alpha with the paint's color+alpha). 498 * bitmap's alpha with the paint's color+alpha).
522 * 499 *
523 * Pass NULL to clear any previous shader. 500 * Pass NULL to clear any previous shader.
524 * As a convenience, the parameter passed is also returned. 501 * As a convenience, the parameter passed is also returned.
525 * If a previous shader exists, its reference count is decremented. 502 * If a previous shader exists, its reference count is decremented.
526 * If shader is not NULL, its reference count is incremented. 503 * If shader is not NULL, its reference count is incremented.
527 * @param shader May be NULL. The shader to be installed in the paint 504 * @param shader May be NULL. The shader to be installed in the paint
528 * @return shader 505 * @return shader
529 */ 506 */
530 SkShader* setShader(SkShader* shader); 507 SkShader* setShader(SkShader* shader);
531 508
532 /** Get the paint's colorfilter. If there is a colorfilter, its reference 509 /** Get the paint's colorfilter. If there is a colorfilter, its reference
533 count is not changed. 510 count is not changed.
534 @return the paint's colorfilter (or NULL) 511 @return the paint's colorfilter (or NULL)
535 */ 512 */
536 SkColorFilter* getColorFilter() const { return fColorFilter; } 513 SkColorFilter* getColorFilter() const { return fParts.fColorFilter; }
537 514
538 /** Set or clear the paint's colorfilter, returning the parameter. 515 /** Set or clear the paint's colorfilter, returning the parameter.
539 <p /> 516 <p />
540 If the paint already has a filter, its reference count is decremented. 517 If the paint already has a filter, its reference count is decremented.
541 If filter is not NULL, its reference count is incremented. 518 If filter is not NULL, its reference count is incremented.
542 @param filter May be NULL. The filter to be installed in the paint 519 @param filter May be NULL. The filter to be installed in the paint
543 @return filter 520 @return filter
544 */ 521 */
545 SkColorFilter* setColorFilter(SkColorFilter* filter); 522 SkColorFilter* setColorFilter(SkColorFilter* filter);
546 523
547 /** Get the paint's xfermode object. 524 /** Get the paint's xfermode object.
548 <p /> 525 <p />
549 The xfermode's reference count is not affected. 526 The xfermode's reference count is not affected.
550 @return the paint's xfermode (or NULL) 527 @return the paint's xfermode (or NULL)
551 */ 528 */
552 SkXfermode* getXfermode() const { return fXfermode; } 529 SkXfermode* getXfermode() const { return fParts.fXfermode; }
553 530
554 /** Set or clear the xfermode object. 531 /** Set or clear the xfermode object.
555 <p /> 532 <p />
556 Pass NULL to clear any previous xfermode. 533 Pass NULL to clear any previous xfermode.
557 As a convenience, the parameter passed is also returned. 534 As a convenience, the parameter passed is also returned.
558 If a previous xfermode exists, its reference count is decremented. 535 If a previous xfermode exists, its reference count is decremented.
559 If xfermode is not NULL, its reference count is incremented. 536 If xfermode is not NULL, its reference count is incremented.
560 @param xfermode May be NULL. The new xfermode to be installed in the 537 @param xfermode May be NULL. The new xfermode to be installed in the
561 paint 538 paint
562 @return xfermode 539 @return xfermode
563 */ 540 */
564 SkXfermode* setXfermode(SkXfermode* xfermode); 541 SkXfermode* setXfermode(SkXfermode* xfermode);
565 542
566 /** Create an xfermode based on the specified Mode, and assign it into the 543 /** Create an xfermode based on the specified Mode, and assign it into the
567 paint, returning the mode that was set. If the Mode is SrcOver, then 544 paint, returning the mode that was set. If the Mode is SrcOver, then
568 the paint's xfermode is set to null. 545 the paint's xfermode is set to null.
569 */ 546 */
570 SkXfermode* setXfermodeMode(SkXfermode::Mode); 547 SkXfermode* setXfermodeMode(SkXfermode::Mode);
571 548
572 /** Get the paint's patheffect object. 549 /** Get the paint's patheffect object.
573 <p /> 550 <p />
574 The patheffect reference count is not affected. 551 The patheffect reference count is not affected.
575 @return the paint's patheffect (or NULL) 552 @return the paint's patheffect (or NULL)
576 */ 553 */
577 SkPathEffect* getPathEffect() const { return fPathEffect; } 554 SkPathEffect* getPathEffect() const { return fParts.fPathEffect; }
578 555
579 /** Set or clear the patheffect object. 556 /** Set or clear the patheffect object.
580 <p /> 557 <p />
581 Pass NULL to clear any previous patheffect. 558 Pass NULL to clear any previous patheffect.
582 As a convenience, the parameter passed is also returned. 559 As a convenience, the parameter passed is also returned.
583 If a previous patheffect exists, its reference count is decremented. 560 If a previous patheffect exists, its reference count is decremented.
584 If patheffect is not NULL, its reference count is incremented. 561 If patheffect is not NULL, its reference count is incremented.
585 @param effect May be NULL. The new patheffect to be installed in the 562 @param effect May be NULL. The new patheffect to be installed in the
586 paint 563 paint
587 @return effect 564 @return effect
588 */ 565 */
589 SkPathEffect* setPathEffect(SkPathEffect* effect); 566 SkPathEffect* setPathEffect(SkPathEffect* effect);
590 567
591 /** Get the paint's maskfilter object. 568 /** Get the paint's maskfilter object.
592 <p /> 569 <p />
593 The maskfilter reference count is not affected. 570 The maskfilter reference count is not affected.
594 @return the paint's maskfilter (or NULL) 571 @return the paint's maskfilter (or NULL)
595 */ 572 */
596 SkMaskFilter* getMaskFilter() const { return fMaskFilter; } 573 SkMaskFilter* getMaskFilter() const { return fParts.fMaskFilter; }
597 574
598 /** Set or clear the maskfilter object. 575 /** Set or clear the maskfilter object.
599 <p /> 576 <p />
600 Pass NULL to clear any previous maskfilter. 577 Pass NULL to clear any previous maskfilter.
601 As a convenience, the parameter passed is also returned. 578 As a convenience, the parameter passed is also returned.
602 If a previous maskfilter exists, its reference count is decremented. 579 If a previous maskfilter exists, its reference count is decremented.
603 If maskfilter is not NULL, its reference count is incremented. 580 If maskfilter is not NULL, its reference count is incremented.
604 @param maskfilter May be NULL. The new maskfilter to be installed in 581 @param maskfilter May be NULL. The new maskfilter to be installed in
605 the paint 582 the paint
606 @return maskfilter 583 @return maskfilter
607 */ 584 */
608 SkMaskFilter* setMaskFilter(SkMaskFilter* maskfilter); 585 SkMaskFilter* setMaskFilter(SkMaskFilter* maskfilter);
609 586
610 // These attributes are for text/fonts 587 // These attributes are for text/fonts
611 588
612 /** Get the paint's typeface object. 589 /** Get the paint's typeface object.
613 <p /> 590 <p />
614 The typeface object identifies which font to use when drawing or 591 The typeface object identifies which font to use when drawing or
615 measuring text. The typeface reference count is not affected. 592 measuring text. The typeface reference count is not affected.
616 @return the paint's typeface (or NULL) 593 @return the paint's typeface (or NULL)
617 */ 594 */
618 SkTypeface* getTypeface() const { return fTypeface; } 595 SkTypeface* getTypeface() const { return fParts.fTypeface; }
619 596
620 /** Set or clear the typeface object. 597 /** Set or clear the typeface object.
621 <p /> 598 <p />
622 Pass NULL to clear any previous typeface. 599 Pass NULL to clear any previous typeface.
623 As a convenience, the parameter passed is also returned. 600 As a convenience, the parameter passed is also returned.
624 If a previous typeface exists, its reference count is decremented. 601 If a previous typeface exists, its reference count is decremented.
625 If typeface is not NULL, its reference count is incremented. 602 If typeface is not NULL, its reference count is incremented.
626 @param typeface May be NULL. The new typeface to be installed in the 603 @param typeface May be NULL. The new typeface to be installed in the
627 paint 604 paint
628 @return typeface 605 @return typeface
629 */ 606 */
630 SkTypeface* setTypeface(SkTypeface* typeface); 607 SkTypeface* setTypeface(SkTypeface* typeface);
631 608
632 /** Get the paint's rasterizer (or NULL). 609 /** Get the paint's rasterizer (or NULL).
633 <p /> 610 <p />
634 The raster controls how paths/text are turned into alpha masks. 611 The raster controls how paths/text are turned into alpha masks.
635 @return the paint's rasterizer (or NULL) 612 @return the paint's rasterizer (or NULL)
636 */ 613 */
637 SkRasterizer* getRasterizer() const { return fRasterizer; } 614 SkRasterizer* getRasterizer() const { return fParts.fRasterizer; }
638 615
639 /** Set or clear the rasterizer object. 616 /** Set or clear the rasterizer object.
640 <p /> 617 <p />
641 Pass NULL to clear any previous rasterizer. 618 Pass NULL to clear any previous rasterizer.
642 As a convenience, the parameter passed is also returned. 619 As a convenience, the parameter passed is also returned.
643 If a previous rasterizer exists in the paint, its reference count is 620 If a previous rasterizer exists in the paint, its reference count is
644 decremented. If rasterizer is not NULL, its reference count is 621 decremented. If rasterizer is not NULL, its reference count is
645 incremented. 622 incremented.
646 @param rasterizer May be NULL. The new rasterizer to be installed in 623 @param rasterizer May be NULL. The new rasterizer to be installed in
647 the paint. 624 the paint.
648 @return rasterizer 625 @return rasterizer
649 */ 626 */
650 SkRasterizer* setRasterizer(SkRasterizer* rasterizer); 627 SkRasterizer* setRasterizer(SkRasterizer* rasterizer);
651 628
652 SkImageFilter* getImageFilter() const { return fImageFilter; } 629 SkImageFilter* getImageFilter() const { return fParts.fImageFilter; }
653 SkImageFilter* setImageFilter(SkImageFilter*); 630 SkImageFilter* setImageFilter(SkImageFilter*);
654 631
655 SkAnnotation* getAnnotation() const { return fAnnotation; } 632 SkAnnotation* getAnnotation() const { return fParts.fAnnotation; }
656 SkAnnotation* setAnnotation(SkAnnotation*); 633 SkAnnotation* setAnnotation(SkAnnotation*);
657 634
658 /** 635 /**
659 * Returns true if there is an annotation installed on this paint, and 636 * Returns true if there is an annotation installed on this paint, and
660 * the annotation specifics no-drawing. 637 * the annotation specifics no-drawing.
661 */ 638 */
662 SK_ATTR_DEPRECATED("use getAnnotation and check for non-null") 639 SK_ATTR_DEPRECATED("use getAnnotation and check for non-null")
663 bool isNoDrawAnnotation() const { return this->getAnnotation() != NULL; } 640 bool isNoDrawAnnotation() const { return this->getAnnotation() != NULL; }
664 641
665 /** 642 /**
666 * Return the paint's SkDrawLooper (if any). Does not affect the looper's 643 * Return the paint's SkDrawLooper (if any). Does not affect the looper's
667 * reference count. 644 * reference count.
668 */ 645 */
669 SkDrawLooper* getLooper() const { return fLooper; } 646 SkDrawLooper* getLooper() const { return fParts.fLooper; }
670 647
671 /** 648 /**
672 * Set or clear the looper object. 649 * Set or clear the looper object.
673 * <p /> 650 * <p />
674 * Pass NULL to clear any previous looper. 651 * Pass NULL to clear any previous looper.
675 * As a convenience, the parameter passed is also returned. 652 * As a convenience, the parameter passed is also returned.
676 * If a previous looper exists in the paint, its reference count is 653 * If a previous looper exists in the paint, its reference count is
677 * decremented. If looper is not NULL, its reference count is 654 * decremented. If looper is not NULL, its reference count is
678 * incremented. 655 * incremented.
679 * @param looper May be NULL. The new looper to be installed in the paint. 656 * @param looper May be NULL. The new looper to be installed in the paint.
680 * @return looper 657 * @return looper
681 */ 658 */
682 SkDrawLooper* setLooper(SkDrawLooper* looper); 659 SkDrawLooper* setLooper(SkDrawLooper* looper);
683 660
684 enum Align { 661 enum Align {
685 kLeft_Align, 662 kLeft_Align,
686 kCenter_Align, 663 kCenter_Align,
687 kRight_Align, 664 kRight_Align,
688 }; 665 };
689 enum { 666 enum {
690 kAlignCount = 3 667 kAlignCount = 3
691 }; 668 };
692 669
693 /** Return the paint's Align value for drawing text. 670 /** Return the paint's Align value for drawing text.
694 @return the paint's Align value for drawing text. 671 @return the paint's Align value for drawing text.
695 */ 672 */
696 Align getTextAlign() const { return (Align)fTextAlign; } 673 Align getTextAlign() const { return (Align)fParts.getTextAlign(); }
scroggo 2014/04/15 17:21:07 If we remove the duplication, this cast is unneces
697 674
698 /** Set the paint's text alignment. 675 /** Set the paint's text alignment.
699 @param align set the paint's Align value for drawing text. 676 @param align set the paint's Align value for drawing text.
700 */ 677 */
701 void setTextAlign(Align align); 678 void setTextAlign(Align align);
702 679
703 /** Return the paint's text size. 680 /** Return the paint's text size.
704 @return the paint's text size. 681 @return the paint's text size.
705 */ 682 */
706 SkScalar getTextSize() const { return fTextSize; } 683 SkScalar getTextSize() const { return fParts.getTextSize(); }
707 684
708 /** Set the paint's text size. This value must be > 0 685 /** Set the paint's text size. This value must be > 0
709 @param textSize set the paint's text size. 686 @param textSize set the paint's text size.
710 */ 687 */
711 void setTextSize(SkScalar textSize); 688 void setTextSize(SkScalar textSize);
712 689
713 /** Return the paint's horizontal scale factor for text. The default value 690 /** Return the paint's horizontal scale factor for text. The default value
714 is 1.0. 691 is 1.0.
715 @return the paint's scale factor in X for drawing/measuring text 692 @return the paint's scale factor in X for drawing/measuring text
716 */ 693 */
717 SkScalar getTextScaleX() const { return fTextScaleX; } 694 SkScalar getTextScaleX() const { return fParts.getTextScaleX(); }
718 695
719 /** Set the paint's horizontal scale factor for text. The default value 696 /** Set the paint's horizontal scale factor for text. The default value
720 is 1.0. Values > 1.0 will stretch the text wider. Values < 1.0 will 697 is 1.0. Values > 1.0 will stretch the text wider. Values < 1.0 will
721 stretch the text narrower. 698 stretch the text narrower.
722 @param scaleX set the paint's scale factor in X for drawing/measuring 699 @param scaleX set the paint's scale factor in X for drawing/measuring
723 text. 700 text.
724 */ 701 */
725 void setTextScaleX(SkScalar scaleX); 702 void setTextScaleX(SkScalar scaleX);
726 703
727 /** Return the paint's horizontal skew factor for text. The default value 704 /** Return the paint's horizontal skew factor for text. The default value
728 is 0. 705 is 0.
729 @return the paint's skew factor in X for drawing text. 706 @return the paint's skew factor in X for drawing text.
730 */ 707 */
731 SkScalar getTextSkewX() const { return fTextSkewX; } 708 SkScalar getTextSkewX() const { return fParts.getTextSkewX(); }
732 709
733 /** Set the paint's horizontal skew factor for text. The default value 710 /** Set the paint's horizontal skew factor for text. The default value
734 is 0. For approximating oblique text, use values around -0.25. 711 is 0. For approximating oblique text, use values around -0.25.
735 @param skewX set the paint's skew factor in X for drawing text. 712 @param skewX set the paint's skew factor in X for drawing text.
736 */ 713 */
737 void setTextSkewX(SkScalar skewX); 714 void setTextSkewX(SkScalar skewX);
738 715
739 /** Describes how to interpret the text parameters that are passed to paint 716 /** Describes how to interpret the text parameters that are passed to paint
740 methods like measureText() and getTextWidths(). 717 methods like measureText() and getTextWidths().
741 */ 718 */
742 enum TextEncoding { 719 enum TextEncoding {
743 kUTF8_TextEncoding, //!< the text parameters are UTF8 720 kUTF8_TextEncoding, //!< the text parameters are UTF8
744 kUTF16_TextEncoding, //!< the text parameters are UTF16 721 kUTF16_TextEncoding, //!< the text parameters are UTF16
745 kUTF32_TextEncoding, //!< the text parameters are UTF32 722 kUTF32_TextEncoding, //!< the text parameters are UTF32
746 kGlyphID_TextEncoding //!< the text parameters are glyph indices 723 kGlyphID_TextEncoding //!< the text parameters are glyph indices
747 }; 724 };
748 725
749 TextEncoding getTextEncoding() const { return (TextEncoding)fTextEncoding; } 726 TextEncoding getTextEncoding() const { return (TextEncoding)fParts.getTextEn coding(); }
scroggo 2014/04/15 17:21:07 Same casting issue.
750 727
751 void setTextEncoding(TextEncoding encoding); 728 void setTextEncoding(TextEncoding encoding);
752 729
753 struct FontMetrics { 730 struct FontMetrics {
754 /** Flags which indicate the confidence level of various metrics. 731 /** Flags which indicate the confidence level of various metrics.
755 A set flag indicates that the metric may be trusted. 732 A set flag indicates that the metric may be trusted.
756 */ 733 */
757 enum FontMetricsFlags { 734 enum FontMetricsFlags {
758 kUnderlineThinknessIsValid_Flag = 1 << 0, 735 kUnderlineThinknessIsValid_Flag = 1 << 0,
759 kUnderlinePositionIsValid_Flag = 1 << 1, 736 kUnderlinePositionIsValid_Flag = 1 << 1,
(...skipping 267 matching lines...) Expand 10 before | Expand all | Expand 10 after
1027 static SkMatrix* SetTextMatrix(SkMatrix* matrix, SkScalar size, 1004 static SkMatrix* SetTextMatrix(SkMatrix* matrix, SkScalar size,
1028 SkScalar scaleX, SkScalar skewX) { 1005 SkScalar scaleX, SkScalar skewX) {
1029 matrix->setScale(size * scaleX, size); 1006 matrix->setScale(size * scaleX, size);
1030 if (skewX) { 1007 if (skewX) {
1031 matrix->postSkew(skewX, 0); 1008 matrix->postSkew(skewX, 0);
1032 } 1009 }
1033 return matrix; 1010 return matrix;
1034 } 1011 }
1035 1012
1036 SkMatrix* setTextMatrix(SkMatrix* matrix) const { 1013 SkMatrix* setTextMatrix(SkMatrix* matrix) const {
1037 return SetTextMatrix(matrix, fTextSize, fTextScaleX, fTextSkewX); 1014 return SetTextMatrix(matrix, fParts.fTextSize, fParts.fTextScaleX, fPart s.fTextSkewX);
1038 } 1015 }
1039 1016
1040 SK_TO_STRING_NONVIRT() 1017 SK_TO_STRING_NONVIRT()
1041 1018
1042 struct FlatteningTraits { 1019 struct FlatteningTraits {
1043 static void Flatten(SkWriteBuffer& buffer, const SkPaint& paint); 1020 static void Flatten(SkWriteBuffer& buffer, const SkPaint& paint);
1044 static void Unflatten(SkReadBuffer& buffer, SkPaint* paint); 1021 static void Unflatten(SkReadBuffer& buffer, SkPaint* paint);
1045 }; 1022 };
1046 1023
1047 private: 1024 private:
1048 SkTypeface* fTypeface; 1025 SkPaintParts fParts;
1049 SkPathEffect* fPathEffect; 1026 uint32_t fDirtyBits;
1050 SkShader* fShader; 1027
1051 SkXfermode* fXfermode; 1028 #ifdef SK_BUILD_FOR_ANDROID
1052 SkMaskFilter* fMaskFilter; 1029 SkPaintOptionsAndroid fPaintOptionsAndroid;
1053 SkColorFilter* fColorFilter; 1030 // In order for the == operator to work properly this must be the last field
1054 SkRasterizer* fRasterizer; 1031 // in the struct so that we can do a memcmp to this field's offset.
1055 SkDrawLooper* fLooper; 1032 uint32_t fGenerationID;
1056 SkImageFilter* fImageFilter; 1033 #endif
1057 SkAnnotation* fAnnotation;
1058 1034
1059 SkScalar fTextSize; 1035 uint32_t getBitfields() const { return fParts.fBitfields; }
1060 SkScalar fTextScaleX;
1061 SkScalar fTextSkewX;
1062 SkColor fColor;
1063 SkScalar fWidth;
1064 SkScalar fMiterLimit;
1065 union {
1066 struct {
1067 // all of these bitfields should add up to 32
1068 unsigned fFlags : 16;
1069 unsigned fTextAlign : 2;
1070 unsigned fCapType : 2;
1071 unsigned fJoinType : 2;
1072 unsigned fStyle : 2;
1073 unsigned fTextEncoding : 2; // 3 values
1074 unsigned fHinting : 2;
1075 //unsigned fFreeBits : 4;
1076 };
1077 uint32_t fBitfields;
1078 };
1079 uint32_t fDirtyBits;
1080
1081 uint32_t getBitfields() const { return fBitfields; }
1082 void setBitfields(uint32_t bitfields); 1036 void setBitfields(uint32_t bitfields);
1083 1037
1084 SkDrawCacheProc getDrawCacheProc() const; 1038 SkDrawCacheProc getDrawCacheProc() const;
1085 SkMeasureCacheProc getMeasureCacheProc(TextBufferDirection dir, 1039 SkMeasureCacheProc getMeasureCacheProc(TextBufferDirection dir,
1086 bool needFullMetrics) const; 1040 bool needFullMetrics) const;
1087 1041
1088 SkScalar measure_text(SkGlyphCache*, const char* text, size_t length, 1042 SkScalar measure_text(SkGlyphCache*, const char* text, size_t length,
1089 int* count, SkRect* bounds) const; 1043 int* count, SkRect* bounds) const;
1090 1044
1091 SkGlyphCache* detachCache(const SkDeviceProperties* deviceProperties, const SkMatrix*) const; 1045 SkGlyphCache* detachCache(const SkDeviceProperties* deviceProperties, const SkMatrix*) const;
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after
1139 1093
1140 friend class SkAutoGlyphCache; 1094 friend class SkAutoGlyphCache;
1141 friend class SkCanvas; 1095 friend class SkCanvas;
1142 friend class SkDraw; 1096 friend class SkDraw;
1143 friend class SkGraphics; // So Term() can be called. 1097 friend class SkGraphics; // So Term() can be called.
1144 friend class SkPDFDevice; 1098 friend class SkPDFDevice;
1145 friend class GrBitmapTextContext; 1099 friend class GrBitmapTextContext;
1146 friend class GrDistanceFieldTextContext; 1100 friend class GrDistanceFieldTextContext;
1147 friend class SkTextToPathIter; 1101 friend class SkTextToPathIter;
1148 friend class SkCanonicalizePaint; 1102 friend class SkCanonicalizePaint;
1149
1150 #ifdef SK_BUILD_FOR_ANDROID
1151 SkPaintOptionsAndroid fPaintOptionsAndroid;
1152
1153 // In order for the == operator to work properly this must be the last field
1154 // in the struct so that we can do a memcmp to this field's offset.
1155 uint32_t fGenerationID;
1156 #endif
1157 }; 1103 };
1158 1104
1159 #endif 1105 #endif
OLDNEW
« no previous file with comments | « no previous file | include/core/SkPaintParts.h » ('j') | include/core/SkPaintParts.h » ('J')

Powered by Google App Engine
This is Rietveld 408576698