mirror of
https://gitlab.gnome.org/GNOME/gtk.git
synced 2024-12-25 21:21:21 +00:00
Merge branch 'matthiasc/for-main' into 'main'
tools: Cosmetics See merge request GNOME/gtk!5972
This commit is contained in:
commit
3fb06ca29d
@ -225,17 +225,17 @@ gdk_texture_downloader_download_into (const GdkTextureDownloader *self,
|
||||
/**
|
||||
* gdk_texture_downloader_download_bytes:
|
||||
* @self: the downloader
|
||||
* @out_stride: (out): The stride of the resulting data in bytes.
|
||||
* @out_stride: (out): The stride of the resulting data in bytes
|
||||
*
|
||||
* Downloads the given texture pixels into a `GBytes`. The rowstride will
|
||||
* be stored in the stride value.
|
||||
*
|
||||
* This function will abort if it tries to download a large texture and
|
||||
* fails to allocate memory. If you think that may happen, you should
|
||||
* handle memory allocation yourself and use
|
||||
* gdk_texture_downloader_download_into() once allocation succeeded.
|
||||
* fails to allocate memory. If you think that may happen, you should handle
|
||||
* memory allocation yourself and use [method@Gdk.TextureDownloader.download_into]
|
||||
* once allocation succeeded.
|
||||
*
|
||||
* Returns: The downloaded pixels.
|
||||
* Returns: The downloaded pixels
|
||||
*
|
||||
* Since: 4.10
|
||||
**/
|
||||
|
@ -218,6 +218,37 @@ test_parse_fail (void)
|
||||
}
|
||||
}
|
||||
|
||||
static void
|
||||
test_match (void)
|
||||
{
|
||||
GdkContentFormatsBuilder *builder;
|
||||
GdkContentFormats *formats, *formats2;
|
||||
|
||||
builder = gdk_content_formats_builder_new ();
|
||||
gdk_content_formats_builder_ref (builder);
|
||||
|
||||
gdk_content_formats_builder_add_gtype (builder, GDK_TYPE_RGBA);
|
||||
gdk_content_formats_builder_add_mime_type (builder, "image/png");
|
||||
formats = gdk_content_formats_builder_free_to_formats (builder);
|
||||
|
||||
gdk_content_formats_builder_add_gtype (builder, G_TYPE_STRING);
|
||||
gdk_content_formats_builder_add_mime_type (builder, "text/plain");
|
||||
formats2 = gdk_content_formats_builder_free_to_formats (builder);
|
||||
|
||||
g_assert_false (gdk_content_formats_match (formats, formats2));
|
||||
|
||||
gdk_content_formats_unref (formats2);
|
||||
|
||||
builder = gdk_content_formats_builder_new ();
|
||||
gdk_content_formats_builder_add_mime_type (builder, "image/png");
|
||||
formats2 = gdk_content_formats_builder_free_to_formats (builder);
|
||||
|
||||
g_assert_true (gdk_content_formats_match (formats, formats2));
|
||||
|
||||
gdk_content_formats_unref (formats2);
|
||||
gdk_content_formats_unref (formats);
|
||||
}
|
||||
|
||||
int
|
||||
main (int argc, char *argv[])
|
||||
{
|
||||
@ -238,6 +269,7 @@ main (int argc, char *argv[])
|
||||
g_test_add_func ("/contentformats/parse_fail", test_parse_fail);
|
||||
g_test_add_func ("/contentformats/print_and_parse", test_print_and_parse);
|
||||
g_test_add_func ("/contentformats/union", test_union);
|
||||
g_test_add_func ("/contentformats/match", test_match);
|
||||
|
||||
return g_test_run ();
|
||||
}
|
||||
|
@ -67,6 +67,85 @@ test_allowed_backends (gconstpointer data)
|
||||
g_object_unref (context);
|
||||
}
|
||||
|
||||
static void
|
||||
test_use_es (void)
|
||||
{
|
||||
GdkDisplay *display;
|
||||
GdkGLContext *context;
|
||||
GError *error = NULL;
|
||||
GdkGLAPI allowed_apis, api;
|
||||
GdkGLContext *shared;
|
||||
|
||||
display = gdk_display_get_default ();
|
||||
if (!gdk_display_prepare_gl (display, &error))
|
||||
{
|
||||
g_test_skip_printf ("no GL support: %s", error->message);
|
||||
g_clear_error (&error);
|
||||
return;
|
||||
}
|
||||
|
||||
context = gdk_display_create_gl_context (display, &error);
|
||||
g_assert_nonnull (context);
|
||||
g_assert_no_error (error);
|
||||
|
||||
g_object_set (context, "allowed-apis", GDK_GL_API_GL | GDK_GL_API_GLES, NULL);
|
||||
|
||||
G_GNUC_BEGIN_IGNORE_DEPRECATIONS
|
||||
gdk_gl_context_set_use_es (context, 1);
|
||||
g_assert_true (gdk_gl_context_get_allowed_apis (context) == GDK_GL_API_GLES);
|
||||
gdk_gl_context_set_use_es (context, 0);
|
||||
g_assert_true (gdk_gl_context_get_allowed_apis (context) == GDK_GL_API_GL);
|
||||
gdk_gl_context_set_use_es (context, -1);
|
||||
g_assert_true (gdk_gl_context_get_allowed_apis (context) == (GDK_GL_API_GL | GDK_GL_API_GLES));
|
||||
G_GNUC_END_IGNORE_DEPRECATIONS
|
||||
|
||||
api = gdk_gl_context_realize (context, &error);
|
||||
g_assert_no_error (error);
|
||||
g_assert_true (api != 0);
|
||||
|
||||
g_object_get (context,
|
||||
"allowed-apis", &allowed_apis,
|
||||
"api", &api,
|
||||
"shared-context", &shared,
|
||||
NULL);
|
||||
|
||||
g_assert_true (allowed_apis == (GDK_GL_API_GL | GDK_GL_API_GLES));
|
||||
g_assert_true (api == GDK_GL_API_GL || api == GDK_GL_API_GLES);
|
||||
g_assert_null (shared);
|
||||
|
||||
g_object_unref (context);
|
||||
}
|
||||
|
||||
static void
|
||||
test_version (void)
|
||||
{
|
||||
GdkDisplay *display;
|
||||
GdkGLContext *context;
|
||||
GError *error = NULL;
|
||||
int major, minor;
|
||||
|
||||
display = gdk_display_get_default ();
|
||||
if (!gdk_display_prepare_gl (display, &error))
|
||||
{
|
||||
g_test_skip_printf ("no GL support: %s", error->message);
|
||||
g_clear_error (&error);
|
||||
return;
|
||||
}
|
||||
|
||||
context = gdk_display_create_gl_context (display, &error);
|
||||
g_assert_nonnull (context);
|
||||
g_assert_no_error (error);
|
||||
|
||||
gdk_gl_context_get_required_version (context, &major, &minor);
|
||||
g_assert_true (major == 0 && minor == 0);
|
||||
|
||||
gdk_gl_context_set_required_version (context, 4, 0);
|
||||
gdk_gl_context_get_required_version (context, &major, &minor);
|
||||
g_assert_true (major == 4 && minor == 0);
|
||||
|
||||
g_object_unref (context);
|
||||
}
|
||||
|
||||
int
|
||||
main (int argc, char *argv[])
|
||||
{
|
||||
@ -77,5 +156,8 @@ main (int argc, char *argv[])
|
||||
g_test_add_data_func ("/allowed-apis/gles", GSIZE_TO_POINTER (GDK_GL_API_GLES), test_allowed_backends);
|
||||
g_test_add_data_func ("/allowed-apis/all", GSIZE_TO_POINTER (GDK_GL_API_GL | GDK_GL_API_GLES), test_allowed_backends);
|
||||
|
||||
g_test_add_func ("/allowed-apis/use-es", test_use_es);
|
||||
g_test_add_func ("/allowed-apis/version", test_version);
|
||||
|
||||
return g_test_run ();
|
||||
}
|
||||
|
@ -1,5 +1,7 @@
|
||||
#include <gtk/gtk.h>
|
||||
#include <epoxy/gl.h>
|
||||
#include "gdk/gdktextureprivate.h"
|
||||
#include "gdk/gdkglcontextprivate.h"
|
||||
|
||||
static cairo_surface_t *
|
||||
make_surface (void)
|
||||
@ -20,6 +22,23 @@ make_surface (void)
|
||||
return surface;
|
||||
}
|
||||
|
||||
static unsigned int
|
||||
make_gl_texture (GdkGLContext *context,
|
||||
cairo_surface_t *surface)
|
||||
{
|
||||
unsigned int id;
|
||||
|
||||
glGenTextures (1, &id);
|
||||
glActiveTexture (GL_TEXTURE0);
|
||||
glBindTexture (GL_TEXTURE_2D, id);
|
||||
glTexImage2D (GL_TEXTURE_2D, 0, GL_RGBA8, 64, 64, 0, GL_BGRA, GL_UNSIGNED_BYTE,
|
||||
cairo_image_surface_get_data (surface));
|
||||
|
||||
g_assert_true (glGetError () == GL_NO_ERROR);
|
||||
|
||||
return id;
|
||||
}
|
||||
|
||||
enum {
|
||||
SAME_CONTEXT,
|
||||
NO_CONTEXT,
|
||||
@ -59,13 +78,7 @@ test_gltexture (int test)
|
||||
|
||||
gdk_gl_context_make_current (context);
|
||||
|
||||
glGenTextures (1, &id);
|
||||
glActiveTexture (GL_TEXTURE0);
|
||||
glBindTexture (GL_TEXTURE_2D, id);
|
||||
glTexImage2D (GL_TEXTURE_2D, 0, GL_RGBA8, 64, 64, 0, GL_BGRA, GL_UNSIGNED_BYTE,
|
||||
cairo_image_surface_get_data (surface));
|
||||
|
||||
g_assert_true (glGetError () == GL_NO_ERROR);
|
||||
id = make_gl_texture (context, surface);
|
||||
|
||||
if (test == NO_CONTEXT)
|
||||
gdk_gl_context_clear_current ();
|
||||
@ -122,6 +135,102 @@ test_gltexture_shared_context (void)
|
||||
test_gltexture (SHARED_CONTEXT);
|
||||
}
|
||||
|
||||
static void
|
||||
test_gltexture_updates (void)
|
||||
{
|
||||
GdkDisplay *display;
|
||||
GdkGLContext *context;
|
||||
GdkGLTextureBuilder *builder;
|
||||
cairo_surface_t *surface;
|
||||
GError *error = NULL;
|
||||
unsigned int id;
|
||||
guchar *data;
|
||||
gpointer sync;
|
||||
GdkTexture *old_texture;
|
||||
GdkTexture *texture;
|
||||
cairo_region_t *update_region, *diff;
|
||||
|
||||
display = gdk_display_get_default ();
|
||||
if (!gdk_display_prepare_gl (display, &error))
|
||||
{
|
||||
g_test_message ("no GL support: %s", error->message);
|
||||
g_test_skip ("no GL support");
|
||||
g_clear_error (&error);
|
||||
return;
|
||||
}
|
||||
|
||||
context = gdk_display_create_gl_context (display, &error);
|
||||
g_assert_nonnull (context);
|
||||
g_assert_no_error (error);
|
||||
|
||||
builder = gdk_gl_texture_builder_new ();
|
||||
gdk_gl_texture_builder_set_id (builder, 10);
|
||||
|
||||
surface = make_surface ();
|
||||
|
||||
gdk_gl_context_make_current (context);
|
||||
|
||||
id = make_gl_texture (context, surface);
|
||||
|
||||
G_GNUC_BEGIN_IGNORE_DEPRECATIONS
|
||||
old_texture = gdk_gl_texture_new (context, id, 64, 64, NULL, NULL);
|
||||
G_GNUC_END_IGNORE_DEPRECATIONS
|
||||
|
||||
id = make_gl_texture (context, surface);
|
||||
|
||||
if (gdk_gl_context_has_sync (context))
|
||||
sync = glFenceSync (GL_SYNC_GPU_COMMANDS_COMPLETE, 0);
|
||||
else
|
||||
sync = NULL;
|
||||
|
||||
update_region = cairo_region_create_rectangle (&(cairo_rectangle_int_t) { 10, 10, 32, 32 });
|
||||
|
||||
builder = gdk_gl_texture_builder_new ();
|
||||
g_object_set (builder,
|
||||
"context", context,
|
||||
"id", id,
|
||||
"width", 64,
|
||||
"height", 64,
|
||||
"sync", sync,
|
||||
"update-texture", old_texture,
|
||||
"update-region", update_region,
|
||||
NULL);
|
||||
|
||||
g_assert_true (gdk_gl_texture_builder_get_sync (builder) == sync);
|
||||
g_assert_true (gdk_gl_texture_builder_get_update_texture (builder) == old_texture);
|
||||
g_assert_true (cairo_region_equal (gdk_gl_texture_builder_get_update_region (builder), update_region));
|
||||
|
||||
texture = gdk_gl_texture_builder_build (builder, NULL, NULL);
|
||||
|
||||
data = g_malloc0 (64 * 64 * 4);
|
||||
gdk_texture_download (texture, data, 64 * 4);
|
||||
|
||||
g_assert_true (memcmp (data, cairo_image_surface_get_data (surface), 64 * 64 * 4) == 0);
|
||||
|
||||
diff = cairo_region_create ();
|
||||
gdk_texture_diff (texture, old_texture, diff);
|
||||
g_assert_true (cairo_region_equal (diff, update_region));
|
||||
cairo_region_destroy (diff);
|
||||
|
||||
diff = cairo_region_create ();
|
||||
gdk_texture_diff (old_texture, texture, diff);
|
||||
g_assert_true (cairo_region_equal (diff, update_region));
|
||||
cairo_region_destroy (diff);
|
||||
|
||||
g_free (data);
|
||||
g_object_unref (texture);
|
||||
g_object_unref (builder);
|
||||
|
||||
cairo_surface_destroy (surface);
|
||||
|
||||
if (sync)
|
||||
glDeleteSync (sync);
|
||||
cairo_region_destroy (update_region);
|
||||
g_object_unref (old_texture);
|
||||
|
||||
g_object_unref (context);
|
||||
}
|
||||
|
||||
int
|
||||
main (int argc, char *argv[])
|
||||
{
|
||||
@ -130,6 +239,7 @@ main (int argc, char *argv[])
|
||||
g_test_add_func ("/gltexture/same-context", test_gltexture_same_context);
|
||||
g_test_add_func ("/gltexture/no-context", test_gltexture_no_context);
|
||||
g_test_add_func ("/gltexture/shared-context", test_gltexture_shared_context);
|
||||
g_test_add_func ("/gltexture/updates", test_gltexture_updates);
|
||||
|
||||
return g_test_run ();
|
||||
}
|
||||
|
@ -17,7 +17,6 @@ tests = [
|
||||
{ 'name': 'displaymanager' },
|
||||
{ 'name': 'encoding' },
|
||||
{ 'name': 'glcontext' },
|
||||
{ 'name': 'gltexture' },
|
||||
{ 'name': 'keysyms' },
|
||||
{ 'name': 'memorytexture' },
|
||||
{ 'name': 'rectangle' },
|
||||
@ -55,6 +54,7 @@ endforeach
|
||||
internal_tests = [
|
||||
'image',
|
||||
'texture',
|
||||
'gltexture',
|
||||
]
|
||||
|
||||
foreach t : internal_tests
|
||||
|
@ -355,6 +355,45 @@ test_texture_diff (void)
|
||||
g_object_unref (texture2);
|
||||
}
|
||||
|
||||
static void
|
||||
test_texture_downloader (void)
|
||||
{
|
||||
GdkTexture *texture;
|
||||
GdkTexture *texture2;
|
||||
GdkTextureDownloader *downloader;
|
||||
GdkTextureDownloader *downloader2;
|
||||
gsize stride;
|
||||
GBytes *bytes;
|
||||
guchar *data;
|
||||
|
||||
texture = gdk_texture_new_from_resource ("/org/gtk/libgtk/icons/16x16/places/user-trash.png");
|
||||
texture2 = gdk_texture_new_from_resource ("/org/gtk/libgtk/icons/16x16/places/user-trash.png");
|
||||
|
||||
downloader = gdk_texture_downloader_new (texture);
|
||||
|
||||
downloader2 = gdk_texture_downloader_copy (downloader);
|
||||
g_assert_true (gdk_texture_downloader_get_texture (downloader2) == texture);
|
||||
gdk_texture_downloader_free (downloader2);
|
||||
|
||||
gdk_texture_downloader_set_texture (downloader, texture2);
|
||||
gdk_texture_downloader_set_format (downloader, GDK_MEMORY_R16G16B16A16);
|
||||
g_assert_true (gdk_texture_downloader_get_format (downloader) == GDK_MEMORY_R16G16B16A16);
|
||||
|
||||
bytes = gdk_texture_downloader_download_bytes (downloader, &stride);
|
||||
|
||||
g_assert_true (stride == 4 * 2 * 16);
|
||||
g_assert_true (g_bytes_get_size (bytes) == stride * 16);
|
||||
|
||||
data = g_malloc (stride * 16);
|
||||
gdk_texture_downloader_download_into (downloader, data, stride);
|
||||
|
||||
g_assert_true (memcmp (data, g_bytes_get_data (bytes, NULL), stride * 16) == 0);
|
||||
|
||||
g_free (data);
|
||||
g_bytes_unref (bytes);
|
||||
gdk_texture_downloader_free (downloader);
|
||||
}
|
||||
|
||||
int
|
||||
main (int argc, char *argv[])
|
||||
{
|
||||
@ -370,6 +409,7 @@ main (int argc, char *argv[])
|
||||
g_test_add_func ("/texture/icon/load-async", test_texture_icon_async);
|
||||
g_test_add_func ("/texture/icon/serialize", test_texture_icon_serialize);
|
||||
g_test_add_func ("/texture/diff", test_texture_diff);
|
||||
g_test_add_func ("/texture/downloader", test_texture_downloader);
|
||||
|
||||
return g_test_run ();
|
||||
}
|
||||
|
@ -328,7 +328,8 @@ screenshot_file (const char *filename,
|
||||
g_bytes_get_size (bytes),
|
||||
&error))
|
||||
{
|
||||
g_print (_("Output written to %s.\n"), save_to);
|
||||
if (save_file == NULL)
|
||||
g_print (_("Output written to %s.\n"), save_to);
|
||||
}
|
||||
else
|
||||
{
|
||||
@ -359,7 +360,7 @@ do_screenshot (int *argc,
|
||||
{ "css", 0, 0, G_OPTION_ARG_FILENAME, &css, N_("Use style from CSS file"), N_("FILE") },
|
||||
{ "node", 0, 0, G_OPTION_ARG_NONE, &as_node, N_("Save as node file instead of png"), NULL },
|
||||
{ "force", 0, 0, G_OPTION_ARG_NONE, &force, N_("Overwrite existing file"), NULL },
|
||||
{ G_OPTION_REMAINING, 0, 0, G_OPTION_ARG_FILENAME_ARRAY, &filenames, NULL, N_("FILE") },
|
||||
{ G_OPTION_REMAINING, 0, 0, G_OPTION_ARG_FILENAME_ARRAY, &filenames, NULL, N_("FILE…") },
|
||||
{ NULL, }
|
||||
};
|
||||
GError *error = NULL;
|
||||
|
Loading…
Reference in New Issue
Block a user