Skip to content

Commit

Permalink
display optimization (dirty region) #2
Browse files Browse the repository at this point in the history
  • Loading branch information
mvladic committed Mar 16, 2020
1 parent dfbc9b2 commit 35eb12a
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 19 deletions.
47 changes: 34 additions & 13 deletions src/eez/modules/mcu/display.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -237,38 +237,59 @@ uint8_t getOpacity() {
return g_opacity;
}

static int g_prevDirtyX1;
static int g_prevDirtyY1;
static int g_prevDirtyX2;
static int g_prevDirtyY2;

static int g_nextDirtyX1 = getDisplayWidth();
static int g_nextDirtyY1 = getDisplayHeight();
static int g_nextDirtyX2 = -1;
static int g_nextDirtyY2 = -1;

static int g_dirtyX1;
static int g_dirtyY1;
static int g_dirtyX2;
static int g_dirtyY2;

void clearDirty() {
g_dirtyX1 = getDisplayWidth();
g_dirtyY1 = getDisplayHeight();
g_dirtyX2 = -1;
g_dirtyY2 = -1;
g_prevDirtyX1 = g_nextDirtyX1;
g_prevDirtyY1 = g_nextDirtyY1;
g_prevDirtyX2 = g_nextDirtyX2;
g_prevDirtyY2 = g_nextDirtyY2;

g_nextDirtyX1 = getDisplayWidth();
g_nextDirtyY1 = getDisplayHeight();
g_nextDirtyX2 = -1;
g_nextDirtyY2 = -1;
}

void markDirty(int x1, int y1, int x2, int y2) {
if (x1 < g_dirtyX1) {
g_dirtyX1 = x1;
if (x1 < g_nextDirtyX1) {
g_nextDirtyX1 = x1;
}
if (x2 > g_dirtyX2) {
g_dirtyX2 = x2;
if (y1 < g_nextDirtyY1) {
g_nextDirtyY1 = y1;
}
if (y1 < g_dirtyY1) {
g_dirtyY1 = y1;
if (x2 > g_nextDirtyX2) {
g_nextDirtyX2 = x2;
}
if (y2 > g_dirtyY2) {
g_dirtyY2 = y2;
if (y2 > g_nextDirtyY2) {
g_nextDirtyY2 = y2;
}
}

bool isDirty() {
g_dirtyX1 = MIN(g_prevDirtyX1, g_nextDirtyX1);
g_dirtyY1 = MIN(g_prevDirtyY1, g_nextDirtyY1);
g_dirtyX2 = MAX(g_prevDirtyX2, g_nextDirtyX2);
g_dirtyY2 = MAX(g_prevDirtyY2, g_nextDirtyY2);

if (g_dirtyX1 <= g_dirtyX2 && g_dirtyY1 <= g_dirtyY2) {
printf("%d x %d\n", g_dirtyX2 - g_dirtyX1 + 1, g_dirtyY2 - g_dirtyY1 + 1);
// printf("%d x %d\n", g_dirtyX2 - g_dirtyX1 + 1, g_dirtyY2 - g_dirtyY1 + 1);
return true;
}

return false;
}

Expand Down
7 changes: 5 additions & 2 deletions src/eez/modules/mcu/simulator/display.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -327,6 +327,7 @@ void sync() {
finishAnimation();
}
clearDirty();
clearDirty();
return;
}

Expand All @@ -351,11 +352,15 @@ void sync() {
void finishAnimation() {
updateScreen(g_buffer);

auto oldBuffer = g_buffer;

if (g_buffer == (uint32_t *)VRAM_BUFFER1_START_ADDRESS) {
g_buffer = (uint32_t *)VRAM_BUFFER2_START_ADDRESS;
} else {
g_buffer = (uint32_t *)VRAM_BUFFER1_START_ADDRESS;
}

bitBlt(oldBuffer, 0, 0, getDisplayWidth() - 1, getDisplayHeight() - 1);
}

////////////////////////////////////////////////////////////////////////////////
Expand Down Expand Up @@ -607,8 +612,6 @@ void bitBlt(void *src, void *dst, int sx, int sy, int sw, int sh, int dx, int dy
}
}
}

markDirty(dx, dy, dx + sx - 1, dy + sy - 1);
}

void drawBitmap(Image *image, int x, int y) {
Expand Down
8 changes: 4 additions & 4 deletions src/eez/modules/mcu/stm32/display.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -313,8 +313,6 @@ void bitBlt(void *src, void *dst, int sx, int sy, int sw, int sh, int dx, int dy
HAL_DMA2D_ConfigLayer(&hdma2d, 0);
HAL_DMA2D_BlendingStart(&hdma2d, srcOffset, dstOffset, dstOffset, sw, sh);
}

markDirty(dx, dy, dx + sx - 1, dy + sy - 1);
}

void bitBltA8Init(uint16_t color) {
Expand Down Expand Up @@ -510,6 +508,7 @@ void sync() {
finishAnimation();
}
clearDirty();
clearDirty();
return;
}

Expand All @@ -529,7 +528,9 @@ void sync() {
}

void finishAnimation() {
auto oldBuffer = g_buffer;
swapBuffers();
bitBlt(oldBuffer, 0, 0, getDisplayWidth() - 1, getDisplayHeight() - 1);
}

////////////////////////////////////////////////////////////////////////////////
Expand Down Expand Up @@ -675,8 +676,7 @@ void drawBitmap(Image *image, int x, int y) {
markDirty(x, y, x + image->width - 1, y + image->height - 1);
}

void drawStr(const char *text, int textLength, int x, int y, int clip_x1, int clip_y1, int clip_x2,
int clip_y2, gui::font::Font &font) {
void drawStr(const char *text, int textLength, int x, int y, int clip_x1, int clip_y1, int clip_x2, int clip_y2, gui::font::Font &font) {
g_font = font;

bitBltA8Init(g_fc);
Expand Down

0 comments on commit 35eb12a

Please sign in to comment.