Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
40 changes: 34 additions & 6 deletions plugins/rust-search/src/bin/rs-launcher.rs
Original file line number Diff line number Diff line change
Expand Up @@ -305,6 +305,7 @@ unsafe fn step(h: HWND) {
ShowWindow(h, SW_HIDE);
KillTimer(h, T_ANIM);
KillTimer(h, T_CARET);
release_buf();
} else if !moving {
KillTimer(h, T_ANIM);
}
Expand Down Expand Up @@ -1728,6 +1729,38 @@ unsafe fn ensure_icons(h: HWND) {
});
}

thread_local! {
static PAINT_BUF: std::cell::Cell<(HDC, HBITMAP, i32, i32)> = const { std::cell::Cell::new((null_mut(), null_mut(), 0, 0)) };
}

unsafe fn paint_buf(dc: HDC, w: i32, h: i32) -> HDC {
let (mut mem, mut bmp, bw, bh) = PAINT_BUF.get();
if !mem.is_null() && bw >= w && bh >= h {
return mem;
}
if mem.is_null() {
mem = CreateCompatibleDC(dc);
}
if !bmp.is_null() {
DeleteObject(bmp);
}
let (nw, nh) = (w.max(bw), h.max(bh));
bmp = CreateCompatibleBitmap(dc, nw, nh);
SelectObject(mem, bmp);
PAINT_BUF.set((mem, bmp, nw, nh));
mem
}

unsafe fn release_buf() {
let (mem, bmp, _, _) = PAINT_BUF.replace((null_mut(), null_mut(), 0, 0));
if !bmp.is_null() {
DeleteObject(bmp);
}
if !mem.is_null() {
DeleteDC(mem);
}
}

unsafe fn paint(h: HWND) {
ensure_icons(h);
let v = st(|s| View {
Expand Down Expand Up @@ -1756,14 +1789,9 @@ unsafe fn paint(h: HWND) {
let mut rc: RECT = zeroed();
GetClientRect(h, &mut rc);
let (w, hgt) = (rc.right, rc.bottom);
let mem = CreateCompatibleDC(dc);
let bmp = CreateCompatibleBitmap(dc, w, hgt);
let old = SelectObject(mem, bmp);
let mem = paint_buf(dc, w, hgt);
draw(mem, w, hgt, &v);
BitBlt(dc, 0, 0, w, hgt, mem, 0, 0, SRCCOPY);
SelectObject(mem, old);
DeleteObject(bmp);
DeleteDC(mem);
EndPaint(h, &ps);
}

Expand Down
Loading
Loading