OLD | NEW |
1 /* | 1 /* |
2 * Copyright (C) 2004, 2005, 2006, 2007 Nikolas Zimmermann <zimmermann@kde.org> | 2 * Copyright (C) 2004, 2005, 2006, 2007 Nikolas Zimmermann <zimmermann@kde.org> |
3 * Copyright (C) 2004, 2005 Rob Buis <buis@kde.org> | 3 * Copyright (C) 2004, 2005 Rob Buis <buis@kde.org> |
4 * Copyright (C) 2005 Eric Seidel <eric@webkit.org> | 4 * Copyright (C) 2005 Eric Seidel <eric@webkit.org> |
5 * Copyright (C) 2010 Dirk Schulze <krit@webkit.org> | 5 * Copyright (C) 2010 Dirk Schulze <krit@webkit.org> |
6 * | 6 * |
7 * This library is free software; you can redistribute it and/or | 7 * This library is free software; you can redistribute it and/or |
8 * modify it under the terms of the GNU Library General Public | 8 * modify it under the terms of the GNU Library General Public |
9 * License as published by the Free Software Foundation; either | 9 * License as published by the Free Software Foundation; either |
10 * version 2 of the License, or (at your option) any later version. | 10 * version 2 of the License, or (at your option) any later version. |
(...skipping 10 matching lines...) Expand all Loading... |
21 */ | 21 */ |
22 | 22 |
23 #include "config.h" | 23 #include "config.h" |
24 | 24 |
25 #if ENABLE(SVG) && ENABLE(FILTERS) | 25 #if ENABLE(SVG) && ENABLE(FILTERS) |
26 #include "SVGFEImage.h" | 26 #include "SVGFEImage.h" |
27 | 27 |
28 #include "AffineTransform.h" | 28 #include "AffineTransform.h" |
29 #include "Filter.h" | 29 #include "Filter.h" |
30 #include "GraphicsContext.h" | 30 #include "GraphicsContext.h" |
| 31 #include "RenderObject.h" |
31 #include "RenderTreeAsText.h" | 32 #include "RenderTreeAsText.h" |
| 33 #include "SVGFilter.h" |
| 34 #include "SVGImageBufferTools.h" |
32 #include "SVGPreserveAspectRatio.h" | 35 #include "SVGPreserveAspectRatio.h" |
| 36 #include "SVGURIReference.h" |
33 #include "TextStream.h" | 37 #include "TextStream.h" |
34 | 38 |
35 namespace WebCore { | 39 namespace WebCore { |
36 | 40 |
37 FEImage::FEImage(Filter* filter, PassRefPtr<Image> image, const SVGPreserveAspec
tRatio& preserveAspectRatio) | 41 FEImage::FEImage(Filter* filter, PassRefPtr<Image> image, const SVGPreserveAspec
tRatio& preserveAspectRatio) |
38 : FilterEffect(filter) | 42 : FilterEffect(filter) |
39 , m_image(image) | 43 , m_image(image) |
| 44 , m_document(0) |
40 , m_preserveAspectRatio(preserveAspectRatio) | 45 , m_preserveAspectRatio(preserveAspectRatio) |
41 { | 46 { |
42 } | 47 } |
43 | 48 |
44 PassRefPtr<FEImage> FEImage::create(Filter* filter, PassRefPtr<Image> image, con
st SVGPreserveAspectRatio& preserveAspectRatio) | 49 FEImage::FEImage(Filter* filter, Document* document, const String& href, const S
VGPreserveAspectRatio& preserveAspectRatio) |
| 50 : FilterEffect(filter) |
| 51 , m_document(document) |
| 52 , m_href(href) |
| 53 , m_preserveAspectRatio(preserveAspectRatio) |
| 54 { |
| 55 } |
| 56 |
| 57 PassRefPtr<FEImage> FEImage::createWithImage(Filter* filter, PassRefPtr<Image> i
mage, const SVGPreserveAspectRatio& preserveAspectRatio) |
45 { | 58 { |
46 return adoptRef(new FEImage(filter, image, preserveAspectRatio)); | 59 return adoptRef(new FEImage(filter, image, preserveAspectRatio)); |
47 } | 60 } |
48 | 61 |
| 62 PassRefPtr<FEImage> FEImage::createWithIRIReference(Filter* filter, Document* do
cument, const String& href, const SVGPreserveAspectRatio& preserveAspectRatio) |
| 63 { |
| 64 return adoptRef(new FEImage(filter, document, href, preserveAspectRatio)); |
| 65 } |
| 66 |
49 void FEImage::determineAbsolutePaintRect() | 67 void FEImage::determineAbsolutePaintRect() |
50 { | 68 { |
51 ASSERT(m_image); | 69 FloatRect srcRect; |
52 FloatRect srcRect(FloatPoint(), m_image->size()); | 70 if (m_image) |
| 71 srcRect.setSize(m_image->size()); |
| 72 else if (RenderObject* renderer = referencedRenderer()) |
| 73 srcRect = static_cast<SVGFilter*>(filter())->absoluteTransform().mapRect
(renderer->repaintRectInLocalCoordinates()); |
| 74 |
53 FloatRect paintRect(m_absoluteSubregion); | 75 FloatRect paintRect(m_absoluteSubregion); |
54 m_preserveAspectRatio.transformRect(paintRect, srcRect); | 76 m_preserveAspectRatio.transformRect(paintRect, srcRect); |
55 paintRect.intersect(maxEffectRect()); | 77 paintRect.intersect(maxEffectRect()); |
56 setAbsolutePaintRect(enclosingIntRect(paintRect)); | 78 setAbsolutePaintRect(enclosingIntRect(paintRect)); |
57 } | 79 } |
58 | 80 |
| 81 RenderObject* FEImage::referencedRenderer() const |
| 82 { |
| 83 if (!m_document) |
| 84 return 0; |
| 85 Element* hrefElement = SVGURIReference::targetElementFromIRIString(m_href, m
_document); |
| 86 if (!hrefElement || !hrefElement->isSVGElement()) |
| 87 return 0; |
| 88 return hrefElement->renderer(); |
| 89 } |
| 90 |
59 void FEImage::platformApplySoftware() | 91 void FEImage::platformApplySoftware() |
60 { | 92 { |
61 if (!m_image.get()) | 93 RenderObject* renderer = referencedRenderer(); |
| 94 if (!m_image && !renderer) |
62 return; | 95 return; |
63 | 96 |
64 ImageBuffer* resultImage = createImageBufferResult(); | 97 ImageBuffer* resultImage = createImageBufferResult(); |
65 if (!resultImage) | 98 if (!resultImage) |
66 return; | 99 return; |
67 | 100 |
| 101 if (renderer) { |
| 102 const AffineTransform& absoluteTransform = static_cast<SVGFilter*>(filte
r())->absoluteTransform(); |
| 103 resultImage->context()->concatCTM(absoluteTransform); |
| 104 |
| 105 AffineTransform contentTransformation; |
| 106 SVGImageBufferTools::renderSubtreeToImageBuffer(resultImage, renderer, c
ontentTransformation); |
| 107 |
| 108 resultImage->context()->concatCTM(absoluteTransform.inverse()); |
| 109 return; |
| 110 } |
| 111 |
68 FloatRect srcRect(FloatPoint(), m_image->size()); | 112 FloatRect srcRect(FloatPoint(), m_image->size()); |
69 FloatRect destRect(m_absoluteSubregion); | 113 FloatRect destRect(m_absoluteSubregion); |
70 m_preserveAspectRatio.transformRect(destRect, srcRect); | 114 m_preserveAspectRatio.transformRect(destRect, srcRect); |
71 | 115 |
72 IntPoint paintLocation = absolutePaintRect().location(); | 116 IntPoint paintLocation = absolutePaintRect().location(); |
73 destRect.move(-paintLocation.x(), -paintLocation.y()); | 117 destRect.move(-paintLocation.x(), -paintLocation.y()); |
74 | 118 |
75 resultImage->context()->drawImage(m_image.get(), ColorSpaceDeviceRGB, destRe
ct, srcRect); | 119 resultImage->context()->drawImage(m_image.get(), ColorSpaceDeviceRGB, destRe
ct, srcRect); |
76 } | 120 } |
77 | 121 |
78 void FEImage::dump() | 122 void FEImage::dump() |
79 { | 123 { |
80 } | 124 } |
81 | 125 |
82 TextStream& FEImage::externalRepresentation(TextStream& ts, int indent) const | 126 TextStream& FEImage::externalRepresentation(TextStream& ts, int indent) const |
83 { | 127 { |
84 ASSERT(m_image); | 128 IntSize imageSize; |
85 IntSize imageSize = m_image->size(); | 129 if (m_image) |
| 130 imageSize = m_image->size(); |
| 131 else if (RenderObject* renderer = referencedRenderer()) |
| 132 imageSize = enclosingIntRect(renderer->repaintRectInLocalCoordinates()).
size(); |
86 writeIndent(ts, indent); | 133 writeIndent(ts, indent); |
87 ts << "[feImage"; | 134 ts << "[feImage"; |
88 FilterEffect::externalRepresentation(ts); | 135 FilterEffect::externalRepresentation(ts); |
89 ts << " image-size=\"" << imageSize.width() << "x" << imageSize.height() <<
"\"]\n"; | 136 ts << " image-size=\"" << imageSize.width() << "x" << imageSize.height() <<
"\"]\n"; |
90 // FIXME: should this dump also object returned by SVGFEImage::image() ? | 137 // FIXME: should this dump also object returned by SVGFEImage::image() ? |
91 return ts; | 138 return ts; |
92 } | 139 } |
93 | 140 |
94 } // namespace WebCore | 141 } // namespace WebCore |
95 | 142 |
96 #endif // ENABLE(SVG) && ENABLE(FILTERS) | 143 #endif // ENABLE(SVG) && ENABLE(FILTERS) |
OLD | NEW |