Add a GraphicsContextImpl and use it for DispayList::Recorder
[WebKit-https.git] / Source / WebCore / platform / graphics / GraphicsContext.cpp
1 /*
2  * Copyright (C) 2003, 2004, 2005, 2006, 2009, 2013 Apple Inc. All rights reserved.
3  *
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 INC. AND ITS CONTRIBUTORS ``AS IS''
14  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
15  * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
16  * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS
17  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
18  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
19  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
20  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
21  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
22  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
23  * THE POSSIBILITY OF SUCH DAMAGE.
24  */
25
26 #include "config.h"
27 #include "GraphicsContext.h"
28
29 #include "BidiResolver.h"
30 #include "BitmapImage.h"
31 #include "FloatRoundedRect.h"
32 #include "Gradient.h"
33 #include "GraphicsContextImpl.h"
34 #include "ImageBuffer.h"
35 #include "IntRect.h"
36 #include "RoundedRect.h"
37 #include "TextRun.h"
38 #include <wtf/text/TextStream.h>
39
40 namespace WebCore {
41
42 class TextRunIterator {
43 public:
44     TextRunIterator()
45         : m_textRun(0)
46         , m_offset(0)
47     {
48     }
49
50     TextRunIterator(const TextRun* textRun, unsigned offset)
51         : m_textRun(textRun)
52         , m_offset(offset)
53     {
54     }
55
56     TextRunIterator(const TextRunIterator& other)
57         : m_textRun(other.m_textRun)
58         , m_offset(other.m_offset)
59     {
60     }
61
62     unsigned offset() const { return m_offset; }
63     void increment() { m_offset++; }
64     bool atEnd() const { return !m_textRun || m_offset >= m_textRun->length(); }
65     UChar current() const { return (*m_textRun)[m_offset]; }
66     UCharDirection direction() const { return atEnd() ? U_OTHER_NEUTRAL : u_charDirection(current()); }
67
68     bool operator==(const TextRunIterator& other)
69     {
70         return m_offset == other.m_offset && m_textRun == other.m_textRun;
71     }
72
73     bool operator!=(const TextRunIterator& other) { return !operator==(other); }
74
75 private:
76     const TextRun* m_textRun;
77     unsigned m_offset;
78 };
79
80 #define CHECK_FOR_CHANGED_PROPERTY(flag, property) \
81     if ((m_changeFlags & GraphicsContextState::flag) && (m_state.property != state.property)) \
82         changeFlags |= GraphicsContextState::flag;
83
84 GraphicsContextState::StateChangeFlags GraphicsContextStateChange::changesFromState(const GraphicsContextState& state) const
85 {
86     GraphicsContextState::StateChangeFlags changeFlags = GraphicsContextState::NoChange;
87
88     CHECK_FOR_CHANGED_PROPERTY(StrokeGradientChange, strokeGradient);
89     CHECK_FOR_CHANGED_PROPERTY(StrokePatternChange, strokePattern);
90     CHECK_FOR_CHANGED_PROPERTY(FillGradientChange, fillGradient);
91     CHECK_FOR_CHANGED_PROPERTY(FillPatternChange, fillPattern);
92
93     if ((m_changeFlags & GraphicsContextState::ShadowChange)
94         && (m_state.shadowOffset != state.shadowOffset
95             || m_state.shadowBlur != state.shadowBlur
96             || m_state.shadowColor != state.shadowColor))
97         changeFlags |= GraphicsContextState::ShadowChange;
98
99     CHECK_FOR_CHANGED_PROPERTY(StrokeThicknessChange, strokeThickness);
100     CHECK_FOR_CHANGED_PROPERTY(TextDrawingModeChange, textDrawingMode);
101     CHECK_FOR_CHANGED_PROPERTY(StrokeColorChange, strokeColor);
102     CHECK_FOR_CHANGED_PROPERTY(FillColorChange, fillColor);
103     CHECK_FOR_CHANGED_PROPERTY(StrokeStyleChange, strokeStyle);
104     CHECK_FOR_CHANGED_PROPERTY(FillRuleChange, fillRule);
105     CHECK_FOR_CHANGED_PROPERTY(AlphaChange, alpha);
106
107     if ((m_changeFlags & (GraphicsContextState::CompositeOperationChange | GraphicsContextState::BlendModeChange))
108         && (m_state.compositeOperator != state.compositeOperator || m_state.blendMode != state.blendMode))
109         changeFlags |= (GraphicsContextState::CompositeOperationChange | GraphicsContextState::BlendModeChange);
110
111     CHECK_FOR_CHANGED_PROPERTY(ShouldAntialiasChange, shouldAntialias);
112     CHECK_FOR_CHANGED_PROPERTY(ShouldSmoothFontsChange, shouldSmoothFonts);
113     CHECK_FOR_CHANGED_PROPERTY(ShouldSubpixelQuantizeFontsChange, shouldSubpixelQuantizeFonts);
114     CHECK_FOR_CHANGED_PROPERTY(ShadowsIgnoreTransformsChange, shadowsIgnoreTransforms);
115     CHECK_FOR_CHANGED_PROPERTY(DrawLuminanceMaskChange, drawLuminanceMask);
116     CHECK_FOR_CHANGED_PROPERTY(ImageInterpolationQualityChange, imageInterpolationQuality);
117
118     return changeFlags;
119 }
120
121 void GraphicsContextStateChange::accumulate(const GraphicsContextState& state, GraphicsContextState::StateChangeFlags flags)
122 {
123     // FIXME: This code should move to GraphicsContextState.
124     if (flags & GraphicsContextState::StrokeGradientChange)
125         m_state.strokeGradient = state.strokeGradient;
126
127     if (flags & GraphicsContextState::StrokePatternChange)
128         m_state.strokePattern = state.strokePattern;
129
130     if (flags & GraphicsContextState::FillGradientChange)
131         m_state.fillGradient = state.fillGradient;
132
133     if (flags & GraphicsContextState::FillPatternChange)
134         m_state.fillPattern = state.fillPattern;
135
136     if (flags & GraphicsContextState::ShadowChange) {
137         // FIXME: Deal with state.shadowsUseLegacyRadius.
138         m_state.shadowOffset = state.shadowOffset;
139         m_state.shadowBlur = state.shadowBlur;
140         m_state.shadowColor = state.shadowColor;
141     }
142
143     if (flags & GraphicsContextState::StrokeThicknessChange)
144         m_state.strokeThickness = state.strokeThickness;
145
146     if (flags & GraphicsContextState::TextDrawingModeChange)
147         m_state.textDrawingMode = state.textDrawingMode;
148
149     if (flags & GraphicsContextState::StrokeColorChange)
150         m_state.strokeColor = state.strokeColor;
151
152     if (flags & GraphicsContextState::FillColorChange)
153         m_state.fillColor = state.fillColor;
154
155     if (flags & GraphicsContextState::StrokeStyleChange)
156         m_state.strokeStyle = state.strokeStyle;
157
158     if (flags & GraphicsContextState::FillRuleChange)
159         m_state.fillRule = state.fillRule;
160
161     if (flags & GraphicsContextState::AlphaChange)
162         m_state.alpha = state.alpha;
163
164     if (flags & (GraphicsContextState::CompositeOperationChange | GraphicsContextState::BlendModeChange)) {
165         m_state.compositeOperator = state.compositeOperator;
166         m_state.blendMode = state.blendMode;
167     }
168
169     if (flags & GraphicsContextState::ShouldAntialiasChange)
170         m_state.shouldAntialias = state.shouldAntialias;
171
172     if (flags & GraphicsContextState::ShouldSmoothFontsChange)
173         m_state.shouldSmoothFonts = state.shouldSmoothFonts;
174
175     if (flags & GraphicsContextState::ShouldSubpixelQuantizeFontsChange)
176         m_state.shouldSubpixelQuantizeFonts = state.shouldSubpixelQuantizeFonts;
177
178     if (flags & GraphicsContextState::ShadowsIgnoreTransformsChange)
179         m_state.shadowsIgnoreTransforms = state.shadowsIgnoreTransforms;
180
181     if (flags & GraphicsContextState::DrawLuminanceMaskChange)
182         m_state.drawLuminanceMask = state.drawLuminanceMask;
183
184     if (flags & GraphicsContextState::ImageInterpolationQualityChange)
185         m_state.imageInterpolationQuality = state.imageInterpolationQuality;
186     
187     m_changeFlags |= flags;
188 }
189
190 void GraphicsContextStateChange::apply(GraphicsContext& context) const
191 {
192     if (m_changeFlags & GraphicsContextState::StrokeGradientChange)
193         context.setStrokeGradient(*m_state.strokeGradient);
194
195     if (m_changeFlags & GraphicsContextState::StrokePatternChange)
196         context.setStrokePattern(*m_state.strokePattern);
197
198     if (m_changeFlags & GraphicsContextState::FillGradientChange)
199         context.setFillGradient(*m_state.fillGradient);
200
201     if (m_changeFlags & GraphicsContextState::FillPatternChange)
202         context.setFillPattern(*m_state.fillPattern);
203
204     if (m_changeFlags & GraphicsContextState::ShadowChange) {
205 #if USE(CG)
206         if (m_state.shadowsUseLegacyRadius)
207             context.setLegacyShadow(m_state.shadowOffset, m_state.shadowBlur, m_state.shadowColor);
208         else
209 #endif
210             context.setShadow(m_state.shadowOffset, m_state.shadowBlur, m_state.shadowColor);
211     }
212
213     if (m_changeFlags & GraphicsContextState::StrokeThicknessChange)
214         context.setStrokeThickness(m_state.strokeThickness);
215
216     if (m_changeFlags & GraphicsContextState::TextDrawingModeChange)
217         context.setTextDrawingMode(m_state.textDrawingMode);
218
219     if (m_changeFlags & GraphicsContextState::StrokeColorChange)
220         context.setStrokeColor(m_state.strokeColor);
221
222     if (m_changeFlags & GraphicsContextState::FillColorChange)
223         context.setFillColor(m_state.fillColor);
224
225     if (m_changeFlags & GraphicsContextState::StrokeStyleChange)
226         context.setStrokeStyle(m_state.strokeStyle);
227
228     if (m_changeFlags & GraphicsContextState::FillRuleChange)
229         context.setFillRule(m_state.fillRule);
230
231     if (m_changeFlags & GraphicsContextState::AlphaChange)
232         context.setAlpha(m_state.alpha);
233
234     if (m_changeFlags & (GraphicsContextState::CompositeOperationChange | GraphicsContextState::BlendModeChange))
235         context.setCompositeOperation(m_state.compositeOperator, m_state.blendMode);
236
237     if (m_changeFlags & GraphicsContextState::ShouldAntialiasChange)
238         context.setShouldAntialias(m_state.shouldAntialias);
239
240     if (m_changeFlags & GraphicsContextState::ShouldSmoothFontsChange)
241         context.setShouldSmoothFonts(m_state.shouldSmoothFonts);
242
243     if (m_changeFlags & GraphicsContextState::ShouldSubpixelQuantizeFontsChange)
244         context.setShouldSubpixelQuantizeFonts(m_state.shouldSubpixelQuantizeFonts);
245
246     if (m_changeFlags & GraphicsContextState::ShadowsIgnoreTransformsChange)
247         context.setShadowsIgnoreTransforms(m_state.shadowsIgnoreTransforms);
248
249     if (m_changeFlags & GraphicsContextState::DrawLuminanceMaskChange)
250         context.setDrawLuminanceMask(m_state.drawLuminanceMask);
251
252     if (m_changeFlags & GraphicsContextState::ImageInterpolationQualityChange)
253         context.setImageInterpolationQuality(m_state.imageInterpolationQuality);
254 }
255
256 void GraphicsContextStateChange::dump(TextStream& ts) const
257 {
258     ts.dumpProperty("change-flags", m_changeFlags);
259
260     if (m_changeFlags & GraphicsContextState::StrokeGradientChange)
261         ts.dumpProperty("stroke-gradient", m_state.strokeGradient.get());
262
263     if (m_changeFlags & GraphicsContextState::StrokePatternChange)
264         ts.dumpProperty("stroke-pattern", m_state.strokePattern.get());
265
266     if (m_changeFlags & GraphicsContextState::FillGradientChange)
267         ts.dumpProperty("fill-gradient", m_state.fillGradient.get());
268
269     if (m_changeFlags & GraphicsContextState::FillPatternChange)
270         ts.dumpProperty("fill-pattern", m_state.fillPattern.get());
271
272     if (m_changeFlags & GraphicsContextState::ShadowChange) {
273         ts.dumpProperty("shadow-blur", m_state.shadowBlur);
274         ts.dumpProperty("shadow-offset", m_state.shadowOffset);
275 #if USE(CG)
276         ts.dumpProperty("shadows-use-legacy-radius", m_state.shadowsUseLegacyRadius);
277 #endif
278     }
279
280     if (m_changeFlags & GraphicsContextState::StrokeThicknessChange)
281         ts.dumpProperty("stroke-thickness", m_state.strokeThickness);
282
283     if (m_changeFlags & GraphicsContextState::TextDrawingModeChange)
284         ts.dumpProperty("text-drawing-mode", m_state.textDrawingMode);
285
286     if (m_changeFlags & GraphicsContextState::StrokeColorChange)
287         ts.dumpProperty("stroke-color", m_state.strokeColor);
288
289     if (m_changeFlags & GraphicsContextState::FillColorChange)
290         ts.dumpProperty("fill-color", m_state.fillColor);
291
292     if (m_changeFlags & GraphicsContextState::StrokeStyleChange)
293         ts.dumpProperty("stroke-style", m_state.strokeStyle);
294
295     if (m_changeFlags & GraphicsContextState::FillRuleChange)
296         ts.dumpProperty("fill-rule", m_state.fillRule);
297
298     if (m_changeFlags & GraphicsContextState::AlphaChange)
299         ts.dumpProperty("alpha", m_state.alpha);
300
301     if (m_changeFlags & GraphicsContextState::CompositeOperationChange)
302         ts.dumpProperty("composite-operator", m_state.compositeOperator);
303
304     if (m_changeFlags & GraphicsContextState::BlendModeChange)
305         ts.dumpProperty("blend-mode", m_state.blendMode);
306
307     if (m_changeFlags & GraphicsContextState::ShouldAntialiasChange)
308         ts.dumpProperty("should-antialias", m_state.shouldAntialias);
309
310     if (m_changeFlags & GraphicsContextState::ShouldSmoothFontsChange)
311         ts.dumpProperty("should-smooth-fonts", m_state.shouldSmoothFonts);
312
313     if (m_changeFlags & GraphicsContextState::ShouldSubpixelQuantizeFontsChange)
314         ts.dumpProperty("should-subpixel-quantize-fonts", m_state.shouldSubpixelQuantizeFonts);
315
316     if (m_changeFlags & GraphicsContextState::ShadowsIgnoreTransformsChange)
317         ts.dumpProperty("shadows-ignore-transforms", m_state.shadowsIgnoreTransforms);
318
319     if (m_changeFlags & GraphicsContextState::DrawLuminanceMaskChange)
320         ts.dumpProperty("draw-luminance-mask", m_state.drawLuminanceMask);
321 }
322
323 TextStream& operator<<(TextStream& ts, const GraphicsContextStateChange& stateChange)
324 {
325     stateChange.dump(ts);
326     return ts;
327 }
328
329 GraphicsContext::GraphicsContext(NonPaintingReasons nonPaintingReasons)
330     : m_nonPaintingReasons(nonPaintingReasons)
331 {
332 }
333
334 GraphicsContext::GraphicsContext(PlatformGraphicsContext* platformGraphicsContext)
335 {
336     platformInit(platformGraphicsContext);
337 }
338
339 GraphicsContext::GraphicsContext(const GraphicsContextImplFactory& factoryFunction)
340     : m_impl(factoryFunction(*this))
341 {
342 }
343
344 GraphicsContext::~GraphicsContext()
345 {
346     ASSERT(m_stack.isEmpty());
347     ASSERT(!m_transparencyCount);
348     platformDestroy();
349 }
350
351 void GraphicsContext::save()
352 {
353     if (paintingDisabled())
354         return;
355
356     m_stack.append(m_state);
357
358     if (m_impl) {
359         m_impl->save();
360         return;
361     }
362
363     savePlatformState();
364 }
365
366 void GraphicsContext::restore()
367 {
368     if (paintingDisabled())
369         return;
370
371     if (m_stack.isEmpty()) {
372         LOG_ERROR("ERROR void GraphicsContext::restore() stack is empty");
373         return;
374     }
375
376     m_state = m_stack.last();
377     m_stack.removeLast();
378
379     // Make sure we deallocate the state stack buffer when it goes empty.
380     // Canvas elements will immediately save() again, but that goes into inline capacity.
381     if (m_stack.isEmpty())
382         m_stack.clear();
383
384     if (m_impl) {
385         m_impl->restore();
386         return;
387     }
388
389     restorePlatformState();
390 }
391
392 void GraphicsContext::drawRaisedEllipse(const FloatRect& rect, const Color& ellipseColor, const Color& shadowColor)
393 {
394     if (paintingDisabled())
395         return;
396
397     save();
398
399     setStrokeColor(shadowColor);
400     setFillColor(shadowColor);
401
402     drawEllipse(FloatRect(rect.x(), rect.y() + 1, rect.width(), rect.height()));
403
404     setStrokeColor(ellipseColor);
405     setFillColor(ellipseColor);
406
407     drawEllipse(rect);  
408
409     restore();
410 }
411
412 void GraphicsContext::setStrokeThickness(float thickness)
413 {
414     m_state.strokeThickness = thickness;
415     if (m_impl) {
416         m_impl->updateState(m_state, GraphicsContextState::StrokeThicknessChange);
417         return;
418     }
419
420     setPlatformStrokeThickness(thickness);
421 }
422
423 void GraphicsContext::setStrokeStyle(StrokeStyle style)
424 {
425     m_state.strokeStyle = style;
426     if (m_impl) {
427         m_impl->updateState(m_state, GraphicsContextState::StrokeStyleChange);
428         return;
429     }
430     setPlatformStrokeStyle(style);
431 }
432
433 void GraphicsContext::setStrokeColor(const Color& color)
434 {
435     m_state.strokeColor = color;
436     m_state.strokeGradient = nullptr;
437     m_state.strokePattern = nullptr;
438     if (m_impl) {
439         m_impl->updateState(m_state, GraphicsContextState::StrokeColorChange);
440         return;
441     }
442     setPlatformStrokeColor(color);
443 }
444
445 void GraphicsContext::setShadow(const FloatSize& offset, float blur, const Color& color)
446 {
447     m_state.shadowOffset = offset;
448     m_state.shadowBlur = blur;
449     m_state.shadowColor = color;
450 #if USE(CG)
451     m_state.shadowsUseLegacyRadius = false;
452 #endif
453     if (m_impl) {
454         m_impl->updateState(m_state, GraphicsContextState::ShadowChange);
455         return;
456     }
457     setPlatformShadow(offset, blur, color);
458 }
459
460 void GraphicsContext::setLegacyShadow(const FloatSize& offset, float blur, const Color& color)
461 {
462     m_state.shadowOffset = offset;
463     m_state.shadowBlur = blur;
464     m_state.shadowColor = color;
465 #if USE(CG)
466     m_state.shadowsUseLegacyRadius = true;
467 #endif
468     if (m_impl) {
469         m_impl->updateState(m_state, GraphicsContextState::ShadowChange);
470         return;
471     }
472     setPlatformShadow(offset, blur, color);
473 }
474
475 void GraphicsContext::clearShadow()
476 {
477     m_state.shadowOffset = FloatSize();
478     m_state.shadowBlur = 0;
479     m_state.shadowColor = Color();
480 #if USE(CG)
481     m_state.shadowsUseLegacyRadius = false;
482 #endif
483
484     if (m_impl) {
485         m_impl->clearShadow();
486         return;
487     }
488     clearPlatformShadow();
489 }
490
491 bool GraphicsContext::getShadow(FloatSize& offset, float& blur, Color& color) const
492 {
493     offset = m_state.shadowOffset;
494     blur = m_state.shadowBlur;
495     color = m_state.shadowColor;
496
497     return hasShadow();
498 }
499
500 #if USE(CAIRO)
501 bool GraphicsContext::mustUseShadowBlur() const
502 {
503     // We can't avoid ShadowBlur if the shadow has blur.
504     if (hasBlurredShadow())
505         return true;
506     // We can avoid ShadowBlur and optimize, since we're not drawing on a
507     // canvas and box shadows are affected by the transformation matrix.
508     if (!m_state.shadowsIgnoreTransforms)
509         return false;
510     // We can avoid ShadowBlur, since there are no transformations to apply to the canvas.
511     if (getCTM().isIdentity())
512         return false;
513     // Otherwise, no chance avoiding ShadowBlur.
514     return true;
515 }
516 #endif
517
518 void GraphicsContext::setFillColor(const Color& color)
519 {
520     m_state.fillColor = color;
521     m_state.fillGradient = nullptr;
522     m_state.fillPattern = nullptr;
523
524     if (m_impl) {
525         m_impl->updateState(m_state, GraphicsContextState::FillColorChange);
526         return;
527     }
528
529     setPlatformFillColor(color);
530 }
531
532 void GraphicsContext::setShadowsIgnoreTransforms(bool shadowsIgnoreTransforms)
533 {
534     m_state.shadowsIgnoreTransforms = shadowsIgnoreTransforms;
535     if (m_impl)
536         m_impl->updateState(m_state, GraphicsContextState::ShadowsIgnoreTransformsChange);
537 }
538
539 void GraphicsContext::setShouldAntialias(bool shouldAntialias)
540 {
541     m_state.shouldAntialias = shouldAntialias;
542
543     if (m_impl) {
544         m_impl->updateState(m_state, GraphicsContextState::ShouldAntialiasChange);
545         return;
546     }
547
548     setPlatformShouldAntialias(shouldAntialias);
549 }
550
551 void GraphicsContext::setShouldSmoothFonts(bool shouldSmoothFonts)
552 {
553     m_state.shouldSmoothFonts = shouldSmoothFonts;
554     
555     if (m_impl) {
556         m_impl->updateState(m_state, GraphicsContextState::ShouldSmoothFontsChange);
557         return;
558     }
559     
560     setPlatformShouldSmoothFonts(shouldSmoothFonts);
561 }
562
563 void GraphicsContext::setShouldSubpixelQuantizeFonts(bool shouldSubpixelQuantizeFonts)
564 {
565     m_state.shouldSubpixelQuantizeFonts = shouldSubpixelQuantizeFonts;
566     if (m_impl)
567         m_impl->updateState(m_state, GraphicsContextState::ShouldSubpixelQuantizeFontsChange);
568 }
569
570 void GraphicsContext::setImageInterpolationQuality(InterpolationQuality imageInterpolationQuality)
571 {
572     m_state.imageInterpolationQuality = imageInterpolationQuality;
573
574     if (paintingDisabled())
575         return;
576
577     if (m_impl) {
578         m_impl->updateState(m_state, GraphicsContextState::ImageInterpolationQualityChange);
579         return;
580     }
581
582     setPlatformImageInterpolationQuality(imageInterpolationQuality);
583 }
584
585 void GraphicsContext::setStrokePattern(Ref<Pattern>&& pattern)
586 {
587     m_state.strokeGradient = nullptr;
588     m_state.strokePattern = WTFMove(pattern);
589     if (m_impl)
590         m_impl->updateState(m_state, GraphicsContextState::StrokePatternChange);
591 }
592
593 void GraphicsContext::setFillPattern(Ref<Pattern>&& pattern)
594 {
595     m_state.fillGradient = nullptr;
596     m_state.fillPattern = WTFMove(pattern);
597     if (m_impl)
598         m_impl->updateState(m_state, GraphicsContextState::FillPatternChange);
599 }
600
601 void GraphicsContext::setStrokeGradient(Ref<Gradient>&& gradient)
602 {
603     m_state.strokeGradient = WTFMove(gradient);
604     m_state.strokePattern = nullptr;
605     if (m_impl)
606         m_impl->updateState(m_state, GraphicsContextState::StrokeGradientChange);
607 }
608
609 void GraphicsContext::setFillRule(WindRule fillRule)
610 {
611     m_state.fillRule = fillRule;
612     if (m_impl)
613         m_impl->updateState(m_state, GraphicsContextState::FillRuleChange);
614 }
615
616 void GraphicsContext::setFillGradient(Ref<Gradient>&& gradient)
617 {
618     m_state.fillGradient = WTFMove(gradient);
619     m_state.fillPattern = nullptr;
620     if (m_impl)
621         m_impl->updateState(m_state, GraphicsContextState::FillGradientChange); // FIXME: also fill pattern?
622 }
623
624 void GraphicsContext::beginTransparencyLayer(float opacity)
625 {
626     if (m_impl) {
627         m_impl->beginTransparencyLayer(opacity);
628         return;
629     }
630     beginPlatformTransparencyLayer(opacity);
631     ++m_transparencyCount;
632 }
633
634 void GraphicsContext::endTransparencyLayer()
635 {
636     if (m_impl) {
637         m_impl->endTransparencyLayer();
638         return;
639     }
640     endPlatformTransparencyLayer();
641     ASSERT(m_transparencyCount > 0);
642     --m_transparencyCount;
643 }
644
645 float GraphicsContext::drawText(const FontCascade& font, const TextRun& run, const FloatPoint& point, unsigned from, std::optional<unsigned> to)
646 {
647     if (paintingDisabled())
648         return 0;
649
650     // Display list recording for text content is done at glyphs level. See GraphicsContext::drawGlyphs.
651     return font.drawText(*this, run, point, from, to);
652 }
653
654 void GraphicsContext::drawGlyphs(const FontCascade& fontCascade, const Font& font, const GlyphBuffer& buffer, unsigned from, unsigned numGlyphs, const FloatPoint& point)
655 {
656     if (paintingDisabled())
657         return;
658
659     if (m_impl) {
660         m_impl->drawGlyphs(font, buffer, from, numGlyphs, point, fontCascade.fontDescription().fontSmoothing());
661         return;
662     }
663
664     fontCascade.drawGlyphs(*this, font, buffer, from, numGlyphs, point, fontCascade.fontDescription().fontSmoothing());
665 }
666
667 void GraphicsContext::drawEmphasisMarks(const FontCascade& font, const TextRun& run, const AtomicString& mark, const FloatPoint& point, unsigned from, std::optional<unsigned> to)
668 {
669     if (paintingDisabled())
670         return;
671
672     font.drawEmphasisMarks(*this, run, mark, point, from, to);
673 }
674
675 void GraphicsContext::drawBidiText(const FontCascade& font, const TextRun& run, const FloatPoint& point, FontCascade::CustomFontNotReadyAction customFontNotReadyAction)
676 {
677     if (paintingDisabled())
678         return;
679
680     BidiResolver<TextRunIterator, BidiCharacterRun> bidiResolver;
681     bidiResolver.setStatus(BidiStatus(run.direction(), run.directionalOverride()));
682     bidiResolver.setPositionIgnoringNestedIsolates(TextRunIterator(&run, 0));
683
684     // FIXME: This ownership should be reversed. We should pass BidiRunList
685     // to BidiResolver in createBidiRunsForLine.
686     BidiRunList<BidiCharacterRun>& bidiRuns = bidiResolver.runs();
687     bidiResolver.createBidiRunsForLine(TextRunIterator(&run, run.length()));
688
689     if (!bidiRuns.runCount())
690         return;
691
692     FloatPoint currPoint = point;
693     BidiCharacterRun* bidiRun = bidiRuns.firstRun();
694     while (bidiRun) {
695         TextRun subrun = run.subRun(bidiRun->start(), bidiRun->stop() - bidiRun->start());
696         bool isRTL = bidiRun->level() % 2;
697         subrun.setDirection(isRTL ? RTL : LTR);
698         subrun.setDirectionalOverride(bidiRun->dirOverride(false));
699
700         float width = font.drawText(*this, subrun, currPoint, 0, std::nullopt, customFontNotReadyAction);
701         currPoint.move(width, 0);
702
703         bidiRun = bidiRun->next();
704     }
705
706     bidiRuns.clear();
707 }
708
709 ImageDrawResult GraphicsContext::drawImage(Image& image, const FloatPoint& destination, const ImagePaintingOptions& imagePaintingOptions)
710 {
711     return drawImage(image, FloatRect(destination, image.size()), FloatRect(FloatPoint(), image.size()), imagePaintingOptions);
712 }
713
714 ImageDrawResult GraphicsContext::drawImage(Image& image, const FloatRect& destination, const ImagePaintingOptions& imagePaintingOptions)
715 {
716 #if PLATFORM(IOS)
717     FloatRect srcRect(FloatPoint(), image.originalSize());
718 #else
719     FloatRect srcRect(FloatPoint(), image.size());
720 #endif
721         
722     return drawImage(image, destination, srcRect, imagePaintingOptions);
723 }
724
725 ImageDrawResult GraphicsContext::drawImage(Image& image, const FloatRect& destination, const FloatRect& source, const ImagePaintingOptions& imagePaintingOptions)
726 {
727     if (paintingDisabled())
728         return ImageDrawResult::DidNothing;
729
730     if (m_impl) {
731         m_impl->drawImage(image, destination, source, imagePaintingOptions);
732         return ImageDrawResult::DidRecord;
733     }
734
735     InterpolationQualityMaintainer interpolationQualityForThisScope(*this, imagePaintingOptions.m_interpolationQuality);
736     return image.draw(*this, destination, source, imagePaintingOptions.m_compositeOperator, imagePaintingOptions.m_blendMode, imagePaintingOptions.m_decodingMode, imagePaintingOptions.m_orientationDescription);
737 }
738
739 ImageDrawResult GraphicsContext::drawTiledImage(Image& image, const FloatRect& destination, const FloatPoint& source, const FloatSize& tileSize, const FloatSize& spacing, const ImagePaintingOptions& imagePaintingOptions)
740 {
741     if (paintingDisabled())
742         return ImageDrawResult::DidNothing;
743
744     if (m_impl) {
745         m_impl->drawTiledImage(image, destination, source, tileSize, spacing, imagePaintingOptions);
746         return ImageDrawResult::DidRecord;
747     }
748
749     InterpolationQualityMaintainer interpolationQualityForThisScope(*this, imagePaintingOptions.m_interpolationQuality);
750     return image.drawTiled(*this, destination, source, tileSize, spacing, imagePaintingOptions.m_compositeOperator, imagePaintingOptions.m_blendMode, imagePaintingOptions.m_decodingMode);
751 }
752
753 ImageDrawResult GraphicsContext::drawTiledImage(Image& image, const FloatRect& destination, const FloatRect& source, const FloatSize& tileScaleFactor,
754     Image::TileRule hRule, Image::TileRule vRule, const ImagePaintingOptions& imagePaintingOptions)
755 {
756     if (paintingDisabled())
757         return ImageDrawResult::DidNothing;
758
759     if (m_impl) {
760         m_impl->drawTiledImage(image, destination, source, tileScaleFactor, hRule, vRule, imagePaintingOptions);
761         return ImageDrawResult::DidRecord;
762     }
763
764     if (hRule == Image::StretchTile && vRule == Image::StretchTile) {
765         // Just do a scale.
766         return drawImage(image, destination, source, imagePaintingOptions);
767     }
768
769     InterpolationQualityMaintainer interpolationQualityForThisScope(*this, imagePaintingOptions.m_interpolationQuality);
770     return image.drawTiled(*this, destination, source, tileScaleFactor, hRule, vRule, imagePaintingOptions.m_compositeOperator);
771 }
772
773 void GraphicsContext::drawImageBuffer(ImageBuffer& image, const FloatPoint& destination, const ImagePaintingOptions& imagePaintingOptions)
774 {
775     drawImageBuffer(image, FloatRect(destination, image.logicalSize()), FloatRect(FloatPoint(), image.logicalSize()), imagePaintingOptions);
776 }
777
778 void GraphicsContext::drawImageBuffer(ImageBuffer& image, const FloatRect& destination, const ImagePaintingOptions& imagePaintingOptions)
779 {
780     drawImageBuffer(image, destination, FloatRect(FloatPoint(), FloatSize(image.logicalSize())), imagePaintingOptions);
781 }
782
783 void GraphicsContext::drawImageBuffer(ImageBuffer& image, const FloatRect& destination, const FloatRect& source, const ImagePaintingOptions& imagePaintingOptions)
784 {
785     if (paintingDisabled())
786         return;
787
788     InterpolationQualityMaintainer interpolationQualityForThisScope(*this, imagePaintingOptions.m_interpolationQuality);
789     image.draw(*this, destination, source, imagePaintingOptions.m_compositeOperator, imagePaintingOptions.m_blendMode);
790 }
791
792 void GraphicsContext::drawConsumingImageBuffer(std::unique_ptr<ImageBuffer> image, const FloatPoint& destination, const ImagePaintingOptions& imagePaintingOptions)
793 {
794     if (!image)
795         return;
796     IntSize imageLogicalSize = image->logicalSize();
797     drawConsumingImageBuffer(WTFMove(image), FloatRect(destination, imageLogicalSize), FloatRect(FloatPoint(), imageLogicalSize), imagePaintingOptions);
798 }
799
800 void GraphicsContext::drawConsumingImageBuffer(std::unique_ptr<ImageBuffer> image, const FloatRect& destination, const ImagePaintingOptions& imagePaintingOptions)
801 {
802     if (!image)
803         return;
804     IntSize imageLogicalSize = image->logicalSize();
805     drawConsumingImageBuffer(WTFMove(image), destination, FloatRect(FloatPoint(), FloatSize(imageLogicalSize)), imagePaintingOptions);
806 }
807
808 void GraphicsContext::drawConsumingImageBuffer(std::unique_ptr<ImageBuffer> image, const FloatRect& destination, const FloatRect& source, const ImagePaintingOptions& imagePaintingOptions)
809 {
810     if (paintingDisabled() || !image)
811         return;
812     
813     InterpolationQualityMaintainer interpolationQualityForThisScope(*this, imagePaintingOptions.m_interpolationQuality);
814     ImageBuffer::drawConsuming(WTFMove(image), *this, destination, source, imagePaintingOptions.m_compositeOperator, imagePaintingOptions.m_blendMode);
815 }
816
817 void GraphicsContext::clipRoundedRect(const FloatRoundedRect& rect)
818 {
819     if (paintingDisabled())
820         return;
821
822     Path path;
823     path.addRoundedRect(rect);
824     clipPath(path);
825 }
826
827 void GraphicsContext::clipOutRoundedRect(const FloatRoundedRect& rect)
828 {
829     if (paintingDisabled())
830         return;
831
832     if (!rect.isRounded()) {
833         clipOut(rect.rect());
834         return;
835     }
836
837     Path path;
838     path.addRoundedRect(rect);
839     clipOut(path);
840 }
841
842 #if !USE(CG) && !USE(DIRECT2D) && !USE(CAIRO)
843 IntRect GraphicsContext::clipBounds() const
844 {
845     ASSERT_NOT_REACHED();
846     return IntRect();
847 }
848 #endif
849
850 void GraphicsContext::setTextDrawingMode(TextDrawingModeFlags mode)
851 {
852     m_state.textDrawingMode = mode;
853     if (paintingDisabled())
854         return;
855
856     if (m_impl) {
857         m_impl->updateState(m_state, GraphicsContextState::TextDrawingModeChange);
858         return;
859     }
860     setPlatformTextDrawingMode(mode);
861 }
862
863 void GraphicsContext::fillRect(const FloatRect& rect, Gradient& gradient)
864 {
865     if (paintingDisabled())
866         return;
867
868     if (m_impl) {
869         m_impl->fillRect(rect, gradient);
870         return;
871     }
872
873     gradient.fill(this, rect);
874 }
875
876 void GraphicsContext::fillRect(const FloatRect& rect, const Color& color, CompositeOperator op, BlendMode blendMode)
877 {
878     if (paintingDisabled())
879         return;
880
881     if (m_impl) {
882         m_impl->fillRect(rect, color, op, blendMode);
883         return;
884     }
885
886     CompositeOperator previousOperator = compositeOperation();
887     setCompositeOperation(op, blendMode);
888     fillRect(rect, color);
889     setCompositeOperation(previousOperator);
890 }
891
892 void GraphicsContext::fillRoundedRect(const FloatRoundedRect& rect, const Color& color, BlendMode blendMode)
893 {
894     if (paintingDisabled())
895         return;
896
897     if (m_impl) {
898         m_impl->fillRoundedRect(rect, color, blendMode);
899         return;
900     }
901
902     if (rect.isRounded()) {
903         setCompositeOperation(compositeOperation(), blendMode);
904         platformFillRoundedRect(rect, color);
905         setCompositeOperation(compositeOperation());
906     } else
907         fillRect(rect.rect(), color, compositeOperation(), blendMode);
908 }
909
910 #if !USE(CG) && !USE(DIRECT2D) && !USE(CAIRO)
911 void GraphicsContext::fillRectWithRoundedHole(const IntRect& rect, const FloatRoundedRect& roundedHoleRect, const Color& color)
912 {
913     if (paintingDisabled())
914         return;
915
916     Path path;
917     path.addRect(rect);
918
919     if (!roundedHoleRect.radii().isZero())
920         path.addRoundedRect(roundedHoleRect);
921     else
922         path.addRect(roundedHoleRect.rect());
923
924     WindRule oldFillRule = fillRule();
925     Color oldFillColor = fillColor();
926     
927     setFillRule(RULE_EVENODD);
928     setFillColor(color);
929
930     fillPath(path);
931     
932     setFillRule(oldFillRule);
933     setFillColor(oldFillColor);
934 }
935 #endif
936
937 void GraphicsContext::setAlpha(float alpha)
938 {
939     m_state.alpha = alpha;
940     if (m_impl) {
941         m_impl->updateState(m_state, GraphicsContextState::AlphaChange);
942         return;
943     }
944     setPlatformAlpha(alpha);
945 }
946
947 void GraphicsContext::setCompositeOperation(CompositeOperator compositeOperation, BlendMode blendMode)
948 {
949     m_state.compositeOperator = compositeOperation;
950     m_state.blendMode = blendMode;
951     if (m_impl) {
952         m_impl->updateState(m_state, GraphicsContextState::CompositeOperationChange);
953         return;
954     }
955     setPlatformCompositeOperation(compositeOperation, blendMode);
956 }
957
958 void GraphicsContext::setDrawLuminanceMask(bool drawLuminanceMask)
959 {
960     m_state.drawLuminanceMask = drawLuminanceMask;
961     if (m_impl)
962         m_impl->updateState(m_state, GraphicsContextState::DrawLuminanceMaskChange);
963 }
964
965 #if !USE(CG) && !USE(DIRECT2D)
966 // Implement this if you want to go push the drawing mode into your native context immediately.
967 void GraphicsContext::setPlatformTextDrawingMode(TextDrawingModeFlags)
968 {
969 }
970 #endif
971
972 #if !USE(CAIRO) && !USE(DIRECT2D)
973 void GraphicsContext::setPlatformStrokeStyle(StrokeStyle)
974 {
975 }
976 #endif
977
978 #if !USE(CG) && !USE(DIRECT2D)
979 void GraphicsContext::setPlatformShouldSmoothFonts(bool)
980 {
981 }
982 #endif
983
984 #if !USE(CG) && !USE(DIRECT2D) && !USE(CAIRO)
985 bool GraphicsContext::isAcceleratedContext() const
986 {
987     return false;
988 }
989 #endif
990
991 void GraphicsContext::adjustLineToPixelBoundaries(FloatPoint& p1, FloatPoint& p2, float strokeWidth, StrokeStyle penStyle)
992 {
993     // For odd widths, we add in 0.5 to the appropriate x/y so that the float arithmetic
994     // works out.  For example, with a border width of 3, WebKit will pass us (y1+y2)/2, e.g.,
995     // (50+53)/2 = 103/2 = 51 when we want 51.5.  It is always true that an even width gave
996     // us a perfect position, but an odd width gave us a position that is off by exactly 0.5.
997     if (penStyle == DottedStroke || penStyle == DashedStroke) {
998         if (p1.x() == p2.x()) {
999             p1.setY(p1.y() + strokeWidth);
1000             p2.setY(p2.y() - strokeWidth);
1001         } else {
1002             p1.setX(p1.x() + strokeWidth);
1003             p2.setX(p2.x() - strokeWidth);
1004         }
1005     }
1006
1007     if (static_cast<int>(strokeWidth) % 2) { //odd
1008         if (p1.x() == p2.x()) {
1009             // We're a vertical line.  Adjust our x.
1010             p1.setX(p1.x() + 0.5f);
1011             p2.setX(p2.x() + 0.5f);
1012         } else {
1013             // We're a horizontal line. Adjust our y.
1014             p1.setY(p1.y() + 0.5f);
1015             p2.setY(p2.y() + 0.5f);
1016         }
1017     }
1018 }
1019
1020 #if !USE(CG) && !USE(DIRECT2D)
1021 void GraphicsContext::platformApplyDeviceScaleFactor(float)
1022 {
1023 }
1024 #endif
1025
1026 void GraphicsContext::applyDeviceScaleFactor(float deviceScaleFactor)
1027 {
1028     scale(deviceScaleFactor);
1029
1030     if (m_impl) {
1031         m_impl->applyDeviceScaleFactor(deviceScaleFactor);
1032         return;
1033     }
1034
1035     platformApplyDeviceScaleFactor(deviceScaleFactor);
1036 }
1037     
1038 FloatSize GraphicsContext::scaleFactor() const
1039 {
1040     AffineTransform transform = getCTM(GraphicsContext::DefinitelyIncludeDeviceScale);
1041     return FloatSize(transform.xScale(), transform.yScale());
1042 }
1043     
1044 FloatSize GraphicsContext::scaleFactorForDrawing(const FloatRect& destRect, const FloatRect& srcRect) const
1045 {
1046     AffineTransform transform = getCTM(GraphicsContext::DefinitelyIncludeDeviceScale);
1047     auto transformedDestRect = transform.mapRect(destRect);
1048     return transformedDestRect.size() / srcRect.size();
1049 }
1050
1051 void GraphicsContext::fillEllipse(const FloatRect& ellipse)
1052 {
1053     if (m_impl) {
1054         m_impl->fillEllipse(ellipse);
1055         return;
1056     }
1057
1058     platformFillEllipse(ellipse);
1059 }
1060
1061 void GraphicsContext::strokeEllipse(const FloatRect& ellipse)
1062 {
1063     if (m_impl) {
1064         m_impl->strokeEllipse(ellipse);
1065         return;
1066     }
1067
1068     platformStrokeEllipse(ellipse);
1069 }
1070
1071 void GraphicsContext::fillEllipseAsPath(const FloatRect& ellipse)
1072 {
1073     Path path;
1074     path.addEllipse(ellipse);
1075     fillPath(path);
1076 }
1077
1078 void GraphicsContext::strokeEllipseAsPath(const FloatRect& ellipse)
1079 {
1080     Path path;
1081     path.addEllipse(ellipse);
1082     strokePath(path);
1083 }
1084
1085 #if !USE(CG) && !USE(DIRECT2D)
1086 void GraphicsContext::platformFillEllipse(const FloatRect& ellipse)
1087 {
1088     if (paintingDisabled())
1089         return;
1090
1091     fillEllipseAsPath(ellipse);
1092 }
1093
1094 void GraphicsContext::platformStrokeEllipse(const FloatRect& ellipse)
1095 {
1096     if (paintingDisabled())
1097         return;
1098
1099     strokeEllipseAsPath(ellipse);
1100 }
1101 #endif
1102
1103 FloatRect GraphicsContext::computeUnderlineBoundsForText(const FloatPoint& point, float width, bool printing)
1104 {
1105     Color dummyColor;
1106     return computeLineBoundsAndAntialiasingModeForText(point, width, printing, dummyColor);
1107 }
1108
1109 FloatRect GraphicsContext::computeLineBoundsAndAntialiasingModeForText(const FloatPoint& point, float width, bool printing, Color& color)
1110 {
1111     FloatPoint origin = point;
1112     float thickness = std::max(strokeThickness(), 0.5f);
1113     if (printing)
1114         return FloatRect(origin, FloatSize(width, thickness));
1115
1116     AffineTransform transform = getCTM(GraphicsContext::DefinitelyIncludeDeviceScale);
1117     // Just compute scale in x dimension, assuming x and y scales are equal.
1118     float scale = transform.b() ? sqrtf(transform.a() * transform.a() + transform.b() * transform.b()) : transform.a();
1119     if (scale < 1.0) {
1120         // This code always draws a line that is at least one-pixel line high,
1121         // which tends to visually overwhelm text at small scales. To counter this
1122         // effect, an alpha is applied to the underline color when text is at small scales.
1123         static const float minimumUnderlineAlpha = 0.4f;
1124         float shade = scale > minimumUnderlineAlpha ? scale : minimumUnderlineAlpha;
1125         color = color.colorWithAlphaMultipliedBy(shade);
1126     }
1127
1128     FloatPoint devicePoint = transform.mapPoint(point);
1129     // Visual overflow might occur here due to integral roundf/ceilf. visualOverflowForDecorations adjusts the overflow value for underline decoration.
1130     FloatPoint deviceOrigin = FloatPoint(roundf(devicePoint.x()), ceilf(devicePoint.y()));
1131     if (auto inverse = transform.inverse())
1132         origin = inverse.value().mapPoint(deviceOrigin);
1133     return FloatRect(origin, FloatSize(width, thickness));
1134 }
1135
1136 void GraphicsContext::applyState(const GraphicsContextState& state)
1137 {
1138     setPlatformShadow(state.shadowOffset, state.shadowBlur, state.shadowColor);
1139     setPlatformStrokeThickness(state.strokeThickness);
1140     setPlatformTextDrawingMode(state.textDrawingMode);
1141     setPlatformStrokeColor(state.strokeColor);
1142     setPlatformFillColor(state.fillColor);
1143     setPlatformStrokeStyle(state.strokeStyle);
1144     setPlatformAlpha(state.alpha);
1145     setPlatformCompositeOperation(state.compositeOperator, state.blendMode);
1146     setPlatformShouldAntialias(state.shouldAntialias);
1147     setPlatformShouldSmoothFonts(state.shouldSmoothFonts);
1148 }
1149
1150 float GraphicsContext::dashedLineCornerWidthForStrokeWidth(float strokeWidth) const
1151 {
1152     float thickness = strokeThickness();
1153     return strokeStyle() == DottedStroke ? thickness : std::min(2.0f * thickness, std::max(thickness, strokeWidth / 3.0f));
1154 }
1155
1156 float GraphicsContext::dashedLinePatternWidthForStrokeWidth(float strokeWidth) const
1157 {
1158     float thickness = strokeThickness();
1159     return strokeStyle() == DottedStroke ? thickness : std::min(3.0f * thickness, std::max(thickness, strokeWidth / 3.0f));
1160 }
1161
1162 float GraphicsContext::dashedLinePatternOffsetForPatternAndStrokeWidth(float patternWidth, float strokeWidth) const
1163 {
1164     // Pattern starts with full fill and ends with the empty fill.
1165     // 1. Let's start with the empty phase after the corner.
1166     // 2. Check if we've got odd or even number of patterns and whether they fully cover the line.
1167     // 3. In case of even number of patterns and/or remainder, move the pattern start position
1168     // so that the pattern is balanced between the corners.
1169     float patternOffset = patternWidth;
1170     int numberOfSegments = std::floor(strokeWidth / patternWidth);
1171     bool oddNumberOfSegments = numberOfSegments % 2;
1172     float remainder = strokeWidth - (numberOfSegments * patternWidth);
1173     if (oddNumberOfSegments && remainder)
1174         patternOffset -= remainder / 2.0f;
1175     else if (!oddNumberOfSegments) {
1176         if (remainder)
1177             patternOffset += patternOffset - (patternWidth + remainder) / 2.0f;
1178         else
1179             patternOffset += patternWidth / 2.0f;
1180     }
1181
1182     return patternOffset;
1183 }
1184
1185 Vector<FloatPoint> GraphicsContext::centerLineAndCutOffCorners(bool isVerticalLine, float cornerWidth, FloatPoint point1, FloatPoint point2) const
1186 {
1187     // Center line and cut off corners for pattern painting.
1188     if (isVerticalLine) {
1189         float centerOffset = (point2.x() - point1.x()) / 2.0f;
1190         point1.move(centerOffset, cornerWidth);
1191         point2.move(-centerOffset, -cornerWidth);
1192     } else {
1193         float centerOffset = (point2.y() - point1.y()) / 2.0f;
1194         point1.move(cornerWidth, centerOffset);
1195         point2.move(-cornerWidth, -centerOffset);
1196     }
1197
1198     return { point1, point2 };
1199 }
1200
1201 #if !USE(CG)
1202 bool GraphicsContext::supportsInternalLinks() const
1203 {
1204     return false;
1205 }
1206
1207 void GraphicsContext::setDestinationForRect(const String&, const FloatRect&)
1208 {
1209 }
1210
1211 void GraphicsContext::addDestinationAtPoint(const String&, const FloatPoint&)
1212 {
1213 }
1214 #endif
1215
1216 }