diff --git a/cogl/cogl/cogl-bitmap-private.h b/cogl/cogl/cogl-bitmap-private.h index e3877440a..a92d6af48 100644 --- a/cogl/cogl/cogl-bitmap-private.h +++ b/cogl/cogl/cogl-bitmap-private.h @@ -177,24 +177,6 @@ _cogl_bitmap_map (CoglBitmap *bitmap, void _cogl_bitmap_unmap (CoglBitmap *bitmap); -/* These two are replacements for map and unmap that should used when - * the pointer is going to be passed to GL for pixel packing or - * unpacking. The address might not be valid for reading if the bitmap - * was created with new_from_buffer but it will however be good to - * pass to glTexImage2D for example. The access should be READ for - * unpacking and WRITE for packing. It can not be both - * - * TODO: split this bind/unbind functions out into a GL specific file - */ -uint8_t * -_cogl_bitmap_gl_bind (CoglBitmap *bitmap, - CoglBufferAccess access, - CoglBufferMapHint hints, - GError **error); - -void -_cogl_bitmap_gl_unbind (CoglBitmap *bitmap); - CoglContext * _cogl_bitmap_get_context (CoglBitmap *bitmap); diff --git a/cogl/cogl/cogl-bitmap.c b/cogl/cogl/cogl-bitmap.c index 40eaabe8d..f5577e342 100644 --- a/cogl/cogl/cogl-bitmap.c +++ b/cogl/cogl/cogl-bitmap.c @@ -38,7 +38,6 @@ #include "cogl-pixel-buffer.h" #include "cogl-context-private.h" #include "cogl-gtype-private.h" -#include "driver/gl/cogl-buffer-gl-private.h" #include @@ -443,86 +442,6 @@ _cogl_bitmap_unmap (CoglBitmap *bitmap) cogl_buffer_unmap (bitmap->buffer); } -uint8_t * -_cogl_bitmap_gl_bind (CoglBitmap *bitmap, - CoglBufferAccess access, - CoglBufferMapHint hints, - GError **error) -{ - uint8_t *ptr; - GError *internal_error = NULL; - - g_return_val_if_fail (access & (COGL_BUFFER_ACCESS_READ | - COGL_BUFFER_ACCESS_WRITE), - NULL); - - /* Divert to another bitmap if this data is shared */ - if (bitmap->shared_bmp) - return _cogl_bitmap_gl_bind (bitmap->shared_bmp, access, hints, error); - - g_return_val_if_fail (!bitmap->bound, NULL); - - /* If the bitmap wasn't created from a buffer then the - implementation of bind is the same as map */ - if (bitmap->buffer == NULL) - { - uint8_t *data = _cogl_bitmap_map (bitmap, access, hints, error); - if (data) - bitmap->bound = TRUE; - return data; - } - - if (access == COGL_BUFFER_ACCESS_READ) - ptr = _cogl_buffer_gl_bind (bitmap->buffer, - COGL_BUFFER_BIND_TARGET_PIXEL_UNPACK, - &internal_error); - else if (access == COGL_BUFFER_ACCESS_WRITE) - ptr = _cogl_buffer_gl_bind (bitmap->buffer, - COGL_BUFFER_BIND_TARGET_PIXEL_PACK, - &internal_error); - else - { - ptr = NULL; - g_assert_not_reached (); - return NULL; - } - - /* NB: _cogl_buffer_gl_bind() may return NULL in non-error - * conditions so we have to explicitly check internal_error to see - * if an exception was thrown */ - if (internal_error) - { - g_propagate_error (error, internal_error); - return NULL; - } - - bitmap->bound = TRUE; - - /* The data pointer actually stores the offset */ - return ptr + GPOINTER_TO_INT (bitmap->data); -} - -void -_cogl_bitmap_gl_unbind (CoglBitmap *bitmap) -{ - /* Divert to another bitmap if this data is shared */ - if (bitmap->shared_bmp) - { - _cogl_bitmap_gl_unbind (bitmap->shared_bmp); - return; - } - - g_assert (bitmap->bound); - bitmap->bound = FALSE; - - /* If the bitmap wasn't created from a pixel array then the - implementation of unbind is the same as unmap */ - if (bitmap->buffer) - _cogl_buffer_gl_unbind (bitmap->buffer); - else - _cogl_bitmap_unmap (bitmap); -} - CoglContext * _cogl_bitmap_get_context (CoglBitmap *bitmap) { diff --git a/cogl/cogl/driver/gl/cogl-bitmap-gl-private.h b/cogl/cogl/driver/gl/cogl-bitmap-gl-private.h new file mode 100644 index 000000000..b2726c421 --- /dev/null +++ b/cogl/cogl/driver/gl/cogl-bitmap-gl-private.h @@ -0,0 +1,52 @@ +/* + * Cogl + * + * A Low Level GPU Graphics and Utilities API + * + * Copyright (C) 2007 OpenedHand + * + * Permission is hereby granted, free of charge, to any person + * obtaining a copy of this software and associated documentation + * files (the "Software"), to deal in the Software without + * restriction, including without limitation the rights to use, copy, + * modify, merge, publish, distribute, sublicense, and/or sell copies + * of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be + * included in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND + * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS + * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN + * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN + * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + * + * + */ + +#ifndef __COGL_BITMAP_GL_PRIVATE_H +#define __COGL_BITMAP_GL_PRIVATE_H + +#include "cogl-bitmap-private.h" + +/* These two are replacements for map and unmap that should used when + * the pointer is going to be passed to GL for pixel packing or + * unpacking. The address might not be valid for reading if the bitmap + * was created with new_from_buffer but it will however be good to + * pass to glTexImage2D for example. The access should be READ for + * unpacking and WRITE for packing. It can not be both + */ +uint8_t * +_cogl_bitmap_gl_bind (CoglBitmap *bitmap, + CoglBufferAccess access, + CoglBufferMapHint hints, + GError **error); + +void +_cogl_bitmap_gl_unbind (CoglBitmap *bitmap); + +#endif /* __COGL_BITMAP_GL_PRIVATE_H */ diff --git a/cogl/cogl/driver/gl/cogl-bitmap-gl.c b/cogl/cogl/driver/gl/cogl-bitmap-gl.c new file mode 100644 index 000000000..8011d7fc8 --- /dev/null +++ b/cogl/cogl/driver/gl/cogl-bitmap-gl.c @@ -0,0 +1,122 @@ +/* + * Cogl + * + * A Low Level GPU Graphics and Utilities API + * + * Copyright (C) 2007,2008,2009 Intel Corporation. + * + * Permission is hereby granted, free of charge, to any person + * obtaining a copy of this software and associated documentation + * files (the "Software"), to deal in the Software without + * restriction, including without limitation the rights to use, copy, + * modify, merge, publish, distribute, sublicense, and/or sell copies + * of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be + * included in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND + * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS + * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN + * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN + * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + * + * + */ + +#include "cogl-config.h" + +#include "cogl-util.h" +#include "cogl-debug.h" +#include "cogl-private.h" +#include "cogl-bitmap-private.h" +#include "cogl-buffer-private.h" +#include "cogl-pixel-buffer.h" +#include "cogl-context-private.h" +#include "cogl-gtype-private.h" +#include "cogl-buffer-gl-private.h" +#include "cogl-bitmap-gl-private.h" + +uint8_t * +_cogl_bitmap_gl_bind (CoglBitmap *bitmap, + CoglBufferAccess access, + CoglBufferMapHint hints, + GError **error) +{ + uint8_t *ptr; + GError *internal_error = NULL; + + g_return_val_if_fail (access & (COGL_BUFFER_ACCESS_READ | + COGL_BUFFER_ACCESS_WRITE), + NULL); + + /* Divert to another bitmap if this data is shared */ + if (bitmap->shared_bmp) + return _cogl_bitmap_gl_bind (bitmap->shared_bmp, access, hints, error); + + g_return_val_if_fail (!bitmap->bound, NULL); + + /* If the bitmap wasn't created from a buffer then the + implementation of bind is the same as map */ + if (bitmap->buffer == NULL) + { + uint8_t *data = _cogl_bitmap_map (bitmap, access, hints, error); + if (data) + bitmap->bound = TRUE; + return data; + } + + if (access == COGL_BUFFER_ACCESS_READ) + ptr = _cogl_buffer_gl_bind (bitmap->buffer, + COGL_BUFFER_BIND_TARGET_PIXEL_UNPACK, + &internal_error); + else if (access == COGL_BUFFER_ACCESS_WRITE) + ptr = _cogl_buffer_gl_bind (bitmap->buffer, + COGL_BUFFER_BIND_TARGET_PIXEL_PACK, + &internal_error); + else + { + ptr = NULL; + g_assert_not_reached (); + return NULL; + } + + /* NB: _cogl_buffer_gl_bind() may return NULL in non-error + * conditions so we have to explicitly check internal_error to see + * if an exception was thrown */ + if (internal_error) + { + g_propagate_error (error, internal_error); + return NULL; + } + + bitmap->bound = TRUE; + + /* The data pointer actually stores the offset */ + return ptr + GPOINTER_TO_INT (bitmap->data); +} + +void +_cogl_bitmap_gl_unbind (CoglBitmap *bitmap) +{ + /* Divert to another bitmap if this data is shared */ + if (bitmap->shared_bmp) + { + _cogl_bitmap_gl_unbind (bitmap->shared_bmp); + return; + } + + g_assert (bitmap->bound); + bitmap->bound = FALSE; + + /* If the bitmap wasn't created from a pixel array then the + implementation of unbind is the same as unmap */ + if (bitmap->buffer) + _cogl_buffer_gl_unbind (bitmap->buffer); + else + _cogl_bitmap_unmap (bitmap); +} diff --git a/cogl/cogl/driver/gl/cogl-framebuffer-gl.c b/cogl/cogl/driver/gl/cogl-framebuffer-gl.c index 94b1decde..c0a15a688 100644 --- a/cogl/cogl/driver/gl/cogl-framebuffer-gl.c +++ b/cogl/cogl/driver/gl/cogl-framebuffer-gl.c @@ -36,6 +36,7 @@ #include "cogl-texture-private.h" #include "driver/gl/cogl-util-gl-private.h" #include "driver/gl/cogl-framebuffer-gl-private.h" +#include "driver/gl/cogl-bitmap-gl-private.h" #include "driver/gl/cogl-buffer-gl-private.h" #include "driver/gl/cogl-texture-gl-private.h" diff --git a/cogl/cogl/driver/gl/gl/cogl-texture-driver-gl.c b/cogl/cogl/driver/gl/gl/cogl-texture-driver-gl.c index 6f138cd8d..7e3a3afce 100644 --- a/cogl/cogl/driver/gl/gl/cogl-texture-driver-gl.c +++ b/cogl/cogl/driver/gl/gl/cogl-texture-driver-gl.c @@ -47,6 +47,7 @@ #include "driver/gl/cogl-pipeline-opengl-private.h" #include "driver/gl/cogl-util-gl-private.h" #include "driver/gl/cogl-texture-gl-private.h" +#include "driver/gl/cogl-bitmap-gl-private.h" #include #include diff --git a/cogl/cogl/driver/gl/gles/cogl-texture-driver-gles.c b/cogl/cogl/driver/gl/gles/cogl-texture-driver-gles.c index dcbe4bf51..0e66169fb 100644 --- a/cogl/cogl/driver/gl/gles/cogl-texture-driver-gles.c +++ b/cogl/cogl/driver/gl/gles/cogl-texture-driver-gles.c @@ -47,6 +47,7 @@ #include "driver/gl/cogl-pipeline-opengl-private.h" #include "driver/gl/cogl-util-gl-private.h" #include "driver/gl/cogl-texture-gl-private.h" +#include "driver/gl/cogl-bitmap-gl-private.h" #include #include diff --git a/cogl/cogl/meson.build b/cogl/cogl/meson.build index b0e66bff3..f6c61f8c8 100644 --- a/cogl/cogl/meson.build +++ b/cogl/cogl/meson.build @@ -168,6 +168,8 @@ cogl_common_driver_sources = [ 'driver/gl/cogl-clip-stack-gl.c', 'driver/gl/cogl-buffer-gl-private.h', 'driver/gl/cogl-buffer-gl.c', + 'driver/gl/cogl-bitmap-gl-private.h', + 'driver/gl/cogl-bitmap-gl.c', 'driver/gl/cogl-pipeline-opengl.c', 'driver/gl/cogl-pipeline-opengl-private.h', 'driver/gl/cogl-pipeline-fragend-glsl.c',