| 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 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 50 const SkPixmap& srcPixmap, | 50 const SkPixmap& srcPixmap, |
| 51 float finalAlpha, | 51 float finalAlpha, |
| 52 SkXfermode::Mode xferMode, | 52 SkXfermode::Mode xferMode, |
| 53 const SkImageInfo& dstInfo); | 53 const SkImageInfo& dstInfo); |
| 54 | 54 |
| 55 ~SkLinearBitmapPipeline(); | 55 ~SkLinearBitmapPipeline(); |
| 56 | 56 |
| 57 void shadeSpan4f(int x, int y, SkPM4f* dst, int count); | 57 void shadeSpan4f(int x, int y, SkPM4f* dst, int count); |
| 58 void blitSpan(int32_t x, int32_t y, void* dst, int count); | 58 void blitSpan(int32_t x, int32_t y, void* dst, int count); |
| 59 | 59 |
| 60 template <size_t N> | |
| 61 using Storage = typename std::aligned_storage<N, 16>::type; | |
| 62 | |
| 63 template<typename Base, size_t kSize, typename Next = void> | 60 template<typename Base, size_t kSize, typename Next = void> |
| 64 class Stage { | 61 class Stage { |
| 65 public: | 62 public: |
| 66 Stage() : fIsInitialized{false} {} | 63 Stage() : fIsInitialized{false} {} |
| 67 ~Stage(); | 64 ~Stage(); |
| 68 | 65 |
| 69 template<typename Variant, typename... Args> | 66 template<typename Variant, typename... Args> |
| 70 void initStage(Next* next, Args&& ... args); | 67 void initStage(Next* next, Args&& ... args); |
| 71 | 68 |
| 72 template<typename Variant, typename... Args> | 69 template<typename Variant, typename... Args> |
| 73 void initSink(Args&& ... args); | 70 void initSink(Args&& ... args); |
| 74 | 71 |
| 75 template <typename To, typename From> | 72 template <typename To, typename From> |
| 76 To* getInterface(); | 73 To* getInterface(); |
| 77 | 74 |
| 78 // Copy this stage to `cloneToStage` with `next` as its next stage | 75 // Copy this stage to `cloneToStage` with `next` as its next stage |
| 79 // (not necessarily the same as our next, you see), returning `cloneToSt
age`. | 76 // (not necessarily the same as our next, you see), returning `cloneToSt
age`. |
| 80 // 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 |
| 81 // the pipeline on a new sampler. | 78 // the pipeline on a new sampler. |
| 82 Base* cloneStageTo(Next* next, Stage* cloneToStage) const; | 79 Base* cloneStageTo(Next* next, Stage* cloneToStage) const; |
| 83 | 80 |
| 84 Base* get() const { return reinterpret_cast<Base*>(&fSpace); } | 81 Base* get() const { return reinterpret_cast<Base*>(&fSpace); } |
| 85 Base* operator->() const { return this->get(); } | 82 Base* operator->() const { return this->get(); } |
| 86 Base& operator*() const { return *(this->get()); } | 83 Base& operator*() const { return *(this->get()); } |
| 87 | 84 |
| 88 private: | 85 private: |
| 89 std::function<void (Next*, void*)> fStageCloner; | 86 std::function<void (Next*, void*)> fStageCloner; |
| 90 mutable Storage<kSize> fSpace; | 87 struct SK_STRUCT_ALIGN(16) Space { |
| 91 bool fIsInitialized; | 88 char space[kSize]; |
| 89 }; |
| 90 bool fIsInitialized; |
| 91 mutable Space fSpace; |
| 92 }; | 92 }; |
| 93 | 93 |
| 94 ////////////////////////////////////////////////////////////////////////////////
/////////////////// | 94 ////////////////////////////////////////////////////////////////////////////////
/////////////////// |
| 95 // PolyMemory | 95 // PolyMemory |
| 96 template <typename Base, size_t kSize> | 96 template <typename Base, size_t kSize> |
| 97 class PolyMemory { | 97 class PolyMemory { |
| 98 public: | 98 public: |
| 99 PolyMemory() : fIsInitialized{false} { } | 99 PolyMemory() : fIsInitialized{false} { } |
| 100 ~PolyMemory() { | 100 ~PolyMemory() { |
| 101 if (fIsInitialized) { | 101 if (fIsInitialized) { |
| 102 this->get()->~Base(); | 102 this->get()->~Base(); |
| 103 } | 103 } |
| 104 } | 104 } |
| 105 template<typename Variant, typename... Args> | 105 template<typename Variant, typename... Args> |
| 106 void init(Args&& ... args) { | 106 void init(Args&& ... args) { |
| 107 SkASSERTF(sizeof(Variant) <= sizeof(fSpace), | 107 SkASSERTF(sizeof(Variant) <= sizeof(fSpace), |
| 108 "Size Variant: %d, Space: %d", sizeof(Variant), sizeof(fSp
ace)); | 108 "Size Variant: %d, Space: %d", sizeof(Variant), sizeof(fSp
ace)); |
| 109 | 109 |
| 110 new (&fSpace) Variant(std::forward<Args>(args)...); | 110 new (&fSpace) Variant(std::forward<Args>(args)...); |
| 111 fIsInitialized = true; | 111 fIsInitialized = true; |
| 112 } | 112 } |
| 113 | 113 |
| 114 Base* get() const { return reinterpret_cast<Base*>(&fSpace); } | 114 Base* get() const { return reinterpret_cast<Base*>(&fSpace); } |
| 115 Base* operator->() const { return this->get(); } | 115 Base* operator->() const { return this->get(); } |
| 116 Base& operator*() const { return *(this->get()); } | 116 Base& operator*() const { return *(this->get()); } |
| 117 | 117 |
| 118 private: | 118 private: |
| 119 mutable Storage<kSize> fSpace; | 119 struct SK_STRUCT_ALIGN(16) Space { |
| 120 bool fIsInitialized; | 120 char space[kSize]; |
| 121 }; |
| 122 mutable Space fSpace; |
| 123 bool fIsInitialized; |
| 121 | 124 |
| 122 }; | 125 }; |
| 123 | 126 |
| 124 class PointProcessorInterface; | 127 class PointProcessorInterface; |
| 125 class SampleProcessorInterface; | 128 class SampleProcessorInterface; |
| 126 class BlendProcessorInterface; | 129 class BlendProcessorInterface; |
| 127 class DestinationInterface; | 130 class DestinationInterface; |
| 128 class PixelAccessorInterface; | 131 class PixelAccessorInterface; |
| 129 | 132 |
| 130 // 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
}. |
| (...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 169 private: | 172 private: |
| 170 enum { | 173 enum { |
| 171 kActualSize = sizeof(SkLinearBitmapPipeline), | 174 kActualSize = sizeof(SkLinearBitmapPipeline), |
| 172 kPaddedSize = SkAlignPtr(kActualSize + 12), | 175 kPaddedSize = SkAlignPtr(kActualSize + 12), |
| 173 }; | 176 }; |
| 174 void* fPipelineStorage[kPaddedSize / sizeof(void*)]; | 177 void* fPipelineStorage[kPaddedSize / sizeof(void*)]; |
| 175 SkLinearBitmapPipeline* fPipeline{nullptr}; | 178 SkLinearBitmapPipeline* fPipeline{nullptr}; |
| 176 }; | 179 }; |
| 177 | 180 |
| 178 #endif // SkLinearBitmapPipeline_DEFINED | 181 #endif // SkLinearBitmapPipeline_DEFINED |
| OLD | NEW |