| 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 73 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 84 | 84 |
| 85 private: | 85 private: |
| 86 std::function<void (Next*, void*)> fStageCloner; | 86 std::function<void (Next*, void*)> fStageCloner; |
| 87 struct SK_STRUCT_ALIGN(16) Space { | 87 struct SK_STRUCT_ALIGN(16) Space { |
| 88 char space[kSize]; | 88 char space[kSize]; |
| 89 }; | 89 }; |
| 90 bool fIsInitialized; | 90 bool fIsInitialized; |
| 91 mutable Space fSpace; | 91 mutable Space fSpace; |
| 92 }; | 92 }; |
| 93 | 93 |
| 94 ////////////////////////////////////////////////////////////////////////////////
/////////////////// |
| 95 // PolyMemory |
| 96 template <typename Base, size_t kSize> |
| 97 class PolyMemory { |
| 98 public: |
| 99 PolyMemory() : fIsInitialized{false} { } |
| 100 ~PolyMemory() { |
| 101 if (fIsInitialized) { |
| 102 this->get()->~Base(); |
| 103 } |
| 104 } |
| 105 template<typename Variant, typename... Args> |
| 106 void init(Args&& ... args) { |
| 107 SkASSERTF(sizeof(Variant) <= sizeof(fSpace), |
| 108 "Size Variant: %d, Space: %d", sizeof(Variant), sizeof(fSp
ace)); |
| 109 |
| 110 new (&fSpace) Variant(std::forward<Args>(args)...); |
| 111 fIsInitialized = true; |
| 112 } |
| 113 |
| 114 Base* get() const { return reinterpret_cast<Base*>(&fSpace); } |
| 115 Base* operator->() const { return this->get(); } |
| 116 Base& operator*() const { return *(this->get()); } |
| 117 |
| 118 private: |
| 119 struct SK_STRUCT_ALIGN(16) Space { |
| 120 char space[kSize]; |
| 121 }; |
| 122 mutable Space fSpace; |
| 123 bool fIsInitialized; |
| 124 |
| 125 }; |
| 126 |
| 94 class PointProcessorInterface; | 127 class PointProcessorInterface; |
| 95 class SampleProcessorInterface; | 128 class SampleProcessorInterface; |
| 96 class BlendProcessorInterface; | 129 class BlendProcessorInterface; |
| 97 class DestinationInterface; | 130 class DestinationInterface; |
| 131 class PixelAccessorInterface; |
| 98 | 132 |
| 99 // These values were generated by the assert above in Stage::init{Sink|Stage
}. | 133 // These values were generated by the assert above in Stage::init{Sink|Stage
}. |
| 100 using MatrixStage = Stage<PointProcessorInterface, 160, PointProcessorInte
rface>; | 134 using MatrixStage = Stage<PointProcessorInterface, 160, PointProcessorIn
terface>; |
| 101 using TileStage = Stage<PointProcessorInterface, 160, SampleProcessorInt
erface>; | 135 using TileStage = Stage<PointProcessorInterface, 160, SampleProcessorI
nterface>; |
| 102 using SampleStage = Stage<SampleProcessorInterface, 100, BlendProcessorInte
rface>; | 136 using SampleStage = Stage<SampleProcessorInterface, 100, BlendProcessorIn
terface>; |
| 103 using BlenderStage = Stage<BlendProcessorInterface, 40>; | 137 using BlenderStage = Stage<BlendProcessorInterface, 40>; |
| 138 using Accessor = PolyMemory<PixelAccessorInterface, 48>; |
| 104 | 139 |
| 105 private: | 140 private: |
| 106 PointProcessorInterface* fFirstStage; | 141 PointProcessorInterface* fFirstStage; |
| 107 MatrixStage fMatrixStage; | 142 MatrixStage fMatrixStage; |
| 108 TileStage fTileStage; | 143 TileStage fTileStage; |
| 109 SampleStage fSampleStage; | 144 SampleStage fSampleStage; |
| 110 BlenderStage fBlenderStage; | 145 BlenderStage fBlenderStage; |
| 111 DestinationInterface* fLastStage; | 146 DestinationInterface* fLastStage; |
| 147 Accessor fAccessor; |
| 112 }; | 148 }; |
| 113 | 149 |
| 114 ////////////////////////////////////////////////////////////////////////////////
//////////////////// | 150 ////////////////////////////////////////////////////////////////////////////////
//////////////////// |
| 115 // SkEmbeddableLinearPipeline - manage stricter alignment needs for SkLinearBitm
apPipeline. | 151 // SkEmbeddableLinearPipeline - manage stricter alignment needs for SkLinearBitm
apPipeline. |
| 116 class SkEmbeddableLinearPipeline { | 152 class SkEmbeddableLinearPipeline { |
| 117 public: | 153 public: |
| 118 SkEmbeddableLinearPipeline() { } | 154 SkEmbeddableLinearPipeline() { } |
| 119 ~SkEmbeddableLinearPipeline() { | 155 ~SkEmbeddableLinearPipeline() { |
| 120 if (get() != nullptr) { | 156 if (get() != nullptr) { |
| 121 get()->~SkLinearBitmapPipeline(); | 157 get()->~SkLinearBitmapPipeline(); |
| (...skipping 14 matching lines...) Expand all Loading... |
| 136 private: | 172 private: |
| 137 enum { | 173 enum { |
| 138 kActualSize = sizeof(SkLinearBitmapPipeline), | 174 kActualSize = sizeof(SkLinearBitmapPipeline), |
| 139 kPaddedSize = SkAlignPtr(kActualSize + 12), | 175 kPaddedSize = SkAlignPtr(kActualSize + 12), |
| 140 }; | 176 }; |
| 141 void* fPipelineStorage[kPaddedSize / sizeof(void*)]; | 177 void* fPipelineStorage[kPaddedSize / sizeof(void*)]; |
| 142 SkLinearBitmapPipeline* fPipeline{nullptr}; | 178 SkLinearBitmapPipeline* fPipeline{nullptr}; |
| 143 }; | 179 }; |
| 144 | 180 |
| 145 #endif // SkLinearBitmapPipeline_DEFINED | 181 #endif // SkLinearBitmapPipeline_DEFINED |
| OLD | NEW |