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 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
77 // Note: There is no cloneSinkTo method because the code usually places
the top part of | 77 // Note: There is no cloneSinkTo method because the code usually places
the top part of |
78 // the pipeline on a new sampler. | 78 // the pipeline on a new sampler. |
79 Base* cloneStageTo(Next* next, Stage* cloneToStage) const; | 79 Base* cloneStageTo(Next* next, Stage* cloneToStage) const; |
80 | 80 |
81 Base* get() const { return reinterpret_cast<Base*>(fSpace); } | 81 Base* get() const { return reinterpret_cast<Base*>(fSpace); } |
82 Base* operator->() const { return this->get(); } | 82 Base* operator->() const { return this->get(); } |
83 Base& operator*() const { return *(this->get()); } | 83 Base& operator*() const { return *(this->get()); } |
84 | 84 |
85 private: | 85 private: |
86 std::function<void (Next*, void*)> fStageCloner; | 86 std::function<void (Next*, void*)> fStageCloner; |
87 alignas(16) mutable char fSpace[kSize]; | 87 mutable char fSpace[kSize]; |
88 bool fIsInitialized; | 88 bool fIsInitialized; |
89 }; | 89 }; |
90 | 90 |
91 ////////////////////////////////////////////////////////////////////////////////
/////////////////// | 91 ////////////////////////////////////////////////////////////////////////////////
/////////////////// |
92 // PolyMemory | 92 // PolyMemory |
93 template <typename Base, size_t kSize> | 93 template <typename Base, size_t kSize> |
94 class PolyMemory { | 94 class PolyMemory { |
95 public: | 95 public: |
96 PolyMemory() : fIsInitialized{false} { } | 96 PolyMemory() : fIsInitialized{false} { } |
97 ~PolyMemory() { | 97 ~PolyMemory() { |
98 if (fIsInitialized) { | 98 if (fIsInitialized) { |
99 this->get()->~Base(); | 99 this->get()->~Base(); |
100 } | 100 } |
101 } | 101 } |
102 template<typename Variant, typename... Args> | 102 template<typename Variant, typename... Args> |
103 void init(Args&& ... args) { | 103 void init(Args&& ... args) { |
104 SkASSERTF(sizeof(Variant) <= sizeof(fSpace), | 104 SkASSERTF(sizeof(Variant) <= sizeof(fSpace), |
105 "Size Variant: %d, Space: %d", sizeof(Variant), sizeof(fSp
ace)); | 105 "Size Variant: %d, Space: %d", sizeof(Variant), sizeof(fSp
ace)); |
106 | 106 |
107 new (&fSpace) Variant(std::forward<Args>(args)...); | 107 new (&fSpace) Variant(std::forward<Args>(args)...); |
108 fIsInitialized = true; | 108 fIsInitialized = true; |
109 } | 109 } |
110 | 110 |
111 Base* get() const { return reinterpret_cast<Base*>(fSpace); } | 111 Base* get() const { return reinterpret_cast<Base*>(fSpace); } |
112 Base* operator->() const { return this->get(); } | 112 Base* operator->() const { return this->get(); } |
113 Base& operator*() const { return *(this->get()); } | 113 Base& operator*() const { return *(this->get()); } |
114 | 114 |
115 private: | 115 private: |
116 alignas(16) mutable char fSpace[kSize]; | 116 mutable char fSpace[kSize]; |
117 bool fIsInitialized; | 117 bool fIsInitialized; |
118 | 118 |
119 }; | 119 }; |
120 | 120 |
121 class PointProcessorInterface; | 121 class PointProcessorInterface; |
122 class SampleProcessorInterface; | 122 class SampleProcessorInterface; |
123 class BlendProcessorInterface; | 123 class BlendProcessorInterface; |
124 class DestinationInterface; | 124 class DestinationInterface; |
125 class PixelAccessorInterface; | 125 class PixelAccessorInterface; |
126 | 126 |
127 // These values were generated by the assert above in Stage::init{Sink|Stage
}. | 127 // These values were generated by the assert above in Stage::init{Sink|Stage
}. |
128 using MatrixStage = Stage<PointProcessorInterface, 160, PointProcessorIn
terface>; | 128 using MatrixStage = Stage<PointProcessorInterface, 56, PointProcessorIn
terface>; |
129 using TileStage = Stage<PointProcessorInterface, 160, SampleProcessorI
nterface>; | 129 using TileStage = Stage<PointProcessorInterface, 48, SampleProcessorI
nterface>; |
130 using SampleStage = Stage<SampleProcessorInterface, 160, BlendProcessorIn
terface>; | 130 using SampleStage = Stage<SampleProcessorInterface, 160, BlendProcessorIn
terface>; |
131 using BlenderStage = Stage<BlendProcessorInterface, 48>; | 131 using BlenderStage = Stage<BlendProcessorInterface, 48>; |
132 using Accessor = PolyMemory<PixelAccessorInterface, 64>; | 132 using Accessor = PolyMemory<PixelAccessorInterface, 64>; |
133 | 133 |
134 private: | 134 private: |
135 PointProcessorInterface* fFirstStage; | 135 PointProcessorInterface* fFirstStage; |
136 MatrixStage fMatrixStage; | 136 MatrixStage fMatrixStage; |
137 TileStage fTileStage; | 137 TileStage fTileStage; |
138 SampleStage fSampleStage; | 138 SampleStage fSampleStage; |
139 BlenderStage fBlenderStage; | 139 BlenderStage fBlenderStage; |
140 DestinationInterface* fLastStage; | 140 DestinationInterface* fLastStage; |
141 Accessor fAccessor; | 141 Accessor fAccessor; |
142 }; | 142 }; |
143 | 143 |
144 ////////////////////////////////////////////////////////////////////////////////
//////////////////// | 144 ////////////////////////////////////////////////////////////////////////////////
//////////////////// |
145 // SkEmbeddableLinearPipeline - manage stricter alignment needs for SkLinearBitm
apPipeline. | 145 // SkEmbeddableLinearPipeline - manage stricter alignment needs for SkLinearBitm
apPipeline. |
146 class SkEmbeddableLinearPipeline { | 146 class SkEmbeddableLinearPipeline { |
147 public: | 147 public: |
148 SkEmbeddableLinearPipeline() { } | 148 SkEmbeddableLinearPipeline() { } |
149 ~SkEmbeddableLinearPipeline() { | 149 ~SkEmbeddableLinearPipeline() { |
150 if (get() != nullptr) { | 150 if (fInitialized) { |
151 get()->~SkLinearBitmapPipeline(); | 151 get()->~SkLinearBitmapPipeline(); |
152 } | 152 } |
153 } | 153 } |
154 | 154 |
155 template <typename... Args> | 155 template <typename... Args> |
156 void init(Args&&... args) { | 156 void init(Args&&... args) { |
157 // Ensure that our pipeline is created at a 16 byte aligned address. | 157 new (fPipelineStorage) SkLinearBitmapPipeline{std::forward<Args>(args)..
.}; |
158 fPipeline = (SkLinearBitmapPipeline*)SkAlign16((intptr_t)fPipelineStorag
e); | 158 fInitialized = true; |
159 new (fPipeline) SkLinearBitmapPipeline{std::forward<Args>(args)...}; | |
160 } | 159 } |
161 | 160 |
162 SkLinearBitmapPipeline* get() const { return fPipeline; } | 161 SkLinearBitmapPipeline* get() const { |
| 162 return reinterpret_cast<SkLinearBitmapPipeline*>(fPipelineStorage); |
| 163 } |
163 SkLinearBitmapPipeline& operator*() const { return *this->get(); } | 164 SkLinearBitmapPipeline& operator*() const { return *this->get(); } |
164 SkLinearBitmapPipeline* operator->() const { return this->get(); } | 165 SkLinearBitmapPipeline* operator->() const { return this->get(); } |
165 | 166 |
166 private: | 167 private: |
167 enum { | 168 alignas(SkLinearBitmapPipeline) mutable char fPipelineStorage[sizeof(SkLinea
rBitmapPipeline)]; |
168 kActualSize = sizeof(SkLinearBitmapPipeline), | 169 bool fInitialized {false}; |
169 kPaddedSize = SkAlignPtr(kActualSize + 12), | |
170 }; | |
171 void* fPipelineStorage[kPaddedSize / sizeof(void*)]; | |
172 SkLinearBitmapPipeline* fPipeline{nullptr}; | |
173 }; | 170 }; |
174 | 171 |
175 #endif // SkLinearBitmapPipeline_DEFINED | 172 #endif // SkLinearBitmapPipeline_DEFINED |
OLD | NEW |