support 16 bits, 32 bits color, framebuffer map; remove redundant files

This commit is contained in:
idea4good
2017-12-13 22:29:28 +08:00
parent 50b144b4c8
commit 565ef43706
43 changed files with 590 additions and 1096 deletions

View File

@@ -3,21 +3,23 @@
#include "../core_include/cmd_target.h"
#include "../core_include/wnd.h"
#include "../core_include/surface.h"
#include "../core_include/display.h"
#include <string.h>
#include <stdlib.h>
c_surface::c_surface(c_display* display, void* phy_fb, unsigned int width, unsigned int height)
c_surface::c_surface(c_display* display, void* phy_fb, 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_fb = m_usr = NULL;
m_top_zorder = m_max_zorder = Z_ORDER_LEVEL_0;
m_is_active = false;
m_fb = calloc(m_width * m_height * 2, 1);
m_frame_layers[Z_ORDER_LEVEL_0].rect = c_rect(0,0,m_width,m_height);
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);
}
void c_surface::set_surface(void* wnd_root, Z_ORDER_LEVEL max_z_order)
@@ -26,69 +28,29 @@ void c_surface::set_surface(void* wnd_root, Z_ORDER_LEVEL max_z_order)
m_max_zorder = max_z_order;
for(int i = 0; i <= m_max_zorder; i++)
{
m_frame_layers[i].fb = calloc(m_width * m_height * 2, 1);
m_frame_layers[i].fb = calloc(m_width * m_height, m_color_bytes);
ASSERT(NULL != m_frame_layers[i].fb);
}
}
void c_surface::do_quick_set_pixel(int x, int y, unsigned int rgb)
{
((short*)m_fb)[y * m_width + x] = rgb;
if(m_is_active)
{
((short*)m_phy_fb)[y * m_width + x] = rgb;
}
}
void c_surface::do_quick_fill_rect(int x0, int y0, int x1, int y1, unsigned int rgb)
{
if (x0 < 0 || y0 < 0 || x1 < 0 || y1 < 0)
{
ASSERT(FALSE);
}
if (x0 >= m_width || x1 >= m_width || y0 >= m_height || y1 >= m_height)
{
ASSERT(FALSE);
}
int x;
short *fb, *phy_fb;
for(;y0 <= y1; y0++)
{
x = x0;
fb = &((short*)m_fb)[y0 * m_width + x];
phy_fb = &((short*)m_phy_fb)[y0 * m_width + x];
for(; x <= x1; x++)
{
*fb++ = rgb;
if(m_is_active)
{
*phy_fb++ = rgb;
}
}
}
}
void c_surface::set_pixel(int x, int y, unsigned int rgb, unsigned int z_order)
{
if ( x >= m_width || y >= m_height || x < 0 || y < 0)
if (x >= m_width || y >= m_height || x < 0 || y < 0)
{
return;
}
if (z_order > m_max_zorder)
{
ASSERT(FALSE);
return;
}
if(z_order > m_top_zorder)
if (z_order > m_top_zorder)
{
m_top_zorder = (Z_ORDER_LEVEL)z_order;
}
if(0 == m_frame_layers[z_order].rect.PtInRect(x, y))
if (0 == m_frame_layers[z_order].rect.PtInRect(x, y))
{
ASSERT(FALSE);
return;
@@ -96,20 +58,20 @@ void c_surface::set_pixel(int x, int y, unsigned int rgb, unsigned int z_order)
if (z_order == m_max_zorder)
{
return do_quick_set_pixel(x, y, rgb);
return set_pixel_on_fb(x, y, rgb);
}
((short*)(m_frame_layers[z_order].fb))[x + y * m_width] = 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 do_quick_set_pixel(x, y, rgb);
return set_pixel_on_fb(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))
if (1 == m_frame_layers[tmp_z_order].rect.PtInRect(x, y))
{
is_covered = true;
break;
@@ -118,10 +80,75 @@ void c_surface::set_pixel(int x, int y, unsigned int rgb, unsigned int z_order)
if (!is_covered)
{
((short*)m_fb)[y * m_width + x] = rgb;
if(m_is_active)
set_pixel_on_fb(x, y, rgb);
}
}
void c_surface::set_pixel_on_fb(int x, int y, unsigned int rgb)
{
((unsigned int*)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 int*)m_phy_fb)[y * (m_display->get_width()) + x] = rgb;
}
}
void c_surface::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, rgb);
}
if (z_order == m_top_zorder)
{
int x, y;
unsigned int *mem_fb;
for (y = y0; y <= y1; y++)
{
((short*)m_phy_fb)[y * m_width + x] = rgb;
x = x0;
mem_fb = &((unsigned int*)m_frame_layers[z_order].fb)[y * m_width + x];
for (; x <= x1; x++)
{
*mem_fb++ = rgb;
}
}
return fill_rect_on_fb(x0, y0, x1, y1, rgb);
}
for (; y0 <= y1; y0++)
{
draw_hline(x0, x1, y0, rgb, z_order);
}
}
void c_surface::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 int *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 int*)m_fb)[y0 * m_width + x];
phy_fb = &((unsigned int*)m_phy_fb)[y0 * display_width + x];
for (; x <= x1; x++)
{
*fb++ = rgb;
if (m_is_active && (x < display_width) && (y0 < display_height))
{
*phy_fb++ = rgb;
}
}
}
}
@@ -137,10 +164,10 @@ unsigned int c_surface::get_pixel(int x, int y, unsigned int z_order)
if (z_order == m_max_zorder)
{
return ((unsigned short*)m_fb)[y * m_width + x];
return ((unsigned int*)m_fb)[y * m_width + x];
}
return ((unsigned short*)(m_frame_layers[z_order].fb))[y * m_width + x];
return ((unsigned int*)(m_frame_layers[z_order].fb))[y * m_width + x];
}
void c_surface::draw_hline(int x0, int x1, int y, unsigned int rgb, unsigned int z_order)
@@ -277,55 +304,6 @@ void c_surface::draw_rect(int x0, int y0, int x1, int y1, unsigned int rgb, unsi
draw_vline(x1, y0, y1, rgb, z_order);
}
void c_surface::fill_rect(int x0, int y0, int x1, int y1, unsigned int rgb, unsigned int z_order)
{
if (z_order == m_max_zorder)
{
return do_quick_fill_rect(x0, y0, x1, y1, rgb);
}
if(z_order == m_top_zorder)
{
int x,y;
short *mem_fb;
for(y = y0; y <= y1; y++)
{
x = x0;
mem_fb = &((short*)m_frame_layers[z_order].fb)[y * m_width + x];
for(; x <= x1; x++)
{
*mem_fb++ = rgb;
}
}
return do_quick_fill_rect(x0, y0, x1, y1, rgb);
}
for (; y0 <= y1; y0++)
{
draw_hline(x0, x1, y0, rgb, z_order);
}
}
int c_surface::copy_layer_pixel_2_fb(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;
}
char* des_addr,* src_addr;
short rgb = ((short*)(m_frame_layers[z_order].fb))[x + y * m_width];
((short*)m_fb)[y * m_width + x] = rgb;
if(m_is_active)
{
((short*)m_phy_fb)[y * m_width + x] = rgb;
}
return 0;
}
int c_surface::set_frame_layer(c_rect& rect, unsigned int z_order)
{
if (z_order <= Z_ORDER_LEVEL_0 || z_order >= Z_ORDER_LEVEL_MAX)
@@ -363,6 +341,39 @@ int c_surface::set_frame_layer(c_rect& rect, unsigned int z_order)
return 1;
}
int c_surface::copy_layer_pixel_2_fb(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;
}
int display_width = m_display->get_width();
int display_height = m_display->get_height();
if (m_color_bytes == 4)
{
unsigned int rgb = ((unsigned int*)(m_frame_layers[z_order].fb))[x + y * m_width];
((unsigned int*)m_fb)[y * m_width + x] = rgb;
if (m_is_active && (x < display_width) && (y < display_height))
{
((unsigned int*)m_phy_fb)[y * display_width + x] = rgb;
}
}
else//16 bits
{
short rgb = ((short*)(m_frame_layers[z_order].fb))[x + y * m_width];
((short*)m_fb)[y * m_width + x] = rgb;
if (m_is_active && (x < display_width) && (y < display_height))
{
((short*)m_phy_fb)[y * display_width + x] = rgb;
}
}
return 0;
}
void c_surface::draw_custom_shape(int l, int t, int r, int b, unsigned int color, const CUSTOM_SHAPE pRgn[], int z_order)
{
int i = 0;
@@ -395,39 +406,30 @@ void c_surface::draw_custom_shape(int l, int t, int r, int b, unsigned int color
int c_surface::flush_scrren(int left, int top, int right, int bottom)
{
if(left < 0 || left >= m_width)
{
ASSERT(FALSE);
}
if(right < 0 || right >= m_width)
if(left < 0 || left >= m_width || right < 0 || right >= m_width ||
top < 0 || top >= m_height || bottom < 0 || bottom >= m_height)
{
ASSERT(FALSE);
}
if(top < 0 || top >= m_height)
{
ASSERT(FALSE);
}
if(bottom < 0 || bottom >= m_height)
{
ASSERT(FALSE);
}
if(!m_is_active)
if(!m_is_active || (0 == m_phy_fb) || (0 == m_fb))
{
return -1;
}
if((0 == m_phy_fb) || (0 == m_fb))
{
return -2;
}
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++)
{
void* s_addr = (char*)m_fb + ((y * m_width + left) * 2);
void* d_addr = (char*)m_phy_fb + ((y * m_width + left) * 2);
memcpy(d_addr, s_addr, (right - left) * 2);
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);
}
return 0;
}
@@ -444,4 +446,143 @@ bool c_surface::is_valid(c_rect rect)
return false;
}
return true;
}
//////////////////////////////////////////////////////////////////////////////////////
void c_surface_16bits::set_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 (z_order > m_max_zorder)
{
ASSERT(FALSE);
return;
}
if (z_order > m_top_zorder)
{
m_top_zorder = (Z_ORDER_LEVEL)z_order;
}
if (0 == m_frame_layers[z_order].rect.PtInRect(x, y))
{
ASSERT(FALSE);
return;
}
rgb = GLT_RGB_32_to_16(rgb);
if (z_order == m_max_zorder)
{
return set_pixel_on_fb(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_on_fb(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_on_fb(x, y, rgb);
}
}
void c_surface_16bits::set_pixel_on_fb(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;
}
}
void c_surface_16bits::fill_rect(int x0, int y0, int x1, int y1, unsigned int rgb, unsigned int z_order)
{
rgb = GLT_RGB_32_to_16(rgb);
if (z_order == m_max_zorder)
{
return fill_rect_on_fb(x0, y0, x1, y1, rgb);
}
if (z_order == m_top_zorder)
{
int x, y;
unsigned short *mem_fb;
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;
}
}
return fill_rect_on_fb(x0, y0, x1, y1, 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];
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 GLT_RGB_16_to_32(((unsigned short*)m_fb)[y * m_width + x]);
}
return GLT_RGB_16_to_32(((unsigned short*)(m_frame_layers[z_order].fb))[y * m_width + x]);
}