OLD | NEW |
---|---|
1 /* | 1 // Copyright 2016 The Chromium Authors. All rights reserved. |
2 * Copyright (C) 2006, 2007, 2009, 2010, 2011, 2012 Apple Inc. All rights reserv ed. | 2 // Use of this source code is governed by a BSD-style license that can be |
3 * | 3 // found in the LICENSE file. |
4 * Redistribution and use in source and binary forms, with or without | |
5 * modification, are permitted provided that the following conditions | |
6 * are met: | |
7 * 1. Redistributions of source code must retain the above copyright | |
8 * notice, this list of conditions and the following disclaimer. | |
9 * 2. Redistributions in binary form must reproduce the above copyright | |
10 * notice, this list of conditions and the following disclaimer in the | |
11 * documentation and/or other materials provided with the distribution. | |
12 * | |
13 * THIS SOFTWARE IS PROVIDED BY APPLE COMPUTER, INC. ``AS IS'' AND ANY | |
14 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | |
15 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR | |
16 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE COMPUTER, INC. OR | |
17 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, | |
18 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, | |
19 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR | |
20 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY | |
21 * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | |
22 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE | |
23 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | |
24 */ | |
25 | 4 |
26 #ifndef CanvasRenderingContext2D_h | 5 #ifndef BaseRenderingContext2D_h |
27 #define CanvasRenderingContext2D_h | 6 #define BaseRenderingContext2D_h |
28 | 7 |
29 #include "bindings/core/v8/ScriptWrappable.h" | 8 #include "bindings/core/v8/UnionTypesCore.h" |
30 #include "bindings/modules/v8/UnionTypesModules.h" | 9 #include "bindings/modules/v8/UnionTypesModules.h" |
31 #include "core/html/canvas/CanvasContextCreationAttributes.h" | |
32 #include "core/html/canvas/CanvasRenderingContext.h" | 10 #include "core/html/canvas/CanvasRenderingContext.h" |
33 #include "core/html/canvas/CanvasRenderingContextFactory.h" | |
34 #include "core/svg/SVGResourceClient.h" | |
35 #include "modules/ModulesExport.h" | 11 #include "modules/ModulesExport.h" |
36 #include "modules/canvas2d/Canvas2DContextAttributes.h" | 12 #include "modules/canvas2d/CanvasGradient.h" |
37 #include "modules/canvas2d/CanvasPathMethods.h" | 13 #include "modules/canvas2d/CanvasPathMethods.h" |
38 #include "modules/canvas2d/CanvasRenderingContext2DState.h" | 14 #include "modules/canvas2d/CanvasRenderingContext2DState.h" |
39 #include "platform/graphics/GraphicsTypes.h" | 15 #include "modules/canvas2d/CanvasStyle.h" |
40 #include "platform/heap/GarbageCollected.h" | 16 #include "third_party/skia/include/core/SkCanvas.h" |
41 #include "public/platform/WebThread.h" | |
42 #include "wtf/Vector.h" | |
43 #include "wtf/text/WTFString.h" | |
44 | |
45 namespace blink { class WebLayer; } | |
46 | 17 |
47 namespace blink { | 18 namespace blink { |
48 | 19 |
49 class CanvasImageSource; | 20 class CanvasImageSource; |
50 class Element; | 21 class Color; |
51 class ExceptionState; | 22 class Image; |
52 class FloatRect; | 23 class ImageBuffer; |
53 class FloatSize; | |
54 class Font; | |
55 class FontMetrics; | |
56 class HitRegion; | |
57 class HitRegionOptions; | |
58 class HitRegionManager; | |
59 class ImageData; | |
60 class Path2D; | 24 class Path2D; |
61 class SVGMatrixTearOff; | 25 class SVGMatrixTearOff; |
62 class TextMetrics; | |
63 | 26 |
64 typedef HTMLImageElementOrHTMLVideoElementOrHTMLCanvasElementOrImageBitmap Canva sImageSourceUnion; | 27 typedef HTMLImageElementOrHTMLVideoElementOrHTMLCanvasElementOrImageBitmap Canva sImageSourceUnion; |
65 | 28 |
66 class MODULES_EXPORT CanvasRenderingContext2D final : public CanvasRenderingCont ext, public CanvasPathMethods, public WebThread::TaskObserver, public SVGResourc eClient { | 29 class MODULES_EXPORT BaseRenderingContext2D : public WillBeGarbageCollectedMixin , public CanvasPathMethods { |
67 DEFINE_WRAPPERTYPEINFO(); | |
68 WILL_BE_USING_PRE_FINALIZER(CanvasRenderingContext2D, dispose); | |
69 public: | 30 public: |
70 class Factory : public CanvasRenderingContextFactory { | 31 ~BaseRenderingContext2D() override; |
71 WTF_MAKE_NONCOPYABLE(Factory); | |
72 public: | |
73 Factory() {} | |
74 ~Factory() override {} | |
75 | |
76 PassOwnPtrWillBeRawPtr<CanvasRenderingContext> create(HTMLCanvasElement* canvas, const CanvasContextCreationAttributes& attrs, Document& document) overr ide | |
77 { | |
78 return adoptPtrWillBeNoop(new CanvasRenderingContext2D(canvas, attrs , document)); | |
79 } | |
80 CanvasRenderingContext::ContextType contextType() const override { retur n CanvasRenderingContext::Context2d; } | |
81 void onError(HTMLCanvasElement*, const String& error) override { } | |
82 }; | |
83 | |
84 ~CanvasRenderingContext2D() override; | |
85 | 32 |
86 void strokeStyle(StringOrCanvasGradientOrCanvasPattern&) const; | 33 void strokeStyle(StringOrCanvasGradientOrCanvasPattern&) const; |
87 void setStrokeStyle(const StringOrCanvasGradientOrCanvasPattern&); | 34 void setStrokeStyle(const StringOrCanvasGradientOrCanvasPattern&); |
88 | 35 |
89 void fillStyle(StringOrCanvasGradientOrCanvasPattern&) const; | 36 void fillStyle(StringOrCanvasGradientOrCanvasPattern&) const; |
90 void setFillStyle(const StringOrCanvasGradientOrCanvasPattern&); | 37 void setFillStyle(const StringOrCanvasGradientOrCanvasPattern&); |
91 | 38 |
92 double lineWidth() const; | 39 double lineWidth() const; |
93 void setLineWidth(double); | 40 void setLineWidth(double); |
94 | 41 |
(...skipping 20 matching lines...) Expand all Loading... | |
115 | 62 |
116 double shadowBlur() const; | 63 double shadowBlur() const; |
117 void setShadowBlur(double); | 64 void setShadowBlur(double); |
118 | 65 |
119 String shadowColor() const; | 66 String shadowColor() const; |
120 void setShadowColor(const String&); | 67 void setShadowColor(const String&); |
121 | 68 |
122 double globalAlpha() const; | 69 double globalAlpha() const; |
123 void setGlobalAlpha(double); | 70 void setGlobalAlpha(double); |
124 | 71 |
125 bool isContextLost() const override; | |
126 | |
127 bool shouldAntialias() const; | |
128 void setShouldAntialias(bool) override; | |
129 | |
130 String globalCompositeOperation() const; | 72 String globalCompositeOperation() const; |
131 void setGlobalCompositeOperation(const String&); | 73 void setGlobalCompositeOperation(const String&); |
132 | 74 |
133 String filter() const; | 75 String filter() const; |
134 void setFilter(const String&); | 76 void setFilter(const String&); |
135 | 77 |
136 void save(); | 78 void save(); |
137 void restore(); | 79 void restore(); |
138 | 80 |
139 PassRefPtrWillBeRawPtr<SVGMatrixTearOff> currentTransform() const; | 81 PassRefPtrWillBeRawPtr<SVGMatrixTearOff> currentTransform() const; |
(...skipping 13 matching lines...) Expand all Loading... | |
153 void stroke(); | 95 void stroke(); |
154 void stroke(Path2D*); | 96 void stroke(Path2D*); |
155 void clip(const String& winding = "nonzero"); | 97 void clip(const String& winding = "nonzero"); |
156 void clip(Path2D*, const String& winding = "nonzero"); | 98 void clip(Path2D*, const String& winding = "nonzero"); |
157 | 99 |
158 bool isPointInPath(const double x, const double y, const String& winding = " nonzero"); | 100 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"); | 101 bool isPointInPath(Path2D*, const double x, const double y, const String& wi nding = "nonzero"); |
160 bool isPointInStroke(const double x, const double y); | 102 bool isPointInStroke(const double x, const double y); |
161 bool isPointInStroke(Path2D*, const double x, const double y); | 103 bool isPointInStroke(Path2D*, const double x, const double y); |
162 | 104 |
163 void scrollPathIntoView(); | 105 void clearRect(double x, double y, double width, double height); |
164 void scrollPathIntoView(Path2D*); | |
165 | |
166 void clearRect(double x, double y, double width, double height) override; | |
167 void fillRect(double x, double y, double width, double height); | 106 void fillRect(double x, double y, double width, double height); |
168 void strokeRect(double x, double y, double width, double height); | 107 void strokeRect(double x, double y, double width, double height); |
169 | 108 |
170 void drawImage(const CanvasImageSourceUnion&, double x, double y, ExceptionS tate&); | 109 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&); | 110 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&); | 111 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&); | 112 void drawImage(CanvasImageSource*, double sx, double sy, double sw, double s h, double dx, double dy, double dw, double dh, ExceptionState&); |
174 | 113 |
175 CanvasGradient* createLinearGradient(double x0, double y0, double x1, double y1); | 114 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&); | 115 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&); | 116 CanvasPattern* createPattern(const CanvasImageSourceUnion&, const String& re petitionType, ExceptionState&); |
178 | 117 |
179 ImageData* createImageData(ImageData*) const; | 118 ImageData* createImageData(ImageData*) const; |
180 ImageData* createImageData(double width, double height, ExceptionState&) con st; | 119 ImageData* createImageData(double width, double height, ExceptionState&) con st; |
181 ImageData* getImageData(double sx, double sy, double sw, double sh, Exceptio nState&) const; | 120 ImageData* getImageData(double sx, double sy, double sw, double sh, Exceptio nState&) const; |
182 void putImageData(ImageData*, double dx, double dy, ExceptionState&); | 121 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&); | 122 void putImageData(ImageData*, double dx, double dy, double dirtyX, double di rtyY, double dirtyWidth, double dirtyHeight, ExceptionState&); |
184 | 123 |
185 void reset() override; | |
186 | |
187 String font() const; | |
188 void setFont(const String&) override; | |
189 | |
190 String textAlign() const; | |
191 void setTextAlign(const String&); | |
192 | |
193 String textBaseline() const; | |
194 void setTextBaseline(const String&); | |
195 | |
196 String direction() const; | |
197 void setDirection(const String&); | |
198 | |
199 void fillText(const String& text, double x, double y); | |
200 void fillText(const String& text, double x, double y, double maxWidth); | |
201 void strokeText(const String& text, double x, double y); | |
202 void strokeText(const String& text, double x, double y, double maxWidth); | |
203 TextMetrics* measureText(const String& text); | |
204 | |
205 bool imageSmoothingEnabled() const; | 124 bool imageSmoothingEnabled() const; |
206 void setImageSmoothingEnabled(bool); | 125 void setImageSmoothingEnabled(bool); |
207 String imageSmoothingQuality() const; | 126 String imageSmoothingQuality() const; |
208 void setImageSmoothingQuality(const String&); | 127 void setImageSmoothingQuality(const String&); |
209 | 128 |
210 void getContextAttributes(Canvas2DContextAttributes&) const; | 129 virtual bool originClean() const = 0; |
130 virtual void setOriginTainted() = 0; | |
131 virtual bool wouldTaintOrigin(CanvasImageSource*) = 0; | |
211 | 132 |
212 void drawFocusIfNeeded(Element*); | 133 virtual int width() const = 0; |
213 void drawFocusIfNeeded(Path2D*, Element*); | 134 virtual int height() const = 0; |
214 | 135 |
215 void addHitRegion(const HitRegionOptions&, ExceptionState&); | 136 virtual bool hasImageBuffer() const = 0; |
216 void removeHitRegion(const String& id); | 137 virtual ImageBuffer* imageBuffer() const = 0; |
217 void clearHitRegions(); | |
218 HitRegion* hitRegionAtPoint(const FloatPoint&); | |
219 unsigned hitRegionsCount() const override; | |
220 | 138 |
221 void loseContext(LostContextMode) override; | 139 virtual bool parseColorOrCurrentColor(Color&, const String& colorString) con st = 0; |
222 void didSetSurfaceSize() override; | |
223 | 140 |
224 void restoreCanvasMatrixClipStack(SkCanvas*) const override; | 141 virtual SkCanvas* drawingCanvas() const = 0; |
142 virtual SkCanvas* existingDrawingCanvas() const = 0; | |
143 virtual void disableDeferral(DisableDeferralReason) = 0; | |
225 | 144 |
226 // TaskObserver implementation | 145 virtual AffineTransform baseTransform() const = 0; |
227 void didProcessTask() override; | |
228 void willProcessTask() override { } | |
229 | 146 |
230 void styleDidChange(const ComputedStyle* oldStyle, const ComputedStyle& newS tyle) override; | 147 virtual void didDraw(const SkIRect& dirtyRect) = 0; |
231 | 148 |
232 // SVGResourceClient implementation | 149 virtual bool stateHasFilter() = 0; |
233 void filterNeedsInvalidation() override; | 150 virtual SkImageFilter* stateGetFilter() = 0; |
234 | 151 |
235 private: | 152 virtual void validateStateStack() = 0; |
236 friend class CanvasRenderingContext2DAutoRestoreSkCanvas; | |
237 | 153 |
238 CanvasRenderingContext2D(HTMLCanvasElement*, const CanvasContextCreationAttr ibutes& attrs, Document&); | 154 virtual bool hasAlpha() const = 0; |
239 | 155 |
240 void dispose(); | 156 virtual bool isContextLost() const = 0; |
157 | |
158 DECLARE_VIRTUAL_TRACE(); | |
159 | |
160 protected: | |
161 BaseRenderingContext2D(); | |
241 | 162 |
242 CanvasRenderingContext2DState& modifiableState(); | 163 CanvasRenderingContext2DState& modifiableState(); |
243 const CanvasRenderingContext2DState& state() const { return *m_stateStack.la st(); } | 164 const CanvasRenderingContext2DState& state() const { return *m_stateStack.la st(); } |
244 | 165 |
245 void setShadow(const FloatSize& offset, double blur, RGBA32 color); | |
246 | |
247 void dispatchContextLostEvent(Timer<CanvasRenderingContext2D>*); | |
248 void dispatchContextRestoredEvent(Timer<CanvasRenderingContext2D>*); | |
249 void tryRestoreContextEvent(Timer<CanvasRenderingContext2D>*); | |
250 | |
251 bool computeDirtyRect(const FloatRect& localBounds, SkIRect*); | 166 bool computeDirtyRect(const FloatRect& localBounds, SkIRect*); |
252 bool computeDirtyRect(const FloatRect& localBounds, const SkIRect& transform edClipBounds, SkIRect*); | 167 bool computeDirtyRect(const FloatRect& localBounds, const SkIRect& transform edClipBounds, SkIRect*); |
253 void didDraw(const SkIRect&); | |
254 | 168 |
255 SkCanvas* drawingCanvas() const; | 169 template<typename DrawFunc, typename ContainsFunc> |
170 bool draw(const DrawFunc& drawFunc, const ContainsFunc& drawCoversClipBounds , const SkRect& bounds, CanvasRenderingContext2DState::PaintType paintType, Canv asRenderingContext2DState::ImageType imageType = CanvasRenderingContext2DState:: NoImage) | |
171 { | |
172 if (!state().isTransformInvertible()) | |
173 return false; | |
256 | 174 |
257 void unwindStateStack(); | 175 SkIRect clipBounds; |
176 if (!drawingCanvas() || !drawingCanvas()->getClipDeviceBounds(&clipBound s)) | |
177 return false; | |
178 | |
179 // If gradient size is zero, then paint nothing. | |
180 CanvasStyle* style = state().style(paintType); | |
181 if (style) { | |
182 CanvasGradient* gradient = style->canvasGradient(); | |
183 if (gradient && gradient->gradient()->isZeroSize()) | |
184 return false; | |
185 } | |
186 | |
187 if (isFullCanvasCompositeMode(state().globalComposite()) || stateHasFilt er()) { | |
188 compositedDraw(drawFunc, drawingCanvas(), paintType, imageType); | |
189 didDraw(clipBounds); | |
190 } else if (state().globalComposite() == SkXfermode::kSrc_Mode) { | |
191 clearCanvas(); // takes care of checkOverdraw() | |
192 const SkPaint* paint = state().getPaint(paintType, DrawForegroundOnl y, imageType); | |
193 drawFunc(drawingCanvas(), paint); | |
194 didDraw(clipBounds); | |
195 } else { | |
196 SkIRect dirtyRect; | |
197 if (computeDirtyRect(bounds, clipBounds, &dirtyRect)) { | |
198 const SkPaint* paint = state().getPaint(paintType, DrawShadowAnd Foreground, imageType); | |
199 if (paintType != CanvasRenderingContext2DState::StrokePaintType && drawCoversClipBounds(clipBounds)) | |
200 checkOverdraw(bounds, paint, imageType, ClipFill); | |
201 drawFunc(drawingCanvas(), paint); | |
202 didDraw(dirtyRect); | |
203 } | |
204 } | |
205 return true; | |
206 } | |
207 | |
208 void inflateStrokeRect(FloatRect&) const; | |
209 | |
210 enum DrawType { | |
211 ClipFill, // Fill that is already known to cover the current clip | |
212 UntransformedUnclippedFill | |
213 }; | |
214 | |
215 void checkOverdraw(const SkRect&, const SkPaint*, CanvasRenderingContext2DSt ate::ImageType, DrawType); | |
216 | |
217 WillBeHeapVector<OwnPtrWillBeMember<CanvasRenderingContext2DState>> m_stateS tack; | |
218 AntiAliasingMode m_clipAntialiasing; | |
219 | |
220 private: | |
258 void realizeSaves(); | 221 void realizeSaves(); |
259 | 222 |
260 void pruneLocalFontCache(size_t targetSize); | |
261 void schedulePruneLocalFontCacheIfNeeded(); | |
262 | |
263 bool shouldDrawImageAntialiased(const FloatRect& destRect) const; | 223 bool shouldDrawImageAntialiased(const FloatRect& destRect) const; |
264 | 224 |
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); | 225 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*); | 226 void drawImageInternal(SkCanvas*, CanvasImageSource*, Image*, const FloatRec t& srcRect, const FloatRect& dstRect, const SkPaint*); |
269 void clipInternal(const Path&, const String& windingRuleString); | 227 void clipInternal(const Path&, const String& windingRuleString); |
270 | 228 |
271 bool isPointInPathInternal(const Path&, const double x, const double y, cons t String& windingRuleString); | 229 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); | 230 bool isPointInStrokeInternal(const Path&, const double x, const double y); |
273 | 231 |
274 void scrollPathIntoViewInternal(const Path&); | 232 static bool isFullCanvasCompositeMode(SkXfermode::Mode); |
275 | 233 |
276 void drawTextInternal(const String&, double x, double y, CanvasRenderingCont ext2DState::PaintType, double* maxWidth = nullptr); | 234 template<typename DrawFunc> |
235 void compositedDraw(const DrawFunc& drawFunc, SkCanvas* c, CanvasRenderingCo ntext2DState::PaintType paintType, CanvasRenderingContext2DState::ImageType imag eType) | |
Justin Novosad
2016/02/22 22:50:55
This is a pretty big method. I don't think a separ
ikilpatrick
2016/02/22 23:19:10
Done.
| |
236 { | |
237 SkImageFilter* filter = stateGetFilter(); | |
238 ASSERT(isFullCanvasCompositeMode(state().globalComposite()) || filter); | |
239 SkMatrix ctm = c->getTotalMatrix(); | |
240 c->resetMatrix(); | |
241 SkPaint compositePaint; | |
242 compositePaint.setXfermodeMode(state().globalComposite()); | |
243 if (state().shouldDrawShadows()) { | |
244 // unroll into two independently composited passes if drawing shadow s | |
245 SkPaint shadowPaint = *state().getPaint(paintType, DrawShadowOnly, i mageType); | |
246 int saveCount = c->getSaveCount(); | |
247 if (filter) { | |
248 SkPaint filterPaint; | |
249 filterPaint.setImageFilter(filter); | |
250 // TODO(junov): crbug.com/502921 We could use primitive bounds i f we knew that the filter | |
251 // does not affect transparent black regions. | |
252 c->saveLayer(nullptr, &shadowPaint); | |
253 c->saveLayer(nullptr, &filterPaint); | |
254 SkPaint foregroundPaint = *state().getPaint(paintType, DrawForeg roundOnly, imageType); | |
255 c->setMatrix(ctm); | |
256 drawFunc(c, &foregroundPaint); | |
257 } else { | |
258 ASSERT(isFullCanvasCompositeMode(state().globalComposite())); | |
259 c->saveLayer(nullptr, &compositePaint); | |
260 shadowPaint.setXfermodeMode(SkXfermode::kSrcOver_Mode); | |
261 c->setMatrix(ctm); | |
262 drawFunc(c, &shadowPaint); | |
263 } | |
264 c->restoreToCount(saveCount); | |
265 } | |
277 | 266 |
278 const Font& accessFont(); | 267 compositePaint.setImageFilter(filter); |
279 int getFontBaseline(const FontMetrics&) const; | 268 // TODO(junov): crbug.com/502921 We could use primitive bounds if we kne w that the filter |
269 // does not affect transparent black regions *and* !isFullCanvasComposit eMode | |
270 c->saveLayer(nullptr, &compositePaint); | |
271 SkPaint foregroundPaint = *state().getPaint(paintType, DrawForegroundOnl y, imageType); | |
272 foregroundPaint.setXfermodeMode(SkXfermode::kSrcOver_Mode); | |
273 c->setMatrix(ctm); | |
274 drawFunc(c, &foregroundPaint); | |
275 c->restore(); | |
276 c->setMatrix(ctm); | |
277 } | |
280 | 278 |
281 void clearCanvas(); | 279 void clearCanvas(); |
282 bool rectContainsTransformedRect(const FloatRect&, const SkIRect&) const; | 280 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 | |
289 void drawFocusIfNeededInternal(const Path&, Element*); | |
290 bool focusRingCallIsValid(const Path&, Element*); | |
291 void drawFocusRing(const Path&); | |
292 void updateElementAccessibility(const Path&, Element*); | |
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 | |
303 CanvasRenderingContext::ContextType contextType() const override { return Ca nvasRenderingContext::Context2d; } | |
304 bool is2d() const override { return true; } | |
305 bool isAccelerated() const override; | |
306 bool hasAlpha() const override { return m_hasAlpha; } | |
307 void setIsHidden(bool) override; | |
308 void stop() final; | |
309 DECLARE_VIRTUAL_TRACE(); | |
310 | |
311 virtual bool isTransformInvertible() const; | |
312 | |
313 WebLayer* platformLayer() const override; | |
314 | |
315 WillBeHeapVector<OwnPtrWillBeMember<CanvasRenderingContext2DState>> m_stateS tack; | |
316 PersistentWillBeMember<HitRegionManager> m_hitRegionManager; | |
317 AntiAliasingMode m_clipAntialiasing; | |
318 bool m_hasAlpha; | |
319 LostContextMode m_contextLostMode; | |
320 bool m_contextRestorable; | |
321 unsigned m_tryRestoreContextAttemptCount; | |
322 Timer<CanvasRenderingContext2D> m_dispatchContextLostEventTimer; | |
323 Timer<CanvasRenderingContext2D> m_dispatchContextRestoredEventTimer; | |
324 Timer<CanvasRenderingContext2D> m_tryRestoreContextEventTimer; | |
325 | |
326 HashMap<String, Font> m_fontsResolvedUsingCurrentStyle; | |
327 bool m_pruneLocalFontCacheScheduled; | |
328 ListHashSet<String> m_fontLRUList; | |
329 }; | 281 }; |
330 | 282 |
331 DEFINE_TYPE_CASTS(CanvasRenderingContext2D, CanvasRenderingContext, context, con text->is2d(), context.is2d()); | |
332 | |
333 } // namespace blink | 283 } // namespace blink |
334 | 284 |
335 #endif // CanvasRenderingContext2D_h | 285 #endif // BaseRenderingContext2D_h |
OLD | NEW |