2 * Copyright (C) 2007 Rob Buis <buis@kde.org>
3 * Copyright (C) 2007 Nikolas Zimmermann <zimmermann@kde.org>
4 * Copyright (C) 2007 Eric Seidel <eric@webkit.org>
5 * Copyright (C) 2009 Google, Inc. All rights reserved.
6 * Copyright (C) Research In Motion Limited 2010. All rights reserved.
7 * Copyright (C) 2012 Zoltan Herczeg <zherczeg@webkit.org>.
9 * This library is free software; you can redistribute it and/or
10 * modify it under the terms of the GNU Library General Public
11 * License as published by the Free Software Foundation; either
12 * version 2 of the License, or (at your option) any later version.
14 * This library is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17 * Library General Public License for more details.
19 * You should have received a copy of the GNU Library General Public License
20 * along with this library; see the file COPYING.LIB. If not, write to
21 * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
22 * Boston, MA 02110-1301, USA.
25 #ifndef SVGRenderingContext_h
26 #define SVGRenderingContext_h
28 #include "ImageBuffer.h"
29 #include "PaintInfo.h"
33 class AffineTransform;
37 class RenderSVGResourceFilter;
39 // SVGRenderingContext
40 class SVGRenderingContext {
42 enum NeedsGraphicsContextSave {
44 DontSaveGraphicsContext,
47 // Does not start rendering.
51 , m_paintInfo(nullptr)
52 , m_savedContext(nullptr)
57 SVGRenderingContext(RenderElement& object, PaintInfo& paintinfo, NeedsGraphicsContextSave needsGraphicsContextSave = DontSaveGraphicsContext)
60 , m_paintInfo(nullptr)
61 , m_savedContext(nullptr)
64 prepareToRenderSVGContent(object, paintinfo, needsGraphicsContextSave);
67 // Automatically finishes context rendering.
68 ~SVGRenderingContext();
70 // Used by all SVG renderers who apply clip/filter/etc. resources to the renderer content.
71 void prepareToRenderSVGContent(RenderElement&, PaintInfo&, NeedsGraphicsContextSave = DontSaveGraphicsContext);
72 bool isRenderingPrepared() const { return m_renderingFlags & RenderingPrepared; }
74 static std::unique_ptr<ImageBuffer> createImageBuffer(const FloatRect& targetRect, const AffineTransform& absoluteTransform, ColorSpace, RenderingMode);
75 static std::unique_ptr<ImageBuffer> createImageBuffer(const FloatRect& targetRect, const FloatRect& clampedRect, ColorSpace, RenderingMode);
77 static void renderSubtreeToImageBuffer(ImageBuffer*, RenderElement&, const AffineTransform&);
78 static void clipToImageBuffer(GraphicsContext*, const AffineTransform& absoluteTransform, const FloatRect& targetRect, std::unique_ptr<ImageBuffer>&, bool safeToClear);
80 static float calculateScreenFontSizeScalingFactor(const RenderObject&);
81 static AffineTransform calculateTransformationToOutermostCoordinateSystem(const RenderObject&);
82 static void clear2DRotation(AffineTransform&);
84 static IntRect calculateImageBufferRect(const FloatRect& targetRect, const AffineTransform& absoluteTransform)
86 return enclosingIntRect(absoluteTransform.mapRect(targetRect));
89 // Support for the buffered-rendering hint.
90 bool bufferForeground(std::unique_ptr<ImageBuffer>&);
93 // To properly revert partially successful initializtions in the destructor, we record all successful steps.
95 RenderingPrepared = 1,
96 RestoreGraphicsContext = 1 << 1,
97 EndOpacityLayer = 1 << 2,
98 EndShadowLayer = 1 << 3,
99 EndFilterLayer = 1 << 4,
100 PrepareToRenderSVGContentWasCalled = 1 << 5
103 // List of those flags which require actions during the destructor.
104 const static int ActionsNeeded = RestoreGraphicsContext | EndOpacityLayer | EndShadowLayer | EndFilterLayer;
106 int m_renderingFlags;
107 RenderElement* m_renderer;
108 PaintInfo* m_paintInfo;
109 GraphicsContext* m_savedContext;
110 LayoutRect m_savedPaintRect;
111 RenderSVGResourceFilter* m_filter;
114 } // namespace WebCore
116 #endif // SVGRenderingContext_h