Move ImageBuffer:clip() into GraphicsContextCG
[WebKit-https.git] / Source / WebCore / platform / graphics / GraphicsContext.h
index 5418666..c83f408 100644 (file)
@@ -32,6 +32,7 @@
 #include "FloatRect.h"
 #include "FontCascade.h"
 #include "Gradient.h"
+#include "GraphicsTypes.h"
 #include "Image.h"
 #include "ImageOrientation.h"
 #include "Path.h"
@@ -73,7 +74,6 @@ namespace WebCore {
     const int cMisspellingLinePatternGapWidth = 1;
 
     class AffineTransform;
-    class DrawingBuffer;
     class FloatRoundedRect;
     class Gradient;
     class GraphicsContextPlatformPrivate;
@@ -84,9 +84,6 @@ namespace WebCore {
     class GraphicsContext3D;
     class TextRun;
     class TransformationMatrix;
-#if PLATFORM(IOS)
-    struct BidiStatus;
-#endif
 
     enum TextDrawingMode {
         TextModeFill = 1 << 0,
@@ -116,20 +113,9 @@ namespace WebCore {
 
     struct GraphicsContextState {
         GraphicsContextState()
-            : strokeThickness(0)
-            , shadowBlur(0)
-            , textDrawingMode(TextModeFill)
-            , strokeColor(Color::black)
-            , fillColor(Color::black)
-            , strokeStyle(SolidStroke)
-            , fillRule(RULE_NONZERO)
-            , strokeColorSpace(ColorSpaceDeviceRGB)
-            , fillColorSpace(ColorSpaceDeviceRGB)
-            , shadowColorSpace(ColorSpaceDeviceRGB)
-            , compositeOperator(CompositeSourceOver)
-            , blendMode(BlendModeNormal)
-            , shouldAntialias(true)
+            : shouldAntialias(true)
             , shouldSmoothFonts(true)
+            , antialiasedFontDilationEnabled(true)
             , shouldSubpixelQuantizeFonts(true)
             , paintingDisabled(false)
             , shadowsIgnoreTransforms(false)
@@ -150,27 +136,29 @@ namespace WebCore {
 
         FloatSize shadowOffset;
 
-        float strokeThickness;
-        float shadowBlur;
+        float strokeThickness { 0 };
+        float shadowBlur { 0 };
 
-        TextDrawingModeFlags textDrawingMode;
+        TextDrawingModeFlags textDrawingMode { TextModeFill };
 
-        Color strokeColor;
-        Color fillColor;
+        Color strokeColor { Color::black };
+        Color fillColor { Color::black };
         Color shadowColor;
 
-        StrokeStyle strokeStyle;
-        WindRule fillRule;
+        StrokeStyle strokeStyle { SolidStroke };
+        WindRule fillRule { RULE_NONZERO };
 
-        ColorSpace strokeColorSpace;
-        ColorSpace fillColorSpace;
-        ColorSpace shadowColorSpace;
+        ColorSpace strokeColorSpace { ColorSpaceDeviceRGB };
+        ColorSpace fillColorSpace { ColorSpaceDeviceRGB };
+        ColorSpace shadowColorSpace { ColorSpaceDeviceRGB };
 
-        CompositeOperator compositeOperator;
-        BlendMode blendMode;
+        float alpha { 1 };
+        CompositeOperator compositeOperator { CompositeSourceOver };
+        BlendMode blendMode { BlendModeNormal };
 
         bool shouldAntialias : 1;
         bool shouldSmoothFonts : 1;
+        bool antialiasedFontDilationEnabled : 1;
         bool shouldSubpixelQuantizeFonts : 1;
         bool paintingDisabled : 1;
         bool shadowsIgnoreTransforms : 1;
@@ -219,47 +207,53 @@ namespace WebCore {
 
         WEBCORE_EXPORT PlatformGraphicsContext* platformContext() const;
 
-        float strokeThickness() const;
         void setStrokeThickness(float);
-        StrokeStyle strokeStyle() const;
+        float strokeThickness() const { return m_state.strokeThickness; }
+
         void setStrokeStyle(StrokeStyle);
-        Color strokeColor() const;
-        ColorSpace strokeColorSpace() const;
+        StrokeStyle strokeStyle() const { return m_state.strokeStyle; }
+
         WEBCORE_EXPORT void setStrokeColor(const Color&, ColorSpace);
+        Color strokeColor() const { return m_state.strokeColor; }
+        ColorSpace strokeColorSpace() const { return m_state.strokeColorSpace; }
 
         void setStrokePattern(Ref<Pattern>&&);
-        Pattern* strokePattern() const;
+        Pattern* strokePattern() const { return m_state.strokePattern.get(); }
 
         void setStrokeGradient(Ref<Gradient>&&);
-        Gradient* strokeGradient() const;
+        Gradient* strokeGradient() const { return m_state.strokeGradient.get(); }
 
-        WindRule fillRule() const;
-        void setFillRule(WindRule);
-        Color fillColor() const;
-        ColorSpace fillColorSpace() const;
+        void setFillRule(WindRule fillRule) { m_state.fillRule = fillRule; }
+        WindRule fillRule() const { return m_state.fillRule; }
+    
         WEBCORE_EXPORT void setFillColor(const Color&, ColorSpace);
+        Color fillColor() const { return m_state.fillColor; }
+        ColorSpace fillColorSpace() const { return m_state.fillColorSpace; }
 
         void setFillPattern(Ref<Pattern>&&);
-        Pattern* fillPattern() const;
+        Pattern* fillPattern() const { return m_state.fillPattern.get(); }
 
         WEBCORE_EXPORT void setFillGradient(Ref<Gradient>&&);
-        Gradient* fillGradient() const;
+        Gradient* fillGradient() const { return m_state.fillGradient.get(); }
 
-        void setShadowsIgnoreTransforms(bool);
-        bool shadowsIgnoreTransforms() const;
+        void setShadowsIgnoreTransforms(bool shadowsIgnoreTransforms) { m_state.shadowsIgnoreTransforms = shadowsIgnoreTransforms; }
+        bool shadowsIgnoreTransforms() const { return m_state.shadowsIgnoreTransforms; }
 
         WEBCORE_EXPORT void setShouldAntialias(bool);
-        bool shouldAntialias() const;
+        bool shouldAntialias() const { return m_state.shouldAntialias; }
+
+        WEBCORE_EXPORT void setAntialiasedFontDilationEnabled(bool);
+        bool antialiasedFontDilationEnabled() const { return m_state.antialiasedFontDilationEnabled; }
 
         WEBCORE_EXPORT void setShouldSmoothFonts(bool);
-        bool shouldSmoothFonts() const;
+        bool shouldSmoothFonts() const { return m_state.shouldSmoothFonts; }
 
         // Normally CG enables subpixel-quantization because it improves the performance of aligning glyphs.
         // In some cases we have to disable to to ensure a high-quality output of the glyphs.
-        void setShouldSubpixelQuantizeFonts(bool);
-        bool shouldSubpixelQuantizeFonts() const;
+        void setShouldSubpixelQuantizeFonts(bool shouldSubpixelQuantizeFonts) { m_state.shouldSubpixelQuantizeFonts = shouldSubpixelQuantizeFonts; }
+        bool shouldSubpixelQuantizeFonts() const { return m_state.shouldSubpixelQuantizeFonts; }
 
-        const GraphicsContextState& state() const;
+        const GraphicsContextState& state() const { return m_state; }
 
 #if USE(CG)
         void applyStrokePattern();
@@ -268,6 +262,8 @@ namespace WebCore {
 
         WEBCORE_EXPORT void drawNativeImage(PassNativeImagePtr, const FloatSize& selfSize, ColorSpace styleColorSpace, const FloatRect& destRect, const FloatRect& srcRect, CompositeOperator = CompositeSourceOver, BlendMode = BlendModeNormal, ImageOrientation = DefaultImageOrientation);
 
+        void clipToNativeImage(PassNativeImagePtr, const FloatRect& destRect, const FloatSize& bufferSize);
+
         // Allow font smoothing (LCD antialiasing). Not part of the graphics state.
         void setAllowsFontSmoothing(bool);
         
@@ -277,6 +273,7 @@ namespace WebCore {
         WEBCORE_EXPORT void setIsAcceleratedContext(bool);
 #endif
         bool isAcceleratedContext() const;
+        RenderingMode renderingMode() const { return isAcceleratedContext() ? Accelerated : Unaccelerated; }
 
         WEBCORE_EXPORT void save();
         WEBCORE_EXPORT void restore();
@@ -313,18 +310,19 @@ namespace WebCore {
 
         WEBCORE_EXPORT void strokeRect(const FloatRect&, float lineWidth);
 
-        WEBCORE_EXPORT void drawImage(Image*, ColorSpace, const FloatPoint& destination, const ImagePaintingOptions& = ImagePaintingOptions());
-        void drawImage(Image*, ColorSpace, const FloatRect& destination, const ImagePaintingOptions& = ImagePaintingOptions());
-        void drawImage(Image*, ColorSpace, const FloatRect& destination, const FloatRect& source, const ImagePaintingOptions& = ImagePaintingOptions());
+        WEBCORE_EXPORT void drawImage(Image&, ColorSpace, const FloatPoint& destination, const ImagePaintingOptions& = ImagePaintingOptions());
+        WEBCORE_EXPORT void drawImage(Image&, ColorSpace, const FloatRect& destination, const ImagePaintingOptions& = ImagePaintingOptions());
+        void drawImage(Image&, ColorSpace, const FloatRect& destination, const FloatRect& source, const ImagePaintingOptions& = ImagePaintingOptions());
 
-        void drawTiledImage(Image*, ColorSpace, const FloatRect& destination, const FloatPoint& source, const FloatSize& tileSize,
-            const ImagePaintingOptions& = ImagePaintingOptions());
-        void drawTiledImage(Image*, ColorSpace, const FloatRect& destination, const FloatRect& source, const FloatSize& tileScaleFactor,
+        void drawTiledImage(Image&, ColorSpace, const FloatRect& destination, const FloatPoint& source, const FloatSize& tileSize, const FloatSize& spacing, const ImagePaintingOptions& = ImagePaintingOptions());
+        void drawTiledImage(Image&, ColorSpace, const FloatRect& destination, const FloatRect& source, const FloatSize& tileScaleFactor,
             Image::TileRule, Image::TileRule, const ImagePaintingOptions& = ImagePaintingOptions());
 
-        WEBCORE_EXPORT void drawImageBuffer(ImageBuffer*, ColorSpace, const FloatPoint& destination, const ImagePaintingOptions& = ImagePaintingOptions());
-        void drawImageBuffer(ImageBuffer*, ColorSpace, const FloatRect& destination, const ImagePaintingOptions& = ImagePaintingOptions());
-        void drawImageBuffer(ImageBuffer*, ColorSpace, const FloatRect& destination, const FloatRect& source, const ImagePaintingOptions& = ImagePaintingOptions());
+        WEBCORE_EXPORT void drawImageBuffer(ImageBuffer&, ColorSpace, const FloatPoint& destination, const ImagePaintingOptions& = ImagePaintingOptions());
+        void drawImageBuffer(ImageBuffer&, ColorSpace, const FloatRect& destination, const ImagePaintingOptions& = ImagePaintingOptions());
+        void drawImageBuffer(ImageBuffer&, ColorSpace, const FloatRect& destination, const FloatRect& source, const ImagePaintingOptions& = ImagePaintingOptions());
+
+        void drawPattern(Image&, const FloatRect& srcRect, const AffineTransform&, const FloatPoint& phase, const FloatSize& spacing, ColorSpace, CompositeOperator, const FloatRect& destRect, BlendMode = BlendModeNormal);
 
         WEBCORE_EXPORT void setImageInterpolationQuality(InterpolationQuality);
         InterpolationQuality imageInterpolationQuality() const;
@@ -337,25 +335,18 @@ namespace WebCore {
         void clipOutRoundedRect(const FloatRoundedRect&);
         void clipPath(const Path&, WindRule);
         void clipConvexPolygon(size_t numPoints, const FloatPoint*, bool antialias = true);
-        void clipToImageBuffer(ImageBuffer*, const FloatRect&);
+        void clipToImageBuffer(ImageBuffer&, const FloatRect&);
         
         IntRect clipBounds() const;
 
-        TextDrawingModeFlags textDrawingMode() const;
         void setTextDrawingMode(TextDrawingModeFlags);
-        
-#if !PLATFORM(IOS)
-        void drawText(const FontCascade&, const TextRun&, const FloatPoint&, int from = 0, int to = -1);
-#else
+        TextDrawingModeFlags textDrawingMode() const { return m_state.textDrawingMode; }
+
         float drawText(const FontCascade&, const TextRun&, const FloatPoint&, int from = 0, int to = -1);
-#endif
         void drawGlyphs(const FontCascade&, const Font&, const GlyphBuffer&, int from, int numGlyphs, const FloatPoint&);
         void drawEmphasisMarks(const FontCascade&, const TextRun& , const AtomicString& mark, const FloatPoint&, int from = 0, int to = -1);
-#if !PLATFORM(IOS)
         void drawBidiText(const FontCascade&, const TextRun&, const FloatPoint&, FontCascade::CustomFontNotReadyAction = FontCascade::DoNotPaintIfFontNotReady);
-#else
-        WEBCORE_EXPORT float drawBidiText(const FontCascade&, const TextRun&, const FloatPoint&, FontCascade::CustomFontNotReadyAction = FontCascade::DoNotPaintIfFontNotReady, BidiStatus* = 0, int length = -1);
-#endif
+
         enum RoundingMode {
             RoundAllSides,
             RoundOriginAndDimensions
@@ -377,26 +368,28 @@ namespace WebCore {
         static void updateDocumentMarkerResources();
         void drawLineForDocumentMarker(const FloatPoint&, float width, DocumentMarkerLineStyle);
 
-        WEBCORE_EXPORT bool paintingDisabled() const;
-        void setPaintingDisabled(bool);
+        void setPaintingDisabled(bool paintingDisabled) { m_state.paintingDisabled = paintingDisabled; }
+        bool paintingDisabled() const { return m_state.paintingDisabled; }
 
-        WEBCORE_EXPORT bool updatingControlTints() const;
         void setUpdatingControlTints(bool);
+        bool updatingControlTints() const { return m_updatingControlTints; }
 
         WEBCORE_EXPORT void beginTransparencyLayer(float opacity);
         WEBCORE_EXPORT void endTransparencyLayer();
-        bool isInTransparencyLayer() const;
+        bool isInTransparencyLayer() const { return (m_transparencyCount > 0) && supportsTransparencyLayers(); }
 
-        bool hasShadow() const;
         WEBCORE_EXPORT void setShadow(const FloatSize&, float blur, const Color&, ColorSpace);
         // Legacy shadow blur radius is used for canvas, and -webkit-box-shadow.
         // It has different treatment of radii > 8px.
         void setLegacyShadow(const FloatSize&, float blur, const Color&, ColorSpace);
 
-        bool getShadow(FloatSize&, float&, Color&, ColorSpace&) const;
         WEBCORE_EXPORT void clearShadow();
+        bool getShadow(FloatSize&, float&, Color&, ColorSpace&) const;
+
+        bool hasVisibleShadow() const { return m_state.shadowColor.isValid() && m_state.shadowColor.alpha(); }
+        bool hasShadow() const { return hasVisibleShadow() && (m_state.shadowBlur || m_state.shadowOffset.width() || m_state.shadowOffset.height()); }
+        bool hasBlurredShadow() const { return hasVisibleShadow() && m_state.shadowBlur; }
 
-        bool hasBlurredShadow() const;
 #if USE(CAIRO)
         bool mustUseShadowBlur() const;
 #endif
@@ -413,13 +406,14 @@ namespace WebCore {
         void setMiterLimit(float);
 
         void setAlpha(float);
+        float alpha() const { return m_state.alpha; }
 
         WEBCORE_EXPORT void setCompositeOperation(CompositeOperator, BlendMode = BlendModeNormal);
-        CompositeOperator compositeOperation() const;
-        BlendMode blendModeOperation() const;
+        CompositeOperator compositeOperation() const { return m_state.compositeOperator; }
+        BlendMode blendModeOperation() const { return m_state.blendMode; }
 
-        void setDrawLuminanceMask(bool);
-        bool drawLuminanceMask() const;
+        void setDrawLuminanceMask(bool drawLuminanceMask) { m_state.drawLuminanceMask = drawLuminanceMask; }
+        bool drawLuminanceMask() const { return m_state.drawLuminanceMask; }
 
         WEBCORE_EXPORT void clip(const Path&, WindRule = RULE_EVENODD);
 
@@ -442,7 +436,7 @@ namespace WebCore {
         enum IncludeDeviceScale { DefinitelyIncludeDeviceScale, PossiblyIncludeDeviceScale };
         AffineTransform getCTM(IncludeDeviceScale includeScale = PossiblyIncludeDeviceScale) const;
 
-#if ENABLE(3D_RENDERING) && USE(TEXTURE_MAPPER)
+#if ENABLE(3D_TRANSFORMS) && USE(TEXTURE_MAPPER)
         // This is needed when using accelerated-compositing in software mode, like in TextureMapper.
         void concat3DTransform(const TransformationMatrix&);
         void set3DTransform(const TransformationMatrix&);
@@ -451,7 +445,7 @@ namespace WebCore {
         // Create an image buffer compatible with this context, with suitable resolution
         // for drawing into the buffer and then into this context.
         std::unique_ptr<ImageBuffer> createCompatibleBuffer(const FloatSize&, bool hasAlpha = true) const;
-        bool isCompatibleWithBuffer(ImageBuffer*) const;
+        bool isCompatibleWithBuffer(ImageBuffer&) const;
 
         // This function applies the device scale factor to the context, making the context capable of
         // acting as a base-level context for a HiDPI environment.
@@ -461,6 +455,7 @@ namespace WebCore {
 #if OS(WINDOWS)
         HDC getWindowsContext(const IntRect&, bool supportAlphaBlend, bool mayCreateBitmap); // The passed in rect is used to create a bitmap for compositing inside transparency layers.
         void releaseWindowsContext(HDC, const IntRect&, bool supportAlphaBlend, bool mayCreateBitmap); // The passed in HDC should be the one handed back by getWindowsContext.
+        HDC hdc() const;
 #if PLATFORM(WIN)
 #if USE(WINGDI)
         void setBitmap(PassRefPtr<SharedBitmap>);
@@ -468,7 +463,7 @@ namespace WebCore {
         AffineTransform& affineTransform();
         void resetAffineTransform();
         void fillRect(const FloatRect&, const Gradient*);
-        void drawText(const Font*, const GlyphBuffer&, int from, int numGlyphs, const FloatPoint&);
+        void drawText(const Font&, const GlyphBuffer&, int from, int numGlyphs, const FloatPoint&);
         void drawFrameControl(const IntRect& rect, unsigned type, unsigned state);
         void drawFocusRect(const IntRect& rect);
         void paintTextField(const IntRect& rect, unsigned state);
@@ -550,6 +545,7 @@ namespace WebCore {
         void setPlatformShadow(const FloatSize&, float blur, const Color&, ColorSpace);
         void clearPlatformShadow();
 
+        void setPlatformAlpha(float);
         void setPlatformCompositeOperation(CompositeOperator, BlendMode = BlendModeNormal);
 
         void beginPlatformTransparencyLayer(float opacity);
@@ -569,7 +565,7 @@ namespace WebCore {
         GraphicsContextPlatformPrivate* m_data;
 
         GraphicsContextState m_state;
-        Vector<GraphicsContextState> m_stack;
+        Vector<GraphicsContextState, 1> m_stack;
         bool m_updatingControlTints;
         unsigned m_transparencyCount;
     };