mirror of
https://gitee.com/idea4good/GuiLite.git
synced 2025-01-29 17:22:55 +08:00
refactor surface.cpp
This commit is contained in:
parent
c065620203
commit
3d58ef1c3f
@ -8,7 +8,7 @@
|
|||||||
***
|
***
|
||||||
## GuiLite是什么鬼?
|
## GuiLite是什么鬼?
|
||||||
- GuiLite(超轻量UI框架)是5千行代码的**全平台UI框架**,可以完美运行在iOS,Android,Windows(包含VR),Mac,和**市面所有的 ARM Linux物联网终端设备**上。
|
- GuiLite(超轻量UI框架)是5千行代码的**全平台UI框架**,可以完美运行在iOS,Android,Windows(包含VR),Mac,和**市面所有的 ARM Linux物联网终端设备**上。
|
||||||
- GuiLite与操作系统无关,甚至也可以运行在无OS的单片机环境。
|
- GuiLite与操作系统及第三方图形库无关,甚至也可以运行在无OS的单片机环境。
|
||||||
- GuiLite可以嵌入在iOS、Android、MFC、QT等其他UI系统中,让你的界面集百家之长,又不失个性。
|
- GuiLite可以嵌入在iOS、Android、MFC、QT等其他UI系统中,让你的界面集百家之长,又不失个性。
|
||||||
- GuiLite鼓励混合编程,开发者可以用GuiLite接管UI部分,用Swift,Java,Go,C#,Python开发业务部分。
|
- GuiLite鼓励混合编程,开发者可以用GuiLite接管UI部分,用Swift,Java,Go,C#,Python开发业务部分。
|
||||||
- ⚠️不鼓励大家全盘接受GuiLite,更愿意大家掌握UI的核心原理
|
- ⚠️不鼓励大家全盘接受GuiLite,更愿意大家掌握UI的核心原理
|
||||||
|
@ -1,9 +1,11 @@
|
|||||||
#ifndef GAL_H
|
#ifndef GAL_H
|
||||||
#define GAL_H
|
#define GAL_H
|
||||||
|
|
||||||
struct FRAME_LAYER
|
class c_frame_layer
|
||||||
{
|
{
|
||||||
void* fb;
|
public:
|
||||||
|
c_frame_layer() { fb = NULL;}
|
||||||
|
unsigned short* fb;
|
||||||
c_rect rect;
|
c_rect rect;
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -27,7 +29,7 @@ class c_surface {
|
|||||||
public:
|
public:
|
||||||
virtual void draw_pixel(int x, int y, unsigned int rgb, unsigned int z_order);
|
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(int x0, int y0, int x1, int y1, unsigned int rgb, unsigned int z_order);
|
||||||
virtual unsigned int get_pixel(int x, int y, unsigned int z_order);
|
unsigned int get_pixel(int x, int y, unsigned int z_order);
|
||||||
|
|
||||||
int get_width() { return m_width; }
|
int get_width() { return m_width; }
|
||||||
int get_height() { return m_height; }
|
int get_height() { return m_height; }
|
||||||
@ -45,14 +47,14 @@ public:
|
|||||||
void set_active(bool flag){m_is_active = flag;}
|
void set_active(bool flag){m_is_active = flag;}
|
||||||
protected:
|
protected:
|
||||||
virtual void fill_rect_on_fb(int x0, int y0, int x1, int y1, unsigned int rgb);
|
virtual void fill_rect_on_fb(int x0, int y0, int x1, int y1, unsigned int rgb);
|
||||||
virtual void set_pixel(int x, int y, unsigned int rgb);
|
virtual void draw_pixel_on_fb(int x, int y, unsigned int rgb);
|
||||||
virtual void set_surface(void* wnd_root, Z_ORDER_LEVEL max_z_order);
|
void set_surface(void* wnd_root, Z_ORDER_LEVEL max_z_order);
|
||||||
c_surface(c_display* display, unsigned int width, unsigned int height, unsigned int color_bytes, struct EXTERNAL_GFX_OP* gfx_op);
|
c_surface(c_display* display, unsigned int width, unsigned int height, unsigned int color_bytes);
|
||||||
int m_width; //in pixels
|
int m_width; //in pixels
|
||||||
int m_height; //in pixels
|
int m_height; //in pixels
|
||||||
int m_color_bytes; //16 bits, 32 bits only
|
int m_color_bytes; //16 bits, 32 bits only
|
||||||
void* m_fb;
|
void* m_fb; //Top frame buffer you could see
|
||||||
struct FRAME_LAYER m_frame_layers[Z_ORDER_LEVEL_MAX];
|
c_frame_layer m_frame_layers[Z_ORDER_LEVEL_MAX];//Top layber fb always be NULL
|
||||||
void* m_usr;
|
void* m_usr;
|
||||||
bool m_is_active;
|
bool m_is_active;
|
||||||
Z_ORDER_LEVEL m_max_zorder;
|
Z_ORDER_LEVEL m_max_zorder;
|
||||||
@ -60,32 +62,16 @@ protected:
|
|||||||
void* m_phy_fb;
|
void* m_phy_fb;
|
||||||
int* m_phy_write_index;
|
int* m_phy_write_index;
|
||||||
c_display* m_display;
|
c_display* m_display;
|
||||||
struct EXTERNAL_GFX_OP* m_gfx_op;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
class c_surface_16bits : public c_surface {
|
class c_surface_no_fb : public c_surface {//No physical framebuffer, memory fb is 32 bits
|
||||||
friend class c_display;
|
friend class c_display;
|
||||||
c_surface_16bits(c_display* display, unsigned int width, unsigned int height, unsigned int color_bytes, struct EXTERNAL_GFX_OP* gfx_op) :
|
c_surface_no_fb(c_display* display, unsigned int width, unsigned int height, unsigned int color_bytes, struct EXTERNAL_GFX_OP* gfx_op) :
|
||||||
c_surface(display, width, height, color_bytes, gfx_op) {};
|
c_surface(display, width, height, color_bytes) {m_gfx_op = gfx_op;}
|
||||||
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);
|
|
||||||
virtual unsigned int get_pixel(int x, int y, unsigned int z_order);
|
|
||||||
protected:
|
protected:
|
||||||
virtual void set_pixel(int x, int y, unsigned int rgb);
|
virtual void fill_rect_on_fb(int x0, int y0, int x1, int y1, unsigned int rgb);
|
||||||
|
virtual void draw_pixel_on_fb(int x, int y, unsigned int rgb);
|
||||||
|
struct EXTERNAL_GFX_OP* m_gfx_op;//Rendering by external method
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
class c_surface_mcu : public c_surface {
|
|
||||||
friend class c_display;
|
|
||||||
c_surface_mcu(c_display* display, unsigned int width, unsigned int height, unsigned int color_bytes, struct EXTERNAL_GFX_OP* gfx_op) :
|
|
||||||
c_surface(display, width, height, color_bytes, gfx_op) {};
|
|
||||||
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);
|
|
||||||
virtual unsigned int get_pixel(int x, int y, unsigned int z_order);
|
|
||||||
protected:
|
|
||||||
virtual void set_pixel(int x, int y, unsigned int rgb);
|
|
||||||
virtual void set_surface(void* wnd_root, Z_ORDER_LEVEL max_z_order);
|
|
||||||
};
|
|
||||||
#endif
|
#endif
|
||||||
|
@ -26,16 +26,10 @@ c_display::c_display(void* phy_fb, unsigned int display_width, unsigned int disp
|
|||||||
memset(m_surface_group, 0, sizeof(m_surface_group));
|
memset(m_surface_group, 0, sizeof(m_surface_group));
|
||||||
m_surface_cnt = surface_cnt;
|
m_surface_cnt = surface_cnt;
|
||||||
ASSERT(m_surface_cnt <= SURFACE_CNT_MAX);
|
ASSERT(m_surface_cnt <= SURFACE_CNT_MAX);
|
||||||
if (!phy_fb)
|
|
||||||
{
|
|
||||||
ASSERT(m_surface_cnt == 1);
|
|
||||||
m_surface_group[0] = new c_surface_mcu(this, surface_width, surface_height, color_bytes, gfx_op);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
for (int i = 0; i < m_surface_cnt; i++)
|
for (int i = 0; i < m_surface_cnt; i++)
|
||||||
{
|
{
|
||||||
m_surface_group[i] = (color_bytes == 4) ? new c_surface(this, surface_width, surface_height, color_bytes , gfx_op) :
|
m_surface_group[i] = phy_fb ? new c_surface(this, surface_width, surface_height, color_bytes) : new c_surface_no_fb(this, surface_width, surface_height, color_bytes, gfx_op);
|
||||||
new c_surface_16bits(this, surface_width, surface_height, color_bytes, gfx_op);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -93,6 +87,9 @@ int c_display::merge_surface(c_surface* s0, c_surface* s1, int x0, int x1, int y
|
|||||||
x1 = (x1 >= m_width) ? (m_width - 1) : x1;
|
x1 = (x1 >= m_width) ? (m_width - 1) : x1;
|
||||||
y0 = (y0 >= m_height) ? (m_height - 1) : y0;
|
y0 = (y0 >= m_height) ? (m_height - 1) : y0;
|
||||||
y1 = (y1 >= m_height) ? (m_height - 1) : y1;
|
y1 = (y1 >= m_height) ? (m_height - 1) : y1;
|
||||||
|
|
||||||
|
if (m_phy_fb)
|
||||||
|
{
|
||||||
for (int y = y0; y <= y1; y++)
|
for (int y = y0; y <= y1; y++)
|
||||||
{
|
{
|
||||||
//Left surface
|
//Left surface
|
||||||
@ -104,6 +101,42 @@ 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);
|
addr_d = ((char*)(m_phy_fb)+(y * m_width + x0 + (width - offset)) * m_color_bytes);
|
||||||
memcpy(addr_d, addr_s, 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;
|
||||||
|
for (int y = y0; y <= y1; y++)
|
||||||
|
{
|
||||||
|
//Left surface
|
||||||
|
for (int x = x0; x <= (x1 - offset); x++)
|
||||||
|
{
|
||||||
|
draw_pixel(x, y, ((unsigned int*)s0->m_fb)[y * m_width + x + offset]);
|
||||||
|
}
|
||||||
|
//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]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
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;
|
||||||
|
for (int y = y0; y <= y1; y++)
|
||||||
|
{
|
||||||
|
//Left surface
|
||||||
|
for (int x = x0; x <= (x1 - offset); x++)
|
||||||
|
{
|
||||||
|
draw_pixel(x, y, GL_RGB_16_to_32(((unsigned short*)s0->m_fb)[y * m_width + x + offset]));
|
||||||
|
}
|
||||||
|
//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]));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
m_phy_write_index++;
|
m_phy_write_index++;
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
@ -8,7 +8,9 @@
|
|||||||
#include <string.h>
|
#include <string.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
|
|
||||||
c_surface::c_surface(c_display* display, unsigned int width, unsigned int height, unsigned int color_bytes, struct EXTERNAL_GFX_OP* gfx_op)
|
#define GL_ROUND_RGB_32(rgb) (rgb & 0xFFF8FCF8) //make RGB32 = RGB16
|
||||||
|
|
||||||
|
c_surface::c_surface(c_display* display, unsigned int width, unsigned int height, unsigned int color_bytes)
|
||||||
{
|
{
|
||||||
m_width = width;
|
m_width = width;
|
||||||
m_height = height;
|
m_height = height;
|
||||||
@ -19,9 +21,6 @@ c_surface::c_surface(c_display* display, unsigned int width, unsigned int heigh
|
|||||||
m_fb = m_usr = NULL;
|
m_fb = m_usr = NULL;
|
||||||
m_top_zorder = m_max_zorder = Z_ORDER_LEVEL_0;
|
m_top_zorder = m_max_zorder = Z_ORDER_LEVEL_0;
|
||||||
m_is_active = false;
|
m_is_active = false;
|
||||||
m_gfx_op = gfx_op;
|
|
||||||
|
|
||||||
m_fb = calloc(m_width * m_height, color_bytes);
|
|
||||||
m_frame_layers[Z_ORDER_LEVEL_0].rect = c_rect(0, 0, m_width, m_height);
|
m_frame_layers[Z_ORDER_LEVEL_0].rect = c_rect(0, 0, m_width, m_height);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -29,9 +28,15 @@ void c_surface::set_surface(void* wnd_root, Z_ORDER_LEVEL max_z_order)
|
|||||||
{
|
{
|
||||||
m_usr = wnd_root;
|
m_usr = wnd_root;
|
||||||
m_max_zorder = max_z_order;
|
m_max_zorder = max_z_order;
|
||||||
for(int i = 0; i <= m_max_zorder; i++)
|
|
||||||
|
if (m_display->m_surface_cnt > 1)
|
||||||
{
|
{
|
||||||
m_frame_layers[i].fb = calloc(m_width * m_height, m_color_bytes);
|
m_fb = calloc(m_width * m_height, m_color_bytes);
|
||||||
|
}
|
||||||
|
|
||||||
|
for(int i = Z_ORDER_LEVEL_0; i < m_max_zorder; i++)
|
||||||
|
{//Top layber fb always be NULL
|
||||||
|
m_frame_layers[i].fb = (unsigned short*)calloc(m_width * m_height, sizeof(unsigned short));
|
||||||
ASSERT(NULL != m_frame_layers[i].fb);
|
ASSERT(NULL != m_frame_layers[i].fb);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -47,6 +52,11 @@ void c_surface::draw_pixel(int x, int y, unsigned int rgb, unsigned int z_order)
|
|||||||
ASSERT(FALSE);
|
ASSERT(FALSE);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
rgb = GL_ROUND_RGB_32(rgb);
|
||||||
|
if (z_order == m_max_zorder)
|
||||||
|
{
|
||||||
|
return draw_pixel_on_fb(x, y, rgb);
|
||||||
|
}
|
||||||
|
|
||||||
if (z_order > m_top_zorder)
|
if (z_order > m_top_zorder)
|
||||||
{
|
{
|
||||||
@ -58,23 +68,17 @@ void c_surface::draw_pixel(int x, int y, unsigned int rgb, unsigned int z_order)
|
|||||||
ASSERT(FALSE);
|
ASSERT(FALSE);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
((unsigned short*)(m_frame_layers[z_order].fb))[x + y * m_width] = GL_RGB_32_to_16(rgb);
|
||||||
if (z_order == m_max_zorder)
|
|
||||||
{
|
|
||||||
return set_pixel(x, y, rgb);
|
|
||||||
}
|
|
||||||
|
|
||||||
((unsigned int*)(m_frame_layers[z_order].fb))[x + y * m_width] = rgb;
|
|
||||||
|
|
||||||
if (z_order == m_top_zorder)
|
if (z_order == m_top_zorder)
|
||||||
{
|
{
|
||||||
return set_pixel(x, y, rgb);
|
return draw_pixel_on_fb(x, y, rgb);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool is_covered = false;
|
bool is_covered = false;
|
||||||
for (int tmp_z_order = Z_ORDER_LEVEL_MAX - 1; tmp_z_order > z_order; tmp_z_order--)
|
for (int tmp_z_order = Z_ORDER_LEVEL_MAX - 1; tmp_z_order > z_order; tmp_z_order--)
|
||||||
{
|
{
|
||||||
if (1 == m_frame_layers[tmp_z_order].rect.PtInRect(x, y))
|
if (TRUE == m_frame_layers[tmp_z_order].rect.PtInRect(x, y))
|
||||||
{
|
{
|
||||||
is_covered = true;
|
is_covered = true;
|
||||||
break;
|
break;
|
||||||
@ -83,25 +87,36 @@ void c_surface::draw_pixel(int x, int y, unsigned int rgb, unsigned int z_order)
|
|||||||
|
|
||||||
if (!is_covered)
|
if (!is_covered)
|
||||||
{
|
{
|
||||||
set_pixel(x, y, rgb);
|
draw_pixel_on_fb(x, y, rgb);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void c_surface::set_pixel(int x, int y, unsigned int rgb)
|
void c_surface::draw_pixel_on_fb(int x, int y, unsigned int rgb)
|
||||||
{
|
{
|
||||||
((unsigned int*)m_fb)[y * m_width + x] = 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);
|
||||||
|
}
|
||||||
|
|
||||||
int display_width = m_display->get_width();
|
int display_width = m_display->get_width();
|
||||||
int display_height = m_display->get_height();
|
int display_height = m_display->get_height();
|
||||||
if (m_is_active && (x < display_width) && (y < display_height))
|
if (m_is_active && (x < display_width) && (y < display_height))
|
||||||
|
{
|
||||||
|
if (m_color_bytes == 4)
|
||||||
{
|
{
|
||||||
((unsigned int*)m_phy_fb)[y * (m_display->get_width()) + x] = rgb;
|
((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;
|
*m_phy_write_index = *m_phy_write_index + 1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void c_surface::fill_rect(int x0, int y0, int x1, int y1, unsigned int rgb, unsigned int z_order)
|
void c_surface::fill_rect(int x0, int y0, int x1, int y1, unsigned int rgb, unsigned int z_order)
|
||||||
{
|
{
|
||||||
|
rgb = GL_ROUND_RGB_32(rgb);
|
||||||
if (z_order == m_max_zorder)
|
if (z_order == m_max_zorder)
|
||||||
{
|
{
|
||||||
return fill_rect_on_fb(x0, y0, x1, y1, rgb);
|
return fill_rect_on_fb(x0, y0, x1, y1, rgb);
|
||||||
@ -110,14 +125,15 @@ void c_surface::fill_rect(int x0, int y0, int x1, int y1, unsigned int rgb, unsi
|
|||||||
if (z_order == m_top_zorder)
|
if (z_order == m_top_zorder)
|
||||||
{
|
{
|
||||||
int x, y;
|
int x, y;
|
||||||
unsigned int *mem_fb;
|
unsigned short *mem_fb;
|
||||||
|
unsigned int rgb_16 = GL_RGB_32_to_16(rgb);
|
||||||
for (y = y0; y <= y1; y++)
|
for (y = y0; y <= y1; y++)
|
||||||
{
|
{
|
||||||
x = x0;
|
x = x0;
|
||||||
mem_fb = &((unsigned int*)m_frame_layers[z_order].fb)[y * m_width + x];
|
mem_fb = &((unsigned short*)m_frame_layers[z_order].fb)[y * m_width + x];
|
||||||
for (; x <= x1; x++)
|
for (; x <= x1; x++)
|
||||||
{
|
{
|
||||||
*mem_fb++ = rgb;
|
*mem_fb++ = rgb_16;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return fill_rect_on_fb(x0, y0, x1, y1, rgb);
|
return fill_rect_on_fb(x0, y0, x1, y1, rgb);
|
||||||
@ -136,20 +152,25 @@ void c_surface::fill_rect_on_fb(int x0, int y0, int x1, int y1, unsigned int rgb
|
|||||||
{
|
{
|
||||||
ASSERT(FALSE);
|
ASSERT(FALSE);
|
||||||
}
|
}
|
||||||
|
|
||||||
int x;
|
|
||||||
unsigned int *fb, *phy_fb;
|
|
||||||
int display_width = m_display->get_width();
|
int display_width = m_display->get_width();
|
||||||
int display_height = m_display->get_height();
|
int display_height = m_display->get_height();
|
||||||
|
|
||||||
|
if (m_color_bytes == 4)
|
||||||
|
{
|
||||||
|
int x;
|
||||||
|
unsigned int *fb, *phy_fb;
|
||||||
for (; y0 <= y1; y0++)
|
for (; y0 <= y1; y0++)
|
||||||
{
|
{
|
||||||
x = x0;
|
x = x0;
|
||||||
fb = &((unsigned int*)m_fb)[y0 * m_width + x];
|
fb = m_fb ? &((unsigned int*)m_fb)[y0 * m_width + x] : NULL;
|
||||||
phy_fb = &((unsigned int*)m_phy_fb)[y0 * display_width + x];
|
phy_fb = &((unsigned int*)m_phy_fb)[y0 * display_width + x];
|
||||||
*m_phy_write_index = *m_phy_write_index + 1;
|
*m_phy_write_index = *m_phy_write_index + 1;
|
||||||
for (; x <= x1; x++)
|
for (; x <= x1; x++)
|
||||||
|
{
|
||||||
|
if (fb)
|
||||||
{
|
{
|
||||||
*fb++ = rgb;
|
*fb++ = rgb;
|
||||||
|
}
|
||||||
if (m_is_active && (x < display_width) && (y0 < display_height))
|
if (m_is_active && (x < display_width) && (y0 < display_height))
|
||||||
{
|
{
|
||||||
*phy_fb++ = rgb;
|
*phy_fb++ = rgb;
|
||||||
@ -157,6 +178,32 @@ void c_surface::fill_rect_on_fb(int x0, int y0, int x1, int y1, unsigned int rgb
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
else if(m_color_bytes == 2)
|
||||||
|
{
|
||||||
|
int x;
|
||||||
|
unsigned short *fb, *phy_fb;
|
||||||
|
rgb = GL_RGB_32_to_16(rgb);
|
||||||
|
for (; y0 <= y1; y0++)
|
||||||
|
{
|
||||||
|
x = x0;
|
||||||
|
fb = m_fb ? &((unsigned short*)m_fb)[y0 * m_width + x] : NULL;
|
||||||
|
phy_fb = &((unsigned short*)m_phy_fb)[y0 * display_width + x];
|
||||||
|
*m_phy_write_index = *m_phy_write_index + 1;
|
||||||
|
for (; x <= x1; x++)
|
||||||
|
{
|
||||||
|
if (fb)
|
||||||
|
{
|
||||||
|
*fb++ = rgb;
|
||||||
|
}
|
||||||
|
if (m_is_active && (x < display_width) && (y0 < display_height))
|
||||||
|
{
|
||||||
|
*phy_fb++ = rgb;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
unsigned int c_surface::get_pixel(int x, int y, unsigned int z_order)
|
unsigned int c_surface::get_pixel(int x, int y, unsigned int z_order)
|
||||||
{
|
{
|
||||||
@ -169,36 +216,31 @@ unsigned int c_surface::get_pixel(int x, int y, unsigned int z_order)
|
|||||||
|
|
||||||
if (z_order == m_max_zorder)
|
if (z_order == m_max_zorder)
|
||||||
{
|
{
|
||||||
return ((unsigned int*)m_fb)[y * m_width + x];
|
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]);
|
||||||
|
}
|
||||||
|
else if(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 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
return ((unsigned int*)(m_frame_layers[z_order].fb))[y * m_width + x];
|
unsigned short rgb_16 = ((unsigned short*)(m_frame_layers[z_order].fb))[y * m_width + x];
|
||||||
|
return GL_RGB_16_to_32(rgb_16);
|
||||||
}
|
}
|
||||||
|
|
||||||
void c_surface::draw_hline(int x0, int x1, int y, unsigned int rgb, unsigned int z_order)
|
void c_surface::draw_hline(int x0, int x1, int y, unsigned int rgb, unsigned int z_order)
|
||||||
{
|
{
|
||||||
if (x0 > x1)
|
|
||||||
{
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
for (;x0 <= x1; x0++)
|
for (;x0 <= x1; x0++)
|
||||||
{
|
{ draw_pixel(x0, y, rgb, z_order); }
|
||||||
draw_pixel(x0, y, rgb, z_order);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void c_surface::draw_vline(int x, int y0, int y1, unsigned int rgb, unsigned int z_order)
|
void c_surface::draw_vline(int x, int y0, int y1, unsigned int rgb, unsigned int z_order)
|
||||||
{
|
{
|
||||||
if (y0 > y1)
|
|
||||||
{
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
for (;y0 <= y1; y0++)
|
for (;y0 <= y1; y0++)
|
||||||
{
|
{ draw_pixel(x, y0, rgb, z_order); }
|
||||||
draw_pixel(x, y0, rgb, z_order);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void c_surface::draw_line(int x1, int y1, int x2, int y2, unsigned int rgb, unsigned int z_order)
|
void c_surface::draw_line(int x1, int y1, int x2, int y2, unsigned int rgb, unsigned int z_order)
|
||||||
@ -326,7 +368,7 @@ int c_surface::set_frame_layer(c_rect& rect, unsigned int z_order)
|
|||||||
ASSERT(FALSE);
|
ASSERT(FALSE);
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
if (!(z_order > Z_ORDER_LEVEL_0 || z_order < Z_ORDER_LEVEL_MAX))
|
if (!(z_order > Z_ORDER_LEVEL_0 && z_order < Z_ORDER_LEVEL_MAX))
|
||||||
{
|
{
|
||||||
ASSERT(FALSE);
|
ASSERT(FALSE);
|
||||||
return -2;
|
return -2;
|
||||||
@ -352,22 +394,22 @@ int c_surface::set_frame_layer(c_rect& rect, unsigned int z_order)
|
|||||||
{
|
{
|
||||||
if (m_frame_layers[src_zorder].rect.PtInRect(x, y))
|
if (m_frame_layers[src_zorder].rect.PtInRect(x, y))
|
||||||
{
|
{
|
||||||
|
unsigned int rgb = ((unsigned short*)(m_frame_layers[src_zorder].fb))[x + y * m_width];
|
||||||
if (m_color_bytes == 4)
|
if (m_color_bytes == 4)
|
||||||
{
|
{
|
||||||
unsigned int rgb = ((unsigned int*)(m_frame_layers[src_zorder].fb))[x + y * m_width];
|
rgb = GL_RGB_16_to_32(rgb);
|
||||||
((unsigned int*)m_fb)[y * m_width + x] = rgb;
|
if (m_fb) { ((unsigned int*)m_fb)[y * m_width + x] = rgb; }
|
||||||
if (m_is_active && (x < display_width) && (y < display_height))
|
if (m_is_active && (x < display_width) && (y < display_height))
|
||||||
{
|
{
|
||||||
((unsigned int*)m_phy_fb)[y * display_width + x] = rgb;
|
((unsigned int*)m_phy_fb)[y * display_width + x] = rgb;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else//16 bits
|
else if(m_color_bytes == 2)
|
||||||
{
|
{
|
||||||
short rgb = ((short*)(m_frame_layers[src_zorder].fb))[x + y * m_width];
|
if (m_fb) { ((unsigned short*)m_fb)[y * m_width + x] = rgb; }
|
||||||
((short*)m_fb)[y * m_width + x] = rgb;
|
|
||||||
if (m_is_active && (x < display_width) && (y < display_height))
|
if (m_is_active && (x < display_width) && (y < display_height))
|
||||||
{
|
{
|
||||||
((short*)m_phy_fb)[y * display_width + x] = rgb;
|
((unsigned short*)m_phy_fb)[y * display_width + x] = rgb;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -430,189 +472,74 @@ bool c_surface::is_valid(c_rect rect)
|
|||||||
}
|
}
|
||||||
|
|
||||||
//////////////////////////////////////////////////////////////////////////////////////
|
//////////////////////////////////////////////////////////////////////////////////////
|
||||||
void c_surface_16bits::draw_pixel(int x, int y, unsigned int rgb, unsigned int z_order)
|
void c_surface_no_fb::fill_rect_on_fb(int x0, int y0, int x1, int y1, unsigned int rgb)
|
||||||
{
|
{
|
||||||
if (x >= m_width || y >= m_height || x < 0 || y < 0)
|
if (!m_gfx_op)
|
||||||
{
|
{
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (z_order > m_max_zorder)
|
if (m_gfx_op->fill_rect)
|
||||||
{
|
{
|
||||||
ASSERT(FALSE);
|
return m_gfx_op->fill_rect(x0, y0, x1, y1, rgb);
|
||||||
return;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (z_order > m_top_zorder)
|
if (m_gfx_op->draw_pixel && m_is_active)
|
||||||
{
|
{
|
||||||
m_top_zorder = (Z_ORDER_LEVEL)z_order;
|
for (int y = y0; y <= y1; y++)
|
||||||
}
|
|
||||||
|
|
||||||
if (0 == m_frame_layers[z_order].rect.PtInRect(x, y))
|
|
||||||
{
|
{
|
||||||
ASSERT(FALSE);
|
for (int x = x0; x <= x1; x++)
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
rgb = GL_RGB_32_to_16(rgb);
|
|
||||||
if (z_order == m_max_zorder)
|
|
||||||
{
|
|
||||||
return set_pixel(x, y, rgb);
|
|
||||||
}
|
|
||||||
|
|
||||||
((unsigned short*)(m_frame_layers[z_order].fb))[x + y * m_width] = rgb;
|
|
||||||
|
|
||||||
if (z_order == m_top_zorder)
|
|
||||||
{
|
|
||||||
return set_pixel(x, y, rgb);
|
|
||||||
}
|
|
||||||
|
|
||||||
bool is_covered = false;
|
|
||||||
for (int tmp_z_order = Z_ORDER_LEVEL_MAX - 1; tmp_z_order > z_order; tmp_z_order--)
|
|
||||||
{
|
|
||||||
if (1 == m_frame_layers[tmp_z_order].rect.PtInRect(x, y))
|
|
||||||
{
|
|
||||||
is_covered = true;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!is_covered)
|
|
||||||
{
|
|
||||||
set_pixel(x, y, rgb);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void c_surface_16bits::set_pixel(int x, int y, unsigned int rgb)
|
|
||||||
{
|
|
||||||
((unsigned short*)m_fb)[y * m_width + x] = rgb;
|
|
||||||
|
|
||||||
int display_width = m_display->get_width();
|
|
||||||
int display_height = m_display->get_height();
|
|
||||||
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;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void c_surface_16bits::fill_rect(int x0, int y0, int x1, int y1, unsigned int rgb, unsigned int z_order)
|
|
||||||
{
|
|
||||||
if (z_order == m_max_zorder)
|
|
||||||
{
|
|
||||||
return fill_rect_on_fb(x0, y0, x1, y1, GL_RGB_32_to_16(rgb));
|
|
||||||
}
|
|
||||||
if (z_order == m_top_zorder)
|
|
||||||
{
|
|
||||||
int x, y;
|
|
||||||
unsigned short *mem_fb;
|
|
||||||
unsigned int rgb_16 = GL_RGB_32_to_16(rgb);
|
|
||||||
for (y = y0; y <= y1; y++)
|
|
||||||
{
|
|
||||||
x = x0;
|
|
||||||
mem_fb = &((unsigned short*)m_frame_layers[z_order].fb)[y * m_width + x];
|
|
||||||
for (; x <= x1; x++)
|
|
||||||
{
|
|
||||||
*mem_fb++ = rgb_16;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return fill_rect_on_fb(x0, y0, x1, y1, GL_RGB_32_to_16(rgb));
|
|
||||||
}
|
|
||||||
|
|
||||||
for (; y0 <= y1; y0++)
|
|
||||||
{
|
|
||||||
draw_hline(x0, x1, y0, rgb, z_order);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void c_surface_16bits::fill_rect_on_fb(int x0, int y0, int x1, int y1, unsigned int rgb)
|
|
||||||
{
|
|
||||||
if (x0 < 0 || y0 < 0 || x1 < 0 || y1 < 0 ||
|
|
||||||
x0 >= m_width || x1 >= m_width || y0 >= m_height || y1 >= m_height)
|
|
||||||
{
|
|
||||||
ASSERT(FALSE);
|
|
||||||
}
|
|
||||||
|
|
||||||
int x;
|
|
||||||
unsigned short *fb, *phy_fb;
|
|
||||||
int display_width = m_display->get_width();
|
|
||||||
int display_height = m_display->get_height();
|
|
||||||
for (; y0 <= y1; y0++)
|
|
||||||
{
|
|
||||||
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;
|
|
||||||
if (m_is_active && (x < display_width) && (y0 < display_height))
|
|
||||||
{
|
|
||||||
*phy_fb++ = rgb;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
unsigned int c_surface_16bits::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)
|
|
||||||
{
|
|
||||||
ASSERT(FALSE);
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (z_order == m_max_zorder)
|
|
||||||
{
|
|
||||||
return GL_RGB_16_to_32(((unsigned short*)m_fb)[y * m_width + x]);
|
|
||||||
}
|
|
||||||
|
|
||||||
return GL_RGB_16_to_32(((unsigned short*)(m_frame_layers[z_order].fb))[y * m_width + x]);
|
|
||||||
}
|
|
||||||
|
|
||||||
//////////////////////////////////////////////////////////////////////////////////////
|
|
||||||
void c_surface_mcu::draw_pixel(int x, int y, unsigned int rgb, unsigned int z_order)
|
|
||||||
{
|
|
||||||
if (x >= m_width || y >= m_height || x < 0 || y < 0)
|
|
||||||
{
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
if (m_gfx_op && m_gfx_op->draw_pixel)
|
|
||||||
{
|
{
|
||||||
m_gfx_op->draw_pixel(x, y, rgb);
|
m_gfx_op->draw_pixel(x, y, rgb);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
void c_surface_mcu::fill_rect(int x0, int y0, int x1, int y1, unsigned int rgb, unsigned int z_order)
|
if (!m_fb) { return; }
|
||||||
|
if(m_color_bytes == 4)
|
||||||
{
|
{
|
||||||
if (m_gfx_op && m_gfx_op->fill_rect)
|
unsigned int *fb;
|
||||||
|
for (int y = y0; y <= y1; y++)
|
||||||
{
|
{
|
||||||
return m_gfx_op->fill_rect(x0, y0, x1, y1, rgb);
|
fb = &((unsigned int*)m_fb)[y0 * m_width + x0];
|
||||||
}
|
for (int x = x0; x <= x1; x++)
|
||||||
for (; y0 <= y1; y0++)
|
|
||||||
{
|
{
|
||||||
draw_hline(x0, x1, y0, rgb, z_order);
|
*fb++ = rgb;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void c_surface_mcu::fill_rect_on_fb(int x0, int y0, int x1, int y1, unsigned int rgb)
|
|
||||||
{//Not support
|
|
||||||
ASSERT(FALSE);
|
|
||||||
}
|
}
|
||||||
|
else if (m_color_bytes == 2)
|
||||||
unsigned int c_surface_mcu::get_pixel(int x, int y, unsigned int z_order)
|
|
||||||
{//Not support
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
void c_surface_mcu::set_pixel(int x, int y, unsigned int rgb)
|
|
||||||
{//Not support
|
|
||||||
ASSERT(FALSE);
|
|
||||||
}
|
|
||||||
|
|
||||||
void c_surface_mcu::set_surface(void* wnd_root, Z_ORDER_LEVEL max_z_order)
|
|
||||||
{
|
{
|
||||||
ASSERT(max_z_order == Z_ORDER_LEVEL_0);
|
unsigned short *fb;
|
||||||
m_usr = wnd_root;
|
rgb = GL_RGB_32_to_16(rgb);
|
||||||
m_max_zorder = max_z_order;
|
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;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void c_surface_no_fb::draw_pixel_on_fb(int x, int y, unsigned int rgb)
|
||||||
|
{
|
||||||
|
if (x >= m_width || y >= m_height || x < 0 || y < 0)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
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);
|
||||||
|
}
|
||||||
}
|
}
|
Loading…
x
Reference in New Issue
Block a user