[Horus] DMA2D more used. Some graphics are really faster.

This commit is contained in:
Bertrand Songis
2015-11-10 21:57:41 +01:00
parent a9603cbdb7
commit 312c370162
9 changed files with 122 additions and 38 deletions
Binary file not shown.

Before

Width:  |  Height:  |  Size: 14 KiB

After

Width:  |  Height:  |  Size: 9.2 KiB

+4 -4
View File
@@ -330,7 +330,7 @@ const char * bmpLoad(uint8_t * bmp, const char * filename, uint16_t width, uint1
switch (depth) { switch (depth) {
case 32: case 32:
for (int i=h-1; i>=0; i--) { for (int i=h-1; i>=0; i--) {
uint8_t * dst = ((uint8_t *)dest) + i*w*3; uint8_t * dst = ((uint8_t *)dest) + i*w*2;
for (unsigned int j=0; j<w; j++) { for (unsigned int j=0; j<w; j++) {
uint32_t pixel; uint32_t pixel;
result = f_read(&bmpFile, (uint8_t *)&pixel, 4, &read); result = f_read(&bmpFile, (uint8_t *)&pixel, 4, &read);
@@ -340,10 +340,10 @@ const char * bmpLoad(uint8_t * bmp, const char * filename, uint16_t width, uint1
} }
*((uint16_t *)dst) = RGB((pixel>>24) & 0xff, (pixel>>16) & 0xff, (pixel>>8) & 0xff); *((uint16_t *)dst) = RGB((pixel>>24) & 0xff, (pixel>>16) & 0xff, (pixel>>8) & 0xff);
dst += 2; dst += 2;
*dst++ = 0x0F;
} }
} }
break; break;
case 1: case 1:
break; break;
@@ -355,13 +355,13 @@ const char * bmpLoad(uint8_t * bmp, const char * filename, uint16_t width, uint1
f_close(&bmpFile); f_close(&bmpFile);
return SDCARD_ERROR(result); return SDCARD_ERROR(result);
} }
uint8_t * dst = ((uint8_t *)dest) + i*w*3; uint8_t * dst = ((uint8_t *)dest) + i*w*2;
for (uint32_t j=0; j<w; j++) { for (uint32_t j=0; j<w; j++) {
uint8_t index = (buf[j/2] >> ((j & 1) ? 0 : 4)) & 0x0F; uint8_t index = (buf[j/2] >> ((j & 1) ? 0 : 4)) & 0x0F;
uint8_t val = palette[index]; uint8_t val = palette[index];
*((uint16_t *)dst) = RGB(val, val, val); *((uint16_t *)dst) = RGB(val, val, val);
dst += 2; dst += 2;
*dst++ = 0x0F; // *dst++ = 0x0F;
} }
} }
break; break;
+33 -20
View File
@@ -400,14 +400,13 @@ void lcdDrawSolidFilledRect(coord_t x, scoord_t y, coord_t w, coord_t h, LcdFlag
#endif #endif
#if !defined(BOOT) #if !defined(BOOT)
void lcdDrawFilledRect(coord_t x, scoord_t y, coord_t w, coord_t h, uint8_t pat, LcdFlags att) void lcdDrawFilledRect(coord_t x, scoord_t y, coord_t w, coord_t h, LcdFlags att)
{ {
for (scoord_t i=y; i<y+h; i++) { for (scoord_t i=y; i<y+h; i++) {
if ((att&ROUND) && (i==y || i==y+h-1)) if ((att&ROUND) && (i==y || i==y+h-1))
lcdDrawHorizontalLine(x+1, i, w-2, pat, att); lcdDrawHorizontalLine(x+1, i, w-2, SOLID, att);
else else
lcdDrawHorizontalLine(x, i, w, pat, att); lcdDrawHorizontalLine(x, i, w, SOLID, att);
pat = (pat >> 1) + ((pat & 1) << 7);
} }
} }
#endif #endif
@@ -847,15 +846,23 @@ void lcdDrawHorizontalLine(coord_t x, coord_t y, coord_t w, uint8_t pat, LcdFlag
display_t color = lcdColorTable[COLOR_IDX(att)]; display_t color = lcdColorTable[COLOR_IDX(att)];
uint8_t opacity = 0x0F - (att >> 24); uint8_t opacity = 0x0F - (att >> 24);
while (w--) { if (pat == SOLID) {
if (pat & 1) { while (w--) {
lcdDrawTransparentPixel(p, opacity, color); lcdDrawTransparentPixel(p, opacity, color);
pat = (pat >> 1) | 0x80; p++;
} }
else { }
pat = pat >> 1; else {
while (w--) {
if (pat & 1) {
lcdDrawTransparentPixel(p, opacity, color);
pat = (pat >> 1) | 0x80;
}
else {
pat = pat >> 1;
}
p++;
} }
p++;
} }
} }
@@ -883,6 +890,13 @@ void lcdDrawVerticalLine(coord_t x, coord_t y, coord_t h, uint8_t pat, LcdFlags
} }
} }
#if defined(SIMU)
inline void lcdDrawBitmapDMA(coord_t x, coord_t y, coord_t width, coord_t height, const uint8_t * img)
{
lcdDrawBitmap(x, y, img-4, 0, 0, -1);
}
#endif
#if !defined(BOOT) #if !defined(BOOT)
void lcdDrawBitmap(coord_t x, coord_t y, const uint8_t * bmp, coord_t offset, coord_t width, int scale) void lcdDrawBitmap(coord_t x, coord_t y, const uint8_t * bmp, coord_t offset, coord_t width, int scale)
{ {
@@ -898,16 +912,15 @@ void lcdDrawBitmap(coord_t x, coord_t y, const uint8_t * bmp, coord_t offset, co
} }
if (scale == 0) { if (scale == 0) {
scale = -1; lcdDrawBitmapDMA(x, y, width, height, bmp+4);
} }
else if (scale < 0) {
if (scale < 0) {
for (coord_t i=0, row=0; row<height; i+=1, row-=scale) { for (coord_t i=0, row=0; row<height; i+=1, row-=scale) {
display_t * p = &displayBuf[(y+i)*LCD_W + x]; display_t * p = &displayBuf[(y+i)*LCD_W + x];
const uint8_t * q = bmp + 4 + (row*w + offset) * 3; const uint8_t * q = bmp + 4 + (row*w + offset) * 2;
for (coord_t col=0; col<width; col-=scale) { for (coord_t col=0; col<width; col-=scale) {
lcdDrawTransparentPixel(p, *(q+2), *((uint16_t *)q)); lcdDrawPixel(p, *((uint16_t *)q));
p++; q-=3*scale; p++; q-=2*scale;
} }
} }
} }
@@ -915,13 +928,13 @@ void lcdDrawBitmap(coord_t x, coord_t y, const uint8_t * bmp, coord_t offset, co
for (coord_t row=0; row<height; row++) { for (coord_t row=0; row<height; row++) {
for (int i=0; i<scale; i++) { for (int i=0; i<scale; i++) {
display_t * p = &displayBuf[(y+scale*row+i)*LCD_W + x]; display_t * p = &displayBuf[(y+scale*row+i)*LCD_W + x];
const uint8_t * q = bmp + 4 + (row*w + offset) * 3; const uint8_t * q = bmp + 4 + (row*w + offset) * 2;
for (coord_t col=0; col<width; col++) { for (coord_t col=0; col<width; col++) {
for (int j=0; j<scale; j++) { for (int j=0; j<scale; j++) {
lcdDrawTransparentPixel(p, *(q+2), *((uint16_t *)q)); lcdDrawPixel(p, *((uint16_t *)q));
p++; p++;
} }
q+=3; q+=2;
} }
} }
} }
@@ -931,7 +944,7 @@ void lcdDrawBitmap(coord_t x, coord_t y, const uint8_t * bmp, coord_t offset, co
void lcdDrawBlackOverlay() void lcdDrawBlackOverlay()
{ {
lcdDrawFilledRect(0, 0, LCD_W, LCD_H, SOLID, TEXT_COLOR | (8<<24)); lcdDrawFilledRect(0, 0, LCD_W, LCD_H, TEXT_COLOR | (8<<24));
} }
void lcdDrawCircle(int x0, int y0, int radius) void lcdDrawCircle(int x0, int y0, int radius)
+1 -1
View File
@@ -265,7 +265,7 @@ inline void lcdDrawSolidRect(coord_t x, scoord_t y, coord_t w, coord_t h, LcdFla
lcdDrawSolidHorizontalLine(x, y+h-1, w, att); lcdDrawSolidHorizontalLine(x, y+h-1, w, att);
} }
void lcdDrawFilledRect(coord_t x, scoord_t y, coord_t w, coord_t h, uint8_t pat, LcdFlags att); void lcdDrawFilledRect(coord_t x, scoord_t y, coord_t w, coord_t h, LcdFlags att);
void lcdDrawBlackOverlay(); void lcdDrawBlackOverlay();
void lcdDrawRect(coord_t x, coord_t y, coord_t w, coord_t h, uint8_t pat=SOLID, LcdFlags att=0); void lcdDrawRect(coord_t x, coord_t y, coord_t w, coord_t h, uint8_t pat=SOLID, LcdFlags att=0);
void lcdDrawCircle(int x0, int y0, int radius); void lcdDrawCircle(int x0, int y0, int radius);
+2 -1
View File
@@ -347,6 +347,7 @@ bool menuMainView(evt_t event)
// 23ms if 24bits per pixel (with transparency) 5/6/5/8 // 23ms if 24bits per pixel (with transparency) 5/6/5/8
// 6ms if 16bits per pixel 5/6/5 no DMA // 6ms if 16bits per pixel 5/6/5 no DMA
// 1.2ms with the DMA
TIME_MEASURE_START(backgroundbitmap); TIME_MEASURE_START(backgroundbitmap);
lcdDrawBitmap(0, 0, LBM_MAINVIEW_BACKGROUND); lcdDrawBitmap(0, 0, LBM_MAINVIEW_BACKGROUND);
TIME_MEASURE_STOP(backgroundbitmap); TIME_MEASURE_STOP(backgroundbitmap);
@@ -383,7 +384,7 @@ bool menuMainView(evt_t event)
// Model panel // Model panel
TIME_MEASURE_START(filledRect); TIME_MEASURE_START(filledRect);
lcdDrawFilledRect(MODELPANEL_LEFT, MODELPANEL_TOP, MODELPANEL_WIDTH, MODELPANEL_HEIGHT, SOLID, TEXT_BGCOLOR | OPACITY(5)); lcdDrawFilledRect(MODELPANEL_LEFT, MODELPANEL_TOP, MODELPANEL_WIDTH, MODELPANEL_HEIGHT, TEXT_BGCOLOR | OPACITY(5));
TIME_MEASURE_STOP(filledRect); // 9ms ! TIME_MEASURE_STOP(filledRect); // 9ms !
lcdDrawBitmapPattern(MODELPANEL_LEFT+6, MODELPANEL_TOP+4, LBM_MODEL_ICON, TITLE_BGCOLOR); lcdDrawBitmapPattern(MODELPANEL_LEFT+6, MODELPANEL_TOP+4, LBM_MODEL_ICON, TITLE_BGCOLOR);
+2
View File
@@ -160,7 +160,9 @@ void guiMain(evt_t evt)
if (popupDisplayed == false) { if (popupDisplayed == false) {
g_menuStack[g_menuStackPtr](EVT_REFRESH); g_menuStack[g_menuStackPtr](EVT_REFRESH);
lcdDrawBlackOverlay(); lcdDrawBlackOverlay();
TIME_MEASURE_START(storebackup);
lcdStoreBackupBuffer(); lcdStoreBackupBuffer();
TIME_MEASURE_STOP(storebackup);
} }
if (popupDisplayed == false || evt) { if (popupDisplayed == false || evt) {
lcdRestoreBackupBuffer(); lcdRestoreBackupBuffer();
+1
View File
@@ -248,6 +248,7 @@ void ledBlue(void);
void lcdInit(void); void lcdInit(void);
void lcdRefresh(void); void lcdRefresh(void);
void lcdDrawSolidFilledRectDMA(uint16_t x, uint16_t y, uint16_t w, uint16_t h, uint16_t color); void lcdDrawSolidFilledRectDMA(uint16_t x, uint16_t y, uint16_t w, uint16_t h, uint16_t color);
void lcdDrawBitmapDMA(uint16_t x, uint16_t y, uint16_t w, uint16_t h, const uint8_t * bitmap);
void lcdStoreBackupBuffer(void); void lcdStoreBackupBuffer(void);
void lcdRestoreBackupBuffer(void); void lcdRestoreBackupBuffer(void);
+77 -11
View File
@@ -424,13 +424,13 @@ void lcdInit(void)
void lcdDrawSolidFilledRectDMA(uint16_t x, uint16_t y, uint16_t w, uint16_t h, uint16_t color) void lcdDrawSolidFilledRectDMA(uint16_t x, uint16_t y, uint16_t w, uint16_t h, uint16_t color)
{ {
uint32_t addr = CurrentFrameBuffer + 2*(LCD_W*y + x); uint32_t addr = CurrentFrameBuffer + 2*(LCD_W*y + x);
uint16_t red = (0xF800 & color) >> 11; uint8_t red = (0xF800 & color) >> 11;
uint16_t blue = 0x001F & color; uint8_t blue = 0x001F & color;
uint16_t green = (0x07E0 & color) >> 5; uint8_t green = (0x07E0 & color) >> 5;
/* configure DMA2D */
DMA2D_InitTypeDef DMA2D_InitStruct;
DMA2D_DeInit(); DMA2D_DeInit();
DMA2D_InitTypeDef DMA2D_InitStruct;
DMA2D_InitStruct.DMA2D_Mode = DMA2D_R2M; DMA2D_InitStruct.DMA2D_Mode = DMA2D_R2M;
DMA2D_InitStruct.DMA2D_CMode = DMA2D_RGB565; DMA2D_InitStruct.DMA2D_CMode = DMA2D_RGB565;
DMA2D_InitStruct.DMA2D_OutputGreen = green; DMA2D_InitStruct.DMA2D_OutputGreen = green;
@@ -450,18 +450,84 @@ void lcdDrawSolidFilledRectDMA(uint16_t x, uint16_t y, uint16_t w, uint16_t h, u
while (DMA2D_GetFlagStatus(DMA2D_FLAG_TC) == RESET); while (DMA2D_GetFlagStatus(DMA2D_FLAG_TC) == RESET);
} }
void lcdDrawBitmapDMA(uint16_t x, uint16_t y, uint16_t w, uint16_t h, const uint8_t * bitmap)
{
uint32_t addr = CurrentFrameBuffer + 2*(LCD_W*y + x);
DMA2D_DeInit();
DMA2D_InitTypeDef DMA2D_InitStruct;
DMA2D_InitStruct.DMA2D_Mode = DMA2D_M2M;
DMA2D_InitStruct.DMA2D_CMode = DMA2D_RGB565;
DMA2D_InitStruct.DMA2D_OutputMemoryAdd = addr;
DMA2D_InitStruct.DMA2D_OutputGreen = 0;
DMA2D_InitStruct.DMA2D_OutputBlue = 0;
DMA2D_InitStruct.DMA2D_OutputRed = 0;
DMA2D_InitStruct.DMA2D_OutputAlpha = 0;
DMA2D_InitStruct.DMA2D_OutputOffset = (LCD_W - w);
DMA2D_InitStruct.DMA2D_NumberOfLine = h;
DMA2D_InitStruct.DMA2D_PixelPerLine = w;
DMA2D_Init(&DMA2D_InitStruct);
DMA2D_FG_InitTypeDef DMA2D_FG_InitStruct;
DMA2D_FG_StructInit(&DMA2D_FG_InitStruct);
DMA2D_FG_InitStruct.DMA2D_FGMA = CONVERT_PTR_UINT(bitmap);
DMA2D_FG_InitStruct.DMA2D_FGO = 0;
DMA2D_FG_InitStruct.DMA2D_FGCM = CM_RGB565;
DMA2D_FG_InitStruct.DMA2D_FGPFC_ALPHA_MODE = NO_MODIF_ALPHA_VALUE;
DMA2D_FG_InitStruct.DMA2D_FGPFC_ALPHA_VALUE = 0;
DMA2D_FGConfig(&DMA2D_FG_InitStruct);
/* Start Transfer */
DMA2D_StartTransfer();
/* Wait for CTC Flag activation */
while (DMA2D_GetFlagStatus(DMA2D_FLAG_TC) == RESET);
}
void DMAcopy(void * src, void * dest, int len)
{
DMA2D_DeInit();
DMA2D_InitTypeDef DMA2D_InitStruct;
DMA2D_InitStruct.DMA2D_Mode = DMA2D_M2M;
DMA2D_InitStruct.DMA2D_CMode = DMA2D_RGB565;
DMA2D_InitStruct.DMA2D_OutputMemoryAdd = CONVERT_PTR_UINT(dest);
DMA2D_InitStruct.DMA2D_OutputGreen = 0;
DMA2D_InitStruct.DMA2D_OutputBlue = 0;
DMA2D_InitStruct.DMA2D_OutputRed = 0;
DMA2D_InitStruct.DMA2D_OutputAlpha = 0;
DMA2D_InitStruct.DMA2D_OutputOffset = 0;
DMA2D_InitStruct.DMA2D_NumberOfLine = LCD_H;
DMA2D_InitStruct.DMA2D_PixelPerLine = LCD_W;
DMA2D_Init(&DMA2D_InitStruct);
DMA2D_FG_InitTypeDef DMA2D_FG_InitStruct;
DMA2D_FG_StructInit(&DMA2D_FG_InitStruct);
DMA2D_FG_InitStruct.DMA2D_FGMA = CONVERT_PTR_UINT(src);
DMA2D_FG_InitStruct.DMA2D_FGO = 0;
DMA2D_FG_InitStruct.DMA2D_FGCM = CM_RGB565;
DMA2D_FG_InitStruct.DMA2D_FGPFC_ALPHA_MODE = NO_MODIF_ALPHA_VALUE;
DMA2D_FG_InitStruct.DMA2D_FGPFC_ALPHA_VALUE = 0;
DMA2D_FGConfig(&DMA2D_FG_InitStruct);
/* Start Transfer */
DMA2D_StartTransfer();
/* Wait for CTC Flag activation */
while (DMA2D_GetFlagStatus(DMA2D_FLAG_TC) == RESET);
}
void lcdStoreBackupBuffer() void lcdStoreBackupBuffer()
{ {
for (uint16_t * src = (uint16_t *)CurrentFrameBuffer, * dest = (uint16_t *)LCD_BACKUP_FRAME_BUFFER; src < (uint16_t *)(CurrentFrameBuffer+DISPLAY_BUFFER_SIZE); src++, dest++) { uint16_t * src = (uint16_t *)CurrentFrameBuffer, * dest = (uint16_t *)LCD_BACKUP_FRAME_BUFFER;
*dest = *src; DMAcopy(src, dest, DISPLAY_BUFFER_SIZE);
}
} }
void lcdRestoreBackupBuffer() void lcdRestoreBackupBuffer()
{ {
for (uint16_t * dest = (uint16_t *)CurrentFrameBuffer, * src = (uint16_t *)LCD_BACKUP_FRAME_BUFFER; dest < (uint16_t *)(CurrentFrameBuffer+DISPLAY_BUFFER_SIZE); src++, dest++) { uint16_t * dest = (uint16_t *)CurrentFrameBuffer, * src = (uint16_t *)LCD_BACKUP_FRAME_BUFFER;
*dest = *src; DMAcopy(src, dest, DISPLAY_BUFFER_SIZE);
}
} }
void lcdRefresh() void lcdRefresh()
+2 -1
View File
@@ -51,7 +51,8 @@ elif what == "5/6/5/8":
for x in range(width): for x in range(width):
pixel = image.pixel(x, y) pixel = image.pixel(x, y)
val = ((Qt.qRed(pixel) >> 3) << 11) + ((Qt.qGreen(pixel) >> 2) << 5) + ((Qt.qBlue(pixel) >> 3) << 0) val = ((Qt.qRed(pixel) >> 3) << 11) + ((Qt.qGreen(pixel) >> 2) << 5) + ((Qt.qBlue(pixel) >> 3) << 0)
f.write("%d,%d,%d," % (val%256, val/256, Qt.qAlpha(pixel) >> 4)) # f.write("%d,%d,%d," % (val%256, val/256, Qt.qAlpha(pixel) >> 4))
f.write("%d,%d," % (val%256, val/256))
f.write("\n") f.write("\n")
elif what == "4bits": elif what == "4bits":
colors = [] colors = []