diff options
Diffstat (limited to 'Source/WebCore/html/canvas/CanvasRenderingContext2D.h')
-rw-r--r-- | Source/WebCore/html/canvas/CanvasRenderingContext2D.h | 227 |
1 files changed, 146 insertions, 81 deletions
diff --git a/Source/WebCore/html/canvas/CanvasRenderingContext2D.h b/Source/WebCore/html/canvas/CanvasRenderingContext2D.h index 3fa2a04d8..a334873dc 100644 --- a/Source/WebCore/html/canvas/CanvasRenderingContext2D.h +++ b/Source/WebCore/html/canvas/CanvasRenderingContext2D.h @@ -10,10 +10,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 COMPUTER, INC. ``AS IS'' AND ANY + * THIS SOFTWARE IS PROVIDED BY APPLE 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 COMPUTER, INC. OR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE 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 @@ -31,26 +31,22 @@ #include "CanvasRenderingContext.h" #include "CanvasStyle.h" #include "Color.h" -#include "ColorSpace.h" #include "FloatSize.h" -#include "Font.h" +#include "FontCascade.h" +#include "GraphicsContext.h" #include "GraphicsTypes.h" #include "ImageBuffer.h" #include "Path.h" +#include "PlatformLayer.h" +#include "TextFlags.h" #include <wtf/Vector.h> #include <wtf/text/WTFString.h> -#if USE(ACCELERATED_COMPOSITING) -#include "PlatformLayer.h" -#endif - namespace WebCore { class CanvasGradient; class CanvasPattern; -#if ENABLE(CANVAS_PATH) class DOMPath; -#endif class FloatRect; class GraphicsContext; class HTMLCanvasElement; @@ -61,18 +57,15 @@ class TextMetrics; typedef int ExceptionCode; -class CanvasRenderingContext2D : public CanvasRenderingContext, public CanvasPathMethods { +class CanvasRenderingContext2D final : public CanvasRenderingContext, public CanvasPathMethods { public: - static PassOwnPtr<CanvasRenderingContext2D> create(HTMLCanvasElement* canvas, bool usesCSSCompatibilityParseMode, bool usesDashboardCompatibilityMode) - { - return adoptPtr(new CanvasRenderingContext2D(canvas, usesCSSCompatibilityParseMode, usesDashboardCompatibilityMode)); - } + CanvasRenderingContext2D(HTMLCanvasElement*, bool usesCSSCompatibilityParseMode, bool usesDashboardCompatibilityMode); virtual ~CanvasRenderingContext2D(); - const CanvasStyle& strokeStyle() const { return state().m_strokeStyle; } + const CanvasStyle& strokeStyle() const { return state().strokeStyle; } void setStrokeStyle(CanvasStyle); - const CanvasStyle& fillStyle() const { return state().m_fillStyle; } + const CanvasStyle& fillStyle() const { return state().fillStyle; } void setFillStyle(CanvasStyle); float lineWidth() const; @@ -139,17 +132,20 @@ public: void beginPath(); -#if ENABLE(CANVAS_PATH) - PassRefPtr<DOMPath> currentPath(); - void setCurrentPath(DOMPath*); -#endif - void fill(const String& winding = "nonzero"); + void fill(const String& winding = ASCIILiteral("nonzero")); void stroke(); - void clip(const String& winding = "nonzero"); + void clip(const String& winding = ASCIILiteral("nonzero")); + + void fill(DOMPath*, const String& winding = ASCIILiteral("nonzero")); + void stroke(DOMPath*); + void clip(DOMPath*, const String& winding = ASCIILiteral("nonzero")); - bool isPointInPath(const float x, const float y, const String& winding = "nonzero"); + bool isPointInPath(const float x, const float y, const String& winding = ASCIILiteral("nonzero")); bool isPointInStroke(const float x, const float y); + bool isPointInPath(DOMPath*, const float x, const float y, const String& winding = ASCIILiteral("nonzero")); + bool isPointInStroke(DOMPath*, const float x, const float y); + void clearRect(float x, float y, float width, float height); void fillRect(float x, float y, float width, float height); void strokeRect(float x, float y, float width, float height); @@ -187,21 +183,24 @@ public: void setCompositeOperation(const String&); - PassRefPtr<CanvasGradient> createLinearGradient(float x0, float y0, float x1, float y1, ExceptionCode&); - PassRefPtr<CanvasGradient> createRadialGradient(float x0, float y0, float r0, float x1, float y1, float r1, ExceptionCode&); - PassRefPtr<CanvasPattern> createPattern(HTMLImageElement*, const String& repetitionType, ExceptionCode&); - PassRefPtr<CanvasPattern> createPattern(HTMLCanvasElement*, const String& repetitionType, ExceptionCode&); + RefPtr<CanvasGradient> createLinearGradient(float x0, float y0, float x1, float y1, ExceptionCode&); + RefPtr<CanvasGradient> createRadialGradient(float x0, float y0, float r0, float x1, float y1, float r1, ExceptionCode&); + RefPtr<CanvasPattern> createPattern(HTMLImageElement*, const String& repetitionType, ExceptionCode&); + RefPtr<CanvasPattern> createPattern(HTMLCanvasElement*, const String& repetitionType, ExceptionCode&); - PassRefPtr<ImageData> createImageData(PassRefPtr<ImageData>, ExceptionCode&) const; - PassRefPtr<ImageData> createImageData(float width, float height, ExceptionCode&) const; - PassRefPtr<ImageData> getImageData(float sx, float sy, float sw, float sh, ExceptionCode&) const; - PassRefPtr<ImageData> webkitGetImageDataHD(float sx, float sy, float sw, float sh, ExceptionCode&) const; + RefPtr<ImageData> createImageData(RefPtr<ImageData>&&, ExceptionCode&) const; + RefPtr<ImageData> createImageData(float width, float height, ExceptionCode&) const; + RefPtr<ImageData> getImageData(float sx, float sy, float sw, float sh, ExceptionCode&) const; + RefPtr<ImageData> webkitGetImageDataHD(float sx, float sy, float sw, float sh, ExceptionCode&) const; void putImageData(ImageData*, float dx, float dy, ExceptionCode&); void putImageData(ImageData*, float dx, float dy, float dirtyX, float dirtyY, float dirtyWidth, float dirtyHeight, ExceptionCode&); void webkitPutImageDataHD(ImageData*, float dx, float dy, ExceptionCode&); void webkitPutImageDataHD(ImageData*, float dx, float dy, float dirtyX, float dirtyY, float dirtyWidth, float dirtyHeight, ExceptionCode&); - float webkitBackingStorePixelRatio() const { return canvas()->deviceScaleFactor(); } + void drawFocusIfNeeded(Element*); + void drawFocusIfNeeded(DOMPath*, Element*); + + float webkitBackingStorePixelRatio() const { return 1; } void reset(); @@ -214,55 +213,101 @@ public: String textBaseline() const; void setTextBaseline(const String&); + String direction() const; + void setDirection(const String&); + void fillText(const String& text, float x, float y); void fillText(const String& text, float x, float y, float maxWidth); void strokeText(const String& text, float x, float y); void strokeText(const String& text, float x, float y, float maxWidth); - PassRefPtr<TextMetrics> measureText(const String& text); + Ref<TextMetrics> measureText(const String& text); + + LineCap getLineCap() const { return state().lineCap; } + LineJoin getLineJoin() const { return state().lineJoin; } + + bool imageSmoothingEnabled() const; + void setImageSmoothingEnabled(bool); + + String imageSmoothingQuality() const; + void setImageSmoothingQuality(const String&); - LineCap getLineCap() const { return state().m_lineCap; } - LineJoin getLineJoin() const { return state().m_lineJoin; } + enum class SmoothingQuality { + Low, + Medium, + High + }; + + bool usesDisplayListDrawing() const { return m_usesDisplayListDrawing; }; + void setUsesDisplayListDrawing(bool flag) { m_usesDisplayListDrawing = flag; }; - bool webkitImageSmoothingEnabled() const; - void setWebkitImageSmoothingEnabled(bool); + bool tracksDisplayListReplay() const { return m_tracksDisplayListReplay; } + void setTracksDisplayListReplay(bool); + + String displayListAsText(DisplayList::AsTextFlags) const; + String replayDisplayListAsText(DisplayList::AsTextFlags) const; private: - struct State : FontSelectorClient { + enum class Direction { + Inherit, + RTL, + LTR + }; + + class FontProxy : public FontSelectorClient { + public: + FontProxy() = default; + virtual ~FontProxy(); + FontProxy(const FontProxy&); + FontProxy& operator=(const FontProxy&); + + bool realized() const { return m_font.fontSelector(); } + void initialize(FontSelector&, RenderStyle&); + FontMetrics fontMetrics() const; + const FontCascadeDescription& fontDescription() const; + float width(const TextRun&) const; + void drawBidiText(GraphicsContext&, const TextRun&, const FloatPoint&, FontCascade::CustomFontNotReadyAction) const; + + private: + void update(FontSelector&); + virtual void fontsNeedUpdate(FontSelector&) override; + + FontCascade m_font; + }; + + struct State final { State(); - virtual ~State(); State(const State&); State& operator=(const State&); - virtual void fontsNeedUpdate(FontSelector*) OVERRIDE; - - String m_unparsedStrokeColor; - String m_unparsedFillColor; - CanvasStyle m_strokeStyle; - CanvasStyle m_fillStyle; - float m_lineWidth; - LineCap m_lineCap; - LineJoin m_lineJoin; - float m_miterLimit; - FloatSize m_shadowOffset; - float m_shadowBlur; - RGBA32 m_shadowColor; - float m_globalAlpha; - CompositeOperator m_globalComposite; - BlendMode m_globalBlend; - AffineTransform m_transform; - bool m_invertibleCTM; - Vector<float> m_lineDash; - float m_lineDashOffset; - bool m_imageSmoothingEnabled; + String unparsedStrokeColor; + String unparsedFillColor; + CanvasStyle strokeStyle; + CanvasStyle fillStyle; + float lineWidth; + LineCap lineCap; + LineJoin lineJoin; + float miterLimit; + FloatSize shadowOffset; + float shadowBlur; + RGBA32 shadowColor; + float globalAlpha; + CompositeOperator globalComposite; + BlendMode globalBlend; + AffineTransform transform; + bool hasInvertibleTransform; + Vector<float> lineDash; + float lineDashOffset; + bool imageSmoothingEnabled; + SmoothingQuality imageSmoothingQuality; // Text state. - TextAlign m_textAlign; - TextBaseline m_textBaseline; + TextAlign textAlign; + TextBaseline textBaseline; + Direction direction; - String m_unparsedFont; - Font m_font; - bool m_realizedFont; + String unparsedFont; + FontProxy font; }; enum CanvasDidDrawOption { @@ -273,8 +318,6 @@ private: CanvasDidDrawApplyAll = 0xffffffff }; - CanvasRenderingContext2D(HTMLCanvasElement*, bool usesCSSCompatibilityParseMode, bool usesDashboardCompatibilityMode); - State& modifiableState() { ASSERT(!m_unrealizedSaveCount); return m_stateStack.last(); } const State& state() const { return m_stateStack.last(); } @@ -286,6 +329,8 @@ private: void didDraw(const FloatRect&, unsigned options = CanvasDidDrawApplyAll); void didDrawEntireCanvas(); + void paintRenderingResultsToCanvas() override; + GraphicsContext* drawingContext() const; void unwindStateStack(); @@ -301,48 +346,68 @@ private: void drawTextInternal(const String& text, float x, float y, bool fill, float maxWidth = 0, bool useMaxWidth = false); - const Font& accessFont(); + // The relationship between FontCascade and CanvasRenderingContext2D::FontProxy must hold certain invariants. + // Therefore, all font operations must pass through the State. + const FontProxy& fontProxy(); #if ENABLE(DASHBOARD_SUPPORT) void clearPathForDashboardBackwardCompatibilityMode(); #endif + void beginCompositeLayer(); + void endCompositeLayer(); + + void fillInternal(const Path&, const String& winding); + void strokeInternal(const Path&); + void clipInternal(const Path&, const String& winding); + + bool isPointInPathInternal(const Path&, float x, float y, const String& winding); + bool isPointInStrokeInternal(const Path&, float x, float y); + + void drawFocusIfNeededInternal(const Path&, Element*); + void clearCanvas(); Path transformAreaToDevice(const Path&) const; Path transformAreaToDevice(const FloatRect&) const; bool rectContainsCanvas(const FloatRect&) const; template<class T> IntRect calculateCompositingBufferRect(const T&, IntSize*); - PassOwnPtr<ImageBuffer> createCompositingBuffer(const IntRect&); - void compositeBuffer(ImageBuffer*, const IntRect&, CompositeOperator); + std::unique_ptr<ImageBuffer> createCompositingBuffer(const IntRect&); + void compositeBuffer(ImageBuffer&, const IntRect&, CompositeOperator); void inflateStrokeRect(FloatRect&) const; - template<class T> void fullCanvasCompositedFill(const T&); - template<class T> void fullCanvasCompositedDrawImage(T*, ColorSpace, const FloatRect&, const FloatRect&, CompositeOperator); + template<class T> void fullCanvasCompositedDrawImage(T&, const FloatRect&, const FloatRect&, CompositeOperator); - void prepareGradientForDashboard(CanvasGradient* gradient) const; + void prepareGradientForDashboard(CanvasGradient& gradient) const; - PassRefPtr<ImageData> getImageData(ImageBuffer::CoordinateSystem, float sx, float sy, float sw, float sh, ExceptionCode&) const; + RefPtr<ImageData> getImageData(ImageBuffer::CoordinateSystem, float sx, float sy, float sw, float sh, ExceptionCode&) const; void putImageData(ImageData*, ImageBuffer::CoordinateSystem, float dx, float dy, float dirtyX, float dirtyY, float dirtyWidth, float dirtyHeight, ExceptionCode&); - virtual bool is2d() const OVERRIDE { return true; } - virtual bool isAccelerated() const OVERRIDE; + virtual bool is2d() const override { return true; } + virtual bool isAccelerated() const override; - virtual bool isTransformInvertible() const { return state().m_invertibleCTM; } + virtual bool hasInvertibleTransform() const override { return state().hasInvertibleTransform; } + TextDirection toTextDirection(Direction, RenderStyle** computedStyle = nullptr) const; -#if ENABLE(ACCELERATED_2D_CANVAS) && USE(ACCELERATED_COMPOSITING) - virtual PlatformLayer* platformLayer() const OVERRIDE; +#if ENABLE(ACCELERATED_2D_CANVAS) + virtual PlatformLayer* platformLayer() const override; #endif Vector<State, 1> m_stateStack; - unsigned m_unrealizedSaveCount; + unsigned m_unrealizedSaveCount { 0 }; bool m_usesCSSCompatibilityParseMode; #if ENABLE(DASHBOARD_SUPPORT) bool m_usesDashboardCompatibilityMode; #endif + + bool m_usesDisplayListDrawing { false }; + bool m_tracksDisplayListReplay { false }; + mutable std::unique_ptr<struct DisplayListDrawingContext> m_recordingContext; }; } // namespace WebCore +SPECIALIZE_TYPE_TRAITS_CANVASRENDERINGCONTEXT(WebCore::CanvasRenderingContext2D, is2d()) + #endif |