Export API for uploading a tex subregion from a CoglBuffer

This exposes 2 experimental functions that make it possible to upload a
subregion of a texture from a CoglBuffer by first wrapping the buffer as
a CoglBitmap and then allowing uploading of a subregion from a
CoglBitmap. The new functions are:

cogl_bitmap_new_from_buffer() and
cogl_texture_set_region_from_bitmap()

Actually for now we are exporting this API for practical reasons since
we already had this API internally and it enables a specific feature
that was requested, but it is worth nothing that it's quite likely we
will replace these with functions that don't involve the CoglBitmap API
at some point.

For reference: The CoglBitmap API was actually removed from the 2.0
experimental API reference manual some time ago because the hope was
that we'd come up with a neater replacement. It doesn't seem entirely
clear what the scope of the CoglBitmap api is so it has became a bit of
a dumping ground.  CoglBitmap is used for image loading, as a means to
represent the layout of image data and also internally deals with format
conversions.

Note: Because we are avoiding including CoglBitmap as part of the 2.0
API these functions aren't currently included in the 2.0 reference
manual.

Reviewed-by: Neil Roberts <neil@linux.intel.com>
This commit is contained in:
Robert Bragg 2011-07-25 22:14:08 +01:00
parent 7860df92d1
commit a9184d5cb7
9 changed files with 176 additions and 130 deletions

View File

@ -437,52 +437,52 @@ _cogl_atlas_texture_set_region_with_border (CoglAtlasTexture *atlas_tex,
CoglAtlas *atlas = atlas_tex->atlas;
/* Copy the central data */
if (!_cogl_texture_set_region_from_bitmap (atlas->texture,
src_x, src_y,
dst_x + atlas_tex->rectangle.x + 1,
dst_y + atlas_tex->rectangle.y + 1,
dst_width,
dst_height,
bmp))
if (!cogl_texture_set_region_from_bitmap (atlas->texture,
src_x, src_y,
dst_x + atlas_tex->rectangle.x + 1,
dst_y + atlas_tex->rectangle.y + 1,
dst_width,
dst_height,
bmp))
return FALSE;
/* Update the left edge pixels */
if (dst_x == 0 &&
!_cogl_texture_set_region_from_bitmap (atlas->texture,
src_x, src_y,
atlas_tex->rectangle.x,
dst_y + atlas_tex->rectangle.y + 1,
1, dst_height,
bmp))
!cogl_texture_set_region_from_bitmap (atlas->texture,
src_x, src_y,
atlas_tex->rectangle.x,
dst_y + atlas_tex->rectangle.y + 1,
1, dst_height,
bmp))
return FALSE;
/* Update the right edge pixels */
if (dst_x + dst_width == atlas_tex->rectangle.width - 2 &&
!_cogl_texture_set_region_from_bitmap (atlas->texture,
src_x + dst_width - 1, src_y,
atlas_tex->rectangle.x +
atlas_tex->rectangle.width - 1,
dst_y + atlas_tex->rectangle.y + 1,
1, dst_height,
bmp))
!cogl_texture_set_region_from_bitmap (atlas->texture,
src_x + dst_width - 1, src_y,
atlas_tex->rectangle.x +
atlas_tex->rectangle.width - 1,
dst_y + atlas_tex->rectangle.y + 1,
1, dst_height,
bmp))
return FALSE;
/* Update the top edge pixels */
if (dst_y == 0 &&
!_cogl_texture_set_region_from_bitmap (atlas->texture,
src_x, src_y,
dst_x + atlas_tex->rectangle.x + 1,
atlas_tex->rectangle.y,
dst_width, 1,
bmp))
!cogl_texture_set_region_from_bitmap (atlas->texture,
src_x, src_y,
dst_x + atlas_tex->rectangle.x + 1,
atlas_tex->rectangle.y,
dst_width, 1,
bmp))
return FALSE;
/* Update the bottom edge pixels */
if (dst_y + dst_height == atlas_tex->rectangle.height - 2 &&
!_cogl_texture_set_region_from_bitmap (atlas->texture,
src_x, src_y + dst_height - 1,
dst_x + atlas_tex->rectangle.x + 1,
atlas_tex->rectangle.y +
atlas_tex->rectangle.height - 1,
dst_width, 1,
bmp))
!cogl_texture_set_region_from_bitmap (atlas->texture,
src_x, src_y + dst_height - 1,
dst_x + atlas_tex->rectangle.x + 1,
atlas_tex->rectangle.y +
atlas_tex->rectangle.height - 1,
dst_width, 1,
bmp))
return FALSE;
return TRUE;
@ -526,11 +526,11 @@ _cogl_atlas_texture_set_region (CoglTexture *tex,
}
else
/* Otherwise we can just forward on to the sub texture */
return _cogl_texture_set_region_from_bitmap (atlas_tex->sub_texture,
src_x, src_y,
dst_x, dst_y,
dst_width, dst_height,
bmp);
return cogl_texture_set_region_from_bitmap (atlas_tex->sub_texture,
src_x, src_y,
dst_x, dst_y,
dst_width, dst_height,
bmp);
}
static CoglPixelFormat

View File

@ -83,17 +83,6 @@ _cogl_bitmap_new_shared (CoglBitmap *shared_bmp,
int height,
int rowstride);
/* This creates a cogl bitmap that internally references a pixel
array. The data is not copied. _cogl_bitmap_map will divert to
mapping the pixel array */
CoglBitmap *
_cogl_bitmap_new_from_buffer (CoglBuffer *buffer,
CoglPixelFormat format,
int width,
int height,
int rowstride,
int offset);
gboolean
_cogl_bitmap_can_convert (CoglPixelFormat src, CoglPixelFormat dst);

View File

@ -327,12 +327,12 @@ cogl_bitmap_new_from_file (const char *filename,
}
CoglBitmap *
_cogl_bitmap_new_from_buffer (CoglBuffer *buffer,
CoglPixelFormat format,
int width,
int height,
int rowstride,
int offset)
cogl_bitmap_new_from_buffer (CoglBuffer *buffer,
CoglPixelFormat format,
int width,
int height,
int rowstride,
int offset)
{
CoglBitmap *bmp;

View File

@ -29,6 +29,7 @@
#define __COGL_BITMAP_H__
#include <cogl/cogl-types.h>
#include <cogl/cogl-buffer.h>
G_BEGIN_DECLS
@ -62,6 +63,37 @@ CoglBitmap *
cogl_bitmap_new_from_file (const char *filename,
GError **error);
#if defined (COGL_ENABLE_EXPERIMENTAL_API)
#define cogl_bitmap_new_from_buffer cogl_bitmap_new_from_buffer_EXP
/**
* cogl_bitmap_new_from_buffer:
* @buffer: A #CoglBuffer containing image data
* @format: The #CoglPixelFormat defining the format of the image data
* in the given @buffer.
* @width: The width of the image data in the given @buffer.
* @height: The height of the image data in the given @buffer.
* @rowstride: The rowstride in bytes of the image data in the given @buffer.
* @offset: The offset into the given @buffer to the first pixel that
* should be considered part of the #CoglBitmap.
*
* Wraps some image data that has been uploaded into a #CoglBuffer as
* a #CoglBitmap. The data is not copied in this process.
*
* Return value: a #CoglBitmap encapsulating the given @buffer.
*
* Since: 1.8
* Stability: unstable
*/
CoglBitmap *
cogl_bitmap_new_from_buffer (CoglBuffer *buffer,
CoglPixelFormat format,
int width,
int height,
int rowstride,
int offset);
#endif
/**
* cogl_bitmap_get_size_from_file:
* @filename: the file to check

View File

@ -409,12 +409,12 @@ _cogl_sub_texture_set_region (CoglTexture *tex,
{
CoglSubTexture *sub_tex = COGL_SUB_TEXTURE (tex);
return _cogl_texture_set_region_from_bitmap (sub_tex->full_texture,
src_x, src_y,
dst_x + sub_tex->sub_x,
dst_y + sub_tex->sub_y,
dst_width, dst_height,
bmp);
return cogl_texture_set_region_from_bitmap (sub_tex->full_texture,
src_x, src_y,
dst_x + sub_tex->sub_x,
dst_y + sub_tex->sub_y,
dst_width, dst_height,
bmp);
}
static CoglPixelFormat

View File

@ -318,18 +318,18 @@ _cogl_texture_2d_sliced_set_waste (CoglTexture2DSliced *tex_2ds,
NULL,
NULL);
_cogl_texture_set_region_from_bitmap (slice_tex,
0, /* src_x */
0, /* src_y */
/* dst_x */
x_span->size - x_span->waste,
y_iter->intersect_start -
y_span->start, /* dst_y */
x_span->waste, /* dst_width */
/* dst_height */
y_iter->intersect_end -
y_iter->intersect_start,
waste_bmp);
cogl_texture_set_region_from_bitmap (slice_tex,
0, /* src_x */
0, /* src_y */
/* dst_x */
x_span->size - x_span->waste,
y_iter->intersect_start -
y_span->start, /* dst_y */
x_span->waste, /* dst_width */
/* dst_height */
y_iter->intersect_end -
y_iter->intersect_start,
waste_bmp);
cogl_object_unref (waste_bmp);
}
@ -374,17 +374,17 @@ _cogl_texture_2d_sliced_set_waste (CoglTexture2DSliced *tex_2ds,
NULL,
NULL);
_cogl_texture_set_region_from_bitmap (slice_tex,
0, /* src_x */
0, /* src_y */
/* dst_x */
x_iter->intersect_start -
x_iter->pos,
/* dst_y */
y_span->size - y_span->waste,
copy_width, /* dst_width */
y_span->waste, /* dst_height */
waste_bmp);
cogl_texture_set_region_from_bitmap (slice_tex,
0, /* src_x */
0, /* src_y */
/* dst_x */
x_iter->intersect_start -
x_iter->pos,
/* dst_y */
y_span->size - y_span->waste,
copy_width, /* dst_width */
y_span->waste, /* dst_height */
waste_bmp);
cogl_object_unref (waste_bmp);
}
@ -426,16 +426,16 @@ _cogl_texture_2d_sliced_upload_to_gl (CoglTexture2DSliced *tex_2ds,
slice_tex = g_array_index (tex_2ds->slice_textures,
CoglHandle, slice_num);
_cogl_texture_set_region_from_bitmap (slice_tex,
x_span->start, /* src x */
y_span->start, /* src y */
0, /* dst x */
0, /* dst y */
x_span->size -
x_span->waste, /* width */
y_span->size -
y_span->waste, /* height */
bmp);
cogl_texture_set_region_from_bitmap (slice_tex,
x_span->start, /* src x */
y_span->start, /* src y */
0, /* dst x */
0, /* dst y */
x_span->size -
x_span->waste, /* width */
y_span->size -
y_span->waste, /* height */
bmp);
/* Set up a fake iterator that covers the whole slice */
x_iter.intersect_start = x_span->start;
@ -559,14 +559,14 @@ _cogl_texture_2d_sliced_upload_subregion_to_gl (CoglTexture2DSliced *tex_2ds,
slice_tex = g_array_index (tex_2ds->slice_textures,
CoglHandle, slice_num);
_cogl_texture_set_region_from_bitmap (slice_tex,
source_x,
source_y,
local_x, /* dst x */
local_y, /* dst y */
inter_w, /* width */
inter_h, /* height */
source_bmp);
cogl_texture_set_region_from_bitmap (slice_tex,
source_x,
source_y,
local_x, /* dst x */
local_y, /* dst y */
inter_w, /* width */
inter_h, /* height */
source_bmp);
_cogl_texture_2d_sliced_set_waste (tex_2ds,
source_bmp,

View File

@ -280,16 +280,6 @@ _cogl_texture_draw_and_read (CoglHandle handle,
gboolean
_cogl_texture_is_foreign (CoglHandle handle);
gboolean
_cogl_texture_set_region_from_bitmap (CoglHandle handle,
int src_x,
int src_y,
int dst_x,
int dst_y,
unsigned int dst_width,
unsigned int dst_height,
CoglBitmap *bmp);
void
_cogl_texture_associate_framebuffer (CoglHandle handle,
CoglFramebuffer *framebuffer);

View File

@ -627,11 +627,11 @@ cogl_texture_new_from_buffer_EXP (CoglHandle buffer,
}
/* Wrap the buffer into a bitmap */
bmp = _cogl_bitmap_new_from_buffer (cogl_buffer,
format,
width, height,
rowstride,
offset);
bmp = cogl_bitmap_new_from_buffer (cogl_buffer,
format,
width, height,
rowstride,
offset);
texture = cogl_texture_new_from_bitmap (bmp, flags, internal_format);
@ -852,14 +852,14 @@ _cogl_texture_ensure_non_quad_rendering (CoglHandle handle)
}
gboolean
_cogl_texture_set_region_from_bitmap (CoglHandle handle,
int src_x,
int src_y,
int dst_x,
int dst_y,
unsigned int dst_width,
unsigned int dst_height,
CoglBitmap *bmp)
cogl_texture_set_region_from_bitmap (CoglHandle handle,
int src_x,
int src_y,
int dst_x,
int dst_y,
unsigned int dst_width,
unsigned int dst_height,
CoglBitmap *bmp)
{
CoglTexture *tex = COGL_TEXTURE (handle);
GLenum closest_gl_format;
@ -924,11 +924,11 @@ cogl_texture_set_region (CoglHandle handle,
NULL, /* destroy_fn */
NULL); /* destroy_fn_data */
ret = _cogl_texture_set_region_from_bitmap (handle,
src_x, src_y,
dst_x, dst_y,
dst_width, dst_height,
source_bmp);
ret = cogl_texture_set_region_from_bitmap (handle,
src_x, src_y,
dst_x, dst_y,
dst_width, dst_height,
source_bmp);
cogl_object_unref (source_bmp);

View File

@ -367,6 +367,41 @@ cogl_texture_set_region (CoglHandle handle,
unsigned int rowstride,
const guint8 *data);
#if defined (COGL_ENABLE_EXPERIMENTAL_API)
#define cogl_texture_set_region_from_bitmap \
cogl_texture_set_region_from_bitmap_EXP
/**
* cogl_texture_set_region_from_bitmap:
* @handle: a #CoglHandle for a texture
* @src_x: upper left coordinate to use from the source bitmap.
* @src_y: upper left coordinate to use from the source bitmap
* @dst_x: upper left destination horizontal coordinate.
* @dst_y: upper left destination vertical coordinate.
* @dst_width: width of destination region to write.
* @dst_height: height of destination region to write.
* @bitmap: The source bitmap to read from
*
* Copies a specified source region from @bitmap to the position
* (@src_x, @src_y) of the given destination texture @handle.
*
* Return value: %TRUE if the subregion upload was successful, and
* %FALSE otherwise
*
* Since: 1.8
* Stability: unstable
*/
gboolean
cogl_texture_set_region_from_bitmap (CoglHandle handle,
int src_x,
int src_y,
int dst_x,
int dst_y,
unsigned int dst_width,
unsigned int dst_height,
CoglBitmap *bitmap);
#endif
/**
* cogl_texture_new_from_sub_texture:
* @full_texture: a #CoglHandle to an existing texture