#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/SkPaint.h"
#include "wtf/PassOwnPtr.h"
#include "wtf/RefPtr.h"
namespace WebCore {
class PLATFORM_EXPORT GraphicsContextState FINAL {
WTF_MAKE_NONCOPYABLE(GraphicsContextState);
public:
static PassOwnPtr<GraphicsContextState> create() { return adoptPtr(new GraphicsContextState()); }
GraphicsContextState();
void copy(GraphicsContextState*);
const SkPaint& strokePaint(int strokedPathLength = 0) const;
const SkPaint& fillPaint() const;
uint16_t saveCount() const { return m_saveCount; }
void incrementSaveCount() { ++m_saveCount; }
void decrementSaveCount() { --m_saveCount; }
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);
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();
WindRule fillRule() const { return m_fillRule; }
void setFillRule(WindRule rule) { m_fillRule = rule; }
SkDrawLooper* drawLooper() const { return m_looper.get(); }
void setDrawLooper(PassRefPtr<SkDrawLooper>);
void clearDrawLooper();
TextDrawingModeFlags textDrawingMode() const { return m_textDrawingMode; }
void setTextDrawingMode(TextDrawingModeFlags mode) { m_textDrawingMode = mode; }
int alpha() const { return m_alpha; }
void setAlphaAsFloat(float);
SkColorFilter* colorFilter() const { return m_colorFilter.get(); }
void setColorFilter(PassRefPtr<SkColorFilter>);
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(); }
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:
SkColor applyAlpha(SkColor c) const
{
int a = SkAlphaMul(SkColorGetA(c), m_alpha);
return (c & 0x00FFFFFF) | (a << 24);
}
mutable SkPaint m_strokePaint;
mutable SkPaint m_fillPaint;
StrokeData m_strokeData;
Color m_fillColor;
WindRule m_fillRule;
RefPtr<Gradient> m_fillGradient;
RefPtr<Pattern> m_fillPattern;
RefPtr<SkDrawLooper> m_looper;
TextDrawingModeFlags m_textDrawingMode;
int m_alpha;
RefPtr<SkXfermode> m_xferMode;
RefPtr<SkColorFilter> m_colorFilter;
CompositeOperator m_compositeOperator;
blink::WebBlendMode m_blendMode;
InterpolationQuality m_interpolationQuality;
uint16_t m_saveCount;
bool m_shouldAntialias : 1;
bool m_shouldSmoothFonts : 1;
bool m_shouldClampToSourceRect : 1;
};
}
#endif