dirty rect
This commit is contained in:
parent
285e8c9182
commit
6df6355ba7
2 changed files with 32 additions and 24 deletions
|
|
@ -111,15 +111,10 @@ void Window::AddDirtyRect(ScaleData scale) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
for (ClipRect& existingRect : dirtyRects) {
|
//merging logic should work so that no pixel is drawn twice, and that no pixel not marked dirty is drawn.
|
||||||
if (rect.left <= existingRect.right && rect.right >= existingRect.left && rect.top <= existingRect.bottom && rect.bottom >= existingRect.top) {
|
//so lets say there is already an existing horizontal bar and the new rect is a vertical bar making a cross shape, the center of the cross will currently be drawn twice
|
||||||
existingRect.left = std::min(existingRect.left, rect.left);
|
//so we need to turn it into 3 rects, the top part of the vertical bar, the horizontal bar, and the bottom part of the vertical bar
|
||||||
existingRect.right = std::max(existingRect.right, rect.right);
|
//in this way no pixel is drawn twice and no area not marked dirty is included
|
||||||
existingRect.top = std::min(existingRect.top, rect.top);
|
|
||||||
existingRect.bottom = std::max(existingRect.bottom, rect.bottom);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
dirtyRects.push_back(rect);
|
dirtyRects.push_back(rect);
|
||||||
}
|
}
|
||||||
|
|
@ -212,25 +212,38 @@ void WindowWayland::Render() {
|
||||||
elements.erase(std::remove(elements.begin(), elements.end(), static_cast<Transform*>(nullptr)), elements.end());
|
elements.erase(std::remove(elements.begin(), elements.end(), static_cast<Transform*>(nullptr)), elements.end());
|
||||||
std::sort(elements.begin(), elements.end(), [](Transform* a, Transform* b){ return a->z < b->z; });
|
std::sort(elements.begin(), elements.end(), [](Transform* a, Transform* b){ return a->z < b->z; });
|
||||||
|
|
||||||
if (!dirtyRects.empty()) {
|
for(uint_fast32_t i = 0; i < width*height; i++) {
|
||||||
for (ClipRect rect : dirtyRects) {
|
framebuffer[i] = {0, 0, 0, 255};
|
||||||
for (std::int_fast32_t y = rect.top; y < rect.bottom; y++) {
|
}
|
||||||
for (std::int_fast32_t x = rect.left; x < rect.right; x++) {
|
|
||||||
framebuffer[y * width + x] = {0, 0, 0, 0};
|
for (ClipRect rect : dirtyRects) {
|
||||||
}
|
//std::cout << std::format("{}, {}, {}, {}", rect.left, rect.top, rect.right, rect.bottom) << std::endl;
|
||||||
|
for (std::int_fast32_t y = rect.top; y < rect.bottom; y++) {
|
||||||
|
for (std::int_fast32_t x = rect.left; x < rect.right; x++) {
|
||||||
|
framebuffer[y * width + x].r += 30;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
for(Transform* child : elements) {
|
|
||||||
RenderElement(child);
|
|
||||||
}
|
|
||||||
|
|
||||||
for (ClipRect rect : dirtyRects) {
|
|
||||||
wl_surface_damage(surface, rect.left, rect.top, rect.right-rect.left, rect.bottom-rect.top);
|
|
||||||
}
|
|
||||||
dirtyRects.clear();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// if (!dirtyRects.empty()) {
|
||||||
|
// for (ClipRect rect : dirtyRects) {
|
||||||
|
// for (std::int_fast32_t y = rect.top; y < rect.bottom; y++) {
|
||||||
|
// for (std::int_fast32_t x = rect.left; x < rect.right; x++) {
|
||||||
|
// framebuffer[y * width + x] = {0, 0, 0, 0};
|
||||||
|
// }
|
||||||
|
// }
|
||||||
|
// }
|
||||||
|
|
||||||
|
// for(Transform* child : elements) {
|
||||||
|
// RenderElement(child);
|
||||||
|
// }
|
||||||
|
|
||||||
|
// for (ClipRect rect : dirtyRects) {
|
||||||
|
// wl_surface_damage(surface, rect.left, rect.top, rect.right-rect.left, rect.bottom-rect.top);
|
||||||
|
// }
|
||||||
|
// dirtyRects.clear();
|
||||||
|
// }
|
||||||
|
|
||||||
dirtyRects.clear();
|
dirtyRects.clear();
|
||||||
wl_surface_damage(surface, 0, 0, width, height);
|
wl_surface_damage(surface, 0, 0, width, height);
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue