Index: Source/platform/graphics/GraphicsContextState.h |
diff --git a/Source/platform/graphics/GraphicsContextState.h b/Source/platform/graphics/GraphicsContextState.h |
index 4417d4f218ef4b4521815ff27ee5e9a5c29e1902..b8bcd778f3c5298911a40a417512a1e27798825f 100644 |
--- a/Source/platform/graphics/GraphicsContextState.h |
+++ b/Source/platform/graphics/GraphicsContextState.h |
@@ -74,11 +74,11 @@ public: |
void setStrokeColor(const Color&); |
Gradient* strokeGradient() const { return m_strokeGradient.get(); } |
- void setStrokeGradient(const PassRefPtr<Gradient>); |
+ void setStrokeGradient(const PassRefPtr<Gradient>, float); |
void clearStrokeGradient(); |
Pattern* strokePattern() const { return m_strokePattern.get(); } |
- void setStrokePattern(const PassRefPtr<Pattern>); |
+ void setStrokePattern(const PassRefPtr<Pattern>, float); |
void clearStrokePattern(); |
const StrokeData& strokeData() const { return m_strokeData; } |
@@ -95,11 +95,11 @@ public: |
void setFillColor(const Color&); |
Gradient* fillGradient() const { return m_fillGradient.get(); } |
- void setFillGradient(const PassRefPtr<Gradient>); |
+ void setFillGradient(const PassRefPtr<Gradient>, float); |
void clearFillGradient(); |
Pattern* fillPattern() const { return m_fillPattern.get(); } |
- void setFillPattern(const PassRefPtr<Pattern>); |
+ void setFillPattern(const PassRefPtr<Pattern>, float); |
void clearFillPattern(); |
// Path fill rule |
@@ -145,17 +145,42 @@ public: |
bool hasComplexClip() const; |
void setHasComplexClip(); |
+ // Multiply a color's alpha channel by an additional alpha factor where |
+ // alpha is in the range [0, 1]. |
+ static SkColor combineWithAlpha(SkColor color, float alpha) |
f(malita)
2015/02/03 00:33:28
Is there any reason to keep these helpers in GC/GC
pdr.
2015/02/04 04:04:31
Moved to the other dumping ground, SkiaUtils :)
|
+ { |
+ return combineWithAlpha(color, clampedAlphaForBlending(alpha)); |
f(malita)
2015/02/03 00:33:28
Naming nit: "combineWithAlpha" sounds pretty weird
pdr.
2015/02/04 04:04:31
After much fighting, I renamed this to multiplyAlp
|
+ } |
+ |
private: |
GraphicsContextState(); |
explicit GraphicsContextState(const GraphicsContextState&); |
GraphicsContextState& operator=(const GraphicsContextState&); |
+ // Multiply a color's alpha channel by an additional alpha factor where |
+ // alpha is in the range [0, 256]. |
+ static SkColor combineWithAlpha(SkColor color, int alpha) |
+ { |
+ int a = (SkColorGetA(color) * alpha) >> 8; |
+ return (color & 0x00FFFFFF) | (a << 24); |
+ } |
+ |
// Helper function for applying the state's alpha value to the given input |
// color to produce a new output color. |
- SkColor applyAlpha(SkColor c) const |
+ SkColor applyAlpha(SkColor color) const |
+ { |
+ return combineWithAlpha(color, m_alpha); |
+ } |
+ |
+ // Map alpha values from [0, 1] to [0, 256] for alpha blending. |
+ static int clampedAlphaForBlending(float alpha) |
{ |
- int a = SkAlphaMul(SkColorGetA(c), m_alpha); |
- return (c & 0x00FFFFFF) | (a << 24); |
+ if (alpha < 0) |
+ return 0; |
+ int roundedAlpha = roundf(alpha * 256); |
+ if (roundedAlpha > 256) |
+ roundedAlpha = 256; |
+ return roundedAlpha; |
} |
// These are mutbale to enable gradient updates when the paints are fetched for use. |