436df54c53c9dea8aff097705bdcb581782d4462
[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 "DisplayListRecorder.h"
32 #include "FloatRoundedRect.h"
33 #include "Gradient.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()
340 {
341     ASSERT(m_stack.isEmpty());
342     ASSERT(!m_transparencyCount);
343     platformDestroy();
344 }
345
346 void GraphicsContext::save()
347 {
348     if (paintingDisabled())
349         return;
350
351     m_stack.append(m_state);
352
353     if (isRecording()) {
354         m_displayListRecorder->save();
355         return;
356     }
357
358     savePlatformState();
359 }
360
361 void GraphicsContext::restore()
362 {
363     if (paintingDisabled())
364         return;
365
366     if (m_stack.isEmpty()) {
367         LOG_ERROR("ERROR void GraphicsContext::restore() stack is empty");
368         return;
369     }
370
371     m_state = m_stack.last();
372     m_stack.removeLast();
373
374     // Make sure we deallocate the state stack buffer when it goes empty.
375     // Canvas elements will immediately save() again, but that goes into inline capacity.
376     if (m_stack.isEmpty())
377         m_stack.clear();
378
379     if (isRecording()) {
380         m_displayListRecorder->restore();
381         return;
382     }
383
384     restorePlatformState();
385 }
386
387 void GraphicsContext::drawRaisedEllipse(const FloatRect& rect, const Color& ellipseColor, const Color& shadowColor)
388 {
389     if (paintingDisabled())
390         return;
391
392     save();
393
394     setStrokeColor(shadowColor);
395     setFillColor(shadowColor);
396
397     drawEllipse(FloatRect(rect.x(), rect.y() + 1, rect.width(), rect.height()));
398
399     setStrokeColor(ellipseColor);
400     setFillColor(ellipseColor);
401
402     drawEllipse(rect);  
403
404     restore();
405 }
406
407 void GraphicsContext::setStrokeThickness(float thickness)
408 {
409     m_state.strokeThickness = thickness;
410     if (isRecording()) {
411         m_displayListRecorder->updateState(m_state, GraphicsContextState::StrokeThicknessChange);
412         return;
413     }
414
415     setPlatformStrokeThickness(thickness);
416 }
417
418 void GraphicsContext::setStrokeStyle(StrokeStyle style)
419 {
420     m_state.strokeStyle = style;
421     if (isRecording()) {
422         m_displayListRecorder->updateState(m_state, GraphicsContextState::StrokeStyleChange);
423         return;
424     }
425     setPlatformStrokeStyle(style);
426 }
427
428 void GraphicsContext::setStrokeColor(const Color& color)
429 {
430     m_state.strokeColor = color;
431     m_state.strokeGradient = nullptr;
432     m_state.strokePattern = nullptr;
433     if (isRecording()) {
434         m_displayListRecorder->updateState(m_state, GraphicsContextState::StrokeColorChange);
435         return;
436     }
437     setPlatformStrokeColor(color);
438 }
439
440 void GraphicsContext::setShadow(const FloatSize& offset, float blur, const Color& color)
441 {
442     m_state.shadowOffset = offset;
443     m_state.shadowBlur = blur;
444     m_state.shadowColor = color;
445 #if USE(CG)
446     m_state.shadowsUseLegacyRadius = false;
447 #endif
448     if (isRecording()) {
449         m_displayListRecorder->updateState(m_state, GraphicsContextState::ShadowChange);
450         return;
451     }
452     setPlatformShadow(offset, blur, color);
453 }
454
455 void GraphicsContext::setLegacyShadow(const FloatSize& offset, float blur, const Color& color)
456 {
457     m_state.shadowOffset = offset;
458     m_state.shadowBlur = blur;
459     m_state.shadowColor = color;
460 #if USE(CG)
461     m_state.shadowsUseLegacyRadius = true;
462 #endif
463     if (isRecording()) {
464         m_displayListRecorder->updateState(m_state, GraphicsContextState::ShadowChange);
465         return;
466     }
467     setPlatformShadow(offset, blur, color);
468 }
469
470 void GraphicsContext::clearShadow()
471 {
472     m_state.shadowOffset = FloatSize();
473     m_state.shadowBlur = 0;
474     m_state.shadowColor = Color();
475 #if USE(CG)
476     m_state.shadowsUseLegacyRadius = false;
477 #endif
478
479     if (isRecording()) {
480         m_displayListRecorder->clearShadow();
481         return;
482     }
483     clearPlatformShadow();
484 }
485
486 bool GraphicsContext::getShadow(FloatSize& offset, float& blur, Color& color) const
487 {
488     offset = m_state.shadowOffset;
489     blur = m_state.shadowBlur;
490     color = m_state.shadowColor;
491
492     return hasShadow();
493 }
494
495 #if USE(CAIRO)
496 bool GraphicsContext::mustUseShadowBlur() const
497 {
498     // We can't avoid ShadowBlur if the shadow has blur.
499     if (hasBlurredShadow())
500         return true;
501     // We can avoid ShadowBlur and optimize, since we're not drawing on a
502     // canvas and box shadows are affected by the transformation matrix.
503     if (!m_state.shadowsIgnoreTransforms)
504         return false;
505     // We can avoid ShadowBlur, since there are no transformations to apply to the canvas.
506     if (getCTM().isIdentity())
507         return false;
508     // Otherwise, no chance avoiding ShadowBlur.
509     return true;
510 }
511 #endif
512
513 void GraphicsContext::setFillColor(const Color& color)
514 {
515     m_state.fillColor = color;
516     m_state.fillGradient = nullptr;
517     m_state.fillPattern = nullptr;
518
519     if (isRecording()) {
520         m_displayListRecorder->updateState(m_state, GraphicsContextState::FillColorChange);
521         return;
522     }
523
524     setPlatformFillColor(color);
525 }
526
527 void GraphicsContext::setShadowsIgnoreTransforms(bool shadowsIgnoreTransforms)
528 {
529     m_state.shadowsIgnoreTransforms = shadowsIgnoreTransforms;
530     if (isRecording())
531         m_displayListRecorder->updateState(m_state, GraphicsContextState::ShadowsIgnoreTransformsChange);
532 }
533
534 void GraphicsContext::setShouldAntialias(bool shouldAntialias)
535 {
536     m_state.shouldAntialias = shouldAntialias;
537
538     if (isRecording()) {
539         m_displayListRecorder->updateState(m_state, GraphicsContextState::ShouldAntialiasChange);
540         return;
541     }
542
543     setPlatformShouldAntialias(shouldAntialias);
544 }
545
546 void GraphicsContext::setShouldSmoothFonts(bool shouldSmoothFonts)
547 {
548     m_state.shouldSmoothFonts = shouldSmoothFonts;
549     
550     if (isRecording()) {
551         m_displayListRecorder->updateState(m_state, GraphicsContextState::ShouldSmoothFontsChange);
552         return;
553     }
554     
555     setPlatformShouldSmoothFonts(shouldSmoothFonts);
556 }
557
558 void GraphicsContext::setShouldSubpixelQuantizeFonts(bool shouldSubpixelQuantizeFonts)
559 {
560     m_state.shouldSubpixelQuantizeFonts = shouldSubpixelQuantizeFonts;
561     if (isRecording())
562         m_displayListRecorder->updateState(m_state, GraphicsContextState::ShouldSubpixelQuantizeFontsChange);
563 }
564
565 void GraphicsContext::setImageInterpolationQuality(InterpolationQuality imageInterpolationQuality)
566 {
567     m_state.imageInterpolationQuality = imageInterpolationQuality;
568
569     if (paintingDisabled())
570         return;
571
572     if (isRecording()) {
573         m_displayListRecorder->updateState(m_state, GraphicsContextState::ImageInterpolationQualityChange);
574         return;
575     }
576
577     setPlatformImageInterpolationQuality(imageInterpolationQuality);
578 }
579
580 void GraphicsContext::setStrokePattern(Ref<Pattern>&& pattern)
581 {
582     m_state.strokeGradient = nullptr;
583     m_state.strokePattern = WTFMove(pattern);
584     if (isRecording())
585         m_displayListRecorder->updateState(m_state, GraphicsContextState::StrokePatternChange);
586 }
587
588 void GraphicsContext::setFillPattern(Ref<Pattern>&& pattern)
589 {
590     m_state.fillGradient = nullptr;
591     m_state.fillPattern = WTFMove(pattern);
592     if (isRecording())
593         m_displayListRecorder->updateState(m_state, GraphicsContextState::FillPatternChange);
594 }
595
596 void GraphicsContext::setStrokeGradient(Ref<Gradient>&& gradient)
597 {
598     m_state.strokeGradient = WTFMove(gradient);
599     m_state.strokePattern = nullptr;
600     if (isRecording())
601         m_displayListRecorder->updateState(m_state, GraphicsContextState::StrokeGradientChange);
602 }
603
604 void GraphicsContext::setFillRule(WindRule fillRule)
605 {
606     m_state.fillRule = fillRule;
607     if (isRecording())
608         m_displayListRecorder->updateState(m_state, GraphicsContextState::FillRuleChange);
609 }
610
611 void GraphicsContext::setFillGradient(Ref<Gradient>&& gradient)
612 {
613     m_state.fillGradient = WTFMove(gradient);
614     m_state.fillPattern = nullptr;
615     if (isRecording())
616         m_displayListRecorder->updateState(m_state, GraphicsContextState::FillGradientChange); // FIXME: also fill pattern?
617 }
618
619 void GraphicsContext::beginTransparencyLayer(float opacity)
620 {
621     if (isRecording()) {
622         m_displayListRecorder->beginTransparencyLayer(opacity);
623         return;
624     }
625     beginPlatformTransparencyLayer(opacity);
626     ++m_transparencyCount;
627 }
628
629 void GraphicsContext::endTransparencyLayer()
630 {
631     if (isRecording()) {
632         m_displayListRecorder->endTransparencyLayer();
633         return;
634     }
635     endPlatformTransparencyLayer();
636     ASSERT(m_transparencyCount > 0);
637     --m_transparencyCount;
638 }
639
640 float GraphicsContext::drawText(const FontCascade& font, const TextRun& run, const FloatPoint& point, unsigned from, std::optional<unsigned> to)
641 {
642     if (paintingDisabled())
643         return 0;
644
645     // Display list recording for text content is done at glyphs level. See GraphicsContext::drawGlyphs.
646     return font.drawText(*this, run, point, from, to);
647 }
648
649 void GraphicsContext::drawGlyphs(const FontCascade& fontCascade, const Font& font, const GlyphBuffer& buffer, unsigned from, unsigned numGlyphs, const FloatPoint& point)
650 {
651     if (paintingDisabled())
652         return;
653
654     if (isRecording()) {
655         m_displayListRecorder->drawGlyphs(font, buffer, from, numGlyphs, point, fontCascade.fontDescription().fontSmoothing());
656         return;
657     }
658
659     fontCascade.drawGlyphs(*this, font, buffer, from, numGlyphs, point, fontCascade.fontDescription().fontSmoothing());
660 }
661
662 void GraphicsContext::drawEmphasisMarks(const FontCascade& font, const TextRun& run, const AtomicString& mark, const FloatPoint& point, unsigned from, std::optional<unsigned> to)
663 {
664     if (paintingDisabled())
665         return;
666
667     font.drawEmphasisMarks(*this, run, mark, point, from, to);
668 }
669
670 void GraphicsContext::drawBidiText(const FontCascade& font, const TextRun& run, const FloatPoint& point, FontCascade::CustomFontNotReadyAction customFontNotReadyAction)
671 {
672     if (paintingDisabled())
673         return;
674
675     BidiResolver<TextRunIterator, BidiCharacterRun> bidiResolver;
676     bidiResolver.setStatus(BidiStatus(run.direction(), run.directionalOverride()));
677     bidiResolver.setPositionIgnoringNestedIsolates(TextRunIterator(&run, 0));
678
679     // FIXME: This ownership should be reversed. We should pass BidiRunList
680     // to BidiResolver in createBidiRunsForLine.
681     BidiRunList<BidiCharacterRun>& bidiRuns = bidiResolver.runs();
682     bidiResolver.createBidiRunsForLine(TextRunIterator(&run, run.length()));
683
684     if (!bidiRuns.runCount())
685         return;
686
687     FloatPoint currPoint = point;
688     BidiCharacterRun* bidiRun = bidiRuns.firstRun();
689     while (bidiRun) {
690         TextRun subrun = run.subRun(bidiRun->start(), bidiRun->stop() - bidiRun->start());
691         bool isRTL = bidiRun->level() % 2;
692         subrun.setDirection(isRTL ? RTL : LTR);
693         subrun.setDirectionalOverride(bidiRun->dirOverride(false));
694
695         float width = font.drawText(*this, subrun, currPoint, 0, std::nullopt, customFontNotReadyAction);
696         currPoint.move(width, 0);
697
698         bidiRun = bidiRun->next();
699     }
700
701     bidiRuns.clear();
702 }
703
704 ImageDrawResult GraphicsContext::drawImage(Image& image, const FloatPoint& destination, const ImagePaintingOptions& imagePaintingOptions)
705 {
706     return drawImage(image, FloatRect(destination, image.size()), FloatRect(FloatPoint(), image.size()), imagePaintingOptions);
707 }
708
709 ImageDrawResult GraphicsContext::drawImage(Image& image, const FloatRect& destination, const ImagePaintingOptions& imagePaintingOptions)
710 {
711 #if PLATFORM(IOS)
712     FloatRect srcRect(FloatPoint(), image.originalSize());
713 #else
714     FloatRect srcRect(FloatPoint(), image.size());
715 #endif
716         
717     return drawImage(image, destination, srcRect, imagePaintingOptions);
718 }
719
720 ImageDrawResult GraphicsContext::drawImage(Image& image, const FloatRect& destination, const FloatRect& source, const ImagePaintingOptions& imagePaintingOptions)
721 {
722     if (paintingDisabled())
723         return ImageDrawResult::DidNothing;
724
725     if (isRecording()) {
726         m_displayListRecorder->drawImage(image, destination, source, imagePaintingOptions);
727         return ImageDrawResult::DidRecord;
728     }
729
730     InterpolationQualityMaintainer interpolationQualityForThisScope(*this, imagePaintingOptions.m_interpolationQuality);
731     return image.draw(*this, destination, source, imagePaintingOptions.m_compositeOperator, imagePaintingOptions.m_blendMode, imagePaintingOptions.m_decodingMode, imagePaintingOptions.m_orientationDescription);
732 }
733
734 ImageDrawResult GraphicsContext::drawTiledImage(Image& image, const FloatRect& destination, const FloatPoint& source, const FloatSize& tileSize, const FloatSize& spacing, const ImagePaintingOptions& imagePaintingOptions)
735 {
736     if (paintingDisabled())
737         return ImageDrawResult::DidNothing;
738
739     if (isRecording()) {
740         m_displayListRecorder->drawTiledImage(image, destination, source, tileSize, spacing, imagePaintingOptions);
741         return ImageDrawResult::DidRecord;
742     }
743
744     InterpolationQualityMaintainer interpolationQualityForThisScope(*this, imagePaintingOptions.m_interpolationQuality);
745     return image.drawTiled(*this, destination, source, tileSize, spacing, imagePaintingOptions.m_compositeOperator, imagePaintingOptions.m_blendMode, imagePaintingOptions.m_decodingMode);
746 }
747
748 ImageDrawResult GraphicsContext::drawTiledImage(Image& image, const FloatRect& destination, const FloatRect& source, const FloatSize& tileScaleFactor,
749     Image::TileRule hRule, Image::TileRule vRule, const ImagePaintingOptions& imagePaintingOptions)
750 {
751     if (paintingDisabled())
752         return ImageDrawResult::DidNothing;
753
754     if (isRecording()) {
755         m_displayListRecorder->drawTiledImage(image, destination, source, tileScaleFactor, hRule, vRule, imagePaintingOptions);
756         return ImageDrawResult::DidRecord;
757     }
758
759     if (hRule == Image::StretchTile && vRule == Image::StretchTile) {
760         // Just do a scale.
761         return drawImage(image, destination, source, imagePaintingOptions);
762     }
763
764     InterpolationQualityMaintainer interpolationQualityForThisScope(*this, imagePaintingOptions.m_interpolationQuality);
765     return image.drawTiled(*this, destination, source, tileScaleFactor, hRule, vRule, imagePaintingOptions.m_compositeOperator);
766 }
767
768 void GraphicsContext::drawImageBuffer(ImageBuffer& image, const FloatPoint& destination, const ImagePaintingOptions& imagePaintingOptions)
769 {
770     drawImageBuffer(image, FloatRect(destination, image.logicalSize()), FloatRect(FloatPoint(), image.logicalSize()), imagePaintingOptions);
771 }
772
773 void GraphicsContext::drawImageBuffer(ImageBuffer& image, const FloatRect& destination, const ImagePaintingOptions& imagePaintingOptions)
774 {
775     drawImageBuffer(image, destination, FloatRect(FloatPoint(), FloatSize(image.logicalSize())), imagePaintingOptions);
776 }
777
778 void GraphicsContext::drawImageBuffer(ImageBuffer& image, const FloatRect& destination, const FloatRect& source, const ImagePaintingOptions& imagePaintingOptions)
779 {
780     if (paintingDisabled())
781         return;
782
783     InterpolationQualityMaintainer interpolationQualityForThisScope(*this, imagePaintingOptions.m_interpolationQuality);
784     image.draw(*this, destination, source, imagePaintingOptions.m_compositeOperator, imagePaintingOptions.m_blendMode);
785 }
786
787 void GraphicsContext::drawConsumingImageBuffer(std::unique_ptr<ImageBuffer> image, const FloatPoint& destination, const ImagePaintingOptions& imagePaintingOptions)
788 {
789     if (!image)
790         return;
791     IntSize imageLogicalSize = image->logicalSize();
792     drawConsumingImageBuffer(WTFMove(image), FloatRect(destination, imageLogicalSize), FloatRect(FloatPoint(), imageLogicalSize), imagePaintingOptions);
793 }
794
795 void GraphicsContext::drawConsumingImageBuffer(std::unique_ptr<ImageBuffer> image, const FloatRect& destination, const ImagePaintingOptions& imagePaintingOptions)
796 {
797     if (!image)
798         return;
799     IntSize imageLogicalSize = image->logicalSize();
800     drawConsumingImageBuffer(WTFMove(image), destination, FloatRect(FloatPoint(), FloatSize(imageLogicalSize)), imagePaintingOptions);
801 }
802
803 void GraphicsContext::drawConsumingImageBuffer(std::unique_ptr<ImageBuffer> image, const FloatRect& destination, const FloatRect& source, const ImagePaintingOptions& imagePaintingOptions)
804 {
805     if (paintingDisabled() || !image)
806         return;
807     
808     InterpolationQualityMaintainer interpolationQualityForThisScope(*this, imagePaintingOptions.m_interpolationQuality);
809     ImageBuffer::drawConsuming(WTFMove(image), *this, destination, source, imagePaintingOptions.m_compositeOperator, imagePaintingOptions.m_blendMode);
810 }
811
812 void GraphicsContext::clipRoundedRect(const FloatRoundedRect& rect)
813 {
814     if (paintingDisabled())
815         return;
816
817     Path path;
818     path.addRoundedRect(rect);
819     clipPath(path);
820 }
821
822 void GraphicsContext::clipOutRoundedRect(const FloatRoundedRect& rect)
823 {
824     if (paintingDisabled())
825         return;
826
827     if (!rect.isRounded()) {
828         clipOut(rect.rect());
829         return;
830     }
831
832     Path path;
833     path.addRoundedRect(rect);
834     clipOut(path);
835 }
836
837 #if !USE(CG) && !USE(DIRECT2D) && !USE(CAIRO)
838 IntRect GraphicsContext::clipBounds() const
839 {
840     ASSERT_NOT_REACHED();
841     return IntRect();
842 }
843 #endif
844
845 void GraphicsContext::setTextDrawingMode(TextDrawingModeFlags mode)
846 {
847     m_state.textDrawingMode = mode;
848     if (paintingDisabled())
849         return;
850
851     if (isRecording()) {
852         m_displayListRecorder->updateState(m_state, GraphicsContextState::TextDrawingModeChange);
853         return;
854     }
855     setPlatformTextDrawingMode(mode);
856 }
857
858 void GraphicsContext::fillRect(const FloatRect& rect, Gradient& gradient)
859 {
860     if (paintingDisabled())
861         return;
862
863     if (isRecording()) {
864         m_displayListRecorder->fillRect(rect, gradient);
865         return;
866     }
867
868     gradient.fill(this, rect);
869 }
870
871 void GraphicsContext::fillRect(const FloatRect& rect, const Color& color, CompositeOperator op, BlendMode blendMode)
872 {
873     if (paintingDisabled())
874         return;
875
876     if (isRecording()) {
877         m_displayListRecorder->fillRect(rect, color, op, blendMode);
878         return;
879     }
880
881     CompositeOperator previousOperator = compositeOperation();
882     setCompositeOperation(op, blendMode);
883     fillRect(rect, color);
884     setCompositeOperation(previousOperator);
885 }
886
887 void GraphicsContext::fillRoundedRect(const FloatRoundedRect& rect, const Color& color, BlendMode blendMode)
888 {
889     if (paintingDisabled())
890         return;
891
892     if (isRecording()) {
893         m_displayListRecorder->fillRoundedRect(rect, color, blendMode);
894         return;
895     }
896
897     if (rect.isRounded()) {
898         setCompositeOperation(compositeOperation(), blendMode);
899         platformFillRoundedRect(rect, color);
900         setCompositeOperation(compositeOperation());
901     } else
902         fillRect(rect.rect(), color, compositeOperation(), blendMode);
903 }
904
905 #if !USE(CG) && !USE(DIRECT2D) && !USE(CAIRO)
906 void GraphicsContext::fillRectWithRoundedHole(const IntRect& rect, const FloatRoundedRect& roundedHoleRect, const Color& color)
907 {
908     if (paintingDisabled())
909         return;
910
911     Path path;
912     path.addRect(rect);
913
914     if (!roundedHoleRect.radii().isZero())
915         path.addRoundedRect(roundedHoleRect);
916     else
917         path.addRect(roundedHoleRect.rect());
918
919     WindRule oldFillRule = fillRule();
920     Color oldFillColor = fillColor();
921     
922     setFillRule(RULE_EVENODD);
923     setFillColor(color);
924
925     fillPath(path);
926     
927     setFillRule(oldFillRule);
928     setFillColor(oldFillColor);
929 }
930 #endif
931
932 void GraphicsContext::setAlpha(float alpha)
933 {
934     m_state.alpha = alpha;
935     if (isRecording()) {
936         m_displayListRecorder->updateState(m_state, GraphicsContextState::AlphaChange);
937         return;
938     }
939     setPlatformAlpha(alpha);
940 }
941
942 void GraphicsContext::setCompositeOperation(CompositeOperator compositeOperation, BlendMode blendMode)
943 {
944     m_state.compositeOperator = compositeOperation;
945     m_state.blendMode = blendMode;
946     if (isRecording()) {
947         m_displayListRecorder->updateState(m_state, GraphicsContextState::CompositeOperationChange);
948         return;
949     }
950     setPlatformCompositeOperation(compositeOperation, blendMode);
951 }
952
953 void GraphicsContext::setDrawLuminanceMask(bool drawLuminanceMask)
954 {
955     m_state.drawLuminanceMask = drawLuminanceMask;
956     if (isRecording())
957         m_displayListRecorder->updateState(m_state, GraphicsContextState::DrawLuminanceMaskChange);
958 }
959
960 #if !USE(CG) && !USE(DIRECT2D)
961 // Implement this if you want to go push the drawing mode into your native context immediately.
962 void GraphicsContext::setPlatformTextDrawingMode(TextDrawingModeFlags)
963 {
964 }
965 #endif
966
967 #if !USE(CAIRO) && !USE(DIRECT2D)
968 void GraphicsContext::setPlatformStrokeStyle(StrokeStyle)
969 {
970 }
971 #endif
972
973 #if !USE(CG) && !USE(DIRECT2D)
974 void GraphicsContext::setPlatformShouldSmoothFonts(bool)
975 {
976 }
977 #endif
978
979 #if !USE(CG) && !USE(DIRECT2D) && !USE(CAIRO)
980 bool GraphicsContext::isAcceleratedContext() const
981 {
982     return false;
983 }
984 #endif
985
986 void GraphicsContext::adjustLineToPixelBoundaries(FloatPoint& p1, FloatPoint& p2, float strokeWidth, StrokeStyle penStyle)
987 {
988     // For odd widths, we add in 0.5 to the appropriate x/y so that the float arithmetic
989     // works out.  For example, with a border width of 3, WebKit will pass us (y1+y2)/2, e.g.,
990     // (50+53)/2 = 103/2 = 51 when we want 51.5.  It is always true that an even width gave
991     // us a perfect position, but an odd width gave us a position that is off by exactly 0.5.
992     if (penStyle == DottedStroke || penStyle == DashedStroke) {
993         if (p1.x() == p2.x()) {
994             p1.setY(p1.y() + strokeWidth);
995             p2.setY(p2.y() - strokeWidth);
996         } else {
997             p1.setX(p1.x() + strokeWidth);
998             p2.setX(p2.x() - strokeWidth);
999         }
1000     }
1001
1002     if (static_cast<int>(strokeWidth) % 2) { //odd
1003         if (p1.x() == p2.x()) {
1004             // We're a vertical line.  Adjust our x.
1005             p1.setX(p1.x() + 0.5f);
1006             p2.setX(p2.x() + 0.5f);
1007         } else {
1008             // We're a horizontal line. Adjust our y.
1009             p1.setY(p1.y() + 0.5f);
1010             p2.setY(p2.y() + 0.5f);
1011         }
1012     }
1013 }
1014
1015 #if !USE(CG) && !USE(DIRECT2D)
1016 void GraphicsContext::platformApplyDeviceScaleFactor(float)
1017 {
1018 }
1019 #endif
1020
1021 void GraphicsContext::applyDeviceScaleFactor(float deviceScaleFactor)
1022 {
1023     scale(deviceScaleFactor);
1024
1025     if (isRecording()) {
1026         m_displayListRecorder->applyDeviceScaleFactor(deviceScaleFactor);
1027         return;
1028     }
1029
1030     platformApplyDeviceScaleFactor(deviceScaleFactor);
1031 }
1032     
1033 FloatSize GraphicsContext::scaleFactor() const
1034 {
1035     AffineTransform transform = getCTM(GraphicsContext::DefinitelyIncludeDeviceScale);
1036     return FloatSize(transform.xScale(), transform.yScale());
1037 }
1038     
1039 FloatSize GraphicsContext::scaleFactorForDrawing(const FloatRect& destRect, const FloatRect& srcRect) const
1040 {
1041     AffineTransform transform = getCTM(GraphicsContext::DefinitelyIncludeDeviceScale);
1042     auto transformedDestRect = transform.mapRect(destRect);
1043     return transformedDestRect.size() / srcRect.size();
1044 }
1045
1046 void GraphicsContext::fillEllipse(const FloatRect& ellipse)
1047 {
1048     if (isRecording()) {
1049         m_displayListRecorder->fillEllipse(ellipse);
1050         return;
1051     }
1052
1053     platformFillEllipse(ellipse);
1054 }
1055
1056 void GraphicsContext::strokeEllipse(const FloatRect& ellipse)
1057 {
1058     if (isRecording()) {
1059         m_displayListRecorder->strokeEllipse(ellipse);
1060         return;
1061     }
1062
1063     platformStrokeEllipse(ellipse);
1064 }
1065
1066 void GraphicsContext::fillEllipseAsPath(const FloatRect& ellipse)
1067 {
1068     Path path;
1069     path.addEllipse(ellipse);
1070     fillPath(path);
1071 }
1072
1073 void GraphicsContext::strokeEllipseAsPath(const FloatRect& ellipse)
1074 {
1075     Path path;
1076     path.addEllipse(ellipse);
1077     strokePath(path);
1078 }
1079
1080 #if !USE(CG) && !USE(DIRECT2D)
1081 void GraphicsContext::platformFillEllipse(const FloatRect& ellipse)
1082 {
1083     if (paintingDisabled())
1084         return;
1085
1086     fillEllipseAsPath(ellipse);
1087 }
1088
1089 void GraphicsContext::platformStrokeEllipse(const FloatRect& ellipse)
1090 {
1091     if (paintingDisabled())
1092         return;
1093
1094     strokeEllipseAsPath(ellipse);
1095 }
1096 #endif
1097
1098 FloatRect GraphicsContext::computeUnderlineBoundsForText(const FloatPoint& point, float width, bool printing)
1099 {
1100     Color dummyColor;
1101     return computeLineBoundsAndAntialiasingModeForText(point, width, printing, dummyColor);
1102 }
1103
1104 FloatRect GraphicsContext::computeLineBoundsAndAntialiasingModeForText(const FloatPoint& point, float width, bool printing, Color& color)
1105 {
1106     FloatPoint origin = point;
1107     float thickness = std::max(strokeThickness(), 0.5f);
1108     if (printing)
1109         return FloatRect(origin, FloatSize(width, thickness));
1110
1111     AffineTransform transform = getCTM(GraphicsContext::DefinitelyIncludeDeviceScale);
1112     // Just compute scale in x dimension, assuming x and y scales are equal.
1113     float scale = transform.b() ? sqrtf(transform.a() * transform.a() + transform.b() * transform.b()) : transform.a();
1114     if (scale < 1.0) {
1115         // This code always draws a line that is at least one-pixel line high,
1116         // which tends to visually overwhelm text at small scales. To counter this
1117         // effect, an alpha is applied to the underline color when text is at small scales.
1118         static const float minimumUnderlineAlpha = 0.4f;
1119         float shade = scale > minimumUnderlineAlpha ? scale : minimumUnderlineAlpha;
1120         color = color.colorWithAlphaMultipliedBy(shade);
1121     }
1122
1123     FloatPoint devicePoint = transform.mapPoint(point);
1124     // Visual overflow might occur here due to integral roundf/ceilf. visualOverflowForDecorations adjusts the overflow value for underline decoration.
1125     FloatPoint deviceOrigin = FloatPoint(roundf(devicePoint.x()), ceilf(devicePoint.y()));
1126     if (auto inverse = transform.inverse())
1127         origin = inverse.value().mapPoint(deviceOrigin);
1128     return FloatRect(origin, FloatSize(width, thickness));
1129 }
1130
1131 void GraphicsContext::applyState(const GraphicsContextState& state)
1132 {
1133     setPlatformShadow(state.shadowOffset, state.shadowBlur, state.shadowColor);
1134     setPlatformStrokeThickness(state.strokeThickness);
1135     setPlatformTextDrawingMode(state.textDrawingMode);
1136     setPlatformStrokeColor(state.strokeColor);
1137     setPlatformFillColor(state.fillColor);
1138     setPlatformStrokeStyle(state.strokeStyle);
1139     setPlatformAlpha(state.alpha);
1140     setPlatformCompositeOperation(state.compositeOperator, state.blendMode);
1141     setPlatformShouldAntialias(state.shouldAntialias);
1142     setPlatformShouldSmoothFonts(state.shouldSmoothFonts);
1143 }
1144
1145 float GraphicsContext::dashedLineCornerWidthForStrokeWidth(float strokeWidth) const
1146 {
1147     float thickness = strokeThickness();
1148     return strokeStyle() == DottedStroke ? thickness : std::min(2.0f * thickness, std::max(thickness, strokeWidth / 3.0f));
1149 }
1150
1151 float GraphicsContext::dashedLinePatternWidthForStrokeWidth(float strokeWidth) const
1152 {
1153     float thickness = strokeThickness();
1154     return strokeStyle() == DottedStroke ? thickness : std::min(3.0f * thickness, std::max(thickness, strokeWidth / 3.0f));
1155 }
1156
1157 float GraphicsContext::dashedLinePatternOffsetForPatternAndStrokeWidth(float patternWidth, float strokeWidth) const
1158 {
1159     // Pattern starts with full fill and ends with the empty fill.
1160     // 1. Let's start with the empty phase after the corner.
1161     // 2. Check if we've got odd or even number of patterns and whether they fully cover the line.
1162     // 3. In case of even number of patterns and/or remainder, move the pattern start position
1163     // so that the pattern is balanced between the corners.
1164     float patternOffset = patternWidth;
1165     int numberOfSegments = std::floor(strokeWidth / patternWidth);
1166     bool oddNumberOfSegments = numberOfSegments % 2;
1167     float remainder = strokeWidth - (numberOfSegments * patternWidth);
1168     if (oddNumberOfSegments && remainder)
1169         patternOffset -= remainder / 2.0f;
1170     else if (!oddNumberOfSegments) {
1171         if (remainder)
1172             patternOffset += patternOffset - (patternWidth + remainder) / 2.0f;
1173         else
1174             patternOffset += patternWidth / 2.0f;
1175     }
1176
1177     return patternOffset;
1178 }
1179
1180 Vector<FloatPoint> GraphicsContext::centerLineAndCutOffCorners(bool isVerticalLine, float cornerWidth, FloatPoint point1, FloatPoint point2) const
1181 {
1182     // Center line and cut off corners for pattern painting.
1183     if (isVerticalLine) {
1184         float centerOffset = (point2.x() - point1.x()) / 2.0f;
1185         point1.move(centerOffset, cornerWidth);
1186         point2.move(-centerOffset, -cornerWidth);
1187     } else {
1188         float centerOffset = (point2.y() - point1.y()) / 2.0f;
1189         point1.move(cornerWidth, centerOffset);
1190         point2.move(-cornerWidth, -centerOffset);
1191     }
1192
1193     return { point1, point2 };
1194 }
1195
1196 #if !USE(CG)
1197 bool GraphicsContext::supportsInternalLinks() const
1198 {
1199     return false;
1200 }
1201
1202 void GraphicsContext::setDestinationForRect(const String&, const FloatRect&)
1203 {
1204 }
1205
1206 void GraphicsContext::addDestinationAtPoint(const String&, const FloatPoint&)
1207 {
1208 }
1209 #endif
1210
1211 }