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) 2012 Nokia Corporation and/or its subsidiary(-ies)
7 * Copyright (C) 2014 Adobe Systems Incorporated. All rights reserved.
8 *
9 * This library is free software; you can redistribute it and/or
10 * modify it under the terms of the GNU Library General Public
11 * License as published by the Free Software Foundation; either
12 * version 2 of the License, or (at your option) any later version.
13 *
14 * This library is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
17 * Library General Public License for more details.
18 *
19 * You should have received a copy of the GNU Library General Public License
20 * along with this library; see the file COPYING.LIB.  If not, write to
21 * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
22 * Boston, MA 02110-1301, USA.
23 */
24
25#include "config.h"
26
27#if ENABLE(FILTERS)
28#include "FEBlend.h"
29#include "FEBlendNEON.h"
30
31#include "Filter.h"
32#include "FloatPoint.h"
33#include "GraphicsContext.h"
34#include "TextStream.h"
35
36#include <runtime/Uint8ClampedArray.h>
37
38namespace WebCore {
39
40FEBlend::FEBlend(Filter* filter, BlendMode mode)
41    : FilterEffect(filter)
42    , m_mode(mode)
43{
44}
45
46PassRefPtr<FEBlend> FEBlend::create(Filter* filter, BlendMode mode)
47{
48    return adoptRef(new FEBlend(filter, mode));
49}
50
51BlendMode FEBlend::blendMode() const
52{
53    return m_mode;
54}
55
56bool FEBlend::setBlendMode(BlendMode mode)
57{
58    if (m_mode == mode)
59        return false;
60    m_mode = mode;
61    return true;
62}
63
64#if !HAVE(ARM_NEON_INTRINSICS)
65void FEBlend::platformApplySoftware()
66{
67    FilterEffect* in = inputEffect(0);
68    FilterEffect* in2 = inputEffect(1);
69
70    ImageBuffer* resultImage = createImageBufferResult();
71    if (!resultImage)
72        return;
73    GraphicsContext* filterContext = resultImage->context();
74
75    ImageBuffer* imageBuffer = in->asImageBuffer();
76    ImageBuffer* imageBuffer2 = in2->asImageBuffer();
77    ASSERT(imageBuffer);
78    ASSERT(imageBuffer2);
79
80    filterContext->drawImageBuffer(imageBuffer2, ColorSpaceDeviceRGB, drawingRegionOfInputImage(in2->absolutePaintRect()));
81    filterContext->drawImageBuffer(imageBuffer, ColorSpaceDeviceRGB, drawingRegionOfInputImage(in->absolutePaintRect()), IntRect(IntPoint(), imageBuffer->logicalSize()), ImagePaintingOptions(CompositeSourceOver, m_mode));
82}
83#endif
84
85void FEBlend::dump()
86{
87}
88
89TextStream& FEBlend::externalRepresentation(TextStream& ts, int indent) const
90{
91    writeIndent(ts, indent);
92    ts << "[feBlend";
93    FilterEffect::externalRepresentation(ts);
94    ts << " mode=\"" << (m_mode == BlendModeNormal ? "normal" : compositeOperatorName(CompositeSourceOver, m_mode)) << "\"]\n";
95    inputEffect(0)->externalRepresentation(ts, indent + 1);
96    inputEffect(1)->externalRepresentation(ts, indent + 1);
97    return ts;
98}
99
100} // namespace WebCore
101
102#endif // ENABLE(FILTERS)
103