9c44458d1413a73694c877bfb089ed23c6b0ea11
[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 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_STREAM_OUTPUTS |
221 CSO_BIT_VERTEX_ELEMENTS |
222 CSO_BIT_AUX_VERTEX_BUFFER_SLOT |
223 CSO_BITS_ALL_SHADERS));
224
225
226 /* rasterizer state: just scissor */
227 st->bitmap.rasterizer.scissor = ctx->Scissor.EnableFlags & 1;
228 cso_set_rasterizer(cso, &st->bitmap.rasterizer);
229
230 /* fragment shader state: TEX lookup program */
231 cso_set_fragment_shader_handle(cso, fpv->driver_shader);
232
233 /* vertex shader state: position + texcoord pass-through */
234 cso_set_vertex_shader_handle(cso, st->bitmap.vs);
235
236 /* disable other shaders */
237 cso_set_tessctrl_shader_handle(cso, NULL);
238 cso_set_tesseval_shader_handle(cso, NULL);
239 cso_set_geometry_shader_handle(cso, NULL);
240
241 /* user samplers, plus our bitmap sampler */
242 {
243 struct pipe_sampler_state *samplers[PIPE_MAX_SAMPLERS];
244 uint num = MAX2(fpv->bitmap_sampler + 1,
245 st->state.num_samplers[PIPE_SHADER_FRAGMENT]);
246 uint i;
247 for (i = 0; i < st->state.num_samplers[PIPE_SHADER_FRAGMENT]; i++) {
248 samplers[i] = &st->state.samplers[PIPE_SHADER_FRAGMENT][i];
249 }
250 samplers[fpv->bitmap_sampler] = &st->bitmap.sampler;
251 cso_set_samplers(cso, PIPE_SHADER_FRAGMENT, num,
252 (const struct pipe_sampler_state **) samplers);
253 }
254
255 /* user textures, plus the bitmap texture */
256 {
257 struct pipe_sampler_view *sampler_views[PIPE_MAX_SAMPLERS];
258 uint num = MAX2(fpv->bitmap_sampler + 1,
259 st->state.num_sampler_views[PIPE_SHADER_FRAGMENT]);
260 memcpy(sampler_views, st->state.sampler_views[PIPE_SHADER_FRAGMENT],
261 sizeof(sampler_views));
262 sampler_views[fpv->bitmap_sampler] = sv;
263 cso_set_sampler_views(cso, PIPE_SHADER_FRAGMENT, num, sampler_views);
264 }
265
266 /* viewport state: viewport matching window dims */
267 cso_set_viewport_dims(cso, st->state.framebuffer.width,
268 st->state.framebuffer.height,
269 st->state.fb_orientation == Y_0_TOP);
270
271 cso_set_vertex_elements(cso, 3, st->util_velems);
272
273 cso_set_stream_outputs(st->cso_context, 0, NULL, NULL);
274 }
275
276
277 /**
278 * Restore pipeline state after rendering the bitmap textured quad.
279 */
280 static void
281 restore_render_state(struct gl_context *ctx)
282 {
283 struct st_context *st = st_context(ctx);
284 struct cso_context *cso = st->cso_context;
285
286 cso_restore_state(cso);
287 }
288
289
290 /**
291 * Render a glBitmap by drawing a textured quad
292 */
293 static void
294 draw_bitmap_quad(struct gl_context *ctx, GLint x, GLint y, GLfloat z,
295 GLsizei width, GLsizei height,
296 struct pipe_sampler_view *sv,
297 const GLfloat *color)
298 {
299 struct st_context *st = st_context(ctx);
300 struct pipe_context *pipe = st->pipe;
301 const float fb_width = (float) st->state.framebuffer.width;
302 const float fb_height = (float) st->state.framebuffer.height;
303 const float x0 = (float) x;
304 const float x1 = (float) (x + width);
305 const float y0 = (float) y;
306 const float y1 = (float) (y + height);
307 float sLeft = 0.0f, sRight = 1.0f;
308 float tTop = 0.0f, tBot = 1.0f - tTop;
309 const float clip_x0 = x0 / fb_width * 2.0f - 1.0f;
310 const float clip_y0 = y0 / fb_height * 2.0f - 1.0f;
311 const float clip_x1 = x1 / fb_width * 2.0f - 1.0f;
312 const float clip_y1 = y1 / fb_height * 2.0f - 1.0f;
313
314 /* limit checks */
315 {
316 /* XXX if the bitmap is larger than the max texture size, break
317 * it up into chunks.
318 */
319 GLuint maxSize = 1 << (pipe->screen->get_param(pipe->screen,
320 PIPE_CAP_MAX_TEXTURE_2D_LEVELS) - 1);
321 assert(width <= (GLsizei) maxSize);
322 assert(height <= (GLsizei) maxSize);
323 }
324
325 setup_render_state(ctx, sv, color);
326
327 /* convert Z from [0,1] to [-1,-1] to match viewport Z scale/bias */
328 z = z * 2.0f - 1.0f;
329
330 if (sv->texture->target == PIPE_TEXTURE_RECT) {
331 /* use non-normalized texcoords */
332 sRight = (float) width;
333 tBot = (float) height;
334 }
335
336 if (!st_draw_quad(st, clip_x0, clip_y0, clip_x1, clip_y1, z,
337 sLeft, tBot, sRight, tTop, color, 0)) {
338 _mesa_error(ctx, GL_OUT_OF_MEMORY, "glBitmap");
339 }
340
341 restore_render_state(ctx);
342
343 /* We uploaded modified constants, need to invalidate them. */
344 st->dirty.mesa |= _NEW_PROGRAM_CONSTANTS;
345 }
346
347
348 static void
349 reset_cache(struct st_context *st)
350 {
351 struct bitmap_cache *cache = st->bitmap.cache;
352
353 /*memset(cache->buffer, 0xff, sizeof(cache->buffer));*/
354 cache->empty = GL_TRUE;
355
356 cache->xmin = 1000000;
357 cache->xmax = -1000000;
358 cache->ymin = 1000000;
359 cache->ymax = -1000000;
360
361 assert(!cache->texture);
362
363 /* allocate a new texture */
364 cache->texture = st_texture_create(st, st->internal_target,
365 st->bitmap.tex_format, 0,
366 BITMAP_CACHE_WIDTH, BITMAP_CACHE_HEIGHT,
367 1, 1, 0,
368 PIPE_BIND_SAMPLER_VIEW);
369 }
370
371
372 /** Print bitmap image to stdout (debug) */
373 static void
374 print_cache(const struct bitmap_cache *cache)
375 {
376 int i, j, k;
377
378 for (i = 0; i < BITMAP_CACHE_HEIGHT; i++) {
379 k = BITMAP_CACHE_WIDTH * (BITMAP_CACHE_HEIGHT - i - 1);
380 for (j = 0; j < BITMAP_CACHE_WIDTH; j++) {
381 if (cache->buffer[k])
382 printf("X");
383 else
384 printf(" ");
385 k++;
386 }
387 printf("\n");
388 }
389 }
390
391
392 /**
393 * Create gallium pipe_transfer object for the bitmap cache.
394 */
395 static void
396 create_cache_trans(struct st_context *st)
397 {
398 struct pipe_context *pipe = st->pipe;
399 struct bitmap_cache *cache = st->bitmap.cache;
400
401 if (cache->trans)
402 return;
403
404 /* Map the texture transfer.
405 * Subsequent glBitmap calls will write into the texture image.
406 */
407 cache->buffer = pipe_transfer_map(pipe, cache->texture, 0, 0,
408 PIPE_TRANSFER_WRITE, 0, 0,
409 BITMAP_CACHE_WIDTH,
410 BITMAP_CACHE_HEIGHT, &cache->trans);
411
412 /* init image to all 0xff */
413 memset(cache->buffer, 0xff, cache->trans->stride * BITMAP_CACHE_HEIGHT);
414 }
415
416
417 /**
418 * If there's anything in the bitmap cache, draw/flush it now.
419 */
420 void
421 st_flush_bitmap_cache(struct st_context *st)
422 {
423 struct bitmap_cache *cache = st->bitmap.cache;
424
425 if (cache && !cache->empty) {
426 struct pipe_context *pipe = st->pipe;
427 struct pipe_sampler_view *sv;
428
429 assert(cache->xmin <= cache->xmax);
430
431 if (0)
432 printf("flush bitmap, size %d x %d at %d, %d\n",
433 cache->xmax - cache->xmin,
434 cache->ymax - cache->ymin,
435 cache->xpos, cache->ypos);
436
437 /* The texture transfer has been mapped until now.
438 * So unmap and release the texture transfer before drawing.
439 */
440 if (cache->trans && cache->buffer) {
441 if (0)
442 print_cache(cache);
443 pipe_transfer_unmap(pipe, cache->trans);
444 cache->buffer = NULL;
445 cache->trans = NULL;
446 }
447
448 sv = st_create_texture_sampler_view(st->pipe, cache->texture);
449 if (sv) {
450 draw_bitmap_quad(st->ctx,
451 cache->xpos,
452 cache->ypos,
453 cache->zpos,
454 BITMAP_CACHE_WIDTH, BITMAP_CACHE_HEIGHT,
455 sv,
456 cache->color);
457
458 pipe_sampler_view_reference(&sv, NULL);
459 }
460
461 /* release/free the texture */
462 pipe_resource_reference(&cache->texture, NULL);
463
464 reset_cache(st);
465 }
466 }
467
468
469 /**
470 * Try to accumulate this glBitmap call in the bitmap cache.
471 * \return GL_TRUE for success, GL_FALSE if bitmap is too large, etc.
472 */
473 static GLboolean
474 accum_bitmap(struct gl_context *ctx,
475 GLint x, GLint y, GLsizei width, GLsizei height,
476 const struct gl_pixelstore_attrib *unpack,
477 const GLubyte *bitmap )
478 {
479 struct st_context *st = ctx->st;
480 struct bitmap_cache *cache = st->bitmap.cache;
481 int px = -999, py = -999;
482 const GLfloat z = ctx->Current.RasterPos[2];
483
484 if (width > BITMAP_CACHE_WIDTH ||
485 height > BITMAP_CACHE_HEIGHT)
486 return GL_FALSE; /* too big to cache */
487
488 if (!cache->empty) {
489 px = x - cache->xpos; /* pos in buffer */
490 py = y - cache->ypos;
491 if (px < 0 || px + width > BITMAP_CACHE_WIDTH ||
492 py < 0 || py + height > BITMAP_CACHE_HEIGHT ||
493 !TEST_EQ_4V(ctx->Current.RasterColor, cache->color) ||
494 ((fabs(z - cache->zpos) > Z_EPSILON))) {
495 /* This bitmap would extend beyond cache bounds, or the bitmap
496 * color is changing
497 * so flush and continue.
498 */
499 st_flush_bitmap_cache(st);
500 }
501 }
502
503 if (cache->empty) {
504 /* Initialize. Center bitmap vertically in the buffer. */
505 px = 0;
506 py = (BITMAP_CACHE_HEIGHT - height) / 2;
507 cache->xpos = x;
508 cache->ypos = y - py;
509 cache->zpos = z;
510 cache->empty = GL_FALSE;
511 COPY_4FV(cache->color, ctx->Current.RasterColor);
512 }
513
514 assert(px != -999);
515 assert(py != -999);
516
517 if (x < cache->xmin)
518 cache->xmin = x;
519 if (y < cache->ymin)
520 cache->ymin = y;
521 if (x + width > cache->xmax)
522 cache->xmax = x + width;
523 if (y + height > cache->ymax)
524 cache->ymax = y + height;
525
526 /* create the transfer if needed */
527 create_cache_trans(st);
528
529 /* PBO source... */
530 bitmap = _mesa_map_pbo_source(ctx, unpack, bitmap);
531 if (!bitmap) {
532 return FALSE;
533 }
534
535 unpack_bitmap(st, px, py, width, height, unpack, bitmap,
536 cache->buffer, BITMAP_CACHE_WIDTH);
537
538 _mesa_unmap_pbo_source(ctx, unpack);
539
540 return GL_TRUE; /* accumulated */
541 }
542
543
544 /**
545 * One-time init for drawing bitmaps.
546 */
547 static void
548 init_bitmap_state(struct st_context *st)
549 {
550 struct pipe_context *pipe = st->pipe;
551 struct pipe_screen *screen = pipe->screen;
552
553 /* This function should only be called once */
554 assert(st->bitmap.cache == NULL);
555
556 assert(st->internal_target == PIPE_TEXTURE_2D ||
557 st->internal_target == PIPE_TEXTURE_RECT);
558
559 /* alloc bitmap cache object */
560 st->bitmap.cache = ST_CALLOC_STRUCT(bitmap_cache);
561
562 /* init sampler state once */
563 memset(&st->bitmap.sampler, 0, sizeof(st->bitmap.sampler));
564 st->bitmap.sampler.wrap_s = PIPE_TEX_WRAP_CLAMP;
565 st->bitmap.sampler.wrap_t = PIPE_TEX_WRAP_CLAMP;
566 st->bitmap.sampler.wrap_r = PIPE_TEX_WRAP_CLAMP;
567 st->bitmap.sampler.min_img_filter = PIPE_TEX_FILTER_NEAREST;
568 st->bitmap.sampler.min_mip_filter = PIPE_TEX_MIPFILTER_NONE;
569 st->bitmap.sampler.mag_img_filter = PIPE_TEX_FILTER_NEAREST;
570 st->bitmap.sampler.normalized_coords = st->internal_target == PIPE_TEXTURE_2D;
571
572 /* init baseline rasterizer state once */
573 memset(&st->bitmap.rasterizer, 0, sizeof(st->bitmap.rasterizer));
574 st->bitmap.rasterizer.half_pixel_center = 1;
575 st->bitmap.rasterizer.bottom_edge_rule = 1;
576 st->bitmap.rasterizer.depth_clip = 1;
577
578 /* find a usable texture format */
579 if (screen->is_format_supported(screen, PIPE_FORMAT_I8_UNORM,
580 st->internal_target, 0,
581 PIPE_BIND_SAMPLER_VIEW)) {
582 st->bitmap.tex_format = PIPE_FORMAT_I8_UNORM;
583 }
584 else if (screen->is_format_supported(screen, PIPE_FORMAT_A8_UNORM,
585 st->internal_target, 0,
586 PIPE_BIND_SAMPLER_VIEW)) {
587 st->bitmap.tex_format = PIPE_FORMAT_A8_UNORM;
588 }
589 else if (screen->is_format_supported(screen, PIPE_FORMAT_L8_UNORM,
590 st->internal_target, 0,
591 PIPE_BIND_SAMPLER_VIEW)) {
592 st->bitmap.tex_format = PIPE_FORMAT_L8_UNORM;
593 }
594 else {
595 /* XXX support more formats */
596 assert(0);
597 }
598
599 /* Create the vertex shader */
600 {
601 const uint semantic_names[] = { TGSI_SEMANTIC_POSITION,
602 TGSI_SEMANTIC_COLOR,
603 st->needs_texcoord_semantic ? TGSI_SEMANTIC_TEXCOORD :
604 TGSI_SEMANTIC_GENERIC };
605 const uint semantic_indexes[] = { 0, 0, 0 };
606 st->bitmap.vs = util_make_vertex_passthrough_shader(st->pipe, 3,
607 semantic_names,
608 semantic_indexes,
609 FALSE);
610 }
611
612 reset_cache(st);
613 }
614
615
616 /**
617 * Called via ctx->Driver.Bitmap()
618 */
619 static void
620 st_Bitmap(struct gl_context *ctx, GLint x, GLint y,
621 GLsizei width, GLsizei height,
622 const struct gl_pixelstore_attrib *unpack, const GLubyte *bitmap )
623 {
624 struct st_context *st = st_context(ctx);
625 struct pipe_resource *pt;
626
627 assert(width > 0);
628 assert(height > 0);
629
630 if (!st->bitmap.cache) {
631 init_bitmap_state(st);
632 }
633
634 /* We only need to validate state of the st dirty flags are set or
635 * any non-_NEW_PROGRAM_CONSTANTS mesa flags are set. The VS we use
636 * for bitmap drawing uses no constants and the FS constants are
637 * explicitly uploaded in the draw_bitmap_quad() function.
638 */
639 if ((st->dirty.mesa & ~_NEW_PROGRAM_CONSTANTS) || st->dirty.st) {
640 st_validate_state(st, ST_PIPELINE_RENDER);
641 }
642
643 if (UseBitmapCache && accum_bitmap(ctx, x, y, width, height, unpack, bitmap))
644 return;
645
646 pt = make_bitmap_texture(ctx, width, height, unpack, bitmap);
647 if (pt) {
648 struct pipe_sampler_view *sv =
649 st_create_texture_sampler_view(st->pipe, pt);
650
651 assert(pt->target == PIPE_TEXTURE_2D || pt->target == PIPE_TEXTURE_RECT);
652
653 if (sv) {
654 draw_bitmap_quad(ctx, x, y, ctx->Current.RasterPos[2],
655 width, height, sv, ctx->Current.RasterColor);
656
657 pipe_sampler_view_reference(&sv, NULL);
658 }
659
660 /* release/free the texture */
661 pipe_resource_reference(&pt, NULL);
662 }
663 }
664
665
666 /** Per-context init */
667 void
668 st_init_bitmap_functions(struct dd_function_table *functions)
669 {
670 functions->Bitmap = st_Bitmap;
671 }
672
673
674 /** Per-context tear-down */
675 void
676 st_destroy_bitmap(struct st_context *st)
677 {
678 struct pipe_context *pipe = st->pipe;
679 struct bitmap_cache *cache = st->bitmap.cache;
680
681 if (st->bitmap.vs) {
682 cso_delete_vertex_shader(st->cso_context, st->bitmap.vs);
683 st->bitmap.vs = NULL;
684 }
685
686 if (cache) {
687 if (cache->trans && cache->buffer) {
688 pipe_transfer_unmap(pipe, cache->trans);
689 }
690 pipe_resource_reference(&st->bitmap.cache->texture, NULL);
691 free(st->bitmap.cache);
692 st->bitmap.cache = NULL;
693 }
694 }