Merge display constructor function in One

Merge pull request !9 from idea4good/dev
This commit is contained in:
idea4good 2019-01-21 15:27:11 +08:00
parent 281237a8dd
commit b7fd946448
11 changed files with 33 additions and 59 deletions

View File

@ -36,7 +36,7 @@
在Windows混合现实及单片机下的运行效果:
![Win MR](doc/WinMR.gif) ![MCU](doc/HelloWave.gif)
![Win MR](doc/WinMR.gif) ![MCU](doc/MCU.gif)
### 万国语和墙纸
- 墙纸:

View File

@ -11,8 +11,7 @@ class c_display {
public:
c_display(void* phy_fb, unsigned int display_width, unsigned int display_height,
unsigned int surface_width, unsigned int surface_height,
unsigned int color_bytes, unsigned int surface_cnt);
c_display(unsigned int display_width, unsigned int display_height, unsigned int color_bytes, EXTERNAL_GFX_OP* gfx_op);
unsigned int color_bytes, unsigned int surface_cnt, EXTERNAL_GFX_OP* gfx_op = NULL);
c_surface* alloc_surface(void* usr, Z_ORDER_LEVEL max_zorder);
int merge_surface(c_surface* s1, c_surface* s2, int x0, int x1, int y0, int y2, int offset);
unsigned int get_width() { return m_width; }

View File

@ -15,7 +15,11 @@ typedef enum
Z_ORDER_LEVEL_MAX
}Z_ORDER_LEVEL;
typedef struct struct_color_rect COLOR_RECT;
struct EXTERNAL_GFX_OP
{
void(*draw_pixel)(int x, int y, unsigned int rgb);
void(*fill_rect)(int x0, int y0, int x1, int y1, unsigned int rgb);
};
class c_display;
class c_surface {
@ -43,7 +47,7 @@ protected:
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 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);
c_surface(c_display* display, unsigned int width, unsigned int height, unsigned int color_bytes, struct EXTERNAL_GFX_OP* gfx_op);
int m_width; //in pixels
int m_height; //in pixels
int m_color_bytes; //16 bits, 32 bits only
@ -56,12 +60,13 @@ protected:
void* m_phy_fb;
int* m_phy_write_index;
c_display* m_display;
struct EXTERNAL_GFX_OP* m_gfx_op;
};
class c_surface_16bits : public c_surface {
friend class c_display;
c_surface_16bits(c_display* display, unsigned int width, unsigned int height, unsigned int color_bytes) :
c_surface(display, width, height, color_bytes) {};
c_surface_16bits(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);
@ -70,14 +75,11 @@ protected:
virtual void set_pixel(int x, int y, unsigned int rgb);
};
struct EXTERNAL_GFX_OP
{
void (*draw_pixel)(int x, int y, unsigned int rgb);
void (*fill_rect)(int x0, int y0, int x1, int y1, unsigned int rgb);
};
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_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);
@ -85,7 +87,5 @@ class c_surface_mcu : public c_surface {
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);
private:
struct EXTERNAL_GFX_OP* m_gfx_op;
};
#endif

View File

@ -10,7 +10,7 @@
c_display::c_display(void* phy_fb, unsigned int display_width, unsigned int display_height,
unsigned int surface_width, unsigned int surface_height,
unsigned int color_bytes, unsigned int surface_cnt)
unsigned int color_bytes, unsigned int surface_cnt, EXTERNAL_GFX_OP* gfx_op)
{
if (color_bytes != 2 && color_bytes != 4)
{
@ -23,36 +23,26 @@ c_display::c_display(void* phy_fb, unsigned int display_width, unsigned int disp
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)
{
ASSERT(FALSE);
}
memset(m_surface_group, 0, sizeof(m_surface_group));
m_surface_cnt = surface_cnt;
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++)
{
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);
m_surface_group[i] = (color_bytes == 4) ? new c_surface(this, surface_width, surface_height, color_bytes , gfx_op) :
new c_surface_16bits(this, surface_width, surface_height, color_bytes, gfx_op);
}
}
c_display::c_display(unsigned int display_width, unsigned int display_height, unsigned int color_bytes, EXTERNAL_GFX_OP* gfx_op)
{
m_width = display_width;
m_height = display_height;
m_surface_cnt = 1;
m_phy_fb = NULL;
m_surface_group[0] = new c_surface_mcu(this, display_width, display_height, color_bytes, gfx_op);
}
c_surface* c_display::alloc_surface(void* usr, Z_ORDER_LEVEL max_zorder)
{
int i = 0;
if (max_zorder >= Z_ORDER_LEVEL_MAX)
{
ASSERT(FALSE);
}
ASSERT(max_zorder < Z_ORDER_LEVEL_MAX);
while (i < m_surface_cnt)
{

View File

@ -8,7 +8,7 @@
#include <string.h>
#include <stdlib.h>
c_surface::c_surface(c_display* display, 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, struct EXTERNAL_GFX_OP* gfx_op)
{
m_width = width;
m_height = height;
@ -19,6 +19,7 @@ c_surface::c_surface(c_display* display, unsigned int width, unsigned int heigh
m_fb = m_usr = NULL;
m_top_zorder = m_max_zorder = Z_ORDER_LEVEL_0;
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);
@ -570,12 +571,6 @@ unsigned int c_surface_16bits::get_pixel(int x, int y, unsigned int z_order)
}
//////////////////////////////////////////////////////////////////////////////////////
c_surface_mcu::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)
{
m_gfx_op = gfx_op;
}
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)
@ -617,6 +612,7 @@ void c_surface_mcu::set_pixel(int x, int y, unsigned int rgb)
void c_surface_mcu::set_surface(void* wnd_root, Z_ORDER_LEVEL max_z_order)
{
ASSERT(max_z_order == Z_ORDER_LEVEL_0);
m_usr = wnd_root;
m_max_zorder = max_z_order;
}

View File

@ -25,7 +25,7 @@ int c_wave_buffer::write_wave_data(short data)
{
if ((m_tail + 1) % WAVE_BUFFER_LEN == m_head)
{//full
log_out("wave buf full\n");
//log_out("wave buf full\n");
return BUFFER_FULL;
}
m_wave_buf[m_tail] = data;
@ -37,7 +37,7 @@ int c_wave_buffer::read_data()
{
if (m_head == m_tail)
{//empty
log_out("wave buf empty\n");
//log_out("wave buf empty\n");
return BUFFER_EMPTY;
}
int ret = m_wave_buf[m_head];

View File

@ -27,7 +27,7 @@ c_wave_ctrl::c_wave_ctrl()
m_wave_name = m_wave_unit = 0;
m_max_data = 500;
m_min_data = 0;
m_wave_speed = 4;
m_wave_speed = 1;
m_wave_data_rate = 0;
m_wave_refresh_rate = 1000;
m_frame_len_map_index = 0;
@ -72,18 +72,7 @@ void c_wave_ctrl::set_wave_in_out_rate(unsigned int data_rate, unsigned int refr
void c_wave_ctrl::set_wave_speed(unsigned int speed)
{
switch(speed)
{
case 1:
case 2:
case 4:
case 8:
m_wave_speed = speed;
break;
default:
ASSERT(FALSE);
break;
}
m_wave_speed = speed;
set_wave_in_out_rate(m_wave_data_rate, m_wave_refresh_rate);
}

Binary file not shown.

Before

Width:  |  Height:  |  Size: 275 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 523 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 1.1 MiB

BIN
doc/MCU.gif Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 671 KiB