freemyipod r497 - Code Review

Jump to: navigation, search
Repository:freemyipod
Revision:r496‎ | r497 | r498 >
Date:20:53, 31 January 2011
Author:theseven
Status:new
Tags:
Comment:
emCORE: Rework text rendering code, allow for fully alpha-blended rendering on RGB888 framebuffers
Modified paths:
  • /emcore/trunk/drawing.S (modified) (history)
  • /emcore/trunk/drawing.h (modified) (history)
  • /emcore/trunk/export/syscallapi.h (modified) (history)
  • /emcore/trunk/export/syscallwrappers.h (modified) (history)
  • /emcore/trunk/lcdconsole.c (modified) (history)
  • /emcore/trunk/syscallapi.c (modified) (history)

Diff [purge]

Index: emcore/trunk/drawing.S
@@ -50,46 +50,130 @@
5151 .global rendertext
5252 .type rendertext, %function
5353 rendertext:
54 - stmfd sp!, {r0-r2,r4,r5,lr}
55 - ldr r4, [sp,#0x18]
56 - str r4, [sp,#-4]!
57 - mov r4, r3
58 - mov r5, #6 * LCD_BYTESPERPIXEL
 54+ stmfd sp!, {r1-r8,lr}
 55+ mov r4, r0
 56+ ldmfd sp, {r5-r7}
 57+ ldr r0, [sp,#0x24]
 58+ ldr r1, [sp,#0x28]
 59+ ldr r8, [sp,#0x2c]
 60+ stmia sp, {r0,r1}
5961 rendertext_loop:
60 - ldrb r3, [r4], #1
61 - cmp r3, #0
 62+ ldrb r12, [r8], #1
 63+ mov r0, r4
 64+ cmp r12, #0
 65+ mov r1, r5
6266 beq rendertext_done
 67+ mov r2, r6
 68+ str r12, [sp,#0x8]
 69+ mov r3, r7
6370 bl renderchar
64 - ldmed sp, {r0-r2}
65 - add r0, r0, r5
66 - str r0, [sp,#4]
 71+ add r5, r5, #6
6772 b rendertext_loop
6873 rendertext_done:
69 - ldmfd sp!, {r0-r5,pc}
 74+ ldmfd sp!, {r1-r8,pc}
7075 .size rendertext, .-rendertext
7176
7277
73 -#if (LCD_BYTESPERPIXEL == 2)
7478 .section .icode.renderchar, "ax", %progbits
7579 .align 2
7680 .global renderchar
7781 .type renderchar, %function
 82+.global renderchar_native
 83+.type renderchar_native, %function
7884 renderchar:
 85+ stmfd sp!, {r4-r9,lr}
 86+ mla r1, r2, r3, r1
 87+ ldr r2, [sp,#0x24]
 88+ add r1, r1, r1,lsl#1
 89+ sub r2, r2, #0x20
 90+ add r0, r0, r1
 91+ adr r7, renderchar_font
 92+ cmp r2, #0x5f
 93+ add r2, r2, r2,lsl#2
 94+ mov r1, #6
 95+ addcc r7, r7, r2
 96+ ldr r4, [sp,#0x1c]
 97+ add r3, r3, r3,lsl#1
 98+ ldr r5, [sp,#0x20]
 99+renderchar_x:
 100+ cmp r1, #1
 101+ mov r2, #8
 102+ ldrneb lr, [r7], #1
 103+renderchar_y:
 104+ mov r12, r5,lsr#24
 105+ and r9, r5, #0xff
 106+ ldrb r8, [r0]
 107+ mul r9, r12, r9
 108+ rsb r12, r12, #0xff
 109+ tst lr, #1
 110+ mla r8, r12, r8, r9
 111+ movne r12, r4,lsr#24
 112+ andne r9, r4, #0xff
 113+ mov r8, r8,lsr#8
 114+ mulne r9, r12, r9
 115+ rsbne r12, r12, #0xff
 116+ mov lr, lr,lsr#1
 117+ mlane r8, r12, r8, r9
 118+ mov r9, r5,lsr#8
 119+ movne r8, r8,lsr#8
 120+ mov r12, r5,lsr#24
 121+ strb r8, [r0]
 122+ and r9, r9, #0xff
 123+ ldrb r8, [r0,#1]
 124+ mul r9, r12, r9
 125+ rsb r12, r12, #0xff
 126+ mla r8, r12, r8, r9
 127+ movne r9, r4,lsr#8
 128+ movne r12, r4,lsr#24
 129+ andne r9, r9, #0xff
 130+ mov r8, r8,lsr#8
 131+ mulne r9, r12, r9
 132+ rsbne r12, r12, #0xff
 133+ mlane r8, r12, r8, r9
 134+ mov r12, r5,lsr#24
 135+ mov r9, r5,lsr#16
 136+ movne r8, r8,lsr#8
 137+ and r9, r9, #0xff
 138+ strb r8, [r0,#1]
 139+ mul r9, r12, r9
 140+ ldrb r8, [r0,#2]
 141+ rsb r12, r12, #0xff
 142+ movne r9, r4,lsr#16
 143+ mla r8, r12, r8, r9
 144+ andne r9, r9, #0xff
 145+ movne r12, r4,lsr#24
 146+ mov r8, r8,lsr#8
 147+ mulne r9, r12, r9
 148+ rsbne r12, r12, #0xff
 149+ mlane r8, r12, r8, r9
 150+ movne r8, r8,lsr#8
 151+ subs r2, r2, #1
 152+ strb r8, [r0,#2]
 153+ add r0, r0, r3
 154+ bne renderchar_y
 155+ sub r0, r0, r3,lsl#3
 156+ subs r1, r1, #1
 157+ add r0, r0, #3
 158+ bne renderchar_x
 159+ ldmfd sp!, {r4-r9,pc}
 160+
 161+#if (LCD_BYTESPERPIXEL == 2)
 162+renderchar_native:
79163 stmfd sp!, {r4-r7,lr}
80164 ldr r7, [sp,#0x14]
81165 cmn r2, #1
82 - beq renderchar_nobg
 166+ beq renderchar_native_nobg
83167 mov r6, r0
84168 mov r4, #8
85169 mov lr, r2,lsr#16
86170 sub lr, lr, #0xff00
87171 subs lr, lr, #0xff
88 - bne renderchar_opaquerow
 172+ bne renderchar_native_opaquerow
89173 mov r12, r2,lsl#16
90174 mov r12, r12,lsr#16
91 -renderchar_blendrow:
 175+renderchar_native_blendrow:
92176 mov r5, #6
93 -renderchar_blendcol:
 177+renderchar_native_blendcol:
94178 ldrh lr, [r6]
95179 movs lr, lr,lsr#1
96180 #ifdef LCD_BIGENDIAN
@@ -102,23 +186,23 @@
103187 add lr, lr, r12
104188 strh lr, [r6], #2
105189 subs r5, r5, #1
106 - bne renderchar_blendcol
 190+ bne renderchar_native_blendcol
107191 add r6, r6, r7,lsl#1
108192 sub r6, r6, #12
109193 subs r4, r4, #1
110 - bne renderchar_blendrow
111 - b renderchar_nobg
112 -renderchar_opaquerow:
 194+ bne renderchar_native_blendrow
 195+ b renderchar_native_nobg
 196+renderchar_native_opaquerow:
113197 mov r5, #6
114 -renderchar_opaquecol:
 198+renderchar_native_opaquecol:
115199 strh r2, [r6], #2
116200 subs r5, r5, #1
117 - bne renderchar_opaquecol
 201+ bne renderchar_native_opaquecol
118202 add r6, r6, r7,lsl#1
119203 sub r6, r6, #12
120204 subs r4, r4, #1
121 - bne renderchar_opaquerow
122 -renderchar_nobg:
 205+ bne renderchar_native_opaquerow
 206+renderchar_native_nobg:
123207 adr r5, renderchar_font
124208 sub r3, r3, #0x20
125209 cmp r3, #0x5f
@@ -125,20 +209,23 @@
126210 addcc r5, r3,lsl#2
127211 addcc r5, r3
128212 mov r3, #5
129 -renderchar_col:
 213+renderchar_native_col:
130214 mov r6, r0
131215 ldrb r4, [r5], #1
132 -renderchar_row:
 216+renderchar_native_row:
133217 tst r4, #1
134218 strneh r1, [r6]
135219 add r6, r6, r7,lsl#1
136220 movs r4, r4,lsr#1
137 - bne renderchar_row
 221+ bne renderchar_native_row
138222 add r0, r0, #2
139223 subs r3, r3, #1
140 - bne renderchar_col
 224+ bne renderchar_native_col
141225 add r0, r0, #2
142226 ldmfd sp!, {r4-r7,pc}
 227+#else
 228+#error Unknown number of bytes per pixel!
 229+#endif
143230
144231 renderchar_font:
145232 .byte 0, 0, 0, 0, 0
@@ -237,7 +324,4 @@
238325 .byte 0, 65, 54, 8, 0
239326 .byte 2, 1, 2, 4, 2
240327 .align 2
241 -.size renderchar, .-renderchar
242 -#else
243 -#error Unknown number of bytes per pixel!
244 -#endif
 328+.size renderchar_native, .-renderchar_native
Index: emcore/trunk/drawing.h
@@ -32,8 +32,11 @@
3333 #define FONT_HEIGHT 8
3434
3535
36 -void renderchar(void* buffer, int fgcol, int bgcol, char text, int stride);
37 -void rendertext(void* buffer, int fgcol, int bgcol, char* text, int stride);
 36+void renderchar_native(void* buffer, int fgcol, int bgcol, char text, int stride);
 37+void renderchar(void* buffer, int x, int y, int stride,
 38+ uint32_t fgcolor, uint32_t bgcolor, char c);
 39+void rendertext(void* buffer, int x, int y, int stride,
 40+ uint32_t fgcolor, uint32_t bgcolor, char* str);
3841 int get_font_width(void);
3942 int get_font_height(void);
4043
Index: emcore/trunk/export/syscallwrappers.h
@@ -48,6 +48,7 @@
4949 #define readdir __emcore_syscall->readdir
5050 #define mkdir __emcore_syscall->mkdir
5151 #define rmdir __emcore_syscall->rmdir
 52+#define renderchar_native __emcore_syscall->renderchar_native
5253 #define renderchar __emcore_syscall->renderchar
5354 #define rendertext __emcore_syscall->rendertext
5455 #define get_font_width __emcore_syscall->get_font_width
Index: emcore/trunk/export/syscallapi.h
@@ -108,6 +108,7 @@
109109 typeof(readdir) *readdir;
110110 typeof(mkdir) *mkdir;
111111 typeof(rmdir) *rmdir;
 112+ typeof(renderchar_native) *renderchar_native;
112113 typeof(renderchar) *renderchar;
113114 typeof(rendertext) *rendertext;
114115 typeof(get_font_width) *get_font_width;
Index: emcore/trunk/syscallapi.c
@@ -169,6 +169,7 @@
170170 .lcd_get_height = lcd_get_height,
171171 .lcd_get_bytes_per_pixel = lcd_get_bytes_per_pixel,
172172 .lcd_translate_color = lcd_translate_color,
 173+ .renderchar_native = renderchar_native,
173174 .renderchar = renderchar,
174175 .rendertext = rendertext,
175176 .get_font_width = get_font_width,
Index: emcore/trunk/lcdconsole.c
@@ -81,8 +81,8 @@
8282 LCDCONSOLE_BGCOLOR, ROWBYTES * offset);
8383 current_row = LCDCONSOLE_ROWS - 1;
8484 }
85 - renderchar(&framebuf[OFFSETBYTES + ROWBYTES * current_row + COLBYTES * current_col],
86 - fgcolor, bgcolor, string, LCD_WIDTH);
 85+ renderchar_native(&framebuf[OFFSETBYTES + ROWBYTES * current_row + COLBYTES * current_col],
 86+ fgcolor, bgcolor, string, LCD_WIDTH);
8787 }
8888
8989 void lcdconsole_puts_noblit(const char* string, int fgcolor, int bgcolor)