1/* 2 * Copyright (C) 2004, 2005, 2006, 2007 Nikolas Zimmermann <zimmermann@kde.org> 3 * Copyright (C) 2004, 2005 Rob Buis <buis@kde.org> 4 * Copyright (C) 2005 Eric Seidel <eric@webkit.org> 5 * Copyright (C) 2009 Dirk Schulze <krit@webkit.org> 6 * Copyright (C) Research In Motion Limited 2010. All rights reserved. 7 * 8 * This library is free software; you can redistribute it and/or 9 * modify it under the terms of the GNU Library General Public 10 * License as published by the Free Software Foundation; either 11 * version 2 of the License, or (at your option) any later version. 12 * 13 * This library is distributed in the hope that it will be useful, 14 * but WITHOUT ANY WARRANTY; without even the implied warranty of 15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 16 * Library General Public License for more details. 17 * 18 * You should have received a copy of the GNU Library General Public License 19 * along with this library; see the file COPYING.LIB. If not, write to 20 * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, 21 * Boston, MA 02110-1301, USA. 22 */ 23 24#include "config.h" 25 26#if ENABLE(FILTERS) 27#include "FEOffset.h" 28 29#include "Filter.h" 30#include "GraphicsContext.h" 31#include "RenderTreeAsText.h" 32#include "TextStream.h" 33 34namespace WebCore { 35 36FEOffset::FEOffset(Filter* filter, float dx, float dy) 37 : FilterEffect(filter) 38 , m_dx(dx) 39 , m_dy(dy) 40{ 41} 42 43PassRefPtr<FEOffset> FEOffset::create(Filter* filter, float dx, float dy) 44{ 45 return adoptRef(new FEOffset(filter, dx, dy)); 46} 47 48float FEOffset::dx() const 49{ 50 return m_dx; 51} 52 53void FEOffset::setDx(float dx) 54{ 55 m_dx = dx; 56} 57 58float FEOffset::dy() const 59{ 60 return m_dy; 61} 62 63void FEOffset::setDy(float dy) 64{ 65 m_dy = dy; 66} 67 68void FEOffset::determineAbsolutePaintRect() 69{ 70 FloatRect paintRect = inputEffect(0)->absolutePaintRect(); 71 Filter* filter = this->filter(); 72 paintRect.move(filter->applyHorizontalScale(m_dx), filter->applyVerticalScale(m_dy)); 73 if (clipsToBounds()) 74 paintRect.intersect(maxEffectRect()); 75 else 76 paintRect.unite(maxEffectRect()); 77 setAbsolutePaintRect(enclosingIntRect(paintRect)); 78} 79 80void FEOffset::platformApplySoftware() 81{ 82 FilterEffect* in = inputEffect(0); 83 84 ImageBuffer* resultImage = createImageBufferResult(); 85 if (!resultImage) 86 return; 87 88 setIsAlphaImage(in->isAlphaImage()); 89 90 FloatRect drawingRegion = drawingRegionOfInputImage(in->absolutePaintRect()); 91 Filter* filter = this->filter(); 92 drawingRegion.move(filter->applyHorizontalScale(m_dx), filter->applyVerticalScale(m_dy)); 93 resultImage->context()->drawImageBuffer(in->asImageBuffer(), ColorSpaceDeviceRGB, drawingRegion); 94} 95 96void FEOffset::dump() 97{ 98} 99 100TextStream& FEOffset::externalRepresentation(TextStream& ts, int indent) const 101{ 102 writeIndent(ts, indent); 103 ts << "[feOffset"; 104 FilterEffect::externalRepresentation(ts); 105 ts << " dx=\"" << dx() << "\" dy=\"" << dy() << "\"]\n"; 106 inputEffect(0)->externalRepresentation(ts, indent + 1); 107 return ts; 108} 109 110} // namespace WebCore 111 112#endif // ENABLE(FILTERS) 113