mutter/test-fixtures/test-utils.h

287 lines
10 KiB
C
Raw Normal View History

#ifndef _TEST_UTILS_H_
#define _TEST_UTILS_H_
/* NB: This header is for private and public api testing and so
* we need consider that if we are testing the public api we should
* just include <cogl/cogl.h> but since that will only provide
* opaque typedefs we need to include the specific internal headers
* for testing private apis...
*/
#ifdef COGL_COMPILATION
#include <cogl/cogl-context.h>
#include <cogl/cogl-onscreen.h>
#include <cogl/cogl-offscreen.h>
#include <cogl/cogl-texture-2d.h>
#include <cogl/cogl-primitive-texture.h>
#include <cogl/cogl-texture-2d-sliced.h>
#include <cogl/cogl-meta-texture.h>
#include <cogl/cogl-atlas-texture.h>
#else
#include <cogl/cogl.h>
#endif
#include <glib.h>
Add -Wmissing-declarations to maintainer flags and fix problems This option to GCC makes it give a warning whenever a global function is defined without a declaration. This should catch cases were we've defined a function but forgot to put it in a header. In that case it is either only used within one file so we should make it static or we should declare it in a header. The following changes where made to fix problems: • Some functions were made static • cogl-path.h (the one containing the 1.0 API) was split into two files, one defining the functions and one defining the enums so that cogl-path.c can include the enum and function declarations from the 2.0 API as well as the function declarations from the 1.0 API. • cogl2-clip-state has been removed. This only had one experimental function called cogl_clip_push_from_path but as this is unstable we might as well remove it favour of the equivalent cogl_framebuffer_* API. • The GLX, SDL and WGL winsys's now have a private header to define their get_vtable function instead of directly declaring in the C file where it is called. • All places that were calling COGL_OBJECT_DEFINE need to have the cogl_is_whatever function declared so these have been added either as a public function or in a private header. • Some files that were not including the header containing their function declarations have been fixed to do so. • Any unused error quark functions have been removed. If we later want them we should add them back one by one and add a declaration for them in a header. • _cogl_is_framebuffer has been renamed to cogl_is_framebuffer and made a public function with a declaration in cogl-framebuffer.h • Similarly for CoglOnscreen. • cogl_vdraw_indexed_attributes is called cogl_framebuffer_vdraw_indexed_attributes in the header. The definition has been changed to match the header. • cogl_index_buffer_allocate has been removed. This had no declaration and I'm not sure what it's supposed to do. • CoglJournal has been changed to use the internal CoglObject macro so that it won't define an exported cogl_is_journal symbol. • The _cogl_blah_pointer_from_handle functions have been removed. CoglHandle isn't used much anymore anyway and in the few places where it is used I think it's safe to just use the implicit cast from void* to the right type. • The test-utils.h header for the conformance tests explicitly disables the -Wmissing-declaration option using a pragma because all of the tests declare their main function without a header. Any mistakes relating to missing declarations aren't really important for the tests. • cogl_quaternion_init_from_quaternion and init_from_matrix have been given declarations in cogl-quaternion.h Reviewed-by: Robert Bragg <robert@linux.intel.com>
2012-03-06 13:21:28 -05:00
/* We don't really care about functions that are defined without a
header for the unit tests so we can just disable it here */
#ifdef __GNUC__
#pragma GCC diagnostic ignored "-Wmissing-declarations"
#endif
typedef enum _TestFlags
{
TEST_KNOWN_FAILURE = 1<<0,
TEST_REQUIREMENT_GL = 1<<1,
TEST_REQUIREMENT_NPOT = 1<<2,
TEST_REQUIREMENT_TEXTURE_3D = 1<<3,
TEST_REQUIREMENT_TEXTURE_RECTANGLE = 1<<4,
TEST_REQUIREMENT_POINT_SPRITE = 1<<5,
TEST_REQUIREMENT_GLES2_CONTEXT = 1<<6,
TEST_REQUIREMENT_MAP_WRITE = 1<<7,
TEST_REQUIREMENT_GLSL = 1<<8,
TEST_REQUIREMENT_OFFSCREEN = 1<<9,
Add support for per-vertex point sizes This adds a new function to enable per-vertex point size on a pipeline. This can be set with cogl_pipeline_set_per_vertex_point_size(). Once enabled the point size can be set either by drawing with an attribute named 'cogl_point_size_in' or by writing to the 'cogl_point_size_out' builtin from a snippet. There is a feature flag which must be checked for before using per-vertex point sizes. This will only be set on GL >= 2.0 or on GLES 2.0. GL will only let you set a per-vertex point size from GLSL by writing to gl_PointSize. This is only available in GL2 and not in the older GLSL extensions. The per-vertex point size has its own pipeline state flag so that it can be part of the state that affects vertex shader generation. Having to enable the per vertex point size with a separate function is a bit awkward. Ideally it would work like the color attribute where you can just set it for every vertex in your primitive with cogl_pipeline_set_color or set it per-vertex by just using the attribute. This is harder to get working with the point size because we need to generate a different vertex shader depending on what attributes are bound. I think if we wanted to make this work transparently we would still want to internally have a pipeline property describing whether the shader was generated with per-vertex support so that it would work with the shader cache correctly. Potentially we could make the per-vertex property internal and automatically make a weak pipeline whenever the attribute is bound. However we would then also need to automatically detect when an application is writing to cogl_point_size_out from a snippet. Reviewed-by: Robert Bragg <robert@linux.intel.com> (cherry picked from commit 8495d9c1c15ce389885a9356d965eabd97758115) Conflicts: cogl/cogl-context.c cogl/cogl-pipeline-private.h cogl/cogl-pipeline.c cogl/cogl-private.h cogl/driver/gl/cogl-pipeline-progend-fixed.c cogl/driver/gl/gl/cogl-pipeline-progend-fixed-arbfp.c
2012-11-08 11:56:02 -05:00
TEST_REQUIREMENT_FENCE = 1<<10,
TEST_REQUIREMENT_PER_VERTEX_POINT_SIZE = 1<<11
} TestFlags;
/**
* TestUtilsTextureFlags:
* @TEST_UTILS_TEXTURE_NONE: No flags specified
* @TEST_UTILS_TEXTURE_NO_AUTO_MIPMAP: Disables the automatic generation of
* the mipmap pyramid from the base level image whenever it is
* updated. The mipmaps are only generated when the texture is
* rendered with a mipmap filter so it should be free to leave out
* this flag when using other filtering modes
* @TEST_UTILS_TEXTURE_NO_SLICING: Disables the slicing of the texture
* @TEST_UTILS_TEXTURE_NO_ATLAS: Disables the insertion of the texture inside
* the texture atlas used by Cogl
*
* Flags to pass to the test_utils_texture_new_* family of functions.
*/
typedef enum {
TEST_UTILS_TEXTURE_NONE = 0,
TEST_UTILS_TEXTURE_NO_AUTO_MIPMAP = 1 << 0,
TEST_UTILS_TEXTURE_NO_SLICING = 1 << 1,
TEST_UTILS_TEXTURE_NO_ATLAS = 1 << 2
} TestUtilsTextureFlags;
extern CoglContext *test_ctx;
extern CoglFramebuffer *test_fb;
void
test_utils_init (TestFlags requirement_flags,
TestFlags known_failure_flags);
void
test_utils_fini (void);
/*
* test_utils_texture_new_with_size:
* @context: A #CoglContext
* @width: width of texture in pixels.
* @height: height of texture in pixels.
* @flags: Optional flags for the texture, or %TEST_UTILS_TEXTURE_NONE
* @internal_format: the #CoglPixelFormat to use for the GPU storage of the
* texture.
*
* Creates a new #CoglTexture with the specified dimensions and pixel format.
*
* The storage for the texture is not necesarily created before this
* function returns. The storage can be explicitly allocated using
* cogl_texture_allocate() or preferably you can let Cogl
* automatically allocate the storage lazily when uploading data when
* Cogl may know more about how the texture will be used and can
* optimize how it is allocated.
*
* Return value: A newly created #CoglTexture
*/
CoglTexture *
test_utils_texture_new_with_size (CoglContext *ctx,
int width,
int height,
TestUtilsTextureFlags flags,
CoglPixelFormat internal_format);
/*
* test_utils_texture_new_from_data:
* @context: A #CoglContext
* @width: width of texture in pixels
* @height: height of texture in pixels
* @flags: Optional flags for the texture, or %TEST_UTILS_TEXTURE_NONE
* @format: the #CoglPixelFormat the buffer is stored in in RAM
* @internal_format: the #CoglPixelFormat that will be used for storing
* the buffer on the GPU. If COGL_PIXEL_FORMAT_ANY is given then a
* premultiplied format similar to the format of the source data will
* be used. The default blending equations of Cogl expect premultiplied
* color data; the main use of passing a non-premultiplied format here
* is if you have non-premultiplied source data and are going to adjust
* the blend mode (see cogl_material_set_blend()) or use the data for
* something other than straight blending.
* @rowstride: the memory offset in bytes between the starts of
* scanlines in @data
* @data: pointer the memory region where the source buffer resides
* @error: A #CoglError to catch exceptional errors or %NULL
*
* Creates a new #CoglTexture based on data residing in memory.
*
* Return value: A newly created #CoglTexture or %NULL on failure
*/
CoglTexture *
test_utils_texture_new_from_data (CoglContext *ctx,
int width,
int height,
TestUtilsTextureFlags flags,
CoglPixelFormat format,
CoglPixelFormat internal_format,
int rowstride,
const uint8_t *data);
/*
* test_utils_texture_new_from_bitmap:
* @bitmap: A #CoglBitmap pointer
* @flags: Optional flags for the texture, or %TEST_UTILS_TEXTURE_NONE
* @internal_format: the #CoglPixelFormat to use for the GPU storage of the
* texture
* @error: A #CoglError to catch exceptional errors or %NULL
*
* Creates a #CoglTexture from a #CoglBitmap.
*
* Return value: A newly created #CoglTexture or %NULL on failure
*/
CoglTexture *
test_utils_texture_new_from_bitmap (CoglBitmap *bitmap,
TestUtilsTextureFlags flags,
CoglPixelFormat internal_format);
/*
* test_utils_check_pixel:
* @framebuffer: The #CoglFramebuffer to read from
* @x: x co-ordinate of the pixel to test
* @y: y co-ordinate of the pixel to test
* @pixel: An integer of the form 0xRRGGBBAA representing the expected
* pixel value
*
* This performs reads a pixel on the given cogl @framebuffer and
* asserts that it matches the given color. The alpha channel of the
* color is ignored. The pixels are converted to a string and compared
* with g_assert_cmpstr so that if the comparison fails then the
* assert will display a meaningful message
*/
void
test_utils_check_pixel (CoglFramebuffer *framebuffer,
int x, int y, uint32_t expected_pixel);
/**
* @framebuffer: The #CoglFramebuffer to read from
* @x: x co-ordinate of the pixel to test
* @y: y co-ordinate of the pixel to test
* @pixel: An integer of the form 0xRRGGBBAA representing the expected
* pixel value
*
* This performs reads a pixel on the given cogl @framebuffer and
* asserts that it matches the given color. The alpha channel is also
* checked unlike with test_utils_check_pixel(). The pixels are
* converted to a string and compared with g_assert_cmpstr so that if
* the comparison fails then the assert will display a meaningful
* message.
*/
void
test_utils_check_pixel_and_alpha (CoglFramebuffer *fb,
int x, int y, uint32_t expected_pixel);
/*
* test_utils_check_pixel:
* @framebuffer: The #CoglFramebuffer to read from
* @x: x co-ordinate of the pixel to test
* @y: y co-ordinate of the pixel to test
* @pixel: An integer of the form 0xrrggbb representing the expected pixel value
*
* This performs reads a pixel on the given cogl @framebuffer and
* asserts that it matches the given color. The alpha channel of the
* color is ignored. The pixels are converted to a string and compared
* with g_assert_cmpstr so that if the comparison fails then the
* assert will display a meaningful message
*/
void
test_utils_check_pixel_rgb (CoglFramebuffer *framebuffer,
int x, int y, int r, int g, int b);
/*
* test_utils_check_region:
* @framebuffer: The #CoglFramebuffer to read from
* @x: x co-ordinate of the region to test
* @y: y co-ordinate of the region to test
* @width: width of the region to test
* @height: height of the region to test
* @pixel: An integer of the form 0xrrggbb representing the expected region color
*
* Performs a read pixel on the specified region of the given cogl
* @framebuffer and asserts that it matches the given color. The alpha
* channel of the color is ignored. The pixels are converted to a
* string and compared with g_assert_cmpstr so that if the comparison
* fails then the assert will display a meaningful message
*/
void
test_utils_check_region (CoglFramebuffer *framebuffer,
int x, int y,
int width, int height,
uint32_t expected_rgba);
/*
* test_utils_compare_pixel:
* @screen_pixel: A pixel stored in memory
* @expected_pixel: The expected RGBA value
*
* Compares a pixel from a buffer to an expected value. The pixels are
* converted to a string and compared with g_assert_cmpstr so that if
* the comparison fails then the assert will display a meaningful
* message.
*/
void
test_utils_compare_pixel (const uint8_t *screen_pixel, uint32_t expected_pixel);
/*
* test_utils_compare_pixel_and_alpha:
* @screen_pixel: A pixel stored in memory
* @expected_pixel: The expected RGBA value
*
* Compares a pixel from a buffer to an expected value. This is
* similar to test_utils_compare_pixel() except that it doesn't ignore
* the alpha component.
*/
void
test_utils_compare_pixel_and_alpha (const uint8_t *screen_pixel,
uint32_t expected_pixel);
/*
* test_utils_create_color_texture:
* @context: A #CoglContext
* @color: A color to put in the texture
*
* Creates a 1x1-pixel RGBA texture filled with the given color.
*/
CoglTexture *
test_utils_create_color_texture (CoglContext *context,
uint32_t color);
/* cogl_test_verbose:
*
* Queries if the user asked for verbose output or not.
*/
CoglBool
cogl_test_verbose (void);
/* test_util_is_pot:
* @number: A number to test
*
* Returns whether the given integer is a power of two
*/
static inline CoglBool
test_utils_is_pot (unsigned int number)
{
/* Make sure there is only one bit set */
return (number & (number - 1)) == 0;
}
#endif /* _TEST_UTILS_H_ */