/src/mozilla-central/gfx/2d/Tools.h
Line | Count | Source (jump to first uncovered line) |
1 | | /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ |
2 | | /* vim: set ts=8 sts=2 et sw=2 tw=80: */ |
3 | | /* This Source Code Form is subject to the terms of the Mozilla Public |
4 | | * License, v. 2.0. If a copy of the MPL was not distributed with this |
5 | | * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ |
6 | | |
7 | | #ifndef MOZILLA_GFX_TOOLS_H_ |
8 | | #define MOZILLA_GFX_TOOLS_H_ |
9 | | |
10 | | #include "mozilla/CheckedInt.h" |
11 | | #include "mozilla/MemoryReporting.h" // for MallocSizeOf |
12 | | #include "mozilla/Move.h" |
13 | | #include "mozilla/TypeTraits.h" |
14 | | #include "Types.h" |
15 | | #include "Point.h" |
16 | | #include <math.h> |
17 | | |
18 | | namespace mozilla { |
19 | | namespace gfx { |
20 | | |
21 | | static inline bool |
22 | 0 | IsOperatorBoundByMask(CompositionOp aOp) { |
23 | 0 | switch (aOp) { |
24 | 0 | case CompositionOp::OP_IN: |
25 | 0 | case CompositionOp::OP_OUT: |
26 | 0 | case CompositionOp::OP_DEST_IN: |
27 | 0 | case CompositionOp::OP_DEST_ATOP: |
28 | 0 | case CompositionOp::OP_SOURCE: |
29 | 0 | return false; |
30 | 0 | default: |
31 | 0 | return true; |
32 | 0 | } |
33 | 0 | } Unexecuted instantiation: ConvolutionFilter.cpp:mozilla::gfx::IsOperatorBoundByMask(mozilla::gfx::CompositionOp) Unexecuted instantiation: Factory.cpp:mozilla::gfx::IsOperatorBoundByMask(mozilla::gfx::CompositionOp) Unexecuted instantiation: FilterProcessingSSE2.cpp:mozilla::gfx::IsOperatorBoundByMask(mozilla::gfx::CompositionOp) Unexecuted instantiation: InlineTranslator.cpp:mozilla::gfx::IsOperatorBoundByMask(mozilla::gfx::CompositionOp) Unexecuted instantiation: NativeFontResourceFreeType.cpp:mozilla::gfx::IsOperatorBoundByMask(mozilla::gfx::CompositionOp) Unexecuted instantiation: PathSkia.cpp:mozilla::gfx::IsOperatorBoundByMask(mozilla::gfx::CompositionOp) Unexecuted instantiation: SourceSurfaceSkia.cpp:mozilla::gfx::IsOperatorBoundByMask(mozilla::gfx::CompositionOp) Unexecuted instantiation: UnscaledFontFreeType.cpp:mozilla::gfx::IsOperatorBoundByMask(mozilla::gfx::CompositionOp) Unexecuted instantiation: Unified_cpp_gfx_2d1.cpp:mozilla::gfx::IsOperatorBoundByMask(mozilla::gfx::CompositionOp) Unexecuted instantiation: Unified_cpp_gfx_2d2.cpp:mozilla::gfx::IsOperatorBoundByMask(mozilla::gfx::CompositionOp) Unexecuted instantiation: Unified_cpp_dom_ipc0.cpp:mozilla::gfx::IsOperatorBoundByMask(mozilla::gfx::CompositionOp) |
34 | | |
35 | | template <class T> |
36 | | struct ClassStorage |
37 | | { |
38 | | char bytes[sizeof(T)]; |
39 | | |
40 | | const T *addr() const { return (const T *)bytes; } |
41 | 0 | T *addr() { return (T *)(void *)bytes; } |
42 | | }; |
43 | | |
44 | | static inline bool |
45 | | FuzzyEqual(Float aA, Float aB, Float aErr) |
46 | 0 | { |
47 | 0 | if ((aA + aErr >= aB) && (aA - aErr <= aB)) { |
48 | 0 | return true; |
49 | 0 | } |
50 | 0 | return false; |
51 | 0 | } Unexecuted instantiation: ConvolutionFilter.cpp:mozilla::gfx::FuzzyEqual(float, float, float) Unexecuted instantiation: DrawTargetSkia.cpp:mozilla::gfx::FuzzyEqual(float, float, float) Unexecuted instantiation: Factory.cpp:mozilla::gfx::FuzzyEqual(float, float, float) Unexecuted instantiation: FilterProcessingSSE2.cpp:mozilla::gfx::FuzzyEqual(float, float, float) Unexecuted instantiation: InlineTranslator.cpp:mozilla::gfx::FuzzyEqual(float, float, float) Unexecuted instantiation: NativeFontResourceFreeType.cpp:mozilla::gfx::FuzzyEqual(float, float, float) Unexecuted instantiation: PathSkia.cpp:mozilla::gfx::FuzzyEqual(float, float, float) Unexecuted instantiation: SourceSurfaceSkia.cpp:mozilla::gfx::FuzzyEqual(float, float, float) Unexecuted instantiation: UnscaledFontFreeType.cpp:mozilla::gfx::FuzzyEqual(float, float, float) Unexecuted instantiation: Unified_cpp_gfx_2d0.cpp:mozilla::gfx::FuzzyEqual(float, float, float) Unexecuted instantiation: Unified_cpp_gfx_2d1.cpp:mozilla::gfx::FuzzyEqual(float, float, float) Unexecuted instantiation: Unified_cpp_gfx_2d2.cpp:mozilla::gfx::FuzzyEqual(float, float, float) Unexecuted instantiation: Unified_cpp_dom_ipc0.cpp:mozilla::gfx::FuzzyEqual(float, float, float) |
52 | | |
53 | | static inline void |
54 | | NudgeToInteger(float *aVal) |
55 | 0 | { |
56 | 0 | float r = floorf(*aVal + 0.5f); |
57 | 0 | // The error threshold should be proportional to the rounded value. This |
58 | 0 | // bounds the relative error introduced by the nudge operation. However, |
59 | 0 | // when the rounded value is 0, the error threshold can't be proportional |
60 | 0 | // to the rounded value (we'd never round), so we just choose the same |
61 | 0 | // threshold as for a rounded value of 1. |
62 | 0 | if (FuzzyEqual(r, *aVal, r == 0.0f ? 1e-6f : fabs(r*1e-6f))) { |
63 | 0 | *aVal = r; |
64 | 0 | } |
65 | 0 | } Unexecuted instantiation: ConvolutionFilter.cpp:mozilla::gfx::NudgeToInteger(float*) Unexecuted instantiation: DrawTargetSkia.cpp:mozilla::gfx::NudgeToInteger(float*) Unexecuted instantiation: Factory.cpp:mozilla::gfx::NudgeToInteger(float*) Unexecuted instantiation: FilterProcessingSSE2.cpp:mozilla::gfx::NudgeToInteger(float*) Unexecuted instantiation: InlineTranslator.cpp:mozilla::gfx::NudgeToInteger(float*) Unexecuted instantiation: NativeFontResourceFreeType.cpp:mozilla::gfx::NudgeToInteger(float*) Unexecuted instantiation: PathSkia.cpp:mozilla::gfx::NudgeToInteger(float*) Unexecuted instantiation: SourceSurfaceSkia.cpp:mozilla::gfx::NudgeToInteger(float*) Unexecuted instantiation: UnscaledFontFreeType.cpp:mozilla::gfx::NudgeToInteger(float*) Unexecuted instantiation: Unified_cpp_gfx_2d0.cpp:mozilla::gfx::NudgeToInteger(float*) Unexecuted instantiation: Unified_cpp_gfx_2d1.cpp:mozilla::gfx::NudgeToInteger(float*) Unexecuted instantiation: Unified_cpp_gfx_2d2.cpp:mozilla::gfx::NudgeToInteger(float*) Unexecuted instantiation: Unified_cpp_dom_ipc0.cpp:mozilla::gfx::NudgeToInteger(float*) |
66 | | |
67 | | static inline void |
68 | | NudgeToInteger(float *aVal, float aErr) |
69 | 0 | { |
70 | 0 | float r = floorf(*aVal + 0.5f); |
71 | 0 | if (FuzzyEqual(r, *aVal, aErr)) { |
72 | 0 | *aVal = r; |
73 | 0 | } |
74 | 0 | } Unexecuted instantiation: ConvolutionFilter.cpp:mozilla::gfx::NudgeToInteger(float*, float) Unexecuted instantiation: DrawTargetSkia.cpp:mozilla::gfx::NudgeToInteger(float*, float) Unexecuted instantiation: Factory.cpp:mozilla::gfx::NudgeToInteger(float*, float) Unexecuted instantiation: FilterProcessingSSE2.cpp:mozilla::gfx::NudgeToInteger(float*, float) Unexecuted instantiation: InlineTranslator.cpp:mozilla::gfx::NudgeToInteger(float*, float) Unexecuted instantiation: NativeFontResourceFreeType.cpp:mozilla::gfx::NudgeToInteger(float*, float) Unexecuted instantiation: PathSkia.cpp:mozilla::gfx::NudgeToInteger(float*, float) Unexecuted instantiation: SourceSurfaceSkia.cpp:mozilla::gfx::NudgeToInteger(float*, float) Unexecuted instantiation: UnscaledFontFreeType.cpp:mozilla::gfx::NudgeToInteger(float*, float) Unexecuted instantiation: Unified_cpp_gfx_2d0.cpp:mozilla::gfx::NudgeToInteger(float*, float) Unexecuted instantiation: Unified_cpp_gfx_2d1.cpp:mozilla::gfx::NudgeToInteger(float*, float) Unexecuted instantiation: Unified_cpp_gfx_2d2.cpp:mozilla::gfx::NudgeToInteger(float*, float) Unexecuted instantiation: Unified_cpp_dom_ipc0.cpp:mozilla::gfx::NudgeToInteger(float*, float) |
75 | | |
76 | | static inline void |
77 | | NudgeToInteger(double *aVal) |
78 | 0 | { |
79 | 0 | float f = float(*aVal); |
80 | 0 | NudgeToInteger(&f); |
81 | 0 | *aVal = f; |
82 | 0 | } Unexecuted instantiation: ConvolutionFilter.cpp:mozilla::gfx::NudgeToInteger(double*) Unexecuted instantiation: DrawTargetSkia.cpp:mozilla::gfx::NudgeToInteger(double*) Unexecuted instantiation: Factory.cpp:mozilla::gfx::NudgeToInteger(double*) Unexecuted instantiation: FilterProcessingSSE2.cpp:mozilla::gfx::NudgeToInteger(double*) Unexecuted instantiation: InlineTranslator.cpp:mozilla::gfx::NudgeToInteger(double*) Unexecuted instantiation: NativeFontResourceFreeType.cpp:mozilla::gfx::NudgeToInteger(double*) Unexecuted instantiation: PathSkia.cpp:mozilla::gfx::NudgeToInteger(double*) Unexecuted instantiation: SourceSurfaceSkia.cpp:mozilla::gfx::NudgeToInteger(double*) Unexecuted instantiation: UnscaledFontFreeType.cpp:mozilla::gfx::NudgeToInteger(double*) Unexecuted instantiation: Unified_cpp_gfx_2d0.cpp:mozilla::gfx::NudgeToInteger(double*) Unexecuted instantiation: Unified_cpp_gfx_2d1.cpp:mozilla::gfx::NudgeToInteger(double*) Unexecuted instantiation: Unified_cpp_gfx_2d2.cpp:mozilla::gfx::NudgeToInteger(double*) Unexecuted instantiation: Unified_cpp_dom_ipc0.cpp:mozilla::gfx::NudgeToInteger(double*) |
83 | | |
84 | | static inline Float |
85 | | Distance(Point aA, Point aB) |
86 | 0 | { |
87 | 0 | return hypotf(aB.x - aA.x, aB.y - aA.y); |
88 | 0 | } Unexecuted instantiation: ConvolutionFilter.cpp:mozilla::gfx::Distance(mozilla::gfx::PointTyped<mozilla::gfx::UnknownUnits, float>, mozilla::gfx::PointTyped<mozilla::gfx::UnknownUnits, float>) Unexecuted instantiation: DrawTargetSkia.cpp:mozilla::gfx::Distance(mozilla::gfx::PointTyped<mozilla::gfx::UnknownUnits, float>, mozilla::gfx::PointTyped<mozilla::gfx::UnknownUnits, float>) Unexecuted instantiation: Factory.cpp:mozilla::gfx::Distance(mozilla::gfx::PointTyped<mozilla::gfx::UnknownUnits, float>, mozilla::gfx::PointTyped<mozilla::gfx::UnknownUnits, float>) Unexecuted instantiation: FilterProcessingSSE2.cpp:mozilla::gfx::Distance(mozilla::gfx::PointTyped<mozilla::gfx::UnknownUnits, float>, mozilla::gfx::PointTyped<mozilla::gfx::UnknownUnits, float>) Unexecuted instantiation: InlineTranslator.cpp:mozilla::gfx::Distance(mozilla::gfx::PointTyped<mozilla::gfx::UnknownUnits, float>, mozilla::gfx::PointTyped<mozilla::gfx::UnknownUnits, float>) Unexecuted instantiation: NativeFontResourceFreeType.cpp:mozilla::gfx::Distance(mozilla::gfx::PointTyped<mozilla::gfx::UnknownUnits, float>, mozilla::gfx::PointTyped<mozilla::gfx::UnknownUnits, float>) Unexecuted instantiation: PathSkia.cpp:mozilla::gfx::Distance(mozilla::gfx::PointTyped<mozilla::gfx::UnknownUnits, float>, mozilla::gfx::PointTyped<mozilla::gfx::UnknownUnits, float>) Unexecuted instantiation: SourceSurfaceSkia.cpp:mozilla::gfx::Distance(mozilla::gfx::PointTyped<mozilla::gfx::UnknownUnits, float>, mozilla::gfx::PointTyped<mozilla::gfx::UnknownUnits, float>) Unexecuted instantiation: UnscaledFontFreeType.cpp:mozilla::gfx::Distance(mozilla::gfx::PointTyped<mozilla::gfx::UnknownUnits, float>, mozilla::gfx::PointTyped<mozilla::gfx::UnknownUnits, float>) Unexecuted instantiation: Unified_cpp_gfx_2d0.cpp:mozilla::gfx::Distance(mozilla::gfx::PointTyped<mozilla::gfx::UnknownUnits, float>, mozilla::gfx::PointTyped<mozilla::gfx::UnknownUnits, float>) Unexecuted instantiation: Unified_cpp_gfx_2d1.cpp:mozilla::gfx::Distance(mozilla::gfx::PointTyped<mozilla::gfx::UnknownUnits, float>, mozilla::gfx::PointTyped<mozilla::gfx::UnknownUnits, float>) Unexecuted instantiation: Unified_cpp_gfx_2d2.cpp:mozilla::gfx::Distance(mozilla::gfx::PointTyped<mozilla::gfx::UnknownUnits, float>, mozilla::gfx::PointTyped<mozilla::gfx::UnknownUnits, float>) Unexecuted instantiation: Unified_cpp_dom_ipc0.cpp:mozilla::gfx::Distance(mozilla::gfx::PointTyped<mozilla::gfx::UnknownUnits, float>, mozilla::gfx::PointTyped<mozilla::gfx::UnknownUnits, float>) |
89 | | |
90 | | static inline int |
91 | | BytesPerPixel(SurfaceFormat aFormat) |
92 | 0 | { |
93 | 0 | switch (aFormat) { |
94 | 0 | case SurfaceFormat::A8: |
95 | 0 | return 1; |
96 | 0 | case SurfaceFormat::R5G6B5_UINT16: |
97 | 0 | case SurfaceFormat::A16: |
98 | 0 | return 2; |
99 | 0 | case SurfaceFormat::R8G8B8: |
100 | 0 | case SurfaceFormat::B8G8R8: |
101 | 0 | return 3; |
102 | 0 | case SurfaceFormat::HSV: |
103 | 0 | case SurfaceFormat::Lab: |
104 | 0 | return 3 * sizeof(float); |
105 | 0 | case SurfaceFormat::Depth: |
106 | 0 | return sizeof(uint16_t); |
107 | 0 | default: |
108 | 0 | return 4; |
109 | 0 | } |
110 | 0 | } Unexecuted instantiation: ConvolutionFilter.cpp:mozilla::gfx::BytesPerPixel(mozilla::gfx::SurfaceFormat) Unexecuted instantiation: DrawTargetSkia.cpp:mozilla::gfx::BytesPerPixel(mozilla::gfx::SurfaceFormat) Unexecuted instantiation: FilterProcessingSSE2.cpp:mozilla::gfx::BytesPerPixel(mozilla::gfx::SurfaceFormat) Unexecuted instantiation: NativeFontResourceFreeType.cpp:mozilla::gfx::BytesPerPixel(mozilla::gfx::SurfaceFormat) Unexecuted instantiation: PathSkia.cpp:mozilla::gfx::BytesPerPixel(mozilla::gfx::SurfaceFormat) Unexecuted instantiation: SourceSurfaceSkia.cpp:mozilla::gfx::BytesPerPixel(mozilla::gfx::SurfaceFormat) Unexecuted instantiation: UnscaledFontFreeType.cpp:mozilla::gfx::BytesPerPixel(mozilla::gfx::SurfaceFormat) Unexecuted instantiation: Unified_cpp_dom_ipc0.cpp:mozilla::gfx::BytesPerPixel(mozilla::gfx::SurfaceFormat) |
111 | | |
112 | | static inline SurfaceFormat |
113 | | SurfaceFormatForAlphaBitDepth(uint32_t aBitDepth) |
114 | 0 | { |
115 | 0 | if (aBitDepth == 8) { |
116 | 0 | return SurfaceFormat::A8; |
117 | 0 | } else if (aBitDepth == 10 || |
118 | 0 | aBitDepth == 12) { |
119 | 0 | return SurfaceFormat::A16; |
120 | 0 | } |
121 | 0 | MOZ_ASSERT_UNREACHABLE("Unsupported alpha bit depth"); |
122 | 0 | return SurfaceFormat::UNKNOWN; |
123 | 0 | } Unexecuted instantiation: ConvolutionFilter.cpp:mozilla::gfx::SurfaceFormatForAlphaBitDepth(unsigned int) Unexecuted instantiation: DrawTargetSkia.cpp:mozilla::gfx::SurfaceFormatForAlphaBitDepth(unsigned int) Unexecuted instantiation: Factory.cpp:mozilla::gfx::SurfaceFormatForAlphaBitDepth(unsigned int) Unexecuted instantiation: FilterProcessingSSE2.cpp:mozilla::gfx::SurfaceFormatForAlphaBitDepth(unsigned int) Unexecuted instantiation: InlineTranslator.cpp:mozilla::gfx::SurfaceFormatForAlphaBitDepth(unsigned int) Unexecuted instantiation: NativeFontResourceFreeType.cpp:mozilla::gfx::SurfaceFormatForAlphaBitDepth(unsigned int) Unexecuted instantiation: PathSkia.cpp:mozilla::gfx::SurfaceFormatForAlphaBitDepth(unsigned int) Unexecuted instantiation: SourceSurfaceSkia.cpp:mozilla::gfx::SurfaceFormatForAlphaBitDepth(unsigned int) Unexecuted instantiation: UnscaledFontFreeType.cpp:mozilla::gfx::SurfaceFormatForAlphaBitDepth(unsigned int) Unexecuted instantiation: Unified_cpp_gfx_2d0.cpp:mozilla::gfx::SurfaceFormatForAlphaBitDepth(unsigned int) Unexecuted instantiation: Unified_cpp_gfx_2d1.cpp:mozilla::gfx::SurfaceFormatForAlphaBitDepth(unsigned int) Unexecuted instantiation: Unified_cpp_gfx_2d2.cpp:mozilla::gfx::SurfaceFormatForAlphaBitDepth(unsigned int) Unexecuted instantiation: Unified_cpp_dom_ipc0.cpp:mozilla::gfx::SurfaceFormatForAlphaBitDepth(unsigned int) |
124 | | |
125 | | static inline bool |
126 | 0 | IsOpaqueFormat(SurfaceFormat aFormat) { |
127 | 0 | switch (aFormat) { |
128 | 0 | case SurfaceFormat::B8G8R8X8: |
129 | 0 | case SurfaceFormat::R8G8B8X8: |
130 | 0 | case SurfaceFormat::X8R8G8B8: |
131 | 0 | case SurfaceFormat::YUV: |
132 | 0 | case SurfaceFormat::NV12: |
133 | 0 | case SurfaceFormat::YUV422: |
134 | 0 | case SurfaceFormat::R5G6B5_UINT16: |
135 | 0 | return true; |
136 | 0 | default: |
137 | 0 | return false; |
138 | 0 | } |
139 | 0 | } Unexecuted instantiation: ConvolutionFilter.cpp:mozilla::gfx::IsOpaqueFormat(mozilla::gfx::SurfaceFormat) Unexecuted instantiation: DrawTargetSkia.cpp:mozilla::gfx::IsOpaqueFormat(mozilla::gfx::SurfaceFormat) Unexecuted instantiation: Factory.cpp:mozilla::gfx::IsOpaqueFormat(mozilla::gfx::SurfaceFormat) Unexecuted instantiation: FilterProcessingSSE2.cpp:mozilla::gfx::IsOpaqueFormat(mozilla::gfx::SurfaceFormat) Unexecuted instantiation: InlineTranslator.cpp:mozilla::gfx::IsOpaqueFormat(mozilla::gfx::SurfaceFormat) Unexecuted instantiation: NativeFontResourceFreeType.cpp:mozilla::gfx::IsOpaqueFormat(mozilla::gfx::SurfaceFormat) Unexecuted instantiation: PathSkia.cpp:mozilla::gfx::IsOpaqueFormat(mozilla::gfx::SurfaceFormat) Unexecuted instantiation: SourceSurfaceSkia.cpp:mozilla::gfx::IsOpaqueFormat(mozilla::gfx::SurfaceFormat) Unexecuted instantiation: UnscaledFontFreeType.cpp:mozilla::gfx::IsOpaqueFormat(mozilla::gfx::SurfaceFormat) Unexecuted instantiation: Unified_cpp_gfx_2d0.cpp:mozilla::gfx::IsOpaqueFormat(mozilla::gfx::SurfaceFormat) Unexecuted instantiation: Unified_cpp_gfx_2d1.cpp:mozilla::gfx::IsOpaqueFormat(mozilla::gfx::SurfaceFormat) Unexecuted instantiation: Unified_cpp_gfx_2d2.cpp:mozilla::gfx::IsOpaqueFormat(mozilla::gfx::SurfaceFormat) Unexecuted instantiation: Unified_cpp_dom_ipc0.cpp:mozilla::gfx::IsOpaqueFormat(mozilla::gfx::SurfaceFormat) |
140 | | |
141 | | template<typename T, int alignment = 16> |
142 | | struct AlignedArray |
143 | | { |
144 | | typedef T value_type; |
145 | | |
146 | | AlignedArray() |
147 | | : mPtr(nullptr) |
148 | | , mStorage(nullptr) |
149 | | , mCount(0) |
150 | 0 | { |
151 | 0 | } |
152 | | |
153 | | explicit MOZ_ALWAYS_INLINE AlignedArray(size_t aCount, bool aZero = false) |
154 | | : mPtr(nullptr) |
155 | | , mStorage(nullptr) |
156 | | , mCount(0) |
157 | 0 | { |
158 | 0 | Realloc(aCount, aZero); |
159 | 0 | } |
160 | | |
161 | | MOZ_ALWAYS_INLINE ~AlignedArray() |
162 | 0 | { |
163 | 0 | Dealloc(); |
164 | 0 | } Unexecuted instantiation: mozilla::gfx::AlignedArray<unsigned int, 16>::~AlignedArray() Unexecuted instantiation: mozilla::gfx::AlignedArray<unsigned char, 16>::~AlignedArray() |
165 | | |
166 | | void Dealloc() |
167 | 0 | { |
168 | 0 | // If we fail this assert we'll need to uncomment the loop below to make |
169 | 0 | // sure dtors are properly invoked. If we do that, we should check that the |
170 | 0 | // comment about compiler dead code elimination is in fact true for all the |
171 | 0 | // compilers that we care about. |
172 | 0 | static_assert(mozilla::IsPod<T>::value, |
173 | 0 | "Destructors must be invoked for this type"); |
174 | | #if 0 |
175 | | for (size_t i = 0; i < mCount; ++i) { |
176 | | // Since we used the placement |operator new| function to construct the |
177 | | // elements of this array we need to invoke their destructors manually. |
178 | | // For types where the destructor does nothing the compiler's dead code |
179 | | // elimination step should optimize this loop away. |
180 | | mPtr[i].~T(); |
181 | | } |
182 | | #endif |
183 | |
|
184 | 0 | free(mStorage); |
185 | 0 | mStorage = nullptr; |
186 | 0 | mPtr = nullptr; |
187 | 0 | } Unexecuted instantiation: mozilla::gfx::AlignedArray<unsigned char, 16>::Dealloc() Unexecuted instantiation: mozilla::gfx::AlignedArray<unsigned int, 16>::Dealloc() |
188 | | |
189 | | MOZ_ALWAYS_INLINE void Realloc(size_t aCount, bool aZero = false) |
190 | 0 | { |
191 | 0 | free(mStorage); |
192 | 0 | CheckedInt32 storageByteCount = |
193 | 0 | CheckedInt32(sizeof(T)) * aCount + (alignment - 1); |
194 | 0 | if (!storageByteCount.isValid()) { |
195 | 0 | mStorage = nullptr; |
196 | 0 | mPtr = nullptr; |
197 | 0 | mCount = 0; |
198 | 0 | return; |
199 | 0 | } |
200 | 0 | // We don't create an array of T here, since we don't want ctors to be |
201 | 0 | // invoked at the wrong places if we realign below. |
202 | 0 | if (aZero) { |
203 | 0 | // calloc can be more efficient than new[] for large chunks, |
204 | 0 | // so we use calloc/malloc/free for everything. |
205 | 0 | mStorage = static_cast<uint8_t *>(calloc(1, storageByteCount.value())); |
206 | 0 | } else { |
207 | 0 | mStorage = static_cast<uint8_t *>(malloc(storageByteCount.value())); |
208 | 0 | } |
209 | 0 | if (!mStorage) { |
210 | 0 | mStorage = nullptr; |
211 | 0 | mPtr = nullptr; |
212 | 0 | mCount = 0; |
213 | 0 | return; |
214 | 0 | } |
215 | 0 | if (uintptr_t(mStorage) % alignment) { |
216 | 0 | // Our storage does not start at a <alignment>-byte boundary. Make sure mPtr does! |
217 | 0 | mPtr = (T*)(uintptr_t(mStorage) + alignment - (uintptr_t(mStorage) % alignment)); |
218 | 0 | } else { |
219 | 0 | mPtr = (T*)(mStorage); |
220 | 0 | } |
221 | 0 | // Now that mPtr is pointing to the aligned position we can use placement |
222 | 0 | // |operator new| to invoke any ctors at the correct positions. For types |
223 | 0 | // that have a no-op default constructor the compiler's dead code |
224 | 0 | // elimination step should optimize this away. |
225 | 0 | mPtr = new (mPtr) T[aCount]; |
226 | 0 | mCount = aCount; |
227 | 0 | } Unexecuted instantiation: mozilla::gfx::AlignedArray<unsigned int, 16>::Realloc(unsigned long, bool) Unexecuted instantiation: mozilla::gfx::AlignedArray<unsigned char, 16>::Realloc(unsigned long, bool) |
228 | | |
229 | | void Swap(AlignedArray<T, alignment>& aOther) |
230 | | { |
231 | | mozilla::Swap(mPtr, aOther.mPtr); |
232 | | mozilla::Swap(mStorage, aOther.mStorage); |
233 | | mozilla::Swap(mCount, aOther.mCount); |
234 | | } |
235 | | |
236 | | size_t |
237 | | HeapSizeOfExcludingThis(MallocSizeOf aMallocSizeOf) const |
238 | 0 | { |
239 | 0 | return aMallocSizeOf(mStorage); |
240 | 0 | } |
241 | | |
242 | | MOZ_ALWAYS_INLINE operator T*() |
243 | 0 | { |
244 | 0 | return mPtr; |
245 | 0 | } Unexecuted instantiation: mozilla::gfx::AlignedArray<unsigned char, 16>::operator unsigned char*() Unexecuted instantiation: mozilla::gfx::AlignedArray<unsigned int, 16>::operator unsigned int*() |
246 | | |
247 | | T *mPtr; |
248 | | |
249 | | private: |
250 | | uint8_t *mStorage; |
251 | | size_t mCount; |
252 | | }; |
253 | | |
254 | | /** |
255 | | * Returns aWidth * aBytesPerPixel increased, if necessary, so that it divides |
256 | | * exactly into |alignment|. |
257 | | * |
258 | | * Note that currently |alignment| must be a power-of-2. If for some reason we |
259 | | * want to support NPOT alignment we can revert back to this functions old |
260 | | * implementation. |
261 | | */ |
262 | | template<int alignment> |
263 | | int32_t GetAlignedStride(int32_t aWidth, int32_t aBytesPerPixel) |
264 | 0 | { |
265 | 0 | static_assert(alignment > 0 && (alignment & (alignment-1)) == 0, |
266 | 0 | "This implementation currently require power-of-two alignment"); |
267 | 0 | const int32_t mask = alignment - 1; |
268 | 0 | CheckedInt32 stride = CheckedInt32(aWidth) * CheckedInt32(aBytesPerPixel) + CheckedInt32(mask); |
269 | 0 | if (stride.isValid()) { |
270 | 0 | return stride.value() & ~mask; |
271 | 0 | } |
272 | 0 | return 0; |
273 | 0 | } |
274 | | |
275 | | } // namespace gfx |
276 | | } // namespace mozilla |
277 | | |
278 | | #endif /* MOZILLA_GFX_TOOLS_H_ */ |