From 60eb5a183a6df716fb9680566be5f7323f17497a Mon Sep 17 00:00:00 2001 From: jethead71 Date: Sun, 8 Jul 2007 17:10:22 +0000 Subject: [PATCH] Gigabeat: properly confined framebuffer copies and a few pendantic changes to lcd_yuv_blit. No difference full screen but quite a speedup to copy only the required bit: 534->1062 fps for 1/4 screen update using test_fps. git-svn-id: svn://svn.rockbox.org/rockbox/trunk@13821 a1c6a512-1295-4272-9138-f99709370657 --- .../target/arm/s3c2440/gigabeat-fx/lcd-as-meg-fx.S | 101 +++++++++++++++++++-- .../target/arm/s3c2440/gigabeat-fx/lcd-meg-fx.c | 86 +++++++++++------- 2 files changed, 146 insertions(+), 41 deletions(-) diff --git a/firmware/target/arm/s3c2440/gigabeat-fx/lcd-as-meg-fx.S b/firmware/target/arm/s3c2440/gigabeat-fx/lcd-as-meg-fx.S index d431c95f2..f4805fd1e 100644 --- a/firmware/target/arm/s3c2440/gigabeat-fx/lcd-as-meg-fx.S +++ b/firmware/target/arm/s3c2440/gigabeat-fx/lcd-as-meg-fx.S @@ -21,6 +21,87 @@ #include "cpu.h" /**************************************************************************** + * void lcd_copy_buffer_rect(fb_data *dst, fb_data *src, int width, + * int height); + */ + .section .icode, "ax", %progbits + .align 2 + .global lcd_copy_buffer_rect + .type lcd_copy_buffer_rect, %function + @ r0 = dst + @ r1 = src + @ r2 = width + @ r3 = height +lcd_copy_buffer_rect: @ + stmfd sp!, { r4-r12, lr } @ save non-scratch regs + mov r5, r2 @ r5 = cached width + rsb r4, r2, #LCD_WIDTH @ r4 = LCD_WIDTH - width +10: @ copy line @ + subs r2, r5, #1 @ r2 = width - 1 + beq 40f @ finish line @ one halfword? skip to trailing copy + tst r0, #2 @ word aligned? + beq 20f @ rem copy @ yes? skip to word copy + ldrh r6, [r1], #2 @ copy leading halfword + subs r2, r2, #1 @ + strh r6, [r0], #2 @ + ble 40f @ finish line @ next line if lt or finish + @ trailing halfword if eq +20: @ rem copy @ + add r14, r2, #1 @ get remaining width mod 16 after word + @ align (rw) + and r14, r14, #0xe @ r14 = 0 (16), 2, 4, 6, 8, 10, 12, 14 + add pc, pc, r14, lsl #3 @ branch to 32-byte align + nop @ + b 30f @ rw % 16 = 0 or 1? use octword loop + nop @ + nop @ + nop @ + ldr r6, [r1], #4 @ rw % 16 = 2 or 3 + subs r2, r2, #2 @ + str r6, [r0], #4 @ + b 25f @ copy up done @ + ldmia r1!, { r6-r7 } @ rw % 16 = 4 or 5 + subs r2, r2, #4 @ + stmia r0!, { r6-r7 } @ + b 25f @ copy up done @ + ldmia r1!, { r6-r8 } @ rw % 16 = 6 or 7 + subs r2, r2, #6 @ + stmia r0!, { r6-r8 } @ + b 25f @ copy up done @ + ldmia r1!, { r6-r9 } @ rw % 16 = 8 or 9 + subs r2, r2, #8 @ + stmia r0!, { r6-r9 } @ + b 25f @ copy up done @ + ldmia r1!, { r6-r10 } @ rw % 16 = 10 or 11 + subs r2, r2, #10 @ + stmia r0!, { r6-r10 } @ + b 25f @ copy up done @ + ldmia r1!, { r6-r11 } @ rw % 16 = 12 or 13 + subs r2, r2, #12 @ + stmia r0!, { r6-r11 } @ + b 25f @ copy up done @ + ldmia r1!, { r6-r12 } @ rw % 16 = 14 or 15 + subs r2, r2, #14 @ + stmia r0!, { r6-r12 } @ +25: @ copy up done @ + ble 40f @ finish line @ no 32-byte segments remaining? +30: @ octword loop @ copy 16 pixels per loop + ldmia r1!, { r6-r12, r14 } @ + subs r2, r2, #16 @ + stmia r0!, { r6-r12, r14 } @ + bgt 30b @ octword loop @ +40: @ finish line @ + ldreqh r6, [r1], #2 @ finish last halfword if eq ... + add r1, r1, r4, lsl #1 @ + streqh r6, [r0], #2 @ ... + add r0, r0, r4, lsl #1 @ + subs r3, r3, #1 @ next line + bgt 10b @ copy line @ + ldmfd sp!, { r4-r12, pc } @ restore regs and return + .size lcd_copy_buffer_rect, .-lcd_copy_buffer_rect + + +/**************************************************************************** * void lcd_write_yuv_420_lines(fb_data *dst, * unsigned char chroma_buf[LCD_HEIGHT/2*3], unsigned char const * const src[3], @@ -45,8 +126,8 @@ lcd_write_yuv420_lines: @ r2 = yuv_src @ r3 = width @ [sp] = stride - stmdb sp!, { r4-r12, lr } @ save non-scratch - stmdb sp!, { r0, r3 } @ save dst and width + stmfd sp!, { r4-r12, lr } @ save non-scratch + stmfd sp!, { r0, r3 } @ save dst and width mov r14, #74 @ r14 = Y factor ldmia r2, { r4, r5, r6 } @ r4 = yuv_src[0] = Y'_p @ r5 = yuv_src[1] = Cb_p @@ -105,7 +186,7 @@ lcd_write_yuv420_lines: orr r12, r2, r7, lsl #5 @ r4 |= (g << 5) ldrb r2, [r4], #1 @ r2 = Y' = *Y'_p++ orr r12, r12, r11, lsl #11 @ r4 = b | (r << 11) - strh r12, [r0], #240 @ store pixel + strh r12, [r0], #LCD_WIDTH @ store pixel @ sub r2, r2, #16 @ r7 = Y = (Y' - 16)*74 mul r7, r2, r14 @ next Y @@ -133,14 +214,14 @@ lcd_write_yuv420_lines: @ orr r12, r2, r11, lsl #11 @ r4 = b | (r << 11) orr r12, r12, r7, lsl #5 @ r4 |= (g << 5) - strh r12, [r0, #240]! @ store pixel - add r0, r0, #2*240 @ + strh r12, [r0, #LCD_WIDTH]! @ store pixel + add r0, r0, #2*LCD_WIDTH @ @ subs r3, r3, #2 @ bgt 10b @ loop line 1 @ @ do second line @ - ldmia sp!, { r0, r3 } @ pop dst and width + ldmfd sp!, { r0, r3 } @ pop dst and width sub r0, r0, #2 @ set dst to start of next line sub r1, r1, r3, asl #1 @ rewind chroma pointer... ldr r2, [sp, #40] @ r2 = stride @@ -182,7 +263,7 @@ lcd_write_yuv420_lines: orr r12, r2, r11, lsl #11 @ r4 = b | (r << 11) ldrb r2, [r4], #1 @ r2 = Y' = *Y'_p++ orr r12, r12, r7, lsl #5 @ r4 |= (g << 5) - strh r12, [r0], #240 @ store pixel + strh r12, [r0], #LCD_WIDTH @ store pixel @ @ do second pixel @ @@ -212,11 +293,11 @@ lcd_write_yuv420_lines: @ orr r12, r2, r11, lsl #11 @ r4 = b | (r << 11) orr r12, r12, r7, lsl #5 @ r4 |= (g << 5) - strh r12, [r0, #240]! @ store pixel - add r0, r0, #2*240 @ + strh r12, [r0, #LCD_WIDTH]! @ store pixel + add r0, r0, #2*LCD_WIDTH @ @ subs r3, r3, #2 @ bgt 20b @ loop line 2 @ @ - ldmia sp!, { r4-r12, pc } @ restore registers and return + ldmfd sp!, { r4-r12, pc } @ restore registers and return .size lcd_write_yuv420_lines, .-lcd_write_yuv420_lines diff --git a/firmware/target/arm/s3c2440/gigabeat-fx/lcd-meg-fx.c b/firmware/target/arm/s3c2440/gigabeat-fx/lcd-meg-fx.c index c96e0d6d2..5e1110eb3 100644 --- a/firmware/target/arm/s3c2440/gigabeat-fx/lcd-meg-fx.c +++ b/firmware/target/arm/s3c2440/gigabeat-fx/lcd-meg-fx.c @@ -15,6 +15,12 @@ volatile bool lcd_poweroff = false; extern unsigned fg_pattern; extern unsigned bg_pattern; +/* Copies a rectangle from one framebuffer to another. Can be used in + single transfer mode with width = num pixels, and height = 1 which + allows a full-width rectangle to be copied more efficiently. */ +extern void lcd_copy_buffer_rect(fb_data *dst, const fb_data *src, + int width, int height); + bool lcd_enabled() { return lcd_on; @@ -36,7 +42,6 @@ unsigned int LCDBASEL(unsigned int address) return (address & ((1 << 22)-1)) >> 1; } - /* LCD init */ void lcd_init_device(void) { @@ -122,17 +127,41 @@ void lcd_init_device(void) /* Update a fraction of the display. */ void lcd_update_rect(int x, int y, int width, int height) { - (void)x; - (void)width; - (void)y; - (void)height; + fb_data *dst, *src; - if(!lcd_on) - { - sleep(200); + if (!lcd_on) return; + + if (x + width > LCD_WIDTH) + width = LCD_WIDTH - x; /* Clip right */ + if (x < 0) + width += x, x = 0; /* Clip left */ + if (width <= 0) + return; /* nothing left to do */ + + if (y + height > LCD_HEIGHT) + height = LCD_HEIGHT - y; /* Clip bottom */ + if (y < 0) + height += y, y = 0; /* Clip top */ + if (height <= 0) + return; /* nothing left to do */ + + /* TODO: It may be faster to swap the addresses of lcd_driver_framebuffer + * and lcd_framebuffer */ + dst = (fb_data *)FRAME + LCD_WIDTH*y + x; + src = &lcd_framebuffer[y][x]; + + /* Copy part of the Rockbox framebuffer to the second framebuffer */ + if (width < LCD_WIDTH) + { + /* Not full width - do line-by-line */ + lcd_copy_buffer_rect(dst, src, width, height); + } + else + { + /* Full width - copy as one line */ + lcd_copy_buffer_rect(dst, src, LCD_WIDTH*height, 1); } - memcpy(((char*)FRAME) + (y * sizeof(fb_data) * LCD_WIDTH), ((char *)&lcd_framebuffer) + (y * sizeof(fb_data) * LCD_WIDTH), ((height * sizeof(fb_data) * LCD_WIDTH))); } void lcd_enable(bool state) @@ -144,7 +173,7 @@ void lcd_enable(bool state) if(!lcd_on) { lcd_on = true; - memcpy(FRAME, lcd_framebuffer, LCD_WIDTH*LCD_HEIGHT*2); + lcd_update(); LCDCON1 |= 1; } } @@ -161,7 +190,11 @@ void lcd_enable(bool state) This must be called after all other LCD functions that change the display. */ void lcd_update(void) { - lcd_update_rect(0, 0, LCD_WIDTH, LCD_HEIGHT); + if (!lcd_on) + return; + + lcd_copy_buffer_rect((fb_data *)FRAME, &lcd_framebuffer[0][0], + LCD_WIDTH*LCD_HEIGHT, 1); } void lcd_bitmap_transparent_part(const fb_data *src, int src_x, int src_y, @@ -171,28 +204,19 @@ void lcd_bitmap_transparent_part(const fb_data *src, int src_x, int src_y, fb_data *dst, *dst_end; unsigned int transcolor; - /* nothing to draw? */ - if ((width <= 0) || (height <= 0) || (x >= LCD_WIDTH) || (y >= LCD_HEIGHT) - || (x + width <= 0) || (y + height <= 0)) - return; - - /* clipping */ - if (x < 0) - { - width += x; - src_x -= x; - x = 0; - } - if (y < 0) - { - height += y; - src_y -= y; - y = 0; - } if (x + width > LCD_WIDTH) - width = LCD_WIDTH - x; + width = LCD_WIDTH - x; /* Clip right */ + if (x < 0) + width += x, x = 0; /* Clip left */ + if (width <= 0) + return; /* nothing left to do */ + if (y + height > LCD_HEIGHT) - height = LCD_HEIGHT - y; + height = LCD_HEIGHT - y; /* Clip bottom */ + if (y < 0) + height += y, y = 0; /* Clip top */ + if (height <= 0) + return; /* nothing left to do */ src += stride * src_y + src_x; /* move starting point */ dst = &lcd_framebuffer[(y)][(x)]; -- 2.11.4.GIT