summaryrefslogtreecommitdiff
path: root/Source/WebCore/html/canvas/CanvasRenderingContext2D.cpp
diff options
context:
space:
mode:
authorLorry Tar Creator <lorry-tar-importer@lorry>2016-04-10 09:28:39 +0000
committerLorry Tar Creator <lorry-tar-importer@lorry>2016-04-10 09:28:39 +0000
commit32761a6cee1d0dee366b885b7b9c777e67885688 (patch)
treed6bec92bebfb216f4126356e55518842c2f476a1 /Source/WebCore/html/canvas/CanvasRenderingContext2D.cpp
parenta4e969f4965059196ca948db781e52f7cfebf19e (diff)
downloadWebKitGtk-tarball-32761a6cee1d0dee366b885b7b9c777e67885688.tar.gz
webkitgtk-2.4.11webkitgtk-2.4.11
Diffstat (limited to 'Source/WebCore/html/canvas/CanvasRenderingContext2D.cpp')
-rwxr-xr-x[-rw-r--r--]Source/WebCore/html/canvas/CanvasRenderingContext2D.cpp1380
1 files changed, 515 insertions, 865 deletions
diff --git a/Source/WebCore/html/canvas/CanvasRenderingContext2D.cpp b/Source/WebCore/html/canvas/CanvasRenderingContext2D.cpp
index 85fea4dc9..dc55df0e3 100644..100755
--- a/Source/WebCore/html/canvas/CanvasRenderingContext2D.cpp
+++ b/Source/WebCore/html/canvas/CanvasRenderingContext2D.cpp
@@ -6,7 +6,7 @@
* Copyright (C) 2008 Dirk Schulze <krit@webkit.org>
* Copyright (C) 2010 Torch Mobile (Beijing) Co. Ltd. All rights reserved.
* Copyright (C) 2012 Intel Corporation. All rights reserved.
- * Copyright (C) 2013, 2014 Adobe Systems Incorporated. All rights reserved.
+ * Copyright (C) 2013 Adobe Systems Incorporated. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
@@ -17,10 +17,10 @@
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
- * THIS SOFTWARE IS PROVIDED BY APPLE INC. ``AS IS'' AND ANY
+ * THIS SOFTWARE IS PROVIDED BY APPLE COMPUTER, INC. ``AS IS'' AND ANY
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
- * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR
+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE COMPUTER, INC. OR
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
@@ -40,28 +40,27 @@
#include "CanvasGradient.h"
#include "CanvasPattern.h"
#include "DOMPath.h"
-#include "DisplayListRecorder.h"
-#include "DisplayListReplayer.h"
#include "ExceptionCodePlaceholder.h"
#include "FloatQuad.h"
+#include "FontCache.h"
+#include "GraphicsContext.h"
#include "HTMLImageElement.h"
#include "HTMLVideoElement.h"
#include "ImageData.h"
#include "RenderElement.h"
-#include "RenderImage.h"
-#include "RenderLayer.h"
-#include "RenderTheme.h"
#include "SecurityOrigin.h"
#include "StrokeStyleApplier.h"
#include "StyleProperties.h"
#include "StyleResolver.h"
#include "TextMetrics.h"
#include "TextRun.h"
-#include "TextStream.h"
+
+#if USE(ACCELERATED_COMPOSITING)
+#include "RenderLayer.h"
+#endif
#include <wtf/CheckedArithmetic.h>
#include <wtf/MathExtras.h>
-#include <wtf/NeverDestroyed.h>
#include <wtf/text/StringBuilder.h>
#if USE(CG)
@@ -74,12 +73,6 @@
#include "Settings.h"
#endif
-#if USE(CG)
-#define DefaultSmoothingQuality SmoothingQuality::Low
-#else
-#define DefaultSmoothingQuality SmoothingQuality::Medium
-#endif
-
namespace WebCore {
using namespace HTMLNames;
@@ -88,25 +81,6 @@ static const int defaultFontSize = 10;
static const char* const defaultFontFamily = "sans-serif";
static const char* const defaultFont = "10px sans-serif";
-struct DisplayListDrawingContext {
- GraphicsContext context;
- DisplayList::Recorder recorder;
- DisplayList::DisplayList displayList;
-
- DisplayListDrawingContext(const FloatRect& clip)
- : recorder(context, displayList, clip, AffineTransform())
- {
- }
-};
-
-typedef HashMap<const CanvasRenderingContext2D*, std::unique_ptr<DisplayList::DisplayList>> ContextDisplayListHashMap;
-
-static ContextDisplayListHashMap& contextDisplayListMap()
-{
- static NeverDestroyed<ContextDisplayListHashMap> sharedHashMap;
- return sharedHashMap;
-}
-
class CanvasStrokeStyleApplier : public StrokeStyleApplier {
public:
CanvasStrokeStyleApplier(CanvasRenderingContext2D* canvasContext)
@@ -134,6 +108,7 @@ private:
CanvasRenderingContext2D::CanvasRenderingContext2D(HTMLCanvasElement* canvas, bool usesCSSCompatibilityParseMode, bool usesDashboardCompatibilityMode)
: CanvasRenderingContext(canvas)
, m_stateStack(1)
+ , m_unrealizedSaveCount(0)
, m_usesCSSCompatibilityParseMode(usesCSSCompatibilityParseMode)
#if ENABLE(DASHBOARD_SUPPORT)
, m_usesDashboardCompatibilityMode(usesDashboardCompatibilityMode)
@@ -162,9 +137,6 @@ CanvasRenderingContext2D::~CanvasRenderingContext2D()
#if !ASSERT_DISABLED
unwindStateStack();
#endif
-
- if (UNLIKELY(tracksDisplayListReplay()))
- contextDisplayListMap().remove(this);
}
bool CanvasRenderingContext2D::isAccelerated() const
@@ -186,59 +158,58 @@ void CanvasRenderingContext2D::reset()
m_stateStack.first() = State();
m_path.clear();
m_unrealizedSaveCount = 0;
-
- m_recordingContext = nullptr;
}
CanvasRenderingContext2D::State::State()
- : strokeStyle(Color::black)
- , fillStyle(Color::black)
- , lineWidth(1)
- , lineCap(ButtCap)
- , lineJoin(MiterJoin)
- , miterLimit(10)
- , shadowBlur(0)
- , shadowColor(Color::transparent)
- , globalAlpha(1)
- , globalComposite(CompositeSourceOver)
- , globalBlend(BlendModeNormal)
- , hasInvertibleTransform(true)
- , lineDashOffset(0)
- , imageSmoothingEnabled(true)
- , imageSmoothingQuality(DefaultSmoothingQuality)
- , textAlign(StartTextAlign)
- , textBaseline(AlphabeticTextBaseline)
- , direction(Direction::Inherit)
- , unparsedFont(defaultFont)
+ : m_strokeStyle(Color::black)
+ , m_fillStyle(Color::black)
+ , m_lineWidth(1)
+ , m_lineCap(ButtCap)
+ , m_lineJoin(MiterJoin)
+ , m_miterLimit(10)
+ , m_shadowBlur(0)
+ , m_shadowColor(Color::transparent)
+ , m_globalAlpha(1)
+ , m_globalComposite(CompositeSourceOver)
+ , m_globalBlend(BlendModeNormal)
+ , m_hasInvertibleTransform(true)
+ , m_lineDashOffset(0)
+ , m_imageSmoothingEnabled(true)
+ , m_textAlign(StartTextAlign)
+ , m_textBaseline(AlphabeticTextBaseline)
+ , m_unparsedFont(defaultFont)
+ , m_realizedFont(false)
{
}
CanvasRenderingContext2D::State::State(const State& other)
- : unparsedStrokeColor(other.unparsedStrokeColor)
- , unparsedFillColor(other.unparsedFillColor)
- , strokeStyle(other.strokeStyle)
- , fillStyle(other.fillStyle)
- , lineWidth(other.lineWidth)
- , lineCap(other.lineCap)
- , lineJoin(other.lineJoin)
- , miterLimit(other.miterLimit)
- , shadowOffset(other.shadowOffset)
- , shadowBlur(other.shadowBlur)
- , shadowColor(other.shadowColor)
- , globalAlpha(other.globalAlpha)
- , globalComposite(other.globalComposite)
- , globalBlend(other.globalBlend)
- , transform(other.transform)
- , hasInvertibleTransform(other.hasInvertibleTransform)
- , lineDashOffset(other.lineDashOffset)
- , imageSmoothingEnabled(other.imageSmoothingEnabled)
- , imageSmoothingQuality(other.imageSmoothingQuality)
- , textAlign(other.textAlign)
- , textBaseline(other.textBaseline)
- , direction(other.direction)
- , unparsedFont(other.unparsedFont)
- , font(other.font)
-{
+ : FontSelectorClient()
+ , m_unparsedStrokeColor(other.m_unparsedStrokeColor)
+ , m_unparsedFillColor(other.m_unparsedFillColor)
+ , m_strokeStyle(other.m_strokeStyle)
+ , m_fillStyle(other.m_fillStyle)
+ , m_lineWidth(other.m_lineWidth)
+ , m_lineCap(other.m_lineCap)
+ , m_lineJoin(other.m_lineJoin)
+ , m_miterLimit(other.m_miterLimit)
+ , m_shadowOffset(other.m_shadowOffset)
+ , m_shadowBlur(other.m_shadowBlur)
+ , m_shadowColor(other.m_shadowColor)
+ , m_globalAlpha(other.m_globalAlpha)
+ , m_globalComposite(other.m_globalComposite)
+ , m_globalBlend(other.m_globalBlend)
+ , m_transform(other.m_transform)
+ , m_hasInvertibleTransform(other.m_hasInvertibleTransform)
+ , m_lineDashOffset(other.m_lineDashOffset)
+ , m_imageSmoothingEnabled(other.m_imageSmoothingEnabled)
+ , m_textAlign(other.m_textAlign)
+ , m_textBaseline(other.m_textBaseline)
+ , m_unparsedFont(other.m_unparsedFont)
+ , m_font(other.m_font)
+ , m_realizedFont(other.m_realizedFont)
+{
+ if (m_realizedFont)
+ m_font.fontSelector()->registerForInvalidationCallbacks(this);
}
CanvasRenderingContext2D::State& CanvasRenderingContext2D::State::operator=(const State& other)
@@ -246,108 +217,50 @@ CanvasRenderingContext2D::State& CanvasRenderingContext2D::State::operator=(cons
if (this == &other)
return *this;
- unparsedStrokeColor = other.unparsedStrokeColor;
- unparsedFillColor = other.unparsedFillColor;
- strokeStyle = other.strokeStyle;
- fillStyle = other.fillStyle;
- lineWidth = other.lineWidth;
- lineCap = other.lineCap;
- lineJoin = other.lineJoin;
- miterLimit = other.miterLimit;
- shadowOffset = other.shadowOffset;
- shadowBlur = other.shadowBlur;
- shadowColor = other.shadowColor;
- globalAlpha = other.globalAlpha;
- globalComposite = other.globalComposite;
- globalBlend = other.globalBlend;
- transform = other.transform;
- hasInvertibleTransform = other.hasInvertibleTransform;
- imageSmoothingEnabled = other.imageSmoothingEnabled;
- imageSmoothingQuality = other.imageSmoothingQuality;
- textAlign = other.textAlign;
- textBaseline = other.textBaseline;
- direction = other.direction;
- unparsedFont = other.unparsedFont;
- font = other.font;
-
- return *this;
-}
-
-CanvasRenderingContext2D::FontProxy::~FontProxy()
-{
- if (realized())
- m_font.fontSelector()->unregisterForInvalidationCallbacks(*this);
-}
-
-CanvasRenderingContext2D::FontProxy::FontProxy(const FontProxy& other)
- : m_font(other.m_font)
-{
- if (realized())
- m_font.fontSelector()->registerForInvalidationCallbacks(*this);
-}
-
-auto CanvasRenderingContext2D::FontProxy::operator=(const FontProxy& other) -> FontProxy&
-{
- if (realized())
- m_font.fontSelector()->unregisterForInvalidationCallbacks(*this);
-
+ if (m_realizedFont)
+ m_font.fontSelector()->unregisterForInvalidationCallbacks(this);
+
+ m_unparsedStrokeColor = other.m_unparsedStrokeColor;
+ m_unparsedFillColor = other.m_unparsedFillColor;
+ m_strokeStyle = other.m_strokeStyle;
+ m_fillStyle = other.m_fillStyle;
+ m_lineWidth = other.m_lineWidth;
+ m_lineCap = other.m_lineCap;
+ m_lineJoin = other.m_lineJoin;
+ m_miterLimit = other.m_miterLimit;
+ m_shadowOffset = other.m_shadowOffset;
+ m_shadowBlur = other.m_shadowBlur;
+ m_shadowColor = other.m_shadowColor;
+ m_globalAlpha = other.m_globalAlpha;
+ m_globalComposite = other.m_globalComposite;
+ m_globalBlend = other.m_globalBlend;
+ m_transform = other.m_transform;
+ m_hasInvertibleTransform = other.m_hasInvertibleTransform;
+ m_imageSmoothingEnabled = other.m_imageSmoothingEnabled;
+ m_textAlign = other.m_textAlign;
+ m_textBaseline = other.m_textBaseline;
+ m_unparsedFont = other.m_unparsedFont;
m_font = other.m_font;
+ m_realizedFont = other.m_realizedFont;
- if (realized())
- m_font.fontSelector()->registerForInvalidationCallbacks(*this);
+ if (m_realizedFont)
+ m_font.fontSelector()->registerForInvalidationCallbacks(this);
return *this;
}
-inline void CanvasRenderingContext2D::FontProxy::update(FontSelector& selector)
-{
- ASSERT(&selector == m_font.fontSelector()); // This is an invariant. We should only ever be registered for callbacks on m_font.m_fonts.m_fontSelector.
- if (realized())
- m_font.fontSelector()->unregisterForInvalidationCallbacks(*this);
- m_font.update(&selector);
- if (realized())
- m_font.fontSelector()->registerForInvalidationCallbacks(*this);
- ASSERT(&selector == m_font.fontSelector());
-}
-
-void CanvasRenderingContext2D::FontProxy::fontsNeedUpdate(FontSelector& selector)
-{
- ASSERT_ARG(selector, &selector == m_font.fontSelector());
- ASSERT(realized());
-
- update(selector);
-}
-
-inline void CanvasRenderingContext2D::FontProxy::initialize(FontSelector& fontSelector, RenderStyle& newStyle)
-{
- // Beware! m_font.fontSelector() might not point to document.fontSelector()!
- ASSERT(newStyle.fontCascade().fontSelector() == &fontSelector);
- if (realized())
- m_font.fontSelector()->unregisterForInvalidationCallbacks(*this);
- m_font = newStyle.fontCascade();
- m_font.update(&fontSelector);
- ASSERT(&fontSelector == m_font.fontSelector());
- m_font.fontSelector()->registerForInvalidationCallbacks(*this);
-}
-
-inline FontMetrics CanvasRenderingContext2D::FontProxy::fontMetrics() const
+CanvasRenderingContext2D::State::~State()
{
- return m_font.fontMetrics();
+ if (m_realizedFont)
+ m_font.fontSelector()->unregisterForInvalidationCallbacks(this);
}
-inline const FontCascadeDescription& CanvasRenderingContext2D::FontProxy::fontDescription() const
+void CanvasRenderingContext2D::State::fontsNeedUpdate(FontSelector* fontSelector)
{
- return m_font.fontDescription();
-}
+ ASSERT_ARG(fontSelector, fontSelector == m_font.fontSelector());
+ ASSERT(m_realizedFont);
-inline float CanvasRenderingContext2D::FontProxy::width(const TextRun& textRun) const
-{
- return m_font.width(textRun);
-}
-
-inline void CanvasRenderingContext2D::FontProxy::drawBidiText(GraphicsContext& context, const TextRun& run, const FloatPoint& point, FontCascade::CustomFontNotReadyAction action) const
-{
- context.drawBidiText(m_font, run, point, action);
+ m_font.update(fontSelector);
}
void CanvasRenderingContext2D::realizeSavesLoop()
@@ -371,10 +284,9 @@ void CanvasRenderingContext2D::restore()
ASSERT(m_stateStack.size() >= 1);
if (m_stateStack.size() <= 1)
return;
- m_path.transform(state().transform);
+ m_path.transform(state().m_transform);
m_stateStack.removeLast();
- if (Optional<AffineTransform> inverse = state().transform.inverse())
- m_path.transform(inverse.value());
+ m_path.transform(state().m_transform.inverse());
GraphicsContext* c = drawingContext();
if (!c)
return;
@@ -386,7 +298,7 @@ void CanvasRenderingContext2D::setStrokeStyle(CanvasStyle style)
if (!style.isValid())
return;
- if (state().strokeStyle.isValid() && state().strokeStyle.isEquivalentColor(style))
+ if (state().m_strokeStyle.isValid() && state().m_strokeStyle.isEquivalentColor(style))
return;
if (style.isCurrentColor()) {
@@ -399,12 +311,12 @@ void CanvasRenderingContext2D::setStrokeStyle(CanvasStyle style)
realizeSaves();
State& state = modifiableState();
- state.strokeStyle = style;
+ state.m_strokeStyle = style;
GraphicsContext* c = drawingContext();
if (!c)
return;
- state.strokeStyle.applyStrokeColor(c);
- state.unparsedStrokeColor = String();
+ state.m_strokeStyle.applyStrokeColor(c);
+ state.m_unparsedStrokeColor = String();
}
void CanvasRenderingContext2D::setFillStyle(CanvasStyle style)
@@ -412,7 +324,7 @@ void CanvasRenderingContext2D::setFillStyle(CanvasStyle style)
if (!style.isValid())
return;
- if (state().fillStyle.isValid() && state().fillStyle.isEquivalentColor(style))
+ if (state().m_fillStyle.isValid() && state().m_fillStyle.isEquivalentColor(style))
return;
if (style.isCurrentColor()) {
@@ -425,27 +337,27 @@ void CanvasRenderingContext2D::setFillStyle(CanvasStyle style)
realizeSaves();
State& state = modifiableState();
- state.fillStyle = style;
+ state.m_fillStyle = style;
GraphicsContext* c = drawingContext();
if (!c)
return;
- state.fillStyle.applyFillColor(c);
- state.unparsedFillColor = String();
+ state.m_fillStyle.applyFillColor(c);
+ state.m_unparsedFillColor = String();
}
float CanvasRenderingContext2D::lineWidth() const
{
- return state().lineWidth;
+ return state().m_lineWidth;
}
void CanvasRenderingContext2D::setLineWidth(float width)
{
if (!(std::isfinite(width) && width > 0))
return;
- if (state().lineWidth == width)
+ if (state().m_lineWidth == width)
return;
realizeSaves();
- modifiableState().lineWidth = width;
+ modifiableState().m_lineWidth = width;
GraphicsContext* c = drawingContext();
if (!c)
return;
@@ -454,7 +366,7 @@ void CanvasRenderingContext2D::setLineWidth(float width)
String CanvasRenderingContext2D::lineCap() const
{
- return lineCapName(state().lineCap);
+ return lineCapName(state().m_lineCap);
}
void CanvasRenderingContext2D::setLineCap(const String& s)
@@ -462,10 +374,10 @@ void CanvasRenderingContext2D::setLineCap(const String& s)
LineCap cap;
if (!parseLineCap(s, cap))
return;
- if (state().lineCap == cap)
+ if (state().m_lineCap == cap)
return;
realizeSaves();
- modifiableState().lineCap = cap;
+ modifiableState().m_lineCap = cap;
GraphicsContext* c = drawingContext();
if (!c)
return;
@@ -474,7 +386,7 @@ void CanvasRenderingContext2D::setLineCap(const String& s)
String CanvasRenderingContext2D::lineJoin() const
{
- return lineJoinName(state().lineJoin);
+ return lineJoinName(state().m_lineJoin);
}
void CanvasRenderingContext2D::setLineJoin(const String& s)
@@ -482,10 +394,10 @@ void CanvasRenderingContext2D::setLineJoin(const String& s)
LineJoin join;
if (!parseLineJoin(s, join))
return;
- if (state().lineJoin == join)
+ if (state().m_lineJoin == join)
return;
realizeSaves();
- modifiableState().lineJoin = join;
+ modifiableState().m_lineJoin = join;
GraphicsContext* c = drawingContext();
if (!c)
return;
@@ -494,17 +406,17 @@ void CanvasRenderingContext2D::setLineJoin(const String& s)
float CanvasRenderingContext2D::miterLimit() const
{
- return state().miterLimit;
+ return state().m_miterLimit;
}
void CanvasRenderingContext2D::setMiterLimit(float limit)
{
if (!(std::isfinite(limit) && limit > 0))
return;
- if (state().miterLimit == limit)
+ if (state().m_miterLimit == limit)
return;
realizeSaves();
- modifiableState().miterLimit = limit;
+ modifiableState().m_miterLimit = limit;
GraphicsContext* c = drawingContext();
if (!c)
return;
@@ -513,55 +425,55 @@ void CanvasRenderingContext2D::setMiterLimit(float limit)
float CanvasRenderingContext2D::shadowOffsetX() const
{
- return state().shadowOffset.width();
+ return state().m_shadowOffset.width();
}
void CanvasRenderingContext2D::setShadowOffsetX(float x)
{
if (!std::isfinite(x))
return;
- if (state().shadowOffset.width() == x)
+ if (state().m_shadowOffset.width() == x)
return;
realizeSaves();
- modifiableState().shadowOffset.setWidth(x);
+ modifiableState().m_shadowOffset.setWidth(x);
applyShadow();
}
float CanvasRenderingContext2D::shadowOffsetY() const
{
- return state().shadowOffset.height();
+ return state().m_shadowOffset.height();
}
void CanvasRenderingContext2D::setShadowOffsetY(float y)
{
if (!std::isfinite(y))
return;
- if (state().shadowOffset.height() == y)
+ if (state().m_shadowOffset.height() == y)
return;
realizeSaves();
- modifiableState().shadowOffset.setHeight(y);
+ modifiableState().m_shadowOffset.setHeight(y);
applyShadow();
}
float CanvasRenderingContext2D::shadowBlur() const
{
- return state().shadowBlur;
+ return state().m_shadowBlur;
}
void CanvasRenderingContext2D::setShadowBlur(float blur)
{
if (!(std::isfinite(blur) && blur >= 0))
return;
- if (state().shadowBlur == blur)
+ if (state().m_shadowBlur == blur)
return;
realizeSaves();
- modifiableState().shadowBlur = blur;
+ modifiableState().m_shadowBlur = blur;
applyShadow();
}
String CanvasRenderingContext2D::shadowColor() const
{
- return Color(state().shadowColor).serialized();
+ return Color(state().m_shadowColor).serialized();
}
void CanvasRenderingContext2D::setShadowColor(const String& color)
@@ -569,16 +481,16 @@ void CanvasRenderingContext2D::setShadowColor(const String& color)
RGBA32 rgba;
if (!parseColorOrCurrentColor(rgba, color, canvas()))
return;
- if (state().shadowColor == rgba)
+ if (state().m_shadowColor == rgba)
return;
realizeSaves();
- modifiableState().shadowColor = rgba;
+ modifiableState().m_shadowColor = rgba;
applyShadow();
}
const Vector<float>& CanvasRenderingContext2D::getLineDash() const
{
- return state().lineDash;
+ return state().m_lineDash;
}
static bool lineDashSequenceIsValid(const Vector<float>& dash)
@@ -596,11 +508,11 @@ void CanvasRenderingContext2D::setLineDash(const Vector<float>& dash)
return;
realizeSaves();
- modifiableState().lineDash = dash;
+ modifiableState().m_lineDash = dash;
// Spec requires the concatenation of two copies the dash list when the
// number of elements is odd
if (dash.size() % 2)
- modifiableState().lineDash.appendVector(dash);
+ modifiableState().m_lineDash.appendVector(dash);
applyLineDash();
}
@@ -611,23 +523,23 @@ void CanvasRenderingContext2D::setWebkitLineDash(const Vector<float>& dash)
return;
realizeSaves();
- modifiableState().lineDash = dash;
+ modifiableState().m_lineDash = dash;
applyLineDash();
}
float CanvasRenderingContext2D::lineDashOffset() const
{
- return state().lineDashOffset;
+ return state().m_lineDashOffset;
}
void CanvasRenderingContext2D::setLineDashOffset(float offset)
{
- if (!std::isfinite(offset) || state().lineDashOffset == offset)
+ if (!std::isfinite(offset) || state().m_lineDashOffset == offset)
return;
realizeSaves();
- modifiableState().lineDashOffset = offset;
+ modifiableState().m_lineDashOffset = offset;
applyLineDash();
}
@@ -646,25 +558,25 @@ void CanvasRenderingContext2D::applyLineDash() const
GraphicsContext* c = drawingContext();
if (!c)
return;
- DashArray convertedLineDash(state().lineDash.size());
- for (size_t i = 0; i < state().lineDash.size(); ++i)
- convertedLineDash[i] = static_cast<DashArrayElement>(state().lineDash[i]);
- c->setLineDash(convertedLineDash, state().lineDashOffset);
+ DashArray convertedLineDash(state().m_lineDash.size());
+ for (size_t i = 0; i < state().m_lineDash.size(); ++i)
+ convertedLineDash[i] = static_cast<DashArrayElement>(state().m_lineDash[i]);
+ c->setLineDash(convertedLineDash, state().m_lineDashOffset);
}
float CanvasRenderingContext2D::globalAlpha() const
{
- return state().globalAlpha;
+ return state().m_globalAlpha;
}
void CanvasRenderingContext2D::setGlobalAlpha(float alpha)
{
if (!(alpha >= 0 && alpha <= 1))
return;
- if (state().globalAlpha == alpha)
+ if (state().m_globalAlpha == alpha)
return;
realizeSaves();
- modifiableState().globalAlpha = alpha;
+ modifiableState().m_globalAlpha = alpha;
GraphicsContext* c = drawingContext();
if (!c)
return;
@@ -673,7 +585,7 @@ void CanvasRenderingContext2D::setGlobalAlpha(float alpha)
String CanvasRenderingContext2D::globalCompositeOperation() const
{
- return compositeOperatorName(state().globalComposite, state().globalBlend);
+ return compositeOperatorName(state().m_globalComposite, state().m_globalBlend);
}
void CanvasRenderingContext2D::setGlobalCompositeOperation(const String& operation)
@@ -682,11 +594,11 @@ void CanvasRenderingContext2D::setGlobalCompositeOperation(const String& operati
BlendMode blendMode = BlendModeNormal;
if (!parseCompositeAndBlendOperator(operation, op, blendMode))
return;
- if ((state().globalComposite == op) && (state().globalBlend == blendMode))
+ if ((state().m_globalComposite == op) && (state().m_globalBlend == blendMode))
return;
realizeSaves();
- modifiableState().globalComposite = op;
- modifiableState().globalBlend = blendMode;
+ modifiableState().m_globalComposite = op;
+ modifiableState().m_globalBlend = blendMode;
GraphicsContext* c = drawingContext();
if (!c)
return;
@@ -698,25 +610,25 @@ void CanvasRenderingContext2D::scale(float sx, float sy)
GraphicsContext* c = drawingContext();
if (!c)
return;
- if (!state().hasInvertibleTransform)
+ if (!state().m_hasInvertibleTransform)
return;
- if (!std::isfinite(sx) || !std::isfinite(sy))
+ if (!std::isfinite(sx) | !std::isfinite(sy))
return;
- AffineTransform newTransform = state().transform;
+ AffineTransform newTransform = state().m_transform;
newTransform.scaleNonUniform(sx, sy);
- if (state().transform == newTransform)
+ if (state().m_transform == newTransform)
return;
realizeSaves();
- if (!sx || !sy) {
- modifiableState().hasInvertibleTransform = false;
+ if (!newTransform.isInvertible()) {
+ modifiableState().m_hasInvertibleTransform = false;
return;
}
- modifiableState().transform = newTransform;
+ modifiableState().m_transform = newTransform;
c->scale(FloatSize(sx, sy));
m_path.transform(AffineTransform().scaleNonUniform(1.0 / sx, 1.0 / sy));
}
@@ -726,20 +638,25 @@ void CanvasRenderingContext2D::rotate(float angleInRadians)
GraphicsContext* c = drawingContext();
if (!c)
return;
- if (!state().hasInvertibleTransform)
+ if (!state().m_hasInvertibleTransform)
return;
if (!std::isfinite(angleInRadians))
return;
- AffineTransform newTransform = state().transform;
+ AffineTransform newTransform = state().m_transform;
newTransform.rotate(angleInRadians / piDouble * 180.0);
- if (state().transform == newTransform)
+ if (state().m_transform == newTransform)
return;
realizeSaves();
- modifiableState().transform = newTransform;
+ if (!newTransform.isInvertible()) {
+ modifiableState().m_hasInvertibleTransform = false;
+ return;
+ }
+
+ modifiableState().m_transform = newTransform;
c->rotate(angleInRadians);
m_path.transform(AffineTransform().rotate(-angleInRadians / piDouble * 180.0));
}
@@ -749,20 +666,25 @@ void CanvasRenderingContext2D::translate(float tx, float ty)
GraphicsContext* c = drawingContext();
if (!c)
return;
- if (!state().hasInvertibleTransform)
+ if (!state().m_hasInvertibleTransform)
return;
if (!std::isfinite(tx) | !std::isfinite(ty))
return;
- AffineTransform newTransform = state().transform;
+ AffineTransform newTransform = state().m_transform;
newTransform.translate(tx, ty);
- if (state().transform == newTransform)
+ if (state().m_transform == newTransform)
return;
realizeSaves();
- modifiableState().transform = newTransform;
+ if (!newTransform.isInvertible()) {
+ modifiableState().m_hasInvertibleTransform = false;
+ return;
+ }
+
+ modifiableState().m_transform = newTransform;
c->translate(tx, ty);
m_path.transform(AffineTransform().translate(-tx, -ty));
}
@@ -772,26 +694,27 @@ void CanvasRenderingContext2D::transform(float m11, float m12, float m21, float
GraphicsContext* c = drawingContext();
if (!c)
return;
- if (!state().hasInvertibleTransform)
+ if (!state().m_hasInvertibleTransform)
return;
if (!std::isfinite(m11) | !std::isfinite(m21) | !std::isfinite(dx) | !std::isfinite(m12) | !std::isfinite(m22) | !std::isfinite(dy))
return;
AffineTransform transform(m11, m12, m21, m22, dx, dy);
- AffineTransform newTransform = state().transform * transform;
- if (state().transform == newTransform)
+ AffineTransform newTransform = state().m_transform * transform;
+ if (state().m_transform == newTransform)
return;
realizeSaves();
- if (auto inverse = newTransform.inverse()) {
- modifiableState().transform = newTransform;
- c->concatCTM(transform);
- m_path.transform(inverse.value());
+ if (!newTransform.isInvertible()) {
+ modifiableState().m_hasInvertibleTransform = false;
return;
}
- modifiableState().hasInvertibleTransform = false;
+
+ modifiableState().m_transform = newTransform;
+ c->concatCTM(transform);
+ m_path.transform(transform.inverse());
}
void CanvasRenderingContext2D::setTransform(float m11, float m12, float m21, float m22, float dx, float dy)
@@ -803,32 +726,32 @@ void CanvasRenderingContext2D::setTransform(float m11, float m12, float m21, flo
if (!std::isfinite(m11) | !std::isfinite(m21) | !std::isfinite(dx) | !std::isfinite(m12) | !std::isfinite(m22) | !std::isfinite(dy))
return;
- AffineTransform ctm = state().transform;
+ AffineTransform ctm = state().m_transform;
if (!ctm.isInvertible())
return;
realizeSaves();
c->setCTM(canvas()->baseTransform());
- modifiableState().transform = AffineTransform();
+ modifiableState().m_transform = AffineTransform();
m_path.transform(ctm);
- modifiableState().hasInvertibleTransform = true;
+ modifiableState().m_hasInvertibleTransform = true;
transform(m11, m12, m21, m22, dx, dy);
}
void CanvasRenderingContext2D::setStrokeColor(const String& color)
{
- if (color == state().unparsedStrokeColor)
+ if (color == state().m_unparsedStrokeColor)
return;
realizeSaves();
setStrokeStyle(CanvasStyle::createFromString(color, &canvas()->document()));
- modifiableState().unparsedStrokeColor = color;
+ modifiableState().m_unparsedStrokeColor = color;
}
void CanvasRenderingContext2D::setStrokeColor(float grayLevel)
{
- if (state().strokeStyle.isValid() && state().strokeStyle.isEquivalentRGBA(grayLevel, grayLevel, grayLevel, 1.0f))
+ if (state().m_strokeStyle.isValid() && state().m_strokeStyle.isEquivalentRGBA(grayLevel, grayLevel, grayLevel, 1.0f))
return;
setStrokeStyle(CanvasStyle(grayLevel, 1.0f));
}
@@ -840,37 +763,37 @@ void CanvasRenderingContext2D::setStrokeColor(const String& color, float alpha)
void CanvasRenderingContext2D::setStrokeColor(float grayLevel, float alpha)
{
- if (state().strokeStyle.isValid() && state().strokeStyle.isEquivalentRGBA(grayLevel, grayLevel, grayLevel, alpha))
+ if (state().m_strokeStyle.isValid() && state().m_strokeStyle.isEquivalentRGBA(grayLevel, grayLevel, grayLevel, alpha))
return;
setStrokeStyle(CanvasStyle(grayLevel, alpha));
}
void CanvasRenderingContext2D::setStrokeColor(float r, float g, float b, float a)
{
- if (state().strokeStyle.isValid() && state().strokeStyle.isEquivalentRGBA(r, g, b, a))
+ if (state().m_strokeStyle.isValid() && state().m_strokeStyle.isEquivalentRGBA(r, g, b, a))
return;
setStrokeStyle(CanvasStyle(r, g, b, a));
}
void CanvasRenderingContext2D::setStrokeColor(float c, float m, float y, float k, float a)
{
- if (state().strokeStyle.isValid() && state().strokeStyle.isEquivalentCMYKA(c, m, y, k, a))
+ if (state().m_strokeStyle.isValid() && state().m_strokeStyle.isEquivalentCMYKA(c, m, y, k, a))
return;
setStrokeStyle(CanvasStyle(c, m, y, k, a));
}
void CanvasRenderingContext2D::setFillColor(const String& color)
{
- if (color == state().unparsedFillColor)
+ if (color == state().m_unparsedFillColor)
return;
realizeSaves();
setFillStyle(CanvasStyle::createFromString(color, &canvas()->document()));
- modifiableState().unparsedFillColor = color;
+ modifiableState().m_unparsedFillColor = color;
}
void CanvasRenderingContext2D::setFillColor(float grayLevel)
{
- if (state().fillStyle.isValid() && state().fillStyle.isEquivalentRGBA(grayLevel, grayLevel, grayLevel, 1.0f))
+ if (state().m_fillStyle.isValid() && state().m_fillStyle.isEquivalentRGBA(grayLevel, grayLevel, grayLevel, 1.0f))
return;
setFillStyle(CanvasStyle(grayLevel, 1.0f));
}
@@ -882,21 +805,21 @@ void CanvasRenderingContext2D::setFillColor(const String& color, float alpha)
void CanvasRenderingContext2D::setFillColor(float grayLevel, float alpha)
{
- if (state().fillStyle.isValid() && state().fillStyle.isEquivalentRGBA(grayLevel, grayLevel, grayLevel, alpha))
+ if (state().m_fillStyle.isValid() && state().m_fillStyle.isEquivalentRGBA(grayLevel, grayLevel, grayLevel, alpha))
return;
setFillStyle(CanvasStyle(grayLevel, alpha));
}
void CanvasRenderingContext2D::setFillColor(float r, float g, float b, float a)
{
- if (state().fillStyle.isValid() && state().fillStyle.isEquivalentRGBA(r, g, b, a))
+ if (state().m_fillStyle.isValid() && state().m_fillStyle.isEquivalentRGBA(r, g, b, a))
return;
setFillStyle(CanvasStyle(r, g, b, a));
}
void CanvasRenderingContext2D::setFillColor(float c, float m, float y, float k, float a)
{
- if (state().fillStyle.isValid() && state().fillStyle.isEquivalentCMYKA(c, m, y, k, a))
+ if (state().m_fillStyle.isValid() && state().m_fillStyle.isEquivalentCMYKA(c, m, y, k, a))
return;
setFillStyle(CanvasStyle(c, m, y, k, a));
}
@@ -906,6 +829,22 @@ void CanvasRenderingContext2D::beginPath()
m_path.clear();
}
+#if ENABLE(CANVAS_PATH)
+
+PassRefPtr<DOMPath> CanvasRenderingContext2D::currentPath()
+{
+ return DOMPath::create(m_path);
+}
+
+void CanvasRenderingContext2D::setCurrentPath(DOMPath* path)
+{
+ if (!path)
+ return;
+ m_path = path->path();
+}
+
+#endif
+
static bool validateRectForCanvas(float& x, float& y, float& width, float& height)
{
if (!std::isfinite(x) | !std::isfinite(y) | !std::isfinite(width) | !std::isfinite(height))
@@ -957,52 +896,10 @@ static bool parseWinding(const String& windingRuleString, WindRule& windRule)
void CanvasRenderingContext2D::fill(const String& windingRuleString)
{
- fillInternal(m_path, windingRuleString);
-
-#if ENABLE(DASHBOARD_SUPPORT)
- clearPathForDashboardBackwardCompatibilityMode();
-#endif
-}
-
-void CanvasRenderingContext2D::stroke()
-{
- strokeInternal(m_path);
-
-#if ENABLE(DASHBOARD_SUPPORT)
- clearPathForDashboardBackwardCompatibilityMode();
-#endif
-}
-
-void CanvasRenderingContext2D::clip(const String& windingRuleString)
-{
- clipInternal(m_path, windingRuleString);
-
-#if ENABLE(DASHBOARD_SUPPORT)
- clearPathForDashboardBackwardCompatibilityMode();
-#endif
-}
-
-void CanvasRenderingContext2D::fill(DOMPath* path, const String& windingRuleString)
-{
- fillInternal(path->path(), windingRuleString);
-}
-
-void CanvasRenderingContext2D::stroke(DOMPath* path)
-{
- strokeInternal(path->path());
-}
-
-void CanvasRenderingContext2D::clip(DOMPath* path, const String& windingRuleString)
-{
- clipInternal(path->path(), windingRuleString);
-}
-
-void CanvasRenderingContext2D::fillInternal(const Path& path, const String& windingRuleString)
-{
GraphicsContext* c = drawingContext();
if (!c)
return;
- if (!state().hasInvertibleTransform)
+ if (!state().m_hasInvertibleTransform)
return;
// If gradient size is zero, then paint nothing.
@@ -1010,37 +907,39 @@ void CanvasRenderingContext2D::fillInternal(const Path& path, const String& wind
if (gradient && gradient->isZeroSize())
return;
- if (!path.isEmpty()) {
+ if (!m_path.isEmpty()) {
WindRule windRule = c->fillRule();
WindRule newWindRule = RULE_NONZERO;
if (!parseWinding(windingRuleString, newWindRule))
return;
c->setFillRule(newWindRule);
- if (isFullCanvasCompositeMode(state().globalComposite)) {
- beginCompositeLayer();
- c->fillPath(path);
- endCompositeLayer();
+ if (isFullCanvasCompositeMode(state().m_globalComposite)) {
+ fullCanvasCompositedFill(m_path);
didDrawEntireCanvas();
- } else if (state().globalComposite == CompositeCopy) {
+ } else if (state().m_globalComposite == CompositeCopy) {
clearCanvas();
- c->fillPath(path);
+ c->fillPath(m_path);
didDrawEntireCanvas();
} else {
- c->fillPath(path);
- didDraw(path.fastBoundingRect());
+ c->fillPath(m_path);
+ didDraw(m_path.fastBoundingRect());
}
c->setFillRule(windRule);
}
+
+#if ENABLE(DASHBOARD_SUPPORT)
+ clearPathForDashboardBackwardCompatibilityMode();
+#endif
}
-void CanvasRenderingContext2D::strokeInternal(const Path& path)
+void CanvasRenderingContext2D::stroke()
{
GraphicsContext* c = drawingContext();
if (!c)
return;
- if (!state().hasInvertibleTransform)
+ if (!state().m_hasInvertibleTransform)
return;
// If gradient size is zero, then paint nothing.
@@ -1048,31 +947,25 @@ void CanvasRenderingContext2D::strokeInternal(const Path& path)
if (gradient && gradient->isZeroSize())
return;
- if (!path.isEmpty()) {
- if (isFullCanvasCompositeMode(state().globalComposite)) {
- beginCompositeLayer();
- c->strokePath(path);
- endCompositeLayer();
- didDrawEntireCanvas();
- } else if (state().globalComposite == CompositeCopy) {
- clearCanvas();
- c->strokePath(path);
- didDrawEntireCanvas();
- } else {
- FloatRect dirtyRect = path.fastBoundingRect();
- inflateStrokeRect(dirtyRect);
- c->strokePath(path);
- didDraw(dirtyRect);
- }
+ if (!m_path.isEmpty()) {
+ FloatRect dirtyRect = m_path.fastBoundingRect();
+ inflateStrokeRect(dirtyRect);
+
+ c->strokePath(m_path);
+ didDraw(dirtyRect);
}
+
+#if ENABLE(DASHBOARD_SUPPORT)
+ clearPathForDashboardBackwardCompatibilityMode();
+#endif
}
-void CanvasRenderingContext2D::clipInternal(const Path& path, const String& windingRuleString)
+void CanvasRenderingContext2D::clip(const String& windingRuleString)
{
GraphicsContext* c = drawingContext();
if (!c)
return;
- if (!state().hasInvertibleTransform)
+ if (!state().m_hasInvertibleTransform)
return;
WindRule newWindRule = RULE_NONZERO;
@@ -1080,53 +973,24 @@ void CanvasRenderingContext2D::clipInternal(const Path& path, const String& wind
return;
realizeSaves();
- c->canvasClip(path, newWindRule);
-}
-
-inline void CanvasRenderingContext2D::beginCompositeLayer()
-{
-#if !USE(CAIRO)
- drawingContext()->beginTransparencyLayer(1);
-#endif
-}
-
-inline void CanvasRenderingContext2D::endCompositeLayer()
-{
-#if !USE(CAIRO)
- drawingContext()->endTransparencyLayer();
+ c->canvasClip(m_path, newWindRule);
+
+#if ENABLE(DASHBOARD_SUPPORT)
+ clearPathForDashboardBackwardCompatibilityMode();
#endif
}
bool CanvasRenderingContext2D::isPointInPath(const float x, const float y, const String& windingRuleString)
{
- return isPointInPathInternal(m_path, x, y, windingRuleString);
-}
-
-bool CanvasRenderingContext2D::isPointInStroke(const float x, const float y)
-{
- return isPointInStrokeInternal(m_path, x, y);
-}
-
-bool CanvasRenderingContext2D::isPointInPath(DOMPath* path, const float x, const float y, const String& windingRuleString)
-{
- return isPointInPathInternal(path->path(), x, y, windingRuleString);
-}
-
-bool CanvasRenderingContext2D::isPointInStroke(DOMPath* path, const float x, const float y)
-{
- return isPointInStrokeInternal(path->path(), x, y);
-}
-
-bool CanvasRenderingContext2D::isPointInPathInternal(const Path& path, float x, float y, const String& windingRuleString)
-{
GraphicsContext* c = drawingContext();
if (!c)
return false;
- if (!state().hasInvertibleTransform)
+ if (!state().m_hasInvertibleTransform)
return false;
- FloatPoint transformedPoint = state().transform.inverse().valueOr(AffineTransform()).mapPoint(FloatPoint(x, y));
-
+ FloatPoint point(x, y);
+ AffineTransform ctm = state().m_transform;
+ FloatPoint transformedPoint = ctm.inverse().mapPoint(point);
if (!std::isfinite(transformedPoint.x()) || !std::isfinite(transformedPoint.y()))
return false;
@@ -1134,23 +998,26 @@ bool CanvasRenderingContext2D::isPointInPathInternal(const Path& path, float x,
if (!parseWinding(windingRuleString, windRule))
return false;
- return path.contains(transformedPoint, windRule);
+ return m_path.contains(transformedPoint, windRule);
}
-bool CanvasRenderingContext2D::isPointInStrokeInternal(const Path& path, float x, float y)
+
+bool CanvasRenderingContext2D::isPointInStroke(const float x, const float y)
{
GraphicsContext* c = drawingContext();
if (!c)
return false;
- if (!state().hasInvertibleTransform)
+ if (!state().m_hasInvertibleTransform)
return false;
- FloatPoint transformedPoint = state().transform.inverse().valueOr(AffineTransform()).mapPoint(FloatPoint(x, y));
+ FloatPoint point(x, y);
+ AffineTransform ctm = state().m_transform;
+ FloatPoint transformedPoint = ctm.inverse().mapPoint(point);
if (!std::isfinite(transformedPoint.x()) || !std::isfinite(transformedPoint.y()))
return false;
CanvasStrokeStyleApplier applier(this);
- return path.strokeContains(&applier, transformedPoint);
+ return m_path.strokeContains(&applier, transformedPoint);
}
void CanvasRenderingContext2D::clearRect(float x, float y, float width, float height)
@@ -1160,7 +1027,7 @@ void CanvasRenderingContext2D::clearRect(float x, float y, float width, float he
GraphicsContext* context = drawingContext();
if (!context)
return;
- if (!state().hasInvertibleTransform)
+ if (!state().m_hasInvertibleTransform)
return;
FloatRect rect(x, y, width, height);
@@ -1168,16 +1035,16 @@ void CanvasRenderingContext2D::clearRect(float x, float y, float width, float he
if (shouldDrawShadows()) {
context->save();
saved = true;
- context->setLegacyShadow(FloatSize(), 0, Color::transparent);
+ context->setLegacyShadow(FloatSize(), 0, Color::transparent, ColorSpaceDeviceRGB);
}
- if (state().globalAlpha != 1) {
+ if (state().m_globalAlpha != 1) {
if (!saved) {
context->save();
saved = true;
}
context->setAlpha(1);
}
- if (state().globalComposite != CompositeSourceOver) {
+ if (state().m_globalComposite != CompositeSourceOver) {
if (!saved) {
context->save();
saved = true;
@@ -1198,7 +1065,7 @@ void CanvasRenderingContext2D::fillRect(float x, float y, float width, float hei
GraphicsContext* c = drawingContext();
if (!c)
return;
- if (!state().hasInvertibleTransform)
+ if (!state().m_hasInvertibleTransform)
return;
// from the HTML5 Canvas spec:
@@ -1213,12 +1080,10 @@ void CanvasRenderingContext2D::fillRect(float x, float y, float width, float hei
if (rectContainsCanvas(rect)) {
c->fillRect(rect);
didDrawEntireCanvas();
- } else if (isFullCanvasCompositeMode(state().globalComposite)) {
- beginCompositeLayer();
- c->fillRect(rect);
- endCompositeLayer();
+ } else if (isFullCanvasCompositeMode(state().m_globalComposite)) {
+ fullCanvasCompositedFill(rect);
didDrawEntireCanvas();
- } else if (state().globalComposite == CompositeCopy) {
+ } else if (state().m_globalComposite == CompositeCopy) {
clearCanvas();
c->fillRect(rect);
didDrawEntireCanvas();
@@ -1236,9 +1101,9 @@ void CanvasRenderingContext2D::strokeRect(float x, float y, float width, float h
GraphicsContext* c = drawingContext();
if (!c)
return;
- if (!state().hasInvertibleTransform)
+ if (!state().m_hasInvertibleTransform)
return;
- if (!(state().lineWidth >= 0))
+ if (!(state().m_lineWidth >= 0))
return;
// If gradient size is zero, then paint nothing.
@@ -1247,21 +1112,12 @@ void CanvasRenderingContext2D::strokeRect(float x, float y, float width, float h
return;
FloatRect rect(x, y, width, height);
- if (isFullCanvasCompositeMode(state().globalComposite)) {
- beginCompositeLayer();
- c->strokeRect(rect, state().lineWidth);
- endCompositeLayer();
- didDrawEntireCanvas();
- } else if (state().globalComposite == CompositeCopy) {
- clearCanvas();
- c->strokeRect(rect, state().lineWidth);
- didDrawEntireCanvas();
- } else {
- FloatRect boundingRect = rect;
- boundingRect.inflate(state().lineWidth / 2);
- c->strokeRect(rect, state().lineWidth);
- didDraw(boundingRect);
- }
+
+ FloatRect boundingRect = rect;
+ boundingRect.inflate(state().m_lineWidth / 2);
+
+ c->strokeRect(rect, state().m_lineWidth);
+ didDraw(boundingRect);
}
void CanvasRenderingContext2D::setShadow(float width, float height, float blur)
@@ -1312,13 +1168,13 @@ void CanvasRenderingContext2D::clearShadow()
void CanvasRenderingContext2D::setShadow(const FloatSize& offset, float blur, RGBA32 color)
{
- if (state().shadowOffset == offset && state().shadowBlur == blur && state().shadowColor == color)
+ if (state().m_shadowOffset == offset && state().m_shadowBlur == blur && state().m_shadowColor == color)
return;
bool wasDrawingShadows = shouldDrawShadows();
realizeSaves();
- modifiableState().shadowOffset = offset;
- modifiableState().shadowBlur = blur;
- modifiableState().shadowColor = color;
+ modifiableState().m_shadowOffset = offset;
+ modifiableState().m_shadowBlur = blur;
+ modifiableState().m_shadowColor = color;
if (!wasDrawingShadows && !shouldDrawShadows())
return;
applyShadow();
@@ -1331,41 +1187,31 @@ void CanvasRenderingContext2D::applyShadow()
return;
if (shouldDrawShadows()) {
- float width = state().shadowOffset.width();
- float height = state().shadowOffset.height();
- c->setLegacyShadow(FloatSize(width, -height), state().shadowBlur, state().shadowColor);
+ float width = state().m_shadowOffset.width();
+ float height = state().m_shadowOffset.height();
+ c->setLegacyShadow(FloatSize(width, -height), state().m_shadowBlur, state().m_shadowColor, ColorSpaceDeviceRGB);
} else
- c->setLegacyShadow(FloatSize(), 0, Color::transparent);
+ c->setLegacyShadow(FloatSize(), 0, Color::transparent, ColorSpaceDeviceRGB);
}
bool CanvasRenderingContext2D::shouldDrawShadows() const
{
- return alphaChannel(state().shadowColor) && (state().shadowBlur || !state().shadowOffset.isZero());
+ return alphaChannel(state().m_shadowColor) && (state().m_shadowBlur || !state().m_shadowOffset.isZero());
}
-enum ImageSizeType {
- ImageSizeAfterDevicePixelRatio,
- ImageSizeBeforeDevicePixelRatio
-};
-
-static LayoutSize size(HTMLImageElement* imageElement, ImageSizeType sizeType)
+static LayoutSize size(HTMLImageElement* image)
{
- LayoutSize size;
- if (CachedImage* cachedImage = imageElement->cachedImage()) {
- size = cachedImage->imageSizeForRenderer(imageElement->renderer(), 1.0f); // FIXME: Not sure about this.
-
- if (sizeType == ImageSizeAfterDevicePixelRatio && is<RenderImage>(imageElement->renderer()) && cachedImage->image() && !cachedImage->image()->hasRelativeWidth())
- size.scale(downcast<RenderImage>(*imageElement->renderer()).imageDevicePixelRatio());
- }
- return size;
+ if (CachedImage* cachedImage = image->cachedImage())
+ return cachedImage->imageSizeForRenderer(image->renderer(), 1.0f); // FIXME: Not sure about this.
+ return IntSize();
}
#if ENABLE(VIDEO)
-static FloatSize size(HTMLVideoElement* video)
+static IntSize size(HTMLVideoElement* video)
{
if (MediaPlayer* player = video->player())
return player->naturalSize();
- return FloatSize();
+ return IntSize();
}
#endif
@@ -1377,42 +1223,42 @@ static inline FloatRect normalizeRect(const FloatRect& rect)
std::max(rect.height(), -rect.height()));
}
-void CanvasRenderingContext2D::drawImage(HTMLImageElement* imageElement, float x, float y, ExceptionCode& ec)
+void CanvasRenderingContext2D::drawImage(HTMLImageElement* image, float x, float y, ExceptionCode& ec)
{
- if (!imageElement) {
+ if (!image) {
ec = TYPE_MISMATCH_ERR;
return;
}
- LayoutSize destRectSize = size(imageElement, ImageSizeAfterDevicePixelRatio);
- drawImage(imageElement, x, y, destRectSize.width(), destRectSize.height(), ec);
+ LayoutSize s = size(image);
+ drawImage(image, x, y, s.width(), s.height(), ec);
}
-void CanvasRenderingContext2D::drawImage(HTMLImageElement* imageElement,
+void CanvasRenderingContext2D::drawImage(HTMLImageElement* image,
float x, float y, float width, float height, ExceptionCode& ec)
{
- if (!imageElement) {
+ if (!image) {
ec = TYPE_MISMATCH_ERR;
return;
}
- LayoutSize sourceRectSize = size(imageElement, ImageSizeBeforeDevicePixelRatio);
- drawImage(imageElement, FloatRect(0, 0, sourceRectSize.width(), sourceRectSize.height()), FloatRect(x, y, width, height), ec);
+ LayoutSize s = size(image);
+ drawImage(image, FloatRect(0, 0, s.width(), s.height()), FloatRect(x, y, width, height), ec);
}
-void CanvasRenderingContext2D::drawImage(HTMLImageElement* imageElement,
+void CanvasRenderingContext2D::drawImage(HTMLImageElement* image,
float sx, float sy, float sw, float sh,
float dx, float dy, float dw, float dh, ExceptionCode& ec)
{
- drawImage(imageElement, FloatRect(sx, sy, sw, sh), FloatRect(dx, dy, dw, dh), ec);
+ drawImage(image, FloatRect(sx, sy, sw, sh), FloatRect(dx, dy, dw, dh), ec);
}
-void CanvasRenderingContext2D::drawImage(HTMLImageElement* imageElement, const FloatRect& srcRect, const FloatRect& dstRect, ExceptionCode& ec)
+void CanvasRenderingContext2D::drawImage(HTMLImageElement* image, const FloatRect& srcRect, const FloatRect& dstRect, ExceptionCode& ec)
{
- drawImage(imageElement, srcRect, dstRect, state().globalComposite, state().globalBlend, ec);
+ drawImage(image, srcRect, dstRect, state().m_globalComposite, state().m_globalBlend, ec);
}
-void CanvasRenderingContext2D::drawImage(HTMLImageElement* imageElement, const FloatRect& srcRect, const FloatRect& dstRect, const CompositeOperator& op, const BlendMode& blendMode, ExceptionCode& ec)
+void CanvasRenderingContext2D::drawImage(HTMLImageElement* image, const FloatRect& srcRect, const FloatRect& dstRect, const CompositeOperator& op, const BlendMode& blendMode, ExceptionCode& ec)
{
- if (!imageElement) {
+ if (!image) {
ec = TYPE_MISMATCH_ERR;
return;
}
@@ -1426,13 +1272,13 @@ void CanvasRenderingContext2D::drawImage(HTMLImageElement* imageElement, const F
if (!dstRect.width() || !dstRect.height())
return;
- if (!imageElement->complete())
+ if (!image->complete())
return;
FloatRect normalizedSrcRect = normalizeRect(srcRect);
FloatRect normalizedDstRect = normalizeRect(dstRect);
- FloatRect imageRect = FloatRect(FloatPoint(), size(imageElement, ImageSizeBeforeDevicePixelRatio));
+ FloatRect imageRect = FloatRect(FloatPoint(), size(image));
if (!srcRect.width() || !srcRect.height()) {
ec = INDEX_SIZE_ERR;
return;
@@ -1443,43 +1289,29 @@ void CanvasRenderingContext2D::drawImage(HTMLImageElement* imageElement, const F
GraphicsContext* c = drawingContext();
if (!c)
return;
- if (!state().hasInvertibleTransform)
+ if (!state().m_hasInvertibleTransform)
return;
- CachedImage* cachedImage = imageElement->cachedImage();
+ CachedImage* cachedImage = image->cachedImage();
if (!cachedImage)
return;
- Image* image = cachedImage->imageForRenderer(imageElement->renderer());
- if (!image)
- return;
-
- ImageObserver* observer = image->imageObserver();
-
- if (image->isSVGImage()) {
- image->setImageObserver(nullptr);
- image->setContainerSize(normalizedSrcRect.size());
- }
-
if (rectContainsCanvas(normalizedDstRect)) {
- c->drawImage(*image, normalizedDstRect, normalizedSrcRect, ImagePaintingOptions(op, blendMode));
+ c->drawImage(cachedImage->imageForRenderer(image->renderer()), ColorSpaceDeviceRGB, normalizedDstRect, normalizedSrcRect, op, blendMode, ImageOrientationDescription());
didDrawEntireCanvas();
} else if (isFullCanvasCompositeMode(op)) {
- fullCanvasCompositedDrawImage(*image, normalizedDstRect, normalizedSrcRect, op);
+ fullCanvasCompositedDrawImage(cachedImage->imageForRenderer(image->renderer()), ColorSpaceDeviceRGB, normalizedDstRect, normalizedSrcRect, op);
didDrawEntireCanvas();
} else if (op == CompositeCopy) {
clearCanvas();
- c->drawImage(*image, normalizedDstRect, normalizedSrcRect, ImagePaintingOptions(op, blendMode));
+ c->drawImage(cachedImage->imageForRenderer(image->renderer()), ColorSpaceDeviceRGB, normalizedDstRect, normalizedSrcRect, op, blendMode, ImageOrientationDescription());
didDrawEntireCanvas();
} else {
- c->drawImage(*image, normalizedDstRect, normalizedSrcRect, ImagePaintingOptions(op, blendMode));
+ c->drawImage(cachedImage->imageForRenderer(image->renderer()), ColorSpaceDeviceRGB, normalizedDstRect, normalizedSrcRect, op, blendMode, ImageOrientationDescription());
didDraw(normalizedDstRect);
}
-
- if (image->isSVGImage())
- image->setImageObserver(observer);
- checkOrigin(imageElement);
+ checkOrigin(image);
}
void CanvasRenderingContext2D::drawImage(HTMLCanvasElement* sourceCanvas, float x, float y, ExceptionCode& ec)
@@ -1528,7 +1360,7 @@ void CanvasRenderingContext2D::drawImage(HTMLCanvasElement* sourceCanvas, const
GraphicsContext* c = drawingContext();
if (!c)
return;
- if (!state().hasInvertibleTransform)
+ if (!state().m_hasInvertibleTransform)
return;
// FIXME: Do this through platform-independent GraphicsContext API.
@@ -1550,17 +1382,17 @@ void CanvasRenderingContext2D::drawImage(HTMLCanvasElement* sourceCanvas, const
#endif
if (rectContainsCanvas(dstRect)) {
- c->drawImageBuffer(*buffer, dstRect, srcRect, ImagePaintingOptions(state().globalComposite, state().globalBlend));
+ c->drawImageBuffer(buffer, ColorSpaceDeviceRGB, dstRect, srcRect, state().m_globalComposite, state().m_globalBlend);
didDrawEntireCanvas();
- } else if (isFullCanvasCompositeMode(state().globalComposite)) {
- fullCanvasCompositedDrawImage(*buffer, dstRect, srcRect, state().globalComposite);
+ } else if (isFullCanvasCompositeMode(state().m_globalComposite)) {
+ fullCanvasCompositedDrawImage(buffer, ColorSpaceDeviceRGB, dstRect, srcRect, state().m_globalComposite);
didDrawEntireCanvas();
- } else if (state().globalComposite == CompositeCopy) {
+ } else if (state().m_globalComposite == CompositeCopy) {
clearCanvas();
- c->drawImageBuffer(*buffer, dstRect, srcRect, ImagePaintingOptions(state().globalComposite, state().globalBlend));
+ c->drawImageBuffer(buffer, ColorSpaceDeviceRGB, dstRect, srcRect, state().m_globalComposite, state().m_globalBlend);
didDrawEntireCanvas();
} else {
- c->drawImageBuffer(*buffer, dstRect, srcRect, ImagePaintingOptions(state().globalComposite, state().globalBlend));
+ c->drawImageBuffer(buffer, ColorSpaceDeviceRGB, dstRect, srcRect, state().m_globalComposite, state().m_globalBlend);
didDraw(dstRect);
}
}
@@ -1572,8 +1404,8 @@ void CanvasRenderingContext2D::drawImage(HTMLVideoElement* video, float x, float
ec = TYPE_MISMATCH_ERR;
return;
}
- FloatSize videoSize = size(video);
- drawImage(video, x, y, videoSize.width(), videoSize.height(), ec);
+ IntSize s = size(video);
+ drawImage(video, x, y, s.width(), s.height(), ec);
}
void CanvasRenderingContext2D::drawImage(HTMLVideoElement* video,
@@ -1583,8 +1415,8 @@ void CanvasRenderingContext2D::drawImage(HTMLVideoElement* video,
ec = TYPE_MISMATCH_ERR;
return;
}
- FloatSize videoSize = size(video);
- drawImage(video, FloatRect(0, 0, videoSize.width(), videoSize.height()), FloatRect(x, y, width, height), ec);
+ IntSize s = size(video);
+ drawImage(video, FloatRect(0, 0, s.width(), s.height()), FloatRect(x, y, width, height), ec);
}
void CanvasRenderingContext2D::drawImage(HTMLVideoElement* video,
@@ -1619,14 +1451,14 @@ void CanvasRenderingContext2D::drawImage(HTMLVideoElement* video, const FloatRec
GraphicsContext* c = drawingContext();
if (!c)
return;
- if (!state().hasInvertibleTransform)
+ if (!state().m_hasInvertibleTransform)
return;
checkOrigin(video);
-#if USE(CG) || (ENABLE(ACCELERATED_2D_CANVAS) && USE(GSTREAMER_GL) && USE(CAIRO))
+#if USE(CG)
if (PassNativeImagePtr image = video->nativeImageForCurrentTime()) {
- c->drawNativeImage(image, FloatSize(video->videoWidth(), video->videoHeight()), dstRect, srcRect);
+ c->drawNativeImage(image, FloatSize(video->videoWidth(), video->videoHeight()), ColorSpaceDeviceRGB, dstRect, srcRect);
if (rectContainsCanvas(dstRect))
didDrawEntireCanvas();
else
@@ -1641,13 +1473,13 @@ void CanvasRenderingContext2D::drawImage(HTMLVideoElement* video, const FloatRec
c->translate(dstRect.x(), dstRect.y());
c->scale(FloatSize(dstRect.width() / srcRect.width(), dstRect.height() / srcRect.height()));
c->translate(-srcRect.x(), -srcRect.y());
- video->paintCurrentFrameInContext(*c, FloatRect(FloatPoint(), size(video)));
+ video->paintCurrentFrameInContext(c, IntRect(IntPoint(), size(video)));
stateSaver.restore();
didDraw(dstRect);
}
#endif
-void CanvasRenderingContext2D::drawImageFromRect(HTMLImageElement* imageElement,
+void CanvasRenderingContext2D::drawImageFromRect(HTMLImageElement* image,
float sx, float sy, float sw, float sh,
float dx, float dy, float dw, float dh,
const String& compositeOperation)
@@ -1657,7 +1489,7 @@ void CanvasRenderingContext2D::drawImageFromRect(HTMLImageElement* imageElement,
if (!parseCompositeAndBlendOperator(compositeOperation, op, blendOp) || blendOp != BlendModeNormal)
op = CompositeSourceOver;
- drawImage(imageElement, FloatRect(sx, sy, sw, sh), FloatRect(dx, dy, dw, dh), op, BlendModeNormal, IGNORE_EXCEPTION);
+ drawImage(image, FloatRect(sx, sy, sw, sh), FloatRect(dx, dy, dw, dh), op, BlendModeNormal, IGNORE_EXCEPTION);
}
void CanvasRenderingContext2D::setAlpha(float alpha)
@@ -1686,7 +1518,7 @@ void CanvasRenderingContext2D::clearCanvas()
Path CanvasRenderingContext2D::transformAreaToDevice(const Path& path) const
{
Path transformed(path);
- transformed.transform(state().transform);
+ transformed.transform(state().m_transform);
transformed.transform(canvas()->baseTransform());
return transformed;
}
@@ -1702,7 +1534,7 @@ bool CanvasRenderingContext2D::rectContainsCanvas(const FloatRect& rect) const
{
FloatQuad quad(rect);
FloatQuad canvasQuad(FloatRect(0, 0, canvas()->width(), canvas()->height()));
- return state().transform.mapQuad(quad).containsQuad(canvasQuad);
+ return state().m_transform.mapQuad(quad).containsQuad(canvasQuad);
}
template<class T> IntRect CanvasRenderingContext2D::calculateCompositingBufferRect(const T& area, IntSize* croppedOffset)
@@ -1720,10 +1552,11 @@ template<class T> IntRect CanvasRenderingContext2D::calculateCompositingBufferRe
std::unique_ptr<ImageBuffer> CanvasRenderingContext2D::createCompositingBuffer(const IntRect& bufferRect)
{
- return ImageBuffer::create(bufferRect.size(), isAccelerated() ? Accelerated : Unaccelerated);
+ RenderingMode renderMode = isAccelerated() ? Accelerated : Unaccelerated;
+ return ImageBuffer::create(bufferRect.size(), 1, ColorSpaceDeviceRGB, renderMode);
}
-void CanvasRenderingContext2D::compositeBuffer(ImageBuffer& buffer, const IntRect& bufferRect, CompositeOperator op)
+void CanvasRenderingContext2D::compositeBuffer(ImageBuffer* buffer, const IntRect& bufferRect, CompositeOperator op)
{
IntRect canvasRect(0, 0, canvas()->width(), canvas()->height());
canvasRect = canvas()->baseTransform().mapRect(canvasRect);
@@ -1740,21 +1573,22 @@ void CanvasRenderingContext2D::compositeBuffer(ImageBuffer& buffer, const IntRec
c->clipOut(bufferRect);
c->clearRect(canvasRect);
c->restore();
- c->drawImageBuffer(buffer, bufferRect.location(), state().globalComposite);
+
+ c->drawImageBuffer(buffer, ColorSpaceDeviceRGB, bufferRect.location(), state().m_globalComposite);
c->restore();
}
-static void drawImageToContext(Image& image, GraphicsContext& context, const FloatRect& dest, const FloatRect& src, CompositeOperator op)
+static void drawImageToContext(Image* image, GraphicsContext* context, ColorSpace styleColorSpace, const FloatRect& dest, const FloatRect& src, CompositeOperator op)
{
- context.drawImage(image, dest, src, op);
+ context->drawImage(image, styleColorSpace, dest, src, op, ImageOrientationDescription());
}
-static void drawImageToContext(ImageBuffer& imageBuffer, GraphicsContext& context, const FloatRect& dest, const FloatRect& src, CompositeOperator op)
+static void drawImageToContext(ImageBuffer* imageBuffer, GraphicsContext* context, ColorSpace styleColorSpace, const FloatRect& dest, const FloatRect& src, CompositeOperator op)
{
- context.drawImageBuffer(imageBuffer, dest, src, op);
+ context->drawImageBuffer(imageBuffer, styleColorSpace, dest, src, op);
}
-template<class T> void CanvasRenderingContext2D::fullCanvasCompositedDrawImage(T& image, const FloatRect& dest, const FloatRect& src, CompositeOperator op)
+template<class T> void CanvasRenderingContext2D::fullCanvasCompositedDrawImage(T* image, ColorSpace styleColorSpace, const FloatRect& dest, const FloatRect& src, CompositeOperator op)
{
ASSERT(isFullCanvasCompositeMode(op));
@@ -1777,110 +1611,118 @@ template<class T> void CanvasRenderingContext2D::fullCanvasCompositedDrawImage(T
adjustedDest.setLocation(FloatPoint(0, 0));
AffineTransform effectiveTransform = c->getCTM();
IntRect transformedAdjustedRect = enclosingIntRect(effectiveTransform.mapRect(adjustedDest));
- buffer->context().translate(-transformedAdjustedRect.location().x(), -transformedAdjustedRect.location().y());
- buffer->context().translate(croppedOffset.width(), croppedOffset.height());
- buffer->context().concatCTM(effectiveTransform);
- drawImageToContext(image, buffer->context(), adjustedDest, src, CompositeSourceOver);
+ buffer->context()->translate(-transformedAdjustedRect.location().x(), -transformedAdjustedRect.location().y());
+ buffer->context()->translate(croppedOffset.width(), croppedOffset.height());
+ buffer->context()->concatCTM(effectiveTransform);
+ drawImageToContext(image, buffer->context(), styleColorSpace, adjustedDest, src, CompositeSourceOver);
- compositeBuffer(*buffer, bufferRect, op);
+ compositeBuffer(buffer.get(), bufferRect, op);
}
-void CanvasRenderingContext2D::prepareGradientForDashboard(CanvasGradient& gradient) const
+template<class T> void CanvasRenderingContext2D::fullCanvasCompositedFill(const T& area)
+{
+ ASSERT(isFullCanvasCompositeMode(state().m_globalComposite));
+
+ IntRect bufferRect = calculateCompositingBufferRect(area, 0);
+ if (bufferRect.isEmpty()) {
+ clearCanvas();
+ return;
+ }
+
+ std::unique_ptr<ImageBuffer> buffer = createCompositingBuffer(bufferRect);
+ if (!buffer)
+ return;
+
+ Path path = transformAreaToDevice(area);
+ path.translate(FloatSize(-bufferRect.x(), -bufferRect.y()));
+
+ buffer->context()->setCompositeOperation(CompositeSourceOver);
+ modifiableState().m_fillStyle.applyFillColor(buffer->context());
+ buffer->context()->fillPath(path);
+
+ compositeBuffer(buffer.get(), bufferRect, state().m_globalComposite);
+}
+
+void CanvasRenderingContext2D::prepareGradientForDashboard(CanvasGradient* gradient) const
{
#if ENABLE(DASHBOARD_SUPPORT)
if (m_usesDashboardCompatibilityMode)
- gradient.setDashboardCompatibilityMode();
+ gradient->setDashboardCompatibilityMode();
#else
UNUSED_PARAM(gradient);
#endif
}
-RefPtr<CanvasGradient> CanvasRenderingContext2D::createLinearGradient(float x0, float y0, float x1, float y1, ExceptionCode& ec)
+PassRefPtr<CanvasGradient> CanvasRenderingContext2D::createLinearGradient(float x0, float y0, float x1, float y1, ExceptionCode& ec)
{
if (!std::isfinite(x0) || !std::isfinite(y0) || !std::isfinite(x1) || !std::isfinite(y1)) {
ec = NOT_SUPPORTED_ERR;
- return nullptr;
+ return 0;
}
- Ref<CanvasGradient> gradient = CanvasGradient::create(FloatPoint(x0, y0), FloatPoint(x1, y1));
+ RefPtr<CanvasGradient> gradient = CanvasGradient::create(FloatPoint(x0, y0), FloatPoint(x1, y1));
prepareGradientForDashboard(gradient.get());
- return WTFMove(gradient);
+ return gradient.release();
}
-RefPtr<CanvasGradient> CanvasRenderingContext2D::createRadialGradient(float x0, float y0, float r0, float x1, float y1, float r1, ExceptionCode& ec)
+PassRefPtr<CanvasGradient> CanvasRenderingContext2D::createRadialGradient(float x0, float y0, float r0, float x1, float y1, float r1, ExceptionCode& ec)
{
if (!std::isfinite(x0) || !std::isfinite(y0) || !std::isfinite(r0) || !std::isfinite(x1) || !std::isfinite(y1) || !std::isfinite(r1)) {
ec = NOT_SUPPORTED_ERR;
- return nullptr;
+ return 0;
}
if (r0 < 0 || r1 < 0) {
ec = INDEX_SIZE_ERR;
- return nullptr;
+ return 0;
}
- Ref<CanvasGradient> gradient = CanvasGradient::create(FloatPoint(x0, y0), r0, FloatPoint(x1, y1), r1);
+ RefPtr<CanvasGradient> gradient = CanvasGradient::create(FloatPoint(x0, y0), r0, FloatPoint(x1, y1), r1);
prepareGradientForDashboard(gradient.get());
- return WTFMove(gradient);
+ return gradient.release();
}
-RefPtr<CanvasPattern> CanvasRenderingContext2D::createPattern(HTMLImageElement* imageElement,
+PassRefPtr<CanvasPattern> CanvasRenderingContext2D::createPattern(HTMLImageElement* image,
const String& repetitionType, ExceptionCode& ec)
{
- if (!imageElement) {
+ if (!image) {
ec = TYPE_MISMATCH_ERR;
- return nullptr;
+ return 0;
}
bool repeatX, repeatY;
ec = 0;
CanvasPattern::parseRepetitionType(repetitionType, repeatX, repeatY, ec);
if (ec)
- return nullptr;
+ return 0;
- CachedImage* cachedImage = imageElement->cachedImage();
- // If the image loading hasn't started or the image is not complete, it is not fully decodable.
- if (!cachedImage || !imageElement->complete())
- return nullptr;
-
- if (cachedImage->status() == CachedResource::LoadError) {
- ec = INVALID_STATE_ERR;
- return nullptr;
- }
+ if (!image->complete())
+ return 0;
- if (!imageElement->cachedImage()->imageForRenderer(imageElement->renderer()))
+ CachedImage* cachedImage = image->cachedImage();
+ if (!cachedImage || !image->cachedImage()->imageForRenderer(image->renderer()))
return CanvasPattern::create(Image::nullImage(), repeatX, repeatY, true);
bool originClean = cachedImage->isOriginClean(canvas()->securityOrigin());
-
- // FIXME: SVG images with animations can switch between clean and dirty (leaking cross-origin
- // data). We should either:
- // 1) Take a fixed snapshot of an SVG image when creating a pattern and determine then whether
- // the origin is clean.
- // 2) Dynamically verify the origin checks at draw time, and dirty the canvas accordingly.
- // To be on the safe side, taint the origin for all patterns containing SVG images for now.
- if (cachedImage->image()->isSVGImage())
- originClean = false;
-
- return CanvasPattern::create(cachedImage->imageForRenderer(imageElement->renderer()), repeatX, repeatY, originClean);
+ return CanvasPattern::create(cachedImage->imageForRenderer(image->renderer()), repeatX, repeatY, originClean);
}
-RefPtr<CanvasPattern> CanvasRenderingContext2D::createPattern(HTMLCanvasElement* canvas,
+PassRefPtr<CanvasPattern> CanvasRenderingContext2D::createPattern(HTMLCanvasElement* canvas,
const String& repetitionType, ExceptionCode& ec)
{
if (!canvas) {
ec = TYPE_MISMATCH_ERR;
- return nullptr;
+ return 0;
}
- if (!canvas->width() || !canvas->height() || !canvas->buffer()) {
+ if (!canvas->width() || !canvas->height()) {
ec = INVALID_STATE_ERR;
- return nullptr;
+ return 0;
}
bool repeatX, repeatY;
ec = 0;
CanvasPattern::parseRepetitionType(repetitionType, repeatX, repeatY, ec);
if (ec)
- return nullptr;
+ return 0;
return CanvasPattern::create(canvas->copiedImage(), repeatX, repeatY, canvas->originClean());
}
@@ -1894,10 +1736,10 @@ void CanvasRenderingContext2D::didDraw(const FloatRect& r, unsigned options)
GraphicsContext* c = drawingContext();
if (!c)
return;
- if (!state().hasInvertibleTransform)
+ if (!state().m_hasInvertibleTransform)
return;
-#if ENABLE(ACCELERATED_2D_CANVAS)
+#if ENABLE(ACCELERATED_2D_CANVAS) && USE(ACCELERATED_COMPOSITING)
// If we are drawing to hardware and we have a composited layer, just call contentChanged().
if (isAccelerated()) {
RenderBox* renderBox = canvas()->renderBox();
@@ -1912,15 +1754,15 @@ void CanvasRenderingContext2D::didDraw(const FloatRect& r, unsigned options)
FloatRect dirtyRect = r;
if (options & CanvasDidDrawApplyTransform) {
- AffineTransform ctm = state().transform;
+ AffineTransform ctm = state().m_transform;
dirtyRect = ctm.mapRect(r);
}
- if (options & CanvasDidDrawApplyShadow && alphaChannel(state().shadowColor)) {
+ if (options & CanvasDidDrawApplyShadow && alphaChannel(state().m_shadowColor)) {
// The shadow gets applied after transformation
FloatRect shadowRect(dirtyRect);
- shadowRect.move(state().shadowOffset);
- shadowRect.inflate(state().shadowBlur);
+ shadowRect.move(state().m_shadowOffset);
+ shadowRect.inflate(state().m_shadowBlur);
dirtyRect.unite(shadowRect);
}
@@ -1933,102 +1775,58 @@ void CanvasRenderingContext2D::didDraw(const FloatRect& r, unsigned options)
canvas()->didDraw(dirtyRect);
}
-void CanvasRenderingContext2D::setTracksDisplayListReplay(bool tracksDisplayListReplay)
-{
- if (tracksDisplayListReplay == m_tracksDisplayListReplay)
- return;
-
- m_tracksDisplayListReplay = tracksDisplayListReplay;
- if (!m_tracksDisplayListReplay)
- contextDisplayListMap().remove(this);
-}
-
-String CanvasRenderingContext2D::displayListAsText(DisplayList::AsTextFlags flags) const
-{
- if (m_recordingContext)
- return m_recordingContext->displayList.asText(flags);
-
- return String();
-}
-
-String CanvasRenderingContext2D::replayDisplayListAsText(DisplayList::AsTextFlags flags) const
-{
- auto it = contextDisplayListMap().find(this);
- if (it != contextDisplayListMap().end()) {
- TextStream stream;
- stream << it->value->asText(flags);
- return stream.release();
- }
-
- return String();
-}
-
-void CanvasRenderingContext2D::paintRenderingResultsToCanvas()
-{
- if (UNLIKELY(m_usesDisplayListDrawing)) {
- if (!m_recordingContext)
- return;
-
- FloatRect clip(FloatPoint::zero(), canvas()->size());
- DisplayList::Replayer replayer(*canvas()->drawingContext(), m_recordingContext->displayList);
-
- if (UNLIKELY(m_tracksDisplayListReplay)) {
- auto replayList = replayer.replay(clip, m_tracksDisplayListReplay);
- contextDisplayListMap().add(this, WTFMove(replayList));
- } else
- replayer.replay(clip);
-
- m_recordingContext->displayList.clear();
- }
-}
-
GraphicsContext* CanvasRenderingContext2D::drawingContext() const
{
- if (UNLIKELY(m_usesDisplayListDrawing)) {
- if (!m_recordingContext)
- m_recordingContext = std::make_unique<DisplayListDrawingContext>(FloatRect(FloatPoint::zero(), canvas()->size()));
-
- return &m_recordingContext->context;
- }
-
return canvas()->drawingContext();
}
-static RefPtr<ImageData> createEmptyImageData(const IntSize& size)
+static PassRefPtr<ImageData> createEmptyImageData(const IntSize& size)
{
- if (RefPtr<ImageData> data = ImageData::create(size)) {
- data->data()->zeroFill();
- return data;
- }
+ Checked<int, RecordOverflow> dataSize = 4;
+ dataSize *= size.width();
+ dataSize *= size.height();
+ if (dataSize.hasOverflowed())
+ return 0;
- return nullptr;
+ RefPtr<ImageData> data = ImageData::create(size);
+ data->data()->zeroFill();
+ return data.release();
}
-RefPtr<ImageData> CanvasRenderingContext2D::createImageData(RefPtr<ImageData>&& imageData, ExceptionCode& ec) const
+PassRefPtr<ImageData> CanvasRenderingContext2D::createImageData(PassRefPtr<ImageData> imageData, ExceptionCode& ec) const
{
if (!imageData) {
ec = NOT_SUPPORTED_ERR;
- return nullptr;
+ return 0;
}
return createEmptyImageData(imageData->size());
}
-RefPtr<ImageData> CanvasRenderingContext2D::createImageData(float sw, float sh, ExceptionCode& ec) const
+PassRefPtr<ImageData> CanvasRenderingContext2D::createImageData(float sw, float sh, ExceptionCode& ec) const
{
ec = 0;
if (!sw || !sh) {
ec = INDEX_SIZE_ERR;
- return nullptr;
+ return 0;
}
if (!std::isfinite(sw) || !std::isfinite(sh)) {
- ec = TypeError;
- return nullptr;
+ ec = NOT_SUPPORTED_ERR;
+ return 0;
}
+#if PLATFORM(IOS)
+ // If the canvas element was created before Document had a Frame,
+ // then no maximumDecodedImageSize was set.
+ if (!canvas()->maximumDecodedImageSize()) {
+ if (Settings* settings = canvas()->document().settings())
+ canvas()->setMaximumDecodedImageSize(settings->maximumDecodedImageSize());
+ }
+#endif
+
FloatSize logicalSize(fabs(sw), fabs(sh));
if (!logicalSize.isExpressibleAsIntSize())
- return nullptr;
+ return 0;
IntSize size = expandedIntSize(logicalSize);
if (size.width() < 1)
@@ -2039,32 +1837,32 @@ RefPtr<ImageData> CanvasRenderingContext2D::createImageData(float sw, float sh,
return createEmptyImageData(size);
}
-RefPtr<ImageData> CanvasRenderingContext2D::getImageData(float sx, float sy, float sw, float sh, ExceptionCode& ec) const
+PassRefPtr<ImageData> CanvasRenderingContext2D::getImageData(float sx, float sy, float sw, float sh, ExceptionCode& ec) const
{
return getImageData(ImageBuffer::LogicalCoordinateSystem, sx, sy, sw, sh, ec);
}
-RefPtr<ImageData> CanvasRenderingContext2D::webkitGetImageDataHD(float sx, float sy, float sw, float sh, ExceptionCode& ec) const
+PassRefPtr<ImageData> CanvasRenderingContext2D::webkitGetImageDataHD(float sx, float sy, float sw, float sh, ExceptionCode& ec) const
{
return getImageData(ImageBuffer::BackingStoreCoordinateSystem, sx, sy, sw, sh, ec);
}
-RefPtr<ImageData> CanvasRenderingContext2D::getImageData(ImageBuffer::CoordinateSystem coordinateSystem, float sx, float sy, float sw, float sh, ExceptionCode& ec) const
+PassRefPtr<ImageData> CanvasRenderingContext2D::getImageData(ImageBuffer::CoordinateSystem coordinateSystem, float sx, float sy, float sw, float sh, ExceptionCode& ec) const
{
if (!canvas()->originClean()) {
- static NeverDestroyed<String> consoleMessage(ASCIILiteral("Unable to get image data from canvas because the canvas has been tainted by cross-origin data."));
- canvas()->document().addConsoleMessage(MessageSource::Security, MessageLevel::Error, consoleMessage);
+ DEFINE_STATIC_LOCAL(String, consoleMessage, (ASCIILiteral("Unable to get image data from canvas because the canvas has been tainted by cross-origin data.")));
+ canvas()->document().addConsoleMessage(SecurityMessageSource, ErrorMessageLevel, consoleMessage);
ec = SECURITY_ERR;
- return nullptr;
+ return 0;
}
if (!sw || !sh) {
ec = INDEX_SIZE_ERR;
- return nullptr;
+ return 0;
}
if (!std::isfinite(sx) || !std::isfinite(sy) || !std::isfinite(sw) || !std::isfinite(sh)) {
ec = NOT_SUPPORTED_ERR;
- return nullptr;
+ return 0;
}
if (sw < 0) {
@@ -2076,13 +1874,22 @@ RefPtr<ImageData> CanvasRenderingContext2D::getImageData(ImageBuffer::Coordinate
sh = -sh;
}
+#if PLATFORM(IOS)
+ // If the canvas element was created before Document had a Frame,
+ // then no maximumDecodedImageSize was set.
+ if (!canvas()->maximumDecodedImageSize()) {
+ if (Settings* settings = canvas()->document().settings())
+ canvas()->setMaximumDecodedImageSize(settings->maximumDecodedImageSize());
+ }
+#endif
+
FloatRect logicalRect(sx, sy, sw, sh);
if (logicalRect.width() < 1)
logicalRect.setWidth(1);
if (logicalRect.height() < 1)
logicalRect.setHeight(1);
if (!logicalRect.isExpressibleAsIntRect())
- return nullptr;
+ return 0;
IntRect imageDataRect = enclosingIntRect(logicalRect);
ImageBuffer* buffer = canvas()->buffer();
@@ -2091,7 +1898,7 @@ RefPtr<ImageData> CanvasRenderingContext2D::getImageData(ImageBuffer::Coordinate
RefPtr<Uint8ClampedArray> byteArray = buffer->getUnmultipliedImageData(imageDataRect, coordinateSystem);
if (!byteArray)
- return nullptr;
+ return 0;
return ImageData::create(imageDataRect.size(), byteArray.release());
}
@@ -2125,27 +1932,6 @@ void CanvasRenderingContext2D::webkitPutImageDataHD(ImageData* data, float dx, f
putImageData(data, ImageBuffer::BackingStoreCoordinateSystem, dx, dy, dirtyX, dirtyY, dirtyWidth, dirtyHeight, ec);
}
-void CanvasRenderingContext2D::drawFocusIfNeeded(Element* element)
-{
- drawFocusIfNeededInternal(m_path, element);
-}
-
-void CanvasRenderingContext2D::drawFocusIfNeeded(DOMPath* path, Element* element)
-{
- drawFocusIfNeededInternal(path->path(), element);
-}
-
-void CanvasRenderingContext2D::drawFocusIfNeededInternal(const Path& path, Element* element)
-{
- GraphicsContext* context = drawingContext();
-
- if (!element || !element->focused() || !state().hasInvertibleTransform || path.isEmpty()
- || !element->isDescendantOf(canvas()) || !context)
- return;
-
- context->drawFocusRing(path, 1, 1, RenderTheme::focusRingColor());
-}
-
void CanvasRenderingContext2D::putImageData(ImageData* data, ImageBuffer::CoordinateSystem coordinateSystem, float dx, float dy, float dirtyX, float dirtyY,
float dirtyWidth, float dirtyHeight, ExceptionCode& ec)
{
@@ -2185,30 +1971,35 @@ void CanvasRenderingContext2D::putImageData(ImageData* data, ImageBuffer::Coordi
buffer->putByteArray(Unmultiplied, data->data(), IntSize(data->width(), data->height()), sourceRect, IntPoint(destOffset), coordinateSystem);
+ if (coordinateSystem == ImageBuffer::BackingStoreCoordinateSystem) {
+ FloatRect dirtyRect = destRect;
+ dirtyRect.scale(1 / canvas()->deviceScaleFactor());
+ destRect = enclosingIntRect(dirtyRect);
+ }
didDraw(destRect, CanvasDidDrawApplyNone); // ignore transform, shadow and clip
}
String CanvasRenderingContext2D::font() const
{
- if (!state().font.realized())
+ if (!state().m_realizedFont)
return defaultFont;
StringBuilder serializedFont;
- const auto& fontDescription = state().font.fontDescription();
+ const FontDescription& fontDescription = state().m_font.fontDescription();
if (fontDescription.italic())
serializedFont.appendLiteral("italic ");
- if (fontDescription.variantCaps() == FontVariantCaps::Small)
+ if (fontDescription.smallCaps() == FontSmallCapsOn)
serializedFont.appendLiteral("small-caps ");
serializedFont.appendNumber(fontDescription.computedPixelSize());
serializedFont.appendLiteral("px");
- for (unsigned i = 0; i < fontDescription.familyCount(); ++i) {
+ for (unsigned i = 0; i < state().m_font.familyCount(); ++i) {
if (i)
serializedFont.append(',');
// FIXME: We should append family directly to serializedFont rather than building a temporary string.
- String family = fontDescription.familyAt(i);
+ String family = state().m_font.familyAt(i);
if (family.startsWith("-webkit-"))
family = family.substring(8);
if (family.contains(' '))
@@ -2223,11 +2014,11 @@ String CanvasRenderingContext2D::font() const
void CanvasRenderingContext2D::setFont(const String& newFont)
{
- if (newFont == state().unparsedFont && state().font.realized())
+ if (newFont == state().m_unparsedFont && state().m_realizedFont)
return;
RefPtr<MutableStyleProperties> parsedStyle = MutableStyleProperties::create();
- CSSParser::parseValue(parsedStyle.get(), CSSPropertyFont, newFont, true, strictToCSSParserMode(!m_usesCSSCompatibilityParseMode), nullptr);
+ CSSParser::parseValue(parsedStyle.get(), CSSPropertyFont, newFont, true, strictToCSSParserMode(!m_usesCSSCompatibilityParseMode), 0);
if (parsedStyle->isEmpty())
return;
@@ -2241,19 +2032,15 @@ void CanvasRenderingContext2D::setFont(const String& newFont)
// The parse succeeded.
String newFontSafeCopy(newFont); // Create a string copy since newFont can be deleted inside realizeSaves.
realizeSaves();
- modifiableState().unparsedFont = newFontSafeCopy;
+ modifiableState().m_unparsedFont = newFontSafeCopy;
// Map the <canvas> font into the text style. If the font uses keywords like larger/smaller, these will work
// relative to the canvas.
- Ref<RenderStyle> newStyle = RenderStyle::create();
-
- Document& document = canvas()->document();
- document.updateStyleIfNeeded();
-
+ RefPtr<RenderStyle> newStyle = RenderStyle::create();
if (RenderStyle* computedStyle = canvas()->computedStyle())
newStyle->setFontDescription(computedStyle->fontDescription());
else {
- FontCascadeDescription defaultFontDescription;
+ FontDescription defaultFontDescription;
defaultFontDescription.setOneFamily(defaultFontFamily);
defaultFontDescription.setSpecifiedSize(defaultFontSize);
defaultFontDescription.setComputedSize(defaultFontSize);
@@ -2261,13 +2048,13 @@ void CanvasRenderingContext2D::setFont(const String& newFont)
newStyle->setFontDescription(defaultFontDescription);
}
- newStyle->fontCascade().update(&document.fontSelector());
+ newStyle->font().update(newStyle->font().fontSelector());
// Now map the font property longhands into the style.
- StyleResolver& styleResolver = canvas()->styleResolver();
- styleResolver.applyPropertyToStyle(CSSPropertyFontFamily, parsedStyle->getPropertyCSSValue(CSSPropertyFontFamily).get(), &newStyle.get());
+ StyleResolver& styleResolver = canvas()->document().ensureStyleResolver();
+ styleResolver.applyPropertyToStyle(CSSPropertyFontFamily, parsedStyle->getPropertyCSSValue(CSSPropertyFontFamily).get(), newStyle.get());
styleResolver.applyPropertyToCurrentStyle(CSSPropertyFontStyle, parsedStyle->getPropertyCSSValue(CSSPropertyFontStyle).get());
- styleResolver.applyPropertyToCurrentStyle(CSSPropertyFontVariantCaps, parsedStyle->getPropertyCSSValue(CSSPropertyFontVariantCaps).get());
+ styleResolver.applyPropertyToCurrentStyle(CSSPropertyFontVariant, parsedStyle->getPropertyCSSValue(CSSPropertyFontVariant).get());
styleResolver.applyPropertyToCurrentStyle(CSSPropertyFontWeight, parsedStyle->getPropertyCSSValue(CSSPropertyFontWeight).get());
// As described in BUG66291, setting font-size and line-height on a font may entail a CSSPrimitiveValue::computeLengthDouble call,
@@ -2278,12 +2065,15 @@ void CanvasRenderingContext2D::setFont(const String& newFont)
styleResolver.updateFont();
styleResolver.applyPropertyToCurrentStyle(CSSPropertyLineHeight, parsedStyle->getPropertyCSSValue(CSSPropertyLineHeight).get());
- modifiableState().font.initialize(document.fontSelector(), newStyle);
+ modifiableState().m_font = newStyle->font();
+ modifiableState().m_font.update(styleResolver.fontSelector());
+ modifiableState().m_realizedFont = true;
+ styleResolver.fontSelector()->registerForInvalidationCallbacks(&modifiableState());
}
String CanvasRenderingContext2D::textAlign() const
{
- return textAlignName(state().textAlign);
+ return textAlignName(state().m_textAlign);
}
void CanvasRenderingContext2D::setTextAlign(const String& s)
@@ -2291,15 +2081,15 @@ void CanvasRenderingContext2D::setTextAlign(const String& s)
TextAlign align;
if (!parseTextAlign(s, align))
return;
- if (state().textAlign == align)
+ if (state().m_textAlign == align)
return;
realizeSaves();
- modifiableState().textAlign = align;
+ modifiableState().m_textAlign = align;
}
String CanvasRenderingContext2D::textBaseline() const
{
- return textBaselineName(state().textBaseline);
+ return textBaselineName(state().m_textBaseline);
}
void CanvasRenderingContext2D::setTextBaseline(const String& s)
@@ -2307,53 +2097,10 @@ void CanvasRenderingContext2D::setTextBaseline(const String& s)
TextBaseline baseline;
if (!parseTextBaseline(s, baseline))
return;
- if (state().textBaseline == baseline)
+ if (state().m_textBaseline == baseline)
return;
realizeSaves();
- modifiableState().textBaseline = baseline;
-}
-
-inline TextDirection CanvasRenderingContext2D::toTextDirection(Direction direction, RenderStyle** computedStyle) const
-{
- RenderStyle* style = (computedStyle || direction == Direction::Inherit) ? canvas()->computedStyle() : nullptr;
- if (computedStyle)
- *computedStyle = style;
- switch (direction) {
- case Direction::Inherit:
- return style ? style->direction() : LTR;
- case Direction::RTL:
- return RTL;
- case Direction::LTR:
- return LTR;
- }
- ASSERT_NOT_REACHED();
- return LTR;
-}
-
-String CanvasRenderingContext2D::direction() const
-{
- if (state().direction == Direction::Inherit)
- canvas()->document().updateStyleIfNeeded();
- return toTextDirection(state().direction) == RTL ? ASCIILiteral("rtl") : ASCIILiteral("ltr");
-}
-
-void CanvasRenderingContext2D::setDirection(const String& directionString)
-{
- Direction direction;
- if (directionString == "inherit")
- direction = Direction::Inherit;
- else if (directionString == "rtl")
- direction = Direction::RTL;
- else if (directionString == "ltr")
- direction = Direction::LTR;
- else
- return;
-
- if (state().direction == direction)
- return;
-
- realizeSaves();
- modifiableState().direction = direction;
+ modifiableState().m_textBaseline = baseline;
}
void CanvasRenderingContext2D::fillText(const String& text, float x, float y)
@@ -2396,7 +2143,7 @@ static void normalizeSpaces(String& text)
unsigned textLength = text.length();
Vector<UChar> charVector(textLength);
- StringView(text).getCharactersWithUpconvert(charVector.data());
+ memcpy(charVector.data(), text.deprecatedCharacters(), textLength * sizeof(UChar));
charVector[i++] = ' ';
@@ -2407,27 +2154,26 @@ static void normalizeSpaces(String& text)
text = String::adopt(charVector);
}
-Ref<TextMetrics> CanvasRenderingContext2D::measureText(const String& text)
+PassRefPtr<TextMetrics> CanvasRenderingContext2D::measureText(const String& text)
{
- Ref<TextMetrics> metrics = TextMetrics::create();
+ FontCachePurgePreventer fontCachePurgePreventer;
+
+ RefPtr<TextMetrics> metrics = TextMetrics::create();
String normalizedText = text;
normalizeSpaces(normalizedText);
- metrics->setWidth(fontProxy().width(TextRun(normalizedText)));
+ metrics->setWidth(accessFont().width(TextRun(normalizedText)));
- return metrics;
+ return metrics.release();
}
void CanvasRenderingContext2D::drawTextInternal(const String& text, float x, float y, bool fill, float maxWidth, bool useMaxWidth)
{
- const auto& fontProxy = this->fontProxy();
- const FontMetrics& fontMetrics = fontProxy.fontMetrics();
-
GraphicsContext* c = drawingContext();
if (!c)
return;
- if (!state().hasInvertibleTransform)
+ if (!state().m_hasInvertibleTransform)
return;
if (!std::isfinite(x) | !std::isfinite(y))
return;
@@ -2443,20 +2189,25 @@ void CanvasRenderingContext2D::drawTextInternal(const String& text, float x, flo
if (fill && gradient && gradient->isZeroSize())
return;
+ FontCachePurgePreventer fontCachePurgePreventer;
+
+ const Font& font = accessFont();
+ const FontMetrics& fontMetrics = font.fontMetrics();
+
String normalizedText = text;
normalizeSpaces(normalizedText);
// FIXME: Need to turn off font smoothing.
- RenderStyle* computedStyle;
- TextDirection direction = toTextDirection(state().direction, &computedStyle);
+ RenderStyle* computedStyle = canvas()->computedStyle();
+ TextDirection direction = computedStyle ? computedStyle->direction() : LTR;
bool isRTL = direction == RTL;
bool override = computedStyle ? isOverride(computedStyle->unicodeBidi()) : false;
- TextRun textRun(normalizedText, 0, 0, AllowTrailingExpansion, direction, override, true);
+ TextRun textRun(normalizedText, 0, 0, TextRun::AllowTrailingExpansion, direction, override, true, TextRun::NoRounding);
// Draw the item text at the correct point.
FloatPoint location(x, y);
- switch (state().textBaseline) {
+ switch (state().m_textBaseline) {
case TopTextBaseline:
case HangingTextBaseline:
location.setY(y + fontMetrics.ascent());
@@ -2474,12 +2225,12 @@ void CanvasRenderingContext2D::drawTextInternal(const String& text, float x, flo
break;
}
- float fontWidth = fontProxy.width(TextRun(normalizedText, 0, 0, AllowTrailingExpansion, direction, override));
+ float fontWidth = font.width(TextRun(normalizedText, 0, 0, TextRun::AllowTrailingExpansion, direction, override));
useMaxWidth = (useMaxWidth && maxWidth < fontWidth);
float width = useMaxWidth ? maxWidth : fontWidth;
- TextAlign align = state().textAlign;
+ TextAlign align = state().m_textAlign;
if (align == StartTextAlign)
align = isRTL ? RightTextAlign : LeftTextAlign;
else if (align == EndTextAlign)
@@ -2498,73 +2249,40 @@ void CanvasRenderingContext2D::drawTextInternal(const String& text, float x, flo
// The slop built in to this mask rect matches the heuristic used in FontCGWin.cpp for GDI text.
FloatRect textRect = FloatRect(location.x() - fontMetrics.height() / 2, location.y() - fontMetrics.ascent() - fontMetrics.lineGap(),
- width + fontMetrics.height(), fontMetrics.lineSpacing());
+ width + fontMetrics.height(), fontMetrics.lineSpacing());
if (!fill)
inflateStrokeRect(textRect);
#if USE(CG)
- const CanvasStyle& drawStyle = fill ? state().fillStyle : state().strokeStyle;
+ const CanvasStyle& drawStyle = fill ? state().m_fillStyle : state().m_strokeStyle;
if (drawStyle.canvasGradient() || drawStyle.canvasPattern()) {
-
IntRect maskRect = enclosingIntRect(textRect);
- // If we have a shadow, we need to draw it before the mask operation.
- // Follow a procedure similar to paintTextWithShadows in TextPainter.
-
- if (shouldDrawShadows()) {
- GraphicsContextStateSaver stateSaver(*c);
-
- FloatSize offset = FloatSize(0, 2 * maskRect.height());
-
- FloatSize shadowOffset;
- float shadowRadius;
- Color shadowColor;
- c->getShadow(shadowOffset, shadowRadius, shadowColor);
-
- FloatRect shadowRect(maskRect);
- shadowRect.inflate(shadowRadius * 1.4);
- shadowRect.move(shadowOffset * -1);
- c->clip(shadowRect);
-
- shadowOffset += offset;
-
- c->setLegacyShadow(shadowOffset, shadowRadius, shadowColor);
-
- if (fill)
- c->setFillColor(Color::black);
- else
- c->setStrokeColor(Color::black);
-
- fontProxy.drawBidiText(*c, textRun, location + offset, FontCascade::UseFallbackIfFontNotReady);
- }
-
std::unique_ptr<ImageBuffer> maskImage = c->createCompatibleBuffer(maskRect.size());
- if (!maskImage)
- return;
- GraphicsContext& maskImageContext = maskImage->context();
+ GraphicsContext* maskImageContext = maskImage->context();
if (fill)
- maskImageContext.setFillColor(Color::black);
+ maskImageContext->setFillColor(Color::black, ColorSpaceDeviceRGB);
else {
- maskImageContext.setStrokeColor(Color::black);
- maskImageContext.setStrokeThickness(c->strokeThickness());
+ maskImageContext->setStrokeColor(Color::black, ColorSpaceDeviceRGB);
+ maskImageContext->setStrokeThickness(c->strokeThickness());
}
- maskImageContext.setTextDrawingMode(fill ? TextModeFill : TextModeStroke);
+ maskImageContext->setTextDrawingMode(fill ? TextModeFill : TextModeStroke);
if (useMaxWidth) {
- maskImageContext.translate(location.x() - maskRect.x(), location.y() - maskRect.y());
+ maskImageContext->translate(location.x() - maskRect.x(), location.y() - maskRect.y());
// We draw when fontWidth is 0 so compositing operations (eg, a "copy" op) still work.
- maskImageContext.scale(FloatSize((fontWidth > 0 ? (width / fontWidth) : 0), 1));
- fontProxy.drawBidiText(maskImageContext, textRun, FloatPoint(0, 0), FontCascade::UseFallbackIfFontNotReady);
+ maskImageContext->scale(FloatSize((fontWidth > 0 ? (width / fontWidth) : 0), 1));
+ maskImageContext->drawBidiText(font, textRun, FloatPoint(0, 0), Font::UseFallbackIfFontNotReady);
} else {
- maskImageContext.translate(-maskRect.x(), -maskRect.y());
- fontProxy.drawBidiText(maskImageContext, textRun, location, FontCascade::UseFallbackIfFontNotReady);
+ maskImageContext->translate(-maskRect.x(), -maskRect.y());
+ maskImageContext->drawBidiText(font, textRun, location, Font::UseFallbackIfFontNotReady);
}
GraphicsContextStateSaver stateSaver(*c);
- c->clipToImageBuffer(*maskImage, maskRect);
+ c->clipToImageBuffer(maskImage.get(), maskRect);
drawStyle.applyFillColor(c);
c->fillRect(maskRect);
return;
@@ -2573,27 +2291,16 @@ void CanvasRenderingContext2D::drawTextInternal(const String& text, float x, flo
c->setTextDrawingMode(fill ? TextModeFill : TextModeStroke);
- GraphicsContextStateSaver stateSaver(*c);
if (useMaxWidth) {
+ GraphicsContextStateSaver stateSaver(*c);
c->translate(location.x(), location.y());
// We draw when fontWidth is 0 so compositing operations (eg, a "copy" op) still work.
c->scale(FloatSize((fontWidth > 0 ? (width / fontWidth) : 0), 1));
- location = FloatPoint();
- }
+ c->drawBidiText(font, textRun, FloatPoint(0, 0), Font::UseFallbackIfFontNotReady);
+ } else
+ c->drawBidiText(font, textRun, location, Font::UseFallbackIfFontNotReady);
- if (isFullCanvasCompositeMode(state().globalComposite)) {
- beginCompositeLayer();
- fontProxy.drawBidiText(*c, textRun, location, FontCascade::UseFallbackIfFontNotReady);
- endCompositeLayer();
- didDrawEntireCanvas();
- } else if (state().globalComposite == CompositeCopy) {
- clearCanvas();
- fontProxy.drawBidiText(*c, textRun, location, FontCascade::UseFallbackIfFontNotReady);
- didDrawEntireCanvas();
- } else {
- fontProxy.drawBidiText(*c, textRun, location, FontCascade::UseFallbackIfFontNotReady);
- didDraw(textRect);
- }
+ didDraw(textRect);
}
void CanvasRenderingContext2D::inflateStrokeRect(FloatRect& rect) const
@@ -2602,103 +2309,46 @@ void CanvasRenderingContext2D::inflateStrokeRect(FloatRect& rect) const
// This yields a slightly oversized rect but is very fast
// compared to Path::strokeBoundingRect().
static const float root2 = sqrtf(2);
- float delta = state().lineWidth / 2;
- if (state().lineJoin == MiterJoin)
- delta *= state().miterLimit;
- else if (state().lineCap == SquareCap)
+ float delta = state().m_lineWidth / 2;
+ if (state().m_lineJoin == MiterJoin)
+ delta *= state().m_miterLimit;
+ else if (state().m_lineCap == SquareCap)
delta *= root2;
rect.inflate(delta);
}
-auto CanvasRenderingContext2D::fontProxy() -> const FontProxy&
+const Font& CanvasRenderingContext2D::accessFont()
{
canvas()->document().updateStyleIfNeeded();
- if (!state().font.realized())
- setFont(state().unparsedFont);
- return state().font;
+ if (!state().m_realizedFont)
+ setFont(state().m_unparsedFont);
+ return state().m_font;
}
-#if ENABLE(ACCELERATED_2D_CANVAS)
+#if ENABLE(ACCELERATED_2D_CANVAS) && USE(ACCELERATED_COMPOSITING)
PlatformLayer* CanvasRenderingContext2D::platformLayer() const
{
return canvas()->buffer() ? canvas()->buffer()->platformLayer() : 0;
}
#endif
-static InterpolationQuality smoothingToInterpolationQuality(CanvasRenderingContext2D::SmoothingQuality quality)
-{
- switch (quality) {
- case CanvasRenderingContext2D::SmoothingQuality::Low:
- return InterpolationLow;
- case CanvasRenderingContext2D::SmoothingQuality::Medium:
- return InterpolationMedium;
- case CanvasRenderingContext2D::SmoothingQuality::High:
- return InterpolationHigh;
- }
-
- ASSERT_NOT_REACHED();
- return InterpolationLow;
-};
-
-String CanvasRenderingContext2D::imageSmoothingQuality() const
-{
- switch (state().imageSmoothingQuality) {
- case SmoothingQuality::Low:
- return ASCIILiteral("low");
- case SmoothingQuality::Medium:
- return ASCIILiteral("medium");
- case SmoothingQuality::High:
- return ASCIILiteral("high");
- }
-
- ASSERT_NOT_REACHED();
- return ASCIILiteral("low");
-}
-
-void CanvasRenderingContext2D::setImageSmoothingQuality(const String& smoothingQualityString)
-{
- SmoothingQuality quality;
- if (smoothingQualityString == "low")
- quality = SmoothingQuality::Low;
- else if (smoothingQualityString == "medium")
- quality = SmoothingQuality::Medium;
- else if (smoothingQualityString == "high")
- quality = SmoothingQuality::High;
- else {
- ASSERT_NOT_REACHED();
- return;
- }
-
- if (quality == state().imageSmoothingQuality)
- return;
-
- realizeSaves();
- modifiableState().imageSmoothingQuality = quality;
-
- if (!state().imageSmoothingEnabled)
- return;
-
- if (auto* context = drawingContext())
- context->setImageInterpolationQuality(smoothingToInterpolationQuality(quality));
-}
-
-bool CanvasRenderingContext2D::imageSmoothingEnabled() const
+bool CanvasRenderingContext2D::webkitImageSmoothingEnabled() const
{
- return state().imageSmoothingEnabled;
+ return state().m_imageSmoothingEnabled;
}
-void CanvasRenderingContext2D::setImageSmoothingEnabled(bool enabled)
+void CanvasRenderingContext2D::setWebkitImageSmoothingEnabled(bool enabled)
{
- if (enabled == state().imageSmoothingEnabled)
+ if (enabled == state().m_imageSmoothingEnabled)
return;
realizeSaves();
- modifiableState().imageSmoothingEnabled = enabled;
+ modifiableState().m_imageSmoothingEnabled = enabled;
GraphicsContext* c = drawingContext();
if (c)
- c->setImageInterpolationQuality(enabled ? smoothingToInterpolationQuality(state().imageSmoothingQuality) : InterpolationNone);
+ c->setImageInterpolationQuality(enabled ? DefaultInterpolationQuality : InterpolationNone);
}
} // namespace WebCore