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

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

Powered by Google App Engine
This is Rietveld 408576698