gboolean meta_surface_actor_is_argb32 (MetaSurfaceActor *self) { MetaShapedTexture *stex = meta_surface_actor_get_texture (self); CoglTexture *texture = meta_shaped_texture_get_texture (stex); /* If we don't have a texture, like during initialization, assume * that we're ARGB32. * * If we are unredirected and we have no texture assume that we are * not ARGB32 otherwise we wouldn't be unredirected in the first * place. This prevents us from continually redirecting and * unredirecting on every paint. */ if (!texture) return !meta_surface_actor_is_unredirected (self); switch (cogl_texture_get_components (texture)) { case COGL_TEXTURE_COMPONENTS_A: case COGL_TEXTURE_COMPONENTS_RGBA: return TRUE; case COGL_TEXTURE_COMPONENTS_RG: case COGL_TEXTURE_COMPONENTS_RGB: case COGL_TEXTURE_COMPONENTS_DEPTH: return FALSE; default: g_assert_not_reached (); } }
void test_texture_rg (void) { CoglPipeline *pipeline; CoglTexture2D *tex; int fb_width, fb_height; int x, y; fb_width = cogl_framebuffer_get_width (test_fb); fb_height = cogl_framebuffer_get_height (test_fb); tex = make_texture (); g_assert (cogl_texture_get_components (tex) == COGL_TEXTURE_COMPONENTS_RG); pipeline = cogl_pipeline_new (test_ctx); cogl_pipeline_set_layer_texture (pipeline, 0, tex); cogl_pipeline_set_layer_filters (pipeline, 0, COGL_PIPELINE_FILTER_NEAREST, COGL_PIPELINE_FILTER_NEAREST); cogl_framebuffer_draw_rectangle (test_fb, pipeline, -1.0f, 1.0f, 1.0f, -1.0f); for (y = 0; y < TEX_HEIGHT; y++) for (x = 0; x < TEX_WIDTH; x++) { test_utils_check_pixel_rgb (test_fb, x * fb_width / TEX_WIDTH + fb_width / (TEX_WIDTH * 2), y * fb_height / TEX_HEIGHT + fb_height / (TEX_HEIGHT * 2), x * 256 / TEX_WIDTH, y * 256 / TEX_HEIGHT, 0); } cogl_object_unref (pipeline); cogl_object_unref (tex); }
gboolean meta_surface_actor_is_argb32 (MetaSurfaceActor *self) { MetaShapedTexture *stex = meta_surface_actor_get_texture (self); CoglTexture *texture = meta_shaped_texture_get_texture (stex); /* If we don't have a texture, like during initialization, assume * that we're ARGB32. */ if (!texture) return TRUE; switch (cogl_texture_get_components (texture)) { case COGL_TEXTURE_COMPONENTS_A: case COGL_TEXTURE_COMPONENTS_RGBA: return TRUE; case COGL_TEXTURE_COMPONENTS_RG: case COGL_TEXTURE_COMPONENTS_RGB: case COGL_TEXTURE_COMPONENTS_DEPTH: return FALSE; default: g_assert_not_reached (); } }
static gboolean shm_buffer_attach (MetaWaylandBuffer *buffer, CoglTexture **texture, gboolean *changed_texture, GError **error) { MetaBackend *backend = meta_get_backend (); ClutterBackend *clutter_backend = meta_backend_get_clutter_backend (backend); CoglContext *cogl_context = clutter_backend_get_cogl_context (clutter_backend); struct wl_shm_buffer *shm_buffer; int stride, width, height; CoglPixelFormat format; CoglTextureComponents components; CoglBitmap *bitmap; CoglTexture *new_texture; shm_buffer = wl_shm_buffer_get (buffer->resource); stride = wl_shm_buffer_get_stride (shm_buffer); width = wl_shm_buffer_get_width (shm_buffer); height = wl_shm_buffer_get_height (shm_buffer); shm_buffer_get_cogl_pixel_format (shm_buffer, &format, &components); if (*texture && cogl_texture_get_width (*texture) == width && cogl_texture_get_height (*texture) == height && cogl_texture_get_components (*texture) == components && _cogl_texture_get_format (*texture) == format) { buffer->is_y_inverted = TRUE; *changed_texture = FALSE; return TRUE; } cogl_clear_object (texture); wl_shm_buffer_begin_access (shm_buffer); bitmap = cogl_bitmap_new_for_data (cogl_context, width, height, format, stride, wl_shm_buffer_get_data (shm_buffer)); new_texture = COGL_TEXTURE (cogl_texture_2d_new_from_bitmap (bitmap)); cogl_texture_set_components (new_texture, components); if (!cogl_texture_allocate (new_texture, error)) { g_clear_pointer (&new_texture, cogl_object_unref); if (g_error_matches (*error, COGL_TEXTURE_ERROR, COGL_TEXTURE_ERROR_SIZE)) { CoglTexture2DSliced *texture_sliced; g_clear_error (error); texture_sliced = cogl_texture_2d_sliced_new_from_bitmap (bitmap, COGL_TEXTURE_MAX_WASTE); new_texture = COGL_TEXTURE (texture_sliced); cogl_texture_set_components (new_texture, components); if (!cogl_texture_allocate (new_texture, error)) g_clear_pointer (&new_texture, cogl_object_unref); } } cogl_object_unref (bitmap); wl_shm_buffer_end_access (shm_buffer); if (!new_texture) return FALSE; *texture = new_texture; *changed_texture = TRUE; buffer->is_y_inverted = TRUE; return TRUE; }