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

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

Issue 2473143002: Use alignas to force alignment. (Closed)
Patch Set: Remove comment. 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 alignas(16) mutable char fSpace[kSize];
88 char space[kSize]; 88 bool fIsInitialized;
89 };
90 bool fIsInitialized;
91 mutable Space fSpace;
92 }; 89 };
93 90
94 //////////////////////////////////////////////////////////////////////////////// /////////////////// 91 //////////////////////////////////////////////////////////////////////////////// ///////////////////
95 // PolyMemory 92 // PolyMemory
96 template <typename Base, size_t kSize> 93 template <typename Base, size_t kSize>
97 class PolyMemory { 94 class PolyMemory {
98 public: 95 public:
99 PolyMemory() : fIsInitialized{false} { } 96 PolyMemory() : fIsInitialized{false} { }
100 ~PolyMemory() { 97 ~PolyMemory() {
101 if (fIsInitialized) { 98 if (fIsInitialized) {
102 this->get()->~Base(); 99 this->get()->~Base();
103 } 100 }
104 } 101 }
105 template<typename Variant, typename... Args> 102 template<typename Variant, typename... Args>
106 void init(Args&& ... args) { 103 void init(Args&& ... args) {
107 SkASSERTF(sizeof(Variant) <= sizeof(fSpace), 104 SkASSERTF(sizeof(Variant) <= sizeof(fSpace),
108 "Size Variant: %d, Space: %d", sizeof(Variant), sizeof(fSp ace)); 105 "Size Variant: %d, Space: %d", sizeof(Variant), sizeof(fSp ace));
109 106
110 new (&fSpace) Variant(std::forward<Args>(args)...); 107 new (&fSpace) Variant(std::forward<Args>(args)...);
111 fIsInitialized = true; 108 fIsInitialized = true;
112 } 109 }
113 110
114 Base* get() const { return reinterpret_cast<Base*>(&fSpace); } 111 Base* get() const { return reinterpret_cast<Base*>(fSpace); }
115 Base* operator->() const { return this->get(); } 112 Base* operator->() const { return this->get(); }
116 Base& operator*() const { return *(this->get()); } 113 Base& operator*() const { return *(this->get()); }
117 114
118 private: 115 private:
119 struct SK_STRUCT_ALIGN(16) Space { 116 alignas(16) mutable char fSpace[kSize];
120 char space[kSize]; 117 bool fIsInitialized;
121 };
122 mutable Space fSpace;
123 bool fIsInitialized;
124 118
125 }; 119 };
126 120
127 class PointProcessorInterface; 121 class PointProcessorInterface;
128 class SampleProcessorInterface; 122 class SampleProcessorInterface;
129 class BlendProcessorInterface; 123 class BlendProcessorInterface;
130 class DestinationInterface; 124 class DestinationInterface;
131 class PixelAccessorInterface; 125 class PixelAccessorInterface;
132 126
133 // 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 }.
134 using MatrixStage = Stage<PointProcessorInterface, 160, PointProcessorIn terface>; 128 using MatrixStage = Stage<PointProcessorInterface, 160, PointProcessorIn terface>;
135 using TileStage = Stage<PointProcessorInterface, 160, SampleProcessorI nterface>; 129 using TileStage = Stage<PointProcessorInterface, 160, SampleProcessorI nterface>;
136 using SampleStage = Stage<SampleProcessorInterface, 160, BlendProcessorIn terface>; 130 using SampleStage = Stage<SampleProcessorInterface, 160, BlendProcessorIn terface>;
137 using BlenderStage = Stage<BlendProcessorInterface, 40>; 131 using BlenderStage = Stage<BlendProcessorInterface, 48>;
138 using Accessor = PolyMemory<PixelAccessorInterface, 64>; 132 using Accessor = PolyMemory<PixelAccessorInterface, 64>;
139 133
140 private: 134 private:
141 PointProcessorInterface* fFirstStage; 135 PointProcessorInterface* fFirstStage;
142 MatrixStage fMatrixStage; 136 MatrixStage fMatrixStage;
143 TileStage fTileStage; 137 TileStage fTileStage;
144 SampleStage fSampleStage; 138 SampleStage fSampleStage;
145 BlenderStage fBlenderStage; 139 BlenderStage fBlenderStage;
146 DestinationInterface* fLastStage; 140 DestinationInterface* fLastStage;
147 Accessor fAccessor; 141 Accessor fAccessor;
(...skipping 24 matching lines...) Expand all
172 private: 166 private:
173 enum { 167 enum {
174 kActualSize = sizeof(SkLinearBitmapPipeline), 168 kActualSize = sizeof(SkLinearBitmapPipeline),
175 kPaddedSize = SkAlignPtr(kActualSize + 12), 169 kPaddedSize = SkAlignPtr(kActualSize + 12),
176 }; 170 };
177 void* fPipelineStorage[kPaddedSize / sizeof(void*)]; 171 void* fPipelineStorage[kPaddedSize / sizeof(void*)];
178 SkLinearBitmapPipeline* fPipeline{nullptr}; 172 SkLinearBitmapPipeline* fPipeline{nullptr};
179 }; 173 };
180 174
181 #endif // SkLinearBitmapPipeline_DEFINED 175 #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