Ejemplo n.º 1
0
/* draw raw hline */
static void framebuffer_draw_raw_hline(rt_uint8_t *pixels, int x1, int x2, int y)
{
    struct rtgui_graphic_driver *drv;
    rt_uint8_t *dst;

    drv = rtgui_graphic_get_device();
    dst = GET_PIXEL(drv, x1, y, rt_uint8_t);
    memcpy(dst, pixels,
              (x2 - x1) * _UI_BITBYTES(drv->bits_per_pixel));
}
Ejemplo n.º 2
0
rt_uint8_t rtgui_color_get_bpp(rt_uint8_t pixel_format)
{
	rt_uint8_t bpp = 4;
	
	if (pixel_format <= RTGRAPHIC_PIXEL_FORMAT_ARGB888)
	{
		bpp = _UI_BITBYTES(pixel_bits_table[pixel_format]);
	}

	return bpp;
}
Ejemplo n.º 3
0
static rt_bool_t rtgui_image_hdc_load(struct rtgui_image *image, struct rtgui_filerw *file, rt_bool_t load)
{
    rt_uint32_t header[5];
    struct rtgui_image_hdc *hdc;

    hdc = (struct rtgui_image_hdc *) rtgui_malloc(sizeof(struct rtgui_image_hdc));
    if (hdc == RT_NULL) return RT_FALSE;

    hdc->hw_driver = rtgui_graphic_driver_get_default();
    if (hdc->hw_driver == RT_NULL)
    {
        rtgui_free(hdc);
        return RT_FALSE;
    }

    rtgui_filerw_read(file, (char *)&header, 1, sizeof(header));

    /* set image information */
    image->w = (rt_uint16_t)header[1];
    image->h = (rt_uint16_t)header[2];
    image->engine = &rtgui_image_hdc_engine;
    image->data = hdc;
    hdc->filerw = file;
    hdc->byte_per_pixel = _UI_BITBYTES(hdc->hw_driver->bits_per_pixel);
    hdc->pitch = image->w * hdc->byte_per_pixel;
    hdc->pixel_offset = rtgui_filerw_tell(file);

    if (load == RT_TRUE)
    {
        /* load all pixels */
        hdc->pixels = rtgui_malloc(image->h * hdc->pitch);
        if (hdc->pixels == RT_NULL)
        {
            /* release data */
            rtgui_free(hdc);
            return RT_FALSE;
        }

        rtgui_filerw_read(hdc->filerw, hdc->pixels, 1, image->h * hdc->pitch);
        rtgui_filerw_close(hdc->filerw);
        hdc->filerw = RT_NULL;
        hdc->pixel_offset = 0;
    }
    else
    {
        hdc->pixels = RT_NULL;
    }

    return RT_TRUE;
}
Ejemplo n.º 4
0
static void _graphic_driver_vmode_init(void)
{
	if (_vfb_driver.width != _driver.width || _vfb_driver.height != _driver.height)
	{
		if (_vfb_driver.framebuffer != RT_NULL) rtgui_free((void*)_vfb_driver.framebuffer);

		_vfb_driver.device = RT_NULL;
		_vfb_driver.pixel_format = RTGUI_VFB_PIXEL_FMT;
		_vfb_driver.bits_per_pixel = rtgui_color_get_bits(RTGUI_VFB_PIXEL_FMT);
		_vfb_driver.width  = _driver.width;
		_vfb_driver.height = _driver.height;
		_vfb_driver.pitch  = _driver.width * _UI_BITBYTES(_vfb_driver.bits_per_pixel);
		_vfb_driver.framebuffer = rtgui_malloc(_vfb_driver.height * _vfb_driver.pitch);
		_vfb_driver.ext_ops = RT_NULL;
		_vfb_driver.ops = rtgui_framebuffer_get_ops(_vfb_driver.pixel_format);
	}
}
Ejemplo n.º 5
0
/* blit a dc to another dc */
static void rtgui_dc_buffer_blit(struct rtgui_dc *self, struct rtgui_point *dc_pt, struct rtgui_dc *dest, rtgui_rect_t *rect)
{
	int pitch;
	rt_uint16_t rect_width, rect_height;
	struct rtgui_rect _rect, *dest_rect;
    struct rtgui_point dc_point;
    struct rtgui_dc_buffer *dc = (struct rtgui_dc_buffer *)self;

    if (rtgui_dc_get_visible(dest) == RT_FALSE)
        return;

	/* use the (0,0) origin point */
    if (dc_pt == RT_NULL)
        dc_point = rtgui_empty_point;
    else
    {
        dc_point = *dc_pt;
    }

    rtgui_dc_get_rect(dest, &_rect);
	/* use the rect of dest dc */
	if (rect == RT_NULL)
	{
		dest_rect = &_rect;
	}
	else
    {
        dest_rect = rect;
        if (dest_rect->x1 > _rect.x2 || dest_rect->y1 > _rect.y2)
            return;
        if (dest_rect->x1 < 0)
        {
            if (-dest_rect->x1 > dc->width)
                return;
            dc_point.x += -dest_rect->x1;
            dest_rect->x1 = 0;
        }
        if (dest_rect->y1 < 0)
        {
            if (-dest_rect->y1 > dc->height)
                return;
            dc_point.y += -dest_rect->y1;
            dest_rect->y1 = 0;
        }
        if (dest_rect->x2 > _rect.x2)
            dest_rect->x2 = _rect.x2;
        if (dest_rect->y2 > _rect.y2)
            dest_rect->y2 = _rect.y2;
    }

    if (dc_point.x > dc->width || dc_point.y > dc->height)
        return;

	/* get the minimal width and height */
	rect_width  = _UI_MIN(rtgui_rect_width(*dest_rect), dc->width - dc_point.x);
	rect_height = _UI_MIN(rtgui_rect_height(*dest_rect), dc->height - dc_point.y);

    if ((dest->type == RTGUI_DC_HW) || (dest->type == RTGUI_DC_CLIENT))
    {
		int index;
        rt_uint8_t *line_ptr, *pixels;
        rtgui_blit_line_func blit_line;
		struct rtgui_graphic_driver *hw_driver;

		hw_driver = rtgui_graphic_driver_get_default();
        /* prepare pixel line */
		pixels = _dc_get_pixel(dc, dc_point.x, dc_point.y);

        if (hw_driver->bits_per_pixel == _dc_get_bits_per_pixel(dc))
        {
			if (dest->type == RTGUI_DC_HW && hw_driver->framebuffer != RT_NULL)
			{
				rt_uint8_t *hw_pixels;
				struct rtgui_dc_hw *hw;

				hw = (struct rtgui_dc_hw*)dest;

				/* NOTES: the rect of DC is the logic coordination.
				 * It should be converted to client
				 */
				if (dest_rect != &_rect)
				{
					/* use local rect */
					_rect = *dest_rect;
					dest_rect = &_rect;
				}
				rtgui_rect_moveto(dest_rect, hw->owner->extent.x1, hw->owner->extent.y1);

				pitch = rtgui_color_get_bpp(hw_driver->pixel_format) * rect_width;
				hw_pixels = (rt_uint8_t*)(hw_driver->framebuffer + dest_rect->y1 * hw_driver->pitch +
					dest_rect->x1 * rtgui_color_get_bpp(hw_driver->pixel_format));

				/* do the blit with memory copy */
				for (index = 0; index < rect_height; index ++)
				{
					rt_memcpy(hw_pixels, pixels, pitch);
					pixels += dc->pitch;
					hw_pixels += hw_driver->pitch;
				}
			}
			else
			{
	            /* it's the same bits per pixel, draw it directly */
	            for (index = dest_rect->y1; index < dest_rect->y1 + rect_height; index++)
	            {
	                dest->engine->blit_line(dest, dest_rect->x1, dest_rect->x1 + rect_width, index, pixels);
					pixels += dc->pitch;
	            }
			}
        }
        else
        {
			struct rtgui_graphic_driver *hw_driver;

			hw_driver = rtgui_graphic_driver_get_default();

			if ((dc->pixel_format == RTGRAPHIC_PIXEL_FORMAT_ARGB888) && (dest->type == RTGUI_DC_HW) &&
				(hw_driver->framebuffer != RT_NULL) &&
				(hw_driver->pixel_format == RTGRAPHIC_PIXEL_FORMAT_RGB565))
			{
				/* do the fast ARGB to RGB565 blit */
				struct rtgui_blit_info info;
				struct rtgui_widget *owner;

				/* blit source */
				info.src = _dc_get_pixel(dc, dc_point.x, dc_point.y);
				info.src_fmt = dc->pixel_format;
				info.src_h = rect_height;
				info.src_w = rect_width;
				info.src_pitch = dc->pitch;
				info.src_skip = info.src_pitch - info.src_w * rtgui_color_get_bpp(dc->pixel_format);

				owner = ((struct rtgui_dc_hw*)dest)->owner;

				/* blit destination */
				info.dst = (rt_uint8_t*)hw_driver->framebuffer;
				info.dst = info.dst + (owner->extent.y1 + dest_rect->y1) * hw_driver->pitch +
                    (owner->extent.x1 + dest_rect->x1) * rtgui_color_get_bpp(hw_driver->pixel_format);
				info.dst_fmt = hw_driver->pixel_format;
				info.dst_h = rect_height;
				info.dst_w = rect_width;
				info.dst_pitch = hw_driver->pitch;
				info.dst_skip = info.dst_pitch - info.dst_w * rtgui_color_get_bpp(hw_driver->pixel_format);

				rtgui_blit(&info);
			}
			else
			{
	            /* get blit line function */
	            blit_line = rtgui_blit_line_get(_UI_BITBYTES(hw_driver->bits_per_pixel), rtgui_color_get_bpp(dc->pixel_format));
	            /* calculate pitch */
	            pitch = rect_width * rtgui_color_get_bpp(dc->pixel_format);
	            /* create line buffer */
	            line_ptr = (rt_uint8_t *) rtgui_malloc(rect_width * _UI_BITBYTES(hw_driver->bits_per_pixel));

	            /* draw each line */
	            for (index = dest_rect->y1; index < dest_rect->y1 + rect_height; index ++)
	            {
	                /* blit on line buffer */
	                blit_line(line_ptr, (rt_uint8_t *)pixels, pitch);
	                pixels += dc->pitch;

	                /* draw on hardware dc */
	                dest->engine->blit_line(dest, dest_rect->x1, dest_rect->x1 + rect_width, index, line_ptr);
	            }

	            /* release line buffer */
	            rtgui_free(line_ptr);
			}
        }
    }
	else if (dest->type == RTGUI_DC_BUFFER)
	{
		struct rtgui_dc_buffer *dest_dc = (struct rtgui_dc_buffer*)dest;

		if (dest_dc->pixel_format == dc->pixel_format && dest_dc->pixel_format == RTGRAPHIC_PIXEL_FORMAT_RGB565)
		{
			int index;
			rt_uint8_t *pixels, *dest_pixels;

			/* get pitch */
			pitch = rect_width * rtgui_color_get_bpp(dc->pixel_format);

			pixels = _dc_get_pixel(dc, dc_point.x, dc_point.y);
			dest_pixels = _dc_get_pixel(dest_dc, dest_rect->x1, dest_rect->y1);

			for (index = 0; index < rect_height; index ++)
			{
				rt_memcpy(dest_pixels, pixels, pitch);
				pixels += dc->pitch;
				dest_pixels += dest_dc->pitch;
			}
		}
		else /* use rtgui_blit to handle buffer blit */
		{
			/* do the fast ARGB to RGB565 blit */
			struct rtgui_blit_info info;

			/* blit source */
			info.src = _dc_get_pixel(dc, dc_point.x, dc_point.y);
			info.src_fmt = dc->pixel_format;
			info.src_h = rect_height;
			info.src_w = rect_width;
			info.src_pitch = dc->pitch;
			info.src_skip = info.src_pitch - info.src_w * rtgui_color_get_bpp(dc->pixel_format);

			/* blit destination */
			info.dst = _dc_get_pixel(dest_dc, dest_rect->x1, dest_rect->y1);
			info.dst_fmt = dest_dc->pixel_format;
			info.dst_h = rect_height;
			info.dst_w = rect_width;
			info.dst_pitch = dest_dc->pitch;
			info.dst_skip = info.dst_pitch - info.dst_w * rtgui_color_get_bpp(dest_dc->pixel_format);

			rtgui_blit(&info);
		}
	}
}
Ejemplo n.º 6
0
rt_err_t rtgui_graphic_set_device(rt_device_t device)
{
    rt_err_t result;
    struct rt_device_graphic_info info;
    struct rtgui_graphic_ext_ops *ext_ops;

    /* get framebuffer address */
    result = rt_device_control(device, RTGRAPHIC_CTRL_GET_INFO, &info);
    if (result != RT_EOK)
    {
        /* get device information failed */
        return -RT_ERROR;
    }

    /* if the first set graphic device */
    if (_driver.width == 0 || _driver.height == 0)
    {
        rtgui_rect_t rect;

        rtgui_get_mainwin_rect(&rect);
        if (rect.x2 == 0 || rect.y2 == 0)
        {
            rtgui_rect_init(&rect, 0, 0, info.width, info.height);
            /* re-set main-window */
            rtgui_set_mainwin_rect(&rect);
        }
    }

    /* initialize framebuffer driver */
    _driver.device = device;
    _driver.pixel_format = info.pixel_format;
    _driver.bits_per_pixel = info.bits_per_pixel;
    _driver.width = info.width;
    _driver.height = info.height;
    _driver.pitch = _driver.width * _UI_BITBYTES(_driver.bits_per_pixel);
    _driver.framebuffer = info.framebuffer;

    /* get graphic extension operations */
    result = rt_device_control(device, RTGRAPHIC_CTRL_GET_EXT, &ext_ops);
    if (result == RT_EOK)
    {
        _driver.ext_ops = ext_ops;
    }

    if (info.framebuffer != RT_NULL)
    {
        /* is a frame buffer device */
        _driver.ops = rtgui_framebuffer_get_ops(_driver.pixel_format);
    }
    else
    {
        /* is a pixel device */
        _driver.ops = rtgui_pixel_device_get_ops(_driver.pixel_format);
    }

#ifdef RTGUI_USING_HW_CURSOR
    /* set default cursor image */
    rtgui_cursor_set_image(RTGUI_CURSOR_ARROW);
#endif

#ifdef RTGUI_USING_VFRAMEBUFFER
    _graphic_driver_vmode_init();
#endif

    return RT_EOK;
}
Ejemplo n.º 7
0
/* blit a dc to a hardware dc */
static void rtgui_dc_buffer_blit(struct rtgui_dc *self, struct rtgui_point *dc_point, struct rtgui_dc *dest, rtgui_rect_t *rect)
{
	int pitch;
	rt_uint16_t rect_width, rect_height;
    struct rtgui_dc_buffer *dc = (struct rtgui_dc_buffer *)self;

    if (dc_point == RT_NULL) dc_point = &rtgui_empty_point;
    if (rtgui_dc_get_visible(dest) == RT_FALSE) return;

	/* get the minimal width and height */
	rect_width  = _UI_MIN(rtgui_rect_width(*rect), dc->width - dc_point->x);
	rect_height = _UI_MIN(rtgui_rect_height(*rect), dc->height - dc_point->y);

    if ((dest->type == RTGUI_DC_HW) || (dest->type == RTGUI_DC_CLIENT))
    {
		int index;
        rt_uint8_t *line_ptr, *pixels;
        rtgui_blit_line_func blit_line;
		struct rtgui_graphic_driver *hw_driver;

		hw_driver = rtgui_graphic_driver_get_default();
        /* prepare pixel line */
		pixels = _dc_get_pixel(dc, dc_point->x, dc_point->y);

        if (hw_driver->bits_per_pixel == _dc_get_bits_per_pixel(dc))
        {
			if (dest->type == RTGUI_DC_HW && hw_driver->framebuffer != RT_NULL)
			{
				rt_uint8_t *hw_pixels;

				pitch = rtgui_color_get_bpp(hw_driver->pixel_format) * rect_width;
				hw_pixels = (rt_uint8_t*)(hw_driver->framebuffer + rect->y1 * hw_driver->pitch + 
					rect->x1 * rtgui_color_get_bpp(hw_driver->pixel_format));
				for (index = 0; index < rect_height; index ++)
				{
					memcpy(hw_pixels, pixels, pitch);
					pixels += dc->pitch;
					hw_pixels += hw_driver->pitch;
				}
			}
			else
			{
	            /* it's the same bits per pixel, draw it directly */
	            for (index = rect->y1; index < rect->y1 + rect_height; index++)
	            {
	                dest->engine->blit_line(dest, rect->x1, rect->x1 + rect_width, index, pixels);
					pixels += dc->pitch;
	            }
			}
        }
        else
        {
            /* get blit line function */
            blit_line = rtgui_blit_line_get(_UI_BITBYTES(hw_driver->bits_per_pixel), rtgui_color_get_bpp(dc->pixel_format));
            /* calculate pitch */
            pitch = rect_width * rtgui_color_get_bpp(hw_driver->pixel_format);
            /* create line buffer */
            line_ptr = (rt_uint8_t *) rtgui_malloc(rect_width * _UI_BITBYTES(hw_driver->bits_per_pixel));

            /* draw each line */
            for (index = rect->y1; index < rect->y1 + rect_height; index ++)
            {
                /* blit on line buffer */
                blit_line(line_ptr, (rt_uint8_t *)pixels, pitch);
                pixels += dc->pitch;

                /* draw on hardware dc */
                dest->engine->blit_line(dest, rect->x1, rect->x1 + rect_width, index, line_ptr);
            }

            /* release line buffer */
            rtgui_free(line_ptr);
        }
    }
	else if (dest->type == RTGUI_DC_BUFFER)
	{
		struct rtgui_dc_buffer *dest_dc = (struct rtgui_dc_buffer*)dest;

		if (dest_dc->pixel_format == dc->pixel_format)
		{
			int index;
			rt_uint8_t *pixels, *dest_pixels;
			
			/* get pitch */
			pitch = rect_width * rtgui_color_get_bpp(dc->pixel_format);

			pixels = _dc_get_pixel(dc, dc_point->x, dc_point->y);
			dest_pixels = _dc_get_pixel(dest_dc, rect->x1, rect->y1);

			for (index = 0; index < rect_height; index ++)
			{
				memcpy(dest_pixels, pixels, pitch);
				pixels += dc->pitch;
				dest_pixels += dest_dc->pitch;
			}
		}
	}
}