OLD | NEW |
1 /* | 1 /* |
2 * Copyright 2016 Google Inc. | 2 * Copyright 2016 Google Inc. |
3 * | 3 * |
4 * Use of this source code is governed by a BSD-style license that can be | 4 * Use of this source code is governed by a BSD-style license that can be |
5 * found in the LICENSE file. | 5 * found in the LICENSE file. |
6 */ | 6 */ |
7 | 7 |
8 #ifndef SkLinearBitmapPipeline_DEFINED | 8 #ifndef SkLinearBitmapPipeline_DEFINED |
9 #define SkLinearBitmapPipeline_DEFINED | 9 #define SkLinearBitmapPipeline_DEFINED |
10 | 10 |
(...skipping 11 matching lines...) Expand all Loading... |
22 SkFilterQuality filterQuality, | 22 SkFilterQuality filterQuality, |
23 SkShader::TileMode xTile, SkShader::TileMode yTile, | 23 SkShader::TileMode xTile, SkShader::TileMode yTile, |
24 const SkPixmap& srcPixmap); | 24 const SkPixmap& srcPixmap); |
25 ~SkLinearBitmapPipeline(); | 25 ~SkLinearBitmapPipeline(); |
26 | 26 |
27 void shadeSpan4f(int x, int y, SkPM4f* dst, int count); | 27 void shadeSpan4f(int x, int y, SkPM4f* dst, int count); |
28 | 28 |
29 template<typename Base, size_t kSize> | 29 template<typename Base, size_t kSize> |
30 class PolymorphicUnion { | 30 class PolymorphicUnion { |
31 public: | 31 public: |
32 PolymorphicUnion() {} | 32 PolymorphicUnion() : fIsInitialized{false} {} |
33 | 33 |
34 ~PolymorphicUnion() { get()->~Base(); } | 34 ~PolymorphicUnion() { |
| 35 if (fIsInitialized) { |
| 36 get()->~Base(); |
| 37 } |
| 38 } |
35 | 39 |
36 template<typename Variant, typename... Args> | 40 template<typename Variant, typename... Args> |
37 void Initialize(Args&&... args) { | 41 void Initialize(Args&&... args) { |
38 SkASSERTF(sizeof(Variant) <= sizeof(fSpace), | 42 SkASSERTF(sizeof(Variant) <= sizeof(fSpace), |
39 "Size Variant: %d, Space: %d", sizeof(Variant), sizeof(fSp
ace)); | 43 "Size Variant: %d, Space: %d", sizeof(Variant), sizeof(fSp
ace)); |
40 | 44 |
41 new(&fSpace) Variant(std::forward<Args>(args)...); | 45 new(&fSpace) Variant(std::forward<Args>(args)...); |
| 46 fIsInitialized = true; |
42 }; | 47 }; |
43 | 48 |
44 Base* get() const { return reinterpret_cast<Base*>(&fSpace); } | 49 Base* get() const { return reinterpret_cast<Base*>(&fSpace); } |
45 Base* operator->() const { return get(); } | 50 Base* operator->() const { return get(); } |
46 Base& operator*() const { return *get(); } | 51 Base& operator*() const { return *get(); } |
47 | 52 |
48 private: | 53 private: |
49 struct SK_STRUCT_ALIGN(16) Space { | 54 struct SK_STRUCT_ALIGN(16) Space { |
50 char space[kSize]; | 55 char space[kSize]; |
51 }; | 56 }; |
| 57 bool fIsInitialized; |
52 mutable Space fSpace; | 58 mutable Space fSpace; |
53 }; | 59 }; |
54 | 60 |
55 class PointProcessorInterface; | 61 class PointProcessorInterface; |
56 class BilerpProcessorInterface; | 62 class BilerpProcessorInterface; |
57 class PixelPlacerInterface; | 63 class PixelPlacerInterface; |
58 | 64 |
59 using MatrixStage = PolymorphicUnion<PointProcessorInterface, 112>; | 65 using MatrixStage = PolymorphicUnion<PointProcessorInterface, 112>; |
60 using FilterStage = PolymorphicUnion<PointProcessorInterface, 8>; | 66 using FilterStage = PolymorphicUnion<PointProcessorInterface, 8>; |
61 using TileStage = PolymorphicUnion<BilerpProcessorInterface, 96>; | 67 using TileStage = PolymorphicUnion<BilerpProcessorInterface, 96>; |
62 using SampleStage = PolymorphicUnion<BilerpProcessorInterface, 80>; | 68 using SampleStage = PolymorphicUnion<BilerpProcessorInterface, 80>; |
63 using PixelStage = PolymorphicUnion<PixelPlacerInterface, 80>; | 69 using PixelStage = PolymorphicUnion<PixelPlacerInterface, 80>; |
64 | 70 |
65 private: | 71 private: |
66 PointProcessorInterface* fFirstStage; | 72 PointProcessorInterface* fFirstStage; |
67 MatrixStage fMatrixStage; | 73 MatrixStage fMatrixStage; |
68 FilterStage fFilterStage; | 74 FilterStage fFilterStage; |
69 TileStage fTileXOrBothStage; | 75 TileStage fTileXOrBothStage; |
70 TileStage fTileYStage; | 76 TileStage fTileYStage; |
71 SampleStage fSampleStage; | 77 SampleStage fSampleStage; |
72 PixelStage fPixelStage; | 78 PixelStage fPixelStage; |
73 }; | 79 }; |
74 | 80 |
75 #endif // SkLinearBitmapPipeline_DEFINED | 81 #endif // SkLinearBitmapPipeline_DEFINED |
OLD | NEW |