2 * Copyright (C) Research In Motion Limited 2009-2010. All rights reserved.
4 * This library is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU Library General Public
6 * License as published by the Free Software Foundation; either
7 * version 2 of the License, or (at your option) any later version.
9 * This library is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * Library General Public License for more details.
14 * You should have received a copy of the GNU Library General Public License
15 * along with this library; see the file COPYING.LIB. If not, write to
16 * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
17 * Boston, MA 02110-1301, USA.
20 #ifndef LayoutSVGResourcePaintServer_h
21 #define LayoutSVGResourcePaintServer_h
23 #include "core/layout/svg/LayoutSVGResourceContainer.h"
24 #include "platform/graphics/Color.h"
25 #include "platform/graphics/Gradient.h"
26 #include "platform/graphics/Pattern.h"
27 #include "wtf/Allocator.h"
33 enum LayoutSVGResourceMode
{
39 class LayoutSVGResourcePaintServer
;
42 class SVGPaintServer
{
45 explicit SVGPaintServer(Color
);
46 explicit SVGPaintServer(PassRefPtr
<Gradient
>);
47 explicit SVGPaintServer(PassRefPtr
<Pattern
>);
49 static SVGPaintServer
requestForLayoutObject(const LayoutObject
&, const ComputedStyle
&, LayoutSVGResourceMode
);
50 static bool existsForLayoutObject(const LayoutObject
&, const ComputedStyle
&, LayoutSVGResourceMode
);
52 void applyToSkPaint(SkPaint
&, float paintAlpha
);
54 static SVGPaintServer
invalid() { return SVGPaintServer(Color(Color::transparent
)); }
55 bool isValid() const { return m_color
!= Color::transparent
; }
57 bool isTransformDependent() const { return m_gradient
|| m_pattern
; }
58 void prependTransform(const AffineTransform
&);
61 RefPtr
<Gradient
> m_gradient
;
62 RefPtr
<Pattern
> m_pattern
;
66 // If |SVGPaintDescription::hasFallback| is true, |SVGPaintDescription::color| is set to a fallback color.
67 struct SVGPaintDescription
{
69 SVGPaintDescription() : resource(nullptr), isValid(false), hasFallback(false) { }
70 SVGPaintDescription(Color color
) : resource(nullptr), color(color
), isValid(true), hasFallback(false) { }
71 SVGPaintDescription(LayoutSVGResourcePaintServer
* resource
) : resource(resource
), isValid(true), hasFallback(false) { ASSERT(resource
); }
72 SVGPaintDescription(LayoutSVGResourcePaintServer
* resource
, Color fallbackColor
) : resource(resource
), color(fallbackColor
), isValid(true), hasFallback(true) { ASSERT(resource
); }
74 LayoutSVGResourcePaintServer
* resource
;
80 class LayoutSVGResourcePaintServer
: public LayoutSVGResourceContainer
{
82 LayoutSVGResourcePaintServer(SVGElement
*);
83 ~LayoutSVGResourcePaintServer() override
;
85 virtual SVGPaintServer
preparePaintServer(const LayoutObject
&) = 0;
87 // Helper utilities used in to access the underlying resources for DRT.
88 static SVGPaintDescription
requestPaintDescription(const LayoutObject
&, const ComputedStyle
&, LayoutSVGResourceMode
);
91 DEFINE_TYPE_CASTS(LayoutSVGResourcePaintServer
, LayoutSVGResourceContainer
, resource
, resource
->isSVGPaintServer(), resource
.isSVGPaintServer());