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 |
11 | 11 |
12 #include "SkColor.h" | 12 #include "SkColor.h" |
13 #include "SkImageInfo.h" | 13 #include "SkImageInfo.h" |
14 #include "SkMatrix.h" | 14 #include "SkMatrix.h" |
15 #include "SkNx.h" | 15 #include "SkNx.h" |
16 #include "SkShader.h" | 16 #include "SkShader.h" |
17 | 17 |
18 class SkLinearBitmapPipeline { | 18 class SkLinearBitmapPipeline { |
19 public: | 19 public: |
20 SkLinearBitmapPipeline( | 20 SkLinearBitmapPipeline( |
21 const SkMatrix& inverse, | 21 const SkMatrix& inverse, |
22 SkFilterQuality filterQuality, | 22 SkFilterQuality filterQuality, |
23 SkShader::TileMode xTile, SkShader::TileMode yTile, | 23 SkShader::TileMode xTile, SkShader::TileMode yTile, |
| 24 float postAlpha, |
24 const SkPixmap& srcPixmap); | 25 const SkPixmap& srcPixmap); |
25 ~SkLinearBitmapPipeline(); | 26 ~SkLinearBitmapPipeline(); |
26 | 27 |
27 void shadeSpan4f(int x, int y, SkPM4f* dst, int count); | 28 void shadeSpan4f(int x, int y, SkPM4f* dst, int count); |
28 | 29 |
29 template<typename Base, size_t kSize> | 30 template<typename Base, size_t kSize> |
30 class PolymorphicUnion { | 31 class PolymorphicUnion { |
31 public: | 32 public: |
32 PolymorphicUnion() : fIsInitialized{false} {} | 33 PolymorphicUnion() : fIsInitialized{false} {} |
33 | 34 |
34 ~PolymorphicUnion() { | 35 ~PolymorphicUnion() { |
35 if (fIsInitialized) { | 36 if (fIsInitialized) { |
36 get()->~Base(); | 37 this->get()->~Base(); |
37 } | 38 } |
38 } | 39 } |
39 | 40 |
40 template<typename Variant, typename... Args> | 41 template<typename Variant, typename... Args> |
41 void Initialize(Args&&... args) { | 42 void Initialize(Args&&... args) { |
42 SkASSERTF(sizeof(Variant) <= sizeof(fSpace), | 43 SkASSERTF(sizeof(Variant) <= sizeof(fSpace), |
43 "Size Variant: %d, Space: %d", sizeof(Variant), sizeof(fSp
ace)); | 44 "Size Variant: %d, Space: %d", sizeof(Variant), sizeof(fSp
ace)); |
44 | 45 |
45 new(&fSpace) Variant(std::forward<Args>(args)...); | 46 new(&fSpace) Variant(std::forward<Args>(args)...); |
46 fIsInitialized = true; | 47 fIsInitialized = true; |
47 }; | 48 }; |
48 | 49 |
49 Base* get() const { return reinterpret_cast<Base*>(&fSpace); } | 50 Base* get() const { return reinterpret_cast<Base*>(&fSpace); } |
50 Base* operator->() const { return get(); } | 51 Base* operator->() const { return this->get(); } |
51 Base& operator*() const { return *get(); } | 52 Base& operator*() const { return *(this->get()); } |
52 | 53 |
53 private: | 54 private: |
54 struct SK_STRUCT_ALIGN(16) Space { | 55 struct SK_STRUCT_ALIGN(16) Space { |
55 char space[kSize]; | 56 char space[kSize]; |
56 }; | 57 }; |
57 bool fIsInitialized; | 58 bool fIsInitialized; |
58 mutable Space fSpace; | 59 mutable Space fSpace; |
59 }; | 60 }; |
60 | 61 |
61 class PointProcessorInterface; | 62 class PointProcessorInterface; |
62 class BilerpProcessorInterface; | 63 class BilerpProcessorInterface; |
63 class PixelPlacerInterface; | 64 class PixelPlacerInterface; |
64 | 65 |
65 using MatrixStage = PolymorphicUnion<PointProcessorInterface, 112>; | 66 // These values were generated by the assert above in PolymorphicUnion. |
66 using FilterStage = PolymorphicUnion<PointProcessorInterface, 8>; | 67 using MatrixStage = PolymorphicUnion<PointProcessorInterface, 160>; |
67 using TileStage = PolymorphicUnion<BilerpProcessorInterface, 96>; | 68 using TileStage = PolymorphicUnion<PointProcessorInterface, 160>; |
68 using SampleStage = PolymorphicUnion<BilerpProcessorInterface, 80>; | 69 using SampleStage = PolymorphicUnion<BilerpProcessorInterface, 80>; |
69 using PixelStage = PolymorphicUnion<PixelPlacerInterface, 80>; | 70 using PixelStage = PolymorphicUnion<PixelPlacerInterface, 80>; |
70 | 71 |
71 private: | 72 private: |
72 PointProcessorInterface* fFirstStage; | 73 PointProcessorInterface* fFirstStage; |
73 MatrixStage fMatrixStage; | 74 MatrixStage fMatrixStage; |
74 FilterStage fFilterStage; | 75 TileStage fTiler; |
75 TileStage fTileXOrBothStage; | |
76 TileStage fTileYStage; | |
77 SampleStage fSampleStage; | 76 SampleStage fSampleStage; |
78 PixelStage fPixelStage; | 77 PixelStage fPixelStage; |
79 }; | 78 }; |
80 | 79 |
81 #endif // SkLinearBitmapPipeline_DEFINED | 80 #endif // SkLinearBitmapPipeline_DEFINED |
OLD | NEW |