1 | /* gskgltexture.c |
2 | * |
3 | * Copyright 2020 Christian Hergert <chergert@redhat.com> |
4 | * |
5 | * This file is free software; you can redistribute it and/or modify it under |
6 | * the terms of the GNU Lesser General Public License as published by the Free |
7 | * Software Foundation; either version 2.1 of the License, or (at your option) |
8 | * any later version. |
9 | * |
10 | * This file is distributed in the hope that it will be useful, but WITHOUT |
11 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
12 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public |
13 | * License for more details. |
14 | * |
15 | * You should have received a copy of the GNU General Public License along |
16 | * with this program. If not, see <http://www.gnu.org/licenses/>. |
17 | * |
18 | * SPDX-License-Identifier: LGPL-2.1-or-later |
19 | */ |
20 | |
21 | #include "config.h" |
22 | |
23 | #include <gdk/gdktextureprivate.h> |
24 | |
25 | #include "gskgltextureprivate.h" |
26 | #include "ninesliceprivate.h" |
27 | |
28 | void |
29 | gsk_gl_texture_free (GskGLTexture *texture) |
30 | { |
31 | if (texture != NULL) |
32 | { |
33 | g_assert (texture->link.prev == NULL); |
34 | g_assert (texture->link.next == NULL); |
35 | |
36 | if (texture->user) |
37 | g_clear_pointer (&texture->user, gdk_texture_clear_render_data); |
38 | |
39 | if (texture->texture_id != 0) |
40 | { |
41 | glDeleteTextures (1, &texture->texture_id); |
42 | texture->texture_id = 0; |
43 | } |
44 | |
45 | for (guint i = 0; i < texture->n_slices; i++) |
46 | { |
47 | glDeleteTextures (1, &texture->slices[i].texture_id); |
48 | texture->slices[i].texture_id = 0; |
49 | } |
50 | |
51 | g_clear_pointer (&texture->slices, g_free); |
52 | g_clear_pointer (&texture->nine_slice, g_free); |
53 | |
54 | g_slice_free (GskGLTexture, texture); |
55 | } |
56 | } |
57 | |
58 | GskGLTexture * |
59 | gsk_gl_texture_new (guint texture_id, |
60 | int width, |
61 | int height, |
62 | int format, |
63 | int min_filter, |
64 | int mag_filter, |
65 | gint64 frame_id) |
66 | { |
67 | GskGLTexture *texture; |
68 | |
69 | texture = g_slice_new0 (GskGLTexture); |
70 | texture->texture_id = texture_id; |
71 | texture->link.data = texture; |
72 | texture->min_filter = min_filter; |
73 | texture->mag_filter = mag_filter; |
74 | texture->format = format; |
75 | texture->width = width; |
76 | texture->height = height; |
77 | texture->last_used_in_frame = frame_id; |
78 | |
79 | return texture; |
80 | } |
81 | |
82 | const GskGLTextureNineSlice * |
83 | gsk_gl_texture_get_nine_slice (GskGLTexture *texture, |
84 | const GskRoundedRect *outline, |
85 | float , |
86 | float ) |
87 | { |
88 | g_assert (texture != NULL); |
89 | g_assert (outline != NULL); |
90 | |
91 | if G_UNLIKELY (texture->nine_slice == NULL) |
92 | { |
93 | texture->nine_slice = g_new0 (GskGLTextureNineSlice, 9); |
94 | |
95 | nine_slice_rounded_rect (slices: texture->nine_slice, rect: outline); |
96 | nine_slice_grow (slices: texture->nine_slice, amount_x: extra_pixels_x, amount_y: extra_pixels_y); |
97 | nine_slice_to_texture_coords (slices: texture->nine_slice, texture_width: texture->width, texture_height: texture->height); |
98 | } |
99 | |
100 | return texture->nine_slice; |
101 | } |
102 | |