mirror of
https://github.com/brl/mutter.git
synced 2024-11-10 07:56:14 -05:00
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:
parent
7860df92d1
commit
a9184d5cb7
@ -437,52 +437,52 @@ _cogl_atlas_texture_set_region_with_border (CoglAtlasTexture *atlas_tex,
|
|||||||
CoglAtlas *atlas = atlas_tex->atlas;
|
CoglAtlas *atlas = atlas_tex->atlas;
|
||||||
|
|
||||||
/* Copy the central data */
|
/* Copy the central data */
|
||||||
if (!_cogl_texture_set_region_from_bitmap (atlas->texture,
|
if (!cogl_texture_set_region_from_bitmap (atlas->texture,
|
||||||
src_x, src_y,
|
src_x, src_y,
|
||||||
dst_x + atlas_tex->rectangle.x + 1,
|
dst_x + atlas_tex->rectangle.x + 1,
|
||||||
dst_y + atlas_tex->rectangle.y + 1,
|
dst_y + atlas_tex->rectangle.y + 1,
|
||||||
dst_width,
|
dst_width,
|
||||||
dst_height,
|
dst_height,
|
||||||
bmp))
|
bmp))
|
||||||
return FALSE;
|
return FALSE;
|
||||||
|
|
||||||
/* Update the left edge pixels */
|
/* Update the left edge pixels */
|
||||||
if (dst_x == 0 &&
|
if (dst_x == 0 &&
|
||||||
!_cogl_texture_set_region_from_bitmap (atlas->texture,
|
!cogl_texture_set_region_from_bitmap (atlas->texture,
|
||||||
src_x, src_y,
|
src_x, src_y,
|
||||||
atlas_tex->rectangle.x,
|
atlas_tex->rectangle.x,
|
||||||
dst_y + atlas_tex->rectangle.y + 1,
|
dst_y + atlas_tex->rectangle.y + 1,
|
||||||
1, dst_height,
|
1, dst_height,
|
||||||
bmp))
|
bmp))
|
||||||
return FALSE;
|
return FALSE;
|
||||||
/* Update the right edge pixels */
|
/* Update the right edge pixels */
|
||||||
if (dst_x + dst_width == atlas_tex->rectangle.width - 2 &&
|
if (dst_x + dst_width == atlas_tex->rectangle.width - 2 &&
|
||||||
!_cogl_texture_set_region_from_bitmap (atlas->texture,
|
!cogl_texture_set_region_from_bitmap (atlas->texture,
|
||||||
src_x + dst_width - 1, src_y,
|
src_x + dst_width - 1, src_y,
|
||||||
atlas_tex->rectangle.x +
|
atlas_tex->rectangle.x +
|
||||||
atlas_tex->rectangle.width - 1,
|
atlas_tex->rectangle.width - 1,
|
||||||
dst_y + atlas_tex->rectangle.y + 1,
|
dst_y + atlas_tex->rectangle.y + 1,
|
||||||
1, dst_height,
|
1, dst_height,
|
||||||
bmp))
|
bmp))
|
||||||
return FALSE;
|
return FALSE;
|
||||||
/* Update the top edge pixels */
|
/* Update the top edge pixels */
|
||||||
if (dst_y == 0 &&
|
if (dst_y == 0 &&
|
||||||
!_cogl_texture_set_region_from_bitmap (atlas->texture,
|
!cogl_texture_set_region_from_bitmap (atlas->texture,
|
||||||
src_x, src_y,
|
src_x, src_y,
|
||||||
dst_x + atlas_tex->rectangle.x + 1,
|
dst_x + atlas_tex->rectangle.x + 1,
|
||||||
atlas_tex->rectangle.y,
|
atlas_tex->rectangle.y,
|
||||||
dst_width, 1,
|
dst_width, 1,
|
||||||
bmp))
|
bmp))
|
||||||
return FALSE;
|
return FALSE;
|
||||||
/* Update the bottom edge pixels */
|
/* Update the bottom edge pixels */
|
||||||
if (dst_y + dst_height == atlas_tex->rectangle.height - 2 &&
|
if (dst_y + dst_height == atlas_tex->rectangle.height - 2 &&
|
||||||
!_cogl_texture_set_region_from_bitmap (atlas->texture,
|
!cogl_texture_set_region_from_bitmap (atlas->texture,
|
||||||
src_x, src_y + dst_height - 1,
|
src_x, src_y + dst_height - 1,
|
||||||
dst_x + atlas_tex->rectangle.x + 1,
|
dst_x + atlas_tex->rectangle.x + 1,
|
||||||
atlas_tex->rectangle.y +
|
atlas_tex->rectangle.y +
|
||||||
atlas_tex->rectangle.height - 1,
|
atlas_tex->rectangle.height - 1,
|
||||||
dst_width, 1,
|
dst_width, 1,
|
||||||
bmp))
|
bmp))
|
||||||
return FALSE;
|
return FALSE;
|
||||||
|
|
||||||
return TRUE;
|
return TRUE;
|
||||||
@ -526,11 +526,11 @@ _cogl_atlas_texture_set_region (CoglTexture *tex,
|
|||||||
}
|
}
|
||||||
else
|
else
|
||||||
/* Otherwise we can just forward on to the sub texture */
|
/* Otherwise we can just forward on to the sub texture */
|
||||||
return _cogl_texture_set_region_from_bitmap (atlas_tex->sub_texture,
|
return cogl_texture_set_region_from_bitmap (atlas_tex->sub_texture,
|
||||||
src_x, src_y,
|
src_x, src_y,
|
||||||
dst_x, dst_y,
|
dst_x, dst_y,
|
||||||
dst_width, dst_height,
|
dst_width, dst_height,
|
||||||
bmp);
|
bmp);
|
||||||
}
|
}
|
||||||
|
|
||||||
static CoglPixelFormat
|
static CoglPixelFormat
|
||||||
|
@ -83,17 +83,6 @@ _cogl_bitmap_new_shared (CoglBitmap *shared_bmp,
|
|||||||
int height,
|
int height,
|
||||||
int rowstride);
|
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
|
gboolean
|
||||||
_cogl_bitmap_can_convert (CoglPixelFormat src, CoglPixelFormat dst);
|
_cogl_bitmap_can_convert (CoglPixelFormat src, CoglPixelFormat dst);
|
||||||
|
|
||||||
|
@ -327,12 +327,12 @@ cogl_bitmap_new_from_file (const char *filename,
|
|||||||
}
|
}
|
||||||
|
|
||||||
CoglBitmap *
|
CoglBitmap *
|
||||||
_cogl_bitmap_new_from_buffer (CoglBuffer *buffer,
|
cogl_bitmap_new_from_buffer (CoglBuffer *buffer,
|
||||||
CoglPixelFormat format,
|
CoglPixelFormat format,
|
||||||
int width,
|
int width,
|
||||||
int height,
|
int height,
|
||||||
int rowstride,
|
int rowstride,
|
||||||
int offset)
|
int offset)
|
||||||
{
|
{
|
||||||
CoglBitmap *bmp;
|
CoglBitmap *bmp;
|
||||||
|
|
||||||
|
@ -29,6 +29,7 @@
|
|||||||
#define __COGL_BITMAP_H__
|
#define __COGL_BITMAP_H__
|
||||||
|
|
||||||
#include <cogl/cogl-types.h>
|
#include <cogl/cogl-types.h>
|
||||||
|
#include <cogl/cogl-buffer.h>
|
||||||
|
|
||||||
G_BEGIN_DECLS
|
G_BEGIN_DECLS
|
||||||
|
|
||||||
@ -62,6 +63,37 @@ CoglBitmap *
|
|||||||
cogl_bitmap_new_from_file (const char *filename,
|
cogl_bitmap_new_from_file (const char *filename,
|
||||||
GError **error);
|
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:
|
* cogl_bitmap_get_size_from_file:
|
||||||
* @filename: the file to check
|
* @filename: the file to check
|
||||||
|
@ -409,12 +409,12 @@ _cogl_sub_texture_set_region (CoglTexture *tex,
|
|||||||
{
|
{
|
||||||
CoglSubTexture *sub_tex = COGL_SUB_TEXTURE (tex);
|
CoglSubTexture *sub_tex = COGL_SUB_TEXTURE (tex);
|
||||||
|
|
||||||
return _cogl_texture_set_region_from_bitmap (sub_tex->full_texture,
|
return cogl_texture_set_region_from_bitmap (sub_tex->full_texture,
|
||||||
src_x, src_y,
|
src_x, src_y,
|
||||||
dst_x + sub_tex->sub_x,
|
dst_x + sub_tex->sub_x,
|
||||||
dst_y + sub_tex->sub_y,
|
dst_y + sub_tex->sub_y,
|
||||||
dst_width, dst_height,
|
dst_width, dst_height,
|
||||||
bmp);
|
bmp);
|
||||||
}
|
}
|
||||||
|
|
||||||
static CoglPixelFormat
|
static CoglPixelFormat
|
||||||
|
@ -318,18 +318,18 @@ _cogl_texture_2d_sliced_set_waste (CoglTexture2DSliced *tex_2ds,
|
|||||||
NULL,
|
NULL,
|
||||||
NULL);
|
NULL);
|
||||||
|
|
||||||
_cogl_texture_set_region_from_bitmap (slice_tex,
|
cogl_texture_set_region_from_bitmap (slice_tex,
|
||||||
0, /* src_x */
|
0, /* src_x */
|
||||||
0, /* src_y */
|
0, /* src_y */
|
||||||
/* dst_x */
|
/* dst_x */
|
||||||
x_span->size - x_span->waste,
|
x_span->size - x_span->waste,
|
||||||
y_iter->intersect_start -
|
y_iter->intersect_start -
|
||||||
y_span->start, /* dst_y */
|
y_span->start, /* dst_y */
|
||||||
x_span->waste, /* dst_width */
|
x_span->waste, /* dst_width */
|
||||||
/* dst_height */
|
/* dst_height */
|
||||||
y_iter->intersect_end -
|
y_iter->intersect_end -
|
||||||
y_iter->intersect_start,
|
y_iter->intersect_start,
|
||||||
waste_bmp);
|
waste_bmp);
|
||||||
|
|
||||||
cogl_object_unref (waste_bmp);
|
cogl_object_unref (waste_bmp);
|
||||||
}
|
}
|
||||||
@ -374,17 +374,17 @@ _cogl_texture_2d_sliced_set_waste (CoglTexture2DSliced *tex_2ds,
|
|||||||
NULL,
|
NULL,
|
||||||
NULL);
|
NULL);
|
||||||
|
|
||||||
_cogl_texture_set_region_from_bitmap (slice_tex,
|
cogl_texture_set_region_from_bitmap (slice_tex,
|
||||||
0, /* src_x */
|
0, /* src_x */
|
||||||
0, /* src_y */
|
0, /* src_y */
|
||||||
/* dst_x */
|
/* dst_x */
|
||||||
x_iter->intersect_start -
|
x_iter->intersect_start -
|
||||||
x_iter->pos,
|
x_iter->pos,
|
||||||
/* dst_y */
|
/* dst_y */
|
||||||
y_span->size - y_span->waste,
|
y_span->size - y_span->waste,
|
||||||
copy_width, /* dst_width */
|
copy_width, /* dst_width */
|
||||||
y_span->waste, /* dst_height */
|
y_span->waste, /* dst_height */
|
||||||
waste_bmp);
|
waste_bmp);
|
||||||
|
|
||||||
cogl_object_unref (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,
|
slice_tex = g_array_index (tex_2ds->slice_textures,
|
||||||
CoglHandle, slice_num);
|
CoglHandle, slice_num);
|
||||||
|
|
||||||
_cogl_texture_set_region_from_bitmap (slice_tex,
|
cogl_texture_set_region_from_bitmap (slice_tex,
|
||||||
x_span->start, /* src x */
|
x_span->start, /* src x */
|
||||||
y_span->start, /* src y */
|
y_span->start, /* src y */
|
||||||
0, /* dst x */
|
0, /* dst x */
|
||||||
0, /* dst y */
|
0, /* dst y */
|
||||||
x_span->size -
|
x_span->size -
|
||||||
x_span->waste, /* width */
|
x_span->waste, /* width */
|
||||||
y_span->size -
|
y_span->size -
|
||||||
y_span->waste, /* height */
|
y_span->waste, /* height */
|
||||||
bmp);
|
bmp);
|
||||||
|
|
||||||
/* Set up a fake iterator that covers the whole slice */
|
/* Set up a fake iterator that covers the whole slice */
|
||||||
x_iter.intersect_start = x_span->start;
|
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,
|
slice_tex = g_array_index (tex_2ds->slice_textures,
|
||||||
CoglHandle, slice_num);
|
CoglHandle, slice_num);
|
||||||
|
|
||||||
_cogl_texture_set_region_from_bitmap (slice_tex,
|
cogl_texture_set_region_from_bitmap (slice_tex,
|
||||||
source_x,
|
source_x,
|
||||||
source_y,
|
source_y,
|
||||||
local_x, /* dst x */
|
local_x, /* dst x */
|
||||||
local_y, /* dst y */
|
local_y, /* dst y */
|
||||||
inter_w, /* width */
|
inter_w, /* width */
|
||||||
inter_h, /* height */
|
inter_h, /* height */
|
||||||
source_bmp);
|
source_bmp);
|
||||||
|
|
||||||
_cogl_texture_2d_sliced_set_waste (tex_2ds,
|
_cogl_texture_2d_sliced_set_waste (tex_2ds,
|
||||||
source_bmp,
|
source_bmp,
|
||||||
|
@ -280,16 +280,6 @@ _cogl_texture_draw_and_read (CoglHandle handle,
|
|||||||
gboolean
|
gboolean
|
||||||
_cogl_texture_is_foreign (CoglHandle handle);
|
_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
|
void
|
||||||
_cogl_texture_associate_framebuffer (CoglHandle handle,
|
_cogl_texture_associate_framebuffer (CoglHandle handle,
|
||||||
CoglFramebuffer *framebuffer);
|
CoglFramebuffer *framebuffer);
|
||||||
|
@ -627,11 +627,11 @@ cogl_texture_new_from_buffer_EXP (CoglHandle buffer,
|
|||||||
}
|
}
|
||||||
|
|
||||||
/* Wrap the buffer into a bitmap */
|
/* Wrap the buffer into a bitmap */
|
||||||
bmp = _cogl_bitmap_new_from_buffer (cogl_buffer,
|
bmp = cogl_bitmap_new_from_buffer (cogl_buffer,
|
||||||
format,
|
format,
|
||||||
width, height,
|
width, height,
|
||||||
rowstride,
|
rowstride,
|
||||||
offset);
|
offset);
|
||||||
|
|
||||||
texture = cogl_texture_new_from_bitmap (bmp, flags, internal_format);
|
texture = cogl_texture_new_from_bitmap (bmp, flags, internal_format);
|
||||||
|
|
||||||
@ -852,14 +852,14 @@ _cogl_texture_ensure_non_quad_rendering (CoglHandle handle)
|
|||||||
}
|
}
|
||||||
|
|
||||||
gboolean
|
gboolean
|
||||||
_cogl_texture_set_region_from_bitmap (CoglHandle handle,
|
cogl_texture_set_region_from_bitmap (CoglHandle handle,
|
||||||
int src_x,
|
int src_x,
|
||||||
int src_y,
|
int src_y,
|
||||||
int dst_x,
|
int dst_x,
|
||||||
int dst_y,
|
int dst_y,
|
||||||
unsigned int dst_width,
|
unsigned int dst_width,
|
||||||
unsigned int dst_height,
|
unsigned int dst_height,
|
||||||
CoglBitmap *bmp)
|
CoglBitmap *bmp)
|
||||||
{
|
{
|
||||||
CoglTexture *tex = COGL_TEXTURE (handle);
|
CoglTexture *tex = COGL_TEXTURE (handle);
|
||||||
GLenum closest_gl_format;
|
GLenum closest_gl_format;
|
||||||
@ -924,11 +924,11 @@ cogl_texture_set_region (CoglHandle handle,
|
|||||||
NULL, /* destroy_fn */
|
NULL, /* destroy_fn */
|
||||||
NULL); /* destroy_fn_data */
|
NULL); /* destroy_fn_data */
|
||||||
|
|
||||||
ret = _cogl_texture_set_region_from_bitmap (handle,
|
ret = cogl_texture_set_region_from_bitmap (handle,
|
||||||
src_x, src_y,
|
src_x, src_y,
|
||||||
dst_x, dst_y,
|
dst_x, dst_y,
|
||||||
dst_width, dst_height,
|
dst_width, dst_height,
|
||||||
source_bmp);
|
source_bmp);
|
||||||
|
|
||||||
cogl_object_unref (source_bmp);
|
cogl_object_unref (source_bmp);
|
||||||
|
|
||||||
|
@ -367,6 +367,41 @@ cogl_texture_set_region (CoglHandle handle,
|
|||||||
unsigned int rowstride,
|
unsigned int rowstride,
|
||||||
const guint8 *data);
|
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:
|
* cogl_texture_new_from_sub_texture:
|
||||||
* @full_texture: a #CoglHandle to an existing texture
|
* @full_texture: a #CoglHandle to an existing texture
|
||||||
|
Loading…
Reference in New Issue
Block a user