1 /* 2 * Copyright (C) 2009 Dirk Schulze <krit (at) webkit.org> 3 * Copyright (C) 2013 Google Inc. All rights reserved. 4 * 5 * This library is free software; you can redistribute it and/or 6 * modify it under the terms of the GNU Library General Public 7 * License as published by the Free Software Foundation; either 8 * version 2 of the License, or (at your option) any later version. 9 * 10 * This library is distributed in the hope that it will be useful, 11 * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 13 * Library General Public License for more details. 14 * 15 * You should have received a copy of the GNU Library General Public License 16 * along with this library; see the file COPYING.LIB. If not, write to 17 * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, 18 * Boston, MA 02110-1301, USA. 19 */ 20 21 #include "config.h" 22 23 #include "core/platform/graphics/filters/SourceAlpha.h" 24 25 #include "core/platform/graphics/Color.h" 26 #include "core/platform/graphics/GraphicsContext.h" 27 #include "core/platform/graphics/filters/Filter.h" 28 #include "core/platform/text/TextStream.h" 29 #include "core/rendering/RenderTreeAsText.h" 30 #include "wtf/StdLibExtras.h" 31 #include "wtf/text/WTFString.h" 32 33 namespace WebCore { 34 35 PassRefPtr<SourceAlpha> SourceAlpha::create(Filter* filter) 36 { 37 return adoptRef(new SourceAlpha(filter)); 38 } 39 40 const AtomicString& SourceAlpha::effectName() 41 { 42 DEFINE_STATIC_LOCAL(const AtomicString, s_effectName, ("SourceAlpha", AtomicString::ConstructFromLiteral)); 43 return s_effectName; 44 } 45 46 void SourceAlpha::determineAbsolutePaintRect() 47 { 48 Filter* filter = this->filter(); 49 FloatRect paintRect = filter->sourceImageRect(); 50 paintRect.scale(filter->filterResolution().width(), filter->filterResolution().height()); 51 setAbsolutePaintRect(enclosingIntRect(paintRect)); 52 } 53 54 void SourceAlpha::applySoftware() 55 { 56 ImageBuffer* resultImage = createImageBufferResult(); 57 Filter* filter = this->filter(); 58 if (!resultImage || !filter->sourceImage()) 59 return; 60 61 setIsAlphaImage(true); 62 63 FloatRect imageRect(FloatPoint(), absolutePaintRect().size()); 64 GraphicsContext* filterContext = resultImage->context(); 65 filterContext->fillRect(imageRect, Color::black); 66 filterContext->drawImageBuffer(filter->sourceImage(), IntPoint(), CompositeDestinationIn); 67 } 68 69 TextStream& SourceAlpha::externalRepresentation(TextStream& ts, int indent) const 70 { 71 writeIndent(ts, indent); 72 ts << "[SourceAlpha]\n"; 73 return ts; 74 } 75 76 } // namespace WebCore 77