summaryrefslogtreecommitdiffstats
path: root/src/mesa/main/dlist.c
diff options
context:
space:
mode:
authorYuanhan Liu <[email protected]>2011-10-14 14:28:22 +0800
committerYuanhan Liu <[email protected]>2011-10-17 09:41:58 +0800
commite9edcf8b1d6f319af6db8dd25aa267f662456139 (patch)
tree50fd6f2fb2a3a5c18adb6e44cbc3b5f3dcd4183b /src/mesa/main/dlist.c
parent1448bdf1c0995e3ac2e0f97c51e5e2d73eded8e0 (diff)
mesa: add a function to do the image data copy stuff for save_CompressedTex(Sub)Image
Introuduce a simple function called copy_data to do the image data copy stuff for all the save_CompressedTex*Image function. The function check the NULL data case to avoid some potential segfault. This also would make the code a bit simpler and less redundance. Signed-off-by: Yuanhan Liu <[email protected]> Reviewed-by: Brian Paul <[email protected]>
Diffstat (limited to 'src/mesa/main/dlist.c')
-rw-r--r--src/mesa/main/dlist.c102
1 files changed, 27 insertions, 75 deletions
diff --git a/src/mesa/main/dlist.c b/src/mesa/main/dlist.c
index 343feec6f57..567629df35c 100644
--- a/src/mesa/main/dlist.c
+++ b/src/mesa/main/dlist.c
@@ -4509,6 +4509,24 @@ save_MultTransposeMatrixfARB(const GLfloat m[16])
save_MultMatrixf(tm);
}
+static GLvoid *copy_data(const GLvoid *data, GLsizei size, const char *func)
+{
+ GET_CURRENT_CONTEXT(ctx);
+ GLvoid *image;
+
+ if (!data)
+ return NULL;
+
+ image = malloc(size);
+ if (!image) {
+ _mesa_error(ctx, GL_OUT_OF_MEMORY, func);
+ return NULL;
+ }
+ memcpy(image, data, size);
+
+ return image;
+}
+
/* GL_ARB_texture_compression */
static void GLAPIENTRY
@@ -4526,15 +4544,8 @@ save_CompressedTexImage1DARB(GLenum target, GLint level,
}
else {
Node *n;
- GLvoid *image;
ASSERT_OUTSIDE_SAVE_BEGIN_END_AND_FLUSH(ctx);
- /* make copy of image */
- image = malloc(imageSize);
- if (!image) {
- _mesa_error(ctx, GL_OUT_OF_MEMORY, "glCompressedTexImage1DARB");
- return;
- }
- memcpy(image, data, imageSize);
+
n = alloc_instruction(ctx, OPCODE_COMPRESSED_TEX_IMAGE_1D, 7);
if (n) {
n[1].e = target;
@@ -4543,10 +4554,7 @@ save_CompressedTexImage1DARB(GLenum target, GLint level,
n[4].i = (GLint) width;
n[5].i = border;
n[6].i = imageSize;
- n[7].data = image;
- }
- else if (image) {
- free(image);
+ n[7].data = copy_data(data, imageSize, "glCompressedTexImage1DARB");
}
if (ctx->ExecuteFlag) {
CALL_CompressedTexImage1DARB(ctx->Exec,
@@ -4572,15 +4580,8 @@ save_CompressedTexImage2DARB(GLenum target, GLint level,
}
else {
Node *n;
- GLvoid *image;
ASSERT_OUTSIDE_SAVE_BEGIN_END_AND_FLUSH(ctx);
- /* make copy of image */
- image = malloc(imageSize);
- if (!image) {
- _mesa_error(ctx, GL_OUT_OF_MEMORY, "glCompressedTexImage2DARB");
- return;
- }
- memcpy(image, data, imageSize);
+
n = alloc_instruction(ctx, OPCODE_COMPRESSED_TEX_IMAGE_2D, 8);
if (n) {
n[1].e = target;
@@ -4590,10 +4591,7 @@ save_CompressedTexImage2DARB(GLenum target, GLint level,
n[5].i = (GLint) height;
n[6].i = border;
n[7].i = imageSize;
- n[8].data = image;
- }
- else if (image) {
- free(image);
+ n[8].data = copy_data(data, imageSize, "glCompressedTexImage2DARB");
}
if (ctx->ExecuteFlag) {
CALL_CompressedTexImage2DARB(ctx->Exec,
@@ -4619,15 +4617,8 @@ save_CompressedTexImage3DARB(GLenum target, GLint level,
}
else {
Node *n;
- GLvoid *image;
ASSERT_OUTSIDE_SAVE_BEGIN_END_AND_FLUSH(ctx);
- /* make copy of image */
- image = malloc(imageSize);
- if (!image) {
- _mesa_error(ctx, GL_OUT_OF_MEMORY, "glCompressedTexImage3DARB");
- return;
- }
- memcpy(image, data, imageSize);
+
n = alloc_instruction(ctx, OPCODE_COMPRESSED_TEX_IMAGE_3D, 9);
if (n) {
n[1].e = target;
@@ -4638,10 +4629,7 @@ save_CompressedTexImage3DARB(GLenum target, GLint level,
n[6].i = (GLint) depth;
n[7].i = border;
n[8].i = imageSize;
- n[9].data = image;
- }
- else if (image) {
- free(image);
+ n[9].data = copy_data(data, imageSize, "glCompressedTexImage3DARB");
}
if (ctx->ExecuteFlag) {
CALL_CompressedTexImage3DARB(ctx->Exec,
@@ -4659,18 +4647,9 @@ save_CompressedTexSubImage1DARB(GLenum target, GLint level, GLint xoffset,
GLsizei imageSize, const GLvoid * data)
{
Node *n;
- GLvoid *image;
-
GET_CURRENT_CONTEXT(ctx);
ASSERT_OUTSIDE_SAVE_BEGIN_END_AND_FLUSH(ctx);
- /* make copy of image */
- image = malloc(imageSize);
- if (!image) {
- _mesa_error(ctx, GL_OUT_OF_MEMORY, "glCompressedTexSubImage1DARB");
- return;
- }
- memcpy(image, data, imageSize);
n = alloc_instruction(ctx, OPCODE_COMPRESSED_TEX_SUB_IMAGE_1D, 7);
if (n) {
n[1].e = target;
@@ -4679,10 +4658,7 @@ save_CompressedTexSubImage1DARB(GLenum target, GLint level, GLint xoffset,
n[4].i = (GLint) width;
n[5].e = format;
n[6].i = imageSize;
- n[7].data = image;
- }
- else if (image) {
- free(image);
+ n[7].data = copy_data(data, imageSize, "glCompressedTexSubImage1DARB");
}
if (ctx->ExecuteFlag) {
CALL_CompressedTexSubImage1DARB(ctx->Exec, (target, level, xoffset,
@@ -4699,18 +4675,9 @@ save_CompressedTexSubImage2DARB(GLenum target, GLint level, GLint xoffset,
const GLvoid * data)
{
Node *n;
- GLvoid *image;
-
GET_CURRENT_CONTEXT(ctx);
ASSERT_OUTSIDE_SAVE_BEGIN_END_AND_FLUSH(ctx);
- /* make copy of image */
- image = malloc(imageSize);
- if (!image) {
- _mesa_error(ctx, GL_OUT_OF_MEMORY, "glCompressedTexSubImage2DARB");
- return;
- }
- memcpy(image, data, imageSize);
n = alloc_instruction(ctx, OPCODE_COMPRESSED_TEX_SUB_IMAGE_2D, 9);
if (n) {
n[1].e = target;
@@ -4721,10 +4688,7 @@ save_CompressedTexSubImage2DARB(GLenum target, GLint level, GLint xoffset,
n[6].i = (GLint) height;
n[7].e = format;
n[8].i = imageSize;
- n[9].data = image;
- }
- else if (image) {
- free(image);
+ n[9].data = copy_data(data, imageSize, "glCompressedTexSubImage2DARB");
}
if (ctx->ExecuteFlag) {
CALL_CompressedTexSubImage2DARB(ctx->Exec,
@@ -4741,18 +4705,9 @@ save_CompressedTexSubImage3DARB(GLenum target, GLint level, GLint xoffset,
GLsizei imageSize, const GLvoid * data)
{
Node *n;
- GLvoid *image;
-
GET_CURRENT_CONTEXT(ctx);
ASSERT_OUTSIDE_SAVE_BEGIN_END_AND_FLUSH(ctx);
- /* make copy of image */
- image = malloc(imageSize);
- if (!image) {
- _mesa_error(ctx, GL_OUT_OF_MEMORY, "glCompressedTexSubImage3DARB");
- return;
- }
- memcpy(image, data, imageSize);
n = alloc_instruction(ctx, OPCODE_COMPRESSED_TEX_SUB_IMAGE_3D, 11);
if (n) {
n[1].e = target;
@@ -4765,10 +4720,7 @@ save_CompressedTexSubImage3DARB(GLenum target, GLint level, GLint xoffset,
n[8].i = (GLint) depth;
n[9].e = format;
n[10].i = imageSize;
- n[11].data = image;
- }
- else if (image) {
- free(image);
+ n[11].data = copy_data(data, imageSize, "glCompressedTexSubImage3DARB");
}
if (ctx->ExecuteFlag) {
CALL_CompressedTexSubImage3DARB(ctx->Exec,