OLD | NEW |
1 /* | 1 /* |
2 * Copyright 2012 Google Inc. | 2 * Copyright 2012 Google Inc. |
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 GrProcessor_DEFINED | 8 #ifndef GrProcessor_DEFINED |
9 #define GrProcessor_DEFINED | 9 #define GrProcessor_DEFINED |
10 | 10 |
(...skipping 20 matching lines...) Expand all Loading... |
31 effect must reach 0 before the thread terminates and the pool is destroyed.
To create a static | 31 effect must reach 0 before the thread terminates and the pool is destroyed.
To create a static |
32 effect use the macro GR_CREATE_STATIC_EFFECT declared below. | 32 effect use the macro GR_CREATE_STATIC_EFFECT declared below. |
33 */ | 33 */ |
34 class GrProcessor : public GrProgramElement { | 34 class GrProcessor : public GrProgramElement { |
35 public: | 35 public: |
36 SK_DECLARE_INST_COUNT(GrProcessor) | 36 SK_DECLARE_INST_COUNT(GrProcessor) |
37 | 37 |
38 virtual ~GrProcessor(); | 38 virtual ~GrProcessor(); |
39 | 39 |
40 struct InvariantOutput{ | 40 struct InvariantOutput{ |
41 GrColor fColor; | 41 InvariantOutput() : fColor(0), fValidFlags(0), fIsSingleComponent(false)
{} |
42 uint32_t fValidFlags; | |
43 bool fIsSingleComponent; | |
44 | 42 |
45 InvariantOutput() : fColor(0), fValidFlags(0), fIsSingleComponent(false)
{} | 43 void mulByUnknownOpaqueColor() { |
| 44 if (this->isOpaque()) { |
| 45 fValidFlags = kA_GrColorComponentFlag; |
| 46 fIsSingleComponent = false; |
| 47 } else { |
| 48 // Since the current state is not opaque we no longer care if th
e color being |
| 49 // multiplied is opaque. |
| 50 this->mulByUnknownColor(); |
| 51 } |
| 52 } |
| 53 |
| 54 void mulByUnknownColor() { |
| 55 if (this->hasZeroAlpha()) { |
| 56 this->setToTransparentBlack(); |
| 57 } else { |
| 58 this->setToUnknown(); |
| 59 } |
| 60 } |
| 61 |
| 62 void mulByUnknownAlpha() { |
| 63 if (this->hasZeroAlpha()) { |
| 64 this->setToTransparentBlack(); |
| 65 } else { |
| 66 // We don't need to change fIsSingleComponent in this case |
| 67 fValidFlags = 0; |
| 68 } |
| 69 } |
| 70 |
| 71 void invalidateComponents(uint8_t invalidateFlags) { |
| 72 fValidFlags &= ~invalidateFlags; |
| 73 fIsSingleComponent = false; |
| 74 } |
| 75 |
| 76 void setToTransparentBlack() { |
| 77 fValidFlags = kRGBA_GrColorComponentFlags; |
| 78 fColor = 0; |
| 79 fIsSingleComponent = true; |
| 80 } |
| 81 |
| 82 void setToOther(uint8_t validFlags, GrColor color) { |
| 83 fValidFlags = validFlags; |
| 84 fColor = color; |
| 85 fIsSingleComponent = false; |
| 86 } |
| 87 |
| 88 void setToUnknown() { |
| 89 fValidFlags = 0; |
| 90 fIsSingleComponent = false; |
| 91 } |
46 | 92 |
47 bool isOpaque() const { | 93 bool isOpaque() const { |
48 return ((fValidFlags & kA_GrColorComponentFlag) && 0xFF == GrColorUn
packA(fColor)); | 94 return ((fValidFlags & kA_GrColorComponentFlag) && 0xFF == GrColorUn
packA(fColor)); |
49 } | 95 } |
50 | 96 |
51 bool isSolidWhite() const { | 97 bool isSolidWhite() const { |
52 return (fValidFlags == kRGBA_GrColorComponentFlags && 0xFFFFFFFF ==
fColor); | 98 return (fValidFlags == kRGBA_GrColorComponentFlags && 0xFFFFFFFF ==
fColor); |
53 } | 99 } |
54 | 100 |
| 101 GrColor color() const { return fColor; } |
| 102 uint8_t validFlags() const { return fValidFlags; } |
| 103 |
55 /** | 104 /** |
56 * If isSingleComponent is true, then the flag values for r, g, b, and a
must all be the | 105 * If isSingleComponent is true, then the flag values for r, g, b, and a
must all be the |
57 * same. If the flags are all set then all color components must be equa
l. | 106 * same. If the flags are all set then all color components must be equa
l. |
58 */ | 107 */ |
59 SkDEBUGCODE(void validate() const;) | 108 SkDEBUGCODE(void validate() const;) |
60 | 109 |
61 private: | 110 private: |
| 111 bool hasZeroAlpha() const { |
| 112 return ((fValidFlags & kA_GrColorComponentFlag) && 0 == GrColorUnpac
kA(fColor)); |
| 113 } |
| 114 |
62 SkDEBUGCODE(bool colorComponentsAllEqual() const;) | 115 SkDEBUGCODE(bool colorComponentsAllEqual() const;) |
63 | |
64 /** | 116 /** |
65 * If alpha is valid, check that any valid R,G,B values are <= A | 117 * If alpha is valid, check that any valid R,G,B values are <= A |
66 */ | 118 */ |
67 SkDEBUGCODE(bool validPreMulColor() const;) | 119 SkDEBUGCODE(bool validPreMulColor() const;) |
| 120 |
| 121 // Friended class that have "controller" code which loop over stages cal
ling |
| 122 // computeInvarianteOutput(). These controllers may need to manually adj
ust the internal |
| 123 // members of InvariantOutput |
| 124 friend class GrDrawState; |
| 125 friend class GrOptDrawState; |
| 126 friend class GrPaint; |
| 127 |
| 128 GrColor fColor; |
| 129 uint32_t fValidFlags; |
| 130 bool fIsSingleComponent; |
68 }; | 131 }; |
69 | 132 |
70 /** | 133 /** |
71 * This function is used to perform optimizations. When called the invarient
Ouput param | 134 * This function is used to perform optimizations. When called the invarient
Ouput param |
72 * indicate whether the input components to this effect in the FS will have
known values. | 135 * indicate whether the input components to this effect in the FS will have
known values. |
73 * In inout the validFlags member is a bitfield of GrColorComponentFlags. Th
e isSingleComponent | 136 * In inout the validFlags member is a bitfield of GrColorComponentFlags. Th
e isSingleComponent |
74 * member indicates whether the input will be 1 or 4 bytes. The function upd
ates the members of | 137 * member indicates whether the input will be 1 or 4 bytes. The function upd
ates the members of |
75 * inout to indicate known values of its output. A component of the color me
mber only has | 138 * inout to indicate known values of its output. A component of the color me
mber only has |
76 * meaning if the corresponding bit in validFlags is set. | 139 * meaning if the corresponding bit in validFlags is set. |
77 */ | 140 */ |
(...skipping 170 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
248 * This creates an effect outside of the effect memory pool. The effect's destru
ctor will be called | 311 * This creates an effect outside of the effect memory pool. The effect's destru
ctor will be called |
249 * at global destruction time. NAME will be the name of the created GrProcessor. | 312 * at global destruction time. NAME will be the name of the created GrProcessor. |
250 */ | 313 */ |
251 #define GR_CREATE_STATIC_FRAGMENT_PROCESSOR(NAME, EFFECT_CLASS, ARGS)
\ | 314 #define GR_CREATE_STATIC_FRAGMENT_PROCESSOR(NAME, EFFECT_CLASS, ARGS)
\ |
252 static SkAlignedSStorage<sizeof(EFFECT_CLASS)> g_##NAME##_Storage;
\ | 315 static SkAlignedSStorage<sizeof(EFFECT_CLASS)> g_##NAME##_Storage;
\ |
253 static GrFragmentProcessor*
\ | 316 static GrFragmentProcessor*
\ |
254 NAME SkNEW_PLACEMENT_ARGS(g_##NAME##_Storage.get(), EFFECT_CLASS, ARGS);
\ | 317 NAME SkNEW_PLACEMENT_ARGS(g_##NAME##_Storage.get(), EFFECT_CLASS, ARGS);
\ |
255 static SkAutoTDestroy<GrFragmentProcessor> NAME##_ad(NAME); | 318 static SkAutoTDestroy<GrFragmentProcessor> NAME##_ad(NAME); |
256 | 319 |
257 #endif | 320 #endif |
OLD | NEW |