| Index: Source/platform/graphics/GraphicsContextState.h
|
| diff --git a/Source/platform/graphics/GraphicsContextState.h b/Source/platform/graphics/GraphicsContextState.h
|
| index e6545e9c7cd6eabe97bf30734eac48905941634d..7e15f49f940e2395277f7f2949f50a6ed4f6b820 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/DrawLooper.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,133 @@ namespace WebCore {
|
|
|
| // Encapsulates the state information we store for each pushed graphics state.
|
| // Only GraphicsContext can use this class.
|
| -class GraphicsContextState {
|
| +class PLATFORM_EXPORT GraphicsContextState FINAL {
|
| 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* source)
|
| - {
|
| - 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;
|
| - }
|
| + 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; }
|
| +
|
| + void setStrokeStyle(StrokeStyle);
|
| +
|
| + void setStrokeThickness(float);
|
| +
|
| + SkColor effectiveStrokeColor() const { return applyAlpha(m_strokeData.color().rgb()); }
|
| + void setStrokeColor(const Color&);
|
|
|
| + void setStrokeGradient(const PassRefPtr<Gradient>);
|
| + void clearStrokeGradient();
|
| +
|
| + void setStrokePattern(const PassRefPtr<Pattern>);
|
| + void clearStrokePattern();
|
| +
|
| + void setLineCap(LineCap);
|
| +
|
| + void setLineJoin(LineJoin);
|
| +
|
| + void setMiterLimit(float);
|
| +
|
| + void setLineDash(const DashArray&, float);
|
| +
|
| + // 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(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(const DrawLooper&);
|
| + void clearDrawLooper();
|
| +
|
| + // Text. (See TextModeFill & friends.)
|
| + TextDrawingModeFlags textDrawingMode() const { return m_textDrawingMode; }
|
| + void setTextDrawingMode(TextDrawingModeFlags mode) { m_textDrawingMode = mode; }
|
| +
|
| + // Common shader state.
|
| + int alpha() const { return m_alpha; }
|
| + void setAlphaAsFloat(float);
|
| +
|
| + SkColorFilter* colorFilter() const { return m_colorFilter.get(); }
|
| + void setColorFilter(PassRefPtr<SkColorFilter>);
|
| +
|
| + // Compositing control, for the CSS and Canvas compositing spec.
|
| + void setCompositeOperation(CompositeOperator, 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(InterpolationQuality);
|
| +
|
| + bool shouldAntialias() const { return m_shouldAntialias; }
|
| + void setShouldAntialias(bool);
|
| +
|
| + bool shouldSmoothFonts() const { return m_shouldSmoothFonts; }
|
| + void setShouldSmoothFonts(bool shouldSmoothFonts) { m_shouldSmoothFonts = shouldSmoothFonts; }
|
| +
|
| + bool shouldClampToSourceRect() const { return m_shouldClampToSourceRect; }
|
| + void setShouldClampToSourceRect(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.
|
| + 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 +182,3 @@ private:
|
| } // namespace WebCore
|
|
|
| #endif // GraphicsContextState_h
|
| -
|
|
|