Tue, 06 Jan 2015 21:39:09 +0100
Conditionally force memory storage according to privacy.thirdparty.isolate;
This solves Tor bug #9701, complying with disk avoidance documented in
https://www.torproject.org/projects/torbrowser/design/#disk-avoidance.
michael@0 | 1 | /* -*- Mode: C++; tab-width: 20; indent-tabs-mode: nil; c-basic-offset: 2 -*- |
michael@0 | 2 | * This Source Code Form is subject to the terms of the Mozilla Public |
michael@0 | 3 | * License, v. 2.0. If a copy of the MPL was not distributed with this |
michael@0 | 4 | * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ |
michael@0 | 5 | |
michael@0 | 6 | #include "FilterProcessing.h" |
michael@0 | 7 | |
michael@0 | 8 | namespace mozilla { |
michael@0 | 9 | namespace gfx { |
michael@0 | 10 | |
michael@0 | 11 | TemporaryRef<DataSourceSurface> |
michael@0 | 12 | FilterProcessing::ExtractAlpha(DataSourceSurface* aSource) |
michael@0 | 13 | { |
michael@0 | 14 | IntSize size = aSource->GetSize(); |
michael@0 | 15 | RefPtr<DataSourceSurface> alpha = Factory::CreateDataSourceSurface(size, SurfaceFormat::A8); |
michael@0 | 16 | uint8_t* sourceData = aSource->GetData(); |
michael@0 | 17 | int32_t sourceStride = aSource->Stride(); |
michael@0 | 18 | uint8_t* alphaData = alpha->GetData(); |
michael@0 | 19 | int32_t alphaStride = alpha->Stride(); |
michael@0 | 20 | |
michael@0 | 21 | if (Factory::HasSSE2()) { |
michael@0 | 22 | #ifdef USE_SSE2 |
michael@0 | 23 | ExtractAlpha_SSE2(size, sourceData, sourceStride, alphaData, alphaStride); |
michael@0 | 24 | #endif |
michael@0 | 25 | } else { |
michael@0 | 26 | ExtractAlpha_Scalar(size, sourceData, sourceStride, alphaData, alphaStride); |
michael@0 | 27 | } |
michael@0 | 28 | |
michael@0 | 29 | return alpha; |
michael@0 | 30 | } |
michael@0 | 31 | |
michael@0 | 32 | TemporaryRef<DataSourceSurface> |
michael@0 | 33 | FilterProcessing::ConvertToB8G8R8A8(SourceSurface* aSurface) |
michael@0 | 34 | { |
michael@0 | 35 | if (Factory::HasSSE2()) { |
michael@0 | 36 | #ifdef USE_SSE2 |
michael@0 | 37 | return ConvertToB8G8R8A8_SSE2(aSurface); |
michael@0 | 38 | #endif |
michael@0 | 39 | } |
michael@0 | 40 | return ConvertToB8G8R8A8_Scalar(aSurface); |
michael@0 | 41 | } |
michael@0 | 42 | |
michael@0 | 43 | TemporaryRef<DataSourceSurface> |
michael@0 | 44 | FilterProcessing::ApplyBlending(DataSourceSurface* aInput1, DataSourceSurface* aInput2, |
michael@0 | 45 | BlendMode aBlendMode) |
michael@0 | 46 | { |
michael@0 | 47 | if (Factory::HasSSE2()) { |
michael@0 | 48 | #ifdef USE_SSE2 |
michael@0 | 49 | return ApplyBlending_SSE2(aInput1, aInput2, aBlendMode); |
michael@0 | 50 | #endif |
michael@0 | 51 | } |
michael@0 | 52 | return ApplyBlending_Scalar(aInput1, aInput2, aBlendMode); |
michael@0 | 53 | } |
michael@0 | 54 | |
michael@0 | 55 | void |
michael@0 | 56 | FilterProcessing::ApplyMorphologyHorizontal(uint8_t* aSourceData, int32_t aSourceStride, |
michael@0 | 57 | uint8_t* aDestData, int32_t aDestStride, |
michael@0 | 58 | const IntRect& aDestRect, int32_t aRadius, |
michael@0 | 59 | MorphologyOperator aOp) |
michael@0 | 60 | { |
michael@0 | 61 | if (Factory::HasSSE2()) { |
michael@0 | 62 | #ifdef USE_SSE2 |
michael@0 | 63 | ApplyMorphologyHorizontal_SSE2( |
michael@0 | 64 | aSourceData, aSourceStride, aDestData, aDestStride, aDestRect, aRadius, aOp); |
michael@0 | 65 | #endif |
michael@0 | 66 | } else { |
michael@0 | 67 | ApplyMorphologyHorizontal_Scalar( |
michael@0 | 68 | aSourceData, aSourceStride, aDestData, aDestStride, aDestRect, aRadius, aOp); |
michael@0 | 69 | } |
michael@0 | 70 | } |
michael@0 | 71 | |
michael@0 | 72 | void |
michael@0 | 73 | FilterProcessing::ApplyMorphologyVertical(uint8_t* aSourceData, int32_t aSourceStride, |
michael@0 | 74 | uint8_t* aDestData, int32_t aDestStride, |
michael@0 | 75 | const IntRect& aDestRect, int32_t aRadius, |
michael@0 | 76 | MorphologyOperator aOp) |
michael@0 | 77 | { |
michael@0 | 78 | if (Factory::HasSSE2()) { |
michael@0 | 79 | #ifdef USE_SSE2 |
michael@0 | 80 | ApplyMorphologyVertical_SSE2( |
michael@0 | 81 | aSourceData, aSourceStride, aDestData, aDestStride, aDestRect, aRadius, aOp); |
michael@0 | 82 | #endif |
michael@0 | 83 | } else { |
michael@0 | 84 | ApplyMorphologyVertical_Scalar( |
michael@0 | 85 | aSourceData, aSourceStride, aDestData, aDestStride, aDestRect, aRadius, aOp); |
michael@0 | 86 | } |
michael@0 | 87 | } |
michael@0 | 88 | |
michael@0 | 89 | TemporaryRef<DataSourceSurface> |
michael@0 | 90 | FilterProcessing::ApplyColorMatrix(DataSourceSurface* aInput, const Matrix5x4 &aMatrix) |
michael@0 | 91 | { |
michael@0 | 92 | if (Factory::HasSSE2()) { |
michael@0 | 93 | #ifdef USE_SSE2 |
michael@0 | 94 | return ApplyColorMatrix_SSE2(aInput, aMatrix); |
michael@0 | 95 | #endif |
michael@0 | 96 | } |
michael@0 | 97 | return ApplyColorMatrix_Scalar(aInput, aMatrix); |
michael@0 | 98 | } |
michael@0 | 99 | |
michael@0 | 100 | void |
michael@0 | 101 | FilterProcessing::ApplyComposition(DataSourceSurface* aSource, DataSourceSurface* aDest, |
michael@0 | 102 | CompositeOperator aOperator) |
michael@0 | 103 | { |
michael@0 | 104 | if (Factory::HasSSE2()) { |
michael@0 | 105 | #ifdef USE_SSE2 |
michael@0 | 106 | ApplyComposition_SSE2(aSource, aDest, aOperator); |
michael@0 | 107 | #endif |
michael@0 | 108 | } else { |
michael@0 | 109 | ApplyComposition_Scalar(aSource, aDest, aOperator); |
michael@0 | 110 | } |
michael@0 | 111 | } |
michael@0 | 112 | |
michael@0 | 113 | void |
michael@0 | 114 | FilterProcessing::SeparateColorChannels(DataSourceSurface* aSource, |
michael@0 | 115 | RefPtr<DataSourceSurface>& aChannel0, |
michael@0 | 116 | RefPtr<DataSourceSurface>& aChannel1, |
michael@0 | 117 | RefPtr<DataSourceSurface>& aChannel2, |
michael@0 | 118 | RefPtr<DataSourceSurface>& aChannel3) |
michael@0 | 119 | { |
michael@0 | 120 | IntSize size = aSource->GetSize(); |
michael@0 | 121 | aChannel0 = Factory::CreateDataSourceSurface(size, SurfaceFormat::A8); |
michael@0 | 122 | aChannel1 = Factory::CreateDataSourceSurface(size, SurfaceFormat::A8); |
michael@0 | 123 | aChannel2 = Factory::CreateDataSourceSurface(size, SurfaceFormat::A8); |
michael@0 | 124 | aChannel3 = Factory::CreateDataSourceSurface(size, SurfaceFormat::A8); |
michael@0 | 125 | uint8_t* sourceData = aSource->GetData(); |
michael@0 | 126 | int32_t sourceStride = aSource->Stride(); |
michael@0 | 127 | uint8_t* channel0Data = aChannel0->GetData(); |
michael@0 | 128 | uint8_t* channel1Data = aChannel1->GetData(); |
michael@0 | 129 | uint8_t* channel2Data = aChannel2->GetData(); |
michael@0 | 130 | uint8_t* channel3Data = aChannel3->GetData(); |
michael@0 | 131 | int32_t channelStride = aChannel0->Stride(); |
michael@0 | 132 | |
michael@0 | 133 | if (Factory::HasSSE2()) { |
michael@0 | 134 | #ifdef USE_SSE2 |
michael@0 | 135 | SeparateColorChannels_SSE2(size, sourceData, sourceStride, channel0Data, channel1Data, channel2Data, channel3Data, channelStride); |
michael@0 | 136 | #endif |
michael@0 | 137 | } else { |
michael@0 | 138 | SeparateColorChannels_Scalar(size, sourceData, sourceStride, channel0Data, channel1Data, channel2Data, channel3Data, channelStride); |
michael@0 | 139 | } |
michael@0 | 140 | } |
michael@0 | 141 | |
michael@0 | 142 | TemporaryRef<DataSourceSurface> |
michael@0 | 143 | FilterProcessing::CombineColorChannels(DataSourceSurface* aChannel0, DataSourceSurface* aChannel1, |
michael@0 | 144 | DataSourceSurface* aChannel2, DataSourceSurface* aChannel3) |
michael@0 | 145 | { |
michael@0 | 146 | IntSize size = aChannel0->GetSize(); |
michael@0 | 147 | RefPtr<DataSourceSurface> result = |
michael@0 | 148 | Factory::CreateDataSourceSurface(size, SurfaceFormat::B8G8R8A8); |
michael@0 | 149 | int32_t resultStride = result->Stride(); |
michael@0 | 150 | uint8_t* resultData = result->GetData(); |
michael@0 | 151 | int32_t channelStride = aChannel0->Stride(); |
michael@0 | 152 | uint8_t* channel0Data = aChannel0->GetData(); |
michael@0 | 153 | uint8_t* channel1Data = aChannel1->GetData(); |
michael@0 | 154 | uint8_t* channel2Data = aChannel2->GetData(); |
michael@0 | 155 | uint8_t* channel3Data = aChannel3->GetData(); |
michael@0 | 156 | |
michael@0 | 157 | if (Factory::HasSSE2()) { |
michael@0 | 158 | #ifdef USE_SSE2 |
michael@0 | 159 | CombineColorChannels_SSE2(size, resultStride, resultData, channelStride, channel0Data, channel1Data, channel2Data, channel3Data); |
michael@0 | 160 | #endif |
michael@0 | 161 | } else { |
michael@0 | 162 | CombineColorChannels_Scalar(size, resultStride, resultData, channelStride, channel0Data, channel1Data, channel2Data, channel3Data); |
michael@0 | 163 | } |
michael@0 | 164 | |
michael@0 | 165 | return result; |
michael@0 | 166 | } |
michael@0 | 167 | |
michael@0 | 168 | void |
michael@0 | 169 | FilterProcessing::DoPremultiplicationCalculation(const IntSize& aSize, |
michael@0 | 170 | uint8_t* aTargetData, int32_t aTargetStride, |
michael@0 | 171 | uint8_t* aSourceData, int32_t aSourceStride) |
michael@0 | 172 | { |
michael@0 | 173 | if (Factory::HasSSE2()) { |
michael@0 | 174 | #ifdef USE_SSE2 |
michael@0 | 175 | DoPremultiplicationCalculation_SSE2( |
michael@0 | 176 | aSize, aTargetData, aTargetStride, aSourceData, aSourceStride); |
michael@0 | 177 | #endif |
michael@0 | 178 | } else { |
michael@0 | 179 | DoPremultiplicationCalculation_Scalar( |
michael@0 | 180 | aSize, aTargetData, aTargetStride, aSourceData, aSourceStride); |
michael@0 | 181 | } |
michael@0 | 182 | } |
michael@0 | 183 | |
michael@0 | 184 | void |
michael@0 | 185 | FilterProcessing::DoUnpremultiplicationCalculation(const IntSize& aSize, |
michael@0 | 186 | uint8_t* aTargetData, int32_t aTargetStride, |
michael@0 | 187 | uint8_t* aSourceData, int32_t aSourceStride) |
michael@0 | 188 | { |
michael@0 | 189 | if (Factory::HasSSE2()) { |
michael@0 | 190 | #ifdef USE_SSE2 |
michael@0 | 191 | DoUnpremultiplicationCalculation_SSE2( |
michael@0 | 192 | aSize, aTargetData, aTargetStride, aSourceData, aSourceStride); |
michael@0 | 193 | #endif |
michael@0 | 194 | } else { |
michael@0 | 195 | DoUnpremultiplicationCalculation_Scalar( |
michael@0 | 196 | aSize, aTargetData, aTargetStride, aSourceData, aSourceStride); |
michael@0 | 197 | } |
michael@0 | 198 | } |
michael@0 | 199 | |
michael@0 | 200 | TemporaryRef<DataSourceSurface> |
michael@0 | 201 | FilterProcessing::RenderTurbulence(const IntSize &aSize, const Point &aOffset, const Size &aBaseFrequency, |
michael@0 | 202 | int32_t aSeed, int aNumOctaves, TurbulenceType aType, bool aStitch, const Rect &aTileRect) |
michael@0 | 203 | { |
michael@0 | 204 | if (Factory::HasSSE2()) { |
michael@0 | 205 | #ifdef USE_SSE2 |
michael@0 | 206 | return RenderTurbulence_SSE2(aSize, aOffset, aBaseFrequency, aSeed, aNumOctaves, aType, aStitch, aTileRect); |
michael@0 | 207 | #endif |
michael@0 | 208 | } |
michael@0 | 209 | return RenderTurbulence_Scalar(aSize, aOffset, aBaseFrequency, aSeed, aNumOctaves, aType, aStitch, aTileRect); |
michael@0 | 210 | } |
michael@0 | 211 | |
michael@0 | 212 | TemporaryRef<DataSourceSurface> |
michael@0 | 213 | FilterProcessing::ApplyArithmeticCombine(DataSourceSurface* aInput1, DataSourceSurface* aInput2, Float aK1, Float aK2, Float aK3, Float aK4) |
michael@0 | 214 | { |
michael@0 | 215 | if (Factory::HasSSE2()) { |
michael@0 | 216 | #ifdef USE_SSE2 |
michael@0 | 217 | return ApplyArithmeticCombine_SSE2(aInput1, aInput2, aK1, aK2, aK3, aK4); |
michael@0 | 218 | #endif |
michael@0 | 219 | } |
michael@0 | 220 | return ApplyArithmeticCombine_Scalar(aInput1, aInput2, aK1, aK2, aK3, aK4); |
michael@0 | 221 | } |
michael@0 | 222 | |
michael@0 | 223 | } // namespace gfx |
michael@0 | 224 | } // namespace mozilla |