|
| 1 | +/* |
| 2 | + * Copyright 2015 Corentin Noël |
| 3 | + * Copyright 2025 elementary, Inc. <https://elementary.io> |
| 4 | + * SPDX-License-Identifier: GPL-3.0-or-later |
| 5 | + */ |
| 6 | + |
| 7 | +#if !HAS_MUTTER46 |
| 8 | +public class Gala.Image : Clutter.Image { |
| 9 | + public Image.from_pixbuf (Gdk.Pixbuf pixbuf) { |
| 10 | + Object (); |
| 11 | + |
| 12 | + Cogl.PixelFormat pixel_format = (pixbuf.get_has_alpha () ? Cogl.PixelFormat.RGBA_8888 : Cogl.PixelFormat.RGB_888); |
| 13 | + //set_data (pixbuf.get_pixels (), pixel_format, pixbuf.width, pixbuf.height, pixbuf.rowstride); |
| 14 | + } |
| 15 | +} |
| 16 | +#else |
| 17 | +public class Gala.Image : GLib.Object, Clutter.Content { |
| 18 | + Cogl.Texture? texture; |
| 19 | + int width; |
| 20 | + int height; |
| 21 | + |
| 22 | + public Image.from_pixbuf (Gdk.Pixbuf pixbuf) { |
| 23 | + Cogl.PixelFormat pixel_format = (pixbuf.get_has_alpha () ? Cogl.PixelFormat.RGBA_8888 : Cogl.PixelFormat.RGB_888); |
| 24 | + //image.set_data (pixbuf.get_pixels (), pixel_format, pixbuf.width, pixbuf.height, pixbuf.rowstride); |
| 25 | + } |
| 26 | + |
| 27 | + public bool get_preferred_size (out float width, out float height) { |
| 28 | + if (texture == null) |
| 29 | + return false; |
| 30 | + |
| 31 | + width = texture.get_width (); |
| 32 | + height = texture.get_height (); |
| 33 | + return true; |
| 34 | + } |
| 35 | + |
| 36 | + public void paint_content (Clutter.Actor actor, Clutter.PaintNode node, Clutter.PaintContext paint_context) { |
| 37 | + if (texture == null) |
| 38 | + return; |
| 39 | + |
| 40 | + var content_node = actor.create_texture_paint_node (texture); |
| 41 | + content_node.set_static_name ("Image Content"); |
| 42 | + node.add_child (content_node); |
| 43 | + } |
| 44 | + |
| 45 | + public void invalidate () { |
| 46 | + |
| 47 | + } |
| 48 | + |
| 49 | + public void invalidate_size () { |
| 50 | + |
| 51 | + } |
| 52 | +/* |
| 53 | + gboolean |
| 54 | + st_image_content_set_data (StImageContent *content, |
| 55 | + const guint8 *data, |
| 56 | + CoglPixelFormat pixel_format, |
| 57 | + guint width, |
| 58 | + guint height, |
| 59 | + guint row_stride, |
| 60 | + GError **error) |
| 61 | + { |
| 62 | + g_return_val_if_fail (ST_IS_IMAGE_CONTENT (content), FALSE); |
| 63 | + g_return_val_if_fail (data != NULL, FALSE); |
| 64 | +
|
| 65 | + if (content->texture != NULL) |
| 66 | + g_object_unref (content->texture); |
| 67 | +
|
| 68 | + content->texture = create_texture_from_data (width, |
| 69 | + height, |
| 70 | + pixel_format, |
| 71 | + row_stride, |
| 72 | + data, |
| 73 | + error); |
| 74 | +
|
| 75 | + if (content->texture == NULL) |
| 76 | + return FALSE; |
| 77 | +
|
| 78 | + clutter_content_invalidate (CLUTTER_CONTENT (content)); |
| 79 | + update_image_size (content); |
| 80 | +
|
| 81 | + return TRUE; |
| 82 | + } |
| 83 | +
|
| 84 | +
|
| 85 | + set_data (this, data, pixel_format, width, height, row_stride) throws { |
| 86 | + backend = Clutter.Backend.get_default(); |
| 87 | + cogl_context = backend.get_cogl_context (); |
| 88 | + this.texture = Cogl.Texture2D.new_from_data (cogl_context, width, height, pixel_format, row_stride, data, error); |
| 89 | +
|
| 90 | + if (!this.texture) |
| 91 | + return; |
| 92 | + |
| 93 | + this.content_invalidate (); |
| 94 | +
|
| 95 | + int width = this.texture.get_width(); |
| 96 | + int height = this.texture.get_height(); |
| 97 | +
|
| 98 | + if (this.width == width && this.height == height) |
| 99 | + return; |
| 100 | +
|
| 101 | + this.width = width; |
| 102 | + this.height = height; |
| 103 | + this.invalidate_size(); |
| 104 | + }*/ |
| 105 | +} |
| 106 | +#endif |
0 commit comments