Home | History | Annotate | Download | only in filters
      1 /*
      2  * Copyright (C) 2004, 2005, 2006, 2007 Nikolas Zimmermann <zimmermann (at) kde.org>
      3  * Copyright (C) 2004, 2005 Rob Buis <buis (at) kde.org>
      4  * Copyright (C) 2005 Eric Seidel <eric (at) webkit.org>
      5  * Copyright (C) 2009 Dirk Schulze <krit (at) webkit.org>
      6  * Copyright (C) 2013 Google Inc. 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 #include "platform/graphics/filters/FEFlood.h"
     26 
     27 #include "SkColorFilter.h"
     28 #include "SkColorFilterImageFilter.h"
     29 #include "platform/graphics/GraphicsContext.h"
     30 #include "platform/graphics/filters/SkiaImageFilterBuilder.h"
     31 #include "platform/text/TextStream.h"
     32 #include "third_party/skia/include/core/SkDevice.h"
     33 
     34 namespace blink {
     35 
     36 FEFlood::FEFlood(Filter* filter, const Color& floodColor, float floodOpacity)
     37     : FilterEffect(filter)
     38     , m_floodColor(floodColor)
     39     , m_floodOpacity(floodOpacity)
     40 {
     41     FilterEffect::setOperatingColorSpace(ColorSpaceDeviceRGB);
     42 }
     43 
     44 PassRefPtr<FEFlood> FEFlood::create(Filter* filter, const Color& floodColor, float floodOpacity)
     45 {
     46     return adoptRef(new FEFlood(filter, floodColor, floodOpacity));
     47 }
     48 
     49 Color FEFlood::floodColor() const
     50 {
     51     return m_floodColor;
     52 }
     53 
     54 bool FEFlood::setFloodColor(const Color& color)
     55 {
     56     if (m_floodColor == color)
     57         return false;
     58     m_floodColor = color;
     59     return true;
     60 }
     61 
     62 float FEFlood::floodOpacity() const
     63 {
     64     return m_floodOpacity;
     65 }
     66 
     67 bool FEFlood::setFloodOpacity(float floodOpacity)
     68 {
     69     if (m_floodOpacity == floodOpacity)
     70         return false;
     71     m_floodOpacity = floodOpacity;
     72     return true;
     73 }
     74 
     75 void FEFlood::applySoftware()
     76 {
     77     ImageBuffer* resultImage = createImageBufferResult();
     78     if (!resultImage)
     79         return;
     80 
     81     Color color = floodColor().combineWithAlpha(floodOpacity());
     82     resultImage->context()->fillRect(FloatRect(FloatPoint(), absolutePaintRect().size()), color);
     83     FilterEffect::setResultColorSpace(ColorSpaceDeviceRGB);
     84 }
     85 
     86 PassRefPtr<SkImageFilter> FEFlood::createImageFilter(SkiaImageFilterBuilder* builder)
     87 {
     88     Color color = floodColor().combineWithAlpha(floodOpacity());
     89 
     90     SkImageFilter::CropRect rect = getCropRect(builder->cropOffset());
     91     SkAutoTUnref<SkColorFilter> cf(SkColorFilter::CreateModeFilter(color.rgb(), SkXfermode::kSrc_Mode));
     92     return adoptRef(SkColorFilterImageFilter::Create(cf, 0, &rect));
     93 }
     94 
     95 TextStream& FEFlood::externalRepresentation(TextStream& ts, int indent) const
     96 {
     97     writeIndent(ts, indent);
     98     ts << "[feFlood";
     99     FilterEffect::externalRepresentation(ts);
    100     ts << " flood-color=\"" << floodColor().nameForRenderTreeAsText() << "\" "
    101        << "flood-opacity=\"" << floodOpacity() << "\"]\n";
    102     return ts;
    103 }
    104 
    105 } // namespace blink
    106