OLD | NEW |
1 /* | 1 /* |
2 * Copyright (C) Research In Motion Limited 2009-2010. All rights reserved. | 2 * Copyright (C) Research In Motion Limited 2009-2010. All rights reserved. |
3 * | 3 * |
4 * This library is free software; you can redistribute it and/or | 4 * This library is free software; you can redistribute it and/or |
5 * modify it under the terms of the GNU Library General Public | 5 * modify it under the terms of the GNU Library General Public |
6 * License as published by the Free Software Foundation; either | 6 * License as published by the Free Software Foundation; either |
7 * version 2 of the License, or (at your option) any later version. | 7 * version 2 of the License, or (at your option) any later version. |
8 * | 8 * |
9 * This library is distributed in the hope that it will be useful, | 9 * This library is distributed in the hope that it will be useful, |
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of | 10 * but WITHOUT ANY WARRANTY; without even the implied warranty of |
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | 11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
12 * Library General Public License for more details. | 12 * Library General Public License for more details. |
13 * | 13 * |
14 * You should have received a copy of the GNU Library General Public License | 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 | 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, | 16 * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, |
17 * Boston, MA 02110-1301, USA. | 17 * Boston, MA 02110-1301, USA. |
18 */ | 18 */ |
19 | 19 |
20 #ifndef LayoutSVGResourcePaintServer_h | 20 #ifndef LayoutSVGResourcePaintServer_h |
21 #define LayoutSVGResourcePaintServer_h | 21 #define LayoutSVGResourcePaintServer_h |
22 | 22 |
23 #include "core/layout/svg/LayoutSVGResourceContainer.h" | 23 #include "core/layout/svg/LayoutSVGResourceContainer.h" |
24 #include "platform/graphics/Color.h" | 24 #include "platform/graphics/Color.h" |
25 #include "platform/graphics/Gradient.h" | 25 #include "platform/graphics/Gradient.h" |
26 #include "platform/graphics/Pattern.h" | 26 #include "platform/graphics/Pattern.h" |
| 27 #include "wtf/Allocator.h" |
27 | 28 |
28 class SkPaint; | 29 class SkPaint; |
29 | 30 |
30 namespace blink { | 31 namespace blink { |
31 | 32 |
32 enum LayoutSVGResourceMode { | 33 enum LayoutSVGResourceMode { |
33 ApplyToFillMode, | 34 ApplyToFillMode, |
34 ApplyToStrokeMode, | 35 ApplyToStrokeMode, |
35 }; | 36 }; |
36 | 37 |
37 class LayoutObject; | 38 class LayoutObject; |
38 class LayoutSVGResourcePaintServer; | 39 class LayoutSVGResourcePaintServer; |
39 class ComputedStyle; | 40 class ComputedStyle; |
40 | 41 |
41 class SVGPaintServer { | 42 class SVGPaintServer { |
| 43 STACK_ALLOCATED(); |
42 public: | 44 public: |
43 explicit SVGPaintServer(Color); | 45 explicit SVGPaintServer(Color); |
44 explicit SVGPaintServer(PassRefPtr<Gradient>); | 46 explicit SVGPaintServer(PassRefPtr<Gradient>); |
45 explicit SVGPaintServer(PassRefPtr<Pattern>); | 47 explicit SVGPaintServer(PassRefPtr<Pattern>); |
46 | 48 |
47 static SVGPaintServer requestForLayoutObject(const LayoutObject&, const Comp
utedStyle&, LayoutSVGResourceMode); | 49 static SVGPaintServer requestForLayoutObject(const LayoutObject&, const Comp
utedStyle&, LayoutSVGResourceMode); |
48 static bool existsForLayoutObject(const LayoutObject&, const ComputedStyle&,
LayoutSVGResourceMode); | 50 static bool existsForLayoutObject(const LayoutObject&, const ComputedStyle&,
LayoutSVGResourceMode); |
49 | 51 |
50 void applyToSkPaint(SkPaint&, float paintAlpha); | 52 void applyToSkPaint(SkPaint&, float paintAlpha); |
51 | 53 |
52 static SVGPaintServer invalid() { return SVGPaintServer(Color(Color::transpa
rent)); } | 54 static SVGPaintServer invalid() { return SVGPaintServer(Color(Color::transpa
rent)); } |
53 bool isValid() const { return m_color != Color::transparent; } | 55 bool isValid() const { return m_color != Color::transparent; } |
54 | 56 |
55 bool isTransformDependent() const { return m_gradient || m_pattern; } | 57 bool isTransformDependent() const { return m_gradient || m_pattern; } |
56 void prependTransform(const AffineTransform&); | 58 void prependTransform(const AffineTransform&); |
57 | 59 |
58 private: | 60 private: |
59 RefPtr<Gradient> m_gradient; | 61 RefPtr<Gradient> m_gradient; |
60 RefPtr<Pattern> m_pattern; | 62 RefPtr<Pattern> m_pattern; |
61 Color m_color; | 63 Color m_color; |
62 }; | 64 }; |
63 | 65 |
64 // If |SVGPaintDescription::hasFallback| is true, |SVGPaintDescription::color| i
s set to a fallback color. | 66 // If |SVGPaintDescription::hasFallback| is true, |SVGPaintDescription::color| i
s set to a fallback color. |
65 struct SVGPaintDescription { | 67 struct SVGPaintDescription { |
| 68 STACK_ALLOCATED(); |
66 SVGPaintDescription() : resource(nullptr), isValid(false), hasFallback(false
) { } | 69 SVGPaintDescription() : resource(nullptr), isValid(false), hasFallback(false
) { } |
67 SVGPaintDescription(Color color) : resource(nullptr), color(color), isValid(
true), hasFallback(false) { } | 70 SVGPaintDescription(Color color) : resource(nullptr), color(color), isValid(
true), hasFallback(false) { } |
68 SVGPaintDescription(LayoutSVGResourcePaintServer* resource) : resource(resou
rce), isValid(true), hasFallback(false) { ASSERT(resource); } | 71 SVGPaintDescription(LayoutSVGResourcePaintServer* resource) : resource(resou
rce), isValid(true), hasFallback(false) { ASSERT(resource); } |
69 SVGPaintDescription(LayoutSVGResourcePaintServer* resource, Color fallbackCo
lor) : resource(resource), color(fallbackColor), isValid(true), hasFallback(true
) { ASSERT(resource); } | 72 SVGPaintDescription(LayoutSVGResourcePaintServer* resource, Color fallbackCo
lor) : resource(resource), color(fallbackColor), isValid(true), hasFallback(true
) { ASSERT(resource); } |
70 | 73 |
71 LayoutSVGResourcePaintServer* resource; | 74 LayoutSVGResourcePaintServer* resource; |
72 Color color; | 75 Color color; |
73 bool isValid; | 76 bool isValid; |
74 bool hasFallback; | 77 bool hasFallback; |
75 }; | 78 }; |
76 | 79 |
77 class LayoutSVGResourcePaintServer : public LayoutSVGResourceContainer { | 80 class LayoutSVGResourcePaintServer : public LayoutSVGResourceContainer { |
78 public: | 81 public: |
79 LayoutSVGResourcePaintServer(SVGElement*); | 82 LayoutSVGResourcePaintServer(SVGElement*); |
80 ~LayoutSVGResourcePaintServer() override; | 83 ~LayoutSVGResourcePaintServer() override; |
81 | 84 |
82 virtual SVGPaintServer preparePaintServer(const LayoutObject&) = 0; | 85 virtual SVGPaintServer preparePaintServer(const LayoutObject&) = 0; |
83 | 86 |
84 // Helper utilities used in to access the underlying resources for DRT. | 87 // Helper utilities used in to access the underlying resources for DRT. |
85 static SVGPaintDescription requestPaintDescription(const LayoutObject&, cons
t ComputedStyle&, LayoutSVGResourceMode); | 88 static SVGPaintDescription requestPaintDescription(const LayoutObject&, cons
t ComputedStyle&, LayoutSVGResourceMode); |
86 }; | 89 }; |
87 | 90 |
88 DEFINE_TYPE_CASTS(LayoutSVGResourcePaintServer, LayoutSVGResourceContainer, reso
urce, resource->isSVGPaintServer(), resource.isSVGPaintServer()); | 91 DEFINE_TYPE_CASTS(LayoutSVGResourcePaintServer, LayoutSVGResourceContainer, reso
urce, resource->isSVGPaintServer(), resource.isSVGPaintServer()); |
89 | 92 |
90 } | 93 } |
91 | 94 |
92 #endif | 95 #endif |
OLD | NEW |