mirror of
https://gitee.com/idea4good/GuiLite.git
synced 2026-04-13 09:18:04 +08:00
refactor display, surface; get_frame_buffer will return NULL if no UI update
This commit is contained in:
@@ -7,6 +7,7 @@ class c_hid_pipe;
|
||||
class c_surface;
|
||||
|
||||
class c_display {
|
||||
friend class c_surface;
|
||||
public:
|
||||
c_display(void* phy_fb, unsigned int display_width, unsigned int display_height,
|
||||
unsigned int surface_width, unsigned int surface_height,
|
||||
@@ -16,13 +17,15 @@ public:
|
||||
unsigned int get_width() { return m_width; }
|
||||
unsigned int get_height() { return m_height; }
|
||||
|
||||
void* get_frame_buffer(int* width, int* height);
|
||||
void* get_updated_fb(int* width, int* height, bool force_update = false);
|
||||
int snap_shot(const char* file_name);
|
||||
private:
|
||||
unsigned int m_width; //in pixels
|
||||
unsigned int m_height; //in pixels
|
||||
unsigned int m_color_bytes; //16 bits, 32 bits only
|
||||
void* m_phy_fb;
|
||||
int m_phy_read_index;
|
||||
int m_phy_write_index;
|
||||
c_surface* m_surface_group[SURFACE_CNT_MAX];
|
||||
unsigned int m_surface_cnt;
|
||||
};
|
||||
|
||||
@@ -46,7 +46,7 @@ protected:
|
||||
|
||||
void set_surface(void* wnd_root, Z_ORDER_LEVEL max_z_order);
|
||||
int copy_layer_pixel_2_fb(int x, int y, unsigned int z_order);
|
||||
c_surface(c_display* display, void* phy_fb, unsigned int width, unsigned int height, unsigned int color_bytes);
|
||||
c_surface(c_display* display, unsigned int width, unsigned int height, unsigned int color_bytes);
|
||||
int m_width; //in pixels
|
||||
int m_height; //in pixels
|
||||
int m_color_bytes; //16 bits, 32 bits only
|
||||
@@ -57,13 +57,14 @@ protected:
|
||||
Z_ORDER_LEVEL m_max_zorder;
|
||||
Z_ORDER_LEVEL m_top_zorder;
|
||||
void* m_phy_fb;
|
||||
int* m_phy_write_index;
|
||||
c_display* m_display;
|
||||
};
|
||||
|
||||
class c_surface_16bits : public c_surface {
|
||||
friend class c_display;
|
||||
c_surface_16bits(c_display* display, void* phy_fb, unsigned int width, unsigned int height, unsigned int color_bytes) :
|
||||
c_surface(display, phy_fb, width, height, color_bytes) {};
|
||||
c_surface_16bits(c_display* display, unsigned int width, unsigned int height, unsigned int color_bytes) :
|
||||
c_surface(display, width, height, color_bytes) {};
|
||||
virtual void draw_pixel(int x, int y, unsigned int rgb, unsigned int z_order);
|
||||
virtual void fill_rect(int x0, int y0, int x1, int y1, unsigned int rgb, unsigned int z_order);
|
||||
virtual void fill_rect_on_fb(int x0, int y0, int x1, int y1, unsigned int rgb);
|
||||
|
||||
@@ -22,6 +22,7 @@ c_display::c_display(void* phy_fb, unsigned int display_width, unsigned int disp
|
||||
m_height = display_height;
|
||||
m_color_bytes = color_bytes;
|
||||
m_phy_fb = phy_fb;
|
||||
m_phy_read_index = m_phy_write_index = 0;
|
||||
|
||||
m_surface_cnt = surface_cnt;
|
||||
if (m_surface_cnt > SURFACE_CNT_MAX)
|
||||
@@ -31,8 +32,8 @@ c_display::c_display(void* phy_fb, unsigned int display_width, unsigned int disp
|
||||
memset(m_surface_group, 0, sizeof(m_surface_group));
|
||||
for (int i = 0; i < m_surface_cnt; i++)
|
||||
{
|
||||
m_surface_group[i] = (color_bytes == 4) ? new c_surface(this, m_phy_fb, surface_width, surface_height, color_bytes) :
|
||||
new c_surface_16bits(this, m_phy_fb, surface_width, surface_height, color_bytes);
|
||||
m_surface_group[i] = (color_bytes == 4) ? new c_surface(this, surface_width, surface_height, color_bytes) :
|
||||
new c_surface_16bits(this, surface_width, surface_height, color_bytes);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -75,7 +76,7 @@ int c_display::merge_surface(c_surface* s0, c_surface* s1, int x0, int x1, int y
|
||||
int surface_width = s0->get_width();
|
||||
int surface_height = s0->get_height();
|
||||
|
||||
if (offset < 0 || offset >= surface_width || y0 < 0 || y0 >= surface_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)
|
||||
{
|
||||
ASSERT(FALSE);
|
||||
@@ -83,7 +84,7 @@ int c_display::merge_surface(c_surface* s0, c_surface* s1, int x0, int x1, int y
|
||||
}
|
||||
|
||||
int width = (x1 - x0 + 1);
|
||||
if (width < 0 || width >= surface_width || width < offset)
|
||||
if (width < 0 || width > surface_width || width < offset)
|
||||
{
|
||||
ASSERT(FALSE);
|
||||
return -1;
|
||||
@@ -104,16 +105,26 @@ int c_display::merge_surface(c_surface* s0, c_surface* s1, int x0, int x1, int y
|
||||
addr_d = ((char*)(m_phy_fb) + (y * m_width + x0 + (width - offset)) * m_color_bytes);
|
||||
memcpy(addr_d, addr_s, offset * m_color_bytes);
|
||||
}
|
||||
m_phy_write_index++;
|
||||
return 0;
|
||||
}
|
||||
|
||||
void* c_display::get_frame_buffer(int* width, int* height)
|
||||
void* c_display::get_updated_fb(int* width, int* height, bool force_update)
|
||||
{
|
||||
if (width && height)
|
||||
{
|
||||
*width = get_width();
|
||||
*height = get_height();
|
||||
}
|
||||
if (force_update)
|
||||
{
|
||||
return m_phy_fb;
|
||||
}
|
||||
if (m_phy_read_index == m_phy_write_index)
|
||||
{//No update
|
||||
return NULL;
|
||||
}
|
||||
m_phy_read_index = m_phy_write_index;
|
||||
return m_phy_fb;
|
||||
}
|
||||
|
||||
|
||||
@@ -8,13 +8,14 @@
|
||||
#include <string.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
c_surface::c_surface(c_display* display, void* phy_fb, unsigned int width, unsigned int height, unsigned int color_bytes)
|
||||
c_surface::c_surface(c_display* display, unsigned int width, unsigned int height, unsigned int color_bytes)
|
||||
{
|
||||
m_width = width;
|
||||
m_height = height;
|
||||
m_color_bytes = color_bytes;
|
||||
m_display = display;
|
||||
m_phy_fb = phy_fb;
|
||||
m_phy_fb = display->m_phy_fb;
|
||||
m_phy_write_index = &display->m_phy_write_index;
|
||||
m_fb = m_usr = NULL;
|
||||
m_top_zorder = m_max_zorder = Z_ORDER_LEVEL_0;
|
||||
m_is_active = false;
|
||||
@@ -94,6 +95,7 @@ void c_surface::set_pixel(int x, int y, unsigned int rgb)
|
||||
if (m_is_active && (x < display_width) && (y < display_height))
|
||||
{
|
||||
((unsigned int*)m_phy_fb)[y * (m_display->get_width()) + x] = rgb;
|
||||
*m_phy_write_index = *m_phy_write_index + 1;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -143,6 +145,7 @@ void c_surface::fill_rect_on_fb(int x0, int y0, int x1, int y1, unsigned int rgb
|
||||
x = x0;
|
||||
fb = &((unsigned int*)m_fb)[y0 * m_width + x];
|
||||
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++ = rgb;
|
||||
@@ -361,6 +364,7 @@ int c_surface::copy_layer_pixel_2_fb(int x, int y, unsigned int z_order)
|
||||
if (m_is_active && (x < display_width) && (y < display_height))
|
||||
{
|
||||
((unsigned int*)m_phy_fb)[y * display_width + x] = rgb;
|
||||
*m_phy_write_index = *m_phy_write_index + 1;
|
||||
}
|
||||
}
|
||||
else//16 bits
|
||||
@@ -370,6 +374,7 @@ int c_surface::copy_layer_pixel_2_fb(int x, int y, unsigned int z_order)
|
||||
if (m_is_active && (x < display_width) && (y < display_height))
|
||||
{
|
||||
((short*)m_phy_fb)[y * display_width + x] = rgb;
|
||||
*m_phy_write_index = *m_phy_write_index + 1;
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
@@ -435,6 +440,7 @@ int c_surface::flush_scrren(int left, int top, int right, int bottom)
|
||||
void* d_addr = (char*)m_phy_fb + ((y * display_width + left) * m_color_bytes);
|
||||
memcpy(d_addr, s_addr, (right - left) * m_color_bytes);
|
||||
}
|
||||
*m_phy_write_index = *m_phy_write_index + 1;
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -514,6 +520,7 @@ void c_surface_16bits::set_pixel(int x, int y, unsigned int rgb)
|
||||
if (m_is_active && (x < display_width) && (y < display_height))
|
||||
{
|
||||
((unsigned short*)m_phy_fb)[y * (m_display->get_width()) + x] = rgb;
|
||||
*m_phy_write_index = *m_phy_write_index + 1;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -562,6 +569,7 @@ void c_surface_16bits::fill_rect_on_fb(int x0, int y0, int x1, int y1, unsigned
|
||||
x = x0;
|
||||
fb = &((unsigned short*)m_fb)[y0 * m_width + x];
|
||||
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++ = rgb;
|
||||
|
||||
Reference in New Issue
Block a user