st/mesa: use new cso_save/restore_state() functions
[mesa.git] / src / mesa / state_tracker / st_cb_bitmap.c
1 /**************************************************************************
2 *
3 * Copyright 2007 VMware, Inc.
4 * All Rights Reserved.
5 *
6 * Permission is hereby granted, free of charge, to any person obtaining a
7 * copy of this software and associated documentation files (the
8 * "Software"), to deal in the Software without restriction, including
9 * without limitation the rights to use, copy, modify, merge, publish,
10 * distribute, sub license, and/or sell copies of the Software, and to
11 * permit persons to whom the Software is furnished to do so, subject to
12 * the following conditions:
13 *
14 * The above copyright notice and this permission notice (including the
15 * next paragraph) shall be included in all copies or substantial portions
16 * of the Software.
17 *
18 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
19 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
20 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT.
21 * IN NO EVENT SHALL VMWARE AND/OR ITS SUPPLIERS BE LIABLE FOR
22 * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
23 * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
24 * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
25 *
26 **************************************************************************/
27
28 /*
29 * Authors:
30 * Brian Paul
31 */
32
33 #include "main/imports.h"
34 #include "main/image.h"
35 #include "main/bufferobj.h"
36 #include "main/macros.h"
37 #include "main/pbo.h"
38 #include "program/program.h"
39 #include "program/prog_print.h"
40
41 #include "st_context.h"
42 #include "st_atom.h"
43 #include "st_atom_constbuf.h"
44 #include "st_draw.h"
45 #include "st_program.h"
46 #include "st_cb_bitmap.h"
47 #include "st_texture.h"
48
49 #include "pipe/p_context.h"
50 #include "pipe/p_defines.h"
51 #include "pipe/p_shader_tokens.h"
52 #include "util/u_inlines.h"
53 #include "util/u_simple_shaders.h"
54 #include "program/prog_instruction.h"
55 #include "cso_cache/cso_context.h"
56
57
58 /**
59 * glBitmaps are drawn as textured quads. The user's bitmap pattern
60 * is stored in a texture image. An alpha8 texture format is used.
61 * The fragment shader samples a bit (texel) from the texture, then
62 * discards the fragment if the bit is off.
63 *
64 * Note that we actually store the inverse image of the bitmap to
65 * simplify the fragment program. An "on" bit gets stored as texel=0x0
66 * and an "off" bit is stored as texel=0xff. Then we kill the
67 * fragment if the negated texel value is less than zero.
68 */
69
70
71 /**
72 * The bitmap cache attempts to accumulate multiple glBitmap calls in a
73 * buffer which is then rendered en mass upon a flush, state change, etc.
74 * A wide, short buffer is used to target the common case of a series
75 * of glBitmap calls being used to draw text.
76 */
77 static GLboolean UseBitmapCache = GL_TRUE;
78
79
80 #define BITMAP_CACHE_WIDTH 512
81 #define BITMAP_CACHE_HEIGHT 32
82
83 struct bitmap_cache
84 {
85 /** Window pos to render the cached image */
86 GLint xpos, ypos;
87 /** Bounds of region used in window coords */
88 GLint xmin, ymin, xmax, ymax;
89
90 GLfloat color[4];
91
92 /** Bitmap's Z position */
93 GLfloat zpos;
94
95 struct pipe_resource *texture;
96 struct pipe_transfer *trans;
97
98 GLboolean empty;
99
100 /** An I8 texture image: */
101 ubyte *buffer;
102 };
103
104
105 /** Epsilon for Z comparisons */
106 #define Z_EPSILON 1e-06
107
108
109 /**
110 * Copy user-provide bitmap bits into texture buffer, expanding
111 * bits into texels.
112 * "On" bits will set texels to 0x0.
113 * "Off" bits will not modify texels.
114 * Note that the image is actually going to be upside down in
115 * the texture. We deal with that with texcoords.
116 */
117 static void
118 unpack_bitmap(struct st_context *st,
119 GLint px, GLint py, GLsizei width, GLsizei height,
120 const struct gl_pixelstore_attrib *unpack,
121 const GLubyte *bitmap,
122 ubyte *destBuffer, uint destStride)
123 {
124 destBuffer += py * destStride + px;
125
126 _mesa_expand_bitmap(width, height, unpack, bitmap,
127 destBuffer, destStride, 0x0);
128 }
129
130
131 /**
132 * Create a texture which represents a bitmap image.
133 */
134 static struct pipe_resource *
135 make_bitmap_texture(struct gl_context *ctx, GLsizei width, GLsizei height,
136 const struct gl_pixelstore_attrib *unpack,
137 const GLubyte *bitmap)
138 {
139 struct st_context *st = st_context(ctx);
140 struct pipe_context *pipe = st->pipe;
141 struct pipe_transfer *transfer;
142 ubyte *dest;
143 struct pipe_resource *pt;
144
145 /* PBO source... */
146 bitmap = _mesa_map_pbo_source(ctx, unpack, bitmap);
147 if (!bitmap) {
148 return NULL;
149 }
150
151 /**
152 * Create texture to hold bitmap pattern.
153 */
154 pt = st_texture_create(st, st->internal_target, st->bitmap.tex_format,
155 0, width, height, 1, 1, 0,
156 PIPE_BIND_SAMPLER_VIEW);
157 if (!pt) {
158 _mesa_unmap_pbo_source(ctx, unpack);
159 return NULL;
160 }
161
162 dest = pipe_transfer_map(st->pipe, pt, 0, 0,
163 PIPE_TRANSFER_WRITE,
164 0, 0, width, height, &transfer);
165
166 /* Put image into texture transfer */
167 memset(dest, 0xff, height * transfer->stride);
168 unpack_bitmap(st, 0, 0, width, height, unpack, bitmap,
169 dest, transfer->stride);
170
171 _mesa_unmap_pbo_source(ctx, unpack);
172
173 /* Release transfer */
174 pipe_transfer_unmap(pipe, transfer);
175 return pt;
176 }
177
178
179 /**
180 * Setup pipeline state prior to rendering the bitmap textured quad.
181 */
182 static void
183 setup_render_state(struct gl_context *ctx,
184 struct pipe_sampler_view *sv,
185 const GLfloat *color)
186 {
187 struct st_context *st = st_context(ctx);
188 struct cso_context *cso = st->cso_context;
189 struct st_fp_variant *fpv;
190 struct st_fp_variant_key key;
191
192 memset(&key, 0, sizeof(key));
193 key.st = st->has_shareable_shaders ? NULL : st;
194 key.bitmap = GL_TRUE;
195 key.clamp_color = st->clamp_frag_color_in_shader &&
196 st->ctx->Color._ClampFragmentColor;
197
198 fpv = st_get_fp_variant(st, st->fp, &key);
199
200 /* As an optimization, Mesa's fragment programs will sometimes get the
201 * primary color from a statevar/constant rather than a varying variable.
202 * when that's the case, we need to ensure that we use the 'color'
203 * parameter and not the current attribute color (which may have changed
204 * through glRasterPos and state validation.
205 * So, we force the proper color here. Not elegant, but it works.
206 */
207 {
208 GLfloat colorSave[4];
209 COPY_4V(colorSave, ctx->Current.Attrib[VERT_ATTRIB_COLOR0]);
210 COPY_4V(ctx->Current.Attrib[VERT_ATTRIB_COLOR0], color);
211 st_upload_constants(st, st->fp->Base.Base.Parameters,
212 PIPE_SHADER_FRAGMENT);
213 COPY_4V(ctx->Current.Attrib[VERT_ATTRIB_COLOR0], colorSave);
214 }
215
216 cso_save_state(cso, (CSO_BIT_RASTERIZER |
217 CSO_BIT_FRAGMENT_SAMPLERS |
218 CSO_BIT_FRAGMENT_SAMPLER_VIEWS |
219 CSO_BIT_VIEWPORT |
220 CSO_BIT_FRAGMENT_SHADER |
221 CSO_BIT_STREAM_OUTPUTS |
222 CSO_BIT_TESSCTRL_SHADER |
223 CSO_BIT_TESSEVAL_SHADER |
224 CSO_BIT_GEOMETRY_SHADER |
225 CSO_BIT_VERTEX_ELEMENTS |
226 CSO_BIT_VERTEX_SHADER |
227 CSO_BIT_AUX_VERTEX_BUFFER_SLOT));
228
229 /* rasterizer state: just scissor */
230 st->bitmap.rasterizer.scissor = ctx->Scissor.EnableFlags & 1;
231 cso_set_rasterizer(cso, &st->bitmap.rasterizer);
232
233 /* fragment shader state: TEX lookup program */
234 cso_set_fragment_shader_handle(cso, fpv->driver_shader);
235
236 /* vertex shader state: position + texcoord pass-through */
237 cso_set_vertex_shader_handle(cso, st->bitmap.vs);
238
239 /* disable other shaders */
240 cso_set_tessctrl_shader_handle(cso, NULL);
241 cso_set_tesseval_shader_handle(cso, NULL);
242 cso_set_geometry_shader_handle(cso, NULL);
243
244 /* user samplers, plus our bitmap sampler */
245 {
246 struct pipe_sampler_state *samplers[PIPE_MAX_SAMPLERS];
247 uint num = MAX2(fpv->bitmap_sampler + 1,
248 st->state.num_samplers[PIPE_SHADER_FRAGMENT]);
249 uint i;
250 for (i = 0; i < st->state.num_samplers[PIPE_SHADER_FRAGMENT]; i++) {
251 samplers[i] = &st->state.samplers[PIPE_SHADER_FRAGMENT][i];
252 }
253 samplers[fpv->bitmap_sampler] = &st->bitmap.sampler;
254 cso_set_samplers(cso, PIPE_SHADER_FRAGMENT, num,
255 (const struct pipe_sampler_state **) samplers);
256 }
257
258 /* user textures, plus the bitmap texture */
259 {
260 struct pipe_sampler_view *sampler_views[PIPE_MAX_SAMPLERS];
261 uint num = MAX2(fpv->bitmap_sampler + 1,
262 st->state.num_sampler_views[PIPE_SHADER_FRAGMENT]);
263 memcpy(sampler_views, st->state.sampler_views[PIPE_SHADER_FRAGMENT],
264 sizeof(sampler_views));
265 sampler_views[fpv->bitmap_sampler] = sv;
266 cso_set_sampler_views(cso, PIPE_SHADER_FRAGMENT, num, sampler_views);
267 }
268
269 /* viewport state: viewport matching window dims */
270 cso_set_viewport_dims(cso, st->state.framebuffer.width,
271 st->state.framebuffer.height,
272 st->state.fb_orientation == Y_0_TOP);
273
274 cso_set_vertex_elements(cso, 3, st->util_velems);
275
276 cso_set_stream_outputs(st->cso_context, 0, NULL, NULL);
277 }
278
279
280 /**
281 * Restore pipeline state after rendering the bitmap textured quad.
282 */
283 static void
284 restore_render_state(struct gl_context *ctx)
285 {
286 struct st_context *st = st_context(ctx);
287 struct cso_context *cso = st->cso_context;
288
289 cso_restore_state(cso);
290 }
291
292
293 /**
294 * Render a glBitmap by drawing a textured quad
295 */
296 static void
297 draw_bitmap_quad(struct gl_context *ctx, GLint x, GLint y, GLfloat z,
298 GLsizei width, GLsizei height,
299 struct pipe_sampler_view *sv,
300 const GLfloat *color)
301 {
302 struct st_context *st = st_context(ctx);
303 struct pipe_context *pipe = st->pipe;
304 const float fb_width = (float) st->state.framebuffer.width;
305 const float fb_height = (float) st->state.framebuffer.height;
306 const float x0 = (float) x;
307 const float x1 = (float) (x + width);
308 const float y0 = (float) y;
309 const float y1 = (float) (y + height);
310 float sLeft = 0.0f, sRight = 1.0f;
311 float tTop = 0.0f, tBot = 1.0f - tTop;
312 const float clip_x0 = x0 / fb_width * 2.0f - 1.0f;
313 const float clip_y0 = y0 / fb_height * 2.0f - 1.0f;
314 const float clip_x1 = x1 / fb_width * 2.0f - 1.0f;
315 const float clip_y1 = y1 / fb_height * 2.0f - 1.0f;
316
317 /* limit checks */
318 {
319 /* XXX if the bitmap is larger than the max texture size, break
320 * it up into chunks.
321 */
322 GLuint maxSize = 1 << (pipe->screen->get_param(pipe->screen,
323 PIPE_CAP_MAX_TEXTURE_2D_LEVELS) - 1);
324 assert(width <= (GLsizei) maxSize);
325 assert(height <= (GLsizei) maxSize);
326 }
327
328 setup_render_state(ctx, sv, color);
329
330 /* convert Z from [0,1] to [-1,-1] to match viewport Z scale/bias */
331 z = z * 2.0f - 1.0f;
332
333 if (sv->texture->target == PIPE_TEXTURE_RECT) {
334 /* use non-normalized texcoords */
335 sRight = (float) width;
336 tBot = (float) height;
337 }
338
339 if (!st_draw_quad(st, clip_x0, clip_y0, clip_x1, clip_y1, z,
340 sLeft, tBot, sRight, tTop, color, 0)) {
341 _mesa_error(ctx, GL_OUT_OF_MEMORY, "glBitmap");
342 }
343
344 restore_render_state(ctx);
345
346 /* We uploaded modified constants, need to invalidate them. */
347 st->dirty.mesa |= _NEW_PROGRAM_CONSTANTS;
348 }
349
350
351 static void
352 reset_cache(struct st_context *st)
353 {
354 struct bitmap_cache *cache = st->bitmap.cache;
355
356 /*memset(cache->buffer, 0xff, sizeof(cache->buffer));*/
357 cache->empty = GL_TRUE;
358
359 cache->xmin = 1000000;
360 cache->xmax = -1000000;
361 cache->ymin = 1000000;
362 cache->ymax = -1000000;
363
364 assert(!cache->texture);
365
366 /* allocate a new texture */
367 cache->texture = st_texture_create(st, st->internal_target,
368 st->bitmap.tex_format, 0,
369 BITMAP_CACHE_WIDTH, BITMAP_CACHE_HEIGHT,
370 1, 1, 0,
371 PIPE_BIND_SAMPLER_VIEW);
372 }
373
374
375 /** Print bitmap image to stdout (debug) */
376 static void
377 print_cache(const struct bitmap_cache *cache)
378 {
379 int i, j, k;
380
381 for (i = 0; i < BITMAP_CACHE_HEIGHT; i++) {
382 k = BITMAP_CACHE_WIDTH * (BITMAP_CACHE_HEIGHT - i - 1);
383 for (j = 0; j < BITMAP_CACHE_WIDTH; j++) {
384 if (cache->buffer[k])
385 printf("X");
386 else
387 printf(" ");
388 k++;
389 }
390 printf("\n");
391 }
392 }
393
394
395 /**
396 * Create gallium pipe_transfer object for the bitmap cache.
397 */
398 static void
399 create_cache_trans(struct st_context *st)
400 {
401 struct pipe_context *pipe = st->pipe;
402 struct bitmap_cache *cache = st->bitmap.cache;
403
404 if (cache->trans)
405 return;
406
407 /* Map the texture transfer.
408 * Subsequent glBitmap calls will write into the texture image.
409 */
410 cache->buffer = pipe_transfer_map(pipe, cache->texture, 0, 0,
411 PIPE_TRANSFER_WRITE, 0, 0,
412 BITMAP_CACHE_WIDTH,
413 BITMAP_CACHE_HEIGHT, &cache->trans);
414
415 /* init image to all 0xff */
416 memset(cache->buffer, 0xff, cache->trans->stride * BITMAP_CACHE_HEIGHT);
417 }
418
419
420 /**
421 * If there's anything in the bitmap cache, draw/flush it now.
422 */
423 void
424 st_flush_bitmap_cache(struct st_context *st)
425 {
426 struct bitmap_cache *cache = st->bitmap.cache;
427
428 if (cache && !cache->empty) {
429 struct pipe_context *pipe = st->pipe;
430 struct pipe_sampler_view *sv;
431
432 assert(cache->xmin <= cache->xmax);
433
434 if (0)
435 printf("flush bitmap, size %d x %d at %d, %d\n",
436 cache->xmax - cache->xmin,
437 cache->ymax - cache->ymin,
438 cache->xpos, cache->ypos);
439
440 /* The texture transfer has been mapped until now.
441 * So unmap and release the texture transfer before drawing.
442 */
443 if (cache->trans && cache->buffer) {
444 if (0)
445 print_cache(cache);
446 pipe_transfer_unmap(pipe, cache->trans);
447 cache->buffer = NULL;
448 cache->trans = NULL;
449 }
450
451 sv = st_create_texture_sampler_view(st->pipe, cache->texture);
452 if (sv) {
453 draw_bitmap_quad(st->ctx,
454 cache->xpos,
455 cache->ypos,
456 cache->zpos,
457 BITMAP_CACHE_WIDTH, BITMAP_CACHE_HEIGHT,
458 sv,
459 cache->color);
460
461 pipe_sampler_view_reference(&sv, NULL);
462 }
463
464 /* release/free the texture */
465 pipe_resource_reference(&cache->texture, NULL);
466
467 reset_cache(st);
468 }
469 }
470
471
472 /**
473 * Try to accumulate this glBitmap call in the bitmap cache.
474 * \return GL_TRUE for success, GL_FALSE if bitmap is too large, etc.
475 */
476 static GLboolean
477 accum_bitmap(struct gl_context *ctx,
478 GLint x, GLint y, GLsizei width, GLsizei height,
479 const struct gl_pixelstore_attrib *unpack,
480 const GLubyte *bitmap )
481 {
482 struct st_context *st = ctx->st;
483 struct bitmap_cache *cache = st->bitmap.cache;
484 int px = -999, py = -999;
485 const GLfloat z = st->ctx->Current.RasterPos[2];
486
487 if (width > BITMAP_CACHE_WIDTH ||
488 height > BITMAP_CACHE_HEIGHT)
489 return GL_FALSE; /* too big to cache */
490
491 if (!cache->empty) {
492 px = x - cache->xpos; /* pos in buffer */
493 py = y - cache->ypos;
494 if (px < 0 || px + width > BITMAP_CACHE_WIDTH ||
495 py < 0 || py + height > BITMAP_CACHE_HEIGHT ||
496 !TEST_EQ_4V(st->ctx->Current.RasterColor, cache->color) ||
497 ((fabs(z - cache->zpos) > Z_EPSILON))) {
498 /* This bitmap would extend beyond cache bounds, or the bitmap
499 * color is changing
500 * so flush and continue.
501 */
502 st_flush_bitmap_cache(st);
503 }
504 }
505
506 if (cache->empty) {
507 /* Initialize. Center bitmap vertically in the buffer. */
508 px = 0;
509 py = (BITMAP_CACHE_HEIGHT - height) / 2;
510 cache->xpos = x;
511 cache->ypos = y - py;
512 cache->zpos = z;
513 cache->empty = GL_FALSE;
514 COPY_4FV(cache->color, st->ctx->Current.RasterColor);
515 }
516
517 assert(px != -999);
518 assert(py != -999);
519
520 if (x < cache->xmin)
521 cache->xmin = x;
522 if (y < cache->ymin)
523 cache->ymin = y;
524 if (x + width > cache->xmax)
525 cache->xmax = x + width;
526 if (y + height > cache->ymax)
527 cache->ymax = y + height;
528
529 /* create the transfer if needed */
530 create_cache_trans(st);
531
532 /* PBO source... */
533 bitmap = _mesa_map_pbo_source(ctx, unpack, bitmap);
534 if (!bitmap) {
535 return FALSE;
536 }
537
538 unpack_bitmap(st, px, py, width, height, unpack, bitmap,
539 cache->buffer, BITMAP_CACHE_WIDTH);
540
541 _mesa_unmap_pbo_source(ctx, unpack);
542
543 return GL_TRUE; /* accumulated */
544 }
545
546
547 /**
548 * One-time init for drawing bitmaps.
549 */
550 static void
551 init_bitmap_state(struct st_context *st)
552 {
553 struct pipe_context *pipe = st->pipe;
554 struct pipe_screen *screen = pipe->screen;
555
556 /* This function should only be called once */
557 assert(st->bitmap.cache == NULL);
558
559 assert(st->internal_target == PIPE_TEXTURE_2D ||
560 st->internal_target == PIPE_TEXTURE_RECT);
561
562 /* alloc bitmap cache object */
563 st->bitmap.cache = ST_CALLOC_STRUCT(bitmap_cache);
564
565 /* init sampler state once */
566 memset(&st->bitmap.sampler, 0, sizeof(st->bitmap.sampler));
567 st->bitmap.sampler.wrap_s = PIPE_TEX_WRAP_CLAMP;
568 st->bitmap.sampler.wrap_t = PIPE_TEX_WRAP_CLAMP;
569 st->bitmap.sampler.wrap_r = PIPE_TEX_WRAP_CLAMP;
570 st->bitmap.sampler.min_img_filter = PIPE_TEX_FILTER_NEAREST;
571 st->bitmap.sampler.min_mip_filter = PIPE_TEX_MIPFILTER_NONE;
572 st->bitmap.sampler.mag_img_filter = PIPE_TEX_FILTER_NEAREST;
573 st->bitmap.sampler.normalized_coords = st->internal_target == PIPE_TEXTURE_2D;
574
575 /* init baseline rasterizer state once */
576 memset(&st->bitmap.rasterizer, 0, sizeof(st->bitmap.rasterizer));
577 st->bitmap.rasterizer.half_pixel_center = 1;
578 st->bitmap.rasterizer.bottom_edge_rule = 1;
579 st->bitmap.rasterizer.depth_clip = 1;
580
581 /* find a usable texture format */
582 if (screen->is_format_supported(screen, PIPE_FORMAT_I8_UNORM,
583 st->internal_target, 0,
584 PIPE_BIND_SAMPLER_VIEW)) {
585 st->bitmap.tex_format = PIPE_FORMAT_I8_UNORM;
586 }
587 else if (screen->is_format_supported(screen, PIPE_FORMAT_A8_UNORM,
588 st->internal_target, 0,
589 PIPE_BIND_SAMPLER_VIEW)) {
590 st->bitmap.tex_format = PIPE_FORMAT_A8_UNORM;
591 }
592 else if (screen->is_format_supported(screen, PIPE_FORMAT_L8_UNORM,
593 st->internal_target, 0,
594 PIPE_BIND_SAMPLER_VIEW)) {
595 st->bitmap.tex_format = PIPE_FORMAT_L8_UNORM;
596 }
597 else {
598 /* XXX support more formats */
599 assert(0);
600 }
601
602 /* Create the vertex shader */
603 {
604 const uint semantic_names[] = { TGSI_SEMANTIC_POSITION,
605 TGSI_SEMANTIC_COLOR,
606 st->needs_texcoord_semantic ? TGSI_SEMANTIC_TEXCOORD :
607 TGSI_SEMANTIC_GENERIC };
608 const uint semantic_indexes[] = { 0, 0, 0 };
609 st->bitmap.vs = util_make_vertex_passthrough_shader(st->pipe, 3,
610 semantic_names,
611 semantic_indexes,
612 FALSE);
613 }
614
615 reset_cache(st);
616 }
617
618
619 /**
620 * Called via ctx->Driver.Bitmap()
621 */
622 static void
623 st_Bitmap(struct gl_context *ctx, GLint x, GLint y,
624 GLsizei width, GLsizei height,
625 const struct gl_pixelstore_attrib *unpack, const GLubyte *bitmap )
626 {
627 struct st_context *st = st_context(ctx);
628 struct pipe_resource *pt;
629
630 assert(width > 0);
631 assert(height > 0);
632
633 if (!st->bitmap.cache) {
634 init_bitmap_state(st);
635 }
636
637 /* We only need to validate state of the st dirty flags are set or
638 * any non-_NEW_PROGRAM_CONSTANTS mesa flags are set. The VS we use
639 * for bitmap drawing uses no constants and the FS constants are
640 * explicitly uploaded in the draw_bitmap_quad() function.
641 */
642 if ((st->dirty.mesa & ~_NEW_PROGRAM_CONSTANTS) || st->dirty.st) {
643 st_validate_state(st, ST_PIPELINE_RENDER);
644 }
645
646 if (UseBitmapCache && accum_bitmap(ctx, x, y, width, height, unpack, bitmap))
647 return;
648
649 pt = make_bitmap_texture(ctx, width, height, unpack, bitmap);
650 if (pt) {
651 struct pipe_sampler_view *sv =
652 st_create_texture_sampler_view(st->pipe, pt);
653
654 assert(pt->target == PIPE_TEXTURE_2D || pt->target == PIPE_TEXTURE_RECT);
655
656 if (sv) {
657 draw_bitmap_quad(ctx, x, y, ctx->Current.RasterPos[2],
658 width, height, sv,
659 st->ctx->Current.RasterColor);
660
661 pipe_sampler_view_reference(&sv, NULL);
662 }
663
664 /* release/free the texture */
665 pipe_resource_reference(&pt, NULL);
666 }
667 }
668
669
670 /** Per-context init */
671 void
672 st_init_bitmap_functions(struct dd_function_table *functions)
673 {
674 functions->Bitmap = st_Bitmap;
675 }
676
677
678 /** Per-context tear-down */
679 void
680 st_destroy_bitmap(struct st_context *st)
681 {
682 struct pipe_context *pipe = st->pipe;
683 struct bitmap_cache *cache = st->bitmap.cache;
684
685 if (st->bitmap.vs) {
686 cso_delete_vertex_shader(st->cso_context, st->bitmap.vs);
687 st->bitmap.vs = NULL;
688 }
689
690 if (cache) {
691 if (cache->trans && cache->buffer) {
692 pipe_transfer_unmap(pipe, cache->trans);
693 }
694 pipe_resource_reference(&st->bitmap.cache->texture, NULL);
695 free(st->bitmap.cache);
696 st->bitmap.cache = NULL;
697 }
698 }