Home | History | Annotate | Download | only in svg
      1 /**
      2  * Copyright (C) 2007 Rob Buis <buis (at) kde.org>
      3  * Copyright (C) 2007 Nikolas Zimmermann <zimmermann (at) kde.org>
      4  * Copyright (C) 2007 Eric Seidel <eric (at) 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 (at) 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 #ifndef SVGRenderingContext_h
     26 #define SVGRenderingContext_h
     27 
     28 #include "core/rendering/PaintInfo.h"
     29 #include "core/rendering/svg/RenderSVGResourceClipper.h"
     30 #include "platform/graphics/ImageBuffer.h"
     31 
     32 namespace WebCore {
     33 
     34 class AffineTransform;
     35 class RenderObject;
     36 class FloatRect;
     37 class RenderSVGResourceFilter;
     38 class RenderSVGResourceMasker;
     39 
     40 // SVGRenderingContext
     41 class SVGRenderingContext {
     42 public:
     43     enum NeedsGraphicsContextSave {
     44         SaveGraphicsContext,
     45         DontSaveGraphicsContext,
     46     };
     47 
     48     // Does not start rendering.
     49     SVGRenderingContext()
     50         : m_renderingFlags(0)
     51         , m_object(0)
     52         , m_paintInfo(0)
     53         , m_savedContext(0)
     54         , m_filter(0)
     55         , m_clipper(0)
     56         , m_masker(0)
     57     {
     58     }
     59 
     60     SVGRenderingContext(RenderObject* object, PaintInfo& paintinfo, NeedsGraphicsContextSave needsGraphicsContextSave = DontSaveGraphicsContext)
     61         : m_renderingFlags(0)
     62         , m_object(0)
     63         , m_paintInfo(0)
     64         , m_savedContext(0)
     65         , m_filter(0)
     66         , m_clipper(0)
     67         , m_masker(0)
     68     {
     69         prepareToRenderSVGContent(object, paintinfo, needsGraphicsContextSave);
     70     }
     71 
     72     // Automatically finishes context rendering.
     73     ~SVGRenderingContext();
     74 
     75     // Used by all SVG renderers who apply clip/filter/etc. resources to the renderer content.
     76     void prepareToRenderSVGContent(RenderObject*, PaintInfo&, NeedsGraphicsContextSave = DontSaveGraphicsContext);
     77     bool isRenderingPrepared() const { return m_renderingFlags & RenderingPrepared; }
     78 
     79     static void renderSubtree(GraphicsContext*, RenderObject*, const AffineTransform&);
     80 
     81     static float calculateScreenFontSizeScalingFactor(const RenderObject*);
     82     static void calculateTransformationToOutermostCoordinateSystem(const RenderObject*, AffineTransform& absoluteTransform);
     83     static FloatRect clampedAbsoluteTargetRect(const FloatRect& absoluteTargetRect);
     84     static void clear2DRotation(AffineTransform&);
     85 
     86     static IntRect calculateImageBufferRect(const FloatRect& targetRect, const AffineTransform& absoluteTransform)
     87     {
     88         return enclosingIntRect(absoluteTransform.mapRect(targetRect));
     89     }
     90 
     91     // Support for the buffered-rendering hint.
     92     bool bufferForeground(OwnPtr<ImageBuffer>&);
     93 
     94 private:
     95     // To properly revert partially successful initializtions in the destructor, we record all successful steps.
     96     enum RenderingFlags {
     97         RenderingPrepared = 1,
     98         RestoreGraphicsContext = 1 << 1,
     99         EndOpacityLayer = 1 << 2,
    100         PostApplyResources = 1 << 3,
    101         PrepareToRenderSVGContentWasCalled = 1 << 4
    102     };
    103 
    104     // List of those flags which require actions during the destructor.
    105     const static int ActionsNeeded = RestoreGraphicsContext | EndOpacityLayer | PostApplyResources;
    106 
    107     int m_renderingFlags;
    108     RenderObject* m_object;
    109     PaintInfo* m_paintInfo;
    110     GraphicsContext* m_savedContext;
    111     IntRect m_savedPaintRect;
    112     RenderSVGResourceFilter* m_filter;
    113     RenderSVGResourceClipper* m_clipper;
    114     ClipperContext m_clipperContext;
    115     RenderSVGResourceMasker* m_masker;
    116 };
    117 
    118 } // namespace WebCore
    119 
    120 #endif // SVGRenderingContext_h
    121