2 * Copyright (C) 2009 Dirk Schulze <krit@webkit.org>
3 * Copyright (C) 2013 Google Inc. All rights reserved.
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.
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.
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.
22 #include "platform/graphics/filters/SourceAlpha.h"
24 #include "platform/graphics/Color.h"
25 #include "platform/graphics/filters/Filter.h"
26 #include "platform/graphics/filters/SkiaImageFilterBuilder.h"
27 #include "platform/graphics/filters/SourceGraphic.h"
28 #include "platform/text/TextStream.h"
29 #include "third_party/skia/include/effects/SkColorFilterImageFilter.h"
30 #include "third_party/skia/include/effects/SkColorMatrixFilter.h"
31 #include "wtf/text/WTFString.h"
35 PassRefPtr<SourceAlpha> SourceAlpha::create(Filter* filter)
37 return adoptRef(new SourceAlpha(filter));
40 const AtomicString& SourceAlpha::effectName()
42 DEFINE_STATIC_LOCAL(const AtomicString, s_effectName, ("SourceAlpha", AtomicString::ConstructFromLiteral));
46 FloatRect SourceAlpha::determineAbsolutePaintRect(const FloatRect& requestedRect)
48 FloatRect srcRect = filter()->sourceImageRect();
49 srcRect.intersect(requestedRect);
50 addAbsolutePaintRect(srcRect);
54 PassRefPtr<SkImageFilter> SourceAlpha::createImageFilter(SkiaImageFilterBuilder* builder)
56 RefPtr<SkImageFilter> sourceGraphic(builder->build(builder->sourceGraphic(), operatingColorSpace()));
57 SkScalar matrix[20] = {
61 0, 0, 0, SK_Scalar1, 0
63 RefPtr<SkColorFilter> colorFilter(adoptRef(SkColorMatrixFilter::Create(matrix)));
64 return adoptRef(SkColorFilterImageFilter::Create(colorFilter.get(), sourceGraphic.get()));
67 TextStream& SourceAlpha::externalRepresentation(TextStream& ts, int indent) const
69 writeIndent(ts, indent);
70 ts << "[SourceAlpha]\n";