window

present

the presenter interface and the three present paths

mirrored from window/cpp/window.core/present/README.md, which is the only copy of this text. edits made here are overwritten the next time the site builds

presenter_t n its three implementations, layered (UpdateLayeredWindow), opaque (BitBlt) n dcomp (composition swapchain). a presenter owns the backing store n hands a surface up through begin()

links into window.core, this is the only place that is allowed to know where the pixels go

filewhat
presenter.hthe interface, the begin n end contract n what keeps_contents is for
presenter_layered.{h,cpp}P1.4, the default path, a 32bpp top-down dib through ULW_ALPHA
presenter_opaque.{h,cpp}P1.35, the same dib blitted SRCCOPY into a plain windows client
presenter_dcomp.{h,cpp}P1.16, a composition swapchain fed from a WRITE_DISCARD mapped d3d11 texture

the first two share a backing store build line for line n differ only at the present, which is the criterion P1.35 was written to prove. the opaque one has no set_partial switch bc a partial BitBlt is ordinary rather than the doubtful thing the layered path hedges against, n it overrides no set_opacity bc an opaque window has no constant alpha story

it validates only the box it blitted rather than the whole window the way renderer-b2d.ahk:633 does, a partial blit that validates everything eats an expose from another window uncovering ours

the layered one holds an hwnd but never makes, moves or sizes one, the host owns all of that. its set_partial opt-in is the dirty rect present n it still defaults off, mirroring ../../../gui/window.ahk:202 where the same path shipped on n got switched back off

G-window-7 answered it on 2026-08-17 n the answer came in two halves. prcDirty does nothing at all unless BOTH pptDst n psize come with it, with the pair left null NEITHER block showed, i.e. the ahk libs switch was hiding a missing argument n not a broken api, n that argument is supplied here now. but the partial ANIMATION path still failed on real hardware, 240 frames in 3727ms with nothing visibly moving where a full present over the same frames was smooth, so the path is unproven rather than unwritten n the switch stays off. m_partials n m_fulls count which way each present went, n neither of them says the pixels arrived, a present return code proves nothing visually. P1.12 is what reads all of this

the dcomp path, P1.16, n its traps

the route is the one ../../probes/g-window-4-dcomp-alpha.cpp proved on 2026-08-17, a d3d11 device, a CreateSwapChainForComposition swapchain at DXGI_FORMAT_B8G8R8A8_UNORM n DXGI_ALPHA_MODE_PREMULTIPLIED, n a one visual dcomp tree bound to the hwnd. begin() maps a D3D11_USAGE_DYNAMIC texture WRITE_DISCARD n hands that back, end() copies it into the back buffer n presents. no shader n no d2d, bc the seam is a pointer n a stride n a present path needing a draw call would have broken it

  • it does NOT keep its contents, keeps_contents() is false n that is the whole point of the item. a WRITE_DISCARD map hands back undefined memory, so last frames pixels are gone n a partial repaint would leave driver garbage outside the dirty box. the dirty model has to repaint whole here n narrow only the present
  • it DOES pace frames since P1.17, paces_frames() is true, so the pump runs no frame timer of its own on this path. see the section below for what actually does the pacing, bc it is not the thing it looks like
  • the stride is NOT width * 4. the map hands back whatever RowPitch the driver picked, measured at 896 bytes for a 200px wide texture where width * 4 is 800. anything working its own stride out from the width rasterises into the wrong rows, which is exactly why the seam carries both
  • the window must be WS_EX_NOREDIRECTIONBITMAP n must NOT be WS_EX_LAYERED. a redirection bitmap sits in front of the composition visual n hides everything presented, n a layered window is drawn by ULW n never shows a visual at all, so host_t::create treats the two flags as exclusive
  • DXGI_ALPHA_MODE_PREMULTIPLIED is 1, not 2. the console text in the g-window-4 probe says 2 n that one line is just wrong, GetDesc1 reads back 1 on a swapchain asked for premultiplied. the gate itself was signed off by eye n is unaffected
  • including presenter_dcomp.h costs you the name small. d3d11.h drags rpcndr.h in behind it n that header does #define small char, which WIN32_LEAN_AND_MEAN otherwise keeps out of the build. the error is a C2628, followed by char is illegal pointing at a line with nothing wrong with it
  • a live back buffer reference makes a later ResizeBuffers fail with DXGI_ERROR_INVALID_CALL n nothing anywhere saying why, so end() lets go of its one straight after the copy. the resize is done in place rather than by rebuilding the device, which is the gpu resize this path was wanted for

the pacing n the dirty rect present, P1.17

two separate things landed together n the interesting part is that the obvious one is not the one doing the work. a mutation run settled both

sync_interval = 1 on Present1 is the pacing, n the frame latency waitable is not. a build with wait_frame() taken out entirely still lands on the refresh, bc Present1 blocks in there instead, where a build with the wait left in n a sync interval of 0 free runs at 7975 fps. so the waitable never changes WHETHER there is a block, only where it sits

what it buys is latency. with it the shape is wait then draw, without it the shape is draw then wait, i.e. pixels rasterised a whole refresh before the vblank that shows them. measured over 60 frames, 488ms sat in begin() against 8ms in end() with the waitable, n 0.4ms against 465ms without it. the check for it times the two halves rather than counting frames, bc a frame count cannot tell the two shapes apart n a first pass at this had exactly that hole in it

end() narrows the PRESENT n never the copy. the whole upload texture goes into the back buffer every frame n only the Present1 dirty rect is narrow, bc a flip chain rotates buffers so buffer 0 this frame is the one that was on screen two frames back n a sub copy would leave the rest of it showing that

that also makes the rect safe in a way the layered one never was. the buffer being flipped is always the complete frame, so a dirty rect can only ever stop dwm recompositing what did not change, it can never show a stale pixel the way a ULW prcDirty can, which is why dcomp is in partial_proven n layered still is not. it is still a PROMISE though, dwm keeps its own last composition outside the box, so a caller lying about what it repainted leaves that much of the window stale

  • the swapchain flags have to go back into ResizeBuffers as they were, they REPLACE what the swapchain has rather than adding to it. passing 0 for a waitable swapchain is refused, measured, the whole resize comes back DXGI_ERROR_INVALID_CALL, so the trap is a dead window n not a quiet loss of pacing. P1.16s resize checks catch it
  • the first present after a create or a resize is always FULL, a dirty rect only means something against a buffer the compositor has already seen once
  • presents() reads GetLastPresentCount, i.e. the runtime counting n not us. a counter of our own would only ever say we reached the call, where the idle criterion is about a frame being TAKEN

what none of this proves, n both were found by mutations left alive on purpose. that dwm really recomposites less for a dirty rect is not readable in process, a build that never sends one passes every check, the same wall G-window-7 hit. n the full frame gate on the first present is the docs rule rather than an observation, a build without it passes too

reading what actually landed

set_readback(true) then read_back(surface) is the only way to see what the swapchain took, n it exists bc buffer 0 goes undefined the moment Present returns, measured, the first pixel reads back 0 straight after a present that definitely worked. so the copy has to be taken inside end() between the upload n the present n no caller can reach in there. it is off by default n costs one gpu side copy a frame while it is on. everything past the present belongs to the compositor n cannot be read from in process at all, so nothing here can tell you a pixel reached the screen, that half is G-window-4

On this page