ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/deliantra/Deliantra-Client/pango-render.c
(Generate patch)

Comparing deliantra/Deliantra-Client/pango-render.c (file contents):
Revision 1.16 by root, Thu Nov 26 07:19:11 2009 UTC vs.
Revision 1.20 by root, Sun Nov 18 03:06:13 2018 UTC

38 PangoRenderer parent_instance; 38 PangoRenderer parent_instance;
39 float r, g, b, a; // modulate 39 float r, g, b, a; // modulate
40 int flags; 40 int flags;
41 rc_t *rc; // rendercache 41 rc_t *rc; // rendercache
42 rc_key_t key; // current render key 42 rc_key_t key; // current render key
43 rc_array_t *arr; 43 rc_t::array_t *arr;
44}; 44};
45 45
46G_DEFINE_TYPE (PangoOpenGLRenderer, pango_opengl_renderer, PANGO_TYPE_RENDERER) 46G_DEFINE_TYPE (PangoOpenGLRenderer, pango_opengl_renderer, PANGO_TYPE_RENDERER)
47 47
48typedef struct 48typedef struct
60 if (size > alloc) 60 if (size > alloc)
61 { 61 {
62 size = (size + 4095) & ~4095; 62 size = (size + 4095) & ~4095;
63 free (buffer); 63 free (buffer);
64 alloc = size; 64 alloc = size;
65 buffer = malloc (size); 65 buffer = (char *)malloc (size);
66 } 66 }
67 67
68 return buffer; 68 return buffer;
69} 69}
70 70
90 glyph->width = width; 90 glyph->width = width;
91 glyph->height = height; 91 glyph->height = height;
92 glyph->top = top; 92 glyph->top = top;
93 glyph->left = left; 93 glyph->left = left;
94 94
95 glyph->bitmap = temp_buffer (width * height); 95 glyph->bitmap = (uint8_t *)temp_buffer (width * height);
96 memset (glyph->bitmap, 0, glyph->stride * height); 96 memset (glyph->bitmap, 0, glyph->stride * height);
97 97
98 for (i = width; i--; ) 98 for (i = width; i--; )
99 glyph->bitmap [i] = glyph->bitmap [i + (height - 1) * glyph->stride] = 0xff; 99 glyph->bitmap [i] = glyph->bitmap [i + (height - 1) * glyph->stride] = 0xff;
100 100
159{ 159{
160 tc_put (&g->tex); 160 tc_put (&g->tex);
161 g_slice_free (glyph_info, g); 161 g_slice_free (glyph_info, g);
162} 162}
163 163
164static char *apple_nvidia_bug_buf; 164static int apple_nvidia_bug_workaround;
165 165
166static void 166static void
167apple_nvidia_bug (int enable) 167apple_nvidia_bug (int enable)
168{ 168{
169 g_slice_free1 (TC_WIDTH * TC_HEIGHT, apple_nvidia_bug_buf); 169 apple_nvidia_bug_workaround = enable;
170 apple_nvidia_bug_buf = enable ? g_slice_alloc (TC_WIDTH * TC_HEIGHT) : 0;
171} 170}
172 171
173static void 172static void
174tex_update (int name, int x, int y, int w, int stride, int h, void *bm) 173tex_update (int name, int x, int y, int w, int stride, int h, void *bm)
175{ 174{
176 glBindTexture (GL_TEXTURE_2D, name); 175 glBindTexture (GL_TEXTURE_2D, name);
177 176
178 if (!apple_nvidia_bug_buf) 177 if (!apple_nvidia_bug_workaround)
179 { 178 {
180 glPixelStorei (GL_UNPACK_ROW_LENGTH, stride); 179 glPixelStorei (GL_UNPACK_ROW_LENGTH, stride);
181 glPixelStorei (GL_UNPACK_ALIGNMENT, 1); 180 /*glPixelStorei (GL_UNPACK_ALIGNMENT, 1); expected cfplus default */
182 glTexSubImage2D (GL_TEXTURE_2D, 0, x, y, w, h, GL_ALPHA, GL_UNSIGNED_BYTE, bm); 181 glTexSubImage2D (GL_TEXTURE_2D, 0, x, y, w, h, GL_ALPHA, GL_UNSIGNED_BYTE, bm);
182 /*glPixelStorei (GL_UNPACK_ALIGNMENT, 4);*/
183 glPixelStorei (GL_UNPACK_ROW_LENGTH, 0); 183 glPixelStorei (GL_UNPACK_ROW_LENGTH, 0);
184 glPixelStorei (GL_UNPACK_ALIGNMENT, 4);
185 } 184 }
186 else 185 else
187 { 186 {
188 /* starting with 10.5.5 (or 10.5.6), pple's nvidia driver corrupts textures */ 187 /* starting with 10.5.5 (or 10.5.6), pple's nvidia driver corrupts textures */
189 /* when glTexSubImage is used, so do it the horribly slow way, */ 188 /* when glTexSubImage is used, so do it the horribly slow way, */
190 /* reading/patching/uploading the full texture one each change */ 189 /* reading/patching/uploading the full texture one each change */
191 int r; 190 int r;
192 191
193 glGetTexImage (GL_TEXTURE_2D, 0, GL_ALPHA, GL_UNSIGNED_BYTE, apple_nvidia_bug_buf); 192 glGetTexImage (GL_TEXTURE_2D, 0, GL_ALPHA, GL_UNSIGNED_BYTE, tc_temptile);
194 193
195 for (r = 0; r < h; ++r) 194 for (r = 0; r < h; ++r)
196 memcpy ((char *)apple_nvidia_bug_buf + (y + r) * TC_WIDTH + x, (char *)bm + r * stride, w); 195 memcpy (tc_temptile + (y + r) * TC_WIDTH + x, (char *)bm + r * stride, w);
197 196
198 glTexImage2D (GL_TEXTURE_2D, 0, GL_ALPHA, TC_WIDTH, TC_HEIGHT, 0, GL_ALPHA, GL_UNSIGNED_BYTE, apple_nvidia_bug_buf); 197 glTexImage2D (GL_TEXTURE_2D, 0, GL_ALPHA, TC_WIDTH, TC_HEIGHT, 0, GL_ALPHA, GL_UNSIGNED_BYTE, tc_temptile);
199 } 198 }
200} 199}
201 200
202static void 201static void
203draw_glyph (PangoRenderer *renderer_, PangoFont *font, PangoGlyph glyph, double x, double y) 202draw_glyph (PangoRenderer *renderer_, PangoFont *font, PangoGlyph glyph, double x, double y)
211 210
212 if (glyph == PANGO_GLYPH_EMPTY) 211 if (glyph == PANGO_GLYPH_EMPTY)
213 glyph = PANGO_GLYPH_UNKNOWN_FLAG; 212 glyph = PANGO_GLYPH_UNKNOWN_FLAG;
214 } 213 }
215 214
216 g = _pango_opengl_font_get_cache_glyph_data (font, glyph); 215 g = (glyph_info *)_pango_opengl_font_get_cache_glyph_data (font, glyph);
217 216
218 if (!g || g->generation != tc_generation) 217 if (!g || g->generation != tc_generation)
219 { 218 {
220 Glyph bm; 219 Glyph bm;
221 font_render_glyph (&bm, font, glyph); 220 font_render_glyph (&bm, font, glyph);
243 y -= g->top; 242 y -= g->top;
244 243
245 if (g->tex.name != renderer->key.texname) 244 if (g->tex.name != renderer->key.texname)
246 { 245 {
247 renderer->key.texname = g->tex.name; 246 renderer->key.texname = g->tex.name;
248 renderer->arr = rc_array (renderer->rc, &renderer->key); 247 renderer->arr = &renderer->rc->array (renderer->key);
249 } 248 }
250 249
251 rc_glyph (renderer->arr, g->tex.x, g->tex.y, g->tex.w, g->tex.h, x, y); 250 renderer->arr->glyph (g->tex.x, g->tex.y, g->tex.w, g->tex.h, x, y);
252} 251}
253 252
254static void 253static void
255draw_trapezoid (PangoRenderer *renderer_, 254draw_trapezoid (PangoRenderer *renderer_,
256 PangoRenderPart part, 255 PangoRenderPart part,
261 double x12, 260 double x12,
262 double x22) 261 double x22)
263{ 262{
264 PangoOpenGLRenderer *renderer = (PangoOpenGLRenderer *)renderer_; 263 PangoOpenGLRenderer *renderer = (PangoOpenGLRenderer *)renderer_;
265 rc_key_t key = renderer->key; 264 rc_key_t key = renderer->key;
266 rc_array_t *arr;
267 265
268 key.mode = GL_QUADS; 266 key.mode = GL_QUADS;
269 key.format = GL_V2F; 267 key.format = GL_V2F;
270 key.texname = 0; 268 key.texname = 0;
271 269
272 arr = rc_array (renderer->rc, &key); 270 auto &arr = renderer->rc->array (key);
273 271
274 rc_v2f (arr, x11, y1); 272 arr.v2f (x11, y1);
275 rc_v2f (arr, x21, y1); 273 arr.v2f (x21, y1);
276 rc_v2f (arr, x22, y2); 274 arr.v2f (x22, y2);
277 rc_v2f (arr, x12, y2); 275 arr.v2f (x12, y2);
278} 276}
279 277
280void 278void
281pango_opengl_render_layout_subpixel (PangoLayout *layout, 279pango_opengl_render_layout_subpixel (PangoLayout *layout,
282 rc_t *rc, 280 rc_t *rc,
283 int x, int y, 281 int x, int y,
284 float r, float g, float b, float a, 282 float r, float g, float b, float a,
285 int flags) 283 int flags)
292 context = pango_layout_get_context (layout); 290 context = pango_layout_get_context (layout);
293 fontmap = pango_context_get_font_map (context); 291 fontmap = pango_context_get_font_map (context);
294 renderer = _pango_opengl_font_map_get_renderer (PANGO_OPENGL_FONT_MAP (fontmap)); 292 renderer = _pango_opengl_font_map_get_renderer (PANGO_OPENGL_FONT_MAP (fontmap));
295 gl = PANGO_OPENGL_RENDERER (renderer); 293 gl = PANGO_OPENGL_RENDERER (renderer);
296 294
297 gl->rc = rc; 295 gl->rc = rc;
298 gl->r = r; 296 gl->r = r;
299 gl->g = g; 297 gl->g = g;
300 gl->b = b; 298 gl->b = b;
301 gl->a = a; 299 gl->a = a;
302 gl->flags = flags; 300 gl->flags = flags;
303 301
304 pango_renderer_draw_layout (renderer, layout, x, y); 302 pango_renderer_draw_layout (renderer, layout, x, y);
305} 303}
306 304
307void 305void
308pango_opengl_render_layout (PangoLayout *layout, 306pango_opengl_render_layout (PangoLayout *layout,
309 rc_t *rc, 307 rc_t *rc,
310 int x, int y, 308 int x, int y,
311 float r, float g, float b, float a, 309 float r, float g, float b, float a,
312 int flags) 310 int flags)
342 gl->key.format = 0; // glyphs 340 gl->key.format = 0; // glyphs
343 gl->key.texname = 0; 341 gl->key.texname = 0;
344 342
345 for (l = run->item->analysis.extra_attrs; l; l = l->next) 343 for (l = run->item->analysis.extra_attrs; l; l = l->next)
346 { 344 {
347 PangoAttribute *attr = l->data; 345 PangoAttribute *attr = (PangoAttribute *)l->data;
348 346
349 switch (attr->klass->type) 347 switch (attr->klass->type)
350 { 348 {
351 case PANGO_ATTR_UNDERLINE: 349 case PANGO_ATTR_UNDERLINE:
352 renderer->underline = ((PangoAttrInt *)attr)->value; 350 renderer->underline = (PangoUnderline)((PangoAttrInt *)attr)->value;
353 break; 351 break;
354 352
355 case PANGO_ATTR_STRIKETHROUGH: 353 case PANGO_ATTR_STRIKETHROUGH:
356 renderer->strikethrough = ((PangoAttrInt *)attr)->value; 354 renderer->strikethrough = ((PangoAttrInt *)attr)->value;
357 break; 355 break;
369 { 367 {
370 r = fg->red * (255.f / 65535.f); 368 r = fg->red * (255.f / 65535.f);
371 g = fg->green * (255.f / 65535.f); 369 g = fg->green * (255.f / 65535.f);
372 b = fg->blue * (255.f / 65535.f); 370 b = fg->blue * (255.f / 65535.f);
373 } 371 }
374 else 372 else
375 { 373 {
376 r = gl->r * 255.f; 374 r = gl->r * 255.f;
377 g = gl->g * 255.f; 375 g = gl->g * 255.f;
378 b = gl->b * 255.f; 376 b = gl->b * 255.f;
379 } 377 }

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines