cogl: Move _cogl_bitmap_gl_{,un}bind into the GL driver

These are the only pieces of the cogl bitmap support that need GL driver
knowledge, so move them there like the TODO suggests.

https://gitlab.gnome.org/GNOME/mutter/merge_requests/874
This commit is contained in:
Adam Jackson 2019-10-18 16:19:32 -04:00
parent f297a5faa5
commit 049e7882b7
8 changed files with 179 additions and 99 deletions

View File

@ -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);

View File

@ -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 <string.h>
@ -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)
{

View File

@ -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 */

View File

@ -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);
}

View File

@ -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"

View File

@ -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 <string.h>
#include <stdlib.h>

View File

@ -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 <string.h>
#include <stdlib.h>

View File

@ -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',