mirror of
https://gitee.com/idea4good/GuiLite.git
synced 2025-10-15 18:55:09 +08:00
Refactor message, display, resource, readme
This commit is contained in:
@@ -46,5 +46,5 @@ void register_timer(int milli_second, void func(void* ptmr, void* parg));
|
||||
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(char *filename, unsigned int width, unsigned int height, unsigned char *data);
|
||||
int build_bmp(const char *filename, unsigned int width, unsigned int height, unsigned char *data);
|
||||
#endif
|
||||
|
@@ -1,7 +1,6 @@
|
||||
#ifndef _DISPLAY_H_
|
||||
#define _DISPLAY_H_
|
||||
|
||||
#define MAX_DISPLAY 9
|
||||
#define SURFACE_CNT_MAX 6//root + pages
|
||||
|
||||
class c_hid_pipe;
|
||||
@@ -14,21 +13,17 @@ public:
|
||||
unsigned int color_bytes, unsigned int surface_cnt);
|
||||
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);
|
||||
c_hid_pipe* get_hid_pipe() { return m_hid_pipe; }
|
||||
unsigned int get_width() { return m_width; }
|
||||
unsigned int get_height() { return m_height; }
|
||||
|
||||
static void* get_frame_buffer(unsigned int display_id, int* width, int* height);
|
||||
static int snap_shot(unsigned int display_id);
|
||||
void* get_frame_buffer(int* width, int* height);
|
||||
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;
|
||||
c_hid_pipe* m_hid_pipe;
|
||||
c_surface* m_surface_group[SURFACE_CNT_MAX];
|
||||
unsigned int m_surface_cnt;
|
||||
|
||||
static c_display* ms_displays[MAX_DISPLAY];
|
||||
};
|
||||
#endif
|
@@ -8,39 +8,20 @@ typedef struct
|
||||
unsigned int dwParam2;
|
||||
}MSG_INFO;
|
||||
|
||||
int read_usr_msg(MSG_INFO* msg);
|
||||
int write_usr_msg(MSG_INFO* msg);
|
||||
|
||||
#define FIFO_BUFFER_LEN 1024
|
||||
#define FIFO_NAME_LEN 16
|
||||
class c_fifo
|
||||
{
|
||||
public:
|
||||
c_fifo(const char* name);
|
||||
c_fifo();
|
||||
int read(void* buf, int len);
|
||||
int write(void* buf, int len);
|
||||
|
||||
private:
|
||||
unsigned char m_buf[FIFO_BUFFER_LEN];
|
||||
char m_name[FIFO_NAME_LEN];
|
||||
int m_head;
|
||||
int m_tail;
|
||||
void* m_read_sem;
|
||||
void* m_write_mutex;
|
||||
};
|
||||
|
||||
#define MAX_HID_PIPES 9
|
||||
class c_hid_pipe
|
||||
{
|
||||
public:
|
||||
c_hid_pipe(void* id);
|
||||
|
||||
static int read_hid_msg();
|
||||
static int write_hid_msg(MSG_INFO* msg, unsigned int display_id = 0);
|
||||
MSG_INFO m_msg;
|
||||
int m_fd;
|
||||
private:
|
||||
static c_hid_pipe* ms_pipes[MAX_HID_PIPES];
|
||||
static int ms_max_fd;
|
||||
};
|
||||
#endif
|
||||
|
@@ -137,7 +137,7 @@ static int set_a_timer(int interval, void (* timer_proc) (void* ptmr, void* parg
|
||||
|
||||
typedef void (*EXPIRE_ROUTINE)(void* arg);
|
||||
EXPIRE_ROUTINE s_expire_function;
|
||||
static c_fifo s_real_timer_fifo("real timer fifo");
|
||||
static c_fifo s_real_timer_fifo;
|
||||
|
||||
static void* real_timer_routine(void*)
|
||||
{
|
||||
@@ -269,7 +269,7 @@ typedef struct{
|
||||
unsigned int biBlueMask;
|
||||
}__attribute__((packed))Infohead;
|
||||
|
||||
int build_bmp(char *filename, unsigned int width, unsigned int height, unsigned char *data)
|
||||
int build_bmp(const char *filename, unsigned int width, unsigned int height, unsigned char *data)
|
||||
{
|
||||
FileHead bmp_head;
|
||||
Infohead bmp_info;
|
||||
|
@@ -136,7 +136,7 @@ static int set_a_timer(int interval, void (* timer_proc) (void* ptmr, void* parg
|
||||
|
||||
typedef void (*EXPIRE_ROUTINE)(void* arg);
|
||||
EXPIRE_ROUTINE s_expire_function;
|
||||
static c_fifo s_real_timer_fifo("real timer fifo");
|
||||
static c_fifo s_real_timer_fifo;
|
||||
|
||||
static DWORD WINAPI fire_real_timer(LPVOID lpParam)
|
||||
{
|
||||
@@ -276,7 +276,7 @@ typedef struct {
|
||||
}Infohead;
|
||||
#pragma pack(pop)
|
||||
|
||||
int build_bmp(char *filename, unsigned int width, unsigned int height, unsigned char *data)
|
||||
int build_bmp(const char *filename, unsigned int width, unsigned int height, unsigned char *data)
|
||||
{
|
||||
FileHead bmp_head;
|
||||
Infohead bmp_info;
|
||||
|
@@ -15,7 +15,7 @@ typedef struct
|
||||
AUDIO_TYPE type;
|
||||
}AUDIO_REQUEST;
|
||||
|
||||
static c_fifo s_request_fifo("aduio fifo");
|
||||
static c_fifo s_request_fifo;
|
||||
|
||||
static void* render_thread(void* param)
|
||||
{
|
||||
|
@@ -30,7 +30,7 @@ typedef struct
|
||||
}WAV_RESOURCE;
|
||||
|
||||
static WAV_RESOURCE s_wav_resource[AUDIO_MAX];
|
||||
static c_fifo s_request_fifo("aduio fifo");
|
||||
static c_fifo s_request_fifo;
|
||||
static IAudioClient* s_audio_client;
|
||||
static IAudioRenderClient* s_audio_render_client;
|
||||
static HANDLE s_audio_event;
|
||||
|
@@ -9,31 +9,8 @@
|
||||
#include <pthread.h>
|
||||
#include <semaphore.h>
|
||||
|
||||
c_hid_pipe* c_hid_pipe::ms_pipes[MAX_HID_PIPES];
|
||||
int c_hid_pipe::ms_max_fd;
|
||||
|
||||
static c_fifo s_usr_fifo("usr fifo");
|
||||
|
||||
int read_usr_msg(MSG_INFO* msg)
|
||||
c_fifo::c_fifo()
|
||||
{
|
||||
return s_usr_fifo.read(msg, sizeof(MSG_INFO));
|
||||
}
|
||||
|
||||
int write_usr_msg(MSG_INFO* msg)
|
||||
{
|
||||
if(msg->dwMsgId & 0xf000000)ASSERT(FALSE);
|
||||
return s_usr_fifo.write(msg, sizeof(MSG_INFO));
|
||||
}
|
||||
|
||||
c_fifo::c_fifo(const char* name)
|
||||
{
|
||||
if (strlen(name) >= FIFO_NAME_LEN)
|
||||
{
|
||||
ASSERT(FALSE);
|
||||
}
|
||||
memset(m_name, 0, sizeof(m_name));
|
||||
strcpy(m_name, name);
|
||||
|
||||
m_head = m_tail = 0;
|
||||
m_read_sem = malloc(sizeof(sem_t));
|
||||
m_write_mutex = malloc(sizeof(pthread_mutex_t));
|
||||
@@ -76,9 +53,7 @@ int c_fifo::write(void* buf, int len)
|
||||
if ((m_tail + 1) % FIFO_BUFFER_LEN == m_head)
|
||||
{//full, clear data has been written;
|
||||
m_tail = tail;
|
||||
log_out("Warning: ");
|
||||
log_out(m_name);
|
||||
log_out(" full\n");
|
||||
log_out("Warning: fifo full\n");
|
||||
pthread_mutex_unlock((pthread_mutex_t*)m_write_mutex);
|
||||
return 0;
|
||||
}
|
||||
@@ -98,57 +73,3 @@ int c_fifo::write(void* buf, int len)
|
||||
}
|
||||
return i;
|
||||
}
|
||||
|
||||
////////////////////////////////////
|
||||
// HID //
|
||||
////////////////////////////////////
|
||||
static c_fifo s_hid_fifo("hid fifo");
|
||||
c_hid_pipe::c_hid_pipe(void* id)
|
||||
{
|
||||
for(int i = 0; i < MAX_HID_PIPES; i++)
|
||||
{
|
||||
if(!ms_pipes[i])
|
||||
{
|
||||
ms_pipes[i] = this;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
int c_hid_pipe::read_hid_msg()
|
||||
{
|
||||
int ret = -1;
|
||||
for(int i = 0; i < MAX_HID_PIPES; i++)
|
||||
{
|
||||
if(ms_pipes[i])
|
||||
{
|
||||
ms_pipes[i]->m_msg.dwMsgId = XXX;
|
||||
}
|
||||
}
|
||||
MSG_INFO msg;
|
||||
ret = s_hid_fifo.read(&msg, sizeof(MSG_INFO));
|
||||
if(0 >= ret)
|
||||
{
|
||||
return ret;
|
||||
}
|
||||
int display_id = ((msg.dwMsgId & 0xff00000) >> 24);
|
||||
msg.dwMsgId &= 0x00ffffff;//recover message.
|
||||
|
||||
if (!ms_pipes[display_id])
|
||||
{
|
||||
return -2;
|
||||
}
|
||||
ms_pipes[display_id]->m_msg = msg;
|
||||
return ret;
|
||||
}
|
||||
|
||||
int c_hid_pipe::write_hid_msg(MSG_INFO* msg, unsigned int display_id)
|
||||
{
|
||||
if(MAX_DISPLAY <= display_id)
|
||||
{
|
||||
ASSERT(FALSE);
|
||||
return -1;
|
||||
}
|
||||
msg->dwMsgId |= ((display_id) << 24);//merge display ID in message.
|
||||
return s_hid_fifo.write(msg, sizeof(MSG_INFO));
|
||||
}
|
||||
|
@@ -5,32 +5,8 @@
|
||||
#include "../../core_include/msg.h"
|
||||
#include <windows.h>
|
||||
|
||||
c_hid_pipe* c_hid_pipe::ms_pipes[MAX_HID_PIPES];
|
||||
int c_hid_pipe::ms_max_fd;
|
||||
|
||||
static c_fifo s_usr_fifo("usr fifo");
|
||||
static c_fifo s_hid_fifo("hid fifo");
|
||||
|
||||
int read_usr_msg(MSG_INFO* msg)
|
||||
c_fifo::c_fifo()
|
||||
{
|
||||
return s_usr_fifo.read(msg, sizeof(MSG_INFO));
|
||||
}
|
||||
|
||||
int write_usr_msg(MSG_INFO* msg)
|
||||
{
|
||||
if(msg->dwMsgId & 0xf000000)ASSERT(FALSE);
|
||||
return s_usr_fifo.write(msg, sizeof(MSG_INFO));
|
||||
}
|
||||
|
||||
c_fifo::c_fifo(const char* name)
|
||||
{
|
||||
if (strlen(name) >= FIFO_NAME_LEN)
|
||||
{
|
||||
ASSERT(FALSE);
|
||||
}
|
||||
memset(m_name, 0, sizeof(m_name));
|
||||
strcpy(m_name, name);
|
||||
|
||||
m_head = m_tail = 0;
|
||||
m_read_sem = CreateSemaphore(NULL, // default security attributes
|
||||
0, // initial count
|
||||
@@ -73,9 +49,7 @@ int c_fifo::write(void* buf, int len)
|
||||
if ((m_tail + 1) % FIFO_BUFFER_LEN == m_head)
|
||||
{//full, clear data has been written;
|
||||
m_tail = tail;
|
||||
log_out("Warning: ");
|
||||
log_out(m_name);
|
||||
log_out(" full\n");
|
||||
log_out("Warning: fifo full\n");
|
||||
ReleaseMutex(m_write_mutex);
|
||||
return 0;
|
||||
}
|
||||
@@ -95,58 +69,3 @@ int c_fifo::write(void* buf, int len)
|
||||
}
|
||||
return i;
|
||||
}
|
||||
|
||||
////////////////////////////////////
|
||||
// HID //
|
||||
////////////////////////////////////
|
||||
c_hid_pipe::c_hid_pipe(void* id)
|
||||
{
|
||||
for(int i = 0; i < MAX_HID_PIPES; i++)
|
||||
{
|
||||
if(!ms_pipes[i])
|
||||
{
|
||||
ms_pipes[i] = this;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
int c_hid_pipe::read_hid_msg()
|
||||
{
|
||||
int ret = -1;
|
||||
|
||||
for(int i = 0; i < MAX_HID_PIPES; i++)
|
||||
{
|
||||
if(ms_pipes[i])
|
||||
{
|
||||
ms_pipes[i]->m_msg.dwMsgId = XXX;
|
||||
}
|
||||
}
|
||||
|
||||
MSG_INFO msg;
|
||||
ret = s_hid_fifo.read(&msg, sizeof(MSG_INFO));
|
||||
if(0 >= ret)
|
||||
{
|
||||
return ret;
|
||||
}
|
||||
int display_id = ((msg.dwMsgId & 0xff00000) >> 24);
|
||||
msg.dwMsgId &= 0x00ffffff;//recover message.
|
||||
|
||||
if (!ms_pipes[display_id])
|
||||
{
|
||||
return -2;
|
||||
}
|
||||
ms_pipes[display_id]->m_msg = msg;
|
||||
return ret;
|
||||
}
|
||||
|
||||
int c_hid_pipe::write_hid_msg(MSG_INFO* msg, unsigned int display_id)
|
||||
{
|
||||
if(MAX_DISPLAY <= display_id)
|
||||
{
|
||||
ASSERT(FALSE);
|
||||
return -1;
|
||||
}
|
||||
msg->dwMsgId |= ((display_id) << 24);//merge display ID in message.
|
||||
return s_hid_fifo.write(msg, sizeof(MSG_INFO));
|
||||
}
|
||||
|
@@ -8,8 +8,6 @@
|
||||
#include <string.h>
|
||||
#include <stdio.h>
|
||||
|
||||
c_display* c_display::ms_displays[MAX_DISPLAY];
|
||||
|
||||
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)
|
||||
@@ -24,15 +22,6 @@ 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_hid_pipe = new c_hid_pipe(NULL);
|
||||
for (int i = 0; i < MAX_DISPLAY; i++)
|
||||
{
|
||||
if (!ms_displays[i])
|
||||
{
|
||||
ms_displays[i] = this;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
m_surface_cnt = surface_cnt;
|
||||
if (m_surface_cnt > SURFACE_CNT_MAX)
|
||||
@@ -118,54 +107,35 @@ int c_display::merge_surface(c_surface* s0, c_surface* s1, int x0, int x1, int y
|
||||
return 0;
|
||||
}
|
||||
|
||||
void* c_display::get_frame_buffer(unsigned int display_id, int* width, int* height)
|
||||
void* c_display::get_frame_buffer(int* width, int* height)
|
||||
{
|
||||
if (MAX_DISPLAY <= display_id)
|
||||
if (width && height)
|
||||
{
|
||||
ASSERT(FALSE);
|
||||
return NULL;
|
||||
*width = get_width();
|
||||
*height = get_height();
|
||||
}
|
||||
if (ms_displays[display_id])
|
||||
{
|
||||
if (width && height)
|
||||
{
|
||||
*width = ms_displays[display_id]->get_width();
|
||||
*height = ms_displays[display_id]->get_height();
|
||||
}
|
||||
return ms_displays[display_id]->m_phy_fb;
|
||||
}
|
||||
return NULL;
|
||||
return m_phy_fb;
|
||||
}
|
||||
|
||||
int c_display::snap_shot(unsigned int display_id)
|
||||
int c_display::snap_shot(const char* file_name)
|
||||
{
|
||||
if (MAX_DISPLAY <= display_id)
|
||||
if (!m_phy_fb)
|
||||
{
|
||||
ASSERT(FALSE);
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (!ms_displays[display_id] || !ms_displays[display_id]->m_phy_fb)
|
||||
{
|
||||
return -2;
|
||||
}
|
||||
|
||||
char path[32];
|
||||
memset(path, 0, sizeof(path));
|
||||
sprintf(path, "snapshot_%d.bmp", display_id);
|
||||
|
||||
unsigned int width = ms_displays[display_id]->get_width();
|
||||
unsigned int height = ms_displays[display_id]->get_height();
|
||||
unsigned int width = get_width();
|
||||
unsigned int height = get_height();
|
||||
|
||||
//16 bits framebuffer
|
||||
if (ms_displays[display_id]->m_color_bytes == 2)
|
||||
if (m_color_bytes == 2)
|
||||
{
|
||||
return build_bmp(path, width, height, (unsigned char*)ms_displays[display_id]->m_phy_fb);
|
||||
return build_bmp(file_name, width, height, (unsigned char*)m_phy_fb);
|
||||
}
|
||||
|
||||
//32 bits framebuffer
|
||||
unsigned short* p_bmp565_data = new unsigned short[width * height];
|
||||
unsigned int* p_raw_data = (unsigned int*)ms_displays[display_id]->m_phy_fb;
|
||||
unsigned int* p_raw_data = (unsigned int*)m_phy_fb;
|
||||
|
||||
for (int i = 0; i < width * height; i++)
|
||||
{
|
||||
@@ -173,7 +143,7 @@ int c_display::snap_shot(unsigned int display_id)
|
||||
p_bmp565_data[i] = GL_RGB_32_to_16(rgb);
|
||||
}
|
||||
|
||||
int ret = build_bmp(path, width, height, (unsigned char*)p_bmp565_data);
|
||||
int ret = build_bmp(file_name, width, height, (unsigned char*)p_bmp565_data);
|
||||
delete []p_bmp565_data;
|
||||
return ret;
|
||||
}
|
Reference in New Issue
Block a user