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

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

Issue 1093673002: Removing the dependency on GraphicsContext for drawing images in 2D canvas (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: pdr corrections + needsrebaselines Created 5 years, 7 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 19 matching lines...) Expand all
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
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 // Path fill rule 99 // Path fill rule
103 WindRule fillRule() const { return m_fillRule; } 100 WindRule fillRule() const { return m_fillRule; }
104 void setFillRule(WindRule rule) { m_fillRule = rule; } 101 void setFillRule(WindRule rule) { m_fillRule = rule; }
105 102
106 // Shadow. (This will need tweaking if we use draw loopers for other things. ) 103 // Shadow. (This will need tweaking if we use draw loopers for other things. )
107 SkDrawLooper* drawLooper() const { return m_looper.get(); } 104 SkDrawLooper* drawLooper() const { return m_looper.get(); }
108 void setDrawLooper(PassRefPtr<SkDrawLooper>); 105 void setDrawLooper(PassRefPtr<SkDrawLooper>);
109 void clearDrawLooper(); 106 void clearDrawLooper();
110 107
111 SkImageFilter* dropShadowImageFilter() const { return m_dropShadowImageFilte r.get(); }
112 void setDropShadowImageFilter(PassRefPtr<SkImageFilter>);
113 void clearDropShadowImageFilter();
114
115 // Text. (See TextModeFill & friends.) 108 // Text. (See TextModeFill & friends.)
116 TextDrawingModeFlags textDrawingMode() const { return m_textDrawingMode; } 109 TextDrawingModeFlags textDrawingMode() const { return m_textDrawingMode; }
117 void setTextDrawingMode(TextDrawingModeFlags mode) { m_textDrawingMode = mod e; } 110 void setTextDrawingMode(TextDrawingModeFlags mode) { m_textDrawingMode = mod e; }
118 111
119 // Common shader state.
120 int alpha() const { return m_alpha; }
121 void setAlphaAsFloat(float);
122
123 SkColorFilter* colorFilter() const { return m_colorFilter.get(); } 112 SkColorFilter* colorFilter() const { return m_colorFilter.get(); }
124 void setColorFilter(PassRefPtr<SkColorFilter>); 113 void setColorFilter(PassRefPtr<SkColorFilter>);
125 114
126 // Compositing control, for the CSS and Canvas compositing spec.
127 void setCompositeOperation(SkXfermode::Mode);
128 SkXfermode::Mode compositeOperation() const { return m_compositeOperation; }
129
130 // Image interpolation control. 115 // Image interpolation control.
131 InterpolationQuality interpolationQuality() const { return m_interpolationQu ality; } 116 InterpolationQuality interpolationQuality() const { return m_interpolationQu ality; }
132 void setInterpolationQuality(InterpolationQuality); 117 void setInterpolationQuality(InterpolationQuality);
133 118
134 bool shouldAntialias() const { return m_shouldAntialias; } 119 bool shouldAntialias() const { return m_shouldAntialias; }
135 void setShouldAntialias(bool); 120 void setShouldAntialias(bool);
136 121
137 bool shouldClampToSourceRect() const { return m_shouldClampToSourceRect; }
138 void setShouldClampToSourceRect(bool shouldClampToSourceRect) { m_shouldClam pToSourceRect = shouldClampToSourceRect; }
139
140 private: 122 private:
141 GraphicsContextState(); 123 GraphicsContextState();
142 explicit GraphicsContextState(const GraphicsContextState&); 124 explicit GraphicsContextState(const GraphicsContextState&);
143 GraphicsContextState& operator=(const GraphicsContextState&); 125 GraphicsContextState& operator=(const GraphicsContextState&);
144 126
145 // Helper function for applying the state's alpha value to the given input
146 // color to produce a new output color.
147 SkColor applyAlpha(SkColor color) const
148 {
149 return scaleAlpha(color, m_alpha);
150 }
151
152 // These are mutbale to enable gradient updates when the paints are fetched for use. 127 // These are mutbale to enable gradient updates when the paints are fetched for use.
153 mutable SkPaint m_strokePaint; 128 mutable SkPaint m_strokePaint;
154 mutable SkPaint m_fillPaint; 129 mutable SkPaint m_fillPaint;
155 130
156 StrokeData m_strokeData; 131 StrokeData m_strokeData;
157 132
158 Color m_strokeColor; 133 Color m_strokeColor;
159 RefPtr<Gradient> m_strokeGradient; 134 RefPtr<Gradient> m_strokeGradient;
160 RefPtr<Pattern> m_strokePattern; 135 RefPtr<Pattern> m_strokePattern;
161 136
162 Color m_fillColor; 137 Color m_fillColor;
163 WindRule m_fillRule; 138 WindRule m_fillRule;
164 RefPtr<Gradient> m_fillGradient; 139 RefPtr<Gradient> m_fillGradient;
165 RefPtr<Pattern> m_fillPattern; 140 RefPtr<Pattern> m_fillPattern;
166 141
167 RefPtr<SkDrawLooper> m_looper; 142 RefPtr<SkDrawLooper> m_looper;
168 RefPtr<SkImageFilter> m_dropShadowImageFilter;
169 143
170 TextDrawingModeFlags m_textDrawingMode; 144 TextDrawingModeFlags m_textDrawingMode;
171 145
172 int m_alpha;
173 RefPtr<SkColorFilter> m_colorFilter; 146 RefPtr<SkColorFilter> m_colorFilter;
174 147
175 SkXfermode::Mode m_compositeOperation;
176
177 InterpolationQuality m_interpolationQuality; 148 InterpolationQuality m_interpolationQuality;
178 149
179 uint16_t m_saveCount; 150 uint16_t m_saveCount;
180 151
181 bool m_shouldAntialias : 1; 152 bool m_shouldAntialias : 1;
182 bool m_shouldClampToSourceRect : 1;
183 }; 153 };
184 154
185 } // namespace blink 155 } // namespace blink
186 156
187 #endif // GraphicsContextState_h 157 #endif // GraphicsContextState_h
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698