fix batch system

This commit is contained in:
hippoz 2022-07-26 04:47:17 +03:00
parent 3c5c5b6b51
commit b6c6f1e78c
Signed by: hippoz
GPG key ID: 7C52899193467641
2 changed files with 24 additions and 21 deletions

View file

@ -73,10 +73,8 @@ bool Window::dispatch_to_main_widget(Event &event) {
void Window::repaint(Box geometry) { void Window::repaint(Box geometry) {
m_did_repaint_during_batch = true; m_did_repaint_during_batch = true;
if (m_batches)
if (m_is_batching) {
return; return;
}
auto event = RepaintRectEvent(true, geometry); auto event = RepaintRectEvent(true, geometry);
dispatch_to_main_widget(event); dispatch_to_main_widget(event);
@ -92,10 +90,8 @@ void Window::repaint() {
void Window::relayout(Widget *target) { void Window::relayout(Widget *target) {
m_did_relayout_during_batch = true; m_did_relayout_during_batch = true;
if (m_batches)
if (m_is_batching) {
return; return;
}
auto event = RelayoutSubtreeEvent(); auto event = RelayoutSubtreeEvent();
target->dispatch_event(event); target->dispatch_event(event);
@ -103,10 +99,8 @@ void Window::relayout(Widget *target) {
void Window::relayout() { void Window::relayout() {
m_did_relayout_during_batch = true; m_did_relayout_during_batch = true;
if (m_batches)
if (m_is_batching) {
return; return;
}
auto event = RelayoutSubtreeEvent(); auto event = RelayoutSubtreeEvent();
dispatch_to_main_widget(event); dispatch_to_main_widget(event);
@ -118,20 +112,29 @@ void Window::reflow() {
} }
void Window::start_batch() { void Window::start_batch() {
m_is_batching = true; m_batches++;
m_did_relayout_during_batch = false;
m_did_repaint_during_batch = false;
} }
void Window::end_batch() { void Window::end_batch() {
if (m_is_batching) { if (m_batches < 1)
m_is_batching = false; return;
if (m_did_relayout_during_batch) {
reflow(); // we are only interested in performing batch operations for the last batch
} else if (m_did_repaint_during_batch) { if (m_batches > 1) {
repaint(); m_batches--;
} return;
} }
m_batches = 0;
if (m_did_relayout_during_batch) {
reflow();
} else if (m_did_repaint_during_batch) {
repaint();
}
m_did_relayout_during_batch = false;
m_did_repaint_during_batch = false;
} }
void Window::run(bool block) { void Window::run(bool block) {

View file

@ -56,9 +56,9 @@ private:
Box m_rect { 0, 0, 800, 600 }; Box m_rect { 0, 0, 800, 600 };
Painter m_painter {}; Painter m_painter {};
Cairo::RefPtr<Cairo::XlibSurface> m_xlib_surface { nullptr }; Cairo::RefPtr<Cairo::XlibSurface> m_xlib_surface { nullptr };
bool m_is_batching { true }; int m_batches { 1 };
bool m_did_relayout_during_batch { true };
bool m_did_repaint_during_batch { false }; bool m_did_repaint_during_batch { false };
bool m_did_relayout_during_batch { false };
Display *m_x_display { nullptr }; Display *m_x_display { nullptr };