Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(215)

Side by Side Diff: src/core/SkLinearBitmapPipeline.h

Issue 2473143002: Use alignas to force alignment. (Closed)
Patch Set: Created 4 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « include/core/SkPostConfig.h ('k') | src/core/SkSmallAllocator.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 60 matching lines...) Expand 10 before | Expand all | Expand 10 after
71 71
72 template <typename To, typename From> 72 template <typename To, typename From>
73 To* getInterface(); 73 To* getInterface();
74 74
75 // Copy this stage to `cloneToStage` with `next` as its next stage 75 // Copy this stage to `cloneToStage` with `next` as its next stage
76 // (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`.
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 struct SK_STRUCT_ALIGN(16) Space { 87 // This could be implemented using std::aligned_storage, but MSVC does n ot implement this. Use the
mtklein_C 2016/11/03 20:47:36 This code is clearer and less reinterpret_cast-y t
88 char space[kSize]; 88 // work around from:
89 }; 89 // https://connect.microsoft.com/VisualStudio/feedback/details/1559873/s td-aligned-storage-cannot-align-type-with-16-byte
90 bool fIsInitialized; 90 mutable alignas(16) char fSpace[kSize];
91 mutable Space fSpace; 91 bool fIsInitialized;
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 struct SK_STRUCT_ALIGN(16) Space { 119 mutable alignas(16) char fSpace[kSize];
120 char space[kSize]; 120 bool fIsInitialized;
121 };
122 mutable Space fSpace;
123 bool fIsInitialized;
124 121
125 }; 122 };
126 123
127 class PointProcessorInterface; 124 class PointProcessorInterface;
128 class SampleProcessorInterface; 125 class SampleProcessorInterface;
129 class BlendProcessorInterface; 126 class BlendProcessorInterface;
130 class DestinationInterface; 127 class DestinationInterface;
131 class PixelAccessorInterface; 128 class PixelAccessorInterface;
132 129
133 // These values were generated by the assert above in Stage::init{Sink|Stage }. 130 // These values were generated by the assert above in Stage::init{Sink|Stage }.
134 using MatrixStage = Stage<PointProcessorInterface, 160, PointProcessorIn terface>; 131 using MatrixStage = Stage<PointProcessorInterface, 160, PointProcessorIn terface>;
135 using TileStage = Stage<PointProcessorInterface, 160, SampleProcessorI nterface>; 132 using TileStage = Stage<PointProcessorInterface, 160, SampleProcessorI nterface>;
136 using SampleStage = Stage<SampleProcessorInterface, 160, BlendProcessorIn terface>; 133 using SampleStage = Stage<SampleProcessorInterface, 160, BlendProcessorIn terface>;
137 using BlenderStage = Stage<BlendProcessorInterface, 40>; 134 using BlenderStage = Stage<BlendProcessorInterface, 48>;
138 using Accessor = PolyMemory<PixelAccessorInterface, 64>; 135 using Accessor = PolyMemory<PixelAccessorInterface, 64>;
139 136
140 private: 137 private:
141 PointProcessorInterface* fFirstStage; 138 PointProcessorInterface* fFirstStage;
142 MatrixStage fMatrixStage; 139 MatrixStage fMatrixStage;
143 TileStage fTileStage; 140 TileStage fTileStage;
144 SampleStage fSampleStage; 141 SampleStage fSampleStage;
145 BlenderStage fBlenderStage; 142 BlenderStage fBlenderStage;
146 DestinationInterface* fLastStage; 143 DestinationInterface* fLastStage;
147 Accessor fAccessor; 144 Accessor fAccessor;
(...skipping 24 matching lines...) Expand all
172 private: 169 private:
173 enum { 170 enum {
174 kActualSize = sizeof(SkLinearBitmapPipeline), 171 kActualSize = sizeof(SkLinearBitmapPipeline),
175 kPaddedSize = SkAlignPtr(kActualSize + 12), 172 kPaddedSize = SkAlignPtr(kActualSize + 12),
176 }; 173 };
177 void* fPipelineStorage[kPaddedSize / sizeof(void*)]; 174 void* fPipelineStorage[kPaddedSize / sizeof(void*)];
178 SkLinearBitmapPipeline* fPipeline{nullptr}; 175 SkLinearBitmapPipeline* fPipeline{nullptr};
179 }; 176 };
180 177
181 #endif // SkLinearBitmapPipeline_DEFINED 178 #endif // SkLinearBitmapPipeline_DEFINED
OLDNEW
« no previous file with comments | « include/core/SkPostConfig.h ('k') | src/core/SkSmallAllocator.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698