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 | |
12 #include "SkColor.h" | 11 #include "SkColor.h" |
13 #include "SkImageInfo.h" | 12 #include "SkImageInfo.h" |
14 #include "SkMatrix.h" | 13 #include "SkMatrix.h" |
15 #include "SkNx.h" | |
16 #include "SkShader.h" | 14 #include "SkShader.h" |
17 | 15 |
18 class SkLinearBitmapPipeline { | 16 class SkLinearBitmapPipeline { |
19 public: | 17 public: |
20 SkLinearBitmapPipeline( | 18 SkLinearBitmapPipeline( |
21 const SkMatrix& inverse, | 19 const SkMatrix& inverse, |
22 SkFilterQuality filterQuality, | 20 SkFilterQuality filterQuality, |
23 SkShader::TileMode xTile, SkShader::TileMode yTile, | 21 SkShader::TileMode xTile, SkShader::TileMode yTile, |
24 float postAlpha, | 22 float postAlpha, |
25 const SkPixmap& srcPixmap); | 23 const SkPixmap& srcPixmap); |
26 ~SkLinearBitmapPipeline(); | 24 ~SkLinearBitmapPipeline(); |
27 | 25 |
28 void shadeSpan4f(int x, int y, SkPM4f* dst, int count); | 26 void shadeSpan4f(int x, int y, SkPM4f* dst, int count); |
29 | 27 |
30 template<typename Base, size_t kSize> | 28 template<typename Base, size_t kSize, typename Next = void> |
31 class PolymorphicUnion { | 29 class Stage { |
32 public: | 30 public: |
33 PolymorphicUnion() : fIsInitialized{false} {} | 31 Stage() : fIsInitialized{false} {} |
34 | 32 ~Stage(); |
35 ~PolymorphicUnion() { | |
36 if (fIsInitialized) { | |
37 this->get()->~Base(); | |
38 } | |
39 } | |
40 | 33 |
41 template<typename Variant, typename... Args> | 34 template<typename Variant, typename... Args> |
42 void Initialize(Args&&... args) { | 35 void initStage(Next* next, Args&& ... args); |
43 SkASSERTF(sizeof(Variant) <= sizeof(fSpace), | |
44 "Size Variant: %d, Space: %d", sizeof(Variant), sizeof(fSp
ace)); | |
45 | 36 |
46 new(&fSpace) Variant(std::forward<Args>(args)...); | 37 template<typename Variant, typename... Args> |
47 fIsInitialized = true; | 38 void initSink(Args&& ... args); |
48 }; | 39 |
| 40 template <typename To, typename From> |
| 41 To* getInterface(); |
| 42 |
| 43 // Copy this stage to `cloneToStage` with `next` as its next stage |
| 44 // (not necessarily the same as our next, you see), returning `cloneToSt
age`. |
| 45 // Note: There is no cloneSinkTo method because the code usually places
the top part of |
| 46 // the pipeline on a new sampler. |
| 47 Base* cloneStageTo(Next* next, Stage* cloneToStage) const; |
49 | 48 |
50 Base* get() const { return reinterpret_cast<Base*>(&fSpace); } | 49 Base* get() const { return reinterpret_cast<Base*>(&fSpace); } |
51 Base* operator->() const { return this->get(); } | 50 Base* operator->() const { return this->get(); } |
52 Base& operator*() const { return *(this->get()); } | 51 Base& operator*() const { return *(this->get()); } |
53 | 52 |
54 private: | 53 private: |
| 54 std::function<void (Next*, void*)> fStageCloner; |
55 struct SK_STRUCT_ALIGN(16) Space { | 55 struct SK_STRUCT_ALIGN(16) Space { |
56 char space[kSize]; | 56 char space[kSize]; |
57 }; | 57 }; |
58 bool fIsInitialized; | 58 bool fIsInitialized; |
59 mutable Space fSpace; | 59 mutable Space fSpace; |
60 }; | 60 }; |
61 | 61 |
62 class PointProcessorInterface; | 62 class PointProcessorInterface; |
63 class SampleProcessorInterface; | 63 class SampleProcessorInterface; |
64 class PixelPlacerInterface; | 64 class BlendProcessorInterface; |
65 class DestinationInterface; | 65 class DestinationInterface; |
66 | 66 |
67 // These values were generated by the assert above in PolymorphicUnion. | 67 // These values were generated by the assert above in Stage::init{Sink|Stage
}. |
68 using MatrixStage = PolymorphicUnion<PointProcessorInterface, 160>; | 68 using MatrixStage = Stage<PointProcessorInterface, 160, PointProcessorInter
face>; |
69 using TileStage = PolymorphicUnion<PointProcessorInterface, 160>; | 69 using TileStage = Stage<PointProcessorInterface, 160, SampleProcessorInte
rface>; |
70 using SampleStage = PolymorphicUnion<SampleProcessorInterface,100>; | 70 using SampleStage = Stage<SampleProcessorInterface, 100, BlendProcessorInte
rface>; |
71 using PixelStage = PolymorphicUnion<PixelPlacerInterface, 80>; | 71 using BlenderStage = Stage<BlendProcessorInterface, 80>; |
72 | 72 |
73 private: | 73 private: |
74 PointProcessorInterface* fFirstStage; | 74 PointProcessorInterface* fFirstStage; |
75 MatrixStage fMatrixStage; | 75 MatrixStage fMatrixStage; |
76 TileStage fTiler; | 76 TileStage fTileStage; |
77 SampleStage fSampleStage; | 77 SampleStage fSampleStage; |
78 PixelStage fPixelStage; | 78 BlenderStage fBlenderStage; |
79 DestinationInterface* fLastStage; | 79 DestinationInterface* fLastStage; |
80 }; | 80 }; |
81 | 81 |
82 #endif // SkLinearBitmapPipeline_DEFINED | 82 #endif // SkLinearBitmapPipeline_DEFINED |
OLD | NEW |