diff --git a/.github/.test.sh b/.github/.test.sh new file mode 100644 index 0000000000000000000000000000000000000000..dc66c0f5ab4bd02f6beb8d6adbb1f9108466e4be --- /dev/null +++ b/.github/.test.sh @@ -0,0 +1,21 @@ +# exit while meet error +set -e + +#test HelloXXX +for file in ./Hello* +do + echo -e "\e[44m $file running...\e[49m" + if [ "$file" == "./HelloAzureIoT" ]; then + echo "skip $file" + continue + fi + cd $file/BuildLinux + timeout 5s ./.sync_build.sh & + sleep 6s + cd ../.. +done + +#test HostMonitor +echo -e "\e[44m ./HostMonitor running...\e[49m" +cd HostMonitor/BuildLinux +timeout 5s ./.sync_data.sh diff --git a/.github/.updateGuiLite.sh b/.github/.updateGuiLite.sh index 793a2d77225cc0f764bdf877bd4a702ca3460fad..748155a19dc90ee47eb4f0e08d29ea1fcbb53ec9 100644 --- a/.github/.updateGuiLite.sh +++ b/.github/.updateGuiLite.sh @@ -3,7 +3,7 @@ src=../../GuiLite.gitee set -e declare -i sum=0 -#build HelloXXX +#update for HelloXXX for file in ./Hello* do echo -e "\e[44m $file sync up...\e[49m" @@ -17,7 +17,7 @@ do sum+=1 done -#build HostMonitor +#update for HostMonitor echo -e "\e[44m ./HostMonitor sync up...\e[49m" cd HostMonitor cp $src/GuiLite.h UIcode/include/GuiLite.h diff --git a/Hello3D/BuildAppleWatch/Hello3D WatchKit Extension/Hello3D WatchKit Extension-Bridging-Header.h b/Hello3D/BuildAppleWatch/Hello3D WatchKit Extension/Hello3D WatchKit Extension-Bridging-Header.h index 287af9a8d33ccfb579756dfdb4be921cb65c62ca..2aafa7a018cdbe250f109c658116fd8577840877 100644 --- a/Hello3D/BuildAppleWatch/Hello3D WatchKit Extension/Hello3D WatchKit Extension-Bridging-Header.h +++ b/Hello3D/BuildAppleWatch/Hello3D WatchKit Extension/Hello3D WatchKit Extension-Bridging-Header.h @@ -8,7 +8,7 @@ extern "C"{ #endif - void startHello3D(void* phy_fb, int width, int height, int color_bytes, struct EXTERNAL_GFX_OP* gfx_op); + void startHello3D(void* phy_fb, int width, int height, int color_bytes, struct DISPLAY_DRIVER* driver); void* getUiOfHello3D(int* width, int* height, bool force_update); #ifdef __cplusplus diff --git a/Hello3D/BuildLinux/.sync_build.sh b/Hello3D/BuildLinux/.sync_build.sh index 49cff5b473ac606967676ebefa6f0d333e301227..1b470d562aba5aadb03942d5567006181041d0fa 100644 --- a/Hello3D/BuildLinux/.sync_build.sh +++ b/Hello3D/BuildLinux/.sync_build.sh @@ -1,5 +1,6 @@ if [ "$#" -ne 1 ]; then - echo "Invalid arguments" + echo "Do testing" + ./xWindow 240 320 | ./Hello3D shared-fb exit -1 fi diff --git a/Hello3D/BuildLinux/main.cpp b/Hello3D/BuildLinux/main.cpp index b3d6e03ec75186f0562a2a2ac81dff3a697bbc62..c4a066719e2214fa6773b7ceb619be4a0cc5161f 100644 --- a/Hello3D/BuildLinux/main.cpp +++ b/Hello3D/BuildLinux/main.cpp @@ -10,7 +10,7 @@ #include #include -extern "C" void startHello3D(void* phy_fb, int width, int height, int color_bytes, struct EXTERNAL_GFX_OP* gfx_op); +extern "C" void startHello3D(void* phy_fb, int width, int height, int color_bytes, struct DISPLAY_DRIVER* driver); extern void init_std_io(); static void* get_embeded_fb_in_display_app(int shared_id); diff --git a/Hello3D/BuildMFC/Hello3DDlg.cpp b/Hello3D/BuildMFC/Hello3DDlg.cpp index 38ed46ede3da298f2f65a4093d105fb926d02b54..46d94fe550eec86ec82b9a402b79e310ebd5830b 100644 Binary files a/Hello3D/BuildMFC/Hello3DDlg.cpp and b/Hello3D/BuildMFC/Hello3DDlg.cpp differ diff --git a/Hello3D/BuildMFC/Hello3DDlg.h b/Hello3D/BuildMFC/Hello3DDlg.h index 4335d37b77c06b71411c6f462cc5d36d9832adbf..c4b506ed251173ac0945d7c4e2f5c2ded20326f1 100644 Binary files a/Hello3D/BuildMFC/Hello3DDlg.h and b/Hello3D/BuildMFC/Hello3DDlg.h differ diff --git a/Hello3D/BuildQt/mainwindow.cpp b/Hello3D/BuildQt/mainwindow.cpp index 8d438b9419c08502bb68c06c95eb31cf0afaf563..48bc04e8d9dd6af2510ac233cc240a553f652145 100644 --- a/Hello3D/BuildQt/mainwindow.cpp +++ b/Hello3D/BuildQt/mainwindow.cpp @@ -10,7 +10,7 @@ #include #include -extern "C" void startHello3D(void* phy_fb, int width, int height, int color_bytes, struct EXTERNAL_GFX_OP* gfx_op); +extern "C" void startHello3D(void* phy_fb, int width, int height, int color_bytes, struct DISPLAY_DRIVER* driver); extern "C" void* getUiOfHello3D(int* width, int* height, bool force_update); #define UI_WIDTH 480 diff --git a/Hello3D/BuildSTM32F103-Keil/USER/main.c b/Hello3D/BuildSTM32F103-Keil/USER/main.c index e9fabd098854233c3454b0db4df097e069f23307..8fc07d9cb145c7bd9672ee8e835cffc65e858da8 100644 --- a/Hello3D/BuildSTM32F103-Keil/USER/main.c +++ b/Hello3D/BuildSTM32F103-Keil/USER/main.c @@ -15,12 +15,12 @@ void gfx_draw_pixel(int x, int y, unsigned int rgb) //void gfx_fill_rect(int x0, int y0, int x1, int y1, unsigned int rgb){} //UI entry -struct EXTERNAL_GFX_OP +struct DISPLAY_DRIVER { void (*draw_pixel)(int x, int y, unsigned int rgb); void (*fill_rect)(int x0, int y0, int x1, int y1, unsigned int rgb); -} my_gfx_op; -extern void startHello3D(void* phy_fb, int width, int height, int color_bytes, struct EXTERNAL_GFX_OP* gfx_op); +} my_driver; +extern void startHello3D(void* phy_fb, int width, int height, int color_bytes, struct DISPLAY_DRIVER* driver); int main(void) { @@ -30,8 +30,8 @@ int main(void) LCD_Init(); //Link your LCD driver & start UI: - my_gfx_op.draw_pixel = gfx_draw_pixel; - my_gfx_op.fill_rect = NULL;//gfx_fill_rect; - startHello3D(NULL, 240, 320, 2, &my_gfx_op); + my_driver.draw_pixel = gfx_draw_pixel; + my_driver.fill_rect = NULL;//gfx_fill_rect; + startHello3D(NULL, 240, 320, 2, &my_driver); while(1); } diff --git a/Hello3D/BuildWin32/Hello3D.cpp b/Hello3D/BuildWin32/Hello3D.cpp index 7a4cdd3d324817b8aa0d66dae24b3240f91ee2a1..668cffcf472ebc7911d24c9a22ee034f98463483 100644 --- a/Hello3D/BuildWin32/Hello3D.cpp +++ b/Hello3D/BuildWin32/Hello3D.cpp @@ -161,7 +161,7 @@ LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam) } //////////////////////// Hello3D Interface //////////////////////// -extern "C" void startHello3D(void* phy_fb, int width, int height, int color_bytes, struct EXTERNAL_GFX_OP* gfx_op); +extern "C" void startHello3D(void* phy_fb, int width, int height, int color_bytes, struct DISPLAY_DRIVER* driver); DWORD WINAPI ThreadHello3D(LPVOID pParam) { diff --git a/Hello3D/UIcode/GuiLite.h b/Hello3D/UIcode/GuiLite.h index c4fc88a51476d2c8309c3e55e1270e13784fc510..80550e1632ad7bc82541a2edbb0f7f8f5937954f 100644 --- a/Hello3D/UIcode/GuiLite.h +++ b/Hello3D/UIcode/GuiLite.h @@ -1,107 +1,94 @@ #pragma once - -#define REAL_TIME_TASK_CYCLE_MS 50 -#define MAX(a,b) (((a)>(b))?(a):(b)) -#define MIN(a,b) (((a)<(b))?(a):(b)) - -#define GL_ARGB(a, r, g, b) ((((unsigned int)(a)) << 24) | (((unsigned int)(r)) << 16) | (((unsigned int)(g)) << 8) | ((unsigned int)(b))) -#define GL_ARGB_A(rgb) ((((unsigned int)(rgb)) >> 24) & 0xFF) - -#define GL_RGB(r, g, b) ((0xFF << 24) | (((unsigned int)(r)) << 16) | (((unsigned int)(g)) << 8) | ((unsigned int)(b))) -#define GL_RGB_R(rgb) ((((unsigned int)(rgb)) >> 16) & 0xFF) -#define GL_RGB_G(rgb) ((((unsigned int)(rgb)) >> 8) & 0xFF) -#define GL_RGB_B(rgb) (((unsigned int)(rgb)) & 0xFF) -#define GL_RGB_32_to_16(rgb) (((((unsigned int)(rgb)) & 0xFF) >> 3) | ((((unsigned int)(rgb)) & 0xFC00) >> 5) | ((((unsigned int)(rgb)) & 0xF80000) >> 8)) -#define GL_RGB_16_to_32(rgb) ((0xFF << 24) | ((((unsigned int)(rgb)) & 0x1F) << 3) | ((((unsigned int)(rgb)) & 0x7E0) << 5) | ((((unsigned int)(rgb)) & 0xF800) << 8)) - -#define ALIGN_HCENTER 0x00000000L -#define ALIGN_LEFT 0x01000000L -#define ALIGN_RIGHT 0x02000000L -#define ALIGN_HMASK 0x03000000L - -#define ALIGN_VCENTER 0x00000000L -#define ALIGN_TOP 0x00100000L -#define ALIGN_BOTTOM 0x00200000L -#define ALIGN_VMASK 0x00300000L - -typedef struct -{ - unsigned short year; - unsigned short month; - unsigned short date; - unsigned short day; - unsigned short hour; - unsigned short minute; - unsigned short second; -}T_TIME; - -void register_debug_function(void(*my_assert)(const char* file, int line), void(*my_log_out)(const char* log)); -void _assert(const char* file, int line); -#define ASSERT(condition) \ - do{ \ - if(!(condition))_assert(__FILE__, __LINE__);\ - }while(0) -void log_out(const char* log); - -long get_time_in_second(); -T_TIME second_to_day(long second); -T_TIME get_time(); - -void start_real_timer(void (*func)(void* arg)); -void register_timer(int milli_second, void func(void* param), void* param); - -unsigned int get_cur_thread_id(); -void create_thread(unsigned long* thread_id, void* attr, void *(*start_routine) (void *), void* arg); -void thread_sleep(unsigned int milli_seconds); -int build_bmp(const char *filename, unsigned int width, unsigned int height, unsigned char *data); - -#define FIFO_BUFFER_LEN 1024 -class c_fifo -{ -public: - c_fifo(); - int read(void* buf, int len); - int write(void* buf, int len); -private: - unsigned char m_buf[FIFO_BUFFER_LEN]; - int m_head; - int m_tail; - void* m_read_sem; - void* m_write_mutex; -}; - -class c_rect -{ -public: - c_rect(){ m_left = m_top = m_right = m_bottom = -1; } - c_rect(int left, int top, int width, int height) - { - set_rect(left, top, width, height); - } - void set_rect(int left, int top, int width, int height) - { - ASSERT(width > 0 && height > 0); - m_left = left; - m_top = top; - m_right = left + width - 1; - m_bottom = top + height -1; - } - bool pt_in_rect(int x, int y) const - { - return x >= m_left && x <= m_right && y >= m_top && y <= m_bottom; - } - int operator==(const c_rect& rect) const - { - return (m_left == rect.m_left) && (m_top == rect.m_top) && (m_right == rect.m_right) && (m_bottom == rect.m_bottom); - } - int width() const { return m_right - m_left + 1; } - int height() const { return m_bottom - m_top + 1 ; } - - int m_left; - int m_top; - int m_right; - int m_bottom; -}; +#define REAL_TIME_TASK_CYCLE_MS 50 +#define MAX(a,b) (((a)>(b))?(a):(b)) +#define MIN(a,b) (((a)<(b))?(a):(b)) +#define GL_ARGB(a, r, g, b) ((((unsigned int)(a)) << 24) | (((unsigned int)(r)) << 16) | (((unsigned int)(g)) << 8) | ((unsigned int)(b))) +#define GL_ARGB_A(rgb) ((((unsigned int)(rgb)) >> 24) & 0xFF) +#define GL_RGB(r, g, b) ((0xFF << 24) | (((unsigned int)(r)) << 16) | (((unsigned int)(g)) << 8) | ((unsigned int)(b))) +#define GL_RGB_R(rgb) ((((unsigned int)(rgb)) >> 16) & 0xFF) +#define GL_RGB_G(rgb) ((((unsigned int)(rgb)) >> 8) & 0xFF) +#define GL_RGB_B(rgb) (((unsigned int)(rgb)) & 0xFF) +#define GL_RGB_32_to_16(rgb) (((((unsigned int)(rgb)) & 0xFF) >> 3) | ((((unsigned int)(rgb)) & 0xFC00) >> 5) | ((((unsigned int)(rgb)) & 0xF80000) >> 8)) +#define GL_RGB_16_to_32(rgb) ((0xFF << 24) | ((((unsigned int)(rgb)) & 0x1F) << 3) | ((((unsigned int)(rgb)) & 0x7E0) << 5) | ((((unsigned int)(rgb)) & 0xF800) << 8)) +#define ALIGN_HCENTER 0x00000000L +#define ALIGN_LEFT 0x01000000L +#define ALIGN_RIGHT 0x02000000L +#define ALIGN_HMASK 0x03000000L +#define ALIGN_VCENTER 0x00000000L +#define ALIGN_TOP 0x00100000L +#define ALIGN_BOTTOM 0x00200000L +#define ALIGN_VMASK 0x00300000L +typedef struct +{ + unsigned short year; + unsigned short month; + unsigned short date; + unsigned short day; + unsigned short hour; + unsigned short minute; + unsigned short second; +}T_TIME; +void register_debug_function(void(*my_assert)(const char* file, int line), void(*my_log_out)(const char* log)); +void _assert(const char* file, int line); +#define ASSERT(condition) \ + do{ \ + if(!(condition))_assert(__FILE__, __LINE__);\ + }while(0) +void log_out(const char* log); +long get_time_in_second(); +T_TIME second_to_day(long second); +T_TIME get_time(); +void start_real_timer(void (*func)(void* arg)); +void register_timer(int milli_second, void func(void* param), void* param); +unsigned int get_cur_thread_id(); +void create_thread(unsigned long* thread_id, void* attr, void *(*start_routine) (void *), void* arg); +void thread_sleep(unsigned int milli_seconds); +int build_bmp(const char *filename, unsigned int width, unsigned int height, unsigned char *data); +#define FIFO_BUFFER_LEN 1024 +class c_fifo +{ +public: + c_fifo(); + int read(void* buf, int len); + int write(void* buf, int len); +private: + unsigned char m_buf[FIFO_BUFFER_LEN]; + int m_head; + int m_tail; + void* m_read_sem; + void* m_write_mutex; +}; +class c_rect +{ +public: + c_rect(){ m_left = m_top = m_right = m_bottom = -1; } + c_rect(int left, int top, int width, int height) + { + set_rect(left, top, width, height); + } + void set_rect(int left, int top, int width, int height) + { + ASSERT(width > 0 && height > 0); + m_left = left; + m_top = top; + m_right = left + width - 1; + m_bottom = top + height -1; + } + bool pt_in_rect(int x, int y) const + { + return x >= m_left && x <= m_right && y >= m_top && y <= m_bottom; + } + int operator==(const c_rect& rect) const + { + return (m_left == rect.m_left) && (m_top == rect.m_top) && (m_right == rect.m_right) && (m_bottom == rect.m_bottom); + } + int width() const { return m_right - m_left + 1; } + int height() const { return m_bottom - m_top + 1 ; } + int m_left; + int m_top; + int m_right; + int m_bottom; +}; //BITMAP typedef struct struct_bitmap_info { @@ -238,7 +225,7 @@ typedef enum Z_ORDER_LEVEL_2,//highest graphic level Z_ORDER_LEVEL_MAX }Z_ORDER_LEVEL; -struct EXTERNAL_GFX_OP +struct DISPLAY_DRIVER { void(*draw_pixel)(int x, int y, unsigned int rgb); void(*fill_rect)(int x0, int y0, int x1, int y1, unsigned int rgb); @@ -247,18 +234,19 @@ class c_surface; class c_display { friend class c_surface; public: - inline c_display(void* phy_fb, int display_width, int display_height, int surface_width, int surface_height, unsigned int color_bytes, int surface_cnt, EXTERNAL_GFX_OP* gfx_op = 0);//multiple surface or surface_no_fb - inline c_display(void* phy_fb, int display_width, int display_height, c_surface* surface);//single custom surface - inline c_surface* alloc_surface(Z_ORDER_LEVEL max_zorder, c_rect layer_rect = c_rect());//for multiple surfaces + inline c_display(void* phy_fb, int display_width, int display_height, c_surface* surface, DISPLAY_DRIVER* driver = 0);//single custom surface + inline c_display(void* phy_fb, int display_width, int display_height, int surface_width, int surface_height, unsigned int color_bytes, int surface_cnt, DISPLAY_DRIVER* driver = 0);//multiple surface + inline c_surface* alloc_surface(Z_ORDER_LEVEL max_zorder, c_rect layer_rect = c_rect());//for slide group inline int swipe_surface(c_surface* s0, c_surface* s1, int x0, int x1, int y0, int y1, int offset); int get_width() { return m_width; } int get_height() { return m_height; } + void* get_phy_fb() { return m_phy_fb; } void* get_updated_fb(int* width, int* height, bool force_update = false) { if (width && height) { - *width = get_width(); - *height = get_height(); + *width = m_width; + *height = m_height; } if (force_update) { @@ -277,35 +265,123 @@ public: { return -1; } - int width = get_width(); - int height = get_height(); //16 bits framebuffer if (m_color_bytes == 2) { - return build_bmp(file_name, width, height, (unsigned char*)m_phy_fb); + return build_bmp(file_name, m_width, m_height, (unsigned char*)m_phy_fb); } //32 bits framebuffer - unsigned short* p_bmp565_data = new unsigned short[width * height]; + unsigned short* p_bmp565_data = new unsigned short[m_width * m_height]; unsigned int* p_raw_data = (unsigned int*)m_phy_fb; - for (int i = 0; i < width * height; i++) + for (int i = 0; i < m_width * m_height; i++) { unsigned int rgb = *p_raw_data++; p_bmp565_data[i] = GL_RGB_32_to_16(rgb); } - int ret = build_bmp(file_name, width, height, (unsigned char*)p_bmp565_data); + int ret = build_bmp(file_name, m_width, m_height, (unsigned char*)p_bmp565_data); delete[]p_bmp565_data; return ret; } -private: - int m_width; //in pixels - int m_height; //in pixels - int m_color_bytes; //16 bits, 32 bits only - void* m_phy_fb; //physical framebuffer +protected: + virtual void draw_pixel(int x, int y, unsigned int rgb) + { + if ((x >= m_width) || (y >= m_height)) { return; } + if (m_driver && m_driver->draw_pixel) + { + return m_driver->draw_pixel(x, y, rgb); + } + if (m_color_bytes == 2) + { + ((unsigned short*)m_phy_fb)[y * m_width + x] = GL_RGB_32_to_16(rgb); + } + else + { + ((unsigned int*)m_phy_fb)[y * m_width + x] = rgb; + } + } + virtual void fill_rect(int x0, int y0, int x1, int y1, unsigned int rgb) + { + if (m_driver && m_driver->fill_rect) + { + return m_driver->fill_rect(x0, y0, x1, y1, rgb); + } + if (m_driver && m_driver->draw_pixel) + { + for (int y = y0; y <= y1; y++) + { + for (int x = x0; x <= x1; x++) + { + m_driver->draw_pixel(x, y, rgb); + } + } + return; + } + register int _width = m_width; + register int _height = m_height; + int x, y; + if (m_color_bytes == 2) + { + unsigned short* phy_fb; + unsigned int rgb_16 = GL_RGB_32_to_16(rgb); + for (y = y0; y <= y1; y++) + { + phy_fb = &((unsigned short*)m_phy_fb)[y * _width + x0]; + for (x = x0; x <= x1; x++) + { + if ((x < _width) && (y < _height)) + { + *phy_fb++ = rgb_16; + } + } + } + } + else + { + unsigned int* phy_fb; + for (y = y0; y <= y1; y++) + { + phy_fb = &((unsigned int*)m_phy_fb)[y * _width + x0]; + for (x = x0; x <= x1; x++) + { + if ((x < _width) && (y < _height)) + { + *phy_fb++ = rgb; + } + } + } + } + } + virtual int flush_screen(int left, int top, int right, int bottom, void* fb, int fb_width) + { + if ((0 == m_phy_fb) || (0 == fb)) + { + return -1; + } + register int _width = m_width; + register int _height = m_height; + left = (left >= _width) ? (_width - 1) : left; + right = (right >= _width) ? (_width - 1) : right; + top = (top >= _height) ? (_height - 1) : top; + bottom = (bottom >= _height) ? (_height - 1) : bottom; + for (int y = top; y < bottom; y++) + { + void* s_addr = (char*)fb + ((y * fb_width + left) * m_color_bytes); + void* d_addr = (char*)m_phy_fb + ((y * _width + left) * m_color_bytes); + memcpy(d_addr, s_addr, (right - left) * m_color_bytes); + } + return 0; + } + int m_width; //in pixels + int m_height; //in pixels + int m_color_bytes; //16/32 bits for default + void* m_phy_fb; //physical framebuffer for default + struct DISPLAY_DRIVER* m_driver; //Rendering by external method without default physical framebuffer int m_phy_read_index; int m_phy_write_index; c_surface* m_surface_group[SURFACE_CNT_MAX]; int m_surface_cnt; //surface count int m_surface_index; + }; class c_layer { @@ -317,12 +393,10 @@ public: class c_surface { friend class c_display; friend class c_bitmap_operator; public: - c_surface(unsigned int width, unsigned int height, unsigned int color_bytes, Z_ORDER_LEVEL max_zorder = Z_ORDER_LEVEL_0, c_rect overlpa_rect = c_rect()) : m_width(width), m_height(height), m_color_bytes(color_bytes), m_fb(0), m_is_active(false), m_top_zorder(Z_ORDER_LEVEL_0), m_phy_fb(0), m_phy_write_index(0), m_display(0) + c_surface(unsigned int width, unsigned int height, unsigned int color_bytes, Z_ORDER_LEVEL max_zorder = Z_ORDER_LEVEL_0, c_rect overlpa_rect = c_rect()) : m_width(width), m_height(height), m_color_bytes(color_bytes), m_fb(0), m_is_active(false), m_top_zorder(Z_ORDER_LEVEL_0), m_phy_write_index(0), m_display(0) { (overlpa_rect == c_rect()) ? set_surface(max_zorder, c_rect(0, 0, width - 1, height - 1)) : set_surface(max_zorder, overlpa_rect); } - int get_width() { return m_width; } - int get_height() { return m_height; } unsigned int get_pixel(int x, int y, unsigned int z_order) { if (x >= m_width || y >= m_height || x < 0 || y < 0 || z_order >= Z_ORDER_LEVEL_MAX) @@ -332,15 +406,15 @@ public: } if (m_layers[z_order].fb) { - return (m_color_bytes == 4) ? ((unsigned int*)(m_layers[z_order].fb))[y * m_width + x] : GL_RGB_16_to_32(((unsigned short*)(m_layers[z_order].fb))[y * m_width + x]); + return (m_color_bytes == 2) ? GL_RGB_16_to_32(((unsigned short*)(m_layers[z_order].fb))[y * m_width + x]) : ((unsigned int*)(m_layers[z_order].fb))[y * m_width + x]; } else if (m_fb) { - return (m_color_bytes == 4) ? ((unsigned int*)m_fb)[y * m_width + x] : GL_RGB_16_to_32(((unsigned short*)m_fb)[y * m_width + x]); + return (m_color_bytes == 2) ? GL_RGB_16_to_32(((unsigned short*)m_fb)[y * m_width + x]) : ((unsigned int*)m_fb)[y * m_width + x]; } - else if (m_phy_fb) + else if (m_display->m_phy_fb) { - return (m_color_bytes == 4) ? ((unsigned int*)m_phy_fb)[y * m_width + x] : GL_RGB_16_to_32(((unsigned short*)m_phy_fb)[y * m_width + x]); + return (m_color_bytes == 2) ? GL_RGB_16_to_32(((unsigned short*)m_display->m_phy_fb)[y * m_width + x]) : ((unsigned int*)m_display->m_phy_fb)[y * m_width + x]; } return 0; } @@ -357,7 +431,7 @@ public: } if (z_order == m_max_zorder) { - return draw_pixel_on_fb(x, y, rgb); + return draw_pixel_low_level(x, y, rgb); } if (z_order > (unsigned int)m_top_zorder) @@ -367,19 +441,19 @@ public: if (m_layers[z_order].rect.pt_in_rect(x, y)) { c_rect layer_rect = m_layers[z_order].rect; - if (m_color_bytes == 4) + if (m_color_bytes == 2) { - ((unsigned int*)(m_layers[z_order].fb))[(x - layer_rect.m_left) + (y - layer_rect.m_top) * layer_rect.width()] = rgb; + ((unsigned short*)(m_layers[z_order].fb))[(x - layer_rect.m_left) + (y - layer_rect.m_top) * layer_rect.width()] = GL_RGB_32_to_16(rgb); } else { - ((unsigned short*)(m_layers[z_order].fb))[(x - layer_rect.m_left) + (y - layer_rect.m_top) * layer_rect.width()] = GL_RGB_32_to_16(rgb); + ((unsigned int*)(m_layers[z_order].fb))[(x - layer_rect.m_left) + (y - layer_rect.m_top) * layer_rect.width()] = rgb; } } if (z_order == m_top_zorder) { - return draw_pixel_on_fb(x, y, rgb); + return draw_pixel_low_level(x, y, rgb); } bool be_overlapped = false; for (unsigned int tmp_z_order = Z_ORDER_LEVEL_MAX - 1; tmp_z_order > z_order; tmp_z_order--) @@ -392,7 +466,7 @@ public: } if (!be_overlapped) { - draw_pixel_on_fb(x, y, rgb); + draw_pixel_low_level(x, y, rgb); } } virtual void fill_rect(int x0, int y0, int x1, int y1, unsigned int rgb, unsigned int z_order) @@ -403,7 +477,7 @@ public: y1 = (y1 > (m_height - 1)) ? (m_height - 1) : y1; if (z_order == m_max_zorder) { - return fill_rect_on_fb(x0, y0, x1, y1, rgb); + return fill_rect_low_level(x0, y0, x1, y1, rgb); } if (z_order == m_top_zorder) { @@ -416,18 +490,18 @@ public: { if (layer_rect.pt_in_rect(x, y)) { - if (m_color_bytes == 4) + if (m_color_bytes == 2) { - ((unsigned int*)m_layers[z_order].fb)[(y - layer_rect.m_top) * layer_rect.width() + (x - layer_rect.m_left)] = rgb; + ((unsigned short*)m_layers[z_order].fb)[(y - layer_rect.m_top) * layer_rect.width() + (x - layer_rect.m_left)] = rgb_16; } else { - ((unsigned short*)m_layers[z_order].fb)[(y - layer_rect.m_top) * layer_rect.width() + (x - layer_rect.m_left)] = rgb_16; + ((unsigned int*)m_layers[z_order].fb)[(y - layer_rect.m_top) * layer_rect.width() + (x - layer_rect.m_left)] = rgb; } } } } - return fill_rect_on_fb(x0, y0, x1, y1, rgb); + return fill_rect_low_level(x0, y0, x1, y1, rgb); } for (; y0 <= y1; y0++) { @@ -499,27 +573,16 @@ public: } int flush_screen(int left, int top, int right, int bottom) { - if (left < 0 || left >= m_width || right < 0 || right >= m_width || - top < 0 || top >= m_height || bottom < 0 || bottom >= m_height) - { - ASSERT(false); - } - if (!m_is_active || (0 == m_phy_fb) || (0 == m_fb)) + if (!m_is_active) { return -1; } - int display_width = m_display->get_width(); - int display_height = m_display->get_height(); - left = (left >= display_width) ? (display_width - 1) : left; - right = (right >= display_width) ? (display_width - 1) : right; - top = (top >= display_height) ? (display_height - 1) : top; - bottom = (bottom >= display_height) ? (display_height - 1) : bottom; - for (int y = top; y < bottom; y++) + if (left < 0 || left >= m_width || right < 0 || right >= m_width || + top < 0 || top >= m_height || bottom < 0 || bottom >= m_height) { - void* s_addr = (char*)m_fb + ((y * m_width + left) * m_color_bytes); - void* d_addr = (char*)m_phy_fb + ((y * display_width + left) * m_color_bytes); - memcpy(d_addr, s_addr, (right - left) * m_color_bytes); + ASSERT(false); } + m_display->flush_screen(left, top, right, bottom, m_fb, m_width); *m_phy_write_index = *m_phy_write_index + 1; return 0; } @@ -537,90 +600,62 @@ public: { for (int x = rect.m_left; x <= rect.m_right; x++) { - unsigned int rgb = (m_color_bytes == 4) ? ((unsigned int*)fb)[(x - layer_rect.m_left) + (y - layer_rect.m_top) * width] : GL_RGB_16_to_32(((unsigned short*)fb)[(x - layer_rect.m_left) + (y - layer_rect.m_top) * width]); - draw_pixel_on_fb(x, y, rgb); + unsigned int rgb = (m_color_bytes == 2) ? GL_RGB_16_to_32(((unsigned short*)fb)[(x - layer_rect.m_left) + (y - layer_rect.m_top) * width]) : ((unsigned int*)fb)[(x - layer_rect.m_left) + (y - layer_rect.m_top) * width]; + draw_pixel_low_level(x, y, rgb); } } return 0; } void set_active(bool flag) { m_is_active = flag; } protected: - virtual void fill_rect_on_fb(int x0, int y0, int x1, int y1, unsigned int rgb) - { - int display_width = m_display->get_width(); - int display_height = m_display->get_height(); - if (m_color_bytes == 4) + virtual void fill_rect_low_level(int x0, int y0, int x1, int y1, unsigned int rgb) + {//fill rect on framebuffer of surface + int x, y; + if (m_color_bytes == 2) { - int x; - unsigned int* fb, * phy_fb; - for (; y0 <= y1; y0++) + unsigned short* fb; + unsigned int rgb_16 = GL_RGB_32_to_16(rgb); + for (y = y0; y <= y1; y++) { - x = x0; - fb = m_fb ? &((unsigned int*)m_fb)[y0 * m_width + x] : 0; - phy_fb = &((unsigned int*)m_phy_fb)[y0 * display_width + x]; - *m_phy_write_index = *m_phy_write_index + 1; - for (; x <= x1; x++) + fb = m_fb ? &((unsigned short*)m_fb)[y * m_width + x0] : 0; + if (!fb) { break; } + for (x = x0; x <= x1; x++) { - if (fb) - { - *fb++ = rgb; - } - if (m_is_active && (x < display_width) && (y0 < display_height)) - { - *phy_fb++ = rgb; - } + *fb++ = rgb_16; } } } - else if (m_color_bytes == 2) + else { - int x; - unsigned short* fb, * phy_fb; - rgb = GL_RGB_32_to_16(rgb); - for (; y0 <= y1; y0++) + unsigned int* fb; + for (y = y0; y <= y1; y++) { - x = x0; - fb = m_fb ? &((unsigned short*)m_fb)[y0 * m_width + x] : 0; - phy_fb = &((unsigned short*)m_phy_fb)[y0 * display_width + x]; - *m_phy_write_index = *m_phy_write_index + 1; - for (; x <= x1; x++) + fb = m_fb ? &((unsigned int*)m_fb)[y * m_width + x0] : 0; + if (!fb) { break; } + for (x = x0; x <= x1; x++) { - if (fb) - { - *fb++ = rgb; - } - if (m_is_active && (x < display_width) && (y0 < display_height)) - { - *phy_fb++ = rgb; - } + *fb++ = rgb; } } } + if (!m_is_active) { return; } + m_display->fill_rect(x0, y0, x1, y1, rgb); + *m_phy_write_index = *m_phy_write_index + 1; } - virtual void draw_pixel_on_fb(int x, int y, unsigned int rgb) + virtual void draw_pixel_low_level(int x, int y, unsigned int rgb) { if (m_fb) - { - (m_color_bytes == 4) ? ((unsigned int*)m_fb)[y * m_width + x] = rgb : ((unsigned short*)m_fb)[y * m_width + x] = GL_RGB_32_to_16(rgb); - } - if (m_is_active && (x < m_display->get_width()) && (y < m_display->get_height())) - { - if (m_color_bytes == 4) - { - ((unsigned int*)m_phy_fb)[y * (m_display->get_width()) + x] = rgb; - } - else - { - ((unsigned short*)m_phy_fb)[y * (m_display->get_width()) + x] = GL_RGB_32_to_16(rgb); - } - *m_phy_write_index = *m_phy_write_index + 1; + {//draw pixel on framebuffer of surface + (m_color_bytes == 2) ? ((unsigned short*)m_fb)[y * m_width + x] = GL_RGB_32_to_16(rgb): ((unsigned int*)m_fb)[y * m_width + x] = rgb; } + if (!m_is_active) { return; } + m_display->draw_pixel(x, y, rgb); + *m_phy_write_index = *m_phy_write_index + 1; } void attach_display(c_display* display) { ASSERT(display); m_display = display; - m_phy_fb = display->m_phy_fb; m_phy_write_index = &display->m_phy_write_index; } void set_surface(Z_ORDER_LEVEL max_z_order, c_rect layer_rect) @@ -638,87 +673,22 @@ protected: } int m_width; //in pixels int m_height; //in pixels - int m_color_bytes; //16 bits, 32 bits only + int m_color_bytes; //16 bits, 32 bits for default void* m_fb; //frame buffer you could see c_layer m_layers[Z_ORDER_LEVEL_MAX];//all graphic layers bool m_is_active; //active flag Z_ORDER_LEVEL m_max_zorder; //the highest graphic layer the surface will have Z_ORDER_LEVEL m_top_zorder; //the current highest graphic layer the surface have - void* m_phy_fb; //physical framebufer int* m_phy_write_index; c_display* m_display; }; -class c_surface_no_fb : public c_surface {//No physical framebuffer, render with external graphic interface - friend class c_display; -public: - c_surface_no_fb(unsigned int width, unsigned int height, unsigned int color_bytes, struct EXTERNAL_GFX_OP* gfx_op, Z_ORDER_LEVEL max_zorder = Z_ORDER_LEVEL_0, c_rect overlpa_rect = c_rect()) : c_surface(width, height, color_bytes, max_zorder, overlpa_rect), m_gfx_op(gfx_op) {} -protected: - virtual void fill_rect_on_fb(int x0, int y0, int x1, int y1, unsigned int rgb) - { - if (!m_gfx_op) - { - return; - } - if (m_gfx_op->fill_rect) - { - return m_gfx_op->fill_rect(x0, y0, x1, y1, rgb); - } - if (m_gfx_op->draw_pixel && m_is_active) - { - for (int y = y0; y <= y1; y++) - { - for (int x = x0; x <= x1; x++) - { - m_gfx_op->draw_pixel(x, y, rgb); - } - } - } - if (!m_fb) { return; } - if (m_color_bytes == 4) - { - unsigned int* fb; - for (int y = y0; y <= y1; y++) - { - fb = &((unsigned int*)m_fb)[y0 * m_width + x0]; - for (int x = x0; x <= x1; x++) - { - *fb++ = rgb; - } - } - } - else if (m_color_bytes == 2) - { - unsigned short* fb; - rgb = GL_RGB_32_to_16(rgb); - for (int y = y0; y <= y1; y++) - { - fb = &((unsigned short*)m_fb)[y0 * m_width + x0]; - for (int x = x0; x <= x1; x++) - { - *fb++ = rgb; - } - } - } - } - virtual void draw_pixel_on_fb(int x, int y, unsigned int rgb) - { - if (m_gfx_op && m_gfx_op->draw_pixel && m_is_active) - { - m_gfx_op->draw_pixel(x, y, rgb); - } - if (!m_fb) { return; } - if (m_color_bytes == 4) - { - ((unsigned int*)m_fb)[y * m_width + x] = rgb; - } - else if (m_color_bytes == 2) - { - ((unsigned short*)m_fb)[y * m_width + x] = GL_RGB_32_to_16(rgb); - } - } - struct EXTERNAL_GFX_OP* m_gfx_op;//Rendering by external method -}; -inline c_display::c_display(void* phy_fb, int display_width, int display_height, int surface_width, int surface_height, unsigned int color_bytes, int surface_cnt, EXTERNAL_GFX_OP* gfx_op) : m_width(display_width), m_height(display_height), m_color_bytes(color_bytes), m_phy_fb(phy_fb), m_phy_read_index(0), m_phy_write_index(0), m_surface_cnt(surface_cnt), m_surface_index(0) +inline c_display::c_display(void* phy_fb, int display_width, int display_height, c_surface* surface, DISPLAY_DRIVER* driver) : m_phy_fb(phy_fb), m_width(display_width), m_height(display_height), m_driver(driver), m_phy_read_index(0), m_phy_write_index(0), m_surface_cnt(1), m_surface_index(0) +{ + m_color_bytes = surface->m_color_bytes; + surface->m_is_active = true; + (m_surface_group[0] = surface)->attach_display(this); +} +inline c_display::c_display(void* phy_fb, int display_width, int display_height, int surface_width, int surface_height, unsigned int color_bytes, int surface_cnt, DISPLAY_DRIVER* driver) : m_phy_fb(phy_fb), m_width(display_width), m_height(display_height), m_color_bytes(color_bytes), m_phy_read_index(0), m_phy_write_index(0), m_surface_cnt(surface_cnt), m_driver(driver), m_surface_index(0) { ASSERT(color_bytes == 2 || color_bytes == 4); ASSERT(m_surface_cnt <= SURFACE_CNT_MAX); @@ -726,16 +696,10 @@ inline c_display::c_display(void* phy_fb, int display_width, int display_height, for (int i = 0; i < m_surface_cnt; i++) { - m_surface_group[i] = (phy_fb) ? new c_surface(surface_width, surface_height, color_bytes) : new c_surface_no_fb(surface_width, surface_height, color_bytes, gfx_op); + m_surface_group[i] = new c_surface(surface_width, surface_height, color_bytes); m_surface_group[i]->attach_display(this); } } -inline c_display::c_display(void* phy_fb, int display_width, int display_height, c_surface* surface) : m_width(display_width), m_height(display_height), m_phy_fb(phy_fb), m_phy_read_index(0), m_phy_write_index(0), m_surface_cnt(1), m_surface_index(0) -{ - m_color_bytes = surface->m_color_bytes; - surface->m_is_active = true; - (m_surface_group[0] = surface)->attach_display(this); -} inline c_surface* c_display::alloc_surface(Z_ORDER_LEVEL max_zorder, c_rect layer_rect) { ASSERT(max_zorder < Z_ORDER_LEVEL_MAX && m_surface_index < m_surface_cnt); @@ -744,8 +708,8 @@ inline c_surface* c_display::alloc_surface(Z_ORDER_LEVEL max_zorder, c_rect laye } inline int c_display::swipe_surface(c_surface* s0, c_surface* s1, int x0, int x1, int y0, int y1, int offset) { - int surface_width = s0->get_width(); - int surface_height = s0->get_height(); + register int surface_width = s0->m_width; + register int surface_height = s0->m_height; if (offset < 0 || offset > surface_width || y0 < 0 || y0 >= surface_height || y1 < 0 || y1 >= surface_height || x0 < 0 || x0 >= surface_width || x1 < 0 || x1 >= surface_width) { @@ -767,46 +731,46 @@ inline int c_display::swipe_surface(c_surface* s0, c_surface* s1, int x0, int x1 for (int y = y0; y <= y1; y++) { //Left surface - char* addr_s = ((char*)(s0->m_fb) + (y * (s0->get_width()) + x0 + offset) * m_color_bytes); + char* addr_s = ((char*)(s0->m_fb) + (y * surface_width + x0 + offset) * m_color_bytes); char* addr_d = ((char*)(m_phy_fb)+(y * m_width + x0) * m_color_bytes); memcpy(addr_d, addr_s, (width - offset) * m_color_bytes); //Right surface - addr_s = ((char*)(s1->m_fb) + (y * (s1->get_width()) + x0) * m_color_bytes); + addr_s = ((char*)(s1->m_fb) + (y * surface_width + x0) * m_color_bytes); addr_d = ((char*)(m_phy_fb)+(y * m_width + x0 + (width - offset)) * m_color_bytes); memcpy(addr_d, addr_s, offset * m_color_bytes); } } - else if (m_color_bytes == 4) + else if (m_color_bytes == 2) { - void(*draw_pixel)(int x, int y, unsigned int rgb) = ((c_surface_no_fb*)s0)->m_gfx_op->draw_pixel; + void(*draw_pixel)(int x, int y, unsigned int rgb) = m_driver->draw_pixel; for (int y = y0; y <= y1; y++) { //Left surface for (int x = x0; x <= (x1 - offset); x++) { - draw_pixel(x, y, ((unsigned int*)s0->m_fb)[y * m_width + x + offset]); + draw_pixel(x, y, GL_RGB_16_to_32(((unsigned short*)s0->m_fb)[y * m_width + x + offset])); } //Right surface for (int x = x1 - offset; x <= x1; x++) { - draw_pixel(x, y, ((unsigned int*)s1->m_fb)[y * m_width + x + offset - x1 + x0]); + draw_pixel(x, y, GL_RGB_16_to_32(((unsigned short*)s1->m_fb)[y * m_width + x + offset - x1 + x0])); } } } - else if (m_color_bytes == 2) + else //m_color_bytes == 3/4... { - void(*draw_pixel)(int x, int y, unsigned int rgb) = ((c_surface_no_fb*)s0)->m_gfx_op->draw_pixel; + void(*draw_pixel)(int x, int y, unsigned int rgb) = m_driver->draw_pixel; for (int y = y0; y <= y1; y++) { //Left surface for (int x = x0; x <= (x1 - offset); x++) { - draw_pixel(x, y, GL_RGB_16_to_32(((unsigned short*)s0->m_fb)[y * m_width + x + offset])); + draw_pixel(x, y, ((unsigned int*)s0->m_fb)[y * m_width + x + offset]); } //Right surface for (int x = x1 - offset; x <= x1; x++) { - draw_pixel(x, y, GL_RGB_16_to_32(((unsigned short*)s1->m_fb)[y * m_width + x + offset - x1 + x0])); + draw_pixel(x, y, ((unsigned int*)s1->m_fb)[y * m_width + x + offset - x1 + x0]); } } } @@ -3407,22 +3371,12 @@ private: #ifdef GUILITE_ON c_bitmap_operator the_bitmap_op = c_bitmap_operator(); c_image_operator* c_image::image_operator = &the_bitmap_op; +const void* c_theme::s_font_map[FONT_MAX]; +const void* c_theme::s_image_map[IMAGE_MAX]; +unsigned int c_theme::s_color_map[COLOR_MAX]; +c_lattice_font_op the_lattice_font_op = c_lattice_font_op(); +c_font_operator* c_word::fontOperator = &the_lattice_font_op; #endif - -#ifdef GUILITE_ON - -const void* c_theme::s_font_map[FONT_MAX]; -const void* c_theme::s_image_map[IMAGE_MAX]; -unsigned int c_theme::s_color_map[COLOR_MAX]; - -#endif - -#ifdef GUILITE_ON - -c_lattice_font_op the_lattice_font_op = c_lattice_font_op(); -c_font_operator* c_word::fontOperator = &the_lattice_font_op; - -#endif #ifdef GUILITE_ON #if (defined __linux__) || (defined __APPLE__) #include @@ -4264,11 +4218,7 @@ int c_fifo::write(void* buf, int len) #endif #ifdef GUILITE_ON DIALOG_ARRAY c_dialog::ms_the_dialogs[SURFACE_CNT_MAX]; -#endif -#ifdef GUILITE_ON c_keyboard c_edit::s_keyboard; -#endif -#ifdef GUILITE_ON static c_keyboard_button s_key_0, s_key_1, s_key_2, s_key_3, s_key_4, s_key_5, s_key_6, s_key_7, s_key_8, s_key_9; static c_keyboard_button s_key_A, s_key_B, s_key_C, s_key_D, s_key_E, s_key_F, s_key_G, s_key_H, s_key_I, s_key_J; static c_keyboard_button s_key_K, s_key_L, s_key_M, s_key_N, s_key_O, s_key_P, s_key_Q, s_key_R, s_key_S, s_key_T; @@ -4306,12 +4256,12 @@ WND_TREE g_key_board_children[] = {&s_key_B, 'B', 0, ((KEY_WIDTH / 2) + POS_X(5)), POS_Y(2), KEY_WIDTH, KEY_HEIGHT}, {&s_key_N, 'N', 0, ((KEY_WIDTH / 2) + POS_X(6)), POS_Y(2), KEY_WIDTH, KEY_HEIGHT}, {&s_key_M, 'M', 0, ((KEY_WIDTH / 2) + POS_X(7)), POS_Y(2), KEY_WIDTH, KEY_HEIGHT}, - {&s_key_del, 0x7F, 0, ((KEY_WIDTH / 2) + POS_X(8)), POS_Y(2), DEL_WIDTH, KEY_HEIGHT}, + {&s_key_del,0x7F, 0, ((KEY_WIDTH / 2) + POS_X(8)), POS_Y(2), DEL_WIDTH, KEY_HEIGHT}, //Row 4 - {&s_key_esc, 0x1B, 0, POS_X(0), POS_Y(3), ESC_WIDTH, KEY_HEIGHT}, + {&s_key_esc, 0x1B, 0, POS_X(0), POS_Y(3), ESC_WIDTH, KEY_HEIGHT}, {&s_key_num_switch, 0x90, 0, POS_X(2), POS_Y(3), SWITCH_WIDTH, KEY_HEIGHT}, {&s_key_space, ' ', 0, ((KEY_WIDTH / 2) + POS_X(3)), POS_Y(3), SPACE_WIDTH, KEY_HEIGHT}, - {&s_key_dot, '.', 0, ((KEY_WIDTH / 2) + POS_X(6)), POS_Y(3), DOT_WIDTH, KEY_HEIGHT}, + {&s_key_dot, '.', 0, ((KEY_WIDTH / 2) + POS_X(6)), POS_Y(3), DOT_WIDTH, KEY_HEIGHT}, {&s_key_enter, '\n', 0, POS_X(8), POS_Y(3), ENTER_WIDTH, KEY_HEIGHT}, {0,0,0,0,0,0,0} }; @@ -4326,12 +4276,11 @@ WND_TREE g_number_board_children[] = {&s_key_7, '7', 0, POS_X(0), POS_Y(2), KEY_WIDTH, KEY_HEIGHT}, {&s_key_8, '8', 0, POS_X(1), POS_Y(2), KEY_WIDTH, KEY_HEIGHT}, {&s_key_9, '9', 0, POS_X(2), POS_Y(2), KEY_WIDTH, KEY_HEIGHT}, - - {&s_key_esc, 0x1B, 0, POS_X(0), POS_Y(3), KEY_WIDTH, KEY_HEIGHT}, + {&s_key_esc,0x1B, 0, POS_X(0), POS_Y(3), KEY_WIDTH, KEY_HEIGHT}, {&s_key_0, '0', 0, POS_X(1), POS_Y(3), KEY_WIDTH, KEY_HEIGHT}, - {&s_key_dot, '.', 0, POS_X(2), POS_Y(3), KEY_WIDTH, KEY_HEIGHT}, + {&s_key_dot,'.', 0, POS_X(2), POS_Y(3), KEY_WIDTH, KEY_HEIGHT}, {&s_key_del, 0x7F, 0, POS_X(3), POS_Y(0), KEY_WIDTH, KEY_HEIGHT * 2 + 2}, {&s_key_enter,'\n', 0, POS_X(3), POS_Y(2), KEY_WIDTH, KEY_HEIGHT * 2 + 2}, {0,0,0,0,0,0,0} }; -#endif +#endif \ No newline at end of file diff --git a/Hello3D/UIcode/UIcode.cpp b/Hello3D/UIcode/UIcode.cpp index 85ac833217def029b69d7f81c97856ca75ae0df2..e383ce07a8be683e03e55f08ccff37db71aff492 100644 --- a/Hello3D/UIcode/UIcode.cpp +++ b/Hello3D/UIcode/UIcode.cpp @@ -164,21 +164,12 @@ double Pyramid::points[5][3] = { }; // Demo -void create_ui(void* phy_fb, int screen_width, int screen_height, int color_bytes, struct EXTERNAL_GFX_OP* gfx_op) { - if (phy_fb) - { - static c_surface surface(UI_WIDTH, UI_HEIGHT, color_bytes, Z_ORDER_LEVEL_0); - static c_display display(phy_fb, screen_width, screen_height, &surface); - s_surface = &surface; - s_display = &display; - } - else - {//for MCU without framebuffer - static c_surface_no_fb surface_no_fb(UI_WIDTH, UI_HEIGHT, color_bytes, gfx_op, Z_ORDER_LEVEL_0); - static c_display display(phy_fb, screen_width, screen_height, &surface_no_fb); - s_surface = &surface_no_fb; - s_display = &display; - } +void create_ui(void* phy_fb, int screen_width, int screen_height, int color_bytes, struct DISPLAY_DRIVER* driver) { + static c_surface surface(UI_WIDTH, UI_HEIGHT, color_bytes, Z_ORDER_LEVEL_0); + static c_display display(phy_fb, screen_width, screen_height, &surface, driver); + s_surface = &surface; + s_display = &display; + s_surface->fill_rect(0, 0, UI_WIDTH - 1, UI_HEIGHT - 1, 0, Z_ORDER_LEVEL_0); Cube theCube; Pyramid thePyramid; @@ -195,8 +186,8 @@ void create_ui(void* phy_fb, int screen_width, int screen_height, int color_byte } //////////////////////// interface for all platform //////////////////////// -extern "C" void startHello3D(void* phy_fb, int width, int height, int color_bytes, struct EXTERNAL_GFX_OP* gfx_op) { - create_ui(phy_fb, width, height, color_bytes, gfx_op); +extern "C" void startHello3D(void* phy_fb, int width, int height, int color_bytes, struct DISPLAY_DRIVER* driver) { + create_ui(phy_fb, width, height, color_bytes, driver); } extern "C" void* getUiOfHello3D(int* width, int* height, bool force_update) diff --git a/Hello3Ddonut/BuildLinux/.sync_build.sh b/Hello3Ddonut/BuildLinux/.sync_build.sh index 49cff5b473ac606967676ebefa6f0d333e301227..0c45b253768971c4ecf62540c57d913faef13096 100644 --- a/Hello3Ddonut/BuildLinux/.sync_build.sh +++ b/Hello3Ddonut/BuildLinux/.sync_build.sh @@ -1,5 +1,6 @@ if [ "$#" -ne 1 ]; then - echo "Invalid arguments" + echo "Do testing" + ./xWindow 240 320 | ./Hello3Ddonut shared-fb exit -1 fi diff --git a/Hello3Ddonut/BuildLinux/main.cpp b/Hello3Ddonut/BuildLinux/main.cpp index b3c3da2ae631a8ed12e32236312c216da56fd33e..98b93e61d1c0b2c005ad516e6590169bbb9fe62b 100644 --- a/Hello3Ddonut/BuildLinux/main.cpp +++ b/Hello3Ddonut/BuildLinux/main.cpp @@ -10,7 +10,7 @@ #include #include -extern "C" void startHello3Ddonut(void* phy_fb, int width, int height, int color_bytes, struct EXTERNAL_GFX_OP* gfx_op); +extern "C" void startHello3Ddonut(void* phy_fb, int width, int height, int color_bytes, struct DISPLAY_DRIVER* driver); extern void init_std_io(); static void* get_embeded_fb_in_display_app(int shared_id); diff --git a/Hello3Ddonut/BuildMFC/Hello3DdonutDlg.cpp b/Hello3Ddonut/BuildMFC/Hello3DdonutDlg.cpp index 35142e5ddc64dc717a28fa6ed67eda50a7f4c0a2..7b3edf28c4cee091fb69a5a57084e02f9a5432af 100644 Binary files a/Hello3Ddonut/BuildMFC/Hello3DdonutDlg.cpp and b/Hello3Ddonut/BuildMFC/Hello3DdonutDlg.cpp differ diff --git a/Hello3Ddonut/BuildMFC/Hello3DdonutDlg.h b/Hello3Ddonut/BuildMFC/Hello3DdonutDlg.h index 61c1ce12cd9b173bc35bf7db6683e76944d819fa..11ab911df689ef994d98902066266b1c81a68ebf 100644 Binary files a/Hello3Ddonut/BuildMFC/Hello3DdonutDlg.h and b/Hello3Ddonut/BuildMFC/Hello3DdonutDlg.h differ diff --git a/Hello3Ddonut/BuildSTM32F103-Keil/USER/main.c b/Hello3Ddonut/BuildSTM32F103-Keil/USER/main.c index 3c5b564cf72955dfc1238af0d5843df30d274678..f0eb4f3b4eecf439a22af4c4de157612b4e99712 100644 --- a/Hello3Ddonut/BuildSTM32F103-Keil/USER/main.c +++ b/Hello3Ddonut/BuildSTM32F103-Keil/USER/main.c @@ -15,12 +15,12 @@ void gfx_draw_pixel(int x, int y, unsigned int rgb) //void gfx_fill_rect(int x0, int y0, int x1, int y1, unsigned int rgb){} //UI entry -struct EXTERNAL_GFX_OP +struct DISPLAY_DRIVER { void (*draw_pixel)(int x, int y, unsigned int rgb); void (*fill_rect)(int x0, int y0, int x1, int y1, unsigned int rgb); -} my_gfx_op; -extern void startHello3Ddonut(void* phy_fb, int width, int height, int color_bytes, struct EXTERNAL_GFX_OP* gfx_op); +} my_driver; +extern void startHello3Ddonut(void* phy_fb, int width, int height, int color_bytes, struct DISPLAY_DRIVER* driver); int main(void) { @@ -30,8 +30,8 @@ int main(void) LCD_Init(); //Link your LCD driver & start UI: - my_gfx_op.draw_pixel = gfx_draw_pixel; - my_gfx_op.fill_rect = NULL;//gfx_fill_rect; - startHello3Ddonut(NULL, 240, 320, 2, &my_gfx_op); + my_driver.draw_pixel = gfx_draw_pixel; + my_driver.fill_rect = NULL;//gfx_fill_rect; + startHello3Ddonut(NULL, 240, 320, 2, &my_driver); while(1); } diff --git a/Hello3Ddonut/BuildWin32/Hello3Ddonut.cpp b/Hello3Ddonut/BuildWin32/Hello3Ddonut.cpp index 7e19f14b007d2d796b5e3ce8c97e74b65c5f5226..d1ac28fc90b5e104f0c3f32e518e2a8e1ef16335 100644 --- a/Hello3Ddonut/BuildWin32/Hello3Ddonut.cpp +++ b/Hello3Ddonut/BuildWin32/Hello3Ddonut.cpp @@ -161,7 +161,7 @@ LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam) } //////////////////////// Hello3Ddonut Interface //////////////////////// -extern "C" void startHello3Ddonut(void* phy_fb, int width, int height, int color_bytes, struct EXTERNAL_GFX_OP* gfx_op); +extern "C" void startHello3Ddonut(void* phy_fb, int width, int height, int color_bytes, struct DISPLAY_DRIVER* driver); DWORD WINAPI ThreadHello3Ddonut(LPVOID pParam) { diff --git a/Hello3Ddonut/UIcode/GuiLite.h b/Hello3Ddonut/UIcode/GuiLite.h index c4fc88a51476d2c8309c3e55e1270e13784fc510..80550e1632ad7bc82541a2edbb0f7f8f5937954f 100644 --- a/Hello3Ddonut/UIcode/GuiLite.h +++ b/Hello3Ddonut/UIcode/GuiLite.h @@ -1,107 +1,94 @@ #pragma once - -#define REAL_TIME_TASK_CYCLE_MS 50 -#define MAX(a,b) (((a)>(b))?(a):(b)) -#define MIN(a,b) (((a)<(b))?(a):(b)) - -#define GL_ARGB(a, r, g, b) ((((unsigned int)(a)) << 24) | (((unsigned int)(r)) << 16) | (((unsigned int)(g)) << 8) | ((unsigned int)(b))) -#define GL_ARGB_A(rgb) ((((unsigned int)(rgb)) >> 24) & 0xFF) - -#define GL_RGB(r, g, b) ((0xFF << 24) | (((unsigned int)(r)) << 16) | (((unsigned int)(g)) << 8) | ((unsigned int)(b))) -#define GL_RGB_R(rgb) ((((unsigned int)(rgb)) >> 16) & 0xFF) -#define GL_RGB_G(rgb) ((((unsigned int)(rgb)) >> 8) & 0xFF) -#define GL_RGB_B(rgb) (((unsigned int)(rgb)) & 0xFF) -#define GL_RGB_32_to_16(rgb) (((((unsigned int)(rgb)) & 0xFF) >> 3) | ((((unsigned int)(rgb)) & 0xFC00) >> 5) | ((((unsigned int)(rgb)) & 0xF80000) >> 8)) -#define GL_RGB_16_to_32(rgb) ((0xFF << 24) | ((((unsigned int)(rgb)) & 0x1F) << 3) | ((((unsigned int)(rgb)) & 0x7E0) << 5) | ((((unsigned int)(rgb)) & 0xF800) << 8)) - -#define ALIGN_HCENTER 0x00000000L -#define ALIGN_LEFT 0x01000000L -#define ALIGN_RIGHT 0x02000000L -#define ALIGN_HMASK 0x03000000L - -#define ALIGN_VCENTER 0x00000000L -#define ALIGN_TOP 0x00100000L -#define ALIGN_BOTTOM 0x00200000L -#define ALIGN_VMASK 0x00300000L - -typedef struct -{ - unsigned short year; - unsigned short month; - unsigned short date; - unsigned short day; - unsigned short hour; - unsigned short minute; - unsigned short second; -}T_TIME; - -void register_debug_function(void(*my_assert)(const char* file, int line), void(*my_log_out)(const char* log)); -void _assert(const char* file, int line); -#define ASSERT(condition) \ - do{ \ - if(!(condition))_assert(__FILE__, __LINE__);\ - }while(0) -void log_out(const char* log); - -long get_time_in_second(); -T_TIME second_to_day(long second); -T_TIME get_time(); - -void start_real_timer(void (*func)(void* arg)); -void register_timer(int milli_second, void func(void* param), void* param); - -unsigned int get_cur_thread_id(); -void create_thread(unsigned long* thread_id, void* attr, void *(*start_routine) (void *), void* arg); -void thread_sleep(unsigned int milli_seconds); -int build_bmp(const char *filename, unsigned int width, unsigned int height, unsigned char *data); - -#define FIFO_BUFFER_LEN 1024 -class c_fifo -{ -public: - c_fifo(); - int read(void* buf, int len); - int write(void* buf, int len); -private: - unsigned char m_buf[FIFO_BUFFER_LEN]; - int m_head; - int m_tail; - void* m_read_sem; - void* m_write_mutex; -}; - -class c_rect -{ -public: - c_rect(){ m_left = m_top = m_right = m_bottom = -1; } - c_rect(int left, int top, int width, int height) - { - set_rect(left, top, width, height); - } - void set_rect(int left, int top, int width, int height) - { - ASSERT(width > 0 && height > 0); - m_left = left; - m_top = top; - m_right = left + width - 1; - m_bottom = top + height -1; - } - bool pt_in_rect(int x, int y) const - { - return x >= m_left && x <= m_right && y >= m_top && y <= m_bottom; - } - int operator==(const c_rect& rect) const - { - return (m_left == rect.m_left) && (m_top == rect.m_top) && (m_right == rect.m_right) && (m_bottom == rect.m_bottom); - } - int width() const { return m_right - m_left + 1; } - int height() const { return m_bottom - m_top + 1 ; } - - int m_left; - int m_top; - int m_right; - int m_bottom; -}; +#define REAL_TIME_TASK_CYCLE_MS 50 +#define MAX(a,b) (((a)>(b))?(a):(b)) +#define MIN(a,b) (((a)<(b))?(a):(b)) +#define GL_ARGB(a, r, g, b) ((((unsigned int)(a)) << 24) | (((unsigned int)(r)) << 16) | (((unsigned int)(g)) << 8) | ((unsigned int)(b))) +#define GL_ARGB_A(rgb) ((((unsigned int)(rgb)) >> 24) & 0xFF) +#define GL_RGB(r, g, b) ((0xFF << 24) | (((unsigned int)(r)) << 16) | (((unsigned int)(g)) << 8) | ((unsigned int)(b))) +#define GL_RGB_R(rgb) ((((unsigned int)(rgb)) >> 16) & 0xFF) +#define GL_RGB_G(rgb) ((((unsigned int)(rgb)) >> 8) & 0xFF) +#define GL_RGB_B(rgb) (((unsigned int)(rgb)) & 0xFF) +#define GL_RGB_32_to_16(rgb) (((((unsigned int)(rgb)) & 0xFF) >> 3) | ((((unsigned int)(rgb)) & 0xFC00) >> 5) | ((((unsigned int)(rgb)) & 0xF80000) >> 8)) +#define GL_RGB_16_to_32(rgb) ((0xFF << 24) | ((((unsigned int)(rgb)) & 0x1F) << 3) | ((((unsigned int)(rgb)) & 0x7E0) << 5) | ((((unsigned int)(rgb)) & 0xF800) << 8)) +#define ALIGN_HCENTER 0x00000000L +#define ALIGN_LEFT 0x01000000L +#define ALIGN_RIGHT 0x02000000L +#define ALIGN_HMASK 0x03000000L +#define ALIGN_VCENTER 0x00000000L +#define ALIGN_TOP 0x00100000L +#define ALIGN_BOTTOM 0x00200000L +#define ALIGN_VMASK 0x00300000L +typedef struct +{ + unsigned short year; + unsigned short month; + unsigned short date; + unsigned short day; + unsigned short hour; + unsigned short minute; + unsigned short second; +}T_TIME; +void register_debug_function(void(*my_assert)(const char* file, int line), void(*my_log_out)(const char* log)); +void _assert(const char* file, int line); +#define ASSERT(condition) \ + do{ \ + if(!(condition))_assert(__FILE__, __LINE__);\ + }while(0) +void log_out(const char* log); +long get_time_in_second(); +T_TIME second_to_day(long second); +T_TIME get_time(); +void start_real_timer(void (*func)(void* arg)); +void register_timer(int milli_second, void func(void* param), void* param); +unsigned int get_cur_thread_id(); +void create_thread(unsigned long* thread_id, void* attr, void *(*start_routine) (void *), void* arg); +void thread_sleep(unsigned int milli_seconds); +int build_bmp(const char *filename, unsigned int width, unsigned int height, unsigned char *data); +#define FIFO_BUFFER_LEN 1024 +class c_fifo +{ +public: + c_fifo(); + int read(void* buf, int len); + int write(void* buf, int len); +private: + unsigned char m_buf[FIFO_BUFFER_LEN]; + int m_head; + int m_tail; + void* m_read_sem; + void* m_write_mutex; +}; +class c_rect +{ +public: + c_rect(){ m_left = m_top = m_right = m_bottom = -1; } + c_rect(int left, int top, int width, int height) + { + set_rect(left, top, width, height); + } + void set_rect(int left, int top, int width, int height) + { + ASSERT(width > 0 && height > 0); + m_left = left; + m_top = top; + m_right = left + width - 1; + m_bottom = top + height -1; + } + bool pt_in_rect(int x, int y) const + { + return x >= m_left && x <= m_right && y >= m_top && y <= m_bottom; + } + int operator==(const c_rect& rect) const + { + return (m_left == rect.m_left) && (m_top == rect.m_top) && (m_right == rect.m_right) && (m_bottom == rect.m_bottom); + } + int width() const { return m_right - m_left + 1; } + int height() const { return m_bottom - m_top + 1 ; } + int m_left; + int m_top; + int m_right; + int m_bottom; +}; //BITMAP typedef struct struct_bitmap_info { @@ -238,7 +225,7 @@ typedef enum Z_ORDER_LEVEL_2,//highest graphic level Z_ORDER_LEVEL_MAX }Z_ORDER_LEVEL; -struct EXTERNAL_GFX_OP +struct DISPLAY_DRIVER { void(*draw_pixel)(int x, int y, unsigned int rgb); void(*fill_rect)(int x0, int y0, int x1, int y1, unsigned int rgb); @@ -247,18 +234,19 @@ class c_surface; class c_display { friend class c_surface; public: - inline c_display(void* phy_fb, int display_width, int display_height, int surface_width, int surface_height, unsigned int color_bytes, int surface_cnt, EXTERNAL_GFX_OP* gfx_op = 0);//multiple surface or surface_no_fb - inline c_display(void* phy_fb, int display_width, int display_height, c_surface* surface);//single custom surface - inline c_surface* alloc_surface(Z_ORDER_LEVEL max_zorder, c_rect layer_rect = c_rect());//for multiple surfaces + inline c_display(void* phy_fb, int display_width, int display_height, c_surface* surface, DISPLAY_DRIVER* driver = 0);//single custom surface + inline c_display(void* phy_fb, int display_width, int display_height, int surface_width, int surface_height, unsigned int color_bytes, int surface_cnt, DISPLAY_DRIVER* driver = 0);//multiple surface + inline c_surface* alloc_surface(Z_ORDER_LEVEL max_zorder, c_rect layer_rect = c_rect());//for slide group inline int swipe_surface(c_surface* s0, c_surface* s1, int x0, int x1, int y0, int y1, int offset); int get_width() { return m_width; } int get_height() { return m_height; } + void* get_phy_fb() { return m_phy_fb; } void* get_updated_fb(int* width, int* height, bool force_update = false) { if (width && height) { - *width = get_width(); - *height = get_height(); + *width = m_width; + *height = m_height; } if (force_update) { @@ -277,35 +265,123 @@ public: { return -1; } - int width = get_width(); - int height = get_height(); //16 bits framebuffer if (m_color_bytes == 2) { - return build_bmp(file_name, width, height, (unsigned char*)m_phy_fb); + return build_bmp(file_name, m_width, m_height, (unsigned char*)m_phy_fb); } //32 bits framebuffer - unsigned short* p_bmp565_data = new unsigned short[width * height]; + unsigned short* p_bmp565_data = new unsigned short[m_width * m_height]; unsigned int* p_raw_data = (unsigned int*)m_phy_fb; - for (int i = 0; i < width * height; i++) + for (int i = 0; i < m_width * m_height; i++) { unsigned int rgb = *p_raw_data++; p_bmp565_data[i] = GL_RGB_32_to_16(rgb); } - int ret = build_bmp(file_name, width, height, (unsigned char*)p_bmp565_data); + int ret = build_bmp(file_name, m_width, m_height, (unsigned char*)p_bmp565_data); delete[]p_bmp565_data; return ret; } -private: - int m_width; //in pixels - int m_height; //in pixels - int m_color_bytes; //16 bits, 32 bits only - void* m_phy_fb; //physical framebuffer +protected: + virtual void draw_pixel(int x, int y, unsigned int rgb) + { + if ((x >= m_width) || (y >= m_height)) { return; } + if (m_driver && m_driver->draw_pixel) + { + return m_driver->draw_pixel(x, y, rgb); + } + if (m_color_bytes == 2) + { + ((unsigned short*)m_phy_fb)[y * m_width + x] = GL_RGB_32_to_16(rgb); + } + else + { + ((unsigned int*)m_phy_fb)[y * m_width + x] = rgb; + } + } + virtual void fill_rect(int x0, int y0, int x1, int y1, unsigned int rgb) + { + if (m_driver && m_driver->fill_rect) + { + return m_driver->fill_rect(x0, y0, x1, y1, rgb); + } + if (m_driver && m_driver->draw_pixel) + { + for (int y = y0; y <= y1; y++) + { + for (int x = x0; x <= x1; x++) + { + m_driver->draw_pixel(x, y, rgb); + } + } + return; + } + register int _width = m_width; + register int _height = m_height; + int x, y; + if (m_color_bytes == 2) + { + unsigned short* phy_fb; + unsigned int rgb_16 = GL_RGB_32_to_16(rgb); + for (y = y0; y <= y1; y++) + { + phy_fb = &((unsigned short*)m_phy_fb)[y * _width + x0]; + for (x = x0; x <= x1; x++) + { + if ((x < _width) && (y < _height)) + { + *phy_fb++ = rgb_16; + } + } + } + } + else + { + unsigned int* phy_fb; + for (y = y0; y <= y1; y++) + { + phy_fb = &((unsigned int*)m_phy_fb)[y * _width + x0]; + for (x = x0; x <= x1; x++) + { + if ((x < _width) && (y < _height)) + { + *phy_fb++ = rgb; + } + } + } + } + } + virtual int flush_screen(int left, int top, int right, int bottom, void* fb, int fb_width) + { + if ((0 == m_phy_fb) || (0 == fb)) + { + return -1; + } + register int _width = m_width; + register int _height = m_height; + left = (left >= _width) ? (_width - 1) : left; + right = (right >= _width) ? (_width - 1) : right; + top = (top >= _height) ? (_height - 1) : top; + bottom = (bottom >= _height) ? (_height - 1) : bottom; + for (int y = top; y < bottom; y++) + { + void* s_addr = (char*)fb + ((y * fb_width + left) * m_color_bytes); + void* d_addr = (char*)m_phy_fb + ((y * _width + left) * m_color_bytes); + memcpy(d_addr, s_addr, (right - left) * m_color_bytes); + } + return 0; + } + int m_width; //in pixels + int m_height; //in pixels + int m_color_bytes; //16/32 bits for default + void* m_phy_fb; //physical framebuffer for default + struct DISPLAY_DRIVER* m_driver; //Rendering by external method without default physical framebuffer int m_phy_read_index; int m_phy_write_index; c_surface* m_surface_group[SURFACE_CNT_MAX]; int m_surface_cnt; //surface count int m_surface_index; + }; class c_layer { @@ -317,12 +393,10 @@ public: class c_surface { friend class c_display; friend class c_bitmap_operator; public: - c_surface(unsigned int width, unsigned int height, unsigned int color_bytes, Z_ORDER_LEVEL max_zorder = Z_ORDER_LEVEL_0, c_rect overlpa_rect = c_rect()) : m_width(width), m_height(height), m_color_bytes(color_bytes), m_fb(0), m_is_active(false), m_top_zorder(Z_ORDER_LEVEL_0), m_phy_fb(0), m_phy_write_index(0), m_display(0) + c_surface(unsigned int width, unsigned int height, unsigned int color_bytes, Z_ORDER_LEVEL max_zorder = Z_ORDER_LEVEL_0, c_rect overlpa_rect = c_rect()) : m_width(width), m_height(height), m_color_bytes(color_bytes), m_fb(0), m_is_active(false), m_top_zorder(Z_ORDER_LEVEL_0), m_phy_write_index(0), m_display(0) { (overlpa_rect == c_rect()) ? set_surface(max_zorder, c_rect(0, 0, width - 1, height - 1)) : set_surface(max_zorder, overlpa_rect); } - int get_width() { return m_width; } - int get_height() { return m_height; } unsigned int get_pixel(int x, int y, unsigned int z_order) { if (x >= m_width || y >= m_height || x < 0 || y < 0 || z_order >= Z_ORDER_LEVEL_MAX) @@ -332,15 +406,15 @@ public: } if (m_layers[z_order].fb) { - return (m_color_bytes == 4) ? ((unsigned int*)(m_layers[z_order].fb))[y * m_width + x] : GL_RGB_16_to_32(((unsigned short*)(m_layers[z_order].fb))[y * m_width + x]); + return (m_color_bytes == 2) ? GL_RGB_16_to_32(((unsigned short*)(m_layers[z_order].fb))[y * m_width + x]) : ((unsigned int*)(m_layers[z_order].fb))[y * m_width + x]; } else if (m_fb) { - return (m_color_bytes == 4) ? ((unsigned int*)m_fb)[y * m_width + x] : GL_RGB_16_to_32(((unsigned short*)m_fb)[y * m_width + x]); + return (m_color_bytes == 2) ? GL_RGB_16_to_32(((unsigned short*)m_fb)[y * m_width + x]) : ((unsigned int*)m_fb)[y * m_width + x]; } - else if (m_phy_fb) + else if (m_display->m_phy_fb) { - return (m_color_bytes == 4) ? ((unsigned int*)m_phy_fb)[y * m_width + x] : GL_RGB_16_to_32(((unsigned short*)m_phy_fb)[y * m_width + x]); + return (m_color_bytes == 2) ? GL_RGB_16_to_32(((unsigned short*)m_display->m_phy_fb)[y * m_width + x]) : ((unsigned int*)m_display->m_phy_fb)[y * m_width + x]; } return 0; } @@ -357,7 +431,7 @@ public: } if (z_order == m_max_zorder) { - return draw_pixel_on_fb(x, y, rgb); + return draw_pixel_low_level(x, y, rgb); } if (z_order > (unsigned int)m_top_zorder) @@ -367,19 +441,19 @@ public: if (m_layers[z_order].rect.pt_in_rect(x, y)) { c_rect layer_rect = m_layers[z_order].rect; - if (m_color_bytes == 4) + if (m_color_bytes == 2) { - ((unsigned int*)(m_layers[z_order].fb))[(x - layer_rect.m_left) + (y - layer_rect.m_top) * layer_rect.width()] = rgb; + ((unsigned short*)(m_layers[z_order].fb))[(x - layer_rect.m_left) + (y - layer_rect.m_top) * layer_rect.width()] = GL_RGB_32_to_16(rgb); } else { - ((unsigned short*)(m_layers[z_order].fb))[(x - layer_rect.m_left) + (y - layer_rect.m_top) * layer_rect.width()] = GL_RGB_32_to_16(rgb); + ((unsigned int*)(m_layers[z_order].fb))[(x - layer_rect.m_left) + (y - layer_rect.m_top) * layer_rect.width()] = rgb; } } if (z_order == m_top_zorder) { - return draw_pixel_on_fb(x, y, rgb); + return draw_pixel_low_level(x, y, rgb); } bool be_overlapped = false; for (unsigned int tmp_z_order = Z_ORDER_LEVEL_MAX - 1; tmp_z_order > z_order; tmp_z_order--) @@ -392,7 +466,7 @@ public: } if (!be_overlapped) { - draw_pixel_on_fb(x, y, rgb); + draw_pixel_low_level(x, y, rgb); } } virtual void fill_rect(int x0, int y0, int x1, int y1, unsigned int rgb, unsigned int z_order) @@ -403,7 +477,7 @@ public: y1 = (y1 > (m_height - 1)) ? (m_height - 1) : y1; if (z_order == m_max_zorder) { - return fill_rect_on_fb(x0, y0, x1, y1, rgb); + return fill_rect_low_level(x0, y0, x1, y1, rgb); } if (z_order == m_top_zorder) { @@ -416,18 +490,18 @@ public: { if (layer_rect.pt_in_rect(x, y)) { - if (m_color_bytes == 4) + if (m_color_bytes == 2) { - ((unsigned int*)m_layers[z_order].fb)[(y - layer_rect.m_top) * layer_rect.width() + (x - layer_rect.m_left)] = rgb; + ((unsigned short*)m_layers[z_order].fb)[(y - layer_rect.m_top) * layer_rect.width() + (x - layer_rect.m_left)] = rgb_16; } else { - ((unsigned short*)m_layers[z_order].fb)[(y - layer_rect.m_top) * layer_rect.width() + (x - layer_rect.m_left)] = rgb_16; + ((unsigned int*)m_layers[z_order].fb)[(y - layer_rect.m_top) * layer_rect.width() + (x - layer_rect.m_left)] = rgb; } } } } - return fill_rect_on_fb(x0, y0, x1, y1, rgb); + return fill_rect_low_level(x0, y0, x1, y1, rgb); } for (; y0 <= y1; y0++) { @@ -499,27 +573,16 @@ public: } int flush_screen(int left, int top, int right, int bottom) { - if (left < 0 || left >= m_width || right < 0 || right >= m_width || - top < 0 || top >= m_height || bottom < 0 || bottom >= m_height) - { - ASSERT(false); - } - if (!m_is_active || (0 == m_phy_fb) || (0 == m_fb)) + if (!m_is_active) { return -1; } - int display_width = m_display->get_width(); - int display_height = m_display->get_height(); - left = (left >= display_width) ? (display_width - 1) : left; - right = (right >= display_width) ? (display_width - 1) : right; - top = (top >= display_height) ? (display_height - 1) : top; - bottom = (bottom >= display_height) ? (display_height - 1) : bottom; - for (int y = top; y < bottom; y++) + if (left < 0 || left >= m_width || right < 0 || right >= m_width || + top < 0 || top >= m_height || bottom < 0 || bottom >= m_height) { - void* s_addr = (char*)m_fb + ((y * m_width + left) * m_color_bytes); - void* d_addr = (char*)m_phy_fb + ((y * display_width + left) * m_color_bytes); - memcpy(d_addr, s_addr, (right - left) * m_color_bytes); + ASSERT(false); } + m_display->flush_screen(left, top, right, bottom, m_fb, m_width); *m_phy_write_index = *m_phy_write_index + 1; return 0; } @@ -537,90 +600,62 @@ public: { for (int x = rect.m_left; x <= rect.m_right; x++) { - unsigned int rgb = (m_color_bytes == 4) ? ((unsigned int*)fb)[(x - layer_rect.m_left) + (y - layer_rect.m_top) * width] : GL_RGB_16_to_32(((unsigned short*)fb)[(x - layer_rect.m_left) + (y - layer_rect.m_top) * width]); - draw_pixel_on_fb(x, y, rgb); + unsigned int rgb = (m_color_bytes == 2) ? GL_RGB_16_to_32(((unsigned short*)fb)[(x - layer_rect.m_left) + (y - layer_rect.m_top) * width]) : ((unsigned int*)fb)[(x - layer_rect.m_left) + (y - layer_rect.m_top) * width]; + draw_pixel_low_level(x, y, rgb); } } return 0; } void set_active(bool flag) { m_is_active = flag; } protected: - virtual void fill_rect_on_fb(int x0, int y0, int x1, int y1, unsigned int rgb) - { - int display_width = m_display->get_width(); - int display_height = m_display->get_height(); - if (m_color_bytes == 4) + virtual void fill_rect_low_level(int x0, int y0, int x1, int y1, unsigned int rgb) + {//fill rect on framebuffer of surface + int x, y; + if (m_color_bytes == 2) { - int x; - unsigned int* fb, * phy_fb; - for (; y0 <= y1; y0++) + unsigned short* fb; + unsigned int rgb_16 = GL_RGB_32_to_16(rgb); + for (y = y0; y <= y1; y++) { - x = x0; - fb = m_fb ? &((unsigned int*)m_fb)[y0 * m_width + x] : 0; - phy_fb = &((unsigned int*)m_phy_fb)[y0 * display_width + x]; - *m_phy_write_index = *m_phy_write_index + 1; - for (; x <= x1; x++) + fb = m_fb ? &((unsigned short*)m_fb)[y * m_width + x0] : 0; + if (!fb) { break; } + for (x = x0; x <= x1; x++) { - if (fb) - { - *fb++ = rgb; - } - if (m_is_active && (x < display_width) && (y0 < display_height)) - { - *phy_fb++ = rgb; - } + *fb++ = rgb_16; } } } - else if (m_color_bytes == 2) + else { - int x; - unsigned short* fb, * phy_fb; - rgb = GL_RGB_32_to_16(rgb); - for (; y0 <= y1; y0++) + unsigned int* fb; + for (y = y0; y <= y1; y++) { - x = x0; - fb = m_fb ? &((unsigned short*)m_fb)[y0 * m_width + x] : 0; - phy_fb = &((unsigned short*)m_phy_fb)[y0 * display_width + x]; - *m_phy_write_index = *m_phy_write_index + 1; - for (; x <= x1; x++) + fb = m_fb ? &((unsigned int*)m_fb)[y * m_width + x0] : 0; + if (!fb) { break; } + for (x = x0; x <= x1; x++) { - if (fb) - { - *fb++ = rgb; - } - if (m_is_active && (x < display_width) && (y0 < display_height)) - { - *phy_fb++ = rgb; - } + *fb++ = rgb; } } } + if (!m_is_active) { return; } + m_display->fill_rect(x0, y0, x1, y1, rgb); + *m_phy_write_index = *m_phy_write_index + 1; } - virtual void draw_pixel_on_fb(int x, int y, unsigned int rgb) + virtual void draw_pixel_low_level(int x, int y, unsigned int rgb) { if (m_fb) - { - (m_color_bytes == 4) ? ((unsigned int*)m_fb)[y * m_width + x] = rgb : ((unsigned short*)m_fb)[y * m_width + x] = GL_RGB_32_to_16(rgb); - } - if (m_is_active && (x < m_display->get_width()) && (y < m_display->get_height())) - { - if (m_color_bytes == 4) - { - ((unsigned int*)m_phy_fb)[y * (m_display->get_width()) + x] = rgb; - } - else - { - ((unsigned short*)m_phy_fb)[y * (m_display->get_width()) + x] = GL_RGB_32_to_16(rgb); - } - *m_phy_write_index = *m_phy_write_index + 1; + {//draw pixel on framebuffer of surface + (m_color_bytes == 2) ? ((unsigned short*)m_fb)[y * m_width + x] = GL_RGB_32_to_16(rgb): ((unsigned int*)m_fb)[y * m_width + x] = rgb; } + if (!m_is_active) { return; } + m_display->draw_pixel(x, y, rgb); + *m_phy_write_index = *m_phy_write_index + 1; } void attach_display(c_display* display) { ASSERT(display); m_display = display; - m_phy_fb = display->m_phy_fb; m_phy_write_index = &display->m_phy_write_index; } void set_surface(Z_ORDER_LEVEL max_z_order, c_rect layer_rect) @@ -638,87 +673,22 @@ protected: } int m_width; //in pixels int m_height; //in pixels - int m_color_bytes; //16 bits, 32 bits only + int m_color_bytes; //16 bits, 32 bits for default void* m_fb; //frame buffer you could see c_layer m_layers[Z_ORDER_LEVEL_MAX];//all graphic layers bool m_is_active; //active flag Z_ORDER_LEVEL m_max_zorder; //the highest graphic layer the surface will have Z_ORDER_LEVEL m_top_zorder; //the current highest graphic layer the surface have - void* m_phy_fb; //physical framebufer int* m_phy_write_index; c_display* m_display; }; -class c_surface_no_fb : public c_surface {//No physical framebuffer, render with external graphic interface - friend class c_display; -public: - c_surface_no_fb(unsigned int width, unsigned int height, unsigned int color_bytes, struct EXTERNAL_GFX_OP* gfx_op, Z_ORDER_LEVEL max_zorder = Z_ORDER_LEVEL_0, c_rect overlpa_rect = c_rect()) : c_surface(width, height, color_bytes, max_zorder, overlpa_rect), m_gfx_op(gfx_op) {} -protected: - virtual void fill_rect_on_fb(int x0, int y0, int x1, int y1, unsigned int rgb) - { - if (!m_gfx_op) - { - return; - } - if (m_gfx_op->fill_rect) - { - return m_gfx_op->fill_rect(x0, y0, x1, y1, rgb); - } - if (m_gfx_op->draw_pixel && m_is_active) - { - for (int y = y0; y <= y1; y++) - { - for (int x = x0; x <= x1; x++) - { - m_gfx_op->draw_pixel(x, y, rgb); - } - } - } - if (!m_fb) { return; } - if (m_color_bytes == 4) - { - unsigned int* fb; - for (int y = y0; y <= y1; y++) - { - fb = &((unsigned int*)m_fb)[y0 * m_width + x0]; - for (int x = x0; x <= x1; x++) - { - *fb++ = rgb; - } - } - } - else if (m_color_bytes == 2) - { - unsigned short* fb; - rgb = GL_RGB_32_to_16(rgb); - for (int y = y0; y <= y1; y++) - { - fb = &((unsigned short*)m_fb)[y0 * m_width + x0]; - for (int x = x0; x <= x1; x++) - { - *fb++ = rgb; - } - } - } - } - virtual void draw_pixel_on_fb(int x, int y, unsigned int rgb) - { - if (m_gfx_op && m_gfx_op->draw_pixel && m_is_active) - { - m_gfx_op->draw_pixel(x, y, rgb); - } - if (!m_fb) { return; } - if (m_color_bytes == 4) - { - ((unsigned int*)m_fb)[y * m_width + x] = rgb; - } - else if (m_color_bytes == 2) - { - ((unsigned short*)m_fb)[y * m_width + x] = GL_RGB_32_to_16(rgb); - } - } - struct EXTERNAL_GFX_OP* m_gfx_op;//Rendering by external method -}; -inline c_display::c_display(void* phy_fb, int display_width, int display_height, int surface_width, int surface_height, unsigned int color_bytes, int surface_cnt, EXTERNAL_GFX_OP* gfx_op) : m_width(display_width), m_height(display_height), m_color_bytes(color_bytes), m_phy_fb(phy_fb), m_phy_read_index(0), m_phy_write_index(0), m_surface_cnt(surface_cnt), m_surface_index(0) +inline c_display::c_display(void* phy_fb, int display_width, int display_height, c_surface* surface, DISPLAY_DRIVER* driver) : m_phy_fb(phy_fb), m_width(display_width), m_height(display_height), m_driver(driver), m_phy_read_index(0), m_phy_write_index(0), m_surface_cnt(1), m_surface_index(0) +{ + m_color_bytes = surface->m_color_bytes; + surface->m_is_active = true; + (m_surface_group[0] = surface)->attach_display(this); +} +inline c_display::c_display(void* phy_fb, int display_width, int display_height, int surface_width, int surface_height, unsigned int color_bytes, int surface_cnt, DISPLAY_DRIVER* driver) : m_phy_fb(phy_fb), m_width(display_width), m_height(display_height), m_color_bytes(color_bytes), m_phy_read_index(0), m_phy_write_index(0), m_surface_cnt(surface_cnt), m_driver(driver), m_surface_index(0) { ASSERT(color_bytes == 2 || color_bytes == 4); ASSERT(m_surface_cnt <= SURFACE_CNT_MAX); @@ -726,16 +696,10 @@ inline c_display::c_display(void* phy_fb, int display_width, int display_height, for (int i = 0; i < m_surface_cnt; i++) { - m_surface_group[i] = (phy_fb) ? new c_surface(surface_width, surface_height, color_bytes) : new c_surface_no_fb(surface_width, surface_height, color_bytes, gfx_op); + m_surface_group[i] = new c_surface(surface_width, surface_height, color_bytes); m_surface_group[i]->attach_display(this); } } -inline c_display::c_display(void* phy_fb, int display_width, int display_height, c_surface* surface) : m_width(display_width), m_height(display_height), m_phy_fb(phy_fb), m_phy_read_index(0), m_phy_write_index(0), m_surface_cnt(1), m_surface_index(0) -{ - m_color_bytes = surface->m_color_bytes; - surface->m_is_active = true; - (m_surface_group[0] = surface)->attach_display(this); -} inline c_surface* c_display::alloc_surface(Z_ORDER_LEVEL max_zorder, c_rect layer_rect) { ASSERT(max_zorder < Z_ORDER_LEVEL_MAX && m_surface_index < m_surface_cnt); @@ -744,8 +708,8 @@ inline c_surface* c_display::alloc_surface(Z_ORDER_LEVEL max_zorder, c_rect laye } inline int c_display::swipe_surface(c_surface* s0, c_surface* s1, int x0, int x1, int y0, int y1, int offset) { - int surface_width = s0->get_width(); - int surface_height = s0->get_height(); + register int surface_width = s0->m_width; + register int surface_height = s0->m_height; if (offset < 0 || offset > surface_width || y0 < 0 || y0 >= surface_height || y1 < 0 || y1 >= surface_height || x0 < 0 || x0 >= surface_width || x1 < 0 || x1 >= surface_width) { @@ -767,46 +731,46 @@ inline int c_display::swipe_surface(c_surface* s0, c_surface* s1, int x0, int x1 for (int y = y0; y <= y1; y++) { //Left surface - char* addr_s = ((char*)(s0->m_fb) + (y * (s0->get_width()) + x0 + offset) * m_color_bytes); + char* addr_s = ((char*)(s0->m_fb) + (y * surface_width + x0 + offset) * m_color_bytes); char* addr_d = ((char*)(m_phy_fb)+(y * m_width + x0) * m_color_bytes); memcpy(addr_d, addr_s, (width - offset) * m_color_bytes); //Right surface - addr_s = ((char*)(s1->m_fb) + (y * (s1->get_width()) + x0) * m_color_bytes); + addr_s = ((char*)(s1->m_fb) + (y * surface_width + x0) * m_color_bytes); addr_d = ((char*)(m_phy_fb)+(y * m_width + x0 + (width - offset)) * m_color_bytes); memcpy(addr_d, addr_s, offset * m_color_bytes); } } - else if (m_color_bytes == 4) + else if (m_color_bytes == 2) { - void(*draw_pixel)(int x, int y, unsigned int rgb) = ((c_surface_no_fb*)s0)->m_gfx_op->draw_pixel; + void(*draw_pixel)(int x, int y, unsigned int rgb) = m_driver->draw_pixel; for (int y = y0; y <= y1; y++) { //Left surface for (int x = x0; x <= (x1 - offset); x++) { - draw_pixel(x, y, ((unsigned int*)s0->m_fb)[y * m_width + x + offset]); + draw_pixel(x, y, GL_RGB_16_to_32(((unsigned short*)s0->m_fb)[y * m_width + x + offset])); } //Right surface for (int x = x1 - offset; x <= x1; x++) { - draw_pixel(x, y, ((unsigned int*)s1->m_fb)[y * m_width + x + offset - x1 + x0]); + draw_pixel(x, y, GL_RGB_16_to_32(((unsigned short*)s1->m_fb)[y * m_width + x + offset - x1 + x0])); } } } - else if (m_color_bytes == 2) + else //m_color_bytes == 3/4... { - void(*draw_pixel)(int x, int y, unsigned int rgb) = ((c_surface_no_fb*)s0)->m_gfx_op->draw_pixel; + void(*draw_pixel)(int x, int y, unsigned int rgb) = m_driver->draw_pixel; for (int y = y0; y <= y1; y++) { //Left surface for (int x = x0; x <= (x1 - offset); x++) { - draw_pixel(x, y, GL_RGB_16_to_32(((unsigned short*)s0->m_fb)[y * m_width + x + offset])); + draw_pixel(x, y, ((unsigned int*)s0->m_fb)[y * m_width + x + offset]); } //Right surface for (int x = x1 - offset; x <= x1; x++) { - draw_pixel(x, y, GL_RGB_16_to_32(((unsigned short*)s1->m_fb)[y * m_width + x + offset - x1 + x0])); + draw_pixel(x, y, ((unsigned int*)s1->m_fb)[y * m_width + x + offset - x1 + x0]); } } } @@ -3407,22 +3371,12 @@ private: #ifdef GUILITE_ON c_bitmap_operator the_bitmap_op = c_bitmap_operator(); c_image_operator* c_image::image_operator = &the_bitmap_op; +const void* c_theme::s_font_map[FONT_MAX]; +const void* c_theme::s_image_map[IMAGE_MAX]; +unsigned int c_theme::s_color_map[COLOR_MAX]; +c_lattice_font_op the_lattice_font_op = c_lattice_font_op(); +c_font_operator* c_word::fontOperator = &the_lattice_font_op; #endif - -#ifdef GUILITE_ON - -const void* c_theme::s_font_map[FONT_MAX]; -const void* c_theme::s_image_map[IMAGE_MAX]; -unsigned int c_theme::s_color_map[COLOR_MAX]; - -#endif - -#ifdef GUILITE_ON - -c_lattice_font_op the_lattice_font_op = c_lattice_font_op(); -c_font_operator* c_word::fontOperator = &the_lattice_font_op; - -#endif #ifdef GUILITE_ON #if (defined __linux__) || (defined __APPLE__) #include @@ -4264,11 +4218,7 @@ int c_fifo::write(void* buf, int len) #endif #ifdef GUILITE_ON DIALOG_ARRAY c_dialog::ms_the_dialogs[SURFACE_CNT_MAX]; -#endif -#ifdef GUILITE_ON c_keyboard c_edit::s_keyboard; -#endif -#ifdef GUILITE_ON static c_keyboard_button s_key_0, s_key_1, s_key_2, s_key_3, s_key_4, s_key_5, s_key_6, s_key_7, s_key_8, s_key_9; static c_keyboard_button s_key_A, s_key_B, s_key_C, s_key_D, s_key_E, s_key_F, s_key_G, s_key_H, s_key_I, s_key_J; static c_keyboard_button s_key_K, s_key_L, s_key_M, s_key_N, s_key_O, s_key_P, s_key_Q, s_key_R, s_key_S, s_key_T; @@ -4306,12 +4256,12 @@ WND_TREE g_key_board_children[] = {&s_key_B, 'B', 0, ((KEY_WIDTH / 2) + POS_X(5)), POS_Y(2), KEY_WIDTH, KEY_HEIGHT}, {&s_key_N, 'N', 0, ((KEY_WIDTH / 2) + POS_X(6)), POS_Y(2), KEY_WIDTH, KEY_HEIGHT}, {&s_key_M, 'M', 0, ((KEY_WIDTH / 2) + POS_X(7)), POS_Y(2), KEY_WIDTH, KEY_HEIGHT}, - {&s_key_del, 0x7F, 0, ((KEY_WIDTH / 2) + POS_X(8)), POS_Y(2), DEL_WIDTH, KEY_HEIGHT}, + {&s_key_del,0x7F, 0, ((KEY_WIDTH / 2) + POS_X(8)), POS_Y(2), DEL_WIDTH, KEY_HEIGHT}, //Row 4 - {&s_key_esc, 0x1B, 0, POS_X(0), POS_Y(3), ESC_WIDTH, KEY_HEIGHT}, + {&s_key_esc, 0x1B, 0, POS_X(0), POS_Y(3), ESC_WIDTH, KEY_HEIGHT}, {&s_key_num_switch, 0x90, 0, POS_X(2), POS_Y(3), SWITCH_WIDTH, KEY_HEIGHT}, {&s_key_space, ' ', 0, ((KEY_WIDTH / 2) + POS_X(3)), POS_Y(3), SPACE_WIDTH, KEY_HEIGHT}, - {&s_key_dot, '.', 0, ((KEY_WIDTH / 2) + POS_X(6)), POS_Y(3), DOT_WIDTH, KEY_HEIGHT}, + {&s_key_dot, '.', 0, ((KEY_WIDTH / 2) + POS_X(6)), POS_Y(3), DOT_WIDTH, KEY_HEIGHT}, {&s_key_enter, '\n', 0, POS_X(8), POS_Y(3), ENTER_WIDTH, KEY_HEIGHT}, {0,0,0,0,0,0,0} }; @@ -4326,12 +4276,11 @@ WND_TREE g_number_board_children[] = {&s_key_7, '7', 0, POS_X(0), POS_Y(2), KEY_WIDTH, KEY_HEIGHT}, {&s_key_8, '8', 0, POS_X(1), POS_Y(2), KEY_WIDTH, KEY_HEIGHT}, {&s_key_9, '9', 0, POS_X(2), POS_Y(2), KEY_WIDTH, KEY_HEIGHT}, - - {&s_key_esc, 0x1B, 0, POS_X(0), POS_Y(3), KEY_WIDTH, KEY_HEIGHT}, + {&s_key_esc,0x1B, 0, POS_X(0), POS_Y(3), KEY_WIDTH, KEY_HEIGHT}, {&s_key_0, '0', 0, POS_X(1), POS_Y(3), KEY_WIDTH, KEY_HEIGHT}, - {&s_key_dot, '.', 0, POS_X(2), POS_Y(3), KEY_WIDTH, KEY_HEIGHT}, + {&s_key_dot,'.', 0, POS_X(2), POS_Y(3), KEY_WIDTH, KEY_HEIGHT}, {&s_key_del, 0x7F, 0, POS_X(3), POS_Y(0), KEY_WIDTH, KEY_HEIGHT * 2 + 2}, {&s_key_enter,'\n', 0, POS_X(3), POS_Y(2), KEY_WIDTH, KEY_HEIGHT * 2 + 2}, {0,0,0,0,0,0,0} }; -#endif +#endif \ No newline at end of file diff --git a/Hello3Ddonut/UIcode/UIcode.cpp b/Hello3Ddonut/UIcode/UIcode.cpp index 42c1dccc2856056dfbc951e63acf34c24afa66e5..0cfc39b06cf2028c10efe2333b30b0ddb520cfbb 100644 --- a/Hello3Ddonut/UIcode/UIcode.cpp +++ b/Hello3Ddonut/UIcode/UIcode.cpp @@ -65,21 +65,12 @@ void render_frame() extern const LATTICE_FONT_INFO Consolas_13; // Demo -void create_ui(void* phy_fb, int screen_width, int screen_height, int color_bytes, struct EXTERNAL_GFX_OP* gfx_op) { - if (phy_fb) - { - static c_surface surface(UI_WIDTH, UI_HEIGHT, color_bytes, Z_ORDER_LEVEL_0); - static c_display display(phy_fb, screen_width, screen_height, &surface); - s_surface = &surface; - s_display = &display; - } - else - {//for MCU without framebuffer - static c_surface_no_fb surface_no_fb(UI_WIDTH, UI_HEIGHT, color_bytes, gfx_op, Z_ORDER_LEVEL_0); - static c_display display(phy_fb, screen_width, screen_height, &surface_no_fb); - s_surface = &surface_no_fb; - s_display = &display; - } +void create_ui(void* phy_fb, int screen_width, int screen_height, int color_bytes, struct DISPLAY_DRIVER* driver) { + static c_surface surface(UI_WIDTH, UI_HEIGHT, color_bytes, Z_ORDER_LEVEL_0); + static c_display display(phy_fb, screen_width, screen_height, &surface, driver); + s_surface = &surface; + s_display = &display; + s_surface->fill_rect(0, 0, UI_WIDTH - 1, UI_HEIGHT - 1, 0, Z_ORDER_LEVEL_0); c_theme::add_font(FONT_DEFAULT, &Consolas_13); @@ -91,8 +82,8 @@ void create_ui(void* phy_fb, int screen_width, int screen_height, int color_byte } //////////////////////// interface for all platform //////////////////////// -extern "C" void startHello3Ddonut(void* phy_fb, int width, int height, int color_bytes, struct EXTERNAL_GFX_OP* gfx_op) { - create_ui(phy_fb, width, height, color_bytes, gfx_op); +extern "C" void startHello3Ddonut(void* phy_fb, int width, int height, int color_bytes, struct DISPLAY_DRIVER* driver) { + create_ui(phy_fb, width, height, color_bytes, driver); } extern "C" void* getUiOfHello3Ddonut(int* width, int* height, bool force_update) diff --git a/Hello3Dwave/BuildAppleWatch/Hello3D WatchKit Extension/Hello3D WatchKit Extension-Bridging-Header.h b/Hello3Dwave/BuildAppleWatch/Hello3D WatchKit Extension/Hello3D WatchKit Extension-Bridging-Header.h index 9466e22e57db174f987b9917f06c1e5fcff3b92b..505e86a30e6500c90a6cb3cfe5d4783686b73a80 100644 --- a/Hello3Dwave/BuildAppleWatch/Hello3D WatchKit Extension/Hello3D WatchKit Extension-Bridging-Header.h +++ b/Hello3Dwave/BuildAppleWatch/Hello3D WatchKit Extension/Hello3D WatchKit Extension-Bridging-Header.h @@ -8,7 +8,7 @@ extern "C"{ #endif - void startHello3Dwave(void* phy_fb, int width, int height, int color_bytes, struct EXTERNAL_GFX_OP* gfx_op); + void startHello3Dwave(void* phy_fb, int width, int height, int color_bytes, struct DISPLAY_DRIVER* driver); void* getUiOfHello3Dwave(int* width, int* height, bool force_update); #ifdef __cplusplus diff --git a/Hello3Dwave/BuildLinux/.sync_build.sh b/Hello3Dwave/BuildLinux/.sync_build.sh index 49cff5b473ac606967676ebefa6f0d333e301227..457ac69991332386a3e953e04ae4d88d8a972d7d 100644 --- a/Hello3Dwave/BuildLinux/.sync_build.sh +++ b/Hello3Dwave/BuildLinux/.sync_build.sh @@ -1,5 +1,6 @@ if [ "$#" -ne 1 ]; then - echo "Invalid arguments" + echo "Do testing" + ./xWindow 240 320 | ./Hello3Dwave shared-fb exit -1 fi diff --git a/Hello3Dwave/BuildLinux/main.cpp b/Hello3Dwave/BuildLinux/main.cpp index 3ed4e7d6649d0751c29d57f76012723cea078be1..38192fe8959beb8baa6e780b577f7f3250f648f3 100644 --- a/Hello3Dwave/BuildLinux/main.cpp +++ b/Hello3Dwave/BuildLinux/main.cpp @@ -10,7 +10,7 @@ #include #include -extern "C" void startHello3Dwave(void* phy_fb, int width, int height, int color_bytes, struct EXTERNAL_GFX_OP* gfx_op); +extern "C" void startHello3Dwave(void* phy_fb, int width, int height, int color_bytes, struct DISPLAY_DRIVER* driver); extern void init_std_io(); static void* get_embeded_fb_in_display_app(int shared_id); diff --git a/Hello3Dwave/BuildMFC/Hello3DwaveDlg.cpp b/Hello3Dwave/BuildMFC/Hello3DwaveDlg.cpp index d3ee0f1e05f7fb3a8b08f2b4e631c1cd22abcb7c..3ead97394032a5a3604aaddbb36f18c04503321c 100644 Binary files a/Hello3Dwave/BuildMFC/Hello3DwaveDlg.cpp and b/Hello3Dwave/BuildMFC/Hello3DwaveDlg.cpp differ diff --git a/Hello3Dwave/BuildMFC/Hello3DwaveDlg.h b/Hello3Dwave/BuildMFC/Hello3DwaveDlg.h index fedb98beaf4b3adfb23fd32895b9d08fc9b2fb75..4bc061d0ae334adf10fcbc53a25133cb15112fce 100644 Binary files a/Hello3Dwave/BuildMFC/Hello3DwaveDlg.h and b/Hello3Dwave/BuildMFC/Hello3DwaveDlg.h differ diff --git a/Hello3Dwave/BuildQt/mainwindow.cpp b/Hello3Dwave/BuildQt/mainwindow.cpp index 94c99a00c3030b03e6ca7e32238edf84d0ddc48e..e83e150c938bcda4b1a1d9ba1a8ded38a70daeff 100644 --- a/Hello3Dwave/BuildQt/mainwindow.cpp +++ b/Hello3Dwave/BuildQt/mainwindow.cpp @@ -10,7 +10,7 @@ #include #include -extern "C" void startHello3Dwave(void* phy_fb, int width, int height, int color_bytes, struct EXTERNAL_GFX_OP* gfx_op); +extern "C" void startHello3Dwave(void* phy_fb, int width, int height, int color_bytes, struct DISPLAY_DRIVER* driver); extern "C" void* getUiOfHello3Dwave(int* width, int* height, bool force_update); #define UI_WIDTH 480 diff --git a/Hello3Dwave/BuildSTM32F103-Keil/USER/main.c b/Hello3Dwave/BuildSTM32F103-Keil/USER/main.c index cc714503bd44e928ad6229048db402dedab907d6..4afd3b52e119c0c5fa5e6cf25e0594c5e6cbc5f0 100644 --- a/Hello3Dwave/BuildSTM32F103-Keil/USER/main.c +++ b/Hello3Dwave/BuildSTM32F103-Keil/USER/main.c @@ -15,12 +15,12 @@ void gfx_draw_pixel(int x, int y, unsigned int rgb) //void gfx_fill_rect(int x0, int y0, int x1, int y1, unsigned int rgb){} //UI entry -struct EXTERNAL_GFX_OP +struct DISPLAY_DRIVER { void (*draw_pixel)(int x, int y, unsigned int rgb); void (*fill_rect)(int x0, int y0, int x1, int y1, unsigned int rgb); -} my_gfx_op; -extern void startHello3Dwave(void* phy_fb, int width, int height, int color_bytes, struct EXTERNAL_GFX_OP* gfx_op); +} my_driver; +extern void startHello3Dwave(void* phy_fb, int width, int height, int color_bytes, struct DISPLAY_DRIVER* driver); int main(void) { @@ -30,8 +30,8 @@ int main(void) LCD_Init(); //Link your LCD driver & start UI: - my_gfx_op.draw_pixel = gfx_draw_pixel; - my_gfx_op.fill_rect = NULL;//gfx_fill_rect; - startHello3Dwave(NULL, 240, 320, 2, &my_gfx_op); + my_driver.draw_pixel = gfx_draw_pixel; + my_driver.fill_rect = NULL;//gfx_fill_rect; + startHello3Dwave(NULL, 240, 320, 2, &my_driver); while(1); } diff --git a/Hello3Dwave/BuildWin32/Hello3Dwave.cpp b/Hello3Dwave/BuildWin32/Hello3Dwave.cpp index 46e180d872f763dbab80d053df0a165ae47876b3..4e46268f43ca26b6ee895b43f4ed22bf28325ac3 100644 --- a/Hello3Dwave/BuildWin32/Hello3Dwave.cpp +++ b/Hello3Dwave/BuildWin32/Hello3Dwave.cpp @@ -161,7 +161,7 @@ LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam) } //////////////////////// Hello3Dwave Interface //////////////////////// -extern "C" void startHello3Dwave(void* phy_fb, int width, int height, int color_bytes, struct EXTERNAL_GFX_OP* gfx_op); +extern "C" void startHello3Dwave(void* phy_fb, int width, int height, int color_bytes, struct DISPLAY_DRIVER* driver); DWORD WINAPI ThreadHello3Dwave(LPVOID pParam) { diff --git a/Hello3Dwave/UIcode/GuiLite.h b/Hello3Dwave/UIcode/GuiLite.h index c4fc88a51476d2c8309c3e55e1270e13784fc510..80550e1632ad7bc82541a2edbb0f7f8f5937954f 100644 --- a/Hello3Dwave/UIcode/GuiLite.h +++ b/Hello3Dwave/UIcode/GuiLite.h @@ -1,107 +1,94 @@ #pragma once - -#define REAL_TIME_TASK_CYCLE_MS 50 -#define MAX(a,b) (((a)>(b))?(a):(b)) -#define MIN(a,b) (((a)<(b))?(a):(b)) - -#define GL_ARGB(a, r, g, b) ((((unsigned int)(a)) << 24) | (((unsigned int)(r)) << 16) | (((unsigned int)(g)) << 8) | ((unsigned int)(b))) -#define GL_ARGB_A(rgb) ((((unsigned int)(rgb)) >> 24) & 0xFF) - -#define GL_RGB(r, g, b) ((0xFF << 24) | (((unsigned int)(r)) << 16) | (((unsigned int)(g)) << 8) | ((unsigned int)(b))) -#define GL_RGB_R(rgb) ((((unsigned int)(rgb)) >> 16) & 0xFF) -#define GL_RGB_G(rgb) ((((unsigned int)(rgb)) >> 8) & 0xFF) -#define GL_RGB_B(rgb) (((unsigned int)(rgb)) & 0xFF) -#define GL_RGB_32_to_16(rgb) (((((unsigned int)(rgb)) & 0xFF) >> 3) | ((((unsigned int)(rgb)) & 0xFC00) >> 5) | ((((unsigned int)(rgb)) & 0xF80000) >> 8)) -#define GL_RGB_16_to_32(rgb) ((0xFF << 24) | ((((unsigned int)(rgb)) & 0x1F) << 3) | ((((unsigned int)(rgb)) & 0x7E0) << 5) | ((((unsigned int)(rgb)) & 0xF800) << 8)) - -#define ALIGN_HCENTER 0x00000000L -#define ALIGN_LEFT 0x01000000L -#define ALIGN_RIGHT 0x02000000L -#define ALIGN_HMASK 0x03000000L - -#define ALIGN_VCENTER 0x00000000L -#define ALIGN_TOP 0x00100000L -#define ALIGN_BOTTOM 0x00200000L -#define ALIGN_VMASK 0x00300000L - -typedef struct -{ - unsigned short year; - unsigned short month; - unsigned short date; - unsigned short day; - unsigned short hour; - unsigned short minute; - unsigned short second; -}T_TIME; - -void register_debug_function(void(*my_assert)(const char* file, int line), void(*my_log_out)(const char* log)); -void _assert(const char* file, int line); -#define ASSERT(condition) \ - do{ \ - if(!(condition))_assert(__FILE__, __LINE__);\ - }while(0) -void log_out(const char* log); - -long get_time_in_second(); -T_TIME second_to_day(long second); -T_TIME get_time(); - -void start_real_timer(void (*func)(void* arg)); -void register_timer(int milli_second, void func(void* param), void* param); - -unsigned int get_cur_thread_id(); -void create_thread(unsigned long* thread_id, void* attr, void *(*start_routine) (void *), void* arg); -void thread_sleep(unsigned int milli_seconds); -int build_bmp(const char *filename, unsigned int width, unsigned int height, unsigned char *data); - -#define FIFO_BUFFER_LEN 1024 -class c_fifo -{ -public: - c_fifo(); - int read(void* buf, int len); - int write(void* buf, int len); -private: - unsigned char m_buf[FIFO_BUFFER_LEN]; - int m_head; - int m_tail; - void* m_read_sem; - void* m_write_mutex; -}; - -class c_rect -{ -public: - c_rect(){ m_left = m_top = m_right = m_bottom = -1; } - c_rect(int left, int top, int width, int height) - { - set_rect(left, top, width, height); - } - void set_rect(int left, int top, int width, int height) - { - ASSERT(width > 0 && height > 0); - m_left = left; - m_top = top; - m_right = left + width - 1; - m_bottom = top + height -1; - } - bool pt_in_rect(int x, int y) const - { - return x >= m_left && x <= m_right && y >= m_top && y <= m_bottom; - } - int operator==(const c_rect& rect) const - { - return (m_left == rect.m_left) && (m_top == rect.m_top) && (m_right == rect.m_right) && (m_bottom == rect.m_bottom); - } - int width() const { return m_right - m_left + 1; } - int height() const { return m_bottom - m_top + 1 ; } - - int m_left; - int m_top; - int m_right; - int m_bottom; -}; +#define REAL_TIME_TASK_CYCLE_MS 50 +#define MAX(a,b) (((a)>(b))?(a):(b)) +#define MIN(a,b) (((a)<(b))?(a):(b)) +#define GL_ARGB(a, r, g, b) ((((unsigned int)(a)) << 24) | (((unsigned int)(r)) << 16) | (((unsigned int)(g)) << 8) | ((unsigned int)(b))) +#define GL_ARGB_A(rgb) ((((unsigned int)(rgb)) >> 24) & 0xFF) +#define GL_RGB(r, g, b) ((0xFF << 24) | (((unsigned int)(r)) << 16) | (((unsigned int)(g)) << 8) | ((unsigned int)(b))) +#define GL_RGB_R(rgb) ((((unsigned int)(rgb)) >> 16) & 0xFF) +#define GL_RGB_G(rgb) ((((unsigned int)(rgb)) >> 8) & 0xFF) +#define GL_RGB_B(rgb) (((unsigned int)(rgb)) & 0xFF) +#define GL_RGB_32_to_16(rgb) (((((unsigned int)(rgb)) & 0xFF) >> 3) | ((((unsigned int)(rgb)) & 0xFC00) >> 5) | ((((unsigned int)(rgb)) & 0xF80000) >> 8)) +#define GL_RGB_16_to_32(rgb) ((0xFF << 24) | ((((unsigned int)(rgb)) & 0x1F) << 3) | ((((unsigned int)(rgb)) & 0x7E0) << 5) | ((((unsigned int)(rgb)) & 0xF800) << 8)) +#define ALIGN_HCENTER 0x00000000L +#define ALIGN_LEFT 0x01000000L +#define ALIGN_RIGHT 0x02000000L +#define ALIGN_HMASK 0x03000000L +#define ALIGN_VCENTER 0x00000000L +#define ALIGN_TOP 0x00100000L +#define ALIGN_BOTTOM 0x00200000L +#define ALIGN_VMASK 0x00300000L +typedef struct +{ + unsigned short year; + unsigned short month; + unsigned short date; + unsigned short day; + unsigned short hour; + unsigned short minute; + unsigned short second; +}T_TIME; +void register_debug_function(void(*my_assert)(const char* file, int line), void(*my_log_out)(const char* log)); +void _assert(const char* file, int line); +#define ASSERT(condition) \ + do{ \ + if(!(condition))_assert(__FILE__, __LINE__);\ + }while(0) +void log_out(const char* log); +long get_time_in_second(); +T_TIME second_to_day(long second); +T_TIME get_time(); +void start_real_timer(void (*func)(void* arg)); +void register_timer(int milli_second, void func(void* param), void* param); +unsigned int get_cur_thread_id(); +void create_thread(unsigned long* thread_id, void* attr, void *(*start_routine) (void *), void* arg); +void thread_sleep(unsigned int milli_seconds); +int build_bmp(const char *filename, unsigned int width, unsigned int height, unsigned char *data); +#define FIFO_BUFFER_LEN 1024 +class c_fifo +{ +public: + c_fifo(); + int read(void* buf, int len); + int write(void* buf, int len); +private: + unsigned char m_buf[FIFO_BUFFER_LEN]; + int m_head; + int m_tail; + void* m_read_sem; + void* m_write_mutex; +}; +class c_rect +{ +public: + c_rect(){ m_left = m_top = m_right = m_bottom = -1; } + c_rect(int left, int top, int width, int height) + { + set_rect(left, top, width, height); + } + void set_rect(int left, int top, int width, int height) + { + ASSERT(width > 0 && height > 0); + m_left = left; + m_top = top; + m_right = left + width - 1; + m_bottom = top + height -1; + } + bool pt_in_rect(int x, int y) const + { + return x >= m_left && x <= m_right && y >= m_top && y <= m_bottom; + } + int operator==(const c_rect& rect) const + { + return (m_left == rect.m_left) && (m_top == rect.m_top) && (m_right == rect.m_right) && (m_bottom == rect.m_bottom); + } + int width() const { return m_right - m_left + 1; } + int height() const { return m_bottom - m_top + 1 ; } + int m_left; + int m_top; + int m_right; + int m_bottom; +}; //BITMAP typedef struct struct_bitmap_info { @@ -238,7 +225,7 @@ typedef enum Z_ORDER_LEVEL_2,//highest graphic level Z_ORDER_LEVEL_MAX }Z_ORDER_LEVEL; -struct EXTERNAL_GFX_OP +struct DISPLAY_DRIVER { void(*draw_pixel)(int x, int y, unsigned int rgb); void(*fill_rect)(int x0, int y0, int x1, int y1, unsigned int rgb); @@ -247,18 +234,19 @@ class c_surface; class c_display { friend class c_surface; public: - inline c_display(void* phy_fb, int display_width, int display_height, int surface_width, int surface_height, unsigned int color_bytes, int surface_cnt, EXTERNAL_GFX_OP* gfx_op = 0);//multiple surface or surface_no_fb - inline c_display(void* phy_fb, int display_width, int display_height, c_surface* surface);//single custom surface - inline c_surface* alloc_surface(Z_ORDER_LEVEL max_zorder, c_rect layer_rect = c_rect());//for multiple surfaces + inline c_display(void* phy_fb, int display_width, int display_height, c_surface* surface, DISPLAY_DRIVER* driver = 0);//single custom surface + inline c_display(void* phy_fb, int display_width, int display_height, int surface_width, int surface_height, unsigned int color_bytes, int surface_cnt, DISPLAY_DRIVER* driver = 0);//multiple surface + inline c_surface* alloc_surface(Z_ORDER_LEVEL max_zorder, c_rect layer_rect = c_rect());//for slide group inline int swipe_surface(c_surface* s0, c_surface* s1, int x0, int x1, int y0, int y1, int offset); int get_width() { return m_width; } int get_height() { return m_height; } + void* get_phy_fb() { return m_phy_fb; } void* get_updated_fb(int* width, int* height, bool force_update = false) { if (width && height) { - *width = get_width(); - *height = get_height(); + *width = m_width; + *height = m_height; } if (force_update) { @@ -277,35 +265,123 @@ public: { return -1; } - int width = get_width(); - int height = get_height(); //16 bits framebuffer if (m_color_bytes == 2) { - return build_bmp(file_name, width, height, (unsigned char*)m_phy_fb); + return build_bmp(file_name, m_width, m_height, (unsigned char*)m_phy_fb); } //32 bits framebuffer - unsigned short* p_bmp565_data = new unsigned short[width * height]; + unsigned short* p_bmp565_data = new unsigned short[m_width * m_height]; unsigned int* p_raw_data = (unsigned int*)m_phy_fb; - for (int i = 0; i < width * height; i++) + for (int i = 0; i < m_width * m_height; i++) { unsigned int rgb = *p_raw_data++; p_bmp565_data[i] = GL_RGB_32_to_16(rgb); } - int ret = build_bmp(file_name, width, height, (unsigned char*)p_bmp565_data); + int ret = build_bmp(file_name, m_width, m_height, (unsigned char*)p_bmp565_data); delete[]p_bmp565_data; return ret; } -private: - int m_width; //in pixels - int m_height; //in pixels - int m_color_bytes; //16 bits, 32 bits only - void* m_phy_fb; //physical framebuffer +protected: + virtual void draw_pixel(int x, int y, unsigned int rgb) + { + if ((x >= m_width) || (y >= m_height)) { return; } + if (m_driver && m_driver->draw_pixel) + { + return m_driver->draw_pixel(x, y, rgb); + } + if (m_color_bytes == 2) + { + ((unsigned short*)m_phy_fb)[y * m_width + x] = GL_RGB_32_to_16(rgb); + } + else + { + ((unsigned int*)m_phy_fb)[y * m_width + x] = rgb; + } + } + virtual void fill_rect(int x0, int y0, int x1, int y1, unsigned int rgb) + { + if (m_driver && m_driver->fill_rect) + { + return m_driver->fill_rect(x0, y0, x1, y1, rgb); + } + if (m_driver && m_driver->draw_pixel) + { + for (int y = y0; y <= y1; y++) + { + for (int x = x0; x <= x1; x++) + { + m_driver->draw_pixel(x, y, rgb); + } + } + return; + } + register int _width = m_width; + register int _height = m_height; + int x, y; + if (m_color_bytes == 2) + { + unsigned short* phy_fb; + unsigned int rgb_16 = GL_RGB_32_to_16(rgb); + for (y = y0; y <= y1; y++) + { + phy_fb = &((unsigned short*)m_phy_fb)[y * _width + x0]; + for (x = x0; x <= x1; x++) + { + if ((x < _width) && (y < _height)) + { + *phy_fb++ = rgb_16; + } + } + } + } + else + { + unsigned int* phy_fb; + for (y = y0; y <= y1; y++) + { + phy_fb = &((unsigned int*)m_phy_fb)[y * _width + x0]; + for (x = x0; x <= x1; x++) + { + if ((x < _width) && (y < _height)) + { + *phy_fb++ = rgb; + } + } + } + } + } + virtual int flush_screen(int left, int top, int right, int bottom, void* fb, int fb_width) + { + if ((0 == m_phy_fb) || (0 == fb)) + { + return -1; + } + register int _width = m_width; + register int _height = m_height; + left = (left >= _width) ? (_width - 1) : left; + right = (right >= _width) ? (_width - 1) : right; + top = (top >= _height) ? (_height - 1) : top; + bottom = (bottom >= _height) ? (_height - 1) : bottom; + for (int y = top; y < bottom; y++) + { + void* s_addr = (char*)fb + ((y * fb_width + left) * m_color_bytes); + void* d_addr = (char*)m_phy_fb + ((y * _width + left) * m_color_bytes); + memcpy(d_addr, s_addr, (right - left) * m_color_bytes); + } + return 0; + } + int m_width; //in pixels + int m_height; //in pixels + int m_color_bytes; //16/32 bits for default + void* m_phy_fb; //physical framebuffer for default + struct DISPLAY_DRIVER* m_driver; //Rendering by external method without default physical framebuffer int m_phy_read_index; int m_phy_write_index; c_surface* m_surface_group[SURFACE_CNT_MAX]; int m_surface_cnt; //surface count int m_surface_index; + }; class c_layer { @@ -317,12 +393,10 @@ public: class c_surface { friend class c_display; friend class c_bitmap_operator; public: - c_surface(unsigned int width, unsigned int height, unsigned int color_bytes, Z_ORDER_LEVEL max_zorder = Z_ORDER_LEVEL_0, c_rect overlpa_rect = c_rect()) : m_width(width), m_height(height), m_color_bytes(color_bytes), m_fb(0), m_is_active(false), m_top_zorder(Z_ORDER_LEVEL_0), m_phy_fb(0), m_phy_write_index(0), m_display(0) + c_surface(unsigned int width, unsigned int height, unsigned int color_bytes, Z_ORDER_LEVEL max_zorder = Z_ORDER_LEVEL_0, c_rect overlpa_rect = c_rect()) : m_width(width), m_height(height), m_color_bytes(color_bytes), m_fb(0), m_is_active(false), m_top_zorder(Z_ORDER_LEVEL_0), m_phy_write_index(0), m_display(0) { (overlpa_rect == c_rect()) ? set_surface(max_zorder, c_rect(0, 0, width - 1, height - 1)) : set_surface(max_zorder, overlpa_rect); } - int get_width() { return m_width; } - int get_height() { return m_height; } unsigned int get_pixel(int x, int y, unsigned int z_order) { if (x >= m_width || y >= m_height || x < 0 || y < 0 || z_order >= Z_ORDER_LEVEL_MAX) @@ -332,15 +406,15 @@ public: } if (m_layers[z_order].fb) { - return (m_color_bytes == 4) ? ((unsigned int*)(m_layers[z_order].fb))[y * m_width + x] : GL_RGB_16_to_32(((unsigned short*)(m_layers[z_order].fb))[y * m_width + x]); + return (m_color_bytes == 2) ? GL_RGB_16_to_32(((unsigned short*)(m_layers[z_order].fb))[y * m_width + x]) : ((unsigned int*)(m_layers[z_order].fb))[y * m_width + x]; } else if (m_fb) { - return (m_color_bytes == 4) ? ((unsigned int*)m_fb)[y * m_width + x] : GL_RGB_16_to_32(((unsigned short*)m_fb)[y * m_width + x]); + return (m_color_bytes == 2) ? GL_RGB_16_to_32(((unsigned short*)m_fb)[y * m_width + x]) : ((unsigned int*)m_fb)[y * m_width + x]; } - else if (m_phy_fb) + else if (m_display->m_phy_fb) { - return (m_color_bytes == 4) ? ((unsigned int*)m_phy_fb)[y * m_width + x] : GL_RGB_16_to_32(((unsigned short*)m_phy_fb)[y * m_width + x]); + return (m_color_bytes == 2) ? GL_RGB_16_to_32(((unsigned short*)m_display->m_phy_fb)[y * m_width + x]) : ((unsigned int*)m_display->m_phy_fb)[y * m_width + x]; } return 0; } @@ -357,7 +431,7 @@ public: } if (z_order == m_max_zorder) { - return draw_pixel_on_fb(x, y, rgb); + return draw_pixel_low_level(x, y, rgb); } if (z_order > (unsigned int)m_top_zorder) @@ -367,19 +441,19 @@ public: if (m_layers[z_order].rect.pt_in_rect(x, y)) { c_rect layer_rect = m_layers[z_order].rect; - if (m_color_bytes == 4) + if (m_color_bytes == 2) { - ((unsigned int*)(m_layers[z_order].fb))[(x - layer_rect.m_left) + (y - layer_rect.m_top) * layer_rect.width()] = rgb; + ((unsigned short*)(m_layers[z_order].fb))[(x - layer_rect.m_left) + (y - layer_rect.m_top) * layer_rect.width()] = GL_RGB_32_to_16(rgb); } else { - ((unsigned short*)(m_layers[z_order].fb))[(x - layer_rect.m_left) + (y - layer_rect.m_top) * layer_rect.width()] = GL_RGB_32_to_16(rgb); + ((unsigned int*)(m_layers[z_order].fb))[(x - layer_rect.m_left) + (y - layer_rect.m_top) * layer_rect.width()] = rgb; } } if (z_order == m_top_zorder) { - return draw_pixel_on_fb(x, y, rgb); + return draw_pixel_low_level(x, y, rgb); } bool be_overlapped = false; for (unsigned int tmp_z_order = Z_ORDER_LEVEL_MAX - 1; tmp_z_order > z_order; tmp_z_order--) @@ -392,7 +466,7 @@ public: } if (!be_overlapped) { - draw_pixel_on_fb(x, y, rgb); + draw_pixel_low_level(x, y, rgb); } } virtual void fill_rect(int x0, int y0, int x1, int y1, unsigned int rgb, unsigned int z_order) @@ -403,7 +477,7 @@ public: y1 = (y1 > (m_height - 1)) ? (m_height - 1) : y1; if (z_order == m_max_zorder) { - return fill_rect_on_fb(x0, y0, x1, y1, rgb); + return fill_rect_low_level(x0, y0, x1, y1, rgb); } if (z_order == m_top_zorder) { @@ -416,18 +490,18 @@ public: { if (layer_rect.pt_in_rect(x, y)) { - if (m_color_bytes == 4) + if (m_color_bytes == 2) { - ((unsigned int*)m_layers[z_order].fb)[(y - layer_rect.m_top) * layer_rect.width() + (x - layer_rect.m_left)] = rgb; + ((unsigned short*)m_layers[z_order].fb)[(y - layer_rect.m_top) * layer_rect.width() + (x - layer_rect.m_left)] = rgb_16; } else { - ((unsigned short*)m_layers[z_order].fb)[(y - layer_rect.m_top) * layer_rect.width() + (x - layer_rect.m_left)] = rgb_16; + ((unsigned int*)m_layers[z_order].fb)[(y - layer_rect.m_top) * layer_rect.width() + (x - layer_rect.m_left)] = rgb; } } } } - return fill_rect_on_fb(x0, y0, x1, y1, rgb); + return fill_rect_low_level(x0, y0, x1, y1, rgb); } for (; y0 <= y1; y0++) { @@ -499,27 +573,16 @@ public: } int flush_screen(int left, int top, int right, int bottom) { - if (left < 0 || left >= m_width || right < 0 || right >= m_width || - top < 0 || top >= m_height || bottom < 0 || bottom >= m_height) - { - ASSERT(false); - } - if (!m_is_active || (0 == m_phy_fb) || (0 == m_fb)) + if (!m_is_active) { return -1; } - int display_width = m_display->get_width(); - int display_height = m_display->get_height(); - left = (left >= display_width) ? (display_width - 1) : left; - right = (right >= display_width) ? (display_width - 1) : right; - top = (top >= display_height) ? (display_height - 1) : top; - bottom = (bottom >= display_height) ? (display_height - 1) : bottom; - for (int y = top; y < bottom; y++) + if (left < 0 || left >= m_width || right < 0 || right >= m_width || + top < 0 || top >= m_height || bottom < 0 || bottom >= m_height) { - void* s_addr = (char*)m_fb + ((y * m_width + left) * m_color_bytes); - void* d_addr = (char*)m_phy_fb + ((y * display_width + left) * m_color_bytes); - memcpy(d_addr, s_addr, (right - left) * m_color_bytes); + ASSERT(false); } + m_display->flush_screen(left, top, right, bottom, m_fb, m_width); *m_phy_write_index = *m_phy_write_index + 1; return 0; } @@ -537,90 +600,62 @@ public: { for (int x = rect.m_left; x <= rect.m_right; x++) { - unsigned int rgb = (m_color_bytes == 4) ? ((unsigned int*)fb)[(x - layer_rect.m_left) + (y - layer_rect.m_top) * width] : GL_RGB_16_to_32(((unsigned short*)fb)[(x - layer_rect.m_left) + (y - layer_rect.m_top) * width]); - draw_pixel_on_fb(x, y, rgb); + unsigned int rgb = (m_color_bytes == 2) ? GL_RGB_16_to_32(((unsigned short*)fb)[(x - layer_rect.m_left) + (y - layer_rect.m_top) * width]) : ((unsigned int*)fb)[(x - layer_rect.m_left) + (y - layer_rect.m_top) * width]; + draw_pixel_low_level(x, y, rgb); } } return 0; } void set_active(bool flag) { m_is_active = flag; } protected: - virtual void fill_rect_on_fb(int x0, int y0, int x1, int y1, unsigned int rgb) - { - int display_width = m_display->get_width(); - int display_height = m_display->get_height(); - if (m_color_bytes == 4) + virtual void fill_rect_low_level(int x0, int y0, int x1, int y1, unsigned int rgb) + {//fill rect on framebuffer of surface + int x, y; + if (m_color_bytes == 2) { - int x; - unsigned int* fb, * phy_fb; - for (; y0 <= y1; y0++) + unsigned short* fb; + unsigned int rgb_16 = GL_RGB_32_to_16(rgb); + for (y = y0; y <= y1; y++) { - x = x0; - fb = m_fb ? &((unsigned int*)m_fb)[y0 * m_width + x] : 0; - phy_fb = &((unsigned int*)m_phy_fb)[y0 * display_width + x]; - *m_phy_write_index = *m_phy_write_index + 1; - for (; x <= x1; x++) + fb = m_fb ? &((unsigned short*)m_fb)[y * m_width + x0] : 0; + if (!fb) { break; } + for (x = x0; x <= x1; x++) { - if (fb) - { - *fb++ = rgb; - } - if (m_is_active && (x < display_width) && (y0 < display_height)) - { - *phy_fb++ = rgb; - } + *fb++ = rgb_16; } } } - else if (m_color_bytes == 2) + else { - int x; - unsigned short* fb, * phy_fb; - rgb = GL_RGB_32_to_16(rgb); - for (; y0 <= y1; y0++) + unsigned int* fb; + for (y = y0; y <= y1; y++) { - x = x0; - fb = m_fb ? &((unsigned short*)m_fb)[y0 * m_width + x] : 0; - phy_fb = &((unsigned short*)m_phy_fb)[y0 * display_width + x]; - *m_phy_write_index = *m_phy_write_index + 1; - for (; x <= x1; x++) + fb = m_fb ? &((unsigned int*)m_fb)[y * m_width + x0] : 0; + if (!fb) { break; } + for (x = x0; x <= x1; x++) { - if (fb) - { - *fb++ = rgb; - } - if (m_is_active && (x < display_width) && (y0 < display_height)) - { - *phy_fb++ = rgb; - } + *fb++ = rgb; } } } + if (!m_is_active) { return; } + m_display->fill_rect(x0, y0, x1, y1, rgb); + *m_phy_write_index = *m_phy_write_index + 1; } - virtual void draw_pixel_on_fb(int x, int y, unsigned int rgb) + virtual void draw_pixel_low_level(int x, int y, unsigned int rgb) { if (m_fb) - { - (m_color_bytes == 4) ? ((unsigned int*)m_fb)[y * m_width + x] = rgb : ((unsigned short*)m_fb)[y * m_width + x] = GL_RGB_32_to_16(rgb); - } - if (m_is_active && (x < m_display->get_width()) && (y < m_display->get_height())) - { - if (m_color_bytes == 4) - { - ((unsigned int*)m_phy_fb)[y * (m_display->get_width()) + x] = rgb; - } - else - { - ((unsigned short*)m_phy_fb)[y * (m_display->get_width()) + x] = GL_RGB_32_to_16(rgb); - } - *m_phy_write_index = *m_phy_write_index + 1; + {//draw pixel on framebuffer of surface + (m_color_bytes == 2) ? ((unsigned short*)m_fb)[y * m_width + x] = GL_RGB_32_to_16(rgb): ((unsigned int*)m_fb)[y * m_width + x] = rgb; } + if (!m_is_active) { return; } + m_display->draw_pixel(x, y, rgb); + *m_phy_write_index = *m_phy_write_index + 1; } void attach_display(c_display* display) { ASSERT(display); m_display = display; - m_phy_fb = display->m_phy_fb; m_phy_write_index = &display->m_phy_write_index; } void set_surface(Z_ORDER_LEVEL max_z_order, c_rect layer_rect) @@ -638,87 +673,22 @@ protected: } int m_width; //in pixels int m_height; //in pixels - int m_color_bytes; //16 bits, 32 bits only + int m_color_bytes; //16 bits, 32 bits for default void* m_fb; //frame buffer you could see c_layer m_layers[Z_ORDER_LEVEL_MAX];//all graphic layers bool m_is_active; //active flag Z_ORDER_LEVEL m_max_zorder; //the highest graphic layer the surface will have Z_ORDER_LEVEL m_top_zorder; //the current highest graphic layer the surface have - void* m_phy_fb; //physical framebufer int* m_phy_write_index; c_display* m_display; }; -class c_surface_no_fb : public c_surface {//No physical framebuffer, render with external graphic interface - friend class c_display; -public: - c_surface_no_fb(unsigned int width, unsigned int height, unsigned int color_bytes, struct EXTERNAL_GFX_OP* gfx_op, Z_ORDER_LEVEL max_zorder = Z_ORDER_LEVEL_0, c_rect overlpa_rect = c_rect()) : c_surface(width, height, color_bytes, max_zorder, overlpa_rect), m_gfx_op(gfx_op) {} -protected: - virtual void fill_rect_on_fb(int x0, int y0, int x1, int y1, unsigned int rgb) - { - if (!m_gfx_op) - { - return; - } - if (m_gfx_op->fill_rect) - { - return m_gfx_op->fill_rect(x0, y0, x1, y1, rgb); - } - if (m_gfx_op->draw_pixel && m_is_active) - { - for (int y = y0; y <= y1; y++) - { - for (int x = x0; x <= x1; x++) - { - m_gfx_op->draw_pixel(x, y, rgb); - } - } - } - if (!m_fb) { return; } - if (m_color_bytes == 4) - { - unsigned int* fb; - for (int y = y0; y <= y1; y++) - { - fb = &((unsigned int*)m_fb)[y0 * m_width + x0]; - for (int x = x0; x <= x1; x++) - { - *fb++ = rgb; - } - } - } - else if (m_color_bytes == 2) - { - unsigned short* fb; - rgb = GL_RGB_32_to_16(rgb); - for (int y = y0; y <= y1; y++) - { - fb = &((unsigned short*)m_fb)[y0 * m_width + x0]; - for (int x = x0; x <= x1; x++) - { - *fb++ = rgb; - } - } - } - } - virtual void draw_pixel_on_fb(int x, int y, unsigned int rgb) - { - if (m_gfx_op && m_gfx_op->draw_pixel && m_is_active) - { - m_gfx_op->draw_pixel(x, y, rgb); - } - if (!m_fb) { return; } - if (m_color_bytes == 4) - { - ((unsigned int*)m_fb)[y * m_width + x] = rgb; - } - else if (m_color_bytes == 2) - { - ((unsigned short*)m_fb)[y * m_width + x] = GL_RGB_32_to_16(rgb); - } - } - struct EXTERNAL_GFX_OP* m_gfx_op;//Rendering by external method -}; -inline c_display::c_display(void* phy_fb, int display_width, int display_height, int surface_width, int surface_height, unsigned int color_bytes, int surface_cnt, EXTERNAL_GFX_OP* gfx_op) : m_width(display_width), m_height(display_height), m_color_bytes(color_bytes), m_phy_fb(phy_fb), m_phy_read_index(0), m_phy_write_index(0), m_surface_cnt(surface_cnt), m_surface_index(0) +inline c_display::c_display(void* phy_fb, int display_width, int display_height, c_surface* surface, DISPLAY_DRIVER* driver) : m_phy_fb(phy_fb), m_width(display_width), m_height(display_height), m_driver(driver), m_phy_read_index(0), m_phy_write_index(0), m_surface_cnt(1), m_surface_index(0) +{ + m_color_bytes = surface->m_color_bytes; + surface->m_is_active = true; + (m_surface_group[0] = surface)->attach_display(this); +} +inline c_display::c_display(void* phy_fb, int display_width, int display_height, int surface_width, int surface_height, unsigned int color_bytes, int surface_cnt, DISPLAY_DRIVER* driver) : m_phy_fb(phy_fb), m_width(display_width), m_height(display_height), m_color_bytes(color_bytes), m_phy_read_index(0), m_phy_write_index(0), m_surface_cnt(surface_cnt), m_driver(driver), m_surface_index(0) { ASSERT(color_bytes == 2 || color_bytes == 4); ASSERT(m_surface_cnt <= SURFACE_CNT_MAX); @@ -726,16 +696,10 @@ inline c_display::c_display(void* phy_fb, int display_width, int display_height, for (int i = 0; i < m_surface_cnt; i++) { - m_surface_group[i] = (phy_fb) ? new c_surface(surface_width, surface_height, color_bytes) : new c_surface_no_fb(surface_width, surface_height, color_bytes, gfx_op); + m_surface_group[i] = new c_surface(surface_width, surface_height, color_bytes); m_surface_group[i]->attach_display(this); } } -inline c_display::c_display(void* phy_fb, int display_width, int display_height, c_surface* surface) : m_width(display_width), m_height(display_height), m_phy_fb(phy_fb), m_phy_read_index(0), m_phy_write_index(0), m_surface_cnt(1), m_surface_index(0) -{ - m_color_bytes = surface->m_color_bytes; - surface->m_is_active = true; - (m_surface_group[0] = surface)->attach_display(this); -} inline c_surface* c_display::alloc_surface(Z_ORDER_LEVEL max_zorder, c_rect layer_rect) { ASSERT(max_zorder < Z_ORDER_LEVEL_MAX && m_surface_index < m_surface_cnt); @@ -744,8 +708,8 @@ inline c_surface* c_display::alloc_surface(Z_ORDER_LEVEL max_zorder, c_rect laye } inline int c_display::swipe_surface(c_surface* s0, c_surface* s1, int x0, int x1, int y0, int y1, int offset) { - int surface_width = s0->get_width(); - int surface_height = s0->get_height(); + register int surface_width = s0->m_width; + register int surface_height = s0->m_height; if (offset < 0 || offset > surface_width || y0 < 0 || y0 >= surface_height || y1 < 0 || y1 >= surface_height || x0 < 0 || x0 >= surface_width || x1 < 0 || x1 >= surface_width) { @@ -767,46 +731,46 @@ inline int c_display::swipe_surface(c_surface* s0, c_surface* s1, int x0, int x1 for (int y = y0; y <= y1; y++) { //Left surface - char* addr_s = ((char*)(s0->m_fb) + (y * (s0->get_width()) + x0 + offset) * m_color_bytes); + char* addr_s = ((char*)(s0->m_fb) + (y * surface_width + x0 + offset) * m_color_bytes); char* addr_d = ((char*)(m_phy_fb)+(y * m_width + x0) * m_color_bytes); memcpy(addr_d, addr_s, (width - offset) * m_color_bytes); //Right surface - addr_s = ((char*)(s1->m_fb) + (y * (s1->get_width()) + x0) * m_color_bytes); + addr_s = ((char*)(s1->m_fb) + (y * surface_width + x0) * m_color_bytes); addr_d = ((char*)(m_phy_fb)+(y * m_width + x0 + (width - offset)) * m_color_bytes); memcpy(addr_d, addr_s, offset * m_color_bytes); } } - else if (m_color_bytes == 4) + else if (m_color_bytes == 2) { - void(*draw_pixel)(int x, int y, unsigned int rgb) = ((c_surface_no_fb*)s0)->m_gfx_op->draw_pixel; + void(*draw_pixel)(int x, int y, unsigned int rgb) = m_driver->draw_pixel; for (int y = y0; y <= y1; y++) { //Left surface for (int x = x0; x <= (x1 - offset); x++) { - draw_pixel(x, y, ((unsigned int*)s0->m_fb)[y * m_width + x + offset]); + draw_pixel(x, y, GL_RGB_16_to_32(((unsigned short*)s0->m_fb)[y * m_width + x + offset])); } //Right surface for (int x = x1 - offset; x <= x1; x++) { - draw_pixel(x, y, ((unsigned int*)s1->m_fb)[y * m_width + x + offset - x1 + x0]); + draw_pixel(x, y, GL_RGB_16_to_32(((unsigned short*)s1->m_fb)[y * m_width + x + offset - x1 + x0])); } } } - else if (m_color_bytes == 2) + else //m_color_bytes == 3/4... { - void(*draw_pixel)(int x, int y, unsigned int rgb) = ((c_surface_no_fb*)s0)->m_gfx_op->draw_pixel; + void(*draw_pixel)(int x, int y, unsigned int rgb) = m_driver->draw_pixel; for (int y = y0; y <= y1; y++) { //Left surface for (int x = x0; x <= (x1 - offset); x++) { - draw_pixel(x, y, GL_RGB_16_to_32(((unsigned short*)s0->m_fb)[y * m_width + x + offset])); + draw_pixel(x, y, ((unsigned int*)s0->m_fb)[y * m_width + x + offset]); } //Right surface for (int x = x1 - offset; x <= x1; x++) { - draw_pixel(x, y, GL_RGB_16_to_32(((unsigned short*)s1->m_fb)[y * m_width + x + offset - x1 + x0])); + draw_pixel(x, y, ((unsigned int*)s1->m_fb)[y * m_width + x + offset - x1 + x0]); } } } @@ -3407,22 +3371,12 @@ private: #ifdef GUILITE_ON c_bitmap_operator the_bitmap_op = c_bitmap_operator(); c_image_operator* c_image::image_operator = &the_bitmap_op; +const void* c_theme::s_font_map[FONT_MAX]; +const void* c_theme::s_image_map[IMAGE_MAX]; +unsigned int c_theme::s_color_map[COLOR_MAX]; +c_lattice_font_op the_lattice_font_op = c_lattice_font_op(); +c_font_operator* c_word::fontOperator = &the_lattice_font_op; #endif - -#ifdef GUILITE_ON - -const void* c_theme::s_font_map[FONT_MAX]; -const void* c_theme::s_image_map[IMAGE_MAX]; -unsigned int c_theme::s_color_map[COLOR_MAX]; - -#endif - -#ifdef GUILITE_ON - -c_lattice_font_op the_lattice_font_op = c_lattice_font_op(); -c_font_operator* c_word::fontOperator = &the_lattice_font_op; - -#endif #ifdef GUILITE_ON #if (defined __linux__) || (defined __APPLE__) #include @@ -4264,11 +4218,7 @@ int c_fifo::write(void* buf, int len) #endif #ifdef GUILITE_ON DIALOG_ARRAY c_dialog::ms_the_dialogs[SURFACE_CNT_MAX]; -#endif -#ifdef GUILITE_ON c_keyboard c_edit::s_keyboard; -#endif -#ifdef GUILITE_ON static c_keyboard_button s_key_0, s_key_1, s_key_2, s_key_3, s_key_4, s_key_5, s_key_6, s_key_7, s_key_8, s_key_9; static c_keyboard_button s_key_A, s_key_B, s_key_C, s_key_D, s_key_E, s_key_F, s_key_G, s_key_H, s_key_I, s_key_J; static c_keyboard_button s_key_K, s_key_L, s_key_M, s_key_N, s_key_O, s_key_P, s_key_Q, s_key_R, s_key_S, s_key_T; @@ -4306,12 +4256,12 @@ WND_TREE g_key_board_children[] = {&s_key_B, 'B', 0, ((KEY_WIDTH / 2) + POS_X(5)), POS_Y(2), KEY_WIDTH, KEY_HEIGHT}, {&s_key_N, 'N', 0, ((KEY_WIDTH / 2) + POS_X(6)), POS_Y(2), KEY_WIDTH, KEY_HEIGHT}, {&s_key_M, 'M', 0, ((KEY_WIDTH / 2) + POS_X(7)), POS_Y(2), KEY_WIDTH, KEY_HEIGHT}, - {&s_key_del, 0x7F, 0, ((KEY_WIDTH / 2) + POS_X(8)), POS_Y(2), DEL_WIDTH, KEY_HEIGHT}, + {&s_key_del,0x7F, 0, ((KEY_WIDTH / 2) + POS_X(8)), POS_Y(2), DEL_WIDTH, KEY_HEIGHT}, //Row 4 - {&s_key_esc, 0x1B, 0, POS_X(0), POS_Y(3), ESC_WIDTH, KEY_HEIGHT}, + {&s_key_esc, 0x1B, 0, POS_X(0), POS_Y(3), ESC_WIDTH, KEY_HEIGHT}, {&s_key_num_switch, 0x90, 0, POS_X(2), POS_Y(3), SWITCH_WIDTH, KEY_HEIGHT}, {&s_key_space, ' ', 0, ((KEY_WIDTH / 2) + POS_X(3)), POS_Y(3), SPACE_WIDTH, KEY_HEIGHT}, - {&s_key_dot, '.', 0, ((KEY_WIDTH / 2) + POS_X(6)), POS_Y(3), DOT_WIDTH, KEY_HEIGHT}, + {&s_key_dot, '.', 0, ((KEY_WIDTH / 2) + POS_X(6)), POS_Y(3), DOT_WIDTH, KEY_HEIGHT}, {&s_key_enter, '\n', 0, POS_X(8), POS_Y(3), ENTER_WIDTH, KEY_HEIGHT}, {0,0,0,0,0,0,0} }; @@ -4326,12 +4276,11 @@ WND_TREE g_number_board_children[] = {&s_key_7, '7', 0, POS_X(0), POS_Y(2), KEY_WIDTH, KEY_HEIGHT}, {&s_key_8, '8', 0, POS_X(1), POS_Y(2), KEY_WIDTH, KEY_HEIGHT}, {&s_key_9, '9', 0, POS_X(2), POS_Y(2), KEY_WIDTH, KEY_HEIGHT}, - - {&s_key_esc, 0x1B, 0, POS_X(0), POS_Y(3), KEY_WIDTH, KEY_HEIGHT}, + {&s_key_esc,0x1B, 0, POS_X(0), POS_Y(3), KEY_WIDTH, KEY_HEIGHT}, {&s_key_0, '0', 0, POS_X(1), POS_Y(3), KEY_WIDTH, KEY_HEIGHT}, - {&s_key_dot, '.', 0, POS_X(2), POS_Y(3), KEY_WIDTH, KEY_HEIGHT}, + {&s_key_dot,'.', 0, POS_X(2), POS_Y(3), KEY_WIDTH, KEY_HEIGHT}, {&s_key_del, 0x7F, 0, POS_X(3), POS_Y(0), KEY_WIDTH, KEY_HEIGHT * 2 + 2}, {&s_key_enter,'\n', 0, POS_X(3), POS_Y(2), KEY_WIDTH, KEY_HEIGHT * 2 + 2}, {0,0,0,0,0,0,0} }; -#endif +#endif \ No newline at end of file diff --git a/Hello3Dwave/UIcode/UIcode.cpp b/Hello3Dwave/UIcode/UIcode.cpp index a11db94e8f536cf24c04679f9ca69e17dcf21859..a1ad232e8bd5ddfc3888a730955ff7164f817b0a 100644 --- a/Hello3Dwave/UIcode/UIcode.cpp +++ b/Hello3Dwave/UIcode/UIcode.cpp @@ -138,21 +138,12 @@ private: float Cwave::points[POINT_CNT][3];//x, y, z // Demo -void create_ui(void* phy_fb, int screen_width, int screen_height, int color_bytes, struct EXTERNAL_GFX_OP* gfx_op) { - if (phy_fb) - { - static c_surface surface(UI_WIDTH, UI_HEIGHT, color_bytes, Z_ORDER_LEVEL_0); - static c_display display(phy_fb, screen_width, screen_height, &surface); - s_surface = &surface; - s_display = &display; - } - else - {//for MCU without framebuffer - static c_surface_no_fb surface_no_fb(UI_WIDTH, UI_HEIGHT, color_bytes, gfx_op, Z_ORDER_LEVEL_0); - static c_display display(phy_fb, screen_width, screen_height, &surface_no_fb); - s_surface = &surface_no_fb; - s_display = &display; - } +void create_ui(void* phy_fb, int screen_width, int screen_height, int color_bytes, struct DISPLAY_DRIVER* driver) { + static c_surface surface(UI_WIDTH, UI_HEIGHT, color_bytes, Z_ORDER_LEVEL_0); + static c_display display(phy_fb, screen_width, screen_height, &surface, driver); + s_surface = &surface; + s_display = &display; + s_surface->fill_rect(0, 0, UI_WIDTH - 1, UI_HEIGHT - 1, 0, Z_ORDER_LEVEL_0); Cwave theCwave; @@ -188,8 +179,8 @@ void create_ui(void* phy_fb, int screen_width, int screen_height, int color_byte } //////////////////////// interface for all platform //////////////////////// -extern "C" void startHello3Dwave(void* phy_fb, int width, int height, int color_bytes, struct EXTERNAL_GFX_OP* gfx_op) { - create_ui(phy_fb, width, height, color_bytes, gfx_op); +extern "C" void startHello3Dwave(void* phy_fb, int width, int height, int color_bytes, struct DISPLAY_DRIVER* driver) { + create_ui(phy_fb, width, height, color_bytes, driver); } extern "C" void* getUiOfHello3Dwave(int* width, int* height, bool force_update) diff --git a/HelloAnimation/BuildLinux/.sync_build.sh b/HelloAnimation/BuildLinux/.sync_build.sh index 49cff5b473ac606967676ebefa6f0d333e301227..a40a99f0ba64af192f4e29cdd25e5988bf1df11c 100644 --- a/HelloAnimation/BuildLinux/.sync_build.sh +++ b/HelloAnimation/BuildLinux/.sync_build.sh @@ -1,5 +1,6 @@ if [ "$#" -ne 1 ]; then - echo "Invalid arguments" + echo "Do testing" + ./xWindow 238 169 | ./HelloAnimation shared-fb exit -1 fi diff --git a/HelloAnimation/UIcode/GuiLite.h b/HelloAnimation/UIcode/GuiLite.h index c4fc88a51476d2c8309c3e55e1270e13784fc510..80550e1632ad7bc82541a2edbb0f7f8f5937954f 100644 --- a/HelloAnimation/UIcode/GuiLite.h +++ b/HelloAnimation/UIcode/GuiLite.h @@ -1,107 +1,94 @@ #pragma once - -#define REAL_TIME_TASK_CYCLE_MS 50 -#define MAX(a,b) (((a)>(b))?(a):(b)) -#define MIN(a,b) (((a)<(b))?(a):(b)) - -#define GL_ARGB(a, r, g, b) ((((unsigned int)(a)) << 24) | (((unsigned int)(r)) << 16) | (((unsigned int)(g)) << 8) | ((unsigned int)(b))) -#define GL_ARGB_A(rgb) ((((unsigned int)(rgb)) >> 24) & 0xFF) - -#define GL_RGB(r, g, b) ((0xFF << 24) | (((unsigned int)(r)) << 16) | (((unsigned int)(g)) << 8) | ((unsigned int)(b))) -#define GL_RGB_R(rgb) ((((unsigned int)(rgb)) >> 16) & 0xFF) -#define GL_RGB_G(rgb) ((((unsigned int)(rgb)) >> 8) & 0xFF) -#define GL_RGB_B(rgb) (((unsigned int)(rgb)) & 0xFF) -#define GL_RGB_32_to_16(rgb) (((((unsigned int)(rgb)) & 0xFF) >> 3) | ((((unsigned int)(rgb)) & 0xFC00) >> 5) | ((((unsigned int)(rgb)) & 0xF80000) >> 8)) -#define GL_RGB_16_to_32(rgb) ((0xFF << 24) | ((((unsigned int)(rgb)) & 0x1F) << 3) | ((((unsigned int)(rgb)) & 0x7E0) << 5) | ((((unsigned int)(rgb)) & 0xF800) << 8)) - -#define ALIGN_HCENTER 0x00000000L -#define ALIGN_LEFT 0x01000000L -#define ALIGN_RIGHT 0x02000000L -#define ALIGN_HMASK 0x03000000L - -#define ALIGN_VCENTER 0x00000000L -#define ALIGN_TOP 0x00100000L -#define ALIGN_BOTTOM 0x00200000L -#define ALIGN_VMASK 0x00300000L - -typedef struct -{ - unsigned short year; - unsigned short month; - unsigned short date; - unsigned short day; - unsigned short hour; - unsigned short minute; - unsigned short second; -}T_TIME; - -void register_debug_function(void(*my_assert)(const char* file, int line), void(*my_log_out)(const char* log)); -void _assert(const char* file, int line); -#define ASSERT(condition) \ - do{ \ - if(!(condition))_assert(__FILE__, __LINE__);\ - }while(0) -void log_out(const char* log); - -long get_time_in_second(); -T_TIME second_to_day(long second); -T_TIME get_time(); - -void start_real_timer(void (*func)(void* arg)); -void register_timer(int milli_second, void func(void* param), void* param); - -unsigned int get_cur_thread_id(); -void create_thread(unsigned long* thread_id, void* attr, void *(*start_routine) (void *), void* arg); -void thread_sleep(unsigned int milli_seconds); -int build_bmp(const char *filename, unsigned int width, unsigned int height, unsigned char *data); - -#define FIFO_BUFFER_LEN 1024 -class c_fifo -{ -public: - c_fifo(); - int read(void* buf, int len); - int write(void* buf, int len); -private: - unsigned char m_buf[FIFO_BUFFER_LEN]; - int m_head; - int m_tail; - void* m_read_sem; - void* m_write_mutex; -}; - -class c_rect -{ -public: - c_rect(){ m_left = m_top = m_right = m_bottom = -1; } - c_rect(int left, int top, int width, int height) - { - set_rect(left, top, width, height); - } - void set_rect(int left, int top, int width, int height) - { - ASSERT(width > 0 && height > 0); - m_left = left; - m_top = top; - m_right = left + width - 1; - m_bottom = top + height -1; - } - bool pt_in_rect(int x, int y) const - { - return x >= m_left && x <= m_right && y >= m_top && y <= m_bottom; - } - int operator==(const c_rect& rect) const - { - return (m_left == rect.m_left) && (m_top == rect.m_top) && (m_right == rect.m_right) && (m_bottom == rect.m_bottom); - } - int width() const { return m_right - m_left + 1; } - int height() const { return m_bottom - m_top + 1 ; } - - int m_left; - int m_top; - int m_right; - int m_bottom; -}; +#define REAL_TIME_TASK_CYCLE_MS 50 +#define MAX(a,b) (((a)>(b))?(a):(b)) +#define MIN(a,b) (((a)<(b))?(a):(b)) +#define GL_ARGB(a, r, g, b) ((((unsigned int)(a)) << 24) | (((unsigned int)(r)) << 16) | (((unsigned int)(g)) << 8) | ((unsigned int)(b))) +#define GL_ARGB_A(rgb) ((((unsigned int)(rgb)) >> 24) & 0xFF) +#define GL_RGB(r, g, b) ((0xFF << 24) | (((unsigned int)(r)) << 16) | (((unsigned int)(g)) << 8) | ((unsigned int)(b))) +#define GL_RGB_R(rgb) ((((unsigned int)(rgb)) >> 16) & 0xFF) +#define GL_RGB_G(rgb) ((((unsigned int)(rgb)) >> 8) & 0xFF) +#define GL_RGB_B(rgb) (((unsigned int)(rgb)) & 0xFF) +#define GL_RGB_32_to_16(rgb) (((((unsigned int)(rgb)) & 0xFF) >> 3) | ((((unsigned int)(rgb)) & 0xFC00) >> 5) | ((((unsigned int)(rgb)) & 0xF80000) >> 8)) +#define GL_RGB_16_to_32(rgb) ((0xFF << 24) | ((((unsigned int)(rgb)) & 0x1F) << 3) | ((((unsigned int)(rgb)) & 0x7E0) << 5) | ((((unsigned int)(rgb)) & 0xF800) << 8)) +#define ALIGN_HCENTER 0x00000000L +#define ALIGN_LEFT 0x01000000L +#define ALIGN_RIGHT 0x02000000L +#define ALIGN_HMASK 0x03000000L +#define ALIGN_VCENTER 0x00000000L +#define ALIGN_TOP 0x00100000L +#define ALIGN_BOTTOM 0x00200000L +#define ALIGN_VMASK 0x00300000L +typedef struct +{ + unsigned short year; + unsigned short month; + unsigned short date; + unsigned short day; + unsigned short hour; + unsigned short minute; + unsigned short second; +}T_TIME; +void register_debug_function(void(*my_assert)(const char* file, int line), void(*my_log_out)(const char* log)); +void _assert(const char* file, int line); +#define ASSERT(condition) \ + do{ \ + if(!(condition))_assert(__FILE__, __LINE__);\ + }while(0) +void log_out(const char* log); +long get_time_in_second(); +T_TIME second_to_day(long second); +T_TIME get_time(); +void start_real_timer(void (*func)(void* arg)); +void register_timer(int milli_second, void func(void* param), void* param); +unsigned int get_cur_thread_id(); +void create_thread(unsigned long* thread_id, void* attr, void *(*start_routine) (void *), void* arg); +void thread_sleep(unsigned int milli_seconds); +int build_bmp(const char *filename, unsigned int width, unsigned int height, unsigned char *data); +#define FIFO_BUFFER_LEN 1024 +class c_fifo +{ +public: + c_fifo(); + int read(void* buf, int len); + int write(void* buf, int len); +private: + unsigned char m_buf[FIFO_BUFFER_LEN]; + int m_head; + int m_tail; + void* m_read_sem; + void* m_write_mutex; +}; +class c_rect +{ +public: + c_rect(){ m_left = m_top = m_right = m_bottom = -1; } + c_rect(int left, int top, int width, int height) + { + set_rect(left, top, width, height); + } + void set_rect(int left, int top, int width, int height) + { + ASSERT(width > 0 && height > 0); + m_left = left; + m_top = top; + m_right = left + width - 1; + m_bottom = top + height -1; + } + bool pt_in_rect(int x, int y) const + { + return x >= m_left && x <= m_right && y >= m_top && y <= m_bottom; + } + int operator==(const c_rect& rect) const + { + return (m_left == rect.m_left) && (m_top == rect.m_top) && (m_right == rect.m_right) && (m_bottom == rect.m_bottom); + } + int width() const { return m_right - m_left + 1; } + int height() const { return m_bottom - m_top + 1 ; } + int m_left; + int m_top; + int m_right; + int m_bottom; +}; //BITMAP typedef struct struct_bitmap_info { @@ -238,7 +225,7 @@ typedef enum Z_ORDER_LEVEL_2,//highest graphic level Z_ORDER_LEVEL_MAX }Z_ORDER_LEVEL; -struct EXTERNAL_GFX_OP +struct DISPLAY_DRIVER { void(*draw_pixel)(int x, int y, unsigned int rgb); void(*fill_rect)(int x0, int y0, int x1, int y1, unsigned int rgb); @@ -247,18 +234,19 @@ class c_surface; class c_display { friend class c_surface; public: - inline c_display(void* phy_fb, int display_width, int display_height, int surface_width, int surface_height, unsigned int color_bytes, int surface_cnt, EXTERNAL_GFX_OP* gfx_op = 0);//multiple surface or surface_no_fb - inline c_display(void* phy_fb, int display_width, int display_height, c_surface* surface);//single custom surface - inline c_surface* alloc_surface(Z_ORDER_LEVEL max_zorder, c_rect layer_rect = c_rect());//for multiple surfaces + inline c_display(void* phy_fb, int display_width, int display_height, c_surface* surface, DISPLAY_DRIVER* driver = 0);//single custom surface + inline c_display(void* phy_fb, int display_width, int display_height, int surface_width, int surface_height, unsigned int color_bytes, int surface_cnt, DISPLAY_DRIVER* driver = 0);//multiple surface + inline c_surface* alloc_surface(Z_ORDER_LEVEL max_zorder, c_rect layer_rect = c_rect());//for slide group inline int swipe_surface(c_surface* s0, c_surface* s1, int x0, int x1, int y0, int y1, int offset); int get_width() { return m_width; } int get_height() { return m_height; } + void* get_phy_fb() { return m_phy_fb; } void* get_updated_fb(int* width, int* height, bool force_update = false) { if (width && height) { - *width = get_width(); - *height = get_height(); + *width = m_width; + *height = m_height; } if (force_update) { @@ -277,35 +265,123 @@ public: { return -1; } - int width = get_width(); - int height = get_height(); //16 bits framebuffer if (m_color_bytes == 2) { - return build_bmp(file_name, width, height, (unsigned char*)m_phy_fb); + return build_bmp(file_name, m_width, m_height, (unsigned char*)m_phy_fb); } //32 bits framebuffer - unsigned short* p_bmp565_data = new unsigned short[width * height]; + unsigned short* p_bmp565_data = new unsigned short[m_width * m_height]; unsigned int* p_raw_data = (unsigned int*)m_phy_fb; - for (int i = 0; i < width * height; i++) + for (int i = 0; i < m_width * m_height; i++) { unsigned int rgb = *p_raw_data++; p_bmp565_data[i] = GL_RGB_32_to_16(rgb); } - int ret = build_bmp(file_name, width, height, (unsigned char*)p_bmp565_data); + int ret = build_bmp(file_name, m_width, m_height, (unsigned char*)p_bmp565_data); delete[]p_bmp565_data; return ret; } -private: - int m_width; //in pixels - int m_height; //in pixels - int m_color_bytes; //16 bits, 32 bits only - void* m_phy_fb; //physical framebuffer +protected: + virtual void draw_pixel(int x, int y, unsigned int rgb) + { + if ((x >= m_width) || (y >= m_height)) { return; } + if (m_driver && m_driver->draw_pixel) + { + return m_driver->draw_pixel(x, y, rgb); + } + if (m_color_bytes == 2) + { + ((unsigned short*)m_phy_fb)[y * m_width + x] = GL_RGB_32_to_16(rgb); + } + else + { + ((unsigned int*)m_phy_fb)[y * m_width + x] = rgb; + } + } + virtual void fill_rect(int x0, int y0, int x1, int y1, unsigned int rgb) + { + if (m_driver && m_driver->fill_rect) + { + return m_driver->fill_rect(x0, y0, x1, y1, rgb); + } + if (m_driver && m_driver->draw_pixel) + { + for (int y = y0; y <= y1; y++) + { + for (int x = x0; x <= x1; x++) + { + m_driver->draw_pixel(x, y, rgb); + } + } + return; + } + register int _width = m_width; + register int _height = m_height; + int x, y; + if (m_color_bytes == 2) + { + unsigned short* phy_fb; + unsigned int rgb_16 = GL_RGB_32_to_16(rgb); + for (y = y0; y <= y1; y++) + { + phy_fb = &((unsigned short*)m_phy_fb)[y * _width + x0]; + for (x = x0; x <= x1; x++) + { + if ((x < _width) && (y < _height)) + { + *phy_fb++ = rgb_16; + } + } + } + } + else + { + unsigned int* phy_fb; + for (y = y0; y <= y1; y++) + { + phy_fb = &((unsigned int*)m_phy_fb)[y * _width + x0]; + for (x = x0; x <= x1; x++) + { + if ((x < _width) && (y < _height)) + { + *phy_fb++ = rgb; + } + } + } + } + } + virtual int flush_screen(int left, int top, int right, int bottom, void* fb, int fb_width) + { + if ((0 == m_phy_fb) || (0 == fb)) + { + return -1; + } + register int _width = m_width; + register int _height = m_height; + left = (left >= _width) ? (_width - 1) : left; + right = (right >= _width) ? (_width - 1) : right; + top = (top >= _height) ? (_height - 1) : top; + bottom = (bottom >= _height) ? (_height - 1) : bottom; + for (int y = top; y < bottom; y++) + { + void* s_addr = (char*)fb + ((y * fb_width + left) * m_color_bytes); + void* d_addr = (char*)m_phy_fb + ((y * _width + left) * m_color_bytes); + memcpy(d_addr, s_addr, (right - left) * m_color_bytes); + } + return 0; + } + int m_width; //in pixels + int m_height; //in pixels + int m_color_bytes; //16/32 bits for default + void* m_phy_fb; //physical framebuffer for default + struct DISPLAY_DRIVER* m_driver; //Rendering by external method without default physical framebuffer int m_phy_read_index; int m_phy_write_index; c_surface* m_surface_group[SURFACE_CNT_MAX]; int m_surface_cnt; //surface count int m_surface_index; + }; class c_layer { @@ -317,12 +393,10 @@ public: class c_surface { friend class c_display; friend class c_bitmap_operator; public: - c_surface(unsigned int width, unsigned int height, unsigned int color_bytes, Z_ORDER_LEVEL max_zorder = Z_ORDER_LEVEL_0, c_rect overlpa_rect = c_rect()) : m_width(width), m_height(height), m_color_bytes(color_bytes), m_fb(0), m_is_active(false), m_top_zorder(Z_ORDER_LEVEL_0), m_phy_fb(0), m_phy_write_index(0), m_display(0) + c_surface(unsigned int width, unsigned int height, unsigned int color_bytes, Z_ORDER_LEVEL max_zorder = Z_ORDER_LEVEL_0, c_rect overlpa_rect = c_rect()) : m_width(width), m_height(height), m_color_bytes(color_bytes), m_fb(0), m_is_active(false), m_top_zorder(Z_ORDER_LEVEL_0), m_phy_write_index(0), m_display(0) { (overlpa_rect == c_rect()) ? set_surface(max_zorder, c_rect(0, 0, width - 1, height - 1)) : set_surface(max_zorder, overlpa_rect); } - int get_width() { return m_width; } - int get_height() { return m_height; } unsigned int get_pixel(int x, int y, unsigned int z_order) { if (x >= m_width || y >= m_height || x < 0 || y < 0 || z_order >= Z_ORDER_LEVEL_MAX) @@ -332,15 +406,15 @@ public: } if (m_layers[z_order].fb) { - return (m_color_bytes == 4) ? ((unsigned int*)(m_layers[z_order].fb))[y * m_width + x] : GL_RGB_16_to_32(((unsigned short*)(m_layers[z_order].fb))[y * m_width + x]); + return (m_color_bytes == 2) ? GL_RGB_16_to_32(((unsigned short*)(m_layers[z_order].fb))[y * m_width + x]) : ((unsigned int*)(m_layers[z_order].fb))[y * m_width + x]; } else if (m_fb) { - return (m_color_bytes == 4) ? ((unsigned int*)m_fb)[y * m_width + x] : GL_RGB_16_to_32(((unsigned short*)m_fb)[y * m_width + x]); + return (m_color_bytes == 2) ? GL_RGB_16_to_32(((unsigned short*)m_fb)[y * m_width + x]) : ((unsigned int*)m_fb)[y * m_width + x]; } - else if (m_phy_fb) + else if (m_display->m_phy_fb) { - return (m_color_bytes == 4) ? ((unsigned int*)m_phy_fb)[y * m_width + x] : GL_RGB_16_to_32(((unsigned short*)m_phy_fb)[y * m_width + x]); + return (m_color_bytes == 2) ? GL_RGB_16_to_32(((unsigned short*)m_display->m_phy_fb)[y * m_width + x]) : ((unsigned int*)m_display->m_phy_fb)[y * m_width + x]; } return 0; } @@ -357,7 +431,7 @@ public: } if (z_order == m_max_zorder) { - return draw_pixel_on_fb(x, y, rgb); + return draw_pixel_low_level(x, y, rgb); } if (z_order > (unsigned int)m_top_zorder) @@ -367,19 +441,19 @@ public: if (m_layers[z_order].rect.pt_in_rect(x, y)) { c_rect layer_rect = m_layers[z_order].rect; - if (m_color_bytes == 4) + if (m_color_bytes == 2) { - ((unsigned int*)(m_layers[z_order].fb))[(x - layer_rect.m_left) + (y - layer_rect.m_top) * layer_rect.width()] = rgb; + ((unsigned short*)(m_layers[z_order].fb))[(x - layer_rect.m_left) + (y - layer_rect.m_top) * layer_rect.width()] = GL_RGB_32_to_16(rgb); } else { - ((unsigned short*)(m_layers[z_order].fb))[(x - layer_rect.m_left) + (y - layer_rect.m_top) * layer_rect.width()] = GL_RGB_32_to_16(rgb); + ((unsigned int*)(m_layers[z_order].fb))[(x - layer_rect.m_left) + (y - layer_rect.m_top) * layer_rect.width()] = rgb; } } if (z_order == m_top_zorder) { - return draw_pixel_on_fb(x, y, rgb); + return draw_pixel_low_level(x, y, rgb); } bool be_overlapped = false; for (unsigned int tmp_z_order = Z_ORDER_LEVEL_MAX - 1; tmp_z_order > z_order; tmp_z_order--) @@ -392,7 +466,7 @@ public: } if (!be_overlapped) { - draw_pixel_on_fb(x, y, rgb); + draw_pixel_low_level(x, y, rgb); } } virtual void fill_rect(int x0, int y0, int x1, int y1, unsigned int rgb, unsigned int z_order) @@ -403,7 +477,7 @@ public: y1 = (y1 > (m_height - 1)) ? (m_height - 1) : y1; if (z_order == m_max_zorder) { - return fill_rect_on_fb(x0, y0, x1, y1, rgb); + return fill_rect_low_level(x0, y0, x1, y1, rgb); } if (z_order == m_top_zorder) { @@ -416,18 +490,18 @@ public: { if (layer_rect.pt_in_rect(x, y)) { - if (m_color_bytes == 4) + if (m_color_bytes == 2) { - ((unsigned int*)m_layers[z_order].fb)[(y - layer_rect.m_top) * layer_rect.width() + (x - layer_rect.m_left)] = rgb; + ((unsigned short*)m_layers[z_order].fb)[(y - layer_rect.m_top) * layer_rect.width() + (x - layer_rect.m_left)] = rgb_16; } else { - ((unsigned short*)m_layers[z_order].fb)[(y - layer_rect.m_top) * layer_rect.width() + (x - layer_rect.m_left)] = rgb_16; + ((unsigned int*)m_layers[z_order].fb)[(y - layer_rect.m_top) * layer_rect.width() + (x - layer_rect.m_left)] = rgb; } } } } - return fill_rect_on_fb(x0, y0, x1, y1, rgb); + return fill_rect_low_level(x0, y0, x1, y1, rgb); } for (; y0 <= y1; y0++) { @@ -499,27 +573,16 @@ public: } int flush_screen(int left, int top, int right, int bottom) { - if (left < 0 || left >= m_width || right < 0 || right >= m_width || - top < 0 || top >= m_height || bottom < 0 || bottom >= m_height) - { - ASSERT(false); - } - if (!m_is_active || (0 == m_phy_fb) || (0 == m_fb)) + if (!m_is_active) { return -1; } - int display_width = m_display->get_width(); - int display_height = m_display->get_height(); - left = (left >= display_width) ? (display_width - 1) : left; - right = (right >= display_width) ? (display_width - 1) : right; - top = (top >= display_height) ? (display_height - 1) : top; - bottom = (bottom >= display_height) ? (display_height - 1) : bottom; - for (int y = top; y < bottom; y++) + if (left < 0 || left >= m_width || right < 0 || right >= m_width || + top < 0 || top >= m_height || bottom < 0 || bottom >= m_height) { - void* s_addr = (char*)m_fb + ((y * m_width + left) * m_color_bytes); - void* d_addr = (char*)m_phy_fb + ((y * display_width + left) * m_color_bytes); - memcpy(d_addr, s_addr, (right - left) * m_color_bytes); + ASSERT(false); } + m_display->flush_screen(left, top, right, bottom, m_fb, m_width); *m_phy_write_index = *m_phy_write_index + 1; return 0; } @@ -537,90 +600,62 @@ public: { for (int x = rect.m_left; x <= rect.m_right; x++) { - unsigned int rgb = (m_color_bytes == 4) ? ((unsigned int*)fb)[(x - layer_rect.m_left) + (y - layer_rect.m_top) * width] : GL_RGB_16_to_32(((unsigned short*)fb)[(x - layer_rect.m_left) + (y - layer_rect.m_top) * width]); - draw_pixel_on_fb(x, y, rgb); + unsigned int rgb = (m_color_bytes == 2) ? GL_RGB_16_to_32(((unsigned short*)fb)[(x - layer_rect.m_left) + (y - layer_rect.m_top) * width]) : ((unsigned int*)fb)[(x - layer_rect.m_left) + (y - layer_rect.m_top) * width]; + draw_pixel_low_level(x, y, rgb); } } return 0; } void set_active(bool flag) { m_is_active = flag; } protected: - virtual void fill_rect_on_fb(int x0, int y0, int x1, int y1, unsigned int rgb) - { - int display_width = m_display->get_width(); - int display_height = m_display->get_height(); - if (m_color_bytes == 4) + virtual void fill_rect_low_level(int x0, int y0, int x1, int y1, unsigned int rgb) + {//fill rect on framebuffer of surface + int x, y; + if (m_color_bytes == 2) { - int x; - unsigned int* fb, * phy_fb; - for (; y0 <= y1; y0++) + unsigned short* fb; + unsigned int rgb_16 = GL_RGB_32_to_16(rgb); + for (y = y0; y <= y1; y++) { - x = x0; - fb = m_fb ? &((unsigned int*)m_fb)[y0 * m_width + x] : 0; - phy_fb = &((unsigned int*)m_phy_fb)[y0 * display_width + x]; - *m_phy_write_index = *m_phy_write_index + 1; - for (; x <= x1; x++) + fb = m_fb ? &((unsigned short*)m_fb)[y * m_width + x0] : 0; + if (!fb) { break; } + for (x = x0; x <= x1; x++) { - if (fb) - { - *fb++ = rgb; - } - if (m_is_active && (x < display_width) && (y0 < display_height)) - { - *phy_fb++ = rgb; - } + *fb++ = rgb_16; } } } - else if (m_color_bytes == 2) + else { - int x; - unsigned short* fb, * phy_fb; - rgb = GL_RGB_32_to_16(rgb); - for (; y0 <= y1; y0++) + unsigned int* fb; + for (y = y0; y <= y1; y++) { - x = x0; - fb = m_fb ? &((unsigned short*)m_fb)[y0 * m_width + x] : 0; - phy_fb = &((unsigned short*)m_phy_fb)[y0 * display_width + x]; - *m_phy_write_index = *m_phy_write_index + 1; - for (; x <= x1; x++) + fb = m_fb ? &((unsigned int*)m_fb)[y * m_width + x0] : 0; + if (!fb) { break; } + for (x = x0; x <= x1; x++) { - if (fb) - { - *fb++ = rgb; - } - if (m_is_active && (x < display_width) && (y0 < display_height)) - { - *phy_fb++ = rgb; - } + *fb++ = rgb; } } } + if (!m_is_active) { return; } + m_display->fill_rect(x0, y0, x1, y1, rgb); + *m_phy_write_index = *m_phy_write_index + 1; } - virtual void draw_pixel_on_fb(int x, int y, unsigned int rgb) + virtual void draw_pixel_low_level(int x, int y, unsigned int rgb) { if (m_fb) - { - (m_color_bytes == 4) ? ((unsigned int*)m_fb)[y * m_width + x] = rgb : ((unsigned short*)m_fb)[y * m_width + x] = GL_RGB_32_to_16(rgb); - } - if (m_is_active && (x < m_display->get_width()) && (y < m_display->get_height())) - { - if (m_color_bytes == 4) - { - ((unsigned int*)m_phy_fb)[y * (m_display->get_width()) + x] = rgb; - } - else - { - ((unsigned short*)m_phy_fb)[y * (m_display->get_width()) + x] = GL_RGB_32_to_16(rgb); - } - *m_phy_write_index = *m_phy_write_index + 1; + {//draw pixel on framebuffer of surface + (m_color_bytes == 2) ? ((unsigned short*)m_fb)[y * m_width + x] = GL_RGB_32_to_16(rgb): ((unsigned int*)m_fb)[y * m_width + x] = rgb; } + if (!m_is_active) { return; } + m_display->draw_pixel(x, y, rgb); + *m_phy_write_index = *m_phy_write_index + 1; } void attach_display(c_display* display) { ASSERT(display); m_display = display; - m_phy_fb = display->m_phy_fb; m_phy_write_index = &display->m_phy_write_index; } void set_surface(Z_ORDER_LEVEL max_z_order, c_rect layer_rect) @@ -638,87 +673,22 @@ protected: } int m_width; //in pixels int m_height; //in pixels - int m_color_bytes; //16 bits, 32 bits only + int m_color_bytes; //16 bits, 32 bits for default void* m_fb; //frame buffer you could see c_layer m_layers[Z_ORDER_LEVEL_MAX];//all graphic layers bool m_is_active; //active flag Z_ORDER_LEVEL m_max_zorder; //the highest graphic layer the surface will have Z_ORDER_LEVEL m_top_zorder; //the current highest graphic layer the surface have - void* m_phy_fb; //physical framebufer int* m_phy_write_index; c_display* m_display; }; -class c_surface_no_fb : public c_surface {//No physical framebuffer, render with external graphic interface - friend class c_display; -public: - c_surface_no_fb(unsigned int width, unsigned int height, unsigned int color_bytes, struct EXTERNAL_GFX_OP* gfx_op, Z_ORDER_LEVEL max_zorder = Z_ORDER_LEVEL_0, c_rect overlpa_rect = c_rect()) : c_surface(width, height, color_bytes, max_zorder, overlpa_rect), m_gfx_op(gfx_op) {} -protected: - virtual void fill_rect_on_fb(int x0, int y0, int x1, int y1, unsigned int rgb) - { - if (!m_gfx_op) - { - return; - } - if (m_gfx_op->fill_rect) - { - return m_gfx_op->fill_rect(x0, y0, x1, y1, rgb); - } - if (m_gfx_op->draw_pixel && m_is_active) - { - for (int y = y0; y <= y1; y++) - { - for (int x = x0; x <= x1; x++) - { - m_gfx_op->draw_pixel(x, y, rgb); - } - } - } - if (!m_fb) { return; } - if (m_color_bytes == 4) - { - unsigned int* fb; - for (int y = y0; y <= y1; y++) - { - fb = &((unsigned int*)m_fb)[y0 * m_width + x0]; - for (int x = x0; x <= x1; x++) - { - *fb++ = rgb; - } - } - } - else if (m_color_bytes == 2) - { - unsigned short* fb; - rgb = GL_RGB_32_to_16(rgb); - for (int y = y0; y <= y1; y++) - { - fb = &((unsigned short*)m_fb)[y0 * m_width + x0]; - for (int x = x0; x <= x1; x++) - { - *fb++ = rgb; - } - } - } - } - virtual void draw_pixel_on_fb(int x, int y, unsigned int rgb) - { - if (m_gfx_op && m_gfx_op->draw_pixel && m_is_active) - { - m_gfx_op->draw_pixel(x, y, rgb); - } - if (!m_fb) { return; } - if (m_color_bytes == 4) - { - ((unsigned int*)m_fb)[y * m_width + x] = rgb; - } - else if (m_color_bytes == 2) - { - ((unsigned short*)m_fb)[y * m_width + x] = GL_RGB_32_to_16(rgb); - } - } - struct EXTERNAL_GFX_OP* m_gfx_op;//Rendering by external method -}; -inline c_display::c_display(void* phy_fb, int display_width, int display_height, int surface_width, int surface_height, unsigned int color_bytes, int surface_cnt, EXTERNAL_GFX_OP* gfx_op) : m_width(display_width), m_height(display_height), m_color_bytes(color_bytes), m_phy_fb(phy_fb), m_phy_read_index(0), m_phy_write_index(0), m_surface_cnt(surface_cnt), m_surface_index(0) +inline c_display::c_display(void* phy_fb, int display_width, int display_height, c_surface* surface, DISPLAY_DRIVER* driver) : m_phy_fb(phy_fb), m_width(display_width), m_height(display_height), m_driver(driver), m_phy_read_index(0), m_phy_write_index(0), m_surface_cnt(1), m_surface_index(0) +{ + m_color_bytes = surface->m_color_bytes; + surface->m_is_active = true; + (m_surface_group[0] = surface)->attach_display(this); +} +inline c_display::c_display(void* phy_fb, int display_width, int display_height, int surface_width, int surface_height, unsigned int color_bytes, int surface_cnt, DISPLAY_DRIVER* driver) : m_phy_fb(phy_fb), m_width(display_width), m_height(display_height), m_color_bytes(color_bytes), m_phy_read_index(0), m_phy_write_index(0), m_surface_cnt(surface_cnt), m_driver(driver), m_surface_index(0) { ASSERT(color_bytes == 2 || color_bytes == 4); ASSERT(m_surface_cnt <= SURFACE_CNT_MAX); @@ -726,16 +696,10 @@ inline c_display::c_display(void* phy_fb, int display_width, int display_height, for (int i = 0; i < m_surface_cnt; i++) { - m_surface_group[i] = (phy_fb) ? new c_surface(surface_width, surface_height, color_bytes) : new c_surface_no_fb(surface_width, surface_height, color_bytes, gfx_op); + m_surface_group[i] = new c_surface(surface_width, surface_height, color_bytes); m_surface_group[i]->attach_display(this); } } -inline c_display::c_display(void* phy_fb, int display_width, int display_height, c_surface* surface) : m_width(display_width), m_height(display_height), m_phy_fb(phy_fb), m_phy_read_index(0), m_phy_write_index(0), m_surface_cnt(1), m_surface_index(0) -{ - m_color_bytes = surface->m_color_bytes; - surface->m_is_active = true; - (m_surface_group[0] = surface)->attach_display(this); -} inline c_surface* c_display::alloc_surface(Z_ORDER_LEVEL max_zorder, c_rect layer_rect) { ASSERT(max_zorder < Z_ORDER_LEVEL_MAX && m_surface_index < m_surface_cnt); @@ -744,8 +708,8 @@ inline c_surface* c_display::alloc_surface(Z_ORDER_LEVEL max_zorder, c_rect laye } inline int c_display::swipe_surface(c_surface* s0, c_surface* s1, int x0, int x1, int y0, int y1, int offset) { - int surface_width = s0->get_width(); - int surface_height = s0->get_height(); + register int surface_width = s0->m_width; + register int surface_height = s0->m_height; if (offset < 0 || offset > surface_width || y0 < 0 || y0 >= surface_height || y1 < 0 || y1 >= surface_height || x0 < 0 || x0 >= surface_width || x1 < 0 || x1 >= surface_width) { @@ -767,46 +731,46 @@ inline int c_display::swipe_surface(c_surface* s0, c_surface* s1, int x0, int x1 for (int y = y0; y <= y1; y++) { //Left surface - char* addr_s = ((char*)(s0->m_fb) + (y * (s0->get_width()) + x0 + offset) * m_color_bytes); + char* addr_s = ((char*)(s0->m_fb) + (y * surface_width + x0 + offset) * m_color_bytes); char* addr_d = ((char*)(m_phy_fb)+(y * m_width + x0) * m_color_bytes); memcpy(addr_d, addr_s, (width - offset) * m_color_bytes); //Right surface - addr_s = ((char*)(s1->m_fb) + (y * (s1->get_width()) + x0) * m_color_bytes); + addr_s = ((char*)(s1->m_fb) + (y * surface_width + x0) * m_color_bytes); addr_d = ((char*)(m_phy_fb)+(y * m_width + x0 + (width - offset)) * m_color_bytes); memcpy(addr_d, addr_s, offset * m_color_bytes); } } - else if (m_color_bytes == 4) + else if (m_color_bytes == 2) { - void(*draw_pixel)(int x, int y, unsigned int rgb) = ((c_surface_no_fb*)s0)->m_gfx_op->draw_pixel; + void(*draw_pixel)(int x, int y, unsigned int rgb) = m_driver->draw_pixel; for (int y = y0; y <= y1; y++) { //Left surface for (int x = x0; x <= (x1 - offset); x++) { - draw_pixel(x, y, ((unsigned int*)s0->m_fb)[y * m_width + x + offset]); + draw_pixel(x, y, GL_RGB_16_to_32(((unsigned short*)s0->m_fb)[y * m_width + x + offset])); } //Right surface for (int x = x1 - offset; x <= x1; x++) { - draw_pixel(x, y, ((unsigned int*)s1->m_fb)[y * m_width + x + offset - x1 + x0]); + draw_pixel(x, y, GL_RGB_16_to_32(((unsigned short*)s1->m_fb)[y * m_width + x + offset - x1 + x0])); } } } - else if (m_color_bytes == 2) + else //m_color_bytes == 3/4... { - void(*draw_pixel)(int x, int y, unsigned int rgb) = ((c_surface_no_fb*)s0)->m_gfx_op->draw_pixel; + void(*draw_pixel)(int x, int y, unsigned int rgb) = m_driver->draw_pixel; for (int y = y0; y <= y1; y++) { //Left surface for (int x = x0; x <= (x1 - offset); x++) { - draw_pixel(x, y, GL_RGB_16_to_32(((unsigned short*)s0->m_fb)[y * m_width + x + offset])); + draw_pixel(x, y, ((unsigned int*)s0->m_fb)[y * m_width + x + offset]); } //Right surface for (int x = x1 - offset; x <= x1; x++) { - draw_pixel(x, y, GL_RGB_16_to_32(((unsigned short*)s1->m_fb)[y * m_width + x + offset - x1 + x0])); + draw_pixel(x, y, ((unsigned int*)s1->m_fb)[y * m_width + x + offset - x1 + x0]); } } } @@ -3407,22 +3371,12 @@ private: #ifdef GUILITE_ON c_bitmap_operator the_bitmap_op = c_bitmap_operator(); c_image_operator* c_image::image_operator = &the_bitmap_op; +const void* c_theme::s_font_map[FONT_MAX]; +const void* c_theme::s_image_map[IMAGE_MAX]; +unsigned int c_theme::s_color_map[COLOR_MAX]; +c_lattice_font_op the_lattice_font_op = c_lattice_font_op(); +c_font_operator* c_word::fontOperator = &the_lattice_font_op; #endif - -#ifdef GUILITE_ON - -const void* c_theme::s_font_map[FONT_MAX]; -const void* c_theme::s_image_map[IMAGE_MAX]; -unsigned int c_theme::s_color_map[COLOR_MAX]; - -#endif - -#ifdef GUILITE_ON - -c_lattice_font_op the_lattice_font_op = c_lattice_font_op(); -c_font_operator* c_word::fontOperator = &the_lattice_font_op; - -#endif #ifdef GUILITE_ON #if (defined __linux__) || (defined __APPLE__) #include @@ -4264,11 +4218,7 @@ int c_fifo::write(void* buf, int len) #endif #ifdef GUILITE_ON DIALOG_ARRAY c_dialog::ms_the_dialogs[SURFACE_CNT_MAX]; -#endif -#ifdef GUILITE_ON c_keyboard c_edit::s_keyboard; -#endif -#ifdef GUILITE_ON static c_keyboard_button s_key_0, s_key_1, s_key_2, s_key_3, s_key_4, s_key_5, s_key_6, s_key_7, s_key_8, s_key_9; static c_keyboard_button s_key_A, s_key_B, s_key_C, s_key_D, s_key_E, s_key_F, s_key_G, s_key_H, s_key_I, s_key_J; static c_keyboard_button s_key_K, s_key_L, s_key_M, s_key_N, s_key_O, s_key_P, s_key_Q, s_key_R, s_key_S, s_key_T; @@ -4306,12 +4256,12 @@ WND_TREE g_key_board_children[] = {&s_key_B, 'B', 0, ((KEY_WIDTH / 2) + POS_X(5)), POS_Y(2), KEY_WIDTH, KEY_HEIGHT}, {&s_key_N, 'N', 0, ((KEY_WIDTH / 2) + POS_X(6)), POS_Y(2), KEY_WIDTH, KEY_HEIGHT}, {&s_key_M, 'M', 0, ((KEY_WIDTH / 2) + POS_X(7)), POS_Y(2), KEY_WIDTH, KEY_HEIGHT}, - {&s_key_del, 0x7F, 0, ((KEY_WIDTH / 2) + POS_X(8)), POS_Y(2), DEL_WIDTH, KEY_HEIGHT}, + {&s_key_del,0x7F, 0, ((KEY_WIDTH / 2) + POS_X(8)), POS_Y(2), DEL_WIDTH, KEY_HEIGHT}, //Row 4 - {&s_key_esc, 0x1B, 0, POS_X(0), POS_Y(3), ESC_WIDTH, KEY_HEIGHT}, + {&s_key_esc, 0x1B, 0, POS_X(0), POS_Y(3), ESC_WIDTH, KEY_HEIGHT}, {&s_key_num_switch, 0x90, 0, POS_X(2), POS_Y(3), SWITCH_WIDTH, KEY_HEIGHT}, {&s_key_space, ' ', 0, ((KEY_WIDTH / 2) + POS_X(3)), POS_Y(3), SPACE_WIDTH, KEY_HEIGHT}, - {&s_key_dot, '.', 0, ((KEY_WIDTH / 2) + POS_X(6)), POS_Y(3), DOT_WIDTH, KEY_HEIGHT}, + {&s_key_dot, '.', 0, ((KEY_WIDTH / 2) + POS_X(6)), POS_Y(3), DOT_WIDTH, KEY_HEIGHT}, {&s_key_enter, '\n', 0, POS_X(8), POS_Y(3), ENTER_WIDTH, KEY_HEIGHT}, {0,0,0,0,0,0,0} }; @@ -4326,12 +4276,11 @@ WND_TREE g_number_board_children[] = {&s_key_7, '7', 0, POS_X(0), POS_Y(2), KEY_WIDTH, KEY_HEIGHT}, {&s_key_8, '8', 0, POS_X(1), POS_Y(2), KEY_WIDTH, KEY_HEIGHT}, {&s_key_9, '9', 0, POS_X(2), POS_Y(2), KEY_WIDTH, KEY_HEIGHT}, - - {&s_key_esc, 0x1B, 0, POS_X(0), POS_Y(3), KEY_WIDTH, KEY_HEIGHT}, + {&s_key_esc,0x1B, 0, POS_X(0), POS_Y(3), KEY_WIDTH, KEY_HEIGHT}, {&s_key_0, '0', 0, POS_X(1), POS_Y(3), KEY_WIDTH, KEY_HEIGHT}, - {&s_key_dot, '.', 0, POS_X(2), POS_Y(3), KEY_WIDTH, KEY_HEIGHT}, + {&s_key_dot,'.', 0, POS_X(2), POS_Y(3), KEY_WIDTH, KEY_HEIGHT}, {&s_key_del, 0x7F, 0, POS_X(3), POS_Y(0), KEY_WIDTH, KEY_HEIGHT * 2 + 2}, {&s_key_enter,'\n', 0, POS_X(3), POS_Y(2), KEY_WIDTH, KEY_HEIGHT * 2 + 2}, {0,0,0,0,0,0,0} }; -#endif +#endif \ No newline at end of file diff --git a/HelloCircle/BuildAppleWatch/HelloCircle WatchKit Extension/HelloCircle WatchKit Extension-Bridging-Header.h b/HelloCircle/BuildAppleWatch/HelloCircle WatchKit Extension/HelloCircle WatchKit Extension-Bridging-Header.h index e685537cf1eed2522881bcaae85854486338dcfc..331721faf5445475157a1d1adfb938cf1fdc152b 100644 --- a/HelloCircle/BuildAppleWatch/HelloCircle WatchKit Extension/HelloCircle WatchKit Extension-Bridging-Header.h +++ b/HelloCircle/BuildAppleWatch/HelloCircle WatchKit Extension/HelloCircle WatchKit Extension-Bridging-Header.h @@ -8,7 +8,7 @@ extern "C"{ #endif - void startHelloCircle(void* phy_fb, int width, int height, int color_bytes, struct EXTERNAL_GFX_OP* gfx_op); + void startHelloCircle(void* phy_fb, int width, int height, int color_bytes, struct DISPLAY_DRIVER* driver); void* getUiOfHelloCircle(int* width, int* height, bool force_update); #ifdef __cplusplus diff --git a/HelloCircle/BuildLinux/.sync_build.sh b/HelloCircle/BuildLinux/.sync_build.sh index 49cff5b473ac606967676ebefa6f0d333e301227..c46888e1135b2cccfce7a02d5bb2b9b5127972c1 100644 --- a/HelloCircle/BuildLinux/.sync_build.sh +++ b/HelloCircle/BuildLinux/.sync_build.sh @@ -1,5 +1,6 @@ if [ "$#" -ne 1 ]; then - echo "Invalid arguments" + echo "Do testing" + ./xWindow 240 320 | ./HelloCircle shared-fb exit -1 fi diff --git a/HelloCircle/BuildLinux/main.cpp b/HelloCircle/BuildLinux/main.cpp index 9204e8cc67fed7e68996af973bdc6e6bece052d5..49d54dccc664f7f5cf8f7dc71c57e0e181cd85fa 100644 --- a/HelloCircle/BuildLinux/main.cpp +++ b/HelloCircle/BuildLinux/main.cpp @@ -10,7 +10,7 @@ #include #include -extern "C" void startHelloCircle(void* phy_fb, int width, int height, int color_bytes, struct EXTERNAL_GFX_OP* gfx_op); +extern "C" void startHelloCircle(void* phy_fb, int width, int height, int color_bytes, struct DISPLAY_DRIVER* driver); extern void init_std_io(); static void* get_embeded_fb_in_display_app(int shared_id); diff --git a/HelloCircle/BuildMFC/HelloCircleDlg.cpp b/HelloCircle/BuildMFC/HelloCircleDlg.cpp index 2bd4c6e385725a9218dc8727697210fe6354e370..50fe4eb89c29868d926dcbdf334c0263dce42076 100644 Binary files a/HelloCircle/BuildMFC/HelloCircleDlg.cpp and b/HelloCircle/BuildMFC/HelloCircleDlg.cpp differ diff --git a/HelloCircle/BuildMFC/HelloCircleDlg.h b/HelloCircle/BuildMFC/HelloCircleDlg.h index 17d8d43d7cea9a612e02207ff64060c7fb2a8da4..e3d4f87107d9a058eed956791dc6b5918b8cc492 100644 Binary files a/HelloCircle/BuildMFC/HelloCircleDlg.h and b/HelloCircle/BuildMFC/HelloCircleDlg.h differ diff --git a/HelloCircle/BuildQt/mainwindow.cpp b/HelloCircle/BuildQt/mainwindow.cpp index 628b979bcf57dc7e7533d98894c1d90076bd53fc..6d9e24625c0db7f0607d183832acb2dadcd287d4 100644 --- a/HelloCircle/BuildQt/mainwindow.cpp +++ b/HelloCircle/BuildQt/mainwindow.cpp @@ -10,7 +10,7 @@ #include #include -extern "C" void startHelloCircle(void* phy_fb, int width, int height, int color_bytes, struct EXTERNAL_GFX_OP* gfx_op); +extern "C" void startHelloCircle(void* phy_fb, int width, int height, int color_bytes, struct DISPLAY_DRIVER* driver); extern "C" void* getUiOfHelloCircle(int* width, int* height, bool force_update); #define UI_WIDTH 480 diff --git a/HelloCircle/BuildSTM32F103-Keil/USER/main.c b/HelloCircle/BuildSTM32F103-Keil/USER/main.c index 69907b9e21a9b5633e217819ed4f065cccd4254b..85337a8da02e22da1fb5532ccd5b0fb79265983a 100644 --- a/HelloCircle/BuildSTM32F103-Keil/USER/main.c +++ b/HelloCircle/BuildSTM32F103-Keil/USER/main.c @@ -15,12 +15,12 @@ void gfx_draw_pixel(int x, int y, unsigned int rgb) //void gfx_fill_rect(int x0, int y0, int x1, int y1, unsigned int rgb){} //UI entry -struct EXTERNAL_GFX_OP +struct DISPLAY_DRIVER { void (*draw_pixel)(int x, int y, unsigned int rgb); void (*fill_rect)(int x0, int y0, int x1, int y1, unsigned int rgb); -} my_gfx_op; -extern void startHelloCircle(void* phy_fb, int width, int height, int color_bytes, struct EXTERNAL_GFX_OP* gfx_op); +} my_driver; +extern void startHelloCircle(void* phy_fb, int width, int height, int color_bytes, struct DISPLAY_DRIVER* driver); int main(void) { @@ -30,8 +30,8 @@ int main(void) LCD_Init(); //Link your LCD driver & start UI: - my_gfx_op.draw_pixel = gfx_draw_pixel; - my_gfx_op.fill_rect = NULL;//gfx_fill_rect; - startHelloCircle(NULL, 240, 320, 2, &my_gfx_op); + my_driver.draw_pixel = gfx_draw_pixel; + my_driver.fill_rect = NULL;//gfx_fill_rect; + startHelloCircle(NULL, 240, 320, 2, &my_driver); while(1); } diff --git a/HelloCircle/BuildWin32/HelloCircle.cpp b/HelloCircle/BuildWin32/HelloCircle.cpp index d38e9c3d6fa5fb3102d17163d13f366becbe408d..e22aef42f41ad8f76c433216553bf8d831175f63 100644 --- a/HelloCircle/BuildWin32/HelloCircle.cpp +++ b/HelloCircle/BuildWin32/HelloCircle.cpp @@ -161,7 +161,7 @@ LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam) } //////////////////////// HelloCircle Interface //////////////////////// -extern "C" void startHelloCircle(void* phy_fb, int width, int height, int color_bytes, struct EXTERNAL_GFX_OP* gfx_op); +extern "C" void startHelloCircle(void* phy_fb, int width, int height, int color_bytes, struct DISPLAY_DRIVER* driver); DWORD WINAPI ThreadHelloCircle(LPVOID pParam) { diff --git a/HelloCircle/UIcode/GuiLite.h b/HelloCircle/UIcode/GuiLite.h index c4fc88a51476d2c8309c3e55e1270e13784fc510..80550e1632ad7bc82541a2edbb0f7f8f5937954f 100644 --- a/HelloCircle/UIcode/GuiLite.h +++ b/HelloCircle/UIcode/GuiLite.h @@ -1,107 +1,94 @@ #pragma once - -#define REAL_TIME_TASK_CYCLE_MS 50 -#define MAX(a,b) (((a)>(b))?(a):(b)) -#define MIN(a,b) (((a)<(b))?(a):(b)) - -#define GL_ARGB(a, r, g, b) ((((unsigned int)(a)) << 24) | (((unsigned int)(r)) << 16) | (((unsigned int)(g)) << 8) | ((unsigned int)(b))) -#define GL_ARGB_A(rgb) ((((unsigned int)(rgb)) >> 24) & 0xFF) - -#define GL_RGB(r, g, b) ((0xFF << 24) | (((unsigned int)(r)) << 16) | (((unsigned int)(g)) << 8) | ((unsigned int)(b))) -#define GL_RGB_R(rgb) ((((unsigned int)(rgb)) >> 16) & 0xFF) -#define GL_RGB_G(rgb) ((((unsigned int)(rgb)) >> 8) & 0xFF) -#define GL_RGB_B(rgb) (((unsigned int)(rgb)) & 0xFF) -#define GL_RGB_32_to_16(rgb) (((((unsigned int)(rgb)) & 0xFF) >> 3) | ((((unsigned int)(rgb)) & 0xFC00) >> 5) | ((((unsigned int)(rgb)) & 0xF80000) >> 8)) -#define GL_RGB_16_to_32(rgb) ((0xFF << 24) | ((((unsigned int)(rgb)) & 0x1F) << 3) | ((((unsigned int)(rgb)) & 0x7E0) << 5) | ((((unsigned int)(rgb)) & 0xF800) << 8)) - -#define ALIGN_HCENTER 0x00000000L -#define ALIGN_LEFT 0x01000000L -#define ALIGN_RIGHT 0x02000000L -#define ALIGN_HMASK 0x03000000L - -#define ALIGN_VCENTER 0x00000000L -#define ALIGN_TOP 0x00100000L -#define ALIGN_BOTTOM 0x00200000L -#define ALIGN_VMASK 0x00300000L - -typedef struct -{ - unsigned short year; - unsigned short month; - unsigned short date; - unsigned short day; - unsigned short hour; - unsigned short minute; - unsigned short second; -}T_TIME; - -void register_debug_function(void(*my_assert)(const char* file, int line), void(*my_log_out)(const char* log)); -void _assert(const char* file, int line); -#define ASSERT(condition) \ - do{ \ - if(!(condition))_assert(__FILE__, __LINE__);\ - }while(0) -void log_out(const char* log); - -long get_time_in_second(); -T_TIME second_to_day(long second); -T_TIME get_time(); - -void start_real_timer(void (*func)(void* arg)); -void register_timer(int milli_second, void func(void* param), void* param); - -unsigned int get_cur_thread_id(); -void create_thread(unsigned long* thread_id, void* attr, void *(*start_routine) (void *), void* arg); -void thread_sleep(unsigned int milli_seconds); -int build_bmp(const char *filename, unsigned int width, unsigned int height, unsigned char *data); - -#define FIFO_BUFFER_LEN 1024 -class c_fifo -{ -public: - c_fifo(); - int read(void* buf, int len); - int write(void* buf, int len); -private: - unsigned char m_buf[FIFO_BUFFER_LEN]; - int m_head; - int m_tail; - void* m_read_sem; - void* m_write_mutex; -}; - -class c_rect -{ -public: - c_rect(){ m_left = m_top = m_right = m_bottom = -1; } - c_rect(int left, int top, int width, int height) - { - set_rect(left, top, width, height); - } - void set_rect(int left, int top, int width, int height) - { - ASSERT(width > 0 && height > 0); - m_left = left; - m_top = top; - m_right = left + width - 1; - m_bottom = top + height -1; - } - bool pt_in_rect(int x, int y) const - { - return x >= m_left && x <= m_right && y >= m_top && y <= m_bottom; - } - int operator==(const c_rect& rect) const - { - return (m_left == rect.m_left) && (m_top == rect.m_top) && (m_right == rect.m_right) && (m_bottom == rect.m_bottom); - } - int width() const { return m_right - m_left + 1; } - int height() const { return m_bottom - m_top + 1 ; } - - int m_left; - int m_top; - int m_right; - int m_bottom; -}; +#define REAL_TIME_TASK_CYCLE_MS 50 +#define MAX(a,b) (((a)>(b))?(a):(b)) +#define MIN(a,b) (((a)<(b))?(a):(b)) +#define GL_ARGB(a, r, g, b) ((((unsigned int)(a)) << 24) | (((unsigned int)(r)) << 16) | (((unsigned int)(g)) << 8) | ((unsigned int)(b))) +#define GL_ARGB_A(rgb) ((((unsigned int)(rgb)) >> 24) & 0xFF) +#define GL_RGB(r, g, b) ((0xFF << 24) | (((unsigned int)(r)) << 16) | (((unsigned int)(g)) << 8) | ((unsigned int)(b))) +#define GL_RGB_R(rgb) ((((unsigned int)(rgb)) >> 16) & 0xFF) +#define GL_RGB_G(rgb) ((((unsigned int)(rgb)) >> 8) & 0xFF) +#define GL_RGB_B(rgb) (((unsigned int)(rgb)) & 0xFF) +#define GL_RGB_32_to_16(rgb) (((((unsigned int)(rgb)) & 0xFF) >> 3) | ((((unsigned int)(rgb)) & 0xFC00) >> 5) | ((((unsigned int)(rgb)) & 0xF80000) >> 8)) +#define GL_RGB_16_to_32(rgb) ((0xFF << 24) | ((((unsigned int)(rgb)) & 0x1F) << 3) | ((((unsigned int)(rgb)) & 0x7E0) << 5) | ((((unsigned int)(rgb)) & 0xF800) << 8)) +#define ALIGN_HCENTER 0x00000000L +#define ALIGN_LEFT 0x01000000L +#define ALIGN_RIGHT 0x02000000L +#define ALIGN_HMASK 0x03000000L +#define ALIGN_VCENTER 0x00000000L +#define ALIGN_TOP 0x00100000L +#define ALIGN_BOTTOM 0x00200000L +#define ALIGN_VMASK 0x00300000L +typedef struct +{ + unsigned short year; + unsigned short month; + unsigned short date; + unsigned short day; + unsigned short hour; + unsigned short minute; + unsigned short second; +}T_TIME; +void register_debug_function(void(*my_assert)(const char* file, int line), void(*my_log_out)(const char* log)); +void _assert(const char* file, int line); +#define ASSERT(condition) \ + do{ \ + if(!(condition))_assert(__FILE__, __LINE__);\ + }while(0) +void log_out(const char* log); +long get_time_in_second(); +T_TIME second_to_day(long second); +T_TIME get_time(); +void start_real_timer(void (*func)(void* arg)); +void register_timer(int milli_second, void func(void* param), void* param); +unsigned int get_cur_thread_id(); +void create_thread(unsigned long* thread_id, void* attr, void *(*start_routine) (void *), void* arg); +void thread_sleep(unsigned int milli_seconds); +int build_bmp(const char *filename, unsigned int width, unsigned int height, unsigned char *data); +#define FIFO_BUFFER_LEN 1024 +class c_fifo +{ +public: + c_fifo(); + int read(void* buf, int len); + int write(void* buf, int len); +private: + unsigned char m_buf[FIFO_BUFFER_LEN]; + int m_head; + int m_tail; + void* m_read_sem; + void* m_write_mutex; +}; +class c_rect +{ +public: + c_rect(){ m_left = m_top = m_right = m_bottom = -1; } + c_rect(int left, int top, int width, int height) + { + set_rect(left, top, width, height); + } + void set_rect(int left, int top, int width, int height) + { + ASSERT(width > 0 && height > 0); + m_left = left; + m_top = top; + m_right = left + width - 1; + m_bottom = top + height -1; + } + bool pt_in_rect(int x, int y) const + { + return x >= m_left && x <= m_right && y >= m_top && y <= m_bottom; + } + int operator==(const c_rect& rect) const + { + return (m_left == rect.m_left) && (m_top == rect.m_top) && (m_right == rect.m_right) && (m_bottom == rect.m_bottom); + } + int width() const { return m_right - m_left + 1; } + int height() const { return m_bottom - m_top + 1 ; } + int m_left; + int m_top; + int m_right; + int m_bottom; +}; //BITMAP typedef struct struct_bitmap_info { @@ -238,7 +225,7 @@ typedef enum Z_ORDER_LEVEL_2,//highest graphic level Z_ORDER_LEVEL_MAX }Z_ORDER_LEVEL; -struct EXTERNAL_GFX_OP +struct DISPLAY_DRIVER { void(*draw_pixel)(int x, int y, unsigned int rgb); void(*fill_rect)(int x0, int y0, int x1, int y1, unsigned int rgb); @@ -247,18 +234,19 @@ class c_surface; class c_display { friend class c_surface; public: - inline c_display(void* phy_fb, int display_width, int display_height, int surface_width, int surface_height, unsigned int color_bytes, int surface_cnt, EXTERNAL_GFX_OP* gfx_op = 0);//multiple surface or surface_no_fb - inline c_display(void* phy_fb, int display_width, int display_height, c_surface* surface);//single custom surface - inline c_surface* alloc_surface(Z_ORDER_LEVEL max_zorder, c_rect layer_rect = c_rect());//for multiple surfaces + inline c_display(void* phy_fb, int display_width, int display_height, c_surface* surface, DISPLAY_DRIVER* driver = 0);//single custom surface + inline c_display(void* phy_fb, int display_width, int display_height, int surface_width, int surface_height, unsigned int color_bytes, int surface_cnt, DISPLAY_DRIVER* driver = 0);//multiple surface + inline c_surface* alloc_surface(Z_ORDER_LEVEL max_zorder, c_rect layer_rect = c_rect());//for slide group inline int swipe_surface(c_surface* s0, c_surface* s1, int x0, int x1, int y0, int y1, int offset); int get_width() { return m_width; } int get_height() { return m_height; } + void* get_phy_fb() { return m_phy_fb; } void* get_updated_fb(int* width, int* height, bool force_update = false) { if (width && height) { - *width = get_width(); - *height = get_height(); + *width = m_width; + *height = m_height; } if (force_update) { @@ -277,35 +265,123 @@ public: { return -1; } - int width = get_width(); - int height = get_height(); //16 bits framebuffer if (m_color_bytes == 2) { - return build_bmp(file_name, width, height, (unsigned char*)m_phy_fb); + return build_bmp(file_name, m_width, m_height, (unsigned char*)m_phy_fb); } //32 bits framebuffer - unsigned short* p_bmp565_data = new unsigned short[width * height]; + unsigned short* p_bmp565_data = new unsigned short[m_width * m_height]; unsigned int* p_raw_data = (unsigned int*)m_phy_fb; - for (int i = 0; i < width * height; i++) + for (int i = 0; i < m_width * m_height; i++) { unsigned int rgb = *p_raw_data++; p_bmp565_data[i] = GL_RGB_32_to_16(rgb); } - int ret = build_bmp(file_name, width, height, (unsigned char*)p_bmp565_data); + int ret = build_bmp(file_name, m_width, m_height, (unsigned char*)p_bmp565_data); delete[]p_bmp565_data; return ret; } -private: - int m_width; //in pixels - int m_height; //in pixels - int m_color_bytes; //16 bits, 32 bits only - void* m_phy_fb; //physical framebuffer +protected: + virtual void draw_pixel(int x, int y, unsigned int rgb) + { + if ((x >= m_width) || (y >= m_height)) { return; } + if (m_driver && m_driver->draw_pixel) + { + return m_driver->draw_pixel(x, y, rgb); + } + if (m_color_bytes == 2) + { + ((unsigned short*)m_phy_fb)[y * m_width + x] = GL_RGB_32_to_16(rgb); + } + else + { + ((unsigned int*)m_phy_fb)[y * m_width + x] = rgb; + } + } + virtual void fill_rect(int x0, int y0, int x1, int y1, unsigned int rgb) + { + if (m_driver && m_driver->fill_rect) + { + return m_driver->fill_rect(x0, y0, x1, y1, rgb); + } + if (m_driver && m_driver->draw_pixel) + { + for (int y = y0; y <= y1; y++) + { + for (int x = x0; x <= x1; x++) + { + m_driver->draw_pixel(x, y, rgb); + } + } + return; + } + register int _width = m_width; + register int _height = m_height; + int x, y; + if (m_color_bytes == 2) + { + unsigned short* phy_fb; + unsigned int rgb_16 = GL_RGB_32_to_16(rgb); + for (y = y0; y <= y1; y++) + { + phy_fb = &((unsigned short*)m_phy_fb)[y * _width + x0]; + for (x = x0; x <= x1; x++) + { + if ((x < _width) && (y < _height)) + { + *phy_fb++ = rgb_16; + } + } + } + } + else + { + unsigned int* phy_fb; + for (y = y0; y <= y1; y++) + { + phy_fb = &((unsigned int*)m_phy_fb)[y * _width + x0]; + for (x = x0; x <= x1; x++) + { + if ((x < _width) && (y < _height)) + { + *phy_fb++ = rgb; + } + } + } + } + } + virtual int flush_screen(int left, int top, int right, int bottom, void* fb, int fb_width) + { + if ((0 == m_phy_fb) || (0 == fb)) + { + return -1; + } + register int _width = m_width; + register int _height = m_height; + left = (left >= _width) ? (_width - 1) : left; + right = (right >= _width) ? (_width - 1) : right; + top = (top >= _height) ? (_height - 1) : top; + bottom = (bottom >= _height) ? (_height - 1) : bottom; + for (int y = top; y < bottom; y++) + { + void* s_addr = (char*)fb + ((y * fb_width + left) * m_color_bytes); + void* d_addr = (char*)m_phy_fb + ((y * _width + left) * m_color_bytes); + memcpy(d_addr, s_addr, (right - left) * m_color_bytes); + } + return 0; + } + int m_width; //in pixels + int m_height; //in pixels + int m_color_bytes; //16/32 bits for default + void* m_phy_fb; //physical framebuffer for default + struct DISPLAY_DRIVER* m_driver; //Rendering by external method without default physical framebuffer int m_phy_read_index; int m_phy_write_index; c_surface* m_surface_group[SURFACE_CNT_MAX]; int m_surface_cnt; //surface count int m_surface_index; + }; class c_layer { @@ -317,12 +393,10 @@ public: class c_surface { friend class c_display; friend class c_bitmap_operator; public: - c_surface(unsigned int width, unsigned int height, unsigned int color_bytes, Z_ORDER_LEVEL max_zorder = Z_ORDER_LEVEL_0, c_rect overlpa_rect = c_rect()) : m_width(width), m_height(height), m_color_bytes(color_bytes), m_fb(0), m_is_active(false), m_top_zorder(Z_ORDER_LEVEL_0), m_phy_fb(0), m_phy_write_index(0), m_display(0) + c_surface(unsigned int width, unsigned int height, unsigned int color_bytes, Z_ORDER_LEVEL max_zorder = Z_ORDER_LEVEL_0, c_rect overlpa_rect = c_rect()) : m_width(width), m_height(height), m_color_bytes(color_bytes), m_fb(0), m_is_active(false), m_top_zorder(Z_ORDER_LEVEL_0), m_phy_write_index(0), m_display(0) { (overlpa_rect == c_rect()) ? set_surface(max_zorder, c_rect(0, 0, width - 1, height - 1)) : set_surface(max_zorder, overlpa_rect); } - int get_width() { return m_width; } - int get_height() { return m_height; } unsigned int get_pixel(int x, int y, unsigned int z_order) { if (x >= m_width || y >= m_height || x < 0 || y < 0 || z_order >= Z_ORDER_LEVEL_MAX) @@ -332,15 +406,15 @@ public: } if (m_layers[z_order].fb) { - return (m_color_bytes == 4) ? ((unsigned int*)(m_layers[z_order].fb))[y * m_width + x] : GL_RGB_16_to_32(((unsigned short*)(m_layers[z_order].fb))[y * m_width + x]); + return (m_color_bytes == 2) ? GL_RGB_16_to_32(((unsigned short*)(m_layers[z_order].fb))[y * m_width + x]) : ((unsigned int*)(m_layers[z_order].fb))[y * m_width + x]; } else if (m_fb) { - return (m_color_bytes == 4) ? ((unsigned int*)m_fb)[y * m_width + x] : GL_RGB_16_to_32(((unsigned short*)m_fb)[y * m_width + x]); + return (m_color_bytes == 2) ? GL_RGB_16_to_32(((unsigned short*)m_fb)[y * m_width + x]) : ((unsigned int*)m_fb)[y * m_width + x]; } - else if (m_phy_fb) + else if (m_display->m_phy_fb) { - return (m_color_bytes == 4) ? ((unsigned int*)m_phy_fb)[y * m_width + x] : GL_RGB_16_to_32(((unsigned short*)m_phy_fb)[y * m_width + x]); + return (m_color_bytes == 2) ? GL_RGB_16_to_32(((unsigned short*)m_display->m_phy_fb)[y * m_width + x]) : ((unsigned int*)m_display->m_phy_fb)[y * m_width + x]; } return 0; } @@ -357,7 +431,7 @@ public: } if (z_order == m_max_zorder) { - return draw_pixel_on_fb(x, y, rgb); + return draw_pixel_low_level(x, y, rgb); } if (z_order > (unsigned int)m_top_zorder) @@ -367,19 +441,19 @@ public: if (m_layers[z_order].rect.pt_in_rect(x, y)) { c_rect layer_rect = m_layers[z_order].rect; - if (m_color_bytes == 4) + if (m_color_bytes == 2) { - ((unsigned int*)(m_layers[z_order].fb))[(x - layer_rect.m_left) + (y - layer_rect.m_top) * layer_rect.width()] = rgb; + ((unsigned short*)(m_layers[z_order].fb))[(x - layer_rect.m_left) + (y - layer_rect.m_top) * layer_rect.width()] = GL_RGB_32_to_16(rgb); } else { - ((unsigned short*)(m_layers[z_order].fb))[(x - layer_rect.m_left) + (y - layer_rect.m_top) * layer_rect.width()] = GL_RGB_32_to_16(rgb); + ((unsigned int*)(m_layers[z_order].fb))[(x - layer_rect.m_left) + (y - layer_rect.m_top) * layer_rect.width()] = rgb; } } if (z_order == m_top_zorder) { - return draw_pixel_on_fb(x, y, rgb); + return draw_pixel_low_level(x, y, rgb); } bool be_overlapped = false; for (unsigned int tmp_z_order = Z_ORDER_LEVEL_MAX - 1; tmp_z_order > z_order; tmp_z_order--) @@ -392,7 +466,7 @@ public: } if (!be_overlapped) { - draw_pixel_on_fb(x, y, rgb); + draw_pixel_low_level(x, y, rgb); } } virtual void fill_rect(int x0, int y0, int x1, int y1, unsigned int rgb, unsigned int z_order) @@ -403,7 +477,7 @@ public: y1 = (y1 > (m_height - 1)) ? (m_height - 1) : y1; if (z_order == m_max_zorder) { - return fill_rect_on_fb(x0, y0, x1, y1, rgb); + return fill_rect_low_level(x0, y0, x1, y1, rgb); } if (z_order == m_top_zorder) { @@ -416,18 +490,18 @@ public: { if (layer_rect.pt_in_rect(x, y)) { - if (m_color_bytes == 4) + if (m_color_bytes == 2) { - ((unsigned int*)m_layers[z_order].fb)[(y - layer_rect.m_top) * layer_rect.width() + (x - layer_rect.m_left)] = rgb; + ((unsigned short*)m_layers[z_order].fb)[(y - layer_rect.m_top) * layer_rect.width() + (x - layer_rect.m_left)] = rgb_16; } else { - ((unsigned short*)m_layers[z_order].fb)[(y - layer_rect.m_top) * layer_rect.width() + (x - layer_rect.m_left)] = rgb_16; + ((unsigned int*)m_layers[z_order].fb)[(y - layer_rect.m_top) * layer_rect.width() + (x - layer_rect.m_left)] = rgb; } } } } - return fill_rect_on_fb(x0, y0, x1, y1, rgb); + return fill_rect_low_level(x0, y0, x1, y1, rgb); } for (; y0 <= y1; y0++) { @@ -499,27 +573,16 @@ public: } int flush_screen(int left, int top, int right, int bottom) { - if (left < 0 || left >= m_width || right < 0 || right >= m_width || - top < 0 || top >= m_height || bottom < 0 || bottom >= m_height) - { - ASSERT(false); - } - if (!m_is_active || (0 == m_phy_fb) || (0 == m_fb)) + if (!m_is_active) { return -1; } - int display_width = m_display->get_width(); - int display_height = m_display->get_height(); - left = (left >= display_width) ? (display_width - 1) : left; - right = (right >= display_width) ? (display_width - 1) : right; - top = (top >= display_height) ? (display_height - 1) : top; - bottom = (bottom >= display_height) ? (display_height - 1) : bottom; - for (int y = top; y < bottom; y++) + if (left < 0 || left >= m_width || right < 0 || right >= m_width || + top < 0 || top >= m_height || bottom < 0 || bottom >= m_height) { - void* s_addr = (char*)m_fb + ((y * m_width + left) * m_color_bytes); - void* d_addr = (char*)m_phy_fb + ((y * display_width + left) * m_color_bytes); - memcpy(d_addr, s_addr, (right - left) * m_color_bytes); + ASSERT(false); } + m_display->flush_screen(left, top, right, bottom, m_fb, m_width); *m_phy_write_index = *m_phy_write_index + 1; return 0; } @@ -537,90 +600,62 @@ public: { for (int x = rect.m_left; x <= rect.m_right; x++) { - unsigned int rgb = (m_color_bytes == 4) ? ((unsigned int*)fb)[(x - layer_rect.m_left) + (y - layer_rect.m_top) * width] : GL_RGB_16_to_32(((unsigned short*)fb)[(x - layer_rect.m_left) + (y - layer_rect.m_top) * width]); - draw_pixel_on_fb(x, y, rgb); + unsigned int rgb = (m_color_bytes == 2) ? GL_RGB_16_to_32(((unsigned short*)fb)[(x - layer_rect.m_left) + (y - layer_rect.m_top) * width]) : ((unsigned int*)fb)[(x - layer_rect.m_left) + (y - layer_rect.m_top) * width]; + draw_pixel_low_level(x, y, rgb); } } return 0; } void set_active(bool flag) { m_is_active = flag; } protected: - virtual void fill_rect_on_fb(int x0, int y0, int x1, int y1, unsigned int rgb) - { - int display_width = m_display->get_width(); - int display_height = m_display->get_height(); - if (m_color_bytes == 4) + virtual void fill_rect_low_level(int x0, int y0, int x1, int y1, unsigned int rgb) + {//fill rect on framebuffer of surface + int x, y; + if (m_color_bytes == 2) { - int x; - unsigned int* fb, * phy_fb; - for (; y0 <= y1; y0++) + unsigned short* fb; + unsigned int rgb_16 = GL_RGB_32_to_16(rgb); + for (y = y0; y <= y1; y++) { - x = x0; - fb = m_fb ? &((unsigned int*)m_fb)[y0 * m_width + x] : 0; - phy_fb = &((unsigned int*)m_phy_fb)[y0 * display_width + x]; - *m_phy_write_index = *m_phy_write_index + 1; - for (; x <= x1; x++) + fb = m_fb ? &((unsigned short*)m_fb)[y * m_width + x0] : 0; + if (!fb) { break; } + for (x = x0; x <= x1; x++) { - if (fb) - { - *fb++ = rgb; - } - if (m_is_active && (x < display_width) && (y0 < display_height)) - { - *phy_fb++ = rgb; - } + *fb++ = rgb_16; } } } - else if (m_color_bytes == 2) + else { - int x; - unsigned short* fb, * phy_fb; - rgb = GL_RGB_32_to_16(rgb); - for (; y0 <= y1; y0++) + unsigned int* fb; + for (y = y0; y <= y1; y++) { - x = x0; - fb = m_fb ? &((unsigned short*)m_fb)[y0 * m_width + x] : 0; - phy_fb = &((unsigned short*)m_phy_fb)[y0 * display_width + x]; - *m_phy_write_index = *m_phy_write_index + 1; - for (; x <= x1; x++) + fb = m_fb ? &((unsigned int*)m_fb)[y * m_width + x0] : 0; + if (!fb) { break; } + for (x = x0; x <= x1; x++) { - if (fb) - { - *fb++ = rgb; - } - if (m_is_active && (x < display_width) && (y0 < display_height)) - { - *phy_fb++ = rgb; - } + *fb++ = rgb; } } } + if (!m_is_active) { return; } + m_display->fill_rect(x0, y0, x1, y1, rgb); + *m_phy_write_index = *m_phy_write_index + 1; } - virtual void draw_pixel_on_fb(int x, int y, unsigned int rgb) + virtual void draw_pixel_low_level(int x, int y, unsigned int rgb) { if (m_fb) - { - (m_color_bytes == 4) ? ((unsigned int*)m_fb)[y * m_width + x] = rgb : ((unsigned short*)m_fb)[y * m_width + x] = GL_RGB_32_to_16(rgb); - } - if (m_is_active && (x < m_display->get_width()) && (y < m_display->get_height())) - { - if (m_color_bytes == 4) - { - ((unsigned int*)m_phy_fb)[y * (m_display->get_width()) + x] = rgb; - } - else - { - ((unsigned short*)m_phy_fb)[y * (m_display->get_width()) + x] = GL_RGB_32_to_16(rgb); - } - *m_phy_write_index = *m_phy_write_index + 1; + {//draw pixel on framebuffer of surface + (m_color_bytes == 2) ? ((unsigned short*)m_fb)[y * m_width + x] = GL_RGB_32_to_16(rgb): ((unsigned int*)m_fb)[y * m_width + x] = rgb; } + if (!m_is_active) { return; } + m_display->draw_pixel(x, y, rgb); + *m_phy_write_index = *m_phy_write_index + 1; } void attach_display(c_display* display) { ASSERT(display); m_display = display; - m_phy_fb = display->m_phy_fb; m_phy_write_index = &display->m_phy_write_index; } void set_surface(Z_ORDER_LEVEL max_z_order, c_rect layer_rect) @@ -638,87 +673,22 @@ protected: } int m_width; //in pixels int m_height; //in pixels - int m_color_bytes; //16 bits, 32 bits only + int m_color_bytes; //16 bits, 32 bits for default void* m_fb; //frame buffer you could see c_layer m_layers[Z_ORDER_LEVEL_MAX];//all graphic layers bool m_is_active; //active flag Z_ORDER_LEVEL m_max_zorder; //the highest graphic layer the surface will have Z_ORDER_LEVEL m_top_zorder; //the current highest graphic layer the surface have - void* m_phy_fb; //physical framebufer int* m_phy_write_index; c_display* m_display; }; -class c_surface_no_fb : public c_surface {//No physical framebuffer, render with external graphic interface - friend class c_display; -public: - c_surface_no_fb(unsigned int width, unsigned int height, unsigned int color_bytes, struct EXTERNAL_GFX_OP* gfx_op, Z_ORDER_LEVEL max_zorder = Z_ORDER_LEVEL_0, c_rect overlpa_rect = c_rect()) : c_surface(width, height, color_bytes, max_zorder, overlpa_rect), m_gfx_op(gfx_op) {} -protected: - virtual void fill_rect_on_fb(int x0, int y0, int x1, int y1, unsigned int rgb) - { - if (!m_gfx_op) - { - return; - } - if (m_gfx_op->fill_rect) - { - return m_gfx_op->fill_rect(x0, y0, x1, y1, rgb); - } - if (m_gfx_op->draw_pixel && m_is_active) - { - for (int y = y0; y <= y1; y++) - { - for (int x = x0; x <= x1; x++) - { - m_gfx_op->draw_pixel(x, y, rgb); - } - } - } - if (!m_fb) { return; } - if (m_color_bytes == 4) - { - unsigned int* fb; - for (int y = y0; y <= y1; y++) - { - fb = &((unsigned int*)m_fb)[y0 * m_width + x0]; - for (int x = x0; x <= x1; x++) - { - *fb++ = rgb; - } - } - } - else if (m_color_bytes == 2) - { - unsigned short* fb; - rgb = GL_RGB_32_to_16(rgb); - for (int y = y0; y <= y1; y++) - { - fb = &((unsigned short*)m_fb)[y0 * m_width + x0]; - for (int x = x0; x <= x1; x++) - { - *fb++ = rgb; - } - } - } - } - virtual void draw_pixel_on_fb(int x, int y, unsigned int rgb) - { - if (m_gfx_op && m_gfx_op->draw_pixel && m_is_active) - { - m_gfx_op->draw_pixel(x, y, rgb); - } - if (!m_fb) { return; } - if (m_color_bytes == 4) - { - ((unsigned int*)m_fb)[y * m_width + x] = rgb; - } - else if (m_color_bytes == 2) - { - ((unsigned short*)m_fb)[y * m_width + x] = GL_RGB_32_to_16(rgb); - } - } - struct EXTERNAL_GFX_OP* m_gfx_op;//Rendering by external method -}; -inline c_display::c_display(void* phy_fb, int display_width, int display_height, int surface_width, int surface_height, unsigned int color_bytes, int surface_cnt, EXTERNAL_GFX_OP* gfx_op) : m_width(display_width), m_height(display_height), m_color_bytes(color_bytes), m_phy_fb(phy_fb), m_phy_read_index(0), m_phy_write_index(0), m_surface_cnt(surface_cnt), m_surface_index(0) +inline c_display::c_display(void* phy_fb, int display_width, int display_height, c_surface* surface, DISPLAY_DRIVER* driver) : m_phy_fb(phy_fb), m_width(display_width), m_height(display_height), m_driver(driver), m_phy_read_index(0), m_phy_write_index(0), m_surface_cnt(1), m_surface_index(0) +{ + m_color_bytes = surface->m_color_bytes; + surface->m_is_active = true; + (m_surface_group[0] = surface)->attach_display(this); +} +inline c_display::c_display(void* phy_fb, int display_width, int display_height, int surface_width, int surface_height, unsigned int color_bytes, int surface_cnt, DISPLAY_DRIVER* driver) : m_phy_fb(phy_fb), m_width(display_width), m_height(display_height), m_color_bytes(color_bytes), m_phy_read_index(0), m_phy_write_index(0), m_surface_cnt(surface_cnt), m_driver(driver), m_surface_index(0) { ASSERT(color_bytes == 2 || color_bytes == 4); ASSERT(m_surface_cnt <= SURFACE_CNT_MAX); @@ -726,16 +696,10 @@ inline c_display::c_display(void* phy_fb, int display_width, int display_height, for (int i = 0; i < m_surface_cnt; i++) { - m_surface_group[i] = (phy_fb) ? new c_surface(surface_width, surface_height, color_bytes) : new c_surface_no_fb(surface_width, surface_height, color_bytes, gfx_op); + m_surface_group[i] = new c_surface(surface_width, surface_height, color_bytes); m_surface_group[i]->attach_display(this); } } -inline c_display::c_display(void* phy_fb, int display_width, int display_height, c_surface* surface) : m_width(display_width), m_height(display_height), m_phy_fb(phy_fb), m_phy_read_index(0), m_phy_write_index(0), m_surface_cnt(1), m_surface_index(0) -{ - m_color_bytes = surface->m_color_bytes; - surface->m_is_active = true; - (m_surface_group[0] = surface)->attach_display(this); -} inline c_surface* c_display::alloc_surface(Z_ORDER_LEVEL max_zorder, c_rect layer_rect) { ASSERT(max_zorder < Z_ORDER_LEVEL_MAX && m_surface_index < m_surface_cnt); @@ -744,8 +708,8 @@ inline c_surface* c_display::alloc_surface(Z_ORDER_LEVEL max_zorder, c_rect laye } inline int c_display::swipe_surface(c_surface* s0, c_surface* s1, int x0, int x1, int y0, int y1, int offset) { - int surface_width = s0->get_width(); - int surface_height = s0->get_height(); + register int surface_width = s0->m_width; + register int surface_height = s0->m_height; if (offset < 0 || offset > surface_width || y0 < 0 || y0 >= surface_height || y1 < 0 || y1 >= surface_height || x0 < 0 || x0 >= surface_width || x1 < 0 || x1 >= surface_width) { @@ -767,46 +731,46 @@ inline int c_display::swipe_surface(c_surface* s0, c_surface* s1, int x0, int x1 for (int y = y0; y <= y1; y++) { //Left surface - char* addr_s = ((char*)(s0->m_fb) + (y * (s0->get_width()) + x0 + offset) * m_color_bytes); + char* addr_s = ((char*)(s0->m_fb) + (y * surface_width + x0 + offset) * m_color_bytes); char* addr_d = ((char*)(m_phy_fb)+(y * m_width + x0) * m_color_bytes); memcpy(addr_d, addr_s, (width - offset) * m_color_bytes); //Right surface - addr_s = ((char*)(s1->m_fb) + (y * (s1->get_width()) + x0) * m_color_bytes); + addr_s = ((char*)(s1->m_fb) + (y * surface_width + x0) * m_color_bytes); addr_d = ((char*)(m_phy_fb)+(y * m_width + x0 + (width - offset)) * m_color_bytes); memcpy(addr_d, addr_s, offset * m_color_bytes); } } - else if (m_color_bytes == 4) + else if (m_color_bytes == 2) { - void(*draw_pixel)(int x, int y, unsigned int rgb) = ((c_surface_no_fb*)s0)->m_gfx_op->draw_pixel; + void(*draw_pixel)(int x, int y, unsigned int rgb) = m_driver->draw_pixel; for (int y = y0; y <= y1; y++) { //Left surface for (int x = x0; x <= (x1 - offset); x++) { - draw_pixel(x, y, ((unsigned int*)s0->m_fb)[y * m_width + x + offset]); + draw_pixel(x, y, GL_RGB_16_to_32(((unsigned short*)s0->m_fb)[y * m_width + x + offset])); } //Right surface for (int x = x1 - offset; x <= x1; x++) { - draw_pixel(x, y, ((unsigned int*)s1->m_fb)[y * m_width + x + offset - x1 + x0]); + draw_pixel(x, y, GL_RGB_16_to_32(((unsigned short*)s1->m_fb)[y * m_width + x + offset - x1 + x0])); } } } - else if (m_color_bytes == 2) + else //m_color_bytes == 3/4... { - void(*draw_pixel)(int x, int y, unsigned int rgb) = ((c_surface_no_fb*)s0)->m_gfx_op->draw_pixel; + void(*draw_pixel)(int x, int y, unsigned int rgb) = m_driver->draw_pixel; for (int y = y0; y <= y1; y++) { //Left surface for (int x = x0; x <= (x1 - offset); x++) { - draw_pixel(x, y, GL_RGB_16_to_32(((unsigned short*)s0->m_fb)[y * m_width + x + offset])); + draw_pixel(x, y, ((unsigned int*)s0->m_fb)[y * m_width + x + offset]); } //Right surface for (int x = x1 - offset; x <= x1; x++) { - draw_pixel(x, y, GL_RGB_16_to_32(((unsigned short*)s1->m_fb)[y * m_width + x + offset - x1 + x0])); + draw_pixel(x, y, ((unsigned int*)s1->m_fb)[y * m_width + x + offset - x1 + x0]); } } } @@ -3407,22 +3371,12 @@ private: #ifdef GUILITE_ON c_bitmap_operator the_bitmap_op = c_bitmap_operator(); c_image_operator* c_image::image_operator = &the_bitmap_op; +const void* c_theme::s_font_map[FONT_MAX]; +const void* c_theme::s_image_map[IMAGE_MAX]; +unsigned int c_theme::s_color_map[COLOR_MAX]; +c_lattice_font_op the_lattice_font_op = c_lattice_font_op(); +c_font_operator* c_word::fontOperator = &the_lattice_font_op; #endif - -#ifdef GUILITE_ON - -const void* c_theme::s_font_map[FONT_MAX]; -const void* c_theme::s_image_map[IMAGE_MAX]; -unsigned int c_theme::s_color_map[COLOR_MAX]; - -#endif - -#ifdef GUILITE_ON - -c_lattice_font_op the_lattice_font_op = c_lattice_font_op(); -c_font_operator* c_word::fontOperator = &the_lattice_font_op; - -#endif #ifdef GUILITE_ON #if (defined __linux__) || (defined __APPLE__) #include @@ -4264,11 +4218,7 @@ int c_fifo::write(void* buf, int len) #endif #ifdef GUILITE_ON DIALOG_ARRAY c_dialog::ms_the_dialogs[SURFACE_CNT_MAX]; -#endif -#ifdef GUILITE_ON c_keyboard c_edit::s_keyboard; -#endif -#ifdef GUILITE_ON static c_keyboard_button s_key_0, s_key_1, s_key_2, s_key_3, s_key_4, s_key_5, s_key_6, s_key_7, s_key_8, s_key_9; static c_keyboard_button s_key_A, s_key_B, s_key_C, s_key_D, s_key_E, s_key_F, s_key_G, s_key_H, s_key_I, s_key_J; static c_keyboard_button s_key_K, s_key_L, s_key_M, s_key_N, s_key_O, s_key_P, s_key_Q, s_key_R, s_key_S, s_key_T; @@ -4306,12 +4256,12 @@ WND_TREE g_key_board_children[] = {&s_key_B, 'B', 0, ((KEY_WIDTH / 2) + POS_X(5)), POS_Y(2), KEY_WIDTH, KEY_HEIGHT}, {&s_key_N, 'N', 0, ((KEY_WIDTH / 2) + POS_X(6)), POS_Y(2), KEY_WIDTH, KEY_HEIGHT}, {&s_key_M, 'M', 0, ((KEY_WIDTH / 2) + POS_X(7)), POS_Y(2), KEY_WIDTH, KEY_HEIGHT}, - {&s_key_del, 0x7F, 0, ((KEY_WIDTH / 2) + POS_X(8)), POS_Y(2), DEL_WIDTH, KEY_HEIGHT}, + {&s_key_del,0x7F, 0, ((KEY_WIDTH / 2) + POS_X(8)), POS_Y(2), DEL_WIDTH, KEY_HEIGHT}, //Row 4 - {&s_key_esc, 0x1B, 0, POS_X(0), POS_Y(3), ESC_WIDTH, KEY_HEIGHT}, + {&s_key_esc, 0x1B, 0, POS_X(0), POS_Y(3), ESC_WIDTH, KEY_HEIGHT}, {&s_key_num_switch, 0x90, 0, POS_X(2), POS_Y(3), SWITCH_WIDTH, KEY_HEIGHT}, {&s_key_space, ' ', 0, ((KEY_WIDTH / 2) + POS_X(3)), POS_Y(3), SPACE_WIDTH, KEY_HEIGHT}, - {&s_key_dot, '.', 0, ((KEY_WIDTH / 2) + POS_X(6)), POS_Y(3), DOT_WIDTH, KEY_HEIGHT}, + {&s_key_dot, '.', 0, ((KEY_WIDTH / 2) + POS_X(6)), POS_Y(3), DOT_WIDTH, KEY_HEIGHT}, {&s_key_enter, '\n', 0, POS_X(8), POS_Y(3), ENTER_WIDTH, KEY_HEIGHT}, {0,0,0,0,0,0,0} }; @@ -4326,12 +4276,11 @@ WND_TREE g_number_board_children[] = {&s_key_7, '7', 0, POS_X(0), POS_Y(2), KEY_WIDTH, KEY_HEIGHT}, {&s_key_8, '8', 0, POS_X(1), POS_Y(2), KEY_WIDTH, KEY_HEIGHT}, {&s_key_9, '9', 0, POS_X(2), POS_Y(2), KEY_WIDTH, KEY_HEIGHT}, - - {&s_key_esc, 0x1B, 0, POS_X(0), POS_Y(3), KEY_WIDTH, KEY_HEIGHT}, + {&s_key_esc,0x1B, 0, POS_X(0), POS_Y(3), KEY_WIDTH, KEY_HEIGHT}, {&s_key_0, '0', 0, POS_X(1), POS_Y(3), KEY_WIDTH, KEY_HEIGHT}, - {&s_key_dot, '.', 0, POS_X(2), POS_Y(3), KEY_WIDTH, KEY_HEIGHT}, + {&s_key_dot,'.', 0, POS_X(2), POS_Y(3), KEY_WIDTH, KEY_HEIGHT}, {&s_key_del, 0x7F, 0, POS_X(3), POS_Y(0), KEY_WIDTH, KEY_HEIGHT * 2 + 2}, {&s_key_enter,'\n', 0, POS_X(3), POS_Y(2), KEY_WIDTH, KEY_HEIGHT * 2 + 2}, {0,0,0,0,0,0,0} }; -#endif +#endif \ No newline at end of file diff --git a/HelloCircle/UIcode/UIcode.cpp b/HelloCircle/UIcode/UIcode.cpp index 8d887465c6aa58ce6d7771bf5307062f0bf739df..ba3506e9cd64ff94164c2e498204bbf5efc5953d 100644 --- a/HelloCircle/UIcode/UIcode.cpp +++ b/HelloCircle/UIcode/UIcode.cpp @@ -201,21 +201,11 @@ public: Circle theSmallCircle(CIRCLE_X, CIRCLE_Y, SMALL_RADIUS, GL_RGB(25, 68, 97), 8); Circle theBigCircle(CIRCLE_X, CIRCLE_Y, BIG_RADIUS, GL_RGB(59, 152, 215), 8, false); -void create_ui(void* phy_fb, int screen_width, int screen_height, int color_bytes, struct EXTERNAL_GFX_OP* gfx_op) { - if (phy_fb) - { - static c_surface surface(UI_WIDTH, UI_HEIGHT, color_bytes, Z_ORDER_LEVEL_0); - static c_display display(phy_fb, screen_width, screen_height, &surface); - s_surface = &surface; - s_display = &display; - } - else - {//for MCU without framebuffer - static c_surface_no_fb surface_no_fb(UI_WIDTH, UI_HEIGHT, color_bytes, gfx_op, Z_ORDER_LEVEL_0); - static c_display display(phy_fb, screen_width, screen_height, &surface_no_fb); - s_surface = &surface_no_fb; - s_display = &display; - } +void create_ui(void* phy_fb, int screen_width, int screen_height, int color_bytes, struct DISPLAY_DRIVER* driver) { + static c_surface surface(UI_WIDTH, UI_HEIGHT, color_bytes, Z_ORDER_LEVEL_0); + static c_display display(phy_fb, screen_width, screen_height, &surface, driver); + s_surface = &surface; + s_display = &display; s_surface->fill_rect(0, 0, UI_WIDTH - 1, UI_HEIGHT - 1, 0, Z_ORDER_LEVEL_0); double time = 0.0; @@ -253,8 +243,8 @@ void create_ui(void* phy_fb, int screen_width, int screen_height, int color_byte } //////////////////////// interface for all platform //////////////////////// -extern "C" void startHelloCircle(void* phy_fb, int width, int height, int color_bytes, struct EXTERNAL_GFX_OP* gfx_op) { - create_ui(phy_fb, width, height, color_bytes, gfx_op); +extern "C" void startHelloCircle(void* phy_fb, int width, int height, int color_bytes, struct DISPLAY_DRIVER* driver) { + create_ui(phy_fb, width, height, color_bytes, driver); } extern "C" void* getUiOfHelloCircle(int* width, int* height, bool force_update) diff --git a/HelloFFmpeg/BuildLinux/.sync_build.sh b/HelloFFmpeg/BuildLinux/.sync_build.sh index 49cff5b473ac606967676ebefa6f0d333e301227..1152b91cce28496a45b3fd571103997f3c601c55 100644 --- a/HelloFFmpeg/BuildLinux/.sync_build.sh +++ b/HelloFFmpeg/BuildLinux/.sync_build.sh @@ -1,5 +1,6 @@ if [ "$#" -ne 1 ]; then - echo "Invalid arguments" + echo "Do testing" + ./xWindow 640 360 | ./HelloFFmpeg ../test.mp4 shared-fb exit -1 fi diff --git a/HelloFFmpeg/UIcode/GuiLite.h b/HelloFFmpeg/UIcode/GuiLite.h index c4fc88a51476d2c8309c3e55e1270e13784fc510..80550e1632ad7bc82541a2edbb0f7f8f5937954f 100644 --- a/HelloFFmpeg/UIcode/GuiLite.h +++ b/HelloFFmpeg/UIcode/GuiLite.h @@ -1,107 +1,94 @@ #pragma once - -#define REAL_TIME_TASK_CYCLE_MS 50 -#define MAX(a,b) (((a)>(b))?(a):(b)) -#define MIN(a,b) (((a)<(b))?(a):(b)) - -#define GL_ARGB(a, r, g, b) ((((unsigned int)(a)) << 24) | (((unsigned int)(r)) << 16) | (((unsigned int)(g)) << 8) | ((unsigned int)(b))) -#define GL_ARGB_A(rgb) ((((unsigned int)(rgb)) >> 24) & 0xFF) - -#define GL_RGB(r, g, b) ((0xFF << 24) | (((unsigned int)(r)) << 16) | (((unsigned int)(g)) << 8) | ((unsigned int)(b))) -#define GL_RGB_R(rgb) ((((unsigned int)(rgb)) >> 16) & 0xFF) -#define GL_RGB_G(rgb) ((((unsigned int)(rgb)) >> 8) & 0xFF) -#define GL_RGB_B(rgb) (((unsigned int)(rgb)) & 0xFF) -#define GL_RGB_32_to_16(rgb) (((((unsigned int)(rgb)) & 0xFF) >> 3) | ((((unsigned int)(rgb)) & 0xFC00) >> 5) | ((((unsigned int)(rgb)) & 0xF80000) >> 8)) -#define GL_RGB_16_to_32(rgb) ((0xFF << 24) | ((((unsigned int)(rgb)) & 0x1F) << 3) | ((((unsigned int)(rgb)) & 0x7E0) << 5) | ((((unsigned int)(rgb)) & 0xF800) << 8)) - -#define ALIGN_HCENTER 0x00000000L -#define ALIGN_LEFT 0x01000000L -#define ALIGN_RIGHT 0x02000000L -#define ALIGN_HMASK 0x03000000L - -#define ALIGN_VCENTER 0x00000000L -#define ALIGN_TOP 0x00100000L -#define ALIGN_BOTTOM 0x00200000L -#define ALIGN_VMASK 0x00300000L - -typedef struct -{ - unsigned short year; - unsigned short month; - unsigned short date; - unsigned short day; - unsigned short hour; - unsigned short minute; - unsigned short second; -}T_TIME; - -void register_debug_function(void(*my_assert)(const char* file, int line), void(*my_log_out)(const char* log)); -void _assert(const char* file, int line); -#define ASSERT(condition) \ - do{ \ - if(!(condition))_assert(__FILE__, __LINE__);\ - }while(0) -void log_out(const char* log); - -long get_time_in_second(); -T_TIME second_to_day(long second); -T_TIME get_time(); - -void start_real_timer(void (*func)(void* arg)); -void register_timer(int milli_second, void func(void* param), void* param); - -unsigned int get_cur_thread_id(); -void create_thread(unsigned long* thread_id, void* attr, void *(*start_routine) (void *), void* arg); -void thread_sleep(unsigned int milli_seconds); -int build_bmp(const char *filename, unsigned int width, unsigned int height, unsigned char *data); - -#define FIFO_BUFFER_LEN 1024 -class c_fifo -{ -public: - c_fifo(); - int read(void* buf, int len); - int write(void* buf, int len); -private: - unsigned char m_buf[FIFO_BUFFER_LEN]; - int m_head; - int m_tail; - void* m_read_sem; - void* m_write_mutex; -}; - -class c_rect -{ -public: - c_rect(){ m_left = m_top = m_right = m_bottom = -1; } - c_rect(int left, int top, int width, int height) - { - set_rect(left, top, width, height); - } - void set_rect(int left, int top, int width, int height) - { - ASSERT(width > 0 && height > 0); - m_left = left; - m_top = top; - m_right = left + width - 1; - m_bottom = top + height -1; - } - bool pt_in_rect(int x, int y) const - { - return x >= m_left && x <= m_right && y >= m_top && y <= m_bottom; - } - int operator==(const c_rect& rect) const - { - return (m_left == rect.m_left) && (m_top == rect.m_top) && (m_right == rect.m_right) && (m_bottom == rect.m_bottom); - } - int width() const { return m_right - m_left + 1; } - int height() const { return m_bottom - m_top + 1 ; } - - int m_left; - int m_top; - int m_right; - int m_bottom; -}; +#define REAL_TIME_TASK_CYCLE_MS 50 +#define MAX(a,b) (((a)>(b))?(a):(b)) +#define MIN(a,b) (((a)<(b))?(a):(b)) +#define GL_ARGB(a, r, g, b) ((((unsigned int)(a)) << 24) | (((unsigned int)(r)) << 16) | (((unsigned int)(g)) << 8) | ((unsigned int)(b))) +#define GL_ARGB_A(rgb) ((((unsigned int)(rgb)) >> 24) & 0xFF) +#define GL_RGB(r, g, b) ((0xFF << 24) | (((unsigned int)(r)) << 16) | (((unsigned int)(g)) << 8) | ((unsigned int)(b))) +#define GL_RGB_R(rgb) ((((unsigned int)(rgb)) >> 16) & 0xFF) +#define GL_RGB_G(rgb) ((((unsigned int)(rgb)) >> 8) & 0xFF) +#define GL_RGB_B(rgb) (((unsigned int)(rgb)) & 0xFF) +#define GL_RGB_32_to_16(rgb) (((((unsigned int)(rgb)) & 0xFF) >> 3) | ((((unsigned int)(rgb)) & 0xFC00) >> 5) | ((((unsigned int)(rgb)) & 0xF80000) >> 8)) +#define GL_RGB_16_to_32(rgb) ((0xFF << 24) | ((((unsigned int)(rgb)) & 0x1F) << 3) | ((((unsigned int)(rgb)) & 0x7E0) << 5) | ((((unsigned int)(rgb)) & 0xF800) << 8)) +#define ALIGN_HCENTER 0x00000000L +#define ALIGN_LEFT 0x01000000L +#define ALIGN_RIGHT 0x02000000L +#define ALIGN_HMASK 0x03000000L +#define ALIGN_VCENTER 0x00000000L +#define ALIGN_TOP 0x00100000L +#define ALIGN_BOTTOM 0x00200000L +#define ALIGN_VMASK 0x00300000L +typedef struct +{ + unsigned short year; + unsigned short month; + unsigned short date; + unsigned short day; + unsigned short hour; + unsigned short minute; + unsigned short second; +}T_TIME; +void register_debug_function(void(*my_assert)(const char* file, int line), void(*my_log_out)(const char* log)); +void _assert(const char* file, int line); +#define ASSERT(condition) \ + do{ \ + if(!(condition))_assert(__FILE__, __LINE__);\ + }while(0) +void log_out(const char* log); +long get_time_in_second(); +T_TIME second_to_day(long second); +T_TIME get_time(); +void start_real_timer(void (*func)(void* arg)); +void register_timer(int milli_second, void func(void* param), void* param); +unsigned int get_cur_thread_id(); +void create_thread(unsigned long* thread_id, void* attr, void *(*start_routine) (void *), void* arg); +void thread_sleep(unsigned int milli_seconds); +int build_bmp(const char *filename, unsigned int width, unsigned int height, unsigned char *data); +#define FIFO_BUFFER_LEN 1024 +class c_fifo +{ +public: + c_fifo(); + int read(void* buf, int len); + int write(void* buf, int len); +private: + unsigned char m_buf[FIFO_BUFFER_LEN]; + int m_head; + int m_tail; + void* m_read_sem; + void* m_write_mutex; +}; +class c_rect +{ +public: + c_rect(){ m_left = m_top = m_right = m_bottom = -1; } + c_rect(int left, int top, int width, int height) + { + set_rect(left, top, width, height); + } + void set_rect(int left, int top, int width, int height) + { + ASSERT(width > 0 && height > 0); + m_left = left; + m_top = top; + m_right = left + width - 1; + m_bottom = top + height -1; + } + bool pt_in_rect(int x, int y) const + { + return x >= m_left && x <= m_right && y >= m_top && y <= m_bottom; + } + int operator==(const c_rect& rect) const + { + return (m_left == rect.m_left) && (m_top == rect.m_top) && (m_right == rect.m_right) && (m_bottom == rect.m_bottom); + } + int width() const { return m_right - m_left + 1; } + int height() const { return m_bottom - m_top + 1 ; } + int m_left; + int m_top; + int m_right; + int m_bottom; +}; //BITMAP typedef struct struct_bitmap_info { @@ -238,7 +225,7 @@ typedef enum Z_ORDER_LEVEL_2,//highest graphic level Z_ORDER_LEVEL_MAX }Z_ORDER_LEVEL; -struct EXTERNAL_GFX_OP +struct DISPLAY_DRIVER { void(*draw_pixel)(int x, int y, unsigned int rgb); void(*fill_rect)(int x0, int y0, int x1, int y1, unsigned int rgb); @@ -247,18 +234,19 @@ class c_surface; class c_display { friend class c_surface; public: - inline c_display(void* phy_fb, int display_width, int display_height, int surface_width, int surface_height, unsigned int color_bytes, int surface_cnt, EXTERNAL_GFX_OP* gfx_op = 0);//multiple surface or surface_no_fb - inline c_display(void* phy_fb, int display_width, int display_height, c_surface* surface);//single custom surface - inline c_surface* alloc_surface(Z_ORDER_LEVEL max_zorder, c_rect layer_rect = c_rect());//for multiple surfaces + inline c_display(void* phy_fb, int display_width, int display_height, c_surface* surface, DISPLAY_DRIVER* driver = 0);//single custom surface + inline c_display(void* phy_fb, int display_width, int display_height, int surface_width, int surface_height, unsigned int color_bytes, int surface_cnt, DISPLAY_DRIVER* driver = 0);//multiple surface + inline c_surface* alloc_surface(Z_ORDER_LEVEL max_zorder, c_rect layer_rect = c_rect());//for slide group inline int swipe_surface(c_surface* s0, c_surface* s1, int x0, int x1, int y0, int y1, int offset); int get_width() { return m_width; } int get_height() { return m_height; } + void* get_phy_fb() { return m_phy_fb; } void* get_updated_fb(int* width, int* height, bool force_update = false) { if (width && height) { - *width = get_width(); - *height = get_height(); + *width = m_width; + *height = m_height; } if (force_update) { @@ -277,35 +265,123 @@ public: { return -1; } - int width = get_width(); - int height = get_height(); //16 bits framebuffer if (m_color_bytes == 2) { - return build_bmp(file_name, width, height, (unsigned char*)m_phy_fb); + return build_bmp(file_name, m_width, m_height, (unsigned char*)m_phy_fb); } //32 bits framebuffer - unsigned short* p_bmp565_data = new unsigned short[width * height]; + unsigned short* p_bmp565_data = new unsigned short[m_width * m_height]; unsigned int* p_raw_data = (unsigned int*)m_phy_fb; - for (int i = 0; i < width * height; i++) + for (int i = 0; i < m_width * m_height; i++) { unsigned int rgb = *p_raw_data++; p_bmp565_data[i] = GL_RGB_32_to_16(rgb); } - int ret = build_bmp(file_name, width, height, (unsigned char*)p_bmp565_data); + int ret = build_bmp(file_name, m_width, m_height, (unsigned char*)p_bmp565_data); delete[]p_bmp565_data; return ret; } -private: - int m_width; //in pixels - int m_height; //in pixels - int m_color_bytes; //16 bits, 32 bits only - void* m_phy_fb; //physical framebuffer +protected: + virtual void draw_pixel(int x, int y, unsigned int rgb) + { + if ((x >= m_width) || (y >= m_height)) { return; } + if (m_driver && m_driver->draw_pixel) + { + return m_driver->draw_pixel(x, y, rgb); + } + if (m_color_bytes == 2) + { + ((unsigned short*)m_phy_fb)[y * m_width + x] = GL_RGB_32_to_16(rgb); + } + else + { + ((unsigned int*)m_phy_fb)[y * m_width + x] = rgb; + } + } + virtual void fill_rect(int x0, int y0, int x1, int y1, unsigned int rgb) + { + if (m_driver && m_driver->fill_rect) + { + return m_driver->fill_rect(x0, y0, x1, y1, rgb); + } + if (m_driver && m_driver->draw_pixel) + { + for (int y = y0; y <= y1; y++) + { + for (int x = x0; x <= x1; x++) + { + m_driver->draw_pixel(x, y, rgb); + } + } + return; + } + register int _width = m_width; + register int _height = m_height; + int x, y; + if (m_color_bytes == 2) + { + unsigned short* phy_fb; + unsigned int rgb_16 = GL_RGB_32_to_16(rgb); + for (y = y0; y <= y1; y++) + { + phy_fb = &((unsigned short*)m_phy_fb)[y * _width + x0]; + for (x = x0; x <= x1; x++) + { + if ((x < _width) && (y < _height)) + { + *phy_fb++ = rgb_16; + } + } + } + } + else + { + unsigned int* phy_fb; + for (y = y0; y <= y1; y++) + { + phy_fb = &((unsigned int*)m_phy_fb)[y * _width + x0]; + for (x = x0; x <= x1; x++) + { + if ((x < _width) && (y < _height)) + { + *phy_fb++ = rgb; + } + } + } + } + } + virtual int flush_screen(int left, int top, int right, int bottom, void* fb, int fb_width) + { + if ((0 == m_phy_fb) || (0 == fb)) + { + return -1; + } + register int _width = m_width; + register int _height = m_height; + left = (left >= _width) ? (_width - 1) : left; + right = (right >= _width) ? (_width - 1) : right; + top = (top >= _height) ? (_height - 1) : top; + bottom = (bottom >= _height) ? (_height - 1) : bottom; + for (int y = top; y < bottom; y++) + { + void* s_addr = (char*)fb + ((y * fb_width + left) * m_color_bytes); + void* d_addr = (char*)m_phy_fb + ((y * _width + left) * m_color_bytes); + memcpy(d_addr, s_addr, (right - left) * m_color_bytes); + } + return 0; + } + int m_width; //in pixels + int m_height; //in pixels + int m_color_bytes; //16/32 bits for default + void* m_phy_fb; //physical framebuffer for default + struct DISPLAY_DRIVER* m_driver; //Rendering by external method without default physical framebuffer int m_phy_read_index; int m_phy_write_index; c_surface* m_surface_group[SURFACE_CNT_MAX]; int m_surface_cnt; //surface count int m_surface_index; + }; class c_layer { @@ -317,12 +393,10 @@ public: class c_surface { friend class c_display; friend class c_bitmap_operator; public: - c_surface(unsigned int width, unsigned int height, unsigned int color_bytes, Z_ORDER_LEVEL max_zorder = Z_ORDER_LEVEL_0, c_rect overlpa_rect = c_rect()) : m_width(width), m_height(height), m_color_bytes(color_bytes), m_fb(0), m_is_active(false), m_top_zorder(Z_ORDER_LEVEL_0), m_phy_fb(0), m_phy_write_index(0), m_display(0) + c_surface(unsigned int width, unsigned int height, unsigned int color_bytes, Z_ORDER_LEVEL max_zorder = Z_ORDER_LEVEL_0, c_rect overlpa_rect = c_rect()) : m_width(width), m_height(height), m_color_bytes(color_bytes), m_fb(0), m_is_active(false), m_top_zorder(Z_ORDER_LEVEL_0), m_phy_write_index(0), m_display(0) { (overlpa_rect == c_rect()) ? set_surface(max_zorder, c_rect(0, 0, width - 1, height - 1)) : set_surface(max_zorder, overlpa_rect); } - int get_width() { return m_width; } - int get_height() { return m_height; } unsigned int get_pixel(int x, int y, unsigned int z_order) { if (x >= m_width || y >= m_height || x < 0 || y < 0 || z_order >= Z_ORDER_LEVEL_MAX) @@ -332,15 +406,15 @@ public: } if (m_layers[z_order].fb) { - return (m_color_bytes == 4) ? ((unsigned int*)(m_layers[z_order].fb))[y * m_width + x] : GL_RGB_16_to_32(((unsigned short*)(m_layers[z_order].fb))[y * m_width + x]); + return (m_color_bytes == 2) ? GL_RGB_16_to_32(((unsigned short*)(m_layers[z_order].fb))[y * m_width + x]) : ((unsigned int*)(m_layers[z_order].fb))[y * m_width + x]; } else if (m_fb) { - return (m_color_bytes == 4) ? ((unsigned int*)m_fb)[y * m_width + x] : GL_RGB_16_to_32(((unsigned short*)m_fb)[y * m_width + x]); + return (m_color_bytes == 2) ? GL_RGB_16_to_32(((unsigned short*)m_fb)[y * m_width + x]) : ((unsigned int*)m_fb)[y * m_width + x]; } - else if (m_phy_fb) + else if (m_display->m_phy_fb) { - return (m_color_bytes == 4) ? ((unsigned int*)m_phy_fb)[y * m_width + x] : GL_RGB_16_to_32(((unsigned short*)m_phy_fb)[y * m_width + x]); + return (m_color_bytes == 2) ? GL_RGB_16_to_32(((unsigned short*)m_display->m_phy_fb)[y * m_width + x]) : ((unsigned int*)m_display->m_phy_fb)[y * m_width + x]; } return 0; } @@ -357,7 +431,7 @@ public: } if (z_order == m_max_zorder) { - return draw_pixel_on_fb(x, y, rgb); + return draw_pixel_low_level(x, y, rgb); } if (z_order > (unsigned int)m_top_zorder) @@ -367,19 +441,19 @@ public: if (m_layers[z_order].rect.pt_in_rect(x, y)) { c_rect layer_rect = m_layers[z_order].rect; - if (m_color_bytes == 4) + if (m_color_bytes == 2) { - ((unsigned int*)(m_layers[z_order].fb))[(x - layer_rect.m_left) + (y - layer_rect.m_top) * layer_rect.width()] = rgb; + ((unsigned short*)(m_layers[z_order].fb))[(x - layer_rect.m_left) + (y - layer_rect.m_top) * layer_rect.width()] = GL_RGB_32_to_16(rgb); } else { - ((unsigned short*)(m_layers[z_order].fb))[(x - layer_rect.m_left) + (y - layer_rect.m_top) * layer_rect.width()] = GL_RGB_32_to_16(rgb); + ((unsigned int*)(m_layers[z_order].fb))[(x - layer_rect.m_left) + (y - layer_rect.m_top) * layer_rect.width()] = rgb; } } if (z_order == m_top_zorder) { - return draw_pixel_on_fb(x, y, rgb); + return draw_pixel_low_level(x, y, rgb); } bool be_overlapped = false; for (unsigned int tmp_z_order = Z_ORDER_LEVEL_MAX - 1; tmp_z_order > z_order; tmp_z_order--) @@ -392,7 +466,7 @@ public: } if (!be_overlapped) { - draw_pixel_on_fb(x, y, rgb); + draw_pixel_low_level(x, y, rgb); } } virtual void fill_rect(int x0, int y0, int x1, int y1, unsigned int rgb, unsigned int z_order) @@ -403,7 +477,7 @@ public: y1 = (y1 > (m_height - 1)) ? (m_height - 1) : y1; if (z_order == m_max_zorder) { - return fill_rect_on_fb(x0, y0, x1, y1, rgb); + return fill_rect_low_level(x0, y0, x1, y1, rgb); } if (z_order == m_top_zorder) { @@ -416,18 +490,18 @@ public: { if (layer_rect.pt_in_rect(x, y)) { - if (m_color_bytes == 4) + if (m_color_bytes == 2) { - ((unsigned int*)m_layers[z_order].fb)[(y - layer_rect.m_top) * layer_rect.width() + (x - layer_rect.m_left)] = rgb; + ((unsigned short*)m_layers[z_order].fb)[(y - layer_rect.m_top) * layer_rect.width() + (x - layer_rect.m_left)] = rgb_16; } else { - ((unsigned short*)m_layers[z_order].fb)[(y - layer_rect.m_top) * layer_rect.width() + (x - layer_rect.m_left)] = rgb_16; + ((unsigned int*)m_layers[z_order].fb)[(y - layer_rect.m_top) * layer_rect.width() + (x - layer_rect.m_left)] = rgb; } } } } - return fill_rect_on_fb(x0, y0, x1, y1, rgb); + return fill_rect_low_level(x0, y0, x1, y1, rgb); } for (; y0 <= y1; y0++) { @@ -499,27 +573,16 @@ public: } int flush_screen(int left, int top, int right, int bottom) { - if (left < 0 || left >= m_width || right < 0 || right >= m_width || - top < 0 || top >= m_height || bottom < 0 || bottom >= m_height) - { - ASSERT(false); - } - if (!m_is_active || (0 == m_phy_fb) || (0 == m_fb)) + if (!m_is_active) { return -1; } - int display_width = m_display->get_width(); - int display_height = m_display->get_height(); - left = (left >= display_width) ? (display_width - 1) : left; - right = (right >= display_width) ? (display_width - 1) : right; - top = (top >= display_height) ? (display_height - 1) : top; - bottom = (bottom >= display_height) ? (display_height - 1) : bottom; - for (int y = top; y < bottom; y++) + if (left < 0 || left >= m_width || right < 0 || right >= m_width || + top < 0 || top >= m_height || bottom < 0 || bottom >= m_height) { - void* s_addr = (char*)m_fb + ((y * m_width + left) * m_color_bytes); - void* d_addr = (char*)m_phy_fb + ((y * display_width + left) * m_color_bytes); - memcpy(d_addr, s_addr, (right - left) * m_color_bytes); + ASSERT(false); } + m_display->flush_screen(left, top, right, bottom, m_fb, m_width); *m_phy_write_index = *m_phy_write_index + 1; return 0; } @@ -537,90 +600,62 @@ public: { for (int x = rect.m_left; x <= rect.m_right; x++) { - unsigned int rgb = (m_color_bytes == 4) ? ((unsigned int*)fb)[(x - layer_rect.m_left) + (y - layer_rect.m_top) * width] : GL_RGB_16_to_32(((unsigned short*)fb)[(x - layer_rect.m_left) + (y - layer_rect.m_top) * width]); - draw_pixel_on_fb(x, y, rgb); + unsigned int rgb = (m_color_bytes == 2) ? GL_RGB_16_to_32(((unsigned short*)fb)[(x - layer_rect.m_left) + (y - layer_rect.m_top) * width]) : ((unsigned int*)fb)[(x - layer_rect.m_left) + (y - layer_rect.m_top) * width]; + draw_pixel_low_level(x, y, rgb); } } return 0; } void set_active(bool flag) { m_is_active = flag; } protected: - virtual void fill_rect_on_fb(int x0, int y0, int x1, int y1, unsigned int rgb) - { - int display_width = m_display->get_width(); - int display_height = m_display->get_height(); - if (m_color_bytes == 4) + virtual void fill_rect_low_level(int x0, int y0, int x1, int y1, unsigned int rgb) + {//fill rect on framebuffer of surface + int x, y; + if (m_color_bytes == 2) { - int x; - unsigned int* fb, * phy_fb; - for (; y0 <= y1; y0++) + unsigned short* fb; + unsigned int rgb_16 = GL_RGB_32_to_16(rgb); + for (y = y0; y <= y1; y++) { - x = x0; - fb = m_fb ? &((unsigned int*)m_fb)[y0 * m_width + x] : 0; - phy_fb = &((unsigned int*)m_phy_fb)[y0 * display_width + x]; - *m_phy_write_index = *m_phy_write_index + 1; - for (; x <= x1; x++) + fb = m_fb ? &((unsigned short*)m_fb)[y * m_width + x0] : 0; + if (!fb) { break; } + for (x = x0; x <= x1; x++) { - if (fb) - { - *fb++ = rgb; - } - if (m_is_active && (x < display_width) && (y0 < display_height)) - { - *phy_fb++ = rgb; - } + *fb++ = rgb_16; } } } - else if (m_color_bytes == 2) + else { - int x; - unsigned short* fb, * phy_fb; - rgb = GL_RGB_32_to_16(rgb); - for (; y0 <= y1; y0++) + unsigned int* fb; + for (y = y0; y <= y1; y++) { - x = x0; - fb = m_fb ? &((unsigned short*)m_fb)[y0 * m_width + x] : 0; - phy_fb = &((unsigned short*)m_phy_fb)[y0 * display_width + x]; - *m_phy_write_index = *m_phy_write_index + 1; - for (; x <= x1; x++) + fb = m_fb ? &((unsigned int*)m_fb)[y * m_width + x0] : 0; + if (!fb) { break; } + for (x = x0; x <= x1; x++) { - if (fb) - { - *fb++ = rgb; - } - if (m_is_active && (x < display_width) && (y0 < display_height)) - { - *phy_fb++ = rgb; - } + *fb++ = rgb; } } } + if (!m_is_active) { return; } + m_display->fill_rect(x0, y0, x1, y1, rgb); + *m_phy_write_index = *m_phy_write_index + 1; } - virtual void draw_pixel_on_fb(int x, int y, unsigned int rgb) + virtual void draw_pixel_low_level(int x, int y, unsigned int rgb) { if (m_fb) - { - (m_color_bytes == 4) ? ((unsigned int*)m_fb)[y * m_width + x] = rgb : ((unsigned short*)m_fb)[y * m_width + x] = GL_RGB_32_to_16(rgb); - } - if (m_is_active && (x < m_display->get_width()) && (y < m_display->get_height())) - { - if (m_color_bytes == 4) - { - ((unsigned int*)m_phy_fb)[y * (m_display->get_width()) + x] = rgb; - } - else - { - ((unsigned short*)m_phy_fb)[y * (m_display->get_width()) + x] = GL_RGB_32_to_16(rgb); - } - *m_phy_write_index = *m_phy_write_index + 1; + {//draw pixel on framebuffer of surface + (m_color_bytes == 2) ? ((unsigned short*)m_fb)[y * m_width + x] = GL_RGB_32_to_16(rgb): ((unsigned int*)m_fb)[y * m_width + x] = rgb; } + if (!m_is_active) { return; } + m_display->draw_pixel(x, y, rgb); + *m_phy_write_index = *m_phy_write_index + 1; } void attach_display(c_display* display) { ASSERT(display); m_display = display; - m_phy_fb = display->m_phy_fb; m_phy_write_index = &display->m_phy_write_index; } void set_surface(Z_ORDER_LEVEL max_z_order, c_rect layer_rect) @@ -638,87 +673,22 @@ protected: } int m_width; //in pixels int m_height; //in pixels - int m_color_bytes; //16 bits, 32 bits only + int m_color_bytes; //16 bits, 32 bits for default void* m_fb; //frame buffer you could see c_layer m_layers[Z_ORDER_LEVEL_MAX];//all graphic layers bool m_is_active; //active flag Z_ORDER_LEVEL m_max_zorder; //the highest graphic layer the surface will have Z_ORDER_LEVEL m_top_zorder; //the current highest graphic layer the surface have - void* m_phy_fb; //physical framebufer int* m_phy_write_index; c_display* m_display; }; -class c_surface_no_fb : public c_surface {//No physical framebuffer, render with external graphic interface - friend class c_display; -public: - c_surface_no_fb(unsigned int width, unsigned int height, unsigned int color_bytes, struct EXTERNAL_GFX_OP* gfx_op, Z_ORDER_LEVEL max_zorder = Z_ORDER_LEVEL_0, c_rect overlpa_rect = c_rect()) : c_surface(width, height, color_bytes, max_zorder, overlpa_rect), m_gfx_op(gfx_op) {} -protected: - virtual void fill_rect_on_fb(int x0, int y0, int x1, int y1, unsigned int rgb) - { - if (!m_gfx_op) - { - return; - } - if (m_gfx_op->fill_rect) - { - return m_gfx_op->fill_rect(x0, y0, x1, y1, rgb); - } - if (m_gfx_op->draw_pixel && m_is_active) - { - for (int y = y0; y <= y1; y++) - { - for (int x = x0; x <= x1; x++) - { - m_gfx_op->draw_pixel(x, y, rgb); - } - } - } - if (!m_fb) { return; } - if (m_color_bytes == 4) - { - unsigned int* fb; - for (int y = y0; y <= y1; y++) - { - fb = &((unsigned int*)m_fb)[y0 * m_width + x0]; - for (int x = x0; x <= x1; x++) - { - *fb++ = rgb; - } - } - } - else if (m_color_bytes == 2) - { - unsigned short* fb; - rgb = GL_RGB_32_to_16(rgb); - for (int y = y0; y <= y1; y++) - { - fb = &((unsigned short*)m_fb)[y0 * m_width + x0]; - for (int x = x0; x <= x1; x++) - { - *fb++ = rgb; - } - } - } - } - virtual void draw_pixel_on_fb(int x, int y, unsigned int rgb) - { - if (m_gfx_op && m_gfx_op->draw_pixel && m_is_active) - { - m_gfx_op->draw_pixel(x, y, rgb); - } - if (!m_fb) { return; } - if (m_color_bytes == 4) - { - ((unsigned int*)m_fb)[y * m_width + x] = rgb; - } - else if (m_color_bytes == 2) - { - ((unsigned short*)m_fb)[y * m_width + x] = GL_RGB_32_to_16(rgb); - } - } - struct EXTERNAL_GFX_OP* m_gfx_op;//Rendering by external method -}; -inline c_display::c_display(void* phy_fb, int display_width, int display_height, int surface_width, int surface_height, unsigned int color_bytes, int surface_cnt, EXTERNAL_GFX_OP* gfx_op) : m_width(display_width), m_height(display_height), m_color_bytes(color_bytes), m_phy_fb(phy_fb), m_phy_read_index(0), m_phy_write_index(0), m_surface_cnt(surface_cnt), m_surface_index(0) +inline c_display::c_display(void* phy_fb, int display_width, int display_height, c_surface* surface, DISPLAY_DRIVER* driver) : m_phy_fb(phy_fb), m_width(display_width), m_height(display_height), m_driver(driver), m_phy_read_index(0), m_phy_write_index(0), m_surface_cnt(1), m_surface_index(0) +{ + m_color_bytes = surface->m_color_bytes; + surface->m_is_active = true; + (m_surface_group[0] = surface)->attach_display(this); +} +inline c_display::c_display(void* phy_fb, int display_width, int display_height, int surface_width, int surface_height, unsigned int color_bytes, int surface_cnt, DISPLAY_DRIVER* driver) : m_phy_fb(phy_fb), m_width(display_width), m_height(display_height), m_color_bytes(color_bytes), m_phy_read_index(0), m_phy_write_index(0), m_surface_cnt(surface_cnt), m_driver(driver), m_surface_index(0) { ASSERT(color_bytes == 2 || color_bytes == 4); ASSERT(m_surface_cnt <= SURFACE_CNT_MAX); @@ -726,16 +696,10 @@ inline c_display::c_display(void* phy_fb, int display_width, int display_height, for (int i = 0; i < m_surface_cnt; i++) { - m_surface_group[i] = (phy_fb) ? new c_surface(surface_width, surface_height, color_bytes) : new c_surface_no_fb(surface_width, surface_height, color_bytes, gfx_op); + m_surface_group[i] = new c_surface(surface_width, surface_height, color_bytes); m_surface_group[i]->attach_display(this); } } -inline c_display::c_display(void* phy_fb, int display_width, int display_height, c_surface* surface) : m_width(display_width), m_height(display_height), m_phy_fb(phy_fb), m_phy_read_index(0), m_phy_write_index(0), m_surface_cnt(1), m_surface_index(0) -{ - m_color_bytes = surface->m_color_bytes; - surface->m_is_active = true; - (m_surface_group[0] = surface)->attach_display(this); -} inline c_surface* c_display::alloc_surface(Z_ORDER_LEVEL max_zorder, c_rect layer_rect) { ASSERT(max_zorder < Z_ORDER_LEVEL_MAX && m_surface_index < m_surface_cnt); @@ -744,8 +708,8 @@ inline c_surface* c_display::alloc_surface(Z_ORDER_LEVEL max_zorder, c_rect laye } inline int c_display::swipe_surface(c_surface* s0, c_surface* s1, int x0, int x1, int y0, int y1, int offset) { - int surface_width = s0->get_width(); - int surface_height = s0->get_height(); + register int surface_width = s0->m_width; + register int surface_height = s0->m_height; if (offset < 0 || offset > surface_width || y0 < 0 || y0 >= surface_height || y1 < 0 || y1 >= surface_height || x0 < 0 || x0 >= surface_width || x1 < 0 || x1 >= surface_width) { @@ -767,46 +731,46 @@ inline int c_display::swipe_surface(c_surface* s0, c_surface* s1, int x0, int x1 for (int y = y0; y <= y1; y++) { //Left surface - char* addr_s = ((char*)(s0->m_fb) + (y * (s0->get_width()) + x0 + offset) * m_color_bytes); + char* addr_s = ((char*)(s0->m_fb) + (y * surface_width + x0 + offset) * m_color_bytes); char* addr_d = ((char*)(m_phy_fb)+(y * m_width + x0) * m_color_bytes); memcpy(addr_d, addr_s, (width - offset) * m_color_bytes); //Right surface - addr_s = ((char*)(s1->m_fb) + (y * (s1->get_width()) + x0) * m_color_bytes); + addr_s = ((char*)(s1->m_fb) + (y * surface_width + x0) * m_color_bytes); addr_d = ((char*)(m_phy_fb)+(y * m_width + x0 + (width - offset)) * m_color_bytes); memcpy(addr_d, addr_s, offset * m_color_bytes); } } - else if (m_color_bytes == 4) + else if (m_color_bytes == 2) { - void(*draw_pixel)(int x, int y, unsigned int rgb) = ((c_surface_no_fb*)s0)->m_gfx_op->draw_pixel; + void(*draw_pixel)(int x, int y, unsigned int rgb) = m_driver->draw_pixel; for (int y = y0; y <= y1; y++) { //Left surface for (int x = x0; x <= (x1 - offset); x++) { - draw_pixel(x, y, ((unsigned int*)s0->m_fb)[y * m_width + x + offset]); + draw_pixel(x, y, GL_RGB_16_to_32(((unsigned short*)s0->m_fb)[y * m_width + x + offset])); } //Right surface for (int x = x1 - offset; x <= x1; x++) { - draw_pixel(x, y, ((unsigned int*)s1->m_fb)[y * m_width + x + offset - x1 + x0]); + draw_pixel(x, y, GL_RGB_16_to_32(((unsigned short*)s1->m_fb)[y * m_width + x + offset - x1 + x0])); } } } - else if (m_color_bytes == 2) + else //m_color_bytes == 3/4... { - void(*draw_pixel)(int x, int y, unsigned int rgb) = ((c_surface_no_fb*)s0)->m_gfx_op->draw_pixel; + void(*draw_pixel)(int x, int y, unsigned int rgb) = m_driver->draw_pixel; for (int y = y0; y <= y1; y++) { //Left surface for (int x = x0; x <= (x1 - offset); x++) { - draw_pixel(x, y, GL_RGB_16_to_32(((unsigned short*)s0->m_fb)[y * m_width + x + offset])); + draw_pixel(x, y, ((unsigned int*)s0->m_fb)[y * m_width + x + offset]); } //Right surface for (int x = x1 - offset; x <= x1; x++) { - draw_pixel(x, y, GL_RGB_16_to_32(((unsigned short*)s1->m_fb)[y * m_width + x + offset - x1 + x0])); + draw_pixel(x, y, ((unsigned int*)s1->m_fb)[y * m_width + x + offset - x1 + x0]); } } } @@ -3407,22 +3371,12 @@ private: #ifdef GUILITE_ON c_bitmap_operator the_bitmap_op = c_bitmap_operator(); c_image_operator* c_image::image_operator = &the_bitmap_op; +const void* c_theme::s_font_map[FONT_MAX]; +const void* c_theme::s_image_map[IMAGE_MAX]; +unsigned int c_theme::s_color_map[COLOR_MAX]; +c_lattice_font_op the_lattice_font_op = c_lattice_font_op(); +c_font_operator* c_word::fontOperator = &the_lattice_font_op; #endif - -#ifdef GUILITE_ON - -const void* c_theme::s_font_map[FONT_MAX]; -const void* c_theme::s_image_map[IMAGE_MAX]; -unsigned int c_theme::s_color_map[COLOR_MAX]; - -#endif - -#ifdef GUILITE_ON - -c_lattice_font_op the_lattice_font_op = c_lattice_font_op(); -c_font_operator* c_word::fontOperator = &the_lattice_font_op; - -#endif #ifdef GUILITE_ON #if (defined __linux__) || (defined __APPLE__) #include @@ -4264,11 +4218,7 @@ int c_fifo::write(void* buf, int len) #endif #ifdef GUILITE_ON DIALOG_ARRAY c_dialog::ms_the_dialogs[SURFACE_CNT_MAX]; -#endif -#ifdef GUILITE_ON c_keyboard c_edit::s_keyboard; -#endif -#ifdef GUILITE_ON static c_keyboard_button s_key_0, s_key_1, s_key_2, s_key_3, s_key_4, s_key_5, s_key_6, s_key_7, s_key_8, s_key_9; static c_keyboard_button s_key_A, s_key_B, s_key_C, s_key_D, s_key_E, s_key_F, s_key_G, s_key_H, s_key_I, s_key_J; static c_keyboard_button s_key_K, s_key_L, s_key_M, s_key_N, s_key_O, s_key_P, s_key_Q, s_key_R, s_key_S, s_key_T; @@ -4306,12 +4256,12 @@ WND_TREE g_key_board_children[] = {&s_key_B, 'B', 0, ((KEY_WIDTH / 2) + POS_X(5)), POS_Y(2), KEY_WIDTH, KEY_HEIGHT}, {&s_key_N, 'N', 0, ((KEY_WIDTH / 2) + POS_X(6)), POS_Y(2), KEY_WIDTH, KEY_HEIGHT}, {&s_key_M, 'M', 0, ((KEY_WIDTH / 2) + POS_X(7)), POS_Y(2), KEY_WIDTH, KEY_HEIGHT}, - {&s_key_del, 0x7F, 0, ((KEY_WIDTH / 2) + POS_X(8)), POS_Y(2), DEL_WIDTH, KEY_HEIGHT}, + {&s_key_del,0x7F, 0, ((KEY_WIDTH / 2) + POS_X(8)), POS_Y(2), DEL_WIDTH, KEY_HEIGHT}, //Row 4 - {&s_key_esc, 0x1B, 0, POS_X(0), POS_Y(3), ESC_WIDTH, KEY_HEIGHT}, + {&s_key_esc, 0x1B, 0, POS_X(0), POS_Y(3), ESC_WIDTH, KEY_HEIGHT}, {&s_key_num_switch, 0x90, 0, POS_X(2), POS_Y(3), SWITCH_WIDTH, KEY_HEIGHT}, {&s_key_space, ' ', 0, ((KEY_WIDTH / 2) + POS_X(3)), POS_Y(3), SPACE_WIDTH, KEY_HEIGHT}, - {&s_key_dot, '.', 0, ((KEY_WIDTH / 2) + POS_X(6)), POS_Y(3), DOT_WIDTH, KEY_HEIGHT}, + {&s_key_dot, '.', 0, ((KEY_WIDTH / 2) + POS_X(6)), POS_Y(3), DOT_WIDTH, KEY_HEIGHT}, {&s_key_enter, '\n', 0, POS_X(8), POS_Y(3), ENTER_WIDTH, KEY_HEIGHT}, {0,0,0,0,0,0,0} }; @@ -4326,12 +4276,11 @@ WND_TREE g_number_board_children[] = {&s_key_7, '7', 0, POS_X(0), POS_Y(2), KEY_WIDTH, KEY_HEIGHT}, {&s_key_8, '8', 0, POS_X(1), POS_Y(2), KEY_WIDTH, KEY_HEIGHT}, {&s_key_9, '9', 0, POS_X(2), POS_Y(2), KEY_WIDTH, KEY_HEIGHT}, - - {&s_key_esc, 0x1B, 0, POS_X(0), POS_Y(3), KEY_WIDTH, KEY_HEIGHT}, + {&s_key_esc,0x1B, 0, POS_X(0), POS_Y(3), KEY_WIDTH, KEY_HEIGHT}, {&s_key_0, '0', 0, POS_X(1), POS_Y(3), KEY_WIDTH, KEY_HEIGHT}, - {&s_key_dot, '.', 0, POS_X(2), POS_Y(3), KEY_WIDTH, KEY_HEIGHT}, + {&s_key_dot,'.', 0, POS_X(2), POS_Y(3), KEY_WIDTH, KEY_HEIGHT}, {&s_key_del, 0x7F, 0, POS_X(3), POS_Y(0), KEY_WIDTH, KEY_HEIGHT * 2 + 2}, {&s_key_enter,'\n', 0, POS_X(3), POS_Y(2), KEY_WIDTH, KEY_HEIGHT * 2 + 2}, {0,0,0,0,0,0,0} }; -#endif +#endif \ No newline at end of file diff --git a/HelloFont/BuildLinux/.sync_build.sh b/HelloFont/BuildLinux/.sync_build.sh index 49cff5b473ac606967676ebefa6f0d333e301227..1dfbc1b5ba81df486316a64388b0c7f67b916f80 100644 --- a/HelloFont/BuildLinux/.sync_build.sh +++ b/HelloFont/BuildLinux/.sync_build.sh @@ -1,5 +1,6 @@ if [ "$#" -ne 1 ]; then - echo "Invalid arguments" + echo "Do testing" + ./xWindow 1400 580 | ./HelloFont shared-fb exit -1 fi diff --git a/HelloFont/UIcode/GuiLite.h b/HelloFont/UIcode/GuiLite.h index c4fc88a51476d2c8309c3e55e1270e13784fc510..80550e1632ad7bc82541a2edbb0f7f8f5937954f 100644 --- a/HelloFont/UIcode/GuiLite.h +++ b/HelloFont/UIcode/GuiLite.h @@ -1,107 +1,94 @@ #pragma once - -#define REAL_TIME_TASK_CYCLE_MS 50 -#define MAX(a,b) (((a)>(b))?(a):(b)) -#define MIN(a,b) (((a)<(b))?(a):(b)) - -#define GL_ARGB(a, r, g, b) ((((unsigned int)(a)) << 24) | (((unsigned int)(r)) << 16) | (((unsigned int)(g)) << 8) | ((unsigned int)(b))) -#define GL_ARGB_A(rgb) ((((unsigned int)(rgb)) >> 24) & 0xFF) - -#define GL_RGB(r, g, b) ((0xFF << 24) | (((unsigned int)(r)) << 16) | (((unsigned int)(g)) << 8) | ((unsigned int)(b))) -#define GL_RGB_R(rgb) ((((unsigned int)(rgb)) >> 16) & 0xFF) -#define GL_RGB_G(rgb) ((((unsigned int)(rgb)) >> 8) & 0xFF) -#define GL_RGB_B(rgb) (((unsigned int)(rgb)) & 0xFF) -#define GL_RGB_32_to_16(rgb) (((((unsigned int)(rgb)) & 0xFF) >> 3) | ((((unsigned int)(rgb)) & 0xFC00) >> 5) | ((((unsigned int)(rgb)) & 0xF80000) >> 8)) -#define GL_RGB_16_to_32(rgb) ((0xFF << 24) | ((((unsigned int)(rgb)) & 0x1F) << 3) | ((((unsigned int)(rgb)) & 0x7E0) << 5) | ((((unsigned int)(rgb)) & 0xF800) << 8)) - -#define ALIGN_HCENTER 0x00000000L -#define ALIGN_LEFT 0x01000000L -#define ALIGN_RIGHT 0x02000000L -#define ALIGN_HMASK 0x03000000L - -#define ALIGN_VCENTER 0x00000000L -#define ALIGN_TOP 0x00100000L -#define ALIGN_BOTTOM 0x00200000L -#define ALIGN_VMASK 0x00300000L - -typedef struct -{ - unsigned short year; - unsigned short month; - unsigned short date; - unsigned short day; - unsigned short hour; - unsigned short minute; - unsigned short second; -}T_TIME; - -void register_debug_function(void(*my_assert)(const char* file, int line), void(*my_log_out)(const char* log)); -void _assert(const char* file, int line); -#define ASSERT(condition) \ - do{ \ - if(!(condition))_assert(__FILE__, __LINE__);\ - }while(0) -void log_out(const char* log); - -long get_time_in_second(); -T_TIME second_to_day(long second); -T_TIME get_time(); - -void start_real_timer(void (*func)(void* arg)); -void register_timer(int milli_second, void func(void* param), void* param); - -unsigned int get_cur_thread_id(); -void create_thread(unsigned long* thread_id, void* attr, void *(*start_routine) (void *), void* arg); -void thread_sleep(unsigned int milli_seconds); -int build_bmp(const char *filename, unsigned int width, unsigned int height, unsigned char *data); - -#define FIFO_BUFFER_LEN 1024 -class c_fifo -{ -public: - c_fifo(); - int read(void* buf, int len); - int write(void* buf, int len); -private: - unsigned char m_buf[FIFO_BUFFER_LEN]; - int m_head; - int m_tail; - void* m_read_sem; - void* m_write_mutex; -}; - -class c_rect -{ -public: - c_rect(){ m_left = m_top = m_right = m_bottom = -1; } - c_rect(int left, int top, int width, int height) - { - set_rect(left, top, width, height); - } - void set_rect(int left, int top, int width, int height) - { - ASSERT(width > 0 && height > 0); - m_left = left; - m_top = top; - m_right = left + width - 1; - m_bottom = top + height -1; - } - bool pt_in_rect(int x, int y) const - { - return x >= m_left && x <= m_right && y >= m_top && y <= m_bottom; - } - int operator==(const c_rect& rect) const - { - return (m_left == rect.m_left) && (m_top == rect.m_top) && (m_right == rect.m_right) && (m_bottom == rect.m_bottom); - } - int width() const { return m_right - m_left + 1; } - int height() const { return m_bottom - m_top + 1 ; } - - int m_left; - int m_top; - int m_right; - int m_bottom; -}; +#define REAL_TIME_TASK_CYCLE_MS 50 +#define MAX(a,b) (((a)>(b))?(a):(b)) +#define MIN(a,b) (((a)<(b))?(a):(b)) +#define GL_ARGB(a, r, g, b) ((((unsigned int)(a)) << 24) | (((unsigned int)(r)) << 16) | (((unsigned int)(g)) << 8) | ((unsigned int)(b))) +#define GL_ARGB_A(rgb) ((((unsigned int)(rgb)) >> 24) & 0xFF) +#define GL_RGB(r, g, b) ((0xFF << 24) | (((unsigned int)(r)) << 16) | (((unsigned int)(g)) << 8) | ((unsigned int)(b))) +#define GL_RGB_R(rgb) ((((unsigned int)(rgb)) >> 16) & 0xFF) +#define GL_RGB_G(rgb) ((((unsigned int)(rgb)) >> 8) & 0xFF) +#define GL_RGB_B(rgb) (((unsigned int)(rgb)) & 0xFF) +#define GL_RGB_32_to_16(rgb) (((((unsigned int)(rgb)) & 0xFF) >> 3) | ((((unsigned int)(rgb)) & 0xFC00) >> 5) | ((((unsigned int)(rgb)) & 0xF80000) >> 8)) +#define GL_RGB_16_to_32(rgb) ((0xFF << 24) | ((((unsigned int)(rgb)) & 0x1F) << 3) | ((((unsigned int)(rgb)) & 0x7E0) << 5) | ((((unsigned int)(rgb)) & 0xF800) << 8)) +#define ALIGN_HCENTER 0x00000000L +#define ALIGN_LEFT 0x01000000L +#define ALIGN_RIGHT 0x02000000L +#define ALIGN_HMASK 0x03000000L +#define ALIGN_VCENTER 0x00000000L +#define ALIGN_TOP 0x00100000L +#define ALIGN_BOTTOM 0x00200000L +#define ALIGN_VMASK 0x00300000L +typedef struct +{ + unsigned short year; + unsigned short month; + unsigned short date; + unsigned short day; + unsigned short hour; + unsigned short minute; + unsigned short second; +}T_TIME; +void register_debug_function(void(*my_assert)(const char* file, int line), void(*my_log_out)(const char* log)); +void _assert(const char* file, int line); +#define ASSERT(condition) \ + do{ \ + if(!(condition))_assert(__FILE__, __LINE__);\ + }while(0) +void log_out(const char* log); +long get_time_in_second(); +T_TIME second_to_day(long second); +T_TIME get_time(); +void start_real_timer(void (*func)(void* arg)); +void register_timer(int milli_second, void func(void* param), void* param); +unsigned int get_cur_thread_id(); +void create_thread(unsigned long* thread_id, void* attr, void *(*start_routine) (void *), void* arg); +void thread_sleep(unsigned int milli_seconds); +int build_bmp(const char *filename, unsigned int width, unsigned int height, unsigned char *data); +#define FIFO_BUFFER_LEN 1024 +class c_fifo +{ +public: + c_fifo(); + int read(void* buf, int len); + int write(void* buf, int len); +private: + unsigned char m_buf[FIFO_BUFFER_LEN]; + int m_head; + int m_tail; + void* m_read_sem; + void* m_write_mutex; +}; +class c_rect +{ +public: + c_rect(){ m_left = m_top = m_right = m_bottom = -1; } + c_rect(int left, int top, int width, int height) + { + set_rect(left, top, width, height); + } + void set_rect(int left, int top, int width, int height) + { + ASSERT(width > 0 && height > 0); + m_left = left; + m_top = top; + m_right = left + width - 1; + m_bottom = top + height -1; + } + bool pt_in_rect(int x, int y) const + { + return x >= m_left && x <= m_right && y >= m_top && y <= m_bottom; + } + int operator==(const c_rect& rect) const + { + return (m_left == rect.m_left) && (m_top == rect.m_top) && (m_right == rect.m_right) && (m_bottom == rect.m_bottom); + } + int width() const { return m_right - m_left + 1; } + int height() const { return m_bottom - m_top + 1 ; } + int m_left; + int m_top; + int m_right; + int m_bottom; +}; //BITMAP typedef struct struct_bitmap_info { @@ -238,7 +225,7 @@ typedef enum Z_ORDER_LEVEL_2,//highest graphic level Z_ORDER_LEVEL_MAX }Z_ORDER_LEVEL; -struct EXTERNAL_GFX_OP +struct DISPLAY_DRIVER { void(*draw_pixel)(int x, int y, unsigned int rgb); void(*fill_rect)(int x0, int y0, int x1, int y1, unsigned int rgb); @@ -247,18 +234,19 @@ class c_surface; class c_display { friend class c_surface; public: - inline c_display(void* phy_fb, int display_width, int display_height, int surface_width, int surface_height, unsigned int color_bytes, int surface_cnt, EXTERNAL_GFX_OP* gfx_op = 0);//multiple surface or surface_no_fb - inline c_display(void* phy_fb, int display_width, int display_height, c_surface* surface);//single custom surface - inline c_surface* alloc_surface(Z_ORDER_LEVEL max_zorder, c_rect layer_rect = c_rect());//for multiple surfaces + inline c_display(void* phy_fb, int display_width, int display_height, c_surface* surface, DISPLAY_DRIVER* driver = 0);//single custom surface + inline c_display(void* phy_fb, int display_width, int display_height, int surface_width, int surface_height, unsigned int color_bytes, int surface_cnt, DISPLAY_DRIVER* driver = 0);//multiple surface + inline c_surface* alloc_surface(Z_ORDER_LEVEL max_zorder, c_rect layer_rect = c_rect());//for slide group inline int swipe_surface(c_surface* s0, c_surface* s1, int x0, int x1, int y0, int y1, int offset); int get_width() { return m_width; } int get_height() { return m_height; } + void* get_phy_fb() { return m_phy_fb; } void* get_updated_fb(int* width, int* height, bool force_update = false) { if (width && height) { - *width = get_width(); - *height = get_height(); + *width = m_width; + *height = m_height; } if (force_update) { @@ -277,35 +265,123 @@ public: { return -1; } - int width = get_width(); - int height = get_height(); //16 bits framebuffer if (m_color_bytes == 2) { - return build_bmp(file_name, width, height, (unsigned char*)m_phy_fb); + return build_bmp(file_name, m_width, m_height, (unsigned char*)m_phy_fb); } //32 bits framebuffer - unsigned short* p_bmp565_data = new unsigned short[width * height]; + unsigned short* p_bmp565_data = new unsigned short[m_width * m_height]; unsigned int* p_raw_data = (unsigned int*)m_phy_fb; - for (int i = 0; i < width * height; i++) + for (int i = 0; i < m_width * m_height; i++) { unsigned int rgb = *p_raw_data++; p_bmp565_data[i] = GL_RGB_32_to_16(rgb); } - int ret = build_bmp(file_name, width, height, (unsigned char*)p_bmp565_data); + int ret = build_bmp(file_name, m_width, m_height, (unsigned char*)p_bmp565_data); delete[]p_bmp565_data; return ret; } -private: - int m_width; //in pixels - int m_height; //in pixels - int m_color_bytes; //16 bits, 32 bits only - void* m_phy_fb; //physical framebuffer +protected: + virtual void draw_pixel(int x, int y, unsigned int rgb) + { + if ((x >= m_width) || (y >= m_height)) { return; } + if (m_driver && m_driver->draw_pixel) + { + return m_driver->draw_pixel(x, y, rgb); + } + if (m_color_bytes == 2) + { + ((unsigned short*)m_phy_fb)[y * m_width + x] = GL_RGB_32_to_16(rgb); + } + else + { + ((unsigned int*)m_phy_fb)[y * m_width + x] = rgb; + } + } + virtual void fill_rect(int x0, int y0, int x1, int y1, unsigned int rgb) + { + if (m_driver && m_driver->fill_rect) + { + return m_driver->fill_rect(x0, y0, x1, y1, rgb); + } + if (m_driver && m_driver->draw_pixel) + { + for (int y = y0; y <= y1; y++) + { + for (int x = x0; x <= x1; x++) + { + m_driver->draw_pixel(x, y, rgb); + } + } + return; + } + register int _width = m_width; + register int _height = m_height; + int x, y; + if (m_color_bytes == 2) + { + unsigned short* phy_fb; + unsigned int rgb_16 = GL_RGB_32_to_16(rgb); + for (y = y0; y <= y1; y++) + { + phy_fb = &((unsigned short*)m_phy_fb)[y * _width + x0]; + for (x = x0; x <= x1; x++) + { + if ((x < _width) && (y < _height)) + { + *phy_fb++ = rgb_16; + } + } + } + } + else + { + unsigned int* phy_fb; + for (y = y0; y <= y1; y++) + { + phy_fb = &((unsigned int*)m_phy_fb)[y * _width + x0]; + for (x = x0; x <= x1; x++) + { + if ((x < _width) && (y < _height)) + { + *phy_fb++ = rgb; + } + } + } + } + } + virtual int flush_screen(int left, int top, int right, int bottom, void* fb, int fb_width) + { + if ((0 == m_phy_fb) || (0 == fb)) + { + return -1; + } + register int _width = m_width; + register int _height = m_height; + left = (left >= _width) ? (_width - 1) : left; + right = (right >= _width) ? (_width - 1) : right; + top = (top >= _height) ? (_height - 1) : top; + bottom = (bottom >= _height) ? (_height - 1) : bottom; + for (int y = top; y < bottom; y++) + { + void* s_addr = (char*)fb + ((y * fb_width + left) * m_color_bytes); + void* d_addr = (char*)m_phy_fb + ((y * _width + left) * m_color_bytes); + memcpy(d_addr, s_addr, (right - left) * m_color_bytes); + } + return 0; + } + int m_width; //in pixels + int m_height; //in pixels + int m_color_bytes; //16/32 bits for default + void* m_phy_fb; //physical framebuffer for default + struct DISPLAY_DRIVER* m_driver; //Rendering by external method without default physical framebuffer int m_phy_read_index; int m_phy_write_index; c_surface* m_surface_group[SURFACE_CNT_MAX]; int m_surface_cnt; //surface count int m_surface_index; + }; class c_layer { @@ -317,12 +393,10 @@ public: class c_surface { friend class c_display; friend class c_bitmap_operator; public: - c_surface(unsigned int width, unsigned int height, unsigned int color_bytes, Z_ORDER_LEVEL max_zorder = Z_ORDER_LEVEL_0, c_rect overlpa_rect = c_rect()) : m_width(width), m_height(height), m_color_bytes(color_bytes), m_fb(0), m_is_active(false), m_top_zorder(Z_ORDER_LEVEL_0), m_phy_fb(0), m_phy_write_index(0), m_display(0) + c_surface(unsigned int width, unsigned int height, unsigned int color_bytes, Z_ORDER_LEVEL max_zorder = Z_ORDER_LEVEL_0, c_rect overlpa_rect = c_rect()) : m_width(width), m_height(height), m_color_bytes(color_bytes), m_fb(0), m_is_active(false), m_top_zorder(Z_ORDER_LEVEL_0), m_phy_write_index(0), m_display(0) { (overlpa_rect == c_rect()) ? set_surface(max_zorder, c_rect(0, 0, width - 1, height - 1)) : set_surface(max_zorder, overlpa_rect); } - int get_width() { return m_width; } - int get_height() { return m_height; } unsigned int get_pixel(int x, int y, unsigned int z_order) { if (x >= m_width || y >= m_height || x < 0 || y < 0 || z_order >= Z_ORDER_LEVEL_MAX) @@ -332,15 +406,15 @@ public: } if (m_layers[z_order].fb) { - return (m_color_bytes == 4) ? ((unsigned int*)(m_layers[z_order].fb))[y * m_width + x] : GL_RGB_16_to_32(((unsigned short*)(m_layers[z_order].fb))[y * m_width + x]); + return (m_color_bytes == 2) ? GL_RGB_16_to_32(((unsigned short*)(m_layers[z_order].fb))[y * m_width + x]) : ((unsigned int*)(m_layers[z_order].fb))[y * m_width + x]; } else if (m_fb) { - return (m_color_bytes == 4) ? ((unsigned int*)m_fb)[y * m_width + x] : GL_RGB_16_to_32(((unsigned short*)m_fb)[y * m_width + x]); + return (m_color_bytes == 2) ? GL_RGB_16_to_32(((unsigned short*)m_fb)[y * m_width + x]) : ((unsigned int*)m_fb)[y * m_width + x]; } - else if (m_phy_fb) + else if (m_display->m_phy_fb) { - return (m_color_bytes == 4) ? ((unsigned int*)m_phy_fb)[y * m_width + x] : GL_RGB_16_to_32(((unsigned short*)m_phy_fb)[y * m_width + x]); + return (m_color_bytes == 2) ? GL_RGB_16_to_32(((unsigned short*)m_display->m_phy_fb)[y * m_width + x]) : ((unsigned int*)m_display->m_phy_fb)[y * m_width + x]; } return 0; } @@ -357,7 +431,7 @@ public: } if (z_order == m_max_zorder) { - return draw_pixel_on_fb(x, y, rgb); + return draw_pixel_low_level(x, y, rgb); } if (z_order > (unsigned int)m_top_zorder) @@ -367,19 +441,19 @@ public: if (m_layers[z_order].rect.pt_in_rect(x, y)) { c_rect layer_rect = m_layers[z_order].rect; - if (m_color_bytes == 4) + if (m_color_bytes == 2) { - ((unsigned int*)(m_layers[z_order].fb))[(x - layer_rect.m_left) + (y - layer_rect.m_top) * layer_rect.width()] = rgb; + ((unsigned short*)(m_layers[z_order].fb))[(x - layer_rect.m_left) + (y - layer_rect.m_top) * layer_rect.width()] = GL_RGB_32_to_16(rgb); } else { - ((unsigned short*)(m_layers[z_order].fb))[(x - layer_rect.m_left) + (y - layer_rect.m_top) * layer_rect.width()] = GL_RGB_32_to_16(rgb); + ((unsigned int*)(m_layers[z_order].fb))[(x - layer_rect.m_left) + (y - layer_rect.m_top) * layer_rect.width()] = rgb; } } if (z_order == m_top_zorder) { - return draw_pixel_on_fb(x, y, rgb); + return draw_pixel_low_level(x, y, rgb); } bool be_overlapped = false; for (unsigned int tmp_z_order = Z_ORDER_LEVEL_MAX - 1; tmp_z_order > z_order; tmp_z_order--) @@ -392,7 +466,7 @@ public: } if (!be_overlapped) { - draw_pixel_on_fb(x, y, rgb); + draw_pixel_low_level(x, y, rgb); } } virtual void fill_rect(int x0, int y0, int x1, int y1, unsigned int rgb, unsigned int z_order) @@ -403,7 +477,7 @@ public: y1 = (y1 > (m_height - 1)) ? (m_height - 1) : y1; if (z_order == m_max_zorder) { - return fill_rect_on_fb(x0, y0, x1, y1, rgb); + return fill_rect_low_level(x0, y0, x1, y1, rgb); } if (z_order == m_top_zorder) { @@ -416,18 +490,18 @@ public: { if (layer_rect.pt_in_rect(x, y)) { - if (m_color_bytes == 4) + if (m_color_bytes == 2) { - ((unsigned int*)m_layers[z_order].fb)[(y - layer_rect.m_top) * layer_rect.width() + (x - layer_rect.m_left)] = rgb; + ((unsigned short*)m_layers[z_order].fb)[(y - layer_rect.m_top) * layer_rect.width() + (x - layer_rect.m_left)] = rgb_16; } else { - ((unsigned short*)m_layers[z_order].fb)[(y - layer_rect.m_top) * layer_rect.width() + (x - layer_rect.m_left)] = rgb_16; + ((unsigned int*)m_layers[z_order].fb)[(y - layer_rect.m_top) * layer_rect.width() + (x - layer_rect.m_left)] = rgb; } } } } - return fill_rect_on_fb(x0, y0, x1, y1, rgb); + return fill_rect_low_level(x0, y0, x1, y1, rgb); } for (; y0 <= y1; y0++) { @@ -499,27 +573,16 @@ public: } int flush_screen(int left, int top, int right, int bottom) { - if (left < 0 || left >= m_width || right < 0 || right >= m_width || - top < 0 || top >= m_height || bottom < 0 || bottom >= m_height) - { - ASSERT(false); - } - if (!m_is_active || (0 == m_phy_fb) || (0 == m_fb)) + if (!m_is_active) { return -1; } - int display_width = m_display->get_width(); - int display_height = m_display->get_height(); - left = (left >= display_width) ? (display_width - 1) : left; - right = (right >= display_width) ? (display_width - 1) : right; - top = (top >= display_height) ? (display_height - 1) : top; - bottom = (bottom >= display_height) ? (display_height - 1) : bottom; - for (int y = top; y < bottom; y++) + if (left < 0 || left >= m_width || right < 0 || right >= m_width || + top < 0 || top >= m_height || bottom < 0 || bottom >= m_height) { - void* s_addr = (char*)m_fb + ((y * m_width + left) * m_color_bytes); - void* d_addr = (char*)m_phy_fb + ((y * display_width + left) * m_color_bytes); - memcpy(d_addr, s_addr, (right - left) * m_color_bytes); + ASSERT(false); } + m_display->flush_screen(left, top, right, bottom, m_fb, m_width); *m_phy_write_index = *m_phy_write_index + 1; return 0; } @@ -537,90 +600,62 @@ public: { for (int x = rect.m_left; x <= rect.m_right; x++) { - unsigned int rgb = (m_color_bytes == 4) ? ((unsigned int*)fb)[(x - layer_rect.m_left) + (y - layer_rect.m_top) * width] : GL_RGB_16_to_32(((unsigned short*)fb)[(x - layer_rect.m_left) + (y - layer_rect.m_top) * width]); - draw_pixel_on_fb(x, y, rgb); + unsigned int rgb = (m_color_bytes == 2) ? GL_RGB_16_to_32(((unsigned short*)fb)[(x - layer_rect.m_left) + (y - layer_rect.m_top) * width]) : ((unsigned int*)fb)[(x - layer_rect.m_left) + (y - layer_rect.m_top) * width]; + draw_pixel_low_level(x, y, rgb); } } return 0; } void set_active(bool flag) { m_is_active = flag; } protected: - virtual void fill_rect_on_fb(int x0, int y0, int x1, int y1, unsigned int rgb) - { - int display_width = m_display->get_width(); - int display_height = m_display->get_height(); - if (m_color_bytes == 4) + virtual void fill_rect_low_level(int x0, int y0, int x1, int y1, unsigned int rgb) + {//fill rect on framebuffer of surface + int x, y; + if (m_color_bytes == 2) { - int x; - unsigned int* fb, * phy_fb; - for (; y0 <= y1; y0++) + unsigned short* fb; + unsigned int rgb_16 = GL_RGB_32_to_16(rgb); + for (y = y0; y <= y1; y++) { - x = x0; - fb = m_fb ? &((unsigned int*)m_fb)[y0 * m_width + x] : 0; - phy_fb = &((unsigned int*)m_phy_fb)[y0 * display_width + x]; - *m_phy_write_index = *m_phy_write_index + 1; - for (; x <= x1; x++) + fb = m_fb ? &((unsigned short*)m_fb)[y * m_width + x0] : 0; + if (!fb) { break; } + for (x = x0; x <= x1; x++) { - if (fb) - { - *fb++ = rgb; - } - if (m_is_active && (x < display_width) && (y0 < display_height)) - { - *phy_fb++ = rgb; - } + *fb++ = rgb_16; } } } - else if (m_color_bytes == 2) + else { - int x; - unsigned short* fb, * phy_fb; - rgb = GL_RGB_32_to_16(rgb); - for (; y0 <= y1; y0++) + unsigned int* fb; + for (y = y0; y <= y1; y++) { - x = x0; - fb = m_fb ? &((unsigned short*)m_fb)[y0 * m_width + x] : 0; - phy_fb = &((unsigned short*)m_phy_fb)[y0 * display_width + x]; - *m_phy_write_index = *m_phy_write_index + 1; - for (; x <= x1; x++) + fb = m_fb ? &((unsigned int*)m_fb)[y * m_width + x0] : 0; + if (!fb) { break; } + for (x = x0; x <= x1; x++) { - if (fb) - { - *fb++ = rgb; - } - if (m_is_active && (x < display_width) && (y0 < display_height)) - { - *phy_fb++ = rgb; - } + *fb++ = rgb; } } } + if (!m_is_active) { return; } + m_display->fill_rect(x0, y0, x1, y1, rgb); + *m_phy_write_index = *m_phy_write_index + 1; } - virtual void draw_pixel_on_fb(int x, int y, unsigned int rgb) + virtual void draw_pixel_low_level(int x, int y, unsigned int rgb) { if (m_fb) - { - (m_color_bytes == 4) ? ((unsigned int*)m_fb)[y * m_width + x] = rgb : ((unsigned short*)m_fb)[y * m_width + x] = GL_RGB_32_to_16(rgb); - } - if (m_is_active && (x < m_display->get_width()) && (y < m_display->get_height())) - { - if (m_color_bytes == 4) - { - ((unsigned int*)m_phy_fb)[y * (m_display->get_width()) + x] = rgb; - } - else - { - ((unsigned short*)m_phy_fb)[y * (m_display->get_width()) + x] = GL_RGB_32_to_16(rgb); - } - *m_phy_write_index = *m_phy_write_index + 1; + {//draw pixel on framebuffer of surface + (m_color_bytes == 2) ? ((unsigned short*)m_fb)[y * m_width + x] = GL_RGB_32_to_16(rgb): ((unsigned int*)m_fb)[y * m_width + x] = rgb; } + if (!m_is_active) { return; } + m_display->draw_pixel(x, y, rgb); + *m_phy_write_index = *m_phy_write_index + 1; } void attach_display(c_display* display) { ASSERT(display); m_display = display; - m_phy_fb = display->m_phy_fb; m_phy_write_index = &display->m_phy_write_index; } void set_surface(Z_ORDER_LEVEL max_z_order, c_rect layer_rect) @@ -638,87 +673,22 @@ protected: } int m_width; //in pixels int m_height; //in pixels - int m_color_bytes; //16 bits, 32 bits only + int m_color_bytes; //16 bits, 32 bits for default void* m_fb; //frame buffer you could see c_layer m_layers[Z_ORDER_LEVEL_MAX];//all graphic layers bool m_is_active; //active flag Z_ORDER_LEVEL m_max_zorder; //the highest graphic layer the surface will have Z_ORDER_LEVEL m_top_zorder; //the current highest graphic layer the surface have - void* m_phy_fb; //physical framebufer int* m_phy_write_index; c_display* m_display; }; -class c_surface_no_fb : public c_surface {//No physical framebuffer, render with external graphic interface - friend class c_display; -public: - c_surface_no_fb(unsigned int width, unsigned int height, unsigned int color_bytes, struct EXTERNAL_GFX_OP* gfx_op, Z_ORDER_LEVEL max_zorder = Z_ORDER_LEVEL_0, c_rect overlpa_rect = c_rect()) : c_surface(width, height, color_bytes, max_zorder, overlpa_rect), m_gfx_op(gfx_op) {} -protected: - virtual void fill_rect_on_fb(int x0, int y0, int x1, int y1, unsigned int rgb) - { - if (!m_gfx_op) - { - return; - } - if (m_gfx_op->fill_rect) - { - return m_gfx_op->fill_rect(x0, y0, x1, y1, rgb); - } - if (m_gfx_op->draw_pixel && m_is_active) - { - for (int y = y0; y <= y1; y++) - { - for (int x = x0; x <= x1; x++) - { - m_gfx_op->draw_pixel(x, y, rgb); - } - } - } - if (!m_fb) { return; } - if (m_color_bytes == 4) - { - unsigned int* fb; - for (int y = y0; y <= y1; y++) - { - fb = &((unsigned int*)m_fb)[y0 * m_width + x0]; - for (int x = x0; x <= x1; x++) - { - *fb++ = rgb; - } - } - } - else if (m_color_bytes == 2) - { - unsigned short* fb; - rgb = GL_RGB_32_to_16(rgb); - for (int y = y0; y <= y1; y++) - { - fb = &((unsigned short*)m_fb)[y0 * m_width + x0]; - for (int x = x0; x <= x1; x++) - { - *fb++ = rgb; - } - } - } - } - virtual void draw_pixel_on_fb(int x, int y, unsigned int rgb) - { - if (m_gfx_op && m_gfx_op->draw_pixel && m_is_active) - { - m_gfx_op->draw_pixel(x, y, rgb); - } - if (!m_fb) { return; } - if (m_color_bytes == 4) - { - ((unsigned int*)m_fb)[y * m_width + x] = rgb; - } - else if (m_color_bytes == 2) - { - ((unsigned short*)m_fb)[y * m_width + x] = GL_RGB_32_to_16(rgb); - } - } - struct EXTERNAL_GFX_OP* m_gfx_op;//Rendering by external method -}; -inline c_display::c_display(void* phy_fb, int display_width, int display_height, int surface_width, int surface_height, unsigned int color_bytes, int surface_cnt, EXTERNAL_GFX_OP* gfx_op) : m_width(display_width), m_height(display_height), m_color_bytes(color_bytes), m_phy_fb(phy_fb), m_phy_read_index(0), m_phy_write_index(0), m_surface_cnt(surface_cnt), m_surface_index(0) +inline c_display::c_display(void* phy_fb, int display_width, int display_height, c_surface* surface, DISPLAY_DRIVER* driver) : m_phy_fb(phy_fb), m_width(display_width), m_height(display_height), m_driver(driver), m_phy_read_index(0), m_phy_write_index(0), m_surface_cnt(1), m_surface_index(0) +{ + m_color_bytes = surface->m_color_bytes; + surface->m_is_active = true; + (m_surface_group[0] = surface)->attach_display(this); +} +inline c_display::c_display(void* phy_fb, int display_width, int display_height, int surface_width, int surface_height, unsigned int color_bytes, int surface_cnt, DISPLAY_DRIVER* driver) : m_phy_fb(phy_fb), m_width(display_width), m_height(display_height), m_color_bytes(color_bytes), m_phy_read_index(0), m_phy_write_index(0), m_surface_cnt(surface_cnt), m_driver(driver), m_surface_index(0) { ASSERT(color_bytes == 2 || color_bytes == 4); ASSERT(m_surface_cnt <= SURFACE_CNT_MAX); @@ -726,16 +696,10 @@ inline c_display::c_display(void* phy_fb, int display_width, int display_height, for (int i = 0; i < m_surface_cnt; i++) { - m_surface_group[i] = (phy_fb) ? new c_surface(surface_width, surface_height, color_bytes) : new c_surface_no_fb(surface_width, surface_height, color_bytes, gfx_op); + m_surface_group[i] = new c_surface(surface_width, surface_height, color_bytes); m_surface_group[i]->attach_display(this); } } -inline c_display::c_display(void* phy_fb, int display_width, int display_height, c_surface* surface) : m_width(display_width), m_height(display_height), m_phy_fb(phy_fb), m_phy_read_index(0), m_phy_write_index(0), m_surface_cnt(1), m_surface_index(0) -{ - m_color_bytes = surface->m_color_bytes; - surface->m_is_active = true; - (m_surface_group[0] = surface)->attach_display(this); -} inline c_surface* c_display::alloc_surface(Z_ORDER_LEVEL max_zorder, c_rect layer_rect) { ASSERT(max_zorder < Z_ORDER_LEVEL_MAX && m_surface_index < m_surface_cnt); @@ -744,8 +708,8 @@ inline c_surface* c_display::alloc_surface(Z_ORDER_LEVEL max_zorder, c_rect laye } inline int c_display::swipe_surface(c_surface* s0, c_surface* s1, int x0, int x1, int y0, int y1, int offset) { - int surface_width = s0->get_width(); - int surface_height = s0->get_height(); + register int surface_width = s0->m_width; + register int surface_height = s0->m_height; if (offset < 0 || offset > surface_width || y0 < 0 || y0 >= surface_height || y1 < 0 || y1 >= surface_height || x0 < 0 || x0 >= surface_width || x1 < 0 || x1 >= surface_width) { @@ -767,46 +731,46 @@ inline int c_display::swipe_surface(c_surface* s0, c_surface* s1, int x0, int x1 for (int y = y0; y <= y1; y++) { //Left surface - char* addr_s = ((char*)(s0->m_fb) + (y * (s0->get_width()) + x0 + offset) * m_color_bytes); + char* addr_s = ((char*)(s0->m_fb) + (y * surface_width + x0 + offset) * m_color_bytes); char* addr_d = ((char*)(m_phy_fb)+(y * m_width + x0) * m_color_bytes); memcpy(addr_d, addr_s, (width - offset) * m_color_bytes); //Right surface - addr_s = ((char*)(s1->m_fb) + (y * (s1->get_width()) + x0) * m_color_bytes); + addr_s = ((char*)(s1->m_fb) + (y * surface_width + x0) * m_color_bytes); addr_d = ((char*)(m_phy_fb)+(y * m_width + x0 + (width - offset)) * m_color_bytes); memcpy(addr_d, addr_s, offset * m_color_bytes); } } - else if (m_color_bytes == 4) + else if (m_color_bytes == 2) { - void(*draw_pixel)(int x, int y, unsigned int rgb) = ((c_surface_no_fb*)s0)->m_gfx_op->draw_pixel; + void(*draw_pixel)(int x, int y, unsigned int rgb) = m_driver->draw_pixel; for (int y = y0; y <= y1; y++) { //Left surface for (int x = x0; x <= (x1 - offset); x++) { - draw_pixel(x, y, ((unsigned int*)s0->m_fb)[y * m_width + x + offset]); + draw_pixel(x, y, GL_RGB_16_to_32(((unsigned short*)s0->m_fb)[y * m_width + x + offset])); } //Right surface for (int x = x1 - offset; x <= x1; x++) { - draw_pixel(x, y, ((unsigned int*)s1->m_fb)[y * m_width + x + offset - x1 + x0]); + draw_pixel(x, y, GL_RGB_16_to_32(((unsigned short*)s1->m_fb)[y * m_width + x + offset - x1 + x0])); } } } - else if (m_color_bytes == 2) + else //m_color_bytes == 3/4... { - void(*draw_pixel)(int x, int y, unsigned int rgb) = ((c_surface_no_fb*)s0)->m_gfx_op->draw_pixel; + void(*draw_pixel)(int x, int y, unsigned int rgb) = m_driver->draw_pixel; for (int y = y0; y <= y1; y++) { //Left surface for (int x = x0; x <= (x1 - offset); x++) { - draw_pixel(x, y, GL_RGB_16_to_32(((unsigned short*)s0->m_fb)[y * m_width + x + offset])); + draw_pixel(x, y, ((unsigned int*)s0->m_fb)[y * m_width + x + offset]); } //Right surface for (int x = x1 - offset; x <= x1; x++) { - draw_pixel(x, y, GL_RGB_16_to_32(((unsigned short*)s1->m_fb)[y * m_width + x + offset - x1 + x0])); + draw_pixel(x, y, ((unsigned int*)s1->m_fb)[y * m_width + x + offset - x1 + x0]); } } } @@ -3407,22 +3371,12 @@ private: #ifdef GUILITE_ON c_bitmap_operator the_bitmap_op = c_bitmap_operator(); c_image_operator* c_image::image_operator = &the_bitmap_op; +const void* c_theme::s_font_map[FONT_MAX]; +const void* c_theme::s_image_map[IMAGE_MAX]; +unsigned int c_theme::s_color_map[COLOR_MAX]; +c_lattice_font_op the_lattice_font_op = c_lattice_font_op(); +c_font_operator* c_word::fontOperator = &the_lattice_font_op; #endif - -#ifdef GUILITE_ON - -const void* c_theme::s_font_map[FONT_MAX]; -const void* c_theme::s_image_map[IMAGE_MAX]; -unsigned int c_theme::s_color_map[COLOR_MAX]; - -#endif - -#ifdef GUILITE_ON - -c_lattice_font_op the_lattice_font_op = c_lattice_font_op(); -c_font_operator* c_word::fontOperator = &the_lattice_font_op; - -#endif #ifdef GUILITE_ON #if (defined __linux__) || (defined __APPLE__) #include @@ -4264,11 +4218,7 @@ int c_fifo::write(void* buf, int len) #endif #ifdef GUILITE_ON DIALOG_ARRAY c_dialog::ms_the_dialogs[SURFACE_CNT_MAX]; -#endif -#ifdef GUILITE_ON c_keyboard c_edit::s_keyboard; -#endif -#ifdef GUILITE_ON static c_keyboard_button s_key_0, s_key_1, s_key_2, s_key_3, s_key_4, s_key_5, s_key_6, s_key_7, s_key_8, s_key_9; static c_keyboard_button s_key_A, s_key_B, s_key_C, s_key_D, s_key_E, s_key_F, s_key_G, s_key_H, s_key_I, s_key_J; static c_keyboard_button s_key_K, s_key_L, s_key_M, s_key_N, s_key_O, s_key_P, s_key_Q, s_key_R, s_key_S, s_key_T; @@ -4306,12 +4256,12 @@ WND_TREE g_key_board_children[] = {&s_key_B, 'B', 0, ((KEY_WIDTH / 2) + POS_X(5)), POS_Y(2), KEY_WIDTH, KEY_HEIGHT}, {&s_key_N, 'N', 0, ((KEY_WIDTH / 2) + POS_X(6)), POS_Y(2), KEY_WIDTH, KEY_HEIGHT}, {&s_key_M, 'M', 0, ((KEY_WIDTH / 2) + POS_X(7)), POS_Y(2), KEY_WIDTH, KEY_HEIGHT}, - {&s_key_del, 0x7F, 0, ((KEY_WIDTH / 2) + POS_X(8)), POS_Y(2), DEL_WIDTH, KEY_HEIGHT}, + {&s_key_del,0x7F, 0, ((KEY_WIDTH / 2) + POS_X(8)), POS_Y(2), DEL_WIDTH, KEY_HEIGHT}, //Row 4 - {&s_key_esc, 0x1B, 0, POS_X(0), POS_Y(3), ESC_WIDTH, KEY_HEIGHT}, + {&s_key_esc, 0x1B, 0, POS_X(0), POS_Y(3), ESC_WIDTH, KEY_HEIGHT}, {&s_key_num_switch, 0x90, 0, POS_X(2), POS_Y(3), SWITCH_WIDTH, KEY_HEIGHT}, {&s_key_space, ' ', 0, ((KEY_WIDTH / 2) + POS_X(3)), POS_Y(3), SPACE_WIDTH, KEY_HEIGHT}, - {&s_key_dot, '.', 0, ((KEY_WIDTH / 2) + POS_X(6)), POS_Y(3), DOT_WIDTH, KEY_HEIGHT}, + {&s_key_dot, '.', 0, ((KEY_WIDTH / 2) + POS_X(6)), POS_Y(3), DOT_WIDTH, KEY_HEIGHT}, {&s_key_enter, '\n', 0, POS_X(8), POS_Y(3), ENTER_WIDTH, KEY_HEIGHT}, {0,0,0,0,0,0,0} }; @@ -4326,12 +4276,11 @@ WND_TREE g_number_board_children[] = {&s_key_7, '7', 0, POS_X(0), POS_Y(2), KEY_WIDTH, KEY_HEIGHT}, {&s_key_8, '8', 0, POS_X(1), POS_Y(2), KEY_WIDTH, KEY_HEIGHT}, {&s_key_9, '9', 0, POS_X(2), POS_Y(2), KEY_WIDTH, KEY_HEIGHT}, - - {&s_key_esc, 0x1B, 0, POS_X(0), POS_Y(3), KEY_WIDTH, KEY_HEIGHT}, + {&s_key_esc,0x1B, 0, POS_X(0), POS_Y(3), KEY_WIDTH, KEY_HEIGHT}, {&s_key_0, '0', 0, POS_X(1), POS_Y(3), KEY_WIDTH, KEY_HEIGHT}, - {&s_key_dot, '.', 0, POS_X(2), POS_Y(3), KEY_WIDTH, KEY_HEIGHT}, + {&s_key_dot,'.', 0, POS_X(2), POS_Y(3), KEY_WIDTH, KEY_HEIGHT}, {&s_key_del, 0x7F, 0, POS_X(3), POS_Y(0), KEY_WIDTH, KEY_HEIGHT * 2 + 2}, {&s_key_enter,'\n', 0, POS_X(3), POS_Y(2), KEY_WIDTH, KEY_HEIGHT * 2 + 2}, {0,0,0,0,0,0,0} }; -#endif +#endif \ No newline at end of file diff --git a/HelloFreetype/BuildLinux/.sync_build.sh b/HelloFreetype/BuildLinux/.sync_build.sh index 49cff5b473ac606967676ebefa6f0d333e301227..5b74e1d85527630a572459ef1f3ef41d829e2247 100644 --- a/HelloFreetype/BuildLinux/.sync_build.sh +++ b/HelloFreetype/BuildLinux/.sync_build.sh @@ -1,5 +1,6 @@ if [ "$#" -ne 1 ]; then - echo "Invalid arguments" + echo "Do testing" + ./xWindow 800 600 | ./HelloFreetype shared-fb exit -1 fi diff --git a/HelloFreetype/UIcode/GuiLite.h b/HelloFreetype/UIcode/GuiLite.h index c4fc88a51476d2c8309c3e55e1270e13784fc510..80550e1632ad7bc82541a2edbb0f7f8f5937954f 100644 --- a/HelloFreetype/UIcode/GuiLite.h +++ b/HelloFreetype/UIcode/GuiLite.h @@ -1,107 +1,94 @@ #pragma once - -#define REAL_TIME_TASK_CYCLE_MS 50 -#define MAX(a,b) (((a)>(b))?(a):(b)) -#define MIN(a,b) (((a)<(b))?(a):(b)) - -#define GL_ARGB(a, r, g, b) ((((unsigned int)(a)) << 24) | (((unsigned int)(r)) << 16) | (((unsigned int)(g)) << 8) | ((unsigned int)(b))) -#define GL_ARGB_A(rgb) ((((unsigned int)(rgb)) >> 24) & 0xFF) - -#define GL_RGB(r, g, b) ((0xFF << 24) | (((unsigned int)(r)) << 16) | (((unsigned int)(g)) << 8) | ((unsigned int)(b))) -#define GL_RGB_R(rgb) ((((unsigned int)(rgb)) >> 16) & 0xFF) -#define GL_RGB_G(rgb) ((((unsigned int)(rgb)) >> 8) & 0xFF) -#define GL_RGB_B(rgb) (((unsigned int)(rgb)) & 0xFF) -#define GL_RGB_32_to_16(rgb) (((((unsigned int)(rgb)) & 0xFF) >> 3) | ((((unsigned int)(rgb)) & 0xFC00) >> 5) | ((((unsigned int)(rgb)) & 0xF80000) >> 8)) -#define GL_RGB_16_to_32(rgb) ((0xFF << 24) | ((((unsigned int)(rgb)) & 0x1F) << 3) | ((((unsigned int)(rgb)) & 0x7E0) << 5) | ((((unsigned int)(rgb)) & 0xF800) << 8)) - -#define ALIGN_HCENTER 0x00000000L -#define ALIGN_LEFT 0x01000000L -#define ALIGN_RIGHT 0x02000000L -#define ALIGN_HMASK 0x03000000L - -#define ALIGN_VCENTER 0x00000000L -#define ALIGN_TOP 0x00100000L -#define ALIGN_BOTTOM 0x00200000L -#define ALIGN_VMASK 0x00300000L - -typedef struct -{ - unsigned short year; - unsigned short month; - unsigned short date; - unsigned short day; - unsigned short hour; - unsigned short minute; - unsigned short second; -}T_TIME; - -void register_debug_function(void(*my_assert)(const char* file, int line), void(*my_log_out)(const char* log)); -void _assert(const char* file, int line); -#define ASSERT(condition) \ - do{ \ - if(!(condition))_assert(__FILE__, __LINE__);\ - }while(0) -void log_out(const char* log); - -long get_time_in_second(); -T_TIME second_to_day(long second); -T_TIME get_time(); - -void start_real_timer(void (*func)(void* arg)); -void register_timer(int milli_second, void func(void* param), void* param); - -unsigned int get_cur_thread_id(); -void create_thread(unsigned long* thread_id, void* attr, void *(*start_routine) (void *), void* arg); -void thread_sleep(unsigned int milli_seconds); -int build_bmp(const char *filename, unsigned int width, unsigned int height, unsigned char *data); - -#define FIFO_BUFFER_LEN 1024 -class c_fifo -{ -public: - c_fifo(); - int read(void* buf, int len); - int write(void* buf, int len); -private: - unsigned char m_buf[FIFO_BUFFER_LEN]; - int m_head; - int m_tail; - void* m_read_sem; - void* m_write_mutex; -}; - -class c_rect -{ -public: - c_rect(){ m_left = m_top = m_right = m_bottom = -1; } - c_rect(int left, int top, int width, int height) - { - set_rect(left, top, width, height); - } - void set_rect(int left, int top, int width, int height) - { - ASSERT(width > 0 && height > 0); - m_left = left; - m_top = top; - m_right = left + width - 1; - m_bottom = top + height -1; - } - bool pt_in_rect(int x, int y) const - { - return x >= m_left && x <= m_right && y >= m_top && y <= m_bottom; - } - int operator==(const c_rect& rect) const - { - return (m_left == rect.m_left) && (m_top == rect.m_top) && (m_right == rect.m_right) && (m_bottom == rect.m_bottom); - } - int width() const { return m_right - m_left + 1; } - int height() const { return m_bottom - m_top + 1 ; } - - int m_left; - int m_top; - int m_right; - int m_bottom; -}; +#define REAL_TIME_TASK_CYCLE_MS 50 +#define MAX(a,b) (((a)>(b))?(a):(b)) +#define MIN(a,b) (((a)<(b))?(a):(b)) +#define GL_ARGB(a, r, g, b) ((((unsigned int)(a)) << 24) | (((unsigned int)(r)) << 16) | (((unsigned int)(g)) << 8) | ((unsigned int)(b))) +#define GL_ARGB_A(rgb) ((((unsigned int)(rgb)) >> 24) & 0xFF) +#define GL_RGB(r, g, b) ((0xFF << 24) | (((unsigned int)(r)) << 16) | (((unsigned int)(g)) << 8) | ((unsigned int)(b))) +#define GL_RGB_R(rgb) ((((unsigned int)(rgb)) >> 16) & 0xFF) +#define GL_RGB_G(rgb) ((((unsigned int)(rgb)) >> 8) & 0xFF) +#define GL_RGB_B(rgb) (((unsigned int)(rgb)) & 0xFF) +#define GL_RGB_32_to_16(rgb) (((((unsigned int)(rgb)) & 0xFF) >> 3) | ((((unsigned int)(rgb)) & 0xFC00) >> 5) | ((((unsigned int)(rgb)) & 0xF80000) >> 8)) +#define GL_RGB_16_to_32(rgb) ((0xFF << 24) | ((((unsigned int)(rgb)) & 0x1F) << 3) | ((((unsigned int)(rgb)) & 0x7E0) << 5) | ((((unsigned int)(rgb)) & 0xF800) << 8)) +#define ALIGN_HCENTER 0x00000000L +#define ALIGN_LEFT 0x01000000L +#define ALIGN_RIGHT 0x02000000L +#define ALIGN_HMASK 0x03000000L +#define ALIGN_VCENTER 0x00000000L +#define ALIGN_TOP 0x00100000L +#define ALIGN_BOTTOM 0x00200000L +#define ALIGN_VMASK 0x00300000L +typedef struct +{ + unsigned short year; + unsigned short month; + unsigned short date; + unsigned short day; + unsigned short hour; + unsigned short minute; + unsigned short second; +}T_TIME; +void register_debug_function(void(*my_assert)(const char* file, int line), void(*my_log_out)(const char* log)); +void _assert(const char* file, int line); +#define ASSERT(condition) \ + do{ \ + if(!(condition))_assert(__FILE__, __LINE__);\ + }while(0) +void log_out(const char* log); +long get_time_in_second(); +T_TIME second_to_day(long second); +T_TIME get_time(); +void start_real_timer(void (*func)(void* arg)); +void register_timer(int milli_second, void func(void* param), void* param); +unsigned int get_cur_thread_id(); +void create_thread(unsigned long* thread_id, void* attr, void *(*start_routine) (void *), void* arg); +void thread_sleep(unsigned int milli_seconds); +int build_bmp(const char *filename, unsigned int width, unsigned int height, unsigned char *data); +#define FIFO_BUFFER_LEN 1024 +class c_fifo +{ +public: + c_fifo(); + int read(void* buf, int len); + int write(void* buf, int len); +private: + unsigned char m_buf[FIFO_BUFFER_LEN]; + int m_head; + int m_tail; + void* m_read_sem; + void* m_write_mutex; +}; +class c_rect +{ +public: + c_rect(){ m_left = m_top = m_right = m_bottom = -1; } + c_rect(int left, int top, int width, int height) + { + set_rect(left, top, width, height); + } + void set_rect(int left, int top, int width, int height) + { + ASSERT(width > 0 && height > 0); + m_left = left; + m_top = top; + m_right = left + width - 1; + m_bottom = top + height -1; + } + bool pt_in_rect(int x, int y) const + { + return x >= m_left && x <= m_right && y >= m_top && y <= m_bottom; + } + int operator==(const c_rect& rect) const + { + return (m_left == rect.m_left) && (m_top == rect.m_top) && (m_right == rect.m_right) && (m_bottom == rect.m_bottom); + } + int width() const { return m_right - m_left + 1; } + int height() const { return m_bottom - m_top + 1 ; } + int m_left; + int m_top; + int m_right; + int m_bottom; +}; //BITMAP typedef struct struct_bitmap_info { @@ -238,7 +225,7 @@ typedef enum Z_ORDER_LEVEL_2,//highest graphic level Z_ORDER_LEVEL_MAX }Z_ORDER_LEVEL; -struct EXTERNAL_GFX_OP +struct DISPLAY_DRIVER { void(*draw_pixel)(int x, int y, unsigned int rgb); void(*fill_rect)(int x0, int y0, int x1, int y1, unsigned int rgb); @@ -247,18 +234,19 @@ class c_surface; class c_display { friend class c_surface; public: - inline c_display(void* phy_fb, int display_width, int display_height, int surface_width, int surface_height, unsigned int color_bytes, int surface_cnt, EXTERNAL_GFX_OP* gfx_op = 0);//multiple surface or surface_no_fb - inline c_display(void* phy_fb, int display_width, int display_height, c_surface* surface);//single custom surface - inline c_surface* alloc_surface(Z_ORDER_LEVEL max_zorder, c_rect layer_rect = c_rect());//for multiple surfaces + inline c_display(void* phy_fb, int display_width, int display_height, c_surface* surface, DISPLAY_DRIVER* driver = 0);//single custom surface + inline c_display(void* phy_fb, int display_width, int display_height, int surface_width, int surface_height, unsigned int color_bytes, int surface_cnt, DISPLAY_DRIVER* driver = 0);//multiple surface + inline c_surface* alloc_surface(Z_ORDER_LEVEL max_zorder, c_rect layer_rect = c_rect());//for slide group inline int swipe_surface(c_surface* s0, c_surface* s1, int x0, int x1, int y0, int y1, int offset); int get_width() { return m_width; } int get_height() { return m_height; } + void* get_phy_fb() { return m_phy_fb; } void* get_updated_fb(int* width, int* height, bool force_update = false) { if (width && height) { - *width = get_width(); - *height = get_height(); + *width = m_width; + *height = m_height; } if (force_update) { @@ -277,35 +265,123 @@ public: { return -1; } - int width = get_width(); - int height = get_height(); //16 bits framebuffer if (m_color_bytes == 2) { - return build_bmp(file_name, width, height, (unsigned char*)m_phy_fb); + return build_bmp(file_name, m_width, m_height, (unsigned char*)m_phy_fb); } //32 bits framebuffer - unsigned short* p_bmp565_data = new unsigned short[width * height]; + unsigned short* p_bmp565_data = new unsigned short[m_width * m_height]; unsigned int* p_raw_data = (unsigned int*)m_phy_fb; - for (int i = 0; i < width * height; i++) + for (int i = 0; i < m_width * m_height; i++) { unsigned int rgb = *p_raw_data++; p_bmp565_data[i] = GL_RGB_32_to_16(rgb); } - int ret = build_bmp(file_name, width, height, (unsigned char*)p_bmp565_data); + int ret = build_bmp(file_name, m_width, m_height, (unsigned char*)p_bmp565_data); delete[]p_bmp565_data; return ret; } -private: - int m_width; //in pixels - int m_height; //in pixels - int m_color_bytes; //16 bits, 32 bits only - void* m_phy_fb; //physical framebuffer +protected: + virtual void draw_pixel(int x, int y, unsigned int rgb) + { + if ((x >= m_width) || (y >= m_height)) { return; } + if (m_driver && m_driver->draw_pixel) + { + return m_driver->draw_pixel(x, y, rgb); + } + if (m_color_bytes == 2) + { + ((unsigned short*)m_phy_fb)[y * m_width + x] = GL_RGB_32_to_16(rgb); + } + else + { + ((unsigned int*)m_phy_fb)[y * m_width + x] = rgb; + } + } + virtual void fill_rect(int x0, int y0, int x1, int y1, unsigned int rgb) + { + if (m_driver && m_driver->fill_rect) + { + return m_driver->fill_rect(x0, y0, x1, y1, rgb); + } + if (m_driver && m_driver->draw_pixel) + { + for (int y = y0; y <= y1; y++) + { + for (int x = x0; x <= x1; x++) + { + m_driver->draw_pixel(x, y, rgb); + } + } + return; + } + register int _width = m_width; + register int _height = m_height; + int x, y; + if (m_color_bytes == 2) + { + unsigned short* phy_fb; + unsigned int rgb_16 = GL_RGB_32_to_16(rgb); + for (y = y0; y <= y1; y++) + { + phy_fb = &((unsigned short*)m_phy_fb)[y * _width + x0]; + for (x = x0; x <= x1; x++) + { + if ((x < _width) && (y < _height)) + { + *phy_fb++ = rgb_16; + } + } + } + } + else + { + unsigned int* phy_fb; + for (y = y0; y <= y1; y++) + { + phy_fb = &((unsigned int*)m_phy_fb)[y * _width + x0]; + for (x = x0; x <= x1; x++) + { + if ((x < _width) && (y < _height)) + { + *phy_fb++ = rgb; + } + } + } + } + } + virtual int flush_screen(int left, int top, int right, int bottom, void* fb, int fb_width) + { + if ((0 == m_phy_fb) || (0 == fb)) + { + return -1; + } + register int _width = m_width; + register int _height = m_height; + left = (left >= _width) ? (_width - 1) : left; + right = (right >= _width) ? (_width - 1) : right; + top = (top >= _height) ? (_height - 1) : top; + bottom = (bottom >= _height) ? (_height - 1) : bottom; + for (int y = top; y < bottom; y++) + { + void* s_addr = (char*)fb + ((y * fb_width + left) * m_color_bytes); + void* d_addr = (char*)m_phy_fb + ((y * _width + left) * m_color_bytes); + memcpy(d_addr, s_addr, (right - left) * m_color_bytes); + } + return 0; + } + int m_width; //in pixels + int m_height; //in pixels + int m_color_bytes; //16/32 bits for default + void* m_phy_fb; //physical framebuffer for default + struct DISPLAY_DRIVER* m_driver; //Rendering by external method without default physical framebuffer int m_phy_read_index; int m_phy_write_index; c_surface* m_surface_group[SURFACE_CNT_MAX]; int m_surface_cnt; //surface count int m_surface_index; + }; class c_layer { @@ -317,12 +393,10 @@ public: class c_surface { friend class c_display; friend class c_bitmap_operator; public: - c_surface(unsigned int width, unsigned int height, unsigned int color_bytes, Z_ORDER_LEVEL max_zorder = Z_ORDER_LEVEL_0, c_rect overlpa_rect = c_rect()) : m_width(width), m_height(height), m_color_bytes(color_bytes), m_fb(0), m_is_active(false), m_top_zorder(Z_ORDER_LEVEL_0), m_phy_fb(0), m_phy_write_index(0), m_display(0) + c_surface(unsigned int width, unsigned int height, unsigned int color_bytes, Z_ORDER_LEVEL max_zorder = Z_ORDER_LEVEL_0, c_rect overlpa_rect = c_rect()) : m_width(width), m_height(height), m_color_bytes(color_bytes), m_fb(0), m_is_active(false), m_top_zorder(Z_ORDER_LEVEL_0), m_phy_write_index(0), m_display(0) { (overlpa_rect == c_rect()) ? set_surface(max_zorder, c_rect(0, 0, width - 1, height - 1)) : set_surface(max_zorder, overlpa_rect); } - int get_width() { return m_width; } - int get_height() { return m_height; } unsigned int get_pixel(int x, int y, unsigned int z_order) { if (x >= m_width || y >= m_height || x < 0 || y < 0 || z_order >= Z_ORDER_LEVEL_MAX) @@ -332,15 +406,15 @@ public: } if (m_layers[z_order].fb) { - return (m_color_bytes == 4) ? ((unsigned int*)(m_layers[z_order].fb))[y * m_width + x] : GL_RGB_16_to_32(((unsigned short*)(m_layers[z_order].fb))[y * m_width + x]); + return (m_color_bytes == 2) ? GL_RGB_16_to_32(((unsigned short*)(m_layers[z_order].fb))[y * m_width + x]) : ((unsigned int*)(m_layers[z_order].fb))[y * m_width + x]; } else if (m_fb) { - return (m_color_bytes == 4) ? ((unsigned int*)m_fb)[y * m_width + x] : GL_RGB_16_to_32(((unsigned short*)m_fb)[y * m_width + x]); + return (m_color_bytes == 2) ? GL_RGB_16_to_32(((unsigned short*)m_fb)[y * m_width + x]) : ((unsigned int*)m_fb)[y * m_width + x]; } - else if (m_phy_fb) + else if (m_display->m_phy_fb) { - return (m_color_bytes == 4) ? ((unsigned int*)m_phy_fb)[y * m_width + x] : GL_RGB_16_to_32(((unsigned short*)m_phy_fb)[y * m_width + x]); + return (m_color_bytes == 2) ? GL_RGB_16_to_32(((unsigned short*)m_display->m_phy_fb)[y * m_width + x]) : ((unsigned int*)m_display->m_phy_fb)[y * m_width + x]; } return 0; } @@ -357,7 +431,7 @@ public: } if (z_order == m_max_zorder) { - return draw_pixel_on_fb(x, y, rgb); + return draw_pixel_low_level(x, y, rgb); } if (z_order > (unsigned int)m_top_zorder) @@ -367,19 +441,19 @@ public: if (m_layers[z_order].rect.pt_in_rect(x, y)) { c_rect layer_rect = m_layers[z_order].rect; - if (m_color_bytes == 4) + if (m_color_bytes == 2) { - ((unsigned int*)(m_layers[z_order].fb))[(x - layer_rect.m_left) + (y - layer_rect.m_top) * layer_rect.width()] = rgb; + ((unsigned short*)(m_layers[z_order].fb))[(x - layer_rect.m_left) + (y - layer_rect.m_top) * layer_rect.width()] = GL_RGB_32_to_16(rgb); } else { - ((unsigned short*)(m_layers[z_order].fb))[(x - layer_rect.m_left) + (y - layer_rect.m_top) * layer_rect.width()] = GL_RGB_32_to_16(rgb); + ((unsigned int*)(m_layers[z_order].fb))[(x - layer_rect.m_left) + (y - layer_rect.m_top) * layer_rect.width()] = rgb; } } if (z_order == m_top_zorder) { - return draw_pixel_on_fb(x, y, rgb); + return draw_pixel_low_level(x, y, rgb); } bool be_overlapped = false; for (unsigned int tmp_z_order = Z_ORDER_LEVEL_MAX - 1; tmp_z_order > z_order; tmp_z_order--) @@ -392,7 +466,7 @@ public: } if (!be_overlapped) { - draw_pixel_on_fb(x, y, rgb); + draw_pixel_low_level(x, y, rgb); } } virtual void fill_rect(int x0, int y0, int x1, int y1, unsigned int rgb, unsigned int z_order) @@ -403,7 +477,7 @@ public: y1 = (y1 > (m_height - 1)) ? (m_height - 1) : y1; if (z_order == m_max_zorder) { - return fill_rect_on_fb(x0, y0, x1, y1, rgb); + return fill_rect_low_level(x0, y0, x1, y1, rgb); } if (z_order == m_top_zorder) { @@ -416,18 +490,18 @@ public: { if (layer_rect.pt_in_rect(x, y)) { - if (m_color_bytes == 4) + if (m_color_bytes == 2) { - ((unsigned int*)m_layers[z_order].fb)[(y - layer_rect.m_top) * layer_rect.width() + (x - layer_rect.m_left)] = rgb; + ((unsigned short*)m_layers[z_order].fb)[(y - layer_rect.m_top) * layer_rect.width() + (x - layer_rect.m_left)] = rgb_16; } else { - ((unsigned short*)m_layers[z_order].fb)[(y - layer_rect.m_top) * layer_rect.width() + (x - layer_rect.m_left)] = rgb_16; + ((unsigned int*)m_layers[z_order].fb)[(y - layer_rect.m_top) * layer_rect.width() + (x - layer_rect.m_left)] = rgb; } } } } - return fill_rect_on_fb(x0, y0, x1, y1, rgb); + return fill_rect_low_level(x0, y0, x1, y1, rgb); } for (; y0 <= y1; y0++) { @@ -499,27 +573,16 @@ public: } int flush_screen(int left, int top, int right, int bottom) { - if (left < 0 || left >= m_width || right < 0 || right >= m_width || - top < 0 || top >= m_height || bottom < 0 || bottom >= m_height) - { - ASSERT(false); - } - if (!m_is_active || (0 == m_phy_fb) || (0 == m_fb)) + if (!m_is_active) { return -1; } - int display_width = m_display->get_width(); - int display_height = m_display->get_height(); - left = (left >= display_width) ? (display_width - 1) : left; - right = (right >= display_width) ? (display_width - 1) : right; - top = (top >= display_height) ? (display_height - 1) : top; - bottom = (bottom >= display_height) ? (display_height - 1) : bottom; - for (int y = top; y < bottom; y++) + if (left < 0 || left >= m_width || right < 0 || right >= m_width || + top < 0 || top >= m_height || bottom < 0 || bottom >= m_height) { - void* s_addr = (char*)m_fb + ((y * m_width + left) * m_color_bytes); - void* d_addr = (char*)m_phy_fb + ((y * display_width + left) * m_color_bytes); - memcpy(d_addr, s_addr, (right - left) * m_color_bytes); + ASSERT(false); } + m_display->flush_screen(left, top, right, bottom, m_fb, m_width); *m_phy_write_index = *m_phy_write_index + 1; return 0; } @@ -537,90 +600,62 @@ public: { for (int x = rect.m_left; x <= rect.m_right; x++) { - unsigned int rgb = (m_color_bytes == 4) ? ((unsigned int*)fb)[(x - layer_rect.m_left) + (y - layer_rect.m_top) * width] : GL_RGB_16_to_32(((unsigned short*)fb)[(x - layer_rect.m_left) + (y - layer_rect.m_top) * width]); - draw_pixel_on_fb(x, y, rgb); + unsigned int rgb = (m_color_bytes == 2) ? GL_RGB_16_to_32(((unsigned short*)fb)[(x - layer_rect.m_left) + (y - layer_rect.m_top) * width]) : ((unsigned int*)fb)[(x - layer_rect.m_left) + (y - layer_rect.m_top) * width]; + draw_pixel_low_level(x, y, rgb); } } return 0; } void set_active(bool flag) { m_is_active = flag; } protected: - virtual void fill_rect_on_fb(int x0, int y0, int x1, int y1, unsigned int rgb) - { - int display_width = m_display->get_width(); - int display_height = m_display->get_height(); - if (m_color_bytes == 4) + virtual void fill_rect_low_level(int x0, int y0, int x1, int y1, unsigned int rgb) + {//fill rect on framebuffer of surface + int x, y; + if (m_color_bytes == 2) { - int x; - unsigned int* fb, * phy_fb; - for (; y0 <= y1; y0++) + unsigned short* fb; + unsigned int rgb_16 = GL_RGB_32_to_16(rgb); + for (y = y0; y <= y1; y++) { - x = x0; - fb = m_fb ? &((unsigned int*)m_fb)[y0 * m_width + x] : 0; - phy_fb = &((unsigned int*)m_phy_fb)[y0 * display_width + x]; - *m_phy_write_index = *m_phy_write_index + 1; - for (; x <= x1; x++) + fb = m_fb ? &((unsigned short*)m_fb)[y * m_width + x0] : 0; + if (!fb) { break; } + for (x = x0; x <= x1; x++) { - if (fb) - { - *fb++ = rgb; - } - if (m_is_active && (x < display_width) && (y0 < display_height)) - { - *phy_fb++ = rgb; - } + *fb++ = rgb_16; } } } - else if (m_color_bytes == 2) + else { - int x; - unsigned short* fb, * phy_fb; - rgb = GL_RGB_32_to_16(rgb); - for (; y0 <= y1; y0++) + unsigned int* fb; + for (y = y0; y <= y1; y++) { - x = x0; - fb = m_fb ? &((unsigned short*)m_fb)[y0 * m_width + x] : 0; - phy_fb = &((unsigned short*)m_phy_fb)[y0 * display_width + x]; - *m_phy_write_index = *m_phy_write_index + 1; - for (; x <= x1; x++) + fb = m_fb ? &((unsigned int*)m_fb)[y * m_width + x0] : 0; + if (!fb) { break; } + for (x = x0; x <= x1; x++) { - if (fb) - { - *fb++ = rgb; - } - if (m_is_active && (x < display_width) && (y0 < display_height)) - { - *phy_fb++ = rgb; - } + *fb++ = rgb; } } } + if (!m_is_active) { return; } + m_display->fill_rect(x0, y0, x1, y1, rgb); + *m_phy_write_index = *m_phy_write_index + 1; } - virtual void draw_pixel_on_fb(int x, int y, unsigned int rgb) + virtual void draw_pixel_low_level(int x, int y, unsigned int rgb) { if (m_fb) - { - (m_color_bytes == 4) ? ((unsigned int*)m_fb)[y * m_width + x] = rgb : ((unsigned short*)m_fb)[y * m_width + x] = GL_RGB_32_to_16(rgb); - } - if (m_is_active && (x < m_display->get_width()) && (y < m_display->get_height())) - { - if (m_color_bytes == 4) - { - ((unsigned int*)m_phy_fb)[y * (m_display->get_width()) + x] = rgb; - } - else - { - ((unsigned short*)m_phy_fb)[y * (m_display->get_width()) + x] = GL_RGB_32_to_16(rgb); - } - *m_phy_write_index = *m_phy_write_index + 1; + {//draw pixel on framebuffer of surface + (m_color_bytes == 2) ? ((unsigned short*)m_fb)[y * m_width + x] = GL_RGB_32_to_16(rgb): ((unsigned int*)m_fb)[y * m_width + x] = rgb; } + if (!m_is_active) { return; } + m_display->draw_pixel(x, y, rgb); + *m_phy_write_index = *m_phy_write_index + 1; } void attach_display(c_display* display) { ASSERT(display); m_display = display; - m_phy_fb = display->m_phy_fb; m_phy_write_index = &display->m_phy_write_index; } void set_surface(Z_ORDER_LEVEL max_z_order, c_rect layer_rect) @@ -638,87 +673,22 @@ protected: } int m_width; //in pixels int m_height; //in pixels - int m_color_bytes; //16 bits, 32 bits only + int m_color_bytes; //16 bits, 32 bits for default void* m_fb; //frame buffer you could see c_layer m_layers[Z_ORDER_LEVEL_MAX];//all graphic layers bool m_is_active; //active flag Z_ORDER_LEVEL m_max_zorder; //the highest graphic layer the surface will have Z_ORDER_LEVEL m_top_zorder; //the current highest graphic layer the surface have - void* m_phy_fb; //physical framebufer int* m_phy_write_index; c_display* m_display; }; -class c_surface_no_fb : public c_surface {//No physical framebuffer, render with external graphic interface - friend class c_display; -public: - c_surface_no_fb(unsigned int width, unsigned int height, unsigned int color_bytes, struct EXTERNAL_GFX_OP* gfx_op, Z_ORDER_LEVEL max_zorder = Z_ORDER_LEVEL_0, c_rect overlpa_rect = c_rect()) : c_surface(width, height, color_bytes, max_zorder, overlpa_rect), m_gfx_op(gfx_op) {} -protected: - virtual void fill_rect_on_fb(int x0, int y0, int x1, int y1, unsigned int rgb) - { - if (!m_gfx_op) - { - return; - } - if (m_gfx_op->fill_rect) - { - return m_gfx_op->fill_rect(x0, y0, x1, y1, rgb); - } - if (m_gfx_op->draw_pixel && m_is_active) - { - for (int y = y0; y <= y1; y++) - { - for (int x = x0; x <= x1; x++) - { - m_gfx_op->draw_pixel(x, y, rgb); - } - } - } - if (!m_fb) { return; } - if (m_color_bytes == 4) - { - unsigned int* fb; - for (int y = y0; y <= y1; y++) - { - fb = &((unsigned int*)m_fb)[y0 * m_width + x0]; - for (int x = x0; x <= x1; x++) - { - *fb++ = rgb; - } - } - } - else if (m_color_bytes == 2) - { - unsigned short* fb; - rgb = GL_RGB_32_to_16(rgb); - for (int y = y0; y <= y1; y++) - { - fb = &((unsigned short*)m_fb)[y0 * m_width + x0]; - for (int x = x0; x <= x1; x++) - { - *fb++ = rgb; - } - } - } - } - virtual void draw_pixel_on_fb(int x, int y, unsigned int rgb) - { - if (m_gfx_op && m_gfx_op->draw_pixel && m_is_active) - { - m_gfx_op->draw_pixel(x, y, rgb); - } - if (!m_fb) { return; } - if (m_color_bytes == 4) - { - ((unsigned int*)m_fb)[y * m_width + x] = rgb; - } - else if (m_color_bytes == 2) - { - ((unsigned short*)m_fb)[y * m_width + x] = GL_RGB_32_to_16(rgb); - } - } - struct EXTERNAL_GFX_OP* m_gfx_op;//Rendering by external method -}; -inline c_display::c_display(void* phy_fb, int display_width, int display_height, int surface_width, int surface_height, unsigned int color_bytes, int surface_cnt, EXTERNAL_GFX_OP* gfx_op) : m_width(display_width), m_height(display_height), m_color_bytes(color_bytes), m_phy_fb(phy_fb), m_phy_read_index(0), m_phy_write_index(0), m_surface_cnt(surface_cnt), m_surface_index(0) +inline c_display::c_display(void* phy_fb, int display_width, int display_height, c_surface* surface, DISPLAY_DRIVER* driver) : m_phy_fb(phy_fb), m_width(display_width), m_height(display_height), m_driver(driver), m_phy_read_index(0), m_phy_write_index(0), m_surface_cnt(1), m_surface_index(0) +{ + m_color_bytes = surface->m_color_bytes; + surface->m_is_active = true; + (m_surface_group[0] = surface)->attach_display(this); +} +inline c_display::c_display(void* phy_fb, int display_width, int display_height, int surface_width, int surface_height, unsigned int color_bytes, int surface_cnt, DISPLAY_DRIVER* driver) : m_phy_fb(phy_fb), m_width(display_width), m_height(display_height), m_color_bytes(color_bytes), m_phy_read_index(0), m_phy_write_index(0), m_surface_cnt(surface_cnt), m_driver(driver), m_surface_index(0) { ASSERT(color_bytes == 2 || color_bytes == 4); ASSERT(m_surface_cnt <= SURFACE_CNT_MAX); @@ -726,16 +696,10 @@ inline c_display::c_display(void* phy_fb, int display_width, int display_height, for (int i = 0; i < m_surface_cnt; i++) { - m_surface_group[i] = (phy_fb) ? new c_surface(surface_width, surface_height, color_bytes) : new c_surface_no_fb(surface_width, surface_height, color_bytes, gfx_op); + m_surface_group[i] = new c_surface(surface_width, surface_height, color_bytes); m_surface_group[i]->attach_display(this); } } -inline c_display::c_display(void* phy_fb, int display_width, int display_height, c_surface* surface) : m_width(display_width), m_height(display_height), m_phy_fb(phy_fb), m_phy_read_index(0), m_phy_write_index(0), m_surface_cnt(1), m_surface_index(0) -{ - m_color_bytes = surface->m_color_bytes; - surface->m_is_active = true; - (m_surface_group[0] = surface)->attach_display(this); -} inline c_surface* c_display::alloc_surface(Z_ORDER_LEVEL max_zorder, c_rect layer_rect) { ASSERT(max_zorder < Z_ORDER_LEVEL_MAX && m_surface_index < m_surface_cnt); @@ -744,8 +708,8 @@ inline c_surface* c_display::alloc_surface(Z_ORDER_LEVEL max_zorder, c_rect laye } inline int c_display::swipe_surface(c_surface* s0, c_surface* s1, int x0, int x1, int y0, int y1, int offset) { - int surface_width = s0->get_width(); - int surface_height = s0->get_height(); + register int surface_width = s0->m_width; + register int surface_height = s0->m_height; if (offset < 0 || offset > surface_width || y0 < 0 || y0 >= surface_height || y1 < 0 || y1 >= surface_height || x0 < 0 || x0 >= surface_width || x1 < 0 || x1 >= surface_width) { @@ -767,46 +731,46 @@ inline int c_display::swipe_surface(c_surface* s0, c_surface* s1, int x0, int x1 for (int y = y0; y <= y1; y++) { //Left surface - char* addr_s = ((char*)(s0->m_fb) + (y * (s0->get_width()) + x0 + offset) * m_color_bytes); + char* addr_s = ((char*)(s0->m_fb) + (y * surface_width + x0 + offset) * m_color_bytes); char* addr_d = ((char*)(m_phy_fb)+(y * m_width + x0) * m_color_bytes); memcpy(addr_d, addr_s, (width - offset) * m_color_bytes); //Right surface - addr_s = ((char*)(s1->m_fb) + (y * (s1->get_width()) + x0) * m_color_bytes); + addr_s = ((char*)(s1->m_fb) + (y * surface_width + x0) * m_color_bytes); addr_d = ((char*)(m_phy_fb)+(y * m_width + x0 + (width - offset)) * m_color_bytes); memcpy(addr_d, addr_s, offset * m_color_bytes); } } - else if (m_color_bytes == 4) + else if (m_color_bytes == 2) { - void(*draw_pixel)(int x, int y, unsigned int rgb) = ((c_surface_no_fb*)s0)->m_gfx_op->draw_pixel; + void(*draw_pixel)(int x, int y, unsigned int rgb) = m_driver->draw_pixel; for (int y = y0; y <= y1; y++) { //Left surface for (int x = x0; x <= (x1 - offset); x++) { - draw_pixel(x, y, ((unsigned int*)s0->m_fb)[y * m_width + x + offset]); + draw_pixel(x, y, GL_RGB_16_to_32(((unsigned short*)s0->m_fb)[y * m_width + x + offset])); } //Right surface for (int x = x1 - offset; x <= x1; x++) { - draw_pixel(x, y, ((unsigned int*)s1->m_fb)[y * m_width + x + offset - x1 + x0]); + draw_pixel(x, y, GL_RGB_16_to_32(((unsigned short*)s1->m_fb)[y * m_width + x + offset - x1 + x0])); } } } - else if (m_color_bytes == 2) + else //m_color_bytes == 3/4... { - void(*draw_pixel)(int x, int y, unsigned int rgb) = ((c_surface_no_fb*)s0)->m_gfx_op->draw_pixel; + void(*draw_pixel)(int x, int y, unsigned int rgb) = m_driver->draw_pixel; for (int y = y0; y <= y1; y++) { //Left surface for (int x = x0; x <= (x1 - offset); x++) { - draw_pixel(x, y, GL_RGB_16_to_32(((unsigned short*)s0->m_fb)[y * m_width + x + offset])); + draw_pixel(x, y, ((unsigned int*)s0->m_fb)[y * m_width + x + offset]); } //Right surface for (int x = x1 - offset; x <= x1; x++) { - draw_pixel(x, y, GL_RGB_16_to_32(((unsigned short*)s1->m_fb)[y * m_width + x + offset - x1 + x0])); + draw_pixel(x, y, ((unsigned int*)s1->m_fb)[y * m_width + x + offset - x1 + x0]); } } } @@ -3407,22 +3371,12 @@ private: #ifdef GUILITE_ON c_bitmap_operator the_bitmap_op = c_bitmap_operator(); c_image_operator* c_image::image_operator = &the_bitmap_op; +const void* c_theme::s_font_map[FONT_MAX]; +const void* c_theme::s_image_map[IMAGE_MAX]; +unsigned int c_theme::s_color_map[COLOR_MAX]; +c_lattice_font_op the_lattice_font_op = c_lattice_font_op(); +c_font_operator* c_word::fontOperator = &the_lattice_font_op; #endif - -#ifdef GUILITE_ON - -const void* c_theme::s_font_map[FONT_MAX]; -const void* c_theme::s_image_map[IMAGE_MAX]; -unsigned int c_theme::s_color_map[COLOR_MAX]; - -#endif - -#ifdef GUILITE_ON - -c_lattice_font_op the_lattice_font_op = c_lattice_font_op(); -c_font_operator* c_word::fontOperator = &the_lattice_font_op; - -#endif #ifdef GUILITE_ON #if (defined __linux__) || (defined __APPLE__) #include @@ -4264,11 +4218,7 @@ int c_fifo::write(void* buf, int len) #endif #ifdef GUILITE_ON DIALOG_ARRAY c_dialog::ms_the_dialogs[SURFACE_CNT_MAX]; -#endif -#ifdef GUILITE_ON c_keyboard c_edit::s_keyboard; -#endif -#ifdef GUILITE_ON static c_keyboard_button s_key_0, s_key_1, s_key_2, s_key_3, s_key_4, s_key_5, s_key_6, s_key_7, s_key_8, s_key_9; static c_keyboard_button s_key_A, s_key_B, s_key_C, s_key_D, s_key_E, s_key_F, s_key_G, s_key_H, s_key_I, s_key_J; static c_keyboard_button s_key_K, s_key_L, s_key_M, s_key_N, s_key_O, s_key_P, s_key_Q, s_key_R, s_key_S, s_key_T; @@ -4306,12 +4256,12 @@ WND_TREE g_key_board_children[] = {&s_key_B, 'B', 0, ((KEY_WIDTH / 2) + POS_X(5)), POS_Y(2), KEY_WIDTH, KEY_HEIGHT}, {&s_key_N, 'N', 0, ((KEY_WIDTH / 2) + POS_X(6)), POS_Y(2), KEY_WIDTH, KEY_HEIGHT}, {&s_key_M, 'M', 0, ((KEY_WIDTH / 2) + POS_X(7)), POS_Y(2), KEY_WIDTH, KEY_HEIGHT}, - {&s_key_del, 0x7F, 0, ((KEY_WIDTH / 2) + POS_X(8)), POS_Y(2), DEL_WIDTH, KEY_HEIGHT}, + {&s_key_del,0x7F, 0, ((KEY_WIDTH / 2) + POS_X(8)), POS_Y(2), DEL_WIDTH, KEY_HEIGHT}, //Row 4 - {&s_key_esc, 0x1B, 0, POS_X(0), POS_Y(3), ESC_WIDTH, KEY_HEIGHT}, + {&s_key_esc, 0x1B, 0, POS_X(0), POS_Y(3), ESC_WIDTH, KEY_HEIGHT}, {&s_key_num_switch, 0x90, 0, POS_X(2), POS_Y(3), SWITCH_WIDTH, KEY_HEIGHT}, {&s_key_space, ' ', 0, ((KEY_WIDTH / 2) + POS_X(3)), POS_Y(3), SPACE_WIDTH, KEY_HEIGHT}, - {&s_key_dot, '.', 0, ((KEY_WIDTH / 2) + POS_X(6)), POS_Y(3), DOT_WIDTH, KEY_HEIGHT}, + {&s_key_dot, '.', 0, ((KEY_WIDTH / 2) + POS_X(6)), POS_Y(3), DOT_WIDTH, KEY_HEIGHT}, {&s_key_enter, '\n', 0, POS_X(8), POS_Y(3), ENTER_WIDTH, KEY_HEIGHT}, {0,0,0,0,0,0,0} }; @@ -4326,12 +4276,11 @@ WND_TREE g_number_board_children[] = {&s_key_7, '7', 0, POS_X(0), POS_Y(2), KEY_WIDTH, KEY_HEIGHT}, {&s_key_8, '8', 0, POS_X(1), POS_Y(2), KEY_WIDTH, KEY_HEIGHT}, {&s_key_9, '9', 0, POS_X(2), POS_Y(2), KEY_WIDTH, KEY_HEIGHT}, - - {&s_key_esc, 0x1B, 0, POS_X(0), POS_Y(3), KEY_WIDTH, KEY_HEIGHT}, + {&s_key_esc,0x1B, 0, POS_X(0), POS_Y(3), KEY_WIDTH, KEY_HEIGHT}, {&s_key_0, '0', 0, POS_X(1), POS_Y(3), KEY_WIDTH, KEY_HEIGHT}, - {&s_key_dot, '.', 0, POS_X(2), POS_Y(3), KEY_WIDTH, KEY_HEIGHT}, + {&s_key_dot,'.', 0, POS_X(2), POS_Y(3), KEY_WIDTH, KEY_HEIGHT}, {&s_key_del, 0x7F, 0, POS_X(3), POS_Y(0), KEY_WIDTH, KEY_HEIGHT * 2 + 2}, {&s_key_enter,'\n', 0, POS_X(3), POS_Y(2), KEY_WIDTH, KEY_HEIGHT * 2 + 2}, {0,0,0,0,0,0,0} }; -#endif +#endif \ No newline at end of file diff --git a/HelloJPG/BuildLinux/.sync_build.sh b/HelloJPG/BuildLinux/.sync_build.sh index 49cff5b473ac606967676ebefa6f0d333e301227..96541c31d206550b74ff6d6234e904b32dca7ad4 100644 --- a/HelloJPG/BuildLinux/.sync_build.sh +++ b/HelloJPG/BuildLinux/.sync_build.sh @@ -1,5 +1,6 @@ if [ "$#" -ne 1 ]; then - echo "Invalid arguments" + echo "Do testing" + ./xWindow 800 600 | ./HelloJPG shared-fb exit -1 fi diff --git a/HelloJPG/UIcode/GuiLite.h b/HelloJPG/UIcode/GuiLite.h index c4fc88a51476d2c8309c3e55e1270e13784fc510..80550e1632ad7bc82541a2edbb0f7f8f5937954f 100644 --- a/HelloJPG/UIcode/GuiLite.h +++ b/HelloJPG/UIcode/GuiLite.h @@ -1,107 +1,94 @@ #pragma once - -#define REAL_TIME_TASK_CYCLE_MS 50 -#define MAX(a,b) (((a)>(b))?(a):(b)) -#define MIN(a,b) (((a)<(b))?(a):(b)) - -#define GL_ARGB(a, r, g, b) ((((unsigned int)(a)) << 24) | (((unsigned int)(r)) << 16) | (((unsigned int)(g)) << 8) | ((unsigned int)(b))) -#define GL_ARGB_A(rgb) ((((unsigned int)(rgb)) >> 24) & 0xFF) - -#define GL_RGB(r, g, b) ((0xFF << 24) | (((unsigned int)(r)) << 16) | (((unsigned int)(g)) << 8) | ((unsigned int)(b))) -#define GL_RGB_R(rgb) ((((unsigned int)(rgb)) >> 16) & 0xFF) -#define GL_RGB_G(rgb) ((((unsigned int)(rgb)) >> 8) & 0xFF) -#define GL_RGB_B(rgb) (((unsigned int)(rgb)) & 0xFF) -#define GL_RGB_32_to_16(rgb) (((((unsigned int)(rgb)) & 0xFF) >> 3) | ((((unsigned int)(rgb)) & 0xFC00) >> 5) | ((((unsigned int)(rgb)) & 0xF80000) >> 8)) -#define GL_RGB_16_to_32(rgb) ((0xFF << 24) | ((((unsigned int)(rgb)) & 0x1F) << 3) | ((((unsigned int)(rgb)) & 0x7E0) << 5) | ((((unsigned int)(rgb)) & 0xF800) << 8)) - -#define ALIGN_HCENTER 0x00000000L -#define ALIGN_LEFT 0x01000000L -#define ALIGN_RIGHT 0x02000000L -#define ALIGN_HMASK 0x03000000L - -#define ALIGN_VCENTER 0x00000000L -#define ALIGN_TOP 0x00100000L -#define ALIGN_BOTTOM 0x00200000L -#define ALIGN_VMASK 0x00300000L - -typedef struct -{ - unsigned short year; - unsigned short month; - unsigned short date; - unsigned short day; - unsigned short hour; - unsigned short minute; - unsigned short second; -}T_TIME; - -void register_debug_function(void(*my_assert)(const char* file, int line), void(*my_log_out)(const char* log)); -void _assert(const char* file, int line); -#define ASSERT(condition) \ - do{ \ - if(!(condition))_assert(__FILE__, __LINE__);\ - }while(0) -void log_out(const char* log); - -long get_time_in_second(); -T_TIME second_to_day(long second); -T_TIME get_time(); - -void start_real_timer(void (*func)(void* arg)); -void register_timer(int milli_second, void func(void* param), void* param); - -unsigned int get_cur_thread_id(); -void create_thread(unsigned long* thread_id, void* attr, void *(*start_routine) (void *), void* arg); -void thread_sleep(unsigned int milli_seconds); -int build_bmp(const char *filename, unsigned int width, unsigned int height, unsigned char *data); - -#define FIFO_BUFFER_LEN 1024 -class c_fifo -{ -public: - c_fifo(); - int read(void* buf, int len); - int write(void* buf, int len); -private: - unsigned char m_buf[FIFO_BUFFER_LEN]; - int m_head; - int m_tail; - void* m_read_sem; - void* m_write_mutex; -}; - -class c_rect -{ -public: - c_rect(){ m_left = m_top = m_right = m_bottom = -1; } - c_rect(int left, int top, int width, int height) - { - set_rect(left, top, width, height); - } - void set_rect(int left, int top, int width, int height) - { - ASSERT(width > 0 && height > 0); - m_left = left; - m_top = top; - m_right = left + width - 1; - m_bottom = top + height -1; - } - bool pt_in_rect(int x, int y) const - { - return x >= m_left && x <= m_right && y >= m_top && y <= m_bottom; - } - int operator==(const c_rect& rect) const - { - return (m_left == rect.m_left) && (m_top == rect.m_top) && (m_right == rect.m_right) && (m_bottom == rect.m_bottom); - } - int width() const { return m_right - m_left + 1; } - int height() const { return m_bottom - m_top + 1 ; } - - int m_left; - int m_top; - int m_right; - int m_bottom; -}; +#define REAL_TIME_TASK_CYCLE_MS 50 +#define MAX(a,b) (((a)>(b))?(a):(b)) +#define MIN(a,b) (((a)<(b))?(a):(b)) +#define GL_ARGB(a, r, g, b) ((((unsigned int)(a)) << 24) | (((unsigned int)(r)) << 16) | (((unsigned int)(g)) << 8) | ((unsigned int)(b))) +#define GL_ARGB_A(rgb) ((((unsigned int)(rgb)) >> 24) & 0xFF) +#define GL_RGB(r, g, b) ((0xFF << 24) | (((unsigned int)(r)) << 16) | (((unsigned int)(g)) << 8) | ((unsigned int)(b))) +#define GL_RGB_R(rgb) ((((unsigned int)(rgb)) >> 16) & 0xFF) +#define GL_RGB_G(rgb) ((((unsigned int)(rgb)) >> 8) & 0xFF) +#define GL_RGB_B(rgb) (((unsigned int)(rgb)) & 0xFF) +#define GL_RGB_32_to_16(rgb) (((((unsigned int)(rgb)) & 0xFF) >> 3) | ((((unsigned int)(rgb)) & 0xFC00) >> 5) | ((((unsigned int)(rgb)) & 0xF80000) >> 8)) +#define GL_RGB_16_to_32(rgb) ((0xFF << 24) | ((((unsigned int)(rgb)) & 0x1F) << 3) | ((((unsigned int)(rgb)) & 0x7E0) << 5) | ((((unsigned int)(rgb)) & 0xF800) << 8)) +#define ALIGN_HCENTER 0x00000000L +#define ALIGN_LEFT 0x01000000L +#define ALIGN_RIGHT 0x02000000L +#define ALIGN_HMASK 0x03000000L +#define ALIGN_VCENTER 0x00000000L +#define ALIGN_TOP 0x00100000L +#define ALIGN_BOTTOM 0x00200000L +#define ALIGN_VMASK 0x00300000L +typedef struct +{ + unsigned short year; + unsigned short month; + unsigned short date; + unsigned short day; + unsigned short hour; + unsigned short minute; + unsigned short second; +}T_TIME; +void register_debug_function(void(*my_assert)(const char* file, int line), void(*my_log_out)(const char* log)); +void _assert(const char* file, int line); +#define ASSERT(condition) \ + do{ \ + if(!(condition))_assert(__FILE__, __LINE__);\ + }while(0) +void log_out(const char* log); +long get_time_in_second(); +T_TIME second_to_day(long second); +T_TIME get_time(); +void start_real_timer(void (*func)(void* arg)); +void register_timer(int milli_second, void func(void* param), void* param); +unsigned int get_cur_thread_id(); +void create_thread(unsigned long* thread_id, void* attr, void *(*start_routine) (void *), void* arg); +void thread_sleep(unsigned int milli_seconds); +int build_bmp(const char *filename, unsigned int width, unsigned int height, unsigned char *data); +#define FIFO_BUFFER_LEN 1024 +class c_fifo +{ +public: + c_fifo(); + int read(void* buf, int len); + int write(void* buf, int len); +private: + unsigned char m_buf[FIFO_BUFFER_LEN]; + int m_head; + int m_tail; + void* m_read_sem; + void* m_write_mutex; +}; +class c_rect +{ +public: + c_rect(){ m_left = m_top = m_right = m_bottom = -1; } + c_rect(int left, int top, int width, int height) + { + set_rect(left, top, width, height); + } + void set_rect(int left, int top, int width, int height) + { + ASSERT(width > 0 && height > 0); + m_left = left; + m_top = top; + m_right = left + width - 1; + m_bottom = top + height -1; + } + bool pt_in_rect(int x, int y) const + { + return x >= m_left && x <= m_right && y >= m_top && y <= m_bottom; + } + int operator==(const c_rect& rect) const + { + return (m_left == rect.m_left) && (m_top == rect.m_top) && (m_right == rect.m_right) && (m_bottom == rect.m_bottom); + } + int width() const { return m_right - m_left + 1; } + int height() const { return m_bottom - m_top + 1 ; } + int m_left; + int m_top; + int m_right; + int m_bottom; +}; //BITMAP typedef struct struct_bitmap_info { @@ -238,7 +225,7 @@ typedef enum Z_ORDER_LEVEL_2,//highest graphic level Z_ORDER_LEVEL_MAX }Z_ORDER_LEVEL; -struct EXTERNAL_GFX_OP +struct DISPLAY_DRIVER { void(*draw_pixel)(int x, int y, unsigned int rgb); void(*fill_rect)(int x0, int y0, int x1, int y1, unsigned int rgb); @@ -247,18 +234,19 @@ class c_surface; class c_display { friend class c_surface; public: - inline c_display(void* phy_fb, int display_width, int display_height, int surface_width, int surface_height, unsigned int color_bytes, int surface_cnt, EXTERNAL_GFX_OP* gfx_op = 0);//multiple surface or surface_no_fb - inline c_display(void* phy_fb, int display_width, int display_height, c_surface* surface);//single custom surface - inline c_surface* alloc_surface(Z_ORDER_LEVEL max_zorder, c_rect layer_rect = c_rect());//for multiple surfaces + inline c_display(void* phy_fb, int display_width, int display_height, c_surface* surface, DISPLAY_DRIVER* driver = 0);//single custom surface + inline c_display(void* phy_fb, int display_width, int display_height, int surface_width, int surface_height, unsigned int color_bytes, int surface_cnt, DISPLAY_DRIVER* driver = 0);//multiple surface + inline c_surface* alloc_surface(Z_ORDER_LEVEL max_zorder, c_rect layer_rect = c_rect());//for slide group inline int swipe_surface(c_surface* s0, c_surface* s1, int x0, int x1, int y0, int y1, int offset); int get_width() { return m_width; } int get_height() { return m_height; } + void* get_phy_fb() { return m_phy_fb; } void* get_updated_fb(int* width, int* height, bool force_update = false) { if (width && height) { - *width = get_width(); - *height = get_height(); + *width = m_width; + *height = m_height; } if (force_update) { @@ -277,35 +265,123 @@ public: { return -1; } - int width = get_width(); - int height = get_height(); //16 bits framebuffer if (m_color_bytes == 2) { - return build_bmp(file_name, width, height, (unsigned char*)m_phy_fb); + return build_bmp(file_name, m_width, m_height, (unsigned char*)m_phy_fb); } //32 bits framebuffer - unsigned short* p_bmp565_data = new unsigned short[width * height]; + unsigned short* p_bmp565_data = new unsigned short[m_width * m_height]; unsigned int* p_raw_data = (unsigned int*)m_phy_fb; - for (int i = 0; i < width * height; i++) + for (int i = 0; i < m_width * m_height; i++) { unsigned int rgb = *p_raw_data++; p_bmp565_data[i] = GL_RGB_32_to_16(rgb); } - int ret = build_bmp(file_name, width, height, (unsigned char*)p_bmp565_data); + int ret = build_bmp(file_name, m_width, m_height, (unsigned char*)p_bmp565_data); delete[]p_bmp565_data; return ret; } -private: - int m_width; //in pixels - int m_height; //in pixels - int m_color_bytes; //16 bits, 32 bits only - void* m_phy_fb; //physical framebuffer +protected: + virtual void draw_pixel(int x, int y, unsigned int rgb) + { + if ((x >= m_width) || (y >= m_height)) { return; } + if (m_driver && m_driver->draw_pixel) + { + return m_driver->draw_pixel(x, y, rgb); + } + if (m_color_bytes == 2) + { + ((unsigned short*)m_phy_fb)[y * m_width + x] = GL_RGB_32_to_16(rgb); + } + else + { + ((unsigned int*)m_phy_fb)[y * m_width + x] = rgb; + } + } + virtual void fill_rect(int x0, int y0, int x1, int y1, unsigned int rgb) + { + if (m_driver && m_driver->fill_rect) + { + return m_driver->fill_rect(x0, y0, x1, y1, rgb); + } + if (m_driver && m_driver->draw_pixel) + { + for (int y = y0; y <= y1; y++) + { + for (int x = x0; x <= x1; x++) + { + m_driver->draw_pixel(x, y, rgb); + } + } + return; + } + register int _width = m_width; + register int _height = m_height; + int x, y; + if (m_color_bytes == 2) + { + unsigned short* phy_fb; + unsigned int rgb_16 = GL_RGB_32_to_16(rgb); + for (y = y0; y <= y1; y++) + { + phy_fb = &((unsigned short*)m_phy_fb)[y * _width + x0]; + for (x = x0; x <= x1; x++) + { + if ((x < _width) && (y < _height)) + { + *phy_fb++ = rgb_16; + } + } + } + } + else + { + unsigned int* phy_fb; + for (y = y0; y <= y1; y++) + { + phy_fb = &((unsigned int*)m_phy_fb)[y * _width + x0]; + for (x = x0; x <= x1; x++) + { + if ((x < _width) && (y < _height)) + { + *phy_fb++ = rgb; + } + } + } + } + } + virtual int flush_screen(int left, int top, int right, int bottom, void* fb, int fb_width) + { + if ((0 == m_phy_fb) || (0 == fb)) + { + return -1; + } + register int _width = m_width; + register int _height = m_height; + left = (left >= _width) ? (_width - 1) : left; + right = (right >= _width) ? (_width - 1) : right; + top = (top >= _height) ? (_height - 1) : top; + bottom = (bottom >= _height) ? (_height - 1) : bottom; + for (int y = top; y < bottom; y++) + { + void* s_addr = (char*)fb + ((y * fb_width + left) * m_color_bytes); + void* d_addr = (char*)m_phy_fb + ((y * _width + left) * m_color_bytes); + memcpy(d_addr, s_addr, (right - left) * m_color_bytes); + } + return 0; + } + int m_width; //in pixels + int m_height; //in pixels + int m_color_bytes; //16/32 bits for default + void* m_phy_fb; //physical framebuffer for default + struct DISPLAY_DRIVER* m_driver; //Rendering by external method without default physical framebuffer int m_phy_read_index; int m_phy_write_index; c_surface* m_surface_group[SURFACE_CNT_MAX]; int m_surface_cnt; //surface count int m_surface_index; + }; class c_layer { @@ -317,12 +393,10 @@ public: class c_surface { friend class c_display; friend class c_bitmap_operator; public: - c_surface(unsigned int width, unsigned int height, unsigned int color_bytes, Z_ORDER_LEVEL max_zorder = Z_ORDER_LEVEL_0, c_rect overlpa_rect = c_rect()) : m_width(width), m_height(height), m_color_bytes(color_bytes), m_fb(0), m_is_active(false), m_top_zorder(Z_ORDER_LEVEL_0), m_phy_fb(0), m_phy_write_index(0), m_display(0) + c_surface(unsigned int width, unsigned int height, unsigned int color_bytes, Z_ORDER_LEVEL max_zorder = Z_ORDER_LEVEL_0, c_rect overlpa_rect = c_rect()) : m_width(width), m_height(height), m_color_bytes(color_bytes), m_fb(0), m_is_active(false), m_top_zorder(Z_ORDER_LEVEL_0), m_phy_write_index(0), m_display(0) { (overlpa_rect == c_rect()) ? set_surface(max_zorder, c_rect(0, 0, width - 1, height - 1)) : set_surface(max_zorder, overlpa_rect); } - int get_width() { return m_width; } - int get_height() { return m_height; } unsigned int get_pixel(int x, int y, unsigned int z_order) { if (x >= m_width || y >= m_height || x < 0 || y < 0 || z_order >= Z_ORDER_LEVEL_MAX) @@ -332,15 +406,15 @@ public: } if (m_layers[z_order].fb) { - return (m_color_bytes == 4) ? ((unsigned int*)(m_layers[z_order].fb))[y * m_width + x] : GL_RGB_16_to_32(((unsigned short*)(m_layers[z_order].fb))[y * m_width + x]); + return (m_color_bytes == 2) ? GL_RGB_16_to_32(((unsigned short*)(m_layers[z_order].fb))[y * m_width + x]) : ((unsigned int*)(m_layers[z_order].fb))[y * m_width + x]; } else if (m_fb) { - return (m_color_bytes == 4) ? ((unsigned int*)m_fb)[y * m_width + x] : GL_RGB_16_to_32(((unsigned short*)m_fb)[y * m_width + x]); + return (m_color_bytes == 2) ? GL_RGB_16_to_32(((unsigned short*)m_fb)[y * m_width + x]) : ((unsigned int*)m_fb)[y * m_width + x]; } - else if (m_phy_fb) + else if (m_display->m_phy_fb) { - return (m_color_bytes == 4) ? ((unsigned int*)m_phy_fb)[y * m_width + x] : GL_RGB_16_to_32(((unsigned short*)m_phy_fb)[y * m_width + x]); + return (m_color_bytes == 2) ? GL_RGB_16_to_32(((unsigned short*)m_display->m_phy_fb)[y * m_width + x]) : ((unsigned int*)m_display->m_phy_fb)[y * m_width + x]; } return 0; } @@ -357,7 +431,7 @@ public: } if (z_order == m_max_zorder) { - return draw_pixel_on_fb(x, y, rgb); + return draw_pixel_low_level(x, y, rgb); } if (z_order > (unsigned int)m_top_zorder) @@ -367,19 +441,19 @@ public: if (m_layers[z_order].rect.pt_in_rect(x, y)) { c_rect layer_rect = m_layers[z_order].rect; - if (m_color_bytes == 4) + if (m_color_bytes == 2) { - ((unsigned int*)(m_layers[z_order].fb))[(x - layer_rect.m_left) + (y - layer_rect.m_top) * layer_rect.width()] = rgb; + ((unsigned short*)(m_layers[z_order].fb))[(x - layer_rect.m_left) + (y - layer_rect.m_top) * layer_rect.width()] = GL_RGB_32_to_16(rgb); } else { - ((unsigned short*)(m_layers[z_order].fb))[(x - layer_rect.m_left) + (y - layer_rect.m_top) * layer_rect.width()] = GL_RGB_32_to_16(rgb); + ((unsigned int*)(m_layers[z_order].fb))[(x - layer_rect.m_left) + (y - layer_rect.m_top) * layer_rect.width()] = rgb; } } if (z_order == m_top_zorder) { - return draw_pixel_on_fb(x, y, rgb); + return draw_pixel_low_level(x, y, rgb); } bool be_overlapped = false; for (unsigned int tmp_z_order = Z_ORDER_LEVEL_MAX - 1; tmp_z_order > z_order; tmp_z_order--) @@ -392,7 +466,7 @@ public: } if (!be_overlapped) { - draw_pixel_on_fb(x, y, rgb); + draw_pixel_low_level(x, y, rgb); } } virtual void fill_rect(int x0, int y0, int x1, int y1, unsigned int rgb, unsigned int z_order) @@ -403,7 +477,7 @@ public: y1 = (y1 > (m_height - 1)) ? (m_height - 1) : y1; if (z_order == m_max_zorder) { - return fill_rect_on_fb(x0, y0, x1, y1, rgb); + return fill_rect_low_level(x0, y0, x1, y1, rgb); } if (z_order == m_top_zorder) { @@ -416,18 +490,18 @@ public: { if (layer_rect.pt_in_rect(x, y)) { - if (m_color_bytes == 4) + if (m_color_bytes == 2) { - ((unsigned int*)m_layers[z_order].fb)[(y - layer_rect.m_top) * layer_rect.width() + (x - layer_rect.m_left)] = rgb; + ((unsigned short*)m_layers[z_order].fb)[(y - layer_rect.m_top) * layer_rect.width() + (x - layer_rect.m_left)] = rgb_16; } else { - ((unsigned short*)m_layers[z_order].fb)[(y - layer_rect.m_top) * layer_rect.width() + (x - layer_rect.m_left)] = rgb_16; + ((unsigned int*)m_layers[z_order].fb)[(y - layer_rect.m_top) * layer_rect.width() + (x - layer_rect.m_left)] = rgb; } } } } - return fill_rect_on_fb(x0, y0, x1, y1, rgb); + return fill_rect_low_level(x0, y0, x1, y1, rgb); } for (; y0 <= y1; y0++) { @@ -499,27 +573,16 @@ public: } int flush_screen(int left, int top, int right, int bottom) { - if (left < 0 || left >= m_width || right < 0 || right >= m_width || - top < 0 || top >= m_height || bottom < 0 || bottom >= m_height) - { - ASSERT(false); - } - if (!m_is_active || (0 == m_phy_fb) || (0 == m_fb)) + if (!m_is_active) { return -1; } - int display_width = m_display->get_width(); - int display_height = m_display->get_height(); - left = (left >= display_width) ? (display_width - 1) : left; - right = (right >= display_width) ? (display_width - 1) : right; - top = (top >= display_height) ? (display_height - 1) : top; - bottom = (bottom >= display_height) ? (display_height - 1) : bottom; - for (int y = top; y < bottom; y++) + if (left < 0 || left >= m_width || right < 0 || right >= m_width || + top < 0 || top >= m_height || bottom < 0 || bottom >= m_height) { - void* s_addr = (char*)m_fb + ((y * m_width + left) * m_color_bytes); - void* d_addr = (char*)m_phy_fb + ((y * display_width + left) * m_color_bytes); - memcpy(d_addr, s_addr, (right - left) * m_color_bytes); + ASSERT(false); } + m_display->flush_screen(left, top, right, bottom, m_fb, m_width); *m_phy_write_index = *m_phy_write_index + 1; return 0; } @@ -537,90 +600,62 @@ public: { for (int x = rect.m_left; x <= rect.m_right; x++) { - unsigned int rgb = (m_color_bytes == 4) ? ((unsigned int*)fb)[(x - layer_rect.m_left) + (y - layer_rect.m_top) * width] : GL_RGB_16_to_32(((unsigned short*)fb)[(x - layer_rect.m_left) + (y - layer_rect.m_top) * width]); - draw_pixel_on_fb(x, y, rgb); + unsigned int rgb = (m_color_bytes == 2) ? GL_RGB_16_to_32(((unsigned short*)fb)[(x - layer_rect.m_left) + (y - layer_rect.m_top) * width]) : ((unsigned int*)fb)[(x - layer_rect.m_left) + (y - layer_rect.m_top) * width]; + draw_pixel_low_level(x, y, rgb); } } return 0; } void set_active(bool flag) { m_is_active = flag; } protected: - virtual void fill_rect_on_fb(int x0, int y0, int x1, int y1, unsigned int rgb) - { - int display_width = m_display->get_width(); - int display_height = m_display->get_height(); - if (m_color_bytes == 4) + virtual void fill_rect_low_level(int x0, int y0, int x1, int y1, unsigned int rgb) + {//fill rect on framebuffer of surface + int x, y; + if (m_color_bytes == 2) { - int x; - unsigned int* fb, * phy_fb; - for (; y0 <= y1; y0++) + unsigned short* fb; + unsigned int rgb_16 = GL_RGB_32_to_16(rgb); + for (y = y0; y <= y1; y++) { - x = x0; - fb = m_fb ? &((unsigned int*)m_fb)[y0 * m_width + x] : 0; - phy_fb = &((unsigned int*)m_phy_fb)[y0 * display_width + x]; - *m_phy_write_index = *m_phy_write_index + 1; - for (; x <= x1; x++) + fb = m_fb ? &((unsigned short*)m_fb)[y * m_width + x0] : 0; + if (!fb) { break; } + for (x = x0; x <= x1; x++) { - if (fb) - { - *fb++ = rgb; - } - if (m_is_active && (x < display_width) && (y0 < display_height)) - { - *phy_fb++ = rgb; - } + *fb++ = rgb_16; } } } - else if (m_color_bytes == 2) + else { - int x; - unsigned short* fb, * phy_fb; - rgb = GL_RGB_32_to_16(rgb); - for (; y0 <= y1; y0++) + unsigned int* fb; + for (y = y0; y <= y1; y++) { - x = x0; - fb = m_fb ? &((unsigned short*)m_fb)[y0 * m_width + x] : 0; - phy_fb = &((unsigned short*)m_phy_fb)[y0 * display_width + x]; - *m_phy_write_index = *m_phy_write_index + 1; - for (; x <= x1; x++) + fb = m_fb ? &((unsigned int*)m_fb)[y * m_width + x0] : 0; + if (!fb) { break; } + for (x = x0; x <= x1; x++) { - if (fb) - { - *fb++ = rgb; - } - if (m_is_active && (x < display_width) && (y0 < display_height)) - { - *phy_fb++ = rgb; - } + *fb++ = rgb; } } } + if (!m_is_active) { return; } + m_display->fill_rect(x0, y0, x1, y1, rgb); + *m_phy_write_index = *m_phy_write_index + 1; } - virtual void draw_pixel_on_fb(int x, int y, unsigned int rgb) + virtual void draw_pixel_low_level(int x, int y, unsigned int rgb) { if (m_fb) - { - (m_color_bytes == 4) ? ((unsigned int*)m_fb)[y * m_width + x] = rgb : ((unsigned short*)m_fb)[y * m_width + x] = GL_RGB_32_to_16(rgb); - } - if (m_is_active && (x < m_display->get_width()) && (y < m_display->get_height())) - { - if (m_color_bytes == 4) - { - ((unsigned int*)m_phy_fb)[y * (m_display->get_width()) + x] = rgb; - } - else - { - ((unsigned short*)m_phy_fb)[y * (m_display->get_width()) + x] = GL_RGB_32_to_16(rgb); - } - *m_phy_write_index = *m_phy_write_index + 1; + {//draw pixel on framebuffer of surface + (m_color_bytes == 2) ? ((unsigned short*)m_fb)[y * m_width + x] = GL_RGB_32_to_16(rgb): ((unsigned int*)m_fb)[y * m_width + x] = rgb; } + if (!m_is_active) { return; } + m_display->draw_pixel(x, y, rgb); + *m_phy_write_index = *m_phy_write_index + 1; } void attach_display(c_display* display) { ASSERT(display); m_display = display; - m_phy_fb = display->m_phy_fb; m_phy_write_index = &display->m_phy_write_index; } void set_surface(Z_ORDER_LEVEL max_z_order, c_rect layer_rect) @@ -638,87 +673,22 @@ protected: } int m_width; //in pixels int m_height; //in pixels - int m_color_bytes; //16 bits, 32 bits only + int m_color_bytes; //16 bits, 32 bits for default void* m_fb; //frame buffer you could see c_layer m_layers[Z_ORDER_LEVEL_MAX];//all graphic layers bool m_is_active; //active flag Z_ORDER_LEVEL m_max_zorder; //the highest graphic layer the surface will have Z_ORDER_LEVEL m_top_zorder; //the current highest graphic layer the surface have - void* m_phy_fb; //physical framebufer int* m_phy_write_index; c_display* m_display; }; -class c_surface_no_fb : public c_surface {//No physical framebuffer, render with external graphic interface - friend class c_display; -public: - c_surface_no_fb(unsigned int width, unsigned int height, unsigned int color_bytes, struct EXTERNAL_GFX_OP* gfx_op, Z_ORDER_LEVEL max_zorder = Z_ORDER_LEVEL_0, c_rect overlpa_rect = c_rect()) : c_surface(width, height, color_bytes, max_zorder, overlpa_rect), m_gfx_op(gfx_op) {} -protected: - virtual void fill_rect_on_fb(int x0, int y0, int x1, int y1, unsigned int rgb) - { - if (!m_gfx_op) - { - return; - } - if (m_gfx_op->fill_rect) - { - return m_gfx_op->fill_rect(x0, y0, x1, y1, rgb); - } - if (m_gfx_op->draw_pixel && m_is_active) - { - for (int y = y0; y <= y1; y++) - { - for (int x = x0; x <= x1; x++) - { - m_gfx_op->draw_pixel(x, y, rgb); - } - } - } - if (!m_fb) { return; } - if (m_color_bytes == 4) - { - unsigned int* fb; - for (int y = y0; y <= y1; y++) - { - fb = &((unsigned int*)m_fb)[y0 * m_width + x0]; - for (int x = x0; x <= x1; x++) - { - *fb++ = rgb; - } - } - } - else if (m_color_bytes == 2) - { - unsigned short* fb; - rgb = GL_RGB_32_to_16(rgb); - for (int y = y0; y <= y1; y++) - { - fb = &((unsigned short*)m_fb)[y0 * m_width + x0]; - for (int x = x0; x <= x1; x++) - { - *fb++ = rgb; - } - } - } - } - virtual void draw_pixel_on_fb(int x, int y, unsigned int rgb) - { - if (m_gfx_op && m_gfx_op->draw_pixel && m_is_active) - { - m_gfx_op->draw_pixel(x, y, rgb); - } - if (!m_fb) { return; } - if (m_color_bytes == 4) - { - ((unsigned int*)m_fb)[y * m_width + x] = rgb; - } - else if (m_color_bytes == 2) - { - ((unsigned short*)m_fb)[y * m_width + x] = GL_RGB_32_to_16(rgb); - } - } - struct EXTERNAL_GFX_OP* m_gfx_op;//Rendering by external method -}; -inline c_display::c_display(void* phy_fb, int display_width, int display_height, int surface_width, int surface_height, unsigned int color_bytes, int surface_cnt, EXTERNAL_GFX_OP* gfx_op) : m_width(display_width), m_height(display_height), m_color_bytes(color_bytes), m_phy_fb(phy_fb), m_phy_read_index(0), m_phy_write_index(0), m_surface_cnt(surface_cnt), m_surface_index(0) +inline c_display::c_display(void* phy_fb, int display_width, int display_height, c_surface* surface, DISPLAY_DRIVER* driver) : m_phy_fb(phy_fb), m_width(display_width), m_height(display_height), m_driver(driver), m_phy_read_index(0), m_phy_write_index(0), m_surface_cnt(1), m_surface_index(0) +{ + m_color_bytes = surface->m_color_bytes; + surface->m_is_active = true; + (m_surface_group[0] = surface)->attach_display(this); +} +inline c_display::c_display(void* phy_fb, int display_width, int display_height, int surface_width, int surface_height, unsigned int color_bytes, int surface_cnt, DISPLAY_DRIVER* driver) : m_phy_fb(phy_fb), m_width(display_width), m_height(display_height), m_color_bytes(color_bytes), m_phy_read_index(0), m_phy_write_index(0), m_surface_cnt(surface_cnt), m_driver(driver), m_surface_index(0) { ASSERT(color_bytes == 2 || color_bytes == 4); ASSERT(m_surface_cnt <= SURFACE_CNT_MAX); @@ -726,16 +696,10 @@ inline c_display::c_display(void* phy_fb, int display_width, int display_height, for (int i = 0; i < m_surface_cnt; i++) { - m_surface_group[i] = (phy_fb) ? new c_surface(surface_width, surface_height, color_bytes) : new c_surface_no_fb(surface_width, surface_height, color_bytes, gfx_op); + m_surface_group[i] = new c_surface(surface_width, surface_height, color_bytes); m_surface_group[i]->attach_display(this); } } -inline c_display::c_display(void* phy_fb, int display_width, int display_height, c_surface* surface) : m_width(display_width), m_height(display_height), m_phy_fb(phy_fb), m_phy_read_index(0), m_phy_write_index(0), m_surface_cnt(1), m_surface_index(0) -{ - m_color_bytes = surface->m_color_bytes; - surface->m_is_active = true; - (m_surface_group[0] = surface)->attach_display(this); -} inline c_surface* c_display::alloc_surface(Z_ORDER_LEVEL max_zorder, c_rect layer_rect) { ASSERT(max_zorder < Z_ORDER_LEVEL_MAX && m_surface_index < m_surface_cnt); @@ -744,8 +708,8 @@ inline c_surface* c_display::alloc_surface(Z_ORDER_LEVEL max_zorder, c_rect laye } inline int c_display::swipe_surface(c_surface* s0, c_surface* s1, int x0, int x1, int y0, int y1, int offset) { - int surface_width = s0->get_width(); - int surface_height = s0->get_height(); + register int surface_width = s0->m_width; + register int surface_height = s0->m_height; if (offset < 0 || offset > surface_width || y0 < 0 || y0 >= surface_height || y1 < 0 || y1 >= surface_height || x0 < 0 || x0 >= surface_width || x1 < 0 || x1 >= surface_width) { @@ -767,46 +731,46 @@ inline int c_display::swipe_surface(c_surface* s0, c_surface* s1, int x0, int x1 for (int y = y0; y <= y1; y++) { //Left surface - char* addr_s = ((char*)(s0->m_fb) + (y * (s0->get_width()) + x0 + offset) * m_color_bytes); + char* addr_s = ((char*)(s0->m_fb) + (y * surface_width + x0 + offset) * m_color_bytes); char* addr_d = ((char*)(m_phy_fb)+(y * m_width + x0) * m_color_bytes); memcpy(addr_d, addr_s, (width - offset) * m_color_bytes); //Right surface - addr_s = ((char*)(s1->m_fb) + (y * (s1->get_width()) + x0) * m_color_bytes); + addr_s = ((char*)(s1->m_fb) + (y * surface_width + x0) * m_color_bytes); addr_d = ((char*)(m_phy_fb)+(y * m_width + x0 + (width - offset)) * m_color_bytes); memcpy(addr_d, addr_s, offset * m_color_bytes); } } - else if (m_color_bytes == 4) + else if (m_color_bytes == 2) { - void(*draw_pixel)(int x, int y, unsigned int rgb) = ((c_surface_no_fb*)s0)->m_gfx_op->draw_pixel; + void(*draw_pixel)(int x, int y, unsigned int rgb) = m_driver->draw_pixel; for (int y = y0; y <= y1; y++) { //Left surface for (int x = x0; x <= (x1 - offset); x++) { - draw_pixel(x, y, ((unsigned int*)s0->m_fb)[y * m_width + x + offset]); + draw_pixel(x, y, GL_RGB_16_to_32(((unsigned short*)s0->m_fb)[y * m_width + x + offset])); } //Right surface for (int x = x1 - offset; x <= x1; x++) { - draw_pixel(x, y, ((unsigned int*)s1->m_fb)[y * m_width + x + offset - x1 + x0]); + draw_pixel(x, y, GL_RGB_16_to_32(((unsigned short*)s1->m_fb)[y * m_width + x + offset - x1 + x0])); } } } - else if (m_color_bytes == 2) + else //m_color_bytes == 3/4... { - void(*draw_pixel)(int x, int y, unsigned int rgb) = ((c_surface_no_fb*)s0)->m_gfx_op->draw_pixel; + void(*draw_pixel)(int x, int y, unsigned int rgb) = m_driver->draw_pixel; for (int y = y0; y <= y1; y++) { //Left surface for (int x = x0; x <= (x1 - offset); x++) { - draw_pixel(x, y, GL_RGB_16_to_32(((unsigned short*)s0->m_fb)[y * m_width + x + offset])); + draw_pixel(x, y, ((unsigned int*)s0->m_fb)[y * m_width + x + offset]); } //Right surface for (int x = x1 - offset; x <= x1; x++) { - draw_pixel(x, y, GL_RGB_16_to_32(((unsigned short*)s1->m_fb)[y * m_width + x + offset - x1 + x0])); + draw_pixel(x, y, ((unsigned int*)s1->m_fb)[y * m_width + x + offset - x1 + x0]); } } } @@ -3407,22 +3371,12 @@ private: #ifdef GUILITE_ON c_bitmap_operator the_bitmap_op = c_bitmap_operator(); c_image_operator* c_image::image_operator = &the_bitmap_op; +const void* c_theme::s_font_map[FONT_MAX]; +const void* c_theme::s_image_map[IMAGE_MAX]; +unsigned int c_theme::s_color_map[COLOR_MAX]; +c_lattice_font_op the_lattice_font_op = c_lattice_font_op(); +c_font_operator* c_word::fontOperator = &the_lattice_font_op; #endif - -#ifdef GUILITE_ON - -const void* c_theme::s_font_map[FONT_MAX]; -const void* c_theme::s_image_map[IMAGE_MAX]; -unsigned int c_theme::s_color_map[COLOR_MAX]; - -#endif - -#ifdef GUILITE_ON - -c_lattice_font_op the_lattice_font_op = c_lattice_font_op(); -c_font_operator* c_word::fontOperator = &the_lattice_font_op; - -#endif #ifdef GUILITE_ON #if (defined __linux__) || (defined __APPLE__) #include @@ -4264,11 +4218,7 @@ int c_fifo::write(void* buf, int len) #endif #ifdef GUILITE_ON DIALOG_ARRAY c_dialog::ms_the_dialogs[SURFACE_CNT_MAX]; -#endif -#ifdef GUILITE_ON c_keyboard c_edit::s_keyboard; -#endif -#ifdef GUILITE_ON static c_keyboard_button s_key_0, s_key_1, s_key_2, s_key_3, s_key_4, s_key_5, s_key_6, s_key_7, s_key_8, s_key_9; static c_keyboard_button s_key_A, s_key_B, s_key_C, s_key_D, s_key_E, s_key_F, s_key_G, s_key_H, s_key_I, s_key_J; static c_keyboard_button s_key_K, s_key_L, s_key_M, s_key_N, s_key_O, s_key_P, s_key_Q, s_key_R, s_key_S, s_key_T; @@ -4306,12 +4256,12 @@ WND_TREE g_key_board_children[] = {&s_key_B, 'B', 0, ((KEY_WIDTH / 2) + POS_X(5)), POS_Y(2), KEY_WIDTH, KEY_HEIGHT}, {&s_key_N, 'N', 0, ((KEY_WIDTH / 2) + POS_X(6)), POS_Y(2), KEY_WIDTH, KEY_HEIGHT}, {&s_key_M, 'M', 0, ((KEY_WIDTH / 2) + POS_X(7)), POS_Y(2), KEY_WIDTH, KEY_HEIGHT}, - {&s_key_del, 0x7F, 0, ((KEY_WIDTH / 2) + POS_X(8)), POS_Y(2), DEL_WIDTH, KEY_HEIGHT}, + {&s_key_del,0x7F, 0, ((KEY_WIDTH / 2) + POS_X(8)), POS_Y(2), DEL_WIDTH, KEY_HEIGHT}, //Row 4 - {&s_key_esc, 0x1B, 0, POS_X(0), POS_Y(3), ESC_WIDTH, KEY_HEIGHT}, + {&s_key_esc, 0x1B, 0, POS_X(0), POS_Y(3), ESC_WIDTH, KEY_HEIGHT}, {&s_key_num_switch, 0x90, 0, POS_X(2), POS_Y(3), SWITCH_WIDTH, KEY_HEIGHT}, {&s_key_space, ' ', 0, ((KEY_WIDTH / 2) + POS_X(3)), POS_Y(3), SPACE_WIDTH, KEY_HEIGHT}, - {&s_key_dot, '.', 0, ((KEY_WIDTH / 2) + POS_X(6)), POS_Y(3), DOT_WIDTH, KEY_HEIGHT}, + {&s_key_dot, '.', 0, ((KEY_WIDTH / 2) + POS_X(6)), POS_Y(3), DOT_WIDTH, KEY_HEIGHT}, {&s_key_enter, '\n', 0, POS_X(8), POS_Y(3), ENTER_WIDTH, KEY_HEIGHT}, {0,0,0,0,0,0,0} }; @@ -4326,12 +4276,11 @@ WND_TREE g_number_board_children[] = {&s_key_7, '7', 0, POS_X(0), POS_Y(2), KEY_WIDTH, KEY_HEIGHT}, {&s_key_8, '8', 0, POS_X(1), POS_Y(2), KEY_WIDTH, KEY_HEIGHT}, {&s_key_9, '9', 0, POS_X(2), POS_Y(2), KEY_WIDTH, KEY_HEIGHT}, - - {&s_key_esc, 0x1B, 0, POS_X(0), POS_Y(3), KEY_WIDTH, KEY_HEIGHT}, + {&s_key_esc,0x1B, 0, POS_X(0), POS_Y(3), KEY_WIDTH, KEY_HEIGHT}, {&s_key_0, '0', 0, POS_X(1), POS_Y(3), KEY_WIDTH, KEY_HEIGHT}, - {&s_key_dot, '.', 0, POS_X(2), POS_Y(3), KEY_WIDTH, KEY_HEIGHT}, + {&s_key_dot,'.', 0, POS_X(2), POS_Y(3), KEY_WIDTH, KEY_HEIGHT}, {&s_key_del, 0x7F, 0, POS_X(3), POS_Y(0), KEY_WIDTH, KEY_HEIGHT * 2 + 2}, {&s_key_enter,'\n', 0, POS_X(3), POS_Y(2), KEY_WIDTH, KEY_HEIGHT * 2 + 2}, {0,0,0,0,0,0,0} }; -#endif +#endif \ No newline at end of file diff --git a/HelloJPG/UIcode/UIcode.cpp b/HelloJPG/UIcode/UIcode.cpp index f36ad961dee9fca24fecdc0a589d262209ff277c..405afa3c80eede913d1593a3f5789f44eafca8ea 100644 --- a/HelloJPG/UIcode/UIcode.cpp +++ b/HelloJPG/UIcode/UIcode.cpp @@ -43,7 +43,8 @@ void create_ui(void* phy_fb, int screen_width, int screen_height, int color_byte load_resource(); s_surface = new c_surface(UI_WIDTH, UI_HEIGHT, color_bytes, Z_ORDER_LEVEL_0); s_display = new c_display(phy_fb, screen_width, screen_height, s_surface); - + + c_image::draw_image(s_surface, Z_ORDER_LEVEL_0, "../2.jpg", 200, 150); while(1) { thread_sleep(1000000); diff --git a/HelloLayers/BuildLinux/.sync_build.sh b/HelloLayers/BuildLinux/.sync_build.sh index 49cff5b473ac606967676ebefa6f0d333e301227..b7410ec23ee06fb7dad502ee25900398d2d9df04 100644 --- a/HelloLayers/BuildLinux/.sync_build.sh +++ b/HelloLayers/BuildLinux/.sync_build.sh @@ -1,5 +1,6 @@ if [ "$#" -ne 1 ]; then - echo "Invalid arguments" + echo "Do testing" + ./xWindow 240 320 | ./HelloLayers shared-fb exit -1 fi diff --git a/HelloLayers/BuildLinux/main.cpp b/HelloLayers/BuildLinux/main.cpp index 43b86e14ac051c46aa340ba31e059ec166513013..0f4fa9538b32dd96c2a4fcf8af585b054264efa9 100644 --- a/HelloLayers/BuildLinux/main.cpp +++ b/HelloLayers/BuildLinux/main.cpp @@ -10,7 +10,7 @@ #include #include -extern "C" void startHelloLayers(void* phy_fb, int width, int height, int color_bytes, struct EXTERNAL_GFX_OP* gfx_op); +extern "C" void startHelloLayers(void* phy_fb, int width, int height, int color_bytes, struct DISPLAY_DRIVER* driver); extern void init_std_io(); static void* get_embeded_fb_in_display_app(int shared_id); diff --git a/HelloLayers/BuildMFC/HelloLayersDlg.cpp b/HelloLayers/BuildMFC/HelloLayersDlg.cpp index acc00b641dfcfcab1f67f6b4b68b694bedd6c0c5..233789c9047670f1dc17086eac6cf24f23302082 100644 Binary files a/HelloLayers/BuildMFC/HelloLayersDlg.cpp and b/HelloLayers/BuildMFC/HelloLayersDlg.cpp differ diff --git a/HelloLayers/BuildMFC/HelloLayersDlg.h b/HelloLayers/BuildMFC/HelloLayersDlg.h index 9e0f1b0668f558ecff0347b3cf58ac111f422bef..763c7a2a65d6a9ae53974ad41b26c179c7b2380c 100644 Binary files a/HelloLayers/BuildMFC/HelloLayersDlg.h and b/HelloLayers/BuildMFC/HelloLayersDlg.h differ diff --git a/HelloLayers/BuildSTM32F103-Keil/USER/main.c b/HelloLayers/BuildSTM32F103-Keil/USER/main.c index 3177750a626547af504f41f25c699998464f6168..6aa4d7e96b50c1bb1a82c83bb82156e24552074b 100644 --- a/HelloLayers/BuildSTM32F103-Keil/USER/main.c +++ b/HelloLayers/BuildSTM32F103-Keil/USER/main.c @@ -15,12 +15,12 @@ void gfx_draw_pixel(int x, int y, unsigned int rgb) //void gfx_fill_rect(int x0, int y0, int x1, int y1, unsigned int rgb){} //UI entry -struct EXTERNAL_GFX_OP +struct DISPLAY_DRIVER { void (*draw_pixel)(int x, int y, unsigned int rgb); void (*fill_rect)(int x0, int y0, int x1, int y1, unsigned int rgb); -} my_gfx_op; -extern void startHelloLayers(void* phy_fb, int width, int height, int color_bytes, struct EXTERNAL_GFX_OP* gfx_op); +} my_driver; +extern void startHelloLayers(void* phy_fb, int width, int height, int color_bytes, struct DISPLAY_DRIVER* driver); int main(void) { @@ -30,8 +30,8 @@ int main(void) LCD_Init(); //Link your LCD driver & start UI: - my_gfx_op.draw_pixel = gfx_draw_pixel; - my_gfx_op.fill_rect = NULL;//gfx_fill_rect; - startHelloLayers(NULL, 240, 320, 2, &my_gfx_op); + my_driver.draw_pixel = gfx_draw_pixel; + my_driver.fill_rect = NULL;//gfx_fill_rect; + startHelloLayers(NULL, 240, 320, 2, &my_driver); while(1); } diff --git a/HelloLayers/BuildWin32/HelloLayers.cpp b/HelloLayers/BuildWin32/HelloLayers.cpp index 7f98a11ec24dbcb506280209db0d6c6f652291fa..f220b3cf382ae934eead9a233147c5a09463c314 100644 --- a/HelloLayers/BuildWin32/HelloLayers.cpp +++ b/HelloLayers/BuildWin32/HelloLayers.cpp @@ -161,7 +161,7 @@ LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam) } //////////////////////// HelloLayers Interface //////////////////////// -extern "C" void startHelloLayers(void* phy_fb, int width, int height, int color_bytes, struct EXTERNAL_GFX_OP* gfx_op); +extern "C" void startHelloLayers(void* phy_fb, int width, int height, int color_bytes, struct DISPLAY_DRIVER* driver); DWORD WINAPI ThreadHelloLayers(LPVOID pParam) { diff --git a/HelloLayers/UIcode/GuiLite.h b/HelloLayers/UIcode/GuiLite.h index c4fc88a51476d2c8309c3e55e1270e13784fc510..80550e1632ad7bc82541a2edbb0f7f8f5937954f 100644 --- a/HelloLayers/UIcode/GuiLite.h +++ b/HelloLayers/UIcode/GuiLite.h @@ -1,107 +1,94 @@ #pragma once - -#define REAL_TIME_TASK_CYCLE_MS 50 -#define MAX(a,b) (((a)>(b))?(a):(b)) -#define MIN(a,b) (((a)<(b))?(a):(b)) - -#define GL_ARGB(a, r, g, b) ((((unsigned int)(a)) << 24) | (((unsigned int)(r)) << 16) | (((unsigned int)(g)) << 8) | ((unsigned int)(b))) -#define GL_ARGB_A(rgb) ((((unsigned int)(rgb)) >> 24) & 0xFF) - -#define GL_RGB(r, g, b) ((0xFF << 24) | (((unsigned int)(r)) << 16) | (((unsigned int)(g)) << 8) | ((unsigned int)(b))) -#define GL_RGB_R(rgb) ((((unsigned int)(rgb)) >> 16) & 0xFF) -#define GL_RGB_G(rgb) ((((unsigned int)(rgb)) >> 8) & 0xFF) -#define GL_RGB_B(rgb) (((unsigned int)(rgb)) & 0xFF) -#define GL_RGB_32_to_16(rgb) (((((unsigned int)(rgb)) & 0xFF) >> 3) | ((((unsigned int)(rgb)) & 0xFC00) >> 5) | ((((unsigned int)(rgb)) & 0xF80000) >> 8)) -#define GL_RGB_16_to_32(rgb) ((0xFF << 24) | ((((unsigned int)(rgb)) & 0x1F) << 3) | ((((unsigned int)(rgb)) & 0x7E0) << 5) | ((((unsigned int)(rgb)) & 0xF800) << 8)) - -#define ALIGN_HCENTER 0x00000000L -#define ALIGN_LEFT 0x01000000L -#define ALIGN_RIGHT 0x02000000L -#define ALIGN_HMASK 0x03000000L - -#define ALIGN_VCENTER 0x00000000L -#define ALIGN_TOP 0x00100000L -#define ALIGN_BOTTOM 0x00200000L -#define ALIGN_VMASK 0x00300000L - -typedef struct -{ - unsigned short year; - unsigned short month; - unsigned short date; - unsigned short day; - unsigned short hour; - unsigned short minute; - unsigned short second; -}T_TIME; - -void register_debug_function(void(*my_assert)(const char* file, int line), void(*my_log_out)(const char* log)); -void _assert(const char* file, int line); -#define ASSERT(condition) \ - do{ \ - if(!(condition))_assert(__FILE__, __LINE__);\ - }while(0) -void log_out(const char* log); - -long get_time_in_second(); -T_TIME second_to_day(long second); -T_TIME get_time(); - -void start_real_timer(void (*func)(void* arg)); -void register_timer(int milli_second, void func(void* param), void* param); - -unsigned int get_cur_thread_id(); -void create_thread(unsigned long* thread_id, void* attr, void *(*start_routine) (void *), void* arg); -void thread_sleep(unsigned int milli_seconds); -int build_bmp(const char *filename, unsigned int width, unsigned int height, unsigned char *data); - -#define FIFO_BUFFER_LEN 1024 -class c_fifo -{ -public: - c_fifo(); - int read(void* buf, int len); - int write(void* buf, int len); -private: - unsigned char m_buf[FIFO_BUFFER_LEN]; - int m_head; - int m_tail; - void* m_read_sem; - void* m_write_mutex; -}; - -class c_rect -{ -public: - c_rect(){ m_left = m_top = m_right = m_bottom = -1; } - c_rect(int left, int top, int width, int height) - { - set_rect(left, top, width, height); - } - void set_rect(int left, int top, int width, int height) - { - ASSERT(width > 0 && height > 0); - m_left = left; - m_top = top; - m_right = left + width - 1; - m_bottom = top + height -1; - } - bool pt_in_rect(int x, int y) const - { - return x >= m_left && x <= m_right && y >= m_top && y <= m_bottom; - } - int operator==(const c_rect& rect) const - { - return (m_left == rect.m_left) && (m_top == rect.m_top) && (m_right == rect.m_right) && (m_bottom == rect.m_bottom); - } - int width() const { return m_right - m_left + 1; } - int height() const { return m_bottom - m_top + 1 ; } - - int m_left; - int m_top; - int m_right; - int m_bottom; -}; +#define REAL_TIME_TASK_CYCLE_MS 50 +#define MAX(a,b) (((a)>(b))?(a):(b)) +#define MIN(a,b) (((a)<(b))?(a):(b)) +#define GL_ARGB(a, r, g, b) ((((unsigned int)(a)) << 24) | (((unsigned int)(r)) << 16) | (((unsigned int)(g)) << 8) | ((unsigned int)(b))) +#define GL_ARGB_A(rgb) ((((unsigned int)(rgb)) >> 24) & 0xFF) +#define GL_RGB(r, g, b) ((0xFF << 24) | (((unsigned int)(r)) << 16) | (((unsigned int)(g)) << 8) | ((unsigned int)(b))) +#define GL_RGB_R(rgb) ((((unsigned int)(rgb)) >> 16) & 0xFF) +#define GL_RGB_G(rgb) ((((unsigned int)(rgb)) >> 8) & 0xFF) +#define GL_RGB_B(rgb) (((unsigned int)(rgb)) & 0xFF) +#define GL_RGB_32_to_16(rgb) (((((unsigned int)(rgb)) & 0xFF) >> 3) | ((((unsigned int)(rgb)) & 0xFC00) >> 5) | ((((unsigned int)(rgb)) & 0xF80000) >> 8)) +#define GL_RGB_16_to_32(rgb) ((0xFF << 24) | ((((unsigned int)(rgb)) & 0x1F) << 3) | ((((unsigned int)(rgb)) & 0x7E0) << 5) | ((((unsigned int)(rgb)) & 0xF800) << 8)) +#define ALIGN_HCENTER 0x00000000L +#define ALIGN_LEFT 0x01000000L +#define ALIGN_RIGHT 0x02000000L +#define ALIGN_HMASK 0x03000000L +#define ALIGN_VCENTER 0x00000000L +#define ALIGN_TOP 0x00100000L +#define ALIGN_BOTTOM 0x00200000L +#define ALIGN_VMASK 0x00300000L +typedef struct +{ + unsigned short year; + unsigned short month; + unsigned short date; + unsigned short day; + unsigned short hour; + unsigned short minute; + unsigned short second; +}T_TIME; +void register_debug_function(void(*my_assert)(const char* file, int line), void(*my_log_out)(const char* log)); +void _assert(const char* file, int line); +#define ASSERT(condition) \ + do{ \ + if(!(condition))_assert(__FILE__, __LINE__);\ + }while(0) +void log_out(const char* log); +long get_time_in_second(); +T_TIME second_to_day(long second); +T_TIME get_time(); +void start_real_timer(void (*func)(void* arg)); +void register_timer(int milli_second, void func(void* param), void* param); +unsigned int get_cur_thread_id(); +void create_thread(unsigned long* thread_id, void* attr, void *(*start_routine) (void *), void* arg); +void thread_sleep(unsigned int milli_seconds); +int build_bmp(const char *filename, unsigned int width, unsigned int height, unsigned char *data); +#define FIFO_BUFFER_LEN 1024 +class c_fifo +{ +public: + c_fifo(); + int read(void* buf, int len); + int write(void* buf, int len); +private: + unsigned char m_buf[FIFO_BUFFER_LEN]; + int m_head; + int m_tail; + void* m_read_sem; + void* m_write_mutex; +}; +class c_rect +{ +public: + c_rect(){ m_left = m_top = m_right = m_bottom = -1; } + c_rect(int left, int top, int width, int height) + { + set_rect(left, top, width, height); + } + void set_rect(int left, int top, int width, int height) + { + ASSERT(width > 0 && height > 0); + m_left = left; + m_top = top; + m_right = left + width - 1; + m_bottom = top + height -1; + } + bool pt_in_rect(int x, int y) const + { + return x >= m_left && x <= m_right && y >= m_top && y <= m_bottom; + } + int operator==(const c_rect& rect) const + { + return (m_left == rect.m_left) && (m_top == rect.m_top) && (m_right == rect.m_right) && (m_bottom == rect.m_bottom); + } + int width() const { return m_right - m_left + 1; } + int height() const { return m_bottom - m_top + 1 ; } + int m_left; + int m_top; + int m_right; + int m_bottom; +}; //BITMAP typedef struct struct_bitmap_info { @@ -238,7 +225,7 @@ typedef enum Z_ORDER_LEVEL_2,//highest graphic level Z_ORDER_LEVEL_MAX }Z_ORDER_LEVEL; -struct EXTERNAL_GFX_OP +struct DISPLAY_DRIVER { void(*draw_pixel)(int x, int y, unsigned int rgb); void(*fill_rect)(int x0, int y0, int x1, int y1, unsigned int rgb); @@ -247,18 +234,19 @@ class c_surface; class c_display { friend class c_surface; public: - inline c_display(void* phy_fb, int display_width, int display_height, int surface_width, int surface_height, unsigned int color_bytes, int surface_cnt, EXTERNAL_GFX_OP* gfx_op = 0);//multiple surface or surface_no_fb - inline c_display(void* phy_fb, int display_width, int display_height, c_surface* surface);//single custom surface - inline c_surface* alloc_surface(Z_ORDER_LEVEL max_zorder, c_rect layer_rect = c_rect());//for multiple surfaces + inline c_display(void* phy_fb, int display_width, int display_height, c_surface* surface, DISPLAY_DRIVER* driver = 0);//single custom surface + inline c_display(void* phy_fb, int display_width, int display_height, int surface_width, int surface_height, unsigned int color_bytes, int surface_cnt, DISPLAY_DRIVER* driver = 0);//multiple surface + inline c_surface* alloc_surface(Z_ORDER_LEVEL max_zorder, c_rect layer_rect = c_rect());//for slide group inline int swipe_surface(c_surface* s0, c_surface* s1, int x0, int x1, int y0, int y1, int offset); int get_width() { return m_width; } int get_height() { return m_height; } + void* get_phy_fb() { return m_phy_fb; } void* get_updated_fb(int* width, int* height, bool force_update = false) { if (width && height) { - *width = get_width(); - *height = get_height(); + *width = m_width; + *height = m_height; } if (force_update) { @@ -277,35 +265,123 @@ public: { return -1; } - int width = get_width(); - int height = get_height(); //16 bits framebuffer if (m_color_bytes == 2) { - return build_bmp(file_name, width, height, (unsigned char*)m_phy_fb); + return build_bmp(file_name, m_width, m_height, (unsigned char*)m_phy_fb); } //32 bits framebuffer - unsigned short* p_bmp565_data = new unsigned short[width * height]; + unsigned short* p_bmp565_data = new unsigned short[m_width * m_height]; unsigned int* p_raw_data = (unsigned int*)m_phy_fb; - for (int i = 0; i < width * height; i++) + for (int i = 0; i < m_width * m_height; i++) { unsigned int rgb = *p_raw_data++; p_bmp565_data[i] = GL_RGB_32_to_16(rgb); } - int ret = build_bmp(file_name, width, height, (unsigned char*)p_bmp565_data); + int ret = build_bmp(file_name, m_width, m_height, (unsigned char*)p_bmp565_data); delete[]p_bmp565_data; return ret; } -private: - int m_width; //in pixels - int m_height; //in pixels - int m_color_bytes; //16 bits, 32 bits only - void* m_phy_fb; //physical framebuffer +protected: + virtual void draw_pixel(int x, int y, unsigned int rgb) + { + if ((x >= m_width) || (y >= m_height)) { return; } + if (m_driver && m_driver->draw_pixel) + { + return m_driver->draw_pixel(x, y, rgb); + } + if (m_color_bytes == 2) + { + ((unsigned short*)m_phy_fb)[y * m_width + x] = GL_RGB_32_to_16(rgb); + } + else + { + ((unsigned int*)m_phy_fb)[y * m_width + x] = rgb; + } + } + virtual void fill_rect(int x0, int y0, int x1, int y1, unsigned int rgb) + { + if (m_driver && m_driver->fill_rect) + { + return m_driver->fill_rect(x0, y0, x1, y1, rgb); + } + if (m_driver && m_driver->draw_pixel) + { + for (int y = y0; y <= y1; y++) + { + for (int x = x0; x <= x1; x++) + { + m_driver->draw_pixel(x, y, rgb); + } + } + return; + } + register int _width = m_width; + register int _height = m_height; + int x, y; + if (m_color_bytes == 2) + { + unsigned short* phy_fb; + unsigned int rgb_16 = GL_RGB_32_to_16(rgb); + for (y = y0; y <= y1; y++) + { + phy_fb = &((unsigned short*)m_phy_fb)[y * _width + x0]; + for (x = x0; x <= x1; x++) + { + if ((x < _width) && (y < _height)) + { + *phy_fb++ = rgb_16; + } + } + } + } + else + { + unsigned int* phy_fb; + for (y = y0; y <= y1; y++) + { + phy_fb = &((unsigned int*)m_phy_fb)[y * _width + x0]; + for (x = x0; x <= x1; x++) + { + if ((x < _width) && (y < _height)) + { + *phy_fb++ = rgb; + } + } + } + } + } + virtual int flush_screen(int left, int top, int right, int bottom, void* fb, int fb_width) + { + if ((0 == m_phy_fb) || (0 == fb)) + { + return -1; + } + register int _width = m_width; + register int _height = m_height; + left = (left >= _width) ? (_width - 1) : left; + right = (right >= _width) ? (_width - 1) : right; + top = (top >= _height) ? (_height - 1) : top; + bottom = (bottom >= _height) ? (_height - 1) : bottom; + for (int y = top; y < bottom; y++) + { + void* s_addr = (char*)fb + ((y * fb_width + left) * m_color_bytes); + void* d_addr = (char*)m_phy_fb + ((y * _width + left) * m_color_bytes); + memcpy(d_addr, s_addr, (right - left) * m_color_bytes); + } + return 0; + } + int m_width; //in pixels + int m_height; //in pixels + int m_color_bytes; //16/32 bits for default + void* m_phy_fb; //physical framebuffer for default + struct DISPLAY_DRIVER* m_driver; //Rendering by external method without default physical framebuffer int m_phy_read_index; int m_phy_write_index; c_surface* m_surface_group[SURFACE_CNT_MAX]; int m_surface_cnt; //surface count int m_surface_index; + }; class c_layer { @@ -317,12 +393,10 @@ public: class c_surface { friend class c_display; friend class c_bitmap_operator; public: - c_surface(unsigned int width, unsigned int height, unsigned int color_bytes, Z_ORDER_LEVEL max_zorder = Z_ORDER_LEVEL_0, c_rect overlpa_rect = c_rect()) : m_width(width), m_height(height), m_color_bytes(color_bytes), m_fb(0), m_is_active(false), m_top_zorder(Z_ORDER_LEVEL_0), m_phy_fb(0), m_phy_write_index(0), m_display(0) + c_surface(unsigned int width, unsigned int height, unsigned int color_bytes, Z_ORDER_LEVEL max_zorder = Z_ORDER_LEVEL_0, c_rect overlpa_rect = c_rect()) : m_width(width), m_height(height), m_color_bytes(color_bytes), m_fb(0), m_is_active(false), m_top_zorder(Z_ORDER_LEVEL_0), m_phy_write_index(0), m_display(0) { (overlpa_rect == c_rect()) ? set_surface(max_zorder, c_rect(0, 0, width - 1, height - 1)) : set_surface(max_zorder, overlpa_rect); } - int get_width() { return m_width; } - int get_height() { return m_height; } unsigned int get_pixel(int x, int y, unsigned int z_order) { if (x >= m_width || y >= m_height || x < 0 || y < 0 || z_order >= Z_ORDER_LEVEL_MAX) @@ -332,15 +406,15 @@ public: } if (m_layers[z_order].fb) { - return (m_color_bytes == 4) ? ((unsigned int*)(m_layers[z_order].fb))[y * m_width + x] : GL_RGB_16_to_32(((unsigned short*)(m_layers[z_order].fb))[y * m_width + x]); + return (m_color_bytes == 2) ? GL_RGB_16_to_32(((unsigned short*)(m_layers[z_order].fb))[y * m_width + x]) : ((unsigned int*)(m_layers[z_order].fb))[y * m_width + x]; } else if (m_fb) { - return (m_color_bytes == 4) ? ((unsigned int*)m_fb)[y * m_width + x] : GL_RGB_16_to_32(((unsigned short*)m_fb)[y * m_width + x]); + return (m_color_bytes == 2) ? GL_RGB_16_to_32(((unsigned short*)m_fb)[y * m_width + x]) : ((unsigned int*)m_fb)[y * m_width + x]; } - else if (m_phy_fb) + else if (m_display->m_phy_fb) { - return (m_color_bytes == 4) ? ((unsigned int*)m_phy_fb)[y * m_width + x] : GL_RGB_16_to_32(((unsigned short*)m_phy_fb)[y * m_width + x]); + return (m_color_bytes == 2) ? GL_RGB_16_to_32(((unsigned short*)m_display->m_phy_fb)[y * m_width + x]) : ((unsigned int*)m_display->m_phy_fb)[y * m_width + x]; } return 0; } @@ -357,7 +431,7 @@ public: } if (z_order == m_max_zorder) { - return draw_pixel_on_fb(x, y, rgb); + return draw_pixel_low_level(x, y, rgb); } if (z_order > (unsigned int)m_top_zorder) @@ -367,19 +441,19 @@ public: if (m_layers[z_order].rect.pt_in_rect(x, y)) { c_rect layer_rect = m_layers[z_order].rect; - if (m_color_bytes == 4) + if (m_color_bytes == 2) { - ((unsigned int*)(m_layers[z_order].fb))[(x - layer_rect.m_left) + (y - layer_rect.m_top) * layer_rect.width()] = rgb; + ((unsigned short*)(m_layers[z_order].fb))[(x - layer_rect.m_left) + (y - layer_rect.m_top) * layer_rect.width()] = GL_RGB_32_to_16(rgb); } else { - ((unsigned short*)(m_layers[z_order].fb))[(x - layer_rect.m_left) + (y - layer_rect.m_top) * layer_rect.width()] = GL_RGB_32_to_16(rgb); + ((unsigned int*)(m_layers[z_order].fb))[(x - layer_rect.m_left) + (y - layer_rect.m_top) * layer_rect.width()] = rgb; } } if (z_order == m_top_zorder) { - return draw_pixel_on_fb(x, y, rgb); + return draw_pixel_low_level(x, y, rgb); } bool be_overlapped = false; for (unsigned int tmp_z_order = Z_ORDER_LEVEL_MAX - 1; tmp_z_order > z_order; tmp_z_order--) @@ -392,7 +466,7 @@ public: } if (!be_overlapped) { - draw_pixel_on_fb(x, y, rgb); + draw_pixel_low_level(x, y, rgb); } } virtual void fill_rect(int x0, int y0, int x1, int y1, unsigned int rgb, unsigned int z_order) @@ -403,7 +477,7 @@ public: y1 = (y1 > (m_height - 1)) ? (m_height - 1) : y1; if (z_order == m_max_zorder) { - return fill_rect_on_fb(x0, y0, x1, y1, rgb); + return fill_rect_low_level(x0, y0, x1, y1, rgb); } if (z_order == m_top_zorder) { @@ -416,18 +490,18 @@ public: { if (layer_rect.pt_in_rect(x, y)) { - if (m_color_bytes == 4) + if (m_color_bytes == 2) { - ((unsigned int*)m_layers[z_order].fb)[(y - layer_rect.m_top) * layer_rect.width() + (x - layer_rect.m_left)] = rgb; + ((unsigned short*)m_layers[z_order].fb)[(y - layer_rect.m_top) * layer_rect.width() + (x - layer_rect.m_left)] = rgb_16; } else { - ((unsigned short*)m_layers[z_order].fb)[(y - layer_rect.m_top) * layer_rect.width() + (x - layer_rect.m_left)] = rgb_16; + ((unsigned int*)m_layers[z_order].fb)[(y - layer_rect.m_top) * layer_rect.width() + (x - layer_rect.m_left)] = rgb; } } } } - return fill_rect_on_fb(x0, y0, x1, y1, rgb); + return fill_rect_low_level(x0, y0, x1, y1, rgb); } for (; y0 <= y1; y0++) { @@ -499,27 +573,16 @@ public: } int flush_screen(int left, int top, int right, int bottom) { - if (left < 0 || left >= m_width || right < 0 || right >= m_width || - top < 0 || top >= m_height || bottom < 0 || bottom >= m_height) - { - ASSERT(false); - } - if (!m_is_active || (0 == m_phy_fb) || (0 == m_fb)) + if (!m_is_active) { return -1; } - int display_width = m_display->get_width(); - int display_height = m_display->get_height(); - left = (left >= display_width) ? (display_width - 1) : left; - right = (right >= display_width) ? (display_width - 1) : right; - top = (top >= display_height) ? (display_height - 1) : top; - bottom = (bottom >= display_height) ? (display_height - 1) : bottom; - for (int y = top; y < bottom; y++) + if (left < 0 || left >= m_width || right < 0 || right >= m_width || + top < 0 || top >= m_height || bottom < 0 || bottom >= m_height) { - void* s_addr = (char*)m_fb + ((y * m_width + left) * m_color_bytes); - void* d_addr = (char*)m_phy_fb + ((y * display_width + left) * m_color_bytes); - memcpy(d_addr, s_addr, (right - left) * m_color_bytes); + ASSERT(false); } + m_display->flush_screen(left, top, right, bottom, m_fb, m_width); *m_phy_write_index = *m_phy_write_index + 1; return 0; } @@ -537,90 +600,62 @@ public: { for (int x = rect.m_left; x <= rect.m_right; x++) { - unsigned int rgb = (m_color_bytes == 4) ? ((unsigned int*)fb)[(x - layer_rect.m_left) + (y - layer_rect.m_top) * width] : GL_RGB_16_to_32(((unsigned short*)fb)[(x - layer_rect.m_left) + (y - layer_rect.m_top) * width]); - draw_pixel_on_fb(x, y, rgb); + unsigned int rgb = (m_color_bytes == 2) ? GL_RGB_16_to_32(((unsigned short*)fb)[(x - layer_rect.m_left) + (y - layer_rect.m_top) * width]) : ((unsigned int*)fb)[(x - layer_rect.m_left) + (y - layer_rect.m_top) * width]; + draw_pixel_low_level(x, y, rgb); } } return 0; } void set_active(bool flag) { m_is_active = flag; } protected: - virtual void fill_rect_on_fb(int x0, int y0, int x1, int y1, unsigned int rgb) - { - int display_width = m_display->get_width(); - int display_height = m_display->get_height(); - if (m_color_bytes == 4) + virtual void fill_rect_low_level(int x0, int y0, int x1, int y1, unsigned int rgb) + {//fill rect on framebuffer of surface + int x, y; + if (m_color_bytes == 2) { - int x; - unsigned int* fb, * phy_fb; - for (; y0 <= y1; y0++) + unsigned short* fb; + unsigned int rgb_16 = GL_RGB_32_to_16(rgb); + for (y = y0; y <= y1; y++) { - x = x0; - fb = m_fb ? &((unsigned int*)m_fb)[y0 * m_width + x] : 0; - phy_fb = &((unsigned int*)m_phy_fb)[y0 * display_width + x]; - *m_phy_write_index = *m_phy_write_index + 1; - for (; x <= x1; x++) + fb = m_fb ? &((unsigned short*)m_fb)[y * m_width + x0] : 0; + if (!fb) { break; } + for (x = x0; x <= x1; x++) { - if (fb) - { - *fb++ = rgb; - } - if (m_is_active && (x < display_width) && (y0 < display_height)) - { - *phy_fb++ = rgb; - } + *fb++ = rgb_16; } } } - else if (m_color_bytes == 2) + else { - int x; - unsigned short* fb, * phy_fb; - rgb = GL_RGB_32_to_16(rgb); - for (; y0 <= y1; y0++) + unsigned int* fb; + for (y = y0; y <= y1; y++) { - x = x0; - fb = m_fb ? &((unsigned short*)m_fb)[y0 * m_width + x] : 0; - phy_fb = &((unsigned short*)m_phy_fb)[y0 * display_width + x]; - *m_phy_write_index = *m_phy_write_index + 1; - for (; x <= x1; x++) + fb = m_fb ? &((unsigned int*)m_fb)[y * m_width + x0] : 0; + if (!fb) { break; } + for (x = x0; x <= x1; x++) { - if (fb) - { - *fb++ = rgb; - } - if (m_is_active && (x < display_width) && (y0 < display_height)) - { - *phy_fb++ = rgb; - } + *fb++ = rgb; } } } + if (!m_is_active) { return; } + m_display->fill_rect(x0, y0, x1, y1, rgb); + *m_phy_write_index = *m_phy_write_index + 1; } - virtual void draw_pixel_on_fb(int x, int y, unsigned int rgb) + virtual void draw_pixel_low_level(int x, int y, unsigned int rgb) { if (m_fb) - { - (m_color_bytes == 4) ? ((unsigned int*)m_fb)[y * m_width + x] = rgb : ((unsigned short*)m_fb)[y * m_width + x] = GL_RGB_32_to_16(rgb); - } - if (m_is_active && (x < m_display->get_width()) && (y < m_display->get_height())) - { - if (m_color_bytes == 4) - { - ((unsigned int*)m_phy_fb)[y * (m_display->get_width()) + x] = rgb; - } - else - { - ((unsigned short*)m_phy_fb)[y * (m_display->get_width()) + x] = GL_RGB_32_to_16(rgb); - } - *m_phy_write_index = *m_phy_write_index + 1; + {//draw pixel on framebuffer of surface + (m_color_bytes == 2) ? ((unsigned short*)m_fb)[y * m_width + x] = GL_RGB_32_to_16(rgb): ((unsigned int*)m_fb)[y * m_width + x] = rgb; } + if (!m_is_active) { return; } + m_display->draw_pixel(x, y, rgb); + *m_phy_write_index = *m_phy_write_index + 1; } void attach_display(c_display* display) { ASSERT(display); m_display = display; - m_phy_fb = display->m_phy_fb; m_phy_write_index = &display->m_phy_write_index; } void set_surface(Z_ORDER_LEVEL max_z_order, c_rect layer_rect) @@ -638,87 +673,22 @@ protected: } int m_width; //in pixels int m_height; //in pixels - int m_color_bytes; //16 bits, 32 bits only + int m_color_bytes; //16 bits, 32 bits for default void* m_fb; //frame buffer you could see c_layer m_layers[Z_ORDER_LEVEL_MAX];//all graphic layers bool m_is_active; //active flag Z_ORDER_LEVEL m_max_zorder; //the highest graphic layer the surface will have Z_ORDER_LEVEL m_top_zorder; //the current highest graphic layer the surface have - void* m_phy_fb; //physical framebufer int* m_phy_write_index; c_display* m_display; }; -class c_surface_no_fb : public c_surface {//No physical framebuffer, render with external graphic interface - friend class c_display; -public: - c_surface_no_fb(unsigned int width, unsigned int height, unsigned int color_bytes, struct EXTERNAL_GFX_OP* gfx_op, Z_ORDER_LEVEL max_zorder = Z_ORDER_LEVEL_0, c_rect overlpa_rect = c_rect()) : c_surface(width, height, color_bytes, max_zorder, overlpa_rect), m_gfx_op(gfx_op) {} -protected: - virtual void fill_rect_on_fb(int x0, int y0, int x1, int y1, unsigned int rgb) - { - if (!m_gfx_op) - { - return; - } - if (m_gfx_op->fill_rect) - { - return m_gfx_op->fill_rect(x0, y0, x1, y1, rgb); - } - if (m_gfx_op->draw_pixel && m_is_active) - { - for (int y = y0; y <= y1; y++) - { - for (int x = x0; x <= x1; x++) - { - m_gfx_op->draw_pixel(x, y, rgb); - } - } - } - if (!m_fb) { return; } - if (m_color_bytes == 4) - { - unsigned int* fb; - for (int y = y0; y <= y1; y++) - { - fb = &((unsigned int*)m_fb)[y0 * m_width + x0]; - for (int x = x0; x <= x1; x++) - { - *fb++ = rgb; - } - } - } - else if (m_color_bytes == 2) - { - unsigned short* fb; - rgb = GL_RGB_32_to_16(rgb); - for (int y = y0; y <= y1; y++) - { - fb = &((unsigned short*)m_fb)[y0 * m_width + x0]; - for (int x = x0; x <= x1; x++) - { - *fb++ = rgb; - } - } - } - } - virtual void draw_pixel_on_fb(int x, int y, unsigned int rgb) - { - if (m_gfx_op && m_gfx_op->draw_pixel && m_is_active) - { - m_gfx_op->draw_pixel(x, y, rgb); - } - if (!m_fb) { return; } - if (m_color_bytes == 4) - { - ((unsigned int*)m_fb)[y * m_width + x] = rgb; - } - else if (m_color_bytes == 2) - { - ((unsigned short*)m_fb)[y * m_width + x] = GL_RGB_32_to_16(rgb); - } - } - struct EXTERNAL_GFX_OP* m_gfx_op;//Rendering by external method -}; -inline c_display::c_display(void* phy_fb, int display_width, int display_height, int surface_width, int surface_height, unsigned int color_bytes, int surface_cnt, EXTERNAL_GFX_OP* gfx_op) : m_width(display_width), m_height(display_height), m_color_bytes(color_bytes), m_phy_fb(phy_fb), m_phy_read_index(0), m_phy_write_index(0), m_surface_cnt(surface_cnt), m_surface_index(0) +inline c_display::c_display(void* phy_fb, int display_width, int display_height, c_surface* surface, DISPLAY_DRIVER* driver) : m_phy_fb(phy_fb), m_width(display_width), m_height(display_height), m_driver(driver), m_phy_read_index(0), m_phy_write_index(0), m_surface_cnt(1), m_surface_index(0) +{ + m_color_bytes = surface->m_color_bytes; + surface->m_is_active = true; + (m_surface_group[0] = surface)->attach_display(this); +} +inline c_display::c_display(void* phy_fb, int display_width, int display_height, int surface_width, int surface_height, unsigned int color_bytes, int surface_cnt, DISPLAY_DRIVER* driver) : m_phy_fb(phy_fb), m_width(display_width), m_height(display_height), m_color_bytes(color_bytes), m_phy_read_index(0), m_phy_write_index(0), m_surface_cnt(surface_cnt), m_driver(driver), m_surface_index(0) { ASSERT(color_bytes == 2 || color_bytes == 4); ASSERT(m_surface_cnt <= SURFACE_CNT_MAX); @@ -726,16 +696,10 @@ inline c_display::c_display(void* phy_fb, int display_width, int display_height, for (int i = 0; i < m_surface_cnt; i++) { - m_surface_group[i] = (phy_fb) ? new c_surface(surface_width, surface_height, color_bytes) : new c_surface_no_fb(surface_width, surface_height, color_bytes, gfx_op); + m_surface_group[i] = new c_surface(surface_width, surface_height, color_bytes); m_surface_group[i]->attach_display(this); } } -inline c_display::c_display(void* phy_fb, int display_width, int display_height, c_surface* surface) : m_width(display_width), m_height(display_height), m_phy_fb(phy_fb), m_phy_read_index(0), m_phy_write_index(0), m_surface_cnt(1), m_surface_index(0) -{ - m_color_bytes = surface->m_color_bytes; - surface->m_is_active = true; - (m_surface_group[0] = surface)->attach_display(this); -} inline c_surface* c_display::alloc_surface(Z_ORDER_LEVEL max_zorder, c_rect layer_rect) { ASSERT(max_zorder < Z_ORDER_LEVEL_MAX && m_surface_index < m_surface_cnt); @@ -744,8 +708,8 @@ inline c_surface* c_display::alloc_surface(Z_ORDER_LEVEL max_zorder, c_rect laye } inline int c_display::swipe_surface(c_surface* s0, c_surface* s1, int x0, int x1, int y0, int y1, int offset) { - int surface_width = s0->get_width(); - int surface_height = s0->get_height(); + register int surface_width = s0->m_width; + register int surface_height = s0->m_height; if (offset < 0 || offset > surface_width || y0 < 0 || y0 >= surface_height || y1 < 0 || y1 >= surface_height || x0 < 0 || x0 >= surface_width || x1 < 0 || x1 >= surface_width) { @@ -767,46 +731,46 @@ inline int c_display::swipe_surface(c_surface* s0, c_surface* s1, int x0, int x1 for (int y = y0; y <= y1; y++) { //Left surface - char* addr_s = ((char*)(s0->m_fb) + (y * (s0->get_width()) + x0 + offset) * m_color_bytes); + char* addr_s = ((char*)(s0->m_fb) + (y * surface_width + x0 + offset) * m_color_bytes); char* addr_d = ((char*)(m_phy_fb)+(y * m_width + x0) * m_color_bytes); memcpy(addr_d, addr_s, (width - offset) * m_color_bytes); //Right surface - addr_s = ((char*)(s1->m_fb) + (y * (s1->get_width()) + x0) * m_color_bytes); + addr_s = ((char*)(s1->m_fb) + (y * surface_width + x0) * m_color_bytes); addr_d = ((char*)(m_phy_fb)+(y * m_width + x0 + (width - offset)) * m_color_bytes); memcpy(addr_d, addr_s, offset * m_color_bytes); } } - else if (m_color_bytes == 4) + else if (m_color_bytes == 2) { - void(*draw_pixel)(int x, int y, unsigned int rgb) = ((c_surface_no_fb*)s0)->m_gfx_op->draw_pixel; + void(*draw_pixel)(int x, int y, unsigned int rgb) = m_driver->draw_pixel; for (int y = y0; y <= y1; y++) { //Left surface for (int x = x0; x <= (x1 - offset); x++) { - draw_pixel(x, y, ((unsigned int*)s0->m_fb)[y * m_width + x + offset]); + draw_pixel(x, y, GL_RGB_16_to_32(((unsigned short*)s0->m_fb)[y * m_width + x + offset])); } //Right surface for (int x = x1 - offset; x <= x1; x++) { - draw_pixel(x, y, ((unsigned int*)s1->m_fb)[y * m_width + x + offset - x1 + x0]); + draw_pixel(x, y, GL_RGB_16_to_32(((unsigned short*)s1->m_fb)[y * m_width + x + offset - x1 + x0])); } } } - else if (m_color_bytes == 2) + else //m_color_bytes == 3/4... { - void(*draw_pixel)(int x, int y, unsigned int rgb) = ((c_surface_no_fb*)s0)->m_gfx_op->draw_pixel; + void(*draw_pixel)(int x, int y, unsigned int rgb) = m_driver->draw_pixel; for (int y = y0; y <= y1; y++) { //Left surface for (int x = x0; x <= (x1 - offset); x++) { - draw_pixel(x, y, GL_RGB_16_to_32(((unsigned short*)s0->m_fb)[y * m_width + x + offset])); + draw_pixel(x, y, ((unsigned int*)s0->m_fb)[y * m_width + x + offset]); } //Right surface for (int x = x1 - offset; x <= x1; x++) { - draw_pixel(x, y, GL_RGB_16_to_32(((unsigned short*)s1->m_fb)[y * m_width + x + offset - x1 + x0])); + draw_pixel(x, y, ((unsigned int*)s1->m_fb)[y * m_width + x + offset - x1 + x0]); } } } @@ -3407,22 +3371,12 @@ private: #ifdef GUILITE_ON c_bitmap_operator the_bitmap_op = c_bitmap_operator(); c_image_operator* c_image::image_operator = &the_bitmap_op; +const void* c_theme::s_font_map[FONT_MAX]; +const void* c_theme::s_image_map[IMAGE_MAX]; +unsigned int c_theme::s_color_map[COLOR_MAX]; +c_lattice_font_op the_lattice_font_op = c_lattice_font_op(); +c_font_operator* c_word::fontOperator = &the_lattice_font_op; #endif - -#ifdef GUILITE_ON - -const void* c_theme::s_font_map[FONT_MAX]; -const void* c_theme::s_image_map[IMAGE_MAX]; -unsigned int c_theme::s_color_map[COLOR_MAX]; - -#endif - -#ifdef GUILITE_ON - -c_lattice_font_op the_lattice_font_op = c_lattice_font_op(); -c_font_operator* c_word::fontOperator = &the_lattice_font_op; - -#endif #ifdef GUILITE_ON #if (defined __linux__) || (defined __APPLE__) #include @@ -4264,11 +4218,7 @@ int c_fifo::write(void* buf, int len) #endif #ifdef GUILITE_ON DIALOG_ARRAY c_dialog::ms_the_dialogs[SURFACE_CNT_MAX]; -#endif -#ifdef GUILITE_ON c_keyboard c_edit::s_keyboard; -#endif -#ifdef GUILITE_ON static c_keyboard_button s_key_0, s_key_1, s_key_2, s_key_3, s_key_4, s_key_5, s_key_6, s_key_7, s_key_8, s_key_9; static c_keyboard_button s_key_A, s_key_B, s_key_C, s_key_D, s_key_E, s_key_F, s_key_G, s_key_H, s_key_I, s_key_J; static c_keyboard_button s_key_K, s_key_L, s_key_M, s_key_N, s_key_O, s_key_P, s_key_Q, s_key_R, s_key_S, s_key_T; @@ -4306,12 +4256,12 @@ WND_TREE g_key_board_children[] = {&s_key_B, 'B', 0, ((KEY_WIDTH / 2) + POS_X(5)), POS_Y(2), KEY_WIDTH, KEY_HEIGHT}, {&s_key_N, 'N', 0, ((KEY_WIDTH / 2) + POS_X(6)), POS_Y(2), KEY_WIDTH, KEY_HEIGHT}, {&s_key_M, 'M', 0, ((KEY_WIDTH / 2) + POS_X(7)), POS_Y(2), KEY_WIDTH, KEY_HEIGHT}, - {&s_key_del, 0x7F, 0, ((KEY_WIDTH / 2) + POS_X(8)), POS_Y(2), DEL_WIDTH, KEY_HEIGHT}, + {&s_key_del,0x7F, 0, ((KEY_WIDTH / 2) + POS_X(8)), POS_Y(2), DEL_WIDTH, KEY_HEIGHT}, //Row 4 - {&s_key_esc, 0x1B, 0, POS_X(0), POS_Y(3), ESC_WIDTH, KEY_HEIGHT}, + {&s_key_esc, 0x1B, 0, POS_X(0), POS_Y(3), ESC_WIDTH, KEY_HEIGHT}, {&s_key_num_switch, 0x90, 0, POS_X(2), POS_Y(3), SWITCH_WIDTH, KEY_HEIGHT}, {&s_key_space, ' ', 0, ((KEY_WIDTH / 2) + POS_X(3)), POS_Y(3), SPACE_WIDTH, KEY_HEIGHT}, - {&s_key_dot, '.', 0, ((KEY_WIDTH / 2) + POS_X(6)), POS_Y(3), DOT_WIDTH, KEY_HEIGHT}, + {&s_key_dot, '.', 0, ((KEY_WIDTH / 2) + POS_X(6)), POS_Y(3), DOT_WIDTH, KEY_HEIGHT}, {&s_key_enter, '\n', 0, POS_X(8), POS_Y(3), ENTER_WIDTH, KEY_HEIGHT}, {0,0,0,0,0,0,0} }; @@ -4326,12 +4276,11 @@ WND_TREE g_number_board_children[] = {&s_key_7, '7', 0, POS_X(0), POS_Y(2), KEY_WIDTH, KEY_HEIGHT}, {&s_key_8, '8', 0, POS_X(1), POS_Y(2), KEY_WIDTH, KEY_HEIGHT}, {&s_key_9, '9', 0, POS_X(2), POS_Y(2), KEY_WIDTH, KEY_HEIGHT}, - - {&s_key_esc, 0x1B, 0, POS_X(0), POS_Y(3), KEY_WIDTH, KEY_HEIGHT}, + {&s_key_esc,0x1B, 0, POS_X(0), POS_Y(3), KEY_WIDTH, KEY_HEIGHT}, {&s_key_0, '0', 0, POS_X(1), POS_Y(3), KEY_WIDTH, KEY_HEIGHT}, - {&s_key_dot, '.', 0, POS_X(2), POS_Y(3), KEY_WIDTH, KEY_HEIGHT}, + {&s_key_dot,'.', 0, POS_X(2), POS_Y(3), KEY_WIDTH, KEY_HEIGHT}, {&s_key_del, 0x7F, 0, POS_X(3), POS_Y(0), KEY_WIDTH, KEY_HEIGHT * 2 + 2}, {&s_key_enter,'\n', 0, POS_X(3), POS_Y(2), KEY_WIDTH, KEY_HEIGHT * 2 + 2}, {0,0,0,0,0,0,0} }; -#endif +#endif \ No newline at end of file diff --git a/HelloLayers/UIcode/UIcode.cpp b/HelloLayers/UIcode/UIcode.cpp index 46f629b011a93c31e8cc91015f2b855f75ef8aa2..c421ccd1aea060989ed8e2f3c2389f744b8622f6 100644 --- a/HelloLayers/UIcode/UIcode.cpp +++ b/HelloLayers/UIcode/UIcode.cpp @@ -33,7 +33,7 @@ void draw_on_layer_1() { s_surface->fill_rect(c_rect(LAYER_1_X, LAYER_1_Y, LAYER_1_WIDTH, LAYER_1_HEIGHT), GL_RGB(0, 122, 204), Z_ORDER_LEVEL_1); c_word::draw_string(s_surface, Z_ORDER_LEVEL_1, "GuiLite", LAYER_1_X + 5, LAYER_1_Y + 20, c_theme::get_font(FONT_DEFAULT), GL_RGB(255, 255, 255), GL_RGB(0, 122, 204)); - c_word::draw_string(s_surface, Z_ORDER_LEVEL_1, " 5KLOC", LAYER_1_X + 5, LAYER_1_Y + 60, c_theme::get_font(FONT_DEFAULT), GL_RGB(255, 255, 255), GL_RGB(0, 122, 204)); + c_word::draw_string(s_surface, Z_ORDER_LEVEL_1, "4 KLOC", LAYER_1_X + 5, LAYER_1_Y + 60, c_theme::get_font(FONT_DEFAULT), GL_RGB(255, 255, 255), GL_RGB(0, 122, 204)); } void clear_layer_1() @@ -62,21 +62,11 @@ void load_resource() c_theme::add_font(FONT_DEFAULT, &Consolas_19); } -void create_ui(void* phy_fb, int screen_width, int screen_height, int color_bytes, struct EXTERNAL_GFX_OP* gfx_op) { - if (phy_fb) - { - static c_surface surface(UI_WIDTH, UI_HEIGHT, color_bytes, Z_ORDER_LEVEL_1, c_rect(LAYER_1_X, LAYER_1_Y, LAYER_1_X + LAYER_1_WIDTH - 1, LAYER_1_Y + LAYER_1_HEIGHT - 1)); - static c_display display(phy_fb, screen_width, screen_height, &surface); - s_surface = &surface; - s_display = &display; - } - else - {//for MCU without framebuffer - static c_surface_no_fb surface_no_fb(UI_WIDTH, UI_HEIGHT, color_bytes, gfx_op, Z_ORDER_LEVEL_1, c_rect(LAYER_1_X, LAYER_1_Y, LAYER_1_X + LAYER_1_WIDTH - 1, LAYER_1_Y + LAYER_1_HEIGHT - 1)); - static c_display display(phy_fb, screen_width, screen_height, &surface_no_fb); - s_surface = &surface_no_fb; - s_display = &display; - } +void create_ui(void* phy_fb, int screen_width, int screen_height, int color_bytes, struct DISPLAY_DRIVER* driver) { + static c_surface surface(UI_WIDTH, UI_HEIGHT, color_bytes, Z_ORDER_LEVEL_1, c_rect(LAYER_1_X, LAYER_1_Y, LAYER_1_X + LAYER_1_WIDTH - 1, LAYER_1_Y + LAYER_1_HEIGHT - 1)); + static c_display display(phy_fb, screen_width, screen_height, &surface, driver); + s_surface = &surface; + s_display = &display; load_resource(); draw_on_layer_0(); @@ -89,8 +79,8 @@ void create_ui(void* phy_fb, int screen_width, int screen_height, int color_byte } //////////////////////// interface for all platform //////////////////////// -extern "C" void startHelloLayers(void* phy_fb, int width, int height, int color_bytes, struct EXTERNAL_GFX_OP* gfx_op) { - create_ui(phy_fb, width, height, color_bytes, gfx_op); +extern "C" void startHelloLayers(void* phy_fb, int width, int height, int color_bytes, struct DISPLAY_DRIVER* driver) { + create_ui(phy_fb, width, height, color_bytes, driver); } void* getUiOfHelloLayers(int* width, int* height, bool force_update) diff --git a/HelloMario/BuildLinux/.sync_build.sh b/HelloMario/BuildLinux/.sync_build.sh index 49cff5b473ac606967676ebefa6f0d333e301227..44974a804790e57400a480e8381b36bedbf23cab 100644 --- a/HelloMario/BuildLinux/.sync_build.sh +++ b/HelloMario/BuildLinux/.sync_build.sh @@ -1,5 +1,6 @@ if [ "$#" -ne 1 ]; then - echo "Invalid arguments" + echo "Do testing" + ./xWindow 240 320 | ./HelloMario shared-fb exit -1 fi diff --git a/HelloMario/BuildLinux/main.cpp b/HelloMario/BuildLinux/main.cpp index 4a54a8c6e0a42baf9ef28ea0b34794e51820a63e..33b3c3057b4ea9881a705b57437d0651ac700fb1 100644 --- a/HelloMario/BuildLinux/main.cpp +++ b/HelloMario/BuildLinux/main.cpp @@ -10,7 +10,7 @@ #include #include -extern "C" void startHelloMario(void* phy_fb, int width, int height, int color_bytes, struct EXTERNAL_GFX_OP* gfx_op); +extern "C" void startHelloMario(void* phy_fb, int width, int height, int color_bytes, struct DISPLAY_DRIVER* driver); extern void init_std_io(); static void* get_embeded_fb_in_display_app(int shared_id); diff --git a/HelloMario/BuildMFC/HelloMarioDlg.cpp b/HelloMario/BuildMFC/HelloMarioDlg.cpp index 4678c481cdff69f9b406f5e47700e4c28c8d7ad9..be15fcdf94d266ed02dfd897687d4f4f2e710c7c 100644 Binary files a/HelloMario/BuildMFC/HelloMarioDlg.cpp and b/HelloMario/BuildMFC/HelloMarioDlg.cpp differ diff --git a/HelloMario/BuildMFC/HelloMarioDlg.h b/HelloMario/BuildMFC/HelloMarioDlg.h index fa74be1a3ba7975adcbc5d82af5e6ddc7ad03da4..207ab5081c2b3515fe6956d316d060c140176015 100644 Binary files a/HelloMario/BuildMFC/HelloMarioDlg.h and b/HelloMario/BuildMFC/HelloMarioDlg.h differ diff --git a/HelloMario/BuildSTM32F103-Keil/USER/main.c b/HelloMario/BuildSTM32F103-Keil/USER/main.c index 07a8a6c46e22582dc536e449178fc6a3eadd7027..f8b7741e20c32cf3632076eca35dbc685dbaae31 100644 --- a/HelloMario/BuildSTM32F103-Keil/USER/main.c +++ b/HelloMario/BuildSTM32F103-Keil/USER/main.c @@ -16,13 +16,13 @@ void gfx_draw_pixel(int x, int y, unsigned int rgb) //void gfx_fill_rect(int x0, int y0, int x1, int y1, unsigned int rgb){} //UI entry -struct EXTERNAL_GFX_OP +struct DISPLAY_DRIVER { void (*draw_pixel)(int x, int y, unsigned int rgb); void (*fill_rect)(int x0, int y0, int x1, int y1, unsigned int rgb); -} my_gfx_op; +} my_driver; -extern void startHelloMario(void* phy_fb, int width, int height, int color_bytes, struct EXTERNAL_GFX_OP* gfx_op); +extern void startHelloMario(void* phy_fb, int width, int height, int color_bytes, struct DISPLAY_DRIVER* driver); int main(void) { //Hardware initialization: @@ -31,8 +31,8 @@ int main(void) LCD_Init(); //Link your LCD driver & start UI: - my_gfx_op.draw_pixel = gfx_draw_pixel; - my_gfx_op.fill_rect = NULL;//gfx_fill_rect; - startHelloMario(NULL, 240, 320, 2, &my_gfx_op); + my_driver.draw_pixel = gfx_draw_pixel; + my_driver.fill_rect = NULL;//gfx_fill_rect; + startHelloMario(NULL, 240, 320, 2, &my_driver); while(1); } diff --git a/HelloMario/BuildWin32/HelloMario.cpp b/HelloMario/BuildWin32/HelloMario.cpp index baee4902abea5eb597d41f3d939870b8757ea6ec..5b1a5db9b37d35f7fbff9f3f72a2fdd72276a240 100644 --- a/HelloMario/BuildWin32/HelloMario.cpp +++ b/HelloMario/BuildWin32/HelloMario.cpp @@ -161,7 +161,7 @@ LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam) } //////////////////////// HelloMario Interface //////////////////////// -extern "C" void startHelloMario(void* phy_fb, int width, int height, int color_bytes, struct EXTERNAL_GFX_OP* gfx_op); +extern "C" void startHelloMario(void* phy_fb, int width, int height, int color_bytes, struct DISPLAY_DRIVER* driver); DWORD WINAPI ThreadHelloMario(LPVOID pParam) { diff --git a/HelloMario/UIcode/GuiLite.h b/HelloMario/UIcode/GuiLite.h index c4fc88a51476d2c8309c3e55e1270e13784fc510..80550e1632ad7bc82541a2edbb0f7f8f5937954f 100644 --- a/HelloMario/UIcode/GuiLite.h +++ b/HelloMario/UIcode/GuiLite.h @@ -1,107 +1,94 @@ #pragma once - -#define REAL_TIME_TASK_CYCLE_MS 50 -#define MAX(a,b) (((a)>(b))?(a):(b)) -#define MIN(a,b) (((a)<(b))?(a):(b)) - -#define GL_ARGB(a, r, g, b) ((((unsigned int)(a)) << 24) | (((unsigned int)(r)) << 16) | (((unsigned int)(g)) << 8) | ((unsigned int)(b))) -#define GL_ARGB_A(rgb) ((((unsigned int)(rgb)) >> 24) & 0xFF) - -#define GL_RGB(r, g, b) ((0xFF << 24) | (((unsigned int)(r)) << 16) | (((unsigned int)(g)) << 8) | ((unsigned int)(b))) -#define GL_RGB_R(rgb) ((((unsigned int)(rgb)) >> 16) & 0xFF) -#define GL_RGB_G(rgb) ((((unsigned int)(rgb)) >> 8) & 0xFF) -#define GL_RGB_B(rgb) (((unsigned int)(rgb)) & 0xFF) -#define GL_RGB_32_to_16(rgb) (((((unsigned int)(rgb)) & 0xFF) >> 3) | ((((unsigned int)(rgb)) & 0xFC00) >> 5) | ((((unsigned int)(rgb)) & 0xF80000) >> 8)) -#define GL_RGB_16_to_32(rgb) ((0xFF << 24) | ((((unsigned int)(rgb)) & 0x1F) << 3) | ((((unsigned int)(rgb)) & 0x7E0) << 5) | ((((unsigned int)(rgb)) & 0xF800) << 8)) - -#define ALIGN_HCENTER 0x00000000L -#define ALIGN_LEFT 0x01000000L -#define ALIGN_RIGHT 0x02000000L -#define ALIGN_HMASK 0x03000000L - -#define ALIGN_VCENTER 0x00000000L -#define ALIGN_TOP 0x00100000L -#define ALIGN_BOTTOM 0x00200000L -#define ALIGN_VMASK 0x00300000L - -typedef struct -{ - unsigned short year; - unsigned short month; - unsigned short date; - unsigned short day; - unsigned short hour; - unsigned short minute; - unsigned short second; -}T_TIME; - -void register_debug_function(void(*my_assert)(const char* file, int line), void(*my_log_out)(const char* log)); -void _assert(const char* file, int line); -#define ASSERT(condition) \ - do{ \ - if(!(condition))_assert(__FILE__, __LINE__);\ - }while(0) -void log_out(const char* log); - -long get_time_in_second(); -T_TIME second_to_day(long second); -T_TIME get_time(); - -void start_real_timer(void (*func)(void* arg)); -void register_timer(int milli_second, void func(void* param), void* param); - -unsigned int get_cur_thread_id(); -void create_thread(unsigned long* thread_id, void* attr, void *(*start_routine) (void *), void* arg); -void thread_sleep(unsigned int milli_seconds); -int build_bmp(const char *filename, unsigned int width, unsigned int height, unsigned char *data); - -#define FIFO_BUFFER_LEN 1024 -class c_fifo -{ -public: - c_fifo(); - int read(void* buf, int len); - int write(void* buf, int len); -private: - unsigned char m_buf[FIFO_BUFFER_LEN]; - int m_head; - int m_tail; - void* m_read_sem; - void* m_write_mutex; -}; - -class c_rect -{ -public: - c_rect(){ m_left = m_top = m_right = m_bottom = -1; } - c_rect(int left, int top, int width, int height) - { - set_rect(left, top, width, height); - } - void set_rect(int left, int top, int width, int height) - { - ASSERT(width > 0 && height > 0); - m_left = left; - m_top = top; - m_right = left + width - 1; - m_bottom = top + height -1; - } - bool pt_in_rect(int x, int y) const - { - return x >= m_left && x <= m_right && y >= m_top && y <= m_bottom; - } - int operator==(const c_rect& rect) const - { - return (m_left == rect.m_left) && (m_top == rect.m_top) && (m_right == rect.m_right) && (m_bottom == rect.m_bottom); - } - int width() const { return m_right - m_left + 1; } - int height() const { return m_bottom - m_top + 1 ; } - - int m_left; - int m_top; - int m_right; - int m_bottom; -}; +#define REAL_TIME_TASK_CYCLE_MS 50 +#define MAX(a,b) (((a)>(b))?(a):(b)) +#define MIN(a,b) (((a)<(b))?(a):(b)) +#define GL_ARGB(a, r, g, b) ((((unsigned int)(a)) << 24) | (((unsigned int)(r)) << 16) | (((unsigned int)(g)) << 8) | ((unsigned int)(b))) +#define GL_ARGB_A(rgb) ((((unsigned int)(rgb)) >> 24) & 0xFF) +#define GL_RGB(r, g, b) ((0xFF << 24) | (((unsigned int)(r)) << 16) | (((unsigned int)(g)) << 8) | ((unsigned int)(b))) +#define GL_RGB_R(rgb) ((((unsigned int)(rgb)) >> 16) & 0xFF) +#define GL_RGB_G(rgb) ((((unsigned int)(rgb)) >> 8) & 0xFF) +#define GL_RGB_B(rgb) (((unsigned int)(rgb)) & 0xFF) +#define GL_RGB_32_to_16(rgb) (((((unsigned int)(rgb)) & 0xFF) >> 3) | ((((unsigned int)(rgb)) & 0xFC00) >> 5) | ((((unsigned int)(rgb)) & 0xF80000) >> 8)) +#define GL_RGB_16_to_32(rgb) ((0xFF << 24) | ((((unsigned int)(rgb)) & 0x1F) << 3) | ((((unsigned int)(rgb)) & 0x7E0) << 5) | ((((unsigned int)(rgb)) & 0xF800) << 8)) +#define ALIGN_HCENTER 0x00000000L +#define ALIGN_LEFT 0x01000000L +#define ALIGN_RIGHT 0x02000000L +#define ALIGN_HMASK 0x03000000L +#define ALIGN_VCENTER 0x00000000L +#define ALIGN_TOP 0x00100000L +#define ALIGN_BOTTOM 0x00200000L +#define ALIGN_VMASK 0x00300000L +typedef struct +{ + unsigned short year; + unsigned short month; + unsigned short date; + unsigned short day; + unsigned short hour; + unsigned short minute; + unsigned short second; +}T_TIME; +void register_debug_function(void(*my_assert)(const char* file, int line), void(*my_log_out)(const char* log)); +void _assert(const char* file, int line); +#define ASSERT(condition) \ + do{ \ + if(!(condition))_assert(__FILE__, __LINE__);\ + }while(0) +void log_out(const char* log); +long get_time_in_second(); +T_TIME second_to_day(long second); +T_TIME get_time(); +void start_real_timer(void (*func)(void* arg)); +void register_timer(int milli_second, void func(void* param), void* param); +unsigned int get_cur_thread_id(); +void create_thread(unsigned long* thread_id, void* attr, void *(*start_routine) (void *), void* arg); +void thread_sleep(unsigned int milli_seconds); +int build_bmp(const char *filename, unsigned int width, unsigned int height, unsigned char *data); +#define FIFO_BUFFER_LEN 1024 +class c_fifo +{ +public: + c_fifo(); + int read(void* buf, int len); + int write(void* buf, int len); +private: + unsigned char m_buf[FIFO_BUFFER_LEN]; + int m_head; + int m_tail; + void* m_read_sem; + void* m_write_mutex; +}; +class c_rect +{ +public: + c_rect(){ m_left = m_top = m_right = m_bottom = -1; } + c_rect(int left, int top, int width, int height) + { + set_rect(left, top, width, height); + } + void set_rect(int left, int top, int width, int height) + { + ASSERT(width > 0 && height > 0); + m_left = left; + m_top = top; + m_right = left + width - 1; + m_bottom = top + height -1; + } + bool pt_in_rect(int x, int y) const + { + return x >= m_left && x <= m_right && y >= m_top && y <= m_bottom; + } + int operator==(const c_rect& rect) const + { + return (m_left == rect.m_left) && (m_top == rect.m_top) && (m_right == rect.m_right) && (m_bottom == rect.m_bottom); + } + int width() const { return m_right - m_left + 1; } + int height() const { return m_bottom - m_top + 1 ; } + int m_left; + int m_top; + int m_right; + int m_bottom; +}; //BITMAP typedef struct struct_bitmap_info { @@ -238,7 +225,7 @@ typedef enum Z_ORDER_LEVEL_2,//highest graphic level Z_ORDER_LEVEL_MAX }Z_ORDER_LEVEL; -struct EXTERNAL_GFX_OP +struct DISPLAY_DRIVER { void(*draw_pixel)(int x, int y, unsigned int rgb); void(*fill_rect)(int x0, int y0, int x1, int y1, unsigned int rgb); @@ -247,18 +234,19 @@ class c_surface; class c_display { friend class c_surface; public: - inline c_display(void* phy_fb, int display_width, int display_height, int surface_width, int surface_height, unsigned int color_bytes, int surface_cnt, EXTERNAL_GFX_OP* gfx_op = 0);//multiple surface or surface_no_fb - inline c_display(void* phy_fb, int display_width, int display_height, c_surface* surface);//single custom surface - inline c_surface* alloc_surface(Z_ORDER_LEVEL max_zorder, c_rect layer_rect = c_rect());//for multiple surfaces + inline c_display(void* phy_fb, int display_width, int display_height, c_surface* surface, DISPLAY_DRIVER* driver = 0);//single custom surface + inline c_display(void* phy_fb, int display_width, int display_height, int surface_width, int surface_height, unsigned int color_bytes, int surface_cnt, DISPLAY_DRIVER* driver = 0);//multiple surface + inline c_surface* alloc_surface(Z_ORDER_LEVEL max_zorder, c_rect layer_rect = c_rect());//for slide group inline int swipe_surface(c_surface* s0, c_surface* s1, int x0, int x1, int y0, int y1, int offset); int get_width() { return m_width; } int get_height() { return m_height; } + void* get_phy_fb() { return m_phy_fb; } void* get_updated_fb(int* width, int* height, bool force_update = false) { if (width && height) { - *width = get_width(); - *height = get_height(); + *width = m_width; + *height = m_height; } if (force_update) { @@ -277,35 +265,123 @@ public: { return -1; } - int width = get_width(); - int height = get_height(); //16 bits framebuffer if (m_color_bytes == 2) { - return build_bmp(file_name, width, height, (unsigned char*)m_phy_fb); + return build_bmp(file_name, m_width, m_height, (unsigned char*)m_phy_fb); } //32 bits framebuffer - unsigned short* p_bmp565_data = new unsigned short[width * height]; + unsigned short* p_bmp565_data = new unsigned short[m_width * m_height]; unsigned int* p_raw_data = (unsigned int*)m_phy_fb; - for (int i = 0; i < width * height; i++) + for (int i = 0; i < m_width * m_height; i++) { unsigned int rgb = *p_raw_data++; p_bmp565_data[i] = GL_RGB_32_to_16(rgb); } - int ret = build_bmp(file_name, width, height, (unsigned char*)p_bmp565_data); + int ret = build_bmp(file_name, m_width, m_height, (unsigned char*)p_bmp565_data); delete[]p_bmp565_data; return ret; } -private: - int m_width; //in pixels - int m_height; //in pixels - int m_color_bytes; //16 bits, 32 bits only - void* m_phy_fb; //physical framebuffer +protected: + virtual void draw_pixel(int x, int y, unsigned int rgb) + { + if ((x >= m_width) || (y >= m_height)) { return; } + if (m_driver && m_driver->draw_pixel) + { + return m_driver->draw_pixel(x, y, rgb); + } + if (m_color_bytes == 2) + { + ((unsigned short*)m_phy_fb)[y * m_width + x] = GL_RGB_32_to_16(rgb); + } + else + { + ((unsigned int*)m_phy_fb)[y * m_width + x] = rgb; + } + } + virtual void fill_rect(int x0, int y0, int x1, int y1, unsigned int rgb) + { + if (m_driver && m_driver->fill_rect) + { + return m_driver->fill_rect(x0, y0, x1, y1, rgb); + } + if (m_driver && m_driver->draw_pixel) + { + for (int y = y0; y <= y1; y++) + { + for (int x = x0; x <= x1; x++) + { + m_driver->draw_pixel(x, y, rgb); + } + } + return; + } + register int _width = m_width; + register int _height = m_height; + int x, y; + if (m_color_bytes == 2) + { + unsigned short* phy_fb; + unsigned int rgb_16 = GL_RGB_32_to_16(rgb); + for (y = y0; y <= y1; y++) + { + phy_fb = &((unsigned short*)m_phy_fb)[y * _width + x0]; + for (x = x0; x <= x1; x++) + { + if ((x < _width) && (y < _height)) + { + *phy_fb++ = rgb_16; + } + } + } + } + else + { + unsigned int* phy_fb; + for (y = y0; y <= y1; y++) + { + phy_fb = &((unsigned int*)m_phy_fb)[y * _width + x0]; + for (x = x0; x <= x1; x++) + { + if ((x < _width) && (y < _height)) + { + *phy_fb++ = rgb; + } + } + } + } + } + virtual int flush_screen(int left, int top, int right, int bottom, void* fb, int fb_width) + { + if ((0 == m_phy_fb) || (0 == fb)) + { + return -1; + } + register int _width = m_width; + register int _height = m_height; + left = (left >= _width) ? (_width - 1) : left; + right = (right >= _width) ? (_width - 1) : right; + top = (top >= _height) ? (_height - 1) : top; + bottom = (bottom >= _height) ? (_height - 1) : bottom; + for (int y = top; y < bottom; y++) + { + void* s_addr = (char*)fb + ((y * fb_width + left) * m_color_bytes); + void* d_addr = (char*)m_phy_fb + ((y * _width + left) * m_color_bytes); + memcpy(d_addr, s_addr, (right - left) * m_color_bytes); + } + return 0; + } + int m_width; //in pixels + int m_height; //in pixels + int m_color_bytes; //16/32 bits for default + void* m_phy_fb; //physical framebuffer for default + struct DISPLAY_DRIVER* m_driver; //Rendering by external method without default physical framebuffer int m_phy_read_index; int m_phy_write_index; c_surface* m_surface_group[SURFACE_CNT_MAX]; int m_surface_cnt; //surface count int m_surface_index; + }; class c_layer { @@ -317,12 +393,10 @@ public: class c_surface { friend class c_display; friend class c_bitmap_operator; public: - c_surface(unsigned int width, unsigned int height, unsigned int color_bytes, Z_ORDER_LEVEL max_zorder = Z_ORDER_LEVEL_0, c_rect overlpa_rect = c_rect()) : m_width(width), m_height(height), m_color_bytes(color_bytes), m_fb(0), m_is_active(false), m_top_zorder(Z_ORDER_LEVEL_0), m_phy_fb(0), m_phy_write_index(0), m_display(0) + c_surface(unsigned int width, unsigned int height, unsigned int color_bytes, Z_ORDER_LEVEL max_zorder = Z_ORDER_LEVEL_0, c_rect overlpa_rect = c_rect()) : m_width(width), m_height(height), m_color_bytes(color_bytes), m_fb(0), m_is_active(false), m_top_zorder(Z_ORDER_LEVEL_0), m_phy_write_index(0), m_display(0) { (overlpa_rect == c_rect()) ? set_surface(max_zorder, c_rect(0, 0, width - 1, height - 1)) : set_surface(max_zorder, overlpa_rect); } - int get_width() { return m_width; } - int get_height() { return m_height; } unsigned int get_pixel(int x, int y, unsigned int z_order) { if (x >= m_width || y >= m_height || x < 0 || y < 0 || z_order >= Z_ORDER_LEVEL_MAX) @@ -332,15 +406,15 @@ public: } if (m_layers[z_order].fb) { - return (m_color_bytes == 4) ? ((unsigned int*)(m_layers[z_order].fb))[y * m_width + x] : GL_RGB_16_to_32(((unsigned short*)(m_layers[z_order].fb))[y * m_width + x]); + return (m_color_bytes == 2) ? GL_RGB_16_to_32(((unsigned short*)(m_layers[z_order].fb))[y * m_width + x]) : ((unsigned int*)(m_layers[z_order].fb))[y * m_width + x]; } else if (m_fb) { - return (m_color_bytes == 4) ? ((unsigned int*)m_fb)[y * m_width + x] : GL_RGB_16_to_32(((unsigned short*)m_fb)[y * m_width + x]); + return (m_color_bytes == 2) ? GL_RGB_16_to_32(((unsigned short*)m_fb)[y * m_width + x]) : ((unsigned int*)m_fb)[y * m_width + x]; } - else if (m_phy_fb) + else if (m_display->m_phy_fb) { - return (m_color_bytes == 4) ? ((unsigned int*)m_phy_fb)[y * m_width + x] : GL_RGB_16_to_32(((unsigned short*)m_phy_fb)[y * m_width + x]); + return (m_color_bytes == 2) ? GL_RGB_16_to_32(((unsigned short*)m_display->m_phy_fb)[y * m_width + x]) : ((unsigned int*)m_display->m_phy_fb)[y * m_width + x]; } return 0; } @@ -357,7 +431,7 @@ public: } if (z_order == m_max_zorder) { - return draw_pixel_on_fb(x, y, rgb); + return draw_pixel_low_level(x, y, rgb); } if (z_order > (unsigned int)m_top_zorder) @@ -367,19 +441,19 @@ public: if (m_layers[z_order].rect.pt_in_rect(x, y)) { c_rect layer_rect = m_layers[z_order].rect; - if (m_color_bytes == 4) + if (m_color_bytes == 2) { - ((unsigned int*)(m_layers[z_order].fb))[(x - layer_rect.m_left) + (y - layer_rect.m_top) * layer_rect.width()] = rgb; + ((unsigned short*)(m_layers[z_order].fb))[(x - layer_rect.m_left) + (y - layer_rect.m_top) * layer_rect.width()] = GL_RGB_32_to_16(rgb); } else { - ((unsigned short*)(m_layers[z_order].fb))[(x - layer_rect.m_left) + (y - layer_rect.m_top) * layer_rect.width()] = GL_RGB_32_to_16(rgb); + ((unsigned int*)(m_layers[z_order].fb))[(x - layer_rect.m_left) + (y - layer_rect.m_top) * layer_rect.width()] = rgb; } } if (z_order == m_top_zorder) { - return draw_pixel_on_fb(x, y, rgb); + return draw_pixel_low_level(x, y, rgb); } bool be_overlapped = false; for (unsigned int tmp_z_order = Z_ORDER_LEVEL_MAX - 1; tmp_z_order > z_order; tmp_z_order--) @@ -392,7 +466,7 @@ public: } if (!be_overlapped) { - draw_pixel_on_fb(x, y, rgb); + draw_pixel_low_level(x, y, rgb); } } virtual void fill_rect(int x0, int y0, int x1, int y1, unsigned int rgb, unsigned int z_order) @@ -403,7 +477,7 @@ public: y1 = (y1 > (m_height - 1)) ? (m_height - 1) : y1; if (z_order == m_max_zorder) { - return fill_rect_on_fb(x0, y0, x1, y1, rgb); + return fill_rect_low_level(x0, y0, x1, y1, rgb); } if (z_order == m_top_zorder) { @@ -416,18 +490,18 @@ public: { if (layer_rect.pt_in_rect(x, y)) { - if (m_color_bytes == 4) + if (m_color_bytes == 2) { - ((unsigned int*)m_layers[z_order].fb)[(y - layer_rect.m_top) * layer_rect.width() + (x - layer_rect.m_left)] = rgb; + ((unsigned short*)m_layers[z_order].fb)[(y - layer_rect.m_top) * layer_rect.width() + (x - layer_rect.m_left)] = rgb_16; } else { - ((unsigned short*)m_layers[z_order].fb)[(y - layer_rect.m_top) * layer_rect.width() + (x - layer_rect.m_left)] = rgb_16; + ((unsigned int*)m_layers[z_order].fb)[(y - layer_rect.m_top) * layer_rect.width() + (x - layer_rect.m_left)] = rgb; } } } } - return fill_rect_on_fb(x0, y0, x1, y1, rgb); + return fill_rect_low_level(x0, y0, x1, y1, rgb); } for (; y0 <= y1; y0++) { @@ -499,27 +573,16 @@ public: } int flush_screen(int left, int top, int right, int bottom) { - if (left < 0 || left >= m_width || right < 0 || right >= m_width || - top < 0 || top >= m_height || bottom < 0 || bottom >= m_height) - { - ASSERT(false); - } - if (!m_is_active || (0 == m_phy_fb) || (0 == m_fb)) + if (!m_is_active) { return -1; } - int display_width = m_display->get_width(); - int display_height = m_display->get_height(); - left = (left >= display_width) ? (display_width - 1) : left; - right = (right >= display_width) ? (display_width - 1) : right; - top = (top >= display_height) ? (display_height - 1) : top; - bottom = (bottom >= display_height) ? (display_height - 1) : bottom; - for (int y = top; y < bottom; y++) + if (left < 0 || left >= m_width || right < 0 || right >= m_width || + top < 0 || top >= m_height || bottom < 0 || bottom >= m_height) { - void* s_addr = (char*)m_fb + ((y * m_width + left) * m_color_bytes); - void* d_addr = (char*)m_phy_fb + ((y * display_width + left) * m_color_bytes); - memcpy(d_addr, s_addr, (right - left) * m_color_bytes); + ASSERT(false); } + m_display->flush_screen(left, top, right, bottom, m_fb, m_width); *m_phy_write_index = *m_phy_write_index + 1; return 0; } @@ -537,90 +600,62 @@ public: { for (int x = rect.m_left; x <= rect.m_right; x++) { - unsigned int rgb = (m_color_bytes == 4) ? ((unsigned int*)fb)[(x - layer_rect.m_left) + (y - layer_rect.m_top) * width] : GL_RGB_16_to_32(((unsigned short*)fb)[(x - layer_rect.m_left) + (y - layer_rect.m_top) * width]); - draw_pixel_on_fb(x, y, rgb); + unsigned int rgb = (m_color_bytes == 2) ? GL_RGB_16_to_32(((unsigned short*)fb)[(x - layer_rect.m_left) + (y - layer_rect.m_top) * width]) : ((unsigned int*)fb)[(x - layer_rect.m_left) + (y - layer_rect.m_top) * width]; + draw_pixel_low_level(x, y, rgb); } } return 0; } void set_active(bool flag) { m_is_active = flag; } protected: - virtual void fill_rect_on_fb(int x0, int y0, int x1, int y1, unsigned int rgb) - { - int display_width = m_display->get_width(); - int display_height = m_display->get_height(); - if (m_color_bytes == 4) + virtual void fill_rect_low_level(int x0, int y0, int x1, int y1, unsigned int rgb) + {//fill rect on framebuffer of surface + int x, y; + if (m_color_bytes == 2) { - int x; - unsigned int* fb, * phy_fb; - for (; y0 <= y1; y0++) + unsigned short* fb; + unsigned int rgb_16 = GL_RGB_32_to_16(rgb); + for (y = y0; y <= y1; y++) { - x = x0; - fb = m_fb ? &((unsigned int*)m_fb)[y0 * m_width + x] : 0; - phy_fb = &((unsigned int*)m_phy_fb)[y0 * display_width + x]; - *m_phy_write_index = *m_phy_write_index + 1; - for (; x <= x1; x++) + fb = m_fb ? &((unsigned short*)m_fb)[y * m_width + x0] : 0; + if (!fb) { break; } + for (x = x0; x <= x1; x++) { - if (fb) - { - *fb++ = rgb; - } - if (m_is_active && (x < display_width) && (y0 < display_height)) - { - *phy_fb++ = rgb; - } + *fb++ = rgb_16; } } } - else if (m_color_bytes == 2) + else { - int x; - unsigned short* fb, * phy_fb; - rgb = GL_RGB_32_to_16(rgb); - for (; y0 <= y1; y0++) + unsigned int* fb; + for (y = y0; y <= y1; y++) { - x = x0; - fb = m_fb ? &((unsigned short*)m_fb)[y0 * m_width + x] : 0; - phy_fb = &((unsigned short*)m_phy_fb)[y0 * display_width + x]; - *m_phy_write_index = *m_phy_write_index + 1; - for (; x <= x1; x++) + fb = m_fb ? &((unsigned int*)m_fb)[y * m_width + x0] : 0; + if (!fb) { break; } + for (x = x0; x <= x1; x++) { - if (fb) - { - *fb++ = rgb; - } - if (m_is_active && (x < display_width) && (y0 < display_height)) - { - *phy_fb++ = rgb; - } + *fb++ = rgb; } } } + if (!m_is_active) { return; } + m_display->fill_rect(x0, y0, x1, y1, rgb); + *m_phy_write_index = *m_phy_write_index + 1; } - virtual void draw_pixel_on_fb(int x, int y, unsigned int rgb) + virtual void draw_pixel_low_level(int x, int y, unsigned int rgb) { if (m_fb) - { - (m_color_bytes == 4) ? ((unsigned int*)m_fb)[y * m_width + x] = rgb : ((unsigned short*)m_fb)[y * m_width + x] = GL_RGB_32_to_16(rgb); - } - if (m_is_active && (x < m_display->get_width()) && (y < m_display->get_height())) - { - if (m_color_bytes == 4) - { - ((unsigned int*)m_phy_fb)[y * (m_display->get_width()) + x] = rgb; - } - else - { - ((unsigned short*)m_phy_fb)[y * (m_display->get_width()) + x] = GL_RGB_32_to_16(rgb); - } - *m_phy_write_index = *m_phy_write_index + 1; + {//draw pixel on framebuffer of surface + (m_color_bytes == 2) ? ((unsigned short*)m_fb)[y * m_width + x] = GL_RGB_32_to_16(rgb): ((unsigned int*)m_fb)[y * m_width + x] = rgb; } + if (!m_is_active) { return; } + m_display->draw_pixel(x, y, rgb); + *m_phy_write_index = *m_phy_write_index + 1; } void attach_display(c_display* display) { ASSERT(display); m_display = display; - m_phy_fb = display->m_phy_fb; m_phy_write_index = &display->m_phy_write_index; } void set_surface(Z_ORDER_LEVEL max_z_order, c_rect layer_rect) @@ -638,87 +673,22 @@ protected: } int m_width; //in pixels int m_height; //in pixels - int m_color_bytes; //16 bits, 32 bits only + int m_color_bytes; //16 bits, 32 bits for default void* m_fb; //frame buffer you could see c_layer m_layers[Z_ORDER_LEVEL_MAX];//all graphic layers bool m_is_active; //active flag Z_ORDER_LEVEL m_max_zorder; //the highest graphic layer the surface will have Z_ORDER_LEVEL m_top_zorder; //the current highest graphic layer the surface have - void* m_phy_fb; //physical framebufer int* m_phy_write_index; c_display* m_display; }; -class c_surface_no_fb : public c_surface {//No physical framebuffer, render with external graphic interface - friend class c_display; -public: - c_surface_no_fb(unsigned int width, unsigned int height, unsigned int color_bytes, struct EXTERNAL_GFX_OP* gfx_op, Z_ORDER_LEVEL max_zorder = Z_ORDER_LEVEL_0, c_rect overlpa_rect = c_rect()) : c_surface(width, height, color_bytes, max_zorder, overlpa_rect), m_gfx_op(gfx_op) {} -protected: - virtual void fill_rect_on_fb(int x0, int y0, int x1, int y1, unsigned int rgb) - { - if (!m_gfx_op) - { - return; - } - if (m_gfx_op->fill_rect) - { - return m_gfx_op->fill_rect(x0, y0, x1, y1, rgb); - } - if (m_gfx_op->draw_pixel && m_is_active) - { - for (int y = y0; y <= y1; y++) - { - for (int x = x0; x <= x1; x++) - { - m_gfx_op->draw_pixel(x, y, rgb); - } - } - } - if (!m_fb) { return; } - if (m_color_bytes == 4) - { - unsigned int* fb; - for (int y = y0; y <= y1; y++) - { - fb = &((unsigned int*)m_fb)[y0 * m_width + x0]; - for (int x = x0; x <= x1; x++) - { - *fb++ = rgb; - } - } - } - else if (m_color_bytes == 2) - { - unsigned short* fb; - rgb = GL_RGB_32_to_16(rgb); - for (int y = y0; y <= y1; y++) - { - fb = &((unsigned short*)m_fb)[y0 * m_width + x0]; - for (int x = x0; x <= x1; x++) - { - *fb++ = rgb; - } - } - } - } - virtual void draw_pixel_on_fb(int x, int y, unsigned int rgb) - { - if (m_gfx_op && m_gfx_op->draw_pixel && m_is_active) - { - m_gfx_op->draw_pixel(x, y, rgb); - } - if (!m_fb) { return; } - if (m_color_bytes == 4) - { - ((unsigned int*)m_fb)[y * m_width + x] = rgb; - } - else if (m_color_bytes == 2) - { - ((unsigned short*)m_fb)[y * m_width + x] = GL_RGB_32_to_16(rgb); - } - } - struct EXTERNAL_GFX_OP* m_gfx_op;//Rendering by external method -}; -inline c_display::c_display(void* phy_fb, int display_width, int display_height, int surface_width, int surface_height, unsigned int color_bytes, int surface_cnt, EXTERNAL_GFX_OP* gfx_op) : m_width(display_width), m_height(display_height), m_color_bytes(color_bytes), m_phy_fb(phy_fb), m_phy_read_index(0), m_phy_write_index(0), m_surface_cnt(surface_cnt), m_surface_index(0) +inline c_display::c_display(void* phy_fb, int display_width, int display_height, c_surface* surface, DISPLAY_DRIVER* driver) : m_phy_fb(phy_fb), m_width(display_width), m_height(display_height), m_driver(driver), m_phy_read_index(0), m_phy_write_index(0), m_surface_cnt(1), m_surface_index(0) +{ + m_color_bytes = surface->m_color_bytes; + surface->m_is_active = true; + (m_surface_group[0] = surface)->attach_display(this); +} +inline c_display::c_display(void* phy_fb, int display_width, int display_height, int surface_width, int surface_height, unsigned int color_bytes, int surface_cnt, DISPLAY_DRIVER* driver) : m_phy_fb(phy_fb), m_width(display_width), m_height(display_height), m_color_bytes(color_bytes), m_phy_read_index(0), m_phy_write_index(0), m_surface_cnt(surface_cnt), m_driver(driver), m_surface_index(0) { ASSERT(color_bytes == 2 || color_bytes == 4); ASSERT(m_surface_cnt <= SURFACE_CNT_MAX); @@ -726,16 +696,10 @@ inline c_display::c_display(void* phy_fb, int display_width, int display_height, for (int i = 0; i < m_surface_cnt; i++) { - m_surface_group[i] = (phy_fb) ? new c_surface(surface_width, surface_height, color_bytes) : new c_surface_no_fb(surface_width, surface_height, color_bytes, gfx_op); + m_surface_group[i] = new c_surface(surface_width, surface_height, color_bytes); m_surface_group[i]->attach_display(this); } } -inline c_display::c_display(void* phy_fb, int display_width, int display_height, c_surface* surface) : m_width(display_width), m_height(display_height), m_phy_fb(phy_fb), m_phy_read_index(0), m_phy_write_index(0), m_surface_cnt(1), m_surface_index(0) -{ - m_color_bytes = surface->m_color_bytes; - surface->m_is_active = true; - (m_surface_group[0] = surface)->attach_display(this); -} inline c_surface* c_display::alloc_surface(Z_ORDER_LEVEL max_zorder, c_rect layer_rect) { ASSERT(max_zorder < Z_ORDER_LEVEL_MAX && m_surface_index < m_surface_cnt); @@ -744,8 +708,8 @@ inline c_surface* c_display::alloc_surface(Z_ORDER_LEVEL max_zorder, c_rect laye } inline int c_display::swipe_surface(c_surface* s0, c_surface* s1, int x0, int x1, int y0, int y1, int offset) { - int surface_width = s0->get_width(); - int surface_height = s0->get_height(); + register int surface_width = s0->m_width; + register int surface_height = s0->m_height; if (offset < 0 || offset > surface_width || y0 < 0 || y0 >= surface_height || y1 < 0 || y1 >= surface_height || x0 < 0 || x0 >= surface_width || x1 < 0 || x1 >= surface_width) { @@ -767,46 +731,46 @@ inline int c_display::swipe_surface(c_surface* s0, c_surface* s1, int x0, int x1 for (int y = y0; y <= y1; y++) { //Left surface - char* addr_s = ((char*)(s0->m_fb) + (y * (s0->get_width()) + x0 + offset) * m_color_bytes); + char* addr_s = ((char*)(s0->m_fb) + (y * surface_width + x0 + offset) * m_color_bytes); char* addr_d = ((char*)(m_phy_fb)+(y * m_width + x0) * m_color_bytes); memcpy(addr_d, addr_s, (width - offset) * m_color_bytes); //Right surface - addr_s = ((char*)(s1->m_fb) + (y * (s1->get_width()) + x0) * m_color_bytes); + addr_s = ((char*)(s1->m_fb) + (y * surface_width + x0) * m_color_bytes); addr_d = ((char*)(m_phy_fb)+(y * m_width + x0 + (width - offset)) * m_color_bytes); memcpy(addr_d, addr_s, offset * m_color_bytes); } } - else if (m_color_bytes == 4) + else if (m_color_bytes == 2) { - void(*draw_pixel)(int x, int y, unsigned int rgb) = ((c_surface_no_fb*)s0)->m_gfx_op->draw_pixel; + void(*draw_pixel)(int x, int y, unsigned int rgb) = m_driver->draw_pixel; for (int y = y0; y <= y1; y++) { //Left surface for (int x = x0; x <= (x1 - offset); x++) { - draw_pixel(x, y, ((unsigned int*)s0->m_fb)[y * m_width + x + offset]); + draw_pixel(x, y, GL_RGB_16_to_32(((unsigned short*)s0->m_fb)[y * m_width + x + offset])); } //Right surface for (int x = x1 - offset; x <= x1; x++) { - draw_pixel(x, y, ((unsigned int*)s1->m_fb)[y * m_width + x + offset - x1 + x0]); + draw_pixel(x, y, GL_RGB_16_to_32(((unsigned short*)s1->m_fb)[y * m_width + x + offset - x1 + x0])); } } } - else if (m_color_bytes == 2) + else //m_color_bytes == 3/4... { - void(*draw_pixel)(int x, int y, unsigned int rgb) = ((c_surface_no_fb*)s0)->m_gfx_op->draw_pixel; + void(*draw_pixel)(int x, int y, unsigned int rgb) = m_driver->draw_pixel; for (int y = y0; y <= y1; y++) { //Left surface for (int x = x0; x <= (x1 - offset); x++) { - draw_pixel(x, y, GL_RGB_16_to_32(((unsigned short*)s0->m_fb)[y * m_width + x + offset])); + draw_pixel(x, y, ((unsigned int*)s0->m_fb)[y * m_width + x + offset]); } //Right surface for (int x = x1 - offset; x <= x1; x++) { - draw_pixel(x, y, GL_RGB_16_to_32(((unsigned short*)s1->m_fb)[y * m_width + x + offset - x1 + x0])); + draw_pixel(x, y, ((unsigned int*)s1->m_fb)[y * m_width + x + offset - x1 + x0]); } } } @@ -3407,22 +3371,12 @@ private: #ifdef GUILITE_ON c_bitmap_operator the_bitmap_op = c_bitmap_operator(); c_image_operator* c_image::image_operator = &the_bitmap_op; +const void* c_theme::s_font_map[FONT_MAX]; +const void* c_theme::s_image_map[IMAGE_MAX]; +unsigned int c_theme::s_color_map[COLOR_MAX]; +c_lattice_font_op the_lattice_font_op = c_lattice_font_op(); +c_font_operator* c_word::fontOperator = &the_lattice_font_op; #endif - -#ifdef GUILITE_ON - -const void* c_theme::s_font_map[FONT_MAX]; -const void* c_theme::s_image_map[IMAGE_MAX]; -unsigned int c_theme::s_color_map[COLOR_MAX]; - -#endif - -#ifdef GUILITE_ON - -c_lattice_font_op the_lattice_font_op = c_lattice_font_op(); -c_font_operator* c_word::fontOperator = &the_lattice_font_op; - -#endif #ifdef GUILITE_ON #if (defined __linux__) || (defined __APPLE__) #include @@ -4264,11 +4218,7 @@ int c_fifo::write(void* buf, int len) #endif #ifdef GUILITE_ON DIALOG_ARRAY c_dialog::ms_the_dialogs[SURFACE_CNT_MAX]; -#endif -#ifdef GUILITE_ON c_keyboard c_edit::s_keyboard; -#endif -#ifdef GUILITE_ON static c_keyboard_button s_key_0, s_key_1, s_key_2, s_key_3, s_key_4, s_key_5, s_key_6, s_key_7, s_key_8, s_key_9; static c_keyboard_button s_key_A, s_key_B, s_key_C, s_key_D, s_key_E, s_key_F, s_key_G, s_key_H, s_key_I, s_key_J; static c_keyboard_button s_key_K, s_key_L, s_key_M, s_key_N, s_key_O, s_key_P, s_key_Q, s_key_R, s_key_S, s_key_T; @@ -4306,12 +4256,12 @@ WND_TREE g_key_board_children[] = {&s_key_B, 'B', 0, ((KEY_WIDTH / 2) + POS_X(5)), POS_Y(2), KEY_WIDTH, KEY_HEIGHT}, {&s_key_N, 'N', 0, ((KEY_WIDTH / 2) + POS_X(6)), POS_Y(2), KEY_WIDTH, KEY_HEIGHT}, {&s_key_M, 'M', 0, ((KEY_WIDTH / 2) + POS_X(7)), POS_Y(2), KEY_WIDTH, KEY_HEIGHT}, - {&s_key_del, 0x7F, 0, ((KEY_WIDTH / 2) + POS_X(8)), POS_Y(2), DEL_WIDTH, KEY_HEIGHT}, + {&s_key_del,0x7F, 0, ((KEY_WIDTH / 2) + POS_X(8)), POS_Y(2), DEL_WIDTH, KEY_HEIGHT}, //Row 4 - {&s_key_esc, 0x1B, 0, POS_X(0), POS_Y(3), ESC_WIDTH, KEY_HEIGHT}, + {&s_key_esc, 0x1B, 0, POS_X(0), POS_Y(3), ESC_WIDTH, KEY_HEIGHT}, {&s_key_num_switch, 0x90, 0, POS_X(2), POS_Y(3), SWITCH_WIDTH, KEY_HEIGHT}, {&s_key_space, ' ', 0, ((KEY_WIDTH / 2) + POS_X(3)), POS_Y(3), SPACE_WIDTH, KEY_HEIGHT}, - {&s_key_dot, '.', 0, ((KEY_WIDTH / 2) + POS_X(6)), POS_Y(3), DOT_WIDTH, KEY_HEIGHT}, + {&s_key_dot, '.', 0, ((KEY_WIDTH / 2) + POS_X(6)), POS_Y(3), DOT_WIDTH, KEY_HEIGHT}, {&s_key_enter, '\n', 0, POS_X(8), POS_Y(3), ENTER_WIDTH, KEY_HEIGHT}, {0,0,0,0,0,0,0} }; @@ -4326,12 +4276,11 @@ WND_TREE g_number_board_children[] = {&s_key_7, '7', 0, POS_X(0), POS_Y(2), KEY_WIDTH, KEY_HEIGHT}, {&s_key_8, '8', 0, POS_X(1), POS_Y(2), KEY_WIDTH, KEY_HEIGHT}, {&s_key_9, '9', 0, POS_X(2), POS_Y(2), KEY_WIDTH, KEY_HEIGHT}, - - {&s_key_esc, 0x1B, 0, POS_X(0), POS_Y(3), KEY_WIDTH, KEY_HEIGHT}, + {&s_key_esc,0x1B, 0, POS_X(0), POS_Y(3), KEY_WIDTH, KEY_HEIGHT}, {&s_key_0, '0', 0, POS_X(1), POS_Y(3), KEY_WIDTH, KEY_HEIGHT}, - {&s_key_dot, '.', 0, POS_X(2), POS_Y(3), KEY_WIDTH, KEY_HEIGHT}, + {&s_key_dot,'.', 0, POS_X(2), POS_Y(3), KEY_WIDTH, KEY_HEIGHT}, {&s_key_del, 0x7F, 0, POS_X(3), POS_Y(0), KEY_WIDTH, KEY_HEIGHT * 2 + 2}, {&s_key_enter,'\n', 0, POS_X(3), POS_Y(2), KEY_WIDTH, KEY_HEIGHT * 2 + 2}, {0,0,0,0,0,0,0} }; -#endif +#endif \ No newline at end of file diff --git a/HelloMario/UIcode/UIcode.cpp b/HelloMario/UIcode/UIcode.cpp index ef5984cb662386bc9b2467c5ad423a2a63342628..0c8b9165c835b963acbd29b37e92ba4bc5fbb8bd 100644 --- a/HelloMario/UIcode/UIcode.cpp +++ b/HelloMario/UIcode/UIcode.cpp @@ -103,21 +103,11 @@ public: //////////////////////// start UI //////////////////////// c_mario the_mario; -void create_ui(void* phy_fb, int screen_width, int screen_height, int color_bytes, struct EXTERNAL_GFX_OP* gfx_op) { - if (phy_fb) - { - static c_surface surface(UI_WIDTH, UI_HEIGHT, color_bytes, Z_ORDER_LEVEL_1, c_rect(0, UI_HEIGHT - background_bmp.height, UI_WIDTH, background_bmp.height)); - static c_display display(phy_fb, screen_width, screen_height, &surface); - s_surface = &surface; - s_display = &display; - } - else - {//for MCU without framebuffer - static c_surface_no_fb surface_no_fb(UI_WIDTH, UI_HEIGHT, color_bytes, gfx_op, Z_ORDER_LEVEL_1, c_rect(0, UI_HEIGHT - background_bmp.height, UI_WIDTH, background_bmp.height)); - static c_display display(phy_fb, screen_width, screen_height, &surface_no_fb); - s_surface = &surface_no_fb; - s_display = &display; - } +void create_ui(void* phy_fb, int screen_width, int screen_height, int color_bytes, struct DISPLAY_DRIVER* driver) { + static c_surface surface(UI_WIDTH, UI_HEIGHT, color_bytes, Z_ORDER_LEVEL_1, c_rect(0, UI_HEIGHT - background_bmp.height, UI_WIDTH, background_bmp.height)); + static c_display display(phy_fb, screen_width, screen_height, &surface, driver); + s_surface = &surface; + s_display = &display; s_surface->fill_rect(0, 0, UI_WIDTH - 1, UI_HEIGHT - 1, GL_RGB(131, 110, 83), Z_ORDER_LEVEL_0); c_image::draw_image(s_surface, Z_ORDER_LEVEL_0, &title_bmp, 30, 20); @@ -132,8 +122,8 @@ void create_ui(void* phy_fb, int screen_width, int screen_height, int color_byte } //////////////////////// interface for all platform //////////////////////// -extern "C" void startHelloMario(void* phy_fb, int width, int height, int color_bytes, struct EXTERNAL_GFX_OP* gfx_op) { - create_ui(phy_fb, width, height, color_bytes, gfx_op); +extern "C" void startHelloMario(void* phy_fb, int width, int height, int color_bytes, struct DISPLAY_DRIVER* driver) { + create_ui(phy_fb, width, height, color_bytes, driver); } extern "C" void* getUiOfHelloMario(int* width, int* height, bool force_update) diff --git a/HelloMolecule/BuildLinux/.sync_build.sh b/HelloMolecule/BuildLinux/.sync_build.sh index 49cff5b473ac606967676ebefa6f0d333e301227..154fab7b825e2c0e73c62e02b3b59be2ba51b15b 100644 --- a/HelloMolecule/BuildLinux/.sync_build.sh +++ b/HelloMolecule/BuildLinux/.sync_build.sh @@ -1,5 +1,6 @@ if [ "$#" -ne 1 ]; then - echo "Invalid arguments" + echo "Do testing" + ./xWindow 240 320 | ./HelloMolecule shared-fb exit -1 fi diff --git a/HelloMolecule/BuildLinux/main.cpp b/HelloMolecule/BuildLinux/main.cpp index ccf68d70d46aaa72bc670ae756cd6a7585345c87..77cb65a252413ff7ae7452237e1116a73985648e 100644 --- a/HelloMolecule/BuildLinux/main.cpp +++ b/HelloMolecule/BuildLinux/main.cpp @@ -10,7 +10,7 @@ #include #include -extern "C" void startHelloMolecule(void* phy_fb, int width, int height, int color_bytes, struct EXTERNAL_GFX_OP* gfx_op); +extern "C" void startHelloMolecule(void* phy_fb, int width, int height, int color_bytes, struct DISPLAY_DRIVER* driver); extern void init_std_io(); static void* get_embeded_fb_in_display_app(int shared_id); diff --git a/HelloMolecule/BuildMFC/HelloMoleculeDlg.cpp b/HelloMolecule/BuildMFC/HelloMoleculeDlg.cpp index edb057ded70279eb0cf61e900b77fbbec342b15c..e99706933319824e72a81b4f768416cd454dd3ad 100644 Binary files a/HelloMolecule/BuildMFC/HelloMoleculeDlg.cpp and b/HelloMolecule/BuildMFC/HelloMoleculeDlg.cpp differ diff --git a/HelloMolecule/BuildMFC/HelloMoleculeDlg.h b/HelloMolecule/BuildMFC/HelloMoleculeDlg.h index 2bad179f9d166220fc4fddff595ef1b68a1f3388..81a53be40efe2d787bef043533bd005734a76ed9 100644 Binary files a/HelloMolecule/BuildMFC/HelloMoleculeDlg.h and b/HelloMolecule/BuildMFC/HelloMoleculeDlg.h differ diff --git a/HelloMolecule/BuildSTM32F103-Keil/USER/main.c b/HelloMolecule/BuildSTM32F103-Keil/USER/main.c index 5e09e17cd597040306dfc3ca1084aa6175d43b6c..a266f0e92775c78f5513f10d70944ef7045db027 100644 --- a/HelloMolecule/BuildSTM32F103-Keil/USER/main.c +++ b/HelloMolecule/BuildSTM32F103-Keil/USER/main.c @@ -15,12 +15,12 @@ void gfx_draw_pixel(int x, int y, unsigned int rgb) //void gfx_fill_rect(int x0, int y0, int x1, int y1, unsigned int rgb){} //UI entry -struct EXTERNAL_GFX_OP +struct DISPLAY_DRIVER { void (*draw_pixel)(int x, int y, unsigned int rgb); void (*fill_rect)(int x0, int y0, int x1, int y1, unsigned int rgb); -} my_gfx_op; -extern void startHelloMolecule(void* phy_fb, int width, int height, int color_bytes, struct EXTERNAL_GFX_OP* gfx_op); +} my_driver; +extern void startHelloMolecule(void* phy_fb, int width, int height, int color_bytes, struct DISPLAY_DRIVER* driver); int main(void) { @@ -30,8 +30,8 @@ int main(void) LCD_Init(); //Link your LCD driver & start UI: - my_gfx_op.draw_pixel = gfx_draw_pixel; - my_gfx_op.fill_rect = NULL;//gfx_fill_rect; - startHelloMolecule(NULL, 240, 320, 2, &my_gfx_op); + my_driver.draw_pixel = gfx_draw_pixel; + my_driver.fill_rect = NULL;//gfx_fill_rect; + startHelloMolecule(NULL, 240, 320, 2, &my_driver); while(1); } diff --git a/HelloMolecule/BuildWin32/HelloMolecule.cpp b/HelloMolecule/BuildWin32/HelloMolecule.cpp index 2a64d24348860a448f4b36f233a41c28d18db0a7..e532f9d86e87e8ca525cf54efb4557fb3c5557fb 100644 --- a/HelloMolecule/BuildWin32/HelloMolecule.cpp +++ b/HelloMolecule/BuildWin32/HelloMolecule.cpp @@ -161,7 +161,7 @@ LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam) } //////////////////////// HelloMolecule Interface //////////////////////// -extern "C" void startHelloMolecule(void* phy_fb, int width, int height, int color_bytes, struct EXTERNAL_GFX_OP* gfx_op); +extern "C" void startHelloMolecule(void* phy_fb, int width, int height, int color_bytes, struct DISPLAY_DRIVER* driver); DWORD WINAPI ThreadHelloMolecule(LPVOID pParam) { diff --git a/HelloMolecule/UIcode/GuiLite.h b/HelloMolecule/UIcode/GuiLite.h index c4fc88a51476d2c8309c3e55e1270e13784fc510..80550e1632ad7bc82541a2edbb0f7f8f5937954f 100644 --- a/HelloMolecule/UIcode/GuiLite.h +++ b/HelloMolecule/UIcode/GuiLite.h @@ -1,107 +1,94 @@ #pragma once - -#define REAL_TIME_TASK_CYCLE_MS 50 -#define MAX(a,b) (((a)>(b))?(a):(b)) -#define MIN(a,b) (((a)<(b))?(a):(b)) - -#define GL_ARGB(a, r, g, b) ((((unsigned int)(a)) << 24) | (((unsigned int)(r)) << 16) | (((unsigned int)(g)) << 8) | ((unsigned int)(b))) -#define GL_ARGB_A(rgb) ((((unsigned int)(rgb)) >> 24) & 0xFF) - -#define GL_RGB(r, g, b) ((0xFF << 24) | (((unsigned int)(r)) << 16) | (((unsigned int)(g)) << 8) | ((unsigned int)(b))) -#define GL_RGB_R(rgb) ((((unsigned int)(rgb)) >> 16) & 0xFF) -#define GL_RGB_G(rgb) ((((unsigned int)(rgb)) >> 8) & 0xFF) -#define GL_RGB_B(rgb) (((unsigned int)(rgb)) & 0xFF) -#define GL_RGB_32_to_16(rgb) (((((unsigned int)(rgb)) & 0xFF) >> 3) | ((((unsigned int)(rgb)) & 0xFC00) >> 5) | ((((unsigned int)(rgb)) & 0xF80000) >> 8)) -#define GL_RGB_16_to_32(rgb) ((0xFF << 24) | ((((unsigned int)(rgb)) & 0x1F) << 3) | ((((unsigned int)(rgb)) & 0x7E0) << 5) | ((((unsigned int)(rgb)) & 0xF800) << 8)) - -#define ALIGN_HCENTER 0x00000000L -#define ALIGN_LEFT 0x01000000L -#define ALIGN_RIGHT 0x02000000L -#define ALIGN_HMASK 0x03000000L - -#define ALIGN_VCENTER 0x00000000L -#define ALIGN_TOP 0x00100000L -#define ALIGN_BOTTOM 0x00200000L -#define ALIGN_VMASK 0x00300000L - -typedef struct -{ - unsigned short year; - unsigned short month; - unsigned short date; - unsigned short day; - unsigned short hour; - unsigned short minute; - unsigned short second; -}T_TIME; - -void register_debug_function(void(*my_assert)(const char* file, int line), void(*my_log_out)(const char* log)); -void _assert(const char* file, int line); -#define ASSERT(condition) \ - do{ \ - if(!(condition))_assert(__FILE__, __LINE__);\ - }while(0) -void log_out(const char* log); - -long get_time_in_second(); -T_TIME second_to_day(long second); -T_TIME get_time(); - -void start_real_timer(void (*func)(void* arg)); -void register_timer(int milli_second, void func(void* param), void* param); - -unsigned int get_cur_thread_id(); -void create_thread(unsigned long* thread_id, void* attr, void *(*start_routine) (void *), void* arg); -void thread_sleep(unsigned int milli_seconds); -int build_bmp(const char *filename, unsigned int width, unsigned int height, unsigned char *data); - -#define FIFO_BUFFER_LEN 1024 -class c_fifo -{ -public: - c_fifo(); - int read(void* buf, int len); - int write(void* buf, int len); -private: - unsigned char m_buf[FIFO_BUFFER_LEN]; - int m_head; - int m_tail; - void* m_read_sem; - void* m_write_mutex; -}; - -class c_rect -{ -public: - c_rect(){ m_left = m_top = m_right = m_bottom = -1; } - c_rect(int left, int top, int width, int height) - { - set_rect(left, top, width, height); - } - void set_rect(int left, int top, int width, int height) - { - ASSERT(width > 0 && height > 0); - m_left = left; - m_top = top; - m_right = left + width - 1; - m_bottom = top + height -1; - } - bool pt_in_rect(int x, int y) const - { - return x >= m_left && x <= m_right && y >= m_top && y <= m_bottom; - } - int operator==(const c_rect& rect) const - { - return (m_left == rect.m_left) && (m_top == rect.m_top) && (m_right == rect.m_right) && (m_bottom == rect.m_bottom); - } - int width() const { return m_right - m_left + 1; } - int height() const { return m_bottom - m_top + 1 ; } - - int m_left; - int m_top; - int m_right; - int m_bottom; -}; +#define REAL_TIME_TASK_CYCLE_MS 50 +#define MAX(a,b) (((a)>(b))?(a):(b)) +#define MIN(a,b) (((a)<(b))?(a):(b)) +#define GL_ARGB(a, r, g, b) ((((unsigned int)(a)) << 24) | (((unsigned int)(r)) << 16) | (((unsigned int)(g)) << 8) | ((unsigned int)(b))) +#define GL_ARGB_A(rgb) ((((unsigned int)(rgb)) >> 24) & 0xFF) +#define GL_RGB(r, g, b) ((0xFF << 24) | (((unsigned int)(r)) << 16) | (((unsigned int)(g)) << 8) | ((unsigned int)(b))) +#define GL_RGB_R(rgb) ((((unsigned int)(rgb)) >> 16) & 0xFF) +#define GL_RGB_G(rgb) ((((unsigned int)(rgb)) >> 8) & 0xFF) +#define GL_RGB_B(rgb) (((unsigned int)(rgb)) & 0xFF) +#define GL_RGB_32_to_16(rgb) (((((unsigned int)(rgb)) & 0xFF) >> 3) | ((((unsigned int)(rgb)) & 0xFC00) >> 5) | ((((unsigned int)(rgb)) & 0xF80000) >> 8)) +#define GL_RGB_16_to_32(rgb) ((0xFF << 24) | ((((unsigned int)(rgb)) & 0x1F) << 3) | ((((unsigned int)(rgb)) & 0x7E0) << 5) | ((((unsigned int)(rgb)) & 0xF800) << 8)) +#define ALIGN_HCENTER 0x00000000L +#define ALIGN_LEFT 0x01000000L +#define ALIGN_RIGHT 0x02000000L +#define ALIGN_HMASK 0x03000000L +#define ALIGN_VCENTER 0x00000000L +#define ALIGN_TOP 0x00100000L +#define ALIGN_BOTTOM 0x00200000L +#define ALIGN_VMASK 0x00300000L +typedef struct +{ + unsigned short year; + unsigned short month; + unsigned short date; + unsigned short day; + unsigned short hour; + unsigned short minute; + unsigned short second; +}T_TIME; +void register_debug_function(void(*my_assert)(const char* file, int line), void(*my_log_out)(const char* log)); +void _assert(const char* file, int line); +#define ASSERT(condition) \ + do{ \ + if(!(condition))_assert(__FILE__, __LINE__);\ + }while(0) +void log_out(const char* log); +long get_time_in_second(); +T_TIME second_to_day(long second); +T_TIME get_time(); +void start_real_timer(void (*func)(void* arg)); +void register_timer(int milli_second, void func(void* param), void* param); +unsigned int get_cur_thread_id(); +void create_thread(unsigned long* thread_id, void* attr, void *(*start_routine) (void *), void* arg); +void thread_sleep(unsigned int milli_seconds); +int build_bmp(const char *filename, unsigned int width, unsigned int height, unsigned char *data); +#define FIFO_BUFFER_LEN 1024 +class c_fifo +{ +public: + c_fifo(); + int read(void* buf, int len); + int write(void* buf, int len); +private: + unsigned char m_buf[FIFO_BUFFER_LEN]; + int m_head; + int m_tail; + void* m_read_sem; + void* m_write_mutex; +}; +class c_rect +{ +public: + c_rect(){ m_left = m_top = m_right = m_bottom = -1; } + c_rect(int left, int top, int width, int height) + { + set_rect(left, top, width, height); + } + void set_rect(int left, int top, int width, int height) + { + ASSERT(width > 0 && height > 0); + m_left = left; + m_top = top; + m_right = left + width - 1; + m_bottom = top + height -1; + } + bool pt_in_rect(int x, int y) const + { + return x >= m_left && x <= m_right && y >= m_top && y <= m_bottom; + } + int operator==(const c_rect& rect) const + { + return (m_left == rect.m_left) && (m_top == rect.m_top) && (m_right == rect.m_right) && (m_bottom == rect.m_bottom); + } + int width() const { return m_right - m_left + 1; } + int height() const { return m_bottom - m_top + 1 ; } + int m_left; + int m_top; + int m_right; + int m_bottom; +}; //BITMAP typedef struct struct_bitmap_info { @@ -238,7 +225,7 @@ typedef enum Z_ORDER_LEVEL_2,//highest graphic level Z_ORDER_LEVEL_MAX }Z_ORDER_LEVEL; -struct EXTERNAL_GFX_OP +struct DISPLAY_DRIVER { void(*draw_pixel)(int x, int y, unsigned int rgb); void(*fill_rect)(int x0, int y0, int x1, int y1, unsigned int rgb); @@ -247,18 +234,19 @@ class c_surface; class c_display { friend class c_surface; public: - inline c_display(void* phy_fb, int display_width, int display_height, int surface_width, int surface_height, unsigned int color_bytes, int surface_cnt, EXTERNAL_GFX_OP* gfx_op = 0);//multiple surface or surface_no_fb - inline c_display(void* phy_fb, int display_width, int display_height, c_surface* surface);//single custom surface - inline c_surface* alloc_surface(Z_ORDER_LEVEL max_zorder, c_rect layer_rect = c_rect());//for multiple surfaces + inline c_display(void* phy_fb, int display_width, int display_height, c_surface* surface, DISPLAY_DRIVER* driver = 0);//single custom surface + inline c_display(void* phy_fb, int display_width, int display_height, int surface_width, int surface_height, unsigned int color_bytes, int surface_cnt, DISPLAY_DRIVER* driver = 0);//multiple surface + inline c_surface* alloc_surface(Z_ORDER_LEVEL max_zorder, c_rect layer_rect = c_rect());//for slide group inline int swipe_surface(c_surface* s0, c_surface* s1, int x0, int x1, int y0, int y1, int offset); int get_width() { return m_width; } int get_height() { return m_height; } + void* get_phy_fb() { return m_phy_fb; } void* get_updated_fb(int* width, int* height, bool force_update = false) { if (width && height) { - *width = get_width(); - *height = get_height(); + *width = m_width; + *height = m_height; } if (force_update) { @@ -277,35 +265,123 @@ public: { return -1; } - int width = get_width(); - int height = get_height(); //16 bits framebuffer if (m_color_bytes == 2) { - return build_bmp(file_name, width, height, (unsigned char*)m_phy_fb); + return build_bmp(file_name, m_width, m_height, (unsigned char*)m_phy_fb); } //32 bits framebuffer - unsigned short* p_bmp565_data = new unsigned short[width * height]; + unsigned short* p_bmp565_data = new unsigned short[m_width * m_height]; unsigned int* p_raw_data = (unsigned int*)m_phy_fb; - for (int i = 0; i < width * height; i++) + for (int i = 0; i < m_width * m_height; i++) { unsigned int rgb = *p_raw_data++; p_bmp565_data[i] = GL_RGB_32_to_16(rgb); } - int ret = build_bmp(file_name, width, height, (unsigned char*)p_bmp565_data); + int ret = build_bmp(file_name, m_width, m_height, (unsigned char*)p_bmp565_data); delete[]p_bmp565_data; return ret; } -private: - int m_width; //in pixels - int m_height; //in pixels - int m_color_bytes; //16 bits, 32 bits only - void* m_phy_fb; //physical framebuffer +protected: + virtual void draw_pixel(int x, int y, unsigned int rgb) + { + if ((x >= m_width) || (y >= m_height)) { return; } + if (m_driver && m_driver->draw_pixel) + { + return m_driver->draw_pixel(x, y, rgb); + } + if (m_color_bytes == 2) + { + ((unsigned short*)m_phy_fb)[y * m_width + x] = GL_RGB_32_to_16(rgb); + } + else + { + ((unsigned int*)m_phy_fb)[y * m_width + x] = rgb; + } + } + virtual void fill_rect(int x0, int y0, int x1, int y1, unsigned int rgb) + { + if (m_driver && m_driver->fill_rect) + { + return m_driver->fill_rect(x0, y0, x1, y1, rgb); + } + if (m_driver && m_driver->draw_pixel) + { + for (int y = y0; y <= y1; y++) + { + for (int x = x0; x <= x1; x++) + { + m_driver->draw_pixel(x, y, rgb); + } + } + return; + } + register int _width = m_width; + register int _height = m_height; + int x, y; + if (m_color_bytes == 2) + { + unsigned short* phy_fb; + unsigned int rgb_16 = GL_RGB_32_to_16(rgb); + for (y = y0; y <= y1; y++) + { + phy_fb = &((unsigned short*)m_phy_fb)[y * _width + x0]; + for (x = x0; x <= x1; x++) + { + if ((x < _width) && (y < _height)) + { + *phy_fb++ = rgb_16; + } + } + } + } + else + { + unsigned int* phy_fb; + for (y = y0; y <= y1; y++) + { + phy_fb = &((unsigned int*)m_phy_fb)[y * _width + x0]; + for (x = x0; x <= x1; x++) + { + if ((x < _width) && (y < _height)) + { + *phy_fb++ = rgb; + } + } + } + } + } + virtual int flush_screen(int left, int top, int right, int bottom, void* fb, int fb_width) + { + if ((0 == m_phy_fb) || (0 == fb)) + { + return -1; + } + register int _width = m_width; + register int _height = m_height; + left = (left >= _width) ? (_width - 1) : left; + right = (right >= _width) ? (_width - 1) : right; + top = (top >= _height) ? (_height - 1) : top; + bottom = (bottom >= _height) ? (_height - 1) : bottom; + for (int y = top; y < bottom; y++) + { + void* s_addr = (char*)fb + ((y * fb_width + left) * m_color_bytes); + void* d_addr = (char*)m_phy_fb + ((y * _width + left) * m_color_bytes); + memcpy(d_addr, s_addr, (right - left) * m_color_bytes); + } + return 0; + } + int m_width; //in pixels + int m_height; //in pixels + int m_color_bytes; //16/32 bits for default + void* m_phy_fb; //physical framebuffer for default + struct DISPLAY_DRIVER* m_driver; //Rendering by external method without default physical framebuffer int m_phy_read_index; int m_phy_write_index; c_surface* m_surface_group[SURFACE_CNT_MAX]; int m_surface_cnt; //surface count int m_surface_index; + }; class c_layer { @@ -317,12 +393,10 @@ public: class c_surface { friend class c_display; friend class c_bitmap_operator; public: - c_surface(unsigned int width, unsigned int height, unsigned int color_bytes, Z_ORDER_LEVEL max_zorder = Z_ORDER_LEVEL_0, c_rect overlpa_rect = c_rect()) : m_width(width), m_height(height), m_color_bytes(color_bytes), m_fb(0), m_is_active(false), m_top_zorder(Z_ORDER_LEVEL_0), m_phy_fb(0), m_phy_write_index(0), m_display(0) + c_surface(unsigned int width, unsigned int height, unsigned int color_bytes, Z_ORDER_LEVEL max_zorder = Z_ORDER_LEVEL_0, c_rect overlpa_rect = c_rect()) : m_width(width), m_height(height), m_color_bytes(color_bytes), m_fb(0), m_is_active(false), m_top_zorder(Z_ORDER_LEVEL_0), m_phy_write_index(0), m_display(0) { (overlpa_rect == c_rect()) ? set_surface(max_zorder, c_rect(0, 0, width - 1, height - 1)) : set_surface(max_zorder, overlpa_rect); } - int get_width() { return m_width; } - int get_height() { return m_height; } unsigned int get_pixel(int x, int y, unsigned int z_order) { if (x >= m_width || y >= m_height || x < 0 || y < 0 || z_order >= Z_ORDER_LEVEL_MAX) @@ -332,15 +406,15 @@ public: } if (m_layers[z_order].fb) { - return (m_color_bytes == 4) ? ((unsigned int*)(m_layers[z_order].fb))[y * m_width + x] : GL_RGB_16_to_32(((unsigned short*)(m_layers[z_order].fb))[y * m_width + x]); + return (m_color_bytes == 2) ? GL_RGB_16_to_32(((unsigned short*)(m_layers[z_order].fb))[y * m_width + x]) : ((unsigned int*)(m_layers[z_order].fb))[y * m_width + x]; } else if (m_fb) { - return (m_color_bytes == 4) ? ((unsigned int*)m_fb)[y * m_width + x] : GL_RGB_16_to_32(((unsigned short*)m_fb)[y * m_width + x]); + return (m_color_bytes == 2) ? GL_RGB_16_to_32(((unsigned short*)m_fb)[y * m_width + x]) : ((unsigned int*)m_fb)[y * m_width + x]; } - else if (m_phy_fb) + else if (m_display->m_phy_fb) { - return (m_color_bytes == 4) ? ((unsigned int*)m_phy_fb)[y * m_width + x] : GL_RGB_16_to_32(((unsigned short*)m_phy_fb)[y * m_width + x]); + return (m_color_bytes == 2) ? GL_RGB_16_to_32(((unsigned short*)m_display->m_phy_fb)[y * m_width + x]) : ((unsigned int*)m_display->m_phy_fb)[y * m_width + x]; } return 0; } @@ -357,7 +431,7 @@ public: } if (z_order == m_max_zorder) { - return draw_pixel_on_fb(x, y, rgb); + return draw_pixel_low_level(x, y, rgb); } if (z_order > (unsigned int)m_top_zorder) @@ -367,19 +441,19 @@ public: if (m_layers[z_order].rect.pt_in_rect(x, y)) { c_rect layer_rect = m_layers[z_order].rect; - if (m_color_bytes == 4) + if (m_color_bytes == 2) { - ((unsigned int*)(m_layers[z_order].fb))[(x - layer_rect.m_left) + (y - layer_rect.m_top) * layer_rect.width()] = rgb; + ((unsigned short*)(m_layers[z_order].fb))[(x - layer_rect.m_left) + (y - layer_rect.m_top) * layer_rect.width()] = GL_RGB_32_to_16(rgb); } else { - ((unsigned short*)(m_layers[z_order].fb))[(x - layer_rect.m_left) + (y - layer_rect.m_top) * layer_rect.width()] = GL_RGB_32_to_16(rgb); + ((unsigned int*)(m_layers[z_order].fb))[(x - layer_rect.m_left) + (y - layer_rect.m_top) * layer_rect.width()] = rgb; } } if (z_order == m_top_zorder) { - return draw_pixel_on_fb(x, y, rgb); + return draw_pixel_low_level(x, y, rgb); } bool be_overlapped = false; for (unsigned int tmp_z_order = Z_ORDER_LEVEL_MAX - 1; tmp_z_order > z_order; tmp_z_order--) @@ -392,7 +466,7 @@ public: } if (!be_overlapped) { - draw_pixel_on_fb(x, y, rgb); + draw_pixel_low_level(x, y, rgb); } } virtual void fill_rect(int x0, int y0, int x1, int y1, unsigned int rgb, unsigned int z_order) @@ -403,7 +477,7 @@ public: y1 = (y1 > (m_height - 1)) ? (m_height - 1) : y1; if (z_order == m_max_zorder) { - return fill_rect_on_fb(x0, y0, x1, y1, rgb); + return fill_rect_low_level(x0, y0, x1, y1, rgb); } if (z_order == m_top_zorder) { @@ -416,18 +490,18 @@ public: { if (layer_rect.pt_in_rect(x, y)) { - if (m_color_bytes == 4) + if (m_color_bytes == 2) { - ((unsigned int*)m_layers[z_order].fb)[(y - layer_rect.m_top) * layer_rect.width() + (x - layer_rect.m_left)] = rgb; + ((unsigned short*)m_layers[z_order].fb)[(y - layer_rect.m_top) * layer_rect.width() + (x - layer_rect.m_left)] = rgb_16; } else { - ((unsigned short*)m_layers[z_order].fb)[(y - layer_rect.m_top) * layer_rect.width() + (x - layer_rect.m_left)] = rgb_16; + ((unsigned int*)m_layers[z_order].fb)[(y - layer_rect.m_top) * layer_rect.width() + (x - layer_rect.m_left)] = rgb; } } } } - return fill_rect_on_fb(x0, y0, x1, y1, rgb); + return fill_rect_low_level(x0, y0, x1, y1, rgb); } for (; y0 <= y1; y0++) { @@ -499,27 +573,16 @@ public: } int flush_screen(int left, int top, int right, int bottom) { - if (left < 0 || left >= m_width || right < 0 || right >= m_width || - top < 0 || top >= m_height || bottom < 0 || bottom >= m_height) - { - ASSERT(false); - } - if (!m_is_active || (0 == m_phy_fb) || (0 == m_fb)) + if (!m_is_active) { return -1; } - int display_width = m_display->get_width(); - int display_height = m_display->get_height(); - left = (left >= display_width) ? (display_width - 1) : left; - right = (right >= display_width) ? (display_width - 1) : right; - top = (top >= display_height) ? (display_height - 1) : top; - bottom = (bottom >= display_height) ? (display_height - 1) : bottom; - for (int y = top; y < bottom; y++) + if (left < 0 || left >= m_width || right < 0 || right >= m_width || + top < 0 || top >= m_height || bottom < 0 || bottom >= m_height) { - void* s_addr = (char*)m_fb + ((y * m_width + left) * m_color_bytes); - void* d_addr = (char*)m_phy_fb + ((y * display_width + left) * m_color_bytes); - memcpy(d_addr, s_addr, (right - left) * m_color_bytes); + ASSERT(false); } + m_display->flush_screen(left, top, right, bottom, m_fb, m_width); *m_phy_write_index = *m_phy_write_index + 1; return 0; } @@ -537,90 +600,62 @@ public: { for (int x = rect.m_left; x <= rect.m_right; x++) { - unsigned int rgb = (m_color_bytes == 4) ? ((unsigned int*)fb)[(x - layer_rect.m_left) + (y - layer_rect.m_top) * width] : GL_RGB_16_to_32(((unsigned short*)fb)[(x - layer_rect.m_left) + (y - layer_rect.m_top) * width]); - draw_pixel_on_fb(x, y, rgb); + unsigned int rgb = (m_color_bytes == 2) ? GL_RGB_16_to_32(((unsigned short*)fb)[(x - layer_rect.m_left) + (y - layer_rect.m_top) * width]) : ((unsigned int*)fb)[(x - layer_rect.m_left) + (y - layer_rect.m_top) * width]; + draw_pixel_low_level(x, y, rgb); } } return 0; } void set_active(bool flag) { m_is_active = flag; } protected: - virtual void fill_rect_on_fb(int x0, int y0, int x1, int y1, unsigned int rgb) - { - int display_width = m_display->get_width(); - int display_height = m_display->get_height(); - if (m_color_bytes == 4) + virtual void fill_rect_low_level(int x0, int y0, int x1, int y1, unsigned int rgb) + {//fill rect on framebuffer of surface + int x, y; + if (m_color_bytes == 2) { - int x; - unsigned int* fb, * phy_fb; - for (; y0 <= y1; y0++) + unsigned short* fb; + unsigned int rgb_16 = GL_RGB_32_to_16(rgb); + for (y = y0; y <= y1; y++) { - x = x0; - fb = m_fb ? &((unsigned int*)m_fb)[y0 * m_width + x] : 0; - phy_fb = &((unsigned int*)m_phy_fb)[y0 * display_width + x]; - *m_phy_write_index = *m_phy_write_index + 1; - for (; x <= x1; x++) + fb = m_fb ? &((unsigned short*)m_fb)[y * m_width + x0] : 0; + if (!fb) { break; } + for (x = x0; x <= x1; x++) { - if (fb) - { - *fb++ = rgb; - } - if (m_is_active && (x < display_width) && (y0 < display_height)) - { - *phy_fb++ = rgb; - } + *fb++ = rgb_16; } } } - else if (m_color_bytes == 2) + else { - int x; - unsigned short* fb, * phy_fb; - rgb = GL_RGB_32_to_16(rgb); - for (; y0 <= y1; y0++) + unsigned int* fb; + for (y = y0; y <= y1; y++) { - x = x0; - fb = m_fb ? &((unsigned short*)m_fb)[y0 * m_width + x] : 0; - phy_fb = &((unsigned short*)m_phy_fb)[y0 * display_width + x]; - *m_phy_write_index = *m_phy_write_index + 1; - for (; x <= x1; x++) + fb = m_fb ? &((unsigned int*)m_fb)[y * m_width + x0] : 0; + if (!fb) { break; } + for (x = x0; x <= x1; x++) { - if (fb) - { - *fb++ = rgb; - } - if (m_is_active && (x < display_width) && (y0 < display_height)) - { - *phy_fb++ = rgb; - } + *fb++ = rgb; } } } + if (!m_is_active) { return; } + m_display->fill_rect(x0, y0, x1, y1, rgb); + *m_phy_write_index = *m_phy_write_index + 1; } - virtual void draw_pixel_on_fb(int x, int y, unsigned int rgb) + virtual void draw_pixel_low_level(int x, int y, unsigned int rgb) { if (m_fb) - { - (m_color_bytes == 4) ? ((unsigned int*)m_fb)[y * m_width + x] = rgb : ((unsigned short*)m_fb)[y * m_width + x] = GL_RGB_32_to_16(rgb); - } - if (m_is_active && (x < m_display->get_width()) && (y < m_display->get_height())) - { - if (m_color_bytes == 4) - { - ((unsigned int*)m_phy_fb)[y * (m_display->get_width()) + x] = rgb; - } - else - { - ((unsigned short*)m_phy_fb)[y * (m_display->get_width()) + x] = GL_RGB_32_to_16(rgb); - } - *m_phy_write_index = *m_phy_write_index + 1; + {//draw pixel on framebuffer of surface + (m_color_bytes == 2) ? ((unsigned short*)m_fb)[y * m_width + x] = GL_RGB_32_to_16(rgb): ((unsigned int*)m_fb)[y * m_width + x] = rgb; } + if (!m_is_active) { return; } + m_display->draw_pixel(x, y, rgb); + *m_phy_write_index = *m_phy_write_index + 1; } void attach_display(c_display* display) { ASSERT(display); m_display = display; - m_phy_fb = display->m_phy_fb; m_phy_write_index = &display->m_phy_write_index; } void set_surface(Z_ORDER_LEVEL max_z_order, c_rect layer_rect) @@ -638,87 +673,22 @@ protected: } int m_width; //in pixels int m_height; //in pixels - int m_color_bytes; //16 bits, 32 bits only + int m_color_bytes; //16 bits, 32 bits for default void* m_fb; //frame buffer you could see c_layer m_layers[Z_ORDER_LEVEL_MAX];//all graphic layers bool m_is_active; //active flag Z_ORDER_LEVEL m_max_zorder; //the highest graphic layer the surface will have Z_ORDER_LEVEL m_top_zorder; //the current highest graphic layer the surface have - void* m_phy_fb; //physical framebufer int* m_phy_write_index; c_display* m_display; }; -class c_surface_no_fb : public c_surface {//No physical framebuffer, render with external graphic interface - friend class c_display; -public: - c_surface_no_fb(unsigned int width, unsigned int height, unsigned int color_bytes, struct EXTERNAL_GFX_OP* gfx_op, Z_ORDER_LEVEL max_zorder = Z_ORDER_LEVEL_0, c_rect overlpa_rect = c_rect()) : c_surface(width, height, color_bytes, max_zorder, overlpa_rect), m_gfx_op(gfx_op) {} -protected: - virtual void fill_rect_on_fb(int x0, int y0, int x1, int y1, unsigned int rgb) - { - if (!m_gfx_op) - { - return; - } - if (m_gfx_op->fill_rect) - { - return m_gfx_op->fill_rect(x0, y0, x1, y1, rgb); - } - if (m_gfx_op->draw_pixel && m_is_active) - { - for (int y = y0; y <= y1; y++) - { - for (int x = x0; x <= x1; x++) - { - m_gfx_op->draw_pixel(x, y, rgb); - } - } - } - if (!m_fb) { return; } - if (m_color_bytes == 4) - { - unsigned int* fb; - for (int y = y0; y <= y1; y++) - { - fb = &((unsigned int*)m_fb)[y0 * m_width + x0]; - for (int x = x0; x <= x1; x++) - { - *fb++ = rgb; - } - } - } - else if (m_color_bytes == 2) - { - unsigned short* fb; - rgb = GL_RGB_32_to_16(rgb); - for (int y = y0; y <= y1; y++) - { - fb = &((unsigned short*)m_fb)[y0 * m_width + x0]; - for (int x = x0; x <= x1; x++) - { - *fb++ = rgb; - } - } - } - } - virtual void draw_pixel_on_fb(int x, int y, unsigned int rgb) - { - if (m_gfx_op && m_gfx_op->draw_pixel && m_is_active) - { - m_gfx_op->draw_pixel(x, y, rgb); - } - if (!m_fb) { return; } - if (m_color_bytes == 4) - { - ((unsigned int*)m_fb)[y * m_width + x] = rgb; - } - else if (m_color_bytes == 2) - { - ((unsigned short*)m_fb)[y * m_width + x] = GL_RGB_32_to_16(rgb); - } - } - struct EXTERNAL_GFX_OP* m_gfx_op;//Rendering by external method -}; -inline c_display::c_display(void* phy_fb, int display_width, int display_height, int surface_width, int surface_height, unsigned int color_bytes, int surface_cnt, EXTERNAL_GFX_OP* gfx_op) : m_width(display_width), m_height(display_height), m_color_bytes(color_bytes), m_phy_fb(phy_fb), m_phy_read_index(0), m_phy_write_index(0), m_surface_cnt(surface_cnt), m_surface_index(0) +inline c_display::c_display(void* phy_fb, int display_width, int display_height, c_surface* surface, DISPLAY_DRIVER* driver) : m_phy_fb(phy_fb), m_width(display_width), m_height(display_height), m_driver(driver), m_phy_read_index(0), m_phy_write_index(0), m_surface_cnt(1), m_surface_index(0) +{ + m_color_bytes = surface->m_color_bytes; + surface->m_is_active = true; + (m_surface_group[0] = surface)->attach_display(this); +} +inline c_display::c_display(void* phy_fb, int display_width, int display_height, int surface_width, int surface_height, unsigned int color_bytes, int surface_cnt, DISPLAY_DRIVER* driver) : m_phy_fb(phy_fb), m_width(display_width), m_height(display_height), m_color_bytes(color_bytes), m_phy_read_index(0), m_phy_write_index(0), m_surface_cnt(surface_cnt), m_driver(driver), m_surface_index(0) { ASSERT(color_bytes == 2 || color_bytes == 4); ASSERT(m_surface_cnt <= SURFACE_CNT_MAX); @@ -726,16 +696,10 @@ inline c_display::c_display(void* phy_fb, int display_width, int display_height, for (int i = 0; i < m_surface_cnt; i++) { - m_surface_group[i] = (phy_fb) ? new c_surface(surface_width, surface_height, color_bytes) : new c_surface_no_fb(surface_width, surface_height, color_bytes, gfx_op); + m_surface_group[i] = new c_surface(surface_width, surface_height, color_bytes); m_surface_group[i]->attach_display(this); } } -inline c_display::c_display(void* phy_fb, int display_width, int display_height, c_surface* surface) : m_width(display_width), m_height(display_height), m_phy_fb(phy_fb), m_phy_read_index(0), m_phy_write_index(0), m_surface_cnt(1), m_surface_index(0) -{ - m_color_bytes = surface->m_color_bytes; - surface->m_is_active = true; - (m_surface_group[0] = surface)->attach_display(this); -} inline c_surface* c_display::alloc_surface(Z_ORDER_LEVEL max_zorder, c_rect layer_rect) { ASSERT(max_zorder < Z_ORDER_LEVEL_MAX && m_surface_index < m_surface_cnt); @@ -744,8 +708,8 @@ inline c_surface* c_display::alloc_surface(Z_ORDER_LEVEL max_zorder, c_rect laye } inline int c_display::swipe_surface(c_surface* s0, c_surface* s1, int x0, int x1, int y0, int y1, int offset) { - int surface_width = s0->get_width(); - int surface_height = s0->get_height(); + register int surface_width = s0->m_width; + register int surface_height = s0->m_height; if (offset < 0 || offset > surface_width || y0 < 0 || y0 >= surface_height || y1 < 0 || y1 >= surface_height || x0 < 0 || x0 >= surface_width || x1 < 0 || x1 >= surface_width) { @@ -767,46 +731,46 @@ inline int c_display::swipe_surface(c_surface* s0, c_surface* s1, int x0, int x1 for (int y = y0; y <= y1; y++) { //Left surface - char* addr_s = ((char*)(s0->m_fb) + (y * (s0->get_width()) + x0 + offset) * m_color_bytes); + char* addr_s = ((char*)(s0->m_fb) + (y * surface_width + x0 + offset) * m_color_bytes); char* addr_d = ((char*)(m_phy_fb)+(y * m_width + x0) * m_color_bytes); memcpy(addr_d, addr_s, (width - offset) * m_color_bytes); //Right surface - addr_s = ((char*)(s1->m_fb) + (y * (s1->get_width()) + x0) * m_color_bytes); + addr_s = ((char*)(s1->m_fb) + (y * surface_width + x0) * m_color_bytes); addr_d = ((char*)(m_phy_fb)+(y * m_width + x0 + (width - offset)) * m_color_bytes); memcpy(addr_d, addr_s, offset * m_color_bytes); } } - else if (m_color_bytes == 4) + else if (m_color_bytes == 2) { - void(*draw_pixel)(int x, int y, unsigned int rgb) = ((c_surface_no_fb*)s0)->m_gfx_op->draw_pixel; + void(*draw_pixel)(int x, int y, unsigned int rgb) = m_driver->draw_pixel; for (int y = y0; y <= y1; y++) { //Left surface for (int x = x0; x <= (x1 - offset); x++) { - draw_pixel(x, y, ((unsigned int*)s0->m_fb)[y * m_width + x + offset]); + draw_pixel(x, y, GL_RGB_16_to_32(((unsigned short*)s0->m_fb)[y * m_width + x + offset])); } //Right surface for (int x = x1 - offset; x <= x1; x++) { - draw_pixel(x, y, ((unsigned int*)s1->m_fb)[y * m_width + x + offset - x1 + x0]); + draw_pixel(x, y, GL_RGB_16_to_32(((unsigned short*)s1->m_fb)[y * m_width + x + offset - x1 + x0])); } } } - else if (m_color_bytes == 2) + else //m_color_bytes == 3/4... { - void(*draw_pixel)(int x, int y, unsigned int rgb) = ((c_surface_no_fb*)s0)->m_gfx_op->draw_pixel; + void(*draw_pixel)(int x, int y, unsigned int rgb) = m_driver->draw_pixel; for (int y = y0; y <= y1; y++) { //Left surface for (int x = x0; x <= (x1 - offset); x++) { - draw_pixel(x, y, GL_RGB_16_to_32(((unsigned short*)s0->m_fb)[y * m_width + x + offset])); + draw_pixel(x, y, ((unsigned int*)s0->m_fb)[y * m_width + x + offset]); } //Right surface for (int x = x1 - offset; x <= x1; x++) { - draw_pixel(x, y, GL_RGB_16_to_32(((unsigned short*)s1->m_fb)[y * m_width + x + offset - x1 + x0])); + draw_pixel(x, y, ((unsigned int*)s1->m_fb)[y * m_width + x + offset - x1 + x0]); } } } @@ -3407,22 +3371,12 @@ private: #ifdef GUILITE_ON c_bitmap_operator the_bitmap_op = c_bitmap_operator(); c_image_operator* c_image::image_operator = &the_bitmap_op; +const void* c_theme::s_font_map[FONT_MAX]; +const void* c_theme::s_image_map[IMAGE_MAX]; +unsigned int c_theme::s_color_map[COLOR_MAX]; +c_lattice_font_op the_lattice_font_op = c_lattice_font_op(); +c_font_operator* c_word::fontOperator = &the_lattice_font_op; #endif - -#ifdef GUILITE_ON - -const void* c_theme::s_font_map[FONT_MAX]; -const void* c_theme::s_image_map[IMAGE_MAX]; -unsigned int c_theme::s_color_map[COLOR_MAX]; - -#endif - -#ifdef GUILITE_ON - -c_lattice_font_op the_lattice_font_op = c_lattice_font_op(); -c_font_operator* c_word::fontOperator = &the_lattice_font_op; - -#endif #ifdef GUILITE_ON #if (defined __linux__) || (defined __APPLE__) #include @@ -4264,11 +4218,7 @@ int c_fifo::write(void* buf, int len) #endif #ifdef GUILITE_ON DIALOG_ARRAY c_dialog::ms_the_dialogs[SURFACE_CNT_MAX]; -#endif -#ifdef GUILITE_ON c_keyboard c_edit::s_keyboard; -#endif -#ifdef GUILITE_ON static c_keyboard_button s_key_0, s_key_1, s_key_2, s_key_3, s_key_4, s_key_5, s_key_6, s_key_7, s_key_8, s_key_9; static c_keyboard_button s_key_A, s_key_B, s_key_C, s_key_D, s_key_E, s_key_F, s_key_G, s_key_H, s_key_I, s_key_J; static c_keyboard_button s_key_K, s_key_L, s_key_M, s_key_N, s_key_O, s_key_P, s_key_Q, s_key_R, s_key_S, s_key_T; @@ -4306,12 +4256,12 @@ WND_TREE g_key_board_children[] = {&s_key_B, 'B', 0, ((KEY_WIDTH / 2) + POS_X(5)), POS_Y(2), KEY_WIDTH, KEY_HEIGHT}, {&s_key_N, 'N', 0, ((KEY_WIDTH / 2) + POS_X(6)), POS_Y(2), KEY_WIDTH, KEY_HEIGHT}, {&s_key_M, 'M', 0, ((KEY_WIDTH / 2) + POS_X(7)), POS_Y(2), KEY_WIDTH, KEY_HEIGHT}, - {&s_key_del, 0x7F, 0, ((KEY_WIDTH / 2) + POS_X(8)), POS_Y(2), DEL_WIDTH, KEY_HEIGHT}, + {&s_key_del,0x7F, 0, ((KEY_WIDTH / 2) + POS_X(8)), POS_Y(2), DEL_WIDTH, KEY_HEIGHT}, //Row 4 - {&s_key_esc, 0x1B, 0, POS_X(0), POS_Y(3), ESC_WIDTH, KEY_HEIGHT}, + {&s_key_esc, 0x1B, 0, POS_X(0), POS_Y(3), ESC_WIDTH, KEY_HEIGHT}, {&s_key_num_switch, 0x90, 0, POS_X(2), POS_Y(3), SWITCH_WIDTH, KEY_HEIGHT}, {&s_key_space, ' ', 0, ((KEY_WIDTH / 2) + POS_X(3)), POS_Y(3), SPACE_WIDTH, KEY_HEIGHT}, - {&s_key_dot, '.', 0, ((KEY_WIDTH / 2) + POS_X(6)), POS_Y(3), DOT_WIDTH, KEY_HEIGHT}, + {&s_key_dot, '.', 0, ((KEY_WIDTH / 2) + POS_X(6)), POS_Y(3), DOT_WIDTH, KEY_HEIGHT}, {&s_key_enter, '\n', 0, POS_X(8), POS_Y(3), ENTER_WIDTH, KEY_HEIGHT}, {0,0,0,0,0,0,0} }; @@ -4326,12 +4276,11 @@ WND_TREE g_number_board_children[] = {&s_key_7, '7', 0, POS_X(0), POS_Y(2), KEY_WIDTH, KEY_HEIGHT}, {&s_key_8, '8', 0, POS_X(1), POS_Y(2), KEY_WIDTH, KEY_HEIGHT}, {&s_key_9, '9', 0, POS_X(2), POS_Y(2), KEY_WIDTH, KEY_HEIGHT}, - - {&s_key_esc, 0x1B, 0, POS_X(0), POS_Y(3), KEY_WIDTH, KEY_HEIGHT}, + {&s_key_esc,0x1B, 0, POS_X(0), POS_Y(3), KEY_WIDTH, KEY_HEIGHT}, {&s_key_0, '0', 0, POS_X(1), POS_Y(3), KEY_WIDTH, KEY_HEIGHT}, - {&s_key_dot, '.', 0, POS_X(2), POS_Y(3), KEY_WIDTH, KEY_HEIGHT}, + {&s_key_dot,'.', 0, POS_X(2), POS_Y(3), KEY_WIDTH, KEY_HEIGHT}, {&s_key_del, 0x7F, 0, POS_X(3), POS_Y(0), KEY_WIDTH, KEY_HEIGHT * 2 + 2}, {&s_key_enter,'\n', 0, POS_X(3), POS_Y(2), KEY_WIDTH, KEY_HEIGHT * 2 + 2}, {0,0,0,0,0,0,0} }; -#endif +#endif \ No newline at end of file diff --git a/HelloMolecule/UIcode/UIcode.cpp b/HelloMolecule/UIcode/UIcode.cpp index d1375f87187db5d7f5fad0108d5b5b1bf5aa1f5f..661c7c4d98d1326b4092fb7204145384a803678b 100644 --- a/HelloMolecule/UIcode/UIcode.cpp +++ b/HelloMolecule/UIcode/UIcode.cpp @@ -150,22 +150,12 @@ public: Bond Bond::bonds[BOND_TOTAL]; -void create_ui(void* phy_fb, int screen_width, int screen_height, int color_bytes, struct EXTERNAL_GFX_OP* gfx_op) +void create_ui(void* phy_fb, int screen_width, int screen_height, int color_bytes, struct DISPLAY_DRIVER* driver) { - if (phy_fb) - { - static c_surface surface(UI_WIDTH, UI_HEIGHT, color_bytes, Z_ORDER_LEVEL_0); - static c_display display(phy_fb, screen_width, screen_height, &surface); - s_surface = &surface; - s_display = &display; - } - else - {//for MCU without framebuffer - static c_surface_no_fb surface_no_fb(UI_WIDTH, UI_HEIGHT, color_bytes, gfx_op, Z_ORDER_LEVEL_0); - static c_display display(phy_fb, screen_width, screen_height, &surface_no_fb); - s_surface = &surface_no_fb; - s_display = &display; - } + static c_surface surface(UI_WIDTH, UI_HEIGHT, color_bytes, Z_ORDER_LEVEL_0); + static c_display display(phy_fb, screen_width, screen_height, &surface, driver); + s_surface = &surface; + s_display = &display; //background s_surface->fill_rect(0, 0, UI_WIDTH, UI_HEIGHT, 0, Z_ORDER_LEVEL_0); @@ -190,9 +180,9 @@ void create_ui(void* phy_fb, int screen_width, int screen_height, int color_byte } //////////////////////// interface for all platform //////////////////////// -extern "C" void startHelloMolecule(void* phy_fb, int width, int height, int color_bytes, struct EXTERNAL_GFX_OP* gfx_op) +extern "C" void startHelloMolecule(void* phy_fb, int width, int height, int color_bytes, struct DISPLAY_DRIVER* driver) { - create_ui(phy_fb, width, height, color_bytes, gfx_op); + create_ui(phy_fb, width, height, color_bytes, driver); } extern void* getUiOfHelloMolecule(int* width, int* height, bool force_update = false) diff --git a/HelloNets/BuildLinux/.sync_build.sh b/HelloNets/BuildLinux/.sync_build.sh index 49cff5b473ac606967676ebefa6f0d333e301227..964054cd68ceb2548e9238bfe6d8fee943f2ee3d 100644 --- a/HelloNets/BuildLinux/.sync_build.sh +++ b/HelloNets/BuildLinux/.sync_build.sh @@ -1,5 +1,6 @@ if [ "$#" -ne 1 ]; then - echo "Invalid arguments" + echo "Do testing" + ./xWindow 500 500 | ./HelloNets shared-fb exit -1 fi diff --git a/HelloNets/BuildMFC/HelloNetsDlg.cpp b/HelloNets/BuildMFC/HelloNetsDlg.cpp index ed159ca8fcc7314c5125c1c9369c306ba5321936..00f5f14810cf296a90a7c78bb4d4eb3e9478aeca 100644 Binary files a/HelloNets/BuildMFC/HelloNetsDlg.cpp and b/HelloNets/BuildMFC/HelloNetsDlg.cpp differ diff --git a/HelloNets/BuildMFC/HelloNetsDlg.h b/HelloNets/BuildMFC/HelloNetsDlg.h index 7610d33d22bb502172e732188b73fd3e8ac9978d..1fa4db7e1c5183f11c2263c8f7728e5422f7a481 100644 Binary files a/HelloNets/BuildMFC/HelloNetsDlg.h and b/HelloNets/BuildMFC/HelloNetsDlg.h differ diff --git a/HelloNets/BuildSTM32F103-Keil/USER/main.c b/HelloNets/BuildSTM32F103-Keil/USER/main.c index 23dbddd3e265b32fe82890883003322038e201a8..667d523ce49f98fded73a4bdf3aace29980498e5 100644 --- a/HelloNets/BuildSTM32F103-Keil/USER/main.c +++ b/HelloNets/BuildSTM32F103-Keil/USER/main.c @@ -15,12 +15,12 @@ void gfx_draw_pixel(int x, int y, unsigned int rgb) //void gfx_fill_rect(int x0, int y0, int x1, int y1, unsigned int rgb){} //UI entry -struct EXTERNAL_GFX_OP +struct DISPLAY_DRIVER { void (*draw_pixel)(int x, int y, unsigned int rgb); void (*fill_rect)(int x0, int y0, int x1, int y1, unsigned int rgb); -} my_gfx_op; -extern void startHelloNets(void* phy_fb, int width, int height, int color_bytes, struct EXTERNAL_GFX_OP* gfx_op); +} my_driver; +extern void startHelloNets(void* phy_fb, int width, int height, int color_bytes, struct DISPLAY_DRIVER* driver); int main(void) { @@ -30,8 +30,8 @@ int main(void) LCD_Init(); //Link your LCD driver & start UI: - my_gfx_op.draw_pixel = gfx_draw_pixel; - my_gfx_op.fill_rect = NULL;//gfx_fill_rect; - startHelloNets(NULL, 240, 320, 2, &my_gfx_op); + my_driver.draw_pixel = gfx_draw_pixel; + my_driver.fill_rect = NULL;//gfx_fill_rect; + startHelloNets(NULL, 240, 320, 2, &my_driver); while(1); } diff --git a/HelloNets/BuildWin32/HelloNets.cpp b/HelloNets/BuildWin32/HelloNets.cpp index c517e756158b5d6ee2fb551ea39fc99c9ef42fdc..7702c670df8f3770b1788842d6304af8db5eac71 100644 --- a/HelloNets/BuildWin32/HelloNets.cpp +++ b/HelloNets/BuildWin32/HelloNets.cpp @@ -161,7 +161,7 @@ LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam) } //////////////////////// HelloNets Interface //////////////////////// -extern "C" void startHelloNets(void* phy_fb, int width, int height, int color_bytes, struct EXTERNAL_GFX_OP* gfx_op); +extern "C" void startHelloNets(void* phy_fb, int width, int height, int color_bytes, struct DISPLAY_DRIVER* driver); DWORD WINAPI ThreadHelloNets(LPVOID pParam) { diff --git a/HelloNets/UIcode/GuiLite.h b/HelloNets/UIcode/GuiLite.h index c4fc88a51476d2c8309c3e55e1270e13784fc510..80550e1632ad7bc82541a2edbb0f7f8f5937954f 100644 --- a/HelloNets/UIcode/GuiLite.h +++ b/HelloNets/UIcode/GuiLite.h @@ -1,107 +1,94 @@ #pragma once - -#define REAL_TIME_TASK_CYCLE_MS 50 -#define MAX(a,b) (((a)>(b))?(a):(b)) -#define MIN(a,b) (((a)<(b))?(a):(b)) - -#define GL_ARGB(a, r, g, b) ((((unsigned int)(a)) << 24) | (((unsigned int)(r)) << 16) | (((unsigned int)(g)) << 8) | ((unsigned int)(b))) -#define GL_ARGB_A(rgb) ((((unsigned int)(rgb)) >> 24) & 0xFF) - -#define GL_RGB(r, g, b) ((0xFF << 24) | (((unsigned int)(r)) << 16) | (((unsigned int)(g)) << 8) | ((unsigned int)(b))) -#define GL_RGB_R(rgb) ((((unsigned int)(rgb)) >> 16) & 0xFF) -#define GL_RGB_G(rgb) ((((unsigned int)(rgb)) >> 8) & 0xFF) -#define GL_RGB_B(rgb) (((unsigned int)(rgb)) & 0xFF) -#define GL_RGB_32_to_16(rgb) (((((unsigned int)(rgb)) & 0xFF) >> 3) | ((((unsigned int)(rgb)) & 0xFC00) >> 5) | ((((unsigned int)(rgb)) & 0xF80000) >> 8)) -#define GL_RGB_16_to_32(rgb) ((0xFF << 24) | ((((unsigned int)(rgb)) & 0x1F) << 3) | ((((unsigned int)(rgb)) & 0x7E0) << 5) | ((((unsigned int)(rgb)) & 0xF800) << 8)) - -#define ALIGN_HCENTER 0x00000000L -#define ALIGN_LEFT 0x01000000L -#define ALIGN_RIGHT 0x02000000L -#define ALIGN_HMASK 0x03000000L - -#define ALIGN_VCENTER 0x00000000L -#define ALIGN_TOP 0x00100000L -#define ALIGN_BOTTOM 0x00200000L -#define ALIGN_VMASK 0x00300000L - -typedef struct -{ - unsigned short year; - unsigned short month; - unsigned short date; - unsigned short day; - unsigned short hour; - unsigned short minute; - unsigned short second; -}T_TIME; - -void register_debug_function(void(*my_assert)(const char* file, int line), void(*my_log_out)(const char* log)); -void _assert(const char* file, int line); -#define ASSERT(condition) \ - do{ \ - if(!(condition))_assert(__FILE__, __LINE__);\ - }while(0) -void log_out(const char* log); - -long get_time_in_second(); -T_TIME second_to_day(long second); -T_TIME get_time(); - -void start_real_timer(void (*func)(void* arg)); -void register_timer(int milli_second, void func(void* param), void* param); - -unsigned int get_cur_thread_id(); -void create_thread(unsigned long* thread_id, void* attr, void *(*start_routine) (void *), void* arg); -void thread_sleep(unsigned int milli_seconds); -int build_bmp(const char *filename, unsigned int width, unsigned int height, unsigned char *data); - -#define FIFO_BUFFER_LEN 1024 -class c_fifo -{ -public: - c_fifo(); - int read(void* buf, int len); - int write(void* buf, int len); -private: - unsigned char m_buf[FIFO_BUFFER_LEN]; - int m_head; - int m_tail; - void* m_read_sem; - void* m_write_mutex; -}; - -class c_rect -{ -public: - c_rect(){ m_left = m_top = m_right = m_bottom = -1; } - c_rect(int left, int top, int width, int height) - { - set_rect(left, top, width, height); - } - void set_rect(int left, int top, int width, int height) - { - ASSERT(width > 0 && height > 0); - m_left = left; - m_top = top; - m_right = left + width - 1; - m_bottom = top + height -1; - } - bool pt_in_rect(int x, int y) const - { - return x >= m_left && x <= m_right && y >= m_top && y <= m_bottom; - } - int operator==(const c_rect& rect) const - { - return (m_left == rect.m_left) && (m_top == rect.m_top) && (m_right == rect.m_right) && (m_bottom == rect.m_bottom); - } - int width() const { return m_right - m_left + 1; } - int height() const { return m_bottom - m_top + 1 ; } - - int m_left; - int m_top; - int m_right; - int m_bottom; -}; +#define REAL_TIME_TASK_CYCLE_MS 50 +#define MAX(a,b) (((a)>(b))?(a):(b)) +#define MIN(a,b) (((a)<(b))?(a):(b)) +#define GL_ARGB(a, r, g, b) ((((unsigned int)(a)) << 24) | (((unsigned int)(r)) << 16) | (((unsigned int)(g)) << 8) | ((unsigned int)(b))) +#define GL_ARGB_A(rgb) ((((unsigned int)(rgb)) >> 24) & 0xFF) +#define GL_RGB(r, g, b) ((0xFF << 24) | (((unsigned int)(r)) << 16) | (((unsigned int)(g)) << 8) | ((unsigned int)(b))) +#define GL_RGB_R(rgb) ((((unsigned int)(rgb)) >> 16) & 0xFF) +#define GL_RGB_G(rgb) ((((unsigned int)(rgb)) >> 8) & 0xFF) +#define GL_RGB_B(rgb) (((unsigned int)(rgb)) & 0xFF) +#define GL_RGB_32_to_16(rgb) (((((unsigned int)(rgb)) & 0xFF) >> 3) | ((((unsigned int)(rgb)) & 0xFC00) >> 5) | ((((unsigned int)(rgb)) & 0xF80000) >> 8)) +#define GL_RGB_16_to_32(rgb) ((0xFF << 24) | ((((unsigned int)(rgb)) & 0x1F) << 3) | ((((unsigned int)(rgb)) & 0x7E0) << 5) | ((((unsigned int)(rgb)) & 0xF800) << 8)) +#define ALIGN_HCENTER 0x00000000L +#define ALIGN_LEFT 0x01000000L +#define ALIGN_RIGHT 0x02000000L +#define ALIGN_HMASK 0x03000000L +#define ALIGN_VCENTER 0x00000000L +#define ALIGN_TOP 0x00100000L +#define ALIGN_BOTTOM 0x00200000L +#define ALIGN_VMASK 0x00300000L +typedef struct +{ + unsigned short year; + unsigned short month; + unsigned short date; + unsigned short day; + unsigned short hour; + unsigned short minute; + unsigned short second; +}T_TIME; +void register_debug_function(void(*my_assert)(const char* file, int line), void(*my_log_out)(const char* log)); +void _assert(const char* file, int line); +#define ASSERT(condition) \ + do{ \ + if(!(condition))_assert(__FILE__, __LINE__);\ + }while(0) +void log_out(const char* log); +long get_time_in_second(); +T_TIME second_to_day(long second); +T_TIME get_time(); +void start_real_timer(void (*func)(void* arg)); +void register_timer(int milli_second, void func(void* param), void* param); +unsigned int get_cur_thread_id(); +void create_thread(unsigned long* thread_id, void* attr, void *(*start_routine) (void *), void* arg); +void thread_sleep(unsigned int milli_seconds); +int build_bmp(const char *filename, unsigned int width, unsigned int height, unsigned char *data); +#define FIFO_BUFFER_LEN 1024 +class c_fifo +{ +public: + c_fifo(); + int read(void* buf, int len); + int write(void* buf, int len); +private: + unsigned char m_buf[FIFO_BUFFER_LEN]; + int m_head; + int m_tail; + void* m_read_sem; + void* m_write_mutex; +}; +class c_rect +{ +public: + c_rect(){ m_left = m_top = m_right = m_bottom = -1; } + c_rect(int left, int top, int width, int height) + { + set_rect(left, top, width, height); + } + void set_rect(int left, int top, int width, int height) + { + ASSERT(width > 0 && height > 0); + m_left = left; + m_top = top; + m_right = left + width - 1; + m_bottom = top + height -1; + } + bool pt_in_rect(int x, int y) const + { + return x >= m_left && x <= m_right && y >= m_top && y <= m_bottom; + } + int operator==(const c_rect& rect) const + { + return (m_left == rect.m_left) && (m_top == rect.m_top) && (m_right == rect.m_right) && (m_bottom == rect.m_bottom); + } + int width() const { return m_right - m_left + 1; } + int height() const { return m_bottom - m_top + 1 ; } + int m_left; + int m_top; + int m_right; + int m_bottom; +}; //BITMAP typedef struct struct_bitmap_info { @@ -238,7 +225,7 @@ typedef enum Z_ORDER_LEVEL_2,//highest graphic level Z_ORDER_LEVEL_MAX }Z_ORDER_LEVEL; -struct EXTERNAL_GFX_OP +struct DISPLAY_DRIVER { void(*draw_pixel)(int x, int y, unsigned int rgb); void(*fill_rect)(int x0, int y0, int x1, int y1, unsigned int rgb); @@ -247,18 +234,19 @@ class c_surface; class c_display { friend class c_surface; public: - inline c_display(void* phy_fb, int display_width, int display_height, int surface_width, int surface_height, unsigned int color_bytes, int surface_cnt, EXTERNAL_GFX_OP* gfx_op = 0);//multiple surface or surface_no_fb - inline c_display(void* phy_fb, int display_width, int display_height, c_surface* surface);//single custom surface - inline c_surface* alloc_surface(Z_ORDER_LEVEL max_zorder, c_rect layer_rect = c_rect());//for multiple surfaces + inline c_display(void* phy_fb, int display_width, int display_height, c_surface* surface, DISPLAY_DRIVER* driver = 0);//single custom surface + inline c_display(void* phy_fb, int display_width, int display_height, int surface_width, int surface_height, unsigned int color_bytes, int surface_cnt, DISPLAY_DRIVER* driver = 0);//multiple surface + inline c_surface* alloc_surface(Z_ORDER_LEVEL max_zorder, c_rect layer_rect = c_rect());//for slide group inline int swipe_surface(c_surface* s0, c_surface* s1, int x0, int x1, int y0, int y1, int offset); int get_width() { return m_width; } int get_height() { return m_height; } + void* get_phy_fb() { return m_phy_fb; } void* get_updated_fb(int* width, int* height, bool force_update = false) { if (width && height) { - *width = get_width(); - *height = get_height(); + *width = m_width; + *height = m_height; } if (force_update) { @@ -277,35 +265,123 @@ public: { return -1; } - int width = get_width(); - int height = get_height(); //16 bits framebuffer if (m_color_bytes == 2) { - return build_bmp(file_name, width, height, (unsigned char*)m_phy_fb); + return build_bmp(file_name, m_width, m_height, (unsigned char*)m_phy_fb); } //32 bits framebuffer - unsigned short* p_bmp565_data = new unsigned short[width * height]; + unsigned short* p_bmp565_data = new unsigned short[m_width * m_height]; unsigned int* p_raw_data = (unsigned int*)m_phy_fb; - for (int i = 0; i < width * height; i++) + for (int i = 0; i < m_width * m_height; i++) { unsigned int rgb = *p_raw_data++; p_bmp565_data[i] = GL_RGB_32_to_16(rgb); } - int ret = build_bmp(file_name, width, height, (unsigned char*)p_bmp565_data); + int ret = build_bmp(file_name, m_width, m_height, (unsigned char*)p_bmp565_data); delete[]p_bmp565_data; return ret; } -private: - int m_width; //in pixels - int m_height; //in pixels - int m_color_bytes; //16 bits, 32 bits only - void* m_phy_fb; //physical framebuffer +protected: + virtual void draw_pixel(int x, int y, unsigned int rgb) + { + if ((x >= m_width) || (y >= m_height)) { return; } + if (m_driver && m_driver->draw_pixel) + { + return m_driver->draw_pixel(x, y, rgb); + } + if (m_color_bytes == 2) + { + ((unsigned short*)m_phy_fb)[y * m_width + x] = GL_RGB_32_to_16(rgb); + } + else + { + ((unsigned int*)m_phy_fb)[y * m_width + x] = rgb; + } + } + virtual void fill_rect(int x0, int y0, int x1, int y1, unsigned int rgb) + { + if (m_driver && m_driver->fill_rect) + { + return m_driver->fill_rect(x0, y0, x1, y1, rgb); + } + if (m_driver && m_driver->draw_pixel) + { + for (int y = y0; y <= y1; y++) + { + for (int x = x0; x <= x1; x++) + { + m_driver->draw_pixel(x, y, rgb); + } + } + return; + } + register int _width = m_width; + register int _height = m_height; + int x, y; + if (m_color_bytes == 2) + { + unsigned short* phy_fb; + unsigned int rgb_16 = GL_RGB_32_to_16(rgb); + for (y = y0; y <= y1; y++) + { + phy_fb = &((unsigned short*)m_phy_fb)[y * _width + x0]; + for (x = x0; x <= x1; x++) + { + if ((x < _width) && (y < _height)) + { + *phy_fb++ = rgb_16; + } + } + } + } + else + { + unsigned int* phy_fb; + for (y = y0; y <= y1; y++) + { + phy_fb = &((unsigned int*)m_phy_fb)[y * _width + x0]; + for (x = x0; x <= x1; x++) + { + if ((x < _width) && (y < _height)) + { + *phy_fb++ = rgb; + } + } + } + } + } + virtual int flush_screen(int left, int top, int right, int bottom, void* fb, int fb_width) + { + if ((0 == m_phy_fb) || (0 == fb)) + { + return -1; + } + register int _width = m_width; + register int _height = m_height; + left = (left >= _width) ? (_width - 1) : left; + right = (right >= _width) ? (_width - 1) : right; + top = (top >= _height) ? (_height - 1) : top; + bottom = (bottom >= _height) ? (_height - 1) : bottom; + for (int y = top; y < bottom; y++) + { + void* s_addr = (char*)fb + ((y * fb_width + left) * m_color_bytes); + void* d_addr = (char*)m_phy_fb + ((y * _width + left) * m_color_bytes); + memcpy(d_addr, s_addr, (right - left) * m_color_bytes); + } + return 0; + } + int m_width; //in pixels + int m_height; //in pixels + int m_color_bytes; //16/32 bits for default + void* m_phy_fb; //physical framebuffer for default + struct DISPLAY_DRIVER* m_driver; //Rendering by external method without default physical framebuffer int m_phy_read_index; int m_phy_write_index; c_surface* m_surface_group[SURFACE_CNT_MAX]; int m_surface_cnt; //surface count int m_surface_index; + }; class c_layer { @@ -317,12 +393,10 @@ public: class c_surface { friend class c_display; friend class c_bitmap_operator; public: - c_surface(unsigned int width, unsigned int height, unsigned int color_bytes, Z_ORDER_LEVEL max_zorder = Z_ORDER_LEVEL_0, c_rect overlpa_rect = c_rect()) : m_width(width), m_height(height), m_color_bytes(color_bytes), m_fb(0), m_is_active(false), m_top_zorder(Z_ORDER_LEVEL_0), m_phy_fb(0), m_phy_write_index(0), m_display(0) + c_surface(unsigned int width, unsigned int height, unsigned int color_bytes, Z_ORDER_LEVEL max_zorder = Z_ORDER_LEVEL_0, c_rect overlpa_rect = c_rect()) : m_width(width), m_height(height), m_color_bytes(color_bytes), m_fb(0), m_is_active(false), m_top_zorder(Z_ORDER_LEVEL_0), m_phy_write_index(0), m_display(0) { (overlpa_rect == c_rect()) ? set_surface(max_zorder, c_rect(0, 0, width - 1, height - 1)) : set_surface(max_zorder, overlpa_rect); } - int get_width() { return m_width; } - int get_height() { return m_height; } unsigned int get_pixel(int x, int y, unsigned int z_order) { if (x >= m_width || y >= m_height || x < 0 || y < 0 || z_order >= Z_ORDER_LEVEL_MAX) @@ -332,15 +406,15 @@ public: } if (m_layers[z_order].fb) { - return (m_color_bytes == 4) ? ((unsigned int*)(m_layers[z_order].fb))[y * m_width + x] : GL_RGB_16_to_32(((unsigned short*)(m_layers[z_order].fb))[y * m_width + x]); + return (m_color_bytes == 2) ? GL_RGB_16_to_32(((unsigned short*)(m_layers[z_order].fb))[y * m_width + x]) : ((unsigned int*)(m_layers[z_order].fb))[y * m_width + x]; } else if (m_fb) { - return (m_color_bytes == 4) ? ((unsigned int*)m_fb)[y * m_width + x] : GL_RGB_16_to_32(((unsigned short*)m_fb)[y * m_width + x]); + return (m_color_bytes == 2) ? GL_RGB_16_to_32(((unsigned short*)m_fb)[y * m_width + x]) : ((unsigned int*)m_fb)[y * m_width + x]; } - else if (m_phy_fb) + else if (m_display->m_phy_fb) { - return (m_color_bytes == 4) ? ((unsigned int*)m_phy_fb)[y * m_width + x] : GL_RGB_16_to_32(((unsigned short*)m_phy_fb)[y * m_width + x]); + return (m_color_bytes == 2) ? GL_RGB_16_to_32(((unsigned short*)m_display->m_phy_fb)[y * m_width + x]) : ((unsigned int*)m_display->m_phy_fb)[y * m_width + x]; } return 0; } @@ -357,7 +431,7 @@ public: } if (z_order == m_max_zorder) { - return draw_pixel_on_fb(x, y, rgb); + return draw_pixel_low_level(x, y, rgb); } if (z_order > (unsigned int)m_top_zorder) @@ -367,19 +441,19 @@ public: if (m_layers[z_order].rect.pt_in_rect(x, y)) { c_rect layer_rect = m_layers[z_order].rect; - if (m_color_bytes == 4) + if (m_color_bytes == 2) { - ((unsigned int*)(m_layers[z_order].fb))[(x - layer_rect.m_left) + (y - layer_rect.m_top) * layer_rect.width()] = rgb; + ((unsigned short*)(m_layers[z_order].fb))[(x - layer_rect.m_left) + (y - layer_rect.m_top) * layer_rect.width()] = GL_RGB_32_to_16(rgb); } else { - ((unsigned short*)(m_layers[z_order].fb))[(x - layer_rect.m_left) + (y - layer_rect.m_top) * layer_rect.width()] = GL_RGB_32_to_16(rgb); + ((unsigned int*)(m_layers[z_order].fb))[(x - layer_rect.m_left) + (y - layer_rect.m_top) * layer_rect.width()] = rgb; } } if (z_order == m_top_zorder) { - return draw_pixel_on_fb(x, y, rgb); + return draw_pixel_low_level(x, y, rgb); } bool be_overlapped = false; for (unsigned int tmp_z_order = Z_ORDER_LEVEL_MAX - 1; tmp_z_order > z_order; tmp_z_order--) @@ -392,7 +466,7 @@ public: } if (!be_overlapped) { - draw_pixel_on_fb(x, y, rgb); + draw_pixel_low_level(x, y, rgb); } } virtual void fill_rect(int x0, int y0, int x1, int y1, unsigned int rgb, unsigned int z_order) @@ -403,7 +477,7 @@ public: y1 = (y1 > (m_height - 1)) ? (m_height - 1) : y1; if (z_order == m_max_zorder) { - return fill_rect_on_fb(x0, y0, x1, y1, rgb); + return fill_rect_low_level(x0, y0, x1, y1, rgb); } if (z_order == m_top_zorder) { @@ -416,18 +490,18 @@ public: { if (layer_rect.pt_in_rect(x, y)) { - if (m_color_bytes == 4) + if (m_color_bytes == 2) { - ((unsigned int*)m_layers[z_order].fb)[(y - layer_rect.m_top) * layer_rect.width() + (x - layer_rect.m_left)] = rgb; + ((unsigned short*)m_layers[z_order].fb)[(y - layer_rect.m_top) * layer_rect.width() + (x - layer_rect.m_left)] = rgb_16; } else { - ((unsigned short*)m_layers[z_order].fb)[(y - layer_rect.m_top) * layer_rect.width() + (x - layer_rect.m_left)] = rgb_16; + ((unsigned int*)m_layers[z_order].fb)[(y - layer_rect.m_top) * layer_rect.width() + (x - layer_rect.m_left)] = rgb; } } } } - return fill_rect_on_fb(x0, y0, x1, y1, rgb); + return fill_rect_low_level(x0, y0, x1, y1, rgb); } for (; y0 <= y1; y0++) { @@ -499,27 +573,16 @@ public: } int flush_screen(int left, int top, int right, int bottom) { - if (left < 0 || left >= m_width || right < 0 || right >= m_width || - top < 0 || top >= m_height || bottom < 0 || bottom >= m_height) - { - ASSERT(false); - } - if (!m_is_active || (0 == m_phy_fb) || (0 == m_fb)) + if (!m_is_active) { return -1; } - int display_width = m_display->get_width(); - int display_height = m_display->get_height(); - left = (left >= display_width) ? (display_width - 1) : left; - right = (right >= display_width) ? (display_width - 1) : right; - top = (top >= display_height) ? (display_height - 1) : top; - bottom = (bottom >= display_height) ? (display_height - 1) : bottom; - for (int y = top; y < bottom; y++) + if (left < 0 || left >= m_width || right < 0 || right >= m_width || + top < 0 || top >= m_height || bottom < 0 || bottom >= m_height) { - void* s_addr = (char*)m_fb + ((y * m_width + left) * m_color_bytes); - void* d_addr = (char*)m_phy_fb + ((y * display_width + left) * m_color_bytes); - memcpy(d_addr, s_addr, (right - left) * m_color_bytes); + ASSERT(false); } + m_display->flush_screen(left, top, right, bottom, m_fb, m_width); *m_phy_write_index = *m_phy_write_index + 1; return 0; } @@ -537,90 +600,62 @@ public: { for (int x = rect.m_left; x <= rect.m_right; x++) { - unsigned int rgb = (m_color_bytes == 4) ? ((unsigned int*)fb)[(x - layer_rect.m_left) + (y - layer_rect.m_top) * width] : GL_RGB_16_to_32(((unsigned short*)fb)[(x - layer_rect.m_left) + (y - layer_rect.m_top) * width]); - draw_pixel_on_fb(x, y, rgb); + unsigned int rgb = (m_color_bytes == 2) ? GL_RGB_16_to_32(((unsigned short*)fb)[(x - layer_rect.m_left) + (y - layer_rect.m_top) * width]) : ((unsigned int*)fb)[(x - layer_rect.m_left) + (y - layer_rect.m_top) * width]; + draw_pixel_low_level(x, y, rgb); } } return 0; } void set_active(bool flag) { m_is_active = flag; } protected: - virtual void fill_rect_on_fb(int x0, int y0, int x1, int y1, unsigned int rgb) - { - int display_width = m_display->get_width(); - int display_height = m_display->get_height(); - if (m_color_bytes == 4) + virtual void fill_rect_low_level(int x0, int y0, int x1, int y1, unsigned int rgb) + {//fill rect on framebuffer of surface + int x, y; + if (m_color_bytes == 2) { - int x; - unsigned int* fb, * phy_fb; - for (; y0 <= y1; y0++) + unsigned short* fb; + unsigned int rgb_16 = GL_RGB_32_to_16(rgb); + for (y = y0; y <= y1; y++) { - x = x0; - fb = m_fb ? &((unsigned int*)m_fb)[y0 * m_width + x] : 0; - phy_fb = &((unsigned int*)m_phy_fb)[y0 * display_width + x]; - *m_phy_write_index = *m_phy_write_index + 1; - for (; x <= x1; x++) + fb = m_fb ? &((unsigned short*)m_fb)[y * m_width + x0] : 0; + if (!fb) { break; } + for (x = x0; x <= x1; x++) { - if (fb) - { - *fb++ = rgb; - } - if (m_is_active && (x < display_width) && (y0 < display_height)) - { - *phy_fb++ = rgb; - } + *fb++ = rgb_16; } } } - else if (m_color_bytes == 2) + else { - int x; - unsigned short* fb, * phy_fb; - rgb = GL_RGB_32_to_16(rgb); - for (; y0 <= y1; y0++) + unsigned int* fb; + for (y = y0; y <= y1; y++) { - x = x0; - fb = m_fb ? &((unsigned short*)m_fb)[y0 * m_width + x] : 0; - phy_fb = &((unsigned short*)m_phy_fb)[y0 * display_width + x]; - *m_phy_write_index = *m_phy_write_index + 1; - for (; x <= x1; x++) + fb = m_fb ? &((unsigned int*)m_fb)[y * m_width + x0] : 0; + if (!fb) { break; } + for (x = x0; x <= x1; x++) { - if (fb) - { - *fb++ = rgb; - } - if (m_is_active && (x < display_width) && (y0 < display_height)) - { - *phy_fb++ = rgb; - } + *fb++ = rgb; } } } + if (!m_is_active) { return; } + m_display->fill_rect(x0, y0, x1, y1, rgb); + *m_phy_write_index = *m_phy_write_index + 1; } - virtual void draw_pixel_on_fb(int x, int y, unsigned int rgb) + virtual void draw_pixel_low_level(int x, int y, unsigned int rgb) { if (m_fb) - { - (m_color_bytes == 4) ? ((unsigned int*)m_fb)[y * m_width + x] = rgb : ((unsigned short*)m_fb)[y * m_width + x] = GL_RGB_32_to_16(rgb); - } - if (m_is_active && (x < m_display->get_width()) && (y < m_display->get_height())) - { - if (m_color_bytes == 4) - { - ((unsigned int*)m_phy_fb)[y * (m_display->get_width()) + x] = rgb; - } - else - { - ((unsigned short*)m_phy_fb)[y * (m_display->get_width()) + x] = GL_RGB_32_to_16(rgb); - } - *m_phy_write_index = *m_phy_write_index + 1; + {//draw pixel on framebuffer of surface + (m_color_bytes == 2) ? ((unsigned short*)m_fb)[y * m_width + x] = GL_RGB_32_to_16(rgb): ((unsigned int*)m_fb)[y * m_width + x] = rgb; } + if (!m_is_active) { return; } + m_display->draw_pixel(x, y, rgb); + *m_phy_write_index = *m_phy_write_index + 1; } void attach_display(c_display* display) { ASSERT(display); m_display = display; - m_phy_fb = display->m_phy_fb; m_phy_write_index = &display->m_phy_write_index; } void set_surface(Z_ORDER_LEVEL max_z_order, c_rect layer_rect) @@ -638,87 +673,22 @@ protected: } int m_width; //in pixels int m_height; //in pixels - int m_color_bytes; //16 bits, 32 bits only + int m_color_bytes; //16 bits, 32 bits for default void* m_fb; //frame buffer you could see c_layer m_layers[Z_ORDER_LEVEL_MAX];//all graphic layers bool m_is_active; //active flag Z_ORDER_LEVEL m_max_zorder; //the highest graphic layer the surface will have Z_ORDER_LEVEL m_top_zorder; //the current highest graphic layer the surface have - void* m_phy_fb; //physical framebufer int* m_phy_write_index; c_display* m_display; }; -class c_surface_no_fb : public c_surface {//No physical framebuffer, render with external graphic interface - friend class c_display; -public: - c_surface_no_fb(unsigned int width, unsigned int height, unsigned int color_bytes, struct EXTERNAL_GFX_OP* gfx_op, Z_ORDER_LEVEL max_zorder = Z_ORDER_LEVEL_0, c_rect overlpa_rect = c_rect()) : c_surface(width, height, color_bytes, max_zorder, overlpa_rect), m_gfx_op(gfx_op) {} -protected: - virtual void fill_rect_on_fb(int x0, int y0, int x1, int y1, unsigned int rgb) - { - if (!m_gfx_op) - { - return; - } - if (m_gfx_op->fill_rect) - { - return m_gfx_op->fill_rect(x0, y0, x1, y1, rgb); - } - if (m_gfx_op->draw_pixel && m_is_active) - { - for (int y = y0; y <= y1; y++) - { - for (int x = x0; x <= x1; x++) - { - m_gfx_op->draw_pixel(x, y, rgb); - } - } - } - if (!m_fb) { return; } - if (m_color_bytes == 4) - { - unsigned int* fb; - for (int y = y0; y <= y1; y++) - { - fb = &((unsigned int*)m_fb)[y0 * m_width + x0]; - for (int x = x0; x <= x1; x++) - { - *fb++ = rgb; - } - } - } - else if (m_color_bytes == 2) - { - unsigned short* fb; - rgb = GL_RGB_32_to_16(rgb); - for (int y = y0; y <= y1; y++) - { - fb = &((unsigned short*)m_fb)[y0 * m_width + x0]; - for (int x = x0; x <= x1; x++) - { - *fb++ = rgb; - } - } - } - } - virtual void draw_pixel_on_fb(int x, int y, unsigned int rgb) - { - if (m_gfx_op && m_gfx_op->draw_pixel && m_is_active) - { - m_gfx_op->draw_pixel(x, y, rgb); - } - if (!m_fb) { return; } - if (m_color_bytes == 4) - { - ((unsigned int*)m_fb)[y * m_width + x] = rgb; - } - else if (m_color_bytes == 2) - { - ((unsigned short*)m_fb)[y * m_width + x] = GL_RGB_32_to_16(rgb); - } - } - struct EXTERNAL_GFX_OP* m_gfx_op;//Rendering by external method -}; -inline c_display::c_display(void* phy_fb, int display_width, int display_height, int surface_width, int surface_height, unsigned int color_bytes, int surface_cnt, EXTERNAL_GFX_OP* gfx_op) : m_width(display_width), m_height(display_height), m_color_bytes(color_bytes), m_phy_fb(phy_fb), m_phy_read_index(0), m_phy_write_index(0), m_surface_cnt(surface_cnt), m_surface_index(0) +inline c_display::c_display(void* phy_fb, int display_width, int display_height, c_surface* surface, DISPLAY_DRIVER* driver) : m_phy_fb(phy_fb), m_width(display_width), m_height(display_height), m_driver(driver), m_phy_read_index(0), m_phy_write_index(0), m_surface_cnt(1), m_surface_index(0) +{ + m_color_bytes = surface->m_color_bytes; + surface->m_is_active = true; + (m_surface_group[0] = surface)->attach_display(this); +} +inline c_display::c_display(void* phy_fb, int display_width, int display_height, int surface_width, int surface_height, unsigned int color_bytes, int surface_cnt, DISPLAY_DRIVER* driver) : m_phy_fb(phy_fb), m_width(display_width), m_height(display_height), m_color_bytes(color_bytes), m_phy_read_index(0), m_phy_write_index(0), m_surface_cnt(surface_cnt), m_driver(driver), m_surface_index(0) { ASSERT(color_bytes == 2 || color_bytes == 4); ASSERT(m_surface_cnt <= SURFACE_CNT_MAX); @@ -726,16 +696,10 @@ inline c_display::c_display(void* phy_fb, int display_width, int display_height, for (int i = 0; i < m_surface_cnt; i++) { - m_surface_group[i] = (phy_fb) ? new c_surface(surface_width, surface_height, color_bytes) : new c_surface_no_fb(surface_width, surface_height, color_bytes, gfx_op); + m_surface_group[i] = new c_surface(surface_width, surface_height, color_bytes); m_surface_group[i]->attach_display(this); } } -inline c_display::c_display(void* phy_fb, int display_width, int display_height, c_surface* surface) : m_width(display_width), m_height(display_height), m_phy_fb(phy_fb), m_phy_read_index(0), m_phy_write_index(0), m_surface_cnt(1), m_surface_index(0) -{ - m_color_bytes = surface->m_color_bytes; - surface->m_is_active = true; - (m_surface_group[0] = surface)->attach_display(this); -} inline c_surface* c_display::alloc_surface(Z_ORDER_LEVEL max_zorder, c_rect layer_rect) { ASSERT(max_zorder < Z_ORDER_LEVEL_MAX && m_surface_index < m_surface_cnt); @@ -744,8 +708,8 @@ inline c_surface* c_display::alloc_surface(Z_ORDER_LEVEL max_zorder, c_rect laye } inline int c_display::swipe_surface(c_surface* s0, c_surface* s1, int x0, int x1, int y0, int y1, int offset) { - int surface_width = s0->get_width(); - int surface_height = s0->get_height(); + register int surface_width = s0->m_width; + register int surface_height = s0->m_height; if (offset < 0 || offset > surface_width || y0 < 0 || y0 >= surface_height || y1 < 0 || y1 >= surface_height || x0 < 0 || x0 >= surface_width || x1 < 0 || x1 >= surface_width) { @@ -767,46 +731,46 @@ inline int c_display::swipe_surface(c_surface* s0, c_surface* s1, int x0, int x1 for (int y = y0; y <= y1; y++) { //Left surface - char* addr_s = ((char*)(s0->m_fb) + (y * (s0->get_width()) + x0 + offset) * m_color_bytes); + char* addr_s = ((char*)(s0->m_fb) + (y * surface_width + x0 + offset) * m_color_bytes); char* addr_d = ((char*)(m_phy_fb)+(y * m_width + x0) * m_color_bytes); memcpy(addr_d, addr_s, (width - offset) * m_color_bytes); //Right surface - addr_s = ((char*)(s1->m_fb) + (y * (s1->get_width()) + x0) * m_color_bytes); + addr_s = ((char*)(s1->m_fb) + (y * surface_width + x0) * m_color_bytes); addr_d = ((char*)(m_phy_fb)+(y * m_width + x0 + (width - offset)) * m_color_bytes); memcpy(addr_d, addr_s, offset * m_color_bytes); } } - else if (m_color_bytes == 4) + else if (m_color_bytes == 2) { - void(*draw_pixel)(int x, int y, unsigned int rgb) = ((c_surface_no_fb*)s0)->m_gfx_op->draw_pixel; + void(*draw_pixel)(int x, int y, unsigned int rgb) = m_driver->draw_pixel; for (int y = y0; y <= y1; y++) { //Left surface for (int x = x0; x <= (x1 - offset); x++) { - draw_pixel(x, y, ((unsigned int*)s0->m_fb)[y * m_width + x + offset]); + draw_pixel(x, y, GL_RGB_16_to_32(((unsigned short*)s0->m_fb)[y * m_width + x + offset])); } //Right surface for (int x = x1 - offset; x <= x1; x++) { - draw_pixel(x, y, ((unsigned int*)s1->m_fb)[y * m_width + x + offset - x1 + x0]); + draw_pixel(x, y, GL_RGB_16_to_32(((unsigned short*)s1->m_fb)[y * m_width + x + offset - x1 + x0])); } } } - else if (m_color_bytes == 2) + else //m_color_bytes == 3/4... { - void(*draw_pixel)(int x, int y, unsigned int rgb) = ((c_surface_no_fb*)s0)->m_gfx_op->draw_pixel; + void(*draw_pixel)(int x, int y, unsigned int rgb) = m_driver->draw_pixel; for (int y = y0; y <= y1; y++) { //Left surface for (int x = x0; x <= (x1 - offset); x++) { - draw_pixel(x, y, GL_RGB_16_to_32(((unsigned short*)s0->m_fb)[y * m_width + x + offset])); + draw_pixel(x, y, ((unsigned int*)s0->m_fb)[y * m_width + x + offset]); } //Right surface for (int x = x1 - offset; x <= x1; x++) { - draw_pixel(x, y, GL_RGB_16_to_32(((unsigned short*)s1->m_fb)[y * m_width + x + offset - x1 + x0])); + draw_pixel(x, y, ((unsigned int*)s1->m_fb)[y * m_width + x + offset - x1 + x0]); } } } @@ -3407,22 +3371,12 @@ private: #ifdef GUILITE_ON c_bitmap_operator the_bitmap_op = c_bitmap_operator(); c_image_operator* c_image::image_operator = &the_bitmap_op; +const void* c_theme::s_font_map[FONT_MAX]; +const void* c_theme::s_image_map[IMAGE_MAX]; +unsigned int c_theme::s_color_map[COLOR_MAX]; +c_lattice_font_op the_lattice_font_op = c_lattice_font_op(); +c_font_operator* c_word::fontOperator = &the_lattice_font_op; #endif - -#ifdef GUILITE_ON - -const void* c_theme::s_font_map[FONT_MAX]; -const void* c_theme::s_image_map[IMAGE_MAX]; -unsigned int c_theme::s_color_map[COLOR_MAX]; - -#endif - -#ifdef GUILITE_ON - -c_lattice_font_op the_lattice_font_op = c_lattice_font_op(); -c_font_operator* c_word::fontOperator = &the_lattice_font_op; - -#endif #ifdef GUILITE_ON #if (defined __linux__) || (defined __APPLE__) #include @@ -4264,11 +4218,7 @@ int c_fifo::write(void* buf, int len) #endif #ifdef GUILITE_ON DIALOG_ARRAY c_dialog::ms_the_dialogs[SURFACE_CNT_MAX]; -#endif -#ifdef GUILITE_ON c_keyboard c_edit::s_keyboard; -#endif -#ifdef GUILITE_ON static c_keyboard_button s_key_0, s_key_1, s_key_2, s_key_3, s_key_4, s_key_5, s_key_6, s_key_7, s_key_8, s_key_9; static c_keyboard_button s_key_A, s_key_B, s_key_C, s_key_D, s_key_E, s_key_F, s_key_G, s_key_H, s_key_I, s_key_J; static c_keyboard_button s_key_K, s_key_L, s_key_M, s_key_N, s_key_O, s_key_P, s_key_Q, s_key_R, s_key_S, s_key_T; @@ -4306,12 +4256,12 @@ WND_TREE g_key_board_children[] = {&s_key_B, 'B', 0, ((KEY_WIDTH / 2) + POS_X(5)), POS_Y(2), KEY_WIDTH, KEY_HEIGHT}, {&s_key_N, 'N', 0, ((KEY_WIDTH / 2) + POS_X(6)), POS_Y(2), KEY_WIDTH, KEY_HEIGHT}, {&s_key_M, 'M', 0, ((KEY_WIDTH / 2) + POS_X(7)), POS_Y(2), KEY_WIDTH, KEY_HEIGHT}, - {&s_key_del, 0x7F, 0, ((KEY_WIDTH / 2) + POS_X(8)), POS_Y(2), DEL_WIDTH, KEY_HEIGHT}, + {&s_key_del,0x7F, 0, ((KEY_WIDTH / 2) + POS_X(8)), POS_Y(2), DEL_WIDTH, KEY_HEIGHT}, //Row 4 - {&s_key_esc, 0x1B, 0, POS_X(0), POS_Y(3), ESC_WIDTH, KEY_HEIGHT}, + {&s_key_esc, 0x1B, 0, POS_X(0), POS_Y(3), ESC_WIDTH, KEY_HEIGHT}, {&s_key_num_switch, 0x90, 0, POS_X(2), POS_Y(3), SWITCH_WIDTH, KEY_HEIGHT}, {&s_key_space, ' ', 0, ((KEY_WIDTH / 2) + POS_X(3)), POS_Y(3), SPACE_WIDTH, KEY_HEIGHT}, - {&s_key_dot, '.', 0, ((KEY_WIDTH / 2) + POS_X(6)), POS_Y(3), DOT_WIDTH, KEY_HEIGHT}, + {&s_key_dot, '.', 0, ((KEY_WIDTH / 2) + POS_X(6)), POS_Y(3), DOT_WIDTH, KEY_HEIGHT}, {&s_key_enter, '\n', 0, POS_X(8), POS_Y(3), ENTER_WIDTH, KEY_HEIGHT}, {0,0,0,0,0,0,0} }; @@ -4326,12 +4276,11 @@ WND_TREE g_number_board_children[] = {&s_key_7, '7', 0, POS_X(0), POS_Y(2), KEY_WIDTH, KEY_HEIGHT}, {&s_key_8, '8', 0, POS_X(1), POS_Y(2), KEY_WIDTH, KEY_HEIGHT}, {&s_key_9, '9', 0, POS_X(2), POS_Y(2), KEY_WIDTH, KEY_HEIGHT}, - - {&s_key_esc, 0x1B, 0, POS_X(0), POS_Y(3), KEY_WIDTH, KEY_HEIGHT}, + {&s_key_esc,0x1B, 0, POS_X(0), POS_Y(3), KEY_WIDTH, KEY_HEIGHT}, {&s_key_0, '0', 0, POS_X(1), POS_Y(3), KEY_WIDTH, KEY_HEIGHT}, - {&s_key_dot, '.', 0, POS_X(2), POS_Y(3), KEY_WIDTH, KEY_HEIGHT}, + {&s_key_dot,'.', 0, POS_X(2), POS_Y(3), KEY_WIDTH, KEY_HEIGHT}, {&s_key_del, 0x7F, 0, POS_X(3), POS_Y(0), KEY_WIDTH, KEY_HEIGHT * 2 + 2}, {&s_key_enter,'\n', 0, POS_X(3), POS_Y(2), KEY_WIDTH, KEY_HEIGHT * 2 + 2}, {0,0,0,0,0,0,0} }; -#endif +#endif \ No newline at end of file diff --git a/HelloNets/UIcode/UIcode.cpp b/HelloNets/UIcode/UIcode.cpp index 14f7b8881800c2e9c2af8224c03de0fa89df3ee9..9a390190c4f0b83bf1f54a5577bc58dd11a4d0fa 100644 --- a/HelloNets/UIcode/UIcode.cpp +++ b/HelloNets/UIcode/UIcode.cpp @@ -112,22 +112,12 @@ void trigger(int x, int y, bool is_down) } } -void run(void* phy_fb, int screen_width, int screen_height, int color_bytes, struct EXTERNAL_GFX_OP* gfx_op) +void run(void* phy_fb, int screen_width, int screen_height, int color_bytes, struct DISPLAY_DRIVER* driver) { - if (phy_fb) - { - static c_surface surface(screen_width, screen_height, color_bytes, Z_ORDER_LEVEL_0); - static c_display display(phy_fb, screen_width, screen_height, &surface); - s_surface = &surface; - s_display = &display; - } - else - {//for MCU without framebuffer - static c_surface_no_fb surface_no_fb(screen_width, screen_height, color_bytes, gfx_op, Z_ORDER_LEVEL_0); - static c_display display(phy_fb, screen_width, screen_height, &surface_no_fb); - s_surface = &surface_no_fb; - s_display = &display; - } + static c_surface surface(screen_width, screen_height, color_bytes, Z_ORDER_LEVEL_0); + static c_display display(phy_fb, screen_width, screen_height, &surface, driver); + s_surface = &surface; + s_display = &display; s_surface->fill_rect(0, 0, screen_width - 1, screen_height - 1, GL_RGB(0, 0, 0), Z_ORDER_LEVEL_0); @@ -194,8 +184,8 @@ void run(void* phy_fb, int screen_width, int screen_height, int color_bytes, str } } //////////////////////// interface for all platform //////////////////////// -extern "C" void startHelloNets(void* phy_fb, int width, int height, int color_bytes, struct EXTERNAL_GFX_OP* gfx_op) { - run(phy_fb, width, height, color_bytes, gfx_op); +extern "C" void startHelloNets(void* phy_fb, int width, int height, int color_bytes, struct DISPLAY_DRIVER* driver) { + run(phy_fb, width, height, color_bytes, driver); } void sendTouch2HelloNets(int x, int y, bool is_down) diff --git a/HelloNoTouch/BuildLinux/.sync_build.sh b/HelloNoTouch/BuildLinux/.sync_build.sh index 49cff5b473ac606967676ebefa6f0d333e301227..ce63bb63a4077137b48e1e7339bb7e9e386ec024 100644 --- a/HelloNoTouch/BuildLinux/.sync_build.sh +++ b/HelloNoTouch/BuildLinux/.sync_build.sh @@ -1,5 +1,6 @@ if [ "$#" -ne 1 ]; then - echo "Invalid arguments" + echo "Do testing" + ./xWindow 240 320 | ./HelloNoTouch shared-fb exit -1 fi diff --git a/HelloNoTouch/BuildLinux/main.cpp b/HelloNoTouch/BuildLinux/main.cpp index 19e4ffe7671ddd7fca3e42e2e711dcb8838626ef..19421e3a8adb3860278c81ce37ccc9d5a9a382ae 100644 --- a/HelloNoTouch/BuildLinux/main.cpp +++ b/HelloNoTouch/BuildLinux/main.cpp @@ -10,7 +10,7 @@ #include #include -extern "C" void startHelloNoTouch(void* phy_fb, int width, int height, int color_bytes, struct EXTERNAL_GFX_OP* gfx_op); +extern "C" void startHelloNoTouch(void* phy_fb, int width, int height, int color_bytes, struct DISPLAY_DRIVER* driver); extern void init_std_io(); static void* get_embeded_fb_in_display_app(int shared_id); diff --git a/HelloNoTouch/BuildMFC/HelloNoTouchDlg.cpp b/HelloNoTouch/BuildMFC/HelloNoTouchDlg.cpp index b15690f5156f3c21d14dc4a8535c4dcbc1c0d28b..f179e0e92d7c09b5514d1efbcc93f9b39fe27738 100644 Binary files a/HelloNoTouch/BuildMFC/HelloNoTouchDlg.cpp and b/HelloNoTouch/BuildMFC/HelloNoTouchDlg.cpp differ diff --git a/HelloNoTouch/BuildMFC/HelloNoTouchDlg.h b/HelloNoTouch/BuildMFC/HelloNoTouchDlg.h index 569c00b783be2102f834fdcca8198d27d54311cf..52e0d259b001a2a161603354faf7de3a5b32cbe7 100644 Binary files a/HelloNoTouch/BuildMFC/HelloNoTouchDlg.h and b/HelloNoTouch/BuildMFC/HelloNoTouchDlg.h differ diff --git a/HelloNoTouch/BuildSTM32F103-Keil/USER/main.c b/HelloNoTouch/BuildSTM32F103-Keil/USER/main.c index c420e8ade4497342eb07ece48db4143676075811..9f0e3e88ee8e2afe78b51970d8a1aac5cce3deb0 100644 --- a/HelloNoTouch/BuildSTM32F103-Keil/USER/main.c +++ b/HelloNoTouch/BuildSTM32F103-Keil/USER/main.c @@ -15,12 +15,12 @@ void gfx_draw_pixel(int x, int y, unsigned int rgb) //void gfx_fill_rect(int x0, int y0, int x1, int y1, unsigned int rgb){} //UI entry -struct EXTERNAL_GFX_OP +struct DISPLAY_DRIVER { void (*draw_pixel)(int x, int y, unsigned int rgb); void (*fill_rect)(int x0, int y0, int x1, int y1, unsigned int rgb); -} my_gfx_op; -extern void startHelloNoTouch(void* phy_fb, int width, int height, int color_bytes, struct EXTERNAL_GFX_OP* gfx_op); +} my_driver; +extern void startHelloNoTouch(void* phy_fb, int width, int height, int color_bytes, struct DISPLAY_DRIVER* driver); extern void sendKey2HelloNoTouch(unsigned int key); int main(void) @@ -31,9 +31,9 @@ int main(void) LCD_Init(); //Link your LCD driver & start UI: - my_gfx_op.draw_pixel = gfx_draw_pixel; - my_gfx_op.fill_rect = NULL;//gfx_fill_rect; - startHelloNoTouch(NULL, 240, 320, 2, &my_gfx_op); + my_driver.draw_pixel = gfx_draw_pixel; + my_driver.fill_rect = NULL;//gfx_fill_rect; + startHelloNoTouch(NULL, 240, 320, 2, &my_driver); while(1) { diff --git a/HelloNoTouch/BuildWin32/HelloNoTouch.cpp b/HelloNoTouch/BuildWin32/HelloNoTouch.cpp index fc640b188f958909910149e19dd691bbd290ce10..c4b47ee0af3f84c50beabe008a447032462ef70b 100644 --- a/HelloNoTouch/BuildWin32/HelloNoTouch.cpp +++ b/HelloNoTouch/BuildWin32/HelloNoTouch.cpp @@ -161,7 +161,7 @@ LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam) } //////////////////////// HelloNoTouch Interface //////////////////////// -extern "C" void startHelloNoTouch(void* phy_fb, int width, int height, int color_bytes, struct EXTERNAL_GFX_OP* gfx_op); +extern "C" void startHelloNoTouch(void* phy_fb, int width, int height, int color_bytes, struct DISPLAY_DRIVER* driver); DWORD WINAPI ThreadHelloNoTouch(LPVOID pParam) { diff --git a/HelloNoTouch/UIcode/GuiLite.h b/HelloNoTouch/UIcode/GuiLite.h index c4fc88a51476d2c8309c3e55e1270e13784fc510..80550e1632ad7bc82541a2edbb0f7f8f5937954f 100644 --- a/HelloNoTouch/UIcode/GuiLite.h +++ b/HelloNoTouch/UIcode/GuiLite.h @@ -1,107 +1,94 @@ #pragma once - -#define REAL_TIME_TASK_CYCLE_MS 50 -#define MAX(a,b) (((a)>(b))?(a):(b)) -#define MIN(a,b) (((a)<(b))?(a):(b)) - -#define GL_ARGB(a, r, g, b) ((((unsigned int)(a)) << 24) | (((unsigned int)(r)) << 16) | (((unsigned int)(g)) << 8) | ((unsigned int)(b))) -#define GL_ARGB_A(rgb) ((((unsigned int)(rgb)) >> 24) & 0xFF) - -#define GL_RGB(r, g, b) ((0xFF << 24) | (((unsigned int)(r)) << 16) | (((unsigned int)(g)) << 8) | ((unsigned int)(b))) -#define GL_RGB_R(rgb) ((((unsigned int)(rgb)) >> 16) & 0xFF) -#define GL_RGB_G(rgb) ((((unsigned int)(rgb)) >> 8) & 0xFF) -#define GL_RGB_B(rgb) (((unsigned int)(rgb)) & 0xFF) -#define GL_RGB_32_to_16(rgb) (((((unsigned int)(rgb)) & 0xFF) >> 3) | ((((unsigned int)(rgb)) & 0xFC00) >> 5) | ((((unsigned int)(rgb)) & 0xF80000) >> 8)) -#define GL_RGB_16_to_32(rgb) ((0xFF << 24) | ((((unsigned int)(rgb)) & 0x1F) << 3) | ((((unsigned int)(rgb)) & 0x7E0) << 5) | ((((unsigned int)(rgb)) & 0xF800) << 8)) - -#define ALIGN_HCENTER 0x00000000L -#define ALIGN_LEFT 0x01000000L -#define ALIGN_RIGHT 0x02000000L -#define ALIGN_HMASK 0x03000000L - -#define ALIGN_VCENTER 0x00000000L -#define ALIGN_TOP 0x00100000L -#define ALIGN_BOTTOM 0x00200000L -#define ALIGN_VMASK 0x00300000L - -typedef struct -{ - unsigned short year; - unsigned short month; - unsigned short date; - unsigned short day; - unsigned short hour; - unsigned short minute; - unsigned short second; -}T_TIME; - -void register_debug_function(void(*my_assert)(const char* file, int line), void(*my_log_out)(const char* log)); -void _assert(const char* file, int line); -#define ASSERT(condition) \ - do{ \ - if(!(condition))_assert(__FILE__, __LINE__);\ - }while(0) -void log_out(const char* log); - -long get_time_in_second(); -T_TIME second_to_day(long second); -T_TIME get_time(); - -void start_real_timer(void (*func)(void* arg)); -void register_timer(int milli_second, void func(void* param), void* param); - -unsigned int get_cur_thread_id(); -void create_thread(unsigned long* thread_id, void* attr, void *(*start_routine) (void *), void* arg); -void thread_sleep(unsigned int milli_seconds); -int build_bmp(const char *filename, unsigned int width, unsigned int height, unsigned char *data); - -#define FIFO_BUFFER_LEN 1024 -class c_fifo -{ -public: - c_fifo(); - int read(void* buf, int len); - int write(void* buf, int len); -private: - unsigned char m_buf[FIFO_BUFFER_LEN]; - int m_head; - int m_tail; - void* m_read_sem; - void* m_write_mutex; -}; - -class c_rect -{ -public: - c_rect(){ m_left = m_top = m_right = m_bottom = -1; } - c_rect(int left, int top, int width, int height) - { - set_rect(left, top, width, height); - } - void set_rect(int left, int top, int width, int height) - { - ASSERT(width > 0 && height > 0); - m_left = left; - m_top = top; - m_right = left + width - 1; - m_bottom = top + height -1; - } - bool pt_in_rect(int x, int y) const - { - return x >= m_left && x <= m_right && y >= m_top && y <= m_bottom; - } - int operator==(const c_rect& rect) const - { - return (m_left == rect.m_left) && (m_top == rect.m_top) && (m_right == rect.m_right) && (m_bottom == rect.m_bottom); - } - int width() const { return m_right - m_left + 1; } - int height() const { return m_bottom - m_top + 1 ; } - - int m_left; - int m_top; - int m_right; - int m_bottom; -}; +#define REAL_TIME_TASK_CYCLE_MS 50 +#define MAX(a,b) (((a)>(b))?(a):(b)) +#define MIN(a,b) (((a)<(b))?(a):(b)) +#define GL_ARGB(a, r, g, b) ((((unsigned int)(a)) << 24) | (((unsigned int)(r)) << 16) | (((unsigned int)(g)) << 8) | ((unsigned int)(b))) +#define GL_ARGB_A(rgb) ((((unsigned int)(rgb)) >> 24) & 0xFF) +#define GL_RGB(r, g, b) ((0xFF << 24) | (((unsigned int)(r)) << 16) | (((unsigned int)(g)) << 8) | ((unsigned int)(b))) +#define GL_RGB_R(rgb) ((((unsigned int)(rgb)) >> 16) & 0xFF) +#define GL_RGB_G(rgb) ((((unsigned int)(rgb)) >> 8) & 0xFF) +#define GL_RGB_B(rgb) (((unsigned int)(rgb)) & 0xFF) +#define GL_RGB_32_to_16(rgb) (((((unsigned int)(rgb)) & 0xFF) >> 3) | ((((unsigned int)(rgb)) & 0xFC00) >> 5) | ((((unsigned int)(rgb)) & 0xF80000) >> 8)) +#define GL_RGB_16_to_32(rgb) ((0xFF << 24) | ((((unsigned int)(rgb)) & 0x1F) << 3) | ((((unsigned int)(rgb)) & 0x7E0) << 5) | ((((unsigned int)(rgb)) & 0xF800) << 8)) +#define ALIGN_HCENTER 0x00000000L +#define ALIGN_LEFT 0x01000000L +#define ALIGN_RIGHT 0x02000000L +#define ALIGN_HMASK 0x03000000L +#define ALIGN_VCENTER 0x00000000L +#define ALIGN_TOP 0x00100000L +#define ALIGN_BOTTOM 0x00200000L +#define ALIGN_VMASK 0x00300000L +typedef struct +{ + unsigned short year; + unsigned short month; + unsigned short date; + unsigned short day; + unsigned short hour; + unsigned short minute; + unsigned short second; +}T_TIME; +void register_debug_function(void(*my_assert)(const char* file, int line), void(*my_log_out)(const char* log)); +void _assert(const char* file, int line); +#define ASSERT(condition) \ + do{ \ + if(!(condition))_assert(__FILE__, __LINE__);\ + }while(0) +void log_out(const char* log); +long get_time_in_second(); +T_TIME second_to_day(long second); +T_TIME get_time(); +void start_real_timer(void (*func)(void* arg)); +void register_timer(int milli_second, void func(void* param), void* param); +unsigned int get_cur_thread_id(); +void create_thread(unsigned long* thread_id, void* attr, void *(*start_routine) (void *), void* arg); +void thread_sleep(unsigned int milli_seconds); +int build_bmp(const char *filename, unsigned int width, unsigned int height, unsigned char *data); +#define FIFO_BUFFER_LEN 1024 +class c_fifo +{ +public: + c_fifo(); + int read(void* buf, int len); + int write(void* buf, int len); +private: + unsigned char m_buf[FIFO_BUFFER_LEN]; + int m_head; + int m_tail; + void* m_read_sem; + void* m_write_mutex; +}; +class c_rect +{ +public: + c_rect(){ m_left = m_top = m_right = m_bottom = -1; } + c_rect(int left, int top, int width, int height) + { + set_rect(left, top, width, height); + } + void set_rect(int left, int top, int width, int height) + { + ASSERT(width > 0 && height > 0); + m_left = left; + m_top = top; + m_right = left + width - 1; + m_bottom = top + height -1; + } + bool pt_in_rect(int x, int y) const + { + return x >= m_left && x <= m_right && y >= m_top && y <= m_bottom; + } + int operator==(const c_rect& rect) const + { + return (m_left == rect.m_left) && (m_top == rect.m_top) && (m_right == rect.m_right) && (m_bottom == rect.m_bottom); + } + int width() const { return m_right - m_left + 1; } + int height() const { return m_bottom - m_top + 1 ; } + int m_left; + int m_top; + int m_right; + int m_bottom; +}; //BITMAP typedef struct struct_bitmap_info { @@ -238,7 +225,7 @@ typedef enum Z_ORDER_LEVEL_2,//highest graphic level Z_ORDER_LEVEL_MAX }Z_ORDER_LEVEL; -struct EXTERNAL_GFX_OP +struct DISPLAY_DRIVER { void(*draw_pixel)(int x, int y, unsigned int rgb); void(*fill_rect)(int x0, int y0, int x1, int y1, unsigned int rgb); @@ -247,18 +234,19 @@ class c_surface; class c_display { friend class c_surface; public: - inline c_display(void* phy_fb, int display_width, int display_height, int surface_width, int surface_height, unsigned int color_bytes, int surface_cnt, EXTERNAL_GFX_OP* gfx_op = 0);//multiple surface or surface_no_fb - inline c_display(void* phy_fb, int display_width, int display_height, c_surface* surface);//single custom surface - inline c_surface* alloc_surface(Z_ORDER_LEVEL max_zorder, c_rect layer_rect = c_rect());//for multiple surfaces + inline c_display(void* phy_fb, int display_width, int display_height, c_surface* surface, DISPLAY_DRIVER* driver = 0);//single custom surface + inline c_display(void* phy_fb, int display_width, int display_height, int surface_width, int surface_height, unsigned int color_bytes, int surface_cnt, DISPLAY_DRIVER* driver = 0);//multiple surface + inline c_surface* alloc_surface(Z_ORDER_LEVEL max_zorder, c_rect layer_rect = c_rect());//for slide group inline int swipe_surface(c_surface* s0, c_surface* s1, int x0, int x1, int y0, int y1, int offset); int get_width() { return m_width; } int get_height() { return m_height; } + void* get_phy_fb() { return m_phy_fb; } void* get_updated_fb(int* width, int* height, bool force_update = false) { if (width && height) { - *width = get_width(); - *height = get_height(); + *width = m_width; + *height = m_height; } if (force_update) { @@ -277,35 +265,123 @@ public: { return -1; } - int width = get_width(); - int height = get_height(); //16 bits framebuffer if (m_color_bytes == 2) { - return build_bmp(file_name, width, height, (unsigned char*)m_phy_fb); + return build_bmp(file_name, m_width, m_height, (unsigned char*)m_phy_fb); } //32 bits framebuffer - unsigned short* p_bmp565_data = new unsigned short[width * height]; + unsigned short* p_bmp565_data = new unsigned short[m_width * m_height]; unsigned int* p_raw_data = (unsigned int*)m_phy_fb; - for (int i = 0; i < width * height; i++) + for (int i = 0; i < m_width * m_height; i++) { unsigned int rgb = *p_raw_data++; p_bmp565_data[i] = GL_RGB_32_to_16(rgb); } - int ret = build_bmp(file_name, width, height, (unsigned char*)p_bmp565_data); + int ret = build_bmp(file_name, m_width, m_height, (unsigned char*)p_bmp565_data); delete[]p_bmp565_data; return ret; } -private: - int m_width; //in pixels - int m_height; //in pixels - int m_color_bytes; //16 bits, 32 bits only - void* m_phy_fb; //physical framebuffer +protected: + virtual void draw_pixel(int x, int y, unsigned int rgb) + { + if ((x >= m_width) || (y >= m_height)) { return; } + if (m_driver && m_driver->draw_pixel) + { + return m_driver->draw_pixel(x, y, rgb); + } + if (m_color_bytes == 2) + { + ((unsigned short*)m_phy_fb)[y * m_width + x] = GL_RGB_32_to_16(rgb); + } + else + { + ((unsigned int*)m_phy_fb)[y * m_width + x] = rgb; + } + } + virtual void fill_rect(int x0, int y0, int x1, int y1, unsigned int rgb) + { + if (m_driver && m_driver->fill_rect) + { + return m_driver->fill_rect(x0, y0, x1, y1, rgb); + } + if (m_driver && m_driver->draw_pixel) + { + for (int y = y0; y <= y1; y++) + { + for (int x = x0; x <= x1; x++) + { + m_driver->draw_pixel(x, y, rgb); + } + } + return; + } + register int _width = m_width; + register int _height = m_height; + int x, y; + if (m_color_bytes == 2) + { + unsigned short* phy_fb; + unsigned int rgb_16 = GL_RGB_32_to_16(rgb); + for (y = y0; y <= y1; y++) + { + phy_fb = &((unsigned short*)m_phy_fb)[y * _width + x0]; + for (x = x0; x <= x1; x++) + { + if ((x < _width) && (y < _height)) + { + *phy_fb++ = rgb_16; + } + } + } + } + else + { + unsigned int* phy_fb; + for (y = y0; y <= y1; y++) + { + phy_fb = &((unsigned int*)m_phy_fb)[y * _width + x0]; + for (x = x0; x <= x1; x++) + { + if ((x < _width) && (y < _height)) + { + *phy_fb++ = rgb; + } + } + } + } + } + virtual int flush_screen(int left, int top, int right, int bottom, void* fb, int fb_width) + { + if ((0 == m_phy_fb) || (0 == fb)) + { + return -1; + } + register int _width = m_width; + register int _height = m_height; + left = (left >= _width) ? (_width - 1) : left; + right = (right >= _width) ? (_width - 1) : right; + top = (top >= _height) ? (_height - 1) : top; + bottom = (bottom >= _height) ? (_height - 1) : bottom; + for (int y = top; y < bottom; y++) + { + void* s_addr = (char*)fb + ((y * fb_width + left) * m_color_bytes); + void* d_addr = (char*)m_phy_fb + ((y * _width + left) * m_color_bytes); + memcpy(d_addr, s_addr, (right - left) * m_color_bytes); + } + return 0; + } + int m_width; //in pixels + int m_height; //in pixels + int m_color_bytes; //16/32 bits for default + void* m_phy_fb; //physical framebuffer for default + struct DISPLAY_DRIVER* m_driver; //Rendering by external method without default physical framebuffer int m_phy_read_index; int m_phy_write_index; c_surface* m_surface_group[SURFACE_CNT_MAX]; int m_surface_cnt; //surface count int m_surface_index; + }; class c_layer { @@ -317,12 +393,10 @@ public: class c_surface { friend class c_display; friend class c_bitmap_operator; public: - c_surface(unsigned int width, unsigned int height, unsigned int color_bytes, Z_ORDER_LEVEL max_zorder = Z_ORDER_LEVEL_0, c_rect overlpa_rect = c_rect()) : m_width(width), m_height(height), m_color_bytes(color_bytes), m_fb(0), m_is_active(false), m_top_zorder(Z_ORDER_LEVEL_0), m_phy_fb(0), m_phy_write_index(0), m_display(0) + c_surface(unsigned int width, unsigned int height, unsigned int color_bytes, Z_ORDER_LEVEL max_zorder = Z_ORDER_LEVEL_0, c_rect overlpa_rect = c_rect()) : m_width(width), m_height(height), m_color_bytes(color_bytes), m_fb(0), m_is_active(false), m_top_zorder(Z_ORDER_LEVEL_0), m_phy_write_index(0), m_display(0) { (overlpa_rect == c_rect()) ? set_surface(max_zorder, c_rect(0, 0, width - 1, height - 1)) : set_surface(max_zorder, overlpa_rect); } - int get_width() { return m_width; } - int get_height() { return m_height; } unsigned int get_pixel(int x, int y, unsigned int z_order) { if (x >= m_width || y >= m_height || x < 0 || y < 0 || z_order >= Z_ORDER_LEVEL_MAX) @@ -332,15 +406,15 @@ public: } if (m_layers[z_order].fb) { - return (m_color_bytes == 4) ? ((unsigned int*)(m_layers[z_order].fb))[y * m_width + x] : GL_RGB_16_to_32(((unsigned short*)(m_layers[z_order].fb))[y * m_width + x]); + return (m_color_bytes == 2) ? GL_RGB_16_to_32(((unsigned short*)(m_layers[z_order].fb))[y * m_width + x]) : ((unsigned int*)(m_layers[z_order].fb))[y * m_width + x]; } else if (m_fb) { - return (m_color_bytes == 4) ? ((unsigned int*)m_fb)[y * m_width + x] : GL_RGB_16_to_32(((unsigned short*)m_fb)[y * m_width + x]); + return (m_color_bytes == 2) ? GL_RGB_16_to_32(((unsigned short*)m_fb)[y * m_width + x]) : ((unsigned int*)m_fb)[y * m_width + x]; } - else if (m_phy_fb) + else if (m_display->m_phy_fb) { - return (m_color_bytes == 4) ? ((unsigned int*)m_phy_fb)[y * m_width + x] : GL_RGB_16_to_32(((unsigned short*)m_phy_fb)[y * m_width + x]); + return (m_color_bytes == 2) ? GL_RGB_16_to_32(((unsigned short*)m_display->m_phy_fb)[y * m_width + x]) : ((unsigned int*)m_display->m_phy_fb)[y * m_width + x]; } return 0; } @@ -357,7 +431,7 @@ public: } if (z_order == m_max_zorder) { - return draw_pixel_on_fb(x, y, rgb); + return draw_pixel_low_level(x, y, rgb); } if (z_order > (unsigned int)m_top_zorder) @@ -367,19 +441,19 @@ public: if (m_layers[z_order].rect.pt_in_rect(x, y)) { c_rect layer_rect = m_layers[z_order].rect; - if (m_color_bytes == 4) + if (m_color_bytes == 2) { - ((unsigned int*)(m_layers[z_order].fb))[(x - layer_rect.m_left) + (y - layer_rect.m_top) * layer_rect.width()] = rgb; + ((unsigned short*)(m_layers[z_order].fb))[(x - layer_rect.m_left) + (y - layer_rect.m_top) * layer_rect.width()] = GL_RGB_32_to_16(rgb); } else { - ((unsigned short*)(m_layers[z_order].fb))[(x - layer_rect.m_left) + (y - layer_rect.m_top) * layer_rect.width()] = GL_RGB_32_to_16(rgb); + ((unsigned int*)(m_layers[z_order].fb))[(x - layer_rect.m_left) + (y - layer_rect.m_top) * layer_rect.width()] = rgb; } } if (z_order == m_top_zorder) { - return draw_pixel_on_fb(x, y, rgb); + return draw_pixel_low_level(x, y, rgb); } bool be_overlapped = false; for (unsigned int tmp_z_order = Z_ORDER_LEVEL_MAX - 1; tmp_z_order > z_order; tmp_z_order--) @@ -392,7 +466,7 @@ public: } if (!be_overlapped) { - draw_pixel_on_fb(x, y, rgb); + draw_pixel_low_level(x, y, rgb); } } virtual void fill_rect(int x0, int y0, int x1, int y1, unsigned int rgb, unsigned int z_order) @@ -403,7 +477,7 @@ public: y1 = (y1 > (m_height - 1)) ? (m_height - 1) : y1; if (z_order == m_max_zorder) { - return fill_rect_on_fb(x0, y0, x1, y1, rgb); + return fill_rect_low_level(x0, y0, x1, y1, rgb); } if (z_order == m_top_zorder) { @@ -416,18 +490,18 @@ public: { if (layer_rect.pt_in_rect(x, y)) { - if (m_color_bytes == 4) + if (m_color_bytes == 2) { - ((unsigned int*)m_layers[z_order].fb)[(y - layer_rect.m_top) * layer_rect.width() + (x - layer_rect.m_left)] = rgb; + ((unsigned short*)m_layers[z_order].fb)[(y - layer_rect.m_top) * layer_rect.width() + (x - layer_rect.m_left)] = rgb_16; } else { - ((unsigned short*)m_layers[z_order].fb)[(y - layer_rect.m_top) * layer_rect.width() + (x - layer_rect.m_left)] = rgb_16; + ((unsigned int*)m_layers[z_order].fb)[(y - layer_rect.m_top) * layer_rect.width() + (x - layer_rect.m_left)] = rgb; } } } } - return fill_rect_on_fb(x0, y0, x1, y1, rgb); + return fill_rect_low_level(x0, y0, x1, y1, rgb); } for (; y0 <= y1; y0++) { @@ -499,27 +573,16 @@ public: } int flush_screen(int left, int top, int right, int bottom) { - if (left < 0 || left >= m_width || right < 0 || right >= m_width || - top < 0 || top >= m_height || bottom < 0 || bottom >= m_height) - { - ASSERT(false); - } - if (!m_is_active || (0 == m_phy_fb) || (0 == m_fb)) + if (!m_is_active) { return -1; } - int display_width = m_display->get_width(); - int display_height = m_display->get_height(); - left = (left >= display_width) ? (display_width - 1) : left; - right = (right >= display_width) ? (display_width - 1) : right; - top = (top >= display_height) ? (display_height - 1) : top; - bottom = (bottom >= display_height) ? (display_height - 1) : bottom; - for (int y = top; y < bottom; y++) + if (left < 0 || left >= m_width || right < 0 || right >= m_width || + top < 0 || top >= m_height || bottom < 0 || bottom >= m_height) { - void* s_addr = (char*)m_fb + ((y * m_width + left) * m_color_bytes); - void* d_addr = (char*)m_phy_fb + ((y * display_width + left) * m_color_bytes); - memcpy(d_addr, s_addr, (right - left) * m_color_bytes); + ASSERT(false); } + m_display->flush_screen(left, top, right, bottom, m_fb, m_width); *m_phy_write_index = *m_phy_write_index + 1; return 0; } @@ -537,90 +600,62 @@ public: { for (int x = rect.m_left; x <= rect.m_right; x++) { - unsigned int rgb = (m_color_bytes == 4) ? ((unsigned int*)fb)[(x - layer_rect.m_left) + (y - layer_rect.m_top) * width] : GL_RGB_16_to_32(((unsigned short*)fb)[(x - layer_rect.m_left) + (y - layer_rect.m_top) * width]); - draw_pixel_on_fb(x, y, rgb); + unsigned int rgb = (m_color_bytes == 2) ? GL_RGB_16_to_32(((unsigned short*)fb)[(x - layer_rect.m_left) + (y - layer_rect.m_top) * width]) : ((unsigned int*)fb)[(x - layer_rect.m_left) + (y - layer_rect.m_top) * width]; + draw_pixel_low_level(x, y, rgb); } } return 0; } void set_active(bool flag) { m_is_active = flag; } protected: - virtual void fill_rect_on_fb(int x0, int y0, int x1, int y1, unsigned int rgb) - { - int display_width = m_display->get_width(); - int display_height = m_display->get_height(); - if (m_color_bytes == 4) + virtual void fill_rect_low_level(int x0, int y0, int x1, int y1, unsigned int rgb) + {//fill rect on framebuffer of surface + int x, y; + if (m_color_bytes == 2) { - int x; - unsigned int* fb, * phy_fb; - for (; y0 <= y1; y0++) + unsigned short* fb; + unsigned int rgb_16 = GL_RGB_32_to_16(rgb); + for (y = y0; y <= y1; y++) { - x = x0; - fb = m_fb ? &((unsigned int*)m_fb)[y0 * m_width + x] : 0; - phy_fb = &((unsigned int*)m_phy_fb)[y0 * display_width + x]; - *m_phy_write_index = *m_phy_write_index + 1; - for (; x <= x1; x++) + fb = m_fb ? &((unsigned short*)m_fb)[y * m_width + x0] : 0; + if (!fb) { break; } + for (x = x0; x <= x1; x++) { - if (fb) - { - *fb++ = rgb; - } - if (m_is_active && (x < display_width) && (y0 < display_height)) - { - *phy_fb++ = rgb; - } + *fb++ = rgb_16; } } } - else if (m_color_bytes == 2) + else { - int x; - unsigned short* fb, * phy_fb; - rgb = GL_RGB_32_to_16(rgb); - for (; y0 <= y1; y0++) + unsigned int* fb; + for (y = y0; y <= y1; y++) { - x = x0; - fb = m_fb ? &((unsigned short*)m_fb)[y0 * m_width + x] : 0; - phy_fb = &((unsigned short*)m_phy_fb)[y0 * display_width + x]; - *m_phy_write_index = *m_phy_write_index + 1; - for (; x <= x1; x++) + fb = m_fb ? &((unsigned int*)m_fb)[y * m_width + x0] : 0; + if (!fb) { break; } + for (x = x0; x <= x1; x++) { - if (fb) - { - *fb++ = rgb; - } - if (m_is_active && (x < display_width) && (y0 < display_height)) - { - *phy_fb++ = rgb; - } + *fb++ = rgb; } } } + if (!m_is_active) { return; } + m_display->fill_rect(x0, y0, x1, y1, rgb); + *m_phy_write_index = *m_phy_write_index + 1; } - virtual void draw_pixel_on_fb(int x, int y, unsigned int rgb) + virtual void draw_pixel_low_level(int x, int y, unsigned int rgb) { if (m_fb) - { - (m_color_bytes == 4) ? ((unsigned int*)m_fb)[y * m_width + x] = rgb : ((unsigned short*)m_fb)[y * m_width + x] = GL_RGB_32_to_16(rgb); - } - if (m_is_active && (x < m_display->get_width()) && (y < m_display->get_height())) - { - if (m_color_bytes == 4) - { - ((unsigned int*)m_phy_fb)[y * (m_display->get_width()) + x] = rgb; - } - else - { - ((unsigned short*)m_phy_fb)[y * (m_display->get_width()) + x] = GL_RGB_32_to_16(rgb); - } - *m_phy_write_index = *m_phy_write_index + 1; + {//draw pixel on framebuffer of surface + (m_color_bytes == 2) ? ((unsigned short*)m_fb)[y * m_width + x] = GL_RGB_32_to_16(rgb): ((unsigned int*)m_fb)[y * m_width + x] = rgb; } + if (!m_is_active) { return; } + m_display->draw_pixel(x, y, rgb); + *m_phy_write_index = *m_phy_write_index + 1; } void attach_display(c_display* display) { ASSERT(display); m_display = display; - m_phy_fb = display->m_phy_fb; m_phy_write_index = &display->m_phy_write_index; } void set_surface(Z_ORDER_LEVEL max_z_order, c_rect layer_rect) @@ -638,87 +673,22 @@ protected: } int m_width; //in pixels int m_height; //in pixels - int m_color_bytes; //16 bits, 32 bits only + int m_color_bytes; //16 bits, 32 bits for default void* m_fb; //frame buffer you could see c_layer m_layers[Z_ORDER_LEVEL_MAX];//all graphic layers bool m_is_active; //active flag Z_ORDER_LEVEL m_max_zorder; //the highest graphic layer the surface will have Z_ORDER_LEVEL m_top_zorder; //the current highest graphic layer the surface have - void* m_phy_fb; //physical framebufer int* m_phy_write_index; c_display* m_display; }; -class c_surface_no_fb : public c_surface {//No physical framebuffer, render with external graphic interface - friend class c_display; -public: - c_surface_no_fb(unsigned int width, unsigned int height, unsigned int color_bytes, struct EXTERNAL_GFX_OP* gfx_op, Z_ORDER_LEVEL max_zorder = Z_ORDER_LEVEL_0, c_rect overlpa_rect = c_rect()) : c_surface(width, height, color_bytes, max_zorder, overlpa_rect), m_gfx_op(gfx_op) {} -protected: - virtual void fill_rect_on_fb(int x0, int y0, int x1, int y1, unsigned int rgb) - { - if (!m_gfx_op) - { - return; - } - if (m_gfx_op->fill_rect) - { - return m_gfx_op->fill_rect(x0, y0, x1, y1, rgb); - } - if (m_gfx_op->draw_pixel && m_is_active) - { - for (int y = y0; y <= y1; y++) - { - for (int x = x0; x <= x1; x++) - { - m_gfx_op->draw_pixel(x, y, rgb); - } - } - } - if (!m_fb) { return; } - if (m_color_bytes == 4) - { - unsigned int* fb; - for (int y = y0; y <= y1; y++) - { - fb = &((unsigned int*)m_fb)[y0 * m_width + x0]; - for (int x = x0; x <= x1; x++) - { - *fb++ = rgb; - } - } - } - else if (m_color_bytes == 2) - { - unsigned short* fb; - rgb = GL_RGB_32_to_16(rgb); - for (int y = y0; y <= y1; y++) - { - fb = &((unsigned short*)m_fb)[y0 * m_width + x0]; - for (int x = x0; x <= x1; x++) - { - *fb++ = rgb; - } - } - } - } - virtual void draw_pixel_on_fb(int x, int y, unsigned int rgb) - { - if (m_gfx_op && m_gfx_op->draw_pixel && m_is_active) - { - m_gfx_op->draw_pixel(x, y, rgb); - } - if (!m_fb) { return; } - if (m_color_bytes == 4) - { - ((unsigned int*)m_fb)[y * m_width + x] = rgb; - } - else if (m_color_bytes == 2) - { - ((unsigned short*)m_fb)[y * m_width + x] = GL_RGB_32_to_16(rgb); - } - } - struct EXTERNAL_GFX_OP* m_gfx_op;//Rendering by external method -}; -inline c_display::c_display(void* phy_fb, int display_width, int display_height, int surface_width, int surface_height, unsigned int color_bytes, int surface_cnt, EXTERNAL_GFX_OP* gfx_op) : m_width(display_width), m_height(display_height), m_color_bytes(color_bytes), m_phy_fb(phy_fb), m_phy_read_index(0), m_phy_write_index(0), m_surface_cnt(surface_cnt), m_surface_index(0) +inline c_display::c_display(void* phy_fb, int display_width, int display_height, c_surface* surface, DISPLAY_DRIVER* driver) : m_phy_fb(phy_fb), m_width(display_width), m_height(display_height), m_driver(driver), m_phy_read_index(0), m_phy_write_index(0), m_surface_cnt(1), m_surface_index(0) +{ + m_color_bytes = surface->m_color_bytes; + surface->m_is_active = true; + (m_surface_group[0] = surface)->attach_display(this); +} +inline c_display::c_display(void* phy_fb, int display_width, int display_height, int surface_width, int surface_height, unsigned int color_bytes, int surface_cnt, DISPLAY_DRIVER* driver) : m_phy_fb(phy_fb), m_width(display_width), m_height(display_height), m_color_bytes(color_bytes), m_phy_read_index(0), m_phy_write_index(0), m_surface_cnt(surface_cnt), m_driver(driver), m_surface_index(0) { ASSERT(color_bytes == 2 || color_bytes == 4); ASSERT(m_surface_cnt <= SURFACE_CNT_MAX); @@ -726,16 +696,10 @@ inline c_display::c_display(void* phy_fb, int display_width, int display_height, for (int i = 0; i < m_surface_cnt; i++) { - m_surface_group[i] = (phy_fb) ? new c_surface(surface_width, surface_height, color_bytes) : new c_surface_no_fb(surface_width, surface_height, color_bytes, gfx_op); + m_surface_group[i] = new c_surface(surface_width, surface_height, color_bytes); m_surface_group[i]->attach_display(this); } } -inline c_display::c_display(void* phy_fb, int display_width, int display_height, c_surface* surface) : m_width(display_width), m_height(display_height), m_phy_fb(phy_fb), m_phy_read_index(0), m_phy_write_index(0), m_surface_cnt(1), m_surface_index(0) -{ - m_color_bytes = surface->m_color_bytes; - surface->m_is_active = true; - (m_surface_group[0] = surface)->attach_display(this); -} inline c_surface* c_display::alloc_surface(Z_ORDER_LEVEL max_zorder, c_rect layer_rect) { ASSERT(max_zorder < Z_ORDER_LEVEL_MAX && m_surface_index < m_surface_cnt); @@ -744,8 +708,8 @@ inline c_surface* c_display::alloc_surface(Z_ORDER_LEVEL max_zorder, c_rect laye } inline int c_display::swipe_surface(c_surface* s0, c_surface* s1, int x0, int x1, int y0, int y1, int offset) { - int surface_width = s0->get_width(); - int surface_height = s0->get_height(); + register int surface_width = s0->m_width; + register int surface_height = s0->m_height; if (offset < 0 || offset > surface_width || y0 < 0 || y0 >= surface_height || y1 < 0 || y1 >= surface_height || x0 < 0 || x0 >= surface_width || x1 < 0 || x1 >= surface_width) { @@ -767,46 +731,46 @@ inline int c_display::swipe_surface(c_surface* s0, c_surface* s1, int x0, int x1 for (int y = y0; y <= y1; y++) { //Left surface - char* addr_s = ((char*)(s0->m_fb) + (y * (s0->get_width()) + x0 + offset) * m_color_bytes); + char* addr_s = ((char*)(s0->m_fb) + (y * surface_width + x0 + offset) * m_color_bytes); char* addr_d = ((char*)(m_phy_fb)+(y * m_width + x0) * m_color_bytes); memcpy(addr_d, addr_s, (width - offset) * m_color_bytes); //Right surface - addr_s = ((char*)(s1->m_fb) + (y * (s1->get_width()) + x0) * m_color_bytes); + addr_s = ((char*)(s1->m_fb) + (y * surface_width + x0) * m_color_bytes); addr_d = ((char*)(m_phy_fb)+(y * m_width + x0 + (width - offset)) * m_color_bytes); memcpy(addr_d, addr_s, offset * m_color_bytes); } } - else if (m_color_bytes == 4) + else if (m_color_bytes == 2) { - void(*draw_pixel)(int x, int y, unsigned int rgb) = ((c_surface_no_fb*)s0)->m_gfx_op->draw_pixel; + void(*draw_pixel)(int x, int y, unsigned int rgb) = m_driver->draw_pixel; for (int y = y0; y <= y1; y++) { //Left surface for (int x = x0; x <= (x1 - offset); x++) { - draw_pixel(x, y, ((unsigned int*)s0->m_fb)[y * m_width + x + offset]); + draw_pixel(x, y, GL_RGB_16_to_32(((unsigned short*)s0->m_fb)[y * m_width + x + offset])); } //Right surface for (int x = x1 - offset; x <= x1; x++) { - draw_pixel(x, y, ((unsigned int*)s1->m_fb)[y * m_width + x + offset - x1 + x0]); + draw_pixel(x, y, GL_RGB_16_to_32(((unsigned short*)s1->m_fb)[y * m_width + x + offset - x1 + x0])); } } } - else if (m_color_bytes == 2) + else //m_color_bytes == 3/4... { - void(*draw_pixel)(int x, int y, unsigned int rgb) = ((c_surface_no_fb*)s0)->m_gfx_op->draw_pixel; + void(*draw_pixel)(int x, int y, unsigned int rgb) = m_driver->draw_pixel; for (int y = y0; y <= y1; y++) { //Left surface for (int x = x0; x <= (x1 - offset); x++) { - draw_pixel(x, y, GL_RGB_16_to_32(((unsigned short*)s0->m_fb)[y * m_width + x + offset])); + draw_pixel(x, y, ((unsigned int*)s0->m_fb)[y * m_width + x + offset]); } //Right surface for (int x = x1 - offset; x <= x1; x++) { - draw_pixel(x, y, GL_RGB_16_to_32(((unsigned short*)s1->m_fb)[y * m_width + x + offset - x1 + x0])); + draw_pixel(x, y, ((unsigned int*)s1->m_fb)[y * m_width + x + offset - x1 + x0]); } } } @@ -3407,22 +3371,12 @@ private: #ifdef GUILITE_ON c_bitmap_operator the_bitmap_op = c_bitmap_operator(); c_image_operator* c_image::image_operator = &the_bitmap_op; +const void* c_theme::s_font_map[FONT_MAX]; +const void* c_theme::s_image_map[IMAGE_MAX]; +unsigned int c_theme::s_color_map[COLOR_MAX]; +c_lattice_font_op the_lattice_font_op = c_lattice_font_op(); +c_font_operator* c_word::fontOperator = &the_lattice_font_op; #endif - -#ifdef GUILITE_ON - -const void* c_theme::s_font_map[FONT_MAX]; -const void* c_theme::s_image_map[IMAGE_MAX]; -unsigned int c_theme::s_color_map[COLOR_MAX]; - -#endif - -#ifdef GUILITE_ON - -c_lattice_font_op the_lattice_font_op = c_lattice_font_op(); -c_font_operator* c_word::fontOperator = &the_lattice_font_op; - -#endif #ifdef GUILITE_ON #if (defined __linux__) || (defined __APPLE__) #include @@ -4264,11 +4218,7 @@ int c_fifo::write(void* buf, int len) #endif #ifdef GUILITE_ON DIALOG_ARRAY c_dialog::ms_the_dialogs[SURFACE_CNT_MAX]; -#endif -#ifdef GUILITE_ON c_keyboard c_edit::s_keyboard; -#endif -#ifdef GUILITE_ON static c_keyboard_button s_key_0, s_key_1, s_key_2, s_key_3, s_key_4, s_key_5, s_key_6, s_key_7, s_key_8, s_key_9; static c_keyboard_button s_key_A, s_key_B, s_key_C, s_key_D, s_key_E, s_key_F, s_key_G, s_key_H, s_key_I, s_key_J; static c_keyboard_button s_key_K, s_key_L, s_key_M, s_key_N, s_key_O, s_key_P, s_key_Q, s_key_R, s_key_S, s_key_T; @@ -4306,12 +4256,12 @@ WND_TREE g_key_board_children[] = {&s_key_B, 'B', 0, ((KEY_WIDTH / 2) + POS_X(5)), POS_Y(2), KEY_WIDTH, KEY_HEIGHT}, {&s_key_N, 'N', 0, ((KEY_WIDTH / 2) + POS_X(6)), POS_Y(2), KEY_WIDTH, KEY_HEIGHT}, {&s_key_M, 'M', 0, ((KEY_WIDTH / 2) + POS_X(7)), POS_Y(2), KEY_WIDTH, KEY_HEIGHT}, - {&s_key_del, 0x7F, 0, ((KEY_WIDTH / 2) + POS_X(8)), POS_Y(2), DEL_WIDTH, KEY_HEIGHT}, + {&s_key_del,0x7F, 0, ((KEY_WIDTH / 2) + POS_X(8)), POS_Y(2), DEL_WIDTH, KEY_HEIGHT}, //Row 4 - {&s_key_esc, 0x1B, 0, POS_X(0), POS_Y(3), ESC_WIDTH, KEY_HEIGHT}, + {&s_key_esc, 0x1B, 0, POS_X(0), POS_Y(3), ESC_WIDTH, KEY_HEIGHT}, {&s_key_num_switch, 0x90, 0, POS_X(2), POS_Y(3), SWITCH_WIDTH, KEY_HEIGHT}, {&s_key_space, ' ', 0, ((KEY_WIDTH / 2) + POS_X(3)), POS_Y(3), SPACE_WIDTH, KEY_HEIGHT}, - {&s_key_dot, '.', 0, ((KEY_WIDTH / 2) + POS_X(6)), POS_Y(3), DOT_WIDTH, KEY_HEIGHT}, + {&s_key_dot, '.', 0, ((KEY_WIDTH / 2) + POS_X(6)), POS_Y(3), DOT_WIDTH, KEY_HEIGHT}, {&s_key_enter, '\n', 0, POS_X(8), POS_Y(3), ENTER_WIDTH, KEY_HEIGHT}, {0,0,0,0,0,0,0} }; @@ -4326,12 +4276,11 @@ WND_TREE g_number_board_children[] = {&s_key_7, '7', 0, POS_X(0), POS_Y(2), KEY_WIDTH, KEY_HEIGHT}, {&s_key_8, '8', 0, POS_X(1), POS_Y(2), KEY_WIDTH, KEY_HEIGHT}, {&s_key_9, '9', 0, POS_X(2), POS_Y(2), KEY_WIDTH, KEY_HEIGHT}, - - {&s_key_esc, 0x1B, 0, POS_X(0), POS_Y(3), KEY_WIDTH, KEY_HEIGHT}, + {&s_key_esc,0x1B, 0, POS_X(0), POS_Y(3), KEY_WIDTH, KEY_HEIGHT}, {&s_key_0, '0', 0, POS_X(1), POS_Y(3), KEY_WIDTH, KEY_HEIGHT}, - {&s_key_dot, '.', 0, POS_X(2), POS_Y(3), KEY_WIDTH, KEY_HEIGHT}, + {&s_key_dot,'.', 0, POS_X(2), POS_Y(3), KEY_WIDTH, KEY_HEIGHT}, {&s_key_del, 0x7F, 0, POS_X(3), POS_Y(0), KEY_WIDTH, KEY_HEIGHT * 2 + 2}, {&s_key_enter,'\n', 0, POS_X(3), POS_Y(2), KEY_WIDTH, KEY_HEIGHT * 2 + 2}, {0,0,0,0,0,0,0} }; -#endif +#endif \ No newline at end of file diff --git a/HelloNoTouch/UIcode/UIcode.cpp b/HelloNoTouch/UIcode/UIcode.cpp index b1ade2a20a81d92162a186bdd363cadd38700d61..2a0c872e0e122f1d77b9491744acd597bbcd85d6 100644 --- a/HelloNoTouch/UIcode/UIcode.cpp +++ b/HelloNoTouch/UIcode/UIcode.cpp @@ -86,32 +86,22 @@ void load_resource() static c_display* s_display; static c_surface* s_surface; -void create_ui(void* phy_fb, int screen_width, int screen_height, int color_bytes, struct EXTERNAL_GFX_OP* gfx_op) +void create_ui(void* phy_fb, int screen_width, int screen_height, int color_bytes, struct DISPLAY_DRIVER* driver) { load_resource(); - if (phy_fb) - { - static c_surface surface(UI_WIDTH, UI_HEIGHT, color_bytes, Z_ORDER_LEVEL_0); - static c_display display(phy_fb, screen_width, screen_height, &surface); - s_surface = &surface; - s_display = &display; - } - else - {//for MCU without framebuffer - static c_surface_no_fb surface_no_fb(UI_WIDTH, UI_HEIGHT, color_bytes, gfx_op, Z_ORDER_LEVEL_0); - static c_display display(phy_fb, screen_width, screen_height, &surface_no_fb); - s_surface = &surface_no_fb; - s_display = &display; - } + static c_surface surface(UI_WIDTH, UI_HEIGHT, color_bytes, Z_ORDER_LEVEL_0); + static c_display display(phy_fb, screen_width, screen_height, &surface, driver); + s_surface = &surface; + s_display = &display; s_myUI.set_surface(s_surface); s_myUI.connect(NULL, ID_ROOT, 0, 0, 0, UI_WIDTH, UI_HEIGHT, s_myUI_children); s_myUI.show_window(); } //////////////////////// interface for all platform //////////////////////// -extern "C" void startHelloNoTouch(void* phy_fb, int width, int height, int color_bytes, struct EXTERNAL_GFX_OP* gfx_op) +extern "C" void startHelloNoTouch(void* phy_fb, int width, int height, int color_bytes, struct DISPLAY_DRIVER* driver) { - create_ui(phy_fb, width, height, color_bytes, gfx_op); + create_ui(phy_fb, width, height, color_bytes, driver); } extern "C" void sendTouch2HelloNoTouch(int x, int y, bool is_down) diff --git a/HelloParticle/BuildIos/BuildIos/Bridging-Header.h b/HelloParticle/BuildIos/BuildIos/Bridging-Header.h index c05ea6bdf8cd869515b68cc9a3c45ef902061e87..823f7509681351501db60ea13719c2c332107cea 100644 --- a/HelloParticle/BuildIos/BuildIos/Bridging-Header.h +++ b/HelloParticle/BuildIos/BuildIos/Bridging-Header.h @@ -8,7 +8,7 @@ extern "C"{ #endif void* getUiOfHelloParticle(); - void startHelloParticle(void* phy_fb, int width, int height, int color_bytes, struct EXTERNAL_GFX_OP* gfx_op); + void startHelloParticle(void* phy_fb, int width, int height, int color_bytes, struct DISPLAY_DRIVER* driver); #ifdef __cplusplus } #endif diff --git a/HelloParticle/BuildLinux/.sync_build.sh b/HelloParticle/BuildLinux/.sync_build.sh index 49cff5b473ac606967676ebefa6f0d333e301227..a892c25974d0dbcf18e43c867586bb8165c7a9a4 100644 --- a/HelloParticle/BuildLinux/.sync_build.sh +++ b/HelloParticle/BuildLinux/.sync_build.sh @@ -1,5 +1,6 @@ if [ "$#" -ne 1 ]; then - echo "Invalid arguments" + echo "Do testing" + ./xWindow 240 320 | ./HelloParticle shared-fb exit -1 fi diff --git a/HelloParticle/BuildLinux/main.cpp b/HelloParticle/BuildLinux/main.cpp index 2400ac2b85f42ece339e2462f168be852333dc18..2731303373be764b14b6b1c5272e1600f89dedd9 100644 --- a/HelloParticle/BuildLinux/main.cpp +++ b/HelloParticle/BuildLinux/main.cpp @@ -10,7 +10,7 @@ #include #include -extern "C" void startHelloParticle(void* phy_fb, int width, int height, int color_bytes, struct EXTERNAL_GFX_OP* gfx_op); +extern "C" void startHelloParticle(void* phy_fb, int width, int height, int color_bytes, struct DISPLAY_DRIVER* driver); extern void init_std_io(); static void* get_embeded_fb_in_display_app(int shared_id); diff --git a/HelloParticle/BuildMFC/HelloParticleDlg.cpp b/HelloParticle/BuildMFC/HelloParticleDlg.cpp index de7016d137f4ad82ced862585fa51b6829a8f76a..252143ab205e07016ca360910e94b6049a764b06 100644 Binary files a/HelloParticle/BuildMFC/HelloParticleDlg.cpp and b/HelloParticle/BuildMFC/HelloParticleDlg.cpp differ diff --git a/HelloParticle/BuildMFC/HelloParticleDlg.h b/HelloParticle/BuildMFC/HelloParticleDlg.h index 454f67e91057fb3a9460bdb75c3ad2d6eaec73ff..9574ee0739ab39a4125e843222726167c208bda5 100644 Binary files a/HelloParticle/BuildMFC/HelloParticleDlg.h and b/HelloParticle/BuildMFC/HelloParticleDlg.h differ diff --git a/HelloParticle/BuildSTM32F103-Keil/USER/main.c b/HelloParticle/BuildSTM32F103-Keil/USER/main.c index 9a2602c377e592a6af0c25ff457ece74c0aa9424..21a650cd69e47b2721458c166a357c0a63a3e225 100644 --- a/HelloParticle/BuildSTM32F103-Keil/USER/main.c +++ b/HelloParticle/BuildSTM32F103-Keil/USER/main.c @@ -15,12 +15,12 @@ void gfx_draw_pixel(int x, int y, unsigned int rgb) //void gfx_fill_rect(int x0, int y0, int x1, int y1, unsigned int rgb){} //UI entry -struct EXTERNAL_GFX_OP +struct DISPLAY_DRIVER { void (*draw_pixel)(int x, int y, unsigned int rgb); void (*fill_rect)(int x0, int y0, int x1, int y1, unsigned int rgb); -} my_gfx_op; -extern void startHelloParticle(void* phy_fb, int width, int height, int color_bytes, struct EXTERNAL_GFX_OP* gfx_op); +} my_driver; +extern void startHelloParticle(void* phy_fb, int width, int height, int color_bytes, struct DISPLAY_DRIVER* driver); int main(void) { @@ -30,8 +30,8 @@ int main(void) LCD_Init(); //Link your LCD driver & start UI: - my_gfx_op.draw_pixel = gfx_draw_pixel; - my_gfx_op.fill_rect = NULL;//gfx_fill_rect; - startHelloParticle(NULL, 240, 320, 2, &my_gfx_op); + my_driver.draw_pixel = gfx_draw_pixel; + my_driver.fill_rect = NULL;//gfx_fill_rect; + startHelloParticle(NULL, 240, 320, 2, &my_driver); while(1); } diff --git a/HelloParticle/BuildWin32/HelloParticle.cpp b/HelloParticle/BuildWin32/HelloParticle.cpp index da0a5cc3227fb44cdd96ed05f3fa284d9223485f..527ca6071dabeaa2f374d61a478f001a05064224 100644 --- a/HelloParticle/BuildWin32/HelloParticle.cpp +++ b/HelloParticle/BuildWin32/HelloParticle.cpp @@ -161,7 +161,7 @@ LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam) } //////////////////////// HelloParticle Interface //////////////////////// -extern "C" void startHelloParticle(void* phy_fb, int width, int height, int color_bytes, struct EXTERNAL_GFX_OP* gfx_op); +extern "C" void startHelloParticle(void* phy_fb, int width, int height, int color_bytes, struct DISPLAY_DRIVER* driver); DWORD WINAPI ThreadHelloParticle(LPVOID pParam) { diff --git a/HelloParticle/UIcode/GuiLite.h b/HelloParticle/UIcode/GuiLite.h index c4fc88a51476d2c8309c3e55e1270e13784fc510..80550e1632ad7bc82541a2edbb0f7f8f5937954f 100644 --- a/HelloParticle/UIcode/GuiLite.h +++ b/HelloParticle/UIcode/GuiLite.h @@ -1,107 +1,94 @@ #pragma once - -#define REAL_TIME_TASK_CYCLE_MS 50 -#define MAX(a,b) (((a)>(b))?(a):(b)) -#define MIN(a,b) (((a)<(b))?(a):(b)) - -#define GL_ARGB(a, r, g, b) ((((unsigned int)(a)) << 24) | (((unsigned int)(r)) << 16) | (((unsigned int)(g)) << 8) | ((unsigned int)(b))) -#define GL_ARGB_A(rgb) ((((unsigned int)(rgb)) >> 24) & 0xFF) - -#define GL_RGB(r, g, b) ((0xFF << 24) | (((unsigned int)(r)) << 16) | (((unsigned int)(g)) << 8) | ((unsigned int)(b))) -#define GL_RGB_R(rgb) ((((unsigned int)(rgb)) >> 16) & 0xFF) -#define GL_RGB_G(rgb) ((((unsigned int)(rgb)) >> 8) & 0xFF) -#define GL_RGB_B(rgb) (((unsigned int)(rgb)) & 0xFF) -#define GL_RGB_32_to_16(rgb) (((((unsigned int)(rgb)) & 0xFF) >> 3) | ((((unsigned int)(rgb)) & 0xFC00) >> 5) | ((((unsigned int)(rgb)) & 0xF80000) >> 8)) -#define GL_RGB_16_to_32(rgb) ((0xFF << 24) | ((((unsigned int)(rgb)) & 0x1F) << 3) | ((((unsigned int)(rgb)) & 0x7E0) << 5) | ((((unsigned int)(rgb)) & 0xF800) << 8)) - -#define ALIGN_HCENTER 0x00000000L -#define ALIGN_LEFT 0x01000000L -#define ALIGN_RIGHT 0x02000000L -#define ALIGN_HMASK 0x03000000L - -#define ALIGN_VCENTER 0x00000000L -#define ALIGN_TOP 0x00100000L -#define ALIGN_BOTTOM 0x00200000L -#define ALIGN_VMASK 0x00300000L - -typedef struct -{ - unsigned short year; - unsigned short month; - unsigned short date; - unsigned short day; - unsigned short hour; - unsigned short minute; - unsigned short second; -}T_TIME; - -void register_debug_function(void(*my_assert)(const char* file, int line), void(*my_log_out)(const char* log)); -void _assert(const char* file, int line); -#define ASSERT(condition) \ - do{ \ - if(!(condition))_assert(__FILE__, __LINE__);\ - }while(0) -void log_out(const char* log); - -long get_time_in_second(); -T_TIME second_to_day(long second); -T_TIME get_time(); - -void start_real_timer(void (*func)(void* arg)); -void register_timer(int milli_second, void func(void* param), void* param); - -unsigned int get_cur_thread_id(); -void create_thread(unsigned long* thread_id, void* attr, void *(*start_routine) (void *), void* arg); -void thread_sleep(unsigned int milli_seconds); -int build_bmp(const char *filename, unsigned int width, unsigned int height, unsigned char *data); - -#define FIFO_BUFFER_LEN 1024 -class c_fifo -{ -public: - c_fifo(); - int read(void* buf, int len); - int write(void* buf, int len); -private: - unsigned char m_buf[FIFO_BUFFER_LEN]; - int m_head; - int m_tail; - void* m_read_sem; - void* m_write_mutex; -}; - -class c_rect -{ -public: - c_rect(){ m_left = m_top = m_right = m_bottom = -1; } - c_rect(int left, int top, int width, int height) - { - set_rect(left, top, width, height); - } - void set_rect(int left, int top, int width, int height) - { - ASSERT(width > 0 && height > 0); - m_left = left; - m_top = top; - m_right = left + width - 1; - m_bottom = top + height -1; - } - bool pt_in_rect(int x, int y) const - { - return x >= m_left && x <= m_right && y >= m_top && y <= m_bottom; - } - int operator==(const c_rect& rect) const - { - return (m_left == rect.m_left) && (m_top == rect.m_top) && (m_right == rect.m_right) && (m_bottom == rect.m_bottom); - } - int width() const { return m_right - m_left + 1; } - int height() const { return m_bottom - m_top + 1 ; } - - int m_left; - int m_top; - int m_right; - int m_bottom; -}; +#define REAL_TIME_TASK_CYCLE_MS 50 +#define MAX(a,b) (((a)>(b))?(a):(b)) +#define MIN(a,b) (((a)<(b))?(a):(b)) +#define GL_ARGB(a, r, g, b) ((((unsigned int)(a)) << 24) | (((unsigned int)(r)) << 16) | (((unsigned int)(g)) << 8) | ((unsigned int)(b))) +#define GL_ARGB_A(rgb) ((((unsigned int)(rgb)) >> 24) & 0xFF) +#define GL_RGB(r, g, b) ((0xFF << 24) | (((unsigned int)(r)) << 16) | (((unsigned int)(g)) << 8) | ((unsigned int)(b))) +#define GL_RGB_R(rgb) ((((unsigned int)(rgb)) >> 16) & 0xFF) +#define GL_RGB_G(rgb) ((((unsigned int)(rgb)) >> 8) & 0xFF) +#define GL_RGB_B(rgb) (((unsigned int)(rgb)) & 0xFF) +#define GL_RGB_32_to_16(rgb) (((((unsigned int)(rgb)) & 0xFF) >> 3) | ((((unsigned int)(rgb)) & 0xFC00) >> 5) | ((((unsigned int)(rgb)) & 0xF80000) >> 8)) +#define GL_RGB_16_to_32(rgb) ((0xFF << 24) | ((((unsigned int)(rgb)) & 0x1F) << 3) | ((((unsigned int)(rgb)) & 0x7E0) << 5) | ((((unsigned int)(rgb)) & 0xF800) << 8)) +#define ALIGN_HCENTER 0x00000000L +#define ALIGN_LEFT 0x01000000L +#define ALIGN_RIGHT 0x02000000L +#define ALIGN_HMASK 0x03000000L +#define ALIGN_VCENTER 0x00000000L +#define ALIGN_TOP 0x00100000L +#define ALIGN_BOTTOM 0x00200000L +#define ALIGN_VMASK 0x00300000L +typedef struct +{ + unsigned short year; + unsigned short month; + unsigned short date; + unsigned short day; + unsigned short hour; + unsigned short minute; + unsigned short second; +}T_TIME; +void register_debug_function(void(*my_assert)(const char* file, int line), void(*my_log_out)(const char* log)); +void _assert(const char* file, int line); +#define ASSERT(condition) \ + do{ \ + if(!(condition))_assert(__FILE__, __LINE__);\ + }while(0) +void log_out(const char* log); +long get_time_in_second(); +T_TIME second_to_day(long second); +T_TIME get_time(); +void start_real_timer(void (*func)(void* arg)); +void register_timer(int milli_second, void func(void* param), void* param); +unsigned int get_cur_thread_id(); +void create_thread(unsigned long* thread_id, void* attr, void *(*start_routine) (void *), void* arg); +void thread_sleep(unsigned int milli_seconds); +int build_bmp(const char *filename, unsigned int width, unsigned int height, unsigned char *data); +#define FIFO_BUFFER_LEN 1024 +class c_fifo +{ +public: + c_fifo(); + int read(void* buf, int len); + int write(void* buf, int len); +private: + unsigned char m_buf[FIFO_BUFFER_LEN]; + int m_head; + int m_tail; + void* m_read_sem; + void* m_write_mutex; +}; +class c_rect +{ +public: + c_rect(){ m_left = m_top = m_right = m_bottom = -1; } + c_rect(int left, int top, int width, int height) + { + set_rect(left, top, width, height); + } + void set_rect(int left, int top, int width, int height) + { + ASSERT(width > 0 && height > 0); + m_left = left; + m_top = top; + m_right = left + width - 1; + m_bottom = top + height -1; + } + bool pt_in_rect(int x, int y) const + { + return x >= m_left && x <= m_right && y >= m_top && y <= m_bottom; + } + int operator==(const c_rect& rect) const + { + return (m_left == rect.m_left) && (m_top == rect.m_top) && (m_right == rect.m_right) && (m_bottom == rect.m_bottom); + } + int width() const { return m_right - m_left + 1; } + int height() const { return m_bottom - m_top + 1 ; } + int m_left; + int m_top; + int m_right; + int m_bottom; +}; //BITMAP typedef struct struct_bitmap_info { @@ -238,7 +225,7 @@ typedef enum Z_ORDER_LEVEL_2,//highest graphic level Z_ORDER_LEVEL_MAX }Z_ORDER_LEVEL; -struct EXTERNAL_GFX_OP +struct DISPLAY_DRIVER { void(*draw_pixel)(int x, int y, unsigned int rgb); void(*fill_rect)(int x0, int y0, int x1, int y1, unsigned int rgb); @@ -247,18 +234,19 @@ class c_surface; class c_display { friend class c_surface; public: - inline c_display(void* phy_fb, int display_width, int display_height, int surface_width, int surface_height, unsigned int color_bytes, int surface_cnt, EXTERNAL_GFX_OP* gfx_op = 0);//multiple surface or surface_no_fb - inline c_display(void* phy_fb, int display_width, int display_height, c_surface* surface);//single custom surface - inline c_surface* alloc_surface(Z_ORDER_LEVEL max_zorder, c_rect layer_rect = c_rect());//for multiple surfaces + inline c_display(void* phy_fb, int display_width, int display_height, c_surface* surface, DISPLAY_DRIVER* driver = 0);//single custom surface + inline c_display(void* phy_fb, int display_width, int display_height, int surface_width, int surface_height, unsigned int color_bytes, int surface_cnt, DISPLAY_DRIVER* driver = 0);//multiple surface + inline c_surface* alloc_surface(Z_ORDER_LEVEL max_zorder, c_rect layer_rect = c_rect());//for slide group inline int swipe_surface(c_surface* s0, c_surface* s1, int x0, int x1, int y0, int y1, int offset); int get_width() { return m_width; } int get_height() { return m_height; } + void* get_phy_fb() { return m_phy_fb; } void* get_updated_fb(int* width, int* height, bool force_update = false) { if (width && height) { - *width = get_width(); - *height = get_height(); + *width = m_width; + *height = m_height; } if (force_update) { @@ -277,35 +265,123 @@ public: { return -1; } - int width = get_width(); - int height = get_height(); //16 bits framebuffer if (m_color_bytes == 2) { - return build_bmp(file_name, width, height, (unsigned char*)m_phy_fb); + return build_bmp(file_name, m_width, m_height, (unsigned char*)m_phy_fb); } //32 bits framebuffer - unsigned short* p_bmp565_data = new unsigned short[width * height]; + unsigned short* p_bmp565_data = new unsigned short[m_width * m_height]; unsigned int* p_raw_data = (unsigned int*)m_phy_fb; - for (int i = 0; i < width * height; i++) + for (int i = 0; i < m_width * m_height; i++) { unsigned int rgb = *p_raw_data++; p_bmp565_data[i] = GL_RGB_32_to_16(rgb); } - int ret = build_bmp(file_name, width, height, (unsigned char*)p_bmp565_data); + int ret = build_bmp(file_name, m_width, m_height, (unsigned char*)p_bmp565_data); delete[]p_bmp565_data; return ret; } -private: - int m_width; //in pixels - int m_height; //in pixels - int m_color_bytes; //16 bits, 32 bits only - void* m_phy_fb; //physical framebuffer +protected: + virtual void draw_pixel(int x, int y, unsigned int rgb) + { + if ((x >= m_width) || (y >= m_height)) { return; } + if (m_driver && m_driver->draw_pixel) + { + return m_driver->draw_pixel(x, y, rgb); + } + if (m_color_bytes == 2) + { + ((unsigned short*)m_phy_fb)[y * m_width + x] = GL_RGB_32_to_16(rgb); + } + else + { + ((unsigned int*)m_phy_fb)[y * m_width + x] = rgb; + } + } + virtual void fill_rect(int x0, int y0, int x1, int y1, unsigned int rgb) + { + if (m_driver && m_driver->fill_rect) + { + return m_driver->fill_rect(x0, y0, x1, y1, rgb); + } + if (m_driver && m_driver->draw_pixel) + { + for (int y = y0; y <= y1; y++) + { + for (int x = x0; x <= x1; x++) + { + m_driver->draw_pixel(x, y, rgb); + } + } + return; + } + register int _width = m_width; + register int _height = m_height; + int x, y; + if (m_color_bytes == 2) + { + unsigned short* phy_fb; + unsigned int rgb_16 = GL_RGB_32_to_16(rgb); + for (y = y0; y <= y1; y++) + { + phy_fb = &((unsigned short*)m_phy_fb)[y * _width + x0]; + for (x = x0; x <= x1; x++) + { + if ((x < _width) && (y < _height)) + { + *phy_fb++ = rgb_16; + } + } + } + } + else + { + unsigned int* phy_fb; + for (y = y0; y <= y1; y++) + { + phy_fb = &((unsigned int*)m_phy_fb)[y * _width + x0]; + for (x = x0; x <= x1; x++) + { + if ((x < _width) && (y < _height)) + { + *phy_fb++ = rgb; + } + } + } + } + } + virtual int flush_screen(int left, int top, int right, int bottom, void* fb, int fb_width) + { + if ((0 == m_phy_fb) || (0 == fb)) + { + return -1; + } + register int _width = m_width; + register int _height = m_height; + left = (left >= _width) ? (_width - 1) : left; + right = (right >= _width) ? (_width - 1) : right; + top = (top >= _height) ? (_height - 1) : top; + bottom = (bottom >= _height) ? (_height - 1) : bottom; + for (int y = top; y < bottom; y++) + { + void* s_addr = (char*)fb + ((y * fb_width + left) * m_color_bytes); + void* d_addr = (char*)m_phy_fb + ((y * _width + left) * m_color_bytes); + memcpy(d_addr, s_addr, (right - left) * m_color_bytes); + } + return 0; + } + int m_width; //in pixels + int m_height; //in pixels + int m_color_bytes; //16/32 bits for default + void* m_phy_fb; //physical framebuffer for default + struct DISPLAY_DRIVER* m_driver; //Rendering by external method without default physical framebuffer int m_phy_read_index; int m_phy_write_index; c_surface* m_surface_group[SURFACE_CNT_MAX]; int m_surface_cnt; //surface count int m_surface_index; + }; class c_layer { @@ -317,12 +393,10 @@ public: class c_surface { friend class c_display; friend class c_bitmap_operator; public: - c_surface(unsigned int width, unsigned int height, unsigned int color_bytes, Z_ORDER_LEVEL max_zorder = Z_ORDER_LEVEL_0, c_rect overlpa_rect = c_rect()) : m_width(width), m_height(height), m_color_bytes(color_bytes), m_fb(0), m_is_active(false), m_top_zorder(Z_ORDER_LEVEL_0), m_phy_fb(0), m_phy_write_index(0), m_display(0) + c_surface(unsigned int width, unsigned int height, unsigned int color_bytes, Z_ORDER_LEVEL max_zorder = Z_ORDER_LEVEL_0, c_rect overlpa_rect = c_rect()) : m_width(width), m_height(height), m_color_bytes(color_bytes), m_fb(0), m_is_active(false), m_top_zorder(Z_ORDER_LEVEL_0), m_phy_write_index(0), m_display(0) { (overlpa_rect == c_rect()) ? set_surface(max_zorder, c_rect(0, 0, width - 1, height - 1)) : set_surface(max_zorder, overlpa_rect); } - int get_width() { return m_width; } - int get_height() { return m_height; } unsigned int get_pixel(int x, int y, unsigned int z_order) { if (x >= m_width || y >= m_height || x < 0 || y < 0 || z_order >= Z_ORDER_LEVEL_MAX) @@ -332,15 +406,15 @@ public: } if (m_layers[z_order].fb) { - return (m_color_bytes == 4) ? ((unsigned int*)(m_layers[z_order].fb))[y * m_width + x] : GL_RGB_16_to_32(((unsigned short*)(m_layers[z_order].fb))[y * m_width + x]); + return (m_color_bytes == 2) ? GL_RGB_16_to_32(((unsigned short*)(m_layers[z_order].fb))[y * m_width + x]) : ((unsigned int*)(m_layers[z_order].fb))[y * m_width + x]; } else if (m_fb) { - return (m_color_bytes == 4) ? ((unsigned int*)m_fb)[y * m_width + x] : GL_RGB_16_to_32(((unsigned short*)m_fb)[y * m_width + x]); + return (m_color_bytes == 2) ? GL_RGB_16_to_32(((unsigned short*)m_fb)[y * m_width + x]) : ((unsigned int*)m_fb)[y * m_width + x]; } - else if (m_phy_fb) + else if (m_display->m_phy_fb) { - return (m_color_bytes == 4) ? ((unsigned int*)m_phy_fb)[y * m_width + x] : GL_RGB_16_to_32(((unsigned short*)m_phy_fb)[y * m_width + x]); + return (m_color_bytes == 2) ? GL_RGB_16_to_32(((unsigned short*)m_display->m_phy_fb)[y * m_width + x]) : ((unsigned int*)m_display->m_phy_fb)[y * m_width + x]; } return 0; } @@ -357,7 +431,7 @@ public: } if (z_order == m_max_zorder) { - return draw_pixel_on_fb(x, y, rgb); + return draw_pixel_low_level(x, y, rgb); } if (z_order > (unsigned int)m_top_zorder) @@ -367,19 +441,19 @@ public: if (m_layers[z_order].rect.pt_in_rect(x, y)) { c_rect layer_rect = m_layers[z_order].rect; - if (m_color_bytes == 4) + if (m_color_bytes == 2) { - ((unsigned int*)(m_layers[z_order].fb))[(x - layer_rect.m_left) + (y - layer_rect.m_top) * layer_rect.width()] = rgb; + ((unsigned short*)(m_layers[z_order].fb))[(x - layer_rect.m_left) + (y - layer_rect.m_top) * layer_rect.width()] = GL_RGB_32_to_16(rgb); } else { - ((unsigned short*)(m_layers[z_order].fb))[(x - layer_rect.m_left) + (y - layer_rect.m_top) * layer_rect.width()] = GL_RGB_32_to_16(rgb); + ((unsigned int*)(m_layers[z_order].fb))[(x - layer_rect.m_left) + (y - layer_rect.m_top) * layer_rect.width()] = rgb; } } if (z_order == m_top_zorder) { - return draw_pixel_on_fb(x, y, rgb); + return draw_pixel_low_level(x, y, rgb); } bool be_overlapped = false; for (unsigned int tmp_z_order = Z_ORDER_LEVEL_MAX - 1; tmp_z_order > z_order; tmp_z_order--) @@ -392,7 +466,7 @@ public: } if (!be_overlapped) { - draw_pixel_on_fb(x, y, rgb); + draw_pixel_low_level(x, y, rgb); } } virtual void fill_rect(int x0, int y0, int x1, int y1, unsigned int rgb, unsigned int z_order) @@ -403,7 +477,7 @@ public: y1 = (y1 > (m_height - 1)) ? (m_height - 1) : y1; if (z_order == m_max_zorder) { - return fill_rect_on_fb(x0, y0, x1, y1, rgb); + return fill_rect_low_level(x0, y0, x1, y1, rgb); } if (z_order == m_top_zorder) { @@ -416,18 +490,18 @@ public: { if (layer_rect.pt_in_rect(x, y)) { - if (m_color_bytes == 4) + if (m_color_bytes == 2) { - ((unsigned int*)m_layers[z_order].fb)[(y - layer_rect.m_top) * layer_rect.width() + (x - layer_rect.m_left)] = rgb; + ((unsigned short*)m_layers[z_order].fb)[(y - layer_rect.m_top) * layer_rect.width() + (x - layer_rect.m_left)] = rgb_16; } else { - ((unsigned short*)m_layers[z_order].fb)[(y - layer_rect.m_top) * layer_rect.width() + (x - layer_rect.m_left)] = rgb_16; + ((unsigned int*)m_layers[z_order].fb)[(y - layer_rect.m_top) * layer_rect.width() + (x - layer_rect.m_left)] = rgb; } } } } - return fill_rect_on_fb(x0, y0, x1, y1, rgb); + return fill_rect_low_level(x0, y0, x1, y1, rgb); } for (; y0 <= y1; y0++) { @@ -499,27 +573,16 @@ public: } int flush_screen(int left, int top, int right, int bottom) { - if (left < 0 || left >= m_width || right < 0 || right >= m_width || - top < 0 || top >= m_height || bottom < 0 || bottom >= m_height) - { - ASSERT(false); - } - if (!m_is_active || (0 == m_phy_fb) || (0 == m_fb)) + if (!m_is_active) { return -1; } - int display_width = m_display->get_width(); - int display_height = m_display->get_height(); - left = (left >= display_width) ? (display_width - 1) : left; - right = (right >= display_width) ? (display_width - 1) : right; - top = (top >= display_height) ? (display_height - 1) : top; - bottom = (bottom >= display_height) ? (display_height - 1) : bottom; - for (int y = top; y < bottom; y++) + if (left < 0 || left >= m_width || right < 0 || right >= m_width || + top < 0 || top >= m_height || bottom < 0 || bottom >= m_height) { - void* s_addr = (char*)m_fb + ((y * m_width + left) * m_color_bytes); - void* d_addr = (char*)m_phy_fb + ((y * display_width + left) * m_color_bytes); - memcpy(d_addr, s_addr, (right - left) * m_color_bytes); + ASSERT(false); } + m_display->flush_screen(left, top, right, bottom, m_fb, m_width); *m_phy_write_index = *m_phy_write_index + 1; return 0; } @@ -537,90 +600,62 @@ public: { for (int x = rect.m_left; x <= rect.m_right; x++) { - unsigned int rgb = (m_color_bytes == 4) ? ((unsigned int*)fb)[(x - layer_rect.m_left) + (y - layer_rect.m_top) * width] : GL_RGB_16_to_32(((unsigned short*)fb)[(x - layer_rect.m_left) + (y - layer_rect.m_top) * width]); - draw_pixel_on_fb(x, y, rgb); + unsigned int rgb = (m_color_bytes == 2) ? GL_RGB_16_to_32(((unsigned short*)fb)[(x - layer_rect.m_left) + (y - layer_rect.m_top) * width]) : ((unsigned int*)fb)[(x - layer_rect.m_left) + (y - layer_rect.m_top) * width]; + draw_pixel_low_level(x, y, rgb); } } return 0; } void set_active(bool flag) { m_is_active = flag; } protected: - virtual void fill_rect_on_fb(int x0, int y0, int x1, int y1, unsigned int rgb) - { - int display_width = m_display->get_width(); - int display_height = m_display->get_height(); - if (m_color_bytes == 4) + virtual void fill_rect_low_level(int x0, int y0, int x1, int y1, unsigned int rgb) + {//fill rect on framebuffer of surface + int x, y; + if (m_color_bytes == 2) { - int x; - unsigned int* fb, * phy_fb; - for (; y0 <= y1; y0++) + unsigned short* fb; + unsigned int rgb_16 = GL_RGB_32_to_16(rgb); + for (y = y0; y <= y1; y++) { - x = x0; - fb = m_fb ? &((unsigned int*)m_fb)[y0 * m_width + x] : 0; - phy_fb = &((unsigned int*)m_phy_fb)[y0 * display_width + x]; - *m_phy_write_index = *m_phy_write_index + 1; - for (; x <= x1; x++) + fb = m_fb ? &((unsigned short*)m_fb)[y * m_width + x0] : 0; + if (!fb) { break; } + for (x = x0; x <= x1; x++) { - if (fb) - { - *fb++ = rgb; - } - if (m_is_active && (x < display_width) && (y0 < display_height)) - { - *phy_fb++ = rgb; - } + *fb++ = rgb_16; } } } - else if (m_color_bytes == 2) + else { - int x; - unsigned short* fb, * phy_fb; - rgb = GL_RGB_32_to_16(rgb); - for (; y0 <= y1; y0++) + unsigned int* fb; + for (y = y0; y <= y1; y++) { - x = x0; - fb = m_fb ? &((unsigned short*)m_fb)[y0 * m_width + x] : 0; - phy_fb = &((unsigned short*)m_phy_fb)[y0 * display_width + x]; - *m_phy_write_index = *m_phy_write_index + 1; - for (; x <= x1; x++) + fb = m_fb ? &((unsigned int*)m_fb)[y * m_width + x0] : 0; + if (!fb) { break; } + for (x = x0; x <= x1; x++) { - if (fb) - { - *fb++ = rgb; - } - if (m_is_active && (x < display_width) && (y0 < display_height)) - { - *phy_fb++ = rgb; - } + *fb++ = rgb; } } } + if (!m_is_active) { return; } + m_display->fill_rect(x0, y0, x1, y1, rgb); + *m_phy_write_index = *m_phy_write_index + 1; } - virtual void draw_pixel_on_fb(int x, int y, unsigned int rgb) + virtual void draw_pixel_low_level(int x, int y, unsigned int rgb) { if (m_fb) - { - (m_color_bytes == 4) ? ((unsigned int*)m_fb)[y * m_width + x] = rgb : ((unsigned short*)m_fb)[y * m_width + x] = GL_RGB_32_to_16(rgb); - } - if (m_is_active && (x < m_display->get_width()) && (y < m_display->get_height())) - { - if (m_color_bytes == 4) - { - ((unsigned int*)m_phy_fb)[y * (m_display->get_width()) + x] = rgb; - } - else - { - ((unsigned short*)m_phy_fb)[y * (m_display->get_width()) + x] = GL_RGB_32_to_16(rgb); - } - *m_phy_write_index = *m_phy_write_index + 1; + {//draw pixel on framebuffer of surface + (m_color_bytes == 2) ? ((unsigned short*)m_fb)[y * m_width + x] = GL_RGB_32_to_16(rgb): ((unsigned int*)m_fb)[y * m_width + x] = rgb; } + if (!m_is_active) { return; } + m_display->draw_pixel(x, y, rgb); + *m_phy_write_index = *m_phy_write_index + 1; } void attach_display(c_display* display) { ASSERT(display); m_display = display; - m_phy_fb = display->m_phy_fb; m_phy_write_index = &display->m_phy_write_index; } void set_surface(Z_ORDER_LEVEL max_z_order, c_rect layer_rect) @@ -638,87 +673,22 @@ protected: } int m_width; //in pixels int m_height; //in pixels - int m_color_bytes; //16 bits, 32 bits only + int m_color_bytes; //16 bits, 32 bits for default void* m_fb; //frame buffer you could see c_layer m_layers[Z_ORDER_LEVEL_MAX];//all graphic layers bool m_is_active; //active flag Z_ORDER_LEVEL m_max_zorder; //the highest graphic layer the surface will have Z_ORDER_LEVEL m_top_zorder; //the current highest graphic layer the surface have - void* m_phy_fb; //physical framebufer int* m_phy_write_index; c_display* m_display; }; -class c_surface_no_fb : public c_surface {//No physical framebuffer, render with external graphic interface - friend class c_display; -public: - c_surface_no_fb(unsigned int width, unsigned int height, unsigned int color_bytes, struct EXTERNAL_GFX_OP* gfx_op, Z_ORDER_LEVEL max_zorder = Z_ORDER_LEVEL_0, c_rect overlpa_rect = c_rect()) : c_surface(width, height, color_bytes, max_zorder, overlpa_rect), m_gfx_op(gfx_op) {} -protected: - virtual void fill_rect_on_fb(int x0, int y0, int x1, int y1, unsigned int rgb) - { - if (!m_gfx_op) - { - return; - } - if (m_gfx_op->fill_rect) - { - return m_gfx_op->fill_rect(x0, y0, x1, y1, rgb); - } - if (m_gfx_op->draw_pixel && m_is_active) - { - for (int y = y0; y <= y1; y++) - { - for (int x = x0; x <= x1; x++) - { - m_gfx_op->draw_pixel(x, y, rgb); - } - } - } - if (!m_fb) { return; } - if (m_color_bytes == 4) - { - unsigned int* fb; - for (int y = y0; y <= y1; y++) - { - fb = &((unsigned int*)m_fb)[y0 * m_width + x0]; - for (int x = x0; x <= x1; x++) - { - *fb++ = rgb; - } - } - } - else if (m_color_bytes == 2) - { - unsigned short* fb; - rgb = GL_RGB_32_to_16(rgb); - for (int y = y0; y <= y1; y++) - { - fb = &((unsigned short*)m_fb)[y0 * m_width + x0]; - for (int x = x0; x <= x1; x++) - { - *fb++ = rgb; - } - } - } - } - virtual void draw_pixel_on_fb(int x, int y, unsigned int rgb) - { - if (m_gfx_op && m_gfx_op->draw_pixel && m_is_active) - { - m_gfx_op->draw_pixel(x, y, rgb); - } - if (!m_fb) { return; } - if (m_color_bytes == 4) - { - ((unsigned int*)m_fb)[y * m_width + x] = rgb; - } - else if (m_color_bytes == 2) - { - ((unsigned short*)m_fb)[y * m_width + x] = GL_RGB_32_to_16(rgb); - } - } - struct EXTERNAL_GFX_OP* m_gfx_op;//Rendering by external method -}; -inline c_display::c_display(void* phy_fb, int display_width, int display_height, int surface_width, int surface_height, unsigned int color_bytes, int surface_cnt, EXTERNAL_GFX_OP* gfx_op) : m_width(display_width), m_height(display_height), m_color_bytes(color_bytes), m_phy_fb(phy_fb), m_phy_read_index(0), m_phy_write_index(0), m_surface_cnt(surface_cnt), m_surface_index(0) +inline c_display::c_display(void* phy_fb, int display_width, int display_height, c_surface* surface, DISPLAY_DRIVER* driver) : m_phy_fb(phy_fb), m_width(display_width), m_height(display_height), m_driver(driver), m_phy_read_index(0), m_phy_write_index(0), m_surface_cnt(1), m_surface_index(0) +{ + m_color_bytes = surface->m_color_bytes; + surface->m_is_active = true; + (m_surface_group[0] = surface)->attach_display(this); +} +inline c_display::c_display(void* phy_fb, int display_width, int display_height, int surface_width, int surface_height, unsigned int color_bytes, int surface_cnt, DISPLAY_DRIVER* driver) : m_phy_fb(phy_fb), m_width(display_width), m_height(display_height), m_color_bytes(color_bytes), m_phy_read_index(0), m_phy_write_index(0), m_surface_cnt(surface_cnt), m_driver(driver), m_surface_index(0) { ASSERT(color_bytes == 2 || color_bytes == 4); ASSERT(m_surface_cnt <= SURFACE_CNT_MAX); @@ -726,16 +696,10 @@ inline c_display::c_display(void* phy_fb, int display_width, int display_height, for (int i = 0; i < m_surface_cnt; i++) { - m_surface_group[i] = (phy_fb) ? new c_surface(surface_width, surface_height, color_bytes) : new c_surface_no_fb(surface_width, surface_height, color_bytes, gfx_op); + m_surface_group[i] = new c_surface(surface_width, surface_height, color_bytes); m_surface_group[i]->attach_display(this); } } -inline c_display::c_display(void* phy_fb, int display_width, int display_height, c_surface* surface) : m_width(display_width), m_height(display_height), m_phy_fb(phy_fb), m_phy_read_index(0), m_phy_write_index(0), m_surface_cnt(1), m_surface_index(0) -{ - m_color_bytes = surface->m_color_bytes; - surface->m_is_active = true; - (m_surface_group[0] = surface)->attach_display(this); -} inline c_surface* c_display::alloc_surface(Z_ORDER_LEVEL max_zorder, c_rect layer_rect) { ASSERT(max_zorder < Z_ORDER_LEVEL_MAX && m_surface_index < m_surface_cnt); @@ -744,8 +708,8 @@ inline c_surface* c_display::alloc_surface(Z_ORDER_LEVEL max_zorder, c_rect laye } inline int c_display::swipe_surface(c_surface* s0, c_surface* s1, int x0, int x1, int y0, int y1, int offset) { - int surface_width = s0->get_width(); - int surface_height = s0->get_height(); + register int surface_width = s0->m_width; + register int surface_height = s0->m_height; if (offset < 0 || offset > surface_width || y0 < 0 || y0 >= surface_height || y1 < 0 || y1 >= surface_height || x0 < 0 || x0 >= surface_width || x1 < 0 || x1 >= surface_width) { @@ -767,46 +731,46 @@ inline int c_display::swipe_surface(c_surface* s0, c_surface* s1, int x0, int x1 for (int y = y0; y <= y1; y++) { //Left surface - char* addr_s = ((char*)(s0->m_fb) + (y * (s0->get_width()) + x0 + offset) * m_color_bytes); + char* addr_s = ((char*)(s0->m_fb) + (y * surface_width + x0 + offset) * m_color_bytes); char* addr_d = ((char*)(m_phy_fb)+(y * m_width + x0) * m_color_bytes); memcpy(addr_d, addr_s, (width - offset) * m_color_bytes); //Right surface - addr_s = ((char*)(s1->m_fb) + (y * (s1->get_width()) + x0) * m_color_bytes); + addr_s = ((char*)(s1->m_fb) + (y * surface_width + x0) * m_color_bytes); addr_d = ((char*)(m_phy_fb)+(y * m_width + x0 + (width - offset)) * m_color_bytes); memcpy(addr_d, addr_s, offset * m_color_bytes); } } - else if (m_color_bytes == 4) + else if (m_color_bytes == 2) { - void(*draw_pixel)(int x, int y, unsigned int rgb) = ((c_surface_no_fb*)s0)->m_gfx_op->draw_pixel; + void(*draw_pixel)(int x, int y, unsigned int rgb) = m_driver->draw_pixel; for (int y = y0; y <= y1; y++) { //Left surface for (int x = x0; x <= (x1 - offset); x++) { - draw_pixel(x, y, ((unsigned int*)s0->m_fb)[y * m_width + x + offset]); + draw_pixel(x, y, GL_RGB_16_to_32(((unsigned short*)s0->m_fb)[y * m_width + x + offset])); } //Right surface for (int x = x1 - offset; x <= x1; x++) { - draw_pixel(x, y, ((unsigned int*)s1->m_fb)[y * m_width + x + offset - x1 + x0]); + draw_pixel(x, y, GL_RGB_16_to_32(((unsigned short*)s1->m_fb)[y * m_width + x + offset - x1 + x0])); } } } - else if (m_color_bytes == 2) + else //m_color_bytes == 3/4... { - void(*draw_pixel)(int x, int y, unsigned int rgb) = ((c_surface_no_fb*)s0)->m_gfx_op->draw_pixel; + void(*draw_pixel)(int x, int y, unsigned int rgb) = m_driver->draw_pixel; for (int y = y0; y <= y1; y++) { //Left surface for (int x = x0; x <= (x1 - offset); x++) { - draw_pixel(x, y, GL_RGB_16_to_32(((unsigned short*)s0->m_fb)[y * m_width + x + offset])); + draw_pixel(x, y, ((unsigned int*)s0->m_fb)[y * m_width + x + offset]); } //Right surface for (int x = x1 - offset; x <= x1; x++) { - draw_pixel(x, y, GL_RGB_16_to_32(((unsigned short*)s1->m_fb)[y * m_width + x + offset - x1 + x0])); + draw_pixel(x, y, ((unsigned int*)s1->m_fb)[y * m_width + x + offset - x1 + x0]); } } } @@ -3407,22 +3371,12 @@ private: #ifdef GUILITE_ON c_bitmap_operator the_bitmap_op = c_bitmap_operator(); c_image_operator* c_image::image_operator = &the_bitmap_op; +const void* c_theme::s_font_map[FONT_MAX]; +const void* c_theme::s_image_map[IMAGE_MAX]; +unsigned int c_theme::s_color_map[COLOR_MAX]; +c_lattice_font_op the_lattice_font_op = c_lattice_font_op(); +c_font_operator* c_word::fontOperator = &the_lattice_font_op; #endif - -#ifdef GUILITE_ON - -const void* c_theme::s_font_map[FONT_MAX]; -const void* c_theme::s_image_map[IMAGE_MAX]; -unsigned int c_theme::s_color_map[COLOR_MAX]; - -#endif - -#ifdef GUILITE_ON - -c_lattice_font_op the_lattice_font_op = c_lattice_font_op(); -c_font_operator* c_word::fontOperator = &the_lattice_font_op; - -#endif #ifdef GUILITE_ON #if (defined __linux__) || (defined __APPLE__) #include @@ -4264,11 +4218,7 @@ int c_fifo::write(void* buf, int len) #endif #ifdef GUILITE_ON DIALOG_ARRAY c_dialog::ms_the_dialogs[SURFACE_CNT_MAX]; -#endif -#ifdef GUILITE_ON c_keyboard c_edit::s_keyboard; -#endif -#ifdef GUILITE_ON static c_keyboard_button s_key_0, s_key_1, s_key_2, s_key_3, s_key_4, s_key_5, s_key_6, s_key_7, s_key_8, s_key_9; static c_keyboard_button s_key_A, s_key_B, s_key_C, s_key_D, s_key_E, s_key_F, s_key_G, s_key_H, s_key_I, s_key_J; static c_keyboard_button s_key_K, s_key_L, s_key_M, s_key_N, s_key_O, s_key_P, s_key_Q, s_key_R, s_key_S, s_key_T; @@ -4306,12 +4256,12 @@ WND_TREE g_key_board_children[] = {&s_key_B, 'B', 0, ((KEY_WIDTH / 2) + POS_X(5)), POS_Y(2), KEY_WIDTH, KEY_HEIGHT}, {&s_key_N, 'N', 0, ((KEY_WIDTH / 2) + POS_X(6)), POS_Y(2), KEY_WIDTH, KEY_HEIGHT}, {&s_key_M, 'M', 0, ((KEY_WIDTH / 2) + POS_X(7)), POS_Y(2), KEY_WIDTH, KEY_HEIGHT}, - {&s_key_del, 0x7F, 0, ((KEY_WIDTH / 2) + POS_X(8)), POS_Y(2), DEL_WIDTH, KEY_HEIGHT}, + {&s_key_del,0x7F, 0, ((KEY_WIDTH / 2) + POS_X(8)), POS_Y(2), DEL_WIDTH, KEY_HEIGHT}, //Row 4 - {&s_key_esc, 0x1B, 0, POS_X(0), POS_Y(3), ESC_WIDTH, KEY_HEIGHT}, + {&s_key_esc, 0x1B, 0, POS_X(0), POS_Y(3), ESC_WIDTH, KEY_HEIGHT}, {&s_key_num_switch, 0x90, 0, POS_X(2), POS_Y(3), SWITCH_WIDTH, KEY_HEIGHT}, {&s_key_space, ' ', 0, ((KEY_WIDTH / 2) + POS_X(3)), POS_Y(3), SPACE_WIDTH, KEY_HEIGHT}, - {&s_key_dot, '.', 0, ((KEY_WIDTH / 2) + POS_X(6)), POS_Y(3), DOT_WIDTH, KEY_HEIGHT}, + {&s_key_dot, '.', 0, ((KEY_WIDTH / 2) + POS_X(6)), POS_Y(3), DOT_WIDTH, KEY_HEIGHT}, {&s_key_enter, '\n', 0, POS_X(8), POS_Y(3), ENTER_WIDTH, KEY_HEIGHT}, {0,0,0,0,0,0,0} }; @@ -4326,12 +4276,11 @@ WND_TREE g_number_board_children[] = {&s_key_7, '7', 0, POS_X(0), POS_Y(2), KEY_WIDTH, KEY_HEIGHT}, {&s_key_8, '8', 0, POS_X(1), POS_Y(2), KEY_WIDTH, KEY_HEIGHT}, {&s_key_9, '9', 0, POS_X(2), POS_Y(2), KEY_WIDTH, KEY_HEIGHT}, - - {&s_key_esc, 0x1B, 0, POS_X(0), POS_Y(3), KEY_WIDTH, KEY_HEIGHT}, + {&s_key_esc,0x1B, 0, POS_X(0), POS_Y(3), KEY_WIDTH, KEY_HEIGHT}, {&s_key_0, '0', 0, POS_X(1), POS_Y(3), KEY_WIDTH, KEY_HEIGHT}, - {&s_key_dot, '.', 0, POS_X(2), POS_Y(3), KEY_WIDTH, KEY_HEIGHT}, + {&s_key_dot,'.', 0, POS_X(2), POS_Y(3), KEY_WIDTH, KEY_HEIGHT}, {&s_key_del, 0x7F, 0, POS_X(3), POS_Y(0), KEY_WIDTH, KEY_HEIGHT * 2 + 2}, {&s_key_enter,'\n', 0, POS_X(3), POS_Y(2), KEY_WIDTH, KEY_HEIGHT * 2 + 2}, {0,0,0,0,0,0,0} }; -#endif +#endif \ No newline at end of file diff --git a/HelloParticle/UIcode/UIcode.cpp b/HelloParticle/UIcode/UIcode.cpp index 5f0aea572b08d9394926e60558f344468c2367f9..825ea57cb8c2859544e25c0c2855c774bf52eb3f 100644 --- a/HelloParticle/UIcode/UIcode.cpp +++ b/HelloParticle/UIcode/UIcode.cpp @@ -48,22 +48,12 @@ void load_resource() { } c_particle particle_array[100]; -void create_ui(void* phy_fb, int screen_width, int screen_height, int color_bytes, struct EXTERNAL_GFX_OP* gfx_op) { +void create_ui(void* phy_fb, int screen_width, int screen_height, int color_bytes, struct DISPLAY_DRIVER* driver) { load_resource(); - if (phy_fb) - { - static c_surface surface(UI_WIDTH, UI_HEIGHT, color_bytes, Z_ORDER_LEVEL_0); - static c_display display(phy_fb, screen_width, screen_height, &surface); - s_surface = &surface; - s_display = &display; - } - else - {//for MCU without framebuffer - static c_surface_no_fb surface_no_fb(UI_WIDTH, UI_HEIGHT, color_bytes, gfx_op, Z_ORDER_LEVEL_0); - static c_display display(phy_fb, screen_width, screen_height, &surface_no_fb); - s_surface = &surface_no_fb; - s_display = &display; - } + static c_surface surface(UI_WIDTH, UI_HEIGHT, color_bytes, Z_ORDER_LEVEL_0); + static c_display display(phy_fb, screen_width, screen_height, &surface, driver); + s_surface = &surface; + s_display = &display; s_surface->fill_rect(0, 0, UI_WIDTH - 1, UI_HEIGHT - 1, 0, Z_ORDER_LEVEL_0); c_word::draw_string(s_surface, Z_ORDER_LEVEL_0, "\xe7\xa5\x9d\x47\x75\x69\x4c\x69\x74\x65\xe5\xbc\x80\xe5\x8f\x91\xe8\x80\x85\xef\xbc\x9a", 10, 10, c_theme::get_font(FONT_DEFAULT), GL_RGB(255, 0, 0), GL_ARGB(0, 0, 0, 0)); @@ -79,8 +69,8 @@ void create_ui(void* phy_fb, int screen_width, int screen_height, int color_byte } //////////////////////// interface for all platform //////////////////////// -extern "C" void startHelloParticle(void* phy_fb, int width, int height, int color_bytes, struct EXTERNAL_GFX_OP* gfx_op) { - create_ui(phy_fb, width, height, color_bytes, gfx_op); +extern "C" void startHelloParticle(void* phy_fb, int width, int height, int color_bytes, struct DISPLAY_DRIVER* driver) { + create_ui(phy_fb, width, height, color_bytes, driver); } extern "C" void* getUiOfHelloParticle(int* width, int* height, bool force_update = false) diff --git a/HelloPendulum/BuildLinux/.sync_build.sh b/HelloPendulum/BuildLinux/.sync_build.sh index 49cff5b473ac606967676ebefa6f0d333e301227..f0035276ccb9a921a041487cf6011fff284c5154 100644 --- a/HelloPendulum/BuildLinux/.sync_build.sh +++ b/HelloPendulum/BuildLinux/.sync_build.sh @@ -1,5 +1,6 @@ if [ "$#" -ne 1 ]; then - echo "Invalid arguments" + echo "Do testing" + ./xWindow 240 320 | ./HelloPendulum shared-fb exit -1 fi diff --git a/HelloPendulum/BuildLinux/main.cpp b/HelloPendulum/BuildLinux/main.cpp index e79cb38c07f70d96c1ad859f261cca537f3370a7..76d9eb746b131a1ded9780230fd2bcc404ba8ebd 100644 --- a/HelloPendulum/BuildLinux/main.cpp +++ b/HelloPendulum/BuildLinux/main.cpp @@ -10,7 +10,7 @@ #include #include -extern "C" void startHelloPendulum(void* phy_fb, int width, int height, int color_bytes, struct EXTERNAL_GFX_OP* gfx_op); +extern "C" void startHelloPendulum(void* phy_fb, int width, int height, int color_bytes, struct DISPLAY_DRIVER* driver); extern void init_std_io(); static void* get_embeded_fb_in_display_app(int shared_id); diff --git a/HelloPendulum/BuildMFC/HelloPendulumDlg.cpp b/HelloPendulum/BuildMFC/HelloPendulumDlg.cpp index a8e967122bd2ec1e52b928302cba3a4167f76545..b2e0eb488c49a9ed9c003e3c8ab64f751b0de0c8 100644 Binary files a/HelloPendulum/BuildMFC/HelloPendulumDlg.cpp and b/HelloPendulum/BuildMFC/HelloPendulumDlg.cpp differ diff --git a/HelloPendulum/BuildMFC/HelloPendulumDlg.h b/HelloPendulum/BuildMFC/HelloPendulumDlg.h index a208fd682ee5af533f824d20c05e8802c2449596..10f16c228e2d905f866a013f3a0f87eb17f0d672 100644 Binary files a/HelloPendulum/BuildMFC/HelloPendulumDlg.h and b/HelloPendulum/BuildMFC/HelloPendulumDlg.h differ diff --git a/HelloPendulum/BuildSTM32F103-Keil/USER/main.c b/HelloPendulum/BuildSTM32F103-Keil/USER/main.c index 6d448a0cf3ddeacc4c526f054e7f8bc5931cdc92..0bc2942c752201944f8da863db7cbd96530645e1 100644 --- a/HelloPendulum/BuildSTM32F103-Keil/USER/main.c +++ b/HelloPendulum/BuildSTM32F103-Keil/USER/main.c @@ -15,12 +15,12 @@ void gfx_draw_pixel(int x, int y, unsigned int rgb) //void gfx_fill_rect(int x0, int y0, int x1, int y1, unsigned int rgb){} //UI entry -struct EXTERNAL_GFX_OP +struct DISPLAY_DRIVER { void (*draw_pixel)(int x, int y, unsigned int rgb); void (*fill_rect)(int x0, int y0, int x1, int y1, unsigned int rgb); -} my_gfx_op; -extern void startHelloPendulum(void* phy_fb, int width, int height, int color_bytes, struct EXTERNAL_GFX_OP* gfx_op); +} my_driver; +extern void startHelloPendulum(void* phy_fb, int width, int height, int color_bytes, struct DISPLAY_DRIVER* driver); int main(void) { @@ -30,8 +30,8 @@ int main(void) LCD_Init(); //Link your LCD driver & start UI: - my_gfx_op.draw_pixel = gfx_draw_pixel; - my_gfx_op.fill_rect = NULL;//gfx_fill_rect; - startHelloPendulum(NULL, 240, 320, 2, &my_gfx_op); + my_driver.draw_pixel = gfx_draw_pixel; + my_driver.fill_rect = NULL;//gfx_fill_rect; + startHelloPendulum(NULL, 240, 320, 2, &my_driver); while(1); } diff --git a/HelloPendulum/BuildWin32/HelloPendulum.cpp b/HelloPendulum/BuildWin32/HelloPendulum.cpp index de73716040bfae31242656edd8b738d331be4527..0eb7eba7b507b10cd5ea4b14afc04a7747c45c9e 100644 --- a/HelloPendulum/BuildWin32/HelloPendulum.cpp +++ b/HelloPendulum/BuildWin32/HelloPendulum.cpp @@ -161,7 +161,7 @@ LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam) } //////////////////////// HelloPendulum Interface //////////////////////// -extern "C" void startHelloPendulum(void* phy_fb, int width, int height, int color_bytes, struct EXTERNAL_GFX_OP* gfx_op); +extern "C" void startHelloPendulum(void* phy_fb, int width, int height, int color_bytes, struct DISPLAY_DRIVER* driver); DWORD WINAPI ThreadHelloPendulum(LPVOID pParam) { diff --git a/HelloPendulum/UIcode/GuiLite.h b/HelloPendulum/UIcode/GuiLite.h index c4fc88a51476d2c8309c3e55e1270e13784fc510..80550e1632ad7bc82541a2edbb0f7f8f5937954f 100644 --- a/HelloPendulum/UIcode/GuiLite.h +++ b/HelloPendulum/UIcode/GuiLite.h @@ -1,107 +1,94 @@ #pragma once - -#define REAL_TIME_TASK_CYCLE_MS 50 -#define MAX(a,b) (((a)>(b))?(a):(b)) -#define MIN(a,b) (((a)<(b))?(a):(b)) - -#define GL_ARGB(a, r, g, b) ((((unsigned int)(a)) << 24) | (((unsigned int)(r)) << 16) | (((unsigned int)(g)) << 8) | ((unsigned int)(b))) -#define GL_ARGB_A(rgb) ((((unsigned int)(rgb)) >> 24) & 0xFF) - -#define GL_RGB(r, g, b) ((0xFF << 24) | (((unsigned int)(r)) << 16) | (((unsigned int)(g)) << 8) | ((unsigned int)(b))) -#define GL_RGB_R(rgb) ((((unsigned int)(rgb)) >> 16) & 0xFF) -#define GL_RGB_G(rgb) ((((unsigned int)(rgb)) >> 8) & 0xFF) -#define GL_RGB_B(rgb) (((unsigned int)(rgb)) & 0xFF) -#define GL_RGB_32_to_16(rgb) (((((unsigned int)(rgb)) & 0xFF) >> 3) | ((((unsigned int)(rgb)) & 0xFC00) >> 5) | ((((unsigned int)(rgb)) & 0xF80000) >> 8)) -#define GL_RGB_16_to_32(rgb) ((0xFF << 24) | ((((unsigned int)(rgb)) & 0x1F) << 3) | ((((unsigned int)(rgb)) & 0x7E0) << 5) | ((((unsigned int)(rgb)) & 0xF800) << 8)) - -#define ALIGN_HCENTER 0x00000000L -#define ALIGN_LEFT 0x01000000L -#define ALIGN_RIGHT 0x02000000L -#define ALIGN_HMASK 0x03000000L - -#define ALIGN_VCENTER 0x00000000L -#define ALIGN_TOP 0x00100000L -#define ALIGN_BOTTOM 0x00200000L -#define ALIGN_VMASK 0x00300000L - -typedef struct -{ - unsigned short year; - unsigned short month; - unsigned short date; - unsigned short day; - unsigned short hour; - unsigned short minute; - unsigned short second; -}T_TIME; - -void register_debug_function(void(*my_assert)(const char* file, int line), void(*my_log_out)(const char* log)); -void _assert(const char* file, int line); -#define ASSERT(condition) \ - do{ \ - if(!(condition))_assert(__FILE__, __LINE__);\ - }while(0) -void log_out(const char* log); - -long get_time_in_second(); -T_TIME second_to_day(long second); -T_TIME get_time(); - -void start_real_timer(void (*func)(void* arg)); -void register_timer(int milli_second, void func(void* param), void* param); - -unsigned int get_cur_thread_id(); -void create_thread(unsigned long* thread_id, void* attr, void *(*start_routine) (void *), void* arg); -void thread_sleep(unsigned int milli_seconds); -int build_bmp(const char *filename, unsigned int width, unsigned int height, unsigned char *data); - -#define FIFO_BUFFER_LEN 1024 -class c_fifo -{ -public: - c_fifo(); - int read(void* buf, int len); - int write(void* buf, int len); -private: - unsigned char m_buf[FIFO_BUFFER_LEN]; - int m_head; - int m_tail; - void* m_read_sem; - void* m_write_mutex; -}; - -class c_rect -{ -public: - c_rect(){ m_left = m_top = m_right = m_bottom = -1; } - c_rect(int left, int top, int width, int height) - { - set_rect(left, top, width, height); - } - void set_rect(int left, int top, int width, int height) - { - ASSERT(width > 0 && height > 0); - m_left = left; - m_top = top; - m_right = left + width - 1; - m_bottom = top + height -1; - } - bool pt_in_rect(int x, int y) const - { - return x >= m_left && x <= m_right && y >= m_top && y <= m_bottom; - } - int operator==(const c_rect& rect) const - { - return (m_left == rect.m_left) && (m_top == rect.m_top) && (m_right == rect.m_right) && (m_bottom == rect.m_bottom); - } - int width() const { return m_right - m_left + 1; } - int height() const { return m_bottom - m_top + 1 ; } - - int m_left; - int m_top; - int m_right; - int m_bottom; -}; +#define REAL_TIME_TASK_CYCLE_MS 50 +#define MAX(a,b) (((a)>(b))?(a):(b)) +#define MIN(a,b) (((a)<(b))?(a):(b)) +#define GL_ARGB(a, r, g, b) ((((unsigned int)(a)) << 24) | (((unsigned int)(r)) << 16) | (((unsigned int)(g)) << 8) | ((unsigned int)(b))) +#define GL_ARGB_A(rgb) ((((unsigned int)(rgb)) >> 24) & 0xFF) +#define GL_RGB(r, g, b) ((0xFF << 24) | (((unsigned int)(r)) << 16) | (((unsigned int)(g)) << 8) | ((unsigned int)(b))) +#define GL_RGB_R(rgb) ((((unsigned int)(rgb)) >> 16) & 0xFF) +#define GL_RGB_G(rgb) ((((unsigned int)(rgb)) >> 8) & 0xFF) +#define GL_RGB_B(rgb) (((unsigned int)(rgb)) & 0xFF) +#define GL_RGB_32_to_16(rgb) (((((unsigned int)(rgb)) & 0xFF) >> 3) | ((((unsigned int)(rgb)) & 0xFC00) >> 5) | ((((unsigned int)(rgb)) & 0xF80000) >> 8)) +#define GL_RGB_16_to_32(rgb) ((0xFF << 24) | ((((unsigned int)(rgb)) & 0x1F) << 3) | ((((unsigned int)(rgb)) & 0x7E0) << 5) | ((((unsigned int)(rgb)) & 0xF800) << 8)) +#define ALIGN_HCENTER 0x00000000L +#define ALIGN_LEFT 0x01000000L +#define ALIGN_RIGHT 0x02000000L +#define ALIGN_HMASK 0x03000000L +#define ALIGN_VCENTER 0x00000000L +#define ALIGN_TOP 0x00100000L +#define ALIGN_BOTTOM 0x00200000L +#define ALIGN_VMASK 0x00300000L +typedef struct +{ + unsigned short year; + unsigned short month; + unsigned short date; + unsigned short day; + unsigned short hour; + unsigned short minute; + unsigned short second; +}T_TIME; +void register_debug_function(void(*my_assert)(const char* file, int line), void(*my_log_out)(const char* log)); +void _assert(const char* file, int line); +#define ASSERT(condition) \ + do{ \ + if(!(condition))_assert(__FILE__, __LINE__);\ + }while(0) +void log_out(const char* log); +long get_time_in_second(); +T_TIME second_to_day(long second); +T_TIME get_time(); +void start_real_timer(void (*func)(void* arg)); +void register_timer(int milli_second, void func(void* param), void* param); +unsigned int get_cur_thread_id(); +void create_thread(unsigned long* thread_id, void* attr, void *(*start_routine) (void *), void* arg); +void thread_sleep(unsigned int milli_seconds); +int build_bmp(const char *filename, unsigned int width, unsigned int height, unsigned char *data); +#define FIFO_BUFFER_LEN 1024 +class c_fifo +{ +public: + c_fifo(); + int read(void* buf, int len); + int write(void* buf, int len); +private: + unsigned char m_buf[FIFO_BUFFER_LEN]; + int m_head; + int m_tail; + void* m_read_sem; + void* m_write_mutex; +}; +class c_rect +{ +public: + c_rect(){ m_left = m_top = m_right = m_bottom = -1; } + c_rect(int left, int top, int width, int height) + { + set_rect(left, top, width, height); + } + void set_rect(int left, int top, int width, int height) + { + ASSERT(width > 0 && height > 0); + m_left = left; + m_top = top; + m_right = left + width - 1; + m_bottom = top + height -1; + } + bool pt_in_rect(int x, int y) const + { + return x >= m_left && x <= m_right && y >= m_top && y <= m_bottom; + } + int operator==(const c_rect& rect) const + { + return (m_left == rect.m_left) && (m_top == rect.m_top) && (m_right == rect.m_right) && (m_bottom == rect.m_bottom); + } + int width() const { return m_right - m_left + 1; } + int height() const { return m_bottom - m_top + 1 ; } + int m_left; + int m_top; + int m_right; + int m_bottom; +}; //BITMAP typedef struct struct_bitmap_info { @@ -238,7 +225,7 @@ typedef enum Z_ORDER_LEVEL_2,//highest graphic level Z_ORDER_LEVEL_MAX }Z_ORDER_LEVEL; -struct EXTERNAL_GFX_OP +struct DISPLAY_DRIVER { void(*draw_pixel)(int x, int y, unsigned int rgb); void(*fill_rect)(int x0, int y0, int x1, int y1, unsigned int rgb); @@ -247,18 +234,19 @@ class c_surface; class c_display { friend class c_surface; public: - inline c_display(void* phy_fb, int display_width, int display_height, int surface_width, int surface_height, unsigned int color_bytes, int surface_cnt, EXTERNAL_GFX_OP* gfx_op = 0);//multiple surface or surface_no_fb - inline c_display(void* phy_fb, int display_width, int display_height, c_surface* surface);//single custom surface - inline c_surface* alloc_surface(Z_ORDER_LEVEL max_zorder, c_rect layer_rect = c_rect());//for multiple surfaces + inline c_display(void* phy_fb, int display_width, int display_height, c_surface* surface, DISPLAY_DRIVER* driver = 0);//single custom surface + inline c_display(void* phy_fb, int display_width, int display_height, int surface_width, int surface_height, unsigned int color_bytes, int surface_cnt, DISPLAY_DRIVER* driver = 0);//multiple surface + inline c_surface* alloc_surface(Z_ORDER_LEVEL max_zorder, c_rect layer_rect = c_rect());//for slide group inline int swipe_surface(c_surface* s0, c_surface* s1, int x0, int x1, int y0, int y1, int offset); int get_width() { return m_width; } int get_height() { return m_height; } + void* get_phy_fb() { return m_phy_fb; } void* get_updated_fb(int* width, int* height, bool force_update = false) { if (width && height) { - *width = get_width(); - *height = get_height(); + *width = m_width; + *height = m_height; } if (force_update) { @@ -277,35 +265,123 @@ public: { return -1; } - int width = get_width(); - int height = get_height(); //16 bits framebuffer if (m_color_bytes == 2) { - return build_bmp(file_name, width, height, (unsigned char*)m_phy_fb); + return build_bmp(file_name, m_width, m_height, (unsigned char*)m_phy_fb); } //32 bits framebuffer - unsigned short* p_bmp565_data = new unsigned short[width * height]; + unsigned short* p_bmp565_data = new unsigned short[m_width * m_height]; unsigned int* p_raw_data = (unsigned int*)m_phy_fb; - for (int i = 0; i < width * height; i++) + for (int i = 0; i < m_width * m_height; i++) { unsigned int rgb = *p_raw_data++; p_bmp565_data[i] = GL_RGB_32_to_16(rgb); } - int ret = build_bmp(file_name, width, height, (unsigned char*)p_bmp565_data); + int ret = build_bmp(file_name, m_width, m_height, (unsigned char*)p_bmp565_data); delete[]p_bmp565_data; return ret; } -private: - int m_width; //in pixels - int m_height; //in pixels - int m_color_bytes; //16 bits, 32 bits only - void* m_phy_fb; //physical framebuffer +protected: + virtual void draw_pixel(int x, int y, unsigned int rgb) + { + if ((x >= m_width) || (y >= m_height)) { return; } + if (m_driver && m_driver->draw_pixel) + { + return m_driver->draw_pixel(x, y, rgb); + } + if (m_color_bytes == 2) + { + ((unsigned short*)m_phy_fb)[y * m_width + x] = GL_RGB_32_to_16(rgb); + } + else + { + ((unsigned int*)m_phy_fb)[y * m_width + x] = rgb; + } + } + virtual void fill_rect(int x0, int y0, int x1, int y1, unsigned int rgb) + { + if (m_driver && m_driver->fill_rect) + { + return m_driver->fill_rect(x0, y0, x1, y1, rgb); + } + if (m_driver && m_driver->draw_pixel) + { + for (int y = y0; y <= y1; y++) + { + for (int x = x0; x <= x1; x++) + { + m_driver->draw_pixel(x, y, rgb); + } + } + return; + } + register int _width = m_width; + register int _height = m_height; + int x, y; + if (m_color_bytes == 2) + { + unsigned short* phy_fb; + unsigned int rgb_16 = GL_RGB_32_to_16(rgb); + for (y = y0; y <= y1; y++) + { + phy_fb = &((unsigned short*)m_phy_fb)[y * _width + x0]; + for (x = x0; x <= x1; x++) + { + if ((x < _width) && (y < _height)) + { + *phy_fb++ = rgb_16; + } + } + } + } + else + { + unsigned int* phy_fb; + for (y = y0; y <= y1; y++) + { + phy_fb = &((unsigned int*)m_phy_fb)[y * _width + x0]; + for (x = x0; x <= x1; x++) + { + if ((x < _width) && (y < _height)) + { + *phy_fb++ = rgb; + } + } + } + } + } + virtual int flush_screen(int left, int top, int right, int bottom, void* fb, int fb_width) + { + if ((0 == m_phy_fb) || (0 == fb)) + { + return -1; + } + register int _width = m_width; + register int _height = m_height; + left = (left >= _width) ? (_width - 1) : left; + right = (right >= _width) ? (_width - 1) : right; + top = (top >= _height) ? (_height - 1) : top; + bottom = (bottom >= _height) ? (_height - 1) : bottom; + for (int y = top; y < bottom; y++) + { + void* s_addr = (char*)fb + ((y * fb_width + left) * m_color_bytes); + void* d_addr = (char*)m_phy_fb + ((y * _width + left) * m_color_bytes); + memcpy(d_addr, s_addr, (right - left) * m_color_bytes); + } + return 0; + } + int m_width; //in pixels + int m_height; //in pixels + int m_color_bytes; //16/32 bits for default + void* m_phy_fb; //physical framebuffer for default + struct DISPLAY_DRIVER* m_driver; //Rendering by external method without default physical framebuffer int m_phy_read_index; int m_phy_write_index; c_surface* m_surface_group[SURFACE_CNT_MAX]; int m_surface_cnt; //surface count int m_surface_index; + }; class c_layer { @@ -317,12 +393,10 @@ public: class c_surface { friend class c_display; friend class c_bitmap_operator; public: - c_surface(unsigned int width, unsigned int height, unsigned int color_bytes, Z_ORDER_LEVEL max_zorder = Z_ORDER_LEVEL_0, c_rect overlpa_rect = c_rect()) : m_width(width), m_height(height), m_color_bytes(color_bytes), m_fb(0), m_is_active(false), m_top_zorder(Z_ORDER_LEVEL_0), m_phy_fb(0), m_phy_write_index(0), m_display(0) + c_surface(unsigned int width, unsigned int height, unsigned int color_bytes, Z_ORDER_LEVEL max_zorder = Z_ORDER_LEVEL_0, c_rect overlpa_rect = c_rect()) : m_width(width), m_height(height), m_color_bytes(color_bytes), m_fb(0), m_is_active(false), m_top_zorder(Z_ORDER_LEVEL_0), m_phy_write_index(0), m_display(0) { (overlpa_rect == c_rect()) ? set_surface(max_zorder, c_rect(0, 0, width - 1, height - 1)) : set_surface(max_zorder, overlpa_rect); } - int get_width() { return m_width; } - int get_height() { return m_height; } unsigned int get_pixel(int x, int y, unsigned int z_order) { if (x >= m_width || y >= m_height || x < 0 || y < 0 || z_order >= Z_ORDER_LEVEL_MAX) @@ -332,15 +406,15 @@ public: } if (m_layers[z_order].fb) { - return (m_color_bytes == 4) ? ((unsigned int*)(m_layers[z_order].fb))[y * m_width + x] : GL_RGB_16_to_32(((unsigned short*)(m_layers[z_order].fb))[y * m_width + x]); + return (m_color_bytes == 2) ? GL_RGB_16_to_32(((unsigned short*)(m_layers[z_order].fb))[y * m_width + x]) : ((unsigned int*)(m_layers[z_order].fb))[y * m_width + x]; } else if (m_fb) { - return (m_color_bytes == 4) ? ((unsigned int*)m_fb)[y * m_width + x] : GL_RGB_16_to_32(((unsigned short*)m_fb)[y * m_width + x]); + return (m_color_bytes == 2) ? GL_RGB_16_to_32(((unsigned short*)m_fb)[y * m_width + x]) : ((unsigned int*)m_fb)[y * m_width + x]; } - else if (m_phy_fb) + else if (m_display->m_phy_fb) { - return (m_color_bytes == 4) ? ((unsigned int*)m_phy_fb)[y * m_width + x] : GL_RGB_16_to_32(((unsigned short*)m_phy_fb)[y * m_width + x]); + return (m_color_bytes == 2) ? GL_RGB_16_to_32(((unsigned short*)m_display->m_phy_fb)[y * m_width + x]) : ((unsigned int*)m_display->m_phy_fb)[y * m_width + x]; } return 0; } @@ -357,7 +431,7 @@ public: } if (z_order == m_max_zorder) { - return draw_pixel_on_fb(x, y, rgb); + return draw_pixel_low_level(x, y, rgb); } if (z_order > (unsigned int)m_top_zorder) @@ -367,19 +441,19 @@ public: if (m_layers[z_order].rect.pt_in_rect(x, y)) { c_rect layer_rect = m_layers[z_order].rect; - if (m_color_bytes == 4) + if (m_color_bytes == 2) { - ((unsigned int*)(m_layers[z_order].fb))[(x - layer_rect.m_left) + (y - layer_rect.m_top) * layer_rect.width()] = rgb; + ((unsigned short*)(m_layers[z_order].fb))[(x - layer_rect.m_left) + (y - layer_rect.m_top) * layer_rect.width()] = GL_RGB_32_to_16(rgb); } else { - ((unsigned short*)(m_layers[z_order].fb))[(x - layer_rect.m_left) + (y - layer_rect.m_top) * layer_rect.width()] = GL_RGB_32_to_16(rgb); + ((unsigned int*)(m_layers[z_order].fb))[(x - layer_rect.m_left) + (y - layer_rect.m_top) * layer_rect.width()] = rgb; } } if (z_order == m_top_zorder) { - return draw_pixel_on_fb(x, y, rgb); + return draw_pixel_low_level(x, y, rgb); } bool be_overlapped = false; for (unsigned int tmp_z_order = Z_ORDER_LEVEL_MAX - 1; tmp_z_order > z_order; tmp_z_order--) @@ -392,7 +466,7 @@ public: } if (!be_overlapped) { - draw_pixel_on_fb(x, y, rgb); + draw_pixel_low_level(x, y, rgb); } } virtual void fill_rect(int x0, int y0, int x1, int y1, unsigned int rgb, unsigned int z_order) @@ -403,7 +477,7 @@ public: y1 = (y1 > (m_height - 1)) ? (m_height - 1) : y1; if (z_order == m_max_zorder) { - return fill_rect_on_fb(x0, y0, x1, y1, rgb); + return fill_rect_low_level(x0, y0, x1, y1, rgb); } if (z_order == m_top_zorder) { @@ -416,18 +490,18 @@ public: { if (layer_rect.pt_in_rect(x, y)) { - if (m_color_bytes == 4) + if (m_color_bytes == 2) { - ((unsigned int*)m_layers[z_order].fb)[(y - layer_rect.m_top) * layer_rect.width() + (x - layer_rect.m_left)] = rgb; + ((unsigned short*)m_layers[z_order].fb)[(y - layer_rect.m_top) * layer_rect.width() + (x - layer_rect.m_left)] = rgb_16; } else { - ((unsigned short*)m_layers[z_order].fb)[(y - layer_rect.m_top) * layer_rect.width() + (x - layer_rect.m_left)] = rgb_16; + ((unsigned int*)m_layers[z_order].fb)[(y - layer_rect.m_top) * layer_rect.width() + (x - layer_rect.m_left)] = rgb; } } } } - return fill_rect_on_fb(x0, y0, x1, y1, rgb); + return fill_rect_low_level(x0, y0, x1, y1, rgb); } for (; y0 <= y1; y0++) { @@ -499,27 +573,16 @@ public: } int flush_screen(int left, int top, int right, int bottom) { - if (left < 0 || left >= m_width || right < 0 || right >= m_width || - top < 0 || top >= m_height || bottom < 0 || bottom >= m_height) - { - ASSERT(false); - } - if (!m_is_active || (0 == m_phy_fb) || (0 == m_fb)) + if (!m_is_active) { return -1; } - int display_width = m_display->get_width(); - int display_height = m_display->get_height(); - left = (left >= display_width) ? (display_width - 1) : left; - right = (right >= display_width) ? (display_width - 1) : right; - top = (top >= display_height) ? (display_height - 1) : top; - bottom = (bottom >= display_height) ? (display_height - 1) : bottom; - for (int y = top; y < bottom; y++) + if (left < 0 || left >= m_width || right < 0 || right >= m_width || + top < 0 || top >= m_height || bottom < 0 || bottom >= m_height) { - void* s_addr = (char*)m_fb + ((y * m_width + left) * m_color_bytes); - void* d_addr = (char*)m_phy_fb + ((y * display_width + left) * m_color_bytes); - memcpy(d_addr, s_addr, (right - left) * m_color_bytes); + ASSERT(false); } + m_display->flush_screen(left, top, right, bottom, m_fb, m_width); *m_phy_write_index = *m_phy_write_index + 1; return 0; } @@ -537,90 +600,62 @@ public: { for (int x = rect.m_left; x <= rect.m_right; x++) { - unsigned int rgb = (m_color_bytes == 4) ? ((unsigned int*)fb)[(x - layer_rect.m_left) + (y - layer_rect.m_top) * width] : GL_RGB_16_to_32(((unsigned short*)fb)[(x - layer_rect.m_left) + (y - layer_rect.m_top) * width]); - draw_pixel_on_fb(x, y, rgb); + unsigned int rgb = (m_color_bytes == 2) ? GL_RGB_16_to_32(((unsigned short*)fb)[(x - layer_rect.m_left) + (y - layer_rect.m_top) * width]) : ((unsigned int*)fb)[(x - layer_rect.m_left) + (y - layer_rect.m_top) * width]; + draw_pixel_low_level(x, y, rgb); } } return 0; } void set_active(bool flag) { m_is_active = flag; } protected: - virtual void fill_rect_on_fb(int x0, int y0, int x1, int y1, unsigned int rgb) - { - int display_width = m_display->get_width(); - int display_height = m_display->get_height(); - if (m_color_bytes == 4) + virtual void fill_rect_low_level(int x0, int y0, int x1, int y1, unsigned int rgb) + {//fill rect on framebuffer of surface + int x, y; + if (m_color_bytes == 2) { - int x; - unsigned int* fb, * phy_fb; - for (; y0 <= y1; y0++) + unsigned short* fb; + unsigned int rgb_16 = GL_RGB_32_to_16(rgb); + for (y = y0; y <= y1; y++) { - x = x0; - fb = m_fb ? &((unsigned int*)m_fb)[y0 * m_width + x] : 0; - phy_fb = &((unsigned int*)m_phy_fb)[y0 * display_width + x]; - *m_phy_write_index = *m_phy_write_index + 1; - for (; x <= x1; x++) + fb = m_fb ? &((unsigned short*)m_fb)[y * m_width + x0] : 0; + if (!fb) { break; } + for (x = x0; x <= x1; x++) { - if (fb) - { - *fb++ = rgb; - } - if (m_is_active && (x < display_width) && (y0 < display_height)) - { - *phy_fb++ = rgb; - } + *fb++ = rgb_16; } } } - else if (m_color_bytes == 2) + else { - int x; - unsigned short* fb, * phy_fb; - rgb = GL_RGB_32_to_16(rgb); - for (; y0 <= y1; y0++) + unsigned int* fb; + for (y = y0; y <= y1; y++) { - x = x0; - fb = m_fb ? &((unsigned short*)m_fb)[y0 * m_width + x] : 0; - phy_fb = &((unsigned short*)m_phy_fb)[y0 * display_width + x]; - *m_phy_write_index = *m_phy_write_index + 1; - for (; x <= x1; x++) + fb = m_fb ? &((unsigned int*)m_fb)[y * m_width + x0] : 0; + if (!fb) { break; } + for (x = x0; x <= x1; x++) { - if (fb) - { - *fb++ = rgb; - } - if (m_is_active && (x < display_width) && (y0 < display_height)) - { - *phy_fb++ = rgb; - } + *fb++ = rgb; } } } + if (!m_is_active) { return; } + m_display->fill_rect(x0, y0, x1, y1, rgb); + *m_phy_write_index = *m_phy_write_index + 1; } - virtual void draw_pixel_on_fb(int x, int y, unsigned int rgb) + virtual void draw_pixel_low_level(int x, int y, unsigned int rgb) { if (m_fb) - { - (m_color_bytes == 4) ? ((unsigned int*)m_fb)[y * m_width + x] = rgb : ((unsigned short*)m_fb)[y * m_width + x] = GL_RGB_32_to_16(rgb); - } - if (m_is_active && (x < m_display->get_width()) && (y < m_display->get_height())) - { - if (m_color_bytes == 4) - { - ((unsigned int*)m_phy_fb)[y * (m_display->get_width()) + x] = rgb; - } - else - { - ((unsigned short*)m_phy_fb)[y * (m_display->get_width()) + x] = GL_RGB_32_to_16(rgb); - } - *m_phy_write_index = *m_phy_write_index + 1; + {//draw pixel on framebuffer of surface + (m_color_bytes == 2) ? ((unsigned short*)m_fb)[y * m_width + x] = GL_RGB_32_to_16(rgb): ((unsigned int*)m_fb)[y * m_width + x] = rgb; } + if (!m_is_active) { return; } + m_display->draw_pixel(x, y, rgb); + *m_phy_write_index = *m_phy_write_index + 1; } void attach_display(c_display* display) { ASSERT(display); m_display = display; - m_phy_fb = display->m_phy_fb; m_phy_write_index = &display->m_phy_write_index; } void set_surface(Z_ORDER_LEVEL max_z_order, c_rect layer_rect) @@ -638,87 +673,22 @@ protected: } int m_width; //in pixels int m_height; //in pixels - int m_color_bytes; //16 bits, 32 bits only + int m_color_bytes; //16 bits, 32 bits for default void* m_fb; //frame buffer you could see c_layer m_layers[Z_ORDER_LEVEL_MAX];//all graphic layers bool m_is_active; //active flag Z_ORDER_LEVEL m_max_zorder; //the highest graphic layer the surface will have Z_ORDER_LEVEL m_top_zorder; //the current highest graphic layer the surface have - void* m_phy_fb; //physical framebufer int* m_phy_write_index; c_display* m_display; }; -class c_surface_no_fb : public c_surface {//No physical framebuffer, render with external graphic interface - friend class c_display; -public: - c_surface_no_fb(unsigned int width, unsigned int height, unsigned int color_bytes, struct EXTERNAL_GFX_OP* gfx_op, Z_ORDER_LEVEL max_zorder = Z_ORDER_LEVEL_0, c_rect overlpa_rect = c_rect()) : c_surface(width, height, color_bytes, max_zorder, overlpa_rect), m_gfx_op(gfx_op) {} -protected: - virtual void fill_rect_on_fb(int x0, int y0, int x1, int y1, unsigned int rgb) - { - if (!m_gfx_op) - { - return; - } - if (m_gfx_op->fill_rect) - { - return m_gfx_op->fill_rect(x0, y0, x1, y1, rgb); - } - if (m_gfx_op->draw_pixel && m_is_active) - { - for (int y = y0; y <= y1; y++) - { - for (int x = x0; x <= x1; x++) - { - m_gfx_op->draw_pixel(x, y, rgb); - } - } - } - if (!m_fb) { return; } - if (m_color_bytes == 4) - { - unsigned int* fb; - for (int y = y0; y <= y1; y++) - { - fb = &((unsigned int*)m_fb)[y0 * m_width + x0]; - for (int x = x0; x <= x1; x++) - { - *fb++ = rgb; - } - } - } - else if (m_color_bytes == 2) - { - unsigned short* fb; - rgb = GL_RGB_32_to_16(rgb); - for (int y = y0; y <= y1; y++) - { - fb = &((unsigned short*)m_fb)[y0 * m_width + x0]; - for (int x = x0; x <= x1; x++) - { - *fb++ = rgb; - } - } - } - } - virtual void draw_pixel_on_fb(int x, int y, unsigned int rgb) - { - if (m_gfx_op && m_gfx_op->draw_pixel && m_is_active) - { - m_gfx_op->draw_pixel(x, y, rgb); - } - if (!m_fb) { return; } - if (m_color_bytes == 4) - { - ((unsigned int*)m_fb)[y * m_width + x] = rgb; - } - else if (m_color_bytes == 2) - { - ((unsigned short*)m_fb)[y * m_width + x] = GL_RGB_32_to_16(rgb); - } - } - struct EXTERNAL_GFX_OP* m_gfx_op;//Rendering by external method -}; -inline c_display::c_display(void* phy_fb, int display_width, int display_height, int surface_width, int surface_height, unsigned int color_bytes, int surface_cnt, EXTERNAL_GFX_OP* gfx_op) : m_width(display_width), m_height(display_height), m_color_bytes(color_bytes), m_phy_fb(phy_fb), m_phy_read_index(0), m_phy_write_index(0), m_surface_cnt(surface_cnt), m_surface_index(0) +inline c_display::c_display(void* phy_fb, int display_width, int display_height, c_surface* surface, DISPLAY_DRIVER* driver) : m_phy_fb(phy_fb), m_width(display_width), m_height(display_height), m_driver(driver), m_phy_read_index(0), m_phy_write_index(0), m_surface_cnt(1), m_surface_index(0) +{ + m_color_bytes = surface->m_color_bytes; + surface->m_is_active = true; + (m_surface_group[0] = surface)->attach_display(this); +} +inline c_display::c_display(void* phy_fb, int display_width, int display_height, int surface_width, int surface_height, unsigned int color_bytes, int surface_cnt, DISPLAY_DRIVER* driver) : m_phy_fb(phy_fb), m_width(display_width), m_height(display_height), m_color_bytes(color_bytes), m_phy_read_index(0), m_phy_write_index(0), m_surface_cnt(surface_cnt), m_driver(driver), m_surface_index(0) { ASSERT(color_bytes == 2 || color_bytes == 4); ASSERT(m_surface_cnt <= SURFACE_CNT_MAX); @@ -726,16 +696,10 @@ inline c_display::c_display(void* phy_fb, int display_width, int display_height, for (int i = 0; i < m_surface_cnt; i++) { - m_surface_group[i] = (phy_fb) ? new c_surface(surface_width, surface_height, color_bytes) : new c_surface_no_fb(surface_width, surface_height, color_bytes, gfx_op); + m_surface_group[i] = new c_surface(surface_width, surface_height, color_bytes); m_surface_group[i]->attach_display(this); } } -inline c_display::c_display(void* phy_fb, int display_width, int display_height, c_surface* surface) : m_width(display_width), m_height(display_height), m_phy_fb(phy_fb), m_phy_read_index(0), m_phy_write_index(0), m_surface_cnt(1), m_surface_index(0) -{ - m_color_bytes = surface->m_color_bytes; - surface->m_is_active = true; - (m_surface_group[0] = surface)->attach_display(this); -} inline c_surface* c_display::alloc_surface(Z_ORDER_LEVEL max_zorder, c_rect layer_rect) { ASSERT(max_zorder < Z_ORDER_LEVEL_MAX && m_surface_index < m_surface_cnt); @@ -744,8 +708,8 @@ inline c_surface* c_display::alloc_surface(Z_ORDER_LEVEL max_zorder, c_rect laye } inline int c_display::swipe_surface(c_surface* s0, c_surface* s1, int x0, int x1, int y0, int y1, int offset) { - int surface_width = s0->get_width(); - int surface_height = s0->get_height(); + register int surface_width = s0->m_width; + register int surface_height = s0->m_height; if (offset < 0 || offset > surface_width || y0 < 0 || y0 >= surface_height || y1 < 0 || y1 >= surface_height || x0 < 0 || x0 >= surface_width || x1 < 0 || x1 >= surface_width) { @@ -767,46 +731,46 @@ inline int c_display::swipe_surface(c_surface* s0, c_surface* s1, int x0, int x1 for (int y = y0; y <= y1; y++) { //Left surface - char* addr_s = ((char*)(s0->m_fb) + (y * (s0->get_width()) + x0 + offset) * m_color_bytes); + char* addr_s = ((char*)(s0->m_fb) + (y * surface_width + x0 + offset) * m_color_bytes); char* addr_d = ((char*)(m_phy_fb)+(y * m_width + x0) * m_color_bytes); memcpy(addr_d, addr_s, (width - offset) * m_color_bytes); //Right surface - addr_s = ((char*)(s1->m_fb) + (y * (s1->get_width()) + x0) * m_color_bytes); + addr_s = ((char*)(s1->m_fb) + (y * surface_width + x0) * m_color_bytes); addr_d = ((char*)(m_phy_fb)+(y * m_width + x0 + (width - offset)) * m_color_bytes); memcpy(addr_d, addr_s, offset * m_color_bytes); } } - else if (m_color_bytes == 4) + else if (m_color_bytes == 2) { - void(*draw_pixel)(int x, int y, unsigned int rgb) = ((c_surface_no_fb*)s0)->m_gfx_op->draw_pixel; + void(*draw_pixel)(int x, int y, unsigned int rgb) = m_driver->draw_pixel; for (int y = y0; y <= y1; y++) { //Left surface for (int x = x0; x <= (x1 - offset); x++) { - draw_pixel(x, y, ((unsigned int*)s0->m_fb)[y * m_width + x + offset]); + draw_pixel(x, y, GL_RGB_16_to_32(((unsigned short*)s0->m_fb)[y * m_width + x + offset])); } //Right surface for (int x = x1 - offset; x <= x1; x++) { - draw_pixel(x, y, ((unsigned int*)s1->m_fb)[y * m_width + x + offset - x1 + x0]); + draw_pixel(x, y, GL_RGB_16_to_32(((unsigned short*)s1->m_fb)[y * m_width + x + offset - x1 + x0])); } } } - else if (m_color_bytes == 2) + else //m_color_bytes == 3/4... { - void(*draw_pixel)(int x, int y, unsigned int rgb) = ((c_surface_no_fb*)s0)->m_gfx_op->draw_pixel; + void(*draw_pixel)(int x, int y, unsigned int rgb) = m_driver->draw_pixel; for (int y = y0; y <= y1; y++) { //Left surface for (int x = x0; x <= (x1 - offset); x++) { - draw_pixel(x, y, GL_RGB_16_to_32(((unsigned short*)s0->m_fb)[y * m_width + x + offset])); + draw_pixel(x, y, ((unsigned int*)s0->m_fb)[y * m_width + x + offset]); } //Right surface for (int x = x1 - offset; x <= x1; x++) { - draw_pixel(x, y, GL_RGB_16_to_32(((unsigned short*)s1->m_fb)[y * m_width + x + offset - x1 + x0])); + draw_pixel(x, y, ((unsigned int*)s1->m_fb)[y * m_width + x + offset - x1 + x0]); } } } @@ -3407,22 +3371,12 @@ private: #ifdef GUILITE_ON c_bitmap_operator the_bitmap_op = c_bitmap_operator(); c_image_operator* c_image::image_operator = &the_bitmap_op; +const void* c_theme::s_font_map[FONT_MAX]; +const void* c_theme::s_image_map[IMAGE_MAX]; +unsigned int c_theme::s_color_map[COLOR_MAX]; +c_lattice_font_op the_lattice_font_op = c_lattice_font_op(); +c_font_operator* c_word::fontOperator = &the_lattice_font_op; #endif - -#ifdef GUILITE_ON - -const void* c_theme::s_font_map[FONT_MAX]; -const void* c_theme::s_image_map[IMAGE_MAX]; -unsigned int c_theme::s_color_map[COLOR_MAX]; - -#endif - -#ifdef GUILITE_ON - -c_lattice_font_op the_lattice_font_op = c_lattice_font_op(); -c_font_operator* c_word::fontOperator = &the_lattice_font_op; - -#endif #ifdef GUILITE_ON #if (defined __linux__) || (defined __APPLE__) #include @@ -4264,11 +4218,7 @@ int c_fifo::write(void* buf, int len) #endif #ifdef GUILITE_ON DIALOG_ARRAY c_dialog::ms_the_dialogs[SURFACE_CNT_MAX]; -#endif -#ifdef GUILITE_ON c_keyboard c_edit::s_keyboard; -#endif -#ifdef GUILITE_ON static c_keyboard_button s_key_0, s_key_1, s_key_2, s_key_3, s_key_4, s_key_5, s_key_6, s_key_7, s_key_8, s_key_9; static c_keyboard_button s_key_A, s_key_B, s_key_C, s_key_D, s_key_E, s_key_F, s_key_G, s_key_H, s_key_I, s_key_J; static c_keyboard_button s_key_K, s_key_L, s_key_M, s_key_N, s_key_O, s_key_P, s_key_Q, s_key_R, s_key_S, s_key_T; @@ -4306,12 +4256,12 @@ WND_TREE g_key_board_children[] = {&s_key_B, 'B', 0, ((KEY_WIDTH / 2) + POS_X(5)), POS_Y(2), KEY_WIDTH, KEY_HEIGHT}, {&s_key_N, 'N', 0, ((KEY_WIDTH / 2) + POS_X(6)), POS_Y(2), KEY_WIDTH, KEY_HEIGHT}, {&s_key_M, 'M', 0, ((KEY_WIDTH / 2) + POS_X(7)), POS_Y(2), KEY_WIDTH, KEY_HEIGHT}, - {&s_key_del, 0x7F, 0, ((KEY_WIDTH / 2) + POS_X(8)), POS_Y(2), DEL_WIDTH, KEY_HEIGHT}, + {&s_key_del,0x7F, 0, ((KEY_WIDTH / 2) + POS_X(8)), POS_Y(2), DEL_WIDTH, KEY_HEIGHT}, //Row 4 - {&s_key_esc, 0x1B, 0, POS_X(0), POS_Y(3), ESC_WIDTH, KEY_HEIGHT}, + {&s_key_esc, 0x1B, 0, POS_X(0), POS_Y(3), ESC_WIDTH, KEY_HEIGHT}, {&s_key_num_switch, 0x90, 0, POS_X(2), POS_Y(3), SWITCH_WIDTH, KEY_HEIGHT}, {&s_key_space, ' ', 0, ((KEY_WIDTH / 2) + POS_X(3)), POS_Y(3), SPACE_WIDTH, KEY_HEIGHT}, - {&s_key_dot, '.', 0, ((KEY_WIDTH / 2) + POS_X(6)), POS_Y(3), DOT_WIDTH, KEY_HEIGHT}, + {&s_key_dot, '.', 0, ((KEY_WIDTH / 2) + POS_X(6)), POS_Y(3), DOT_WIDTH, KEY_HEIGHT}, {&s_key_enter, '\n', 0, POS_X(8), POS_Y(3), ENTER_WIDTH, KEY_HEIGHT}, {0,0,0,0,0,0,0} }; @@ -4326,12 +4276,11 @@ WND_TREE g_number_board_children[] = {&s_key_7, '7', 0, POS_X(0), POS_Y(2), KEY_WIDTH, KEY_HEIGHT}, {&s_key_8, '8', 0, POS_X(1), POS_Y(2), KEY_WIDTH, KEY_HEIGHT}, {&s_key_9, '9', 0, POS_X(2), POS_Y(2), KEY_WIDTH, KEY_HEIGHT}, - - {&s_key_esc, 0x1B, 0, POS_X(0), POS_Y(3), KEY_WIDTH, KEY_HEIGHT}, + {&s_key_esc,0x1B, 0, POS_X(0), POS_Y(3), KEY_WIDTH, KEY_HEIGHT}, {&s_key_0, '0', 0, POS_X(1), POS_Y(3), KEY_WIDTH, KEY_HEIGHT}, - {&s_key_dot, '.', 0, POS_X(2), POS_Y(3), KEY_WIDTH, KEY_HEIGHT}, + {&s_key_dot,'.', 0, POS_X(2), POS_Y(3), KEY_WIDTH, KEY_HEIGHT}, {&s_key_del, 0x7F, 0, POS_X(3), POS_Y(0), KEY_WIDTH, KEY_HEIGHT * 2 + 2}, {&s_key_enter,'\n', 0, POS_X(3), POS_Y(2), KEY_WIDTH, KEY_HEIGHT * 2 + 2}, {0,0,0,0,0,0,0} }; -#endif +#endif \ No newline at end of file diff --git a/HelloPendulum/UIcode/UIcode.cpp b/HelloPendulum/UIcode/UIcode.cpp index 57ab04ed942fa4a07d51d1b9df9578a5bbfbb752..3081019875e6f20114d0f4f5626cdd10062ebe70 100644 --- a/HelloPendulum/UIcode/UIcode.cpp +++ b/HelloPendulum/UIcode/UIcode.cpp @@ -92,21 +92,12 @@ void load_resource() } //////////////////////// start UI //////////////////////// -void create_ui(void* phy_fb, int screen_width, int screen_height, int color_bytes, struct EXTERNAL_GFX_OP* gfx_op) { - if (phy_fb) - { - static c_surface surface(UI_WIDTH, UI_HEIGHT, color_bytes, Z_ORDER_LEVEL_0); - static c_display display(phy_fb, screen_width, screen_height, &surface); - s_surface = &surface; - s_display = &display; - } - else - {//for MCU without framebuffer - static c_surface_no_fb surface_no_fb(UI_WIDTH, UI_HEIGHT, color_bytes, gfx_op, Z_ORDER_LEVEL_0); - static c_display display(phy_fb, screen_width, screen_height, &surface_no_fb); - s_surface = &surface_no_fb; - s_display = &display; - } +void create_ui(void* phy_fb, int screen_width, int screen_height, int color_bytes, struct DISPLAY_DRIVER* driver) { + static c_surface surface(UI_WIDTH, UI_HEIGHT, color_bytes, Z_ORDER_LEVEL_0); + static c_display display(phy_fb, screen_width, screen_height, &surface, driver); + s_surface = &surface; + s_display = &display; + load_resource(); s_surface->fill_rect(c_rect(0, 0, UI_WIDTH, UI_HEIGHT), 0, Z_ORDER_LEVEL_0); @@ -118,8 +109,8 @@ void create_ui(void* phy_fb, int screen_width, int screen_height, int color_byte } //////////////////////// interface for all platform //////////////////////// -extern "C" void startHelloPendulum(void* phy_fb, int width, int height, int color_bytes, struct EXTERNAL_GFX_OP* gfx_op) { - create_ui(phy_fb, width, height, color_bytes, gfx_op); +extern "C" void startHelloPendulum(void* phy_fb, int width, int height, int color_bytes, struct DISPLAY_DRIVER* driver) { + create_ui(phy_fb, width, height, color_bytes, driver); } extern "C" void sendKey2HelloPendulum(unsigned int key) diff --git a/HelloScroll/BuildLinux/.sync_build.sh b/HelloScroll/BuildLinux/.sync_build.sh index 49cff5b473ac606967676ebefa6f0d333e301227..af3dad03827ed7fda7a768b79045e3f71bcee9c9 100644 --- a/HelloScroll/BuildLinux/.sync_build.sh +++ b/HelloScroll/BuildLinux/.sync_build.sh @@ -1,5 +1,6 @@ if [ "$#" -ne 1 ]; then - echo "Invalid arguments" + echo "Do testing" + ./xWindow 600 400 | ./HelloScroll shared-fb exit -1 fi diff --git a/HelloScroll/UIcode/GuiLite.h b/HelloScroll/UIcode/GuiLite.h index c4fc88a51476d2c8309c3e55e1270e13784fc510..80550e1632ad7bc82541a2edbb0f7f8f5937954f 100644 --- a/HelloScroll/UIcode/GuiLite.h +++ b/HelloScroll/UIcode/GuiLite.h @@ -1,107 +1,94 @@ #pragma once - -#define REAL_TIME_TASK_CYCLE_MS 50 -#define MAX(a,b) (((a)>(b))?(a):(b)) -#define MIN(a,b) (((a)<(b))?(a):(b)) - -#define GL_ARGB(a, r, g, b) ((((unsigned int)(a)) << 24) | (((unsigned int)(r)) << 16) | (((unsigned int)(g)) << 8) | ((unsigned int)(b))) -#define GL_ARGB_A(rgb) ((((unsigned int)(rgb)) >> 24) & 0xFF) - -#define GL_RGB(r, g, b) ((0xFF << 24) | (((unsigned int)(r)) << 16) | (((unsigned int)(g)) << 8) | ((unsigned int)(b))) -#define GL_RGB_R(rgb) ((((unsigned int)(rgb)) >> 16) & 0xFF) -#define GL_RGB_G(rgb) ((((unsigned int)(rgb)) >> 8) & 0xFF) -#define GL_RGB_B(rgb) (((unsigned int)(rgb)) & 0xFF) -#define GL_RGB_32_to_16(rgb) (((((unsigned int)(rgb)) & 0xFF) >> 3) | ((((unsigned int)(rgb)) & 0xFC00) >> 5) | ((((unsigned int)(rgb)) & 0xF80000) >> 8)) -#define GL_RGB_16_to_32(rgb) ((0xFF << 24) | ((((unsigned int)(rgb)) & 0x1F) << 3) | ((((unsigned int)(rgb)) & 0x7E0) << 5) | ((((unsigned int)(rgb)) & 0xF800) << 8)) - -#define ALIGN_HCENTER 0x00000000L -#define ALIGN_LEFT 0x01000000L -#define ALIGN_RIGHT 0x02000000L -#define ALIGN_HMASK 0x03000000L - -#define ALIGN_VCENTER 0x00000000L -#define ALIGN_TOP 0x00100000L -#define ALIGN_BOTTOM 0x00200000L -#define ALIGN_VMASK 0x00300000L - -typedef struct -{ - unsigned short year; - unsigned short month; - unsigned short date; - unsigned short day; - unsigned short hour; - unsigned short minute; - unsigned short second; -}T_TIME; - -void register_debug_function(void(*my_assert)(const char* file, int line), void(*my_log_out)(const char* log)); -void _assert(const char* file, int line); -#define ASSERT(condition) \ - do{ \ - if(!(condition))_assert(__FILE__, __LINE__);\ - }while(0) -void log_out(const char* log); - -long get_time_in_second(); -T_TIME second_to_day(long second); -T_TIME get_time(); - -void start_real_timer(void (*func)(void* arg)); -void register_timer(int milli_second, void func(void* param), void* param); - -unsigned int get_cur_thread_id(); -void create_thread(unsigned long* thread_id, void* attr, void *(*start_routine) (void *), void* arg); -void thread_sleep(unsigned int milli_seconds); -int build_bmp(const char *filename, unsigned int width, unsigned int height, unsigned char *data); - -#define FIFO_BUFFER_LEN 1024 -class c_fifo -{ -public: - c_fifo(); - int read(void* buf, int len); - int write(void* buf, int len); -private: - unsigned char m_buf[FIFO_BUFFER_LEN]; - int m_head; - int m_tail; - void* m_read_sem; - void* m_write_mutex; -}; - -class c_rect -{ -public: - c_rect(){ m_left = m_top = m_right = m_bottom = -1; } - c_rect(int left, int top, int width, int height) - { - set_rect(left, top, width, height); - } - void set_rect(int left, int top, int width, int height) - { - ASSERT(width > 0 && height > 0); - m_left = left; - m_top = top; - m_right = left + width - 1; - m_bottom = top + height -1; - } - bool pt_in_rect(int x, int y) const - { - return x >= m_left && x <= m_right && y >= m_top && y <= m_bottom; - } - int operator==(const c_rect& rect) const - { - return (m_left == rect.m_left) && (m_top == rect.m_top) && (m_right == rect.m_right) && (m_bottom == rect.m_bottom); - } - int width() const { return m_right - m_left + 1; } - int height() const { return m_bottom - m_top + 1 ; } - - int m_left; - int m_top; - int m_right; - int m_bottom; -}; +#define REAL_TIME_TASK_CYCLE_MS 50 +#define MAX(a,b) (((a)>(b))?(a):(b)) +#define MIN(a,b) (((a)<(b))?(a):(b)) +#define GL_ARGB(a, r, g, b) ((((unsigned int)(a)) << 24) | (((unsigned int)(r)) << 16) | (((unsigned int)(g)) << 8) | ((unsigned int)(b))) +#define GL_ARGB_A(rgb) ((((unsigned int)(rgb)) >> 24) & 0xFF) +#define GL_RGB(r, g, b) ((0xFF << 24) | (((unsigned int)(r)) << 16) | (((unsigned int)(g)) << 8) | ((unsigned int)(b))) +#define GL_RGB_R(rgb) ((((unsigned int)(rgb)) >> 16) & 0xFF) +#define GL_RGB_G(rgb) ((((unsigned int)(rgb)) >> 8) & 0xFF) +#define GL_RGB_B(rgb) (((unsigned int)(rgb)) & 0xFF) +#define GL_RGB_32_to_16(rgb) (((((unsigned int)(rgb)) & 0xFF) >> 3) | ((((unsigned int)(rgb)) & 0xFC00) >> 5) | ((((unsigned int)(rgb)) & 0xF80000) >> 8)) +#define GL_RGB_16_to_32(rgb) ((0xFF << 24) | ((((unsigned int)(rgb)) & 0x1F) << 3) | ((((unsigned int)(rgb)) & 0x7E0) << 5) | ((((unsigned int)(rgb)) & 0xF800) << 8)) +#define ALIGN_HCENTER 0x00000000L +#define ALIGN_LEFT 0x01000000L +#define ALIGN_RIGHT 0x02000000L +#define ALIGN_HMASK 0x03000000L +#define ALIGN_VCENTER 0x00000000L +#define ALIGN_TOP 0x00100000L +#define ALIGN_BOTTOM 0x00200000L +#define ALIGN_VMASK 0x00300000L +typedef struct +{ + unsigned short year; + unsigned short month; + unsigned short date; + unsigned short day; + unsigned short hour; + unsigned short minute; + unsigned short second; +}T_TIME; +void register_debug_function(void(*my_assert)(const char* file, int line), void(*my_log_out)(const char* log)); +void _assert(const char* file, int line); +#define ASSERT(condition) \ + do{ \ + if(!(condition))_assert(__FILE__, __LINE__);\ + }while(0) +void log_out(const char* log); +long get_time_in_second(); +T_TIME second_to_day(long second); +T_TIME get_time(); +void start_real_timer(void (*func)(void* arg)); +void register_timer(int milli_second, void func(void* param), void* param); +unsigned int get_cur_thread_id(); +void create_thread(unsigned long* thread_id, void* attr, void *(*start_routine) (void *), void* arg); +void thread_sleep(unsigned int milli_seconds); +int build_bmp(const char *filename, unsigned int width, unsigned int height, unsigned char *data); +#define FIFO_BUFFER_LEN 1024 +class c_fifo +{ +public: + c_fifo(); + int read(void* buf, int len); + int write(void* buf, int len); +private: + unsigned char m_buf[FIFO_BUFFER_LEN]; + int m_head; + int m_tail; + void* m_read_sem; + void* m_write_mutex; +}; +class c_rect +{ +public: + c_rect(){ m_left = m_top = m_right = m_bottom = -1; } + c_rect(int left, int top, int width, int height) + { + set_rect(left, top, width, height); + } + void set_rect(int left, int top, int width, int height) + { + ASSERT(width > 0 && height > 0); + m_left = left; + m_top = top; + m_right = left + width - 1; + m_bottom = top + height -1; + } + bool pt_in_rect(int x, int y) const + { + return x >= m_left && x <= m_right && y >= m_top && y <= m_bottom; + } + int operator==(const c_rect& rect) const + { + return (m_left == rect.m_left) && (m_top == rect.m_top) && (m_right == rect.m_right) && (m_bottom == rect.m_bottom); + } + int width() const { return m_right - m_left + 1; } + int height() const { return m_bottom - m_top + 1 ; } + int m_left; + int m_top; + int m_right; + int m_bottom; +}; //BITMAP typedef struct struct_bitmap_info { @@ -238,7 +225,7 @@ typedef enum Z_ORDER_LEVEL_2,//highest graphic level Z_ORDER_LEVEL_MAX }Z_ORDER_LEVEL; -struct EXTERNAL_GFX_OP +struct DISPLAY_DRIVER { void(*draw_pixel)(int x, int y, unsigned int rgb); void(*fill_rect)(int x0, int y0, int x1, int y1, unsigned int rgb); @@ -247,18 +234,19 @@ class c_surface; class c_display { friend class c_surface; public: - inline c_display(void* phy_fb, int display_width, int display_height, int surface_width, int surface_height, unsigned int color_bytes, int surface_cnt, EXTERNAL_GFX_OP* gfx_op = 0);//multiple surface or surface_no_fb - inline c_display(void* phy_fb, int display_width, int display_height, c_surface* surface);//single custom surface - inline c_surface* alloc_surface(Z_ORDER_LEVEL max_zorder, c_rect layer_rect = c_rect());//for multiple surfaces + inline c_display(void* phy_fb, int display_width, int display_height, c_surface* surface, DISPLAY_DRIVER* driver = 0);//single custom surface + inline c_display(void* phy_fb, int display_width, int display_height, int surface_width, int surface_height, unsigned int color_bytes, int surface_cnt, DISPLAY_DRIVER* driver = 0);//multiple surface + inline c_surface* alloc_surface(Z_ORDER_LEVEL max_zorder, c_rect layer_rect = c_rect());//for slide group inline int swipe_surface(c_surface* s0, c_surface* s1, int x0, int x1, int y0, int y1, int offset); int get_width() { return m_width; } int get_height() { return m_height; } + void* get_phy_fb() { return m_phy_fb; } void* get_updated_fb(int* width, int* height, bool force_update = false) { if (width && height) { - *width = get_width(); - *height = get_height(); + *width = m_width; + *height = m_height; } if (force_update) { @@ -277,35 +265,123 @@ public: { return -1; } - int width = get_width(); - int height = get_height(); //16 bits framebuffer if (m_color_bytes == 2) { - return build_bmp(file_name, width, height, (unsigned char*)m_phy_fb); + return build_bmp(file_name, m_width, m_height, (unsigned char*)m_phy_fb); } //32 bits framebuffer - unsigned short* p_bmp565_data = new unsigned short[width * height]; + unsigned short* p_bmp565_data = new unsigned short[m_width * m_height]; unsigned int* p_raw_data = (unsigned int*)m_phy_fb; - for (int i = 0; i < width * height; i++) + for (int i = 0; i < m_width * m_height; i++) { unsigned int rgb = *p_raw_data++; p_bmp565_data[i] = GL_RGB_32_to_16(rgb); } - int ret = build_bmp(file_name, width, height, (unsigned char*)p_bmp565_data); + int ret = build_bmp(file_name, m_width, m_height, (unsigned char*)p_bmp565_data); delete[]p_bmp565_data; return ret; } -private: - int m_width; //in pixels - int m_height; //in pixels - int m_color_bytes; //16 bits, 32 bits only - void* m_phy_fb; //physical framebuffer +protected: + virtual void draw_pixel(int x, int y, unsigned int rgb) + { + if ((x >= m_width) || (y >= m_height)) { return; } + if (m_driver && m_driver->draw_pixel) + { + return m_driver->draw_pixel(x, y, rgb); + } + if (m_color_bytes == 2) + { + ((unsigned short*)m_phy_fb)[y * m_width + x] = GL_RGB_32_to_16(rgb); + } + else + { + ((unsigned int*)m_phy_fb)[y * m_width + x] = rgb; + } + } + virtual void fill_rect(int x0, int y0, int x1, int y1, unsigned int rgb) + { + if (m_driver && m_driver->fill_rect) + { + return m_driver->fill_rect(x0, y0, x1, y1, rgb); + } + if (m_driver && m_driver->draw_pixel) + { + for (int y = y0; y <= y1; y++) + { + for (int x = x0; x <= x1; x++) + { + m_driver->draw_pixel(x, y, rgb); + } + } + return; + } + register int _width = m_width; + register int _height = m_height; + int x, y; + if (m_color_bytes == 2) + { + unsigned short* phy_fb; + unsigned int rgb_16 = GL_RGB_32_to_16(rgb); + for (y = y0; y <= y1; y++) + { + phy_fb = &((unsigned short*)m_phy_fb)[y * _width + x0]; + for (x = x0; x <= x1; x++) + { + if ((x < _width) && (y < _height)) + { + *phy_fb++ = rgb_16; + } + } + } + } + else + { + unsigned int* phy_fb; + for (y = y0; y <= y1; y++) + { + phy_fb = &((unsigned int*)m_phy_fb)[y * _width + x0]; + for (x = x0; x <= x1; x++) + { + if ((x < _width) && (y < _height)) + { + *phy_fb++ = rgb; + } + } + } + } + } + virtual int flush_screen(int left, int top, int right, int bottom, void* fb, int fb_width) + { + if ((0 == m_phy_fb) || (0 == fb)) + { + return -1; + } + register int _width = m_width; + register int _height = m_height; + left = (left >= _width) ? (_width - 1) : left; + right = (right >= _width) ? (_width - 1) : right; + top = (top >= _height) ? (_height - 1) : top; + bottom = (bottom >= _height) ? (_height - 1) : bottom; + for (int y = top; y < bottom; y++) + { + void* s_addr = (char*)fb + ((y * fb_width + left) * m_color_bytes); + void* d_addr = (char*)m_phy_fb + ((y * _width + left) * m_color_bytes); + memcpy(d_addr, s_addr, (right - left) * m_color_bytes); + } + return 0; + } + int m_width; //in pixels + int m_height; //in pixels + int m_color_bytes; //16/32 bits for default + void* m_phy_fb; //physical framebuffer for default + struct DISPLAY_DRIVER* m_driver; //Rendering by external method without default physical framebuffer int m_phy_read_index; int m_phy_write_index; c_surface* m_surface_group[SURFACE_CNT_MAX]; int m_surface_cnt; //surface count int m_surface_index; + }; class c_layer { @@ -317,12 +393,10 @@ public: class c_surface { friend class c_display; friend class c_bitmap_operator; public: - c_surface(unsigned int width, unsigned int height, unsigned int color_bytes, Z_ORDER_LEVEL max_zorder = Z_ORDER_LEVEL_0, c_rect overlpa_rect = c_rect()) : m_width(width), m_height(height), m_color_bytes(color_bytes), m_fb(0), m_is_active(false), m_top_zorder(Z_ORDER_LEVEL_0), m_phy_fb(0), m_phy_write_index(0), m_display(0) + c_surface(unsigned int width, unsigned int height, unsigned int color_bytes, Z_ORDER_LEVEL max_zorder = Z_ORDER_LEVEL_0, c_rect overlpa_rect = c_rect()) : m_width(width), m_height(height), m_color_bytes(color_bytes), m_fb(0), m_is_active(false), m_top_zorder(Z_ORDER_LEVEL_0), m_phy_write_index(0), m_display(0) { (overlpa_rect == c_rect()) ? set_surface(max_zorder, c_rect(0, 0, width - 1, height - 1)) : set_surface(max_zorder, overlpa_rect); } - int get_width() { return m_width; } - int get_height() { return m_height; } unsigned int get_pixel(int x, int y, unsigned int z_order) { if (x >= m_width || y >= m_height || x < 0 || y < 0 || z_order >= Z_ORDER_LEVEL_MAX) @@ -332,15 +406,15 @@ public: } if (m_layers[z_order].fb) { - return (m_color_bytes == 4) ? ((unsigned int*)(m_layers[z_order].fb))[y * m_width + x] : GL_RGB_16_to_32(((unsigned short*)(m_layers[z_order].fb))[y * m_width + x]); + return (m_color_bytes == 2) ? GL_RGB_16_to_32(((unsigned short*)(m_layers[z_order].fb))[y * m_width + x]) : ((unsigned int*)(m_layers[z_order].fb))[y * m_width + x]; } else if (m_fb) { - return (m_color_bytes == 4) ? ((unsigned int*)m_fb)[y * m_width + x] : GL_RGB_16_to_32(((unsigned short*)m_fb)[y * m_width + x]); + return (m_color_bytes == 2) ? GL_RGB_16_to_32(((unsigned short*)m_fb)[y * m_width + x]) : ((unsigned int*)m_fb)[y * m_width + x]; } - else if (m_phy_fb) + else if (m_display->m_phy_fb) { - return (m_color_bytes == 4) ? ((unsigned int*)m_phy_fb)[y * m_width + x] : GL_RGB_16_to_32(((unsigned short*)m_phy_fb)[y * m_width + x]); + return (m_color_bytes == 2) ? GL_RGB_16_to_32(((unsigned short*)m_display->m_phy_fb)[y * m_width + x]) : ((unsigned int*)m_display->m_phy_fb)[y * m_width + x]; } return 0; } @@ -357,7 +431,7 @@ public: } if (z_order == m_max_zorder) { - return draw_pixel_on_fb(x, y, rgb); + return draw_pixel_low_level(x, y, rgb); } if (z_order > (unsigned int)m_top_zorder) @@ -367,19 +441,19 @@ public: if (m_layers[z_order].rect.pt_in_rect(x, y)) { c_rect layer_rect = m_layers[z_order].rect; - if (m_color_bytes == 4) + if (m_color_bytes == 2) { - ((unsigned int*)(m_layers[z_order].fb))[(x - layer_rect.m_left) + (y - layer_rect.m_top) * layer_rect.width()] = rgb; + ((unsigned short*)(m_layers[z_order].fb))[(x - layer_rect.m_left) + (y - layer_rect.m_top) * layer_rect.width()] = GL_RGB_32_to_16(rgb); } else { - ((unsigned short*)(m_layers[z_order].fb))[(x - layer_rect.m_left) + (y - layer_rect.m_top) * layer_rect.width()] = GL_RGB_32_to_16(rgb); + ((unsigned int*)(m_layers[z_order].fb))[(x - layer_rect.m_left) + (y - layer_rect.m_top) * layer_rect.width()] = rgb; } } if (z_order == m_top_zorder) { - return draw_pixel_on_fb(x, y, rgb); + return draw_pixel_low_level(x, y, rgb); } bool be_overlapped = false; for (unsigned int tmp_z_order = Z_ORDER_LEVEL_MAX - 1; tmp_z_order > z_order; tmp_z_order--) @@ -392,7 +466,7 @@ public: } if (!be_overlapped) { - draw_pixel_on_fb(x, y, rgb); + draw_pixel_low_level(x, y, rgb); } } virtual void fill_rect(int x0, int y0, int x1, int y1, unsigned int rgb, unsigned int z_order) @@ -403,7 +477,7 @@ public: y1 = (y1 > (m_height - 1)) ? (m_height - 1) : y1; if (z_order == m_max_zorder) { - return fill_rect_on_fb(x0, y0, x1, y1, rgb); + return fill_rect_low_level(x0, y0, x1, y1, rgb); } if (z_order == m_top_zorder) { @@ -416,18 +490,18 @@ public: { if (layer_rect.pt_in_rect(x, y)) { - if (m_color_bytes == 4) + if (m_color_bytes == 2) { - ((unsigned int*)m_layers[z_order].fb)[(y - layer_rect.m_top) * layer_rect.width() + (x - layer_rect.m_left)] = rgb; + ((unsigned short*)m_layers[z_order].fb)[(y - layer_rect.m_top) * layer_rect.width() + (x - layer_rect.m_left)] = rgb_16; } else { - ((unsigned short*)m_layers[z_order].fb)[(y - layer_rect.m_top) * layer_rect.width() + (x - layer_rect.m_left)] = rgb_16; + ((unsigned int*)m_layers[z_order].fb)[(y - layer_rect.m_top) * layer_rect.width() + (x - layer_rect.m_left)] = rgb; } } } } - return fill_rect_on_fb(x0, y0, x1, y1, rgb); + return fill_rect_low_level(x0, y0, x1, y1, rgb); } for (; y0 <= y1; y0++) { @@ -499,27 +573,16 @@ public: } int flush_screen(int left, int top, int right, int bottom) { - if (left < 0 || left >= m_width || right < 0 || right >= m_width || - top < 0 || top >= m_height || bottom < 0 || bottom >= m_height) - { - ASSERT(false); - } - if (!m_is_active || (0 == m_phy_fb) || (0 == m_fb)) + if (!m_is_active) { return -1; } - int display_width = m_display->get_width(); - int display_height = m_display->get_height(); - left = (left >= display_width) ? (display_width - 1) : left; - right = (right >= display_width) ? (display_width - 1) : right; - top = (top >= display_height) ? (display_height - 1) : top; - bottom = (bottom >= display_height) ? (display_height - 1) : bottom; - for (int y = top; y < bottom; y++) + if (left < 0 || left >= m_width || right < 0 || right >= m_width || + top < 0 || top >= m_height || bottom < 0 || bottom >= m_height) { - void* s_addr = (char*)m_fb + ((y * m_width + left) * m_color_bytes); - void* d_addr = (char*)m_phy_fb + ((y * display_width + left) * m_color_bytes); - memcpy(d_addr, s_addr, (right - left) * m_color_bytes); + ASSERT(false); } + m_display->flush_screen(left, top, right, bottom, m_fb, m_width); *m_phy_write_index = *m_phy_write_index + 1; return 0; } @@ -537,90 +600,62 @@ public: { for (int x = rect.m_left; x <= rect.m_right; x++) { - unsigned int rgb = (m_color_bytes == 4) ? ((unsigned int*)fb)[(x - layer_rect.m_left) + (y - layer_rect.m_top) * width] : GL_RGB_16_to_32(((unsigned short*)fb)[(x - layer_rect.m_left) + (y - layer_rect.m_top) * width]); - draw_pixel_on_fb(x, y, rgb); + unsigned int rgb = (m_color_bytes == 2) ? GL_RGB_16_to_32(((unsigned short*)fb)[(x - layer_rect.m_left) + (y - layer_rect.m_top) * width]) : ((unsigned int*)fb)[(x - layer_rect.m_left) + (y - layer_rect.m_top) * width]; + draw_pixel_low_level(x, y, rgb); } } return 0; } void set_active(bool flag) { m_is_active = flag; } protected: - virtual void fill_rect_on_fb(int x0, int y0, int x1, int y1, unsigned int rgb) - { - int display_width = m_display->get_width(); - int display_height = m_display->get_height(); - if (m_color_bytes == 4) + virtual void fill_rect_low_level(int x0, int y0, int x1, int y1, unsigned int rgb) + {//fill rect on framebuffer of surface + int x, y; + if (m_color_bytes == 2) { - int x; - unsigned int* fb, * phy_fb; - for (; y0 <= y1; y0++) + unsigned short* fb; + unsigned int rgb_16 = GL_RGB_32_to_16(rgb); + for (y = y0; y <= y1; y++) { - x = x0; - fb = m_fb ? &((unsigned int*)m_fb)[y0 * m_width + x] : 0; - phy_fb = &((unsigned int*)m_phy_fb)[y0 * display_width + x]; - *m_phy_write_index = *m_phy_write_index + 1; - for (; x <= x1; x++) + fb = m_fb ? &((unsigned short*)m_fb)[y * m_width + x0] : 0; + if (!fb) { break; } + for (x = x0; x <= x1; x++) { - if (fb) - { - *fb++ = rgb; - } - if (m_is_active && (x < display_width) && (y0 < display_height)) - { - *phy_fb++ = rgb; - } + *fb++ = rgb_16; } } } - else if (m_color_bytes == 2) + else { - int x; - unsigned short* fb, * phy_fb; - rgb = GL_RGB_32_to_16(rgb); - for (; y0 <= y1; y0++) + unsigned int* fb; + for (y = y0; y <= y1; y++) { - x = x0; - fb = m_fb ? &((unsigned short*)m_fb)[y0 * m_width + x] : 0; - phy_fb = &((unsigned short*)m_phy_fb)[y0 * display_width + x]; - *m_phy_write_index = *m_phy_write_index + 1; - for (; x <= x1; x++) + fb = m_fb ? &((unsigned int*)m_fb)[y * m_width + x0] : 0; + if (!fb) { break; } + for (x = x0; x <= x1; x++) { - if (fb) - { - *fb++ = rgb; - } - if (m_is_active && (x < display_width) && (y0 < display_height)) - { - *phy_fb++ = rgb; - } + *fb++ = rgb; } } } + if (!m_is_active) { return; } + m_display->fill_rect(x0, y0, x1, y1, rgb); + *m_phy_write_index = *m_phy_write_index + 1; } - virtual void draw_pixel_on_fb(int x, int y, unsigned int rgb) + virtual void draw_pixel_low_level(int x, int y, unsigned int rgb) { if (m_fb) - { - (m_color_bytes == 4) ? ((unsigned int*)m_fb)[y * m_width + x] = rgb : ((unsigned short*)m_fb)[y * m_width + x] = GL_RGB_32_to_16(rgb); - } - if (m_is_active && (x < m_display->get_width()) && (y < m_display->get_height())) - { - if (m_color_bytes == 4) - { - ((unsigned int*)m_phy_fb)[y * (m_display->get_width()) + x] = rgb; - } - else - { - ((unsigned short*)m_phy_fb)[y * (m_display->get_width()) + x] = GL_RGB_32_to_16(rgb); - } - *m_phy_write_index = *m_phy_write_index + 1; + {//draw pixel on framebuffer of surface + (m_color_bytes == 2) ? ((unsigned short*)m_fb)[y * m_width + x] = GL_RGB_32_to_16(rgb): ((unsigned int*)m_fb)[y * m_width + x] = rgb; } + if (!m_is_active) { return; } + m_display->draw_pixel(x, y, rgb); + *m_phy_write_index = *m_phy_write_index + 1; } void attach_display(c_display* display) { ASSERT(display); m_display = display; - m_phy_fb = display->m_phy_fb; m_phy_write_index = &display->m_phy_write_index; } void set_surface(Z_ORDER_LEVEL max_z_order, c_rect layer_rect) @@ -638,87 +673,22 @@ protected: } int m_width; //in pixels int m_height; //in pixels - int m_color_bytes; //16 bits, 32 bits only + int m_color_bytes; //16 bits, 32 bits for default void* m_fb; //frame buffer you could see c_layer m_layers[Z_ORDER_LEVEL_MAX];//all graphic layers bool m_is_active; //active flag Z_ORDER_LEVEL m_max_zorder; //the highest graphic layer the surface will have Z_ORDER_LEVEL m_top_zorder; //the current highest graphic layer the surface have - void* m_phy_fb; //physical framebufer int* m_phy_write_index; c_display* m_display; }; -class c_surface_no_fb : public c_surface {//No physical framebuffer, render with external graphic interface - friend class c_display; -public: - c_surface_no_fb(unsigned int width, unsigned int height, unsigned int color_bytes, struct EXTERNAL_GFX_OP* gfx_op, Z_ORDER_LEVEL max_zorder = Z_ORDER_LEVEL_0, c_rect overlpa_rect = c_rect()) : c_surface(width, height, color_bytes, max_zorder, overlpa_rect), m_gfx_op(gfx_op) {} -protected: - virtual void fill_rect_on_fb(int x0, int y0, int x1, int y1, unsigned int rgb) - { - if (!m_gfx_op) - { - return; - } - if (m_gfx_op->fill_rect) - { - return m_gfx_op->fill_rect(x0, y0, x1, y1, rgb); - } - if (m_gfx_op->draw_pixel && m_is_active) - { - for (int y = y0; y <= y1; y++) - { - for (int x = x0; x <= x1; x++) - { - m_gfx_op->draw_pixel(x, y, rgb); - } - } - } - if (!m_fb) { return; } - if (m_color_bytes == 4) - { - unsigned int* fb; - for (int y = y0; y <= y1; y++) - { - fb = &((unsigned int*)m_fb)[y0 * m_width + x0]; - for (int x = x0; x <= x1; x++) - { - *fb++ = rgb; - } - } - } - else if (m_color_bytes == 2) - { - unsigned short* fb; - rgb = GL_RGB_32_to_16(rgb); - for (int y = y0; y <= y1; y++) - { - fb = &((unsigned short*)m_fb)[y0 * m_width + x0]; - for (int x = x0; x <= x1; x++) - { - *fb++ = rgb; - } - } - } - } - virtual void draw_pixel_on_fb(int x, int y, unsigned int rgb) - { - if (m_gfx_op && m_gfx_op->draw_pixel && m_is_active) - { - m_gfx_op->draw_pixel(x, y, rgb); - } - if (!m_fb) { return; } - if (m_color_bytes == 4) - { - ((unsigned int*)m_fb)[y * m_width + x] = rgb; - } - else if (m_color_bytes == 2) - { - ((unsigned short*)m_fb)[y * m_width + x] = GL_RGB_32_to_16(rgb); - } - } - struct EXTERNAL_GFX_OP* m_gfx_op;//Rendering by external method -}; -inline c_display::c_display(void* phy_fb, int display_width, int display_height, int surface_width, int surface_height, unsigned int color_bytes, int surface_cnt, EXTERNAL_GFX_OP* gfx_op) : m_width(display_width), m_height(display_height), m_color_bytes(color_bytes), m_phy_fb(phy_fb), m_phy_read_index(0), m_phy_write_index(0), m_surface_cnt(surface_cnt), m_surface_index(0) +inline c_display::c_display(void* phy_fb, int display_width, int display_height, c_surface* surface, DISPLAY_DRIVER* driver) : m_phy_fb(phy_fb), m_width(display_width), m_height(display_height), m_driver(driver), m_phy_read_index(0), m_phy_write_index(0), m_surface_cnt(1), m_surface_index(0) +{ + m_color_bytes = surface->m_color_bytes; + surface->m_is_active = true; + (m_surface_group[0] = surface)->attach_display(this); +} +inline c_display::c_display(void* phy_fb, int display_width, int display_height, int surface_width, int surface_height, unsigned int color_bytes, int surface_cnt, DISPLAY_DRIVER* driver) : m_phy_fb(phy_fb), m_width(display_width), m_height(display_height), m_color_bytes(color_bytes), m_phy_read_index(0), m_phy_write_index(0), m_surface_cnt(surface_cnt), m_driver(driver), m_surface_index(0) { ASSERT(color_bytes == 2 || color_bytes == 4); ASSERT(m_surface_cnt <= SURFACE_CNT_MAX); @@ -726,16 +696,10 @@ inline c_display::c_display(void* phy_fb, int display_width, int display_height, for (int i = 0; i < m_surface_cnt; i++) { - m_surface_group[i] = (phy_fb) ? new c_surface(surface_width, surface_height, color_bytes) : new c_surface_no_fb(surface_width, surface_height, color_bytes, gfx_op); + m_surface_group[i] = new c_surface(surface_width, surface_height, color_bytes); m_surface_group[i]->attach_display(this); } } -inline c_display::c_display(void* phy_fb, int display_width, int display_height, c_surface* surface) : m_width(display_width), m_height(display_height), m_phy_fb(phy_fb), m_phy_read_index(0), m_phy_write_index(0), m_surface_cnt(1), m_surface_index(0) -{ - m_color_bytes = surface->m_color_bytes; - surface->m_is_active = true; - (m_surface_group[0] = surface)->attach_display(this); -} inline c_surface* c_display::alloc_surface(Z_ORDER_LEVEL max_zorder, c_rect layer_rect) { ASSERT(max_zorder < Z_ORDER_LEVEL_MAX && m_surface_index < m_surface_cnt); @@ -744,8 +708,8 @@ inline c_surface* c_display::alloc_surface(Z_ORDER_LEVEL max_zorder, c_rect laye } inline int c_display::swipe_surface(c_surface* s0, c_surface* s1, int x0, int x1, int y0, int y1, int offset) { - int surface_width = s0->get_width(); - int surface_height = s0->get_height(); + register int surface_width = s0->m_width; + register int surface_height = s0->m_height; if (offset < 0 || offset > surface_width || y0 < 0 || y0 >= surface_height || y1 < 0 || y1 >= surface_height || x0 < 0 || x0 >= surface_width || x1 < 0 || x1 >= surface_width) { @@ -767,46 +731,46 @@ inline int c_display::swipe_surface(c_surface* s0, c_surface* s1, int x0, int x1 for (int y = y0; y <= y1; y++) { //Left surface - char* addr_s = ((char*)(s0->m_fb) + (y * (s0->get_width()) + x0 + offset) * m_color_bytes); + char* addr_s = ((char*)(s0->m_fb) + (y * surface_width + x0 + offset) * m_color_bytes); char* addr_d = ((char*)(m_phy_fb)+(y * m_width + x0) * m_color_bytes); memcpy(addr_d, addr_s, (width - offset) * m_color_bytes); //Right surface - addr_s = ((char*)(s1->m_fb) + (y * (s1->get_width()) + x0) * m_color_bytes); + addr_s = ((char*)(s1->m_fb) + (y * surface_width + x0) * m_color_bytes); addr_d = ((char*)(m_phy_fb)+(y * m_width + x0 + (width - offset)) * m_color_bytes); memcpy(addr_d, addr_s, offset * m_color_bytes); } } - else if (m_color_bytes == 4) + else if (m_color_bytes == 2) { - void(*draw_pixel)(int x, int y, unsigned int rgb) = ((c_surface_no_fb*)s0)->m_gfx_op->draw_pixel; + void(*draw_pixel)(int x, int y, unsigned int rgb) = m_driver->draw_pixel; for (int y = y0; y <= y1; y++) { //Left surface for (int x = x0; x <= (x1 - offset); x++) { - draw_pixel(x, y, ((unsigned int*)s0->m_fb)[y * m_width + x + offset]); + draw_pixel(x, y, GL_RGB_16_to_32(((unsigned short*)s0->m_fb)[y * m_width + x + offset])); } //Right surface for (int x = x1 - offset; x <= x1; x++) { - draw_pixel(x, y, ((unsigned int*)s1->m_fb)[y * m_width + x + offset - x1 + x0]); + draw_pixel(x, y, GL_RGB_16_to_32(((unsigned short*)s1->m_fb)[y * m_width + x + offset - x1 + x0])); } } } - else if (m_color_bytes == 2) + else //m_color_bytes == 3/4... { - void(*draw_pixel)(int x, int y, unsigned int rgb) = ((c_surface_no_fb*)s0)->m_gfx_op->draw_pixel; + void(*draw_pixel)(int x, int y, unsigned int rgb) = m_driver->draw_pixel; for (int y = y0; y <= y1; y++) { //Left surface for (int x = x0; x <= (x1 - offset); x++) { - draw_pixel(x, y, GL_RGB_16_to_32(((unsigned short*)s0->m_fb)[y * m_width + x + offset])); + draw_pixel(x, y, ((unsigned int*)s0->m_fb)[y * m_width + x + offset]); } //Right surface for (int x = x1 - offset; x <= x1; x++) { - draw_pixel(x, y, GL_RGB_16_to_32(((unsigned short*)s1->m_fb)[y * m_width + x + offset - x1 + x0])); + draw_pixel(x, y, ((unsigned int*)s1->m_fb)[y * m_width + x + offset - x1 + x0]); } } } @@ -3407,22 +3371,12 @@ private: #ifdef GUILITE_ON c_bitmap_operator the_bitmap_op = c_bitmap_operator(); c_image_operator* c_image::image_operator = &the_bitmap_op; +const void* c_theme::s_font_map[FONT_MAX]; +const void* c_theme::s_image_map[IMAGE_MAX]; +unsigned int c_theme::s_color_map[COLOR_MAX]; +c_lattice_font_op the_lattice_font_op = c_lattice_font_op(); +c_font_operator* c_word::fontOperator = &the_lattice_font_op; #endif - -#ifdef GUILITE_ON - -const void* c_theme::s_font_map[FONT_MAX]; -const void* c_theme::s_image_map[IMAGE_MAX]; -unsigned int c_theme::s_color_map[COLOR_MAX]; - -#endif - -#ifdef GUILITE_ON - -c_lattice_font_op the_lattice_font_op = c_lattice_font_op(); -c_font_operator* c_word::fontOperator = &the_lattice_font_op; - -#endif #ifdef GUILITE_ON #if (defined __linux__) || (defined __APPLE__) #include @@ -4264,11 +4218,7 @@ int c_fifo::write(void* buf, int len) #endif #ifdef GUILITE_ON DIALOG_ARRAY c_dialog::ms_the_dialogs[SURFACE_CNT_MAX]; -#endif -#ifdef GUILITE_ON c_keyboard c_edit::s_keyboard; -#endif -#ifdef GUILITE_ON static c_keyboard_button s_key_0, s_key_1, s_key_2, s_key_3, s_key_4, s_key_5, s_key_6, s_key_7, s_key_8, s_key_9; static c_keyboard_button s_key_A, s_key_B, s_key_C, s_key_D, s_key_E, s_key_F, s_key_G, s_key_H, s_key_I, s_key_J; static c_keyboard_button s_key_K, s_key_L, s_key_M, s_key_N, s_key_O, s_key_P, s_key_Q, s_key_R, s_key_S, s_key_T; @@ -4306,12 +4256,12 @@ WND_TREE g_key_board_children[] = {&s_key_B, 'B', 0, ((KEY_WIDTH / 2) + POS_X(5)), POS_Y(2), KEY_WIDTH, KEY_HEIGHT}, {&s_key_N, 'N', 0, ((KEY_WIDTH / 2) + POS_X(6)), POS_Y(2), KEY_WIDTH, KEY_HEIGHT}, {&s_key_M, 'M', 0, ((KEY_WIDTH / 2) + POS_X(7)), POS_Y(2), KEY_WIDTH, KEY_HEIGHT}, - {&s_key_del, 0x7F, 0, ((KEY_WIDTH / 2) + POS_X(8)), POS_Y(2), DEL_WIDTH, KEY_HEIGHT}, + {&s_key_del,0x7F, 0, ((KEY_WIDTH / 2) + POS_X(8)), POS_Y(2), DEL_WIDTH, KEY_HEIGHT}, //Row 4 - {&s_key_esc, 0x1B, 0, POS_X(0), POS_Y(3), ESC_WIDTH, KEY_HEIGHT}, + {&s_key_esc, 0x1B, 0, POS_X(0), POS_Y(3), ESC_WIDTH, KEY_HEIGHT}, {&s_key_num_switch, 0x90, 0, POS_X(2), POS_Y(3), SWITCH_WIDTH, KEY_HEIGHT}, {&s_key_space, ' ', 0, ((KEY_WIDTH / 2) + POS_X(3)), POS_Y(3), SPACE_WIDTH, KEY_HEIGHT}, - {&s_key_dot, '.', 0, ((KEY_WIDTH / 2) + POS_X(6)), POS_Y(3), DOT_WIDTH, KEY_HEIGHT}, + {&s_key_dot, '.', 0, ((KEY_WIDTH / 2) + POS_X(6)), POS_Y(3), DOT_WIDTH, KEY_HEIGHT}, {&s_key_enter, '\n', 0, POS_X(8), POS_Y(3), ENTER_WIDTH, KEY_HEIGHT}, {0,0,0,0,0,0,0} }; @@ -4326,12 +4276,11 @@ WND_TREE g_number_board_children[] = {&s_key_7, '7', 0, POS_X(0), POS_Y(2), KEY_WIDTH, KEY_HEIGHT}, {&s_key_8, '8', 0, POS_X(1), POS_Y(2), KEY_WIDTH, KEY_HEIGHT}, {&s_key_9, '9', 0, POS_X(2), POS_Y(2), KEY_WIDTH, KEY_HEIGHT}, - - {&s_key_esc, 0x1B, 0, POS_X(0), POS_Y(3), KEY_WIDTH, KEY_HEIGHT}, + {&s_key_esc,0x1B, 0, POS_X(0), POS_Y(3), KEY_WIDTH, KEY_HEIGHT}, {&s_key_0, '0', 0, POS_X(1), POS_Y(3), KEY_WIDTH, KEY_HEIGHT}, - {&s_key_dot, '.', 0, POS_X(2), POS_Y(3), KEY_WIDTH, KEY_HEIGHT}, + {&s_key_dot,'.', 0, POS_X(2), POS_Y(3), KEY_WIDTH, KEY_HEIGHT}, {&s_key_del, 0x7F, 0, POS_X(3), POS_Y(0), KEY_WIDTH, KEY_HEIGHT * 2 + 2}, {&s_key_enter,'\n', 0, POS_X(3), POS_Y(2), KEY_WIDTH, KEY_HEIGHT * 2 + 2}, {0,0,0,0,0,0,0} }; -#endif +#endif \ No newline at end of file diff --git a/HelloScroll/UIcode/scroll.h b/HelloScroll/UIcode/scroll.h index 62736b498983dd5b1e05fe9717a03af7b6f4139d..4b92a7a459f9732846f8e0f33d2bf7b68ab6debc 100644 --- a/HelloScroll/UIcode/scroll.h +++ b/HelloScroll/UIcode/scroll.h @@ -1,6 +1,6 @@ class c_surface_offset : public c_surface { public: - c_surface_offset(unsigned int width, unsigned int height, unsigned int color_bytes, int offset_x, int offset_y) : c_surface(width, height, color_bytes), m_offset_x(offset_x), m_offset_y(offset_y) {} + c_surface_offset(unsigned int width, unsigned int height, unsigned int color_bytes, int offset_x, int offset_y) : c_surface(width, height, color_bytes), m_offset_x(offset_x), m_offset_y(offset_y) {} virtual void draw_pixel(int x, int y, unsigned int rgb, unsigned int z_order) { x -= m_offset_x; @@ -17,6 +17,16 @@ public: } int m_offset_x; int m_offset_y; + + int get_width() { return m_width; } + int get_height() { return m_height; } +}; + +class mem_display : public c_display +{ +public: + mem_display(void* phy_fb, int display_width, int display_height, c_surface* surface, DISPLAY_DRIVER* driver = 0) : c_display(phy_fb, display_width, display_height, surface, driver) {} + int get_width() { return m_width; } }; #define MOVE_THRESHOLD 10 @@ -59,7 +69,7 @@ protected: } m_mem_surface = new c_surface_offset(width, height, 2, rect.m_left, rect.m_top); - m_mem_display = new c_display(calloc(width * height, 2), width, height, m_mem_surface); + m_mem_display = new mem_display(calloc(width * height, 2), width, height, m_mem_surface); //change surface set_surface(m_mem_surface); @@ -164,7 +174,7 @@ protected: } private: TOUCH_ACTION m_touch_action = TOUCH_UP; - c_display* m_mem_display; + mem_display* m_mem_display; c_surface_offset* m_mem_surface; c_surface* m_parent_surface; int m_offset_x = 0; diff --git a/HelloSlide/BuildLinux/.sync_build.sh b/HelloSlide/BuildLinux/.sync_build.sh index 49cff5b473ac606967676ebefa6f0d333e301227..b3e57ae32ce0b57b34de4cf9a0a6417d99f37ebb 100644 --- a/HelloSlide/BuildLinux/.sync_build.sh +++ b/HelloSlide/BuildLinux/.sync_build.sh @@ -1,5 +1,6 @@ if [ "$#" -ne 1 ]; then - echo "Invalid arguments" + echo "Do testing" + ./xWindow 512 768 | ./HelloSlide shared-fb exit -1 fi diff --git a/HelloSlide/UIcode/GuiLite.h b/HelloSlide/UIcode/GuiLite.h index c4fc88a51476d2c8309c3e55e1270e13784fc510..80550e1632ad7bc82541a2edbb0f7f8f5937954f 100644 --- a/HelloSlide/UIcode/GuiLite.h +++ b/HelloSlide/UIcode/GuiLite.h @@ -1,107 +1,94 @@ #pragma once - -#define REAL_TIME_TASK_CYCLE_MS 50 -#define MAX(a,b) (((a)>(b))?(a):(b)) -#define MIN(a,b) (((a)<(b))?(a):(b)) - -#define GL_ARGB(a, r, g, b) ((((unsigned int)(a)) << 24) | (((unsigned int)(r)) << 16) | (((unsigned int)(g)) << 8) | ((unsigned int)(b))) -#define GL_ARGB_A(rgb) ((((unsigned int)(rgb)) >> 24) & 0xFF) - -#define GL_RGB(r, g, b) ((0xFF << 24) | (((unsigned int)(r)) << 16) | (((unsigned int)(g)) << 8) | ((unsigned int)(b))) -#define GL_RGB_R(rgb) ((((unsigned int)(rgb)) >> 16) & 0xFF) -#define GL_RGB_G(rgb) ((((unsigned int)(rgb)) >> 8) & 0xFF) -#define GL_RGB_B(rgb) (((unsigned int)(rgb)) & 0xFF) -#define GL_RGB_32_to_16(rgb) (((((unsigned int)(rgb)) & 0xFF) >> 3) | ((((unsigned int)(rgb)) & 0xFC00) >> 5) | ((((unsigned int)(rgb)) & 0xF80000) >> 8)) -#define GL_RGB_16_to_32(rgb) ((0xFF << 24) | ((((unsigned int)(rgb)) & 0x1F) << 3) | ((((unsigned int)(rgb)) & 0x7E0) << 5) | ((((unsigned int)(rgb)) & 0xF800) << 8)) - -#define ALIGN_HCENTER 0x00000000L -#define ALIGN_LEFT 0x01000000L -#define ALIGN_RIGHT 0x02000000L -#define ALIGN_HMASK 0x03000000L - -#define ALIGN_VCENTER 0x00000000L -#define ALIGN_TOP 0x00100000L -#define ALIGN_BOTTOM 0x00200000L -#define ALIGN_VMASK 0x00300000L - -typedef struct -{ - unsigned short year; - unsigned short month; - unsigned short date; - unsigned short day; - unsigned short hour; - unsigned short minute; - unsigned short second; -}T_TIME; - -void register_debug_function(void(*my_assert)(const char* file, int line), void(*my_log_out)(const char* log)); -void _assert(const char* file, int line); -#define ASSERT(condition) \ - do{ \ - if(!(condition))_assert(__FILE__, __LINE__);\ - }while(0) -void log_out(const char* log); - -long get_time_in_second(); -T_TIME second_to_day(long second); -T_TIME get_time(); - -void start_real_timer(void (*func)(void* arg)); -void register_timer(int milli_second, void func(void* param), void* param); - -unsigned int get_cur_thread_id(); -void create_thread(unsigned long* thread_id, void* attr, void *(*start_routine) (void *), void* arg); -void thread_sleep(unsigned int milli_seconds); -int build_bmp(const char *filename, unsigned int width, unsigned int height, unsigned char *data); - -#define FIFO_BUFFER_LEN 1024 -class c_fifo -{ -public: - c_fifo(); - int read(void* buf, int len); - int write(void* buf, int len); -private: - unsigned char m_buf[FIFO_BUFFER_LEN]; - int m_head; - int m_tail; - void* m_read_sem; - void* m_write_mutex; -}; - -class c_rect -{ -public: - c_rect(){ m_left = m_top = m_right = m_bottom = -1; } - c_rect(int left, int top, int width, int height) - { - set_rect(left, top, width, height); - } - void set_rect(int left, int top, int width, int height) - { - ASSERT(width > 0 && height > 0); - m_left = left; - m_top = top; - m_right = left + width - 1; - m_bottom = top + height -1; - } - bool pt_in_rect(int x, int y) const - { - return x >= m_left && x <= m_right && y >= m_top && y <= m_bottom; - } - int operator==(const c_rect& rect) const - { - return (m_left == rect.m_left) && (m_top == rect.m_top) && (m_right == rect.m_right) && (m_bottom == rect.m_bottom); - } - int width() const { return m_right - m_left + 1; } - int height() const { return m_bottom - m_top + 1 ; } - - int m_left; - int m_top; - int m_right; - int m_bottom; -}; +#define REAL_TIME_TASK_CYCLE_MS 50 +#define MAX(a,b) (((a)>(b))?(a):(b)) +#define MIN(a,b) (((a)<(b))?(a):(b)) +#define GL_ARGB(a, r, g, b) ((((unsigned int)(a)) << 24) | (((unsigned int)(r)) << 16) | (((unsigned int)(g)) << 8) | ((unsigned int)(b))) +#define GL_ARGB_A(rgb) ((((unsigned int)(rgb)) >> 24) & 0xFF) +#define GL_RGB(r, g, b) ((0xFF << 24) | (((unsigned int)(r)) << 16) | (((unsigned int)(g)) << 8) | ((unsigned int)(b))) +#define GL_RGB_R(rgb) ((((unsigned int)(rgb)) >> 16) & 0xFF) +#define GL_RGB_G(rgb) ((((unsigned int)(rgb)) >> 8) & 0xFF) +#define GL_RGB_B(rgb) (((unsigned int)(rgb)) & 0xFF) +#define GL_RGB_32_to_16(rgb) (((((unsigned int)(rgb)) & 0xFF) >> 3) | ((((unsigned int)(rgb)) & 0xFC00) >> 5) | ((((unsigned int)(rgb)) & 0xF80000) >> 8)) +#define GL_RGB_16_to_32(rgb) ((0xFF << 24) | ((((unsigned int)(rgb)) & 0x1F) << 3) | ((((unsigned int)(rgb)) & 0x7E0) << 5) | ((((unsigned int)(rgb)) & 0xF800) << 8)) +#define ALIGN_HCENTER 0x00000000L +#define ALIGN_LEFT 0x01000000L +#define ALIGN_RIGHT 0x02000000L +#define ALIGN_HMASK 0x03000000L +#define ALIGN_VCENTER 0x00000000L +#define ALIGN_TOP 0x00100000L +#define ALIGN_BOTTOM 0x00200000L +#define ALIGN_VMASK 0x00300000L +typedef struct +{ + unsigned short year; + unsigned short month; + unsigned short date; + unsigned short day; + unsigned short hour; + unsigned short minute; + unsigned short second; +}T_TIME; +void register_debug_function(void(*my_assert)(const char* file, int line), void(*my_log_out)(const char* log)); +void _assert(const char* file, int line); +#define ASSERT(condition) \ + do{ \ + if(!(condition))_assert(__FILE__, __LINE__);\ + }while(0) +void log_out(const char* log); +long get_time_in_second(); +T_TIME second_to_day(long second); +T_TIME get_time(); +void start_real_timer(void (*func)(void* arg)); +void register_timer(int milli_second, void func(void* param), void* param); +unsigned int get_cur_thread_id(); +void create_thread(unsigned long* thread_id, void* attr, void *(*start_routine) (void *), void* arg); +void thread_sleep(unsigned int milli_seconds); +int build_bmp(const char *filename, unsigned int width, unsigned int height, unsigned char *data); +#define FIFO_BUFFER_LEN 1024 +class c_fifo +{ +public: + c_fifo(); + int read(void* buf, int len); + int write(void* buf, int len); +private: + unsigned char m_buf[FIFO_BUFFER_LEN]; + int m_head; + int m_tail; + void* m_read_sem; + void* m_write_mutex; +}; +class c_rect +{ +public: + c_rect(){ m_left = m_top = m_right = m_bottom = -1; } + c_rect(int left, int top, int width, int height) + { + set_rect(left, top, width, height); + } + void set_rect(int left, int top, int width, int height) + { + ASSERT(width > 0 && height > 0); + m_left = left; + m_top = top; + m_right = left + width - 1; + m_bottom = top + height -1; + } + bool pt_in_rect(int x, int y) const + { + return x >= m_left && x <= m_right && y >= m_top && y <= m_bottom; + } + int operator==(const c_rect& rect) const + { + return (m_left == rect.m_left) && (m_top == rect.m_top) && (m_right == rect.m_right) && (m_bottom == rect.m_bottom); + } + int width() const { return m_right - m_left + 1; } + int height() const { return m_bottom - m_top + 1 ; } + int m_left; + int m_top; + int m_right; + int m_bottom; +}; //BITMAP typedef struct struct_bitmap_info { @@ -238,7 +225,7 @@ typedef enum Z_ORDER_LEVEL_2,//highest graphic level Z_ORDER_LEVEL_MAX }Z_ORDER_LEVEL; -struct EXTERNAL_GFX_OP +struct DISPLAY_DRIVER { void(*draw_pixel)(int x, int y, unsigned int rgb); void(*fill_rect)(int x0, int y0, int x1, int y1, unsigned int rgb); @@ -247,18 +234,19 @@ class c_surface; class c_display { friend class c_surface; public: - inline c_display(void* phy_fb, int display_width, int display_height, int surface_width, int surface_height, unsigned int color_bytes, int surface_cnt, EXTERNAL_GFX_OP* gfx_op = 0);//multiple surface or surface_no_fb - inline c_display(void* phy_fb, int display_width, int display_height, c_surface* surface);//single custom surface - inline c_surface* alloc_surface(Z_ORDER_LEVEL max_zorder, c_rect layer_rect = c_rect());//for multiple surfaces + inline c_display(void* phy_fb, int display_width, int display_height, c_surface* surface, DISPLAY_DRIVER* driver = 0);//single custom surface + inline c_display(void* phy_fb, int display_width, int display_height, int surface_width, int surface_height, unsigned int color_bytes, int surface_cnt, DISPLAY_DRIVER* driver = 0);//multiple surface + inline c_surface* alloc_surface(Z_ORDER_LEVEL max_zorder, c_rect layer_rect = c_rect());//for slide group inline int swipe_surface(c_surface* s0, c_surface* s1, int x0, int x1, int y0, int y1, int offset); int get_width() { return m_width; } int get_height() { return m_height; } + void* get_phy_fb() { return m_phy_fb; } void* get_updated_fb(int* width, int* height, bool force_update = false) { if (width && height) { - *width = get_width(); - *height = get_height(); + *width = m_width; + *height = m_height; } if (force_update) { @@ -277,35 +265,123 @@ public: { return -1; } - int width = get_width(); - int height = get_height(); //16 bits framebuffer if (m_color_bytes == 2) { - return build_bmp(file_name, width, height, (unsigned char*)m_phy_fb); + return build_bmp(file_name, m_width, m_height, (unsigned char*)m_phy_fb); } //32 bits framebuffer - unsigned short* p_bmp565_data = new unsigned short[width * height]; + unsigned short* p_bmp565_data = new unsigned short[m_width * m_height]; unsigned int* p_raw_data = (unsigned int*)m_phy_fb; - for (int i = 0; i < width * height; i++) + for (int i = 0; i < m_width * m_height; i++) { unsigned int rgb = *p_raw_data++; p_bmp565_data[i] = GL_RGB_32_to_16(rgb); } - int ret = build_bmp(file_name, width, height, (unsigned char*)p_bmp565_data); + int ret = build_bmp(file_name, m_width, m_height, (unsigned char*)p_bmp565_data); delete[]p_bmp565_data; return ret; } -private: - int m_width; //in pixels - int m_height; //in pixels - int m_color_bytes; //16 bits, 32 bits only - void* m_phy_fb; //physical framebuffer +protected: + virtual void draw_pixel(int x, int y, unsigned int rgb) + { + if ((x >= m_width) || (y >= m_height)) { return; } + if (m_driver && m_driver->draw_pixel) + { + return m_driver->draw_pixel(x, y, rgb); + } + if (m_color_bytes == 2) + { + ((unsigned short*)m_phy_fb)[y * m_width + x] = GL_RGB_32_to_16(rgb); + } + else + { + ((unsigned int*)m_phy_fb)[y * m_width + x] = rgb; + } + } + virtual void fill_rect(int x0, int y0, int x1, int y1, unsigned int rgb) + { + if (m_driver && m_driver->fill_rect) + { + return m_driver->fill_rect(x0, y0, x1, y1, rgb); + } + if (m_driver && m_driver->draw_pixel) + { + for (int y = y0; y <= y1; y++) + { + for (int x = x0; x <= x1; x++) + { + m_driver->draw_pixel(x, y, rgb); + } + } + return; + } + register int _width = m_width; + register int _height = m_height; + int x, y; + if (m_color_bytes == 2) + { + unsigned short* phy_fb; + unsigned int rgb_16 = GL_RGB_32_to_16(rgb); + for (y = y0; y <= y1; y++) + { + phy_fb = &((unsigned short*)m_phy_fb)[y * _width + x0]; + for (x = x0; x <= x1; x++) + { + if ((x < _width) && (y < _height)) + { + *phy_fb++ = rgb_16; + } + } + } + } + else + { + unsigned int* phy_fb; + for (y = y0; y <= y1; y++) + { + phy_fb = &((unsigned int*)m_phy_fb)[y * _width + x0]; + for (x = x0; x <= x1; x++) + { + if ((x < _width) && (y < _height)) + { + *phy_fb++ = rgb; + } + } + } + } + } + virtual int flush_screen(int left, int top, int right, int bottom, void* fb, int fb_width) + { + if ((0 == m_phy_fb) || (0 == fb)) + { + return -1; + } + register int _width = m_width; + register int _height = m_height; + left = (left >= _width) ? (_width - 1) : left; + right = (right >= _width) ? (_width - 1) : right; + top = (top >= _height) ? (_height - 1) : top; + bottom = (bottom >= _height) ? (_height - 1) : bottom; + for (int y = top; y < bottom; y++) + { + void* s_addr = (char*)fb + ((y * fb_width + left) * m_color_bytes); + void* d_addr = (char*)m_phy_fb + ((y * _width + left) * m_color_bytes); + memcpy(d_addr, s_addr, (right - left) * m_color_bytes); + } + return 0; + } + int m_width; //in pixels + int m_height; //in pixels + int m_color_bytes; //16/32 bits for default + void* m_phy_fb; //physical framebuffer for default + struct DISPLAY_DRIVER* m_driver; //Rendering by external method without default physical framebuffer int m_phy_read_index; int m_phy_write_index; c_surface* m_surface_group[SURFACE_CNT_MAX]; int m_surface_cnt; //surface count int m_surface_index; + }; class c_layer { @@ -317,12 +393,10 @@ public: class c_surface { friend class c_display; friend class c_bitmap_operator; public: - c_surface(unsigned int width, unsigned int height, unsigned int color_bytes, Z_ORDER_LEVEL max_zorder = Z_ORDER_LEVEL_0, c_rect overlpa_rect = c_rect()) : m_width(width), m_height(height), m_color_bytes(color_bytes), m_fb(0), m_is_active(false), m_top_zorder(Z_ORDER_LEVEL_0), m_phy_fb(0), m_phy_write_index(0), m_display(0) + c_surface(unsigned int width, unsigned int height, unsigned int color_bytes, Z_ORDER_LEVEL max_zorder = Z_ORDER_LEVEL_0, c_rect overlpa_rect = c_rect()) : m_width(width), m_height(height), m_color_bytes(color_bytes), m_fb(0), m_is_active(false), m_top_zorder(Z_ORDER_LEVEL_0), m_phy_write_index(0), m_display(0) { (overlpa_rect == c_rect()) ? set_surface(max_zorder, c_rect(0, 0, width - 1, height - 1)) : set_surface(max_zorder, overlpa_rect); } - int get_width() { return m_width; } - int get_height() { return m_height; } unsigned int get_pixel(int x, int y, unsigned int z_order) { if (x >= m_width || y >= m_height || x < 0 || y < 0 || z_order >= Z_ORDER_LEVEL_MAX) @@ -332,15 +406,15 @@ public: } if (m_layers[z_order].fb) { - return (m_color_bytes == 4) ? ((unsigned int*)(m_layers[z_order].fb))[y * m_width + x] : GL_RGB_16_to_32(((unsigned short*)(m_layers[z_order].fb))[y * m_width + x]); + return (m_color_bytes == 2) ? GL_RGB_16_to_32(((unsigned short*)(m_layers[z_order].fb))[y * m_width + x]) : ((unsigned int*)(m_layers[z_order].fb))[y * m_width + x]; } else if (m_fb) { - return (m_color_bytes == 4) ? ((unsigned int*)m_fb)[y * m_width + x] : GL_RGB_16_to_32(((unsigned short*)m_fb)[y * m_width + x]); + return (m_color_bytes == 2) ? GL_RGB_16_to_32(((unsigned short*)m_fb)[y * m_width + x]) : ((unsigned int*)m_fb)[y * m_width + x]; } - else if (m_phy_fb) + else if (m_display->m_phy_fb) { - return (m_color_bytes == 4) ? ((unsigned int*)m_phy_fb)[y * m_width + x] : GL_RGB_16_to_32(((unsigned short*)m_phy_fb)[y * m_width + x]); + return (m_color_bytes == 2) ? GL_RGB_16_to_32(((unsigned short*)m_display->m_phy_fb)[y * m_width + x]) : ((unsigned int*)m_display->m_phy_fb)[y * m_width + x]; } return 0; } @@ -357,7 +431,7 @@ public: } if (z_order == m_max_zorder) { - return draw_pixel_on_fb(x, y, rgb); + return draw_pixel_low_level(x, y, rgb); } if (z_order > (unsigned int)m_top_zorder) @@ -367,19 +441,19 @@ public: if (m_layers[z_order].rect.pt_in_rect(x, y)) { c_rect layer_rect = m_layers[z_order].rect; - if (m_color_bytes == 4) + if (m_color_bytes == 2) { - ((unsigned int*)(m_layers[z_order].fb))[(x - layer_rect.m_left) + (y - layer_rect.m_top) * layer_rect.width()] = rgb; + ((unsigned short*)(m_layers[z_order].fb))[(x - layer_rect.m_left) + (y - layer_rect.m_top) * layer_rect.width()] = GL_RGB_32_to_16(rgb); } else { - ((unsigned short*)(m_layers[z_order].fb))[(x - layer_rect.m_left) + (y - layer_rect.m_top) * layer_rect.width()] = GL_RGB_32_to_16(rgb); + ((unsigned int*)(m_layers[z_order].fb))[(x - layer_rect.m_left) + (y - layer_rect.m_top) * layer_rect.width()] = rgb; } } if (z_order == m_top_zorder) { - return draw_pixel_on_fb(x, y, rgb); + return draw_pixel_low_level(x, y, rgb); } bool be_overlapped = false; for (unsigned int tmp_z_order = Z_ORDER_LEVEL_MAX - 1; tmp_z_order > z_order; tmp_z_order--) @@ -392,7 +466,7 @@ public: } if (!be_overlapped) { - draw_pixel_on_fb(x, y, rgb); + draw_pixel_low_level(x, y, rgb); } } virtual void fill_rect(int x0, int y0, int x1, int y1, unsigned int rgb, unsigned int z_order) @@ -403,7 +477,7 @@ public: y1 = (y1 > (m_height - 1)) ? (m_height - 1) : y1; if (z_order == m_max_zorder) { - return fill_rect_on_fb(x0, y0, x1, y1, rgb); + return fill_rect_low_level(x0, y0, x1, y1, rgb); } if (z_order == m_top_zorder) { @@ -416,18 +490,18 @@ public: { if (layer_rect.pt_in_rect(x, y)) { - if (m_color_bytes == 4) + if (m_color_bytes == 2) { - ((unsigned int*)m_layers[z_order].fb)[(y - layer_rect.m_top) * layer_rect.width() + (x - layer_rect.m_left)] = rgb; + ((unsigned short*)m_layers[z_order].fb)[(y - layer_rect.m_top) * layer_rect.width() + (x - layer_rect.m_left)] = rgb_16; } else { - ((unsigned short*)m_layers[z_order].fb)[(y - layer_rect.m_top) * layer_rect.width() + (x - layer_rect.m_left)] = rgb_16; + ((unsigned int*)m_layers[z_order].fb)[(y - layer_rect.m_top) * layer_rect.width() + (x - layer_rect.m_left)] = rgb; } } } } - return fill_rect_on_fb(x0, y0, x1, y1, rgb); + return fill_rect_low_level(x0, y0, x1, y1, rgb); } for (; y0 <= y1; y0++) { @@ -499,27 +573,16 @@ public: } int flush_screen(int left, int top, int right, int bottom) { - if (left < 0 || left >= m_width || right < 0 || right >= m_width || - top < 0 || top >= m_height || bottom < 0 || bottom >= m_height) - { - ASSERT(false); - } - if (!m_is_active || (0 == m_phy_fb) || (0 == m_fb)) + if (!m_is_active) { return -1; } - int display_width = m_display->get_width(); - int display_height = m_display->get_height(); - left = (left >= display_width) ? (display_width - 1) : left; - right = (right >= display_width) ? (display_width - 1) : right; - top = (top >= display_height) ? (display_height - 1) : top; - bottom = (bottom >= display_height) ? (display_height - 1) : bottom; - for (int y = top; y < bottom; y++) + if (left < 0 || left >= m_width || right < 0 || right >= m_width || + top < 0 || top >= m_height || bottom < 0 || bottom >= m_height) { - void* s_addr = (char*)m_fb + ((y * m_width + left) * m_color_bytes); - void* d_addr = (char*)m_phy_fb + ((y * display_width + left) * m_color_bytes); - memcpy(d_addr, s_addr, (right - left) * m_color_bytes); + ASSERT(false); } + m_display->flush_screen(left, top, right, bottom, m_fb, m_width); *m_phy_write_index = *m_phy_write_index + 1; return 0; } @@ -537,90 +600,62 @@ public: { for (int x = rect.m_left; x <= rect.m_right; x++) { - unsigned int rgb = (m_color_bytes == 4) ? ((unsigned int*)fb)[(x - layer_rect.m_left) + (y - layer_rect.m_top) * width] : GL_RGB_16_to_32(((unsigned short*)fb)[(x - layer_rect.m_left) + (y - layer_rect.m_top) * width]); - draw_pixel_on_fb(x, y, rgb); + unsigned int rgb = (m_color_bytes == 2) ? GL_RGB_16_to_32(((unsigned short*)fb)[(x - layer_rect.m_left) + (y - layer_rect.m_top) * width]) : ((unsigned int*)fb)[(x - layer_rect.m_left) + (y - layer_rect.m_top) * width]; + draw_pixel_low_level(x, y, rgb); } } return 0; } void set_active(bool flag) { m_is_active = flag; } protected: - virtual void fill_rect_on_fb(int x0, int y0, int x1, int y1, unsigned int rgb) - { - int display_width = m_display->get_width(); - int display_height = m_display->get_height(); - if (m_color_bytes == 4) + virtual void fill_rect_low_level(int x0, int y0, int x1, int y1, unsigned int rgb) + {//fill rect on framebuffer of surface + int x, y; + if (m_color_bytes == 2) { - int x; - unsigned int* fb, * phy_fb; - for (; y0 <= y1; y0++) + unsigned short* fb; + unsigned int rgb_16 = GL_RGB_32_to_16(rgb); + for (y = y0; y <= y1; y++) { - x = x0; - fb = m_fb ? &((unsigned int*)m_fb)[y0 * m_width + x] : 0; - phy_fb = &((unsigned int*)m_phy_fb)[y0 * display_width + x]; - *m_phy_write_index = *m_phy_write_index + 1; - for (; x <= x1; x++) + fb = m_fb ? &((unsigned short*)m_fb)[y * m_width + x0] : 0; + if (!fb) { break; } + for (x = x0; x <= x1; x++) { - if (fb) - { - *fb++ = rgb; - } - if (m_is_active && (x < display_width) && (y0 < display_height)) - { - *phy_fb++ = rgb; - } + *fb++ = rgb_16; } } } - else if (m_color_bytes == 2) + else { - int x; - unsigned short* fb, * phy_fb; - rgb = GL_RGB_32_to_16(rgb); - for (; y0 <= y1; y0++) + unsigned int* fb; + for (y = y0; y <= y1; y++) { - x = x0; - fb = m_fb ? &((unsigned short*)m_fb)[y0 * m_width + x] : 0; - phy_fb = &((unsigned short*)m_phy_fb)[y0 * display_width + x]; - *m_phy_write_index = *m_phy_write_index + 1; - for (; x <= x1; x++) + fb = m_fb ? &((unsigned int*)m_fb)[y * m_width + x0] : 0; + if (!fb) { break; } + for (x = x0; x <= x1; x++) { - if (fb) - { - *fb++ = rgb; - } - if (m_is_active && (x < display_width) && (y0 < display_height)) - { - *phy_fb++ = rgb; - } + *fb++ = rgb; } } } + if (!m_is_active) { return; } + m_display->fill_rect(x0, y0, x1, y1, rgb); + *m_phy_write_index = *m_phy_write_index + 1; } - virtual void draw_pixel_on_fb(int x, int y, unsigned int rgb) + virtual void draw_pixel_low_level(int x, int y, unsigned int rgb) { if (m_fb) - { - (m_color_bytes == 4) ? ((unsigned int*)m_fb)[y * m_width + x] = rgb : ((unsigned short*)m_fb)[y * m_width + x] = GL_RGB_32_to_16(rgb); - } - if (m_is_active && (x < m_display->get_width()) && (y < m_display->get_height())) - { - if (m_color_bytes == 4) - { - ((unsigned int*)m_phy_fb)[y * (m_display->get_width()) + x] = rgb; - } - else - { - ((unsigned short*)m_phy_fb)[y * (m_display->get_width()) + x] = GL_RGB_32_to_16(rgb); - } - *m_phy_write_index = *m_phy_write_index + 1; + {//draw pixel on framebuffer of surface + (m_color_bytes == 2) ? ((unsigned short*)m_fb)[y * m_width + x] = GL_RGB_32_to_16(rgb): ((unsigned int*)m_fb)[y * m_width + x] = rgb; } + if (!m_is_active) { return; } + m_display->draw_pixel(x, y, rgb); + *m_phy_write_index = *m_phy_write_index + 1; } void attach_display(c_display* display) { ASSERT(display); m_display = display; - m_phy_fb = display->m_phy_fb; m_phy_write_index = &display->m_phy_write_index; } void set_surface(Z_ORDER_LEVEL max_z_order, c_rect layer_rect) @@ -638,87 +673,22 @@ protected: } int m_width; //in pixels int m_height; //in pixels - int m_color_bytes; //16 bits, 32 bits only + int m_color_bytes; //16 bits, 32 bits for default void* m_fb; //frame buffer you could see c_layer m_layers[Z_ORDER_LEVEL_MAX];//all graphic layers bool m_is_active; //active flag Z_ORDER_LEVEL m_max_zorder; //the highest graphic layer the surface will have Z_ORDER_LEVEL m_top_zorder; //the current highest graphic layer the surface have - void* m_phy_fb; //physical framebufer int* m_phy_write_index; c_display* m_display; }; -class c_surface_no_fb : public c_surface {//No physical framebuffer, render with external graphic interface - friend class c_display; -public: - c_surface_no_fb(unsigned int width, unsigned int height, unsigned int color_bytes, struct EXTERNAL_GFX_OP* gfx_op, Z_ORDER_LEVEL max_zorder = Z_ORDER_LEVEL_0, c_rect overlpa_rect = c_rect()) : c_surface(width, height, color_bytes, max_zorder, overlpa_rect), m_gfx_op(gfx_op) {} -protected: - virtual void fill_rect_on_fb(int x0, int y0, int x1, int y1, unsigned int rgb) - { - if (!m_gfx_op) - { - return; - } - if (m_gfx_op->fill_rect) - { - return m_gfx_op->fill_rect(x0, y0, x1, y1, rgb); - } - if (m_gfx_op->draw_pixel && m_is_active) - { - for (int y = y0; y <= y1; y++) - { - for (int x = x0; x <= x1; x++) - { - m_gfx_op->draw_pixel(x, y, rgb); - } - } - } - if (!m_fb) { return; } - if (m_color_bytes == 4) - { - unsigned int* fb; - for (int y = y0; y <= y1; y++) - { - fb = &((unsigned int*)m_fb)[y0 * m_width + x0]; - for (int x = x0; x <= x1; x++) - { - *fb++ = rgb; - } - } - } - else if (m_color_bytes == 2) - { - unsigned short* fb; - rgb = GL_RGB_32_to_16(rgb); - for (int y = y0; y <= y1; y++) - { - fb = &((unsigned short*)m_fb)[y0 * m_width + x0]; - for (int x = x0; x <= x1; x++) - { - *fb++ = rgb; - } - } - } - } - virtual void draw_pixel_on_fb(int x, int y, unsigned int rgb) - { - if (m_gfx_op && m_gfx_op->draw_pixel && m_is_active) - { - m_gfx_op->draw_pixel(x, y, rgb); - } - if (!m_fb) { return; } - if (m_color_bytes == 4) - { - ((unsigned int*)m_fb)[y * m_width + x] = rgb; - } - else if (m_color_bytes == 2) - { - ((unsigned short*)m_fb)[y * m_width + x] = GL_RGB_32_to_16(rgb); - } - } - struct EXTERNAL_GFX_OP* m_gfx_op;//Rendering by external method -}; -inline c_display::c_display(void* phy_fb, int display_width, int display_height, int surface_width, int surface_height, unsigned int color_bytes, int surface_cnt, EXTERNAL_GFX_OP* gfx_op) : m_width(display_width), m_height(display_height), m_color_bytes(color_bytes), m_phy_fb(phy_fb), m_phy_read_index(0), m_phy_write_index(0), m_surface_cnt(surface_cnt), m_surface_index(0) +inline c_display::c_display(void* phy_fb, int display_width, int display_height, c_surface* surface, DISPLAY_DRIVER* driver) : m_phy_fb(phy_fb), m_width(display_width), m_height(display_height), m_driver(driver), m_phy_read_index(0), m_phy_write_index(0), m_surface_cnt(1), m_surface_index(0) +{ + m_color_bytes = surface->m_color_bytes; + surface->m_is_active = true; + (m_surface_group[0] = surface)->attach_display(this); +} +inline c_display::c_display(void* phy_fb, int display_width, int display_height, int surface_width, int surface_height, unsigned int color_bytes, int surface_cnt, DISPLAY_DRIVER* driver) : m_phy_fb(phy_fb), m_width(display_width), m_height(display_height), m_color_bytes(color_bytes), m_phy_read_index(0), m_phy_write_index(0), m_surface_cnt(surface_cnt), m_driver(driver), m_surface_index(0) { ASSERT(color_bytes == 2 || color_bytes == 4); ASSERT(m_surface_cnt <= SURFACE_CNT_MAX); @@ -726,16 +696,10 @@ inline c_display::c_display(void* phy_fb, int display_width, int display_height, for (int i = 0; i < m_surface_cnt; i++) { - m_surface_group[i] = (phy_fb) ? new c_surface(surface_width, surface_height, color_bytes) : new c_surface_no_fb(surface_width, surface_height, color_bytes, gfx_op); + m_surface_group[i] = new c_surface(surface_width, surface_height, color_bytes); m_surface_group[i]->attach_display(this); } } -inline c_display::c_display(void* phy_fb, int display_width, int display_height, c_surface* surface) : m_width(display_width), m_height(display_height), m_phy_fb(phy_fb), m_phy_read_index(0), m_phy_write_index(0), m_surface_cnt(1), m_surface_index(0) -{ - m_color_bytes = surface->m_color_bytes; - surface->m_is_active = true; - (m_surface_group[0] = surface)->attach_display(this); -} inline c_surface* c_display::alloc_surface(Z_ORDER_LEVEL max_zorder, c_rect layer_rect) { ASSERT(max_zorder < Z_ORDER_LEVEL_MAX && m_surface_index < m_surface_cnt); @@ -744,8 +708,8 @@ inline c_surface* c_display::alloc_surface(Z_ORDER_LEVEL max_zorder, c_rect laye } inline int c_display::swipe_surface(c_surface* s0, c_surface* s1, int x0, int x1, int y0, int y1, int offset) { - int surface_width = s0->get_width(); - int surface_height = s0->get_height(); + register int surface_width = s0->m_width; + register int surface_height = s0->m_height; if (offset < 0 || offset > surface_width || y0 < 0 || y0 >= surface_height || y1 < 0 || y1 >= surface_height || x0 < 0 || x0 >= surface_width || x1 < 0 || x1 >= surface_width) { @@ -767,46 +731,46 @@ inline int c_display::swipe_surface(c_surface* s0, c_surface* s1, int x0, int x1 for (int y = y0; y <= y1; y++) { //Left surface - char* addr_s = ((char*)(s0->m_fb) + (y * (s0->get_width()) + x0 + offset) * m_color_bytes); + char* addr_s = ((char*)(s0->m_fb) + (y * surface_width + x0 + offset) * m_color_bytes); char* addr_d = ((char*)(m_phy_fb)+(y * m_width + x0) * m_color_bytes); memcpy(addr_d, addr_s, (width - offset) * m_color_bytes); //Right surface - addr_s = ((char*)(s1->m_fb) + (y * (s1->get_width()) + x0) * m_color_bytes); + addr_s = ((char*)(s1->m_fb) + (y * surface_width + x0) * m_color_bytes); addr_d = ((char*)(m_phy_fb)+(y * m_width + x0 + (width - offset)) * m_color_bytes); memcpy(addr_d, addr_s, offset * m_color_bytes); } } - else if (m_color_bytes == 4) + else if (m_color_bytes == 2) { - void(*draw_pixel)(int x, int y, unsigned int rgb) = ((c_surface_no_fb*)s0)->m_gfx_op->draw_pixel; + void(*draw_pixel)(int x, int y, unsigned int rgb) = m_driver->draw_pixel; for (int y = y0; y <= y1; y++) { //Left surface for (int x = x0; x <= (x1 - offset); x++) { - draw_pixel(x, y, ((unsigned int*)s0->m_fb)[y * m_width + x + offset]); + draw_pixel(x, y, GL_RGB_16_to_32(((unsigned short*)s0->m_fb)[y * m_width + x + offset])); } //Right surface for (int x = x1 - offset; x <= x1; x++) { - draw_pixel(x, y, ((unsigned int*)s1->m_fb)[y * m_width + x + offset - x1 + x0]); + draw_pixel(x, y, GL_RGB_16_to_32(((unsigned short*)s1->m_fb)[y * m_width + x + offset - x1 + x0])); } } } - else if (m_color_bytes == 2) + else //m_color_bytes == 3/4... { - void(*draw_pixel)(int x, int y, unsigned int rgb) = ((c_surface_no_fb*)s0)->m_gfx_op->draw_pixel; + void(*draw_pixel)(int x, int y, unsigned int rgb) = m_driver->draw_pixel; for (int y = y0; y <= y1; y++) { //Left surface for (int x = x0; x <= (x1 - offset); x++) { - draw_pixel(x, y, GL_RGB_16_to_32(((unsigned short*)s0->m_fb)[y * m_width + x + offset])); + draw_pixel(x, y, ((unsigned int*)s0->m_fb)[y * m_width + x + offset]); } //Right surface for (int x = x1 - offset; x <= x1; x++) { - draw_pixel(x, y, GL_RGB_16_to_32(((unsigned short*)s1->m_fb)[y * m_width + x + offset - x1 + x0])); + draw_pixel(x, y, ((unsigned int*)s1->m_fb)[y * m_width + x + offset - x1 + x0]); } } } @@ -3407,22 +3371,12 @@ private: #ifdef GUILITE_ON c_bitmap_operator the_bitmap_op = c_bitmap_operator(); c_image_operator* c_image::image_operator = &the_bitmap_op; +const void* c_theme::s_font_map[FONT_MAX]; +const void* c_theme::s_image_map[IMAGE_MAX]; +unsigned int c_theme::s_color_map[COLOR_MAX]; +c_lattice_font_op the_lattice_font_op = c_lattice_font_op(); +c_font_operator* c_word::fontOperator = &the_lattice_font_op; #endif - -#ifdef GUILITE_ON - -const void* c_theme::s_font_map[FONT_MAX]; -const void* c_theme::s_image_map[IMAGE_MAX]; -unsigned int c_theme::s_color_map[COLOR_MAX]; - -#endif - -#ifdef GUILITE_ON - -c_lattice_font_op the_lattice_font_op = c_lattice_font_op(); -c_font_operator* c_word::fontOperator = &the_lattice_font_op; - -#endif #ifdef GUILITE_ON #if (defined __linux__) || (defined __APPLE__) #include @@ -4264,11 +4218,7 @@ int c_fifo::write(void* buf, int len) #endif #ifdef GUILITE_ON DIALOG_ARRAY c_dialog::ms_the_dialogs[SURFACE_CNT_MAX]; -#endif -#ifdef GUILITE_ON c_keyboard c_edit::s_keyboard; -#endif -#ifdef GUILITE_ON static c_keyboard_button s_key_0, s_key_1, s_key_2, s_key_3, s_key_4, s_key_5, s_key_6, s_key_7, s_key_8, s_key_9; static c_keyboard_button s_key_A, s_key_B, s_key_C, s_key_D, s_key_E, s_key_F, s_key_G, s_key_H, s_key_I, s_key_J; static c_keyboard_button s_key_K, s_key_L, s_key_M, s_key_N, s_key_O, s_key_P, s_key_Q, s_key_R, s_key_S, s_key_T; @@ -4306,12 +4256,12 @@ WND_TREE g_key_board_children[] = {&s_key_B, 'B', 0, ((KEY_WIDTH / 2) + POS_X(5)), POS_Y(2), KEY_WIDTH, KEY_HEIGHT}, {&s_key_N, 'N', 0, ((KEY_WIDTH / 2) + POS_X(6)), POS_Y(2), KEY_WIDTH, KEY_HEIGHT}, {&s_key_M, 'M', 0, ((KEY_WIDTH / 2) + POS_X(7)), POS_Y(2), KEY_WIDTH, KEY_HEIGHT}, - {&s_key_del, 0x7F, 0, ((KEY_WIDTH / 2) + POS_X(8)), POS_Y(2), DEL_WIDTH, KEY_HEIGHT}, + {&s_key_del,0x7F, 0, ((KEY_WIDTH / 2) + POS_X(8)), POS_Y(2), DEL_WIDTH, KEY_HEIGHT}, //Row 4 - {&s_key_esc, 0x1B, 0, POS_X(0), POS_Y(3), ESC_WIDTH, KEY_HEIGHT}, + {&s_key_esc, 0x1B, 0, POS_X(0), POS_Y(3), ESC_WIDTH, KEY_HEIGHT}, {&s_key_num_switch, 0x90, 0, POS_X(2), POS_Y(3), SWITCH_WIDTH, KEY_HEIGHT}, {&s_key_space, ' ', 0, ((KEY_WIDTH / 2) + POS_X(3)), POS_Y(3), SPACE_WIDTH, KEY_HEIGHT}, - {&s_key_dot, '.', 0, ((KEY_WIDTH / 2) + POS_X(6)), POS_Y(3), DOT_WIDTH, KEY_HEIGHT}, + {&s_key_dot, '.', 0, ((KEY_WIDTH / 2) + POS_X(6)), POS_Y(3), DOT_WIDTH, KEY_HEIGHT}, {&s_key_enter, '\n', 0, POS_X(8), POS_Y(3), ENTER_WIDTH, KEY_HEIGHT}, {0,0,0,0,0,0,0} }; @@ -4326,12 +4276,11 @@ WND_TREE g_number_board_children[] = {&s_key_7, '7', 0, POS_X(0), POS_Y(2), KEY_WIDTH, KEY_HEIGHT}, {&s_key_8, '8', 0, POS_X(1), POS_Y(2), KEY_WIDTH, KEY_HEIGHT}, {&s_key_9, '9', 0, POS_X(2), POS_Y(2), KEY_WIDTH, KEY_HEIGHT}, - - {&s_key_esc, 0x1B, 0, POS_X(0), POS_Y(3), KEY_WIDTH, KEY_HEIGHT}, + {&s_key_esc,0x1B, 0, POS_X(0), POS_Y(3), KEY_WIDTH, KEY_HEIGHT}, {&s_key_0, '0', 0, POS_X(1), POS_Y(3), KEY_WIDTH, KEY_HEIGHT}, - {&s_key_dot, '.', 0, POS_X(2), POS_Y(3), KEY_WIDTH, KEY_HEIGHT}, + {&s_key_dot,'.', 0, POS_X(2), POS_Y(3), KEY_WIDTH, KEY_HEIGHT}, {&s_key_del, 0x7F, 0, POS_X(3), POS_Y(0), KEY_WIDTH, KEY_HEIGHT * 2 + 2}, {&s_key_enter,'\n', 0, POS_X(3), POS_Y(2), KEY_WIDTH, KEY_HEIGHT * 2 + 2}, {0,0,0,0,0,0,0} }; -#endif +#endif \ No newline at end of file diff --git a/HelloStar/BuildLinux/.sync_build.sh b/HelloStar/BuildLinux/.sync_build.sh index 49cff5b473ac606967676ebefa6f0d333e301227..a16fc7f1148348e8dff109c388486e588247cbe2 100644 --- a/HelloStar/BuildLinux/.sync_build.sh +++ b/HelloStar/BuildLinux/.sync_build.sh @@ -1,5 +1,6 @@ if [ "$#" -ne 1 ]; then - echo "Invalid arguments" + echo "Do testing" + ./xWindow 240 320 | ./HelloStar shared-fb exit -1 fi diff --git a/HelloStar/BuildLinux/main.cpp b/HelloStar/BuildLinux/main.cpp index 054b26d150a372ddfe15ae602c7bc707e7322135..b82c7da545063de030a21f4207efad0e833a5258 100644 --- a/HelloStar/BuildLinux/main.cpp +++ b/HelloStar/BuildLinux/main.cpp @@ -10,7 +10,7 @@ #include #include -extern "C" void startHelloStar(void* phy_fb, int width, int height, int color_bytes, struct EXTERNAL_GFX_OP* gfx_op); +extern "C" void startHelloStar(void* phy_fb, int width, int height, int color_bytes, struct DISPLAY_DRIVER* driver); extern void init_std_io(); static void* get_embeded_fb_in_display_app(int shared_id); diff --git a/HelloStar/BuildMFC/HelloStarDlg.cpp b/HelloStar/BuildMFC/HelloStarDlg.cpp index 2cd362fa931b97d1c3560d81d245a6bbd769be62..5b15ebc07c6c052605c41a6c62bb2f11701c80c4 100644 Binary files a/HelloStar/BuildMFC/HelloStarDlg.cpp and b/HelloStar/BuildMFC/HelloStarDlg.cpp differ diff --git a/HelloStar/BuildMFC/HelloStarDlg.h b/HelloStar/BuildMFC/HelloStarDlg.h index 89af53600b0095e6c23caff2bc019e0756ad7f1b..6e7f7cdd60f55be60e806704ac0abc3164c81386 100644 Binary files a/HelloStar/BuildMFC/HelloStarDlg.h and b/HelloStar/BuildMFC/HelloStarDlg.h differ diff --git a/HelloStar/BuildSTM32F103-Keil/USER/main.c b/HelloStar/BuildSTM32F103-Keil/USER/main.c index e6d2561e35b39c825d64960af0ed4e965be2e139..3e8fd5e1004bc6667646e20a0ed5d6b66c3329fb 100644 --- a/HelloStar/BuildSTM32F103-Keil/USER/main.c +++ b/HelloStar/BuildSTM32F103-Keil/USER/main.c @@ -15,12 +15,12 @@ void gfx_draw_pixel(int x, int y, unsigned int rgb) //void gfx_fill_rect(int x0, int y0, int x1, int y1, unsigned int rgb){} //UI entry -struct EXTERNAL_GFX_OP +struct DISPLAY_DRIVER { void (*draw_pixel)(int x, int y, unsigned int rgb); void (*fill_rect)(int x0, int y0, int x1, int y1, unsigned int rgb); -} my_gfx_op; -extern void startHelloStar(void* phy_fb, int width, int height, int color_bytes, struct EXTERNAL_GFX_OP* gfx_op); +} my_driver; +extern void startHelloStar(void* phy_fb, int width, int height, int color_bytes, struct DISPLAY_DRIVER* driver); int main(void) { @@ -30,8 +30,8 @@ int main(void) LCD_Init(); //Link your LCD driver & start UI: - my_gfx_op.draw_pixel = gfx_draw_pixel; - my_gfx_op.fill_rect = NULL;//gfx_fill_rect; - startHelloStar(NULL, 240, 320, 2, &my_gfx_op); + my_driver.draw_pixel = gfx_draw_pixel; + my_driver.fill_rect = NULL;//gfx_fill_rect; + startHelloStar(NULL, 240, 320, 2, &my_driver); while(1); } diff --git a/HelloStar/BuildWin32/HelloStar.cpp b/HelloStar/BuildWin32/HelloStar.cpp index a120104eaf937e6e8f038a31075131a91ca2b42b..f255d1d0db849d54ef5da6b3bd0db01c9e595930 100644 --- a/HelloStar/BuildWin32/HelloStar.cpp +++ b/HelloStar/BuildWin32/HelloStar.cpp @@ -161,7 +161,7 @@ LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam) } //////////////////////// HelloStar Interface //////////////////////// -extern "C" void startHelloStar(void* phy_fb, int width, int height, int color_bytes, struct EXTERNAL_GFX_OP* gfx_op); +extern "C" void startHelloStar(void* phy_fb, int width, int height, int color_bytes, struct DISPLAY_DRIVER* driver); DWORD WINAPI ThreadHelloStar(LPVOID pParam) { diff --git a/HelloStar/UIcode/GuiLite.h b/HelloStar/UIcode/GuiLite.h index c4fc88a51476d2c8309c3e55e1270e13784fc510..80550e1632ad7bc82541a2edbb0f7f8f5937954f 100644 --- a/HelloStar/UIcode/GuiLite.h +++ b/HelloStar/UIcode/GuiLite.h @@ -1,107 +1,94 @@ #pragma once - -#define REAL_TIME_TASK_CYCLE_MS 50 -#define MAX(a,b) (((a)>(b))?(a):(b)) -#define MIN(a,b) (((a)<(b))?(a):(b)) - -#define GL_ARGB(a, r, g, b) ((((unsigned int)(a)) << 24) | (((unsigned int)(r)) << 16) | (((unsigned int)(g)) << 8) | ((unsigned int)(b))) -#define GL_ARGB_A(rgb) ((((unsigned int)(rgb)) >> 24) & 0xFF) - -#define GL_RGB(r, g, b) ((0xFF << 24) | (((unsigned int)(r)) << 16) | (((unsigned int)(g)) << 8) | ((unsigned int)(b))) -#define GL_RGB_R(rgb) ((((unsigned int)(rgb)) >> 16) & 0xFF) -#define GL_RGB_G(rgb) ((((unsigned int)(rgb)) >> 8) & 0xFF) -#define GL_RGB_B(rgb) (((unsigned int)(rgb)) & 0xFF) -#define GL_RGB_32_to_16(rgb) (((((unsigned int)(rgb)) & 0xFF) >> 3) | ((((unsigned int)(rgb)) & 0xFC00) >> 5) | ((((unsigned int)(rgb)) & 0xF80000) >> 8)) -#define GL_RGB_16_to_32(rgb) ((0xFF << 24) | ((((unsigned int)(rgb)) & 0x1F) << 3) | ((((unsigned int)(rgb)) & 0x7E0) << 5) | ((((unsigned int)(rgb)) & 0xF800) << 8)) - -#define ALIGN_HCENTER 0x00000000L -#define ALIGN_LEFT 0x01000000L -#define ALIGN_RIGHT 0x02000000L -#define ALIGN_HMASK 0x03000000L - -#define ALIGN_VCENTER 0x00000000L -#define ALIGN_TOP 0x00100000L -#define ALIGN_BOTTOM 0x00200000L -#define ALIGN_VMASK 0x00300000L - -typedef struct -{ - unsigned short year; - unsigned short month; - unsigned short date; - unsigned short day; - unsigned short hour; - unsigned short minute; - unsigned short second; -}T_TIME; - -void register_debug_function(void(*my_assert)(const char* file, int line), void(*my_log_out)(const char* log)); -void _assert(const char* file, int line); -#define ASSERT(condition) \ - do{ \ - if(!(condition))_assert(__FILE__, __LINE__);\ - }while(0) -void log_out(const char* log); - -long get_time_in_second(); -T_TIME second_to_day(long second); -T_TIME get_time(); - -void start_real_timer(void (*func)(void* arg)); -void register_timer(int milli_second, void func(void* param), void* param); - -unsigned int get_cur_thread_id(); -void create_thread(unsigned long* thread_id, void* attr, void *(*start_routine) (void *), void* arg); -void thread_sleep(unsigned int milli_seconds); -int build_bmp(const char *filename, unsigned int width, unsigned int height, unsigned char *data); - -#define FIFO_BUFFER_LEN 1024 -class c_fifo -{ -public: - c_fifo(); - int read(void* buf, int len); - int write(void* buf, int len); -private: - unsigned char m_buf[FIFO_BUFFER_LEN]; - int m_head; - int m_tail; - void* m_read_sem; - void* m_write_mutex; -}; - -class c_rect -{ -public: - c_rect(){ m_left = m_top = m_right = m_bottom = -1; } - c_rect(int left, int top, int width, int height) - { - set_rect(left, top, width, height); - } - void set_rect(int left, int top, int width, int height) - { - ASSERT(width > 0 && height > 0); - m_left = left; - m_top = top; - m_right = left + width - 1; - m_bottom = top + height -1; - } - bool pt_in_rect(int x, int y) const - { - return x >= m_left && x <= m_right && y >= m_top && y <= m_bottom; - } - int operator==(const c_rect& rect) const - { - return (m_left == rect.m_left) && (m_top == rect.m_top) && (m_right == rect.m_right) && (m_bottom == rect.m_bottom); - } - int width() const { return m_right - m_left + 1; } - int height() const { return m_bottom - m_top + 1 ; } - - int m_left; - int m_top; - int m_right; - int m_bottom; -}; +#define REAL_TIME_TASK_CYCLE_MS 50 +#define MAX(a,b) (((a)>(b))?(a):(b)) +#define MIN(a,b) (((a)<(b))?(a):(b)) +#define GL_ARGB(a, r, g, b) ((((unsigned int)(a)) << 24) | (((unsigned int)(r)) << 16) | (((unsigned int)(g)) << 8) | ((unsigned int)(b))) +#define GL_ARGB_A(rgb) ((((unsigned int)(rgb)) >> 24) & 0xFF) +#define GL_RGB(r, g, b) ((0xFF << 24) | (((unsigned int)(r)) << 16) | (((unsigned int)(g)) << 8) | ((unsigned int)(b))) +#define GL_RGB_R(rgb) ((((unsigned int)(rgb)) >> 16) & 0xFF) +#define GL_RGB_G(rgb) ((((unsigned int)(rgb)) >> 8) & 0xFF) +#define GL_RGB_B(rgb) (((unsigned int)(rgb)) & 0xFF) +#define GL_RGB_32_to_16(rgb) (((((unsigned int)(rgb)) & 0xFF) >> 3) | ((((unsigned int)(rgb)) & 0xFC00) >> 5) | ((((unsigned int)(rgb)) & 0xF80000) >> 8)) +#define GL_RGB_16_to_32(rgb) ((0xFF << 24) | ((((unsigned int)(rgb)) & 0x1F) << 3) | ((((unsigned int)(rgb)) & 0x7E0) << 5) | ((((unsigned int)(rgb)) & 0xF800) << 8)) +#define ALIGN_HCENTER 0x00000000L +#define ALIGN_LEFT 0x01000000L +#define ALIGN_RIGHT 0x02000000L +#define ALIGN_HMASK 0x03000000L +#define ALIGN_VCENTER 0x00000000L +#define ALIGN_TOP 0x00100000L +#define ALIGN_BOTTOM 0x00200000L +#define ALIGN_VMASK 0x00300000L +typedef struct +{ + unsigned short year; + unsigned short month; + unsigned short date; + unsigned short day; + unsigned short hour; + unsigned short minute; + unsigned short second; +}T_TIME; +void register_debug_function(void(*my_assert)(const char* file, int line), void(*my_log_out)(const char* log)); +void _assert(const char* file, int line); +#define ASSERT(condition) \ + do{ \ + if(!(condition))_assert(__FILE__, __LINE__);\ + }while(0) +void log_out(const char* log); +long get_time_in_second(); +T_TIME second_to_day(long second); +T_TIME get_time(); +void start_real_timer(void (*func)(void* arg)); +void register_timer(int milli_second, void func(void* param), void* param); +unsigned int get_cur_thread_id(); +void create_thread(unsigned long* thread_id, void* attr, void *(*start_routine) (void *), void* arg); +void thread_sleep(unsigned int milli_seconds); +int build_bmp(const char *filename, unsigned int width, unsigned int height, unsigned char *data); +#define FIFO_BUFFER_LEN 1024 +class c_fifo +{ +public: + c_fifo(); + int read(void* buf, int len); + int write(void* buf, int len); +private: + unsigned char m_buf[FIFO_BUFFER_LEN]; + int m_head; + int m_tail; + void* m_read_sem; + void* m_write_mutex; +}; +class c_rect +{ +public: + c_rect(){ m_left = m_top = m_right = m_bottom = -1; } + c_rect(int left, int top, int width, int height) + { + set_rect(left, top, width, height); + } + void set_rect(int left, int top, int width, int height) + { + ASSERT(width > 0 && height > 0); + m_left = left; + m_top = top; + m_right = left + width - 1; + m_bottom = top + height -1; + } + bool pt_in_rect(int x, int y) const + { + return x >= m_left && x <= m_right && y >= m_top && y <= m_bottom; + } + int operator==(const c_rect& rect) const + { + return (m_left == rect.m_left) && (m_top == rect.m_top) && (m_right == rect.m_right) && (m_bottom == rect.m_bottom); + } + int width() const { return m_right - m_left + 1; } + int height() const { return m_bottom - m_top + 1 ; } + int m_left; + int m_top; + int m_right; + int m_bottom; +}; //BITMAP typedef struct struct_bitmap_info { @@ -238,7 +225,7 @@ typedef enum Z_ORDER_LEVEL_2,//highest graphic level Z_ORDER_LEVEL_MAX }Z_ORDER_LEVEL; -struct EXTERNAL_GFX_OP +struct DISPLAY_DRIVER { void(*draw_pixel)(int x, int y, unsigned int rgb); void(*fill_rect)(int x0, int y0, int x1, int y1, unsigned int rgb); @@ -247,18 +234,19 @@ class c_surface; class c_display { friend class c_surface; public: - inline c_display(void* phy_fb, int display_width, int display_height, int surface_width, int surface_height, unsigned int color_bytes, int surface_cnt, EXTERNAL_GFX_OP* gfx_op = 0);//multiple surface or surface_no_fb - inline c_display(void* phy_fb, int display_width, int display_height, c_surface* surface);//single custom surface - inline c_surface* alloc_surface(Z_ORDER_LEVEL max_zorder, c_rect layer_rect = c_rect());//for multiple surfaces + inline c_display(void* phy_fb, int display_width, int display_height, c_surface* surface, DISPLAY_DRIVER* driver = 0);//single custom surface + inline c_display(void* phy_fb, int display_width, int display_height, int surface_width, int surface_height, unsigned int color_bytes, int surface_cnt, DISPLAY_DRIVER* driver = 0);//multiple surface + inline c_surface* alloc_surface(Z_ORDER_LEVEL max_zorder, c_rect layer_rect = c_rect());//for slide group inline int swipe_surface(c_surface* s0, c_surface* s1, int x0, int x1, int y0, int y1, int offset); int get_width() { return m_width; } int get_height() { return m_height; } + void* get_phy_fb() { return m_phy_fb; } void* get_updated_fb(int* width, int* height, bool force_update = false) { if (width && height) { - *width = get_width(); - *height = get_height(); + *width = m_width; + *height = m_height; } if (force_update) { @@ -277,35 +265,123 @@ public: { return -1; } - int width = get_width(); - int height = get_height(); //16 bits framebuffer if (m_color_bytes == 2) { - return build_bmp(file_name, width, height, (unsigned char*)m_phy_fb); + return build_bmp(file_name, m_width, m_height, (unsigned char*)m_phy_fb); } //32 bits framebuffer - unsigned short* p_bmp565_data = new unsigned short[width * height]; + unsigned short* p_bmp565_data = new unsigned short[m_width * m_height]; unsigned int* p_raw_data = (unsigned int*)m_phy_fb; - for (int i = 0; i < width * height; i++) + for (int i = 0; i < m_width * m_height; i++) { unsigned int rgb = *p_raw_data++; p_bmp565_data[i] = GL_RGB_32_to_16(rgb); } - int ret = build_bmp(file_name, width, height, (unsigned char*)p_bmp565_data); + int ret = build_bmp(file_name, m_width, m_height, (unsigned char*)p_bmp565_data); delete[]p_bmp565_data; return ret; } -private: - int m_width; //in pixels - int m_height; //in pixels - int m_color_bytes; //16 bits, 32 bits only - void* m_phy_fb; //physical framebuffer +protected: + virtual void draw_pixel(int x, int y, unsigned int rgb) + { + if ((x >= m_width) || (y >= m_height)) { return; } + if (m_driver && m_driver->draw_pixel) + { + return m_driver->draw_pixel(x, y, rgb); + } + if (m_color_bytes == 2) + { + ((unsigned short*)m_phy_fb)[y * m_width + x] = GL_RGB_32_to_16(rgb); + } + else + { + ((unsigned int*)m_phy_fb)[y * m_width + x] = rgb; + } + } + virtual void fill_rect(int x0, int y0, int x1, int y1, unsigned int rgb) + { + if (m_driver && m_driver->fill_rect) + { + return m_driver->fill_rect(x0, y0, x1, y1, rgb); + } + if (m_driver && m_driver->draw_pixel) + { + for (int y = y0; y <= y1; y++) + { + for (int x = x0; x <= x1; x++) + { + m_driver->draw_pixel(x, y, rgb); + } + } + return; + } + register int _width = m_width; + register int _height = m_height; + int x, y; + if (m_color_bytes == 2) + { + unsigned short* phy_fb; + unsigned int rgb_16 = GL_RGB_32_to_16(rgb); + for (y = y0; y <= y1; y++) + { + phy_fb = &((unsigned short*)m_phy_fb)[y * _width + x0]; + for (x = x0; x <= x1; x++) + { + if ((x < _width) && (y < _height)) + { + *phy_fb++ = rgb_16; + } + } + } + } + else + { + unsigned int* phy_fb; + for (y = y0; y <= y1; y++) + { + phy_fb = &((unsigned int*)m_phy_fb)[y * _width + x0]; + for (x = x0; x <= x1; x++) + { + if ((x < _width) && (y < _height)) + { + *phy_fb++ = rgb; + } + } + } + } + } + virtual int flush_screen(int left, int top, int right, int bottom, void* fb, int fb_width) + { + if ((0 == m_phy_fb) || (0 == fb)) + { + return -1; + } + register int _width = m_width; + register int _height = m_height; + left = (left >= _width) ? (_width - 1) : left; + right = (right >= _width) ? (_width - 1) : right; + top = (top >= _height) ? (_height - 1) : top; + bottom = (bottom >= _height) ? (_height - 1) : bottom; + for (int y = top; y < bottom; y++) + { + void* s_addr = (char*)fb + ((y * fb_width + left) * m_color_bytes); + void* d_addr = (char*)m_phy_fb + ((y * _width + left) * m_color_bytes); + memcpy(d_addr, s_addr, (right - left) * m_color_bytes); + } + return 0; + } + int m_width; //in pixels + int m_height; //in pixels + int m_color_bytes; //16/32 bits for default + void* m_phy_fb; //physical framebuffer for default + struct DISPLAY_DRIVER* m_driver; //Rendering by external method without default physical framebuffer int m_phy_read_index; int m_phy_write_index; c_surface* m_surface_group[SURFACE_CNT_MAX]; int m_surface_cnt; //surface count int m_surface_index; + }; class c_layer { @@ -317,12 +393,10 @@ public: class c_surface { friend class c_display; friend class c_bitmap_operator; public: - c_surface(unsigned int width, unsigned int height, unsigned int color_bytes, Z_ORDER_LEVEL max_zorder = Z_ORDER_LEVEL_0, c_rect overlpa_rect = c_rect()) : m_width(width), m_height(height), m_color_bytes(color_bytes), m_fb(0), m_is_active(false), m_top_zorder(Z_ORDER_LEVEL_0), m_phy_fb(0), m_phy_write_index(0), m_display(0) + c_surface(unsigned int width, unsigned int height, unsigned int color_bytes, Z_ORDER_LEVEL max_zorder = Z_ORDER_LEVEL_0, c_rect overlpa_rect = c_rect()) : m_width(width), m_height(height), m_color_bytes(color_bytes), m_fb(0), m_is_active(false), m_top_zorder(Z_ORDER_LEVEL_0), m_phy_write_index(0), m_display(0) { (overlpa_rect == c_rect()) ? set_surface(max_zorder, c_rect(0, 0, width - 1, height - 1)) : set_surface(max_zorder, overlpa_rect); } - int get_width() { return m_width; } - int get_height() { return m_height; } unsigned int get_pixel(int x, int y, unsigned int z_order) { if (x >= m_width || y >= m_height || x < 0 || y < 0 || z_order >= Z_ORDER_LEVEL_MAX) @@ -332,15 +406,15 @@ public: } if (m_layers[z_order].fb) { - return (m_color_bytes == 4) ? ((unsigned int*)(m_layers[z_order].fb))[y * m_width + x] : GL_RGB_16_to_32(((unsigned short*)(m_layers[z_order].fb))[y * m_width + x]); + return (m_color_bytes == 2) ? GL_RGB_16_to_32(((unsigned short*)(m_layers[z_order].fb))[y * m_width + x]) : ((unsigned int*)(m_layers[z_order].fb))[y * m_width + x]; } else if (m_fb) { - return (m_color_bytes == 4) ? ((unsigned int*)m_fb)[y * m_width + x] : GL_RGB_16_to_32(((unsigned short*)m_fb)[y * m_width + x]); + return (m_color_bytes == 2) ? GL_RGB_16_to_32(((unsigned short*)m_fb)[y * m_width + x]) : ((unsigned int*)m_fb)[y * m_width + x]; } - else if (m_phy_fb) + else if (m_display->m_phy_fb) { - return (m_color_bytes == 4) ? ((unsigned int*)m_phy_fb)[y * m_width + x] : GL_RGB_16_to_32(((unsigned short*)m_phy_fb)[y * m_width + x]); + return (m_color_bytes == 2) ? GL_RGB_16_to_32(((unsigned short*)m_display->m_phy_fb)[y * m_width + x]) : ((unsigned int*)m_display->m_phy_fb)[y * m_width + x]; } return 0; } @@ -357,7 +431,7 @@ public: } if (z_order == m_max_zorder) { - return draw_pixel_on_fb(x, y, rgb); + return draw_pixel_low_level(x, y, rgb); } if (z_order > (unsigned int)m_top_zorder) @@ -367,19 +441,19 @@ public: if (m_layers[z_order].rect.pt_in_rect(x, y)) { c_rect layer_rect = m_layers[z_order].rect; - if (m_color_bytes == 4) + if (m_color_bytes == 2) { - ((unsigned int*)(m_layers[z_order].fb))[(x - layer_rect.m_left) + (y - layer_rect.m_top) * layer_rect.width()] = rgb; + ((unsigned short*)(m_layers[z_order].fb))[(x - layer_rect.m_left) + (y - layer_rect.m_top) * layer_rect.width()] = GL_RGB_32_to_16(rgb); } else { - ((unsigned short*)(m_layers[z_order].fb))[(x - layer_rect.m_left) + (y - layer_rect.m_top) * layer_rect.width()] = GL_RGB_32_to_16(rgb); + ((unsigned int*)(m_layers[z_order].fb))[(x - layer_rect.m_left) + (y - layer_rect.m_top) * layer_rect.width()] = rgb; } } if (z_order == m_top_zorder) { - return draw_pixel_on_fb(x, y, rgb); + return draw_pixel_low_level(x, y, rgb); } bool be_overlapped = false; for (unsigned int tmp_z_order = Z_ORDER_LEVEL_MAX - 1; tmp_z_order > z_order; tmp_z_order--) @@ -392,7 +466,7 @@ public: } if (!be_overlapped) { - draw_pixel_on_fb(x, y, rgb); + draw_pixel_low_level(x, y, rgb); } } virtual void fill_rect(int x0, int y0, int x1, int y1, unsigned int rgb, unsigned int z_order) @@ -403,7 +477,7 @@ public: y1 = (y1 > (m_height - 1)) ? (m_height - 1) : y1; if (z_order == m_max_zorder) { - return fill_rect_on_fb(x0, y0, x1, y1, rgb); + return fill_rect_low_level(x0, y0, x1, y1, rgb); } if (z_order == m_top_zorder) { @@ -416,18 +490,18 @@ public: { if (layer_rect.pt_in_rect(x, y)) { - if (m_color_bytes == 4) + if (m_color_bytes == 2) { - ((unsigned int*)m_layers[z_order].fb)[(y - layer_rect.m_top) * layer_rect.width() + (x - layer_rect.m_left)] = rgb; + ((unsigned short*)m_layers[z_order].fb)[(y - layer_rect.m_top) * layer_rect.width() + (x - layer_rect.m_left)] = rgb_16; } else { - ((unsigned short*)m_layers[z_order].fb)[(y - layer_rect.m_top) * layer_rect.width() + (x - layer_rect.m_left)] = rgb_16; + ((unsigned int*)m_layers[z_order].fb)[(y - layer_rect.m_top) * layer_rect.width() + (x - layer_rect.m_left)] = rgb; } } } } - return fill_rect_on_fb(x0, y0, x1, y1, rgb); + return fill_rect_low_level(x0, y0, x1, y1, rgb); } for (; y0 <= y1; y0++) { @@ -499,27 +573,16 @@ public: } int flush_screen(int left, int top, int right, int bottom) { - if (left < 0 || left >= m_width || right < 0 || right >= m_width || - top < 0 || top >= m_height || bottom < 0 || bottom >= m_height) - { - ASSERT(false); - } - if (!m_is_active || (0 == m_phy_fb) || (0 == m_fb)) + if (!m_is_active) { return -1; } - int display_width = m_display->get_width(); - int display_height = m_display->get_height(); - left = (left >= display_width) ? (display_width - 1) : left; - right = (right >= display_width) ? (display_width - 1) : right; - top = (top >= display_height) ? (display_height - 1) : top; - bottom = (bottom >= display_height) ? (display_height - 1) : bottom; - for (int y = top; y < bottom; y++) + if (left < 0 || left >= m_width || right < 0 || right >= m_width || + top < 0 || top >= m_height || bottom < 0 || bottom >= m_height) { - void* s_addr = (char*)m_fb + ((y * m_width + left) * m_color_bytes); - void* d_addr = (char*)m_phy_fb + ((y * display_width + left) * m_color_bytes); - memcpy(d_addr, s_addr, (right - left) * m_color_bytes); + ASSERT(false); } + m_display->flush_screen(left, top, right, bottom, m_fb, m_width); *m_phy_write_index = *m_phy_write_index + 1; return 0; } @@ -537,90 +600,62 @@ public: { for (int x = rect.m_left; x <= rect.m_right; x++) { - unsigned int rgb = (m_color_bytes == 4) ? ((unsigned int*)fb)[(x - layer_rect.m_left) + (y - layer_rect.m_top) * width] : GL_RGB_16_to_32(((unsigned short*)fb)[(x - layer_rect.m_left) + (y - layer_rect.m_top) * width]); - draw_pixel_on_fb(x, y, rgb); + unsigned int rgb = (m_color_bytes == 2) ? GL_RGB_16_to_32(((unsigned short*)fb)[(x - layer_rect.m_left) + (y - layer_rect.m_top) * width]) : ((unsigned int*)fb)[(x - layer_rect.m_left) + (y - layer_rect.m_top) * width]; + draw_pixel_low_level(x, y, rgb); } } return 0; } void set_active(bool flag) { m_is_active = flag; } protected: - virtual void fill_rect_on_fb(int x0, int y0, int x1, int y1, unsigned int rgb) - { - int display_width = m_display->get_width(); - int display_height = m_display->get_height(); - if (m_color_bytes == 4) + virtual void fill_rect_low_level(int x0, int y0, int x1, int y1, unsigned int rgb) + {//fill rect on framebuffer of surface + int x, y; + if (m_color_bytes == 2) { - int x; - unsigned int* fb, * phy_fb; - for (; y0 <= y1; y0++) + unsigned short* fb; + unsigned int rgb_16 = GL_RGB_32_to_16(rgb); + for (y = y0; y <= y1; y++) { - x = x0; - fb = m_fb ? &((unsigned int*)m_fb)[y0 * m_width + x] : 0; - phy_fb = &((unsigned int*)m_phy_fb)[y0 * display_width + x]; - *m_phy_write_index = *m_phy_write_index + 1; - for (; x <= x1; x++) + fb = m_fb ? &((unsigned short*)m_fb)[y * m_width + x0] : 0; + if (!fb) { break; } + for (x = x0; x <= x1; x++) { - if (fb) - { - *fb++ = rgb; - } - if (m_is_active && (x < display_width) && (y0 < display_height)) - { - *phy_fb++ = rgb; - } + *fb++ = rgb_16; } } } - else if (m_color_bytes == 2) + else { - int x; - unsigned short* fb, * phy_fb; - rgb = GL_RGB_32_to_16(rgb); - for (; y0 <= y1; y0++) + unsigned int* fb; + for (y = y0; y <= y1; y++) { - x = x0; - fb = m_fb ? &((unsigned short*)m_fb)[y0 * m_width + x] : 0; - phy_fb = &((unsigned short*)m_phy_fb)[y0 * display_width + x]; - *m_phy_write_index = *m_phy_write_index + 1; - for (; x <= x1; x++) + fb = m_fb ? &((unsigned int*)m_fb)[y * m_width + x0] : 0; + if (!fb) { break; } + for (x = x0; x <= x1; x++) { - if (fb) - { - *fb++ = rgb; - } - if (m_is_active && (x < display_width) && (y0 < display_height)) - { - *phy_fb++ = rgb; - } + *fb++ = rgb; } } } + if (!m_is_active) { return; } + m_display->fill_rect(x0, y0, x1, y1, rgb); + *m_phy_write_index = *m_phy_write_index + 1; } - virtual void draw_pixel_on_fb(int x, int y, unsigned int rgb) + virtual void draw_pixel_low_level(int x, int y, unsigned int rgb) { if (m_fb) - { - (m_color_bytes == 4) ? ((unsigned int*)m_fb)[y * m_width + x] = rgb : ((unsigned short*)m_fb)[y * m_width + x] = GL_RGB_32_to_16(rgb); - } - if (m_is_active && (x < m_display->get_width()) && (y < m_display->get_height())) - { - if (m_color_bytes == 4) - { - ((unsigned int*)m_phy_fb)[y * (m_display->get_width()) + x] = rgb; - } - else - { - ((unsigned short*)m_phy_fb)[y * (m_display->get_width()) + x] = GL_RGB_32_to_16(rgb); - } - *m_phy_write_index = *m_phy_write_index + 1; + {//draw pixel on framebuffer of surface + (m_color_bytes == 2) ? ((unsigned short*)m_fb)[y * m_width + x] = GL_RGB_32_to_16(rgb): ((unsigned int*)m_fb)[y * m_width + x] = rgb; } + if (!m_is_active) { return; } + m_display->draw_pixel(x, y, rgb); + *m_phy_write_index = *m_phy_write_index + 1; } void attach_display(c_display* display) { ASSERT(display); m_display = display; - m_phy_fb = display->m_phy_fb; m_phy_write_index = &display->m_phy_write_index; } void set_surface(Z_ORDER_LEVEL max_z_order, c_rect layer_rect) @@ -638,87 +673,22 @@ protected: } int m_width; //in pixels int m_height; //in pixels - int m_color_bytes; //16 bits, 32 bits only + int m_color_bytes; //16 bits, 32 bits for default void* m_fb; //frame buffer you could see c_layer m_layers[Z_ORDER_LEVEL_MAX];//all graphic layers bool m_is_active; //active flag Z_ORDER_LEVEL m_max_zorder; //the highest graphic layer the surface will have Z_ORDER_LEVEL m_top_zorder; //the current highest graphic layer the surface have - void* m_phy_fb; //physical framebufer int* m_phy_write_index; c_display* m_display; }; -class c_surface_no_fb : public c_surface {//No physical framebuffer, render with external graphic interface - friend class c_display; -public: - c_surface_no_fb(unsigned int width, unsigned int height, unsigned int color_bytes, struct EXTERNAL_GFX_OP* gfx_op, Z_ORDER_LEVEL max_zorder = Z_ORDER_LEVEL_0, c_rect overlpa_rect = c_rect()) : c_surface(width, height, color_bytes, max_zorder, overlpa_rect), m_gfx_op(gfx_op) {} -protected: - virtual void fill_rect_on_fb(int x0, int y0, int x1, int y1, unsigned int rgb) - { - if (!m_gfx_op) - { - return; - } - if (m_gfx_op->fill_rect) - { - return m_gfx_op->fill_rect(x0, y0, x1, y1, rgb); - } - if (m_gfx_op->draw_pixel && m_is_active) - { - for (int y = y0; y <= y1; y++) - { - for (int x = x0; x <= x1; x++) - { - m_gfx_op->draw_pixel(x, y, rgb); - } - } - } - if (!m_fb) { return; } - if (m_color_bytes == 4) - { - unsigned int* fb; - for (int y = y0; y <= y1; y++) - { - fb = &((unsigned int*)m_fb)[y0 * m_width + x0]; - for (int x = x0; x <= x1; x++) - { - *fb++ = rgb; - } - } - } - else if (m_color_bytes == 2) - { - unsigned short* fb; - rgb = GL_RGB_32_to_16(rgb); - for (int y = y0; y <= y1; y++) - { - fb = &((unsigned short*)m_fb)[y0 * m_width + x0]; - for (int x = x0; x <= x1; x++) - { - *fb++ = rgb; - } - } - } - } - virtual void draw_pixel_on_fb(int x, int y, unsigned int rgb) - { - if (m_gfx_op && m_gfx_op->draw_pixel && m_is_active) - { - m_gfx_op->draw_pixel(x, y, rgb); - } - if (!m_fb) { return; } - if (m_color_bytes == 4) - { - ((unsigned int*)m_fb)[y * m_width + x] = rgb; - } - else if (m_color_bytes == 2) - { - ((unsigned short*)m_fb)[y * m_width + x] = GL_RGB_32_to_16(rgb); - } - } - struct EXTERNAL_GFX_OP* m_gfx_op;//Rendering by external method -}; -inline c_display::c_display(void* phy_fb, int display_width, int display_height, int surface_width, int surface_height, unsigned int color_bytes, int surface_cnt, EXTERNAL_GFX_OP* gfx_op) : m_width(display_width), m_height(display_height), m_color_bytes(color_bytes), m_phy_fb(phy_fb), m_phy_read_index(0), m_phy_write_index(0), m_surface_cnt(surface_cnt), m_surface_index(0) +inline c_display::c_display(void* phy_fb, int display_width, int display_height, c_surface* surface, DISPLAY_DRIVER* driver) : m_phy_fb(phy_fb), m_width(display_width), m_height(display_height), m_driver(driver), m_phy_read_index(0), m_phy_write_index(0), m_surface_cnt(1), m_surface_index(0) +{ + m_color_bytes = surface->m_color_bytes; + surface->m_is_active = true; + (m_surface_group[0] = surface)->attach_display(this); +} +inline c_display::c_display(void* phy_fb, int display_width, int display_height, int surface_width, int surface_height, unsigned int color_bytes, int surface_cnt, DISPLAY_DRIVER* driver) : m_phy_fb(phy_fb), m_width(display_width), m_height(display_height), m_color_bytes(color_bytes), m_phy_read_index(0), m_phy_write_index(0), m_surface_cnt(surface_cnt), m_driver(driver), m_surface_index(0) { ASSERT(color_bytes == 2 || color_bytes == 4); ASSERT(m_surface_cnt <= SURFACE_CNT_MAX); @@ -726,16 +696,10 @@ inline c_display::c_display(void* phy_fb, int display_width, int display_height, for (int i = 0; i < m_surface_cnt; i++) { - m_surface_group[i] = (phy_fb) ? new c_surface(surface_width, surface_height, color_bytes) : new c_surface_no_fb(surface_width, surface_height, color_bytes, gfx_op); + m_surface_group[i] = new c_surface(surface_width, surface_height, color_bytes); m_surface_group[i]->attach_display(this); } } -inline c_display::c_display(void* phy_fb, int display_width, int display_height, c_surface* surface) : m_width(display_width), m_height(display_height), m_phy_fb(phy_fb), m_phy_read_index(0), m_phy_write_index(0), m_surface_cnt(1), m_surface_index(0) -{ - m_color_bytes = surface->m_color_bytes; - surface->m_is_active = true; - (m_surface_group[0] = surface)->attach_display(this); -} inline c_surface* c_display::alloc_surface(Z_ORDER_LEVEL max_zorder, c_rect layer_rect) { ASSERT(max_zorder < Z_ORDER_LEVEL_MAX && m_surface_index < m_surface_cnt); @@ -744,8 +708,8 @@ inline c_surface* c_display::alloc_surface(Z_ORDER_LEVEL max_zorder, c_rect laye } inline int c_display::swipe_surface(c_surface* s0, c_surface* s1, int x0, int x1, int y0, int y1, int offset) { - int surface_width = s0->get_width(); - int surface_height = s0->get_height(); + register int surface_width = s0->m_width; + register int surface_height = s0->m_height; if (offset < 0 || offset > surface_width || y0 < 0 || y0 >= surface_height || y1 < 0 || y1 >= surface_height || x0 < 0 || x0 >= surface_width || x1 < 0 || x1 >= surface_width) { @@ -767,46 +731,46 @@ inline int c_display::swipe_surface(c_surface* s0, c_surface* s1, int x0, int x1 for (int y = y0; y <= y1; y++) { //Left surface - char* addr_s = ((char*)(s0->m_fb) + (y * (s0->get_width()) + x0 + offset) * m_color_bytes); + char* addr_s = ((char*)(s0->m_fb) + (y * surface_width + x0 + offset) * m_color_bytes); char* addr_d = ((char*)(m_phy_fb)+(y * m_width + x0) * m_color_bytes); memcpy(addr_d, addr_s, (width - offset) * m_color_bytes); //Right surface - addr_s = ((char*)(s1->m_fb) + (y * (s1->get_width()) + x0) * m_color_bytes); + addr_s = ((char*)(s1->m_fb) + (y * surface_width + x0) * m_color_bytes); addr_d = ((char*)(m_phy_fb)+(y * m_width + x0 + (width - offset)) * m_color_bytes); memcpy(addr_d, addr_s, offset * m_color_bytes); } } - else if (m_color_bytes == 4) + else if (m_color_bytes == 2) { - void(*draw_pixel)(int x, int y, unsigned int rgb) = ((c_surface_no_fb*)s0)->m_gfx_op->draw_pixel; + void(*draw_pixel)(int x, int y, unsigned int rgb) = m_driver->draw_pixel; for (int y = y0; y <= y1; y++) { //Left surface for (int x = x0; x <= (x1 - offset); x++) { - draw_pixel(x, y, ((unsigned int*)s0->m_fb)[y * m_width + x + offset]); + draw_pixel(x, y, GL_RGB_16_to_32(((unsigned short*)s0->m_fb)[y * m_width + x + offset])); } //Right surface for (int x = x1 - offset; x <= x1; x++) { - draw_pixel(x, y, ((unsigned int*)s1->m_fb)[y * m_width + x + offset - x1 + x0]); + draw_pixel(x, y, GL_RGB_16_to_32(((unsigned short*)s1->m_fb)[y * m_width + x + offset - x1 + x0])); } } } - else if (m_color_bytes == 2) + else //m_color_bytes == 3/4... { - void(*draw_pixel)(int x, int y, unsigned int rgb) = ((c_surface_no_fb*)s0)->m_gfx_op->draw_pixel; + void(*draw_pixel)(int x, int y, unsigned int rgb) = m_driver->draw_pixel; for (int y = y0; y <= y1; y++) { //Left surface for (int x = x0; x <= (x1 - offset); x++) { - draw_pixel(x, y, GL_RGB_16_to_32(((unsigned short*)s0->m_fb)[y * m_width + x + offset])); + draw_pixel(x, y, ((unsigned int*)s0->m_fb)[y * m_width + x + offset]); } //Right surface for (int x = x1 - offset; x <= x1; x++) { - draw_pixel(x, y, GL_RGB_16_to_32(((unsigned short*)s1->m_fb)[y * m_width + x + offset - x1 + x0])); + draw_pixel(x, y, ((unsigned int*)s1->m_fb)[y * m_width + x + offset - x1 + x0]); } } } @@ -3407,22 +3371,12 @@ private: #ifdef GUILITE_ON c_bitmap_operator the_bitmap_op = c_bitmap_operator(); c_image_operator* c_image::image_operator = &the_bitmap_op; +const void* c_theme::s_font_map[FONT_MAX]; +const void* c_theme::s_image_map[IMAGE_MAX]; +unsigned int c_theme::s_color_map[COLOR_MAX]; +c_lattice_font_op the_lattice_font_op = c_lattice_font_op(); +c_font_operator* c_word::fontOperator = &the_lattice_font_op; #endif - -#ifdef GUILITE_ON - -const void* c_theme::s_font_map[FONT_MAX]; -const void* c_theme::s_image_map[IMAGE_MAX]; -unsigned int c_theme::s_color_map[COLOR_MAX]; - -#endif - -#ifdef GUILITE_ON - -c_lattice_font_op the_lattice_font_op = c_lattice_font_op(); -c_font_operator* c_word::fontOperator = &the_lattice_font_op; - -#endif #ifdef GUILITE_ON #if (defined __linux__) || (defined __APPLE__) #include @@ -4264,11 +4218,7 @@ int c_fifo::write(void* buf, int len) #endif #ifdef GUILITE_ON DIALOG_ARRAY c_dialog::ms_the_dialogs[SURFACE_CNT_MAX]; -#endif -#ifdef GUILITE_ON c_keyboard c_edit::s_keyboard; -#endif -#ifdef GUILITE_ON static c_keyboard_button s_key_0, s_key_1, s_key_2, s_key_3, s_key_4, s_key_5, s_key_6, s_key_7, s_key_8, s_key_9; static c_keyboard_button s_key_A, s_key_B, s_key_C, s_key_D, s_key_E, s_key_F, s_key_G, s_key_H, s_key_I, s_key_J; static c_keyboard_button s_key_K, s_key_L, s_key_M, s_key_N, s_key_O, s_key_P, s_key_Q, s_key_R, s_key_S, s_key_T; @@ -4306,12 +4256,12 @@ WND_TREE g_key_board_children[] = {&s_key_B, 'B', 0, ((KEY_WIDTH / 2) + POS_X(5)), POS_Y(2), KEY_WIDTH, KEY_HEIGHT}, {&s_key_N, 'N', 0, ((KEY_WIDTH / 2) + POS_X(6)), POS_Y(2), KEY_WIDTH, KEY_HEIGHT}, {&s_key_M, 'M', 0, ((KEY_WIDTH / 2) + POS_X(7)), POS_Y(2), KEY_WIDTH, KEY_HEIGHT}, - {&s_key_del, 0x7F, 0, ((KEY_WIDTH / 2) + POS_X(8)), POS_Y(2), DEL_WIDTH, KEY_HEIGHT}, + {&s_key_del,0x7F, 0, ((KEY_WIDTH / 2) + POS_X(8)), POS_Y(2), DEL_WIDTH, KEY_HEIGHT}, //Row 4 - {&s_key_esc, 0x1B, 0, POS_X(0), POS_Y(3), ESC_WIDTH, KEY_HEIGHT}, + {&s_key_esc, 0x1B, 0, POS_X(0), POS_Y(3), ESC_WIDTH, KEY_HEIGHT}, {&s_key_num_switch, 0x90, 0, POS_X(2), POS_Y(3), SWITCH_WIDTH, KEY_HEIGHT}, {&s_key_space, ' ', 0, ((KEY_WIDTH / 2) + POS_X(3)), POS_Y(3), SPACE_WIDTH, KEY_HEIGHT}, - {&s_key_dot, '.', 0, ((KEY_WIDTH / 2) + POS_X(6)), POS_Y(3), DOT_WIDTH, KEY_HEIGHT}, + {&s_key_dot, '.', 0, ((KEY_WIDTH / 2) + POS_X(6)), POS_Y(3), DOT_WIDTH, KEY_HEIGHT}, {&s_key_enter, '\n', 0, POS_X(8), POS_Y(3), ENTER_WIDTH, KEY_HEIGHT}, {0,0,0,0,0,0,0} }; @@ -4326,12 +4276,11 @@ WND_TREE g_number_board_children[] = {&s_key_7, '7', 0, POS_X(0), POS_Y(2), KEY_WIDTH, KEY_HEIGHT}, {&s_key_8, '8', 0, POS_X(1), POS_Y(2), KEY_WIDTH, KEY_HEIGHT}, {&s_key_9, '9', 0, POS_X(2), POS_Y(2), KEY_WIDTH, KEY_HEIGHT}, - - {&s_key_esc, 0x1B, 0, POS_X(0), POS_Y(3), KEY_WIDTH, KEY_HEIGHT}, + {&s_key_esc,0x1B, 0, POS_X(0), POS_Y(3), KEY_WIDTH, KEY_HEIGHT}, {&s_key_0, '0', 0, POS_X(1), POS_Y(3), KEY_WIDTH, KEY_HEIGHT}, - {&s_key_dot, '.', 0, POS_X(2), POS_Y(3), KEY_WIDTH, KEY_HEIGHT}, + {&s_key_dot,'.', 0, POS_X(2), POS_Y(3), KEY_WIDTH, KEY_HEIGHT}, {&s_key_del, 0x7F, 0, POS_X(3), POS_Y(0), KEY_WIDTH, KEY_HEIGHT * 2 + 2}, {&s_key_enter,'\n', 0, POS_X(3), POS_Y(2), KEY_WIDTH, KEY_HEIGHT * 2 + 2}, {0,0,0,0,0,0,0} }; -#endif +#endif \ No newline at end of file diff --git a/HelloStar/UIcode/UIcode.cpp b/HelloStar/UIcode/UIcode.cpp index ee5987fdba99ea13841a72dd83a48d7332c0bb75..6561e15c3d0c9408c9a1c956c39f9ee6d386be8c 100644 --- a/HelloStar/UIcode/UIcode.cpp +++ b/HelloStar/UIcode/UIcode.cpp @@ -66,21 +66,11 @@ public: //////////////////////// start UI //////////////////////// c_star stars[100]; -void create_ui(void* phy_fb, int screen_width, int screen_height, int color_bytes, struct EXTERNAL_GFX_OP* gfx_op) { - if (phy_fb) - { - static c_surface surface(UI_WIDTH, UI_HEIGHT, color_bytes, Z_ORDER_LEVEL_0); - static c_display display(phy_fb, screen_width, screen_height, &surface); - s_surface = &surface; - s_display = &display; - } - else - {//for MCU without framebuffer - static c_surface_no_fb surface_no_fb(UI_WIDTH, UI_HEIGHT, color_bytes, gfx_op, Z_ORDER_LEVEL_0); - static c_display display(phy_fb, screen_width, screen_height, &surface_no_fb); - s_surface = &surface_no_fb; - s_display = &display; - } +void create_ui(void* phy_fb, int screen_width, int screen_height, int color_bytes, struct DISPLAY_DRIVER* driver) { + static c_surface surface(UI_WIDTH, UI_HEIGHT, color_bytes, Z_ORDER_LEVEL_0); + static c_display display(phy_fb, screen_width, screen_height, &surface, driver); + s_surface = &surface; + s_display = &display; s_surface->fill_rect(0, 0, UI_WIDTH - 1, UI_HEIGHT - 1, 0, Z_ORDER_LEVEL_0); @@ -93,8 +83,8 @@ void create_ui(void* phy_fb, int screen_width, int screen_height, int color_byte } //////////////////////// interface for all platform //////////////////////// -extern "C" void startHelloStar(void* phy_fb, int width, int height, int color_bytes, struct EXTERNAL_GFX_OP* gfx_op) { - create_ui(phy_fb, width, height, color_bytes, gfx_op); +extern "C" void startHelloStar(void* phy_fb, int width, int height, int color_bytes, struct DISPLAY_DRIVER* driver) { + create_ui(phy_fb, width, height, color_bytes, driver); } void* getUiOfHelloStar(int* width, int* height, bool force_update) diff --git a/HelloTimer/BuildLinux/.sync_build.sh b/HelloTimer/BuildLinux/.sync_build.sh index 49cff5b473ac606967676ebefa6f0d333e301227..a57e9a8f85810937f38bca13d3a12cbdd7b44e98 100644 --- a/HelloTimer/BuildLinux/.sync_build.sh +++ b/HelloTimer/BuildLinux/.sync_build.sh @@ -1,5 +1,6 @@ if [ "$#" -ne 1 ]; then - echo "Invalid arguments" + echo "Do testing" + ./xWindow 240 320 | ./HelloTimer shared-fb exit -1 fi diff --git a/HelloTimer/BuildLinux/main.cpp b/HelloTimer/BuildLinux/main.cpp index 459db9833bc7fd68c714cc2fe8840e122ec9f209..7305cc0da882357d5ac2d44c9f5a8d7f1b23dbec 100644 --- a/HelloTimer/BuildLinux/main.cpp +++ b/HelloTimer/BuildLinux/main.cpp @@ -10,7 +10,7 @@ #include #include -extern "C" void startHelloTimer(void* phy_fb, int width, int height, int color_bytes, struct EXTERNAL_GFX_OP* gfx_op); +extern "C" void startHelloTimer(void* phy_fb, int width, int height, int color_bytes, struct DISPLAY_DRIVER* driver); extern void init_std_io(); static void* get_embeded_fb_in_display_app(int shared_id); diff --git a/HelloTimer/BuildMFC/HelloTimerDlg.cpp b/HelloTimer/BuildMFC/HelloTimerDlg.cpp index 17b6e8e1ea842bdb870419222f99e1455b131eca..09414fc5336ec9334683b18280d536eb7dc24ff9 100644 Binary files a/HelloTimer/BuildMFC/HelloTimerDlg.cpp and b/HelloTimer/BuildMFC/HelloTimerDlg.cpp differ diff --git a/HelloTimer/BuildMFC/HelloTimerDlg.h b/HelloTimer/BuildMFC/HelloTimerDlg.h index 97d4d71a5d9c4befede4f508fa764650cd08415f..f2cde1ba164d87fb8887f71a6128756a48fbba59 100644 Binary files a/HelloTimer/BuildMFC/HelloTimerDlg.h and b/HelloTimer/BuildMFC/HelloTimerDlg.h differ diff --git a/HelloTimer/BuildSTM32F103-Keil/USER/main.c b/HelloTimer/BuildSTM32F103-Keil/USER/main.c index cb43ed11de51fe57b8754e8d7fdc3f49c28b00eb..b6c0117731ae2e32e4df56992bdd0b5f983263ce 100644 --- a/HelloTimer/BuildSTM32F103-Keil/USER/main.c +++ b/HelloTimer/BuildSTM32F103-Keil/USER/main.c @@ -15,12 +15,12 @@ void gfx_draw_pixel(int x, int y, unsigned int rgb) //void gfx_fill_rect(int x0, int y0, int x1, int y1, unsigned int rgb){} //UI entry -struct EXTERNAL_GFX_OP +struct DISPLAY_DRIVER { void (*draw_pixel)(int x, int y, unsigned int rgb); void (*fill_rect)(int x0, int y0, int x1, int y1, unsigned int rgb); -} my_gfx_op; -extern void startHelloTimer(void* phy_fb, int width, int height, int color_bytes, struct EXTERNAL_GFX_OP* gfx_op); +} my_driver; +extern void startHelloTimer(void* phy_fb, int width, int height, int color_bytes, struct DISPLAY_DRIVER* driver); int main(void) { @@ -30,8 +30,8 @@ int main(void) LCD_Init(); //Link your LCD driver & start UI: - my_gfx_op.draw_pixel = gfx_draw_pixel; - my_gfx_op.fill_rect = NULL;//gfx_fill_rect; - startHelloTimer(NULL, 240, 320, 2, &my_gfx_op); + my_driver.draw_pixel = gfx_draw_pixel; + my_driver.fill_rect = NULL;//gfx_fill_rect; + startHelloTimer(NULL, 240, 320, 2, &my_driver); while(1); } diff --git a/HelloTimer/BuildWin32/HelloTimer.cpp b/HelloTimer/BuildWin32/HelloTimer.cpp index 090da41cec0805b00ec33d0f613278f2a110a162..d94213b6bfbdb5bf3a90ee5315c740ab60f6ab98 100644 --- a/HelloTimer/BuildWin32/HelloTimer.cpp +++ b/HelloTimer/BuildWin32/HelloTimer.cpp @@ -161,7 +161,7 @@ LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam) } //////////////////////// HelloTimer Interface //////////////////////// -extern "C" void startHelloTimer(void* phy_fb, int width, int height, int color_bytes, struct EXTERNAL_GFX_OP* gfx_op); +extern "C" void startHelloTimer(void* phy_fb, int width, int height, int color_bytes, struct DISPLAY_DRIVER* driver); DWORD WINAPI ThreadHelloTimer(LPVOID pParam) { diff --git a/HelloTimer/UIcode/GuiLite.h b/HelloTimer/UIcode/GuiLite.h index c4fc88a51476d2c8309c3e55e1270e13784fc510..80550e1632ad7bc82541a2edbb0f7f8f5937954f 100644 --- a/HelloTimer/UIcode/GuiLite.h +++ b/HelloTimer/UIcode/GuiLite.h @@ -1,107 +1,94 @@ #pragma once - -#define REAL_TIME_TASK_CYCLE_MS 50 -#define MAX(a,b) (((a)>(b))?(a):(b)) -#define MIN(a,b) (((a)<(b))?(a):(b)) - -#define GL_ARGB(a, r, g, b) ((((unsigned int)(a)) << 24) | (((unsigned int)(r)) << 16) | (((unsigned int)(g)) << 8) | ((unsigned int)(b))) -#define GL_ARGB_A(rgb) ((((unsigned int)(rgb)) >> 24) & 0xFF) - -#define GL_RGB(r, g, b) ((0xFF << 24) | (((unsigned int)(r)) << 16) | (((unsigned int)(g)) << 8) | ((unsigned int)(b))) -#define GL_RGB_R(rgb) ((((unsigned int)(rgb)) >> 16) & 0xFF) -#define GL_RGB_G(rgb) ((((unsigned int)(rgb)) >> 8) & 0xFF) -#define GL_RGB_B(rgb) (((unsigned int)(rgb)) & 0xFF) -#define GL_RGB_32_to_16(rgb) (((((unsigned int)(rgb)) & 0xFF) >> 3) | ((((unsigned int)(rgb)) & 0xFC00) >> 5) | ((((unsigned int)(rgb)) & 0xF80000) >> 8)) -#define GL_RGB_16_to_32(rgb) ((0xFF << 24) | ((((unsigned int)(rgb)) & 0x1F) << 3) | ((((unsigned int)(rgb)) & 0x7E0) << 5) | ((((unsigned int)(rgb)) & 0xF800) << 8)) - -#define ALIGN_HCENTER 0x00000000L -#define ALIGN_LEFT 0x01000000L -#define ALIGN_RIGHT 0x02000000L -#define ALIGN_HMASK 0x03000000L - -#define ALIGN_VCENTER 0x00000000L -#define ALIGN_TOP 0x00100000L -#define ALIGN_BOTTOM 0x00200000L -#define ALIGN_VMASK 0x00300000L - -typedef struct -{ - unsigned short year; - unsigned short month; - unsigned short date; - unsigned short day; - unsigned short hour; - unsigned short minute; - unsigned short second; -}T_TIME; - -void register_debug_function(void(*my_assert)(const char* file, int line), void(*my_log_out)(const char* log)); -void _assert(const char* file, int line); -#define ASSERT(condition) \ - do{ \ - if(!(condition))_assert(__FILE__, __LINE__);\ - }while(0) -void log_out(const char* log); - -long get_time_in_second(); -T_TIME second_to_day(long second); -T_TIME get_time(); - -void start_real_timer(void (*func)(void* arg)); -void register_timer(int milli_second, void func(void* param), void* param); - -unsigned int get_cur_thread_id(); -void create_thread(unsigned long* thread_id, void* attr, void *(*start_routine) (void *), void* arg); -void thread_sleep(unsigned int milli_seconds); -int build_bmp(const char *filename, unsigned int width, unsigned int height, unsigned char *data); - -#define FIFO_BUFFER_LEN 1024 -class c_fifo -{ -public: - c_fifo(); - int read(void* buf, int len); - int write(void* buf, int len); -private: - unsigned char m_buf[FIFO_BUFFER_LEN]; - int m_head; - int m_tail; - void* m_read_sem; - void* m_write_mutex; -}; - -class c_rect -{ -public: - c_rect(){ m_left = m_top = m_right = m_bottom = -1; } - c_rect(int left, int top, int width, int height) - { - set_rect(left, top, width, height); - } - void set_rect(int left, int top, int width, int height) - { - ASSERT(width > 0 && height > 0); - m_left = left; - m_top = top; - m_right = left + width - 1; - m_bottom = top + height -1; - } - bool pt_in_rect(int x, int y) const - { - return x >= m_left && x <= m_right && y >= m_top && y <= m_bottom; - } - int operator==(const c_rect& rect) const - { - return (m_left == rect.m_left) && (m_top == rect.m_top) && (m_right == rect.m_right) && (m_bottom == rect.m_bottom); - } - int width() const { return m_right - m_left + 1; } - int height() const { return m_bottom - m_top + 1 ; } - - int m_left; - int m_top; - int m_right; - int m_bottom; -}; +#define REAL_TIME_TASK_CYCLE_MS 50 +#define MAX(a,b) (((a)>(b))?(a):(b)) +#define MIN(a,b) (((a)<(b))?(a):(b)) +#define GL_ARGB(a, r, g, b) ((((unsigned int)(a)) << 24) | (((unsigned int)(r)) << 16) | (((unsigned int)(g)) << 8) | ((unsigned int)(b))) +#define GL_ARGB_A(rgb) ((((unsigned int)(rgb)) >> 24) & 0xFF) +#define GL_RGB(r, g, b) ((0xFF << 24) | (((unsigned int)(r)) << 16) | (((unsigned int)(g)) << 8) | ((unsigned int)(b))) +#define GL_RGB_R(rgb) ((((unsigned int)(rgb)) >> 16) & 0xFF) +#define GL_RGB_G(rgb) ((((unsigned int)(rgb)) >> 8) & 0xFF) +#define GL_RGB_B(rgb) (((unsigned int)(rgb)) & 0xFF) +#define GL_RGB_32_to_16(rgb) (((((unsigned int)(rgb)) & 0xFF) >> 3) | ((((unsigned int)(rgb)) & 0xFC00) >> 5) | ((((unsigned int)(rgb)) & 0xF80000) >> 8)) +#define GL_RGB_16_to_32(rgb) ((0xFF << 24) | ((((unsigned int)(rgb)) & 0x1F) << 3) | ((((unsigned int)(rgb)) & 0x7E0) << 5) | ((((unsigned int)(rgb)) & 0xF800) << 8)) +#define ALIGN_HCENTER 0x00000000L +#define ALIGN_LEFT 0x01000000L +#define ALIGN_RIGHT 0x02000000L +#define ALIGN_HMASK 0x03000000L +#define ALIGN_VCENTER 0x00000000L +#define ALIGN_TOP 0x00100000L +#define ALIGN_BOTTOM 0x00200000L +#define ALIGN_VMASK 0x00300000L +typedef struct +{ + unsigned short year; + unsigned short month; + unsigned short date; + unsigned short day; + unsigned short hour; + unsigned short minute; + unsigned short second; +}T_TIME; +void register_debug_function(void(*my_assert)(const char* file, int line), void(*my_log_out)(const char* log)); +void _assert(const char* file, int line); +#define ASSERT(condition) \ + do{ \ + if(!(condition))_assert(__FILE__, __LINE__);\ + }while(0) +void log_out(const char* log); +long get_time_in_second(); +T_TIME second_to_day(long second); +T_TIME get_time(); +void start_real_timer(void (*func)(void* arg)); +void register_timer(int milli_second, void func(void* param), void* param); +unsigned int get_cur_thread_id(); +void create_thread(unsigned long* thread_id, void* attr, void *(*start_routine) (void *), void* arg); +void thread_sleep(unsigned int milli_seconds); +int build_bmp(const char *filename, unsigned int width, unsigned int height, unsigned char *data); +#define FIFO_BUFFER_LEN 1024 +class c_fifo +{ +public: + c_fifo(); + int read(void* buf, int len); + int write(void* buf, int len); +private: + unsigned char m_buf[FIFO_BUFFER_LEN]; + int m_head; + int m_tail; + void* m_read_sem; + void* m_write_mutex; +}; +class c_rect +{ +public: + c_rect(){ m_left = m_top = m_right = m_bottom = -1; } + c_rect(int left, int top, int width, int height) + { + set_rect(left, top, width, height); + } + void set_rect(int left, int top, int width, int height) + { + ASSERT(width > 0 && height > 0); + m_left = left; + m_top = top; + m_right = left + width - 1; + m_bottom = top + height -1; + } + bool pt_in_rect(int x, int y) const + { + return x >= m_left && x <= m_right && y >= m_top && y <= m_bottom; + } + int operator==(const c_rect& rect) const + { + return (m_left == rect.m_left) && (m_top == rect.m_top) && (m_right == rect.m_right) && (m_bottom == rect.m_bottom); + } + int width() const { return m_right - m_left + 1; } + int height() const { return m_bottom - m_top + 1 ; } + int m_left; + int m_top; + int m_right; + int m_bottom; +}; //BITMAP typedef struct struct_bitmap_info { @@ -238,7 +225,7 @@ typedef enum Z_ORDER_LEVEL_2,//highest graphic level Z_ORDER_LEVEL_MAX }Z_ORDER_LEVEL; -struct EXTERNAL_GFX_OP +struct DISPLAY_DRIVER { void(*draw_pixel)(int x, int y, unsigned int rgb); void(*fill_rect)(int x0, int y0, int x1, int y1, unsigned int rgb); @@ -247,18 +234,19 @@ class c_surface; class c_display { friend class c_surface; public: - inline c_display(void* phy_fb, int display_width, int display_height, int surface_width, int surface_height, unsigned int color_bytes, int surface_cnt, EXTERNAL_GFX_OP* gfx_op = 0);//multiple surface or surface_no_fb - inline c_display(void* phy_fb, int display_width, int display_height, c_surface* surface);//single custom surface - inline c_surface* alloc_surface(Z_ORDER_LEVEL max_zorder, c_rect layer_rect = c_rect());//for multiple surfaces + inline c_display(void* phy_fb, int display_width, int display_height, c_surface* surface, DISPLAY_DRIVER* driver = 0);//single custom surface + inline c_display(void* phy_fb, int display_width, int display_height, int surface_width, int surface_height, unsigned int color_bytes, int surface_cnt, DISPLAY_DRIVER* driver = 0);//multiple surface + inline c_surface* alloc_surface(Z_ORDER_LEVEL max_zorder, c_rect layer_rect = c_rect());//for slide group inline int swipe_surface(c_surface* s0, c_surface* s1, int x0, int x1, int y0, int y1, int offset); int get_width() { return m_width; } int get_height() { return m_height; } + void* get_phy_fb() { return m_phy_fb; } void* get_updated_fb(int* width, int* height, bool force_update = false) { if (width && height) { - *width = get_width(); - *height = get_height(); + *width = m_width; + *height = m_height; } if (force_update) { @@ -277,35 +265,123 @@ public: { return -1; } - int width = get_width(); - int height = get_height(); //16 bits framebuffer if (m_color_bytes == 2) { - return build_bmp(file_name, width, height, (unsigned char*)m_phy_fb); + return build_bmp(file_name, m_width, m_height, (unsigned char*)m_phy_fb); } //32 bits framebuffer - unsigned short* p_bmp565_data = new unsigned short[width * height]; + unsigned short* p_bmp565_data = new unsigned short[m_width * m_height]; unsigned int* p_raw_data = (unsigned int*)m_phy_fb; - for (int i = 0; i < width * height; i++) + for (int i = 0; i < m_width * m_height; i++) { unsigned int rgb = *p_raw_data++; p_bmp565_data[i] = GL_RGB_32_to_16(rgb); } - int ret = build_bmp(file_name, width, height, (unsigned char*)p_bmp565_data); + int ret = build_bmp(file_name, m_width, m_height, (unsigned char*)p_bmp565_data); delete[]p_bmp565_data; return ret; } -private: - int m_width; //in pixels - int m_height; //in pixels - int m_color_bytes; //16 bits, 32 bits only - void* m_phy_fb; //physical framebuffer +protected: + virtual void draw_pixel(int x, int y, unsigned int rgb) + { + if ((x >= m_width) || (y >= m_height)) { return; } + if (m_driver && m_driver->draw_pixel) + { + return m_driver->draw_pixel(x, y, rgb); + } + if (m_color_bytes == 2) + { + ((unsigned short*)m_phy_fb)[y * m_width + x] = GL_RGB_32_to_16(rgb); + } + else + { + ((unsigned int*)m_phy_fb)[y * m_width + x] = rgb; + } + } + virtual void fill_rect(int x0, int y0, int x1, int y1, unsigned int rgb) + { + if (m_driver && m_driver->fill_rect) + { + return m_driver->fill_rect(x0, y0, x1, y1, rgb); + } + if (m_driver && m_driver->draw_pixel) + { + for (int y = y0; y <= y1; y++) + { + for (int x = x0; x <= x1; x++) + { + m_driver->draw_pixel(x, y, rgb); + } + } + return; + } + register int _width = m_width; + register int _height = m_height; + int x, y; + if (m_color_bytes == 2) + { + unsigned short* phy_fb; + unsigned int rgb_16 = GL_RGB_32_to_16(rgb); + for (y = y0; y <= y1; y++) + { + phy_fb = &((unsigned short*)m_phy_fb)[y * _width + x0]; + for (x = x0; x <= x1; x++) + { + if ((x < _width) && (y < _height)) + { + *phy_fb++ = rgb_16; + } + } + } + } + else + { + unsigned int* phy_fb; + for (y = y0; y <= y1; y++) + { + phy_fb = &((unsigned int*)m_phy_fb)[y * _width + x0]; + for (x = x0; x <= x1; x++) + { + if ((x < _width) && (y < _height)) + { + *phy_fb++ = rgb; + } + } + } + } + } + virtual int flush_screen(int left, int top, int right, int bottom, void* fb, int fb_width) + { + if ((0 == m_phy_fb) || (0 == fb)) + { + return -1; + } + register int _width = m_width; + register int _height = m_height; + left = (left >= _width) ? (_width - 1) : left; + right = (right >= _width) ? (_width - 1) : right; + top = (top >= _height) ? (_height - 1) : top; + bottom = (bottom >= _height) ? (_height - 1) : bottom; + for (int y = top; y < bottom; y++) + { + void* s_addr = (char*)fb + ((y * fb_width + left) * m_color_bytes); + void* d_addr = (char*)m_phy_fb + ((y * _width + left) * m_color_bytes); + memcpy(d_addr, s_addr, (right - left) * m_color_bytes); + } + return 0; + } + int m_width; //in pixels + int m_height; //in pixels + int m_color_bytes; //16/32 bits for default + void* m_phy_fb; //physical framebuffer for default + struct DISPLAY_DRIVER* m_driver; //Rendering by external method without default physical framebuffer int m_phy_read_index; int m_phy_write_index; c_surface* m_surface_group[SURFACE_CNT_MAX]; int m_surface_cnt; //surface count int m_surface_index; + }; class c_layer { @@ -317,12 +393,10 @@ public: class c_surface { friend class c_display; friend class c_bitmap_operator; public: - c_surface(unsigned int width, unsigned int height, unsigned int color_bytes, Z_ORDER_LEVEL max_zorder = Z_ORDER_LEVEL_0, c_rect overlpa_rect = c_rect()) : m_width(width), m_height(height), m_color_bytes(color_bytes), m_fb(0), m_is_active(false), m_top_zorder(Z_ORDER_LEVEL_0), m_phy_fb(0), m_phy_write_index(0), m_display(0) + c_surface(unsigned int width, unsigned int height, unsigned int color_bytes, Z_ORDER_LEVEL max_zorder = Z_ORDER_LEVEL_0, c_rect overlpa_rect = c_rect()) : m_width(width), m_height(height), m_color_bytes(color_bytes), m_fb(0), m_is_active(false), m_top_zorder(Z_ORDER_LEVEL_0), m_phy_write_index(0), m_display(0) { (overlpa_rect == c_rect()) ? set_surface(max_zorder, c_rect(0, 0, width - 1, height - 1)) : set_surface(max_zorder, overlpa_rect); } - int get_width() { return m_width; } - int get_height() { return m_height; } unsigned int get_pixel(int x, int y, unsigned int z_order) { if (x >= m_width || y >= m_height || x < 0 || y < 0 || z_order >= Z_ORDER_LEVEL_MAX) @@ -332,15 +406,15 @@ public: } if (m_layers[z_order].fb) { - return (m_color_bytes == 4) ? ((unsigned int*)(m_layers[z_order].fb))[y * m_width + x] : GL_RGB_16_to_32(((unsigned short*)(m_layers[z_order].fb))[y * m_width + x]); + return (m_color_bytes == 2) ? GL_RGB_16_to_32(((unsigned short*)(m_layers[z_order].fb))[y * m_width + x]) : ((unsigned int*)(m_layers[z_order].fb))[y * m_width + x]; } else if (m_fb) { - return (m_color_bytes == 4) ? ((unsigned int*)m_fb)[y * m_width + x] : GL_RGB_16_to_32(((unsigned short*)m_fb)[y * m_width + x]); + return (m_color_bytes == 2) ? GL_RGB_16_to_32(((unsigned short*)m_fb)[y * m_width + x]) : ((unsigned int*)m_fb)[y * m_width + x]; } - else if (m_phy_fb) + else if (m_display->m_phy_fb) { - return (m_color_bytes == 4) ? ((unsigned int*)m_phy_fb)[y * m_width + x] : GL_RGB_16_to_32(((unsigned short*)m_phy_fb)[y * m_width + x]); + return (m_color_bytes == 2) ? GL_RGB_16_to_32(((unsigned short*)m_display->m_phy_fb)[y * m_width + x]) : ((unsigned int*)m_display->m_phy_fb)[y * m_width + x]; } return 0; } @@ -357,7 +431,7 @@ public: } if (z_order == m_max_zorder) { - return draw_pixel_on_fb(x, y, rgb); + return draw_pixel_low_level(x, y, rgb); } if (z_order > (unsigned int)m_top_zorder) @@ -367,19 +441,19 @@ public: if (m_layers[z_order].rect.pt_in_rect(x, y)) { c_rect layer_rect = m_layers[z_order].rect; - if (m_color_bytes == 4) + if (m_color_bytes == 2) { - ((unsigned int*)(m_layers[z_order].fb))[(x - layer_rect.m_left) + (y - layer_rect.m_top) * layer_rect.width()] = rgb; + ((unsigned short*)(m_layers[z_order].fb))[(x - layer_rect.m_left) + (y - layer_rect.m_top) * layer_rect.width()] = GL_RGB_32_to_16(rgb); } else { - ((unsigned short*)(m_layers[z_order].fb))[(x - layer_rect.m_left) + (y - layer_rect.m_top) * layer_rect.width()] = GL_RGB_32_to_16(rgb); + ((unsigned int*)(m_layers[z_order].fb))[(x - layer_rect.m_left) + (y - layer_rect.m_top) * layer_rect.width()] = rgb; } } if (z_order == m_top_zorder) { - return draw_pixel_on_fb(x, y, rgb); + return draw_pixel_low_level(x, y, rgb); } bool be_overlapped = false; for (unsigned int tmp_z_order = Z_ORDER_LEVEL_MAX - 1; tmp_z_order > z_order; tmp_z_order--) @@ -392,7 +466,7 @@ public: } if (!be_overlapped) { - draw_pixel_on_fb(x, y, rgb); + draw_pixel_low_level(x, y, rgb); } } virtual void fill_rect(int x0, int y0, int x1, int y1, unsigned int rgb, unsigned int z_order) @@ -403,7 +477,7 @@ public: y1 = (y1 > (m_height - 1)) ? (m_height - 1) : y1; if (z_order == m_max_zorder) { - return fill_rect_on_fb(x0, y0, x1, y1, rgb); + return fill_rect_low_level(x0, y0, x1, y1, rgb); } if (z_order == m_top_zorder) { @@ -416,18 +490,18 @@ public: { if (layer_rect.pt_in_rect(x, y)) { - if (m_color_bytes == 4) + if (m_color_bytes == 2) { - ((unsigned int*)m_layers[z_order].fb)[(y - layer_rect.m_top) * layer_rect.width() + (x - layer_rect.m_left)] = rgb; + ((unsigned short*)m_layers[z_order].fb)[(y - layer_rect.m_top) * layer_rect.width() + (x - layer_rect.m_left)] = rgb_16; } else { - ((unsigned short*)m_layers[z_order].fb)[(y - layer_rect.m_top) * layer_rect.width() + (x - layer_rect.m_left)] = rgb_16; + ((unsigned int*)m_layers[z_order].fb)[(y - layer_rect.m_top) * layer_rect.width() + (x - layer_rect.m_left)] = rgb; } } } } - return fill_rect_on_fb(x0, y0, x1, y1, rgb); + return fill_rect_low_level(x0, y0, x1, y1, rgb); } for (; y0 <= y1; y0++) { @@ -499,27 +573,16 @@ public: } int flush_screen(int left, int top, int right, int bottom) { - if (left < 0 || left >= m_width || right < 0 || right >= m_width || - top < 0 || top >= m_height || bottom < 0 || bottom >= m_height) - { - ASSERT(false); - } - if (!m_is_active || (0 == m_phy_fb) || (0 == m_fb)) + if (!m_is_active) { return -1; } - int display_width = m_display->get_width(); - int display_height = m_display->get_height(); - left = (left >= display_width) ? (display_width - 1) : left; - right = (right >= display_width) ? (display_width - 1) : right; - top = (top >= display_height) ? (display_height - 1) : top; - bottom = (bottom >= display_height) ? (display_height - 1) : bottom; - for (int y = top; y < bottom; y++) + if (left < 0 || left >= m_width || right < 0 || right >= m_width || + top < 0 || top >= m_height || bottom < 0 || bottom >= m_height) { - void* s_addr = (char*)m_fb + ((y * m_width + left) * m_color_bytes); - void* d_addr = (char*)m_phy_fb + ((y * display_width + left) * m_color_bytes); - memcpy(d_addr, s_addr, (right - left) * m_color_bytes); + ASSERT(false); } + m_display->flush_screen(left, top, right, bottom, m_fb, m_width); *m_phy_write_index = *m_phy_write_index + 1; return 0; } @@ -537,90 +600,62 @@ public: { for (int x = rect.m_left; x <= rect.m_right; x++) { - unsigned int rgb = (m_color_bytes == 4) ? ((unsigned int*)fb)[(x - layer_rect.m_left) + (y - layer_rect.m_top) * width] : GL_RGB_16_to_32(((unsigned short*)fb)[(x - layer_rect.m_left) + (y - layer_rect.m_top) * width]); - draw_pixel_on_fb(x, y, rgb); + unsigned int rgb = (m_color_bytes == 2) ? GL_RGB_16_to_32(((unsigned short*)fb)[(x - layer_rect.m_left) + (y - layer_rect.m_top) * width]) : ((unsigned int*)fb)[(x - layer_rect.m_left) + (y - layer_rect.m_top) * width]; + draw_pixel_low_level(x, y, rgb); } } return 0; } void set_active(bool flag) { m_is_active = flag; } protected: - virtual void fill_rect_on_fb(int x0, int y0, int x1, int y1, unsigned int rgb) - { - int display_width = m_display->get_width(); - int display_height = m_display->get_height(); - if (m_color_bytes == 4) + virtual void fill_rect_low_level(int x0, int y0, int x1, int y1, unsigned int rgb) + {//fill rect on framebuffer of surface + int x, y; + if (m_color_bytes == 2) { - int x; - unsigned int* fb, * phy_fb; - for (; y0 <= y1; y0++) + unsigned short* fb; + unsigned int rgb_16 = GL_RGB_32_to_16(rgb); + for (y = y0; y <= y1; y++) { - x = x0; - fb = m_fb ? &((unsigned int*)m_fb)[y0 * m_width + x] : 0; - phy_fb = &((unsigned int*)m_phy_fb)[y0 * display_width + x]; - *m_phy_write_index = *m_phy_write_index + 1; - for (; x <= x1; x++) + fb = m_fb ? &((unsigned short*)m_fb)[y * m_width + x0] : 0; + if (!fb) { break; } + for (x = x0; x <= x1; x++) { - if (fb) - { - *fb++ = rgb; - } - if (m_is_active && (x < display_width) && (y0 < display_height)) - { - *phy_fb++ = rgb; - } + *fb++ = rgb_16; } } } - else if (m_color_bytes == 2) + else { - int x; - unsigned short* fb, * phy_fb; - rgb = GL_RGB_32_to_16(rgb); - for (; y0 <= y1; y0++) + unsigned int* fb; + for (y = y0; y <= y1; y++) { - x = x0; - fb = m_fb ? &((unsigned short*)m_fb)[y0 * m_width + x] : 0; - phy_fb = &((unsigned short*)m_phy_fb)[y0 * display_width + x]; - *m_phy_write_index = *m_phy_write_index + 1; - for (; x <= x1; x++) + fb = m_fb ? &((unsigned int*)m_fb)[y * m_width + x0] : 0; + if (!fb) { break; } + for (x = x0; x <= x1; x++) { - if (fb) - { - *fb++ = rgb; - } - if (m_is_active && (x < display_width) && (y0 < display_height)) - { - *phy_fb++ = rgb; - } + *fb++ = rgb; } } } + if (!m_is_active) { return; } + m_display->fill_rect(x0, y0, x1, y1, rgb); + *m_phy_write_index = *m_phy_write_index + 1; } - virtual void draw_pixel_on_fb(int x, int y, unsigned int rgb) + virtual void draw_pixel_low_level(int x, int y, unsigned int rgb) { if (m_fb) - { - (m_color_bytes == 4) ? ((unsigned int*)m_fb)[y * m_width + x] = rgb : ((unsigned short*)m_fb)[y * m_width + x] = GL_RGB_32_to_16(rgb); - } - if (m_is_active && (x < m_display->get_width()) && (y < m_display->get_height())) - { - if (m_color_bytes == 4) - { - ((unsigned int*)m_phy_fb)[y * (m_display->get_width()) + x] = rgb; - } - else - { - ((unsigned short*)m_phy_fb)[y * (m_display->get_width()) + x] = GL_RGB_32_to_16(rgb); - } - *m_phy_write_index = *m_phy_write_index + 1; + {//draw pixel on framebuffer of surface + (m_color_bytes == 2) ? ((unsigned short*)m_fb)[y * m_width + x] = GL_RGB_32_to_16(rgb): ((unsigned int*)m_fb)[y * m_width + x] = rgb; } + if (!m_is_active) { return; } + m_display->draw_pixel(x, y, rgb); + *m_phy_write_index = *m_phy_write_index + 1; } void attach_display(c_display* display) { ASSERT(display); m_display = display; - m_phy_fb = display->m_phy_fb; m_phy_write_index = &display->m_phy_write_index; } void set_surface(Z_ORDER_LEVEL max_z_order, c_rect layer_rect) @@ -638,87 +673,22 @@ protected: } int m_width; //in pixels int m_height; //in pixels - int m_color_bytes; //16 bits, 32 bits only + int m_color_bytes; //16 bits, 32 bits for default void* m_fb; //frame buffer you could see c_layer m_layers[Z_ORDER_LEVEL_MAX];//all graphic layers bool m_is_active; //active flag Z_ORDER_LEVEL m_max_zorder; //the highest graphic layer the surface will have Z_ORDER_LEVEL m_top_zorder; //the current highest graphic layer the surface have - void* m_phy_fb; //physical framebufer int* m_phy_write_index; c_display* m_display; }; -class c_surface_no_fb : public c_surface {//No physical framebuffer, render with external graphic interface - friend class c_display; -public: - c_surface_no_fb(unsigned int width, unsigned int height, unsigned int color_bytes, struct EXTERNAL_GFX_OP* gfx_op, Z_ORDER_LEVEL max_zorder = Z_ORDER_LEVEL_0, c_rect overlpa_rect = c_rect()) : c_surface(width, height, color_bytes, max_zorder, overlpa_rect), m_gfx_op(gfx_op) {} -protected: - virtual void fill_rect_on_fb(int x0, int y0, int x1, int y1, unsigned int rgb) - { - if (!m_gfx_op) - { - return; - } - if (m_gfx_op->fill_rect) - { - return m_gfx_op->fill_rect(x0, y0, x1, y1, rgb); - } - if (m_gfx_op->draw_pixel && m_is_active) - { - for (int y = y0; y <= y1; y++) - { - for (int x = x0; x <= x1; x++) - { - m_gfx_op->draw_pixel(x, y, rgb); - } - } - } - if (!m_fb) { return; } - if (m_color_bytes == 4) - { - unsigned int* fb; - for (int y = y0; y <= y1; y++) - { - fb = &((unsigned int*)m_fb)[y0 * m_width + x0]; - for (int x = x0; x <= x1; x++) - { - *fb++ = rgb; - } - } - } - else if (m_color_bytes == 2) - { - unsigned short* fb; - rgb = GL_RGB_32_to_16(rgb); - for (int y = y0; y <= y1; y++) - { - fb = &((unsigned short*)m_fb)[y0 * m_width + x0]; - for (int x = x0; x <= x1; x++) - { - *fb++ = rgb; - } - } - } - } - virtual void draw_pixel_on_fb(int x, int y, unsigned int rgb) - { - if (m_gfx_op && m_gfx_op->draw_pixel && m_is_active) - { - m_gfx_op->draw_pixel(x, y, rgb); - } - if (!m_fb) { return; } - if (m_color_bytes == 4) - { - ((unsigned int*)m_fb)[y * m_width + x] = rgb; - } - else if (m_color_bytes == 2) - { - ((unsigned short*)m_fb)[y * m_width + x] = GL_RGB_32_to_16(rgb); - } - } - struct EXTERNAL_GFX_OP* m_gfx_op;//Rendering by external method -}; -inline c_display::c_display(void* phy_fb, int display_width, int display_height, int surface_width, int surface_height, unsigned int color_bytes, int surface_cnt, EXTERNAL_GFX_OP* gfx_op) : m_width(display_width), m_height(display_height), m_color_bytes(color_bytes), m_phy_fb(phy_fb), m_phy_read_index(0), m_phy_write_index(0), m_surface_cnt(surface_cnt), m_surface_index(0) +inline c_display::c_display(void* phy_fb, int display_width, int display_height, c_surface* surface, DISPLAY_DRIVER* driver) : m_phy_fb(phy_fb), m_width(display_width), m_height(display_height), m_driver(driver), m_phy_read_index(0), m_phy_write_index(0), m_surface_cnt(1), m_surface_index(0) +{ + m_color_bytes = surface->m_color_bytes; + surface->m_is_active = true; + (m_surface_group[0] = surface)->attach_display(this); +} +inline c_display::c_display(void* phy_fb, int display_width, int display_height, int surface_width, int surface_height, unsigned int color_bytes, int surface_cnt, DISPLAY_DRIVER* driver) : m_phy_fb(phy_fb), m_width(display_width), m_height(display_height), m_color_bytes(color_bytes), m_phy_read_index(0), m_phy_write_index(0), m_surface_cnt(surface_cnt), m_driver(driver), m_surface_index(0) { ASSERT(color_bytes == 2 || color_bytes == 4); ASSERT(m_surface_cnt <= SURFACE_CNT_MAX); @@ -726,16 +696,10 @@ inline c_display::c_display(void* phy_fb, int display_width, int display_height, for (int i = 0; i < m_surface_cnt; i++) { - m_surface_group[i] = (phy_fb) ? new c_surface(surface_width, surface_height, color_bytes) : new c_surface_no_fb(surface_width, surface_height, color_bytes, gfx_op); + m_surface_group[i] = new c_surface(surface_width, surface_height, color_bytes); m_surface_group[i]->attach_display(this); } } -inline c_display::c_display(void* phy_fb, int display_width, int display_height, c_surface* surface) : m_width(display_width), m_height(display_height), m_phy_fb(phy_fb), m_phy_read_index(0), m_phy_write_index(0), m_surface_cnt(1), m_surface_index(0) -{ - m_color_bytes = surface->m_color_bytes; - surface->m_is_active = true; - (m_surface_group[0] = surface)->attach_display(this); -} inline c_surface* c_display::alloc_surface(Z_ORDER_LEVEL max_zorder, c_rect layer_rect) { ASSERT(max_zorder < Z_ORDER_LEVEL_MAX && m_surface_index < m_surface_cnt); @@ -744,8 +708,8 @@ inline c_surface* c_display::alloc_surface(Z_ORDER_LEVEL max_zorder, c_rect laye } inline int c_display::swipe_surface(c_surface* s0, c_surface* s1, int x0, int x1, int y0, int y1, int offset) { - int surface_width = s0->get_width(); - int surface_height = s0->get_height(); + register int surface_width = s0->m_width; + register int surface_height = s0->m_height; if (offset < 0 || offset > surface_width || y0 < 0 || y0 >= surface_height || y1 < 0 || y1 >= surface_height || x0 < 0 || x0 >= surface_width || x1 < 0 || x1 >= surface_width) { @@ -767,46 +731,46 @@ inline int c_display::swipe_surface(c_surface* s0, c_surface* s1, int x0, int x1 for (int y = y0; y <= y1; y++) { //Left surface - char* addr_s = ((char*)(s0->m_fb) + (y * (s0->get_width()) + x0 + offset) * m_color_bytes); + char* addr_s = ((char*)(s0->m_fb) + (y * surface_width + x0 + offset) * m_color_bytes); char* addr_d = ((char*)(m_phy_fb)+(y * m_width + x0) * m_color_bytes); memcpy(addr_d, addr_s, (width - offset) * m_color_bytes); //Right surface - addr_s = ((char*)(s1->m_fb) + (y * (s1->get_width()) + x0) * m_color_bytes); + addr_s = ((char*)(s1->m_fb) + (y * surface_width + x0) * m_color_bytes); addr_d = ((char*)(m_phy_fb)+(y * m_width + x0 + (width - offset)) * m_color_bytes); memcpy(addr_d, addr_s, offset * m_color_bytes); } } - else if (m_color_bytes == 4) + else if (m_color_bytes == 2) { - void(*draw_pixel)(int x, int y, unsigned int rgb) = ((c_surface_no_fb*)s0)->m_gfx_op->draw_pixel; + void(*draw_pixel)(int x, int y, unsigned int rgb) = m_driver->draw_pixel; for (int y = y0; y <= y1; y++) { //Left surface for (int x = x0; x <= (x1 - offset); x++) { - draw_pixel(x, y, ((unsigned int*)s0->m_fb)[y * m_width + x + offset]); + draw_pixel(x, y, GL_RGB_16_to_32(((unsigned short*)s0->m_fb)[y * m_width + x + offset])); } //Right surface for (int x = x1 - offset; x <= x1; x++) { - draw_pixel(x, y, ((unsigned int*)s1->m_fb)[y * m_width + x + offset - x1 + x0]); + draw_pixel(x, y, GL_RGB_16_to_32(((unsigned short*)s1->m_fb)[y * m_width + x + offset - x1 + x0])); } } } - else if (m_color_bytes == 2) + else //m_color_bytes == 3/4... { - void(*draw_pixel)(int x, int y, unsigned int rgb) = ((c_surface_no_fb*)s0)->m_gfx_op->draw_pixel; + void(*draw_pixel)(int x, int y, unsigned int rgb) = m_driver->draw_pixel; for (int y = y0; y <= y1; y++) { //Left surface for (int x = x0; x <= (x1 - offset); x++) { - draw_pixel(x, y, GL_RGB_16_to_32(((unsigned short*)s0->m_fb)[y * m_width + x + offset])); + draw_pixel(x, y, ((unsigned int*)s0->m_fb)[y * m_width + x + offset]); } //Right surface for (int x = x1 - offset; x <= x1; x++) { - draw_pixel(x, y, GL_RGB_16_to_32(((unsigned short*)s1->m_fb)[y * m_width + x + offset - x1 + x0])); + draw_pixel(x, y, ((unsigned int*)s1->m_fb)[y * m_width + x + offset - x1 + x0]); } } } @@ -3407,22 +3371,12 @@ private: #ifdef GUILITE_ON c_bitmap_operator the_bitmap_op = c_bitmap_operator(); c_image_operator* c_image::image_operator = &the_bitmap_op; +const void* c_theme::s_font_map[FONT_MAX]; +const void* c_theme::s_image_map[IMAGE_MAX]; +unsigned int c_theme::s_color_map[COLOR_MAX]; +c_lattice_font_op the_lattice_font_op = c_lattice_font_op(); +c_font_operator* c_word::fontOperator = &the_lattice_font_op; #endif - -#ifdef GUILITE_ON - -const void* c_theme::s_font_map[FONT_MAX]; -const void* c_theme::s_image_map[IMAGE_MAX]; -unsigned int c_theme::s_color_map[COLOR_MAX]; - -#endif - -#ifdef GUILITE_ON - -c_lattice_font_op the_lattice_font_op = c_lattice_font_op(); -c_font_operator* c_word::fontOperator = &the_lattice_font_op; - -#endif #ifdef GUILITE_ON #if (defined __linux__) || (defined __APPLE__) #include @@ -4264,11 +4218,7 @@ int c_fifo::write(void* buf, int len) #endif #ifdef GUILITE_ON DIALOG_ARRAY c_dialog::ms_the_dialogs[SURFACE_CNT_MAX]; -#endif -#ifdef GUILITE_ON c_keyboard c_edit::s_keyboard; -#endif -#ifdef GUILITE_ON static c_keyboard_button s_key_0, s_key_1, s_key_2, s_key_3, s_key_4, s_key_5, s_key_6, s_key_7, s_key_8, s_key_9; static c_keyboard_button s_key_A, s_key_B, s_key_C, s_key_D, s_key_E, s_key_F, s_key_G, s_key_H, s_key_I, s_key_J; static c_keyboard_button s_key_K, s_key_L, s_key_M, s_key_N, s_key_O, s_key_P, s_key_Q, s_key_R, s_key_S, s_key_T; @@ -4306,12 +4256,12 @@ WND_TREE g_key_board_children[] = {&s_key_B, 'B', 0, ((KEY_WIDTH / 2) + POS_X(5)), POS_Y(2), KEY_WIDTH, KEY_HEIGHT}, {&s_key_N, 'N', 0, ((KEY_WIDTH / 2) + POS_X(6)), POS_Y(2), KEY_WIDTH, KEY_HEIGHT}, {&s_key_M, 'M', 0, ((KEY_WIDTH / 2) + POS_X(7)), POS_Y(2), KEY_WIDTH, KEY_HEIGHT}, - {&s_key_del, 0x7F, 0, ((KEY_WIDTH / 2) + POS_X(8)), POS_Y(2), DEL_WIDTH, KEY_HEIGHT}, + {&s_key_del,0x7F, 0, ((KEY_WIDTH / 2) + POS_X(8)), POS_Y(2), DEL_WIDTH, KEY_HEIGHT}, //Row 4 - {&s_key_esc, 0x1B, 0, POS_X(0), POS_Y(3), ESC_WIDTH, KEY_HEIGHT}, + {&s_key_esc, 0x1B, 0, POS_X(0), POS_Y(3), ESC_WIDTH, KEY_HEIGHT}, {&s_key_num_switch, 0x90, 0, POS_X(2), POS_Y(3), SWITCH_WIDTH, KEY_HEIGHT}, {&s_key_space, ' ', 0, ((KEY_WIDTH / 2) + POS_X(3)), POS_Y(3), SPACE_WIDTH, KEY_HEIGHT}, - {&s_key_dot, '.', 0, ((KEY_WIDTH / 2) + POS_X(6)), POS_Y(3), DOT_WIDTH, KEY_HEIGHT}, + {&s_key_dot, '.', 0, ((KEY_WIDTH / 2) + POS_X(6)), POS_Y(3), DOT_WIDTH, KEY_HEIGHT}, {&s_key_enter, '\n', 0, POS_X(8), POS_Y(3), ENTER_WIDTH, KEY_HEIGHT}, {0,0,0,0,0,0,0} }; @@ -4326,12 +4276,11 @@ WND_TREE g_number_board_children[] = {&s_key_7, '7', 0, POS_X(0), POS_Y(2), KEY_WIDTH, KEY_HEIGHT}, {&s_key_8, '8', 0, POS_X(1), POS_Y(2), KEY_WIDTH, KEY_HEIGHT}, {&s_key_9, '9', 0, POS_X(2), POS_Y(2), KEY_WIDTH, KEY_HEIGHT}, - - {&s_key_esc, 0x1B, 0, POS_X(0), POS_Y(3), KEY_WIDTH, KEY_HEIGHT}, + {&s_key_esc,0x1B, 0, POS_X(0), POS_Y(3), KEY_WIDTH, KEY_HEIGHT}, {&s_key_0, '0', 0, POS_X(1), POS_Y(3), KEY_WIDTH, KEY_HEIGHT}, - {&s_key_dot, '.', 0, POS_X(2), POS_Y(3), KEY_WIDTH, KEY_HEIGHT}, + {&s_key_dot,'.', 0, POS_X(2), POS_Y(3), KEY_WIDTH, KEY_HEIGHT}, {&s_key_del, 0x7F, 0, POS_X(3), POS_Y(0), KEY_WIDTH, KEY_HEIGHT * 2 + 2}, {&s_key_enter,'\n', 0, POS_X(3), POS_Y(2), KEY_WIDTH, KEY_HEIGHT * 2 + 2}, {0,0,0,0,0,0,0} }; -#endif +#endif \ No newline at end of file diff --git a/HelloTimer/UIcode/UIcode.cpp b/HelloTimer/UIcode/UIcode.cpp index 13f2922cc9e481f11c4f98fb73bd454224dc8bee..ee12858f089c087552b34f0d556be417fa7b7a71 100644 --- a/HelloTimer/UIcode/UIcode.cpp +++ b/HelloTimer/UIcode/UIcode.cpp @@ -302,24 +302,14 @@ void switchUI() } } -void create_ui(void* phy_fb, int screen_width, int screen_height, int color_bytes, struct EXTERNAL_GFX_OP* gfx_op) +void create_ui(void* phy_fb, int screen_width, int screen_height, int color_bytes, struct DISPLAY_DRIVER* driver) { load_resource(); - if (phy_fb) - { - static c_surface surface(UI_WIDTH, UI_HEIGHT, color_bytes, Z_ORDER_LEVEL_0); - static c_display display(phy_fb, screen_width, screen_height, &surface); - s_surface = &surface; - s_display = &display; - } - else - {//for MCU without framebuffer - static c_surface_no_fb surface_no_fb(UI_WIDTH, UI_HEIGHT, color_bytes, gfx_op, Z_ORDER_LEVEL_0); - static c_display display(phy_fb, screen_width, screen_height, &surface_no_fb); - s_surface = &surface_no_fb; - s_display = &display; - } + static c_surface surface(UI_WIDTH, UI_HEIGHT, color_bytes, Z_ORDER_LEVEL_0); + static c_display display(phy_fb, screen_width, screen_height, &surface, driver); + s_surface = &surface; + s_display = &display; //background s_surface->fill_rect(0, 0, UI_WIDTH, UI_HEIGHT, 0, Z_ORDER_LEVEL_0); @@ -333,9 +323,9 @@ void create_ui(void* phy_fb, int screen_width, int screen_height, int color_byte } //////////////////////// interface for all platform //////////////////////// -extern "C" void startHelloTimer(void* phy_fb, int width, int height, int color_bytes, struct EXTERNAL_GFX_OP* gfx_op) +extern "C" void startHelloTimer(void* phy_fb, int width, int height, int color_bytes, struct DISPLAY_DRIVER* driver) { - create_ui(phy_fb, width, height, color_bytes, gfx_op); + create_ui(phy_fb, width, height, color_bytes, driver); } extern void* getUiOfHelloTimer(int* width, int* height, bool force_update = false) diff --git a/HelloTransparent/BuildLinux/.sync_build.sh b/HelloTransparent/BuildLinux/.sync_build.sh index 49cff5b473ac606967676ebefa6f0d333e301227..d429316434a47b7b77a4ad64e4b96bc66e96eaaf 100644 --- a/HelloTransparent/BuildLinux/.sync_build.sh +++ b/HelloTransparent/BuildLinux/.sync_build.sh @@ -1,5 +1,6 @@ if [ "$#" -ne 1 ]; then - echo "Invalid arguments" + echo "Do testing" + ./xWindow 522 657 | ./HelloTransparent shared-fb exit -1 fi diff --git a/HelloTransparent/UIcode/GuiLite.h b/HelloTransparent/UIcode/GuiLite.h index c4fc88a51476d2c8309c3e55e1270e13784fc510..80550e1632ad7bc82541a2edbb0f7f8f5937954f 100644 --- a/HelloTransparent/UIcode/GuiLite.h +++ b/HelloTransparent/UIcode/GuiLite.h @@ -1,107 +1,94 @@ #pragma once - -#define REAL_TIME_TASK_CYCLE_MS 50 -#define MAX(a,b) (((a)>(b))?(a):(b)) -#define MIN(a,b) (((a)<(b))?(a):(b)) - -#define GL_ARGB(a, r, g, b) ((((unsigned int)(a)) << 24) | (((unsigned int)(r)) << 16) | (((unsigned int)(g)) << 8) | ((unsigned int)(b))) -#define GL_ARGB_A(rgb) ((((unsigned int)(rgb)) >> 24) & 0xFF) - -#define GL_RGB(r, g, b) ((0xFF << 24) | (((unsigned int)(r)) << 16) | (((unsigned int)(g)) << 8) | ((unsigned int)(b))) -#define GL_RGB_R(rgb) ((((unsigned int)(rgb)) >> 16) & 0xFF) -#define GL_RGB_G(rgb) ((((unsigned int)(rgb)) >> 8) & 0xFF) -#define GL_RGB_B(rgb) (((unsigned int)(rgb)) & 0xFF) -#define GL_RGB_32_to_16(rgb) (((((unsigned int)(rgb)) & 0xFF) >> 3) | ((((unsigned int)(rgb)) & 0xFC00) >> 5) | ((((unsigned int)(rgb)) & 0xF80000) >> 8)) -#define GL_RGB_16_to_32(rgb) ((0xFF << 24) | ((((unsigned int)(rgb)) & 0x1F) << 3) | ((((unsigned int)(rgb)) & 0x7E0) << 5) | ((((unsigned int)(rgb)) & 0xF800) << 8)) - -#define ALIGN_HCENTER 0x00000000L -#define ALIGN_LEFT 0x01000000L -#define ALIGN_RIGHT 0x02000000L -#define ALIGN_HMASK 0x03000000L - -#define ALIGN_VCENTER 0x00000000L -#define ALIGN_TOP 0x00100000L -#define ALIGN_BOTTOM 0x00200000L -#define ALIGN_VMASK 0x00300000L - -typedef struct -{ - unsigned short year; - unsigned short month; - unsigned short date; - unsigned short day; - unsigned short hour; - unsigned short minute; - unsigned short second; -}T_TIME; - -void register_debug_function(void(*my_assert)(const char* file, int line), void(*my_log_out)(const char* log)); -void _assert(const char* file, int line); -#define ASSERT(condition) \ - do{ \ - if(!(condition))_assert(__FILE__, __LINE__);\ - }while(0) -void log_out(const char* log); - -long get_time_in_second(); -T_TIME second_to_day(long second); -T_TIME get_time(); - -void start_real_timer(void (*func)(void* arg)); -void register_timer(int milli_second, void func(void* param), void* param); - -unsigned int get_cur_thread_id(); -void create_thread(unsigned long* thread_id, void* attr, void *(*start_routine) (void *), void* arg); -void thread_sleep(unsigned int milli_seconds); -int build_bmp(const char *filename, unsigned int width, unsigned int height, unsigned char *data); - -#define FIFO_BUFFER_LEN 1024 -class c_fifo -{ -public: - c_fifo(); - int read(void* buf, int len); - int write(void* buf, int len); -private: - unsigned char m_buf[FIFO_BUFFER_LEN]; - int m_head; - int m_tail; - void* m_read_sem; - void* m_write_mutex; -}; - -class c_rect -{ -public: - c_rect(){ m_left = m_top = m_right = m_bottom = -1; } - c_rect(int left, int top, int width, int height) - { - set_rect(left, top, width, height); - } - void set_rect(int left, int top, int width, int height) - { - ASSERT(width > 0 && height > 0); - m_left = left; - m_top = top; - m_right = left + width - 1; - m_bottom = top + height -1; - } - bool pt_in_rect(int x, int y) const - { - return x >= m_left && x <= m_right && y >= m_top && y <= m_bottom; - } - int operator==(const c_rect& rect) const - { - return (m_left == rect.m_left) && (m_top == rect.m_top) && (m_right == rect.m_right) && (m_bottom == rect.m_bottom); - } - int width() const { return m_right - m_left + 1; } - int height() const { return m_bottom - m_top + 1 ; } - - int m_left; - int m_top; - int m_right; - int m_bottom; -}; +#define REAL_TIME_TASK_CYCLE_MS 50 +#define MAX(a,b) (((a)>(b))?(a):(b)) +#define MIN(a,b) (((a)<(b))?(a):(b)) +#define GL_ARGB(a, r, g, b) ((((unsigned int)(a)) << 24) | (((unsigned int)(r)) << 16) | (((unsigned int)(g)) << 8) | ((unsigned int)(b))) +#define GL_ARGB_A(rgb) ((((unsigned int)(rgb)) >> 24) & 0xFF) +#define GL_RGB(r, g, b) ((0xFF << 24) | (((unsigned int)(r)) << 16) | (((unsigned int)(g)) << 8) | ((unsigned int)(b))) +#define GL_RGB_R(rgb) ((((unsigned int)(rgb)) >> 16) & 0xFF) +#define GL_RGB_G(rgb) ((((unsigned int)(rgb)) >> 8) & 0xFF) +#define GL_RGB_B(rgb) (((unsigned int)(rgb)) & 0xFF) +#define GL_RGB_32_to_16(rgb) (((((unsigned int)(rgb)) & 0xFF) >> 3) | ((((unsigned int)(rgb)) & 0xFC00) >> 5) | ((((unsigned int)(rgb)) & 0xF80000) >> 8)) +#define GL_RGB_16_to_32(rgb) ((0xFF << 24) | ((((unsigned int)(rgb)) & 0x1F) << 3) | ((((unsigned int)(rgb)) & 0x7E0) << 5) | ((((unsigned int)(rgb)) & 0xF800) << 8)) +#define ALIGN_HCENTER 0x00000000L +#define ALIGN_LEFT 0x01000000L +#define ALIGN_RIGHT 0x02000000L +#define ALIGN_HMASK 0x03000000L +#define ALIGN_VCENTER 0x00000000L +#define ALIGN_TOP 0x00100000L +#define ALIGN_BOTTOM 0x00200000L +#define ALIGN_VMASK 0x00300000L +typedef struct +{ + unsigned short year; + unsigned short month; + unsigned short date; + unsigned short day; + unsigned short hour; + unsigned short minute; + unsigned short second; +}T_TIME; +void register_debug_function(void(*my_assert)(const char* file, int line), void(*my_log_out)(const char* log)); +void _assert(const char* file, int line); +#define ASSERT(condition) \ + do{ \ + if(!(condition))_assert(__FILE__, __LINE__);\ + }while(0) +void log_out(const char* log); +long get_time_in_second(); +T_TIME second_to_day(long second); +T_TIME get_time(); +void start_real_timer(void (*func)(void* arg)); +void register_timer(int milli_second, void func(void* param), void* param); +unsigned int get_cur_thread_id(); +void create_thread(unsigned long* thread_id, void* attr, void *(*start_routine) (void *), void* arg); +void thread_sleep(unsigned int milli_seconds); +int build_bmp(const char *filename, unsigned int width, unsigned int height, unsigned char *data); +#define FIFO_BUFFER_LEN 1024 +class c_fifo +{ +public: + c_fifo(); + int read(void* buf, int len); + int write(void* buf, int len); +private: + unsigned char m_buf[FIFO_BUFFER_LEN]; + int m_head; + int m_tail; + void* m_read_sem; + void* m_write_mutex; +}; +class c_rect +{ +public: + c_rect(){ m_left = m_top = m_right = m_bottom = -1; } + c_rect(int left, int top, int width, int height) + { + set_rect(left, top, width, height); + } + void set_rect(int left, int top, int width, int height) + { + ASSERT(width > 0 && height > 0); + m_left = left; + m_top = top; + m_right = left + width - 1; + m_bottom = top + height -1; + } + bool pt_in_rect(int x, int y) const + { + return x >= m_left && x <= m_right && y >= m_top && y <= m_bottom; + } + int operator==(const c_rect& rect) const + { + return (m_left == rect.m_left) && (m_top == rect.m_top) && (m_right == rect.m_right) && (m_bottom == rect.m_bottom); + } + int width() const { return m_right - m_left + 1; } + int height() const { return m_bottom - m_top + 1 ; } + int m_left; + int m_top; + int m_right; + int m_bottom; +}; //BITMAP typedef struct struct_bitmap_info { @@ -238,7 +225,7 @@ typedef enum Z_ORDER_LEVEL_2,//highest graphic level Z_ORDER_LEVEL_MAX }Z_ORDER_LEVEL; -struct EXTERNAL_GFX_OP +struct DISPLAY_DRIVER { void(*draw_pixel)(int x, int y, unsigned int rgb); void(*fill_rect)(int x0, int y0, int x1, int y1, unsigned int rgb); @@ -247,18 +234,19 @@ class c_surface; class c_display { friend class c_surface; public: - inline c_display(void* phy_fb, int display_width, int display_height, int surface_width, int surface_height, unsigned int color_bytes, int surface_cnt, EXTERNAL_GFX_OP* gfx_op = 0);//multiple surface or surface_no_fb - inline c_display(void* phy_fb, int display_width, int display_height, c_surface* surface);//single custom surface - inline c_surface* alloc_surface(Z_ORDER_LEVEL max_zorder, c_rect layer_rect = c_rect());//for multiple surfaces + inline c_display(void* phy_fb, int display_width, int display_height, c_surface* surface, DISPLAY_DRIVER* driver = 0);//single custom surface + inline c_display(void* phy_fb, int display_width, int display_height, int surface_width, int surface_height, unsigned int color_bytes, int surface_cnt, DISPLAY_DRIVER* driver = 0);//multiple surface + inline c_surface* alloc_surface(Z_ORDER_LEVEL max_zorder, c_rect layer_rect = c_rect());//for slide group inline int swipe_surface(c_surface* s0, c_surface* s1, int x0, int x1, int y0, int y1, int offset); int get_width() { return m_width; } int get_height() { return m_height; } + void* get_phy_fb() { return m_phy_fb; } void* get_updated_fb(int* width, int* height, bool force_update = false) { if (width && height) { - *width = get_width(); - *height = get_height(); + *width = m_width; + *height = m_height; } if (force_update) { @@ -277,35 +265,123 @@ public: { return -1; } - int width = get_width(); - int height = get_height(); //16 bits framebuffer if (m_color_bytes == 2) { - return build_bmp(file_name, width, height, (unsigned char*)m_phy_fb); + return build_bmp(file_name, m_width, m_height, (unsigned char*)m_phy_fb); } //32 bits framebuffer - unsigned short* p_bmp565_data = new unsigned short[width * height]; + unsigned short* p_bmp565_data = new unsigned short[m_width * m_height]; unsigned int* p_raw_data = (unsigned int*)m_phy_fb; - for (int i = 0; i < width * height; i++) + for (int i = 0; i < m_width * m_height; i++) { unsigned int rgb = *p_raw_data++; p_bmp565_data[i] = GL_RGB_32_to_16(rgb); } - int ret = build_bmp(file_name, width, height, (unsigned char*)p_bmp565_data); + int ret = build_bmp(file_name, m_width, m_height, (unsigned char*)p_bmp565_data); delete[]p_bmp565_data; return ret; } -private: - int m_width; //in pixels - int m_height; //in pixels - int m_color_bytes; //16 bits, 32 bits only - void* m_phy_fb; //physical framebuffer +protected: + virtual void draw_pixel(int x, int y, unsigned int rgb) + { + if ((x >= m_width) || (y >= m_height)) { return; } + if (m_driver && m_driver->draw_pixel) + { + return m_driver->draw_pixel(x, y, rgb); + } + if (m_color_bytes == 2) + { + ((unsigned short*)m_phy_fb)[y * m_width + x] = GL_RGB_32_to_16(rgb); + } + else + { + ((unsigned int*)m_phy_fb)[y * m_width + x] = rgb; + } + } + virtual void fill_rect(int x0, int y0, int x1, int y1, unsigned int rgb) + { + if (m_driver && m_driver->fill_rect) + { + return m_driver->fill_rect(x0, y0, x1, y1, rgb); + } + if (m_driver && m_driver->draw_pixel) + { + for (int y = y0; y <= y1; y++) + { + for (int x = x0; x <= x1; x++) + { + m_driver->draw_pixel(x, y, rgb); + } + } + return; + } + register int _width = m_width; + register int _height = m_height; + int x, y; + if (m_color_bytes == 2) + { + unsigned short* phy_fb; + unsigned int rgb_16 = GL_RGB_32_to_16(rgb); + for (y = y0; y <= y1; y++) + { + phy_fb = &((unsigned short*)m_phy_fb)[y * _width + x0]; + for (x = x0; x <= x1; x++) + { + if ((x < _width) && (y < _height)) + { + *phy_fb++ = rgb_16; + } + } + } + } + else + { + unsigned int* phy_fb; + for (y = y0; y <= y1; y++) + { + phy_fb = &((unsigned int*)m_phy_fb)[y * _width + x0]; + for (x = x0; x <= x1; x++) + { + if ((x < _width) && (y < _height)) + { + *phy_fb++ = rgb; + } + } + } + } + } + virtual int flush_screen(int left, int top, int right, int bottom, void* fb, int fb_width) + { + if ((0 == m_phy_fb) || (0 == fb)) + { + return -1; + } + register int _width = m_width; + register int _height = m_height; + left = (left >= _width) ? (_width - 1) : left; + right = (right >= _width) ? (_width - 1) : right; + top = (top >= _height) ? (_height - 1) : top; + bottom = (bottom >= _height) ? (_height - 1) : bottom; + for (int y = top; y < bottom; y++) + { + void* s_addr = (char*)fb + ((y * fb_width + left) * m_color_bytes); + void* d_addr = (char*)m_phy_fb + ((y * _width + left) * m_color_bytes); + memcpy(d_addr, s_addr, (right - left) * m_color_bytes); + } + return 0; + } + int m_width; //in pixels + int m_height; //in pixels + int m_color_bytes; //16/32 bits for default + void* m_phy_fb; //physical framebuffer for default + struct DISPLAY_DRIVER* m_driver; //Rendering by external method without default physical framebuffer int m_phy_read_index; int m_phy_write_index; c_surface* m_surface_group[SURFACE_CNT_MAX]; int m_surface_cnt; //surface count int m_surface_index; + }; class c_layer { @@ -317,12 +393,10 @@ public: class c_surface { friend class c_display; friend class c_bitmap_operator; public: - c_surface(unsigned int width, unsigned int height, unsigned int color_bytes, Z_ORDER_LEVEL max_zorder = Z_ORDER_LEVEL_0, c_rect overlpa_rect = c_rect()) : m_width(width), m_height(height), m_color_bytes(color_bytes), m_fb(0), m_is_active(false), m_top_zorder(Z_ORDER_LEVEL_0), m_phy_fb(0), m_phy_write_index(0), m_display(0) + c_surface(unsigned int width, unsigned int height, unsigned int color_bytes, Z_ORDER_LEVEL max_zorder = Z_ORDER_LEVEL_0, c_rect overlpa_rect = c_rect()) : m_width(width), m_height(height), m_color_bytes(color_bytes), m_fb(0), m_is_active(false), m_top_zorder(Z_ORDER_LEVEL_0), m_phy_write_index(0), m_display(0) { (overlpa_rect == c_rect()) ? set_surface(max_zorder, c_rect(0, 0, width - 1, height - 1)) : set_surface(max_zorder, overlpa_rect); } - int get_width() { return m_width; } - int get_height() { return m_height; } unsigned int get_pixel(int x, int y, unsigned int z_order) { if (x >= m_width || y >= m_height || x < 0 || y < 0 || z_order >= Z_ORDER_LEVEL_MAX) @@ -332,15 +406,15 @@ public: } if (m_layers[z_order].fb) { - return (m_color_bytes == 4) ? ((unsigned int*)(m_layers[z_order].fb))[y * m_width + x] : GL_RGB_16_to_32(((unsigned short*)(m_layers[z_order].fb))[y * m_width + x]); + return (m_color_bytes == 2) ? GL_RGB_16_to_32(((unsigned short*)(m_layers[z_order].fb))[y * m_width + x]) : ((unsigned int*)(m_layers[z_order].fb))[y * m_width + x]; } else if (m_fb) { - return (m_color_bytes == 4) ? ((unsigned int*)m_fb)[y * m_width + x] : GL_RGB_16_to_32(((unsigned short*)m_fb)[y * m_width + x]); + return (m_color_bytes == 2) ? GL_RGB_16_to_32(((unsigned short*)m_fb)[y * m_width + x]) : ((unsigned int*)m_fb)[y * m_width + x]; } - else if (m_phy_fb) + else if (m_display->m_phy_fb) { - return (m_color_bytes == 4) ? ((unsigned int*)m_phy_fb)[y * m_width + x] : GL_RGB_16_to_32(((unsigned short*)m_phy_fb)[y * m_width + x]); + return (m_color_bytes == 2) ? GL_RGB_16_to_32(((unsigned short*)m_display->m_phy_fb)[y * m_width + x]) : ((unsigned int*)m_display->m_phy_fb)[y * m_width + x]; } return 0; } @@ -357,7 +431,7 @@ public: } if (z_order == m_max_zorder) { - return draw_pixel_on_fb(x, y, rgb); + return draw_pixel_low_level(x, y, rgb); } if (z_order > (unsigned int)m_top_zorder) @@ -367,19 +441,19 @@ public: if (m_layers[z_order].rect.pt_in_rect(x, y)) { c_rect layer_rect = m_layers[z_order].rect; - if (m_color_bytes == 4) + if (m_color_bytes == 2) { - ((unsigned int*)(m_layers[z_order].fb))[(x - layer_rect.m_left) + (y - layer_rect.m_top) * layer_rect.width()] = rgb; + ((unsigned short*)(m_layers[z_order].fb))[(x - layer_rect.m_left) + (y - layer_rect.m_top) * layer_rect.width()] = GL_RGB_32_to_16(rgb); } else { - ((unsigned short*)(m_layers[z_order].fb))[(x - layer_rect.m_left) + (y - layer_rect.m_top) * layer_rect.width()] = GL_RGB_32_to_16(rgb); + ((unsigned int*)(m_layers[z_order].fb))[(x - layer_rect.m_left) + (y - layer_rect.m_top) * layer_rect.width()] = rgb; } } if (z_order == m_top_zorder) { - return draw_pixel_on_fb(x, y, rgb); + return draw_pixel_low_level(x, y, rgb); } bool be_overlapped = false; for (unsigned int tmp_z_order = Z_ORDER_LEVEL_MAX - 1; tmp_z_order > z_order; tmp_z_order--) @@ -392,7 +466,7 @@ public: } if (!be_overlapped) { - draw_pixel_on_fb(x, y, rgb); + draw_pixel_low_level(x, y, rgb); } } virtual void fill_rect(int x0, int y0, int x1, int y1, unsigned int rgb, unsigned int z_order) @@ -403,7 +477,7 @@ public: y1 = (y1 > (m_height - 1)) ? (m_height - 1) : y1; if (z_order == m_max_zorder) { - return fill_rect_on_fb(x0, y0, x1, y1, rgb); + return fill_rect_low_level(x0, y0, x1, y1, rgb); } if (z_order == m_top_zorder) { @@ -416,18 +490,18 @@ public: { if (layer_rect.pt_in_rect(x, y)) { - if (m_color_bytes == 4) + if (m_color_bytes == 2) { - ((unsigned int*)m_layers[z_order].fb)[(y - layer_rect.m_top) * layer_rect.width() + (x - layer_rect.m_left)] = rgb; + ((unsigned short*)m_layers[z_order].fb)[(y - layer_rect.m_top) * layer_rect.width() + (x - layer_rect.m_left)] = rgb_16; } else { - ((unsigned short*)m_layers[z_order].fb)[(y - layer_rect.m_top) * layer_rect.width() + (x - layer_rect.m_left)] = rgb_16; + ((unsigned int*)m_layers[z_order].fb)[(y - layer_rect.m_top) * layer_rect.width() + (x - layer_rect.m_left)] = rgb; } } } } - return fill_rect_on_fb(x0, y0, x1, y1, rgb); + return fill_rect_low_level(x0, y0, x1, y1, rgb); } for (; y0 <= y1; y0++) { @@ -499,27 +573,16 @@ public: } int flush_screen(int left, int top, int right, int bottom) { - if (left < 0 || left >= m_width || right < 0 || right >= m_width || - top < 0 || top >= m_height || bottom < 0 || bottom >= m_height) - { - ASSERT(false); - } - if (!m_is_active || (0 == m_phy_fb) || (0 == m_fb)) + if (!m_is_active) { return -1; } - int display_width = m_display->get_width(); - int display_height = m_display->get_height(); - left = (left >= display_width) ? (display_width - 1) : left; - right = (right >= display_width) ? (display_width - 1) : right; - top = (top >= display_height) ? (display_height - 1) : top; - bottom = (bottom >= display_height) ? (display_height - 1) : bottom; - for (int y = top; y < bottom; y++) + if (left < 0 || left >= m_width || right < 0 || right >= m_width || + top < 0 || top >= m_height || bottom < 0 || bottom >= m_height) { - void* s_addr = (char*)m_fb + ((y * m_width + left) * m_color_bytes); - void* d_addr = (char*)m_phy_fb + ((y * display_width + left) * m_color_bytes); - memcpy(d_addr, s_addr, (right - left) * m_color_bytes); + ASSERT(false); } + m_display->flush_screen(left, top, right, bottom, m_fb, m_width); *m_phy_write_index = *m_phy_write_index + 1; return 0; } @@ -537,90 +600,62 @@ public: { for (int x = rect.m_left; x <= rect.m_right; x++) { - unsigned int rgb = (m_color_bytes == 4) ? ((unsigned int*)fb)[(x - layer_rect.m_left) + (y - layer_rect.m_top) * width] : GL_RGB_16_to_32(((unsigned short*)fb)[(x - layer_rect.m_left) + (y - layer_rect.m_top) * width]); - draw_pixel_on_fb(x, y, rgb); + unsigned int rgb = (m_color_bytes == 2) ? GL_RGB_16_to_32(((unsigned short*)fb)[(x - layer_rect.m_left) + (y - layer_rect.m_top) * width]) : ((unsigned int*)fb)[(x - layer_rect.m_left) + (y - layer_rect.m_top) * width]; + draw_pixel_low_level(x, y, rgb); } } return 0; } void set_active(bool flag) { m_is_active = flag; } protected: - virtual void fill_rect_on_fb(int x0, int y0, int x1, int y1, unsigned int rgb) - { - int display_width = m_display->get_width(); - int display_height = m_display->get_height(); - if (m_color_bytes == 4) + virtual void fill_rect_low_level(int x0, int y0, int x1, int y1, unsigned int rgb) + {//fill rect on framebuffer of surface + int x, y; + if (m_color_bytes == 2) { - int x; - unsigned int* fb, * phy_fb; - for (; y0 <= y1; y0++) + unsigned short* fb; + unsigned int rgb_16 = GL_RGB_32_to_16(rgb); + for (y = y0; y <= y1; y++) { - x = x0; - fb = m_fb ? &((unsigned int*)m_fb)[y0 * m_width + x] : 0; - phy_fb = &((unsigned int*)m_phy_fb)[y0 * display_width + x]; - *m_phy_write_index = *m_phy_write_index + 1; - for (; x <= x1; x++) + fb = m_fb ? &((unsigned short*)m_fb)[y * m_width + x0] : 0; + if (!fb) { break; } + for (x = x0; x <= x1; x++) { - if (fb) - { - *fb++ = rgb; - } - if (m_is_active && (x < display_width) && (y0 < display_height)) - { - *phy_fb++ = rgb; - } + *fb++ = rgb_16; } } } - else if (m_color_bytes == 2) + else { - int x; - unsigned short* fb, * phy_fb; - rgb = GL_RGB_32_to_16(rgb); - for (; y0 <= y1; y0++) + unsigned int* fb; + for (y = y0; y <= y1; y++) { - x = x0; - fb = m_fb ? &((unsigned short*)m_fb)[y0 * m_width + x] : 0; - phy_fb = &((unsigned short*)m_phy_fb)[y0 * display_width + x]; - *m_phy_write_index = *m_phy_write_index + 1; - for (; x <= x1; x++) + fb = m_fb ? &((unsigned int*)m_fb)[y * m_width + x0] : 0; + if (!fb) { break; } + for (x = x0; x <= x1; x++) { - if (fb) - { - *fb++ = rgb; - } - if (m_is_active && (x < display_width) && (y0 < display_height)) - { - *phy_fb++ = rgb; - } + *fb++ = rgb; } } } + if (!m_is_active) { return; } + m_display->fill_rect(x0, y0, x1, y1, rgb); + *m_phy_write_index = *m_phy_write_index + 1; } - virtual void draw_pixel_on_fb(int x, int y, unsigned int rgb) + virtual void draw_pixel_low_level(int x, int y, unsigned int rgb) { if (m_fb) - { - (m_color_bytes == 4) ? ((unsigned int*)m_fb)[y * m_width + x] = rgb : ((unsigned short*)m_fb)[y * m_width + x] = GL_RGB_32_to_16(rgb); - } - if (m_is_active && (x < m_display->get_width()) && (y < m_display->get_height())) - { - if (m_color_bytes == 4) - { - ((unsigned int*)m_phy_fb)[y * (m_display->get_width()) + x] = rgb; - } - else - { - ((unsigned short*)m_phy_fb)[y * (m_display->get_width()) + x] = GL_RGB_32_to_16(rgb); - } - *m_phy_write_index = *m_phy_write_index + 1; + {//draw pixel on framebuffer of surface + (m_color_bytes == 2) ? ((unsigned short*)m_fb)[y * m_width + x] = GL_RGB_32_to_16(rgb): ((unsigned int*)m_fb)[y * m_width + x] = rgb; } + if (!m_is_active) { return; } + m_display->draw_pixel(x, y, rgb); + *m_phy_write_index = *m_phy_write_index + 1; } void attach_display(c_display* display) { ASSERT(display); m_display = display; - m_phy_fb = display->m_phy_fb; m_phy_write_index = &display->m_phy_write_index; } void set_surface(Z_ORDER_LEVEL max_z_order, c_rect layer_rect) @@ -638,87 +673,22 @@ protected: } int m_width; //in pixels int m_height; //in pixels - int m_color_bytes; //16 bits, 32 bits only + int m_color_bytes; //16 bits, 32 bits for default void* m_fb; //frame buffer you could see c_layer m_layers[Z_ORDER_LEVEL_MAX];//all graphic layers bool m_is_active; //active flag Z_ORDER_LEVEL m_max_zorder; //the highest graphic layer the surface will have Z_ORDER_LEVEL m_top_zorder; //the current highest graphic layer the surface have - void* m_phy_fb; //physical framebufer int* m_phy_write_index; c_display* m_display; }; -class c_surface_no_fb : public c_surface {//No physical framebuffer, render with external graphic interface - friend class c_display; -public: - c_surface_no_fb(unsigned int width, unsigned int height, unsigned int color_bytes, struct EXTERNAL_GFX_OP* gfx_op, Z_ORDER_LEVEL max_zorder = Z_ORDER_LEVEL_0, c_rect overlpa_rect = c_rect()) : c_surface(width, height, color_bytes, max_zorder, overlpa_rect), m_gfx_op(gfx_op) {} -protected: - virtual void fill_rect_on_fb(int x0, int y0, int x1, int y1, unsigned int rgb) - { - if (!m_gfx_op) - { - return; - } - if (m_gfx_op->fill_rect) - { - return m_gfx_op->fill_rect(x0, y0, x1, y1, rgb); - } - if (m_gfx_op->draw_pixel && m_is_active) - { - for (int y = y0; y <= y1; y++) - { - for (int x = x0; x <= x1; x++) - { - m_gfx_op->draw_pixel(x, y, rgb); - } - } - } - if (!m_fb) { return; } - if (m_color_bytes == 4) - { - unsigned int* fb; - for (int y = y0; y <= y1; y++) - { - fb = &((unsigned int*)m_fb)[y0 * m_width + x0]; - for (int x = x0; x <= x1; x++) - { - *fb++ = rgb; - } - } - } - else if (m_color_bytes == 2) - { - unsigned short* fb; - rgb = GL_RGB_32_to_16(rgb); - for (int y = y0; y <= y1; y++) - { - fb = &((unsigned short*)m_fb)[y0 * m_width + x0]; - for (int x = x0; x <= x1; x++) - { - *fb++ = rgb; - } - } - } - } - virtual void draw_pixel_on_fb(int x, int y, unsigned int rgb) - { - if (m_gfx_op && m_gfx_op->draw_pixel && m_is_active) - { - m_gfx_op->draw_pixel(x, y, rgb); - } - if (!m_fb) { return; } - if (m_color_bytes == 4) - { - ((unsigned int*)m_fb)[y * m_width + x] = rgb; - } - else if (m_color_bytes == 2) - { - ((unsigned short*)m_fb)[y * m_width + x] = GL_RGB_32_to_16(rgb); - } - } - struct EXTERNAL_GFX_OP* m_gfx_op;//Rendering by external method -}; -inline c_display::c_display(void* phy_fb, int display_width, int display_height, int surface_width, int surface_height, unsigned int color_bytes, int surface_cnt, EXTERNAL_GFX_OP* gfx_op) : m_width(display_width), m_height(display_height), m_color_bytes(color_bytes), m_phy_fb(phy_fb), m_phy_read_index(0), m_phy_write_index(0), m_surface_cnt(surface_cnt), m_surface_index(0) +inline c_display::c_display(void* phy_fb, int display_width, int display_height, c_surface* surface, DISPLAY_DRIVER* driver) : m_phy_fb(phy_fb), m_width(display_width), m_height(display_height), m_driver(driver), m_phy_read_index(0), m_phy_write_index(0), m_surface_cnt(1), m_surface_index(0) +{ + m_color_bytes = surface->m_color_bytes; + surface->m_is_active = true; + (m_surface_group[0] = surface)->attach_display(this); +} +inline c_display::c_display(void* phy_fb, int display_width, int display_height, int surface_width, int surface_height, unsigned int color_bytes, int surface_cnt, DISPLAY_DRIVER* driver) : m_phy_fb(phy_fb), m_width(display_width), m_height(display_height), m_color_bytes(color_bytes), m_phy_read_index(0), m_phy_write_index(0), m_surface_cnt(surface_cnt), m_driver(driver), m_surface_index(0) { ASSERT(color_bytes == 2 || color_bytes == 4); ASSERT(m_surface_cnt <= SURFACE_CNT_MAX); @@ -726,16 +696,10 @@ inline c_display::c_display(void* phy_fb, int display_width, int display_height, for (int i = 0; i < m_surface_cnt; i++) { - m_surface_group[i] = (phy_fb) ? new c_surface(surface_width, surface_height, color_bytes) : new c_surface_no_fb(surface_width, surface_height, color_bytes, gfx_op); + m_surface_group[i] = new c_surface(surface_width, surface_height, color_bytes); m_surface_group[i]->attach_display(this); } } -inline c_display::c_display(void* phy_fb, int display_width, int display_height, c_surface* surface) : m_width(display_width), m_height(display_height), m_phy_fb(phy_fb), m_phy_read_index(0), m_phy_write_index(0), m_surface_cnt(1), m_surface_index(0) -{ - m_color_bytes = surface->m_color_bytes; - surface->m_is_active = true; - (m_surface_group[0] = surface)->attach_display(this); -} inline c_surface* c_display::alloc_surface(Z_ORDER_LEVEL max_zorder, c_rect layer_rect) { ASSERT(max_zorder < Z_ORDER_LEVEL_MAX && m_surface_index < m_surface_cnt); @@ -744,8 +708,8 @@ inline c_surface* c_display::alloc_surface(Z_ORDER_LEVEL max_zorder, c_rect laye } inline int c_display::swipe_surface(c_surface* s0, c_surface* s1, int x0, int x1, int y0, int y1, int offset) { - int surface_width = s0->get_width(); - int surface_height = s0->get_height(); + register int surface_width = s0->m_width; + register int surface_height = s0->m_height; if (offset < 0 || offset > surface_width || y0 < 0 || y0 >= surface_height || y1 < 0 || y1 >= surface_height || x0 < 0 || x0 >= surface_width || x1 < 0 || x1 >= surface_width) { @@ -767,46 +731,46 @@ inline int c_display::swipe_surface(c_surface* s0, c_surface* s1, int x0, int x1 for (int y = y0; y <= y1; y++) { //Left surface - char* addr_s = ((char*)(s0->m_fb) + (y * (s0->get_width()) + x0 + offset) * m_color_bytes); + char* addr_s = ((char*)(s0->m_fb) + (y * surface_width + x0 + offset) * m_color_bytes); char* addr_d = ((char*)(m_phy_fb)+(y * m_width + x0) * m_color_bytes); memcpy(addr_d, addr_s, (width - offset) * m_color_bytes); //Right surface - addr_s = ((char*)(s1->m_fb) + (y * (s1->get_width()) + x0) * m_color_bytes); + addr_s = ((char*)(s1->m_fb) + (y * surface_width + x0) * m_color_bytes); addr_d = ((char*)(m_phy_fb)+(y * m_width + x0 + (width - offset)) * m_color_bytes); memcpy(addr_d, addr_s, offset * m_color_bytes); } } - else if (m_color_bytes == 4) + else if (m_color_bytes == 2) { - void(*draw_pixel)(int x, int y, unsigned int rgb) = ((c_surface_no_fb*)s0)->m_gfx_op->draw_pixel; + void(*draw_pixel)(int x, int y, unsigned int rgb) = m_driver->draw_pixel; for (int y = y0; y <= y1; y++) { //Left surface for (int x = x0; x <= (x1 - offset); x++) { - draw_pixel(x, y, ((unsigned int*)s0->m_fb)[y * m_width + x + offset]); + draw_pixel(x, y, GL_RGB_16_to_32(((unsigned short*)s0->m_fb)[y * m_width + x + offset])); } //Right surface for (int x = x1 - offset; x <= x1; x++) { - draw_pixel(x, y, ((unsigned int*)s1->m_fb)[y * m_width + x + offset - x1 + x0]); + draw_pixel(x, y, GL_RGB_16_to_32(((unsigned short*)s1->m_fb)[y * m_width + x + offset - x1 + x0])); } } } - else if (m_color_bytes == 2) + else //m_color_bytes == 3/4... { - void(*draw_pixel)(int x, int y, unsigned int rgb) = ((c_surface_no_fb*)s0)->m_gfx_op->draw_pixel; + void(*draw_pixel)(int x, int y, unsigned int rgb) = m_driver->draw_pixel; for (int y = y0; y <= y1; y++) { //Left surface for (int x = x0; x <= (x1 - offset); x++) { - draw_pixel(x, y, GL_RGB_16_to_32(((unsigned short*)s0->m_fb)[y * m_width + x + offset])); + draw_pixel(x, y, ((unsigned int*)s0->m_fb)[y * m_width + x + offset]); } //Right surface for (int x = x1 - offset; x <= x1; x++) { - draw_pixel(x, y, GL_RGB_16_to_32(((unsigned short*)s1->m_fb)[y * m_width + x + offset - x1 + x0])); + draw_pixel(x, y, ((unsigned int*)s1->m_fb)[y * m_width + x + offset - x1 + x0]); } } } @@ -3407,22 +3371,12 @@ private: #ifdef GUILITE_ON c_bitmap_operator the_bitmap_op = c_bitmap_operator(); c_image_operator* c_image::image_operator = &the_bitmap_op; +const void* c_theme::s_font_map[FONT_MAX]; +const void* c_theme::s_image_map[IMAGE_MAX]; +unsigned int c_theme::s_color_map[COLOR_MAX]; +c_lattice_font_op the_lattice_font_op = c_lattice_font_op(); +c_font_operator* c_word::fontOperator = &the_lattice_font_op; #endif - -#ifdef GUILITE_ON - -const void* c_theme::s_font_map[FONT_MAX]; -const void* c_theme::s_image_map[IMAGE_MAX]; -unsigned int c_theme::s_color_map[COLOR_MAX]; - -#endif - -#ifdef GUILITE_ON - -c_lattice_font_op the_lattice_font_op = c_lattice_font_op(); -c_font_operator* c_word::fontOperator = &the_lattice_font_op; - -#endif #ifdef GUILITE_ON #if (defined __linux__) || (defined __APPLE__) #include @@ -4264,11 +4218,7 @@ int c_fifo::write(void* buf, int len) #endif #ifdef GUILITE_ON DIALOG_ARRAY c_dialog::ms_the_dialogs[SURFACE_CNT_MAX]; -#endif -#ifdef GUILITE_ON c_keyboard c_edit::s_keyboard; -#endif -#ifdef GUILITE_ON static c_keyboard_button s_key_0, s_key_1, s_key_2, s_key_3, s_key_4, s_key_5, s_key_6, s_key_7, s_key_8, s_key_9; static c_keyboard_button s_key_A, s_key_B, s_key_C, s_key_D, s_key_E, s_key_F, s_key_G, s_key_H, s_key_I, s_key_J; static c_keyboard_button s_key_K, s_key_L, s_key_M, s_key_N, s_key_O, s_key_P, s_key_Q, s_key_R, s_key_S, s_key_T; @@ -4306,12 +4256,12 @@ WND_TREE g_key_board_children[] = {&s_key_B, 'B', 0, ((KEY_WIDTH / 2) + POS_X(5)), POS_Y(2), KEY_WIDTH, KEY_HEIGHT}, {&s_key_N, 'N', 0, ((KEY_WIDTH / 2) + POS_X(6)), POS_Y(2), KEY_WIDTH, KEY_HEIGHT}, {&s_key_M, 'M', 0, ((KEY_WIDTH / 2) + POS_X(7)), POS_Y(2), KEY_WIDTH, KEY_HEIGHT}, - {&s_key_del, 0x7F, 0, ((KEY_WIDTH / 2) + POS_X(8)), POS_Y(2), DEL_WIDTH, KEY_HEIGHT}, + {&s_key_del,0x7F, 0, ((KEY_WIDTH / 2) + POS_X(8)), POS_Y(2), DEL_WIDTH, KEY_HEIGHT}, //Row 4 - {&s_key_esc, 0x1B, 0, POS_X(0), POS_Y(3), ESC_WIDTH, KEY_HEIGHT}, + {&s_key_esc, 0x1B, 0, POS_X(0), POS_Y(3), ESC_WIDTH, KEY_HEIGHT}, {&s_key_num_switch, 0x90, 0, POS_X(2), POS_Y(3), SWITCH_WIDTH, KEY_HEIGHT}, {&s_key_space, ' ', 0, ((KEY_WIDTH / 2) + POS_X(3)), POS_Y(3), SPACE_WIDTH, KEY_HEIGHT}, - {&s_key_dot, '.', 0, ((KEY_WIDTH / 2) + POS_X(6)), POS_Y(3), DOT_WIDTH, KEY_HEIGHT}, + {&s_key_dot, '.', 0, ((KEY_WIDTH / 2) + POS_X(6)), POS_Y(3), DOT_WIDTH, KEY_HEIGHT}, {&s_key_enter, '\n', 0, POS_X(8), POS_Y(3), ENTER_WIDTH, KEY_HEIGHT}, {0,0,0,0,0,0,0} }; @@ -4326,12 +4276,11 @@ WND_TREE g_number_board_children[] = {&s_key_7, '7', 0, POS_X(0), POS_Y(2), KEY_WIDTH, KEY_HEIGHT}, {&s_key_8, '8', 0, POS_X(1), POS_Y(2), KEY_WIDTH, KEY_HEIGHT}, {&s_key_9, '9', 0, POS_X(2), POS_Y(2), KEY_WIDTH, KEY_HEIGHT}, - - {&s_key_esc, 0x1B, 0, POS_X(0), POS_Y(3), KEY_WIDTH, KEY_HEIGHT}, + {&s_key_esc,0x1B, 0, POS_X(0), POS_Y(3), KEY_WIDTH, KEY_HEIGHT}, {&s_key_0, '0', 0, POS_X(1), POS_Y(3), KEY_WIDTH, KEY_HEIGHT}, - {&s_key_dot, '.', 0, POS_X(2), POS_Y(3), KEY_WIDTH, KEY_HEIGHT}, + {&s_key_dot,'.', 0, POS_X(2), POS_Y(3), KEY_WIDTH, KEY_HEIGHT}, {&s_key_del, 0x7F, 0, POS_X(3), POS_Y(0), KEY_WIDTH, KEY_HEIGHT * 2 + 2}, {&s_key_enter,'\n', 0, POS_X(3), POS_Y(2), KEY_WIDTH, KEY_HEIGHT * 2 + 2}, {0,0,0,0,0,0,0} }; -#endif +#endif \ No newline at end of file diff --git a/HelloTransparent/UIcode/UIcode.cpp b/HelloTransparent/UIcode/UIcode.cpp index 5906cbd2c49090c499811e60c4b8ea7aff9a903a..653d082337c36238c9885a2f126ba430f2a5a22d 100644 --- a/HelloTransparent/UIcode/UIcode.cpp +++ b/HelloTransparent/UIcode/UIcode.cpp @@ -58,7 +58,7 @@ class c_my_dialog : public c_dialog { c_rect rect; get_screen_rect(rect); - s_surface->fill_rect(rect, GL_ARGB(220, 0, 0, 0), m_z_order); + s_surface->fill_rect(rect.m_left, rect.m_top, rect.m_right, rect.m_bottom, GL_ARGB(220, 0, 0, 0), m_z_order); } void on_clicked(int ctrl_id, int param) { @@ -125,6 +125,7 @@ void create_ui(void* phy_fb, int screen_width, int screen_height, int color_byte s_surface = new c_surface_transparent(UI_WIDTH, UI_HEIGHT, color_bytes, Z_ORDER_LEVEL_1); s_display = new c_display(phy_fb, screen_width, screen_height, s_surface); + s_surface->correct_color_after_display(); s_my_ui.set_surface(s_surface); s_my_ui.connect(NULL, ID_ROOT, 0, 0, 0, UI_WIDTH, UI_HEIGHT, s_main_widgets); diff --git a/HelloTransparent/UIcode/surface_transparent.h b/HelloTransparent/UIcode/surface_transparent.h index 51b9273983f9a083ab643585bbb8358e603a9387..22ea57d5bbff52f160f3ed7270e33f5e79990fa6 100644 --- a/HelloTransparent/UIcode/surface_transparent.h +++ b/HelloTransparent/UIcode/surface_transparent.h @@ -1,21 +1,29 @@ +#define SURFACE_COLOR_BYTES 4 + class c_surface_transparent : public c_surface { public: - c_surface_transparent(unsigned int width, unsigned int height, unsigned int color_bytes, Z_ORDER_LEVEL max_zorder) : c_surface(width, height, 4) + c_surface_transparent(unsigned int width, unsigned int height, unsigned int color_bytes, Z_ORDER_LEVEL max_zorder) : c_surface(width, height, color_bytes, max_zorder) { - m_max_zorder = max_zorder; - m_display_color_bytes = color_bytes; - c_rect layer_rect(0, 0, width, height); for (int i = Z_ORDER_LEVEL_0; i <= m_max_zorder; i++) { - ASSERT(m_layers[i].fb = calloc(layer_rect.width() * layer_rect.height(), m_color_bytes)); + ASSERT(m_layers[i].fb = calloc(layer_rect.width() * layer_rect.height(), SURFACE_COLOR_BYTES)); m_layers[i].rect = layer_rect; } } + void correct_color_after_display() + { + m_display_color_bytes = m_color_bytes; + if (m_color_bytes != SURFACE_COLOR_BYTES) + { + m_color_bytes = SURFACE_COLOR_BYTES; + } + } + void clear_layer(unsigned int z_order) { - memset(m_layers[z_order].fb, 0, m_layers[z_order].rect.width() * m_layers[z_order].rect.height() * m_color_bytes); + memset(m_layers[z_order].fb, 0, m_layers[z_order].rect.width() * m_layers[z_order].rect.height() * SURFACE_COLOR_BYTES); } virtual void draw_pixel(int x, int y, unsigned int rgb, unsigned int z_order) @@ -54,13 +62,15 @@ public: unsigned int alpha_b = (b_ * a_ + b * (255 - a_)) / 255; rgb = GL_RGB(alpha_r, alpha_g, alpha_b); } + + void* phy_fb = m_display->get_phy_fb(); if (m_display_color_bytes == 4) { - ((unsigned int*)m_phy_fb)[y * (m_display->get_width()) + x] = rgb; + ((unsigned int*)phy_fb)[y * (m_display->get_width()) + x] = rgb; } else { - ((unsigned short*)m_phy_fb)[y * (m_display->get_width()) + x] = GL_RGB_32_to_16(rgb); + ((unsigned short*)phy_fb)[y * (m_display->get_width()) + x] = GL_RGB_32_to_16(rgb); } } @@ -104,10 +114,11 @@ public: lower_rect = m_layers[z_order - 1].rect; } + void* phy_fb = m_display->get_phy_fb(); for (int y = y0; y <= y1; y++) { - unsigned int* phy_fb_32 = &((unsigned int*)m_phy_fb)[y * display_width + x0]; - unsigned short* phy_fb_16 = &((unsigned short*)m_phy_fb)[y * display_width + x0]; + unsigned int* phy_fb_32 = &((unsigned int*)phy_fb)[y * display_width + x0]; + unsigned short* phy_fb_16 = &((unsigned short*)phy_fb)[y * display_width + x0]; *m_phy_write_index = *m_phy_write_index + 1; for (int x = x0; x <= x1; x++) { @@ -149,16 +160,5 @@ public: } } - void fill_rect(c_rect rect, unsigned int rgb, unsigned int z_order) - { - fill_rect(rect.m_left, rect.m_top, rect.m_right, rect.m_bottom, rgb, z_order); - } - - virtual void draw_pixel_on_fb(int x, int y, unsigned int rgb) - { - m_color_bytes = m_display_color_bytes; - c_surface::draw_pixel_on_fb(x, y, rgb); - m_color_bytes = 4; - } int m_display_color_bytes; }; diff --git a/HelloWave/BuildAppleWatch/HelloWave watchOS App Extension/HelloWave watchOS App Extension-Bridging-Header.h b/HelloWave/BuildAppleWatch/HelloWave watchOS App Extension/HelloWave watchOS App Extension-Bridging-Header.h index f3f74f878f2777f247fee62b5a9152164a774bf4..ac32fcd6bcefc521215523a62b3e0a1242932c34 100644 --- a/HelloWave/BuildAppleWatch/HelloWave watchOS App Extension/HelloWave watchOS App Extension-Bridging-Header.h +++ b/HelloWave/BuildAppleWatch/HelloWave watchOS App Extension/HelloWave watchOS App Extension-Bridging-Header.h @@ -8,7 +8,7 @@ extern "C"{ #endif void* getUiOfHelloWave(); - void startHelloWave(void* phy_fb, int width, int height, int color_bytes, struct EXTERNAL_GFX_OP* gfx_op); + void startHelloWave(void* phy_fb, int width, int height, int color_bytes, struct DISPLAY_DRIVER* driver); #ifdef __cplusplus } #endif diff --git a/HelloWave/BuildLinux/.sync_build.sh b/HelloWave/BuildLinux/.sync_build.sh index 49cff5b473ac606967676ebefa6f0d333e301227..859b2392f9d5e51f4099ce3b62378b23d16a48dc 100644 --- a/HelloWave/BuildLinux/.sync_build.sh +++ b/HelloWave/BuildLinux/.sync_build.sh @@ -1,5 +1,6 @@ if [ "$#" -ne 1 ]; then - echo "Invalid arguments" + echo "Do testing" + ./xWindow 240 320 | ./HelloWave shared-fb exit -1 fi diff --git a/HelloWave/BuildLinux/main.cpp b/HelloWave/BuildLinux/main.cpp index 93fdbeafa8d8a20cb408d401a95b8c0f8a10ecd5..94b23dbed0d1a360c82a2e7c390cb8f648d3d031 100644 --- a/HelloWave/BuildLinux/main.cpp +++ b/HelloWave/BuildLinux/main.cpp @@ -10,7 +10,7 @@ #include #include -extern "C" void startHelloWave(void* phy_fb, int width, int height, int color_bytes, struct EXTERNAL_GFX_OP* gfx_op); +extern "C" void startHelloWave(void* phy_fb, int width, int height, int color_bytes, struct DISPLAY_DRIVER* driver); extern void init_std_io(); static void* get_embeded_fb_in_display_app(int shared_id); diff --git a/HelloWave/BuildMFC/HelloWaveDlg.cpp b/HelloWave/BuildMFC/HelloWaveDlg.cpp index 9909b714ba06d139a4fd619121fd52ec308703ed..1cc16c3911464707ff2f0c72a5507a173bccc421 100644 Binary files a/HelloWave/BuildMFC/HelloWaveDlg.cpp and b/HelloWave/BuildMFC/HelloWaveDlg.cpp differ diff --git a/HelloWave/BuildMFC/HelloWaveDlg.h b/HelloWave/BuildMFC/HelloWaveDlg.h index 2586cd5bf73ac2e570ba60a5ec59f2879a506d6d..d365fecfcc7bc9e00953b0c3bcdf87804094edba 100644 Binary files a/HelloWave/BuildMFC/HelloWaveDlg.h and b/HelloWave/BuildMFC/HelloWaveDlg.h differ diff --git a/HelloWave/BuildSTM32F103-Keil/USER/main.c b/HelloWave/BuildSTM32F103-Keil/USER/main.c index 3112316c82541588119b6a7801c70dea58fce944..85e1c907e31738f682b94cbfcd8be9b19ec31707 100644 --- a/HelloWave/BuildSTM32F103-Keil/USER/main.c +++ b/HelloWave/BuildSTM32F103-Keil/USER/main.c @@ -15,12 +15,12 @@ void gfx_draw_pixel(int x, int y, unsigned int rgb) //void gfx_fill_rect(int x0, int y0, int x1, int y1, unsigned int rgb){} //UI entry -struct EXTERNAL_GFX_OP +struct DISPLAY_DRIVER { void (*draw_pixel)(int x, int y, unsigned int rgb); void (*fill_rect)(int x0, int y0, int x1, int y1, unsigned int rgb); -} my_gfx_op; -extern void startHelloWave(void* phy_fb, int width, int height, int color_bytes, struct EXTERNAL_GFX_OP* gfx_op); +} my_driver; +extern void startHelloWave(void* phy_fb, int width, int height, int color_bytes, struct DISPLAY_DRIVER* driver); int main(void) { @@ -30,8 +30,8 @@ int main(void) LCD_Init(); //Link your LCD driver & start UI: - my_gfx_op.draw_pixel = gfx_draw_pixel; - my_gfx_op.fill_rect = NULL;//gfx_fill_rect; - startHelloWave(NULL, 240, 320, 2, &my_gfx_op); + my_driver.draw_pixel = gfx_draw_pixel; + my_driver.fill_rect = NULL;//gfx_fill_rect; + startHelloWave(NULL, 240, 320, 2, &my_driver); while(1); } diff --git a/HelloWave/BuildWin32/HelloWave.cpp b/HelloWave/BuildWin32/HelloWave.cpp index 9f3691066b96898a81528696de6b9bca04ad8a0a..7cb5bb43c97f893a6e1f1aa72d7acecc1f99a39b 100644 --- a/HelloWave/BuildWin32/HelloWave.cpp +++ b/HelloWave/BuildWin32/HelloWave.cpp @@ -161,7 +161,7 @@ LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam) } //////////////////////// HelloWave Interface //////////////////////// -extern "C" void startHelloWave(void* phy_fb, int width, int height, int color_bytes, struct EXTERNAL_GFX_OP* gfx_op); +extern "C" void startHelloWave(void* phy_fb, int width, int height, int color_bytes, struct DISPLAY_DRIVER* driver); DWORD WINAPI ThreadHelloWave(LPVOID pParam) { diff --git a/HelloWave/UIcode/GuiLite.h b/HelloWave/UIcode/GuiLite.h index c4fc88a51476d2c8309c3e55e1270e13784fc510..80550e1632ad7bc82541a2edbb0f7f8f5937954f 100644 --- a/HelloWave/UIcode/GuiLite.h +++ b/HelloWave/UIcode/GuiLite.h @@ -1,107 +1,94 @@ #pragma once - -#define REAL_TIME_TASK_CYCLE_MS 50 -#define MAX(a,b) (((a)>(b))?(a):(b)) -#define MIN(a,b) (((a)<(b))?(a):(b)) - -#define GL_ARGB(a, r, g, b) ((((unsigned int)(a)) << 24) | (((unsigned int)(r)) << 16) | (((unsigned int)(g)) << 8) | ((unsigned int)(b))) -#define GL_ARGB_A(rgb) ((((unsigned int)(rgb)) >> 24) & 0xFF) - -#define GL_RGB(r, g, b) ((0xFF << 24) | (((unsigned int)(r)) << 16) | (((unsigned int)(g)) << 8) | ((unsigned int)(b))) -#define GL_RGB_R(rgb) ((((unsigned int)(rgb)) >> 16) & 0xFF) -#define GL_RGB_G(rgb) ((((unsigned int)(rgb)) >> 8) & 0xFF) -#define GL_RGB_B(rgb) (((unsigned int)(rgb)) & 0xFF) -#define GL_RGB_32_to_16(rgb) (((((unsigned int)(rgb)) & 0xFF) >> 3) | ((((unsigned int)(rgb)) & 0xFC00) >> 5) | ((((unsigned int)(rgb)) & 0xF80000) >> 8)) -#define GL_RGB_16_to_32(rgb) ((0xFF << 24) | ((((unsigned int)(rgb)) & 0x1F) << 3) | ((((unsigned int)(rgb)) & 0x7E0) << 5) | ((((unsigned int)(rgb)) & 0xF800) << 8)) - -#define ALIGN_HCENTER 0x00000000L -#define ALIGN_LEFT 0x01000000L -#define ALIGN_RIGHT 0x02000000L -#define ALIGN_HMASK 0x03000000L - -#define ALIGN_VCENTER 0x00000000L -#define ALIGN_TOP 0x00100000L -#define ALIGN_BOTTOM 0x00200000L -#define ALIGN_VMASK 0x00300000L - -typedef struct -{ - unsigned short year; - unsigned short month; - unsigned short date; - unsigned short day; - unsigned short hour; - unsigned short minute; - unsigned short second; -}T_TIME; - -void register_debug_function(void(*my_assert)(const char* file, int line), void(*my_log_out)(const char* log)); -void _assert(const char* file, int line); -#define ASSERT(condition) \ - do{ \ - if(!(condition))_assert(__FILE__, __LINE__);\ - }while(0) -void log_out(const char* log); - -long get_time_in_second(); -T_TIME second_to_day(long second); -T_TIME get_time(); - -void start_real_timer(void (*func)(void* arg)); -void register_timer(int milli_second, void func(void* param), void* param); - -unsigned int get_cur_thread_id(); -void create_thread(unsigned long* thread_id, void* attr, void *(*start_routine) (void *), void* arg); -void thread_sleep(unsigned int milli_seconds); -int build_bmp(const char *filename, unsigned int width, unsigned int height, unsigned char *data); - -#define FIFO_BUFFER_LEN 1024 -class c_fifo -{ -public: - c_fifo(); - int read(void* buf, int len); - int write(void* buf, int len); -private: - unsigned char m_buf[FIFO_BUFFER_LEN]; - int m_head; - int m_tail; - void* m_read_sem; - void* m_write_mutex; -}; - -class c_rect -{ -public: - c_rect(){ m_left = m_top = m_right = m_bottom = -1; } - c_rect(int left, int top, int width, int height) - { - set_rect(left, top, width, height); - } - void set_rect(int left, int top, int width, int height) - { - ASSERT(width > 0 && height > 0); - m_left = left; - m_top = top; - m_right = left + width - 1; - m_bottom = top + height -1; - } - bool pt_in_rect(int x, int y) const - { - return x >= m_left && x <= m_right && y >= m_top && y <= m_bottom; - } - int operator==(const c_rect& rect) const - { - return (m_left == rect.m_left) && (m_top == rect.m_top) && (m_right == rect.m_right) && (m_bottom == rect.m_bottom); - } - int width() const { return m_right - m_left + 1; } - int height() const { return m_bottom - m_top + 1 ; } - - int m_left; - int m_top; - int m_right; - int m_bottom; -}; +#define REAL_TIME_TASK_CYCLE_MS 50 +#define MAX(a,b) (((a)>(b))?(a):(b)) +#define MIN(a,b) (((a)<(b))?(a):(b)) +#define GL_ARGB(a, r, g, b) ((((unsigned int)(a)) << 24) | (((unsigned int)(r)) << 16) | (((unsigned int)(g)) << 8) | ((unsigned int)(b))) +#define GL_ARGB_A(rgb) ((((unsigned int)(rgb)) >> 24) & 0xFF) +#define GL_RGB(r, g, b) ((0xFF << 24) | (((unsigned int)(r)) << 16) | (((unsigned int)(g)) << 8) | ((unsigned int)(b))) +#define GL_RGB_R(rgb) ((((unsigned int)(rgb)) >> 16) & 0xFF) +#define GL_RGB_G(rgb) ((((unsigned int)(rgb)) >> 8) & 0xFF) +#define GL_RGB_B(rgb) (((unsigned int)(rgb)) & 0xFF) +#define GL_RGB_32_to_16(rgb) (((((unsigned int)(rgb)) & 0xFF) >> 3) | ((((unsigned int)(rgb)) & 0xFC00) >> 5) | ((((unsigned int)(rgb)) & 0xF80000) >> 8)) +#define GL_RGB_16_to_32(rgb) ((0xFF << 24) | ((((unsigned int)(rgb)) & 0x1F) << 3) | ((((unsigned int)(rgb)) & 0x7E0) << 5) | ((((unsigned int)(rgb)) & 0xF800) << 8)) +#define ALIGN_HCENTER 0x00000000L +#define ALIGN_LEFT 0x01000000L +#define ALIGN_RIGHT 0x02000000L +#define ALIGN_HMASK 0x03000000L +#define ALIGN_VCENTER 0x00000000L +#define ALIGN_TOP 0x00100000L +#define ALIGN_BOTTOM 0x00200000L +#define ALIGN_VMASK 0x00300000L +typedef struct +{ + unsigned short year; + unsigned short month; + unsigned short date; + unsigned short day; + unsigned short hour; + unsigned short minute; + unsigned short second; +}T_TIME; +void register_debug_function(void(*my_assert)(const char* file, int line), void(*my_log_out)(const char* log)); +void _assert(const char* file, int line); +#define ASSERT(condition) \ + do{ \ + if(!(condition))_assert(__FILE__, __LINE__);\ + }while(0) +void log_out(const char* log); +long get_time_in_second(); +T_TIME second_to_day(long second); +T_TIME get_time(); +void start_real_timer(void (*func)(void* arg)); +void register_timer(int milli_second, void func(void* param), void* param); +unsigned int get_cur_thread_id(); +void create_thread(unsigned long* thread_id, void* attr, void *(*start_routine) (void *), void* arg); +void thread_sleep(unsigned int milli_seconds); +int build_bmp(const char *filename, unsigned int width, unsigned int height, unsigned char *data); +#define FIFO_BUFFER_LEN 1024 +class c_fifo +{ +public: + c_fifo(); + int read(void* buf, int len); + int write(void* buf, int len); +private: + unsigned char m_buf[FIFO_BUFFER_LEN]; + int m_head; + int m_tail; + void* m_read_sem; + void* m_write_mutex; +}; +class c_rect +{ +public: + c_rect(){ m_left = m_top = m_right = m_bottom = -1; } + c_rect(int left, int top, int width, int height) + { + set_rect(left, top, width, height); + } + void set_rect(int left, int top, int width, int height) + { + ASSERT(width > 0 && height > 0); + m_left = left; + m_top = top; + m_right = left + width - 1; + m_bottom = top + height -1; + } + bool pt_in_rect(int x, int y) const + { + return x >= m_left && x <= m_right && y >= m_top && y <= m_bottom; + } + int operator==(const c_rect& rect) const + { + return (m_left == rect.m_left) && (m_top == rect.m_top) && (m_right == rect.m_right) && (m_bottom == rect.m_bottom); + } + int width() const { return m_right - m_left + 1; } + int height() const { return m_bottom - m_top + 1 ; } + int m_left; + int m_top; + int m_right; + int m_bottom; +}; //BITMAP typedef struct struct_bitmap_info { @@ -238,7 +225,7 @@ typedef enum Z_ORDER_LEVEL_2,//highest graphic level Z_ORDER_LEVEL_MAX }Z_ORDER_LEVEL; -struct EXTERNAL_GFX_OP +struct DISPLAY_DRIVER { void(*draw_pixel)(int x, int y, unsigned int rgb); void(*fill_rect)(int x0, int y0, int x1, int y1, unsigned int rgb); @@ -247,18 +234,19 @@ class c_surface; class c_display { friend class c_surface; public: - inline c_display(void* phy_fb, int display_width, int display_height, int surface_width, int surface_height, unsigned int color_bytes, int surface_cnt, EXTERNAL_GFX_OP* gfx_op = 0);//multiple surface or surface_no_fb - inline c_display(void* phy_fb, int display_width, int display_height, c_surface* surface);//single custom surface - inline c_surface* alloc_surface(Z_ORDER_LEVEL max_zorder, c_rect layer_rect = c_rect());//for multiple surfaces + inline c_display(void* phy_fb, int display_width, int display_height, c_surface* surface, DISPLAY_DRIVER* driver = 0);//single custom surface + inline c_display(void* phy_fb, int display_width, int display_height, int surface_width, int surface_height, unsigned int color_bytes, int surface_cnt, DISPLAY_DRIVER* driver = 0);//multiple surface + inline c_surface* alloc_surface(Z_ORDER_LEVEL max_zorder, c_rect layer_rect = c_rect());//for slide group inline int swipe_surface(c_surface* s0, c_surface* s1, int x0, int x1, int y0, int y1, int offset); int get_width() { return m_width; } int get_height() { return m_height; } + void* get_phy_fb() { return m_phy_fb; } void* get_updated_fb(int* width, int* height, bool force_update = false) { if (width && height) { - *width = get_width(); - *height = get_height(); + *width = m_width; + *height = m_height; } if (force_update) { @@ -277,35 +265,123 @@ public: { return -1; } - int width = get_width(); - int height = get_height(); //16 bits framebuffer if (m_color_bytes == 2) { - return build_bmp(file_name, width, height, (unsigned char*)m_phy_fb); + return build_bmp(file_name, m_width, m_height, (unsigned char*)m_phy_fb); } //32 bits framebuffer - unsigned short* p_bmp565_data = new unsigned short[width * height]; + unsigned short* p_bmp565_data = new unsigned short[m_width * m_height]; unsigned int* p_raw_data = (unsigned int*)m_phy_fb; - for (int i = 0; i < width * height; i++) + for (int i = 0; i < m_width * m_height; i++) { unsigned int rgb = *p_raw_data++; p_bmp565_data[i] = GL_RGB_32_to_16(rgb); } - int ret = build_bmp(file_name, width, height, (unsigned char*)p_bmp565_data); + int ret = build_bmp(file_name, m_width, m_height, (unsigned char*)p_bmp565_data); delete[]p_bmp565_data; return ret; } -private: - int m_width; //in pixels - int m_height; //in pixels - int m_color_bytes; //16 bits, 32 bits only - void* m_phy_fb; //physical framebuffer +protected: + virtual void draw_pixel(int x, int y, unsigned int rgb) + { + if ((x >= m_width) || (y >= m_height)) { return; } + if (m_driver && m_driver->draw_pixel) + { + return m_driver->draw_pixel(x, y, rgb); + } + if (m_color_bytes == 2) + { + ((unsigned short*)m_phy_fb)[y * m_width + x] = GL_RGB_32_to_16(rgb); + } + else + { + ((unsigned int*)m_phy_fb)[y * m_width + x] = rgb; + } + } + virtual void fill_rect(int x0, int y0, int x1, int y1, unsigned int rgb) + { + if (m_driver && m_driver->fill_rect) + { + return m_driver->fill_rect(x0, y0, x1, y1, rgb); + } + if (m_driver && m_driver->draw_pixel) + { + for (int y = y0; y <= y1; y++) + { + for (int x = x0; x <= x1; x++) + { + m_driver->draw_pixel(x, y, rgb); + } + } + return; + } + register int _width = m_width; + register int _height = m_height; + int x, y; + if (m_color_bytes == 2) + { + unsigned short* phy_fb; + unsigned int rgb_16 = GL_RGB_32_to_16(rgb); + for (y = y0; y <= y1; y++) + { + phy_fb = &((unsigned short*)m_phy_fb)[y * _width + x0]; + for (x = x0; x <= x1; x++) + { + if ((x < _width) && (y < _height)) + { + *phy_fb++ = rgb_16; + } + } + } + } + else + { + unsigned int* phy_fb; + for (y = y0; y <= y1; y++) + { + phy_fb = &((unsigned int*)m_phy_fb)[y * _width + x0]; + for (x = x0; x <= x1; x++) + { + if ((x < _width) && (y < _height)) + { + *phy_fb++ = rgb; + } + } + } + } + } + virtual int flush_screen(int left, int top, int right, int bottom, void* fb, int fb_width) + { + if ((0 == m_phy_fb) || (0 == fb)) + { + return -1; + } + register int _width = m_width; + register int _height = m_height; + left = (left >= _width) ? (_width - 1) : left; + right = (right >= _width) ? (_width - 1) : right; + top = (top >= _height) ? (_height - 1) : top; + bottom = (bottom >= _height) ? (_height - 1) : bottom; + for (int y = top; y < bottom; y++) + { + void* s_addr = (char*)fb + ((y * fb_width + left) * m_color_bytes); + void* d_addr = (char*)m_phy_fb + ((y * _width + left) * m_color_bytes); + memcpy(d_addr, s_addr, (right - left) * m_color_bytes); + } + return 0; + } + int m_width; //in pixels + int m_height; //in pixels + int m_color_bytes; //16/32 bits for default + void* m_phy_fb; //physical framebuffer for default + struct DISPLAY_DRIVER* m_driver; //Rendering by external method without default physical framebuffer int m_phy_read_index; int m_phy_write_index; c_surface* m_surface_group[SURFACE_CNT_MAX]; int m_surface_cnt; //surface count int m_surface_index; + }; class c_layer { @@ -317,12 +393,10 @@ public: class c_surface { friend class c_display; friend class c_bitmap_operator; public: - c_surface(unsigned int width, unsigned int height, unsigned int color_bytes, Z_ORDER_LEVEL max_zorder = Z_ORDER_LEVEL_0, c_rect overlpa_rect = c_rect()) : m_width(width), m_height(height), m_color_bytes(color_bytes), m_fb(0), m_is_active(false), m_top_zorder(Z_ORDER_LEVEL_0), m_phy_fb(0), m_phy_write_index(0), m_display(0) + c_surface(unsigned int width, unsigned int height, unsigned int color_bytes, Z_ORDER_LEVEL max_zorder = Z_ORDER_LEVEL_0, c_rect overlpa_rect = c_rect()) : m_width(width), m_height(height), m_color_bytes(color_bytes), m_fb(0), m_is_active(false), m_top_zorder(Z_ORDER_LEVEL_0), m_phy_write_index(0), m_display(0) { (overlpa_rect == c_rect()) ? set_surface(max_zorder, c_rect(0, 0, width - 1, height - 1)) : set_surface(max_zorder, overlpa_rect); } - int get_width() { return m_width; } - int get_height() { return m_height; } unsigned int get_pixel(int x, int y, unsigned int z_order) { if (x >= m_width || y >= m_height || x < 0 || y < 0 || z_order >= Z_ORDER_LEVEL_MAX) @@ -332,15 +406,15 @@ public: } if (m_layers[z_order].fb) { - return (m_color_bytes == 4) ? ((unsigned int*)(m_layers[z_order].fb))[y * m_width + x] : GL_RGB_16_to_32(((unsigned short*)(m_layers[z_order].fb))[y * m_width + x]); + return (m_color_bytes == 2) ? GL_RGB_16_to_32(((unsigned short*)(m_layers[z_order].fb))[y * m_width + x]) : ((unsigned int*)(m_layers[z_order].fb))[y * m_width + x]; } else if (m_fb) { - return (m_color_bytes == 4) ? ((unsigned int*)m_fb)[y * m_width + x] : GL_RGB_16_to_32(((unsigned short*)m_fb)[y * m_width + x]); + return (m_color_bytes == 2) ? GL_RGB_16_to_32(((unsigned short*)m_fb)[y * m_width + x]) : ((unsigned int*)m_fb)[y * m_width + x]; } - else if (m_phy_fb) + else if (m_display->m_phy_fb) { - return (m_color_bytes == 4) ? ((unsigned int*)m_phy_fb)[y * m_width + x] : GL_RGB_16_to_32(((unsigned short*)m_phy_fb)[y * m_width + x]); + return (m_color_bytes == 2) ? GL_RGB_16_to_32(((unsigned short*)m_display->m_phy_fb)[y * m_width + x]) : ((unsigned int*)m_display->m_phy_fb)[y * m_width + x]; } return 0; } @@ -357,7 +431,7 @@ public: } if (z_order == m_max_zorder) { - return draw_pixel_on_fb(x, y, rgb); + return draw_pixel_low_level(x, y, rgb); } if (z_order > (unsigned int)m_top_zorder) @@ -367,19 +441,19 @@ public: if (m_layers[z_order].rect.pt_in_rect(x, y)) { c_rect layer_rect = m_layers[z_order].rect; - if (m_color_bytes == 4) + if (m_color_bytes == 2) { - ((unsigned int*)(m_layers[z_order].fb))[(x - layer_rect.m_left) + (y - layer_rect.m_top) * layer_rect.width()] = rgb; + ((unsigned short*)(m_layers[z_order].fb))[(x - layer_rect.m_left) + (y - layer_rect.m_top) * layer_rect.width()] = GL_RGB_32_to_16(rgb); } else { - ((unsigned short*)(m_layers[z_order].fb))[(x - layer_rect.m_left) + (y - layer_rect.m_top) * layer_rect.width()] = GL_RGB_32_to_16(rgb); + ((unsigned int*)(m_layers[z_order].fb))[(x - layer_rect.m_left) + (y - layer_rect.m_top) * layer_rect.width()] = rgb; } } if (z_order == m_top_zorder) { - return draw_pixel_on_fb(x, y, rgb); + return draw_pixel_low_level(x, y, rgb); } bool be_overlapped = false; for (unsigned int tmp_z_order = Z_ORDER_LEVEL_MAX - 1; tmp_z_order > z_order; tmp_z_order--) @@ -392,7 +466,7 @@ public: } if (!be_overlapped) { - draw_pixel_on_fb(x, y, rgb); + draw_pixel_low_level(x, y, rgb); } } virtual void fill_rect(int x0, int y0, int x1, int y1, unsigned int rgb, unsigned int z_order) @@ -403,7 +477,7 @@ public: y1 = (y1 > (m_height - 1)) ? (m_height - 1) : y1; if (z_order == m_max_zorder) { - return fill_rect_on_fb(x0, y0, x1, y1, rgb); + return fill_rect_low_level(x0, y0, x1, y1, rgb); } if (z_order == m_top_zorder) { @@ -416,18 +490,18 @@ public: { if (layer_rect.pt_in_rect(x, y)) { - if (m_color_bytes == 4) + if (m_color_bytes == 2) { - ((unsigned int*)m_layers[z_order].fb)[(y - layer_rect.m_top) * layer_rect.width() + (x - layer_rect.m_left)] = rgb; + ((unsigned short*)m_layers[z_order].fb)[(y - layer_rect.m_top) * layer_rect.width() + (x - layer_rect.m_left)] = rgb_16; } else { - ((unsigned short*)m_layers[z_order].fb)[(y - layer_rect.m_top) * layer_rect.width() + (x - layer_rect.m_left)] = rgb_16; + ((unsigned int*)m_layers[z_order].fb)[(y - layer_rect.m_top) * layer_rect.width() + (x - layer_rect.m_left)] = rgb; } } } } - return fill_rect_on_fb(x0, y0, x1, y1, rgb); + return fill_rect_low_level(x0, y0, x1, y1, rgb); } for (; y0 <= y1; y0++) { @@ -499,27 +573,16 @@ public: } int flush_screen(int left, int top, int right, int bottom) { - if (left < 0 || left >= m_width || right < 0 || right >= m_width || - top < 0 || top >= m_height || bottom < 0 || bottom >= m_height) - { - ASSERT(false); - } - if (!m_is_active || (0 == m_phy_fb) || (0 == m_fb)) + if (!m_is_active) { return -1; } - int display_width = m_display->get_width(); - int display_height = m_display->get_height(); - left = (left >= display_width) ? (display_width - 1) : left; - right = (right >= display_width) ? (display_width - 1) : right; - top = (top >= display_height) ? (display_height - 1) : top; - bottom = (bottom >= display_height) ? (display_height - 1) : bottom; - for (int y = top; y < bottom; y++) + if (left < 0 || left >= m_width || right < 0 || right >= m_width || + top < 0 || top >= m_height || bottom < 0 || bottom >= m_height) { - void* s_addr = (char*)m_fb + ((y * m_width + left) * m_color_bytes); - void* d_addr = (char*)m_phy_fb + ((y * display_width + left) * m_color_bytes); - memcpy(d_addr, s_addr, (right - left) * m_color_bytes); + ASSERT(false); } + m_display->flush_screen(left, top, right, bottom, m_fb, m_width); *m_phy_write_index = *m_phy_write_index + 1; return 0; } @@ -537,90 +600,62 @@ public: { for (int x = rect.m_left; x <= rect.m_right; x++) { - unsigned int rgb = (m_color_bytes == 4) ? ((unsigned int*)fb)[(x - layer_rect.m_left) + (y - layer_rect.m_top) * width] : GL_RGB_16_to_32(((unsigned short*)fb)[(x - layer_rect.m_left) + (y - layer_rect.m_top) * width]); - draw_pixel_on_fb(x, y, rgb); + unsigned int rgb = (m_color_bytes == 2) ? GL_RGB_16_to_32(((unsigned short*)fb)[(x - layer_rect.m_left) + (y - layer_rect.m_top) * width]) : ((unsigned int*)fb)[(x - layer_rect.m_left) + (y - layer_rect.m_top) * width]; + draw_pixel_low_level(x, y, rgb); } } return 0; } void set_active(bool flag) { m_is_active = flag; } protected: - virtual void fill_rect_on_fb(int x0, int y0, int x1, int y1, unsigned int rgb) - { - int display_width = m_display->get_width(); - int display_height = m_display->get_height(); - if (m_color_bytes == 4) + virtual void fill_rect_low_level(int x0, int y0, int x1, int y1, unsigned int rgb) + {//fill rect on framebuffer of surface + int x, y; + if (m_color_bytes == 2) { - int x; - unsigned int* fb, * phy_fb; - for (; y0 <= y1; y0++) + unsigned short* fb; + unsigned int rgb_16 = GL_RGB_32_to_16(rgb); + for (y = y0; y <= y1; y++) { - x = x0; - fb = m_fb ? &((unsigned int*)m_fb)[y0 * m_width + x] : 0; - phy_fb = &((unsigned int*)m_phy_fb)[y0 * display_width + x]; - *m_phy_write_index = *m_phy_write_index + 1; - for (; x <= x1; x++) + fb = m_fb ? &((unsigned short*)m_fb)[y * m_width + x0] : 0; + if (!fb) { break; } + for (x = x0; x <= x1; x++) { - if (fb) - { - *fb++ = rgb; - } - if (m_is_active && (x < display_width) && (y0 < display_height)) - { - *phy_fb++ = rgb; - } + *fb++ = rgb_16; } } } - else if (m_color_bytes == 2) + else { - int x; - unsigned short* fb, * phy_fb; - rgb = GL_RGB_32_to_16(rgb); - for (; y0 <= y1; y0++) + unsigned int* fb; + for (y = y0; y <= y1; y++) { - x = x0; - fb = m_fb ? &((unsigned short*)m_fb)[y0 * m_width + x] : 0; - phy_fb = &((unsigned short*)m_phy_fb)[y0 * display_width + x]; - *m_phy_write_index = *m_phy_write_index + 1; - for (; x <= x1; x++) + fb = m_fb ? &((unsigned int*)m_fb)[y * m_width + x0] : 0; + if (!fb) { break; } + for (x = x0; x <= x1; x++) { - if (fb) - { - *fb++ = rgb; - } - if (m_is_active && (x < display_width) && (y0 < display_height)) - { - *phy_fb++ = rgb; - } + *fb++ = rgb; } } } + if (!m_is_active) { return; } + m_display->fill_rect(x0, y0, x1, y1, rgb); + *m_phy_write_index = *m_phy_write_index + 1; } - virtual void draw_pixel_on_fb(int x, int y, unsigned int rgb) + virtual void draw_pixel_low_level(int x, int y, unsigned int rgb) { if (m_fb) - { - (m_color_bytes == 4) ? ((unsigned int*)m_fb)[y * m_width + x] = rgb : ((unsigned short*)m_fb)[y * m_width + x] = GL_RGB_32_to_16(rgb); - } - if (m_is_active && (x < m_display->get_width()) && (y < m_display->get_height())) - { - if (m_color_bytes == 4) - { - ((unsigned int*)m_phy_fb)[y * (m_display->get_width()) + x] = rgb; - } - else - { - ((unsigned short*)m_phy_fb)[y * (m_display->get_width()) + x] = GL_RGB_32_to_16(rgb); - } - *m_phy_write_index = *m_phy_write_index + 1; + {//draw pixel on framebuffer of surface + (m_color_bytes == 2) ? ((unsigned short*)m_fb)[y * m_width + x] = GL_RGB_32_to_16(rgb): ((unsigned int*)m_fb)[y * m_width + x] = rgb; } + if (!m_is_active) { return; } + m_display->draw_pixel(x, y, rgb); + *m_phy_write_index = *m_phy_write_index + 1; } void attach_display(c_display* display) { ASSERT(display); m_display = display; - m_phy_fb = display->m_phy_fb; m_phy_write_index = &display->m_phy_write_index; } void set_surface(Z_ORDER_LEVEL max_z_order, c_rect layer_rect) @@ -638,87 +673,22 @@ protected: } int m_width; //in pixels int m_height; //in pixels - int m_color_bytes; //16 bits, 32 bits only + int m_color_bytes; //16 bits, 32 bits for default void* m_fb; //frame buffer you could see c_layer m_layers[Z_ORDER_LEVEL_MAX];//all graphic layers bool m_is_active; //active flag Z_ORDER_LEVEL m_max_zorder; //the highest graphic layer the surface will have Z_ORDER_LEVEL m_top_zorder; //the current highest graphic layer the surface have - void* m_phy_fb; //physical framebufer int* m_phy_write_index; c_display* m_display; }; -class c_surface_no_fb : public c_surface {//No physical framebuffer, render with external graphic interface - friend class c_display; -public: - c_surface_no_fb(unsigned int width, unsigned int height, unsigned int color_bytes, struct EXTERNAL_GFX_OP* gfx_op, Z_ORDER_LEVEL max_zorder = Z_ORDER_LEVEL_0, c_rect overlpa_rect = c_rect()) : c_surface(width, height, color_bytes, max_zorder, overlpa_rect), m_gfx_op(gfx_op) {} -protected: - virtual void fill_rect_on_fb(int x0, int y0, int x1, int y1, unsigned int rgb) - { - if (!m_gfx_op) - { - return; - } - if (m_gfx_op->fill_rect) - { - return m_gfx_op->fill_rect(x0, y0, x1, y1, rgb); - } - if (m_gfx_op->draw_pixel && m_is_active) - { - for (int y = y0; y <= y1; y++) - { - for (int x = x0; x <= x1; x++) - { - m_gfx_op->draw_pixel(x, y, rgb); - } - } - } - if (!m_fb) { return; } - if (m_color_bytes == 4) - { - unsigned int* fb; - for (int y = y0; y <= y1; y++) - { - fb = &((unsigned int*)m_fb)[y0 * m_width + x0]; - for (int x = x0; x <= x1; x++) - { - *fb++ = rgb; - } - } - } - else if (m_color_bytes == 2) - { - unsigned short* fb; - rgb = GL_RGB_32_to_16(rgb); - for (int y = y0; y <= y1; y++) - { - fb = &((unsigned short*)m_fb)[y0 * m_width + x0]; - for (int x = x0; x <= x1; x++) - { - *fb++ = rgb; - } - } - } - } - virtual void draw_pixel_on_fb(int x, int y, unsigned int rgb) - { - if (m_gfx_op && m_gfx_op->draw_pixel && m_is_active) - { - m_gfx_op->draw_pixel(x, y, rgb); - } - if (!m_fb) { return; } - if (m_color_bytes == 4) - { - ((unsigned int*)m_fb)[y * m_width + x] = rgb; - } - else if (m_color_bytes == 2) - { - ((unsigned short*)m_fb)[y * m_width + x] = GL_RGB_32_to_16(rgb); - } - } - struct EXTERNAL_GFX_OP* m_gfx_op;//Rendering by external method -}; -inline c_display::c_display(void* phy_fb, int display_width, int display_height, int surface_width, int surface_height, unsigned int color_bytes, int surface_cnt, EXTERNAL_GFX_OP* gfx_op) : m_width(display_width), m_height(display_height), m_color_bytes(color_bytes), m_phy_fb(phy_fb), m_phy_read_index(0), m_phy_write_index(0), m_surface_cnt(surface_cnt), m_surface_index(0) +inline c_display::c_display(void* phy_fb, int display_width, int display_height, c_surface* surface, DISPLAY_DRIVER* driver) : m_phy_fb(phy_fb), m_width(display_width), m_height(display_height), m_driver(driver), m_phy_read_index(0), m_phy_write_index(0), m_surface_cnt(1), m_surface_index(0) +{ + m_color_bytes = surface->m_color_bytes; + surface->m_is_active = true; + (m_surface_group[0] = surface)->attach_display(this); +} +inline c_display::c_display(void* phy_fb, int display_width, int display_height, int surface_width, int surface_height, unsigned int color_bytes, int surface_cnt, DISPLAY_DRIVER* driver) : m_phy_fb(phy_fb), m_width(display_width), m_height(display_height), m_color_bytes(color_bytes), m_phy_read_index(0), m_phy_write_index(0), m_surface_cnt(surface_cnt), m_driver(driver), m_surface_index(0) { ASSERT(color_bytes == 2 || color_bytes == 4); ASSERT(m_surface_cnt <= SURFACE_CNT_MAX); @@ -726,16 +696,10 @@ inline c_display::c_display(void* phy_fb, int display_width, int display_height, for (int i = 0; i < m_surface_cnt; i++) { - m_surface_group[i] = (phy_fb) ? new c_surface(surface_width, surface_height, color_bytes) : new c_surface_no_fb(surface_width, surface_height, color_bytes, gfx_op); + m_surface_group[i] = new c_surface(surface_width, surface_height, color_bytes); m_surface_group[i]->attach_display(this); } } -inline c_display::c_display(void* phy_fb, int display_width, int display_height, c_surface* surface) : m_width(display_width), m_height(display_height), m_phy_fb(phy_fb), m_phy_read_index(0), m_phy_write_index(0), m_surface_cnt(1), m_surface_index(0) -{ - m_color_bytes = surface->m_color_bytes; - surface->m_is_active = true; - (m_surface_group[0] = surface)->attach_display(this); -} inline c_surface* c_display::alloc_surface(Z_ORDER_LEVEL max_zorder, c_rect layer_rect) { ASSERT(max_zorder < Z_ORDER_LEVEL_MAX && m_surface_index < m_surface_cnt); @@ -744,8 +708,8 @@ inline c_surface* c_display::alloc_surface(Z_ORDER_LEVEL max_zorder, c_rect laye } inline int c_display::swipe_surface(c_surface* s0, c_surface* s1, int x0, int x1, int y0, int y1, int offset) { - int surface_width = s0->get_width(); - int surface_height = s0->get_height(); + register int surface_width = s0->m_width; + register int surface_height = s0->m_height; if (offset < 0 || offset > surface_width || y0 < 0 || y0 >= surface_height || y1 < 0 || y1 >= surface_height || x0 < 0 || x0 >= surface_width || x1 < 0 || x1 >= surface_width) { @@ -767,46 +731,46 @@ inline int c_display::swipe_surface(c_surface* s0, c_surface* s1, int x0, int x1 for (int y = y0; y <= y1; y++) { //Left surface - char* addr_s = ((char*)(s0->m_fb) + (y * (s0->get_width()) + x0 + offset) * m_color_bytes); + char* addr_s = ((char*)(s0->m_fb) + (y * surface_width + x0 + offset) * m_color_bytes); char* addr_d = ((char*)(m_phy_fb)+(y * m_width + x0) * m_color_bytes); memcpy(addr_d, addr_s, (width - offset) * m_color_bytes); //Right surface - addr_s = ((char*)(s1->m_fb) + (y * (s1->get_width()) + x0) * m_color_bytes); + addr_s = ((char*)(s1->m_fb) + (y * surface_width + x0) * m_color_bytes); addr_d = ((char*)(m_phy_fb)+(y * m_width + x0 + (width - offset)) * m_color_bytes); memcpy(addr_d, addr_s, offset * m_color_bytes); } } - else if (m_color_bytes == 4) + else if (m_color_bytes == 2) { - void(*draw_pixel)(int x, int y, unsigned int rgb) = ((c_surface_no_fb*)s0)->m_gfx_op->draw_pixel; + void(*draw_pixel)(int x, int y, unsigned int rgb) = m_driver->draw_pixel; for (int y = y0; y <= y1; y++) { //Left surface for (int x = x0; x <= (x1 - offset); x++) { - draw_pixel(x, y, ((unsigned int*)s0->m_fb)[y * m_width + x + offset]); + draw_pixel(x, y, GL_RGB_16_to_32(((unsigned short*)s0->m_fb)[y * m_width + x + offset])); } //Right surface for (int x = x1 - offset; x <= x1; x++) { - draw_pixel(x, y, ((unsigned int*)s1->m_fb)[y * m_width + x + offset - x1 + x0]); + draw_pixel(x, y, GL_RGB_16_to_32(((unsigned short*)s1->m_fb)[y * m_width + x + offset - x1 + x0])); } } } - else if (m_color_bytes == 2) + else //m_color_bytes == 3/4... { - void(*draw_pixel)(int x, int y, unsigned int rgb) = ((c_surface_no_fb*)s0)->m_gfx_op->draw_pixel; + void(*draw_pixel)(int x, int y, unsigned int rgb) = m_driver->draw_pixel; for (int y = y0; y <= y1; y++) { //Left surface for (int x = x0; x <= (x1 - offset); x++) { - draw_pixel(x, y, GL_RGB_16_to_32(((unsigned short*)s0->m_fb)[y * m_width + x + offset])); + draw_pixel(x, y, ((unsigned int*)s0->m_fb)[y * m_width + x + offset]); } //Right surface for (int x = x1 - offset; x <= x1; x++) { - draw_pixel(x, y, GL_RGB_16_to_32(((unsigned short*)s1->m_fb)[y * m_width + x + offset - x1 + x0])); + draw_pixel(x, y, ((unsigned int*)s1->m_fb)[y * m_width + x + offset - x1 + x0]); } } } @@ -3407,22 +3371,12 @@ private: #ifdef GUILITE_ON c_bitmap_operator the_bitmap_op = c_bitmap_operator(); c_image_operator* c_image::image_operator = &the_bitmap_op; +const void* c_theme::s_font_map[FONT_MAX]; +const void* c_theme::s_image_map[IMAGE_MAX]; +unsigned int c_theme::s_color_map[COLOR_MAX]; +c_lattice_font_op the_lattice_font_op = c_lattice_font_op(); +c_font_operator* c_word::fontOperator = &the_lattice_font_op; #endif - -#ifdef GUILITE_ON - -const void* c_theme::s_font_map[FONT_MAX]; -const void* c_theme::s_image_map[IMAGE_MAX]; -unsigned int c_theme::s_color_map[COLOR_MAX]; - -#endif - -#ifdef GUILITE_ON - -c_lattice_font_op the_lattice_font_op = c_lattice_font_op(); -c_font_operator* c_word::fontOperator = &the_lattice_font_op; - -#endif #ifdef GUILITE_ON #if (defined __linux__) || (defined __APPLE__) #include @@ -4264,11 +4218,7 @@ int c_fifo::write(void* buf, int len) #endif #ifdef GUILITE_ON DIALOG_ARRAY c_dialog::ms_the_dialogs[SURFACE_CNT_MAX]; -#endif -#ifdef GUILITE_ON c_keyboard c_edit::s_keyboard; -#endif -#ifdef GUILITE_ON static c_keyboard_button s_key_0, s_key_1, s_key_2, s_key_3, s_key_4, s_key_5, s_key_6, s_key_7, s_key_8, s_key_9; static c_keyboard_button s_key_A, s_key_B, s_key_C, s_key_D, s_key_E, s_key_F, s_key_G, s_key_H, s_key_I, s_key_J; static c_keyboard_button s_key_K, s_key_L, s_key_M, s_key_N, s_key_O, s_key_P, s_key_Q, s_key_R, s_key_S, s_key_T; @@ -4306,12 +4256,12 @@ WND_TREE g_key_board_children[] = {&s_key_B, 'B', 0, ((KEY_WIDTH / 2) + POS_X(5)), POS_Y(2), KEY_WIDTH, KEY_HEIGHT}, {&s_key_N, 'N', 0, ((KEY_WIDTH / 2) + POS_X(6)), POS_Y(2), KEY_WIDTH, KEY_HEIGHT}, {&s_key_M, 'M', 0, ((KEY_WIDTH / 2) + POS_X(7)), POS_Y(2), KEY_WIDTH, KEY_HEIGHT}, - {&s_key_del, 0x7F, 0, ((KEY_WIDTH / 2) + POS_X(8)), POS_Y(2), DEL_WIDTH, KEY_HEIGHT}, + {&s_key_del,0x7F, 0, ((KEY_WIDTH / 2) + POS_X(8)), POS_Y(2), DEL_WIDTH, KEY_HEIGHT}, //Row 4 - {&s_key_esc, 0x1B, 0, POS_X(0), POS_Y(3), ESC_WIDTH, KEY_HEIGHT}, + {&s_key_esc, 0x1B, 0, POS_X(0), POS_Y(3), ESC_WIDTH, KEY_HEIGHT}, {&s_key_num_switch, 0x90, 0, POS_X(2), POS_Y(3), SWITCH_WIDTH, KEY_HEIGHT}, {&s_key_space, ' ', 0, ((KEY_WIDTH / 2) + POS_X(3)), POS_Y(3), SPACE_WIDTH, KEY_HEIGHT}, - {&s_key_dot, '.', 0, ((KEY_WIDTH / 2) + POS_X(6)), POS_Y(3), DOT_WIDTH, KEY_HEIGHT}, + {&s_key_dot, '.', 0, ((KEY_WIDTH / 2) + POS_X(6)), POS_Y(3), DOT_WIDTH, KEY_HEIGHT}, {&s_key_enter, '\n', 0, POS_X(8), POS_Y(3), ENTER_WIDTH, KEY_HEIGHT}, {0,0,0,0,0,0,0} }; @@ -4326,12 +4276,11 @@ WND_TREE g_number_board_children[] = {&s_key_7, '7', 0, POS_X(0), POS_Y(2), KEY_WIDTH, KEY_HEIGHT}, {&s_key_8, '8', 0, POS_X(1), POS_Y(2), KEY_WIDTH, KEY_HEIGHT}, {&s_key_9, '9', 0, POS_X(2), POS_Y(2), KEY_WIDTH, KEY_HEIGHT}, - - {&s_key_esc, 0x1B, 0, POS_X(0), POS_Y(3), KEY_WIDTH, KEY_HEIGHT}, + {&s_key_esc,0x1B, 0, POS_X(0), POS_Y(3), KEY_WIDTH, KEY_HEIGHT}, {&s_key_0, '0', 0, POS_X(1), POS_Y(3), KEY_WIDTH, KEY_HEIGHT}, - {&s_key_dot, '.', 0, POS_X(2), POS_Y(3), KEY_WIDTH, KEY_HEIGHT}, + {&s_key_dot,'.', 0, POS_X(2), POS_Y(3), KEY_WIDTH, KEY_HEIGHT}, {&s_key_del, 0x7F, 0, POS_X(3), POS_Y(0), KEY_WIDTH, KEY_HEIGHT * 2 + 2}, {&s_key_enter,'\n', 0, POS_X(3), POS_Y(2), KEY_WIDTH, KEY_HEIGHT * 2 + 2}, {0,0,0,0,0,0,0} }; -#endif +#endif \ No newline at end of file diff --git a/HelloWave/UIcode/UIcode.cpp b/HelloWave/UIcode/UIcode.cpp index 68e2aceac93d2955e6f9df36bbf26703b2972533..9adcdc5315fdedbfe167a44c9231d2bd2718bf2c 100644 --- a/HelloWave/UIcode/UIcode.cpp +++ b/HelloWave/UIcode/UIcode.cpp @@ -130,24 +130,14 @@ void load_resource() static c_display* s_display; static c_surface* s_surface; -void create_ui(void* phy_fb, int screen_width, int screen_height, int color_bytes, struct EXTERNAL_GFX_OP* gfx_op) +void create_ui(void* phy_fb, int screen_width, int screen_height, int color_bytes, struct DISPLAY_DRIVER* driver) { load_resource(); - - if (phy_fb) - { - static c_surface surface(UI_WIDTH, UI_HEIGHT, color_bytes, Z_ORDER_LEVEL_0); - static c_display display(phy_fb, screen_width, screen_height, &surface); - s_surface = &surface; - s_display = &display; - } - else - {//for MCU without framebuffer - static c_surface_no_fb surface_no_fb(UI_WIDTH, UI_HEIGHT, color_bytes, gfx_op, Z_ORDER_LEVEL_0); - static c_display display(phy_fb, screen_width, screen_height, &surface_no_fb); - s_surface = &surface_no_fb; - s_display = &display; - } + + static c_surface surface(UI_WIDTH, UI_HEIGHT, color_bytes, Z_ORDER_LEVEL_0); + static c_display display(phy_fb, screen_width, screen_height, &surface, driver); + s_surface = &surface; + s_display = &display; s_myUI.set_surface(s_surface); s_myUI.connect(NULL, ID_ROOT, 0, 0, 0, UI_WIDTH, UI_HEIGHT, s_myUI_children); @@ -176,9 +166,9 @@ void create_ui(void* phy_fb, int screen_width, int screen_height, int color_byte } //////////////////////// interface for all platform //////////////////////// -extern "C" void startHelloWave(void* phy_fb, int width, int height, int color_bytes, struct EXTERNAL_GFX_OP* gfx_op) +extern "C" void startHelloWave(void* phy_fb, int width, int height, int color_bytes, struct DISPLAY_DRIVER* driver) { - create_ui(phy_fb, width, height, color_bytes, gfx_op); + create_ui(phy_fb, width, height, color_bytes, driver); } extern "C" void* getUiOfHelloWave(int* width, int* height, bool force_update) diff --git a/HelloWidgets/BuildLinux/.sync_build.sh b/HelloWidgets/BuildLinux/.sync_build.sh index 49cff5b473ac606967676ebefa6f0d333e301227..01b130e15047e50abf78202db47f8d23efb49bf7 100644 --- a/HelloWidgets/BuildLinux/.sync_build.sh +++ b/HelloWidgets/BuildLinux/.sync_build.sh @@ -1,5 +1,6 @@ if [ "$#" -ne 1 ]; then - echo "Invalid arguments" + echo "Do testing" + ./xWindow 680 512 | ./HelloWidgets shared-fb exit -1 fi diff --git a/HelloWidgets/UIcode/GuiLite.h b/HelloWidgets/UIcode/GuiLite.h index c4fc88a51476d2c8309c3e55e1270e13784fc510..80550e1632ad7bc82541a2edbb0f7f8f5937954f 100644 --- a/HelloWidgets/UIcode/GuiLite.h +++ b/HelloWidgets/UIcode/GuiLite.h @@ -1,107 +1,94 @@ #pragma once - -#define REAL_TIME_TASK_CYCLE_MS 50 -#define MAX(a,b) (((a)>(b))?(a):(b)) -#define MIN(a,b) (((a)<(b))?(a):(b)) - -#define GL_ARGB(a, r, g, b) ((((unsigned int)(a)) << 24) | (((unsigned int)(r)) << 16) | (((unsigned int)(g)) << 8) | ((unsigned int)(b))) -#define GL_ARGB_A(rgb) ((((unsigned int)(rgb)) >> 24) & 0xFF) - -#define GL_RGB(r, g, b) ((0xFF << 24) | (((unsigned int)(r)) << 16) | (((unsigned int)(g)) << 8) | ((unsigned int)(b))) -#define GL_RGB_R(rgb) ((((unsigned int)(rgb)) >> 16) & 0xFF) -#define GL_RGB_G(rgb) ((((unsigned int)(rgb)) >> 8) & 0xFF) -#define GL_RGB_B(rgb) (((unsigned int)(rgb)) & 0xFF) -#define GL_RGB_32_to_16(rgb) (((((unsigned int)(rgb)) & 0xFF) >> 3) | ((((unsigned int)(rgb)) & 0xFC00) >> 5) | ((((unsigned int)(rgb)) & 0xF80000) >> 8)) -#define GL_RGB_16_to_32(rgb) ((0xFF << 24) | ((((unsigned int)(rgb)) & 0x1F) << 3) | ((((unsigned int)(rgb)) & 0x7E0) << 5) | ((((unsigned int)(rgb)) & 0xF800) << 8)) - -#define ALIGN_HCENTER 0x00000000L -#define ALIGN_LEFT 0x01000000L -#define ALIGN_RIGHT 0x02000000L -#define ALIGN_HMASK 0x03000000L - -#define ALIGN_VCENTER 0x00000000L -#define ALIGN_TOP 0x00100000L -#define ALIGN_BOTTOM 0x00200000L -#define ALIGN_VMASK 0x00300000L - -typedef struct -{ - unsigned short year; - unsigned short month; - unsigned short date; - unsigned short day; - unsigned short hour; - unsigned short minute; - unsigned short second; -}T_TIME; - -void register_debug_function(void(*my_assert)(const char* file, int line), void(*my_log_out)(const char* log)); -void _assert(const char* file, int line); -#define ASSERT(condition) \ - do{ \ - if(!(condition))_assert(__FILE__, __LINE__);\ - }while(0) -void log_out(const char* log); - -long get_time_in_second(); -T_TIME second_to_day(long second); -T_TIME get_time(); - -void start_real_timer(void (*func)(void* arg)); -void register_timer(int milli_second, void func(void* param), void* param); - -unsigned int get_cur_thread_id(); -void create_thread(unsigned long* thread_id, void* attr, void *(*start_routine) (void *), void* arg); -void thread_sleep(unsigned int milli_seconds); -int build_bmp(const char *filename, unsigned int width, unsigned int height, unsigned char *data); - -#define FIFO_BUFFER_LEN 1024 -class c_fifo -{ -public: - c_fifo(); - int read(void* buf, int len); - int write(void* buf, int len); -private: - unsigned char m_buf[FIFO_BUFFER_LEN]; - int m_head; - int m_tail; - void* m_read_sem; - void* m_write_mutex; -}; - -class c_rect -{ -public: - c_rect(){ m_left = m_top = m_right = m_bottom = -1; } - c_rect(int left, int top, int width, int height) - { - set_rect(left, top, width, height); - } - void set_rect(int left, int top, int width, int height) - { - ASSERT(width > 0 && height > 0); - m_left = left; - m_top = top; - m_right = left + width - 1; - m_bottom = top + height -1; - } - bool pt_in_rect(int x, int y) const - { - return x >= m_left && x <= m_right && y >= m_top && y <= m_bottom; - } - int operator==(const c_rect& rect) const - { - return (m_left == rect.m_left) && (m_top == rect.m_top) && (m_right == rect.m_right) && (m_bottom == rect.m_bottom); - } - int width() const { return m_right - m_left + 1; } - int height() const { return m_bottom - m_top + 1 ; } - - int m_left; - int m_top; - int m_right; - int m_bottom; -}; +#define REAL_TIME_TASK_CYCLE_MS 50 +#define MAX(a,b) (((a)>(b))?(a):(b)) +#define MIN(a,b) (((a)<(b))?(a):(b)) +#define GL_ARGB(a, r, g, b) ((((unsigned int)(a)) << 24) | (((unsigned int)(r)) << 16) | (((unsigned int)(g)) << 8) | ((unsigned int)(b))) +#define GL_ARGB_A(rgb) ((((unsigned int)(rgb)) >> 24) & 0xFF) +#define GL_RGB(r, g, b) ((0xFF << 24) | (((unsigned int)(r)) << 16) | (((unsigned int)(g)) << 8) | ((unsigned int)(b))) +#define GL_RGB_R(rgb) ((((unsigned int)(rgb)) >> 16) & 0xFF) +#define GL_RGB_G(rgb) ((((unsigned int)(rgb)) >> 8) & 0xFF) +#define GL_RGB_B(rgb) (((unsigned int)(rgb)) & 0xFF) +#define GL_RGB_32_to_16(rgb) (((((unsigned int)(rgb)) & 0xFF) >> 3) | ((((unsigned int)(rgb)) & 0xFC00) >> 5) | ((((unsigned int)(rgb)) & 0xF80000) >> 8)) +#define GL_RGB_16_to_32(rgb) ((0xFF << 24) | ((((unsigned int)(rgb)) & 0x1F) << 3) | ((((unsigned int)(rgb)) & 0x7E0) << 5) | ((((unsigned int)(rgb)) & 0xF800) << 8)) +#define ALIGN_HCENTER 0x00000000L +#define ALIGN_LEFT 0x01000000L +#define ALIGN_RIGHT 0x02000000L +#define ALIGN_HMASK 0x03000000L +#define ALIGN_VCENTER 0x00000000L +#define ALIGN_TOP 0x00100000L +#define ALIGN_BOTTOM 0x00200000L +#define ALIGN_VMASK 0x00300000L +typedef struct +{ + unsigned short year; + unsigned short month; + unsigned short date; + unsigned short day; + unsigned short hour; + unsigned short minute; + unsigned short second; +}T_TIME; +void register_debug_function(void(*my_assert)(const char* file, int line), void(*my_log_out)(const char* log)); +void _assert(const char* file, int line); +#define ASSERT(condition) \ + do{ \ + if(!(condition))_assert(__FILE__, __LINE__);\ + }while(0) +void log_out(const char* log); +long get_time_in_second(); +T_TIME second_to_day(long second); +T_TIME get_time(); +void start_real_timer(void (*func)(void* arg)); +void register_timer(int milli_second, void func(void* param), void* param); +unsigned int get_cur_thread_id(); +void create_thread(unsigned long* thread_id, void* attr, void *(*start_routine) (void *), void* arg); +void thread_sleep(unsigned int milli_seconds); +int build_bmp(const char *filename, unsigned int width, unsigned int height, unsigned char *data); +#define FIFO_BUFFER_LEN 1024 +class c_fifo +{ +public: + c_fifo(); + int read(void* buf, int len); + int write(void* buf, int len); +private: + unsigned char m_buf[FIFO_BUFFER_LEN]; + int m_head; + int m_tail; + void* m_read_sem; + void* m_write_mutex; +}; +class c_rect +{ +public: + c_rect(){ m_left = m_top = m_right = m_bottom = -1; } + c_rect(int left, int top, int width, int height) + { + set_rect(left, top, width, height); + } + void set_rect(int left, int top, int width, int height) + { + ASSERT(width > 0 && height > 0); + m_left = left; + m_top = top; + m_right = left + width - 1; + m_bottom = top + height -1; + } + bool pt_in_rect(int x, int y) const + { + return x >= m_left && x <= m_right && y >= m_top && y <= m_bottom; + } + int operator==(const c_rect& rect) const + { + return (m_left == rect.m_left) && (m_top == rect.m_top) && (m_right == rect.m_right) && (m_bottom == rect.m_bottom); + } + int width() const { return m_right - m_left + 1; } + int height() const { return m_bottom - m_top + 1 ; } + int m_left; + int m_top; + int m_right; + int m_bottom; +}; //BITMAP typedef struct struct_bitmap_info { @@ -238,7 +225,7 @@ typedef enum Z_ORDER_LEVEL_2,//highest graphic level Z_ORDER_LEVEL_MAX }Z_ORDER_LEVEL; -struct EXTERNAL_GFX_OP +struct DISPLAY_DRIVER { void(*draw_pixel)(int x, int y, unsigned int rgb); void(*fill_rect)(int x0, int y0, int x1, int y1, unsigned int rgb); @@ -247,18 +234,19 @@ class c_surface; class c_display { friend class c_surface; public: - inline c_display(void* phy_fb, int display_width, int display_height, int surface_width, int surface_height, unsigned int color_bytes, int surface_cnt, EXTERNAL_GFX_OP* gfx_op = 0);//multiple surface or surface_no_fb - inline c_display(void* phy_fb, int display_width, int display_height, c_surface* surface);//single custom surface - inline c_surface* alloc_surface(Z_ORDER_LEVEL max_zorder, c_rect layer_rect = c_rect());//for multiple surfaces + inline c_display(void* phy_fb, int display_width, int display_height, c_surface* surface, DISPLAY_DRIVER* driver = 0);//single custom surface + inline c_display(void* phy_fb, int display_width, int display_height, int surface_width, int surface_height, unsigned int color_bytes, int surface_cnt, DISPLAY_DRIVER* driver = 0);//multiple surface + inline c_surface* alloc_surface(Z_ORDER_LEVEL max_zorder, c_rect layer_rect = c_rect());//for slide group inline int swipe_surface(c_surface* s0, c_surface* s1, int x0, int x1, int y0, int y1, int offset); int get_width() { return m_width; } int get_height() { return m_height; } + void* get_phy_fb() { return m_phy_fb; } void* get_updated_fb(int* width, int* height, bool force_update = false) { if (width && height) { - *width = get_width(); - *height = get_height(); + *width = m_width; + *height = m_height; } if (force_update) { @@ -277,35 +265,123 @@ public: { return -1; } - int width = get_width(); - int height = get_height(); //16 bits framebuffer if (m_color_bytes == 2) { - return build_bmp(file_name, width, height, (unsigned char*)m_phy_fb); + return build_bmp(file_name, m_width, m_height, (unsigned char*)m_phy_fb); } //32 bits framebuffer - unsigned short* p_bmp565_data = new unsigned short[width * height]; + unsigned short* p_bmp565_data = new unsigned short[m_width * m_height]; unsigned int* p_raw_data = (unsigned int*)m_phy_fb; - for (int i = 0; i < width * height; i++) + for (int i = 0; i < m_width * m_height; i++) { unsigned int rgb = *p_raw_data++; p_bmp565_data[i] = GL_RGB_32_to_16(rgb); } - int ret = build_bmp(file_name, width, height, (unsigned char*)p_bmp565_data); + int ret = build_bmp(file_name, m_width, m_height, (unsigned char*)p_bmp565_data); delete[]p_bmp565_data; return ret; } -private: - int m_width; //in pixels - int m_height; //in pixels - int m_color_bytes; //16 bits, 32 bits only - void* m_phy_fb; //physical framebuffer +protected: + virtual void draw_pixel(int x, int y, unsigned int rgb) + { + if ((x >= m_width) || (y >= m_height)) { return; } + if (m_driver && m_driver->draw_pixel) + { + return m_driver->draw_pixel(x, y, rgb); + } + if (m_color_bytes == 2) + { + ((unsigned short*)m_phy_fb)[y * m_width + x] = GL_RGB_32_to_16(rgb); + } + else + { + ((unsigned int*)m_phy_fb)[y * m_width + x] = rgb; + } + } + virtual void fill_rect(int x0, int y0, int x1, int y1, unsigned int rgb) + { + if (m_driver && m_driver->fill_rect) + { + return m_driver->fill_rect(x0, y0, x1, y1, rgb); + } + if (m_driver && m_driver->draw_pixel) + { + for (int y = y0; y <= y1; y++) + { + for (int x = x0; x <= x1; x++) + { + m_driver->draw_pixel(x, y, rgb); + } + } + return; + } + register int _width = m_width; + register int _height = m_height; + int x, y; + if (m_color_bytes == 2) + { + unsigned short* phy_fb; + unsigned int rgb_16 = GL_RGB_32_to_16(rgb); + for (y = y0; y <= y1; y++) + { + phy_fb = &((unsigned short*)m_phy_fb)[y * _width + x0]; + for (x = x0; x <= x1; x++) + { + if ((x < _width) && (y < _height)) + { + *phy_fb++ = rgb_16; + } + } + } + } + else + { + unsigned int* phy_fb; + for (y = y0; y <= y1; y++) + { + phy_fb = &((unsigned int*)m_phy_fb)[y * _width + x0]; + for (x = x0; x <= x1; x++) + { + if ((x < _width) && (y < _height)) + { + *phy_fb++ = rgb; + } + } + } + } + } + virtual int flush_screen(int left, int top, int right, int bottom, void* fb, int fb_width) + { + if ((0 == m_phy_fb) || (0 == fb)) + { + return -1; + } + register int _width = m_width; + register int _height = m_height; + left = (left >= _width) ? (_width - 1) : left; + right = (right >= _width) ? (_width - 1) : right; + top = (top >= _height) ? (_height - 1) : top; + bottom = (bottom >= _height) ? (_height - 1) : bottom; + for (int y = top; y < bottom; y++) + { + void* s_addr = (char*)fb + ((y * fb_width + left) * m_color_bytes); + void* d_addr = (char*)m_phy_fb + ((y * _width + left) * m_color_bytes); + memcpy(d_addr, s_addr, (right - left) * m_color_bytes); + } + return 0; + } + int m_width; //in pixels + int m_height; //in pixels + int m_color_bytes; //16/32 bits for default + void* m_phy_fb; //physical framebuffer for default + struct DISPLAY_DRIVER* m_driver; //Rendering by external method without default physical framebuffer int m_phy_read_index; int m_phy_write_index; c_surface* m_surface_group[SURFACE_CNT_MAX]; int m_surface_cnt; //surface count int m_surface_index; + }; class c_layer { @@ -317,12 +393,10 @@ public: class c_surface { friend class c_display; friend class c_bitmap_operator; public: - c_surface(unsigned int width, unsigned int height, unsigned int color_bytes, Z_ORDER_LEVEL max_zorder = Z_ORDER_LEVEL_0, c_rect overlpa_rect = c_rect()) : m_width(width), m_height(height), m_color_bytes(color_bytes), m_fb(0), m_is_active(false), m_top_zorder(Z_ORDER_LEVEL_0), m_phy_fb(0), m_phy_write_index(0), m_display(0) + c_surface(unsigned int width, unsigned int height, unsigned int color_bytes, Z_ORDER_LEVEL max_zorder = Z_ORDER_LEVEL_0, c_rect overlpa_rect = c_rect()) : m_width(width), m_height(height), m_color_bytes(color_bytes), m_fb(0), m_is_active(false), m_top_zorder(Z_ORDER_LEVEL_0), m_phy_write_index(0), m_display(0) { (overlpa_rect == c_rect()) ? set_surface(max_zorder, c_rect(0, 0, width - 1, height - 1)) : set_surface(max_zorder, overlpa_rect); } - int get_width() { return m_width; } - int get_height() { return m_height; } unsigned int get_pixel(int x, int y, unsigned int z_order) { if (x >= m_width || y >= m_height || x < 0 || y < 0 || z_order >= Z_ORDER_LEVEL_MAX) @@ -332,15 +406,15 @@ public: } if (m_layers[z_order].fb) { - return (m_color_bytes == 4) ? ((unsigned int*)(m_layers[z_order].fb))[y * m_width + x] : GL_RGB_16_to_32(((unsigned short*)(m_layers[z_order].fb))[y * m_width + x]); + return (m_color_bytes == 2) ? GL_RGB_16_to_32(((unsigned short*)(m_layers[z_order].fb))[y * m_width + x]) : ((unsigned int*)(m_layers[z_order].fb))[y * m_width + x]; } else if (m_fb) { - return (m_color_bytes == 4) ? ((unsigned int*)m_fb)[y * m_width + x] : GL_RGB_16_to_32(((unsigned short*)m_fb)[y * m_width + x]); + return (m_color_bytes == 2) ? GL_RGB_16_to_32(((unsigned short*)m_fb)[y * m_width + x]) : ((unsigned int*)m_fb)[y * m_width + x]; } - else if (m_phy_fb) + else if (m_display->m_phy_fb) { - return (m_color_bytes == 4) ? ((unsigned int*)m_phy_fb)[y * m_width + x] : GL_RGB_16_to_32(((unsigned short*)m_phy_fb)[y * m_width + x]); + return (m_color_bytes == 2) ? GL_RGB_16_to_32(((unsigned short*)m_display->m_phy_fb)[y * m_width + x]) : ((unsigned int*)m_display->m_phy_fb)[y * m_width + x]; } return 0; } @@ -357,7 +431,7 @@ public: } if (z_order == m_max_zorder) { - return draw_pixel_on_fb(x, y, rgb); + return draw_pixel_low_level(x, y, rgb); } if (z_order > (unsigned int)m_top_zorder) @@ -367,19 +441,19 @@ public: if (m_layers[z_order].rect.pt_in_rect(x, y)) { c_rect layer_rect = m_layers[z_order].rect; - if (m_color_bytes == 4) + if (m_color_bytes == 2) { - ((unsigned int*)(m_layers[z_order].fb))[(x - layer_rect.m_left) + (y - layer_rect.m_top) * layer_rect.width()] = rgb; + ((unsigned short*)(m_layers[z_order].fb))[(x - layer_rect.m_left) + (y - layer_rect.m_top) * layer_rect.width()] = GL_RGB_32_to_16(rgb); } else { - ((unsigned short*)(m_layers[z_order].fb))[(x - layer_rect.m_left) + (y - layer_rect.m_top) * layer_rect.width()] = GL_RGB_32_to_16(rgb); + ((unsigned int*)(m_layers[z_order].fb))[(x - layer_rect.m_left) + (y - layer_rect.m_top) * layer_rect.width()] = rgb; } } if (z_order == m_top_zorder) { - return draw_pixel_on_fb(x, y, rgb); + return draw_pixel_low_level(x, y, rgb); } bool be_overlapped = false; for (unsigned int tmp_z_order = Z_ORDER_LEVEL_MAX - 1; tmp_z_order > z_order; tmp_z_order--) @@ -392,7 +466,7 @@ public: } if (!be_overlapped) { - draw_pixel_on_fb(x, y, rgb); + draw_pixel_low_level(x, y, rgb); } } virtual void fill_rect(int x0, int y0, int x1, int y1, unsigned int rgb, unsigned int z_order) @@ -403,7 +477,7 @@ public: y1 = (y1 > (m_height - 1)) ? (m_height - 1) : y1; if (z_order == m_max_zorder) { - return fill_rect_on_fb(x0, y0, x1, y1, rgb); + return fill_rect_low_level(x0, y0, x1, y1, rgb); } if (z_order == m_top_zorder) { @@ -416,18 +490,18 @@ public: { if (layer_rect.pt_in_rect(x, y)) { - if (m_color_bytes == 4) + if (m_color_bytes == 2) { - ((unsigned int*)m_layers[z_order].fb)[(y - layer_rect.m_top) * layer_rect.width() + (x - layer_rect.m_left)] = rgb; + ((unsigned short*)m_layers[z_order].fb)[(y - layer_rect.m_top) * layer_rect.width() + (x - layer_rect.m_left)] = rgb_16; } else { - ((unsigned short*)m_layers[z_order].fb)[(y - layer_rect.m_top) * layer_rect.width() + (x - layer_rect.m_left)] = rgb_16; + ((unsigned int*)m_layers[z_order].fb)[(y - layer_rect.m_top) * layer_rect.width() + (x - layer_rect.m_left)] = rgb; } } } } - return fill_rect_on_fb(x0, y0, x1, y1, rgb); + return fill_rect_low_level(x0, y0, x1, y1, rgb); } for (; y0 <= y1; y0++) { @@ -499,27 +573,16 @@ public: } int flush_screen(int left, int top, int right, int bottom) { - if (left < 0 || left >= m_width || right < 0 || right >= m_width || - top < 0 || top >= m_height || bottom < 0 || bottom >= m_height) - { - ASSERT(false); - } - if (!m_is_active || (0 == m_phy_fb) || (0 == m_fb)) + if (!m_is_active) { return -1; } - int display_width = m_display->get_width(); - int display_height = m_display->get_height(); - left = (left >= display_width) ? (display_width - 1) : left; - right = (right >= display_width) ? (display_width - 1) : right; - top = (top >= display_height) ? (display_height - 1) : top; - bottom = (bottom >= display_height) ? (display_height - 1) : bottom; - for (int y = top; y < bottom; y++) + if (left < 0 || left >= m_width || right < 0 || right >= m_width || + top < 0 || top >= m_height || bottom < 0 || bottom >= m_height) { - void* s_addr = (char*)m_fb + ((y * m_width + left) * m_color_bytes); - void* d_addr = (char*)m_phy_fb + ((y * display_width + left) * m_color_bytes); - memcpy(d_addr, s_addr, (right - left) * m_color_bytes); + ASSERT(false); } + m_display->flush_screen(left, top, right, bottom, m_fb, m_width); *m_phy_write_index = *m_phy_write_index + 1; return 0; } @@ -537,90 +600,62 @@ public: { for (int x = rect.m_left; x <= rect.m_right; x++) { - unsigned int rgb = (m_color_bytes == 4) ? ((unsigned int*)fb)[(x - layer_rect.m_left) + (y - layer_rect.m_top) * width] : GL_RGB_16_to_32(((unsigned short*)fb)[(x - layer_rect.m_left) + (y - layer_rect.m_top) * width]); - draw_pixel_on_fb(x, y, rgb); + unsigned int rgb = (m_color_bytes == 2) ? GL_RGB_16_to_32(((unsigned short*)fb)[(x - layer_rect.m_left) + (y - layer_rect.m_top) * width]) : ((unsigned int*)fb)[(x - layer_rect.m_left) + (y - layer_rect.m_top) * width]; + draw_pixel_low_level(x, y, rgb); } } return 0; } void set_active(bool flag) { m_is_active = flag; } protected: - virtual void fill_rect_on_fb(int x0, int y0, int x1, int y1, unsigned int rgb) - { - int display_width = m_display->get_width(); - int display_height = m_display->get_height(); - if (m_color_bytes == 4) + virtual void fill_rect_low_level(int x0, int y0, int x1, int y1, unsigned int rgb) + {//fill rect on framebuffer of surface + int x, y; + if (m_color_bytes == 2) { - int x; - unsigned int* fb, * phy_fb; - for (; y0 <= y1; y0++) + unsigned short* fb; + unsigned int rgb_16 = GL_RGB_32_to_16(rgb); + for (y = y0; y <= y1; y++) { - x = x0; - fb = m_fb ? &((unsigned int*)m_fb)[y0 * m_width + x] : 0; - phy_fb = &((unsigned int*)m_phy_fb)[y0 * display_width + x]; - *m_phy_write_index = *m_phy_write_index + 1; - for (; x <= x1; x++) + fb = m_fb ? &((unsigned short*)m_fb)[y * m_width + x0] : 0; + if (!fb) { break; } + for (x = x0; x <= x1; x++) { - if (fb) - { - *fb++ = rgb; - } - if (m_is_active && (x < display_width) && (y0 < display_height)) - { - *phy_fb++ = rgb; - } + *fb++ = rgb_16; } } } - else if (m_color_bytes == 2) + else { - int x; - unsigned short* fb, * phy_fb; - rgb = GL_RGB_32_to_16(rgb); - for (; y0 <= y1; y0++) + unsigned int* fb; + for (y = y0; y <= y1; y++) { - x = x0; - fb = m_fb ? &((unsigned short*)m_fb)[y0 * m_width + x] : 0; - phy_fb = &((unsigned short*)m_phy_fb)[y0 * display_width + x]; - *m_phy_write_index = *m_phy_write_index + 1; - for (; x <= x1; x++) + fb = m_fb ? &((unsigned int*)m_fb)[y * m_width + x0] : 0; + if (!fb) { break; } + for (x = x0; x <= x1; x++) { - if (fb) - { - *fb++ = rgb; - } - if (m_is_active && (x < display_width) && (y0 < display_height)) - { - *phy_fb++ = rgb; - } + *fb++ = rgb; } } } + if (!m_is_active) { return; } + m_display->fill_rect(x0, y0, x1, y1, rgb); + *m_phy_write_index = *m_phy_write_index + 1; } - virtual void draw_pixel_on_fb(int x, int y, unsigned int rgb) + virtual void draw_pixel_low_level(int x, int y, unsigned int rgb) { if (m_fb) - { - (m_color_bytes == 4) ? ((unsigned int*)m_fb)[y * m_width + x] = rgb : ((unsigned short*)m_fb)[y * m_width + x] = GL_RGB_32_to_16(rgb); - } - if (m_is_active && (x < m_display->get_width()) && (y < m_display->get_height())) - { - if (m_color_bytes == 4) - { - ((unsigned int*)m_phy_fb)[y * (m_display->get_width()) + x] = rgb; - } - else - { - ((unsigned short*)m_phy_fb)[y * (m_display->get_width()) + x] = GL_RGB_32_to_16(rgb); - } - *m_phy_write_index = *m_phy_write_index + 1; + {//draw pixel on framebuffer of surface + (m_color_bytes == 2) ? ((unsigned short*)m_fb)[y * m_width + x] = GL_RGB_32_to_16(rgb): ((unsigned int*)m_fb)[y * m_width + x] = rgb; } + if (!m_is_active) { return; } + m_display->draw_pixel(x, y, rgb); + *m_phy_write_index = *m_phy_write_index + 1; } void attach_display(c_display* display) { ASSERT(display); m_display = display; - m_phy_fb = display->m_phy_fb; m_phy_write_index = &display->m_phy_write_index; } void set_surface(Z_ORDER_LEVEL max_z_order, c_rect layer_rect) @@ -638,87 +673,22 @@ protected: } int m_width; //in pixels int m_height; //in pixels - int m_color_bytes; //16 bits, 32 bits only + int m_color_bytes; //16 bits, 32 bits for default void* m_fb; //frame buffer you could see c_layer m_layers[Z_ORDER_LEVEL_MAX];//all graphic layers bool m_is_active; //active flag Z_ORDER_LEVEL m_max_zorder; //the highest graphic layer the surface will have Z_ORDER_LEVEL m_top_zorder; //the current highest graphic layer the surface have - void* m_phy_fb; //physical framebufer int* m_phy_write_index; c_display* m_display; }; -class c_surface_no_fb : public c_surface {//No physical framebuffer, render with external graphic interface - friend class c_display; -public: - c_surface_no_fb(unsigned int width, unsigned int height, unsigned int color_bytes, struct EXTERNAL_GFX_OP* gfx_op, Z_ORDER_LEVEL max_zorder = Z_ORDER_LEVEL_0, c_rect overlpa_rect = c_rect()) : c_surface(width, height, color_bytes, max_zorder, overlpa_rect), m_gfx_op(gfx_op) {} -protected: - virtual void fill_rect_on_fb(int x0, int y0, int x1, int y1, unsigned int rgb) - { - if (!m_gfx_op) - { - return; - } - if (m_gfx_op->fill_rect) - { - return m_gfx_op->fill_rect(x0, y0, x1, y1, rgb); - } - if (m_gfx_op->draw_pixel && m_is_active) - { - for (int y = y0; y <= y1; y++) - { - for (int x = x0; x <= x1; x++) - { - m_gfx_op->draw_pixel(x, y, rgb); - } - } - } - if (!m_fb) { return; } - if (m_color_bytes == 4) - { - unsigned int* fb; - for (int y = y0; y <= y1; y++) - { - fb = &((unsigned int*)m_fb)[y0 * m_width + x0]; - for (int x = x0; x <= x1; x++) - { - *fb++ = rgb; - } - } - } - else if (m_color_bytes == 2) - { - unsigned short* fb; - rgb = GL_RGB_32_to_16(rgb); - for (int y = y0; y <= y1; y++) - { - fb = &((unsigned short*)m_fb)[y0 * m_width + x0]; - for (int x = x0; x <= x1; x++) - { - *fb++ = rgb; - } - } - } - } - virtual void draw_pixel_on_fb(int x, int y, unsigned int rgb) - { - if (m_gfx_op && m_gfx_op->draw_pixel && m_is_active) - { - m_gfx_op->draw_pixel(x, y, rgb); - } - if (!m_fb) { return; } - if (m_color_bytes == 4) - { - ((unsigned int*)m_fb)[y * m_width + x] = rgb; - } - else if (m_color_bytes == 2) - { - ((unsigned short*)m_fb)[y * m_width + x] = GL_RGB_32_to_16(rgb); - } - } - struct EXTERNAL_GFX_OP* m_gfx_op;//Rendering by external method -}; -inline c_display::c_display(void* phy_fb, int display_width, int display_height, int surface_width, int surface_height, unsigned int color_bytes, int surface_cnt, EXTERNAL_GFX_OP* gfx_op) : m_width(display_width), m_height(display_height), m_color_bytes(color_bytes), m_phy_fb(phy_fb), m_phy_read_index(0), m_phy_write_index(0), m_surface_cnt(surface_cnt), m_surface_index(0) +inline c_display::c_display(void* phy_fb, int display_width, int display_height, c_surface* surface, DISPLAY_DRIVER* driver) : m_phy_fb(phy_fb), m_width(display_width), m_height(display_height), m_driver(driver), m_phy_read_index(0), m_phy_write_index(0), m_surface_cnt(1), m_surface_index(0) +{ + m_color_bytes = surface->m_color_bytes; + surface->m_is_active = true; + (m_surface_group[0] = surface)->attach_display(this); +} +inline c_display::c_display(void* phy_fb, int display_width, int display_height, int surface_width, int surface_height, unsigned int color_bytes, int surface_cnt, DISPLAY_DRIVER* driver) : m_phy_fb(phy_fb), m_width(display_width), m_height(display_height), m_color_bytes(color_bytes), m_phy_read_index(0), m_phy_write_index(0), m_surface_cnt(surface_cnt), m_driver(driver), m_surface_index(0) { ASSERT(color_bytes == 2 || color_bytes == 4); ASSERT(m_surface_cnt <= SURFACE_CNT_MAX); @@ -726,16 +696,10 @@ inline c_display::c_display(void* phy_fb, int display_width, int display_height, for (int i = 0; i < m_surface_cnt; i++) { - m_surface_group[i] = (phy_fb) ? new c_surface(surface_width, surface_height, color_bytes) : new c_surface_no_fb(surface_width, surface_height, color_bytes, gfx_op); + m_surface_group[i] = new c_surface(surface_width, surface_height, color_bytes); m_surface_group[i]->attach_display(this); } } -inline c_display::c_display(void* phy_fb, int display_width, int display_height, c_surface* surface) : m_width(display_width), m_height(display_height), m_phy_fb(phy_fb), m_phy_read_index(0), m_phy_write_index(0), m_surface_cnt(1), m_surface_index(0) -{ - m_color_bytes = surface->m_color_bytes; - surface->m_is_active = true; - (m_surface_group[0] = surface)->attach_display(this); -} inline c_surface* c_display::alloc_surface(Z_ORDER_LEVEL max_zorder, c_rect layer_rect) { ASSERT(max_zorder < Z_ORDER_LEVEL_MAX && m_surface_index < m_surface_cnt); @@ -744,8 +708,8 @@ inline c_surface* c_display::alloc_surface(Z_ORDER_LEVEL max_zorder, c_rect laye } inline int c_display::swipe_surface(c_surface* s0, c_surface* s1, int x0, int x1, int y0, int y1, int offset) { - int surface_width = s0->get_width(); - int surface_height = s0->get_height(); + register int surface_width = s0->m_width; + register int surface_height = s0->m_height; if (offset < 0 || offset > surface_width || y0 < 0 || y0 >= surface_height || y1 < 0 || y1 >= surface_height || x0 < 0 || x0 >= surface_width || x1 < 0 || x1 >= surface_width) { @@ -767,46 +731,46 @@ inline int c_display::swipe_surface(c_surface* s0, c_surface* s1, int x0, int x1 for (int y = y0; y <= y1; y++) { //Left surface - char* addr_s = ((char*)(s0->m_fb) + (y * (s0->get_width()) + x0 + offset) * m_color_bytes); + char* addr_s = ((char*)(s0->m_fb) + (y * surface_width + x0 + offset) * m_color_bytes); char* addr_d = ((char*)(m_phy_fb)+(y * m_width + x0) * m_color_bytes); memcpy(addr_d, addr_s, (width - offset) * m_color_bytes); //Right surface - addr_s = ((char*)(s1->m_fb) + (y * (s1->get_width()) + x0) * m_color_bytes); + addr_s = ((char*)(s1->m_fb) + (y * surface_width + x0) * m_color_bytes); addr_d = ((char*)(m_phy_fb)+(y * m_width + x0 + (width - offset)) * m_color_bytes); memcpy(addr_d, addr_s, offset * m_color_bytes); } } - else if (m_color_bytes == 4) + else if (m_color_bytes == 2) { - void(*draw_pixel)(int x, int y, unsigned int rgb) = ((c_surface_no_fb*)s0)->m_gfx_op->draw_pixel; + void(*draw_pixel)(int x, int y, unsigned int rgb) = m_driver->draw_pixel; for (int y = y0; y <= y1; y++) { //Left surface for (int x = x0; x <= (x1 - offset); x++) { - draw_pixel(x, y, ((unsigned int*)s0->m_fb)[y * m_width + x + offset]); + draw_pixel(x, y, GL_RGB_16_to_32(((unsigned short*)s0->m_fb)[y * m_width + x + offset])); } //Right surface for (int x = x1 - offset; x <= x1; x++) { - draw_pixel(x, y, ((unsigned int*)s1->m_fb)[y * m_width + x + offset - x1 + x0]); + draw_pixel(x, y, GL_RGB_16_to_32(((unsigned short*)s1->m_fb)[y * m_width + x + offset - x1 + x0])); } } } - else if (m_color_bytes == 2) + else //m_color_bytes == 3/4... { - void(*draw_pixel)(int x, int y, unsigned int rgb) = ((c_surface_no_fb*)s0)->m_gfx_op->draw_pixel; + void(*draw_pixel)(int x, int y, unsigned int rgb) = m_driver->draw_pixel; for (int y = y0; y <= y1; y++) { //Left surface for (int x = x0; x <= (x1 - offset); x++) { - draw_pixel(x, y, GL_RGB_16_to_32(((unsigned short*)s0->m_fb)[y * m_width + x + offset])); + draw_pixel(x, y, ((unsigned int*)s0->m_fb)[y * m_width + x + offset]); } //Right surface for (int x = x1 - offset; x <= x1; x++) { - draw_pixel(x, y, GL_RGB_16_to_32(((unsigned short*)s1->m_fb)[y * m_width + x + offset - x1 + x0])); + draw_pixel(x, y, ((unsigned int*)s1->m_fb)[y * m_width + x + offset - x1 + x0]); } } } @@ -3407,22 +3371,12 @@ private: #ifdef GUILITE_ON c_bitmap_operator the_bitmap_op = c_bitmap_operator(); c_image_operator* c_image::image_operator = &the_bitmap_op; +const void* c_theme::s_font_map[FONT_MAX]; +const void* c_theme::s_image_map[IMAGE_MAX]; +unsigned int c_theme::s_color_map[COLOR_MAX]; +c_lattice_font_op the_lattice_font_op = c_lattice_font_op(); +c_font_operator* c_word::fontOperator = &the_lattice_font_op; #endif - -#ifdef GUILITE_ON - -const void* c_theme::s_font_map[FONT_MAX]; -const void* c_theme::s_image_map[IMAGE_MAX]; -unsigned int c_theme::s_color_map[COLOR_MAX]; - -#endif - -#ifdef GUILITE_ON - -c_lattice_font_op the_lattice_font_op = c_lattice_font_op(); -c_font_operator* c_word::fontOperator = &the_lattice_font_op; - -#endif #ifdef GUILITE_ON #if (defined __linux__) || (defined __APPLE__) #include @@ -4264,11 +4218,7 @@ int c_fifo::write(void* buf, int len) #endif #ifdef GUILITE_ON DIALOG_ARRAY c_dialog::ms_the_dialogs[SURFACE_CNT_MAX]; -#endif -#ifdef GUILITE_ON c_keyboard c_edit::s_keyboard; -#endif -#ifdef GUILITE_ON static c_keyboard_button s_key_0, s_key_1, s_key_2, s_key_3, s_key_4, s_key_5, s_key_6, s_key_7, s_key_8, s_key_9; static c_keyboard_button s_key_A, s_key_B, s_key_C, s_key_D, s_key_E, s_key_F, s_key_G, s_key_H, s_key_I, s_key_J; static c_keyboard_button s_key_K, s_key_L, s_key_M, s_key_N, s_key_O, s_key_P, s_key_Q, s_key_R, s_key_S, s_key_T; @@ -4306,12 +4256,12 @@ WND_TREE g_key_board_children[] = {&s_key_B, 'B', 0, ((KEY_WIDTH / 2) + POS_X(5)), POS_Y(2), KEY_WIDTH, KEY_HEIGHT}, {&s_key_N, 'N', 0, ((KEY_WIDTH / 2) + POS_X(6)), POS_Y(2), KEY_WIDTH, KEY_HEIGHT}, {&s_key_M, 'M', 0, ((KEY_WIDTH / 2) + POS_X(7)), POS_Y(2), KEY_WIDTH, KEY_HEIGHT}, - {&s_key_del, 0x7F, 0, ((KEY_WIDTH / 2) + POS_X(8)), POS_Y(2), DEL_WIDTH, KEY_HEIGHT}, + {&s_key_del,0x7F, 0, ((KEY_WIDTH / 2) + POS_X(8)), POS_Y(2), DEL_WIDTH, KEY_HEIGHT}, //Row 4 - {&s_key_esc, 0x1B, 0, POS_X(0), POS_Y(3), ESC_WIDTH, KEY_HEIGHT}, + {&s_key_esc, 0x1B, 0, POS_X(0), POS_Y(3), ESC_WIDTH, KEY_HEIGHT}, {&s_key_num_switch, 0x90, 0, POS_X(2), POS_Y(3), SWITCH_WIDTH, KEY_HEIGHT}, {&s_key_space, ' ', 0, ((KEY_WIDTH / 2) + POS_X(3)), POS_Y(3), SPACE_WIDTH, KEY_HEIGHT}, - {&s_key_dot, '.', 0, ((KEY_WIDTH / 2) + POS_X(6)), POS_Y(3), DOT_WIDTH, KEY_HEIGHT}, + {&s_key_dot, '.', 0, ((KEY_WIDTH / 2) + POS_X(6)), POS_Y(3), DOT_WIDTH, KEY_HEIGHT}, {&s_key_enter, '\n', 0, POS_X(8), POS_Y(3), ENTER_WIDTH, KEY_HEIGHT}, {0,0,0,0,0,0,0} }; @@ -4326,12 +4276,11 @@ WND_TREE g_number_board_children[] = {&s_key_7, '7', 0, POS_X(0), POS_Y(2), KEY_WIDTH, KEY_HEIGHT}, {&s_key_8, '8', 0, POS_X(1), POS_Y(2), KEY_WIDTH, KEY_HEIGHT}, {&s_key_9, '9', 0, POS_X(2), POS_Y(2), KEY_WIDTH, KEY_HEIGHT}, - - {&s_key_esc, 0x1B, 0, POS_X(0), POS_Y(3), KEY_WIDTH, KEY_HEIGHT}, + {&s_key_esc,0x1B, 0, POS_X(0), POS_Y(3), KEY_WIDTH, KEY_HEIGHT}, {&s_key_0, '0', 0, POS_X(1), POS_Y(3), KEY_WIDTH, KEY_HEIGHT}, - {&s_key_dot, '.', 0, POS_X(2), POS_Y(3), KEY_WIDTH, KEY_HEIGHT}, + {&s_key_dot,'.', 0, POS_X(2), POS_Y(3), KEY_WIDTH, KEY_HEIGHT}, {&s_key_del, 0x7F, 0, POS_X(3), POS_Y(0), KEY_WIDTH, KEY_HEIGHT * 2 + 2}, {&s_key_enter,'\n', 0, POS_X(3), POS_Y(2), KEY_WIDTH, KEY_HEIGHT * 2 + 2}, {0,0,0,0,0,0,0} }; -#endif +#endif \ No newline at end of file diff --git a/HelloWindows/BuildLinux/.sync_build.sh b/HelloWindows/BuildLinux/.sync_build.sh index 49cff5b473ac606967676ebefa6f0d333e301227..e972591dc1445f87fd29bb0e8d6aeab84e242dee 100644 --- a/HelloWindows/BuildLinux/.sync_build.sh +++ b/HelloWindows/BuildLinux/.sync_build.sh @@ -1,5 +1,6 @@ if [ "$#" -ne 1 ]; then - echo "Invalid arguments" + echo "Do testing" + ./xWindow 1280 720 | ./HelloWindows shared-fb exit -1 fi diff --git a/HelloWindows/UIcode/GuiLite.h b/HelloWindows/UIcode/GuiLite.h index c4fc88a51476d2c8309c3e55e1270e13784fc510..80550e1632ad7bc82541a2edbb0f7f8f5937954f 100644 --- a/HelloWindows/UIcode/GuiLite.h +++ b/HelloWindows/UIcode/GuiLite.h @@ -1,107 +1,94 @@ #pragma once - -#define REAL_TIME_TASK_CYCLE_MS 50 -#define MAX(a,b) (((a)>(b))?(a):(b)) -#define MIN(a,b) (((a)<(b))?(a):(b)) - -#define GL_ARGB(a, r, g, b) ((((unsigned int)(a)) << 24) | (((unsigned int)(r)) << 16) | (((unsigned int)(g)) << 8) | ((unsigned int)(b))) -#define GL_ARGB_A(rgb) ((((unsigned int)(rgb)) >> 24) & 0xFF) - -#define GL_RGB(r, g, b) ((0xFF << 24) | (((unsigned int)(r)) << 16) | (((unsigned int)(g)) << 8) | ((unsigned int)(b))) -#define GL_RGB_R(rgb) ((((unsigned int)(rgb)) >> 16) & 0xFF) -#define GL_RGB_G(rgb) ((((unsigned int)(rgb)) >> 8) & 0xFF) -#define GL_RGB_B(rgb) (((unsigned int)(rgb)) & 0xFF) -#define GL_RGB_32_to_16(rgb) (((((unsigned int)(rgb)) & 0xFF) >> 3) | ((((unsigned int)(rgb)) & 0xFC00) >> 5) | ((((unsigned int)(rgb)) & 0xF80000) >> 8)) -#define GL_RGB_16_to_32(rgb) ((0xFF << 24) | ((((unsigned int)(rgb)) & 0x1F) << 3) | ((((unsigned int)(rgb)) & 0x7E0) << 5) | ((((unsigned int)(rgb)) & 0xF800) << 8)) - -#define ALIGN_HCENTER 0x00000000L -#define ALIGN_LEFT 0x01000000L -#define ALIGN_RIGHT 0x02000000L -#define ALIGN_HMASK 0x03000000L - -#define ALIGN_VCENTER 0x00000000L -#define ALIGN_TOP 0x00100000L -#define ALIGN_BOTTOM 0x00200000L -#define ALIGN_VMASK 0x00300000L - -typedef struct -{ - unsigned short year; - unsigned short month; - unsigned short date; - unsigned short day; - unsigned short hour; - unsigned short minute; - unsigned short second; -}T_TIME; - -void register_debug_function(void(*my_assert)(const char* file, int line), void(*my_log_out)(const char* log)); -void _assert(const char* file, int line); -#define ASSERT(condition) \ - do{ \ - if(!(condition))_assert(__FILE__, __LINE__);\ - }while(0) -void log_out(const char* log); - -long get_time_in_second(); -T_TIME second_to_day(long second); -T_TIME get_time(); - -void start_real_timer(void (*func)(void* arg)); -void register_timer(int milli_second, void func(void* param), void* param); - -unsigned int get_cur_thread_id(); -void create_thread(unsigned long* thread_id, void* attr, void *(*start_routine) (void *), void* arg); -void thread_sleep(unsigned int milli_seconds); -int build_bmp(const char *filename, unsigned int width, unsigned int height, unsigned char *data); - -#define FIFO_BUFFER_LEN 1024 -class c_fifo -{ -public: - c_fifo(); - int read(void* buf, int len); - int write(void* buf, int len); -private: - unsigned char m_buf[FIFO_BUFFER_LEN]; - int m_head; - int m_tail; - void* m_read_sem; - void* m_write_mutex; -}; - -class c_rect -{ -public: - c_rect(){ m_left = m_top = m_right = m_bottom = -1; } - c_rect(int left, int top, int width, int height) - { - set_rect(left, top, width, height); - } - void set_rect(int left, int top, int width, int height) - { - ASSERT(width > 0 && height > 0); - m_left = left; - m_top = top; - m_right = left + width - 1; - m_bottom = top + height -1; - } - bool pt_in_rect(int x, int y) const - { - return x >= m_left && x <= m_right && y >= m_top && y <= m_bottom; - } - int operator==(const c_rect& rect) const - { - return (m_left == rect.m_left) && (m_top == rect.m_top) && (m_right == rect.m_right) && (m_bottom == rect.m_bottom); - } - int width() const { return m_right - m_left + 1; } - int height() const { return m_bottom - m_top + 1 ; } - - int m_left; - int m_top; - int m_right; - int m_bottom; -}; +#define REAL_TIME_TASK_CYCLE_MS 50 +#define MAX(a,b) (((a)>(b))?(a):(b)) +#define MIN(a,b) (((a)<(b))?(a):(b)) +#define GL_ARGB(a, r, g, b) ((((unsigned int)(a)) << 24) | (((unsigned int)(r)) << 16) | (((unsigned int)(g)) << 8) | ((unsigned int)(b))) +#define GL_ARGB_A(rgb) ((((unsigned int)(rgb)) >> 24) & 0xFF) +#define GL_RGB(r, g, b) ((0xFF << 24) | (((unsigned int)(r)) << 16) | (((unsigned int)(g)) << 8) | ((unsigned int)(b))) +#define GL_RGB_R(rgb) ((((unsigned int)(rgb)) >> 16) & 0xFF) +#define GL_RGB_G(rgb) ((((unsigned int)(rgb)) >> 8) & 0xFF) +#define GL_RGB_B(rgb) (((unsigned int)(rgb)) & 0xFF) +#define GL_RGB_32_to_16(rgb) (((((unsigned int)(rgb)) & 0xFF) >> 3) | ((((unsigned int)(rgb)) & 0xFC00) >> 5) | ((((unsigned int)(rgb)) & 0xF80000) >> 8)) +#define GL_RGB_16_to_32(rgb) ((0xFF << 24) | ((((unsigned int)(rgb)) & 0x1F) << 3) | ((((unsigned int)(rgb)) & 0x7E0) << 5) | ((((unsigned int)(rgb)) & 0xF800) << 8)) +#define ALIGN_HCENTER 0x00000000L +#define ALIGN_LEFT 0x01000000L +#define ALIGN_RIGHT 0x02000000L +#define ALIGN_HMASK 0x03000000L +#define ALIGN_VCENTER 0x00000000L +#define ALIGN_TOP 0x00100000L +#define ALIGN_BOTTOM 0x00200000L +#define ALIGN_VMASK 0x00300000L +typedef struct +{ + unsigned short year; + unsigned short month; + unsigned short date; + unsigned short day; + unsigned short hour; + unsigned short minute; + unsigned short second; +}T_TIME; +void register_debug_function(void(*my_assert)(const char* file, int line), void(*my_log_out)(const char* log)); +void _assert(const char* file, int line); +#define ASSERT(condition) \ + do{ \ + if(!(condition))_assert(__FILE__, __LINE__);\ + }while(0) +void log_out(const char* log); +long get_time_in_second(); +T_TIME second_to_day(long second); +T_TIME get_time(); +void start_real_timer(void (*func)(void* arg)); +void register_timer(int milli_second, void func(void* param), void* param); +unsigned int get_cur_thread_id(); +void create_thread(unsigned long* thread_id, void* attr, void *(*start_routine) (void *), void* arg); +void thread_sleep(unsigned int milli_seconds); +int build_bmp(const char *filename, unsigned int width, unsigned int height, unsigned char *data); +#define FIFO_BUFFER_LEN 1024 +class c_fifo +{ +public: + c_fifo(); + int read(void* buf, int len); + int write(void* buf, int len); +private: + unsigned char m_buf[FIFO_BUFFER_LEN]; + int m_head; + int m_tail; + void* m_read_sem; + void* m_write_mutex; +}; +class c_rect +{ +public: + c_rect(){ m_left = m_top = m_right = m_bottom = -1; } + c_rect(int left, int top, int width, int height) + { + set_rect(left, top, width, height); + } + void set_rect(int left, int top, int width, int height) + { + ASSERT(width > 0 && height > 0); + m_left = left; + m_top = top; + m_right = left + width - 1; + m_bottom = top + height -1; + } + bool pt_in_rect(int x, int y) const + { + return x >= m_left && x <= m_right && y >= m_top && y <= m_bottom; + } + int operator==(const c_rect& rect) const + { + return (m_left == rect.m_left) && (m_top == rect.m_top) && (m_right == rect.m_right) && (m_bottom == rect.m_bottom); + } + int width() const { return m_right - m_left + 1; } + int height() const { return m_bottom - m_top + 1 ; } + int m_left; + int m_top; + int m_right; + int m_bottom; +}; //BITMAP typedef struct struct_bitmap_info { @@ -238,7 +225,7 @@ typedef enum Z_ORDER_LEVEL_2,//highest graphic level Z_ORDER_LEVEL_MAX }Z_ORDER_LEVEL; -struct EXTERNAL_GFX_OP +struct DISPLAY_DRIVER { void(*draw_pixel)(int x, int y, unsigned int rgb); void(*fill_rect)(int x0, int y0, int x1, int y1, unsigned int rgb); @@ -247,18 +234,19 @@ class c_surface; class c_display { friend class c_surface; public: - inline c_display(void* phy_fb, int display_width, int display_height, int surface_width, int surface_height, unsigned int color_bytes, int surface_cnt, EXTERNAL_GFX_OP* gfx_op = 0);//multiple surface or surface_no_fb - inline c_display(void* phy_fb, int display_width, int display_height, c_surface* surface);//single custom surface - inline c_surface* alloc_surface(Z_ORDER_LEVEL max_zorder, c_rect layer_rect = c_rect());//for multiple surfaces + inline c_display(void* phy_fb, int display_width, int display_height, c_surface* surface, DISPLAY_DRIVER* driver = 0);//single custom surface + inline c_display(void* phy_fb, int display_width, int display_height, int surface_width, int surface_height, unsigned int color_bytes, int surface_cnt, DISPLAY_DRIVER* driver = 0);//multiple surface + inline c_surface* alloc_surface(Z_ORDER_LEVEL max_zorder, c_rect layer_rect = c_rect());//for slide group inline int swipe_surface(c_surface* s0, c_surface* s1, int x0, int x1, int y0, int y1, int offset); int get_width() { return m_width; } int get_height() { return m_height; } + void* get_phy_fb() { return m_phy_fb; } void* get_updated_fb(int* width, int* height, bool force_update = false) { if (width && height) { - *width = get_width(); - *height = get_height(); + *width = m_width; + *height = m_height; } if (force_update) { @@ -277,35 +265,123 @@ public: { return -1; } - int width = get_width(); - int height = get_height(); //16 bits framebuffer if (m_color_bytes == 2) { - return build_bmp(file_name, width, height, (unsigned char*)m_phy_fb); + return build_bmp(file_name, m_width, m_height, (unsigned char*)m_phy_fb); } //32 bits framebuffer - unsigned short* p_bmp565_data = new unsigned short[width * height]; + unsigned short* p_bmp565_data = new unsigned short[m_width * m_height]; unsigned int* p_raw_data = (unsigned int*)m_phy_fb; - for (int i = 0; i < width * height; i++) + for (int i = 0; i < m_width * m_height; i++) { unsigned int rgb = *p_raw_data++; p_bmp565_data[i] = GL_RGB_32_to_16(rgb); } - int ret = build_bmp(file_name, width, height, (unsigned char*)p_bmp565_data); + int ret = build_bmp(file_name, m_width, m_height, (unsigned char*)p_bmp565_data); delete[]p_bmp565_data; return ret; } -private: - int m_width; //in pixels - int m_height; //in pixels - int m_color_bytes; //16 bits, 32 bits only - void* m_phy_fb; //physical framebuffer +protected: + virtual void draw_pixel(int x, int y, unsigned int rgb) + { + if ((x >= m_width) || (y >= m_height)) { return; } + if (m_driver && m_driver->draw_pixel) + { + return m_driver->draw_pixel(x, y, rgb); + } + if (m_color_bytes == 2) + { + ((unsigned short*)m_phy_fb)[y * m_width + x] = GL_RGB_32_to_16(rgb); + } + else + { + ((unsigned int*)m_phy_fb)[y * m_width + x] = rgb; + } + } + virtual void fill_rect(int x0, int y0, int x1, int y1, unsigned int rgb) + { + if (m_driver && m_driver->fill_rect) + { + return m_driver->fill_rect(x0, y0, x1, y1, rgb); + } + if (m_driver && m_driver->draw_pixel) + { + for (int y = y0; y <= y1; y++) + { + for (int x = x0; x <= x1; x++) + { + m_driver->draw_pixel(x, y, rgb); + } + } + return; + } + register int _width = m_width; + register int _height = m_height; + int x, y; + if (m_color_bytes == 2) + { + unsigned short* phy_fb; + unsigned int rgb_16 = GL_RGB_32_to_16(rgb); + for (y = y0; y <= y1; y++) + { + phy_fb = &((unsigned short*)m_phy_fb)[y * _width + x0]; + for (x = x0; x <= x1; x++) + { + if ((x < _width) && (y < _height)) + { + *phy_fb++ = rgb_16; + } + } + } + } + else + { + unsigned int* phy_fb; + for (y = y0; y <= y1; y++) + { + phy_fb = &((unsigned int*)m_phy_fb)[y * _width + x0]; + for (x = x0; x <= x1; x++) + { + if ((x < _width) && (y < _height)) + { + *phy_fb++ = rgb; + } + } + } + } + } + virtual int flush_screen(int left, int top, int right, int bottom, void* fb, int fb_width) + { + if ((0 == m_phy_fb) || (0 == fb)) + { + return -1; + } + register int _width = m_width; + register int _height = m_height; + left = (left >= _width) ? (_width - 1) : left; + right = (right >= _width) ? (_width - 1) : right; + top = (top >= _height) ? (_height - 1) : top; + bottom = (bottom >= _height) ? (_height - 1) : bottom; + for (int y = top; y < bottom; y++) + { + void* s_addr = (char*)fb + ((y * fb_width + left) * m_color_bytes); + void* d_addr = (char*)m_phy_fb + ((y * _width + left) * m_color_bytes); + memcpy(d_addr, s_addr, (right - left) * m_color_bytes); + } + return 0; + } + int m_width; //in pixels + int m_height; //in pixels + int m_color_bytes; //16/32 bits for default + void* m_phy_fb; //physical framebuffer for default + struct DISPLAY_DRIVER* m_driver; //Rendering by external method without default physical framebuffer int m_phy_read_index; int m_phy_write_index; c_surface* m_surface_group[SURFACE_CNT_MAX]; int m_surface_cnt; //surface count int m_surface_index; + }; class c_layer { @@ -317,12 +393,10 @@ public: class c_surface { friend class c_display; friend class c_bitmap_operator; public: - c_surface(unsigned int width, unsigned int height, unsigned int color_bytes, Z_ORDER_LEVEL max_zorder = Z_ORDER_LEVEL_0, c_rect overlpa_rect = c_rect()) : m_width(width), m_height(height), m_color_bytes(color_bytes), m_fb(0), m_is_active(false), m_top_zorder(Z_ORDER_LEVEL_0), m_phy_fb(0), m_phy_write_index(0), m_display(0) + c_surface(unsigned int width, unsigned int height, unsigned int color_bytes, Z_ORDER_LEVEL max_zorder = Z_ORDER_LEVEL_0, c_rect overlpa_rect = c_rect()) : m_width(width), m_height(height), m_color_bytes(color_bytes), m_fb(0), m_is_active(false), m_top_zorder(Z_ORDER_LEVEL_0), m_phy_write_index(0), m_display(0) { (overlpa_rect == c_rect()) ? set_surface(max_zorder, c_rect(0, 0, width - 1, height - 1)) : set_surface(max_zorder, overlpa_rect); } - int get_width() { return m_width; } - int get_height() { return m_height; } unsigned int get_pixel(int x, int y, unsigned int z_order) { if (x >= m_width || y >= m_height || x < 0 || y < 0 || z_order >= Z_ORDER_LEVEL_MAX) @@ -332,15 +406,15 @@ public: } if (m_layers[z_order].fb) { - return (m_color_bytes == 4) ? ((unsigned int*)(m_layers[z_order].fb))[y * m_width + x] : GL_RGB_16_to_32(((unsigned short*)(m_layers[z_order].fb))[y * m_width + x]); + return (m_color_bytes == 2) ? GL_RGB_16_to_32(((unsigned short*)(m_layers[z_order].fb))[y * m_width + x]) : ((unsigned int*)(m_layers[z_order].fb))[y * m_width + x]; } else if (m_fb) { - return (m_color_bytes == 4) ? ((unsigned int*)m_fb)[y * m_width + x] : GL_RGB_16_to_32(((unsigned short*)m_fb)[y * m_width + x]); + return (m_color_bytes == 2) ? GL_RGB_16_to_32(((unsigned short*)m_fb)[y * m_width + x]) : ((unsigned int*)m_fb)[y * m_width + x]; } - else if (m_phy_fb) + else if (m_display->m_phy_fb) { - return (m_color_bytes == 4) ? ((unsigned int*)m_phy_fb)[y * m_width + x] : GL_RGB_16_to_32(((unsigned short*)m_phy_fb)[y * m_width + x]); + return (m_color_bytes == 2) ? GL_RGB_16_to_32(((unsigned short*)m_display->m_phy_fb)[y * m_width + x]) : ((unsigned int*)m_display->m_phy_fb)[y * m_width + x]; } return 0; } @@ -357,7 +431,7 @@ public: } if (z_order == m_max_zorder) { - return draw_pixel_on_fb(x, y, rgb); + return draw_pixel_low_level(x, y, rgb); } if (z_order > (unsigned int)m_top_zorder) @@ -367,19 +441,19 @@ public: if (m_layers[z_order].rect.pt_in_rect(x, y)) { c_rect layer_rect = m_layers[z_order].rect; - if (m_color_bytes == 4) + if (m_color_bytes == 2) { - ((unsigned int*)(m_layers[z_order].fb))[(x - layer_rect.m_left) + (y - layer_rect.m_top) * layer_rect.width()] = rgb; + ((unsigned short*)(m_layers[z_order].fb))[(x - layer_rect.m_left) + (y - layer_rect.m_top) * layer_rect.width()] = GL_RGB_32_to_16(rgb); } else { - ((unsigned short*)(m_layers[z_order].fb))[(x - layer_rect.m_left) + (y - layer_rect.m_top) * layer_rect.width()] = GL_RGB_32_to_16(rgb); + ((unsigned int*)(m_layers[z_order].fb))[(x - layer_rect.m_left) + (y - layer_rect.m_top) * layer_rect.width()] = rgb; } } if (z_order == m_top_zorder) { - return draw_pixel_on_fb(x, y, rgb); + return draw_pixel_low_level(x, y, rgb); } bool be_overlapped = false; for (unsigned int tmp_z_order = Z_ORDER_LEVEL_MAX - 1; tmp_z_order > z_order; tmp_z_order--) @@ -392,7 +466,7 @@ public: } if (!be_overlapped) { - draw_pixel_on_fb(x, y, rgb); + draw_pixel_low_level(x, y, rgb); } } virtual void fill_rect(int x0, int y0, int x1, int y1, unsigned int rgb, unsigned int z_order) @@ -403,7 +477,7 @@ public: y1 = (y1 > (m_height - 1)) ? (m_height - 1) : y1; if (z_order == m_max_zorder) { - return fill_rect_on_fb(x0, y0, x1, y1, rgb); + return fill_rect_low_level(x0, y0, x1, y1, rgb); } if (z_order == m_top_zorder) { @@ -416,18 +490,18 @@ public: { if (layer_rect.pt_in_rect(x, y)) { - if (m_color_bytes == 4) + if (m_color_bytes == 2) { - ((unsigned int*)m_layers[z_order].fb)[(y - layer_rect.m_top) * layer_rect.width() + (x - layer_rect.m_left)] = rgb; + ((unsigned short*)m_layers[z_order].fb)[(y - layer_rect.m_top) * layer_rect.width() + (x - layer_rect.m_left)] = rgb_16; } else { - ((unsigned short*)m_layers[z_order].fb)[(y - layer_rect.m_top) * layer_rect.width() + (x - layer_rect.m_left)] = rgb_16; + ((unsigned int*)m_layers[z_order].fb)[(y - layer_rect.m_top) * layer_rect.width() + (x - layer_rect.m_left)] = rgb; } } } } - return fill_rect_on_fb(x0, y0, x1, y1, rgb); + return fill_rect_low_level(x0, y0, x1, y1, rgb); } for (; y0 <= y1; y0++) { @@ -499,27 +573,16 @@ public: } int flush_screen(int left, int top, int right, int bottom) { - if (left < 0 || left >= m_width || right < 0 || right >= m_width || - top < 0 || top >= m_height || bottom < 0 || bottom >= m_height) - { - ASSERT(false); - } - if (!m_is_active || (0 == m_phy_fb) || (0 == m_fb)) + if (!m_is_active) { return -1; } - int display_width = m_display->get_width(); - int display_height = m_display->get_height(); - left = (left >= display_width) ? (display_width - 1) : left; - right = (right >= display_width) ? (display_width - 1) : right; - top = (top >= display_height) ? (display_height - 1) : top; - bottom = (bottom >= display_height) ? (display_height - 1) : bottom; - for (int y = top; y < bottom; y++) + if (left < 0 || left >= m_width || right < 0 || right >= m_width || + top < 0 || top >= m_height || bottom < 0 || bottom >= m_height) { - void* s_addr = (char*)m_fb + ((y * m_width + left) * m_color_bytes); - void* d_addr = (char*)m_phy_fb + ((y * display_width + left) * m_color_bytes); - memcpy(d_addr, s_addr, (right - left) * m_color_bytes); + ASSERT(false); } + m_display->flush_screen(left, top, right, bottom, m_fb, m_width); *m_phy_write_index = *m_phy_write_index + 1; return 0; } @@ -537,90 +600,62 @@ public: { for (int x = rect.m_left; x <= rect.m_right; x++) { - unsigned int rgb = (m_color_bytes == 4) ? ((unsigned int*)fb)[(x - layer_rect.m_left) + (y - layer_rect.m_top) * width] : GL_RGB_16_to_32(((unsigned short*)fb)[(x - layer_rect.m_left) + (y - layer_rect.m_top) * width]); - draw_pixel_on_fb(x, y, rgb); + unsigned int rgb = (m_color_bytes == 2) ? GL_RGB_16_to_32(((unsigned short*)fb)[(x - layer_rect.m_left) + (y - layer_rect.m_top) * width]) : ((unsigned int*)fb)[(x - layer_rect.m_left) + (y - layer_rect.m_top) * width]; + draw_pixel_low_level(x, y, rgb); } } return 0; } void set_active(bool flag) { m_is_active = flag; } protected: - virtual void fill_rect_on_fb(int x0, int y0, int x1, int y1, unsigned int rgb) - { - int display_width = m_display->get_width(); - int display_height = m_display->get_height(); - if (m_color_bytes == 4) + virtual void fill_rect_low_level(int x0, int y0, int x1, int y1, unsigned int rgb) + {//fill rect on framebuffer of surface + int x, y; + if (m_color_bytes == 2) { - int x; - unsigned int* fb, * phy_fb; - for (; y0 <= y1; y0++) + unsigned short* fb; + unsigned int rgb_16 = GL_RGB_32_to_16(rgb); + for (y = y0; y <= y1; y++) { - x = x0; - fb = m_fb ? &((unsigned int*)m_fb)[y0 * m_width + x] : 0; - phy_fb = &((unsigned int*)m_phy_fb)[y0 * display_width + x]; - *m_phy_write_index = *m_phy_write_index + 1; - for (; x <= x1; x++) + fb = m_fb ? &((unsigned short*)m_fb)[y * m_width + x0] : 0; + if (!fb) { break; } + for (x = x0; x <= x1; x++) { - if (fb) - { - *fb++ = rgb; - } - if (m_is_active && (x < display_width) && (y0 < display_height)) - { - *phy_fb++ = rgb; - } + *fb++ = rgb_16; } } } - else if (m_color_bytes == 2) + else { - int x; - unsigned short* fb, * phy_fb; - rgb = GL_RGB_32_to_16(rgb); - for (; y0 <= y1; y0++) + unsigned int* fb; + for (y = y0; y <= y1; y++) { - x = x0; - fb = m_fb ? &((unsigned short*)m_fb)[y0 * m_width + x] : 0; - phy_fb = &((unsigned short*)m_phy_fb)[y0 * display_width + x]; - *m_phy_write_index = *m_phy_write_index + 1; - for (; x <= x1; x++) + fb = m_fb ? &((unsigned int*)m_fb)[y * m_width + x0] : 0; + if (!fb) { break; } + for (x = x0; x <= x1; x++) { - if (fb) - { - *fb++ = rgb; - } - if (m_is_active && (x < display_width) && (y0 < display_height)) - { - *phy_fb++ = rgb; - } + *fb++ = rgb; } } } + if (!m_is_active) { return; } + m_display->fill_rect(x0, y0, x1, y1, rgb); + *m_phy_write_index = *m_phy_write_index + 1; } - virtual void draw_pixel_on_fb(int x, int y, unsigned int rgb) + virtual void draw_pixel_low_level(int x, int y, unsigned int rgb) { if (m_fb) - { - (m_color_bytes == 4) ? ((unsigned int*)m_fb)[y * m_width + x] = rgb : ((unsigned short*)m_fb)[y * m_width + x] = GL_RGB_32_to_16(rgb); - } - if (m_is_active && (x < m_display->get_width()) && (y < m_display->get_height())) - { - if (m_color_bytes == 4) - { - ((unsigned int*)m_phy_fb)[y * (m_display->get_width()) + x] = rgb; - } - else - { - ((unsigned short*)m_phy_fb)[y * (m_display->get_width()) + x] = GL_RGB_32_to_16(rgb); - } - *m_phy_write_index = *m_phy_write_index + 1; + {//draw pixel on framebuffer of surface + (m_color_bytes == 2) ? ((unsigned short*)m_fb)[y * m_width + x] = GL_RGB_32_to_16(rgb): ((unsigned int*)m_fb)[y * m_width + x] = rgb; } + if (!m_is_active) { return; } + m_display->draw_pixel(x, y, rgb); + *m_phy_write_index = *m_phy_write_index + 1; } void attach_display(c_display* display) { ASSERT(display); m_display = display; - m_phy_fb = display->m_phy_fb; m_phy_write_index = &display->m_phy_write_index; } void set_surface(Z_ORDER_LEVEL max_z_order, c_rect layer_rect) @@ -638,87 +673,22 @@ protected: } int m_width; //in pixels int m_height; //in pixels - int m_color_bytes; //16 bits, 32 bits only + int m_color_bytes; //16 bits, 32 bits for default void* m_fb; //frame buffer you could see c_layer m_layers[Z_ORDER_LEVEL_MAX];//all graphic layers bool m_is_active; //active flag Z_ORDER_LEVEL m_max_zorder; //the highest graphic layer the surface will have Z_ORDER_LEVEL m_top_zorder; //the current highest graphic layer the surface have - void* m_phy_fb; //physical framebufer int* m_phy_write_index; c_display* m_display; }; -class c_surface_no_fb : public c_surface {//No physical framebuffer, render with external graphic interface - friend class c_display; -public: - c_surface_no_fb(unsigned int width, unsigned int height, unsigned int color_bytes, struct EXTERNAL_GFX_OP* gfx_op, Z_ORDER_LEVEL max_zorder = Z_ORDER_LEVEL_0, c_rect overlpa_rect = c_rect()) : c_surface(width, height, color_bytes, max_zorder, overlpa_rect), m_gfx_op(gfx_op) {} -protected: - virtual void fill_rect_on_fb(int x0, int y0, int x1, int y1, unsigned int rgb) - { - if (!m_gfx_op) - { - return; - } - if (m_gfx_op->fill_rect) - { - return m_gfx_op->fill_rect(x0, y0, x1, y1, rgb); - } - if (m_gfx_op->draw_pixel && m_is_active) - { - for (int y = y0; y <= y1; y++) - { - for (int x = x0; x <= x1; x++) - { - m_gfx_op->draw_pixel(x, y, rgb); - } - } - } - if (!m_fb) { return; } - if (m_color_bytes == 4) - { - unsigned int* fb; - for (int y = y0; y <= y1; y++) - { - fb = &((unsigned int*)m_fb)[y0 * m_width + x0]; - for (int x = x0; x <= x1; x++) - { - *fb++ = rgb; - } - } - } - else if (m_color_bytes == 2) - { - unsigned short* fb; - rgb = GL_RGB_32_to_16(rgb); - for (int y = y0; y <= y1; y++) - { - fb = &((unsigned short*)m_fb)[y0 * m_width + x0]; - for (int x = x0; x <= x1; x++) - { - *fb++ = rgb; - } - } - } - } - virtual void draw_pixel_on_fb(int x, int y, unsigned int rgb) - { - if (m_gfx_op && m_gfx_op->draw_pixel && m_is_active) - { - m_gfx_op->draw_pixel(x, y, rgb); - } - if (!m_fb) { return; } - if (m_color_bytes == 4) - { - ((unsigned int*)m_fb)[y * m_width + x] = rgb; - } - else if (m_color_bytes == 2) - { - ((unsigned short*)m_fb)[y * m_width + x] = GL_RGB_32_to_16(rgb); - } - } - struct EXTERNAL_GFX_OP* m_gfx_op;//Rendering by external method -}; -inline c_display::c_display(void* phy_fb, int display_width, int display_height, int surface_width, int surface_height, unsigned int color_bytes, int surface_cnt, EXTERNAL_GFX_OP* gfx_op) : m_width(display_width), m_height(display_height), m_color_bytes(color_bytes), m_phy_fb(phy_fb), m_phy_read_index(0), m_phy_write_index(0), m_surface_cnt(surface_cnt), m_surface_index(0) +inline c_display::c_display(void* phy_fb, int display_width, int display_height, c_surface* surface, DISPLAY_DRIVER* driver) : m_phy_fb(phy_fb), m_width(display_width), m_height(display_height), m_driver(driver), m_phy_read_index(0), m_phy_write_index(0), m_surface_cnt(1), m_surface_index(0) +{ + m_color_bytes = surface->m_color_bytes; + surface->m_is_active = true; + (m_surface_group[0] = surface)->attach_display(this); +} +inline c_display::c_display(void* phy_fb, int display_width, int display_height, int surface_width, int surface_height, unsigned int color_bytes, int surface_cnt, DISPLAY_DRIVER* driver) : m_phy_fb(phy_fb), m_width(display_width), m_height(display_height), m_color_bytes(color_bytes), m_phy_read_index(0), m_phy_write_index(0), m_surface_cnt(surface_cnt), m_driver(driver), m_surface_index(0) { ASSERT(color_bytes == 2 || color_bytes == 4); ASSERT(m_surface_cnt <= SURFACE_CNT_MAX); @@ -726,16 +696,10 @@ inline c_display::c_display(void* phy_fb, int display_width, int display_height, for (int i = 0; i < m_surface_cnt; i++) { - m_surface_group[i] = (phy_fb) ? new c_surface(surface_width, surface_height, color_bytes) : new c_surface_no_fb(surface_width, surface_height, color_bytes, gfx_op); + m_surface_group[i] = new c_surface(surface_width, surface_height, color_bytes); m_surface_group[i]->attach_display(this); } } -inline c_display::c_display(void* phy_fb, int display_width, int display_height, c_surface* surface) : m_width(display_width), m_height(display_height), m_phy_fb(phy_fb), m_phy_read_index(0), m_phy_write_index(0), m_surface_cnt(1), m_surface_index(0) -{ - m_color_bytes = surface->m_color_bytes; - surface->m_is_active = true; - (m_surface_group[0] = surface)->attach_display(this); -} inline c_surface* c_display::alloc_surface(Z_ORDER_LEVEL max_zorder, c_rect layer_rect) { ASSERT(max_zorder < Z_ORDER_LEVEL_MAX && m_surface_index < m_surface_cnt); @@ -744,8 +708,8 @@ inline c_surface* c_display::alloc_surface(Z_ORDER_LEVEL max_zorder, c_rect laye } inline int c_display::swipe_surface(c_surface* s0, c_surface* s1, int x0, int x1, int y0, int y1, int offset) { - int surface_width = s0->get_width(); - int surface_height = s0->get_height(); + register int surface_width = s0->m_width; + register int surface_height = s0->m_height; if (offset < 0 || offset > surface_width || y0 < 0 || y0 >= surface_height || y1 < 0 || y1 >= surface_height || x0 < 0 || x0 >= surface_width || x1 < 0 || x1 >= surface_width) { @@ -767,46 +731,46 @@ inline int c_display::swipe_surface(c_surface* s0, c_surface* s1, int x0, int x1 for (int y = y0; y <= y1; y++) { //Left surface - char* addr_s = ((char*)(s0->m_fb) + (y * (s0->get_width()) + x0 + offset) * m_color_bytes); + char* addr_s = ((char*)(s0->m_fb) + (y * surface_width + x0 + offset) * m_color_bytes); char* addr_d = ((char*)(m_phy_fb)+(y * m_width + x0) * m_color_bytes); memcpy(addr_d, addr_s, (width - offset) * m_color_bytes); //Right surface - addr_s = ((char*)(s1->m_fb) + (y * (s1->get_width()) + x0) * m_color_bytes); + addr_s = ((char*)(s1->m_fb) + (y * surface_width + x0) * m_color_bytes); addr_d = ((char*)(m_phy_fb)+(y * m_width + x0 + (width - offset)) * m_color_bytes); memcpy(addr_d, addr_s, offset * m_color_bytes); } } - else if (m_color_bytes == 4) + else if (m_color_bytes == 2) { - void(*draw_pixel)(int x, int y, unsigned int rgb) = ((c_surface_no_fb*)s0)->m_gfx_op->draw_pixel; + void(*draw_pixel)(int x, int y, unsigned int rgb) = m_driver->draw_pixel; for (int y = y0; y <= y1; y++) { //Left surface for (int x = x0; x <= (x1 - offset); x++) { - draw_pixel(x, y, ((unsigned int*)s0->m_fb)[y * m_width + x + offset]); + draw_pixel(x, y, GL_RGB_16_to_32(((unsigned short*)s0->m_fb)[y * m_width + x + offset])); } //Right surface for (int x = x1 - offset; x <= x1; x++) { - draw_pixel(x, y, ((unsigned int*)s1->m_fb)[y * m_width + x + offset - x1 + x0]); + draw_pixel(x, y, GL_RGB_16_to_32(((unsigned short*)s1->m_fb)[y * m_width + x + offset - x1 + x0])); } } } - else if (m_color_bytes == 2) + else //m_color_bytes == 3/4... { - void(*draw_pixel)(int x, int y, unsigned int rgb) = ((c_surface_no_fb*)s0)->m_gfx_op->draw_pixel; + void(*draw_pixel)(int x, int y, unsigned int rgb) = m_driver->draw_pixel; for (int y = y0; y <= y1; y++) { //Left surface for (int x = x0; x <= (x1 - offset); x++) { - draw_pixel(x, y, GL_RGB_16_to_32(((unsigned short*)s0->m_fb)[y * m_width + x + offset])); + draw_pixel(x, y, ((unsigned int*)s0->m_fb)[y * m_width + x + offset]); } //Right surface for (int x = x1 - offset; x <= x1; x++) { - draw_pixel(x, y, GL_RGB_16_to_32(((unsigned short*)s1->m_fb)[y * m_width + x + offset - x1 + x0])); + draw_pixel(x, y, ((unsigned int*)s1->m_fb)[y * m_width + x + offset - x1 + x0]); } } } @@ -3407,22 +3371,12 @@ private: #ifdef GUILITE_ON c_bitmap_operator the_bitmap_op = c_bitmap_operator(); c_image_operator* c_image::image_operator = &the_bitmap_op; +const void* c_theme::s_font_map[FONT_MAX]; +const void* c_theme::s_image_map[IMAGE_MAX]; +unsigned int c_theme::s_color_map[COLOR_MAX]; +c_lattice_font_op the_lattice_font_op = c_lattice_font_op(); +c_font_operator* c_word::fontOperator = &the_lattice_font_op; #endif - -#ifdef GUILITE_ON - -const void* c_theme::s_font_map[FONT_MAX]; -const void* c_theme::s_image_map[IMAGE_MAX]; -unsigned int c_theme::s_color_map[COLOR_MAX]; - -#endif - -#ifdef GUILITE_ON - -c_lattice_font_op the_lattice_font_op = c_lattice_font_op(); -c_font_operator* c_word::fontOperator = &the_lattice_font_op; - -#endif #ifdef GUILITE_ON #if (defined __linux__) || (defined __APPLE__) #include @@ -4264,11 +4218,7 @@ int c_fifo::write(void* buf, int len) #endif #ifdef GUILITE_ON DIALOG_ARRAY c_dialog::ms_the_dialogs[SURFACE_CNT_MAX]; -#endif -#ifdef GUILITE_ON c_keyboard c_edit::s_keyboard; -#endif -#ifdef GUILITE_ON static c_keyboard_button s_key_0, s_key_1, s_key_2, s_key_3, s_key_4, s_key_5, s_key_6, s_key_7, s_key_8, s_key_9; static c_keyboard_button s_key_A, s_key_B, s_key_C, s_key_D, s_key_E, s_key_F, s_key_G, s_key_H, s_key_I, s_key_J; static c_keyboard_button s_key_K, s_key_L, s_key_M, s_key_N, s_key_O, s_key_P, s_key_Q, s_key_R, s_key_S, s_key_T; @@ -4306,12 +4256,12 @@ WND_TREE g_key_board_children[] = {&s_key_B, 'B', 0, ((KEY_WIDTH / 2) + POS_X(5)), POS_Y(2), KEY_WIDTH, KEY_HEIGHT}, {&s_key_N, 'N', 0, ((KEY_WIDTH / 2) + POS_X(6)), POS_Y(2), KEY_WIDTH, KEY_HEIGHT}, {&s_key_M, 'M', 0, ((KEY_WIDTH / 2) + POS_X(7)), POS_Y(2), KEY_WIDTH, KEY_HEIGHT}, - {&s_key_del, 0x7F, 0, ((KEY_WIDTH / 2) + POS_X(8)), POS_Y(2), DEL_WIDTH, KEY_HEIGHT}, + {&s_key_del,0x7F, 0, ((KEY_WIDTH / 2) + POS_X(8)), POS_Y(2), DEL_WIDTH, KEY_HEIGHT}, //Row 4 - {&s_key_esc, 0x1B, 0, POS_X(0), POS_Y(3), ESC_WIDTH, KEY_HEIGHT}, + {&s_key_esc, 0x1B, 0, POS_X(0), POS_Y(3), ESC_WIDTH, KEY_HEIGHT}, {&s_key_num_switch, 0x90, 0, POS_X(2), POS_Y(3), SWITCH_WIDTH, KEY_HEIGHT}, {&s_key_space, ' ', 0, ((KEY_WIDTH / 2) + POS_X(3)), POS_Y(3), SPACE_WIDTH, KEY_HEIGHT}, - {&s_key_dot, '.', 0, ((KEY_WIDTH / 2) + POS_X(6)), POS_Y(3), DOT_WIDTH, KEY_HEIGHT}, + {&s_key_dot, '.', 0, ((KEY_WIDTH / 2) + POS_X(6)), POS_Y(3), DOT_WIDTH, KEY_HEIGHT}, {&s_key_enter, '\n', 0, POS_X(8), POS_Y(3), ENTER_WIDTH, KEY_HEIGHT}, {0,0,0,0,0,0,0} }; @@ -4326,12 +4276,11 @@ WND_TREE g_number_board_children[] = {&s_key_7, '7', 0, POS_X(0), POS_Y(2), KEY_WIDTH, KEY_HEIGHT}, {&s_key_8, '8', 0, POS_X(1), POS_Y(2), KEY_WIDTH, KEY_HEIGHT}, {&s_key_9, '9', 0, POS_X(2), POS_Y(2), KEY_WIDTH, KEY_HEIGHT}, - - {&s_key_esc, 0x1B, 0, POS_X(0), POS_Y(3), KEY_WIDTH, KEY_HEIGHT}, + {&s_key_esc,0x1B, 0, POS_X(0), POS_Y(3), KEY_WIDTH, KEY_HEIGHT}, {&s_key_0, '0', 0, POS_X(1), POS_Y(3), KEY_WIDTH, KEY_HEIGHT}, - {&s_key_dot, '.', 0, POS_X(2), POS_Y(3), KEY_WIDTH, KEY_HEIGHT}, + {&s_key_dot,'.', 0, POS_X(2), POS_Y(3), KEY_WIDTH, KEY_HEIGHT}, {&s_key_del, 0x7F, 0, POS_X(3), POS_Y(0), KEY_WIDTH, KEY_HEIGHT * 2 + 2}, {&s_key_enter,'\n', 0, POS_X(3), POS_Y(2), KEY_WIDTH, KEY_HEIGHT * 2 + 2}, {0,0,0,0,0,0,0} }; -#endif +#endif \ No newline at end of file diff --git a/HostMonitor/BuildLinux/.sync_data.sh b/HostMonitor/BuildLinux/.sync_data.sh index 15c47c5d4398f1b6a0419f6d0ec69cab9f2b741a..d3d934ee0eb9bba35791a4c870a35e4324205690 100644 --- a/HostMonitor/BuildLinux/.sync_data.sh +++ b/HostMonitor/BuildLinux/.sync_data.sh @@ -1,5 +1,6 @@ if [ "$#" -ne 6 ]; then - echo "Invalid arguments" + echo "Do testing" + ./xWindow 1024 768 | ./HostMonitor shared-fb exit -1 fi diff --git a/HostMonitor/UIcode/include/GuiLite.h b/HostMonitor/UIcode/include/GuiLite.h index c4fc88a51476d2c8309c3e55e1270e13784fc510..80550e1632ad7bc82541a2edbb0f7f8f5937954f 100644 --- a/HostMonitor/UIcode/include/GuiLite.h +++ b/HostMonitor/UIcode/include/GuiLite.h @@ -1,107 +1,94 @@ #pragma once - -#define REAL_TIME_TASK_CYCLE_MS 50 -#define MAX(a,b) (((a)>(b))?(a):(b)) -#define MIN(a,b) (((a)<(b))?(a):(b)) - -#define GL_ARGB(a, r, g, b) ((((unsigned int)(a)) << 24) | (((unsigned int)(r)) << 16) | (((unsigned int)(g)) << 8) | ((unsigned int)(b))) -#define GL_ARGB_A(rgb) ((((unsigned int)(rgb)) >> 24) & 0xFF) - -#define GL_RGB(r, g, b) ((0xFF << 24) | (((unsigned int)(r)) << 16) | (((unsigned int)(g)) << 8) | ((unsigned int)(b))) -#define GL_RGB_R(rgb) ((((unsigned int)(rgb)) >> 16) & 0xFF) -#define GL_RGB_G(rgb) ((((unsigned int)(rgb)) >> 8) & 0xFF) -#define GL_RGB_B(rgb) (((unsigned int)(rgb)) & 0xFF) -#define GL_RGB_32_to_16(rgb) (((((unsigned int)(rgb)) & 0xFF) >> 3) | ((((unsigned int)(rgb)) & 0xFC00) >> 5) | ((((unsigned int)(rgb)) & 0xF80000) >> 8)) -#define GL_RGB_16_to_32(rgb) ((0xFF << 24) | ((((unsigned int)(rgb)) & 0x1F) << 3) | ((((unsigned int)(rgb)) & 0x7E0) << 5) | ((((unsigned int)(rgb)) & 0xF800) << 8)) - -#define ALIGN_HCENTER 0x00000000L -#define ALIGN_LEFT 0x01000000L -#define ALIGN_RIGHT 0x02000000L -#define ALIGN_HMASK 0x03000000L - -#define ALIGN_VCENTER 0x00000000L -#define ALIGN_TOP 0x00100000L -#define ALIGN_BOTTOM 0x00200000L -#define ALIGN_VMASK 0x00300000L - -typedef struct -{ - unsigned short year; - unsigned short month; - unsigned short date; - unsigned short day; - unsigned short hour; - unsigned short minute; - unsigned short second; -}T_TIME; - -void register_debug_function(void(*my_assert)(const char* file, int line), void(*my_log_out)(const char* log)); -void _assert(const char* file, int line); -#define ASSERT(condition) \ - do{ \ - if(!(condition))_assert(__FILE__, __LINE__);\ - }while(0) -void log_out(const char* log); - -long get_time_in_second(); -T_TIME second_to_day(long second); -T_TIME get_time(); - -void start_real_timer(void (*func)(void* arg)); -void register_timer(int milli_second, void func(void* param), void* param); - -unsigned int get_cur_thread_id(); -void create_thread(unsigned long* thread_id, void* attr, void *(*start_routine) (void *), void* arg); -void thread_sleep(unsigned int milli_seconds); -int build_bmp(const char *filename, unsigned int width, unsigned int height, unsigned char *data); - -#define FIFO_BUFFER_LEN 1024 -class c_fifo -{ -public: - c_fifo(); - int read(void* buf, int len); - int write(void* buf, int len); -private: - unsigned char m_buf[FIFO_BUFFER_LEN]; - int m_head; - int m_tail; - void* m_read_sem; - void* m_write_mutex; -}; - -class c_rect -{ -public: - c_rect(){ m_left = m_top = m_right = m_bottom = -1; } - c_rect(int left, int top, int width, int height) - { - set_rect(left, top, width, height); - } - void set_rect(int left, int top, int width, int height) - { - ASSERT(width > 0 && height > 0); - m_left = left; - m_top = top; - m_right = left + width - 1; - m_bottom = top + height -1; - } - bool pt_in_rect(int x, int y) const - { - return x >= m_left && x <= m_right && y >= m_top && y <= m_bottom; - } - int operator==(const c_rect& rect) const - { - return (m_left == rect.m_left) && (m_top == rect.m_top) && (m_right == rect.m_right) && (m_bottom == rect.m_bottom); - } - int width() const { return m_right - m_left + 1; } - int height() const { return m_bottom - m_top + 1 ; } - - int m_left; - int m_top; - int m_right; - int m_bottom; -}; +#define REAL_TIME_TASK_CYCLE_MS 50 +#define MAX(a,b) (((a)>(b))?(a):(b)) +#define MIN(a,b) (((a)<(b))?(a):(b)) +#define GL_ARGB(a, r, g, b) ((((unsigned int)(a)) << 24) | (((unsigned int)(r)) << 16) | (((unsigned int)(g)) << 8) | ((unsigned int)(b))) +#define GL_ARGB_A(rgb) ((((unsigned int)(rgb)) >> 24) & 0xFF) +#define GL_RGB(r, g, b) ((0xFF << 24) | (((unsigned int)(r)) << 16) | (((unsigned int)(g)) << 8) | ((unsigned int)(b))) +#define GL_RGB_R(rgb) ((((unsigned int)(rgb)) >> 16) & 0xFF) +#define GL_RGB_G(rgb) ((((unsigned int)(rgb)) >> 8) & 0xFF) +#define GL_RGB_B(rgb) (((unsigned int)(rgb)) & 0xFF) +#define GL_RGB_32_to_16(rgb) (((((unsigned int)(rgb)) & 0xFF) >> 3) | ((((unsigned int)(rgb)) & 0xFC00) >> 5) | ((((unsigned int)(rgb)) & 0xF80000) >> 8)) +#define GL_RGB_16_to_32(rgb) ((0xFF << 24) | ((((unsigned int)(rgb)) & 0x1F) << 3) | ((((unsigned int)(rgb)) & 0x7E0) << 5) | ((((unsigned int)(rgb)) & 0xF800) << 8)) +#define ALIGN_HCENTER 0x00000000L +#define ALIGN_LEFT 0x01000000L +#define ALIGN_RIGHT 0x02000000L +#define ALIGN_HMASK 0x03000000L +#define ALIGN_VCENTER 0x00000000L +#define ALIGN_TOP 0x00100000L +#define ALIGN_BOTTOM 0x00200000L +#define ALIGN_VMASK 0x00300000L +typedef struct +{ + unsigned short year; + unsigned short month; + unsigned short date; + unsigned short day; + unsigned short hour; + unsigned short minute; + unsigned short second; +}T_TIME; +void register_debug_function(void(*my_assert)(const char* file, int line), void(*my_log_out)(const char* log)); +void _assert(const char* file, int line); +#define ASSERT(condition) \ + do{ \ + if(!(condition))_assert(__FILE__, __LINE__);\ + }while(0) +void log_out(const char* log); +long get_time_in_second(); +T_TIME second_to_day(long second); +T_TIME get_time(); +void start_real_timer(void (*func)(void* arg)); +void register_timer(int milli_second, void func(void* param), void* param); +unsigned int get_cur_thread_id(); +void create_thread(unsigned long* thread_id, void* attr, void *(*start_routine) (void *), void* arg); +void thread_sleep(unsigned int milli_seconds); +int build_bmp(const char *filename, unsigned int width, unsigned int height, unsigned char *data); +#define FIFO_BUFFER_LEN 1024 +class c_fifo +{ +public: + c_fifo(); + int read(void* buf, int len); + int write(void* buf, int len); +private: + unsigned char m_buf[FIFO_BUFFER_LEN]; + int m_head; + int m_tail; + void* m_read_sem; + void* m_write_mutex; +}; +class c_rect +{ +public: + c_rect(){ m_left = m_top = m_right = m_bottom = -1; } + c_rect(int left, int top, int width, int height) + { + set_rect(left, top, width, height); + } + void set_rect(int left, int top, int width, int height) + { + ASSERT(width > 0 && height > 0); + m_left = left; + m_top = top; + m_right = left + width - 1; + m_bottom = top + height -1; + } + bool pt_in_rect(int x, int y) const + { + return x >= m_left && x <= m_right && y >= m_top && y <= m_bottom; + } + int operator==(const c_rect& rect) const + { + return (m_left == rect.m_left) && (m_top == rect.m_top) && (m_right == rect.m_right) && (m_bottom == rect.m_bottom); + } + int width() const { return m_right - m_left + 1; } + int height() const { return m_bottom - m_top + 1 ; } + int m_left; + int m_top; + int m_right; + int m_bottom; +}; //BITMAP typedef struct struct_bitmap_info { @@ -238,7 +225,7 @@ typedef enum Z_ORDER_LEVEL_2,//highest graphic level Z_ORDER_LEVEL_MAX }Z_ORDER_LEVEL; -struct EXTERNAL_GFX_OP +struct DISPLAY_DRIVER { void(*draw_pixel)(int x, int y, unsigned int rgb); void(*fill_rect)(int x0, int y0, int x1, int y1, unsigned int rgb); @@ -247,18 +234,19 @@ class c_surface; class c_display { friend class c_surface; public: - inline c_display(void* phy_fb, int display_width, int display_height, int surface_width, int surface_height, unsigned int color_bytes, int surface_cnt, EXTERNAL_GFX_OP* gfx_op = 0);//multiple surface or surface_no_fb - inline c_display(void* phy_fb, int display_width, int display_height, c_surface* surface);//single custom surface - inline c_surface* alloc_surface(Z_ORDER_LEVEL max_zorder, c_rect layer_rect = c_rect());//for multiple surfaces + inline c_display(void* phy_fb, int display_width, int display_height, c_surface* surface, DISPLAY_DRIVER* driver = 0);//single custom surface + inline c_display(void* phy_fb, int display_width, int display_height, int surface_width, int surface_height, unsigned int color_bytes, int surface_cnt, DISPLAY_DRIVER* driver = 0);//multiple surface + inline c_surface* alloc_surface(Z_ORDER_LEVEL max_zorder, c_rect layer_rect = c_rect());//for slide group inline int swipe_surface(c_surface* s0, c_surface* s1, int x0, int x1, int y0, int y1, int offset); int get_width() { return m_width; } int get_height() { return m_height; } + void* get_phy_fb() { return m_phy_fb; } void* get_updated_fb(int* width, int* height, bool force_update = false) { if (width && height) { - *width = get_width(); - *height = get_height(); + *width = m_width; + *height = m_height; } if (force_update) { @@ -277,35 +265,123 @@ public: { return -1; } - int width = get_width(); - int height = get_height(); //16 bits framebuffer if (m_color_bytes == 2) { - return build_bmp(file_name, width, height, (unsigned char*)m_phy_fb); + return build_bmp(file_name, m_width, m_height, (unsigned char*)m_phy_fb); } //32 bits framebuffer - unsigned short* p_bmp565_data = new unsigned short[width * height]; + unsigned short* p_bmp565_data = new unsigned short[m_width * m_height]; unsigned int* p_raw_data = (unsigned int*)m_phy_fb; - for (int i = 0; i < width * height; i++) + for (int i = 0; i < m_width * m_height; i++) { unsigned int rgb = *p_raw_data++; p_bmp565_data[i] = GL_RGB_32_to_16(rgb); } - int ret = build_bmp(file_name, width, height, (unsigned char*)p_bmp565_data); + int ret = build_bmp(file_name, m_width, m_height, (unsigned char*)p_bmp565_data); delete[]p_bmp565_data; return ret; } -private: - int m_width; //in pixels - int m_height; //in pixels - int m_color_bytes; //16 bits, 32 bits only - void* m_phy_fb; //physical framebuffer +protected: + virtual void draw_pixel(int x, int y, unsigned int rgb) + { + if ((x >= m_width) || (y >= m_height)) { return; } + if (m_driver && m_driver->draw_pixel) + { + return m_driver->draw_pixel(x, y, rgb); + } + if (m_color_bytes == 2) + { + ((unsigned short*)m_phy_fb)[y * m_width + x] = GL_RGB_32_to_16(rgb); + } + else + { + ((unsigned int*)m_phy_fb)[y * m_width + x] = rgb; + } + } + virtual void fill_rect(int x0, int y0, int x1, int y1, unsigned int rgb) + { + if (m_driver && m_driver->fill_rect) + { + return m_driver->fill_rect(x0, y0, x1, y1, rgb); + } + if (m_driver && m_driver->draw_pixel) + { + for (int y = y0; y <= y1; y++) + { + for (int x = x0; x <= x1; x++) + { + m_driver->draw_pixel(x, y, rgb); + } + } + return; + } + register int _width = m_width; + register int _height = m_height; + int x, y; + if (m_color_bytes == 2) + { + unsigned short* phy_fb; + unsigned int rgb_16 = GL_RGB_32_to_16(rgb); + for (y = y0; y <= y1; y++) + { + phy_fb = &((unsigned short*)m_phy_fb)[y * _width + x0]; + for (x = x0; x <= x1; x++) + { + if ((x < _width) && (y < _height)) + { + *phy_fb++ = rgb_16; + } + } + } + } + else + { + unsigned int* phy_fb; + for (y = y0; y <= y1; y++) + { + phy_fb = &((unsigned int*)m_phy_fb)[y * _width + x0]; + for (x = x0; x <= x1; x++) + { + if ((x < _width) && (y < _height)) + { + *phy_fb++ = rgb; + } + } + } + } + } + virtual int flush_screen(int left, int top, int right, int bottom, void* fb, int fb_width) + { + if ((0 == m_phy_fb) || (0 == fb)) + { + return -1; + } + register int _width = m_width; + register int _height = m_height; + left = (left >= _width) ? (_width - 1) : left; + right = (right >= _width) ? (_width - 1) : right; + top = (top >= _height) ? (_height - 1) : top; + bottom = (bottom >= _height) ? (_height - 1) : bottom; + for (int y = top; y < bottom; y++) + { + void* s_addr = (char*)fb + ((y * fb_width + left) * m_color_bytes); + void* d_addr = (char*)m_phy_fb + ((y * _width + left) * m_color_bytes); + memcpy(d_addr, s_addr, (right - left) * m_color_bytes); + } + return 0; + } + int m_width; //in pixels + int m_height; //in pixels + int m_color_bytes; //16/32 bits for default + void* m_phy_fb; //physical framebuffer for default + struct DISPLAY_DRIVER* m_driver; //Rendering by external method without default physical framebuffer int m_phy_read_index; int m_phy_write_index; c_surface* m_surface_group[SURFACE_CNT_MAX]; int m_surface_cnt; //surface count int m_surface_index; + }; class c_layer { @@ -317,12 +393,10 @@ public: class c_surface { friend class c_display; friend class c_bitmap_operator; public: - c_surface(unsigned int width, unsigned int height, unsigned int color_bytes, Z_ORDER_LEVEL max_zorder = Z_ORDER_LEVEL_0, c_rect overlpa_rect = c_rect()) : m_width(width), m_height(height), m_color_bytes(color_bytes), m_fb(0), m_is_active(false), m_top_zorder(Z_ORDER_LEVEL_0), m_phy_fb(0), m_phy_write_index(0), m_display(0) + c_surface(unsigned int width, unsigned int height, unsigned int color_bytes, Z_ORDER_LEVEL max_zorder = Z_ORDER_LEVEL_0, c_rect overlpa_rect = c_rect()) : m_width(width), m_height(height), m_color_bytes(color_bytes), m_fb(0), m_is_active(false), m_top_zorder(Z_ORDER_LEVEL_0), m_phy_write_index(0), m_display(0) { (overlpa_rect == c_rect()) ? set_surface(max_zorder, c_rect(0, 0, width - 1, height - 1)) : set_surface(max_zorder, overlpa_rect); } - int get_width() { return m_width; } - int get_height() { return m_height; } unsigned int get_pixel(int x, int y, unsigned int z_order) { if (x >= m_width || y >= m_height || x < 0 || y < 0 || z_order >= Z_ORDER_LEVEL_MAX) @@ -332,15 +406,15 @@ public: } if (m_layers[z_order].fb) { - return (m_color_bytes == 4) ? ((unsigned int*)(m_layers[z_order].fb))[y * m_width + x] : GL_RGB_16_to_32(((unsigned short*)(m_layers[z_order].fb))[y * m_width + x]); + return (m_color_bytes == 2) ? GL_RGB_16_to_32(((unsigned short*)(m_layers[z_order].fb))[y * m_width + x]) : ((unsigned int*)(m_layers[z_order].fb))[y * m_width + x]; } else if (m_fb) { - return (m_color_bytes == 4) ? ((unsigned int*)m_fb)[y * m_width + x] : GL_RGB_16_to_32(((unsigned short*)m_fb)[y * m_width + x]); + return (m_color_bytes == 2) ? GL_RGB_16_to_32(((unsigned short*)m_fb)[y * m_width + x]) : ((unsigned int*)m_fb)[y * m_width + x]; } - else if (m_phy_fb) + else if (m_display->m_phy_fb) { - return (m_color_bytes == 4) ? ((unsigned int*)m_phy_fb)[y * m_width + x] : GL_RGB_16_to_32(((unsigned short*)m_phy_fb)[y * m_width + x]); + return (m_color_bytes == 2) ? GL_RGB_16_to_32(((unsigned short*)m_display->m_phy_fb)[y * m_width + x]) : ((unsigned int*)m_display->m_phy_fb)[y * m_width + x]; } return 0; } @@ -357,7 +431,7 @@ public: } if (z_order == m_max_zorder) { - return draw_pixel_on_fb(x, y, rgb); + return draw_pixel_low_level(x, y, rgb); } if (z_order > (unsigned int)m_top_zorder) @@ -367,19 +441,19 @@ public: if (m_layers[z_order].rect.pt_in_rect(x, y)) { c_rect layer_rect = m_layers[z_order].rect; - if (m_color_bytes == 4) + if (m_color_bytes == 2) { - ((unsigned int*)(m_layers[z_order].fb))[(x - layer_rect.m_left) + (y - layer_rect.m_top) * layer_rect.width()] = rgb; + ((unsigned short*)(m_layers[z_order].fb))[(x - layer_rect.m_left) + (y - layer_rect.m_top) * layer_rect.width()] = GL_RGB_32_to_16(rgb); } else { - ((unsigned short*)(m_layers[z_order].fb))[(x - layer_rect.m_left) + (y - layer_rect.m_top) * layer_rect.width()] = GL_RGB_32_to_16(rgb); + ((unsigned int*)(m_layers[z_order].fb))[(x - layer_rect.m_left) + (y - layer_rect.m_top) * layer_rect.width()] = rgb; } } if (z_order == m_top_zorder) { - return draw_pixel_on_fb(x, y, rgb); + return draw_pixel_low_level(x, y, rgb); } bool be_overlapped = false; for (unsigned int tmp_z_order = Z_ORDER_LEVEL_MAX - 1; tmp_z_order > z_order; tmp_z_order--) @@ -392,7 +466,7 @@ public: } if (!be_overlapped) { - draw_pixel_on_fb(x, y, rgb); + draw_pixel_low_level(x, y, rgb); } } virtual void fill_rect(int x0, int y0, int x1, int y1, unsigned int rgb, unsigned int z_order) @@ -403,7 +477,7 @@ public: y1 = (y1 > (m_height - 1)) ? (m_height - 1) : y1; if (z_order == m_max_zorder) { - return fill_rect_on_fb(x0, y0, x1, y1, rgb); + return fill_rect_low_level(x0, y0, x1, y1, rgb); } if (z_order == m_top_zorder) { @@ -416,18 +490,18 @@ public: { if (layer_rect.pt_in_rect(x, y)) { - if (m_color_bytes == 4) + if (m_color_bytes == 2) { - ((unsigned int*)m_layers[z_order].fb)[(y - layer_rect.m_top) * layer_rect.width() + (x - layer_rect.m_left)] = rgb; + ((unsigned short*)m_layers[z_order].fb)[(y - layer_rect.m_top) * layer_rect.width() + (x - layer_rect.m_left)] = rgb_16; } else { - ((unsigned short*)m_layers[z_order].fb)[(y - layer_rect.m_top) * layer_rect.width() + (x - layer_rect.m_left)] = rgb_16; + ((unsigned int*)m_layers[z_order].fb)[(y - layer_rect.m_top) * layer_rect.width() + (x - layer_rect.m_left)] = rgb; } } } } - return fill_rect_on_fb(x0, y0, x1, y1, rgb); + return fill_rect_low_level(x0, y0, x1, y1, rgb); } for (; y0 <= y1; y0++) { @@ -499,27 +573,16 @@ public: } int flush_screen(int left, int top, int right, int bottom) { - if (left < 0 || left >= m_width || right < 0 || right >= m_width || - top < 0 || top >= m_height || bottom < 0 || bottom >= m_height) - { - ASSERT(false); - } - if (!m_is_active || (0 == m_phy_fb) || (0 == m_fb)) + if (!m_is_active) { return -1; } - int display_width = m_display->get_width(); - int display_height = m_display->get_height(); - left = (left >= display_width) ? (display_width - 1) : left; - right = (right >= display_width) ? (display_width - 1) : right; - top = (top >= display_height) ? (display_height - 1) : top; - bottom = (bottom >= display_height) ? (display_height - 1) : bottom; - for (int y = top; y < bottom; y++) + if (left < 0 || left >= m_width || right < 0 || right >= m_width || + top < 0 || top >= m_height || bottom < 0 || bottom >= m_height) { - void* s_addr = (char*)m_fb + ((y * m_width + left) * m_color_bytes); - void* d_addr = (char*)m_phy_fb + ((y * display_width + left) * m_color_bytes); - memcpy(d_addr, s_addr, (right - left) * m_color_bytes); + ASSERT(false); } + m_display->flush_screen(left, top, right, bottom, m_fb, m_width); *m_phy_write_index = *m_phy_write_index + 1; return 0; } @@ -537,90 +600,62 @@ public: { for (int x = rect.m_left; x <= rect.m_right; x++) { - unsigned int rgb = (m_color_bytes == 4) ? ((unsigned int*)fb)[(x - layer_rect.m_left) + (y - layer_rect.m_top) * width] : GL_RGB_16_to_32(((unsigned short*)fb)[(x - layer_rect.m_left) + (y - layer_rect.m_top) * width]); - draw_pixel_on_fb(x, y, rgb); + unsigned int rgb = (m_color_bytes == 2) ? GL_RGB_16_to_32(((unsigned short*)fb)[(x - layer_rect.m_left) + (y - layer_rect.m_top) * width]) : ((unsigned int*)fb)[(x - layer_rect.m_left) + (y - layer_rect.m_top) * width]; + draw_pixel_low_level(x, y, rgb); } } return 0; } void set_active(bool flag) { m_is_active = flag; } protected: - virtual void fill_rect_on_fb(int x0, int y0, int x1, int y1, unsigned int rgb) - { - int display_width = m_display->get_width(); - int display_height = m_display->get_height(); - if (m_color_bytes == 4) + virtual void fill_rect_low_level(int x0, int y0, int x1, int y1, unsigned int rgb) + {//fill rect on framebuffer of surface + int x, y; + if (m_color_bytes == 2) { - int x; - unsigned int* fb, * phy_fb; - for (; y0 <= y1; y0++) + unsigned short* fb; + unsigned int rgb_16 = GL_RGB_32_to_16(rgb); + for (y = y0; y <= y1; y++) { - x = x0; - fb = m_fb ? &((unsigned int*)m_fb)[y0 * m_width + x] : 0; - phy_fb = &((unsigned int*)m_phy_fb)[y0 * display_width + x]; - *m_phy_write_index = *m_phy_write_index + 1; - for (; x <= x1; x++) + fb = m_fb ? &((unsigned short*)m_fb)[y * m_width + x0] : 0; + if (!fb) { break; } + for (x = x0; x <= x1; x++) { - if (fb) - { - *fb++ = rgb; - } - if (m_is_active && (x < display_width) && (y0 < display_height)) - { - *phy_fb++ = rgb; - } + *fb++ = rgb_16; } } } - else if (m_color_bytes == 2) + else { - int x; - unsigned short* fb, * phy_fb; - rgb = GL_RGB_32_to_16(rgb); - for (; y0 <= y1; y0++) + unsigned int* fb; + for (y = y0; y <= y1; y++) { - x = x0; - fb = m_fb ? &((unsigned short*)m_fb)[y0 * m_width + x] : 0; - phy_fb = &((unsigned short*)m_phy_fb)[y0 * display_width + x]; - *m_phy_write_index = *m_phy_write_index + 1; - for (; x <= x1; x++) + fb = m_fb ? &((unsigned int*)m_fb)[y * m_width + x0] : 0; + if (!fb) { break; } + for (x = x0; x <= x1; x++) { - if (fb) - { - *fb++ = rgb; - } - if (m_is_active && (x < display_width) && (y0 < display_height)) - { - *phy_fb++ = rgb; - } + *fb++ = rgb; } } } + if (!m_is_active) { return; } + m_display->fill_rect(x0, y0, x1, y1, rgb); + *m_phy_write_index = *m_phy_write_index + 1; } - virtual void draw_pixel_on_fb(int x, int y, unsigned int rgb) + virtual void draw_pixel_low_level(int x, int y, unsigned int rgb) { if (m_fb) - { - (m_color_bytes == 4) ? ((unsigned int*)m_fb)[y * m_width + x] = rgb : ((unsigned short*)m_fb)[y * m_width + x] = GL_RGB_32_to_16(rgb); - } - if (m_is_active && (x < m_display->get_width()) && (y < m_display->get_height())) - { - if (m_color_bytes == 4) - { - ((unsigned int*)m_phy_fb)[y * (m_display->get_width()) + x] = rgb; - } - else - { - ((unsigned short*)m_phy_fb)[y * (m_display->get_width()) + x] = GL_RGB_32_to_16(rgb); - } - *m_phy_write_index = *m_phy_write_index + 1; + {//draw pixel on framebuffer of surface + (m_color_bytes == 2) ? ((unsigned short*)m_fb)[y * m_width + x] = GL_RGB_32_to_16(rgb): ((unsigned int*)m_fb)[y * m_width + x] = rgb; } + if (!m_is_active) { return; } + m_display->draw_pixel(x, y, rgb); + *m_phy_write_index = *m_phy_write_index + 1; } void attach_display(c_display* display) { ASSERT(display); m_display = display; - m_phy_fb = display->m_phy_fb; m_phy_write_index = &display->m_phy_write_index; } void set_surface(Z_ORDER_LEVEL max_z_order, c_rect layer_rect) @@ -638,87 +673,22 @@ protected: } int m_width; //in pixels int m_height; //in pixels - int m_color_bytes; //16 bits, 32 bits only + int m_color_bytes; //16 bits, 32 bits for default void* m_fb; //frame buffer you could see c_layer m_layers[Z_ORDER_LEVEL_MAX];//all graphic layers bool m_is_active; //active flag Z_ORDER_LEVEL m_max_zorder; //the highest graphic layer the surface will have Z_ORDER_LEVEL m_top_zorder; //the current highest graphic layer the surface have - void* m_phy_fb; //physical framebufer int* m_phy_write_index; c_display* m_display; }; -class c_surface_no_fb : public c_surface {//No physical framebuffer, render with external graphic interface - friend class c_display; -public: - c_surface_no_fb(unsigned int width, unsigned int height, unsigned int color_bytes, struct EXTERNAL_GFX_OP* gfx_op, Z_ORDER_LEVEL max_zorder = Z_ORDER_LEVEL_0, c_rect overlpa_rect = c_rect()) : c_surface(width, height, color_bytes, max_zorder, overlpa_rect), m_gfx_op(gfx_op) {} -protected: - virtual void fill_rect_on_fb(int x0, int y0, int x1, int y1, unsigned int rgb) - { - if (!m_gfx_op) - { - return; - } - if (m_gfx_op->fill_rect) - { - return m_gfx_op->fill_rect(x0, y0, x1, y1, rgb); - } - if (m_gfx_op->draw_pixel && m_is_active) - { - for (int y = y0; y <= y1; y++) - { - for (int x = x0; x <= x1; x++) - { - m_gfx_op->draw_pixel(x, y, rgb); - } - } - } - if (!m_fb) { return; } - if (m_color_bytes == 4) - { - unsigned int* fb; - for (int y = y0; y <= y1; y++) - { - fb = &((unsigned int*)m_fb)[y0 * m_width + x0]; - for (int x = x0; x <= x1; x++) - { - *fb++ = rgb; - } - } - } - else if (m_color_bytes == 2) - { - unsigned short* fb; - rgb = GL_RGB_32_to_16(rgb); - for (int y = y0; y <= y1; y++) - { - fb = &((unsigned short*)m_fb)[y0 * m_width + x0]; - for (int x = x0; x <= x1; x++) - { - *fb++ = rgb; - } - } - } - } - virtual void draw_pixel_on_fb(int x, int y, unsigned int rgb) - { - if (m_gfx_op && m_gfx_op->draw_pixel && m_is_active) - { - m_gfx_op->draw_pixel(x, y, rgb); - } - if (!m_fb) { return; } - if (m_color_bytes == 4) - { - ((unsigned int*)m_fb)[y * m_width + x] = rgb; - } - else if (m_color_bytes == 2) - { - ((unsigned short*)m_fb)[y * m_width + x] = GL_RGB_32_to_16(rgb); - } - } - struct EXTERNAL_GFX_OP* m_gfx_op;//Rendering by external method -}; -inline c_display::c_display(void* phy_fb, int display_width, int display_height, int surface_width, int surface_height, unsigned int color_bytes, int surface_cnt, EXTERNAL_GFX_OP* gfx_op) : m_width(display_width), m_height(display_height), m_color_bytes(color_bytes), m_phy_fb(phy_fb), m_phy_read_index(0), m_phy_write_index(0), m_surface_cnt(surface_cnt), m_surface_index(0) +inline c_display::c_display(void* phy_fb, int display_width, int display_height, c_surface* surface, DISPLAY_DRIVER* driver) : m_phy_fb(phy_fb), m_width(display_width), m_height(display_height), m_driver(driver), m_phy_read_index(0), m_phy_write_index(0), m_surface_cnt(1), m_surface_index(0) +{ + m_color_bytes = surface->m_color_bytes; + surface->m_is_active = true; + (m_surface_group[0] = surface)->attach_display(this); +} +inline c_display::c_display(void* phy_fb, int display_width, int display_height, int surface_width, int surface_height, unsigned int color_bytes, int surface_cnt, DISPLAY_DRIVER* driver) : m_phy_fb(phy_fb), m_width(display_width), m_height(display_height), m_color_bytes(color_bytes), m_phy_read_index(0), m_phy_write_index(0), m_surface_cnt(surface_cnt), m_driver(driver), m_surface_index(0) { ASSERT(color_bytes == 2 || color_bytes == 4); ASSERT(m_surface_cnt <= SURFACE_CNT_MAX); @@ -726,16 +696,10 @@ inline c_display::c_display(void* phy_fb, int display_width, int display_height, for (int i = 0; i < m_surface_cnt; i++) { - m_surface_group[i] = (phy_fb) ? new c_surface(surface_width, surface_height, color_bytes) : new c_surface_no_fb(surface_width, surface_height, color_bytes, gfx_op); + m_surface_group[i] = new c_surface(surface_width, surface_height, color_bytes); m_surface_group[i]->attach_display(this); } } -inline c_display::c_display(void* phy_fb, int display_width, int display_height, c_surface* surface) : m_width(display_width), m_height(display_height), m_phy_fb(phy_fb), m_phy_read_index(0), m_phy_write_index(0), m_surface_cnt(1), m_surface_index(0) -{ - m_color_bytes = surface->m_color_bytes; - surface->m_is_active = true; - (m_surface_group[0] = surface)->attach_display(this); -} inline c_surface* c_display::alloc_surface(Z_ORDER_LEVEL max_zorder, c_rect layer_rect) { ASSERT(max_zorder < Z_ORDER_LEVEL_MAX && m_surface_index < m_surface_cnt); @@ -744,8 +708,8 @@ inline c_surface* c_display::alloc_surface(Z_ORDER_LEVEL max_zorder, c_rect laye } inline int c_display::swipe_surface(c_surface* s0, c_surface* s1, int x0, int x1, int y0, int y1, int offset) { - int surface_width = s0->get_width(); - int surface_height = s0->get_height(); + register int surface_width = s0->m_width; + register int surface_height = s0->m_height; if (offset < 0 || offset > surface_width || y0 < 0 || y0 >= surface_height || y1 < 0 || y1 >= surface_height || x0 < 0 || x0 >= surface_width || x1 < 0 || x1 >= surface_width) { @@ -767,46 +731,46 @@ inline int c_display::swipe_surface(c_surface* s0, c_surface* s1, int x0, int x1 for (int y = y0; y <= y1; y++) { //Left surface - char* addr_s = ((char*)(s0->m_fb) + (y * (s0->get_width()) + x0 + offset) * m_color_bytes); + char* addr_s = ((char*)(s0->m_fb) + (y * surface_width + x0 + offset) * m_color_bytes); char* addr_d = ((char*)(m_phy_fb)+(y * m_width + x0) * m_color_bytes); memcpy(addr_d, addr_s, (width - offset) * m_color_bytes); //Right surface - addr_s = ((char*)(s1->m_fb) + (y * (s1->get_width()) + x0) * m_color_bytes); + addr_s = ((char*)(s1->m_fb) + (y * surface_width + x0) * m_color_bytes); addr_d = ((char*)(m_phy_fb)+(y * m_width + x0 + (width - offset)) * m_color_bytes); memcpy(addr_d, addr_s, offset * m_color_bytes); } } - else if (m_color_bytes == 4) + else if (m_color_bytes == 2) { - void(*draw_pixel)(int x, int y, unsigned int rgb) = ((c_surface_no_fb*)s0)->m_gfx_op->draw_pixel; + void(*draw_pixel)(int x, int y, unsigned int rgb) = m_driver->draw_pixel; for (int y = y0; y <= y1; y++) { //Left surface for (int x = x0; x <= (x1 - offset); x++) { - draw_pixel(x, y, ((unsigned int*)s0->m_fb)[y * m_width + x + offset]); + draw_pixel(x, y, GL_RGB_16_to_32(((unsigned short*)s0->m_fb)[y * m_width + x + offset])); } //Right surface for (int x = x1 - offset; x <= x1; x++) { - draw_pixel(x, y, ((unsigned int*)s1->m_fb)[y * m_width + x + offset - x1 + x0]); + draw_pixel(x, y, GL_RGB_16_to_32(((unsigned short*)s1->m_fb)[y * m_width + x + offset - x1 + x0])); } } } - else if (m_color_bytes == 2) + else //m_color_bytes == 3/4... { - void(*draw_pixel)(int x, int y, unsigned int rgb) = ((c_surface_no_fb*)s0)->m_gfx_op->draw_pixel; + void(*draw_pixel)(int x, int y, unsigned int rgb) = m_driver->draw_pixel; for (int y = y0; y <= y1; y++) { //Left surface for (int x = x0; x <= (x1 - offset); x++) { - draw_pixel(x, y, GL_RGB_16_to_32(((unsigned short*)s0->m_fb)[y * m_width + x + offset])); + draw_pixel(x, y, ((unsigned int*)s0->m_fb)[y * m_width + x + offset]); } //Right surface for (int x = x1 - offset; x <= x1; x++) { - draw_pixel(x, y, GL_RGB_16_to_32(((unsigned short*)s1->m_fb)[y * m_width + x + offset - x1 + x0])); + draw_pixel(x, y, ((unsigned int*)s1->m_fb)[y * m_width + x + offset - x1 + x0]); } } } @@ -3407,22 +3371,12 @@ private: #ifdef GUILITE_ON c_bitmap_operator the_bitmap_op = c_bitmap_operator(); c_image_operator* c_image::image_operator = &the_bitmap_op; +const void* c_theme::s_font_map[FONT_MAX]; +const void* c_theme::s_image_map[IMAGE_MAX]; +unsigned int c_theme::s_color_map[COLOR_MAX]; +c_lattice_font_op the_lattice_font_op = c_lattice_font_op(); +c_font_operator* c_word::fontOperator = &the_lattice_font_op; #endif - -#ifdef GUILITE_ON - -const void* c_theme::s_font_map[FONT_MAX]; -const void* c_theme::s_image_map[IMAGE_MAX]; -unsigned int c_theme::s_color_map[COLOR_MAX]; - -#endif - -#ifdef GUILITE_ON - -c_lattice_font_op the_lattice_font_op = c_lattice_font_op(); -c_font_operator* c_word::fontOperator = &the_lattice_font_op; - -#endif #ifdef GUILITE_ON #if (defined __linux__) || (defined __APPLE__) #include @@ -4264,11 +4218,7 @@ int c_fifo::write(void* buf, int len) #endif #ifdef GUILITE_ON DIALOG_ARRAY c_dialog::ms_the_dialogs[SURFACE_CNT_MAX]; -#endif -#ifdef GUILITE_ON c_keyboard c_edit::s_keyboard; -#endif -#ifdef GUILITE_ON static c_keyboard_button s_key_0, s_key_1, s_key_2, s_key_3, s_key_4, s_key_5, s_key_6, s_key_7, s_key_8, s_key_9; static c_keyboard_button s_key_A, s_key_B, s_key_C, s_key_D, s_key_E, s_key_F, s_key_G, s_key_H, s_key_I, s_key_J; static c_keyboard_button s_key_K, s_key_L, s_key_M, s_key_N, s_key_O, s_key_P, s_key_Q, s_key_R, s_key_S, s_key_T; @@ -4306,12 +4256,12 @@ WND_TREE g_key_board_children[] = {&s_key_B, 'B', 0, ((KEY_WIDTH / 2) + POS_X(5)), POS_Y(2), KEY_WIDTH, KEY_HEIGHT}, {&s_key_N, 'N', 0, ((KEY_WIDTH / 2) + POS_X(6)), POS_Y(2), KEY_WIDTH, KEY_HEIGHT}, {&s_key_M, 'M', 0, ((KEY_WIDTH / 2) + POS_X(7)), POS_Y(2), KEY_WIDTH, KEY_HEIGHT}, - {&s_key_del, 0x7F, 0, ((KEY_WIDTH / 2) + POS_X(8)), POS_Y(2), DEL_WIDTH, KEY_HEIGHT}, + {&s_key_del,0x7F, 0, ((KEY_WIDTH / 2) + POS_X(8)), POS_Y(2), DEL_WIDTH, KEY_HEIGHT}, //Row 4 - {&s_key_esc, 0x1B, 0, POS_X(0), POS_Y(3), ESC_WIDTH, KEY_HEIGHT}, + {&s_key_esc, 0x1B, 0, POS_X(0), POS_Y(3), ESC_WIDTH, KEY_HEIGHT}, {&s_key_num_switch, 0x90, 0, POS_X(2), POS_Y(3), SWITCH_WIDTH, KEY_HEIGHT}, {&s_key_space, ' ', 0, ((KEY_WIDTH / 2) + POS_X(3)), POS_Y(3), SPACE_WIDTH, KEY_HEIGHT}, - {&s_key_dot, '.', 0, ((KEY_WIDTH / 2) + POS_X(6)), POS_Y(3), DOT_WIDTH, KEY_HEIGHT}, + {&s_key_dot, '.', 0, ((KEY_WIDTH / 2) + POS_X(6)), POS_Y(3), DOT_WIDTH, KEY_HEIGHT}, {&s_key_enter, '\n', 0, POS_X(8), POS_Y(3), ENTER_WIDTH, KEY_HEIGHT}, {0,0,0,0,0,0,0} }; @@ -4326,12 +4276,11 @@ WND_TREE g_number_board_children[] = {&s_key_7, '7', 0, POS_X(0), POS_Y(2), KEY_WIDTH, KEY_HEIGHT}, {&s_key_8, '8', 0, POS_X(1), POS_Y(2), KEY_WIDTH, KEY_HEIGHT}, {&s_key_9, '9', 0, POS_X(2), POS_Y(2), KEY_WIDTH, KEY_HEIGHT}, - - {&s_key_esc, 0x1B, 0, POS_X(0), POS_Y(3), KEY_WIDTH, KEY_HEIGHT}, + {&s_key_esc,0x1B, 0, POS_X(0), POS_Y(3), KEY_WIDTH, KEY_HEIGHT}, {&s_key_0, '0', 0, POS_X(1), POS_Y(3), KEY_WIDTH, KEY_HEIGHT}, - {&s_key_dot, '.', 0, POS_X(2), POS_Y(3), KEY_WIDTH, KEY_HEIGHT}, + {&s_key_dot,'.', 0, POS_X(2), POS_Y(3), KEY_WIDTH, KEY_HEIGHT}, {&s_key_del, 0x7F, 0, POS_X(3), POS_Y(0), KEY_WIDTH, KEY_HEIGHT * 2 + 2}, {&s_key_enter,'\n', 0, POS_X(3), POS_Y(2), KEY_WIDTH, KEY_HEIGHT * 2 + 2}, {0,0,0,0,0,0,0} }; -#endif +#endif \ No newline at end of file