1 | /* gskglglyphlibraryprivate.h |
2 | * |
3 | * Copyright 2020 Christian Hergert <chergert@redhat.com> |
4 | * |
5 | * This library is free software; you can redistribute it and/or |
6 | * modify it under the terms of the GNU Lesser General Public |
7 | * License as published by the Free Software Foundation; either |
8 | * version 2.1 of the License, or (at your option) any later version. |
9 | * |
10 | * This library is distributed in the hope that it will be useful, |
11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
13 | * Lesser General Public License for more details. |
14 | * |
15 | * You should have received a copy of the GNU Lesser General Public |
16 | * License along with this program. If not, see <http://www.gnu.org/licenses/>. |
17 | * |
18 | * SPDX-License-Identifier: LGPL-2.1-or-later |
19 | */ |
20 | |
21 | #ifndef __GSK_GL_GLYPH_LIBRARY_PRIVATE_H__ |
22 | #define __GSK_GL_GLYPH_LIBRARY_PRIVATE_H__ |
23 | |
24 | #include <pango/pango.h> |
25 | |
26 | #include "gskgltexturelibraryprivate.h" |
27 | |
28 | G_BEGIN_DECLS |
29 | |
30 | #define GSK_TYPE_GL_GLYPH_LIBRARY (gsk_gl_glyph_library_get_type()) |
31 | |
32 | typedef struct _GskGLGlyphKey |
33 | { |
34 | PangoFont *font; |
35 | PangoGlyph glyph; |
36 | guint xshift : 2; |
37 | guint yshift : 2; |
38 | guint scale : 28; /* times 1024 */ |
39 | } GskGLGlyphKey; |
40 | |
41 | typedef struct _GskGLGlyphValue |
42 | { |
43 | GskGLTextureAtlasEntry entry; |
44 | PangoRectangle ink_rect; |
45 | } GskGLGlyphValue; |
46 | |
47 | #if GLIB_SIZEOF_VOID_P == 8 |
48 | G_STATIC_ASSERT (sizeof (GskGLGlyphKey) == 16); |
49 | #elif GLIB_SIZEOF_VOID_P == 4 |
50 | G_STATIC_ASSERT (sizeof (GskGLGlyphKey) == 12); |
51 | #endif |
52 | |
53 | G_DECLARE_FINAL_TYPE (GskGLGlyphLibrary, gsk_gl_glyph_library, GSK, GL_GLYPH_LIBRARY, GskGLTextureLibrary) |
54 | |
55 | struct _GskGLGlyphLibrary |
56 | { |
57 | GskGLTextureLibrary parent_instance; |
58 | guint8 *surface_data; |
59 | gsize surface_data_len; |
60 | struct { |
61 | GskGLGlyphKey key; |
62 | const GskGLGlyphValue *value; |
63 | } front[256]; |
64 | }; |
65 | |
66 | GskGLGlyphLibrary *gsk_gl_glyph_library_new (GskGLDriver *driver); |
67 | gboolean gsk_gl_glyph_library_add (GskGLGlyphLibrary *self, |
68 | GskGLGlyphKey *key, |
69 | const GskGLGlyphValue **out_value); |
70 | |
71 | static inline guint |
72 | gsk_gl_glyph_library_lookup_or_add (GskGLGlyphLibrary *self, |
73 | const GskGLGlyphKey *key, |
74 | const GskGLGlyphValue **out_value) |
75 | { |
76 | GskGLTextureAtlasEntry *entry; |
77 | guint front_index = ((key->glyph << 2) | key->xshift) & 0xFF; |
78 | |
79 | if (memcmp (s1: key, s2: &self->front[front_index], n: sizeof *key) == 0) |
80 | { |
81 | *out_value = self->front[front_index].value; |
82 | } |
83 | else if (gsk_gl_texture_library_lookup (self: (GskGLTextureLibrary *)self, key, out_entry: &entry)) |
84 | { |
85 | *out_value = (GskGLGlyphValue *)entry; |
86 | self->front[front_index].key = *key; |
87 | self->front[front_index].value = *out_value; |
88 | } |
89 | else |
90 | { |
91 | GskGLGlyphKey *k = g_slice_copy (block_size: sizeof *key, mem_block: key); |
92 | g_object_ref (k->font); |
93 | gsk_gl_glyph_library_add (self, key: k, out_value); |
94 | self->front[front_index].key = *key; |
95 | self->front[front_index].value = *out_value; |
96 | } |
97 | |
98 | return GSK_GL_TEXTURE_ATLAS_ENTRY_TEXTURE (d: *out_value); |
99 | } |
100 | |
101 | G_END_DECLS |
102 | |
103 | #endif /* __GSK_GL_GLYPH_LIBRARY_PRIVATE_H__ */ |
104 | |