A Bitmap is a GPU image, as a hardware bitmap is on Android. The CPU never draws its pixels:
Canvas on a bitmap records into the bitmap's own display list. Each frame takes what was recorded since the
last one (Frame flattens it as a node's list) and draws it into the bitmap's image before the frame's own draws.
Compose caches its vector icons this way. The image has a multisampled image of its own that keeps what was
drawn, so that the next drawing goes over it with the same 4x MSAA. When the image holds more than the
multisampled one (after an upload), a draw copies it over first.setPixels, eraseColor, copyPixelsFromBuffer) go up whole, premultiplied, before
the bitmap is drawn again.createBitmap of a part, a matrix or a scale, and copy, draw the source bitmap into the new one through a
Canvas.DRAW_BITMAP draws the image's source rectangle onto the destination with the paint's alpha. A color filter of
SrcIn (or SrcAtop) gives the filter's color where the bitmap is, as an icon's tint does, and one of Modulate
multiplies the texels.Cleaner runs) frees its images at the next frame.getPixel and the other reads see only the pixels the app set, not what a canvas drew: a readback is the last
resort, for an app that reads them.
An encoded image (BitmapFactory, ImageDecoder, a drawable resource) decodes on the CPU into a bitmap's pixels,
which then go up as the app's own pixels do. src/android/hwui/image.c is the codec, the HLE of Skia's: FFmpeg's
PNG, JPEG, WebP, GIF and BMP decoders find the format from its signature, and libswscale converts the decoder's
format to Android's int colors (AV_PIX_FMT_RGB32, 0xAARRGGBB in the host's byte order, as a jint holds it). It
also does the sample size (rounded down, up for a JPEG, as Skia's codecs do) and the density scale of a resource
((int)(size * scale + 0.5f), as BitmapFactory does) with area averaging, in the same pass. Bitmap.compress
encodes PNG and JPEG with FFmpeg's encoders.
A PNG's npTc chunk, which aapt writes for a .9.png, becomes the bitmap's nine-patch chunk in a device's byte
order (little-endian), as Android's NinePatchPeeker makes it, scaled with the bitmap. A drawable resource with it
is a NinePatchDrawable with the chunk's padding. Canvas.drawPatch draws the nine parts: the fixed ones keep their
size (they shrink together when the rectangle is smaller), and the stretchable ones share the rest.
Made from docs/platforms/android-apps/hwui.md at 69237645142c. GPL-3.0-or-later.