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

Side by Side Diff: third_party/WebKit/Source/modules/canvas2d/CanvasRenderingContext2D.h

Issue 1732923002: Revert of Pull up a subset of CanvasRenderingContext2D into BaseRenderingContext2D. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 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
OLDNEW
1 /* 1 /*
2 * Copyright (C) 2006, 2007, 2009, 2010, 2011, 2012 Apple Inc. All rights reserv ed. 2 * Copyright (C) 2006, 2007, 2009, 2010, 2011, 2012 Apple Inc. All rights reserv ed.
3 * 3 *
4 * Redistribution and use in source and binary forms, with or without 4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions 5 * modification, are permitted provided that the following conditions
6 * are met: 6 * are met:
7 * 1. Redistributions of source code must retain the above copyright 7 * 1. 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 * 2. Redistributions in binary form must reproduce the above copyright 9 * 2. Redistributions in binary form must reproduce the above copyright
10 * notice, this list of conditions and the following disclaimer in the 10 * notice, this list of conditions and the following disclaimer in the
(...skipping 15 matching lines...) Expand all
26 #ifndef CanvasRenderingContext2D_h 26 #ifndef CanvasRenderingContext2D_h
27 #define CanvasRenderingContext2D_h 27 #define CanvasRenderingContext2D_h
28 28
29 #include "bindings/core/v8/ScriptWrappable.h" 29 #include "bindings/core/v8/ScriptWrappable.h"
30 #include "bindings/modules/v8/UnionTypesModules.h" 30 #include "bindings/modules/v8/UnionTypesModules.h"
31 #include "core/html/canvas/CanvasContextCreationAttributes.h" 31 #include "core/html/canvas/CanvasContextCreationAttributes.h"
32 #include "core/html/canvas/CanvasRenderingContext.h" 32 #include "core/html/canvas/CanvasRenderingContext.h"
33 #include "core/html/canvas/CanvasRenderingContextFactory.h" 33 #include "core/html/canvas/CanvasRenderingContextFactory.h"
34 #include "core/svg/SVGResourceClient.h" 34 #include "core/svg/SVGResourceClient.h"
35 #include "modules/ModulesExport.h" 35 #include "modules/ModulesExport.h"
36 #include "modules/canvas2d/BaseRenderingContext2D.h"
37 #include "modules/canvas2d/Canvas2DContextAttributes.h" 36 #include "modules/canvas2d/Canvas2DContextAttributes.h"
37 #include "modules/canvas2d/CanvasPathMethods.h"
38 #include "modules/canvas2d/CanvasRenderingContext2DState.h" 38 #include "modules/canvas2d/CanvasRenderingContext2DState.h"
39 #include "platform/graphics/GraphicsTypes.h" 39 #include "platform/graphics/GraphicsTypes.h"
40 #include "platform/heap/GarbageCollected.h" 40 #include "platform/heap/GarbageCollected.h"
41 #include "public/platform/WebThread.h" 41 #include "public/platform/WebThread.h"
42 #include "wtf/Vector.h" 42 #include "wtf/Vector.h"
43 #include "wtf/text/WTFString.h" 43 #include "wtf/text/WTFString.h"
44 44
45 namespace blink { class WebLayer; } 45 namespace blink { class WebLayer; }
46 46
47 namespace blink { 47 namespace blink {
48 48
49 class CanvasImageSource; 49 class CanvasImageSource;
50 class Element; 50 class Element;
51 class ExceptionState; 51 class ExceptionState;
52 class FloatRect; 52 class FloatRect;
53 class FloatSize; 53 class FloatSize;
54 class Font; 54 class Font;
55 class FontMetrics; 55 class FontMetrics;
56 class HitRegion; 56 class HitRegion;
57 class HitRegionOptions; 57 class HitRegionOptions;
58 class HitRegionManager; 58 class HitRegionManager;
59 class ImageData;
59 class Path2D; 60 class Path2D;
60 class SVGMatrixTearOff; 61 class SVGMatrixTearOff;
61 class TextMetrics; 62 class TextMetrics;
62 63
63 typedef HTMLImageElementOrHTMLVideoElementOrHTMLCanvasElementOrImageBitmap Canva sImageSourceUnion; 64 typedef HTMLImageElementOrHTMLVideoElementOrHTMLCanvasElementOrImageBitmap Canva sImageSourceUnion;
64 65
65 class MODULES_EXPORT CanvasRenderingContext2D final : public CanvasRenderingCont ext, public BaseRenderingContext2D, public WebThread::TaskObserver, public SVGRe sourceClient { 66 class MODULES_EXPORT CanvasRenderingContext2D final : public CanvasRenderingCont ext, public CanvasPathMethods, public WebThread::TaskObserver, public SVGResourc eClient {
66 DEFINE_WRAPPERTYPEINFO(); 67 DEFINE_WRAPPERTYPEINFO();
67 WILL_BE_USING_GARBAGE_COLLECTED_MIXIN(CanvasRenderingContext2D);
68 WILL_BE_USING_PRE_FINALIZER(CanvasRenderingContext2D, dispose); 68 WILL_BE_USING_PRE_FINALIZER(CanvasRenderingContext2D, dispose);
69 public: 69 public:
70 class Factory : public CanvasRenderingContextFactory { 70 class Factory : public CanvasRenderingContextFactory {
71 WTF_MAKE_NONCOPYABLE(Factory); 71 WTF_MAKE_NONCOPYABLE(Factory);
72 public: 72 public:
73 Factory() {} 73 Factory() {}
74 ~Factory() override {} 74 ~Factory() override {}
75 75
76 PassOwnPtrWillBeRawPtr<CanvasRenderingContext> create(HTMLCanvasElement* canvas, const CanvasContextCreationAttributes& attrs, Document& document) overr ide 76 PassOwnPtrWillBeRawPtr<CanvasRenderingContext> create(HTMLCanvasElement* canvas, const CanvasContextCreationAttributes& attrs, Document& document) overr ide
77 { 77 {
78 return adoptPtrWillBeNoop(new CanvasRenderingContext2D(canvas, attrs , document)); 78 return adoptPtrWillBeNoop(new CanvasRenderingContext2D(canvas, attrs , document));
79 } 79 }
80 CanvasRenderingContext::ContextType contextType() const override { retur n CanvasRenderingContext::Context2d; } 80 CanvasRenderingContext::ContextType contextType() const override { retur n CanvasRenderingContext::Context2d; }
81 void onError(HTMLCanvasElement*, const String& error) override { } 81 void onError(HTMLCanvasElement*, const String& error) override { }
82 }; 82 };
83 83
84 ~CanvasRenderingContext2D() override; 84 ~CanvasRenderingContext2D() override;
85 85
86 void strokeStyle(StringOrCanvasGradientOrCanvasPattern&) const;
87 void setStrokeStyle(const StringOrCanvasGradientOrCanvasPattern&);
88
89 void fillStyle(StringOrCanvasGradientOrCanvasPattern&) const;
90 void setFillStyle(const StringOrCanvasGradientOrCanvasPattern&);
91
92 double lineWidth() const;
93 void setLineWidth(double);
94
95 String lineCap() const;
96 void setLineCap(const String&);
97
98 String lineJoin() const;
99 void setLineJoin(const String&);
100
101 double miterLimit() const;
102 void setMiterLimit(double);
103
104 const Vector<double>& getLineDash() const;
105 void setLineDash(const Vector<double>&);
106
107 double lineDashOffset() const;
108 void setLineDashOffset(double);
109
110 double shadowOffsetX() const;
111 void setShadowOffsetX(double);
112
113 double shadowOffsetY() const;
114 void setShadowOffsetY(double);
115
116 double shadowBlur() const;
117 void setShadowBlur(double);
118
119 String shadowColor() const;
120 void setShadowColor(const String&);
121
122 double globalAlpha() const;
123 void setGlobalAlpha(double);
124
86 bool isContextLost() const override; 125 bool isContextLost() const override;
87 126
127 bool shouldAntialias() const;
88 void setShouldAntialias(bool) override; 128 void setShouldAntialias(bool) override;
89 129
130 String globalCompositeOperation() const;
131 void setGlobalCompositeOperation(const String&);
132
133 String filter() const;
134 void setFilter(const String&);
135
136 void save();
137 void restore();
138
139 PassRefPtrWillBeRawPtr<SVGMatrixTearOff> currentTransform() const;
140 void setCurrentTransform(PassRefPtrWillBeRawPtr<SVGMatrixTearOff>);
141
142 void scale(double sx, double sy);
143 void rotate(double angleInRadians);
144 void translate(double tx, double ty);
145 void transform(double m11, double m12, double m21, double m22, double dx, do uble dy);
146 void setTransform(double m11, double m12, double m21, double m22, double dx, double dy);
147 void resetTransform();
148
149 void beginPath();
150
151 void fill(const String& winding = "nonzero");
152 void fill(Path2D*, const String& winding = "nonzero");
153 void stroke();
154 void stroke(Path2D*);
155 void clip(const String& winding = "nonzero");
156 void clip(Path2D*, const String& winding = "nonzero");
157
158 bool isPointInPath(const double x, const double y, const String& winding = " nonzero");
159 bool isPointInPath(Path2D*, const double x, const double y, const String& wi nding = "nonzero");
160 bool isPointInStroke(const double x, const double y);
161 bool isPointInStroke(Path2D*, const double x, const double y);
162
90 void scrollPathIntoView(); 163 void scrollPathIntoView();
91 void scrollPathIntoView(Path2D*); 164 void scrollPathIntoView(Path2D*);
92 165
93 void clearRect(double x, double y, double width, double height) override; 166 void clearRect(double x, double y, double width, double height) override;
167 void fillRect(double x, double y, double width, double height);
168 void strokeRect(double x, double y, double width, double height);
169
170 void drawImage(const CanvasImageSourceUnion&, double x, double y, ExceptionS tate&);
171 void drawImage(const CanvasImageSourceUnion&, double x, double y, double wid th, double height, ExceptionState&);
172 void drawImage(const CanvasImageSourceUnion&, double sx, double sy, double s w, double sh, double dx, double dy, double dw, double dh, ExceptionState&);
173 void drawImage(CanvasImageSource*, double sx, double sy, double sw, double s h, double dx, double dy, double dw, double dh, ExceptionState&);
174
175 CanvasGradient* createLinearGradient(double x0, double y0, double x1, double y1);
176 CanvasGradient* createRadialGradient(double x0, double y0, double r0, double x1, double y1, double r1, ExceptionState&);
177 CanvasPattern* createPattern(const CanvasImageSourceUnion&, const String& re petitionType, ExceptionState&);
178
179 ImageData* createImageData(ImageData*) const;
180 ImageData* createImageData(double width, double height, ExceptionState&) con st;
181 ImageData* getImageData(double sx, double sy, double sw, double sh, Exceptio nState&) const;
182 void putImageData(ImageData*, double dx, double dy, ExceptionState&);
183 void putImageData(ImageData*, double dx, double dy, double dirtyX, double di rtyY, double dirtyWidth, double dirtyHeight, ExceptionState&);
94 184
95 void reset() override; 185 void reset() override;
96 186
97 String font() const; 187 String font() const;
98 void setFont(const String&) override; 188 void setFont(const String&) override;
99 189
100 String textAlign() const; 190 String textAlign() const;
101 void setTextAlign(const String&); 191 void setTextAlign(const String&);
102 192
103 String textBaseline() const; 193 String textBaseline() const;
104 void setTextBaseline(const String&); 194 void setTextBaseline(const String&);
105 195
106 String direction() const; 196 String direction() const;
107 void setDirection(const String&); 197 void setDirection(const String&);
108 198
109 void fillText(const String& text, double x, double y); 199 void fillText(const String& text, double x, double y);
110 void fillText(const String& text, double x, double y, double maxWidth); 200 void fillText(const String& text, double x, double y, double maxWidth);
111 void strokeText(const String& text, double x, double y); 201 void strokeText(const String& text, double x, double y);
112 void strokeText(const String& text, double x, double y, double maxWidth); 202 void strokeText(const String& text, double x, double y, double maxWidth);
113 TextMetrics* measureText(const String& text); 203 TextMetrics* measureText(const String& text);
114 204
205 bool imageSmoothingEnabled() const;
206 void setImageSmoothingEnabled(bool);
207 String imageSmoothingQuality() const;
208 void setImageSmoothingQuality(const String&);
209
115 void getContextAttributes(Canvas2DContextAttributes&) const; 210 void getContextAttributes(Canvas2DContextAttributes&) const;
116 211
117 void drawFocusIfNeeded(Element*); 212 void drawFocusIfNeeded(Element*);
118 void drawFocusIfNeeded(Path2D*, Element*); 213 void drawFocusIfNeeded(Path2D*, Element*);
119 214
120 void addHitRegion(const HitRegionOptions&, ExceptionState&); 215 void addHitRegion(const HitRegionOptions&, ExceptionState&);
121 void removeHitRegion(const String& id); 216 void removeHitRegion(const String& id);
122 void clearHitRegions(); 217 void clearHitRegions();
123 HitRegion* hitRegionAtPoint(const FloatPoint&); 218 HitRegion* hitRegionAtPoint(const FloatPoint&);
124 unsigned hitRegionsCount() const override; 219 unsigned hitRegionsCount() const override;
125 220
126 void loseContext(LostContextMode) override; 221 void loseContext(LostContextMode) override;
127 void didSetSurfaceSize() override; 222 void didSetSurfaceSize() override;
128 223
129 void restoreCanvasMatrixClipStack(SkCanvas*) const override; 224 void restoreCanvasMatrixClipStack(SkCanvas*) const override;
130 225
131 // TaskObserver implementation 226 // TaskObserver implementation
132 void didProcessTask() override; 227 void didProcessTask() override;
133 void willProcessTask() override { } 228 void willProcessTask() override { }
134 229
135 void styleDidChange(const ComputedStyle* oldStyle, const ComputedStyle& newS tyle) override; 230 void styleDidChange(const ComputedStyle* oldStyle, const ComputedStyle& newS tyle) override;
136 231
137 // SVGResourceClient implementation 232 // SVGResourceClient implementation
138 void filterNeedsInvalidation() override; 233 void filterNeedsInvalidation() override;
139 234
140 // BaseRenderingContext2D implementation
141 bool originClean() const final;
142 void setOriginTainted() final;
143 bool wouldTaintOrigin(CanvasImageSource* source) final { return CanvasRender ingContext::wouldTaintOrigin(source); }
144
145 int width() const final;
146 int height() const final;
147
148 bool hasImageBuffer() const final;
149 ImageBuffer* imageBuffer() const final;
150
151 bool parseColorOrCurrentColor(Color&, const String& colorString) const final ;
152
153 SkCanvas* drawingCanvas() const final;
154 SkCanvas* existingDrawingCanvas() const final;
155 void disableDeferral(DisableDeferralReason) final;
156
157 AffineTransform baseTransform() const final;
158 void didDraw(const SkIRect& dirtyRect) final;
159
160 bool stateHasFilter() final;
161 SkImageFilter* stateGetFilter() final;
162
163 void validateStateStack() final;
164
165 private: 235 private:
166 friend class CanvasRenderingContext2DAutoRestoreSkCanvas; 236 friend class CanvasRenderingContext2DAutoRestoreSkCanvas;
167 237
168 CanvasRenderingContext2D(HTMLCanvasElement*, const CanvasContextCreationAttr ibutes& attrs, Document&); 238 CanvasRenderingContext2D(HTMLCanvasElement*, const CanvasContextCreationAttr ibutes& attrs, Document&);
169 239
170 void dispose(); 240 void dispose();
171 241
242 CanvasRenderingContext2DState& modifiableState();
243 const CanvasRenderingContext2DState& state() const { return *m_stateStack.la st(); }
244
245 void setShadow(const FloatSize& offset, double blur, RGBA32 color);
246
172 void dispatchContextLostEvent(Timer<CanvasRenderingContext2D>*); 247 void dispatchContextLostEvent(Timer<CanvasRenderingContext2D>*);
173 void dispatchContextRestoredEvent(Timer<CanvasRenderingContext2D>*); 248 void dispatchContextRestoredEvent(Timer<CanvasRenderingContext2D>*);
174 void tryRestoreContextEvent(Timer<CanvasRenderingContext2D>*); 249 void tryRestoreContextEvent(Timer<CanvasRenderingContext2D>*);
175 250
251 bool computeDirtyRect(const FloatRect& localBounds, SkIRect*);
252 bool computeDirtyRect(const FloatRect& localBounds, const SkIRect& transform edClipBounds, SkIRect*);
253 void didDraw(const SkIRect&);
254
255 SkCanvas* drawingCanvas() const;
256
176 void unwindStateStack(); 257 void unwindStateStack();
258 void realizeSaves();
177 259
178 void pruneLocalFontCache(size_t targetSize); 260 void pruneLocalFontCache(size_t targetSize);
179 void schedulePruneLocalFontCacheIfNeeded(); 261 void schedulePruneLocalFontCacheIfNeeded();
180 262
263 bool shouldDrawImageAntialiased(const FloatRect& destRect) const;
264
265 template<typename DrawFunc, typename ContainsFunc>
266 bool draw(const DrawFunc&, const ContainsFunc&, const SkRect& bounds, Canvas RenderingContext2DState::PaintType, CanvasRenderingContext2DState::ImageType = C anvasRenderingContext2DState::NoImage);
267 void drawPathInternal(const Path&, CanvasRenderingContext2DState::PaintType, SkPath::FillType = SkPath::kWinding_FillType);
268 void drawImageInternal(SkCanvas*, CanvasImageSource*, Image*, const FloatRec t& srcRect, const FloatRect& dstRect, const SkPaint*);
269 void clipInternal(const Path&, const String& windingRuleString);
270
271 bool isPointInPathInternal(const Path&, const double x, const double y, cons t String& windingRuleString);
272 bool isPointInStrokeInternal(const Path&, const double x, const double y);
273
181 void scrollPathIntoViewInternal(const Path&); 274 void scrollPathIntoViewInternal(const Path&);
182 275
183 void drawTextInternal(const String&, double x, double y, CanvasRenderingCont ext2DState::PaintType, double* maxWidth = nullptr); 276 void drawTextInternal(const String&, double x, double y, CanvasRenderingCont ext2DState::PaintType, double* maxWidth = nullptr);
184 277
185 const Font& accessFont(); 278 const Font& accessFont();
186 int getFontBaseline(const FontMetrics&) const; 279 int getFontBaseline(const FontMetrics&) const;
187 280
281 void clearCanvas();
282 bool rectContainsTransformedRect(const FloatRect&, const SkIRect&) const;
283
284 void inflateStrokeRect(FloatRect&) const;
285
286 template<typename DrawFunc>
287 void compositedDraw(const DrawFunc&, SkCanvas*, CanvasRenderingContext2DStat e::PaintType, CanvasRenderingContext2DState::ImageType);
288
188 void drawFocusIfNeededInternal(const Path&, Element*); 289 void drawFocusIfNeededInternal(const Path&, Element*);
189 bool focusRingCallIsValid(const Path&, Element*); 290 bool focusRingCallIsValid(const Path&, Element*);
190 void drawFocusRing(const Path&); 291 void drawFocusRing(const Path&);
191 void updateElementAccessibility(const Path&, Element*); 292 void updateElementAccessibility(const Path&, Element*);
192 293
294 void validateStateStack();
295
296 enum DrawType {
297 ClipFill, // Fill that is already known to cover the current clip
298 UntransformedUnclippedFill
299 };
300
301 void checkOverdraw(const SkRect&, const SkPaint*, CanvasRenderingContext2DSt ate::ImageType, DrawType);
302
193 CanvasRenderingContext::ContextType contextType() const override { return Ca nvasRenderingContext::Context2d; } 303 CanvasRenderingContext::ContextType contextType() const override { return Ca nvasRenderingContext::Context2d; }
194 bool is2d() const override { return true; } 304 bool is2d() const override { return true; }
195 bool isAccelerated() const override; 305 bool isAccelerated() const override;
196 bool hasAlpha() const override { return m_hasAlpha; } 306 bool hasAlpha() const override { return m_hasAlpha; }
197 void setIsHidden(bool) override; 307 void setIsHidden(bool) override;
198 void stop() final; 308 void stop() final;
199 DECLARE_VIRTUAL_TRACE(); 309 DECLARE_VIRTUAL_TRACE();
200 310
201 virtual bool isTransformInvertible() const; 311 virtual bool isTransformInvertible() const;
202 312
203 WebLayer* platformLayer() const override; 313 WebLayer* platformLayer() const override;
204 314
315 WillBeHeapVector<OwnPtrWillBeMember<CanvasRenderingContext2DState>> m_stateS tack;
205 PersistentWillBeMember<HitRegionManager> m_hitRegionManager; 316 PersistentWillBeMember<HitRegionManager> m_hitRegionManager;
317 AntiAliasingMode m_clipAntialiasing;
206 bool m_hasAlpha; 318 bool m_hasAlpha;
207 LostContextMode m_contextLostMode; 319 LostContextMode m_contextLostMode;
208 bool m_contextRestorable; 320 bool m_contextRestorable;
209 unsigned m_tryRestoreContextAttemptCount; 321 unsigned m_tryRestoreContextAttemptCount;
210 Timer<CanvasRenderingContext2D> m_dispatchContextLostEventTimer; 322 Timer<CanvasRenderingContext2D> m_dispatchContextLostEventTimer;
211 Timer<CanvasRenderingContext2D> m_dispatchContextRestoredEventTimer; 323 Timer<CanvasRenderingContext2D> m_dispatchContextRestoredEventTimer;
212 Timer<CanvasRenderingContext2D> m_tryRestoreContextEventTimer; 324 Timer<CanvasRenderingContext2D> m_tryRestoreContextEventTimer;
213 325
214 HashMap<String, Font> m_fontsResolvedUsingCurrentStyle; 326 HashMap<String, Font> m_fontsResolvedUsingCurrentStyle;
215 bool m_pruneLocalFontCacheScheduled; 327 bool m_pruneLocalFontCacheScheduled;
216 ListHashSet<String> m_fontLRUList; 328 ListHashSet<String> m_fontLRUList;
217 }; 329 };
218 330
219 DEFINE_TYPE_CASTS(CanvasRenderingContext2D, CanvasRenderingContext, context, con text->is2d(), context.is2d()); 331 DEFINE_TYPE_CASTS(CanvasRenderingContext2D, CanvasRenderingContext, context, con text->is2d(), context.is2d());
220 332
221 } // namespace blink 333 } // namespace blink
222 334
223 #endif // CanvasRenderingContext2D_h 335 #endif // CanvasRenderingContext2D_h
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698