04 Dec 2026 · Compose · 13 min
Breathe on the glass
A phone screen that fogs when you blow on it, and a finger that writes in the fog. This is how the new blur in Compose 1.13 makes the fog, and what it cost on a phone.
Compose 1.13 came out last month with new tools. I want to try them in small screens and share what I learn. This is the first screen.
The tool in this one is a new blur. Until now, a blur in Compose had one strength for the whole element. The new one can be strong in one place and weak in another.
A fogged window is a good place to try it. Years ago there were apps that turned a phone’s screen into one. The ones I could find put a photograph or the camera behind the fog. This one has a street behind it that is drawn by code and moves.
The screen shows a street through a window. The glass starts clear. You blow on the phone and the glass fogs. Then you write in the fog with a finger, as you would on a real window. After a while the fog dries.

The new blur worked in the first test. The rest took longer. The fog had to be much heavier than one blur can make. And on my phone the heavy fog made the picture stutter.
This week’s quest
Every week I give myself a quest: one small thing that should feel like magic. Last week’s was a game played by holding the phone still. This week’s was one sentence long:
A window you fog with your breath and write on with a finger.
Its name is Fogged Glass.
The rules of the quest:
- The glass starts clear. Nothing is fogged until someone blows on the phone.
- A breath fogs it heavily. At full fog the glass is milky, and the street behind it is only colours.
- A finger writes. One finger or several, the way a hand does on a real window.
- The view is a window. There are two streets to choose from: a city in the rain, and a street seen from a café table.
- The fog is the new blur. The screen is there to show that tool, so most of the look has to come from the blur.
- Drawn on a Canvas, and measured. Every shape is drawn by code, and every claim about speed comes from a measurement on a phone.
Most of the work came from the second rule and the last one. The two problems are weight and cost. Weight means that one blur has a limit, and the fog I wanted is heavier than that limit allows. Cost means that a heavy blur is a lot of work for the phone in every frame.

Step 1: A blur that reads its strength from a picture
A blur mixes each point of a picture with the points around it. The radius of the blur says how far around. With a small radius the picture is a little soft. With a large one only colours are left.
Until this release, Modifier.blur took one radius for the whole element. In Compose 1.13 it can also take a block of code, and the block sets a BlurRadiusSpec. The spec says what the radius is at each point. Some specs are ready-made: the same radius everywhere, a radius that grows from top to bottom, a radius that grows outwards from a centre.
One spec takes a shader. A shader gives a value for every point of a surface. A gradient is a shader, and a picture can be used as one too. The blur looks at how opaque the shader is at each point, which means how far it is from transparent. Where the shader is transparent there is no blur. Where it is fully opaque, the blur has its largest radius, and you choose that number.
The radius comes from a picture. That is what a fogged window needs. The picture is opaque where the fog is heavy and transparent where a finger has wiped the fog away.
val spec = remember(painter, density, painter.blurRadius) {
BlurRadiusSpec.shader(with(density) { painter.blurRadius.toDp() }) { painter.mapOverFog }
}
This code makes the spec once for a screen size. painter.blurRadius is the largest radius, and painter.mapOverFog is the picture of the fog, wrapped as a shader.
.blur {
frame.intValue
blurRadiusSpec = spec
}
This is the modifier on the element that gets blurred. The line with frame.intValue is explained in step 2.
A blur with a different radius at each point needs Android 13 or newer. On an older phone the element is drawn without the blur.

Step 2: The fog is a small grid of numbers
The picture of the fog is filled from a small grid of numbers, the fog map. It is 98 points across and 211 down. Each point holds one number from 0 to 255, where 0 is clear glass and 255 is the heaviest fog.
It can be that small because the blur hides anything finer. One point of the map covers about a hundredth of the screen’s width. When the phone reads the map, it smooths between neighbouring points.
The breath and the finger both write into the map.
The breath. A breath lays the fog in three large, soft patches, one after the other. Each patch takes 0.8 seconds of blowing at full strength to fill, and the three together reach every corner of the glass. A patch is heaviest in its middle and gets thinner towards its edge.
The finger. A second grid of the same size remembers how much fog a finger has wiped from each point. The fog at a point is what the patches laid there, less the share of it that was wiped.
A few details copy a real window:
- A patch stays whole for 9 seconds after the breath stops. Then it dries over 6 seconds, from its edge inwards.
- Where a finger lifts, a drop forms. It waits a moment, then runs down and wipes a thin trail behind it.
- A new breath does not cover an old drawing completely. The drawing shows again, faintly, as it does on a real window that fogs a second time.
All of this is plain Kotlin that knows nothing about Android or the screen. That makes it easy to check with unit tests. A unit test is a small program that checks one piece of code. Eighteen of them test the code of the glass, with names such as “a stroke has no gaps however fast the finger moves”.
The map still has to reach the blur. In every frame where the fog changed, its numbers are copied into the picture behind the shader.
fun advance(dt: Float) {
clock += dt
if (!pane.changed) return
val any = pane.cover > 0f
if (any != fogged) fogged = any
mapBytes.rewind()
map.copyPixelsFromBuffer(mapBytes)
}
The spec and the shader from step 1 are never made again. Only the picture they point at changes.
Because the spec stays the same, the blur needs another reason to read the picture again. That reason is frame.intValue, which the blur block reads. It is a counter that goes up by one in every frame. Compose runs the block again when a value that the block read has changed. A frame is one picture on the screen, and my phone shows 60 of them a second. So in every frame the blur reads the picture again, and nothing is composed or laid out again.
Step 3: Hearing a breath
A phone has no sensor for breath. It has a microphone, and air blown on a microphone makes a sound of its own.
That sound is loud, because the air hits the microphone directly. It is also deep. Most of its energy is in low frequencies, below about 500 Hz. Speech near the phone is quieter at the microphone, has more of its energy in higher frequencies, and is full of short gaps.
The microphone gives the sound as a row of numbers, called samples. The code reads them in short pieces of 512 samples, which is 32 ms of sound. It asks two questions about each piece. Is it loud enough? And is it deep? Deep means that at least 55% of its energy is still there after the high frequencies are removed.
When both answers are yes for 0.12 seconds, a breath has started. The wait is there so that a knock on the phone does not fog the glass. When the answers turn to no, the code waits another 0.18 seconds before it ends the breath. So an unsteady breath still counts as one breath.
fun hear(samples: ShortArray, count: Int): Float {
if (count <= 0) return strength
var all = 0f
var deep = 0f
for (i in 0 until count) {
val s = samples[i] / 32768f
low = low * keep + s * (1f - keep)
all += s * s
deep += low * low
}
val level = sqrt(all / count)
val seconds = count.toFloat() / sampleRate
val loud = (room * OVER_ROOM).coerceIn(QUIETEST, loudest)
val windy = level >= loud && deep >= all * lowShare
if (windy) {
heardFor += seconds
quietFor = 0f
} else {
room += (level - room) * min(1f, seconds / if (level < room) ROOM_FALLS else ROOM_RISES)
quietFor += seconds
if (quietFor > BREATH_HOLD) heardFor = 0f
}
strength = if (heardFor >= BREATH_ATTACK && quietFor <= BREATH_HOLD) ((level - loud) / (loud * FULL_OVER_LOUD - loud)).coerceIn(GENTLEST, 1f) else 0f
return strength
}
The loop goes through the samples. low is a running average of the sound, which is an average that is updated with every new sample. Fast changes cancel out in an average and slow ones stay, so low keeps the deep part of the sound. all adds up the energy of the whole sound, and deep adds up the energy of the deep part.
loud is the level a breath has to reach, and it is explained below. windy is the two questions together. BREATH_ATTACK is the 0.12 seconds and BREATH_HOLD is the 0.18 seconds. The last long line turns the loudness into a strength: 0 for no breath, and from 0.45 to 1 for a breath. A harder breath fogs the glass faster.
The sound is read on a thread of its own. A thread is a line of work that runs by itself. The code that draws reads only one number from that thread: the strength of the breath. Nothing that the microphone hears is kept or sent anywhere.
The loudness that counts as a breath began as a guess, and the guess was wrong. With the first version on my phone I had to blow very hard before the glass fogged. The level is on a scale where 1 is the loudest sound the microphone can report. I asked for it to come down a little, twice: from 0.12 to 0.09 and then to 0.07.
One number was still wrong, because microphones differ. On a second phone nothing fogged. One breath measured there read between 0.02 and 0.045, and only its strongest moment passed 0.07.
So the code stopped asking for one number. room is the level of the sound while nobody blows. It follows the sound down in about 0.15 seconds, and up over about 4 seconds, so the soft start of a breath does not raise the level that the breath is about to cross. A breath has to be three times as loud as the room. The code never asks for less than 0.015, and never for more than 0.07. The quiet room in that measurement read between 0.005 and 0.009, so a breath there has to pass a level between 0.015 and 0.027.
This code is the breath detector. Eight unit tests feed it made-up sounds, such as silence, wind and a loud high tone. Two of them are for the room: a soft wind counts after a quiet second, and the same kind of soft sound does not count in a loud room. The rule with the room has not been tried with a real breath yet. Speech and music close to the phone have not been tried either, so they may fog the glass.
Some people cannot blow, and some will not let the app use the microphone. For them, a finger that rests on clear glass for 0.3 seconds fogs a patch under itself.
Step 4: Heavier fog than one blur allows
The second rule asks for milky glass, and a blur with a different radius at each point has a limit. Its radius cannot be more than 150 pixels. In a test on the emulator, a radius of about twice the limit gave the same picture as a radius at the limit. And at 150 pixels the test picture, a pattern of stripes and squares, was soft, but its stripes could still be seen.
A layer is a picture that is drawn separately from the rest, so that it can be changed as a whole. The limit is counted in the pixels of the layer that is blurred. That makes it possible to go past the limit.
Blur a small copy. The street is drawn a second time, much smaller. The small copy is blurred, and then it is stretched back to the size of the screen. When a copy at half size is stretched back, a blur of 150 pixels in it covers 300 pixels of the screen.
A small copy stretched to full size would look bad if anything in it were sharp. Under heavy fog nothing is.
Wiped glass is the opposite. It has to be fully sharp, and a stretched small copy is not. So the screen is made of three layers.
- The street, sharp, at full size.
- The small copy, blurred and stretched. It is cut by the same fog map. Where there is no fog this layer is transparent, and the sharp street shows through it.
- What is not blur. A real fogged window is also pale and wet. So the top layer has a thin milky veil with 2,400 small beads of water. It shows them only where the map has fog. The drops are drawn here too, and so is anything on our side of the glass, such as the cup on the café table.

Spacer(
Modifier
.layout { measurable, constraints ->
val small = measurable.measure(Constraints.fixed(painter.fogWidth, painter.fogHeight))
layout(constraints.maxWidth, constraints.maxHeight) { small.place(0, 0) }
}
.graphicsLayer {
alpha = if (painter.fogged) 1f else 0f
scaleX = painter.fogScale
scaleY = painter.fogScale
transformOrigin = TransformOrigin(0f, 0f)
compositingStrategy = CompositingStrategy.Offscreen
}
.drawWithContent {
drawContent()
painter.cut(drawContext.canvas.nativeCanvas)
}
.blur {
frame.intValue
blurRadiusSpec = spec
}
.drawBehind {
frame.intValue
Trace.beginSection(FoggedTrace.FOG)
try {
painter.street(drawContext.canvas.nativeCanvas, 1f / painter.fogScale, fine = false)
} finally {
Trace.endSection()
}
},
)
This is the second layer. Its parts are easiest to follow from the bottom up.
drawBehind draws the street into the small element. blur is the blur from step 1. drawWithContent takes the blurred copy and cuts it by the fog map. graphicsLayer stretches the result back to the size of the screen, and hides it completely while the glass has no fog. layout, at the top, is what makes the element small.
private val cutPaint = Paint().apply {
shader = mapOverFog
xfermode = PorterDuffXfermode(PorterDuff.Mode.DST_IN)
colorFilter = ColorMatrixColorFilter(floatArrayOf(1f, 0f, 0f, 0f, 0f, 0f, 1f, 0f, 0f, 0f, 0f, 0f, 1f, 0f, 0f, 0f, 0f, 0f, CUT_GAIN, 0f))
}
This paint does the cut. DST_IN keeps what is already drawn only where the new picture, the fog map, is opaque. The matrix multiplies the map’s values by four. Because of this, when the fog is at a quarter of its full value, the blurred layer already hides the sharp street completely. Only below a quarter are the two seen mixed together.
The cut does not hide a flaw of the blur itself. Next to the edge of a wiped stroke, the blur can stretch a bright light into a thin vertical line. It is visible beside the heart in the clip. A softer edge on the finger’s stroke would most likely reduce it.
Step 5: The heavy fog was slow on my phone
At 60 frames a second, each frame has 16.7 ms. A frame that is not ready in time is late, and a late frame is seen as a stutter.
The system keeps a record of every frame that reached the screen late. A trace is a recording of everything the phone does inside a frame, with the time each part takes, and it includes that record. The counts of late frames in this step come from traces.
On the emulator, one frame in about 3,200 was late. On my phone, which runs Android 13, the first version had many late frames. With the small copy at half the size of the screen and the radius at the limit of 150 pixels, 695 of 1,584 frames in one run were late. All of them were frames with fog on the glass. With clear glass, no frame was late.
A slightly smaller radius removed the late frames. At 129 pixels, in the same small copy, no frame was late in two runs. On my phone the cost did not grow evenly with the radius. Between 129 and 150 pixels it went from no late frame to almost every frame late.
Zero late frames can still mean that the phone has no time to spare. So the next measurement was the graphics chip, the part of the phone that does the blur. The measurement read how fast its clock ran and how busy it was. The chip runs its clock slowly when it has little work.
| Size of the small copy | Clock of the graphics chip under fog | How busy it was |
|---|---|---|
| Half the screen | 800 MHz, the highest I saw | 85 to 100% |
| A quarter | 156 to 377 MHz | 48 to 96% |
| About a seventh | 156 MHz, the same as with clear glass | 52 to 61% |
The picture looked the same at all three sizes. Now the copy is a fifth of the screen in width and in height. On my phone that is 216 by 480 pixels. The largest radius in it is 51 pixels, which is far from the limit. Stretched back, that blur covers about a quarter of the screen’s width.

Traces also showed that the rain, the people and the lights cost time. None of that was in the blur.
The rain. Ninety streaks of rain were drawn as ninety lines. The renderer is the part of the system that draws. It handled each line separately, and that took 4 to 5 ms of a frame. That number comes from a trace with extra detail switched on, which adds some time of its own. Now all the streaks are one mesh, a set of 180 triangles that is sent in one call.
The people outside the café. Five people walk past under umbrellas. Their coats and umbrellas are curves, and the phone worked out every curve again in each frame. With clear glass, in one trace of each street, the middle frame took 6.4 ms to draw in the café and 2.2 ms in the city. Runs on my phone differ a lot from one to the next, so that gap is only a rough sign. Now each person is drawn once into a small picture, and each frame only moves the pictures.
The lights. The city has more than two dozen glowing lights, and every glow was a gradient of its own. Now every glow is the same small soft disc, which is stretched and given a colour.
And with clear glass, no fog is drawn at all. While the map is empty, the second layer is not drawn, and the third draws only what is on our side of the glass.
Roads not taken
One idea was to make a new spec in every frame, with a new shader each time. The documentation warns against it. Two specs made from shaders are never equal, even when they look the same. So nothing that depends on the spec can be reused. Changing the picture behind one shader avoids that.
Another idea, for more weight, was two blurs, one after the other. The small copy gave enough weight with one blur, so the second blur was never built.
Drawn on a Canvas
The screen is made with Jetpack Compose. It uses no image files, no SVG and no Lottie animations. A Canvas is a surface that code draws on directly. Both streets are drawn that way, from rectangles, circles, ovals and a few curves: the towers with their lit windows, the lamps, the neon sign, the shop fronts, the cup.
The parts of a street that never move are drawn once into a picture when the screen opens. Each frame then draws that picture, and on top of it the parts that move: the rain, the lights of the cars, the people.
The screen’s own code that runs in every frame creates no new objects in memory. When code creates objects in every frame, the system has to stop now and then to clean them up, and a frame can be late because of it. A scan of the compiled code found new objects only in code that runs when the screen opens, changes size or shows the other street, and when the microphone starts.
How it was measured
Unit tests. Twenty-six of them: eighteen for the glass and eight for the breath detector.
Traces. The counts of late frames and the drawing times in step 5 come from traces of 8 to 30 seconds. The clock and the load of the graphics chip were read from the phone directly, five times in two seconds for each size.
Macrobenchmark on the phone. Macrobenchmark is a Jetpack library. It runs the app on a real phone and records how long every frame took. Nobody can blow on a phone the same way twice, so for these runs a scripted hand uses the screen: it fogs the whole glass, draws a heart, and waits for the fog to dry. That takes 26 seconds, and every run is the same.
The benchmark reads the same record, but not its verdict on which frames were late. For every frame it takes the moment the frame was expected to be finished and the moment it really was, and measures the gap. The library’s notes read any frame that finishes late as a stutter.
The scripted hand played 8 runs on each street, with about 1,550 frames in a run. The table shows the first benchmark and the last one. For the first, the copy was already a quarter of the screen, and the other changes of step 5 had not been made. The last came after all of them.
| City, first | City, last | Café, first | Café, last | |
|---|---|---|---|---|
| How late the middle frame finished | 6.1 ms | 3.3 ms | 6.1 ms | 3.7 ms |
| Frames that finished late | 91% | 75% | 92% | 81% |
The middle frame is the median. Half of the frames finished later than it, and half finished earlier.
So the middle frame finishes 46% less late in the city and 39% less late in the café. Most frames still finish late. In the café the slowest tenth of the frames even got later, from 12.2 ms to 18.6 ms, and the reason has not been found. By the last rule of the quest, the work on frames is not finished.
The system’s own count of late frames does not agree with the benchmark for the same runs. In one of the last runs on the city, it counts 1 frame in 1,522 that reached the screen late. Most likely both are right, because they measure different things. The app seems to be one frame ahead of the screen for the whole run. A frame that finishes a little late then still reaches the screen in time. That explanation has not been proven yet.
These runs also showed that the app’s baseline profile was too old. A baseline profile is a list that tells the phone which code to prepare before the app first runs. The app’s profile had been made before the move to Compose 1.13. It had no lines for this screen. It also lacked 2,597 lines of library code that this screen runs. So every benchmark since the upgrade had run with the old list. A new profile was made on the phone, and the “last” columns of the table were measured with it. Those columns therefore show the changes of step 5 and the new profile together.
What carries over
These carry over to other screens that use the new blur.
A blur can read its radius from a picture. Make the spec and the shader once. To change the blur, change the picture, and let the blur block read one value that changes in every frame.
Blur a small copy. Nothing under a heavy blur is sharp, so the layer that is blurred can be much smaller than the screen. That takes the blur past its limit of 150 pixels. On my phone it also took the graphics chip from the highest clock I saw down to the clock it has with clear glass. Whatever must stay sharp is drawn at full size underneath.
Measure on a phone, with a benchmark. The emulator showed one late frame in about 3,200. On the phone, once the copy was small, the system’s record counted 12 late frames in 3,250. The benchmark, on the same code, showed that nine frames in ten finished late.
Next week, a new quest.
P.S. Accessibility
A screen reader describes the screen as “A window on a street. Breathe on the glass to fog it, then draw in the fog with a finger.” It also offers two actions, “Breathe on the glass” and “Show the other street”, so the glass can be fogged without blowing and without a long press. The last paragraph of step 3 is for the same people: a finger that rests on clear glass fogs it. The two actions still have to be tried with a screen reader.