|
1 | 1 | /* |
2 | 2 | * Copyright (C) 2011 University of Szeged |
3 | 3 | * Copyright (C) 2011 Felician Marton |
| 4 | + * Copyright (C) 2022 Apple Inc. All rights reserved. |
4 | 5 | * |
5 | 6 | * Redistribution and use in source and binary forms, with or without |
6 | 7 | * modification, are permitted provided that the following conditions |
|
24 | 25 | * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
25 | 26 | */ |
26 | 27 |
|
27 | | -#ifndef FECompositeArithmeticNEON_h |
28 | | -#define FECompositeArithmeticNEON_h |
| 28 | +#include "config.h" |
| 29 | +#include "FECompositeNeonArithmeticApplier.h" |
29 | 30 |
|
30 | 31 | #if HAVE(ARM_NEON_INTRINSICS) |
31 | 32 |
|
|
35 | 36 |
|
36 | 37 | namespace WebCore { |
37 | 38 |
|
| 39 | +FECompositeNeonArithmeticApplier::FECompositeNeonArithmeticApplier(const FEComposite& effect) |
| 40 | + : Base(effect) |
| 41 | +{ |
| 42 | + ASSERT(m_effect.operation() == FECOMPOSITE_OPERATOR_ARITHMETIC); |
| 43 | +} |
| 44 | + |
38 | 45 | 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) |
40 | 47 | { |
41 | 48 | float32x4_t k1x4 = vdupq_n_f32(k1 / 255); |
42 | 49 | float32x4_t k2x4 = vdupq_n_f32(k2); |
@@ -67,27 +74,52 @@ inline void FECompositeSoftwareApplier::computeArithmeticPixelsNeon(const uint8_ |
67 | 74 | } |
68 | 75 | } |
69 | 76 |
|
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) |
71 | 78 | { |
72 | 79 | if (!k4) { |
73 | 80 | if (!k1) { |
74 | | - computeArithmeticPixelsNeon<0, 0>(source, destination, pixelArrayLength, k1, k2, k3, k4); |
| 81 | + computePixels<0, 0>(source, destination, pixelArrayLength, k1, k2, k3, k4); |
75 | 82 | return; |
76 | 83 | } |
77 | 84 |
|
78 | | - computeArithmeticPixelsNeon<1, 0>(source, destination, pixelArrayLength, k1, k2, k3, k4); |
| 85 | + computePixels<1, 0>(source, destination, pixelArrayLength, k1, k2, k3, k4); |
79 | 86 | return; |
80 | 87 | } |
81 | 88 |
|
82 | 89 | if (!k1) { |
83 | | - computeArithmeticPixelsNeon<0, 1>(source, destination, pixelArrayLength, k1, k2, k3, k4); |
| 90 | + computePixels<0, 1>(source, destination, pixelArrayLength, k1, k2, k3, k4); |
84 | 91 | return; |
85 | 92 | } |
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; |
87 | 121 | } |
88 | 122 |
|
89 | 123 | } // namespace WebCore |
90 | 124 |
|
91 | 125 | #endif // HAVE(ARM_NEON_INTRINSICS) |
92 | | - |
93 | | -#endif // FECompositeArithmeticNEON_h |
|
0 commit comments