FastLED 3.9.15
Loading...
Searching...
No Matches

◆ PixelIterator()

template<typename PixelControllerT>
PixelIterator::PixelIterator ( PixelControllerT * pc,
Rgbw rgbw )
inline

Definition at line 88 of file pixel_iterator.h.

90 // Manually build up a vtable.
91 // Wait... what? Stupid nerds trying to show off how smart they are...
92 // Why not just use a virtual function?!
93 //
94 // Before you think this then you should know that the alternative straight
95 // forward way is to have a virtual interface class that PixelController inherits from.
96 // ...and that was already tried. And if you try to do this yourself
97 // this then let me tell you what is going to happen...
98 //
99 // EVERY SINGLE PLATFORM THAT HAS A COMPILED BINARY SIZE CHECK WILL IMMEDIATELY
100 // FAIL AS THE BINARY BLOWS UP BY 10-30%!!! It doesn't matter if only one PixelController
101 // with a vtable is used, gcc seems not to de-virtualize the calls. And we really care
102 // about binary size since FastLED needs to run on those tiny little microcontrollers like
103 // the Attiny85 (and family) which are in the sub $1 range used for commercial products.
104 //
105 // So to satisfy these tight memory requirements we make the dynamic dispatch used in PixelIterator
106 // an optional zero-cost abstraction which doesn't affect the binary size for platforms that
107 // don't use it. So that's why we are using this manual construction of the vtable that is built
108 // up using template magic. If your platform has lots of memory then you'll gladly trade
109 // a sliver of memory for the convenience of having a concrete implementation of
110 // PixelController that you can use without having to make all your driver code a template.
111 //
112 // Btw, this pattern in C++ is called the "type-erasure pattern". It allows non virtual
113 // polymorphism by leveraging the C++ template system to ensure type safety.
114 typedef PixelControllerVtable<PixelControllerT> Vtable;
115 mLoadAndScaleRGBW = &Vtable::loadAndScaleRGBW;
116 mLoadAndScaleRGB = &Vtable::loadAndScaleRGB;
117 mLoadAndScale_APA102_HD = &Vtable::loadAndScale_APA102_HD;
118 mLoadAndScale_WS2816_HD = &Vtable::loadAndScale_WS2816_HD;
119 mStepDithering = &Vtable::stepDithering;
120 mAdvanceData = &Vtable::advanceData;
121 mSize = &Vtable::size;
122 mHas = &Vtable::has;
123 #if FASTLED_HD_COLOR_MIXING
124 mGetHdScale = &Vtable::getHdScale;
125 #endif
126 }
Rgbw rgbw
loadAndScaleRGBFunction mLoadAndScaleRGB
void * mPixelController
loadAndScaleRGBWFunction mLoadAndScaleRGBW
stepDitheringFunction mStepDithering
hasFunction mHas
advanceDataFunction mAdvanceData
loadAndScale_WS2816_HDFunction mLoadAndScale_WS2816_HD
sizeFunction mSize
loadAndScale_APA102_HDFunction mLoadAndScale_APA102_HD

References mAdvanceData, mHas, mLoadAndScale_APA102_HD, mLoadAndScale_WS2816_HD, mLoadAndScaleRGB, mLoadAndScaleRGBW, mPixelController, mRgbw, mSize, mStepDithering, and rgbw.