| 1 | /** | 
| 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>. | 
| 8 |  * | 
| 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. | 
| 13 |  * | 
| 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. | 
| 18 |  * | 
| 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. | 
| 23 |  */ | 
| 24 |  | 
| 25 | #pragma once | 
| 26 |  | 
| 27 | #include "ImageBuffer.h" | 
| 28 | #include "PaintInfo.h" | 
| 29 |  | 
| 30 | namespace WebCore { | 
| 31 |  | 
| 32 | class AffineTransform; | 
| 33 | class FloatRect; | 
| 34 | class RenderElement; | 
| 35 | class RenderObject; | 
| 36 | class RenderSVGResourceFilter; | 
| 37 |  | 
| 38 | // SVGRenderingContext  | 
| 39 | class SVGRenderingContext { | 
| 40 | public: | 
| 41 |     enum NeedsGraphicsContextSave { | 
| 42 |         SaveGraphicsContext, | 
| 43 |         DontSaveGraphicsContext, | 
| 44 |     }; | 
| 45 |  | 
| 46 |     // Does not start rendering. | 
| 47 |     SVGRenderingContext() | 
| 48 |     { | 
| 49 |     } | 
| 50 |  | 
| 51 |     SVGRenderingContext(RenderElement& object, PaintInfo& paintinfo, NeedsGraphicsContextSave needsGraphicsContextSave = DontSaveGraphicsContext) | 
| 52 |     { | 
| 53 |         prepareToRenderSVGContent(object, paintinfo, needsGraphicsContextSave); | 
| 54 |     } | 
| 55 |  | 
| 56 |     // Automatically finishes context rendering. | 
| 57 |     ~SVGRenderingContext(); | 
| 58 |  | 
| 59 |     // Used by all SVG renderers who apply clip/filter/etc. resources to the renderer content. | 
| 60 |     void prepareToRenderSVGContent(RenderElement&, PaintInfo&, NeedsGraphicsContextSave = DontSaveGraphicsContext); | 
| 61 |     bool isRenderingPrepared() const { return m_renderingFlags & RenderingPrepared; } | 
| 62 |  | 
| 63 |     static std::unique_ptr<ImageBuffer> createImageBuffer(const FloatRect& targetRect, const AffineTransform& absoluteTransform, ColorSpace, RenderingMode, const GraphicsContext* = nullptr); | 
| 64 |     static std::unique_ptr<ImageBuffer> createImageBuffer(const FloatRect& targetRect, const FloatRect& clampedRect, ColorSpace, RenderingMode, const GraphicsContext* = nullptr); | 
| 65 |  | 
| 66 |     static void renderSubtreeToImageBuffer(ImageBuffer*, RenderElement&, const AffineTransform&); | 
| 67 |     static void clipToImageBuffer(GraphicsContext&, const AffineTransform& absoluteTransform, const FloatRect& targetRect, std::unique_ptr<ImageBuffer>&, bool safeToClear); | 
| 68 |  | 
| 69 |     static float calculateScreenFontSizeScalingFactor(const RenderObject&); | 
| 70 |     static AffineTransform calculateTransformationToOutermostCoordinateSystem(const RenderObject&); | 
| 71 |     static void clear2DRotation(AffineTransform&); | 
| 72 |  | 
| 73 |     static IntRect calculateImageBufferRect(const FloatRect& targetRect, const AffineTransform& absoluteTransform) | 
| 74 |     { | 
| 75 |         return enclosingIntRect(absoluteTransform.mapRect(targetRect)); | 
| 76 |     } | 
| 77 |  | 
| 78 |     // Support for the buffered-rendering hint. | 
| 79 |     bool bufferForeground(std::unique_ptr<ImageBuffer>&); | 
| 80 |  | 
| 81 | private: | 
| 82 |     // To properly revert partially successful initializtions in the destructor, we record all successful steps. | 
| 83 |     enum RenderingFlags { | 
| 84 |         RenderingPrepared = 1, | 
| 85 |         RestoreGraphicsContext = 1 << 1, | 
| 86 |         EndOpacityLayer = 1 << 2, | 
| 87 |         EndShadowLayer = 1 << 3, | 
| 88 |         EndFilterLayer = 1 << 4, | 
| 89 |         PrepareToRenderSVGContentWasCalled = 1 << 5 | 
| 90 |     }; | 
| 91 |  | 
| 92 |     // List of those flags which require actions during the destructor. | 
| 93 |     const static int ActionsNeeded = RestoreGraphicsContext | EndOpacityLayer | EndShadowLayer | EndFilterLayer; | 
| 94 |  | 
| 95 |     RenderElement* m_renderer { nullptr }; | 
| 96 |     PaintInfo* m_paintInfo { nullptr }; | 
| 97 |     GraphicsContext* m_savedContext  { nullptr }; | 
| 98 |     RenderSVGResourceFilter* m_filter  { nullptr }; | 
| 99 |     LayoutRect m_savedPaintRect; | 
| 100 |     int m_renderingFlags { 0 }; | 
| 101 | }; | 
| 102 |  | 
| 103 | } // namespace WebCore | 
| 104 |  |