Is there any non-obvious way to push multiple, arbitrary pixel values into a bitmap/display that's faster than making setColor and drawPixel calls on each pixel?
My watchface wants to fill a relatively large area of the screen with pixel values that it computes on the fly. Specifically, I have some source grayscale pixel data which I'm scaling, clipping, rotating, and dithering to generate a different image every few minutes.
I've done a lot of work to make my pixel-transforming code reasonably quick, such that now much of the execution time of each frame is just the calls to `Dc.setColor` and `Dc.drawPixel` that actually push pixels into an offscreen bitmap. I've verified that in the Simulator's Profiler view, and also by commenting out those calls and running on the device.
Right now I can generate and draw ~100 pixels on each update before my watchface uses too much time and gets killed. But it seems like there are enough cycles to generate many more pixels than that, if I could get them into a Bitmap or the display more efficiently.
For example:
- Somehow access the raw memory used by an offscreen bitmap, say as an `Array<Number>`?
- Put some pixel values in an array and copy (blit) them all at once to a Bitmap?
- Use a smaller palette, fitting more pixels into each Number, and set multiple pixels at once using a single Number value?
- Construct a bit mask and use it to fill multiple pixels with the same color in one call?
- Somehow reduce the overhead of repeatedly mapping the same few Color values to 4-bit raw pixel values that I imagine is eating time?
Lower-level pixel operations like this are often available on performance-constrained platforms, but I can't find anything useful in the docs.
Some things that I've tried that aren't faster:
- Offscreen Bitmap vs drawing to the display (same speed)
- Use a palette with just WHITE, LT_GRAY, DK_GRAY, BLACK, and TRANSPARENT (same)
- Write all pixels of each color in a single pass to avoid most of the setColor calls (the overhead of managing bit vectors, etc. is more than the savings)
- Batch runs of similar values and draw using drawLine (doesn't really apply to my dithered pixels)
For the time being, I'm splitting the rendering across multiple update cycles, which is pretty tricky to manage, and isn't always responsive enough when the device decides not to call onUpdate when I have drawing to finish.
I realize I may be pushing the platform in a way it wasn't really intended to be pushed, but I really like the results I'm getting, and if such a technique existed, it would unlock lots of interesting possibilities (Doom, anyone?)