Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(30)

Side by Side Diff: Source/platform/graphics/GraphicsContextState.h

Issue 169283008: Maintain SkPaint in GraphicsContextState. (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: A couple more optimizations. Created 6 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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 11 matching lines...) Expand all
22 // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 22 // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
23 // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 23 // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
24 // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 24 // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
25 // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 25 // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
26 // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 26 // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
27 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 27 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
28 28
29 #ifndef GraphicsContextState_h 29 #ifndef GraphicsContextState_h
30 #define GraphicsContextState_h 30 #define GraphicsContextState_h
31 31
32 #include "platform/graphics/DrawLooper.h"
32 #include "platform/graphics/Gradient.h" 33 #include "platform/graphics/Gradient.h"
33 #include "platform/graphics/GraphicsTypes.h" 34 #include "platform/graphics/GraphicsTypes.h"
34 #include "platform/graphics/Path.h" 35 #include "platform/graphics/Path.h"
35 #include "platform/graphics/Pattern.h" 36 #include "platform/graphics/Pattern.h"
36 #include "platform/graphics/StrokeData.h" 37 #include "platform/graphics/StrokeData.h"
38 #include "platform/graphics/skia/SkiaUtils.h"
37 #include "third_party/skia/include/core/SkColorFilter.h" 39 #include "third_party/skia/include/core/SkColorFilter.h"
38 #include "third_party/skia/include/core/SkColorPriv.h" 40 #include "third_party/skia/include/core/SkPaint.h"
39 #include "third_party/skia/include/core/SkDrawLooper.h"
40 #include "third_party/skia/include/effects/SkDashPathEffect.h"
41 #include "wtf/PassOwnPtr.h" 41 #include "wtf/PassOwnPtr.h"
42 #include "wtf/RefPtr.h" 42 #include "wtf/RefPtr.h"
43 43
44 namespace WebCore { 44 namespace WebCore {
45 45
46 // Encapsulates the state information we store for each pushed graphics state. 46 // Encapsulates the state information we store for each pushed graphics state.
47 // Only GraphicsContext can use this class. 47 // Only GraphicsContext can use this class.
48 class GraphicsContextState { 48 class PLATFORM_EXPORT GraphicsContextState FINAL {
49 WTF_MAKE_NONCOPYABLE(GraphicsContextState); 49 WTF_MAKE_NONCOPYABLE(GraphicsContextState);
50 private: 50 public:
51 friend class GraphicsContext;
52
53 static PassOwnPtr<GraphicsContextState> create() { return adoptPtr(new Graph icsContextState()); } 51 static PassOwnPtr<GraphicsContextState> create() { return adoptPtr(new Graph icsContextState()); }
54 52
55 GraphicsContextState() 53 GraphicsContextState();
56 : m_fillColor(Color::black)
57 , m_fillRule(RULE_NONZERO)
58 , m_textDrawingMode(TextModeFill)
59 , m_alpha(1)
60 , m_xferMode(nullptr)
61 , m_compositeOperator(CompositeSourceOver)
62 , m_blendMode(blink::WebBlendModeNormal)
63 #if USE(LOW_QUALITY_IMAGE_INTERPOLATION)
64 , m_interpolationQuality(InterpolationLow)
65 #else
66 , m_interpolationQuality(InterpolationHigh)
67 #endif
68 , m_saveCount(0)
69 , m_shouldAntialias(true)
70 , m_shouldSmoothFonts(true)
71 , m_shouldClampToSourceRect(true)
72 {
73 }
74 54
75 void copy(GraphicsContextState* source) 55 void copy(GraphicsContextState*);
76 {
77 m_strokeData = source->m_strokeData;
78 m_fillColor = source->m_fillColor;
79 m_fillRule = source->m_fillRule;
80 m_fillGradient = source->m_fillGradient;
81 m_fillPattern = source->m_fillPattern;
82 m_looper = source->m_looper;
83 m_textDrawingMode = source->m_textDrawingMode;
84 m_alpha = source->m_alpha;
85 m_xferMode = source->m_xferMode;
86 m_colorFilter = source->m_colorFilter;
87 m_compositeOperator = source->m_compositeOperator;
88 m_blendMode = source->m_blendMode;
89 m_interpolationQuality = source->m_interpolationQuality;
90 m_saveCount = 0;
91 m_shouldAntialias = source->m_shouldAntialias;
92 m_shouldSmoothFonts = source->m_shouldSmoothFonts;
93 m_shouldClampToSourceRect = source->m_shouldClampToSourceRect;
94 }
95 56
57 // SkPaint objects that reflect the current state, except:
58 // - Dashed and Dotted strokes.
59 const SkPaint& strokePaint() const;
60 const SkPaint& fillPaint() const;
61
62 uint16_t saveCount() const { return m_saveCount; }
63 void incrementSaveCount() { ++m_saveCount; }
64 void decrementSaveCount() { --m_saveCount; }
65
66 // Stroke data
67 const StrokeData& strokeData() const { return m_strokeData; }
68
69 void setStrokeStyle(StrokeStyle);
70
71 void setStrokeThickness(float);
72
73 SkColor effectiveStrokeColor() const { return applyAlpha(m_strokeData.color( ).rgb()); }
74 void setStrokeColor(const Color&);
75
76 void setStrokeGradient(const PassRefPtr<Gradient>);
77 void clearStrokeGradient();
78
79 void setStrokePattern(const PassRefPtr<Pattern>);
80 void clearStrokePattern();
81
82 void setLineCap(LineCap);
83
84 void setLineJoin(LineJoin);
85
86 void setMiterLimit(float);
87
88 void setLineDash(const DashArray&, float);
89
90 // Fill data
91 Color fillColor() const { return m_fillColor; }
92 SkColor effectiveFillColor() const { return applyAlpha(m_fillColor.rgb()); }
93 void setFillColor(const Color&);
94
95 Gradient* fillGradient() const { return m_fillGradient.get(); }
96 void setFillGradient(const PassRefPtr<Gradient>);
97 void clearFillGradient();
98
99 Pattern* fillPattern() const { return m_fillPattern.get(); }
100 void setFillPattern(const PassRefPtr<Pattern>);
101 void clearFillPattern();
102
103 // Path fill rule
104 WindRule fillRule() const { return m_fillRule; }
105 void setFillRule(WindRule rule) { m_fillRule = rule; }
106
107 // Shadow. (This will need tweaking if we use draw loopers for other things. )
108 SkDrawLooper* drawLooper() const { return m_looper.get(); }
109 void setDrawLooper(const DrawLooper&);
110 void clearDrawLooper();
111
112 // Text. (See TextModeFill & friends.)
113 TextDrawingModeFlags textDrawingMode() const { return m_textDrawingMode; }
114 void setTextDrawingMode(TextDrawingModeFlags mode) { m_textDrawingMode = mod e; }
115
116 // Common shader state.
117 int alpha() const { return m_alpha; }
118 void setAlphaAsFloat(float);
119
120 SkColorFilter* colorFilter() const { return m_colorFilter.get(); }
121 void setColorFilter(PassRefPtr<SkColorFilter>);
122
123 // Compositing control, for the CSS and Canvas compositing spec.
124 void setCompositeOperation(CompositeOperator, blink::WebBlendMode);
125 CompositeOperator compositeOperator() const { return m_compositeOperator; }
126 blink::WebBlendMode blendMode() const { return m_blendMode; }
127 SkXfermode* xferMode() const { return m_xferMode.get(); }
128
129 // Image interpolation control.
130 InterpolationQuality interpolationQuality() const { return m_interpolationQu ality; }
131 void setInterpolationQuality(InterpolationQuality);
132
133 bool shouldAntialias() const { return m_shouldAntialias; }
134 void setShouldAntialias(bool);
135
136 bool shouldSmoothFonts() const { return m_shouldSmoothFonts; }
137 void setShouldSmoothFonts(bool shouldSmoothFonts) { m_shouldSmoothFonts = sh ouldSmoothFonts; }
138
139 bool shouldClampToSourceRect() const { return m_shouldClampToSourceRect; }
140 void setShouldClampToSourceRect(bool shouldClampToSourceRect) { m_shouldClam pToSourceRect = shouldClampToSourceRect; }
141
142 private:
96 // Helper function for applying the state's alpha value to the given input 143 // Helper function for applying the state's alpha value to the given input
97 // color to produce a new output color. 144 // color to produce a new output color.
98 SkColor applyAlpha(SkColor c) const 145 SkColor applyAlpha(SkColor c) const
99 { 146 {
100 int s = roundf(m_alpha * 256); 147 int a = SkAlphaMul(SkColorGetA(c), m_alpha);
101 if (s >= 256)
102 return c;
103 if (s < 0)
104 return 0;
105
106 int a = SkAlphaMul(SkColorGetA(c), s);
107 return (c & 0x00FFFFFF) | (a << 24); 148 return (c & 0x00FFFFFF) | (a << 24);
108 } 149 }
109 150
110 // Stroke. 151 // These are mutbale to enable gradient updates when the paints are fetched for use.
152 mutable SkPaint m_strokePaint;
153 mutable SkPaint m_fillPaint;
154
111 StrokeData m_strokeData; 155 StrokeData m_strokeData;
112 156
113 // Fill.
114 Color m_fillColor; 157 Color m_fillColor;
115 WindRule m_fillRule; 158 WindRule m_fillRule;
116 RefPtr<Gradient> m_fillGradient; 159 RefPtr<Gradient> m_fillGradient;
117 RefPtr<Pattern> m_fillPattern; 160 RefPtr<Pattern> m_fillPattern;
118 161
119 // Shadow. (This will need tweaking if we use draw loopers for other things. )
120 RefPtr<SkDrawLooper> m_looper; 162 RefPtr<SkDrawLooper> m_looper;
121 163
122 // Text. (See TextModeFill & friends.)
123 TextDrawingModeFlags m_textDrawingMode; 164 TextDrawingModeFlags m_textDrawingMode;
124 165
125 // Common shader state. 166 int m_alpha;
126 float m_alpha;
127 RefPtr<SkXfermode> m_xferMode; 167 RefPtr<SkXfermode> m_xferMode;
128 RefPtr<SkColorFilter> m_colorFilter; 168 RefPtr<SkColorFilter> m_colorFilter;
129 169
130 // Compositing control, for the CSS and Canvas compositing spec.
131 CompositeOperator m_compositeOperator; 170 CompositeOperator m_compositeOperator;
132 blink::WebBlendMode m_blendMode; 171 blink::WebBlendMode m_blendMode;
133 172
134 // Image interpolation control.
135 InterpolationQuality m_interpolationQuality; 173 InterpolationQuality m_interpolationQuality;
136 174
137 // The number of GraphicsContext::save calls since this state was pushed.
138 uint16_t m_saveCount; 175 uint16_t m_saveCount;
139 176
140 bool m_shouldAntialias : 1; 177 bool m_shouldAntialias : 1;
141 bool m_shouldSmoothFonts : 1; 178 bool m_shouldSmoothFonts : 1;
142 bool m_shouldClampToSourceRect : 1; 179 bool m_shouldClampToSourceRect : 1;
143 }; 180 };
144 181
145 } // namespace WebCore 182 } // namespace WebCore
146 183
147 #endif // GraphicsContextState_h 184 #endif // GraphicsContextState_h
148
OLDNEW
« no previous file with comments | « Source/platform/graphics/GraphicsContext.cpp ('k') | Source/platform/graphics/GraphicsContextState.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698