From 76cfec7a0e3d058fef6e7237be1e654d58a9ab98 Mon Sep 17 00:00:00 2001 From: idea4good Date: Tue, 24 May 2022 17:27:17 +0800 Subject: [PATCH 1/4] build/run pass --- .github/.test.sh | 21 + .github/.updateGuiLite.sh | 4 +- Hello3D/BuildLinux/.sync_build.sh | 3 +- Hello3D/UIcode/GuiLite.h | 382 ++++++++---------- Hello3D/UIcode/UIcode.cpp | 19 +- Hello3Ddonut/BuildLinux/.sync_build.sh | 3 +- Hello3Ddonut/UIcode/GuiLite.h | 382 ++++++++---------- Hello3Ddonut/UIcode/UIcode.cpp | 19 +- Hello3Dwave/BuildLinux/.sync_build.sh | 3 +- Hello3Dwave/UIcode/GuiLite.h | 382 ++++++++---------- Hello3Dwave/UIcode/UIcode.cpp | 19 +- HelloAnimation/BuildLinux/.sync_build.sh | 3 +- HelloAnimation/UIcode/GuiLite.h | 382 ++++++++---------- HelloCircle/BuildLinux/.sync_build.sh | 3 +- HelloCircle/UIcode/GuiLite.h | 382 ++++++++---------- HelloCircle/UIcode/UIcode.cpp | 18 +- HelloFFmpeg/BuildLinux/.sync_build.sh | 3 +- HelloFFmpeg/UIcode/GuiLite.h | 382 ++++++++---------- HelloFont/BuildLinux/.sync_build.sh | 3 +- HelloFont/UIcode/GuiLite.h | 382 ++++++++---------- HelloFreetype/BuildLinux/.sync_build.sh | 3 +- HelloFreetype/UIcode/GuiLite.h | 382 ++++++++---------- HelloJPG/BuildLinux/.sync_build.sh | 3 +- HelloJPG/UIcode/GuiLite.h | 382 ++++++++---------- HelloLayers/BuildLinux/.sync_build.sh | 3 +- HelloLayers/UIcode/GuiLite.h | 382 ++++++++---------- HelloLayers/UIcode/UIcode.cpp | 18 +- HelloMario/BuildLinux/.sync_build.sh | 3 +- HelloMario/UIcode/GuiLite.h | 382 ++++++++---------- HelloMario/UIcode/UIcode.cpp | 18 +- HelloMolecule/BuildLinux/.sync_build.sh | 3 +- HelloMolecule/UIcode/GuiLite.h | 382 ++++++++---------- HelloMolecule/UIcode/UIcode.cpp | 18 +- HelloNets/BuildLinux/.sync_build.sh | 3 +- HelloNets/UIcode/GuiLite.h | 382 ++++++++---------- HelloNets/UIcode/UIcode.cpp | 18 +- HelloNoTouch/BuildLinux/.sync_build.sh | 3 +- HelloNoTouch/UIcode/GuiLite.h | 382 ++++++++---------- HelloNoTouch/UIcode/UIcode.cpp | 18 +- HelloParticle/BuildLinux/.sync_build.sh | 3 +- HelloParticle/UIcode/GuiLite.h | 382 ++++++++---------- HelloParticle/UIcode/UIcode.cpp | 18 +- HelloPendulum/BuildLinux/.sync_build.sh | 3 +- HelloPendulum/UIcode/GuiLite.h | 382 ++++++++---------- HelloPendulum/UIcode/UIcode.cpp | 19 +- HelloScroll/BuildLinux/.sync_build.sh | 3 +- HelloScroll/UIcode/GuiLite.h | 382 ++++++++---------- HelloScroll/UIcode/scroll.h | 16 +- HelloSlide/BuildLinux/.sync_build.sh | 3 +- HelloSlide/UIcode/GuiLite.h | 382 ++++++++---------- HelloStar/BuildLinux/.sync_build.sh | 3 +- HelloStar/UIcode/GuiLite.h | 382 ++++++++---------- HelloStar/UIcode/UIcode.cpp | 18 +- HelloTimer/BuildLinux/.sync_build.sh | 3 +- HelloTimer/UIcode/GuiLite.h | 382 ++++++++---------- HelloTimer/UIcode/UIcode.cpp | 18 +- HelloTransparent/BuildLinux/.sync_build.sh | 3 +- HelloTransparent/UIcode/GuiLite.h | 382 ++++++++---------- HelloTransparent/UIcode/surface_transparent.h | 15 +- HelloWave/BuildLinux/.sync_build.sh | 3 +- HelloWave/UIcode/GuiLite.h | 382 ++++++++---------- HelloWave/UIcode/UIcode.cpp | 20 +- HelloWidgets/BuildLinux/.sync_build.sh | 3 +- HelloWidgets/UIcode/GuiLite.h | 382 ++++++++---------- HelloWindows/BuildLinux/.sync_build.sh | 3 +- HelloWindows/UIcode/GuiLite.h | 382 ++++++++---------- HostMonitor/BuildLinux/.sync_data.sh | 3 +- HostMonitor/UIcode/include/GuiLite.h | 382 ++++++++---------- 68 files changed, 4456 insertions(+), 5483 deletions(-) create mode 100644 .github/.test.sh diff --git a/.github/.test.sh b/.github/.test.sh new file mode 100644 index 0000000..3c83072 --- /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 building...\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 building...\e[49m" +cd HostMonitor/BuildLinux +timeout 5s ./.sync_build.sh diff --git a/.github/.updateGuiLite.sh b/.github/.updateGuiLite.sh index 793a2d7..748155a 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/BuildLinux/.sync_build.sh b/Hello3D/BuildLinux/.sync_build.sh index 49cff5b..1b470d5 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/UIcode/GuiLite.h b/Hello3D/UIcode/GuiLite.h index c4fc88a..d77aa29 100644 --- a/Hello3D/UIcode/GuiLite.h +++ b/Hello3D/UIcode/GuiLite.h @@ -247,18 +247,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, EXTERNAL_GFX_OP* gfx_op = 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, EXTERNAL_GFX_OP* gfx_op = 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 +278,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_gfx_op && m_gfx_op->draw_pixel) + { + return m_gfx_op->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_gfx_op && m_gfx_op->fill_rect) + { + return m_gfx_op->fill_rect(x0, y0, x1, y1, rgb); + } + if (m_gfx_op && m_gfx_op->draw_pixel) + { + for (int y = y0; y <= y1; y++) + { + for (int x = x0; x <= x1; x++) + { + m_gfx_op->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 bits, 32 bits only + void* m_phy_fb; //physical framebuffer + struct EXTERNAL_GFX_OP* m_gfx_op; //Rendering by external method 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 +406,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) @@ -338,9 +425,9 @@ public: { 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]); } - 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 == 4) ? ((unsigned int*)m_display->m_phy_fb)[y * m_width + x] : GL_RGB_16_to_32(((unsigned short*)m_display->m_phy_fb)[y * m_width + x]); } return 0; } @@ -357,7 +444,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) @@ -379,7 +466,7 @@ public: 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 +479,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 +490,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) { @@ -427,7 +514,7 @@ public: } } } - 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 +586,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; } @@ -538,89 +614,61 @@ 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); + 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 +686,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, EXTERNAL_GFX_OP* gfx_op) : m_phy_fb(phy_fb), m_width(display_width), m_height(display_height), m_gfx_op(gfx_op), 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, EXTERNAL_GFX_OP* gfx_op) : 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_gfx_op(gfx_op), m_surface_index(0) { ASSERT(color_bytes == 2 || color_bytes == 4); ASSERT(m_surface_cnt <= SURFACE_CNT_MAX); @@ -726,16 +709,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 +721,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,18 +744,18 @@ 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) { - 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_gfx_op->draw_pixel; for (int y = y0; y <= y1; y++) { //Left surface @@ -795,7 +772,7 @@ inline int c_display::swipe_surface(c_surface* s0, c_surface* s1, int x0, int x1 } 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_gfx_op->draw_pixel; for (int y = y0; y <= y1; y++) { //Left surface @@ -3407,22 +3384,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 +4231,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 +4269,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 +4289,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 85ac833..fbda811 100644 --- a/Hello3D/UIcode/UIcode.cpp +++ b/Hello3D/UIcode/UIcode.cpp @@ -165,20 +165,11 @@ 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; - } + 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, gfx_op); + 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; diff --git a/Hello3Ddonut/BuildLinux/.sync_build.sh b/Hello3Ddonut/BuildLinux/.sync_build.sh index 49cff5b..0c45b25 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/UIcode/GuiLite.h b/Hello3Ddonut/UIcode/GuiLite.h index c4fc88a..d77aa29 100644 --- a/Hello3Ddonut/UIcode/GuiLite.h +++ b/Hello3Ddonut/UIcode/GuiLite.h @@ -247,18 +247,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, EXTERNAL_GFX_OP* gfx_op = 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, EXTERNAL_GFX_OP* gfx_op = 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 +278,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_gfx_op && m_gfx_op->draw_pixel) + { + return m_gfx_op->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_gfx_op && m_gfx_op->fill_rect) + { + return m_gfx_op->fill_rect(x0, y0, x1, y1, rgb); + } + if (m_gfx_op && m_gfx_op->draw_pixel) + { + for (int y = y0; y <= y1; y++) + { + for (int x = x0; x <= x1; x++) + { + m_gfx_op->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 bits, 32 bits only + void* m_phy_fb; //physical framebuffer + struct EXTERNAL_GFX_OP* m_gfx_op; //Rendering by external method 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 +406,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) @@ -338,9 +425,9 @@ public: { 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]); } - 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 == 4) ? ((unsigned int*)m_display->m_phy_fb)[y * m_width + x] : GL_RGB_16_to_32(((unsigned short*)m_display->m_phy_fb)[y * m_width + x]); } return 0; } @@ -357,7 +444,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) @@ -379,7 +466,7 @@ public: 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 +479,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 +490,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) { @@ -427,7 +514,7 @@ public: } } } - 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 +586,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; } @@ -538,89 +614,61 @@ 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); + 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 +686,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, EXTERNAL_GFX_OP* gfx_op) : m_phy_fb(phy_fb), m_width(display_width), m_height(display_height), m_gfx_op(gfx_op), 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, EXTERNAL_GFX_OP* gfx_op) : 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_gfx_op(gfx_op), m_surface_index(0) { ASSERT(color_bytes == 2 || color_bytes == 4); ASSERT(m_surface_cnt <= SURFACE_CNT_MAX); @@ -726,16 +709,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 +721,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,18 +744,18 @@ 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) { - 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_gfx_op->draw_pixel; for (int y = y0; y <= y1; y++) { //Left surface @@ -795,7 +772,7 @@ inline int c_display::swipe_surface(c_surface* s0, c_surface* s1, int x0, int x1 } 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_gfx_op->draw_pixel; for (int y = y0; y <= y1; y++) { //Left surface @@ -3407,22 +3384,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 +4231,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 +4269,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 +4289,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 42c1dcc..99c2017 100644 --- a/Hello3Ddonut/UIcode/UIcode.cpp +++ b/Hello3Ddonut/UIcode/UIcode.cpp @@ -66,20 +66,11 @@ 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; - } + 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, gfx_op); + 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); diff --git a/Hello3Dwave/BuildLinux/.sync_build.sh b/Hello3Dwave/BuildLinux/.sync_build.sh index 49cff5b..457ac69 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/UIcode/GuiLite.h b/Hello3Dwave/UIcode/GuiLite.h index c4fc88a..d77aa29 100644 --- a/Hello3Dwave/UIcode/GuiLite.h +++ b/Hello3Dwave/UIcode/GuiLite.h @@ -247,18 +247,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, EXTERNAL_GFX_OP* gfx_op = 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, EXTERNAL_GFX_OP* gfx_op = 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 +278,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_gfx_op && m_gfx_op->draw_pixel) + { + return m_gfx_op->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_gfx_op && m_gfx_op->fill_rect) + { + return m_gfx_op->fill_rect(x0, y0, x1, y1, rgb); + } + if (m_gfx_op && m_gfx_op->draw_pixel) + { + for (int y = y0; y <= y1; y++) + { + for (int x = x0; x <= x1; x++) + { + m_gfx_op->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 bits, 32 bits only + void* m_phy_fb; //physical framebuffer + struct EXTERNAL_GFX_OP* m_gfx_op; //Rendering by external method 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 +406,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) @@ -338,9 +425,9 @@ public: { 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]); } - 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 == 4) ? ((unsigned int*)m_display->m_phy_fb)[y * m_width + x] : GL_RGB_16_to_32(((unsigned short*)m_display->m_phy_fb)[y * m_width + x]); } return 0; } @@ -357,7 +444,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) @@ -379,7 +466,7 @@ public: 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 +479,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 +490,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) { @@ -427,7 +514,7 @@ public: } } } - 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 +586,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; } @@ -538,89 +614,61 @@ 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); + 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 +686,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, EXTERNAL_GFX_OP* gfx_op) : m_phy_fb(phy_fb), m_width(display_width), m_height(display_height), m_gfx_op(gfx_op), 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, EXTERNAL_GFX_OP* gfx_op) : 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_gfx_op(gfx_op), m_surface_index(0) { ASSERT(color_bytes == 2 || color_bytes == 4); ASSERT(m_surface_cnt <= SURFACE_CNT_MAX); @@ -726,16 +709,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 +721,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,18 +744,18 @@ 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) { - 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_gfx_op->draw_pixel; for (int y = y0; y <= y1; y++) { //Left surface @@ -795,7 +772,7 @@ inline int c_display::swipe_surface(c_surface* s0, c_surface* s1, int x0, int x1 } 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_gfx_op->draw_pixel; for (int y = y0; y <= y1; y++) { //Left surface @@ -3407,22 +3384,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 +4231,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 +4269,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 +4289,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 a11db94..3eb6fa8 100644 --- a/Hello3Dwave/UIcode/UIcode.cpp +++ b/Hello3Dwave/UIcode/UIcode.cpp @@ -139,20 +139,11 @@ 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; - } + 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, gfx_op); + 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; diff --git a/HelloAnimation/BuildLinux/.sync_build.sh b/HelloAnimation/BuildLinux/.sync_build.sh index 49cff5b..a40a99f 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 c4fc88a..d77aa29 100644 --- a/HelloAnimation/UIcode/GuiLite.h +++ b/HelloAnimation/UIcode/GuiLite.h @@ -247,18 +247,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, EXTERNAL_GFX_OP* gfx_op = 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, EXTERNAL_GFX_OP* gfx_op = 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 +278,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_gfx_op && m_gfx_op->draw_pixel) + { + return m_gfx_op->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_gfx_op && m_gfx_op->fill_rect) + { + return m_gfx_op->fill_rect(x0, y0, x1, y1, rgb); + } + if (m_gfx_op && m_gfx_op->draw_pixel) + { + for (int y = y0; y <= y1; y++) + { + for (int x = x0; x <= x1; x++) + { + m_gfx_op->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 bits, 32 bits only + void* m_phy_fb; //physical framebuffer + struct EXTERNAL_GFX_OP* m_gfx_op; //Rendering by external method 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 +406,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) @@ -338,9 +425,9 @@ public: { 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]); } - 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 == 4) ? ((unsigned int*)m_display->m_phy_fb)[y * m_width + x] : GL_RGB_16_to_32(((unsigned short*)m_display->m_phy_fb)[y * m_width + x]); } return 0; } @@ -357,7 +444,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) @@ -379,7 +466,7 @@ public: 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 +479,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 +490,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) { @@ -427,7 +514,7 @@ public: } } } - 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 +586,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; } @@ -538,89 +614,61 @@ 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); + 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 +686,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, EXTERNAL_GFX_OP* gfx_op) : m_phy_fb(phy_fb), m_width(display_width), m_height(display_height), m_gfx_op(gfx_op), 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, EXTERNAL_GFX_OP* gfx_op) : 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_gfx_op(gfx_op), m_surface_index(0) { ASSERT(color_bytes == 2 || color_bytes == 4); ASSERT(m_surface_cnt <= SURFACE_CNT_MAX); @@ -726,16 +709,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 +721,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,18 +744,18 @@ 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) { - 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_gfx_op->draw_pixel; for (int y = y0; y <= y1; y++) { //Left surface @@ -795,7 +772,7 @@ inline int c_display::swipe_surface(c_surface* s0, c_surface* s1, int x0, int x1 } 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_gfx_op->draw_pixel; for (int y = y0; y <= y1; y++) { //Left surface @@ -3407,22 +3384,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 +4231,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 +4269,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 +4289,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/BuildLinux/.sync_build.sh b/HelloCircle/BuildLinux/.sync_build.sh index 49cff5b..c46888e 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/UIcode/GuiLite.h b/HelloCircle/UIcode/GuiLite.h index c4fc88a..d77aa29 100644 --- a/HelloCircle/UIcode/GuiLite.h +++ b/HelloCircle/UIcode/GuiLite.h @@ -247,18 +247,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, EXTERNAL_GFX_OP* gfx_op = 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, EXTERNAL_GFX_OP* gfx_op = 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 +278,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_gfx_op && m_gfx_op->draw_pixel) + { + return m_gfx_op->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_gfx_op && m_gfx_op->fill_rect) + { + return m_gfx_op->fill_rect(x0, y0, x1, y1, rgb); + } + if (m_gfx_op && m_gfx_op->draw_pixel) + { + for (int y = y0; y <= y1; y++) + { + for (int x = x0; x <= x1; x++) + { + m_gfx_op->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 bits, 32 bits only + void* m_phy_fb; //physical framebuffer + struct EXTERNAL_GFX_OP* m_gfx_op; //Rendering by external method 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 +406,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) @@ -338,9 +425,9 @@ public: { 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]); } - 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 == 4) ? ((unsigned int*)m_display->m_phy_fb)[y * m_width + x] : GL_RGB_16_to_32(((unsigned short*)m_display->m_phy_fb)[y * m_width + x]); } return 0; } @@ -357,7 +444,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) @@ -379,7 +466,7 @@ public: 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 +479,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 +490,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) { @@ -427,7 +514,7 @@ public: } } } - 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 +586,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; } @@ -538,89 +614,61 @@ 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); + 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 +686,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, EXTERNAL_GFX_OP* gfx_op) : m_phy_fb(phy_fb), m_width(display_width), m_height(display_height), m_gfx_op(gfx_op), 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, EXTERNAL_GFX_OP* gfx_op) : 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_gfx_op(gfx_op), m_surface_index(0) { ASSERT(color_bytes == 2 || color_bytes == 4); ASSERT(m_surface_cnt <= SURFACE_CNT_MAX); @@ -726,16 +709,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 +721,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,18 +744,18 @@ 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) { - 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_gfx_op->draw_pixel; for (int y = y0; y <= y1; y++) { //Left surface @@ -795,7 +772,7 @@ inline int c_display::swipe_surface(c_surface* s0, c_surface* s1, int x0, int x1 } 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_gfx_op->draw_pixel; for (int y = y0; y <= y1; y++) { //Left surface @@ -3407,22 +3384,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 +4231,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 +4269,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 +4289,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 8d88746..03759b0 100644 --- a/HelloCircle/UIcode/UIcode.cpp +++ b/HelloCircle/UIcode/UIcode.cpp @@ -202,20 +202,10 @@ 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; - } + 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, gfx_op); + 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; diff --git a/HelloFFmpeg/BuildLinux/.sync_build.sh b/HelloFFmpeg/BuildLinux/.sync_build.sh index 49cff5b..1152b91 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 c4fc88a..d77aa29 100644 --- a/HelloFFmpeg/UIcode/GuiLite.h +++ b/HelloFFmpeg/UIcode/GuiLite.h @@ -247,18 +247,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, EXTERNAL_GFX_OP* gfx_op = 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, EXTERNAL_GFX_OP* gfx_op = 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 +278,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_gfx_op && m_gfx_op->draw_pixel) + { + return m_gfx_op->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_gfx_op && m_gfx_op->fill_rect) + { + return m_gfx_op->fill_rect(x0, y0, x1, y1, rgb); + } + if (m_gfx_op && m_gfx_op->draw_pixel) + { + for (int y = y0; y <= y1; y++) + { + for (int x = x0; x <= x1; x++) + { + m_gfx_op->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 bits, 32 bits only + void* m_phy_fb; //physical framebuffer + struct EXTERNAL_GFX_OP* m_gfx_op; //Rendering by external method 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 +406,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) @@ -338,9 +425,9 @@ public: { 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]); } - 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 == 4) ? ((unsigned int*)m_display->m_phy_fb)[y * m_width + x] : GL_RGB_16_to_32(((unsigned short*)m_display->m_phy_fb)[y * m_width + x]); } return 0; } @@ -357,7 +444,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) @@ -379,7 +466,7 @@ public: 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 +479,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 +490,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) { @@ -427,7 +514,7 @@ public: } } } - 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 +586,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; } @@ -538,89 +614,61 @@ 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); + 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 +686,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, EXTERNAL_GFX_OP* gfx_op) : m_phy_fb(phy_fb), m_width(display_width), m_height(display_height), m_gfx_op(gfx_op), 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, EXTERNAL_GFX_OP* gfx_op) : 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_gfx_op(gfx_op), m_surface_index(0) { ASSERT(color_bytes == 2 || color_bytes == 4); ASSERT(m_surface_cnt <= SURFACE_CNT_MAX); @@ -726,16 +709,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 +721,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,18 +744,18 @@ 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) { - 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_gfx_op->draw_pixel; for (int y = y0; y <= y1; y++) { //Left surface @@ -795,7 +772,7 @@ inline int c_display::swipe_surface(c_surface* s0, c_surface* s1, int x0, int x1 } 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_gfx_op->draw_pixel; for (int y = y0; y <= y1; y++) { //Left surface @@ -3407,22 +3384,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 +4231,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 +4269,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 +4289,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 49cff5b..1dfbc1b 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 c4fc88a..d77aa29 100644 --- a/HelloFont/UIcode/GuiLite.h +++ b/HelloFont/UIcode/GuiLite.h @@ -247,18 +247,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, EXTERNAL_GFX_OP* gfx_op = 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, EXTERNAL_GFX_OP* gfx_op = 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 +278,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_gfx_op && m_gfx_op->draw_pixel) + { + return m_gfx_op->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_gfx_op && m_gfx_op->fill_rect) + { + return m_gfx_op->fill_rect(x0, y0, x1, y1, rgb); + } + if (m_gfx_op && m_gfx_op->draw_pixel) + { + for (int y = y0; y <= y1; y++) + { + for (int x = x0; x <= x1; x++) + { + m_gfx_op->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 bits, 32 bits only + void* m_phy_fb; //physical framebuffer + struct EXTERNAL_GFX_OP* m_gfx_op; //Rendering by external method 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 +406,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) @@ -338,9 +425,9 @@ public: { 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]); } - 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 == 4) ? ((unsigned int*)m_display->m_phy_fb)[y * m_width + x] : GL_RGB_16_to_32(((unsigned short*)m_display->m_phy_fb)[y * m_width + x]); } return 0; } @@ -357,7 +444,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) @@ -379,7 +466,7 @@ public: 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 +479,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 +490,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) { @@ -427,7 +514,7 @@ public: } } } - 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 +586,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; } @@ -538,89 +614,61 @@ 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); + 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 +686,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, EXTERNAL_GFX_OP* gfx_op) : m_phy_fb(phy_fb), m_width(display_width), m_height(display_height), m_gfx_op(gfx_op), 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, EXTERNAL_GFX_OP* gfx_op) : 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_gfx_op(gfx_op), m_surface_index(0) { ASSERT(color_bytes == 2 || color_bytes == 4); ASSERT(m_surface_cnt <= SURFACE_CNT_MAX); @@ -726,16 +709,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 +721,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,18 +744,18 @@ 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) { - 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_gfx_op->draw_pixel; for (int y = y0; y <= y1; y++) { //Left surface @@ -795,7 +772,7 @@ inline int c_display::swipe_surface(c_surface* s0, c_surface* s1, int x0, int x1 } 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_gfx_op->draw_pixel; for (int y = y0; y <= y1; y++) { //Left surface @@ -3407,22 +3384,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 +4231,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 +4269,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 +4289,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 49cff5b..5b74e1d 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 c4fc88a..d77aa29 100644 --- a/HelloFreetype/UIcode/GuiLite.h +++ b/HelloFreetype/UIcode/GuiLite.h @@ -247,18 +247,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, EXTERNAL_GFX_OP* gfx_op = 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, EXTERNAL_GFX_OP* gfx_op = 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 +278,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_gfx_op && m_gfx_op->draw_pixel) + { + return m_gfx_op->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_gfx_op && m_gfx_op->fill_rect) + { + return m_gfx_op->fill_rect(x0, y0, x1, y1, rgb); + } + if (m_gfx_op && m_gfx_op->draw_pixel) + { + for (int y = y0; y <= y1; y++) + { + for (int x = x0; x <= x1; x++) + { + m_gfx_op->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 bits, 32 bits only + void* m_phy_fb; //physical framebuffer + struct EXTERNAL_GFX_OP* m_gfx_op; //Rendering by external method 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 +406,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) @@ -338,9 +425,9 @@ public: { 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]); } - 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 == 4) ? ((unsigned int*)m_display->m_phy_fb)[y * m_width + x] : GL_RGB_16_to_32(((unsigned short*)m_display->m_phy_fb)[y * m_width + x]); } return 0; } @@ -357,7 +444,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) @@ -379,7 +466,7 @@ public: 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 +479,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 +490,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) { @@ -427,7 +514,7 @@ public: } } } - 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 +586,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; } @@ -538,89 +614,61 @@ 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); + 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 +686,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, EXTERNAL_GFX_OP* gfx_op) : m_phy_fb(phy_fb), m_width(display_width), m_height(display_height), m_gfx_op(gfx_op), 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, EXTERNAL_GFX_OP* gfx_op) : 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_gfx_op(gfx_op), m_surface_index(0) { ASSERT(color_bytes == 2 || color_bytes == 4); ASSERT(m_surface_cnt <= SURFACE_CNT_MAX); @@ -726,16 +709,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 +721,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,18 +744,18 @@ 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) { - 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_gfx_op->draw_pixel; for (int y = y0; y <= y1; y++) { //Left surface @@ -795,7 +772,7 @@ inline int c_display::swipe_surface(c_surface* s0, c_surface* s1, int x0, int x1 } 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_gfx_op->draw_pixel; for (int y = y0; y <= y1; y++) { //Left surface @@ -3407,22 +3384,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 +4231,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 +4269,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 +4289,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 49cff5b..96541c3 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 c4fc88a..d77aa29 100644 --- a/HelloJPG/UIcode/GuiLite.h +++ b/HelloJPG/UIcode/GuiLite.h @@ -247,18 +247,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, EXTERNAL_GFX_OP* gfx_op = 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, EXTERNAL_GFX_OP* gfx_op = 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 +278,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_gfx_op && m_gfx_op->draw_pixel) + { + return m_gfx_op->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_gfx_op && m_gfx_op->fill_rect) + { + return m_gfx_op->fill_rect(x0, y0, x1, y1, rgb); + } + if (m_gfx_op && m_gfx_op->draw_pixel) + { + for (int y = y0; y <= y1; y++) + { + for (int x = x0; x <= x1; x++) + { + m_gfx_op->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 bits, 32 bits only + void* m_phy_fb; //physical framebuffer + struct EXTERNAL_GFX_OP* m_gfx_op; //Rendering by external method 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 +406,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) @@ -338,9 +425,9 @@ public: { 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]); } - 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 == 4) ? ((unsigned int*)m_display->m_phy_fb)[y * m_width + x] : GL_RGB_16_to_32(((unsigned short*)m_display->m_phy_fb)[y * m_width + x]); } return 0; } @@ -357,7 +444,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) @@ -379,7 +466,7 @@ public: 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 +479,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 +490,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) { @@ -427,7 +514,7 @@ public: } } } - 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 +586,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; } @@ -538,89 +614,61 @@ 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); + 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 +686,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, EXTERNAL_GFX_OP* gfx_op) : m_phy_fb(phy_fb), m_width(display_width), m_height(display_height), m_gfx_op(gfx_op), 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, EXTERNAL_GFX_OP* gfx_op) : 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_gfx_op(gfx_op), m_surface_index(0) { ASSERT(color_bytes == 2 || color_bytes == 4); ASSERT(m_surface_cnt <= SURFACE_CNT_MAX); @@ -726,16 +709,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 +721,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,18 +744,18 @@ 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) { - 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_gfx_op->draw_pixel; for (int y = y0; y <= y1; y++) { //Left surface @@ -795,7 +772,7 @@ inline int c_display::swipe_surface(c_surface* s0, c_surface* s1, int x0, int x1 } 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_gfx_op->draw_pixel; for (int y = y0; y <= y1; y++) { //Left surface @@ -3407,22 +3384,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 +4231,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 +4269,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 +4289,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/BuildLinux/.sync_build.sh b/HelloLayers/BuildLinux/.sync_build.sh index 49cff5b..b7410ec 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/UIcode/GuiLite.h b/HelloLayers/UIcode/GuiLite.h index c4fc88a..d77aa29 100644 --- a/HelloLayers/UIcode/GuiLite.h +++ b/HelloLayers/UIcode/GuiLite.h @@ -247,18 +247,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, EXTERNAL_GFX_OP* gfx_op = 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, EXTERNAL_GFX_OP* gfx_op = 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 +278,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_gfx_op && m_gfx_op->draw_pixel) + { + return m_gfx_op->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_gfx_op && m_gfx_op->fill_rect) + { + return m_gfx_op->fill_rect(x0, y0, x1, y1, rgb); + } + if (m_gfx_op && m_gfx_op->draw_pixel) + { + for (int y = y0; y <= y1; y++) + { + for (int x = x0; x <= x1; x++) + { + m_gfx_op->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 bits, 32 bits only + void* m_phy_fb; //physical framebuffer + struct EXTERNAL_GFX_OP* m_gfx_op; //Rendering by external method 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 +406,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) @@ -338,9 +425,9 @@ public: { 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]); } - 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 == 4) ? ((unsigned int*)m_display->m_phy_fb)[y * m_width + x] : GL_RGB_16_to_32(((unsigned short*)m_display->m_phy_fb)[y * m_width + x]); } return 0; } @@ -357,7 +444,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) @@ -379,7 +466,7 @@ public: 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 +479,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 +490,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) { @@ -427,7 +514,7 @@ public: } } } - 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 +586,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; } @@ -538,89 +614,61 @@ 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); + 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 +686,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, EXTERNAL_GFX_OP* gfx_op) : m_phy_fb(phy_fb), m_width(display_width), m_height(display_height), m_gfx_op(gfx_op), 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, EXTERNAL_GFX_OP* gfx_op) : 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_gfx_op(gfx_op), m_surface_index(0) { ASSERT(color_bytes == 2 || color_bytes == 4); ASSERT(m_surface_cnt <= SURFACE_CNT_MAX); @@ -726,16 +709,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 +721,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,18 +744,18 @@ 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) { - 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_gfx_op->draw_pixel; for (int y = y0; y <= y1; y++) { //Left surface @@ -795,7 +772,7 @@ inline int c_display::swipe_surface(c_surface* s0, c_surface* s1, int x0, int x1 } 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_gfx_op->draw_pixel; for (int y = y0; y <= y1; y++) { //Left surface @@ -3407,22 +3384,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 +4231,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 +4269,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 +4289,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 46f629b..e45678a 100644 --- a/HelloLayers/UIcode/UIcode.cpp +++ b/HelloLayers/UIcode/UIcode.cpp @@ -63,20 +63,10 @@ void load_resource() } 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; - } + 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, gfx_op); + s_surface = &surface; + s_display = &display; load_resource(); draw_on_layer_0(); diff --git a/HelloMario/BuildLinux/.sync_build.sh b/HelloMario/BuildLinux/.sync_build.sh index 49cff5b..44974a8 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/UIcode/GuiLite.h b/HelloMario/UIcode/GuiLite.h index c4fc88a..d77aa29 100644 --- a/HelloMario/UIcode/GuiLite.h +++ b/HelloMario/UIcode/GuiLite.h @@ -247,18 +247,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, EXTERNAL_GFX_OP* gfx_op = 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, EXTERNAL_GFX_OP* gfx_op = 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 +278,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_gfx_op && m_gfx_op->draw_pixel) + { + return m_gfx_op->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_gfx_op && m_gfx_op->fill_rect) + { + return m_gfx_op->fill_rect(x0, y0, x1, y1, rgb); + } + if (m_gfx_op && m_gfx_op->draw_pixel) + { + for (int y = y0; y <= y1; y++) + { + for (int x = x0; x <= x1; x++) + { + m_gfx_op->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 bits, 32 bits only + void* m_phy_fb; //physical framebuffer + struct EXTERNAL_GFX_OP* m_gfx_op; //Rendering by external method 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 +406,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) @@ -338,9 +425,9 @@ public: { 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]); } - 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 == 4) ? ((unsigned int*)m_display->m_phy_fb)[y * m_width + x] : GL_RGB_16_to_32(((unsigned short*)m_display->m_phy_fb)[y * m_width + x]); } return 0; } @@ -357,7 +444,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) @@ -379,7 +466,7 @@ public: 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 +479,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 +490,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) { @@ -427,7 +514,7 @@ public: } } } - 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 +586,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; } @@ -538,89 +614,61 @@ 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); + 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 +686,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, EXTERNAL_GFX_OP* gfx_op) : m_phy_fb(phy_fb), m_width(display_width), m_height(display_height), m_gfx_op(gfx_op), 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, EXTERNAL_GFX_OP* gfx_op) : 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_gfx_op(gfx_op), m_surface_index(0) { ASSERT(color_bytes == 2 || color_bytes == 4); ASSERT(m_surface_cnt <= SURFACE_CNT_MAX); @@ -726,16 +709,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 +721,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,18 +744,18 @@ 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) { - 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_gfx_op->draw_pixel; for (int y = y0; y <= y1; y++) { //Left surface @@ -795,7 +772,7 @@ inline int c_display::swipe_surface(c_surface* s0, c_surface* s1, int x0, int x1 } 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_gfx_op->draw_pixel; for (int y = y0; y <= y1; y++) { //Left surface @@ -3407,22 +3384,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 +4231,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 +4269,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 +4289,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 ef5984c..6059ec3 100644 --- a/HelloMario/UIcode/UIcode.cpp +++ b/HelloMario/UIcode/UIcode.cpp @@ -104,20 +104,10 @@ 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; - } + 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, gfx_op); + 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); diff --git a/HelloMolecule/BuildLinux/.sync_build.sh b/HelloMolecule/BuildLinux/.sync_build.sh index 49cff5b..154fab7 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/UIcode/GuiLite.h b/HelloMolecule/UIcode/GuiLite.h index c4fc88a..d77aa29 100644 --- a/HelloMolecule/UIcode/GuiLite.h +++ b/HelloMolecule/UIcode/GuiLite.h @@ -247,18 +247,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, EXTERNAL_GFX_OP* gfx_op = 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, EXTERNAL_GFX_OP* gfx_op = 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 +278,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_gfx_op && m_gfx_op->draw_pixel) + { + return m_gfx_op->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_gfx_op && m_gfx_op->fill_rect) + { + return m_gfx_op->fill_rect(x0, y0, x1, y1, rgb); + } + if (m_gfx_op && m_gfx_op->draw_pixel) + { + for (int y = y0; y <= y1; y++) + { + for (int x = x0; x <= x1; x++) + { + m_gfx_op->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 bits, 32 bits only + void* m_phy_fb; //physical framebuffer + struct EXTERNAL_GFX_OP* m_gfx_op; //Rendering by external method 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 +406,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) @@ -338,9 +425,9 @@ public: { 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]); } - 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 == 4) ? ((unsigned int*)m_display->m_phy_fb)[y * m_width + x] : GL_RGB_16_to_32(((unsigned short*)m_display->m_phy_fb)[y * m_width + x]); } return 0; } @@ -357,7 +444,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) @@ -379,7 +466,7 @@ public: 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 +479,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 +490,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) { @@ -427,7 +514,7 @@ public: } } } - 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 +586,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; } @@ -538,89 +614,61 @@ 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); + 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 +686,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, EXTERNAL_GFX_OP* gfx_op) : m_phy_fb(phy_fb), m_width(display_width), m_height(display_height), m_gfx_op(gfx_op), 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, EXTERNAL_GFX_OP* gfx_op) : 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_gfx_op(gfx_op), m_surface_index(0) { ASSERT(color_bytes == 2 || color_bytes == 4); ASSERT(m_surface_cnt <= SURFACE_CNT_MAX); @@ -726,16 +709,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 +721,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,18 +744,18 @@ 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) { - 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_gfx_op->draw_pixel; for (int y = y0; y <= y1; y++) { //Left surface @@ -795,7 +772,7 @@ inline int c_display::swipe_surface(c_surface* s0, c_surface* s1, int x0, int x1 } 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_gfx_op->draw_pixel; for (int y = y0; y <= y1; y++) { //Left surface @@ -3407,22 +3384,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 +4231,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 +4269,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 +4289,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 d1375f8..09949ce 100644 --- a/HelloMolecule/UIcode/UIcode.cpp +++ b/HelloMolecule/UIcode/UIcode.cpp @@ -152,20 +152,10 @@ 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) { - 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, gfx_op); + s_surface = &surface; + s_display = &display; //background s_surface->fill_rect(0, 0, UI_WIDTH, UI_HEIGHT, 0, Z_ORDER_LEVEL_0); diff --git a/HelloNets/BuildLinux/.sync_build.sh b/HelloNets/BuildLinux/.sync_build.sh index 49cff5b..964054c 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/UIcode/GuiLite.h b/HelloNets/UIcode/GuiLite.h index c4fc88a..d77aa29 100644 --- a/HelloNets/UIcode/GuiLite.h +++ b/HelloNets/UIcode/GuiLite.h @@ -247,18 +247,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, EXTERNAL_GFX_OP* gfx_op = 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, EXTERNAL_GFX_OP* gfx_op = 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 +278,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_gfx_op && m_gfx_op->draw_pixel) + { + return m_gfx_op->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_gfx_op && m_gfx_op->fill_rect) + { + return m_gfx_op->fill_rect(x0, y0, x1, y1, rgb); + } + if (m_gfx_op && m_gfx_op->draw_pixel) + { + for (int y = y0; y <= y1; y++) + { + for (int x = x0; x <= x1; x++) + { + m_gfx_op->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 bits, 32 bits only + void* m_phy_fb; //physical framebuffer + struct EXTERNAL_GFX_OP* m_gfx_op; //Rendering by external method 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 +406,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) @@ -338,9 +425,9 @@ public: { 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]); } - 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 == 4) ? ((unsigned int*)m_display->m_phy_fb)[y * m_width + x] : GL_RGB_16_to_32(((unsigned short*)m_display->m_phy_fb)[y * m_width + x]); } return 0; } @@ -357,7 +444,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) @@ -379,7 +466,7 @@ public: 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 +479,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 +490,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) { @@ -427,7 +514,7 @@ public: } } } - 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 +586,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; } @@ -538,89 +614,61 @@ 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); + 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 +686,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, EXTERNAL_GFX_OP* gfx_op) : m_phy_fb(phy_fb), m_width(display_width), m_height(display_height), m_gfx_op(gfx_op), 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, EXTERNAL_GFX_OP* gfx_op) : 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_gfx_op(gfx_op), m_surface_index(0) { ASSERT(color_bytes == 2 || color_bytes == 4); ASSERT(m_surface_cnt <= SURFACE_CNT_MAX); @@ -726,16 +709,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 +721,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,18 +744,18 @@ 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) { - 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_gfx_op->draw_pixel; for (int y = y0; y <= y1; y++) { //Left surface @@ -795,7 +772,7 @@ inline int c_display::swipe_surface(c_surface* s0, c_surface* s1, int x0, int x1 } 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_gfx_op->draw_pixel; for (int y = y0; y <= y1; y++) { //Left surface @@ -3407,22 +3384,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 +4231,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 +4269,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 +4289,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 14f7b88..b0d5bf7 100644 --- a/HelloNets/UIcode/UIcode.cpp +++ b/HelloNets/UIcode/UIcode.cpp @@ -114,20 +114,10 @@ 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) { - 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, gfx_op); + 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); diff --git a/HelloNoTouch/BuildLinux/.sync_build.sh b/HelloNoTouch/BuildLinux/.sync_build.sh index 49cff5b..ce63bb6 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/UIcode/GuiLite.h b/HelloNoTouch/UIcode/GuiLite.h index c4fc88a..d77aa29 100644 --- a/HelloNoTouch/UIcode/GuiLite.h +++ b/HelloNoTouch/UIcode/GuiLite.h @@ -247,18 +247,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, EXTERNAL_GFX_OP* gfx_op = 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, EXTERNAL_GFX_OP* gfx_op = 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 +278,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_gfx_op && m_gfx_op->draw_pixel) + { + return m_gfx_op->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_gfx_op && m_gfx_op->fill_rect) + { + return m_gfx_op->fill_rect(x0, y0, x1, y1, rgb); + } + if (m_gfx_op && m_gfx_op->draw_pixel) + { + for (int y = y0; y <= y1; y++) + { + for (int x = x0; x <= x1; x++) + { + m_gfx_op->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 bits, 32 bits only + void* m_phy_fb; //physical framebuffer + struct EXTERNAL_GFX_OP* m_gfx_op; //Rendering by external method 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 +406,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) @@ -338,9 +425,9 @@ public: { 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]); } - 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 == 4) ? ((unsigned int*)m_display->m_phy_fb)[y * m_width + x] : GL_RGB_16_to_32(((unsigned short*)m_display->m_phy_fb)[y * m_width + x]); } return 0; } @@ -357,7 +444,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) @@ -379,7 +466,7 @@ public: 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 +479,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 +490,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) { @@ -427,7 +514,7 @@ public: } } } - 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 +586,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; } @@ -538,89 +614,61 @@ 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); + 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 +686,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, EXTERNAL_GFX_OP* gfx_op) : m_phy_fb(phy_fb), m_width(display_width), m_height(display_height), m_gfx_op(gfx_op), 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, EXTERNAL_GFX_OP* gfx_op) : 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_gfx_op(gfx_op), m_surface_index(0) { ASSERT(color_bytes == 2 || color_bytes == 4); ASSERT(m_surface_cnt <= SURFACE_CNT_MAX); @@ -726,16 +709,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 +721,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,18 +744,18 @@ 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) { - 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_gfx_op->draw_pixel; for (int y = y0; y <= y1; y++) { //Left surface @@ -795,7 +772,7 @@ inline int c_display::swipe_surface(c_surface* s0, c_surface* s1, int x0, int x1 } 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_gfx_op->draw_pixel; for (int y = y0; y <= y1; y++) { //Left surface @@ -3407,22 +3384,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 +4231,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 +4269,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 +4289,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 b1ade2a..134c739 100644 --- a/HelloNoTouch/UIcode/UIcode.cpp +++ b/HelloNoTouch/UIcode/UIcode.cpp @@ -89,20 +89,10 @@ 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) { 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, gfx_op); + 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(); diff --git a/HelloParticle/BuildLinux/.sync_build.sh b/HelloParticle/BuildLinux/.sync_build.sh index 49cff5b..a892c25 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/UIcode/GuiLite.h b/HelloParticle/UIcode/GuiLite.h index c4fc88a..d77aa29 100644 --- a/HelloParticle/UIcode/GuiLite.h +++ b/HelloParticle/UIcode/GuiLite.h @@ -247,18 +247,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, EXTERNAL_GFX_OP* gfx_op = 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, EXTERNAL_GFX_OP* gfx_op = 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 +278,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_gfx_op && m_gfx_op->draw_pixel) + { + return m_gfx_op->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_gfx_op && m_gfx_op->fill_rect) + { + return m_gfx_op->fill_rect(x0, y0, x1, y1, rgb); + } + if (m_gfx_op && m_gfx_op->draw_pixel) + { + for (int y = y0; y <= y1; y++) + { + for (int x = x0; x <= x1; x++) + { + m_gfx_op->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 bits, 32 bits only + void* m_phy_fb; //physical framebuffer + struct EXTERNAL_GFX_OP* m_gfx_op; //Rendering by external method 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 +406,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) @@ -338,9 +425,9 @@ public: { 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]); } - 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 == 4) ? ((unsigned int*)m_display->m_phy_fb)[y * m_width + x] : GL_RGB_16_to_32(((unsigned short*)m_display->m_phy_fb)[y * m_width + x]); } return 0; } @@ -357,7 +444,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) @@ -379,7 +466,7 @@ public: 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 +479,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 +490,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) { @@ -427,7 +514,7 @@ public: } } } - 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 +586,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; } @@ -538,89 +614,61 @@ 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); + 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 +686,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, EXTERNAL_GFX_OP* gfx_op) : m_phy_fb(phy_fb), m_width(display_width), m_height(display_height), m_gfx_op(gfx_op), 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, EXTERNAL_GFX_OP* gfx_op) : 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_gfx_op(gfx_op), m_surface_index(0) { ASSERT(color_bytes == 2 || color_bytes == 4); ASSERT(m_surface_cnt <= SURFACE_CNT_MAX); @@ -726,16 +709,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 +721,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,18 +744,18 @@ 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) { - 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_gfx_op->draw_pixel; for (int y = y0; y <= y1; y++) { //Left surface @@ -795,7 +772,7 @@ inline int c_display::swipe_surface(c_surface* s0, c_surface* s1, int x0, int x1 } 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_gfx_op->draw_pixel; for (int y = y0; y <= y1; y++) { //Left surface @@ -3407,22 +3384,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 +4231,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 +4269,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 +4289,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 5f0aea5..6d242e2 100644 --- a/HelloParticle/UIcode/UIcode.cpp +++ b/HelloParticle/UIcode/UIcode.cpp @@ -50,20 +50,10 @@ 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) { 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, gfx_op); + 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)); diff --git a/HelloPendulum/BuildLinux/.sync_build.sh b/HelloPendulum/BuildLinux/.sync_build.sh index 49cff5b..f003527 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/UIcode/GuiLite.h b/HelloPendulum/UIcode/GuiLite.h index c4fc88a..d77aa29 100644 --- a/HelloPendulum/UIcode/GuiLite.h +++ b/HelloPendulum/UIcode/GuiLite.h @@ -247,18 +247,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, EXTERNAL_GFX_OP* gfx_op = 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, EXTERNAL_GFX_OP* gfx_op = 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 +278,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_gfx_op && m_gfx_op->draw_pixel) + { + return m_gfx_op->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_gfx_op && m_gfx_op->fill_rect) + { + return m_gfx_op->fill_rect(x0, y0, x1, y1, rgb); + } + if (m_gfx_op && m_gfx_op->draw_pixel) + { + for (int y = y0; y <= y1; y++) + { + for (int x = x0; x <= x1; x++) + { + m_gfx_op->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 bits, 32 bits only + void* m_phy_fb; //physical framebuffer + struct EXTERNAL_GFX_OP* m_gfx_op; //Rendering by external method 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 +406,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) @@ -338,9 +425,9 @@ public: { 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]); } - 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 == 4) ? ((unsigned int*)m_display->m_phy_fb)[y * m_width + x] : GL_RGB_16_to_32(((unsigned short*)m_display->m_phy_fb)[y * m_width + x]); } return 0; } @@ -357,7 +444,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) @@ -379,7 +466,7 @@ public: 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 +479,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 +490,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) { @@ -427,7 +514,7 @@ public: } } } - 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 +586,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; } @@ -538,89 +614,61 @@ 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); + 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 +686,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, EXTERNAL_GFX_OP* gfx_op) : m_phy_fb(phy_fb), m_width(display_width), m_height(display_height), m_gfx_op(gfx_op), 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, EXTERNAL_GFX_OP* gfx_op) : 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_gfx_op(gfx_op), m_surface_index(0) { ASSERT(color_bytes == 2 || color_bytes == 4); ASSERT(m_surface_cnt <= SURFACE_CNT_MAX); @@ -726,16 +709,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 +721,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,18 +744,18 @@ 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) { - 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_gfx_op->draw_pixel; for (int y = y0; y <= y1; y++) { //Left surface @@ -795,7 +772,7 @@ inline int c_display::swipe_surface(c_surface* s0, c_surface* s1, int x0, int x1 } 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_gfx_op->draw_pixel; for (int y = y0; y <= y1; y++) { //Left surface @@ -3407,22 +3384,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 +4231,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 +4269,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 +4289,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 57ab04e..a09e2ef 100644 --- a/HelloPendulum/UIcode/UIcode.cpp +++ b/HelloPendulum/UIcode/UIcode.cpp @@ -93,20 +93,11 @@ 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; - } + 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, gfx_op); + 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); diff --git a/HelloScroll/BuildLinux/.sync_build.sh b/HelloScroll/BuildLinux/.sync_build.sh index 49cff5b..af3dad0 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 c4fc88a..d77aa29 100644 --- a/HelloScroll/UIcode/GuiLite.h +++ b/HelloScroll/UIcode/GuiLite.h @@ -247,18 +247,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, EXTERNAL_GFX_OP* gfx_op = 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, EXTERNAL_GFX_OP* gfx_op = 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 +278,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_gfx_op && m_gfx_op->draw_pixel) + { + return m_gfx_op->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_gfx_op && m_gfx_op->fill_rect) + { + return m_gfx_op->fill_rect(x0, y0, x1, y1, rgb); + } + if (m_gfx_op && m_gfx_op->draw_pixel) + { + for (int y = y0; y <= y1; y++) + { + for (int x = x0; x <= x1; x++) + { + m_gfx_op->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 bits, 32 bits only + void* m_phy_fb; //physical framebuffer + struct EXTERNAL_GFX_OP* m_gfx_op; //Rendering by external method 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 +406,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) @@ -338,9 +425,9 @@ public: { 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]); } - 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 == 4) ? ((unsigned int*)m_display->m_phy_fb)[y * m_width + x] : GL_RGB_16_to_32(((unsigned short*)m_display->m_phy_fb)[y * m_width + x]); } return 0; } @@ -357,7 +444,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) @@ -379,7 +466,7 @@ public: 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 +479,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 +490,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) { @@ -427,7 +514,7 @@ public: } } } - 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 +586,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; } @@ -538,89 +614,61 @@ 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); + 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 +686,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, EXTERNAL_GFX_OP* gfx_op) : m_phy_fb(phy_fb), m_width(display_width), m_height(display_height), m_gfx_op(gfx_op), 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, EXTERNAL_GFX_OP* gfx_op) : 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_gfx_op(gfx_op), m_surface_index(0) { ASSERT(color_bytes == 2 || color_bytes == 4); ASSERT(m_surface_cnt <= SURFACE_CNT_MAX); @@ -726,16 +709,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 +721,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,18 +744,18 @@ 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) { - 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_gfx_op->draw_pixel; for (int y = y0; y <= y1; y++) { //Left surface @@ -795,7 +772,7 @@ inline int c_display::swipe_surface(c_surface* s0, c_surface* s1, int x0, int x1 } 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_gfx_op->draw_pixel; for (int y = y0; y <= y1; y++) { //Left surface @@ -3407,22 +3384,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 +4231,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 +4269,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 +4289,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 62736b4..012f80b 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, EXTERNAL_GFX_OP* gfx_op = 0) : c_display(phy_fb, display_width, display_height, surface, gfx_op) {} + 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 49cff5b..b3e57ae 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 c4fc88a..d77aa29 100644 --- a/HelloSlide/UIcode/GuiLite.h +++ b/HelloSlide/UIcode/GuiLite.h @@ -247,18 +247,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, EXTERNAL_GFX_OP* gfx_op = 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, EXTERNAL_GFX_OP* gfx_op = 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 +278,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_gfx_op && m_gfx_op->draw_pixel) + { + return m_gfx_op->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_gfx_op && m_gfx_op->fill_rect) + { + return m_gfx_op->fill_rect(x0, y0, x1, y1, rgb); + } + if (m_gfx_op && m_gfx_op->draw_pixel) + { + for (int y = y0; y <= y1; y++) + { + for (int x = x0; x <= x1; x++) + { + m_gfx_op->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 bits, 32 bits only + void* m_phy_fb; //physical framebuffer + struct EXTERNAL_GFX_OP* m_gfx_op; //Rendering by external method 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 +406,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) @@ -338,9 +425,9 @@ public: { 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]); } - 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 == 4) ? ((unsigned int*)m_display->m_phy_fb)[y * m_width + x] : GL_RGB_16_to_32(((unsigned short*)m_display->m_phy_fb)[y * m_width + x]); } return 0; } @@ -357,7 +444,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) @@ -379,7 +466,7 @@ public: 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 +479,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 +490,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) { @@ -427,7 +514,7 @@ public: } } } - 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 +586,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; } @@ -538,89 +614,61 @@ 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); + 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 +686,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, EXTERNAL_GFX_OP* gfx_op) : m_phy_fb(phy_fb), m_width(display_width), m_height(display_height), m_gfx_op(gfx_op), 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, EXTERNAL_GFX_OP* gfx_op) : 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_gfx_op(gfx_op), m_surface_index(0) { ASSERT(color_bytes == 2 || color_bytes == 4); ASSERT(m_surface_cnt <= SURFACE_CNT_MAX); @@ -726,16 +709,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 +721,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,18 +744,18 @@ 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) { - 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_gfx_op->draw_pixel; for (int y = y0; y <= y1; y++) { //Left surface @@ -795,7 +772,7 @@ inline int c_display::swipe_surface(c_surface* s0, c_surface* s1, int x0, int x1 } 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_gfx_op->draw_pixel; for (int y = y0; y <= y1; y++) { //Left surface @@ -3407,22 +3384,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 +4231,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 +4269,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 +4289,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 49cff5b..a16fc7f 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/UIcode/GuiLite.h b/HelloStar/UIcode/GuiLite.h index c4fc88a..d77aa29 100644 --- a/HelloStar/UIcode/GuiLite.h +++ b/HelloStar/UIcode/GuiLite.h @@ -247,18 +247,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, EXTERNAL_GFX_OP* gfx_op = 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, EXTERNAL_GFX_OP* gfx_op = 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 +278,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_gfx_op && m_gfx_op->draw_pixel) + { + return m_gfx_op->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_gfx_op && m_gfx_op->fill_rect) + { + return m_gfx_op->fill_rect(x0, y0, x1, y1, rgb); + } + if (m_gfx_op && m_gfx_op->draw_pixel) + { + for (int y = y0; y <= y1; y++) + { + for (int x = x0; x <= x1; x++) + { + m_gfx_op->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 bits, 32 bits only + void* m_phy_fb; //physical framebuffer + struct EXTERNAL_GFX_OP* m_gfx_op; //Rendering by external method 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 +406,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) @@ -338,9 +425,9 @@ public: { 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]); } - 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 == 4) ? ((unsigned int*)m_display->m_phy_fb)[y * m_width + x] : GL_RGB_16_to_32(((unsigned short*)m_display->m_phy_fb)[y * m_width + x]); } return 0; } @@ -357,7 +444,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) @@ -379,7 +466,7 @@ public: 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 +479,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 +490,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) { @@ -427,7 +514,7 @@ public: } } } - 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 +586,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; } @@ -538,89 +614,61 @@ 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); + 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 +686,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, EXTERNAL_GFX_OP* gfx_op) : m_phy_fb(phy_fb), m_width(display_width), m_height(display_height), m_gfx_op(gfx_op), 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, EXTERNAL_GFX_OP* gfx_op) : 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_gfx_op(gfx_op), m_surface_index(0) { ASSERT(color_bytes == 2 || color_bytes == 4); ASSERT(m_surface_cnt <= SURFACE_CNT_MAX); @@ -726,16 +709,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 +721,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,18 +744,18 @@ 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) { - 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_gfx_op->draw_pixel; for (int y = y0; y <= y1; y++) { //Left surface @@ -795,7 +772,7 @@ inline int c_display::swipe_surface(c_surface* s0, c_surface* s1, int x0, int x1 } 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_gfx_op->draw_pixel; for (int y = y0; y <= y1; y++) { //Left surface @@ -3407,22 +3384,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 +4231,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 +4269,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 +4289,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 ee5987f..6d8045b 100644 --- a/HelloStar/UIcode/UIcode.cpp +++ b/HelloStar/UIcode/UIcode.cpp @@ -67,20 +67,10 @@ public: 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; - } + 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, gfx_op); + s_surface = &surface; + s_display = &display; s_surface->fill_rect(0, 0, UI_WIDTH - 1, UI_HEIGHT - 1, 0, Z_ORDER_LEVEL_0); diff --git a/HelloTimer/BuildLinux/.sync_build.sh b/HelloTimer/BuildLinux/.sync_build.sh index 49cff5b..a57e9a8 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/UIcode/GuiLite.h b/HelloTimer/UIcode/GuiLite.h index c4fc88a..d77aa29 100644 --- a/HelloTimer/UIcode/GuiLite.h +++ b/HelloTimer/UIcode/GuiLite.h @@ -247,18 +247,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, EXTERNAL_GFX_OP* gfx_op = 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, EXTERNAL_GFX_OP* gfx_op = 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 +278,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_gfx_op && m_gfx_op->draw_pixel) + { + return m_gfx_op->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_gfx_op && m_gfx_op->fill_rect) + { + return m_gfx_op->fill_rect(x0, y0, x1, y1, rgb); + } + if (m_gfx_op && m_gfx_op->draw_pixel) + { + for (int y = y0; y <= y1; y++) + { + for (int x = x0; x <= x1; x++) + { + m_gfx_op->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 bits, 32 bits only + void* m_phy_fb; //physical framebuffer + struct EXTERNAL_GFX_OP* m_gfx_op; //Rendering by external method 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 +406,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) @@ -338,9 +425,9 @@ public: { 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]); } - 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 == 4) ? ((unsigned int*)m_display->m_phy_fb)[y * m_width + x] : GL_RGB_16_to_32(((unsigned short*)m_display->m_phy_fb)[y * m_width + x]); } return 0; } @@ -357,7 +444,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) @@ -379,7 +466,7 @@ public: 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 +479,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 +490,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) { @@ -427,7 +514,7 @@ public: } } } - 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 +586,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; } @@ -538,89 +614,61 @@ 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); + 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 +686,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, EXTERNAL_GFX_OP* gfx_op) : m_phy_fb(phy_fb), m_width(display_width), m_height(display_height), m_gfx_op(gfx_op), 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, EXTERNAL_GFX_OP* gfx_op) : 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_gfx_op(gfx_op), m_surface_index(0) { ASSERT(color_bytes == 2 || color_bytes == 4); ASSERT(m_surface_cnt <= SURFACE_CNT_MAX); @@ -726,16 +709,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 +721,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,18 +744,18 @@ 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) { - 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_gfx_op->draw_pixel; for (int y = y0; y <= y1; y++) { //Left surface @@ -795,7 +772,7 @@ inline int c_display::swipe_surface(c_surface* s0, c_surface* s1, int x0, int x1 } 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_gfx_op->draw_pixel; for (int y = y0; y <= y1; y++) { //Left surface @@ -3407,22 +3384,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 +4231,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 +4269,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 +4289,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 13f2922..1535989 100644 --- a/HelloTimer/UIcode/UIcode.cpp +++ b/HelloTimer/UIcode/UIcode.cpp @@ -306,20 +306,10 @@ void create_ui(void* phy_fb, int screen_width, int screen_height, int color_byte { 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, gfx_op); + s_surface = &surface; + s_display = &display; //background s_surface->fill_rect(0, 0, UI_WIDTH, UI_HEIGHT, 0, Z_ORDER_LEVEL_0); diff --git a/HelloTransparent/BuildLinux/.sync_build.sh b/HelloTransparent/BuildLinux/.sync_build.sh index 49cff5b..d429316 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 c4fc88a..d77aa29 100644 --- a/HelloTransparent/UIcode/GuiLite.h +++ b/HelloTransparent/UIcode/GuiLite.h @@ -247,18 +247,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, EXTERNAL_GFX_OP* gfx_op = 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, EXTERNAL_GFX_OP* gfx_op = 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 +278,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_gfx_op && m_gfx_op->draw_pixel) + { + return m_gfx_op->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_gfx_op && m_gfx_op->fill_rect) + { + return m_gfx_op->fill_rect(x0, y0, x1, y1, rgb); + } + if (m_gfx_op && m_gfx_op->draw_pixel) + { + for (int y = y0; y <= y1; y++) + { + for (int x = x0; x <= x1; x++) + { + m_gfx_op->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 bits, 32 bits only + void* m_phy_fb; //physical framebuffer + struct EXTERNAL_GFX_OP* m_gfx_op; //Rendering by external method 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 +406,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) @@ -338,9 +425,9 @@ public: { 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]); } - 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 == 4) ? ((unsigned int*)m_display->m_phy_fb)[y * m_width + x] : GL_RGB_16_to_32(((unsigned short*)m_display->m_phy_fb)[y * m_width + x]); } return 0; } @@ -357,7 +444,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) @@ -379,7 +466,7 @@ public: 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 +479,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 +490,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) { @@ -427,7 +514,7 @@ public: } } } - 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 +586,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; } @@ -538,89 +614,61 @@ 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); + 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 +686,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, EXTERNAL_GFX_OP* gfx_op) : m_phy_fb(phy_fb), m_width(display_width), m_height(display_height), m_gfx_op(gfx_op), 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, EXTERNAL_GFX_OP* gfx_op) : 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_gfx_op(gfx_op), m_surface_index(0) { ASSERT(color_bytes == 2 || color_bytes == 4); ASSERT(m_surface_cnt <= SURFACE_CNT_MAX); @@ -726,16 +709,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 +721,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,18 +744,18 @@ 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) { - 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_gfx_op->draw_pixel; for (int y = y0; y <= y1; y++) { //Left surface @@ -795,7 +772,7 @@ inline int c_display::swipe_surface(c_surface* s0, c_surface* s1, int x0, int x1 } 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_gfx_op->draw_pixel; for (int y = y0; y <= y1; y++) { //Left surface @@ -3407,22 +3384,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 +4231,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 +4269,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 +4289,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/surface_transparent.h b/HelloTransparent/UIcode/surface_transparent.h index 51b9273..fa65a57 100644 --- a/HelloTransparent/UIcode/surface_transparent.h +++ b/HelloTransparent/UIcode/surface_transparent.h @@ -54,13 +54,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 +106,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++) { @@ -154,10 +157,10 @@ public: 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) + virtual void draw_pixel_low_level(int x, int y, unsigned int rgb) { m_color_bytes = m_display_color_bytes; - c_surface::draw_pixel_on_fb(x, y, rgb); + c_surface::draw_pixel_low_level(x, y, rgb); m_color_bytes = 4; } int m_display_color_bytes; diff --git a/HelloWave/BuildLinux/.sync_build.sh b/HelloWave/BuildLinux/.sync_build.sh index 49cff5b..859b239 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/UIcode/GuiLite.h b/HelloWave/UIcode/GuiLite.h index c4fc88a..d77aa29 100644 --- a/HelloWave/UIcode/GuiLite.h +++ b/HelloWave/UIcode/GuiLite.h @@ -247,18 +247,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, EXTERNAL_GFX_OP* gfx_op = 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, EXTERNAL_GFX_OP* gfx_op = 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 +278,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_gfx_op && m_gfx_op->draw_pixel) + { + return m_gfx_op->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_gfx_op && m_gfx_op->fill_rect) + { + return m_gfx_op->fill_rect(x0, y0, x1, y1, rgb); + } + if (m_gfx_op && m_gfx_op->draw_pixel) + { + for (int y = y0; y <= y1; y++) + { + for (int x = x0; x <= x1; x++) + { + m_gfx_op->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 bits, 32 bits only + void* m_phy_fb; //physical framebuffer + struct EXTERNAL_GFX_OP* m_gfx_op; //Rendering by external method 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 +406,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) @@ -338,9 +425,9 @@ public: { 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]); } - 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 == 4) ? ((unsigned int*)m_display->m_phy_fb)[y * m_width + x] : GL_RGB_16_to_32(((unsigned short*)m_display->m_phy_fb)[y * m_width + x]); } return 0; } @@ -357,7 +444,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) @@ -379,7 +466,7 @@ public: 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 +479,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 +490,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) { @@ -427,7 +514,7 @@ public: } } } - 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 +586,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; } @@ -538,89 +614,61 @@ 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); + 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 +686,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, EXTERNAL_GFX_OP* gfx_op) : m_phy_fb(phy_fb), m_width(display_width), m_height(display_height), m_gfx_op(gfx_op), 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, EXTERNAL_GFX_OP* gfx_op) : 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_gfx_op(gfx_op), m_surface_index(0) { ASSERT(color_bytes == 2 || color_bytes == 4); ASSERT(m_surface_cnt <= SURFACE_CNT_MAX); @@ -726,16 +709,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 +721,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,18 +744,18 @@ 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) { - 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_gfx_op->draw_pixel; for (int y = y0; y <= y1; y++) { //Left surface @@ -795,7 +772,7 @@ inline int c_display::swipe_surface(c_surface* s0, c_surface* s1, int x0, int x1 } 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_gfx_op->draw_pixel; for (int y = y0; y <= y1; y++) { //Left surface @@ -3407,22 +3384,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 +4231,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 +4269,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 +4289,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 68e2ace..62d4c5b 100644 --- a/HelloWave/UIcode/UIcode.cpp +++ b/HelloWave/UIcode/UIcode.cpp @@ -133,21 +133,11 @@ 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) { 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, gfx_op); + 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); diff --git a/HelloWidgets/BuildLinux/.sync_build.sh b/HelloWidgets/BuildLinux/.sync_build.sh index 49cff5b..01b130e 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 c4fc88a..d77aa29 100644 --- a/HelloWidgets/UIcode/GuiLite.h +++ b/HelloWidgets/UIcode/GuiLite.h @@ -247,18 +247,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, EXTERNAL_GFX_OP* gfx_op = 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, EXTERNAL_GFX_OP* gfx_op = 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 +278,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_gfx_op && m_gfx_op->draw_pixel) + { + return m_gfx_op->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_gfx_op && m_gfx_op->fill_rect) + { + return m_gfx_op->fill_rect(x0, y0, x1, y1, rgb); + } + if (m_gfx_op && m_gfx_op->draw_pixel) + { + for (int y = y0; y <= y1; y++) + { + for (int x = x0; x <= x1; x++) + { + m_gfx_op->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 bits, 32 bits only + void* m_phy_fb; //physical framebuffer + struct EXTERNAL_GFX_OP* m_gfx_op; //Rendering by external method 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 +406,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) @@ -338,9 +425,9 @@ public: { 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]); } - 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 == 4) ? ((unsigned int*)m_display->m_phy_fb)[y * m_width + x] : GL_RGB_16_to_32(((unsigned short*)m_display->m_phy_fb)[y * m_width + x]); } return 0; } @@ -357,7 +444,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) @@ -379,7 +466,7 @@ public: 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 +479,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 +490,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) { @@ -427,7 +514,7 @@ public: } } } - 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 +586,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; } @@ -538,89 +614,61 @@ 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); + 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 +686,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, EXTERNAL_GFX_OP* gfx_op) : m_phy_fb(phy_fb), m_width(display_width), m_height(display_height), m_gfx_op(gfx_op), 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, EXTERNAL_GFX_OP* gfx_op) : 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_gfx_op(gfx_op), m_surface_index(0) { ASSERT(color_bytes == 2 || color_bytes == 4); ASSERT(m_surface_cnt <= SURFACE_CNT_MAX); @@ -726,16 +709,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 +721,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,18 +744,18 @@ 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) { - 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_gfx_op->draw_pixel; for (int y = y0; y <= y1; y++) { //Left surface @@ -795,7 +772,7 @@ inline int c_display::swipe_surface(c_surface* s0, c_surface* s1, int x0, int x1 } 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_gfx_op->draw_pixel; for (int y = y0; y <= y1; y++) { //Left surface @@ -3407,22 +3384,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 +4231,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 +4269,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 +4289,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 49cff5b..e972591 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 c4fc88a..d77aa29 100644 --- a/HelloWindows/UIcode/GuiLite.h +++ b/HelloWindows/UIcode/GuiLite.h @@ -247,18 +247,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, EXTERNAL_GFX_OP* gfx_op = 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, EXTERNAL_GFX_OP* gfx_op = 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 +278,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_gfx_op && m_gfx_op->draw_pixel) + { + return m_gfx_op->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_gfx_op && m_gfx_op->fill_rect) + { + return m_gfx_op->fill_rect(x0, y0, x1, y1, rgb); + } + if (m_gfx_op && m_gfx_op->draw_pixel) + { + for (int y = y0; y <= y1; y++) + { + for (int x = x0; x <= x1; x++) + { + m_gfx_op->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 bits, 32 bits only + void* m_phy_fb; //physical framebuffer + struct EXTERNAL_GFX_OP* m_gfx_op; //Rendering by external method 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 +406,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) @@ -338,9 +425,9 @@ public: { 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]); } - 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 == 4) ? ((unsigned int*)m_display->m_phy_fb)[y * m_width + x] : GL_RGB_16_to_32(((unsigned short*)m_display->m_phy_fb)[y * m_width + x]); } return 0; } @@ -357,7 +444,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) @@ -379,7 +466,7 @@ public: 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 +479,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 +490,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) { @@ -427,7 +514,7 @@ public: } } } - 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 +586,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; } @@ -538,89 +614,61 @@ 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); + 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 +686,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, EXTERNAL_GFX_OP* gfx_op) : m_phy_fb(phy_fb), m_width(display_width), m_height(display_height), m_gfx_op(gfx_op), 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, EXTERNAL_GFX_OP* gfx_op) : 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_gfx_op(gfx_op), m_surface_index(0) { ASSERT(color_bytes == 2 || color_bytes == 4); ASSERT(m_surface_cnt <= SURFACE_CNT_MAX); @@ -726,16 +709,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 +721,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,18 +744,18 @@ 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) { - 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_gfx_op->draw_pixel; for (int y = y0; y <= y1; y++) { //Left surface @@ -795,7 +772,7 @@ inline int c_display::swipe_surface(c_surface* s0, c_surface* s1, int x0, int x1 } 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_gfx_op->draw_pixel; for (int y = y0; y <= y1; y++) { //Left surface @@ -3407,22 +3384,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 +4231,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 +4269,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 +4289,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 15c47c5..4ec3997 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 | ./HelloAnimation shared-fb exit -1 fi diff --git a/HostMonitor/UIcode/include/GuiLite.h b/HostMonitor/UIcode/include/GuiLite.h index c4fc88a..d77aa29 100644 --- a/HostMonitor/UIcode/include/GuiLite.h +++ b/HostMonitor/UIcode/include/GuiLite.h @@ -247,18 +247,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, EXTERNAL_GFX_OP* gfx_op = 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, EXTERNAL_GFX_OP* gfx_op = 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 +278,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_gfx_op && m_gfx_op->draw_pixel) + { + return m_gfx_op->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_gfx_op && m_gfx_op->fill_rect) + { + return m_gfx_op->fill_rect(x0, y0, x1, y1, rgb); + } + if (m_gfx_op && m_gfx_op->draw_pixel) + { + for (int y = y0; y <= y1; y++) + { + for (int x = x0; x <= x1; x++) + { + m_gfx_op->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 bits, 32 bits only + void* m_phy_fb; //physical framebuffer + struct EXTERNAL_GFX_OP* m_gfx_op; //Rendering by external method 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 +406,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) @@ -338,9 +425,9 @@ public: { 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]); } - 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 == 4) ? ((unsigned int*)m_display->m_phy_fb)[y * m_width + x] : GL_RGB_16_to_32(((unsigned short*)m_display->m_phy_fb)[y * m_width + x]); } return 0; } @@ -357,7 +444,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) @@ -379,7 +466,7 @@ public: 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 +479,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 +490,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) { @@ -427,7 +514,7 @@ public: } } } - 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 +586,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; } @@ -538,89 +614,61 @@ 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); + 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 +686,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, EXTERNAL_GFX_OP* gfx_op) : m_phy_fb(phy_fb), m_width(display_width), m_height(display_height), m_gfx_op(gfx_op), 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, EXTERNAL_GFX_OP* gfx_op) : 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_gfx_op(gfx_op), m_surface_index(0) { ASSERT(color_bytes == 2 || color_bytes == 4); ASSERT(m_surface_cnt <= SURFACE_CNT_MAX); @@ -726,16 +709,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 +721,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,18 +744,18 @@ 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) { - 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_gfx_op->draw_pixel; for (int y = y0; y <= y1; y++) { //Left surface @@ -795,7 +772,7 @@ inline int c_display::swipe_surface(c_surface* s0, c_surface* s1, int x0, int x1 } 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_gfx_op->draw_pixel; for (int y = y0; y <= y1; y++) { //Left surface @@ -3407,22 +3384,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 +4231,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 +4269,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 +4289,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 -- Gitee From 6699c41e3909c40e835a38189589fdb4b831fc84 Mon Sep 17 00:00:00 2001 From: idea4good Date: Tue, 24 May 2022 23:50:34 +0800 Subject: [PATCH 2/4] fix HelloTransparent issue --- HelloTransparent/UIcode/UIcode.cpp | 3 +- HelloTransparent/UIcode/surface_transparent.h | 31 +++++++++---------- 2 files changed, 16 insertions(+), 18 deletions(-) diff --git a/HelloTransparent/UIcode/UIcode.cpp b/HelloTransparent/UIcode/UIcode.cpp index 5906cbd..653d082 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 fa65a57..22ea57d 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) @@ -152,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_low_level(int x, int y, unsigned int rgb) - { - m_color_bytes = m_display_color_bytes; - c_surface::draw_pixel_low_level(x, y, rgb); - m_color_bytes = 4; - } int m_display_color_bytes; }; -- Gitee From b4868f1559edefd124b9cbe200933ed9f20c6038 Mon Sep 17 00:00:00 2001 From: idea4good Date: Wed, 25 May 2022 10:54:32 +0800 Subject: [PATCH 3/4] update HelloJPG --- .github/.test.sh | 6 +- Hello3D/UIcode/GuiLite.h | 225 +++++++++++++-------------- Hello3Ddonut/UIcode/GuiLite.h | 225 +++++++++++++-------------- Hello3Dwave/UIcode/GuiLite.h | 225 +++++++++++++-------------- HelloAnimation/UIcode/GuiLite.h | 225 +++++++++++++-------------- HelloCircle/UIcode/GuiLite.h | 225 +++++++++++++-------------- HelloFFmpeg/UIcode/GuiLite.h | 225 +++++++++++++-------------- HelloFont/UIcode/GuiLite.h | 225 +++++++++++++-------------- HelloFreetype/UIcode/GuiLite.h | 225 +++++++++++++-------------- HelloJPG/UIcode/GuiLite.h | 225 +++++++++++++-------------- HelloJPG/UIcode/UIcode.cpp | 3 +- HelloLayers/UIcode/GuiLite.h | 225 +++++++++++++-------------- HelloMario/UIcode/GuiLite.h | 225 +++++++++++++-------------- HelloMolecule/UIcode/GuiLite.h | 225 +++++++++++++-------------- HelloNets/UIcode/GuiLite.h | 225 +++++++++++++-------------- HelloNoTouch/UIcode/GuiLite.h | 225 +++++++++++++-------------- HelloParticle/UIcode/GuiLite.h | 225 +++++++++++++-------------- HelloPendulum/UIcode/GuiLite.h | 225 +++++++++++++-------------- HelloScroll/UIcode/GuiLite.h | 225 +++++++++++++-------------- HelloSlide/UIcode/GuiLite.h | 225 +++++++++++++-------------- HelloStar/UIcode/GuiLite.h | 225 +++++++++++++-------------- HelloTimer/UIcode/GuiLite.h | 225 +++++++++++++-------------- HelloTransparent/UIcode/GuiLite.h | 225 +++++++++++++-------------- HelloWave/UIcode/GuiLite.h | 225 +++++++++++++-------------- HelloWidgets/UIcode/GuiLite.h | 225 +++++++++++++-------------- HelloWindows/UIcode/GuiLite.h | 225 +++++++++++++-------------- HostMonitor/BuildLinux/.sync_data.sh | 2 +- HostMonitor/UIcode/include/GuiLite.h | 225 +++++++++++++-------------- 28 files changed, 2656 insertions(+), 2980 deletions(-) diff --git a/.github/.test.sh b/.github/.test.sh index 3c83072..dc66c0f 100644 --- a/.github/.test.sh +++ b/.github/.test.sh @@ -4,7 +4,7 @@ set -e #test HelloXXX for file in ./Hello* do - echo -e "\e[44m $file building...\e[49m" + echo -e "\e[44m $file running...\e[49m" if [ "$file" == "./HelloAzureIoT" ]; then echo "skip $file" continue @@ -16,6 +16,6 @@ do done #test HostMonitor -echo -e "\e[44m ./HostMonitor building...\e[49m" +echo -e "\e[44m ./HostMonitor running...\e[49m" cd HostMonitor/BuildLinux -timeout 5s ./.sync_build.sh +timeout 5s ./.sync_data.sh diff --git a/Hello3D/UIcode/GuiLite.h b/Hello3D/UIcode/GuiLite.h index d77aa29..1b4611b 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 { @@ -419,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_display->m_phy_fb) { - return (m_color_bytes == 4) ? ((unsigned int*)m_display->m_phy_fb)[y * m_width + x] : GL_RGB_16_to_32(((unsigned short*)m_display->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; } @@ -454,13 +441,13 @@ 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; } } @@ -503,13 +490,13 @@ 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; } } } @@ -613,7 +600,7 @@ 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]); + 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); } } @@ -753,7 +740,7 @@ inline int c_display::swipe_surface(c_surface* s0, c_surface* s1, int x0, int x1 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) = m_gfx_op->draw_pixel; for (int y = y0; y <= y1; y++) @@ -761,16 +748,16 @@ inline int c_display::swipe_surface(c_surface* s0, c_surface* s1, int x0, int x1 //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) = m_gfx_op->draw_pixel; for (int y = y0; y <= y1; y++) @@ -778,12 +765,12 @@ inline int c_display::swipe_surface(c_surface* s0, c_surface* s1, int x0, int x1 //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]); } } } diff --git a/Hello3Ddonut/UIcode/GuiLite.h b/Hello3Ddonut/UIcode/GuiLite.h index d77aa29..1b4611b 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 { @@ -419,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_display->m_phy_fb) { - return (m_color_bytes == 4) ? ((unsigned int*)m_display->m_phy_fb)[y * m_width + x] : GL_RGB_16_to_32(((unsigned short*)m_display->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; } @@ -454,13 +441,13 @@ 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; } } @@ -503,13 +490,13 @@ 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; } } } @@ -613,7 +600,7 @@ 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]); + 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); } } @@ -753,7 +740,7 @@ inline int c_display::swipe_surface(c_surface* s0, c_surface* s1, int x0, int x1 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) = m_gfx_op->draw_pixel; for (int y = y0; y <= y1; y++) @@ -761,16 +748,16 @@ inline int c_display::swipe_surface(c_surface* s0, c_surface* s1, int x0, int x1 //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) = m_gfx_op->draw_pixel; for (int y = y0; y <= y1; y++) @@ -778,12 +765,12 @@ inline int c_display::swipe_surface(c_surface* s0, c_surface* s1, int x0, int x1 //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]); } } } diff --git a/Hello3Dwave/UIcode/GuiLite.h b/Hello3Dwave/UIcode/GuiLite.h index d77aa29..1b4611b 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 { @@ -419,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_display->m_phy_fb) { - return (m_color_bytes == 4) ? ((unsigned int*)m_display->m_phy_fb)[y * m_width + x] : GL_RGB_16_to_32(((unsigned short*)m_display->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; } @@ -454,13 +441,13 @@ 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; } } @@ -503,13 +490,13 @@ 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; } } } @@ -613,7 +600,7 @@ 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]); + 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); } } @@ -753,7 +740,7 @@ inline int c_display::swipe_surface(c_surface* s0, c_surface* s1, int x0, int x1 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) = m_gfx_op->draw_pixel; for (int y = y0; y <= y1; y++) @@ -761,16 +748,16 @@ inline int c_display::swipe_surface(c_surface* s0, c_surface* s1, int x0, int x1 //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) = m_gfx_op->draw_pixel; for (int y = y0; y <= y1; y++) @@ -778,12 +765,12 @@ inline int c_display::swipe_surface(c_surface* s0, c_surface* s1, int x0, int x1 //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]); } } } diff --git a/HelloAnimation/UIcode/GuiLite.h b/HelloAnimation/UIcode/GuiLite.h index d77aa29..1b4611b 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 { @@ -419,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_display->m_phy_fb) { - return (m_color_bytes == 4) ? ((unsigned int*)m_display->m_phy_fb)[y * m_width + x] : GL_RGB_16_to_32(((unsigned short*)m_display->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; } @@ -454,13 +441,13 @@ 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; } } @@ -503,13 +490,13 @@ 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; } } } @@ -613,7 +600,7 @@ 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]); + 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); } } @@ -753,7 +740,7 @@ inline int c_display::swipe_surface(c_surface* s0, c_surface* s1, int x0, int x1 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) = m_gfx_op->draw_pixel; for (int y = y0; y <= y1; y++) @@ -761,16 +748,16 @@ inline int c_display::swipe_surface(c_surface* s0, c_surface* s1, int x0, int x1 //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) = m_gfx_op->draw_pixel; for (int y = y0; y <= y1; y++) @@ -778,12 +765,12 @@ inline int c_display::swipe_surface(c_surface* s0, c_surface* s1, int x0, int x1 //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]); } } } diff --git a/HelloCircle/UIcode/GuiLite.h b/HelloCircle/UIcode/GuiLite.h index d77aa29..1b4611b 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 { @@ -419,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_display->m_phy_fb) { - return (m_color_bytes == 4) ? ((unsigned int*)m_display->m_phy_fb)[y * m_width + x] : GL_RGB_16_to_32(((unsigned short*)m_display->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; } @@ -454,13 +441,13 @@ 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; } } @@ -503,13 +490,13 @@ 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; } } } @@ -613,7 +600,7 @@ 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]); + 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); } } @@ -753,7 +740,7 @@ inline int c_display::swipe_surface(c_surface* s0, c_surface* s1, int x0, int x1 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) = m_gfx_op->draw_pixel; for (int y = y0; y <= y1; y++) @@ -761,16 +748,16 @@ inline int c_display::swipe_surface(c_surface* s0, c_surface* s1, int x0, int x1 //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) = m_gfx_op->draw_pixel; for (int y = y0; y <= y1; y++) @@ -778,12 +765,12 @@ inline int c_display::swipe_surface(c_surface* s0, c_surface* s1, int x0, int x1 //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]); } } } diff --git a/HelloFFmpeg/UIcode/GuiLite.h b/HelloFFmpeg/UIcode/GuiLite.h index d77aa29..1b4611b 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 { @@ -419,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_display->m_phy_fb) { - return (m_color_bytes == 4) ? ((unsigned int*)m_display->m_phy_fb)[y * m_width + x] : GL_RGB_16_to_32(((unsigned short*)m_display->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; } @@ -454,13 +441,13 @@ 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; } } @@ -503,13 +490,13 @@ 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; } } } @@ -613,7 +600,7 @@ 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]); + 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); } } @@ -753,7 +740,7 @@ inline int c_display::swipe_surface(c_surface* s0, c_surface* s1, int x0, int x1 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) = m_gfx_op->draw_pixel; for (int y = y0; y <= y1; y++) @@ -761,16 +748,16 @@ inline int c_display::swipe_surface(c_surface* s0, c_surface* s1, int x0, int x1 //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) = m_gfx_op->draw_pixel; for (int y = y0; y <= y1; y++) @@ -778,12 +765,12 @@ inline int c_display::swipe_surface(c_surface* s0, c_surface* s1, int x0, int x1 //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]); } } } diff --git a/HelloFont/UIcode/GuiLite.h b/HelloFont/UIcode/GuiLite.h index d77aa29..1b4611b 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 { @@ -419,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_display->m_phy_fb) { - return (m_color_bytes == 4) ? ((unsigned int*)m_display->m_phy_fb)[y * m_width + x] : GL_RGB_16_to_32(((unsigned short*)m_display->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; } @@ -454,13 +441,13 @@ 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; } } @@ -503,13 +490,13 @@ 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; } } } @@ -613,7 +600,7 @@ 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]); + 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); } } @@ -753,7 +740,7 @@ inline int c_display::swipe_surface(c_surface* s0, c_surface* s1, int x0, int x1 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) = m_gfx_op->draw_pixel; for (int y = y0; y <= y1; y++) @@ -761,16 +748,16 @@ inline int c_display::swipe_surface(c_surface* s0, c_surface* s1, int x0, int x1 //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) = m_gfx_op->draw_pixel; for (int y = y0; y <= y1; y++) @@ -778,12 +765,12 @@ inline int c_display::swipe_surface(c_surface* s0, c_surface* s1, int x0, int x1 //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]); } } } diff --git a/HelloFreetype/UIcode/GuiLite.h b/HelloFreetype/UIcode/GuiLite.h index d77aa29..1b4611b 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 { @@ -419,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_display->m_phy_fb) { - return (m_color_bytes == 4) ? ((unsigned int*)m_display->m_phy_fb)[y * m_width + x] : GL_RGB_16_to_32(((unsigned short*)m_display->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; } @@ -454,13 +441,13 @@ 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; } } @@ -503,13 +490,13 @@ 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; } } } @@ -613,7 +600,7 @@ 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]); + 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); } } @@ -753,7 +740,7 @@ inline int c_display::swipe_surface(c_surface* s0, c_surface* s1, int x0, int x1 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) = m_gfx_op->draw_pixel; for (int y = y0; y <= y1; y++) @@ -761,16 +748,16 @@ inline int c_display::swipe_surface(c_surface* s0, c_surface* s1, int x0, int x1 //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) = m_gfx_op->draw_pixel; for (int y = y0; y <= y1; y++) @@ -778,12 +765,12 @@ inline int c_display::swipe_surface(c_surface* s0, c_surface* s1, int x0, int x1 //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]); } } } diff --git a/HelloJPG/UIcode/GuiLite.h b/HelloJPG/UIcode/GuiLite.h index d77aa29..1b4611b 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 { @@ -419,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_display->m_phy_fb) { - return (m_color_bytes == 4) ? ((unsigned int*)m_display->m_phy_fb)[y * m_width + x] : GL_RGB_16_to_32(((unsigned short*)m_display->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; } @@ -454,13 +441,13 @@ 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; } } @@ -503,13 +490,13 @@ 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; } } } @@ -613,7 +600,7 @@ 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]); + 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); } } @@ -753,7 +740,7 @@ inline int c_display::swipe_surface(c_surface* s0, c_surface* s1, int x0, int x1 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) = m_gfx_op->draw_pixel; for (int y = y0; y <= y1; y++) @@ -761,16 +748,16 @@ inline int c_display::swipe_surface(c_surface* s0, c_surface* s1, int x0, int x1 //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) = m_gfx_op->draw_pixel; for (int y = y0; y <= y1; y++) @@ -778,12 +765,12 @@ inline int c_display::swipe_surface(c_surface* s0, c_surface* s1, int x0, int x1 //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]); } } } diff --git a/HelloJPG/UIcode/UIcode.cpp b/HelloJPG/UIcode/UIcode.cpp index f36ad96..405afa3 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/UIcode/GuiLite.h b/HelloLayers/UIcode/GuiLite.h index d77aa29..1b4611b 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 { @@ -419,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_display->m_phy_fb) { - return (m_color_bytes == 4) ? ((unsigned int*)m_display->m_phy_fb)[y * m_width + x] : GL_RGB_16_to_32(((unsigned short*)m_display->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; } @@ -454,13 +441,13 @@ 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; } } @@ -503,13 +490,13 @@ 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; } } } @@ -613,7 +600,7 @@ 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]); + 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); } } @@ -753,7 +740,7 @@ inline int c_display::swipe_surface(c_surface* s0, c_surface* s1, int x0, int x1 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) = m_gfx_op->draw_pixel; for (int y = y0; y <= y1; y++) @@ -761,16 +748,16 @@ inline int c_display::swipe_surface(c_surface* s0, c_surface* s1, int x0, int x1 //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) = m_gfx_op->draw_pixel; for (int y = y0; y <= y1; y++) @@ -778,12 +765,12 @@ inline int c_display::swipe_surface(c_surface* s0, c_surface* s1, int x0, int x1 //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]); } } } diff --git a/HelloMario/UIcode/GuiLite.h b/HelloMario/UIcode/GuiLite.h index d77aa29..1b4611b 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 { @@ -419,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_display->m_phy_fb) { - return (m_color_bytes == 4) ? ((unsigned int*)m_display->m_phy_fb)[y * m_width + x] : GL_RGB_16_to_32(((unsigned short*)m_display->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; } @@ -454,13 +441,13 @@ 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; } } @@ -503,13 +490,13 @@ 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; } } } @@ -613,7 +600,7 @@ 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]); + 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); } } @@ -753,7 +740,7 @@ inline int c_display::swipe_surface(c_surface* s0, c_surface* s1, int x0, int x1 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) = m_gfx_op->draw_pixel; for (int y = y0; y <= y1; y++) @@ -761,16 +748,16 @@ inline int c_display::swipe_surface(c_surface* s0, c_surface* s1, int x0, int x1 //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) = m_gfx_op->draw_pixel; for (int y = y0; y <= y1; y++) @@ -778,12 +765,12 @@ inline int c_display::swipe_surface(c_surface* s0, c_surface* s1, int x0, int x1 //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]); } } } diff --git a/HelloMolecule/UIcode/GuiLite.h b/HelloMolecule/UIcode/GuiLite.h index d77aa29..1b4611b 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 { @@ -419,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_display->m_phy_fb) { - return (m_color_bytes == 4) ? ((unsigned int*)m_display->m_phy_fb)[y * m_width + x] : GL_RGB_16_to_32(((unsigned short*)m_display->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; } @@ -454,13 +441,13 @@ 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; } } @@ -503,13 +490,13 @@ 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; } } } @@ -613,7 +600,7 @@ 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]); + 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); } } @@ -753,7 +740,7 @@ inline int c_display::swipe_surface(c_surface* s0, c_surface* s1, int x0, int x1 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) = m_gfx_op->draw_pixel; for (int y = y0; y <= y1; y++) @@ -761,16 +748,16 @@ inline int c_display::swipe_surface(c_surface* s0, c_surface* s1, int x0, int x1 //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) = m_gfx_op->draw_pixel; for (int y = y0; y <= y1; y++) @@ -778,12 +765,12 @@ inline int c_display::swipe_surface(c_surface* s0, c_surface* s1, int x0, int x1 //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]); } } } diff --git a/HelloNets/UIcode/GuiLite.h b/HelloNets/UIcode/GuiLite.h index d77aa29..1b4611b 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 { @@ -419,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_display->m_phy_fb) { - return (m_color_bytes == 4) ? ((unsigned int*)m_display->m_phy_fb)[y * m_width + x] : GL_RGB_16_to_32(((unsigned short*)m_display->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; } @@ -454,13 +441,13 @@ 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; } } @@ -503,13 +490,13 @@ 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; } } } @@ -613,7 +600,7 @@ 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]); + 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); } } @@ -753,7 +740,7 @@ inline int c_display::swipe_surface(c_surface* s0, c_surface* s1, int x0, int x1 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) = m_gfx_op->draw_pixel; for (int y = y0; y <= y1; y++) @@ -761,16 +748,16 @@ inline int c_display::swipe_surface(c_surface* s0, c_surface* s1, int x0, int x1 //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) = m_gfx_op->draw_pixel; for (int y = y0; y <= y1; y++) @@ -778,12 +765,12 @@ inline int c_display::swipe_surface(c_surface* s0, c_surface* s1, int x0, int x1 //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]); } } } diff --git a/HelloNoTouch/UIcode/GuiLite.h b/HelloNoTouch/UIcode/GuiLite.h index d77aa29..1b4611b 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 { @@ -419,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_display->m_phy_fb) { - return (m_color_bytes == 4) ? ((unsigned int*)m_display->m_phy_fb)[y * m_width + x] : GL_RGB_16_to_32(((unsigned short*)m_display->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; } @@ -454,13 +441,13 @@ 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; } } @@ -503,13 +490,13 @@ 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; } } } @@ -613,7 +600,7 @@ 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]); + 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); } } @@ -753,7 +740,7 @@ inline int c_display::swipe_surface(c_surface* s0, c_surface* s1, int x0, int x1 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) = m_gfx_op->draw_pixel; for (int y = y0; y <= y1; y++) @@ -761,16 +748,16 @@ inline int c_display::swipe_surface(c_surface* s0, c_surface* s1, int x0, int x1 //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) = m_gfx_op->draw_pixel; for (int y = y0; y <= y1; y++) @@ -778,12 +765,12 @@ inline int c_display::swipe_surface(c_surface* s0, c_surface* s1, int x0, int x1 //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]); } } } diff --git a/HelloParticle/UIcode/GuiLite.h b/HelloParticle/UIcode/GuiLite.h index d77aa29..1b4611b 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 { @@ -419,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_display->m_phy_fb) { - return (m_color_bytes == 4) ? ((unsigned int*)m_display->m_phy_fb)[y * m_width + x] : GL_RGB_16_to_32(((unsigned short*)m_display->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; } @@ -454,13 +441,13 @@ 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; } } @@ -503,13 +490,13 @@ 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; } } } @@ -613,7 +600,7 @@ 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]); + 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); } } @@ -753,7 +740,7 @@ inline int c_display::swipe_surface(c_surface* s0, c_surface* s1, int x0, int x1 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) = m_gfx_op->draw_pixel; for (int y = y0; y <= y1; y++) @@ -761,16 +748,16 @@ inline int c_display::swipe_surface(c_surface* s0, c_surface* s1, int x0, int x1 //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) = m_gfx_op->draw_pixel; for (int y = y0; y <= y1; y++) @@ -778,12 +765,12 @@ inline int c_display::swipe_surface(c_surface* s0, c_surface* s1, int x0, int x1 //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]); } } } diff --git a/HelloPendulum/UIcode/GuiLite.h b/HelloPendulum/UIcode/GuiLite.h index d77aa29..1b4611b 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 { @@ -419,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_display->m_phy_fb) { - return (m_color_bytes == 4) ? ((unsigned int*)m_display->m_phy_fb)[y * m_width + x] : GL_RGB_16_to_32(((unsigned short*)m_display->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; } @@ -454,13 +441,13 @@ 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; } } @@ -503,13 +490,13 @@ 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; } } } @@ -613,7 +600,7 @@ 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]); + 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); } } @@ -753,7 +740,7 @@ inline int c_display::swipe_surface(c_surface* s0, c_surface* s1, int x0, int x1 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) = m_gfx_op->draw_pixel; for (int y = y0; y <= y1; y++) @@ -761,16 +748,16 @@ inline int c_display::swipe_surface(c_surface* s0, c_surface* s1, int x0, int x1 //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) = m_gfx_op->draw_pixel; for (int y = y0; y <= y1; y++) @@ -778,12 +765,12 @@ inline int c_display::swipe_surface(c_surface* s0, c_surface* s1, int x0, int x1 //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]); } } } diff --git a/HelloScroll/UIcode/GuiLite.h b/HelloScroll/UIcode/GuiLite.h index d77aa29..1b4611b 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 { @@ -419,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_display->m_phy_fb) { - return (m_color_bytes == 4) ? ((unsigned int*)m_display->m_phy_fb)[y * m_width + x] : GL_RGB_16_to_32(((unsigned short*)m_display->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; } @@ -454,13 +441,13 @@ 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; } } @@ -503,13 +490,13 @@ 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; } } } @@ -613,7 +600,7 @@ 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]); + 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); } } @@ -753,7 +740,7 @@ inline int c_display::swipe_surface(c_surface* s0, c_surface* s1, int x0, int x1 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) = m_gfx_op->draw_pixel; for (int y = y0; y <= y1; y++) @@ -761,16 +748,16 @@ inline int c_display::swipe_surface(c_surface* s0, c_surface* s1, int x0, int x1 //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) = m_gfx_op->draw_pixel; for (int y = y0; y <= y1; y++) @@ -778,12 +765,12 @@ inline int c_display::swipe_surface(c_surface* s0, c_surface* s1, int x0, int x1 //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]); } } } diff --git a/HelloSlide/UIcode/GuiLite.h b/HelloSlide/UIcode/GuiLite.h index d77aa29..1b4611b 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 { @@ -419,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_display->m_phy_fb) { - return (m_color_bytes == 4) ? ((unsigned int*)m_display->m_phy_fb)[y * m_width + x] : GL_RGB_16_to_32(((unsigned short*)m_display->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; } @@ -454,13 +441,13 @@ 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; } } @@ -503,13 +490,13 @@ 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; } } } @@ -613,7 +600,7 @@ 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]); + 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); } } @@ -753,7 +740,7 @@ inline int c_display::swipe_surface(c_surface* s0, c_surface* s1, int x0, int x1 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) = m_gfx_op->draw_pixel; for (int y = y0; y <= y1; y++) @@ -761,16 +748,16 @@ inline int c_display::swipe_surface(c_surface* s0, c_surface* s1, int x0, int x1 //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) = m_gfx_op->draw_pixel; for (int y = y0; y <= y1; y++) @@ -778,12 +765,12 @@ inline int c_display::swipe_surface(c_surface* s0, c_surface* s1, int x0, int x1 //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]); } } } diff --git a/HelloStar/UIcode/GuiLite.h b/HelloStar/UIcode/GuiLite.h index d77aa29..1b4611b 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 { @@ -419,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_display->m_phy_fb) { - return (m_color_bytes == 4) ? ((unsigned int*)m_display->m_phy_fb)[y * m_width + x] : GL_RGB_16_to_32(((unsigned short*)m_display->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; } @@ -454,13 +441,13 @@ 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; } } @@ -503,13 +490,13 @@ 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; } } } @@ -613,7 +600,7 @@ 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]); + 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); } } @@ -753,7 +740,7 @@ inline int c_display::swipe_surface(c_surface* s0, c_surface* s1, int x0, int x1 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) = m_gfx_op->draw_pixel; for (int y = y0; y <= y1; y++) @@ -761,16 +748,16 @@ inline int c_display::swipe_surface(c_surface* s0, c_surface* s1, int x0, int x1 //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) = m_gfx_op->draw_pixel; for (int y = y0; y <= y1; y++) @@ -778,12 +765,12 @@ inline int c_display::swipe_surface(c_surface* s0, c_surface* s1, int x0, int x1 //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]); } } } diff --git a/HelloTimer/UIcode/GuiLite.h b/HelloTimer/UIcode/GuiLite.h index d77aa29..1b4611b 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 { @@ -419,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_display->m_phy_fb) { - return (m_color_bytes == 4) ? ((unsigned int*)m_display->m_phy_fb)[y * m_width + x] : GL_RGB_16_to_32(((unsigned short*)m_display->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; } @@ -454,13 +441,13 @@ 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; } } @@ -503,13 +490,13 @@ 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; } } } @@ -613,7 +600,7 @@ 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]); + 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); } } @@ -753,7 +740,7 @@ inline int c_display::swipe_surface(c_surface* s0, c_surface* s1, int x0, int x1 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) = m_gfx_op->draw_pixel; for (int y = y0; y <= y1; y++) @@ -761,16 +748,16 @@ inline int c_display::swipe_surface(c_surface* s0, c_surface* s1, int x0, int x1 //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) = m_gfx_op->draw_pixel; for (int y = y0; y <= y1; y++) @@ -778,12 +765,12 @@ inline int c_display::swipe_surface(c_surface* s0, c_surface* s1, int x0, int x1 //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]); } } } diff --git a/HelloTransparent/UIcode/GuiLite.h b/HelloTransparent/UIcode/GuiLite.h index d77aa29..1b4611b 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 { @@ -419,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_display->m_phy_fb) { - return (m_color_bytes == 4) ? ((unsigned int*)m_display->m_phy_fb)[y * m_width + x] : GL_RGB_16_to_32(((unsigned short*)m_display->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; } @@ -454,13 +441,13 @@ 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; } } @@ -503,13 +490,13 @@ 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; } } } @@ -613,7 +600,7 @@ 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]); + 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); } } @@ -753,7 +740,7 @@ inline int c_display::swipe_surface(c_surface* s0, c_surface* s1, int x0, int x1 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) = m_gfx_op->draw_pixel; for (int y = y0; y <= y1; y++) @@ -761,16 +748,16 @@ inline int c_display::swipe_surface(c_surface* s0, c_surface* s1, int x0, int x1 //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) = m_gfx_op->draw_pixel; for (int y = y0; y <= y1; y++) @@ -778,12 +765,12 @@ inline int c_display::swipe_surface(c_surface* s0, c_surface* s1, int x0, int x1 //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]); } } } diff --git a/HelloWave/UIcode/GuiLite.h b/HelloWave/UIcode/GuiLite.h index d77aa29..1b4611b 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 { @@ -419,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_display->m_phy_fb) { - return (m_color_bytes == 4) ? ((unsigned int*)m_display->m_phy_fb)[y * m_width + x] : GL_RGB_16_to_32(((unsigned short*)m_display->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; } @@ -454,13 +441,13 @@ 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; } } @@ -503,13 +490,13 @@ 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; } } } @@ -613,7 +600,7 @@ 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]); + 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); } } @@ -753,7 +740,7 @@ inline int c_display::swipe_surface(c_surface* s0, c_surface* s1, int x0, int x1 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) = m_gfx_op->draw_pixel; for (int y = y0; y <= y1; y++) @@ -761,16 +748,16 @@ inline int c_display::swipe_surface(c_surface* s0, c_surface* s1, int x0, int x1 //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) = m_gfx_op->draw_pixel; for (int y = y0; y <= y1; y++) @@ -778,12 +765,12 @@ inline int c_display::swipe_surface(c_surface* s0, c_surface* s1, int x0, int x1 //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]); } } } diff --git a/HelloWidgets/UIcode/GuiLite.h b/HelloWidgets/UIcode/GuiLite.h index d77aa29..1b4611b 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 { @@ -419,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_display->m_phy_fb) { - return (m_color_bytes == 4) ? ((unsigned int*)m_display->m_phy_fb)[y * m_width + x] : GL_RGB_16_to_32(((unsigned short*)m_display->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; } @@ -454,13 +441,13 @@ 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; } } @@ -503,13 +490,13 @@ 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; } } } @@ -613,7 +600,7 @@ 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]); + 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); } } @@ -753,7 +740,7 @@ inline int c_display::swipe_surface(c_surface* s0, c_surface* s1, int x0, int x1 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) = m_gfx_op->draw_pixel; for (int y = y0; y <= y1; y++) @@ -761,16 +748,16 @@ inline int c_display::swipe_surface(c_surface* s0, c_surface* s1, int x0, int x1 //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) = m_gfx_op->draw_pixel; for (int y = y0; y <= y1; y++) @@ -778,12 +765,12 @@ inline int c_display::swipe_surface(c_surface* s0, c_surface* s1, int x0, int x1 //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]); } } } diff --git a/HelloWindows/UIcode/GuiLite.h b/HelloWindows/UIcode/GuiLite.h index d77aa29..1b4611b 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 { @@ -419,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_display->m_phy_fb) { - return (m_color_bytes == 4) ? ((unsigned int*)m_display->m_phy_fb)[y * m_width + x] : GL_RGB_16_to_32(((unsigned short*)m_display->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; } @@ -454,13 +441,13 @@ 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; } } @@ -503,13 +490,13 @@ 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; } } } @@ -613,7 +600,7 @@ 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]); + 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); } } @@ -753,7 +740,7 @@ inline int c_display::swipe_surface(c_surface* s0, c_surface* s1, int x0, int x1 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) = m_gfx_op->draw_pixel; for (int y = y0; y <= y1; y++) @@ -761,16 +748,16 @@ inline int c_display::swipe_surface(c_surface* s0, c_surface* s1, int x0, int x1 //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) = m_gfx_op->draw_pixel; for (int y = y0; y <= y1; y++) @@ -778,12 +765,12 @@ inline int c_display::swipe_surface(c_surface* s0, c_surface* s1, int x0, int x1 //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]); } } } diff --git a/HostMonitor/BuildLinux/.sync_data.sh b/HostMonitor/BuildLinux/.sync_data.sh index 4ec3997..d3d934e 100644 --- a/HostMonitor/BuildLinux/.sync_data.sh +++ b/HostMonitor/BuildLinux/.sync_data.sh @@ -1,6 +1,6 @@ if [ "$#" -ne 6 ]; then echo "Do testing" - ./xWindow 1024 768 | ./HelloAnimation shared-fb + ./xWindow 1024 768 | ./HostMonitor shared-fb exit -1 fi diff --git a/HostMonitor/UIcode/include/GuiLite.h b/HostMonitor/UIcode/include/GuiLite.h index d77aa29..1b4611b 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 { @@ -419,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_display->m_phy_fb) { - return (m_color_bytes == 4) ? ((unsigned int*)m_display->m_phy_fb)[y * m_width + x] : GL_RGB_16_to_32(((unsigned short*)m_display->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; } @@ -454,13 +441,13 @@ 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; } } @@ -503,13 +490,13 @@ 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; } } } @@ -613,7 +600,7 @@ 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]); + 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); } } @@ -753,7 +740,7 @@ inline int c_display::swipe_surface(c_surface* s0, c_surface* s1, int x0, int x1 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) = m_gfx_op->draw_pixel; for (int y = y0; y <= y1; y++) @@ -761,16 +748,16 @@ inline int c_display::swipe_surface(c_surface* s0, c_surface* s1, int x0, int x1 //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) = m_gfx_op->draw_pixel; for (int y = y0; y <= y1; y++) @@ -778,12 +765,12 @@ inline int c_display::swipe_surface(c_surface* s0, c_surface* s1, int x0, int x1 //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]); } } } -- Gitee From bc53cd951bfe7a425bf8c18d63eebc1a5b1e8460 Mon Sep 17 00:00:00 2001 From: idea4good Date: Wed, 25 May 2022 14:35:06 +0800 Subject: [PATCH 4/4] rename EXTERNAL_GFX_OP to DISPLAY_DRIVER --- ...llo3D WatchKit Extension-Bridging-Header.h | 2 +- Hello3D/BuildLinux/main.cpp | 2 +- Hello3D/BuildMFC/Hello3DDlg.cpp | Bin 9704 -> 9702 bytes Hello3D/BuildMFC/Hello3DDlg.h | Bin 2674 -> 2672 bytes Hello3D/BuildQt/mainwindow.cpp | 2 +- Hello3D/BuildSTM32F103-Keil/USER/main.c | 12 +++---- Hello3D/BuildWin32/Hello3D.cpp | 2 +- Hello3D/UIcode/GuiLite.h | 32 +++++++++--------- Hello3D/UIcode/UIcode.cpp | 8 ++--- Hello3Ddonut/BuildLinux/main.cpp | 2 +- Hello3Ddonut/BuildMFC/Hello3DdonutDlg.cpp | Bin 9974 -> 9972 bytes Hello3Ddonut/BuildMFC/Hello3DdonutDlg.h | Bin 2754 -> 2752 bytes Hello3Ddonut/BuildSTM32F103-Keil/USER/main.c | 12 +++---- Hello3Ddonut/BuildWin32/Hello3Ddonut.cpp | 2 +- Hello3Ddonut/UIcode/GuiLite.h | 32 +++++++++--------- Hello3Ddonut/UIcode/UIcode.cpp | 8 ++--- ...llo3D WatchKit Extension-Bridging-Header.h | 2 +- Hello3Dwave/BuildLinux/main.cpp | 2 +- Hello3Dwave/BuildMFC/Hello3DwaveDlg.cpp | Bin 9920 -> 9918 bytes Hello3Dwave/BuildMFC/Hello3DwaveDlg.h | Bin 2738 -> 2736 bytes Hello3Dwave/BuildQt/mainwindow.cpp | 2 +- Hello3Dwave/BuildSTM32F103-Keil/USER/main.c | 12 +++---- Hello3Dwave/BuildWin32/Hello3Dwave.cpp | 2 +- Hello3Dwave/UIcode/GuiLite.h | 32 +++++++++--------- Hello3Dwave/UIcode/UIcode.cpp | 8 ++--- HelloAnimation/UIcode/GuiLite.h | 32 +++++++++--------- ...ircle WatchKit Extension-Bridging-Header.h | 2 +- HelloCircle/BuildLinux/main.cpp | 2 +- HelloCircle/BuildMFC/HelloCircleDlg.cpp | Bin 9920 -> 9918 bytes HelloCircle/BuildMFC/HelloCircleDlg.h | Bin 2734 -> 2732 bytes HelloCircle/BuildQt/mainwindow.cpp | 2 +- HelloCircle/BuildSTM32F103-Keil/USER/main.c | 12 +++---- HelloCircle/BuildWin32/HelloCircle.cpp | 2 +- HelloCircle/UIcode/GuiLite.h | 32 +++++++++--------- HelloCircle/UIcode/UIcode.cpp | 8 ++--- HelloFFmpeg/UIcode/GuiLite.h | 32 +++++++++--------- HelloFont/UIcode/GuiLite.h | 32 +++++++++--------- HelloFreetype/UIcode/GuiLite.h | 32 +++++++++--------- HelloJPG/UIcode/GuiLite.h | 32 +++++++++--------- HelloLayers/BuildLinux/main.cpp | 2 +- HelloLayers/BuildMFC/HelloLayersDlg.cpp | Bin 9920 -> 9918 bytes HelloLayers/BuildMFC/HelloLayersDlg.h | Bin 2738 -> 2736 bytes HelloLayers/BuildSTM32F103-Keil/USER/main.c | 12 +++---- HelloLayers/BuildWin32/HelloLayers.cpp | 2 +- HelloLayers/UIcode/GuiLite.h | 32 +++++++++--------- HelloLayers/UIcode/UIcode.cpp | 10 +++--- HelloMario/BuildLinux/main.cpp | 2 +- HelloMario/BuildMFC/HelloMarioDlg.cpp | Bin 9960 -> 9958 bytes HelloMario/BuildMFC/HelloMarioDlg.h | Bin 2834 -> 2832 bytes HelloMario/BuildSTM32F103-Keil/USER/main.c | 12 +++---- HelloMario/BuildWin32/HelloMario.cpp | 2 +- HelloMario/UIcode/GuiLite.h | 32 +++++++++--------- HelloMario/UIcode/UIcode.cpp | 8 ++--- HelloMolecule/BuildLinux/main.cpp | 2 +- HelloMolecule/BuildMFC/HelloMoleculeDlg.cpp | Bin 14600 -> 14598 bytes HelloMolecule/BuildMFC/HelloMoleculeDlg.h | Bin 3646 -> 3644 bytes HelloMolecule/BuildSTM32F103-Keil/USER/main.c | 12 +++---- HelloMolecule/BuildWin32/HelloMolecule.cpp | 2 +- HelloMolecule/UIcode/GuiLite.h | 32 +++++++++--------- HelloMolecule/UIcode/UIcode.cpp | 8 ++--- HelloNets/BuildMFC/HelloNetsDlg.cpp | Bin 15156 -> 15154 bytes HelloNets/BuildMFC/HelloNetsDlg.h | Bin 3676 -> 3674 bytes HelloNets/BuildSTM32F103-Keil/USER/main.c | 12 +++---- HelloNets/BuildWin32/HelloNets.cpp | 2 +- HelloNets/UIcode/GuiLite.h | 32 +++++++++--------- HelloNets/UIcode/UIcode.cpp | 8 ++--- HelloNoTouch/BuildLinux/main.cpp | 2 +- HelloNoTouch/BuildMFC/HelloNoTouchDlg.cpp | Bin 14672 -> 14670 bytes HelloNoTouch/BuildMFC/HelloNoTouchDlg.h | Bin 4014 -> 4012 bytes HelloNoTouch/BuildSTM32F103-Keil/USER/main.c | 12 +++---- HelloNoTouch/BuildWin32/HelloNoTouch.cpp | 2 +- HelloNoTouch/UIcode/GuiLite.h | 32 +++++++++--------- HelloNoTouch/UIcode/UIcode.cpp | 8 ++--- .../BuildIos/BuildIos/Bridging-Header.h | 2 +- HelloParticle/BuildLinux/main.cpp | 2 +- HelloParticle/BuildMFC/HelloParticleDlg.cpp | Bin 10028 -> 10026 bytes HelloParticle/BuildMFC/HelloParticleDlg.h | Bin 2770 -> 2768 bytes HelloParticle/BuildSTM32F103-Keil/USER/main.c | 12 +++---- HelloParticle/BuildWin32/HelloParticle.cpp | 2 +- HelloParticle/UIcode/GuiLite.h | 32 +++++++++--------- HelloParticle/UIcode/UIcode.cpp | 8 ++--- HelloPendulum/BuildLinux/main.cpp | 2 +- HelloPendulum/BuildMFC/HelloPendulumDlg.cpp | Bin 10280 -> 10278 bytes HelloPendulum/BuildMFC/HelloPendulumDlg.h | Bin 3016 -> 3014 bytes HelloPendulum/BuildSTM32F103-Keil/USER/main.c | 12 +++---- HelloPendulum/BuildWin32/HelloPendulum.cpp | 2 +- HelloPendulum/UIcode/GuiLite.h | 32 +++++++++--------- HelloPendulum/UIcode/UIcode.cpp | 8 ++--- HelloScroll/UIcode/GuiLite.h | 32 +++++++++--------- HelloScroll/UIcode/scroll.h | 2 +- HelloSlide/UIcode/GuiLite.h | 32 +++++++++--------- HelloStar/BuildLinux/main.cpp | 2 +- HelloStar/BuildMFC/HelloStarDlg.cpp | Bin 9812 -> 9810 bytes HelloStar/BuildMFC/HelloStarDlg.h | Bin 2706 -> 2704 bytes HelloStar/BuildSTM32F103-Keil/USER/main.c | 12 +++---- HelloStar/BuildWin32/HelloStar.cpp | 2 +- HelloStar/UIcode/GuiLite.h | 32 +++++++++--------- HelloStar/UIcode/UIcode.cpp | 8 ++--- HelloTimer/BuildLinux/main.cpp | 2 +- HelloTimer/BuildMFC/HelloTimerDlg.cpp | Bin 14402 -> 14400 bytes HelloTimer/BuildMFC/HelloTimerDlg.h | Bin 3592 -> 3590 bytes HelloTimer/BuildSTM32F103-Keil/USER/main.c | 12 +++---- HelloTimer/BuildWin32/HelloTimer.cpp | 2 +- HelloTimer/UIcode/GuiLite.h | 32 +++++++++--------- HelloTimer/UIcode/UIcode.cpp | 8 ++--- HelloTransparent/UIcode/GuiLite.h | 32 +++++++++--------- ...ve watchOS App Extension-Bridging-Header.h | 2 +- HelloWave/BuildLinux/main.cpp | 2 +- HelloWave/BuildMFC/HelloWaveDlg.cpp | Bin 10002 -> 9996 bytes HelloWave/BuildMFC/HelloWaveDlg.h | Bin 2816 -> 2814 bytes HelloWave/BuildSTM32F103-Keil/USER/main.c | 12 +++---- HelloWave/BuildWin32/HelloWave.cpp | 2 +- HelloWave/UIcode/GuiLite.h | 32 +++++++++--------- HelloWave/UIcode/UIcode.cpp | 8 ++--- HelloWidgets/UIcode/GuiLite.h | 32 +++++++++--------- HelloWindows/UIcode/GuiLite.h | 32 +++++++++--------- HostMonitor/UIcode/include/GuiLite.h | 32 +++++++++--------- 117 files changed, 577 insertions(+), 577 deletions(-) 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 287af9a..2aafa7a 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/main.cpp b/Hello3D/BuildLinux/main.cpp index b3d6e03..c4a0667 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 GIT binary patch delta 114 zcmaFi{mgsA0qMylDgxXt3_%Q@3}Fne3_+XkN;5O^rZ5ySWHOX7qylN{$?pX83u ue1-xB>&fp0H8+dMZers`5}tff*%pN_sj`$GNuEIys4-Dcc=H1lHbww<6&|Ai diff --git a/Hello3D/BuildMFC/Hello3DDlg.h b/Hello3D/BuildMFC/Hello3DDlg.h index 4335d37b77c06b71411c6f462cc5d36d9832adbf..c4b506ed251173ac0945d7c4e2f5c2ded20326f1 100644 GIT binary patch delta 56 zcmew)@ #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 e9fabd0..8fc07d9 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 7a4cdd3..668cffc 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 1b4611b..80550e1 100644 --- a/Hello3D/UIcode/GuiLite.h +++ b/Hello3D/UIcode/GuiLite.h @@ -225,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); @@ -234,8 +234,8 @@ class c_surface; class c_display { friend class c_surface; public: - inline c_display(void* phy_fb, int display_width, int display_height, c_surface* surface, EXTERNAL_GFX_OP* gfx_op = 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, EXTERNAL_GFX_OP* gfx_op = 0);//multiple surface + 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; } @@ -286,9 +286,9 @@ protected: virtual void draw_pixel(int x, int y, unsigned int rgb) { if ((x >= m_width) || (y >= m_height)) { return; } - if (m_gfx_op && m_gfx_op->draw_pixel) + if (m_driver && m_driver->draw_pixel) { - return m_gfx_op->draw_pixel(x, y, rgb); + return m_driver->draw_pixel(x, y, rgb); } if (m_color_bytes == 2) { @@ -301,17 +301,17 @@ protected: } virtual void fill_rect(int x0, int y0, int x1, int y1, unsigned int rgb) { - if (m_gfx_op && m_gfx_op->fill_rect) + if (m_driver && m_driver->fill_rect) { - return m_gfx_op->fill_rect(x0, y0, x1, y1, rgb); + return m_driver->fill_rect(x0, y0, x1, y1, rgb); } - if (m_gfx_op && m_gfx_op->draw_pixel) + if (m_driver && m_driver->draw_pixel) { for (int y = y0; y <= y1; y++) { for (int x = x0; x <= x1; x++) { - m_gfx_op->draw_pixel(x, y, rgb); + m_driver->draw_pixel(x, y, rgb); } } return; @@ -373,9 +373,9 @@ protected: } 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 - struct EXTERNAL_GFX_OP* m_gfx_op; //Rendering by external method + 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]; @@ -682,13 +682,13 @@ protected: int* m_phy_write_index; c_display* m_display; }; -inline c_display::c_display(void* phy_fb, int display_width, int display_height, c_surface* surface, EXTERNAL_GFX_OP* gfx_op) : m_phy_fb(phy_fb), m_width(display_width), m_height(display_height), m_gfx_op(gfx_op), m_phy_read_index(0), m_phy_write_index(0), m_surface_cnt(1), 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, EXTERNAL_GFX_OP* gfx_op) : 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_gfx_op(gfx_op), m_surface_index(0) +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); @@ -742,7 +742,7 @@ inline int c_display::swipe_surface(c_surface* s0, c_surface* s1, int x0, int x1 } else if (m_color_bytes == 2) { - void(*draw_pixel)(int x, int y, unsigned int rgb) = 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 @@ -759,7 +759,7 @@ inline int c_display::swipe_surface(c_surface* s0, c_surface* s1, int x0, int x1 } else //m_color_bytes == 3/4... { - void(*draw_pixel)(int x, int y, unsigned int rgb) = 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 diff --git a/Hello3D/UIcode/UIcode.cpp b/Hello3D/UIcode/UIcode.cpp index fbda811..e383ce0 100644 --- a/Hello3D/UIcode/UIcode.cpp +++ b/Hello3D/UIcode/UIcode.cpp @@ -164,9 +164,9 @@ 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) { +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, gfx_op); + static c_display display(phy_fb, screen_width, screen_height, &surface, driver); s_surface = &surface; s_display = &display; @@ -186,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/main.cpp b/Hello3Ddonut/BuildLinux/main.cpp index b3c3da2..98b93e6 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 GIT binary patch delta 132 zcmez7`^9%dhm5ofgC|2ULjZ#hgCj#ELp*~ELl96TjKP&5X!BATW=7r=h9ZVchBAg! zAZyiq}TvYhHHeq>Qi2J6X;Lc*JGsY)>d06DN7kN^Mx diff --git a/Hello3Ddonut/BuildMFC/Hello3DdonutDlg.h b/Hello3Ddonut/BuildMFC/Hello3DdonutDlg.h index 61c1ce12cd9b173bc35bf7db6683e76944d819fa..11ab911df689ef994d98902066266b1c81a68ebf 100644 GIT binary patch delta 56 zcmX>kdO&o838S_PgC|2ULjZ#hgCj#ELp*~ELl96TjKLL1YcVJ=q%agQWHOX7q%st3 JPGn5v1OQGC3sV39 delta 58 zcmX>gdPsDG38StnLj*$zgDXQ2gCBz= m_width) || (y >= m_height)) { return; } - if (m_gfx_op && m_gfx_op->draw_pixel) + if (m_driver && m_driver->draw_pixel) { - return m_gfx_op->draw_pixel(x, y, rgb); + return m_driver->draw_pixel(x, y, rgb); } if (m_color_bytes == 2) { @@ -301,17 +301,17 @@ protected: } virtual void fill_rect(int x0, int y0, int x1, int y1, unsigned int rgb) { - if (m_gfx_op && m_gfx_op->fill_rect) + if (m_driver && m_driver->fill_rect) { - return m_gfx_op->fill_rect(x0, y0, x1, y1, rgb); + return m_driver->fill_rect(x0, y0, x1, y1, rgb); } - if (m_gfx_op && m_gfx_op->draw_pixel) + if (m_driver && m_driver->draw_pixel) { for (int y = y0; y <= y1; y++) { for (int x = x0; x <= x1; x++) { - m_gfx_op->draw_pixel(x, y, rgb); + m_driver->draw_pixel(x, y, rgb); } } return; @@ -373,9 +373,9 @@ protected: } 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 - struct EXTERNAL_GFX_OP* m_gfx_op; //Rendering by external method + 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]; @@ -682,13 +682,13 @@ protected: int* m_phy_write_index; c_display* m_display; }; -inline c_display::c_display(void* phy_fb, int display_width, int display_height, c_surface* surface, EXTERNAL_GFX_OP* gfx_op) : m_phy_fb(phy_fb), m_width(display_width), m_height(display_height), m_gfx_op(gfx_op), m_phy_read_index(0), m_phy_write_index(0), m_surface_cnt(1), 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, EXTERNAL_GFX_OP* gfx_op) : 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_gfx_op(gfx_op), m_surface_index(0) +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); @@ -742,7 +742,7 @@ inline int c_display::swipe_surface(c_surface* s0, c_surface* s1, int x0, int x1 } else if (m_color_bytes == 2) { - void(*draw_pixel)(int x, int y, unsigned int rgb) = 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 @@ -759,7 +759,7 @@ inline int c_display::swipe_surface(c_surface* s0, c_surface* s1, int x0, int x1 } else //m_color_bytes == 3/4... { - void(*draw_pixel)(int x, int y, unsigned int rgb) = 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 diff --git a/Hello3Ddonut/UIcode/UIcode.cpp b/Hello3Ddonut/UIcode/UIcode.cpp index 99c2017..0cfc39b 100644 --- a/Hello3Ddonut/UIcode/UIcode.cpp +++ b/Hello3Ddonut/UIcode/UIcode.cpp @@ -65,9 +65,9 @@ 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) { +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, gfx_op); + static c_display display(phy_fb, screen_width, screen_height, &surface, driver); s_surface = &surface; s_display = &display; @@ -82,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 9466e22..505e86a 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/main.cpp b/Hello3Dwave/BuildLinux/main.cpp index 3ed4e7d..38192fe 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 GIT binary patch delta 126 zcmX@$yU%w+f{e5agC|2ULjZ#hgCj#ELp*~ELl96TjKP&5XmhO$Gb3*bLlHwJLm5LV zkhY$@QPptsKG{=jD8hP^C(4LUUZtYOjih+;ZI!kBNPGrOp!SD?!kbsAiZKEJ$oe2= delta 114 zcmdnzd%$-?f{d&yLj*$zgDXQ2gCBz #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 cc71450..4afd3b5 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 46e180d..4e46268 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 1b4611b..80550e1 100644 --- a/Hello3Dwave/UIcode/GuiLite.h +++ b/Hello3Dwave/UIcode/GuiLite.h @@ -225,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); @@ -234,8 +234,8 @@ class c_surface; class c_display { friend class c_surface; public: - inline c_display(void* phy_fb, int display_width, int display_height, c_surface* surface, EXTERNAL_GFX_OP* gfx_op = 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, EXTERNAL_GFX_OP* gfx_op = 0);//multiple surface + 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; } @@ -286,9 +286,9 @@ protected: virtual void draw_pixel(int x, int y, unsigned int rgb) { if ((x >= m_width) || (y >= m_height)) { return; } - if (m_gfx_op && m_gfx_op->draw_pixel) + if (m_driver && m_driver->draw_pixel) { - return m_gfx_op->draw_pixel(x, y, rgb); + return m_driver->draw_pixel(x, y, rgb); } if (m_color_bytes == 2) { @@ -301,17 +301,17 @@ protected: } virtual void fill_rect(int x0, int y0, int x1, int y1, unsigned int rgb) { - if (m_gfx_op && m_gfx_op->fill_rect) + if (m_driver && m_driver->fill_rect) { - return m_gfx_op->fill_rect(x0, y0, x1, y1, rgb); + return m_driver->fill_rect(x0, y0, x1, y1, rgb); } - if (m_gfx_op && m_gfx_op->draw_pixel) + if (m_driver && m_driver->draw_pixel) { for (int y = y0; y <= y1; y++) { for (int x = x0; x <= x1; x++) { - m_gfx_op->draw_pixel(x, y, rgb); + m_driver->draw_pixel(x, y, rgb); } } return; @@ -373,9 +373,9 @@ protected: } 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 - struct EXTERNAL_GFX_OP* m_gfx_op; //Rendering by external method + 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]; @@ -682,13 +682,13 @@ protected: int* m_phy_write_index; c_display* m_display; }; -inline c_display::c_display(void* phy_fb, int display_width, int display_height, c_surface* surface, EXTERNAL_GFX_OP* gfx_op) : m_phy_fb(phy_fb), m_width(display_width), m_height(display_height), m_gfx_op(gfx_op), m_phy_read_index(0), m_phy_write_index(0), m_surface_cnt(1), 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, EXTERNAL_GFX_OP* gfx_op) : 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_gfx_op(gfx_op), m_surface_index(0) +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); @@ -742,7 +742,7 @@ inline int c_display::swipe_surface(c_surface* s0, c_surface* s1, int x0, int x1 } else if (m_color_bytes == 2) { - void(*draw_pixel)(int x, int y, unsigned int rgb) = 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 @@ -759,7 +759,7 @@ inline int c_display::swipe_surface(c_surface* s0, c_surface* s1, int x0, int x1 } else //m_color_bytes == 3/4... { - void(*draw_pixel)(int x, int y, unsigned int rgb) = 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 diff --git a/Hello3Dwave/UIcode/UIcode.cpp b/Hello3Dwave/UIcode/UIcode.cpp index 3eb6fa8..a1ad232 100644 --- a/Hello3Dwave/UIcode/UIcode.cpp +++ b/Hello3Dwave/UIcode/UIcode.cpp @@ -138,9 +138,9 @@ 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) { +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, gfx_op); + static c_display display(phy_fb, screen_width, screen_height, &surface, driver); s_surface = &surface; s_display = &display; @@ -179,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/UIcode/GuiLite.h b/HelloAnimation/UIcode/GuiLite.h index 1b4611b..80550e1 100644 --- a/HelloAnimation/UIcode/GuiLite.h +++ b/HelloAnimation/UIcode/GuiLite.h @@ -225,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); @@ -234,8 +234,8 @@ class c_surface; class c_display { friend class c_surface; public: - inline c_display(void* phy_fb, int display_width, int display_height, c_surface* surface, EXTERNAL_GFX_OP* gfx_op = 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, EXTERNAL_GFX_OP* gfx_op = 0);//multiple surface + 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; } @@ -286,9 +286,9 @@ protected: virtual void draw_pixel(int x, int y, unsigned int rgb) { if ((x >= m_width) || (y >= m_height)) { return; } - if (m_gfx_op && m_gfx_op->draw_pixel) + if (m_driver && m_driver->draw_pixel) { - return m_gfx_op->draw_pixel(x, y, rgb); + return m_driver->draw_pixel(x, y, rgb); } if (m_color_bytes == 2) { @@ -301,17 +301,17 @@ protected: } virtual void fill_rect(int x0, int y0, int x1, int y1, unsigned int rgb) { - if (m_gfx_op && m_gfx_op->fill_rect) + if (m_driver && m_driver->fill_rect) { - return m_gfx_op->fill_rect(x0, y0, x1, y1, rgb); + return m_driver->fill_rect(x0, y0, x1, y1, rgb); } - if (m_gfx_op && m_gfx_op->draw_pixel) + if (m_driver && m_driver->draw_pixel) { for (int y = y0; y <= y1; y++) { for (int x = x0; x <= x1; x++) { - m_gfx_op->draw_pixel(x, y, rgb); + m_driver->draw_pixel(x, y, rgb); } } return; @@ -373,9 +373,9 @@ protected: } 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 - struct EXTERNAL_GFX_OP* m_gfx_op; //Rendering by external method + 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]; @@ -682,13 +682,13 @@ protected: int* m_phy_write_index; c_display* m_display; }; -inline c_display::c_display(void* phy_fb, int display_width, int display_height, c_surface* surface, EXTERNAL_GFX_OP* gfx_op) : m_phy_fb(phy_fb), m_width(display_width), m_height(display_height), m_gfx_op(gfx_op), m_phy_read_index(0), m_phy_write_index(0), m_surface_cnt(1), 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, EXTERNAL_GFX_OP* gfx_op) : 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_gfx_op(gfx_op), m_surface_index(0) +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); @@ -742,7 +742,7 @@ inline int c_display::swipe_surface(c_surface* s0, c_surface* s1, int x0, int x1 } else if (m_color_bytes == 2) { - void(*draw_pixel)(int x, int y, unsigned int rgb) = 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 @@ -759,7 +759,7 @@ inline int c_display::swipe_surface(c_surface* s0, c_surface* s1, int x0, int x1 } else //m_color_bytes == 3/4... { - void(*draw_pixel)(int x, int y, unsigned int rgb) = 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 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 e685537..331721f 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/main.cpp b/HelloCircle/BuildLinux/main.cpp index 9204e8c..49d54dc 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 GIT binary patch delta 126 zcmX@$yU%w+f{e5agC|2ULjZ#hgCj#ELp*~ELl96TjKP&5XmhO$Gb3*bLlHwJLm5LV zkhY$@QPptsKG{=jD8hP^C(4LUUZtYOjih+;ZI!kBNPGrOp!SD?!kbsAiZKEJ$oe2= delta 114 zcmdnzd%$-?f{d&yLj*$zgDXQ2gCBz #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 69907b9..85337a8 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 d38e9c3..e22aef4 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 1b4611b..80550e1 100644 --- a/HelloCircle/UIcode/GuiLite.h +++ b/HelloCircle/UIcode/GuiLite.h @@ -225,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); @@ -234,8 +234,8 @@ class c_surface; class c_display { friend class c_surface; public: - inline c_display(void* phy_fb, int display_width, int display_height, c_surface* surface, EXTERNAL_GFX_OP* gfx_op = 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, EXTERNAL_GFX_OP* gfx_op = 0);//multiple surface + 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; } @@ -286,9 +286,9 @@ protected: virtual void draw_pixel(int x, int y, unsigned int rgb) { if ((x >= m_width) || (y >= m_height)) { return; } - if (m_gfx_op && m_gfx_op->draw_pixel) + if (m_driver && m_driver->draw_pixel) { - return m_gfx_op->draw_pixel(x, y, rgb); + return m_driver->draw_pixel(x, y, rgb); } if (m_color_bytes == 2) { @@ -301,17 +301,17 @@ protected: } virtual void fill_rect(int x0, int y0, int x1, int y1, unsigned int rgb) { - if (m_gfx_op && m_gfx_op->fill_rect) + if (m_driver && m_driver->fill_rect) { - return m_gfx_op->fill_rect(x0, y0, x1, y1, rgb); + return m_driver->fill_rect(x0, y0, x1, y1, rgb); } - if (m_gfx_op && m_gfx_op->draw_pixel) + if (m_driver && m_driver->draw_pixel) { for (int y = y0; y <= y1; y++) { for (int x = x0; x <= x1; x++) { - m_gfx_op->draw_pixel(x, y, rgb); + m_driver->draw_pixel(x, y, rgb); } } return; @@ -373,9 +373,9 @@ protected: } 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 - struct EXTERNAL_GFX_OP* m_gfx_op; //Rendering by external method + 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]; @@ -682,13 +682,13 @@ protected: int* m_phy_write_index; c_display* m_display; }; -inline c_display::c_display(void* phy_fb, int display_width, int display_height, c_surface* surface, EXTERNAL_GFX_OP* gfx_op) : m_phy_fb(phy_fb), m_width(display_width), m_height(display_height), m_gfx_op(gfx_op), m_phy_read_index(0), m_phy_write_index(0), m_surface_cnt(1), 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, EXTERNAL_GFX_OP* gfx_op) : 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_gfx_op(gfx_op), m_surface_index(0) +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); @@ -742,7 +742,7 @@ inline int c_display::swipe_surface(c_surface* s0, c_surface* s1, int x0, int x1 } else if (m_color_bytes == 2) { - void(*draw_pixel)(int x, int y, unsigned int rgb) = 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 @@ -759,7 +759,7 @@ inline int c_display::swipe_surface(c_surface* s0, c_surface* s1, int x0, int x1 } else //m_color_bytes == 3/4... { - void(*draw_pixel)(int x, int y, unsigned int rgb) = 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 diff --git a/HelloCircle/UIcode/UIcode.cpp b/HelloCircle/UIcode/UIcode.cpp index 03759b0..ba3506e 100644 --- a/HelloCircle/UIcode/UIcode.cpp +++ b/HelloCircle/UIcode/UIcode.cpp @@ -201,9 +201,9 @@ 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) { +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, gfx_op); + static c_display display(phy_fb, screen_width, screen_height, &surface, driver); s_surface = &surface; s_display = &display; @@ -243,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/UIcode/GuiLite.h b/HelloFFmpeg/UIcode/GuiLite.h index 1b4611b..80550e1 100644 --- a/HelloFFmpeg/UIcode/GuiLite.h +++ b/HelloFFmpeg/UIcode/GuiLite.h @@ -225,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); @@ -234,8 +234,8 @@ class c_surface; class c_display { friend class c_surface; public: - inline c_display(void* phy_fb, int display_width, int display_height, c_surface* surface, EXTERNAL_GFX_OP* gfx_op = 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, EXTERNAL_GFX_OP* gfx_op = 0);//multiple surface + 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; } @@ -286,9 +286,9 @@ protected: virtual void draw_pixel(int x, int y, unsigned int rgb) { if ((x >= m_width) || (y >= m_height)) { return; } - if (m_gfx_op && m_gfx_op->draw_pixel) + if (m_driver && m_driver->draw_pixel) { - return m_gfx_op->draw_pixel(x, y, rgb); + return m_driver->draw_pixel(x, y, rgb); } if (m_color_bytes == 2) { @@ -301,17 +301,17 @@ protected: } virtual void fill_rect(int x0, int y0, int x1, int y1, unsigned int rgb) { - if (m_gfx_op && m_gfx_op->fill_rect) + if (m_driver && m_driver->fill_rect) { - return m_gfx_op->fill_rect(x0, y0, x1, y1, rgb); + return m_driver->fill_rect(x0, y0, x1, y1, rgb); } - if (m_gfx_op && m_gfx_op->draw_pixel) + if (m_driver && m_driver->draw_pixel) { for (int y = y0; y <= y1; y++) { for (int x = x0; x <= x1; x++) { - m_gfx_op->draw_pixel(x, y, rgb); + m_driver->draw_pixel(x, y, rgb); } } return; @@ -373,9 +373,9 @@ protected: } 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 - struct EXTERNAL_GFX_OP* m_gfx_op; //Rendering by external method + 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]; @@ -682,13 +682,13 @@ protected: int* m_phy_write_index; c_display* m_display; }; -inline c_display::c_display(void* phy_fb, int display_width, int display_height, c_surface* surface, EXTERNAL_GFX_OP* gfx_op) : m_phy_fb(phy_fb), m_width(display_width), m_height(display_height), m_gfx_op(gfx_op), m_phy_read_index(0), m_phy_write_index(0), m_surface_cnt(1), 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, EXTERNAL_GFX_OP* gfx_op) : 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_gfx_op(gfx_op), m_surface_index(0) +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); @@ -742,7 +742,7 @@ inline int c_display::swipe_surface(c_surface* s0, c_surface* s1, int x0, int x1 } else if (m_color_bytes == 2) { - void(*draw_pixel)(int x, int y, unsigned int rgb) = 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 @@ -759,7 +759,7 @@ inline int c_display::swipe_surface(c_surface* s0, c_surface* s1, int x0, int x1 } else //m_color_bytes == 3/4... { - void(*draw_pixel)(int x, int y, unsigned int rgb) = 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 diff --git a/HelloFont/UIcode/GuiLite.h b/HelloFont/UIcode/GuiLite.h index 1b4611b..80550e1 100644 --- a/HelloFont/UIcode/GuiLite.h +++ b/HelloFont/UIcode/GuiLite.h @@ -225,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); @@ -234,8 +234,8 @@ class c_surface; class c_display { friend class c_surface; public: - inline c_display(void* phy_fb, int display_width, int display_height, c_surface* surface, EXTERNAL_GFX_OP* gfx_op = 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, EXTERNAL_GFX_OP* gfx_op = 0);//multiple surface + 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; } @@ -286,9 +286,9 @@ protected: virtual void draw_pixel(int x, int y, unsigned int rgb) { if ((x >= m_width) || (y >= m_height)) { return; } - if (m_gfx_op && m_gfx_op->draw_pixel) + if (m_driver && m_driver->draw_pixel) { - return m_gfx_op->draw_pixel(x, y, rgb); + return m_driver->draw_pixel(x, y, rgb); } if (m_color_bytes == 2) { @@ -301,17 +301,17 @@ protected: } virtual void fill_rect(int x0, int y0, int x1, int y1, unsigned int rgb) { - if (m_gfx_op && m_gfx_op->fill_rect) + if (m_driver && m_driver->fill_rect) { - return m_gfx_op->fill_rect(x0, y0, x1, y1, rgb); + return m_driver->fill_rect(x0, y0, x1, y1, rgb); } - if (m_gfx_op && m_gfx_op->draw_pixel) + if (m_driver && m_driver->draw_pixel) { for (int y = y0; y <= y1; y++) { for (int x = x0; x <= x1; x++) { - m_gfx_op->draw_pixel(x, y, rgb); + m_driver->draw_pixel(x, y, rgb); } } return; @@ -373,9 +373,9 @@ protected: } 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 - struct EXTERNAL_GFX_OP* m_gfx_op; //Rendering by external method + 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]; @@ -682,13 +682,13 @@ protected: int* m_phy_write_index; c_display* m_display; }; -inline c_display::c_display(void* phy_fb, int display_width, int display_height, c_surface* surface, EXTERNAL_GFX_OP* gfx_op) : m_phy_fb(phy_fb), m_width(display_width), m_height(display_height), m_gfx_op(gfx_op), m_phy_read_index(0), m_phy_write_index(0), m_surface_cnt(1), 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, EXTERNAL_GFX_OP* gfx_op) : 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_gfx_op(gfx_op), m_surface_index(0) +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); @@ -742,7 +742,7 @@ inline int c_display::swipe_surface(c_surface* s0, c_surface* s1, int x0, int x1 } else if (m_color_bytes == 2) { - void(*draw_pixel)(int x, int y, unsigned int rgb) = 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 @@ -759,7 +759,7 @@ inline int c_display::swipe_surface(c_surface* s0, c_surface* s1, int x0, int x1 } else //m_color_bytes == 3/4... { - void(*draw_pixel)(int x, int y, unsigned int rgb) = 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 diff --git a/HelloFreetype/UIcode/GuiLite.h b/HelloFreetype/UIcode/GuiLite.h index 1b4611b..80550e1 100644 --- a/HelloFreetype/UIcode/GuiLite.h +++ b/HelloFreetype/UIcode/GuiLite.h @@ -225,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); @@ -234,8 +234,8 @@ class c_surface; class c_display { friend class c_surface; public: - inline c_display(void* phy_fb, int display_width, int display_height, c_surface* surface, EXTERNAL_GFX_OP* gfx_op = 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, EXTERNAL_GFX_OP* gfx_op = 0);//multiple surface + 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; } @@ -286,9 +286,9 @@ protected: virtual void draw_pixel(int x, int y, unsigned int rgb) { if ((x >= m_width) || (y >= m_height)) { return; } - if (m_gfx_op && m_gfx_op->draw_pixel) + if (m_driver && m_driver->draw_pixel) { - return m_gfx_op->draw_pixel(x, y, rgb); + return m_driver->draw_pixel(x, y, rgb); } if (m_color_bytes == 2) { @@ -301,17 +301,17 @@ protected: } virtual void fill_rect(int x0, int y0, int x1, int y1, unsigned int rgb) { - if (m_gfx_op && m_gfx_op->fill_rect) + if (m_driver && m_driver->fill_rect) { - return m_gfx_op->fill_rect(x0, y0, x1, y1, rgb); + return m_driver->fill_rect(x0, y0, x1, y1, rgb); } - if (m_gfx_op && m_gfx_op->draw_pixel) + if (m_driver && m_driver->draw_pixel) { for (int y = y0; y <= y1; y++) { for (int x = x0; x <= x1; x++) { - m_gfx_op->draw_pixel(x, y, rgb); + m_driver->draw_pixel(x, y, rgb); } } return; @@ -373,9 +373,9 @@ protected: } 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 - struct EXTERNAL_GFX_OP* m_gfx_op; //Rendering by external method + 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]; @@ -682,13 +682,13 @@ protected: int* m_phy_write_index; c_display* m_display; }; -inline c_display::c_display(void* phy_fb, int display_width, int display_height, c_surface* surface, EXTERNAL_GFX_OP* gfx_op) : m_phy_fb(phy_fb), m_width(display_width), m_height(display_height), m_gfx_op(gfx_op), m_phy_read_index(0), m_phy_write_index(0), m_surface_cnt(1), 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, EXTERNAL_GFX_OP* gfx_op) : 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_gfx_op(gfx_op), m_surface_index(0) +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); @@ -742,7 +742,7 @@ inline int c_display::swipe_surface(c_surface* s0, c_surface* s1, int x0, int x1 } else if (m_color_bytes == 2) { - void(*draw_pixel)(int x, int y, unsigned int rgb) = 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 @@ -759,7 +759,7 @@ inline int c_display::swipe_surface(c_surface* s0, c_surface* s1, int x0, int x1 } else //m_color_bytes == 3/4... { - void(*draw_pixel)(int x, int y, unsigned int rgb) = 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 diff --git a/HelloJPG/UIcode/GuiLite.h b/HelloJPG/UIcode/GuiLite.h index 1b4611b..80550e1 100644 --- a/HelloJPG/UIcode/GuiLite.h +++ b/HelloJPG/UIcode/GuiLite.h @@ -225,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); @@ -234,8 +234,8 @@ class c_surface; class c_display { friend class c_surface; public: - inline c_display(void* phy_fb, int display_width, int display_height, c_surface* surface, EXTERNAL_GFX_OP* gfx_op = 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, EXTERNAL_GFX_OP* gfx_op = 0);//multiple surface + 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; } @@ -286,9 +286,9 @@ protected: virtual void draw_pixel(int x, int y, unsigned int rgb) { if ((x >= m_width) || (y >= m_height)) { return; } - if (m_gfx_op && m_gfx_op->draw_pixel) + if (m_driver && m_driver->draw_pixel) { - return m_gfx_op->draw_pixel(x, y, rgb); + return m_driver->draw_pixel(x, y, rgb); } if (m_color_bytes == 2) { @@ -301,17 +301,17 @@ protected: } virtual void fill_rect(int x0, int y0, int x1, int y1, unsigned int rgb) { - if (m_gfx_op && m_gfx_op->fill_rect) + if (m_driver && m_driver->fill_rect) { - return m_gfx_op->fill_rect(x0, y0, x1, y1, rgb); + return m_driver->fill_rect(x0, y0, x1, y1, rgb); } - if (m_gfx_op && m_gfx_op->draw_pixel) + if (m_driver && m_driver->draw_pixel) { for (int y = y0; y <= y1; y++) { for (int x = x0; x <= x1; x++) { - m_gfx_op->draw_pixel(x, y, rgb); + m_driver->draw_pixel(x, y, rgb); } } return; @@ -373,9 +373,9 @@ protected: } 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 - struct EXTERNAL_GFX_OP* m_gfx_op; //Rendering by external method + 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]; @@ -682,13 +682,13 @@ protected: int* m_phy_write_index; c_display* m_display; }; -inline c_display::c_display(void* phy_fb, int display_width, int display_height, c_surface* surface, EXTERNAL_GFX_OP* gfx_op) : m_phy_fb(phy_fb), m_width(display_width), m_height(display_height), m_gfx_op(gfx_op), m_phy_read_index(0), m_phy_write_index(0), m_surface_cnt(1), 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, EXTERNAL_GFX_OP* gfx_op) : 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_gfx_op(gfx_op), m_surface_index(0) +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); @@ -742,7 +742,7 @@ inline int c_display::swipe_surface(c_surface* s0, c_surface* s1, int x0, int x1 } else if (m_color_bytes == 2) { - void(*draw_pixel)(int x, int y, unsigned int rgb) = 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 @@ -759,7 +759,7 @@ inline int c_display::swipe_surface(c_surface* s0, c_surface* s1, int x0, int x1 } else //m_color_bytes == 3/4... { - void(*draw_pixel)(int x, int y, unsigned int rgb) = 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 diff --git a/HelloLayers/BuildLinux/main.cpp b/HelloLayers/BuildLinux/main.cpp index 43b86e1..0f4fa95 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 GIT binary patch delta 126 zcmX@$yU%w+f{e5agC|2ULjZ#hgCj#ELp*~ELl96TjKP&5XmhO$Gb3*bLlHwJLm5LV zkhY$@QPptsKG{=jD8hP^C(4LUUZtYOjih+;ZI!kBNPGrOp!SD?!kbsAiZKEJ$oe2= delta 114 zcmdnzd%$-?f{d&yLj*$zgDXQ2gCBz= m_width) || (y >= m_height)) { return; } - if (m_gfx_op && m_gfx_op->draw_pixel) + if (m_driver && m_driver->draw_pixel) { - return m_gfx_op->draw_pixel(x, y, rgb); + return m_driver->draw_pixel(x, y, rgb); } if (m_color_bytes == 2) { @@ -301,17 +301,17 @@ protected: } virtual void fill_rect(int x0, int y0, int x1, int y1, unsigned int rgb) { - if (m_gfx_op && m_gfx_op->fill_rect) + if (m_driver && m_driver->fill_rect) { - return m_gfx_op->fill_rect(x0, y0, x1, y1, rgb); + return m_driver->fill_rect(x0, y0, x1, y1, rgb); } - if (m_gfx_op && m_gfx_op->draw_pixel) + if (m_driver && m_driver->draw_pixel) { for (int y = y0; y <= y1; y++) { for (int x = x0; x <= x1; x++) { - m_gfx_op->draw_pixel(x, y, rgb); + m_driver->draw_pixel(x, y, rgb); } } return; @@ -373,9 +373,9 @@ protected: } 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 - struct EXTERNAL_GFX_OP* m_gfx_op; //Rendering by external method + 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]; @@ -682,13 +682,13 @@ protected: int* m_phy_write_index; c_display* m_display; }; -inline c_display::c_display(void* phy_fb, int display_width, int display_height, c_surface* surface, EXTERNAL_GFX_OP* gfx_op) : m_phy_fb(phy_fb), m_width(display_width), m_height(display_height), m_gfx_op(gfx_op), m_phy_read_index(0), m_phy_write_index(0), m_surface_cnt(1), 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, EXTERNAL_GFX_OP* gfx_op) : 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_gfx_op(gfx_op), m_surface_index(0) +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); @@ -742,7 +742,7 @@ inline int c_display::swipe_surface(c_surface* s0, c_surface* s1, int x0, int x1 } else if (m_color_bytes == 2) { - void(*draw_pixel)(int x, int y, unsigned int rgb) = 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 @@ -759,7 +759,7 @@ inline int c_display::swipe_surface(c_surface* s0, c_surface* s1, int x0, int x1 } else //m_color_bytes == 3/4... { - void(*draw_pixel)(int x, int y, unsigned int rgb) = 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 diff --git a/HelloLayers/UIcode/UIcode.cpp b/HelloLayers/UIcode/UIcode.cpp index e45678a..c421ccd 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,9 +62,9 @@ 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) { +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, gfx_op); + static c_display display(phy_fb, screen_width, screen_height, &surface, driver); s_surface = &surface; s_display = &display; @@ -79,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/main.cpp b/HelloMario/BuildLinux/main.cpp index 4a54a8c..33b3c30 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 GIT binary patch delta 124 zcmaFi`^>|L3q1e; delta 58 zcmbOrHc4!Q4x_FsLj*$zgDXQ2gCBz= m_width) || (y >= m_height)) { return; } - if (m_gfx_op && m_gfx_op->draw_pixel) + if (m_driver && m_driver->draw_pixel) { - return m_gfx_op->draw_pixel(x, y, rgb); + return m_driver->draw_pixel(x, y, rgb); } if (m_color_bytes == 2) { @@ -301,17 +301,17 @@ protected: } virtual void fill_rect(int x0, int y0, int x1, int y1, unsigned int rgb) { - if (m_gfx_op && m_gfx_op->fill_rect) + if (m_driver && m_driver->fill_rect) { - return m_gfx_op->fill_rect(x0, y0, x1, y1, rgb); + return m_driver->fill_rect(x0, y0, x1, y1, rgb); } - if (m_gfx_op && m_gfx_op->draw_pixel) + if (m_driver && m_driver->draw_pixel) { for (int y = y0; y <= y1; y++) { for (int x = x0; x <= x1; x++) { - m_gfx_op->draw_pixel(x, y, rgb); + m_driver->draw_pixel(x, y, rgb); } } return; @@ -373,9 +373,9 @@ protected: } 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 - struct EXTERNAL_GFX_OP* m_gfx_op; //Rendering by external method + 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]; @@ -682,13 +682,13 @@ protected: int* m_phy_write_index; c_display* m_display; }; -inline c_display::c_display(void* phy_fb, int display_width, int display_height, c_surface* surface, EXTERNAL_GFX_OP* gfx_op) : m_phy_fb(phy_fb), m_width(display_width), m_height(display_height), m_gfx_op(gfx_op), m_phy_read_index(0), m_phy_write_index(0), m_surface_cnt(1), 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, EXTERNAL_GFX_OP* gfx_op) : 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_gfx_op(gfx_op), m_surface_index(0) +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); @@ -742,7 +742,7 @@ inline int c_display::swipe_surface(c_surface* s0, c_surface* s1, int x0, int x1 } else if (m_color_bytes == 2) { - void(*draw_pixel)(int x, int y, unsigned int rgb) = 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 @@ -759,7 +759,7 @@ inline int c_display::swipe_surface(c_surface* s0, c_surface* s1, int x0, int x1 } else //m_color_bytes == 3/4... { - void(*draw_pixel)(int x, int y, unsigned int rgb) = 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 diff --git a/HelloMario/UIcode/UIcode.cpp b/HelloMario/UIcode/UIcode.cpp index 6059ec3..0c8b916 100644 --- a/HelloMario/UIcode/UIcode.cpp +++ b/HelloMario/UIcode/UIcode.cpp @@ -103,9 +103,9 @@ 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) { +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, gfx_op); + static c_display display(phy_fb, screen_width, screen_height, &surface, driver); s_surface = &surface; s_display = &display; @@ -122,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/main.cpp b/HelloMolecule/BuildLinux/main.cpp index ccf68d7..77cb65a 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 GIT binary patch delta 119 zcmeAuYAf2%AuH{|;K>lo5WwKW;K&fk5YOPk5CjwnV{l~%+PqYjnUObzp@<=qp^PCF rNLx?-Xl}asmE1KpZY1H!r&VoHl<7@YloQ^pp*D*NS=r{Z8rA{;4lo{~ delta 109 zcmZoG>L}XKAuH?35Wx__;K~rh;K$&|;KLBl;LhL%6pLr@X9(E5SeBWQJDnkop#mt7 g&rq;=qZ}_gvcTk%s= m_width) || (y >= m_height)) { return; } - if (m_gfx_op && m_gfx_op->draw_pixel) + if (m_driver && m_driver->draw_pixel) { - return m_gfx_op->draw_pixel(x, y, rgb); + return m_driver->draw_pixel(x, y, rgb); } if (m_color_bytes == 2) { @@ -301,17 +301,17 @@ protected: } virtual void fill_rect(int x0, int y0, int x1, int y1, unsigned int rgb) { - if (m_gfx_op && m_gfx_op->fill_rect) + if (m_driver && m_driver->fill_rect) { - return m_gfx_op->fill_rect(x0, y0, x1, y1, rgb); + return m_driver->fill_rect(x0, y0, x1, y1, rgb); } - if (m_gfx_op && m_gfx_op->draw_pixel) + if (m_driver && m_driver->draw_pixel) { for (int y = y0; y <= y1; y++) { for (int x = x0; x <= x1; x++) { - m_gfx_op->draw_pixel(x, y, rgb); + m_driver->draw_pixel(x, y, rgb); } } return; @@ -373,9 +373,9 @@ protected: } 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 - struct EXTERNAL_GFX_OP* m_gfx_op; //Rendering by external method + 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]; @@ -682,13 +682,13 @@ protected: int* m_phy_write_index; c_display* m_display; }; -inline c_display::c_display(void* phy_fb, int display_width, int display_height, c_surface* surface, EXTERNAL_GFX_OP* gfx_op) : m_phy_fb(phy_fb), m_width(display_width), m_height(display_height), m_gfx_op(gfx_op), m_phy_read_index(0), m_phy_write_index(0), m_surface_cnt(1), 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, EXTERNAL_GFX_OP* gfx_op) : 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_gfx_op(gfx_op), m_surface_index(0) +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); @@ -742,7 +742,7 @@ inline int c_display::swipe_surface(c_surface* s0, c_surface* s1, int x0, int x1 } else if (m_color_bytes == 2) { - void(*draw_pixel)(int x, int y, unsigned int rgb) = 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 @@ -759,7 +759,7 @@ inline int c_display::swipe_surface(c_surface* s0, c_surface* s1, int x0, int x1 } else //m_color_bytes == 3/4... { - void(*draw_pixel)(int x, int y, unsigned int rgb) = 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 diff --git a/HelloMolecule/UIcode/UIcode.cpp b/HelloMolecule/UIcode/UIcode.cpp index 09949ce..661c7c4 100644 --- a/HelloMolecule/UIcode/UIcode.cpp +++ b/HelloMolecule/UIcode/UIcode.cpp @@ -150,10 +150,10 @@ 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) { 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, gfx_op); + static c_display display(phy_fb, screen_width, screen_height, &surface, driver); s_surface = &surface; s_display = &display; @@ -180,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/BuildMFC/HelloNetsDlg.cpp b/HelloNets/BuildMFC/HelloNetsDlg.cpp index ed159ca8fcc7314c5125c1c9369c306ba5321936..00f5f14810cf296a90a7c78bb4d4eb3e9478aeca 100644 GIT binary patch delta 100 zcmdl|wyA8x8JWo<#sb_f3_%Q@3}Fne3_+V;$}ltXrZ5ySWHOX7qylN{$#2bdH>=4x Zh;SnbPcAgFN8#@_x{1u+Jl}XKI{=gu93KDx delta 120 zcmdl~wxw*t85vnuh6sib23Lk420sQz1|Noa26qNGpjbSEKSRLg=Q7NUyy*;S3>83u te1-xB>&dT$bT_NWIf!s02~W;9vPV&-H#ty2c=9=;Bgm>Y&o!RP4gf7n9})ln diff --git a/HelloNets/BuildMFC/HelloNetsDlg.h b/HelloNets/BuildMFC/HelloNetsDlg.h index 7610d33d22bb502172e732188b73fd3e8ac9978d..1fa4db7e1c5183f11c2263c8f7728e5422f7a481 100644 GIT binary patch delta 60 zcmca3b4zA}8KbrfgC|2ULjZ#hgCj#ELp*~ELl96TjKLL1YcVJ=q%agQWHOX7q%ssu NzRxJXxry->4*-)=4aNWf delta 58 zcmca5b4O-_8KbT%Lj*$zgDXQ2gCBz%_!b*v1J diff --git a/HelloNets/BuildSTM32F103-Keil/USER/main.c b/HelloNets/BuildSTM32F103-Keil/USER/main.c index 23dbddd..667d523 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 c517e75..7702c67 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 1b4611b..80550e1 100644 --- a/HelloNets/UIcode/GuiLite.h +++ b/HelloNets/UIcode/GuiLite.h @@ -225,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); @@ -234,8 +234,8 @@ class c_surface; class c_display { friend class c_surface; public: - inline c_display(void* phy_fb, int display_width, int display_height, c_surface* surface, EXTERNAL_GFX_OP* gfx_op = 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, EXTERNAL_GFX_OP* gfx_op = 0);//multiple surface + 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; } @@ -286,9 +286,9 @@ protected: virtual void draw_pixel(int x, int y, unsigned int rgb) { if ((x >= m_width) || (y >= m_height)) { return; } - if (m_gfx_op && m_gfx_op->draw_pixel) + if (m_driver && m_driver->draw_pixel) { - return m_gfx_op->draw_pixel(x, y, rgb); + return m_driver->draw_pixel(x, y, rgb); } if (m_color_bytes == 2) { @@ -301,17 +301,17 @@ protected: } virtual void fill_rect(int x0, int y0, int x1, int y1, unsigned int rgb) { - if (m_gfx_op && m_gfx_op->fill_rect) + if (m_driver && m_driver->fill_rect) { - return m_gfx_op->fill_rect(x0, y0, x1, y1, rgb); + return m_driver->fill_rect(x0, y0, x1, y1, rgb); } - if (m_gfx_op && m_gfx_op->draw_pixel) + if (m_driver && m_driver->draw_pixel) { for (int y = y0; y <= y1; y++) { for (int x = x0; x <= x1; x++) { - m_gfx_op->draw_pixel(x, y, rgb); + m_driver->draw_pixel(x, y, rgb); } } return; @@ -373,9 +373,9 @@ protected: } 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 - struct EXTERNAL_GFX_OP* m_gfx_op; //Rendering by external method + 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]; @@ -682,13 +682,13 @@ protected: int* m_phy_write_index; c_display* m_display; }; -inline c_display::c_display(void* phy_fb, int display_width, int display_height, c_surface* surface, EXTERNAL_GFX_OP* gfx_op) : m_phy_fb(phy_fb), m_width(display_width), m_height(display_height), m_gfx_op(gfx_op), m_phy_read_index(0), m_phy_write_index(0), m_surface_cnt(1), 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, EXTERNAL_GFX_OP* gfx_op) : 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_gfx_op(gfx_op), m_surface_index(0) +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); @@ -742,7 +742,7 @@ inline int c_display::swipe_surface(c_surface* s0, c_surface* s1, int x0, int x1 } else if (m_color_bytes == 2) { - void(*draw_pixel)(int x, int y, unsigned int rgb) = 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 @@ -759,7 +759,7 @@ inline int c_display::swipe_surface(c_surface* s0, c_surface* s1, int x0, int x1 } else //m_color_bytes == 3/4... { - void(*draw_pixel)(int x, int y, unsigned int rgb) = 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 diff --git a/HelloNets/UIcode/UIcode.cpp b/HelloNets/UIcode/UIcode.cpp index b0d5bf7..9a39019 100644 --- a/HelloNets/UIcode/UIcode.cpp +++ b/HelloNets/UIcode/UIcode.cpp @@ -112,10 +112,10 @@ 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) { 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, gfx_op); + static c_display display(phy_fb, screen_width, screen_height, &surface, driver); s_surface = &surface; s_display = &display; @@ -184,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/main.cpp b/HelloNoTouch/BuildLinux/main.cpp index 19e4ffe..19421e3 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 GIT binary patch delta 107 zcmcambgpPagY4uMRRL}nh9Cw{hA;+KhM>)JWtkayQy7XEG8xJkQh~JfhIod2hJwxUjJ|vTs(lEF diff --git a/HelloNoTouch/BuildSTM32F103-Keil/USER/main.c b/HelloNoTouch/BuildSTM32F103-Keil/USER/main.c index c420e8a..9f0e3e8 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 fc640b1..c4b47ee 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 1b4611b..80550e1 100644 --- a/HelloNoTouch/UIcode/GuiLite.h +++ b/HelloNoTouch/UIcode/GuiLite.h @@ -225,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); @@ -234,8 +234,8 @@ class c_surface; class c_display { friend class c_surface; public: - inline c_display(void* phy_fb, int display_width, int display_height, c_surface* surface, EXTERNAL_GFX_OP* gfx_op = 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, EXTERNAL_GFX_OP* gfx_op = 0);//multiple surface + 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; } @@ -286,9 +286,9 @@ protected: virtual void draw_pixel(int x, int y, unsigned int rgb) { if ((x >= m_width) || (y >= m_height)) { return; } - if (m_gfx_op && m_gfx_op->draw_pixel) + if (m_driver && m_driver->draw_pixel) { - return m_gfx_op->draw_pixel(x, y, rgb); + return m_driver->draw_pixel(x, y, rgb); } if (m_color_bytes == 2) { @@ -301,17 +301,17 @@ protected: } virtual void fill_rect(int x0, int y0, int x1, int y1, unsigned int rgb) { - if (m_gfx_op && m_gfx_op->fill_rect) + if (m_driver && m_driver->fill_rect) { - return m_gfx_op->fill_rect(x0, y0, x1, y1, rgb); + return m_driver->fill_rect(x0, y0, x1, y1, rgb); } - if (m_gfx_op && m_gfx_op->draw_pixel) + if (m_driver && m_driver->draw_pixel) { for (int y = y0; y <= y1; y++) { for (int x = x0; x <= x1; x++) { - m_gfx_op->draw_pixel(x, y, rgb); + m_driver->draw_pixel(x, y, rgb); } } return; @@ -373,9 +373,9 @@ protected: } 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 - struct EXTERNAL_GFX_OP* m_gfx_op; //Rendering by external method + 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]; @@ -682,13 +682,13 @@ protected: int* m_phy_write_index; c_display* m_display; }; -inline c_display::c_display(void* phy_fb, int display_width, int display_height, c_surface* surface, EXTERNAL_GFX_OP* gfx_op) : m_phy_fb(phy_fb), m_width(display_width), m_height(display_height), m_gfx_op(gfx_op), m_phy_read_index(0), m_phy_write_index(0), m_surface_cnt(1), 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, EXTERNAL_GFX_OP* gfx_op) : 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_gfx_op(gfx_op), m_surface_index(0) +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); @@ -742,7 +742,7 @@ inline int c_display::swipe_surface(c_surface* s0, c_surface* s1, int x0, int x1 } else if (m_color_bytes == 2) { - void(*draw_pixel)(int x, int y, unsigned int rgb) = 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 @@ -759,7 +759,7 @@ inline int c_display::swipe_surface(c_surface* s0, c_surface* s1, int x0, int x1 } else //m_color_bytes == 3/4... { - void(*draw_pixel)(int x, int y, unsigned int rgb) = 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 diff --git a/HelloNoTouch/UIcode/UIcode.cpp b/HelloNoTouch/UIcode/UIcode.cpp index 134c739..2a0c872 100644 --- a/HelloNoTouch/UIcode/UIcode.cpp +++ b/HelloNoTouch/UIcode/UIcode.cpp @@ -86,11 +86,11 @@ 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(); 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, gfx_op); + static c_display display(phy_fb, screen_width, screen_height, &surface, driver); s_surface = &surface; s_display = &display; s_myUI.set_surface(s_surface); @@ -99,9 +99,9 @@ void create_ui(void* phy_fb, int screen_width, int screen_height, int color_byte } //////////////////////// 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 c05ea6b..823f750 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/main.cpp b/HelloParticle/BuildLinux/main.cpp index 2400ac2..2731303 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 GIT binary patch delta 126 zcmZ4Ex5{tB1{rA=22X}yh5!a121kZShIj@Sh9ICw7=tTA(B`u;%#6G#3`Go?3}p;;S delta 122 zcmZ4Gx5jV71{qmbh6sib23Lk420sQz1|Noa26qNGpjbSEKSRLg(=yDAyy*;S3>83u ue1-xB>&f*Trke%iuCZ|=2~Ym0VvEAJRNcsrB+sA;)Tk&VyqQN$ju8MRryU#s diff --git a/HelloParticle/BuildMFC/HelloParticleDlg.h b/HelloParticle/BuildMFC/HelloParticleDlg.h index 454f67e91057fb3a9460bdb75c3ad2d6eaec73ff..9574ee0739ab39a4125e843222726167c208bda5 100644 GIT binary patch delta 56 zcmca4dO>u91*5hLgC|2ULjZ#hgCj#ELp*~ELl96TjKLL1YcVJ=q%agQWHOX7q%st3 JPG!vH1OQdz3x@yz delta 58 zcmca0dP#JH1*5JjLj*$zgDXQ2gCBz= m_width) || (y >= m_height)) { return; } - if (m_gfx_op && m_gfx_op->draw_pixel) + if (m_driver && m_driver->draw_pixel) { - return m_gfx_op->draw_pixel(x, y, rgb); + return m_driver->draw_pixel(x, y, rgb); } if (m_color_bytes == 2) { @@ -301,17 +301,17 @@ protected: } virtual void fill_rect(int x0, int y0, int x1, int y1, unsigned int rgb) { - if (m_gfx_op && m_gfx_op->fill_rect) + if (m_driver && m_driver->fill_rect) { - return m_gfx_op->fill_rect(x0, y0, x1, y1, rgb); + return m_driver->fill_rect(x0, y0, x1, y1, rgb); } - if (m_gfx_op && m_gfx_op->draw_pixel) + if (m_driver && m_driver->draw_pixel) { for (int y = y0; y <= y1; y++) { for (int x = x0; x <= x1; x++) { - m_gfx_op->draw_pixel(x, y, rgb); + m_driver->draw_pixel(x, y, rgb); } } return; @@ -373,9 +373,9 @@ protected: } 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 - struct EXTERNAL_GFX_OP* m_gfx_op; //Rendering by external method + 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]; @@ -682,13 +682,13 @@ protected: int* m_phy_write_index; c_display* m_display; }; -inline c_display::c_display(void* phy_fb, int display_width, int display_height, c_surface* surface, EXTERNAL_GFX_OP* gfx_op) : m_phy_fb(phy_fb), m_width(display_width), m_height(display_height), m_gfx_op(gfx_op), m_phy_read_index(0), m_phy_write_index(0), m_surface_cnt(1), 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, EXTERNAL_GFX_OP* gfx_op) : 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_gfx_op(gfx_op), m_surface_index(0) +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); @@ -742,7 +742,7 @@ inline int c_display::swipe_surface(c_surface* s0, c_surface* s1, int x0, int x1 } else if (m_color_bytes == 2) { - void(*draw_pixel)(int x, int y, unsigned int rgb) = 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 @@ -759,7 +759,7 @@ inline int c_display::swipe_surface(c_surface* s0, c_surface* s1, int x0, int x1 } else //m_color_bytes == 3/4... { - void(*draw_pixel)(int x, int y, unsigned int rgb) = 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 diff --git a/HelloParticle/UIcode/UIcode.cpp b/HelloParticle/UIcode/UIcode.cpp index 6d242e2..825ea57 100644 --- a/HelloParticle/UIcode/UIcode.cpp +++ b/HelloParticle/UIcode/UIcode.cpp @@ -48,10 +48,10 @@ 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(); 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, gfx_op); + static c_display display(phy_fb, screen_width, screen_height, &surface, driver); s_surface = &surface; s_display = &display; @@ -69,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/main.cpp b/HelloPendulum/BuildLinux/main.cpp index e79cb38..76d9eb7 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 GIT binary patch delta 132 zcmZ1xuq)&<)=^bM6J=Bso?N6lhacGpO`su$GQyh;)P67m0BVpR ABLDyZ delta 128 zcmZ1$up(f?B^g;)h6sib23Lk420sQz1|Noa26qNGpjbSEKSRLgw=&F(yy*;S3>83u ze1-xB>&X{|Og9_JU1LKL)|<>ID>_+ARgD`-@#JXLjr>S_22G%LLmA=CdTKuy0pMC6 AD*ylh diff --git a/HelloPendulum/BuildMFC/HelloPendulumDlg.h b/HelloPendulum/BuildMFC/HelloPendulumDlg.h index a208fd682ee5af533f824d20c05e8802c2449596..10f16c228e2d905f866a013f3a0f87eb17f0d672 100644 GIT binary patch delta 56 zcmX>heoTCW1*5hLgC|2ULjZ#hgCj#ELp*~ELl96TjKLL1YcVJ=q%agQWHOX7q%st3 JPGwBy0svB63vK`a delta 58 zcmX>menNbM1*5JjLj*$zgDXQ2gCBz= m_width) || (y >= m_height)) { return; } - if (m_gfx_op && m_gfx_op->draw_pixel) + if (m_driver && m_driver->draw_pixel) { - return m_gfx_op->draw_pixel(x, y, rgb); + return m_driver->draw_pixel(x, y, rgb); } if (m_color_bytes == 2) { @@ -301,17 +301,17 @@ protected: } virtual void fill_rect(int x0, int y0, int x1, int y1, unsigned int rgb) { - if (m_gfx_op && m_gfx_op->fill_rect) + if (m_driver && m_driver->fill_rect) { - return m_gfx_op->fill_rect(x0, y0, x1, y1, rgb); + return m_driver->fill_rect(x0, y0, x1, y1, rgb); } - if (m_gfx_op && m_gfx_op->draw_pixel) + if (m_driver && m_driver->draw_pixel) { for (int y = y0; y <= y1; y++) { for (int x = x0; x <= x1; x++) { - m_gfx_op->draw_pixel(x, y, rgb); + m_driver->draw_pixel(x, y, rgb); } } return; @@ -373,9 +373,9 @@ protected: } 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 - struct EXTERNAL_GFX_OP* m_gfx_op; //Rendering by external method + 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]; @@ -682,13 +682,13 @@ protected: int* m_phy_write_index; c_display* m_display; }; -inline c_display::c_display(void* phy_fb, int display_width, int display_height, c_surface* surface, EXTERNAL_GFX_OP* gfx_op) : m_phy_fb(phy_fb), m_width(display_width), m_height(display_height), m_gfx_op(gfx_op), m_phy_read_index(0), m_phy_write_index(0), m_surface_cnt(1), 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, EXTERNAL_GFX_OP* gfx_op) : 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_gfx_op(gfx_op), m_surface_index(0) +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); @@ -742,7 +742,7 @@ inline int c_display::swipe_surface(c_surface* s0, c_surface* s1, int x0, int x1 } else if (m_color_bytes == 2) { - void(*draw_pixel)(int x, int y, unsigned int rgb) = 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 @@ -759,7 +759,7 @@ inline int c_display::swipe_surface(c_surface* s0, c_surface* s1, int x0, int x1 } else //m_color_bytes == 3/4... { - void(*draw_pixel)(int x, int y, unsigned int rgb) = 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 diff --git a/HelloPendulum/UIcode/UIcode.cpp b/HelloPendulum/UIcode/UIcode.cpp index a09e2ef..3081019 100644 --- a/HelloPendulum/UIcode/UIcode.cpp +++ b/HelloPendulum/UIcode/UIcode.cpp @@ -92,9 +92,9 @@ 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) { +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, gfx_op); + static c_display display(phy_fb, screen_width, screen_height, &surface, driver); s_surface = &surface; s_display = &display; @@ -109,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/UIcode/GuiLite.h b/HelloScroll/UIcode/GuiLite.h index 1b4611b..80550e1 100644 --- a/HelloScroll/UIcode/GuiLite.h +++ b/HelloScroll/UIcode/GuiLite.h @@ -225,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); @@ -234,8 +234,8 @@ class c_surface; class c_display { friend class c_surface; public: - inline c_display(void* phy_fb, int display_width, int display_height, c_surface* surface, EXTERNAL_GFX_OP* gfx_op = 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, EXTERNAL_GFX_OP* gfx_op = 0);//multiple surface + 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; } @@ -286,9 +286,9 @@ protected: virtual void draw_pixel(int x, int y, unsigned int rgb) { if ((x >= m_width) || (y >= m_height)) { return; } - if (m_gfx_op && m_gfx_op->draw_pixel) + if (m_driver && m_driver->draw_pixel) { - return m_gfx_op->draw_pixel(x, y, rgb); + return m_driver->draw_pixel(x, y, rgb); } if (m_color_bytes == 2) { @@ -301,17 +301,17 @@ protected: } virtual void fill_rect(int x0, int y0, int x1, int y1, unsigned int rgb) { - if (m_gfx_op && m_gfx_op->fill_rect) + if (m_driver && m_driver->fill_rect) { - return m_gfx_op->fill_rect(x0, y0, x1, y1, rgb); + return m_driver->fill_rect(x0, y0, x1, y1, rgb); } - if (m_gfx_op && m_gfx_op->draw_pixel) + if (m_driver && m_driver->draw_pixel) { for (int y = y0; y <= y1; y++) { for (int x = x0; x <= x1; x++) { - m_gfx_op->draw_pixel(x, y, rgb); + m_driver->draw_pixel(x, y, rgb); } } return; @@ -373,9 +373,9 @@ protected: } 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 - struct EXTERNAL_GFX_OP* m_gfx_op; //Rendering by external method + 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]; @@ -682,13 +682,13 @@ protected: int* m_phy_write_index; c_display* m_display; }; -inline c_display::c_display(void* phy_fb, int display_width, int display_height, c_surface* surface, EXTERNAL_GFX_OP* gfx_op) : m_phy_fb(phy_fb), m_width(display_width), m_height(display_height), m_gfx_op(gfx_op), m_phy_read_index(0), m_phy_write_index(0), m_surface_cnt(1), 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, EXTERNAL_GFX_OP* gfx_op) : 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_gfx_op(gfx_op), m_surface_index(0) +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); @@ -742,7 +742,7 @@ inline int c_display::swipe_surface(c_surface* s0, c_surface* s1, int x0, int x1 } else if (m_color_bytes == 2) { - void(*draw_pixel)(int x, int y, unsigned int rgb) = 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 @@ -759,7 +759,7 @@ inline int c_display::swipe_surface(c_surface* s0, c_surface* s1, int x0, int x1 } else //m_color_bytes == 3/4... { - void(*draw_pixel)(int x, int y, unsigned int rgb) = 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 diff --git a/HelloScroll/UIcode/scroll.h b/HelloScroll/UIcode/scroll.h index 012f80b..4b92a7a 100644 --- a/HelloScroll/UIcode/scroll.h +++ b/HelloScroll/UIcode/scroll.h @@ -25,7 +25,7 @@ public: class mem_display : public c_display { public: - mem_display(void* phy_fb, int display_width, int display_height, c_surface* surface, EXTERNAL_GFX_OP* gfx_op = 0) : c_display(phy_fb, display_width, display_height, surface, gfx_op) {} + 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; } }; diff --git a/HelloSlide/UIcode/GuiLite.h b/HelloSlide/UIcode/GuiLite.h index 1b4611b..80550e1 100644 --- a/HelloSlide/UIcode/GuiLite.h +++ b/HelloSlide/UIcode/GuiLite.h @@ -225,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); @@ -234,8 +234,8 @@ class c_surface; class c_display { friend class c_surface; public: - inline c_display(void* phy_fb, int display_width, int display_height, c_surface* surface, EXTERNAL_GFX_OP* gfx_op = 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, EXTERNAL_GFX_OP* gfx_op = 0);//multiple surface + 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; } @@ -286,9 +286,9 @@ protected: virtual void draw_pixel(int x, int y, unsigned int rgb) { if ((x >= m_width) || (y >= m_height)) { return; } - if (m_gfx_op && m_gfx_op->draw_pixel) + if (m_driver && m_driver->draw_pixel) { - return m_gfx_op->draw_pixel(x, y, rgb); + return m_driver->draw_pixel(x, y, rgb); } if (m_color_bytes == 2) { @@ -301,17 +301,17 @@ protected: } virtual void fill_rect(int x0, int y0, int x1, int y1, unsigned int rgb) { - if (m_gfx_op && m_gfx_op->fill_rect) + if (m_driver && m_driver->fill_rect) { - return m_gfx_op->fill_rect(x0, y0, x1, y1, rgb); + return m_driver->fill_rect(x0, y0, x1, y1, rgb); } - if (m_gfx_op && m_gfx_op->draw_pixel) + if (m_driver && m_driver->draw_pixel) { for (int y = y0; y <= y1; y++) { for (int x = x0; x <= x1; x++) { - m_gfx_op->draw_pixel(x, y, rgb); + m_driver->draw_pixel(x, y, rgb); } } return; @@ -373,9 +373,9 @@ protected: } 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 - struct EXTERNAL_GFX_OP* m_gfx_op; //Rendering by external method + 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]; @@ -682,13 +682,13 @@ protected: int* m_phy_write_index; c_display* m_display; }; -inline c_display::c_display(void* phy_fb, int display_width, int display_height, c_surface* surface, EXTERNAL_GFX_OP* gfx_op) : m_phy_fb(phy_fb), m_width(display_width), m_height(display_height), m_gfx_op(gfx_op), m_phy_read_index(0), m_phy_write_index(0), m_surface_cnt(1), 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, EXTERNAL_GFX_OP* gfx_op) : 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_gfx_op(gfx_op), m_surface_index(0) +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); @@ -742,7 +742,7 @@ inline int c_display::swipe_surface(c_surface* s0, c_surface* s1, int x0, int x1 } else if (m_color_bytes == 2) { - void(*draw_pixel)(int x, int y, unsigned int rgb) = 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 @@ -759,7 +759,7 @@ inline int c_display::swipe_surface(c_surface* s0, c_surface* s1, int x0, int x1 } else //m_color_bytes == 3/4... { - void(*draw_pixel)(int x, int y, unsigned int rgb) = 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 diff --git a/HelloStar/BuildLinux/main.cpp b/HelloStar/BuildLinux/main.cpp index 054b26d..b82c7da 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 GIT binary patch delta 118 zcmccObIE6efQ+;YgC|2ULjZ#hgCj#ELp*~ELl96TjKP&5XtS;iGb3*bLlHwJLm5LV qkhY$z&!M|HOLiX{im={fM;Xz{UMgzbNQx&{tE@!kZ`M~;Wds02qZ?@e delta 114 zcmccQbH!(afQ+mwLj*$zgDXQ2gCBz= m_width) || (y >= m_height)) { return; } - if (m_gfx_op && m_gfx_op->draw_pixel) + if (m_driver && m_driver->draw_pixel) { - return m_gfx_op->draw_pixel(x, y, rgb); + return m_driver->draw_pixel(x, y, rgb); } if (m_color_bytes == 2) { @@ -301,17 +301,17 @@ protected: } virtual void fill_rect(int x0, int y0, int x1, int y1, unsigned int rgb) { - if (m_gfx_op && m_gfx_op->fill_rect) + if (m_driver && m_driver->fill_rect) { - return m_gfx_op->fill_rect(x0, y0, x1, y1, rgb); + return m_driver->fill_rect(x0, y0, x1, y1, rgb); } - if (m_gfx_op && m_gfx_op->draw_pixel) + if (m_driver && m_driver->draw_pixel) { for (int y = y0; y <= y1; y++) { for (int x = x0; x <= x1; x++) { - m_gfx_op->draw_pixel(x, y, rgb); + m_driver->draw_pixel(x, y, rgb); } } return; @@ -373,9 +373,9 @@ protected: } 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 - struct EXTERNAL_GFX_OP* m_gfx_op; //Rendering by external method + 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]; @@ -682,13 +682,13 @@ protected: int* m_phy_write_index; c_display* m_display; }; -inline c_display::c_display(void* phy_fb, int display_width, int display_height, c_surface* surface, EXTERNAL_GFX_OP* gfx_op) : m_phy_fb(phy_fb), m_width(display_width), m_height(display_height), m_gfx_op(gfx_op), m_phy_read_index(0), m_phy_write_index(0), m_surface_cnt(1), 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, EXTERNAL_GFX_OP* gfx_op) : 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_gfx_op(gfx_op), m_surface_index(0) +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); @@ -742,7 +742,7 @@ inline int c_display::swipe_surface(c_surface* s0, c_surface* s1, int x0, int x1 } else if (m_color_bytes == 2) { - void(*draw_pixel)(int x, int y, unsigned int rgb) = 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 @@ -759,7 +759,7 @@ inline int c_display::swipe_surface(c_surface* s0, c_surface* s1, int x0, int x1 } else //m_color_bytes == 3/4... { - void(*draw_pixel)(int x, int y, unsigned int rgb) = 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 diff --git a/HelloStar/UIcode/UIcode.cpp b/HelloStar/UIcode/UIcode.cpp index 6d8045b..6561e15 100644 --- a/HelloStar/UIcode/UIcode.cpp +++ b/HelloStar/UIcode/UIcode.cpp @@ -66,9 +66,9 @@ 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) { +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, gfx_op); + static c_display display(phy_fb, screen_width, screen_height, &surface, driver); s_surface = &surface; s_display = &display; @@ -83,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/main.cpp b/HelloTimer/BuildLinux/main.cpp index 459db98..7305cc0 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 GIT binary patch delta 107 zcmX?9aG+oVm+a&#G6LK#3_%Q@3}Fne3_+XKWtkayQy7XEG8xJkQh~JfWJO{9&1rH+ f*ieM^CI_mDPWDk%<3>`vxmI;C6N-SghPVI#-WwXu delta 127 zcmX?5aHwDdm#nNSLj*$zgDXQ2gCBzX_MKY!>H}T;K>lo5WwKW;K&fk5YOPk5CjwnV{ir1S_}#dDGWsnnG9tNsSHJ% JBN^B8001`r3oZZv delta 58 zcmZpZ>5$o=!>H@Z5Wx__;K~rh;K$&|;KLBl;LhL%6pLr@X9!@>Vo+d6XGmkH0P^!0 L3O0u`uIB*&O?C^3 diff --git a/HelloTimer/BuildSTM32F103-Keil/USER/main.c b/HelloTimer/BuildSTM32F103-Keil/USER/main.c index cb43ed1..b6c0117 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 090da41..d94213b 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 1b4611b..80550e1 100644 --- a/HelloTimer/UIcode/GuiLite.h +++ b/HelloTimer/UIcode/GuiLite.h @@ -225,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); @@ -234,8 +234,8 @@ class c_surface; class c_display { friend class c_surface; public: - inline c_display(void* phy_fb, int display_width, int display_height, c_surface* surface, EXTERNAL_GFX_OP* gfx_op = 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, EXTERNAL_GFX_OP* gfx_op = 0);//multiple surface + 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; } @@ -286,9 +286,9 @@ protected: virtual void draw_pixel(int x, int y, unsigned int rgb) { if ((x >= m_width) || (y >= m_height)) { return; } - if (m_gfx_op && m_gfx_op->draw_pixel) + if (m_driver && m_driver->draw_pixel) { - return m_gfx_op->draw_pixel(x, y, rgb); + return m_driver->draw_pixel(x, y, rgb); } if (m_color_bytes == 2) { @@ -301,17 +301,17 @@ protected: } virtual void fill_rect(int x0, int y0, int x1, int y1, unsigned int rgb) { - if (m_gfx_op && m_gfx_op->fill_rect) + if (m_driver && m_driver->fill_rect) { - return m_gfx_op->fill_rect(x0, y0, x1, y1, rgb); + return m_driver->fill_rect(x0, y0, x1, y1, rgb); } - if (m_gfx_op && m_gfx_op->draw_pixel) + if (m_driver && m_driver->draw_pixel) { for (int y = y0; y <= y1; y++) { for (int x = x0; x <= x1; x++) { - m_gfx_op->draw_pixel(x, y, rgb); + m_driver->draw_pixel(x, y, rgb); } } return; @@ -373,9 +373,9 @@ protected: } 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 - struct EXTERNAL_GFX_OP* m_gfx_op; //Rendering by external method + 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]; @@ -682,13 +682,13 @@ protected: int* m_phy_write_index; c_display* m_display; }; -inline c_display::c_display(void* phy_fb, int display_width, int display_height, c_surface* surface, EXTERNAL_GFX_OP* gfx_op) : m_phy_fb(phy_fb), m_width(display_width), m_height(display_height), m_gfx_op(gfx_op), m_phy_read_index(0), m_phy_write_index(0), m_surface_cnt(1), 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, EXTERNAL_GFX_OP* gfx_op) : 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_gfx_op(gfx_op), m_surface_index(0) +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); @@ -742,7 +742,7 @@ inline int c_display::swipe_surface(c_surface* s0, c_surface* s1, int x0, int x1 } else if (m_color_bytes == 2) { - void(*draw_pixel)(int x, int y, unsigned int rgb) = 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 @@ -759,7 +759,7 @@ inline int c_display::swipe_surface(c_surface* s0, c_surface* s1, int x0, int x1 } else //m_color_bytes == 3/4... { - void(*draw_pixel)(int x, int y, unsigned int rgb) = 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 diff --git a/HelloTimer/UIcode/UIcode.cpp b/HelloTimer/UIcode/UIcode.cpp index 1535989..ee12858 100644 --- a/HelloTimer/UIcode/UIcode.cpp +++ b/HelloTimer/UIcode/UIcode.cpp @@ -302,12 +302,12 @@ 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(); 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, gfx_op); + static c_display display(phy_fb, screen_width, screen_height, &surface, driver); s_surface = &surface; s_display = &display; @@ -323,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/UIcode/GuiLite.h b/HelloTransparent/UIcode/GuiLite.h index 1b4611b..80550e1 100644 --- a/HelloTransparent/UIcode/GuiLite.h +++ b/HelloTransparent/UIcode/GuiLite.h @@ -225,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); @@ -234,8 +234,8 @@ class c_surface; class c_display { friend class c_surface; public: - inline c_display(void* phy_fb, int display_width, int display_height, c_surface* surface, EXTERNAL_GFX_OP* gfx_op = 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, EXTERNAL_GFX_OP* gfx_op = 0);//multiple surface + 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; } @@ -286,9 +286,9 @@ protected: virtual void draw_pixel(int x, int y, unsigned int rgb) { if ((x >= m_width) || (y >= m_height)) { return; } - if (m_gfx_op && m_gfx_op->draw_pixel) + if (m_driver && m_driver->draw_pixel) { - return m_gfx_op->draw_pixel(x, y, rgb); + return m_driver->draw_pixel(x, y, rgb); } if (m_color_bytes == 2) { @@ -301,17 +301,17 @@ protected: } virtual void fill_rect(int x0, int y0, int x1, int y1, unsigned int rgb) { - if (m_gfx_op && m_gfx_op->fill_rect) + if (m_driver && m_driver->fill_rect) { - return m_gfx_op->fill_rect(x0, y0, x1, y1, rgb); + return m_driver->fill_rect(x0, y0, x1, y1, rgb); } - if (m_gfx_op && m_gfx_op->draw_pixel) + if (m_driver && m_driver->draw_pixel) { for (int y = y0; y <= y1; y++) { for (int x = x0; x <= x1; x++) { - m_gfx_op->draw_pixel(x, y, rgb); + m_driver->draw_pixel(x, y, rgb); } } return; @@ -373,9 +373,9 @@ protected: } 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 - struct EXTERNAL_GFX_OP* m_gfx_op; //Rendering by external method + 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]; @@ -682,13 +682,13 @@ protected: int* m_phy_write_index; c_display* m_display; }; -inline c_display::c_display(void* phy_fb, int display_width, int display_height, c_surface* surface, EXTERNAL_GFX_OP* gfx_op) : m_phy_fb(phy_fb), m_width(display_width), m_height(display_height), m_gfx_op(gfx_op), m_phy_read_index(0), m_phy_write_index(0), m_surface_cnt(1), 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, EXTERNAL_GFX_OP* gfx_op) : 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_gfx_op(gfx_op), m_surface_index(0) +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); @@ -742,7 +742,7 @@ inline int c_display::swipe_surface(c_surface* s0, c_surface* s1, int x0, int x1 } else if (m_color_bytes == 2) { - void(*draw_pixel)(int x, int y, unsigned int rgb) = 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 @@ -759,7 +759,7 @@ inline int c_display::swipe_surface(c_surface* s0, c_surface* s1, int x0, int x1 } else //m_color_bytes == 3/4... { - void(*draw_pixel)(int x, int y, unsigned int rgb) = 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 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 f3f74f8..ac32fcd 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/main.cpp b/HelloWave/BuildLinux/main.cpp index 93fdbea..94b23db 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 GIT binary patch delta 129 zcmbQ_*Wa_!G|H9!JWYkC>GD)&k(R#TZWmDH=QAkp#mt7 x&rrZ%J(*EKcXNj9J~nP7;mL+7wkZ5cm6a%bUDer)ypva|1x}Vwn*?Sh0{}+8A07Yz diff --git a/HelloWave/BuildMFC/HelloWaveDlg.h b/HelloWave/BuildMFC/HelloWaveDlg.h index 2586cd5bf73ac2e570ba60a5ec59f2879a506d6d..d365fecfcc7bc9e00953b0c3bcdf87804094edba 100644 GIT binary patch delta 56 zcmZn=`zN|VgHhXs!IL4FA%MY$!I2@7A)dj7AqXfE#^4I1wHOo_QW%ODG8xJkQW=Ui Jhcd3_1OQ6v3xWUu delta 58 zcmew-+90+;gHhL&A%Y=a_!G|H9!JWYkC>GD)&k(?%#h}2D&XC4X0p#a1 L6l@M=T+ImpV;&3L diff --git a/HelloWave/BuildSTM32F103-Keil/USER/main.c b/HelloWave/BuildSTM32F103-Keil/USER/main.c index 3112316..85e1c90 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 9f36910..7cb5bb4 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 1b4611b..80550e1 100644 --- a/HelloWave/UIcode/GuiLite.h +++ b/HelloWave/UIcode/GuiLite.h @@ -225,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); @@ -234,8 +234,8 @@ class c_surface; class c_display { friend class c_surface; public: - inline c_display(void* phy_fb, int display_width, int display_height, c_surface* surface, EXTERNAL_GFX_OP* gfx_op = 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, EXTERNAL_GFX_OP* gfx_op = 0);//multiple surface + 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; } @@ -286,9 +286,9 @@ protected: virtual void draw_pixel(int x, int y, unsigned int rgb) { if ((x >= m_width) || (y >= m_height)) { return; } - if (m_gfx_op && m_gfx_op->draw_pixel) + if (m_driver && m_driver->draw_pixel) { - return m_gfx_op->draw_pixel(x, y, rgb); + return m_driver->draw_pixel(x, y, rgb); } if (m_color_bytes == 2) { @@ -301,17 +301,17 @@ protected: } virtual void fill_rect(int x0, int y0, int x1, int y1, unsigned int rgb) { - if (m_gfx_op && m_gfx_op->fill_rect) + if (m_driver && m_driver->fill_rect) { - return m_gfx_op->fill_rect(x0, y0, x1, y1, rgb); + return m_driver->fill_rect(x0, y0, x1, y1, rgb); } - if (m_gfx_op && m_gfx_op->draw_pixel) + if (m_driver && m_driver->draw_pixel) { for (int y = y0; y <= y1; y++) { for (int x = x0; x <= x1; x++) { - m_gfx_op->draw_pixel(x, y, rgb); + m_driver->draw_pixel(x, y, rgb); } } return; @@ -373,9 +373,9 @@ protected: } 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 - struct EXTERNAL_GFX_OP* m_gfx_op; //Rendering by external method + 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]; @@ -682,13 +682,13 @@ protected: int* m_phy_write_index; c_display* m_display; }; -inline c_display::c_display(void* phy_fb, int display_width, int display_height, c_surface* surface, EXTERNAL_GFX_OP* gfx_op) : m_phy_fb(phy_fb), m_width(display_width), m_height(display_height), m_gfx_op(gfx_op), m_phy_read_index(0), m_phy_write_index(0), m_surface_cnt(1), 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, EXTERNAL_GFX_OP* gfx_op) : 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_gfx_op(gfx_op), m_surface_index(0) +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); @@ -742,7 +742,7 @@ inline int c_display::swipe_surface(c_surface* s0, c_surface* s1, int x0, int x1 } else if (m_color_bytes == 2) { - void(*draw_pixel)(int x, int y, unsigned int rgb) = 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 @@ -759,7 +759,7 @@ inline int c_display::swipe_surface(c_surface* s0, c_surface* s1, int x0, int x1 } else //m_color_bytes == 3/4... { - void(*draw_pixel)(int x, int y, unsigned int rgb) = 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 diff --git a/HelloWave/UIcode/UIcode.cpp b/HelloWave/UIcode/UIcode.cpp index 62d4c5b..9adcdc5 100644 --- a/HelloWave/UIcode/UIcode.cpp +++ b/HelloWave/UIcode/UIcode.cpp @@ -130,12 +130,12 @@ 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(); 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, gfx_op); + static c_display display(phy_fb, screen_width, screen_height, &surface, driver); s_surface = &surface; s_display = &display; @@ -166,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/UIcode/GuiLite.h b/HelloWidgets/UIcode/GuiLite.h index 1b4611b..80550e1 100644 --- a/HelloWidgets/UIcode/GuiLite.h +++ b/HelloWidgets/UIcode/GuiLite.h @@ -225,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); @@ -234,8 +234,8 @@ class c_surface; class c_display { friend class c_surface; public: - inline c_display(void* phy_fb, int display_width, int display_height, c_surface* surface, EXTERNAL_GFX_OP* gfx_op = 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, EXTERNAL_GFX_OP* gfx_op = 0);//multiple surface + 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; } @@ -286,9 +286,9 @@ protected: virtual void draw_pixel(int x, int y, unsigned int rgb) { if ((x >= m_width) || (y >= m_height)) { return; } - if (m_gfx_op && m_gfx_op->draw_pixel) + if (m_driver && m_driver->draw_pixel) { - return m_gfx_op->draw_pixel(x, y, rgb); + return m_driver->draw_pixel(x, y, rgb); } if (m_color_bytes == 2) { @@ -301,17 +301,17 @@ protected: } virtual void fill_rect(int x0, int y0, int x1, int y1, unsigned int rgb) { - if (m_gfx_op && m_gfx_op->fill_rect) + if (m_driver && m_driver->fill_rect) { - return m_gfx_op->fill_rect(x0, y0, x1, y1, rgb); + return m_driver->fill_rect(x0, y0, x1, y1, rgb); } - if (m_gfx_op && m_gfx_op->draw_pixel) + if (m_driver && m_driver->draw_pixel) { for (int y = y0; y <= y1; y++) { for (int x = x0; x <= x1; x++) { - m_gfx_op->draw_pixel(x, y, rgb); + m_driver->draw_pixel(x, y, rgb); } } return; @@ -373,9 +373,9 @@ protected: } 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 - struct EXTERNAL_GFX_OP* m_gfx_op; //Rendering by external method + 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]; @@ -682,13 +682,13 @@ protected: int* m_phy_write_index; c_display* m_display; }; -inline c_display::c_display(void* phy_fb, int display_width, int display_height, c_surface* surface, EXTERNAL_GFX_OP* gfx_op) : m_phy_fb(phy_fb), m_width(display_width), m_height(display_height), m_gfx_op(gfx_op), m_phy_read_index(0), m_phy_write_index(0), m_surface_cnt(1), 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, EXTERNAL_GFX_OP* gfx_op) : 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_gfx_op(gfx_op), m_surface_index(0) +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); @@ -742,7 +742,7 @@ inline int c_display::swipe_surface(c_surface* s0, c_surface* s1, int x0, int x1 } else if (m_color_bytes == 2) { - void(*draw_pixel)(int x, int y, unsigned int rgb) = 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 @@ -759,7 +759,7 @@ inline int c_display::swipe_surface(c_surface* s0, c_surface* s1, int x0, int x1 } else //m_color_bytes == 3/4... { - void(*draw_pixel)(int x, int y, unsigned int rgb) = 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 diff --git a/HelloWindows/UIcode/GuiLite.h b/HelloWindows/UIcode/GuiLite.h index 1b4611b..80550e1 100644 --- a/HelloWindows/UIcode/GuiLite.h +++ b/HelloWindows/UIcode/GuiLite.h @@ -225,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); @@ -234,8 +234,8 @@ class c_surface; class c_display { friend class c_surface; public: - inline c_display(void* phy_fb, int display_width, int display_height, c_surface* surface, EXTERNAL_GFX_OP* gfx_op = 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, EXTERNAL_GFX_OP* gfx_op = 0);//multiple surface + 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; } @@ -286,9 +286,9 @@ protected: virtual void draw_pixel(int x, int y, unsigned int rgb) { if ((x >= m_width) || (y >= m_height)) { return; } - if (m_gfx_op && m_gfx_op->draw_pixel) + if (m_driver && m_driver->draw_pixel) { - return m_gfx_op->draw_pixel(x, y, rgb); + return m_driver->draw_pixel(x, y, rgb); } if (m_color_bytes == 2) { @@ -301,17 +301,17 @@ protected: } virtual void fill_rect(int x0, int y0, int x1, int y1, unsigned int rgb) { - if (m_gfx_op && m_gfx_op->fill_rect) + if (m_driver && m_driver->fill_rect) { - return m_gfx_op->fill_rect(x0, y0, x1, y1, rgb); + return m_driver->fill_rect(x0, y0, x1, y1, rgb); } - if (m_gfx_op && m_gfx_op->draw_pixel) + if (m_driver && m_driver->draw_pixel) { for (int y = y0; y <= y1; y++) { for (int x = x0; x <= x1; x++) { - m_gfx_op->draw_pixel(x, y, rgb); + m_driver->draw_pixel(x, y, rgb); } } return; @@ -373,9 +373,9 @@ protected: } 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 - struct EXTERNAL_GFX_OP* m_gfx_op; //Rendering by external method + 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]; @@ -682,13 +682,13 @@ protected: int* m_phy_write_index; c_display* m_display; }; -inline c_display::c_display(void* phy_fb, int display_width, int display_height, c_surface* surface, EXTERNAL_GFX_OP* gfx_op) : m_phy_fb(phy_fb), m_width(display_width), m_height(display_height), m_gfx_op(gfx_op), m_phy_read_index(0), m_phy_write_index(0), m_surface_cnt(1), 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, EXTERNAL_GFX_OP* gfx_op) : 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_gfx_op(gfx_op), m_surface_index(0) +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); @@ -742,7 +742,7 @@ inline int c_display::swipe_surface(c_surface* s0, c_surface* s1, int x0, int x1 } else if (m_color_bytes == 2) { - void(*draw_pixel)(int x, int y, unsigned int rgb) = 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 @@ -759,7 +759,7 @@ inline int c_display::swipe_surface(c_surface* s0, c_surface* s1, int x0, int x1 } else //m_color_bytes == 3/4... { - void(*draw_pixel)(int x, int y, unsigned int rgb) = 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 diff --git a/HostMonitor/UIcode/include/GuiLite.h b/HostMonitor/UIcode/include/GuiLite.h index 1b4611b..80550e1 100644 --- a/HostMonitor/UIcode/include/GuiLite.h +++ b/HostMonitor/UIcode/include/GuiLite.h @@ -225,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); @@ -234,8 +234,8 @@ class c_surface; class c_display { friend class c_surface; public: - inline c_display(void* phy_fb, int display_width, int display_height, c_surface* surface, EXTERNAL_GFX_OP* gfx_op = 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, EXTERNAL_GFX_OP* gfx_op = 0);//multiple surface + 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; } @@ -286,9 +286,9 @@ protected: virtual void draw_pixel(int x, int y, unsigned int rgb) { if ((x >= m_width) || (y >= m_height)) { return; } - if (m_gfx_op && m_gfx_op->draw_pixel) + if (m_driver && m_driver->draw_pixel) { - return m_gfx_op->draw_pixel(x, y, rgb); + return m_driver->draw_pixel(x, y, rgb); } if (m_color_bytes == 2) { @@ -301,17 +301,17 @@ protected: } virtual void fill_rect(int x0, int y0, int x1, int y1, unsigned int rgb) { - if (m_gfx_op && m_gfx_op->fill_rect) + if (m_driver && m_driver->fill_rect) { - return m_gfx_op->fill_rect(x0, y0, x1, y1, rgb); + return m_driver->fill_rect(x0, y0, x1, y1, rgb); } - if (m_gfx_op && m_gfx_op->draw_pixel) + if (m_driver && m_driver->draw_pixel) { for (int y = y0; y <= y1; y++) { for (int x = x0; x <= x1; x++) { - m_gfx_op->draw_pixel(x, y, rgb); + m_driver->draw_pixel(x, y, rgb); } } return; @@ -373,9 +373,9 @@ protected: } 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 - struct EXTERNAL_GFX_OP* m_gfx_op; //Rendering by external method + 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]; @@ -682,13 +682,13 @@ protected: int* m_phy_write_index; c_display* m_display; }; -inline c_display::c_display(void* phy_fb, int display_width, int display_height, c_surface* surface, EXTERNAL_GFX_OP* gfx_op) : m_phy_fb(phy_fb), m_width(display_width), m_height(display_height), m_gfx_op(gfx_op), m_phy_read_index(0), m_phy_write_index(0), m_surface_cnt(1), 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, EXTERNAL_GFX_OP* gfx_op) : 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_gfx_op(gfx_op), m_surface_index(0) +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); @@ -742,7 +742,7 @@ inline int c_display::swipe_surface(c_surface* s0, c_surface* s1, int x0, int x1 } else if (m_color_bytes == 2) { - void(*draw_pixel)(int x, int y, unsigned int rgb) = 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 @@ -759,7 +759,7 @@ inline int c_display::swipe_surface(c_surface* s0, c_surface* s1, int x0, int x1 } else //m_color_bytes == 3/4... { - void(*draw_pixel)(int x, int y, unsigned int rgb) = 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 -- Gitee