Skip to content

Commit 37b3201

Browse files
author
Diego Ferrari
committed
Unified the mark_dirty functions under draw.c
NOTE: bug with draw_pixel, mark_dirty must be called from outside the function
1 parent e8f82fc commit 37b3201

8 files changed

Lines changed: 81 additions & 170 deletions

File tree

kernel/graph/drivers/ramfb_driver/ramfb.cpp

Lines changed: 1 addition & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -98,8 +98,7 @@ void RamFBGPUDriver::flush(){
9898
}
9999

100100
void RamFBGPUDriver::clear(color color){
101-
fb_clear((uint32_t*)back_framebuffer, screen_size.width, screen_size.height, color);
102-
mark_dirty(0,0,screen_size.width,screen_size.height);
101+
fb_clear((uint32_t*)back_framebuffer, color);
103102
}
104103

105104
void RamFBGPUDriver::draw_pixel(uint32_t x, uint32_t y, color color){
@@ -109,17 +108,14 @@ void RamFBGPUDriver::draw_pixel(uint32_t x, uint32_t y, color color){
109108

110109
void RamFBGPUDriver::fill_rect(uint32_t x, uint32_t y, uint32_t width, uint32_t height, color color){
111110
fb_fill_rect((uint32_t*)back_framebuffer, x, y, width, height, color);
112-
mark_dirty(x,y,width,height);
113111
}
114112

115113
void RamFBGPUDriver::draw_line(uint32_t x0, uint32_t y0, uint32_t x1,uint32_t y1, color color){
116114
gpu_rect rect = fb_draw_line((uint32_t*)framebuffer, x0, y0, x1, y1, color);
117-
mark_dirty(rect.point.x,rect.point.y,rect.size.width,rect.size.height);
118115
}
119116

120117
void RamFBGPUDriver::draw_char(uint32_t x, uint32_t y, char c, uint32_t scale, uint32_t color){
121118
fb_draw_char((uint32_t*)back_framebuffer, x, y, c, scale, color);
122-
mark_dirty(x,y,8*scale,8*scale);
123119
}
124120

125121
gpu_size RamFBGPUDriver::get_screen_size(){
@@ -128,45 +124,8 @@ gpu_size RamFBGPUDriver::get_screen_size(){
128124

129125
void RamFBGPUDriver::draw_string(string s, uint32_t x, uint32_t y, uint32_t scale, uint32_t color){
130126
gpu_size drawn_string = fb_draw_string((uint32_t*)back_framebuffer, s, x, y, scale, color);
131-
mark_dirty(x,y,drawn_string.width,drawn_string.height);
132127
}
133128

134129
uint32_t RamFBGPUDriver::get_char_size(uint32_t scale){
135130
return fb_get_char_size(scale);
136-
}
137-
138-
int RamFBGPUDriver::try_merge(gpu_rect* a, gpu_rect* b) {
139-
uint32_t ax2 = a->point.x + a->size.width;
140-
uint32_t ay2 = a->point.y + a->size.height;
141-
uint32_t bx2 = b->point.x + b->size.width;
142-
uint32_t by2 = b->point.y + b->size.height;
143-
144-
if (a->point.x > bx2 || b->point.x > ax2 || a->point.y > by2 || b->point.y > ay2)
145-
return 0;
146-
147-
uint32_t min_x = a->point.x < b->point.x ? a->point.x : b->point.x;
148-
uint32_t min_y = a->point.y < b->point.y ? a->point.y : b->point.y;
149-
uint32_t max_x = ax2 > bx2 ? ax2 : bx2;
150-
uint32_t max_y = ay2 > by2 ? ay2 : by2;
151-
152-
a->point.x = min_x;
153-
a->point.y = min_y;
154-
a->size.width = max_x - min_x;
155-
a->size.height = max_y - min_y;
156-
157-
return 1;
158-
}
159-
160-
void RamFBGPUDriver::mark_dirty(uint32_t x, uint32_t y, uint32_t w, uint32_t h) {
161-
gpu_rect new_rect = { x, y, w, h };
162-
163-
for (uint32_t i = 0; i < dirty_count; i++) {
164-
if (try_merge(&dirty_rects[i], &new_rect))
165-
return;
166-
}
167-
168-
if (dirty_count < MAX_DIRTY_RECTS_RFB)
169-
dirty_rects[dirty_count++] = new_rect;
170-
else
171-
full_redraw = true;
172131
}

kernel/graph/drivers/ramfb_driver/ramfb.hpp

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,6 @@
22

33
#include "../gpu_driver.hpp"
44

5-
#define MAX_DIRTY_RECTS_RFB 64
6-
75
class RamFBGPUDriver : public GPUDriver {
86
public:
97
static RamFBGPUDriver* try_init(gpu_size preferred_screen_size);
@@ -28,10 +26,5 @@ class RamFBGPUDriver : public GPUDriver {
2826
uintptr_t back_framebuffer;
2927
uint64_t framebuffer_size;
3028
gpu_size screen_size;
31-
gpu_rect dirty_rects[MAX_DIRTY_RECTS_RFB];
32-
uint32_t dirty_count = 0;
33-
bool full_redraw = false;
34-
int try_merge(gpu_rect* a, gpu_rect* b);
35-
void mark_dirty(uint32_t x, uint32_t y, uint32_t w, uint32_t h);
3629
uint32_t stride;
3730
};

kernel/graph/drivers/videocore/videocore.cpp

Lines changed: 3 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -106,8 +106,7 @@ void VideoCoreGPUDriver::flush(){
106106
}
107107

108108
void VideoCoreGPUDriver::clear(color color){
109-
fb_clear((uint32_t*)back_framebuffer, screen_size.width, screen_size.height, color);
110-
mark_dirty(0,0,screen_size.width,screen_size.height);
109+
fb_clear((uint32_t*)back_framebuffer, color);
111110
}
112111

113112
void VideoCoreGPUDriver::draw_pixel(uint32_t x, uint32_t y, color color){
@@ -117,64 +116,24 @@ void VideoCoreGPUDriver::draw_pixel(uint32_t x, uint32_t y, color color){
117116

118117
void VideoCoreGPUDriver::fill_rect(uint32_t x, uint32_t y, uint32_t width, uint32_t height, color color){
119118
fb_fill_rect((uint32_t*)back_framebuffer, x, y, width, height, color);
120-
mark_dirty(x,y,width,height);
121119
}
122120

123121
void VideoCoreGPUDriver::draw_line(uint32_t x0, uint32_t y0, uint32_t x1,uint32_t y1, color color){
124-
gpu_rect rect = fb_draw_line((uint32_t*)framebuffer, x0, y0, x1, y1, color);
125-
mark_dirty(rect.point.x,rect.point.y,rect.size.width,rect.size.height);
122+
fb_draw_line((uint32_t*)back_framebuffer, x0, y0, x1, y1, color);
126123
}
127124

128125
void VideoCoreGPUDriver::draw_char(uint32_t x, uint32_t y, char c, uint32_t scale, uint32_t color){
129126
fb_draw_char((uint32_t*)back_framebuffer, x, y, c, scale, color);
130-
mark_dirty(x,y,8*scale,8*scale);
131127
}
132128

133129
gpu_size VideoCoreGPUDriver::get_screen_size(){
134130
return screen_size;
135131
}
136132

137133
void VideoCoreGPUDriver::draw_string(string s, uint32_t x, uint32_t y, uint32_t scale, uint32_t color){
138-
gpu_size drawn_string = fb_draw_string((uint32_t*)back_framebuffer, s, x, y, scale, color);
139-
mark_dirty(x,y,drawn_string.width,drawn_string.height);
134+
fb_draw_string((uint32_t*)back_framebuffer, s, x, y, scale, color);
140135
}
141136

142137
uint32_t VideoCoreGPUDriver::get_char_size(uint32_t scale){
143138
return fb_get_char_size(max(1,scale-1));//TODO: Screen resolution seems fixed at 640x480 (on QEMU at least). So we make the font smaller
144-
}
145-
146-
int VideoCoreGPUDriver::try_merge(gpu_rect* a, gpu_rect* b) {
147-
uint32_t ax2 = a->point.x + a->size.width;
148-
uint32_t ay2 = a->point.y + a->size.height;
149-
uint32_t bx2 = b->point.x + b->size.width;
150-
uint32_t by2 = b->point.y + b->size.height;
151-
152-
if (a->point.x > bx2 || b->point.x > ax2 || a->point.y > by2 || b->point.y > ay2)
153-
return 0;
154-
155-
uint32_t min_x = a->point.x < b->point.x ? a->point.x : b->point.x;
156-
uint32_t min_y = a->point.y < b->point.y ? a->point.y : b->point.y;
157-
uint32_t max_x = ax2 > bx2 ? ax2 : bx2;
158-
uint32_t max_y = ay2 > by2 ? ay2 : by2;
159-
160-
a->point.x = min_x;
161-
a->point.y = min_y;
162-
a->size.width = max_x - min_x;
163-
a->size.height = max_y - min_y;
164-
165-
return 1;
166-
}
167-
168-
void VideoCoreGPUDriver::mark_dirty(uint32_t x, uint32_t y, uint32_t w, uint32_t h) {
169-
gpu_rect new_rect = { x, y, w, h };
170-
171-
for (uint32_t i = 0; i < dirty_count; i++) {
172-
if (try_merge(&dirty_rects[i], &new_rect))
173-
return;
174-
}
175-
176-
if (dirty_count < MAX_DIRTY_RECTS_VCG)
177-
dirty_rects[dirty_count++] = new_rect;
178-
else
179-
full_redraw = true;
180139
}

kernel/graph/drivers/videocore/videocore.hpp

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,6 @@
22

33
#include "../gpu_driver.hpp"
44

5-
#define MAX_DIRTY_RECTS_VCG 64
6-
75
class VideoCoreGPUDriver : public GPUDriver {
86
public:
97
static VideoCoreGPUDriver* try_init(gpu_size preferred_screen_size);
@@ -26,15 +24,9 @@ class VideoCoreGPUDriver : public GPUDriver {
2624
gpu_size screen_size;
2725
uintptr_t framebuffer;
2826
uintptr_t back_framebuffer;
29-
uint64_t framebuffer_size;
3027

3128
void* page;
3229

33-
gpu_rect dirty_rects[MAX_DIRTY_RECTS_VCG];
34-
uint32_t dirty_count = 0;
35-
bool full_redraw = false;
36-
int try_merge(gpu_rect* a, gpu_rect* b);
37-
void mark_dirty(uint32_t x, uint32_t y, uint32_t w, uint32_t h);
3830
uint8_t bpp;
3931
uint32_t stride;
4032
};

kernel/graph/drivers/virtio_gpu_pci/virtio_gpu_pci.cpp

Lines changed: 3 additions & 57 deletions
Original file line numberDiff line numberDiff line change
@@ -387,58 +387,8 @@ void VirtioGPUDriver::flush() {
387387
return;
388388
}
389389

390-
int VirtioGPUDriver::try_merge(gpu_rect* a, gpu_rect* b) {
391-
uint32_t ax2 = a->point.x + a->size.width;
392-
uint32_t ay2 = a->point.y + a->size.height;
393-
uint32_t bx2 = b->point.x + b->size.width;
394-
uint32_t by2 = b->point.y + b->size.height;
395-
396-
if (a->point.x > bx2 || b->point.x > ax2 || a->point.y > by2 || b->point.y > ay2)
397-
return 0;
398-
399-
uint32_t min_x = a->point.x < b->point.x ? a->point.x : b->point.x;
400-
uint32_t min_y = a->point.y < b->point.y ? a->point.y : b->point.y;
401-
uint32_t max_x = ax2 > bx2 ? ax2 : bx2;
402-
uint32_t max_y = ay2 > by2 ? ay2 : by2;
403-
404-
a->point.x = min_x;
405-
a->point.y = min_y;
406-
a->size.width = max_x - min_x;
407-
a->size.height = max_y - min_y;
408-
409-
return 1;
410-
}
411-
412-
void VirtioGPUDriver::mark_dirty(uint32_t x, uint32_t y, uint32_t w, uint32_t h) {
413-
if (x >= screen_size.width || y >= screen_size.height)
414-
return;
415-
416-
if (x + w > screen_size.width)
417-
w = screen_size.width - x;
418-
419-
if (y + h > screen_size.height)
420-
h = screen_size.height - y;
421-
422-
if (w == 0 || h == 0)
423-
return;
424-
425-
gpu_rect new_rect = { x, y, w, h };
426-
427-
for (uint32_t i = 0; i < dirty_count; i++) {
428-
if (try_merge(&dirty_rects[i], &new_rect))
429-
return;
430-
}
431-
432-
if (dirty_count < MAX_DIRTY_RECTS_VGP)
433-
dirty_rects[dirty_count++] = new_rect;
434-
else
435-
full_redraw = true;
436-
}
437-
438-
439390
void VirtioGPUDriver::clear(uint32_t color) {
440-
fb_clear((uint32_t*)framebuffer, screen_size.width, screen_size.height, color);
441-
mark_dirty(0,0,screen_size.width,screen_size.height);
391+
fb_clear((uint32_t*)framebuffer, color);
442392
}
443393

444394
void VirtioGPUDriver::draw_pixel(uint32_t x, uint32_t y, color color){
@@ -448,22 +398,18 @@ void VirtioGPUDriver::draw_pixel(uint32_t x, uint32_t y, color color){
448398

449399
void VirtioGPUDriver::fill_rect(uint32_t x, uint32_t y, uint32_t width, uint32_t height, color color){
450400
fb_fill_rect((uint32_t*)framebuffer, x, y, width, height, color);
451-
mark_dirty(x,y,width,height);
452401
}
453402

454403
void VirtioGPUDriver::draw_line(uint32_t x0, uint32_t y0, uint32_t x1, uint32_t y1, color color){
455-
gpu_rect rect = fb_draw_line((uint32_t*)framebuffer, x0, y0, x1, y1, color);
456-
mark_dirty(rect.point.x,rect.point.y,rect.size.width,rect.size.height);
404+
fb_draw_line((uint32_t*)framebuffer, x0, y0, x1, y1, color);
457405
}
458406

459407
void VirtioGPUDriver::draw_char(uint32_t x, uint32_t y, char c, uint32_t scale, uint32_t color){
460408
fb_draw_char((uint32_t*)framebuffer, x, y, c, scale, color);
461-
mark_dirty(x,y,8*scale,8*scale);
462409
}
463410

464411
void VirtioGPUDriver::draw_string(string s, uint32_t x, uint32_t y, uint32_t scale, uint32_t color){
465-
gpu_size drawn_string = fb_draw_string((uint32_t*)framebuffer, s, x, y, scale, color);
466-
mark_dirty(x,y,drawn_string.width,drawn_string.height);
412+
fb_draw_string((uint32_t*)framebuffer, s, x, y, scale, color);
467413
}
468414

469415
uint32_t VirtioGPUDriver::get_char_size(uint32_t scale){

kernel/graph/drivers/virtio_gpu_pci/virtio_gpu_pci.hpp

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,6 @@
33
#include "virtio/virtio_pci.h"
44
#include "../gpu_driver.hpp"
55

6-
#define MAX_DIRTY_RECTS_VGP 64
7-
86
class VirtioGPUDriver : public GPUDriver {
97
public:
108
static VirtioGPUDriver* try_init(gpu_size preferred_screen_size);
@@ -35,12 +33,6 @@ class VirtioGPUDriver : public GPUDriver {
3533
bool set_scanout();
3634
bool transfer_to_host(gpu_rect rect);
3735

38-
gpu_rect dirty_rects[MAX_DIRTY_RECTS_VGP];
39-
uint32_t dirty_count = 0;
40-
bool full_redraw = false;
41-
int try_merge(gpu_rect* a, gpu_rect* b);
42-
void mark_dirty(uint32_t x, uint32_t y, uint32_t w, uint32_t h);
43-
4436
bool scanout_found;
4537
uint64_t scanout_id;
4638
};

0 commit comments

Comments
 (0)