Commit 21a246eb authored by Owen W. Taylor's avatar Owen W. Taylor
Browse files

Use a template material for shadows

To avoid unnecessary shader recompilation, use a root template material
for all shadows.
parent 1bbaec81
......@@ -4,7 +4,8 @@
* Create and cache shadow textures for abritrary window shapes
* Copyright (C) 2010 Red Hat, Inc.
* Copyright 2010 Red Hat, Inc.
* Copyright 2010 Intel Corporation
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License as
......@@ -617,6 +618,49 @@ flip_buffer (guchar *buffer,
/* Creates a material with a single layer. Using a common template
* allows sharing a shader between all shadows. To share the same
* shader with all other materials that are just texture plus
* opacity would require cogl fixes. Based on
* gnome-shell/src/st/_st_create_texture_material.c
static CoglHandle
create_texture_material (CoglHandle src_texture)
static CoglHandle texture_material_template = COGL_INVALID_HANDLE;
CoglHandle material;
g_return_val_if_fail (src_texture != COGL_INVALID_HANDLE,
/* We use a material that has a dummy texture as a base for all
texture materials. The idea is that only the Cogl texture object
would be different in the children so it is likely that Cogl will
be able to share GL programs between all the textures. */
if (G_UNLIKELY (texture_material_template == COGL_INVALID_HANDLE))
static const guint8 white_pixel[] = { 0xff, 0xff, 0xff, 0xff };
CoglHandle dummy_texture;
dummy_texture =
cogl_texture_new_from_data (1, 1,
4, white_pixel);
texture_material_template = cogl_material_new ();
cogl_material_set_layer (texture_material_template, 0, dummy_texture);
cogl_handle_unref (dummy_texture);
material = cogl_material_copy (texture_material_template);
cogl_material_set_layer (material, 0, src_texture);
return material;
static void
make_shadow (MetaShadow *shadow,
cairo_region_t *region)
......@@ -724,8 +768,7 @@ make_shadow (MetaShadow *shadow,
cairo_region_destroy (column_convolve_region);
g_free (buffer);
shadow->material = cogl_material_new ();
cogl_material_set_layer (shadow->material, 0, shadow->texture);
shadow->material = create_texture_material (shadow->texture);
static MetaShadowParams *
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment