OLD | NEW |
1 // Copyright (C) 2013 Google Inc. All rights reserved. | 1 // Copyright (C) 2013 Google Inc. All rights reserved. |
2 // | 2 // |
3 // Redistribution and use in source and binary forms, with or without | 3 // Redistribution and use in source and binary forms, with or without |
4 // modification, are permitted provided that the following conditions are | 4 // modification, are permitted provided that the following conditions are |
5 // met: | 5 // met: |
6 // | 6 // |
7 // * Redistributions of source code must retain the above copyright | 7 // * Redistributions of source code must retain the above copyright |
8 // notice, this list of conditions and the following disclaimer. | 8 // notice, this list of conditions and the following disclaimer. |
9 // * Redistributions in binary form must reproduce the above | 9 // * Redistributions in binary form must reproduce the above |
10 // copyright notice, this list of conditions and the following disclaimer | 10 // copyright notice, this list of conditions and the following disclaimer |
(...skipping 19 matching lines...) Expand all Loading... |
30 #define GraphicsContextState_h | 30 #define GraphicsContextState_h |
31 | 31 |
32 #include "platform/graphics/DrawLooperBuilder.h" | 32 #include "platform/graphics/DrawLooperBuilder.h" |
33 #include "platform/graphics/Gradient.h" | 33 #include "platform/graphics/Gradient.h" |
34 #include "platform/graphics/GraphicsTypes.h" | 34 #include "platform/graphics/GraphicsTypes.h" |
35 #include "platform/graphics/Path.h" | 35 #include "platform/graphics/Path.h" |
36 #include "platform/graphics/Pattern.h" | 36 #include "platform/graphics/Pattern.h" |
37 #include "platform/graphics/StrokeData.h" | 37 #include "platform/graphics/StrokeData.h" |
38 #include "platform/graphics/skia/SkiaUtils.h" | 38 #include "platform/graphics/skia/SkiaUtils.h" |
39 #include "third_party/skia/include/core/SkColorFilter.h" | 39 #include "third_party/skia/include/core/SkColorFilter.h" |
40 #include "third_party/skia/include/core/SkImageFilter.h" | |
41 #include "third_party/skia/include/core/SkPaint.h" | 40 #include "third_party/skia/include/core/SkPaint.h" |
42 #include "wtf/PassOwnPtr.h" | 41 #include "wtf/PassOwnPtr.h" |
43 #include "wtf/RefPtr.h" | 42 #include "wtf/RefPtr.h" |
44 | 43 |
45 namespace blink { | 44 namespace blink { |
46 | 45 |
47 // Encapsulates the state information we store for each pushed graphics state. | 46 // Encapsulates the state information we store for each pushed graphics state. |
48 // Only GraphicsContext can use this class. | 47 // Only GraphicsContext can use this class. |
49 class PLATFORM_EXPORT GraphicsContextState final { | 48 class PLATFORM_EXPORT GraphicsContextState final { |
50 public: | 49 public: |
(...skipping 13 matching lines...) Expand all Loading... |
64 // path to be stroked is known, pass it in for correct dash or dot placement
. | 63 // path to be stroked is known, pass it in for correct dash or dot placement
. |
65 const SkPaint& strokePaint(int strokedPathLength = 0) const; | 64 const SkPaint& strokePaint(int strokedPathLength = 0) const; |
66 const SkPaint& fillPaint() const; | 65 const SkPaint& fillPaint() const; |
67 | 66 |
68 uint16_t saveCount() const { return m_saveCount; } | 67 uint16_t saveCount() const { return m_saveCount; } |
69 void incrementSaveCount() { ++m_saveCount; } | 68 void incrementSaveCount() { ++m_saveCount; } |
70 void decrementSaveCount() { --m_saveCount; } | 69 void decrementSaveCount() { --m_saveCount; } |
71 | 70 |
72 // Stroke data | 71 // Stroke data |
73 Color strokeColor() const { return m_strokeColor; } | 72 Color strokeColor() const { return m_strokeColor; } |
74 SkColor effectiveStrokeColor() const { return applyAlpha(m_strokeColor.rgb()
); } | |
75 void setStrokeColor(const Color&); | 73 void setStrokeColor(const Color&); |
76 | 74 |
77 Gradient* strokeGradient() const { return m_strokeGradient.get(); } | 75 Gradient* strokeGradient() const { return m_strokeGradient.get(); } |
78 void setStrokeGradient(const PassRefPtr<Gradient>, float); | 76 void setStrokeGradient(const PassRefPtr<Gradient>, float); |
79 | 77 |
80 Pattern* strokePattern() const { return m_strokePattern.get(); } | 78 Pattern* strokePattern() const { return m_strokePattern.get(); } |
81 void setStrokePattern(const PassRefPtr<Pattern>, float); | 79 void setStrokePattern(const PassRefPtr<Pattern>, float); |
82 | 80 |
83 const StrokeData& strokeData() const { return m_strokeData; } | 81 const StrokeData& strokeData() const { return m_strokeData; } |
84 void setStrokeStyle(StrokeStyle); | 82 void setStrokeStyle(StrokeStyle); |
85 void setStrokeThickness(float); | 83 void setStrokeThickness(float); |
86 void setLineCap(LineCap); | 84 void setLineCap(LineCap); |
87 void setLineJoin(LineJoin); | 85 void setLineJoin(LineJoin); |
88 void setMiterLimit(float); | 86 void setMiterLimit(float); |
89 void setLineDash(const DashArray&, float); | 87 void setLineDash(const DashArray&, float); |
90 | 88 |
91 // Fill data | 89 // Fill data |
92 Color fillColor() const { return m_fillColor; } | 90 Color fillColor() const { return m_fillColor; } |
93 SkColor effectiveFillColor() const { return applyAlpha(m_fillColor.rgb()); } | |
94 void setFillColor(const Color&); | 91 void setFillColor(const Color&); |
95 | 92 |
96 Gradient* fillGradient() const { return m_fillGradient.get(); } | 93 Gradient* fillGradient() const { return m_fillGradient.get(); } |
97 void setFillGradient(const PassRefPtr<Gradient>, float); | 94 void setFillGradient(const PassRefPtr<Gradient>, float); |
98 | 95 |
99 Pattern* fillPattern() const { return m_fillPattern.get(); } | 96 Pattern* fillPattern() const { return m_fillPattern.get(); } |
100 void setFillPattern(const PassRefPtr<Pattern>, float); | 97 void setFillPattern(const PassRefPtr<Pattern>, float); |
101 | 98 |
102 // Shadow. (This will need tweaking if we use draw loopers for other things.
) | 99 // Shadow. (This will need tweaking if we use draw loopers for other things.
) |
103 SkDrawLooper* drawLooper() const { return m_looper.get(); } | 100 SkDrawLooper* drawLooper() const { return m_looper.get(); } |
104 void setDrawLooper(PassRefPtr<SkDrawLooper>); | 101 void setDrawLooper(PassRefPtr<SkDrawLooper>); |
105 void clearDrawLooper(); | 102 void clearDrawLooper(); |
106 | 103 |
107 SkImageFilter* dropShadowImageFilter() const { return m_dropShadowImageFilte
r.get(); } | |
108 void setDropShadowImageFilter(PassRefPtr<SkImageFilter>); | |
109 void clearDropShadowImageFilter(); | |
110 | |
111 // Text. (See TextModeFill & friends.) | 104 // Text. (See TextModeFill & friends.) |
112 TextDrawingModeFlags textDrawingMode() const { return m_textDrawingMode; } | 105 TextDrawingModeFlags textDrawingMode() const { return m_textDrawingMode; } |
113 void setTextDrawingMode(TextDrawingModeFlags mode) { m_textDrawingMode = mod
e; } | 106 void setTextDrawingMode(TextDrawingModeFlags mode) { m_textDrawingMode = mod
e; } |
114 | 107 |
115 // Common shader state. | |
116 int alpha() const { return m_alpha; } | |
117 void setAlphaAsFloat(float); | |
118 | |
119 SkColorFilter* colorFilter() const { return m_colorFilter.get(); } | 108 SkColorFilter* colorFilter() const { return m_colorFilter.get(); } |
120 void setColorFilter(PassRefPtr<SkColorFilter>); | 109 void setColorFilter(PassRefPtr<SkColorFilter>); |
121 | 110 |
122 // Compositing control, for the CSS and Canvas compositing spec. | |
123 void setCompositeOperation(SkXfermode::Mode); | |
124 SkXfermode::Mode compositeOperation() const { return m_compositeOperation; } | |
125 | |
126 // Image interpolation control. | 111 // Image interpolation control. |
127 InterpolationQuality interpolationQuality() const { return m_interpolationQu
ality; } | 112 InterpolationQuality interpolationQuality() const { return m_interpolationQu
ality; } |
128 void setInterpolationQuality(InterpolationQuality); | 113 void setInterpolationQuality(InterpolationQuality); |
129 | 114 |
130 bool shouldAntialias() const { return m_shouldAntialias; } | 115 bool shouldAntialias() const { return m_shouldAntialias; } |
131 void setShouldAntialias(bool); | 116 void setShouldAntialias(bool); |
132 | 117 |
133 bool shouldClampToSourceRect() const { return m_shouldClampToSourceRect; } | |
134 void setShouldClampToSourceRect(bool shouldClampToSourceRect) { m_shouldClam
pToSourceRect = shouldClampToSourceRect; } | |
135 | |
136 private: | 118 private: |
137 GraphicsContextState(); | 119 GraphicsContextState(); |
138 explicit GraphicsContextState(const GraphicsContextState&); | 120 explicit GraphicsContextState(const GraphicsContextState&); |
139 GraphicsContextState& operator=(const GraphicsContextState&); | 121 GraphicsContextState& operator=(const GraphicsContextState&); |
140 | 122 |
141 // Helper function for applying the state's alpha value to the given input | |
142 // color to produce a new output color. | |
143 SkColor applyAlpha(SkColor color) const | |
144 { | |
145 return scaleAlpha(color, m_alpha); | |
146 } | |
147 | |
148 // These are mutbale to enable gradient updates when the paints are fetched
for use. | 123 // These are mutbale to enable gradient updates when the paints are fetched
for use. |
149 mutable SkPaint m_strokePaint; | 124 mutable SkPaint m_strokePaint; |
150 mutable SkPaint m_fillPaint; | 125 mutable SkPaint m_fillPaint; |
151 | 126 |
152 StrokeData m_strokeData; | 127 StrokeData m_strokeData; |
153 | 128 |
154 Color m_strokeColor; | 129 Color m_strokeColor; |
155 RefPtr<Gradient> m_strokeGradient; | 130 RefPtr<Gradient> m_strokeGradient; |
156 RefPtr<Pattern> m_strokePattern; | 131 RefPtr<Pattern> m_strokePattern; |
157 | 132 |
158 Color m_fillColor; | 133 Color m_fillColor; |
159 RefPtr<Gradient> m_fillGradient; | 134 RefPtr<Gradient> m_fillGradient; |
160 RefPtr<Pattern> m_fillPattern; | 135 RefPtr<Pattern> m_fillPattern; |
161 | 136 |
162 RefPtr<SkDrawLooper> m_looper; | 137 RefPtr<SkDrawLooper> m_looper; |
163 RefPtr<SkImageFilter> m_dropShadowImageFilter; | |
164 | 138 |
165 TextDrawingModeFlags m_textDrawingMode; | 139 TextDrawingModeFlags m_textDrawingMode; |
166 | 140 |
167 int m_alpha; | |
168 RefPtr<SkColorFilter> m_colorFilter; | 141 RefPtr<SkColorFilter> m_colorFilter; |
169 | 142 |
170 SkXfermode::Mode m_compositeOperation; | |
171 | |
172 InterpolationQuality m_interpolationQuality; | 143 InterpolationQuality m_interpolationQuality; |
173 | 144 |
174 uint16_t m_saveCount; | 145 uint16_t m_saveCount; |
175 | 146 |
176 bool m_shouldAntialias : 1; | 147 bool m_shouldAntialias : 1; |
177 bool m_shouldClampToSourceRect : 1; | |
178 }; | 148 }; |
179 | 149 |
180 } // namespace blink | 150 } // namespace blink |
181 | 151 |
182 #endif // GraphicsContextState_h | 152 #endif // GraphicsContextState_h |
OLD | NEW |