Skip to content

Commit 65c9cc4

Browse files
authored
Merge pull request #1235 from WebPlatformForEmbedded/pgorszkowski/2.38/ImplementFECompositeNeonArithmeticApplier
Implement fe composite neon arithmetic applier
2 parents 92f2cef + 49d8856 commit 65c9cc4

10 files changed

Lines changed: 352 additions & 162 deletions

Source/WebCore/Sources.txt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2139,6 +2139,8 @@ platform/graphics/WebMResourceClient.cpp
21392139
platform/graphics/WOFFFileFormat.cpp
21402140
platform/graphics/WidthIterator.cpp
21412141
platform/graphics/cpu/arm/filters/FEBlendNeonApplier.cpp
2142+
platform/graphics/cpu/arm/filters/FECompositeNeonArithmeticApplier.cpp
2143+
platform/graphics/cpu/arm/filters/FELightingNEON.cpp
21422144
platform/graphics/displaylists/DisplayList.cpp
21432145
platform/graphics/displaylists/DisplayListDrawingContext.cpp
21442146
platform/graphics/displaylists/DisplayListItems.cpp
@@ -2182,6 +2184,7 @@ platform/graphics/filters/SpotLightSource.cpp
21822184
platform/graphics/filters/software/FEBlendSoftwareApplier.cpp
21832185
platform/graphics/filters/software/FEColorMatrixSoftwareApplier.cpp
21842186
platform/graphics/filters/software/FEComponentTransferSoftwareApplier.cpp
2187+
platform/graphics/filters/software/FECompositeSoftwareArithmeticApplier.cpp
21852188
platform/graphics/filters/software/FECompositeSoftwareApplier.cpp
21862189
platform/graphics/filters/software/FEConvolveMatrixSoftwareApplier.cpp
21872190
platform/graphics/filters/software/FEDisplacementMapSoftwareApplier.cpp

Source/WebCore/WebCore.xcodeproj/project.pbxproj

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11534,6 +11534,9 @@
1153411534
722AF2E327E1CF110078D997 /* TextBoxIterator.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = TextBoxIterator.h; sourceTree = "<group>"; };
1153511535
722AF2E527E1D09E0078D997 /* CGContextStateSaver.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = CGContextStateSaver.h; sourceTree = "<group>"; };
1153611536
7241361A28985069007B3FCD /* FEBlendNeonApplier.cpp */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.cpp; path = FEBlendNeonApplier.cpp; sourceTree = "<group>"; };
11537+
7241361F289863AC007B3FCD /* FECompositeNeonArithmeticApplier.cpp */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.cpp; path = FECompositeNeonArithmeticApplier.cpp; sourceTree = "<group>"; };
11538+
724136202898652A007B3FCD /* FECompositeSoftwareArithmeticApplier.cpp */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.cpp; path = FECompositeSoftwareArithmeticApplier.cpp; sourceTree = "<group>"; };
11539+
724136212898652A007B3FCD /* FECompositeSoftwareArithmeticApplier.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = FECompositeSoftwareArithmeticApplier.h; sourceTree = "<group>"; };
1153711540
72435EF4273D07670005E7EE /* FilterImage.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = FilterImage.h; sourceTree = "<group>"; };
1153811541
72435EF5273D07670005E7EE /* FilterImage.cpp */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.cpp; path = FilterImage.cpp; sourceTree = "<group>"; };
1153911542
724DCF1B284853650026ACF4 /* ImageBufferAllocator.cpp */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.cpp; path = ImageBufferAllocator.cpp; sourceTree = "<group>"; };
@@ -12953,7 +12956,7 @@
1295312956
93309EA1099EB78C0056E581 /* Timer.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = Timer.cpp; sourceTree = "<group>"; };
1295412957
9332AB3D16515D7700D827EC /* GraphicsContextGLNEON.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = GraphicsContextGLNEON.h; sourceTree = "<group>"; };
1295512958
9332AB871653A97900D827EC /* FEBlendNeonApplier.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = FEBlendNeonApplier.h; sourceTree = "<group>"; };
12956-
9332AB881653A97900D827EC /* FECompositeArithmeticNEON.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = FECompositeArithmeticNEON.h; sourceTree = "<group>"; };
12959+
9332AB881653A97900D827EC /* FECompositeNeonArithmeticApplier.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = FECompositeNeonArithmeticApplier.h; sourceTree = "<group>"; };
1295712960
9332AB891653A97900D827EC /* FEGaussianBlurNEON.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = FEGaussianBlurNEON.h; sourceTree = "<group>"; };
1295812961
9332AB8A1653A97900D827EC /* FELightingNEON.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = FELightingNEON.cpp; sourceTree = "<group>"; };
1295912962
9332AB8B1653A97900D827EC /* FELightingNEON.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = FELightingNEON.h; sourceTree = "<group>"; };
@@ -25300,6 +25303,8 @@
2530025303
72A13AB9274DDEC000E2A88E /* FEComponentTransferSoftwareApplier.h */,
2530125304
72A13ABA274DE01200E2A88E /* FECompositeSoftwareApplier.cpp */,
2530225305
72A13ABB274DE01200E2A88E /* FECompositeSoftwareApplier.h */,
25306+
724136202898652A007B3FCD /* FECompositeSoftwareArithmeticApplier.cpp */,
25307+
724136212898652A007B3FCD /* FECompositeSoftwareArithmeticApplier.h */,
2530325308
72A13ABE274DE33F00E2A88E /* FEConvolveMatrixSoftwareApplier.cpp */,
2530425309
72A13ABF274DE33F00E2A88E /* FEConvolveMatrixSoftwareApplier.h */,
2530525310
72A13AC0274DE35900E2A88E /* FEDisplacementMapSoftwareApplier.cpp */,
@@ -25935,7 +25940,8 @@
2593525940
children = (
2593625941
7241361A28985069007B3FCD /* FEBlendNeonApplier.cpp */,
2593725942
9332AB871653A97900D827EC /* FEBlendNeonApplier.h */,
25938-
9332AB881653A97900D827EC /* FECompositeArithmeticNEON.h */,
25943+
7241361F289863AC007B3FCD /* FECompositeNeonArithmeticApplier.cpp */,
25944+
9332AB881653A97900D827EC /* FECompositeNeonArithmeticApplier.h */,
2593925945
9332AB891653A97900D827EC /* FEGaussianBlurNEON.h */,
2594025946
9332AB8A1653A97900D827EC /* FELightingNEON.cpp */,
2594125947
9332AB8B1653A97900D827EC /* FELightingNEON.h */,

Source/WebCore/platform/graphics/cpu/arm/filters/FECompositeArithmeticNEON.h renamed to Source/WebCore/platform/graphics/cpu/arm/filters/FECompositeNeonArithmeticApplier.cpp

Lines changed: 42 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
/*
22
* Copyright (C) 2011 University of Szeged
33
* Copyright (C) 2011 Felician Marton
4+
* Copyright (C) 2022 Apple Inc. All rights reserved.
45
*
56
* Redistribution and use in source and binary forms, with or without
67
* modification, are permitted provided that the following conditions
@@ -24,8 +25,8 @@
2425
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
2526
*/
2627

27-
#ifndef FECompositeArithmeticNEON_h
28-
#define FECompositeArithmeticNEON_h
28+
#include "config.h"
29+
#include "FECompositeNeonArithmeticApplier.h"
2930

3031
#if HAVE(ARM_NEON_INTRINSICS)
3132

@@ -35,8 +36,14 @@
3536

3637
namespace WebCore {
3738

39+
FECompositeNeonArithmeticApplier::FECompositeNeonArithmeticApplier(const FEComposite& effect)
40+
: Base(effect)
41+
{
42+
ASSERT(m_effect.operation() == FECOMPOSITE_OPERATOR_ARITHMETIC);
43+
}
44+
3845
template <int b1, int b4>
39-
inline void FECompositeSoftwareApplier::computeArithmeticPixelsNeon(const uint8_t* source, uint8_t* destination, unsigned pixelArrayLength, float k1, float k2, float k3, float k4)
46+
inline void FECompositeNeonArithmeticApplier::computePixels(const uint8_t* source, uint8_t* destination, unsigned pixelArrayLength, float k1, float k2, float k3, float k4)
4047
{
4148
float32x4_t k1x4 = vdupq_n_f32(k1 / 255);
4249
float32x4_t k2x4 = vdupq_n_f32(k2);
@@ -67,27 +74,52 @@ inline void FECompositeSoftwareApplier::computeArithmeticPixelsNeon(const uint8_
6774
}
6875
}
6976

70-
inline void FECompositeSoftwareApplier::platformArithmeticNeon(const uint8_t* source, uint8_t* destination, unsigned pixelArrayLength, float k1, float k2, float k3, float k4)
77+
inline void FECompositeNeonArithmeticApplier::applyPlatform(const uint8_t* source, uint8_t* destination, unsigned pixelArrayLength, float k1, float k2, float k3, float k4)
7178
{
7279
if (!k4) {
7380
if (!k1) {
74-
computeArithmeticPixelsNeon<0, 0>(source, destination, pixelArrayLength, k1, k2, k3, k4);
81+
computePixels<0, 0>(source, destination, pixelArrayLength, k1, k2, k3, k4);
7582
return;
7683
}
7784

78-
computeArithmeticPixelsNeon<1, 0>(source, destination, pixelArrayLength, k1, k2, k3, k4);
85+
computePixels<1, 0>(source, destination, pixelArrayLength, k1, k2, k3, k4);
7986
return;
8087
}
8188

8289
if (!k1) {
83-
computeArithmeticPixelsNeon<0, 1>(source, destination, pixelArrayLength, k1, k2, k3, k4);
90+
computePixels<0, 1>(source, destination, pixelArrayLength, k1, k2, k3, k4);
8491
return;
8592
}
86-
computeArithmeticPixelsNeon<1, 1>(source, destination, pixelArrayLength, k1, k2, k3, k4);
93+
computePixels<1, 1>(source, destination, pixelArrayLength, k1, k2, k3, k4);
94+
}
95+
96+
bool FECompositeNeonArithmeticApplier::apply(const Filter&, const FilterImageVector& inputs, FilterImage& result) const
97+
{
98+
auto& input = inputs[0].get();
99+
auto& input2 = inputs[1].get();
100+
101+
auto destinationPixelBuffer = result.pixelBuffer(AlphaPremultiplication::Premultiplied);
102+
if (!destinationPixelBuffer)
103+
return false;
104+
105+
IntRect effectADrawingRect = result.absoluteImageRectRelativeTo(input);
106+
auto sourcePixelBuffer = input.getPixelBuffer(AlphaPremultiplication::Premultiplied, effectADrawingRect, m_effect.operatingColorSpace());
107+
if (!sourcePixelBuffer)
108+
return false;
109+
110+
IntRect effectBDrawingRect = result.absoluteImageRectRelativeTo(input2);
111+
input2.copyPixelBuffer(*destinationPixelBuffer, effectBDrawingRect);
112+
113+
auto* sourcePixelBytes = sourcePixelBuffer->bytes();
114+
auto* destinationPixelBytes = destinationPixelBuffer->bytes();
115+
116+
auto length = sourcePixelBuffer->sizeInBytes();
117+
ASSERT(length == destinationPixelBuffer->sizeInBytes());
118+
119+
applyPlatform(sourcePixelBytes, destinationPixelBytes, length, m_effect.k1(), m_effect.k2(), m_effect.k3(), m_effect.k4());
120+
return true;
87121
}
88122

89123
} // namespace WebCore
90124

91125
#endif // HAVE(ARM_NEON_INTRINSICS)
92-
93-
#endif // FECompositeArithmeticNEON_h
Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
/*
2+
* Copyright (C) 2011 University of Szeged
3+
* Copyright (C) 2011 Felician Marton
4+
* Copyright (C) 2022 Apple Inc. All rights reserved.
5+
*
6+
* Redistribution and use in source and binary forms, with or without
7+
* modification, are permitted provided that the following conditions
8+
* are met:
9+
* 1. Redistributions of source code must retain the above copyright
10+
* notice, this list of conditions and the following disclaimer.
11+
* 2. Redistributions in binary form must reproduce the above copyright
12+
* notice, this list of conditions and the following disclaimer in the
13+
* documentation and/or other materials provided with the distribution.
14+
*
15+
* THIS SOFTWARE IS PROVIDED BY UNIVERSITY OF SZEGED ``AS IS'' AND ANY
16+
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
17+
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
18+
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL UNIVERSITY OF SZEGED OR
19+
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
20+
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
21+
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
22+
* PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
23+
* OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
24+
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
25+
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26+
*/
27+
28+
#pragma once
29+
30+
#if HAVE(ARM_NEON_INTRINSICS)
31+
32+
#include "FilterEffectApplier.h"
33+
34+
namespace WebCore {
35+
36+
class FEComposite;
37+
38+
class FECompositeNeonArithmeticApplier final : public FilterEffectConcreteApplier<FEComposite> {
39+
WTF_MAKE_FAST_ALLOCATED;
40+
using Base = FilterEffectConcreteApplier<FEComposite>;
41+
42+
public:
43+
FECompositeNeonArithmeticApplier(const FEComposite&);
44+
45+
private:
46+
template <int b1, int b4>
47+
static inline void computePixels(const uint8_t* source, uint8_t* destination, unsigned pixelArrayLength, float k1, float k2, float k3, float k4);
48+
49+
static inline void applyPlatform(const uint8_t* source, uint8_t* destination, unsigned pixelArrayLength, float k1, float k2, float k3, float k4);
50+
51+
bool apply(const Filter&, const FilterImageVector& inputs, FilterImage& result) const final;
52+
};
53+
54+
} // namespace WebCore
55+
56+
#endif // HAVE(ARM_NEON_INTRINSICS)

Source/WebCore/platform/graphics/filters/FEComposite.cpp

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,9 @@
2525
#include "config.h"
2626
#include "FEComposite.h"
2727

28+
#include "FECompositeNeonArithmeticApplier.h"
2829
#include "FECompositeSoftwareApplier.h"
30+
#include "FECompositeSoftwareArithmeticApplier.h"
2931
#include "Filter.h"
3032
#include <wtf/text/TextStream.h>
3133

@@ -108,7 +110,13 @@ FloatRect FEComposite::calculateImageRect(const Filter& filter, const FilterImag
108110

109111
std::unique_ptr<FilterEffectApplier> FEComposite::createSoftwareApplier() const
110112
{
111-
return FilterEffectApplier::create<FECompositeSoftwareApplier>(*this);
113+
if (m_type != FECOMPOSITE_OPERATOR_ARITHMETIC)
114+
return FilterEffectApplier::create<FECompositeSoftwareApplier>(*this);
115+
#if HAVE(ARM_NEON_INTRINSICS)
116+
return FilterEffectApplier::create<FECompositeNeonArithmeticApplier>(*this);
117+
#else
118+
return FilterEffectApplier::create<FECompositeSoftwareArithmeticApplier>(*this);
119+
#endif
112120
}
113121

114122
static TextStream& operator<<(TextStream& ts, const CompositeOperationType& type)

Source/WebCore/platform/graphics/filters/FEComposite.h

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,13 @@ class FEComposite : public FilterEffect {
7373

7474
WTF::TextStream& externalRepresentation(WTF::TextStream&, FilterRepresentation) const override;
7575

76+
#if HAVE(ARM_NEON_INTRINSICS)
77+
template <int b1, int b4>
78+
static inline void computeArithmeticPixelsNeon(const uint8_t* source, uint8_t* destination, unsigned pixelArrayLength, float k1, float k2, float k3, float k4);
79+
80+
static inline void platformArithmeticNeon(const uint8_t* source, uint8_t* destination, unsigned pixelArrayLength, float k1, float k2, float k3, float k4);
81+
#endif
82+
7683
CompositeOperationType m_type;
7784
float m_k1;
7885
float m_k2;

0 commit comments

Comments
 (0)