summaryrefslogtreecommitdiff
path: root/ui.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'ui.cpp')
-rw-r--r--ui.cpp29
1 files changed, 17 insertions, 12 deletions
diff --git a/ui.cpp b/ui.cpp
index 387b5ac..e20a18c 100644
--- a/ui.cpp
+++ b/ui.cpp
@@ -310,8 +310,7 @@ void UI::Renderer::clear(const Rect& r) {
}
}
-const App* g_app;
-void UI::Renderer::flush(int x, int y) {
+void UI::Renderer::flush_cell(int x, int y) {
Cmd* cmd = (Cmd*)cmd_buf;
Cmd* last = (Cmd*)(cmd_buf + cmd_buf_ptr);
Rect cell = Rect(
@@ -344,36 +343,43 @@ void UI::Renderer::flush(int x, int y) {
}
}
-void UI::Renderer::flush() {
+bool UI::Renderer::flush(void* target) {
uint64_t* next = grid == grid_a? grid_b: grid_a;
uint64_t* h = grid;
uint64_t* p = next;
+ bool dirty = false;
+ pixels = (Colour*)target;
int i, j;
for (j = 0; j < grid_size; j++) {
for (i = 0; i < grid_size; i++) {
if (*p != *h) {
- flush(i, j);
+ dirty = true;
+ flush_cell(i, j);
}
h++;
p++;
}
}
grid = next;
+ return dirty;
}
void UI::Renderer::resize(int w, int h) {
- heap_free(arena, pixels);
- pixels = (Colour*)heap_alloc(arena, w * h * sizeof *pixels);
- assert(pixels != 0);
+ int i, e = grid_size * grid_size;
+ uint64_t* next = grid == grid_a? grid_b: grid_a;
bound = Rect(0, 0, w, h);
+ for (i = 0; i < e; i++)
+ next[i] = 0;
}
void UI::Renderer::init(Heap* heap, int w, int h) {
arena = heap;
- pixels = (Colour*)heap_alloc(heap, w * h * sizeof *pixels);
- assert(pixels != 0);
+ int i, e = grid_size * grid_size;
+ bound = Rect(0, 0, w, h);
bound = Rect(0, 0, w, h);
grid = grid_a;
+ for (i = 0; i < e; i++)
+ grid[i] = 0;
}
UI* UI::create(
@@ -479,13 +485,12 @@ void UI::update(Arena* s) {
layout(area.w, area.h);
}
-void UI::render(Arena* s) {
+bool UI::render(Arena* s, void* pixels) {
if (area.w != ren.bound.w || area.h != ren.bound.h)
ren.resize(area.w, area.h);
ren.reset(ren.bound);
root->render();
- g_app = app;
- ren.flush();
+ return ren.flush(pixels);
}
void UI::draw_container(const Rect& bound, Colour c) {