Index: Source/platform/graphics/GraphicsContextState.h |
diff --git a/Source/platform/graphics/GraphicsContextState.h b/Source/platform/graphics/GraphicsContextState.h |
index e6545e9c7cd6eabe97bf30734eac48905941634d..63f91ec5f68c3db9848b19aa65feb88fb6985614 100644 |
--- a/Source/platform/graphics/GraphicsContextState.h |
+++ b/Source/platform/graphics/GraphicsContextState.h |
@@ -29,15 +29,15 @@ |
#ifndef GraphicsContextState_h |
#define GraphicsContextState_h |
+#include "platform/graphics/DrawLooperBuilder.h" |
#include "platform/graphics/Gradient.h" |
#include "platform/graphics/GraphicsTypes.h" |
#include "platform/graphics/Path.h" |
#include "platform/graphics/Pattern.h" |
#include "platform/graphics/StrokeData.h" |
+#include "platform/graphics/skia/SkiaUtils.h" |
#include "third_party/skia/include/core/SkColorFilter.h" |
-#include "third_party/skia/include/core/SkColorPriv.h" |
-#include "third_party/skia/include/core/SkDrawLooper.h" |
-#include "third_party/skia/include/effects/SkDashPathEffect.h" |
+#include "third_party/skia/include/core/SkPaint.h" |
#include "wtf/PassOwnPtr.h" |
#include "wtf/RefPtr.h" |
@@ -45,96 +45,139 @@ namespace WebCore { |
// Encapsulates the state information we store for each pushed graphics state. |
// Only GraphicsContext can use this class. |
-class GraphicsContextState { |
+class GraphicsContextState final { |
Stephen White
2014/03/04 15:24:13
Unless I missed something, we can't use C++11 in B
|
WTF_MAKE_NONCOPYABLE(GraphicsContextState); |
-private: |
- friend class GraphicsContext; |
- |
+public: |
static PassOwnPtr<GraphicsContextState> create() { return adoptPtr(new GraphicsContextState()); } |
- GraphicsContextState() |
- : m_fillColor(Color::black) |
- , m_fillRule(RULE_NONZERO) |
- , m_textDrawingMode(TextModeFill) |
- , m_alpha(1) |
- , m_xferMode(nullptr) |
- , m_compositeOperator(CompositeSourceOver) |
- , m_blendMode(blink::WebBlendModeNormal) |
-#if USE(LOW_QUALITY_IMAGE_INTERPOLATION) |
- , m_interpolationQuality(InterpolationLow) |
-#else |
- , m_interpolationQuality(InterpolationHigh) |
-#endif |
- , m_saveCount(0) |
- , m_shouldAntialias(true) |
- , m_shouldSmoothFonts(true) |
- , m_shouldClampToSourceRect(true) |
- { |
- } |
+ GraphicsContextState(); |
+ |
+ void copy(GraphicsContextState*); |
+ |
+ // SkPaint objects that reflect the current state, except: |
+ // - Dashed and Dotted strokes. |
+ const SkPaint& strokePaint() const; |
+ const SkPaint& fillPaint() const; |
+ |
+ uint16_t saveCount() const { return m_saveCount; } |
+ void incrementSaveCount() { ++m_saveCount; } |
+ void decrementSaveCount() { --m_saveCount; } |
+ |
+ // Stroke data |
+ const StrokeData& strokeData() const { return m_strokeData; } |
+ |
+ // Does not set up the necessary path effect for dotted or dashed lines. |
Stephen White
2014/03/04 15:24:13
Why the exception? Performance?
Stephen Chennney
2014/03/04 17:41:29
We need the length of the path to correctly set up
|
+ // StrokeData::setupPaintDashPathEffect must be called if the dash effect is |
+ // required. |
+ void setStrokeStyle(const StrokeStyle style) { m_strokeData.setStyle(style); } |
+ |
+ void setStrokeThickness(const float); |
+ |
+ SkColor effectiveStrokeColor() const { return applyAlpha(m_strokeData.color().rgb()); } |
+ void setStrokeColor(const Color&); |
- void copy(GraphicsContextState* source) |
+ void setStrokeGradient(const PassRefPtr<Gradient>); |
+ void clearStrokeGradient(); |
+ |
+ void setStrokePattern(const PassRefPtr<Pattern>); |
+ void clearStrokePattern(); |
+ |
+ void setLineCap(const LineCap); |
+ |
+ void setLineJoin(const LineJoin); |
+ |
+ void setMiterLimit(const float); |
+ |
+ void setLineDash(const DashArray& dashes, float dashOffset) |
{ |
- m_strokeData = source->m_strokeData; |
- m_fillColor = source->m_fillColor; |
- m_fillRule = source->m_fillRule; |
- m_fillGradient = source->m_fillGradient; |
- m_fillPattern = source->m_fillPattern; |
- m_looper = source->m_looper; |
- m_textDrawingMode = source->m_textDrawingMode; |
- m_alpha = source->m_alpha; |
- m_xferMode = source->m_xferMode; |
- m_colorFilter = source->m_colorFilter; |
- m_compositeOperator = source->m_compositeOperator; |
- m_blendMode = source->m_blendMode; |
- m_interpolationQuality = source->m_interpolationQuality; |
- m_saveCount = 0; |
- m_shouldAntialias = source->m_shouldAntialias; |
- m_shouldSmoothFonts = source->m_shouldSmoothFonts; |
- m_shouldClampToSourceRect = source->m_shouldClampToSourceRect; |
+ m_strokeData.setLineDash(dashes, dashOffset); |
} |
+ // Fill data |
+ Color fillColor() const { return m_fillColor; } |
+ SkColor effectiveFillColor() const { return applyAlpha(m_fillColor.rgb()); } |
+ void setFillColor(const Color&); |
+ |
+ Gradient* fillGradient() const { return m_fillGradient.get(); } |
+ void setFillGradient(const PassRefPtr<Gradient>); |
+ void clearFillGradient(); |
+ |
+ Pattern* fillPattern() const { return m_fillPattern.get(); } |
+ void setFillPattern(const PassRefPtr<Pattern>); |
+ void clearFillPattern(); |
+ |
+ // Path fill rule |
+ WindRule fillRule() const { return m_fillRule; } |
+ void setFillRule(const WindRule rule) { m_fillRule = rule; } |
+ |
+ // Shadow. (This will need tweaking if we use draw loopers for other things.) |
+ SkDrawLooper* drawLooper() const { return m_looper.get(); } |
+ void setDrawLooper(PassRefPtr<SkDrawLooper>); |
+ void clearDrawLooper(); |
+ |
+ // Text. (See TextModeFill & friends.) |
+ TextDrawingModeFlags textDrawingMode() const { return m_textDrawingMode; } |
+ void setTextDrawingMode(const TextDrawingModeFlags mode) { m_textDrawingMode = mode; } |
+ |
+ // Common shader state. |
+ int alpha() const { return m_alpha; } |
+ void setAlpha(const float); |
Stephen White
2014/03/04 15:24:13
This is confusing (int 0->256 vs float 0->1, I ass
Stephen Chennney
2014/03/04 17:41:29
Fair call. The 256 is a Skia thing, due to the way
|
+ |
+ SkColorFilter* colorFilter() const { return m_colorFilter.get(); } |
+ void setColorFilter(PassRefPtr<SkColorFilter>); |
+ |
+ // Compositing control, for the CSS and Canvas compositing spec. |
+ void setCompositeOperation(const CompositeOperator, const blink::WebBlendMode); |
+ CompositeOperator compositeOperator() const { return m_compositeOperator; } |
+ blink::WebBlendMode blendMode() const { return m_blendMode; } |
+ SkXfermode* xferMode() const { return m_xferMode.get(); } |
+ |
+ // Image interpolation control. |
+ InterpolationQuality interpolationQuality() const { return m_interpolationQuality; } |
+ void setInterpolationQuality(const InterpolationQuality); |
+ |
+ bool shouldAntialias() const { return m_shouldAntialias; } |
+ void setShouldAntialias(const bool); |
+ |
+ bool shouldSmoothFonts() const { return m_shouldSmoothFonts; } |
+ void setShouldSmoothFonts(const bool shouldSmoothFonts) { m_shouldSmoothFonts = shouldSmoothFonts; } |
+ |
+ bool shouldClampToSourceRect() const { return m_shouldClampToSourceRect; } |
+ void setShouldClampToSourceRect(const bool shouldClampToSourceRect) { m_shouldClampToSourceRect = shouldClampToSourceRect; } |
+ |
+private: |
// 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 |
{ |
- int s = roundf(m_alpha * 256); |
- if (s >= 256) |
- return c; |
- if (s < 0) |
- return 0; |
- |
- int a = SkAlphaMul(SkColorGetA(c), s); |
+ int a = SkAlphaMul(SkColorGetA(c), m_alpha); |
return (c & 0x00FFFFFF) | (a << 24); |
} |
- // Stroke. |
+ // These are mutbale to enable gradient updates when the paints are fetched for use. |
Stephen White
2014/03/04 15:24:13
Hmm.. if they're mutable, than won't that prevent
Stephen Chennney
2014/03/04 17:41:29
Yes. The fact that canvas gradients are mutable af
|
+ mutable SkPaint m_strokePaint; |
+ mutable SkPaint m_fillPaint; |
+ |
StrokeData m_strokeData; |
- // Fill. |
Color m_fillColor; |
WindRule m_fillRule; |
RefPtr<Gradient> m_fillGradient; |
RefPtr<Pattern> m_fillPattern; |
- // Shadow. (This will need tweaking if we use draw loopers for other things.) |
RefPtr<SkDrawLooper> m_looper; |
- // Text. (See TextModeFill & friends.) |
TextDrawingModeFlags m_textDrawingMode; |
- // Common shader state. |
- float m_alpha; |
+ int m_alpha; |
RefPtr<SkXfermode> m_xferMode; |
RefPtr<SkColorFilter> m_colorFilter; |
- // Compositing control, for the CSS and Canvas compositing spec. |
CompositeOperator m_compositeOperator; |
blink::WebBlendMode m_blendMode; |
- // Image interpolation control. |
InterpolationQuality m_interpolationQuality; |
- // The number of GraphicsContext::save calls since this state was pushed. |
uint16_t m_saveCount; |
bool m_shouldAntialias : 1; |
@@ -145,4 +188,3 @@ private: |
} // namespace WebCore |
#endif // GraphicsContextState_h |
- |