2 * Copyright 2008, 2010 George Sapountzis <gsapountzis@gmail.com>
4 * Permission is hereby granted, free of charge, to any person obtaining a
5 * copy of this software and associated documentation files (the "Software"),
6 * to deal in the Software without restriction, including without limitation
7 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
8 * and/or sell copies of the Software, and to permit persons to whom the
9 * Software is furnished to do so, subject to the following conditions:
11 * The above copyright notice and this permission notice shall be included
12 * in all copies or substantial portions of the Software.
14 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
15 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
17 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR
18 * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
19 * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
20 * OTHER DEALINGS IN THE SOFTWARE.
24 * DRI software rasterizer
26 * This is the mesa swrast module packaged into a DRI driver structure.
28 * The front-buffer is allocated by the loader. The loader provides read/write
29 * callbacks for access to the front-buffer. The driver uses a scratch row for
30 * front-buffer rendering to avoid repeated calls to the loader.
32 * The back-buffer is allocated by the driver and is private.
35 #include "main/api_exec.h"
36 #include "main/context.h"
37 #include "main/extensions.h"
38 #include "main/formats.h"
39 #include "main/framebuffer.h"
40 #include "main/imports.h"
41 #include "main/renderbuffer.h"
42 #include "main/version.h"
43 #include "main/vtxfmt.h"
44 #include "swrast/swrast.h"
45 #include "swrast/s_renderbuffer.h"
46 #include "swrast_setup/swrast_setup.h"
48 #include "tnl/t_context.h"
49 #include "tnl/t_pipeline.h"
51 #include "drivers/common/driverfuncs.h"
52 #include "drivers/common/meta.h"
55 #include "main/teximage.h"
56 #include "main/texformat.h"
57 #include "main/texstate.h"
59 #include "swrast_priv.h"
60 #include "swrast/s_context.h"
62 const __DRIextension
**__driDriverGetExtensions_swrast(void);
64 const char const *swrast_vendor_string
= "Mesa Project";
65 const char const *swrast_renderer_string
= "Software Rasterizer";
68 * Screen and config-related functions
71 static void swrastSetTexBuffer2(__DRIcontext
*pDRICtx
, GLint target
,
72 GLint texture_format
, __DRIdrawable
*dPriv
)
74 struct dri_context
*dri_ctx
;
76 __DRIscreen
*sPriv
= dPriv
->driScreenPriv
;
77 struct gl_texture_object
*texObj
;
78 struct gl_texture_image
*texImage
;
79 struct swrast_texture_image
*swImage
;
80 uint32_t internalFormat
;
81 mesa_format texFormat
;
83 dri_ctx
= pDRICtx
->driverPrivate
;
85 internalFormat
= (texture_format
== __DRI_TEXTURE_FORMAT_RGB
? 3 : 4);
87 texObj
= _mesa_get_current_tex_object(&dri_ctx
->Base
, target
);
88 texImage
= _mesa_get_tex_image(&dri_ctx
->Base
, texObj
, target
, 0);
89 swImage
= swrast_texture_image(texImage
);
91 _mesa_lock_texture(&dri_ctx
->Base
, texObj
);
93 sPriv
->swrast_loader
->getDrawableInfo(dPriv
, &x
, &y
, &w
, &h
, dPriv
->loaderPrivate
);
95 if (texture_format
== __DRI_TEXTURE_FORMAT_RGB
)
96 texFormat
= MESA_FORMAT_B8G8R8X8_UNORM
;
98 texFormat
= MESA_FORMAT_B8G8R8A8_UNORM
;
100 _mesa_init_teximage_fields(&dri_ctx
->Base
, texImage
,
101 w
, h
, 1, 0, internalFormat
, texFormat
);
103 sPriv
->swrast_loader
->getImage(dPriv
, x
, y
, w
, h
, (char *)swImage
->Buffer
,
104 dPriv
->loaderPrivate
);
106 _mesa_unlock_texture(&dri_ctx
->Base
, texObj
);
109 static void swrastSetTexBuffer(__DRIcontext
*pDRICtx
, GLint target
,
110 __DRIdrawable
*dPriv
)
112 swrastSetTexBuffer2(pDRICtx
, target
, __DRI_TEXTURE_FORMAT_RGBA
, dPriv
);
115 static const __DRItexBufferExtension swrastTexBufferExtension
= {
116 .base
= { __DRI_TEX_BUFFER
, 3 },
118 .setTexBuffer
= swrastSetTexBuffer
,
119 .setTexBuffer2
= swrastSetTexBuffer2
,
120 .releaseTexBuffer
= NULL
,
125 swrast_query_renderer_integer(__DRIscreen
*psp
, int param
,
129 case __DRI2_RENDERER_VENDOR_ID
:
130 case __DRI2_RENDERER_DEVICE_ID
:
131 /* Return 0xffffffff for both vendor and device id */
132 value
[0] = 0xffffffff;
134 case __DRI2_RENDERER_ACCELERATED
:
137 case __DRI2_RENDERER_VIDEO_MEMORY
: {
138 /* XXX: Do we want to return the full amount of system memory ? */
139 const long system_memory_pages
= sysconf(_SC_PHYS_PAGES
);
140 const long system_page_size
= sysconf(_SC_PAGE_SIZE
);
142 if (system_memory_pages
<= 0 || system_page_size
<= 0)
145 const uint64_t system_memory_bytes
= (uint64_t) system_memory_pages
146 * (uint64_t) system_page_size
;
148 const unsigned system_memory_megabytes
=
149 (unsigned) (system_memory_bytes
/ (1024 * 1024));
151 value
[0] = system_memory_megabytes
;
154 case __DRI2_RENDERER_UNIFIED_MEMORY_ARCHITECTURE
:
156 * XXX: Perhaps we should return 1 ?
157 * See issue #7 from the spec, currently UNRESOLVED.
162 return driQueryRendererIntegerCommon(psp
, param
, value
);
167 swrast_query_renderer_string(__DRIscreen
*psp
, int param
, const char **value
)
170 case __DRI2_RENDERER_VENDOR_ID
:
171 value
[0] = swrast_vendor_string
;
173 case __DRI2_RENDERER_DEVICE_ID
:
174 value
[0] = swrast_renderer_string
;
181 static const __DRI2rendererQueryExtension swrast_query_renderer_extension
= {
182 .base
= { __DRI2_RENDERER_QUERY
, 1 },
184 .queryInteger
= swrast_query_renderer_integer
,
185 .queryString
= swrast_query_renderer_string
188 static const __DRIextension
*dri_screen_extensions
[] = {
189 &swrastTexBufferExtension
.base
,
190 &swrast_query_renderer_extension
.base
,
194 static __DRIconfig
**
195 swrastFillInModes(__DRIscreen
*psp
,
196 unsigned pixel_bits
, unsigned depth_bits
,
197 unsigned stencil_bits
, GLboolean have_back_buffer
)
199 __DRIconfig
**configs
;
200 unsigned depth_buffer_factor
;
201 unsigned back_buffer_factor
;
204 /* GLX_SWAP_COPY_OML is only supported because the Intel driver doesn't
205 * support pageflipping at all.
207 static const GLenum back_buffer_modes
[] = {
208 GLX_NONE
, GLX_SWAP_UNDEFINED_OML
211 uint8_t depth_bits_array
[4];
212 uint8_t stencil_bits_array
[4];
213 uint8_t msaa_samples_array
[1];
216 (void) have_back_buffer
;
218 depth_bits_array
[0] = 0;
219 depth_bits_array
[1] = 0;
220 depth_bits_array
[2] = depth_bits
;
221 depth_bits_array
[3] = depth_bits
;
223 /* Just like with the accumulation buffer, always provide some modes
224 * with a stencil buffer.
226 stencil_bits_array
[0] = 0;
227 stencil_bits_array
[1] = (stencil_bits
== 0) ? 8 : stencil_bits
;
228 stencil_bits_array
[2] = 0;
229 stencil_bits_array
[3] = (stencil_bits
== 0) ? 8 : stencil_bits
;
231 msaa_samples_array
[0] = 0;
233 depth_buffer_factor
= 4;
234 back_buffer_factor
= 2;
236 switch (pixel_bits
) {
238 format
= MESA_FORMAT_B5G6R5_UNORM
;
241 format
= MESA_FORMAT_B8G8R8X8_UNORM
;
244 format
= MESA_FORMAT_B8G8R8A8_UNORM
;
247 fprintf(stderr
, "[%s:%u] bad depth %d\n", __func__
, __LINE__
,
252 configs
= driCreateConfigs(format
,
253 depth_bits_array
, stencil_bits_array
,
254 depth_buffer_factor
, back_buffer_modes
,
255 back_buffer_factor
, msaa_samples_array
, 1,
257 if (configs
== NULL
) {
258 fprintf(stderr
, "[%s:%u] Error creating FBConfig!\n", __func__
,
266 static const __DRIconfig
**
267 dri_init_screen(__DRIscreen
* psp
)
269 __DRIconfig
**configs16
, **configs24
, **configs32
;
273 psp
->max_gl_compat_version
= 21;
274 psp
->max_gl_es1_version
= 11;
275 psp
->max_gl_es2_version
= 20;
277 psp
->extensions
= dri_screen_extensions
;
279 configs16
= swrastFillInModes(psp
, 16, 16, 0, 1);
280 configs24
= swrastFillInModes(psp
, 24, 24, 8, 1);
281 configs32
= swrastFillInModes(psp
, 32, 24, 8, 1);
283 configs24
= driConcatConfigs(configs16
, configs24
);
284 configs32
= driConcatConfigs(configs24
, configs32
);
286 return (const __DRIconfig
**)configs32
;
290 dri_destroy_screen(__DRIscreen
* sPriv
)
298 * Framebuffer and renderbuffer-related functions.
302 choose_pixel_format(const struct gl_config
*v
)
304 int depth
= v
->rgbBits
;
307 && v
->redMask
== 0xff0000
308 && v
->greenMask
== 0x00ff00
309 && v
->blueMask
== 0x0000ff)
312 && v
->redMask
== 0xff0000
313 && v
->greenMask
== 0x00ff00
314 && v
->blueMask
== 0x0000ff)
317 && v
->redMask
== 0xf800
318 && v
->greenMask
== 0x07e0
319 && v
->blueMask
== 0x001f)
322 && v
->redMask
== 0x07
323 && v
->greenMask
== 0x38
324 && v
->blueMask
== 0xc0)
327 _mesa_problem( NULL
, "unexpected format in %s", __FUNCTION__
);
332 swrast_delete_renderbuffer(struct gl_context
*ctx
, struct gl_renderbuffer
*rb
)
334 struct dri_swrast_renderbuffer
*xrb
= dri_swrast_renderbuffer(rb
);
338 free(xrb
->Base
.Buffer
);
339 _mesa_delete_renderbuffer(ctx
, rb
);
342 /* see bytes_per_line in libGL */
344 bytes_per_line(unsigned pitch_bits
, unsigned mul
)
346 unsigned mask
= mul
- 1;
348 return ((pitch_bits
+ mask
) & ~mask
) / 8;
352 swrast_alloc_front_storage(struct gl_context
*ctx
, struct gl_renderbuffer
*rb
,
353 GLenum internalFormat
, GLuint width
, GLuint height
)
355 struct dri_swrast_renderbuffer
*xrb
= dri_swrast_renderbuffer(rb
);
360 (void) internalFormat
;
362 xrb
->Base
.Buffer
= NULL
;
365 xrb
->pitch
= bytes_per_line(width
* xrb
->bpp
, 32);
371 swrast_alloc_back_storage(struct gl_context
*ctx
, struct gl_renderbuffer
*rb
,
372 GLenum internalFormat
, GLuint width
, GLuint height
)
374 struct dri_swrast_renderbuffer
*xrb
= dri_swrast_renderbuffer(rb
);
378 free(xrb
->Base
.Buffer
);
380 swrast_alloc_front_storage(ctx
, rb
, internalFormat
, width
, height
);
382 xrb
->Base
.Buffer
= malloc(height
* xrb
->pitch
);
387 static struct dri_swrast_renderbuffer
*
388 swrast_new_renderbuffer(const struct gl_config
*visual
, __DRIdrawable
*dPriv
,
391 struct dri_swrast_renderbuffer
*xrb
= calloc(1, sizeof *xrb
);
392 struct gl_renderbuffer
*rb
;
400 rb
= &xrb
->Base
.Base
;
402 _mesa_init_renderbuffer(rb
, 0);
404 pixel_format
= choose_pixel_format(visual
);
407 xrb
->Base
.Base
.Delete
= swrast_delete_renderbuffer
;
409 rb
->AllocStorage
= swrast_alloc_front_storage
;
412 rb
->AllocStorage
= swrast_alloc_back_storage
;
415 switch (pixel_format
) {
417 rb
->Format
= MESA_FORMAT_B8G8R8A8_UNORM
;
418 rb
->InternalFormat
= GL_RGBA
;
419 rb
->_BaseFormat
= GL_RGBA
;
423 rb
->Format
= MESA_FORMAT_B8G8R8A8_UNORM
; /* XXX */
424 rb
->InternalFormat
= GL_RGB
;
425 rb
->_BaseFormat
= GL_RGB
;
429 rb
->Format
= MESA_FORMAT_B5G6R5_UNORM
;
430 rb
->InternalFormat
= GL_RGB
;
431 rb
->_BaseFormat
= GL_RGB
;
435 rb
->Format
= MESA_FORMAT_B2G3R3_UNORM
;
436 rb
->InternalFormat
= GL_RGB
;
437 rb
->_BaseFormat
= GL_RGB
;
449 swrast_map_renderbuffer(struct gl_context
*ctx
,
450 struct gl_renderbuffer
*rb
,
451 GLuint x
, GLuint y
, GLuint w
, GLuint h
,
456 struct dri_swrast_renderbuffer
*xrb
= dri_swrast_renderbuffer(rb
);
457 GLubyte
*map
= xrb
->Base
.Buffer
;
458 int cpp
= _mesa_get_format_bytes(rb
->Format
);
459 int stride
= rb
->Width
* cpp
;
461 if (rb
->AllocStorage
== swrast_alloc_front_storage
) {
462 __DRIdrawable
*dPriv
= xrb
->dPriv
;
463 __DRIscreen
*sPriv
= dPriv
->driScreenPriv
;
465 xrb
->map_mode
= mode
;
472 xrb
->Base
.Buffer
= malloc(h
* stride
);
474 sPriv
->swrast_loader
->getImage(dPriv
, x
, rb
->Height
- y
- h
, w
, h
,
475 (char *) xrb
->Base
.Buffer
,
476 dPriv
->loaderPrivate
);
478 *out_map
= xrb
->Base
.Buffer
+ (h
- 1) * stride
;
479 *out_stride
= -stride
;
483 ASSERT(xrb
->Base
.Buffer
);
485 if (rb
->AllocStorage
== swrast_alloc_back_storage
) {
486 map
+= (rb
->Height
- 1) * stride
;
490 map
+= (GLsizei
)y
* stride
;
491 map
+= (GLsizei
)x
* cpp
;
494 *out_stride
= stride
;
498 swrast_unmap_renderbuffer(struct gl_context
*ctx
,
499 struct gl_renderbuffer
*rb
)
501 struct dri_swrast_renderbuffer
*xrb
= dri_swrast_renderbuffer(rb
);
503 if (rb
->AllocStorage
== swrast_alloc_front_storage
) {
504 __DRIdrawable
*dPriv
= xrb
->dPriv
;
505 __DRIscreen
*sPriv
= dPriv
->driScreenPriv
;
507 if (xrb
->map_mode
& GL_MAP_WRITE_BIT
) {
508 sPriv
->swrast_loader
->putImage(dPriv
, __DRI_SWRAST_IMAGE_OP_DRAW
,
509 xrb
->map_x
, xrb
->map_y
,
510 xrb
->map_w
, xrb
->map_h
,
511 (char *) xrb
->Base
.Buffer
,
512 dPriv
->loaderPrivate
);
515 free(xrb
->Base
.Buffer
);
516 xrb
->Base
.Buffer
= NULL
;
521 dri_create_buffer(__DRIscreen
* sPriv
,
522 __DRIdrawable
* dPriv
,
523 const struct gl_config
* visual
, GLboolean isPixmap
)
525 struct dri_drawable
*drawable
= NULL
;
526 struct gl_framebuffer
*fb
;
527 struct dri_swrast_renderbuffer
*frontrb
, *backrb
;
534 drawable
= CALLOC_STRUCT(dri_drawable
);
535 if (drawable
== NULL
)
538 dPriv
->driverPrivate
= drawable
;
539 drawable
->dPriv
= dPriv
;
541 drawable
->row
= malloc(SWRAST_MAX_WIDTH
* 4);
542 if (drawable
->row
== NULL
)
545 fb
= &drawable
->Base
;
547 /* basic framebuffer setup */
548 _mesa_initialize_window_framebuffer(fb
, visual
);
550 /* add front renderbuffer */
551 frontrb
= swrast_new_renderbuffer(visual
, dPriv
, GL_TRUE
);
552 _mesa_add_renderbuffer(fb
, BUFFER_FRONT_LEFT
, &frontrb
->Base
.Base
);
554 /* add back renderbuffer */
555 if (visual
->doubleBufferMode
) {
556 backrb
= swrast_new_renderbuffer(visual
, dPriv
, GL_FALSE
);
557 _mesa_add_renderbuffer(fb
, BUFFER_BACK_LEFT
, &backrb
->Base
.Base
);
560 /* add software renderbuffers */
561 _swrast_add_soft_renderbuffers(fb
,
562 GL_FALSE
, /* color */
563 visual
->haveDepthBuffer
,
564 visual
->haveStencilBuffer
,
565 visual
->haveAccumBuffer
,
566 GL_FALSE
, /* alpha */
567 GL_FALSE
/* aux bufs */);
582 dri_destroy_buffer(__DRIdrawable
* dPriv
)
587 struct dri_drawable
*drawable
= dri_drawable(dPriv
);
588 struct gl_framebuffer
*fb
;
592 fb
= &drawable
->Base
;
594 fb
->DeletePending
= GL_TRUE
;
595 _mesa_reference_framebuffer(&fb
, NULL
);
600 dri_swap_buffers(__DRIdrawable
* dPriv
)
602 __DRIscreen
*sPriv
= dPriv
->driScreenPriv
;
604 GET_CURRENT_CONTEXT(ctx
);
606 struct dri_drawable
*drawable
= dri_drawable(dPriv
);
607 struct gl_framebuffer
*fb
;
608 struct dri_swrast_renderbuffer
*frontrb
, *backrb
;
612 fb
= &drawable
->Base
;
615 dri_swrast_renderbuffer(fb
->Attachment
[BUFFER_FRONT_LEFT
].Renderbuffer
);
617 dri_swrast_renderbuffer(fb
->Attachment
[BUFFER_BACK_LEFT
].Renderbuffer
);
619 /* check for signle-buffered */
623 /* check if swapping currently bound buffer */
624 if (ctx
&& ctx
->DrawBuffer
== fb
) {
625 /* flush pending rendering */
626 _mesa_notifySwapBuffers(ctx
);
629 sPriv
->swrast_loader
->putImage(dPriv
, __DRI_SWRAST_IMAGE_OP_SWAP
,
631 frontrb
->Base
.Base
.Width
,
632 frontrb
->Base
.Base
.Height
,
633 (char *) backrb
->Base
.Buffer
,
634 dPriv
->loaderPrivate
);
639 * General device driver functions.
643 get_window_size( struct gl_framebuffer
*fb
, GLsizei
*w
, GLsizei
*h
)
645 __DRIdrawable
*dPriv
= swrast_drawable(fb
)->dPriv
;
646 __DRIscreen
*sPriv
= dPriv
->driScreenPriv
;
649 sPriv
->swrast_loader
->getDrawableInfo(dPriv
,
651 dPriv
->loaderPrivate
);
655 swrast_check_and_update_window_size( struct gl_context
*ctx
, struct gl_framebuffer
*fb
)
657 GLsizei width
, height
;
659 get_window_size(fb
, &width
, &height
);
660 if (fb
->Width
!= width
|| fb
->Height
!= height
) {
661 _mesa_resize_framebuffer(ctx
, fb
, width
, height
);
665 static const GLubyte
*
666 get_string(struct gl_context
*ctx
, GLenum pname
)
671 return (const GLubyte
*) swrast_vendor_string
;
673 return (const GLubyte
*) swrast_renderer_string
;
680 update_state( struct gl_context
*ctx
, GLuint new_state
)
682 /* not much to do here - pass it on */
683 _swrast_InvalidateState( ctx
, new_state
);
684 _swsetup_InvalidateState( ctx
, new_state
);
685 _vbo_InvalidateState( ctx
, new_state
);
686 _tnl_InvalidateState( ctx
, new_state
);
690 viewport(struct gl_context
*ctx
)
692 struct gl_framebuffer
*draw
= ctx
->WinSysDrawBuffer
;
693 struct gl_framebuffer
*read
= ctx
->WinSysReadBuffer
;
695 swrast_check_and_update_window_size(ctx
, draw
);
696 swrast_check_and_update_window_size(ctx
, read
);
699 static mesa_format
swrastChooseTextureFormat(struct gl_context
* ctx
,
701 GLint internalFormat
,
705 if (internalFormat
== GL_RGB
)
706 return MESA_FORMAT_B8G8R8X8_UNORM
;
707 return _mesa_choose_tex_format(ctx
, target
, internalFormat
, format
, type
);
711 swrast_init_driver_functions(struct dd_function_table
*driver
)
713 driver
->GetString
= get_string
;
714 driver
->UpdateState
= update_state
;
715 driver
->Viewport
= viewport
;
716 driver
->ChooseTextureFormat
= swrastChooseTextureFormat
;
717 driver
->MapRenderbuffer
= swrast_map_renderbuffer
;
718 driver
->UnmapRenderbuffer
= swrast_unmap_renderbuffer
;
722 * Context-related functions.
726 dri_create_context(gl_api api
,
727 const struct gl_config
* visual
,
728 __DRIcontext
* cPriv
,
729 unsigned major_version
,
730 unsigned minor_version
,
734 void *sharedContextPrivate
)
736 struct dri_context
*ctx
= NULL
;
737 struct dri_context
*share
= (struct dri_context
*)sharedContextPrivate
;
738 struct gl_context
*mesaCtx
= NULL
;
739 struct gl_context
*sharedCtx
= NULL
;
740 struct dd_function_table functions
;
744 /* Flag filtering is handled in dri2CreateContextAttribs.
748 ctx
= CALLOC_STRUCT(dri_context
);
750 *error
= __DRI_CTX_ERROR_NO_MEMORY
;
754 cPriv
->driverPrivate
= ctx
;
757 /* build table of device driver functions */
758 _mesa_init_driver_functions(&functions
);
759 swrast_init_driver_functions(&functions
);
762 sharedCtx
= &share
->Base
;
765 mesaCtx
= &ctx
->Base
;
767 /* basic context setup */
768 if (!_mesa_initialize_context(mesaCtx
, api
, visual
, sharedCtx
, &functions
)) {
769 *error
= __DRI_CTX_ERROR_NO_MEMORY
;
773 driContextSetFlags(mesaCtx
, flags
);
775 /* create module contexts */
776 _swrast_CreateContext( mesaCtx
);
777 _vbo_CreateContext( mesaCtx
);
778 _tnl_CreateContext( mesaCtx
);
779 _swsetup_CreateContext( mesaCtx
);
780 _swsetup_Wakeup( mesaCtx
);
782 /* use default TCL pipeline */
784 TNLcontext
*tnl
= TNL_CONTEXT(mesaCtx
);
785 tnl
->Driver
.RunPipeline
= _tnl_run_pipeline
;
788 _mesa_meta_init(mesaCtx
);
789 _mesa_enable_sw_extensions(mesaCtx
);
791 _mesa_compute_version(mesaCtx
);
793 _mesa_initialize_dispatch_tables(mesaCtx
);
794 _mesa_initialize_vbo_vtxfmt(mesaCtx
);
796 *error
= __DRI_CTX_ERROR_SUCCESS
;
807 dri_destroy_context(__DRIcontext
* cPriv
)
812 struct dri_context
*ctx
= dri_context(cPriv
);
813 struct gl_context
*mesaCtx
;
815 mesaCtx
= &ctx
->Base
;
817 _mesa_meta_free(mesaCtx
);
818 _swsetup_DestroyContext( mesaCtx
);
819 _swrast_DestroyContext( mesaCtx
);
820 _tnl_DestroyContext( mesaCtx
);
821 _vbo_DestroyContext( mesaCtx
);
822 _mesa_destroy_context( mesaCtx
);
827 dri_make_current(__DRIcontext
* cPriv
,
828 __DRIdrawable
* driDrawPriv
,
829 __DRIdrawable
* driReadPriv
)
831 struct gl_context
*mesaCtx
;
832 struct gl_framebuffer
*mesaDraw
;
833 struct gl_framebuffer
*mesaRead
;
837 struct dri_context
*ctx
= dri_context(cPriv
);
838 struct dri_drawable
*draw
;
839 struct dri_drawable
*read
;
841 if (!driDrawPriv
|| !driReadPriv
)
844 draw
= dri_drawable(driDrawPriv
);
845 read
= dri_drawable(driReadPriv
);
846 mesaCtx
= &ctx
->Base
;
847 mesaDraw
= &draw
->Base
;
848 mesaRead
= &read
->Base
;
850 /* check for same context and buffer */
851 if (mesaCtx
== _mesa_get_current_context()
852 && mesaCtx
->DrawBuffer
== mesaDraw
853 && mesaCtx
->ReadBuffer
== mesaRead
) {
857 _glapi_check_multithread();
859 swrast_check_and_update_window_size(mesaCtx
, mesaDraw
);
860 if (mesaRead
!= mesaDraw
)
861 swrast_check_and_update_window_size(mesaCtx
, mesaRead
);
863 _mesa_make_current( mesaCtx
,
869 _mesa_make_current( NULL
, NULL
, NULL
);
876 dri_unbind_context(__DRIcontext
* cPriv
)
881 /* Unset current context and dispath table */
882 _mesa_make_current(NULL
, NULL
, NULL
);
888 dri_copy_sub_buffer(__DRIdrawable
*dPriv
, int x
, int y
,
891 __DRIscreen
*sPriv
= dPriv
->driScreenPriv
;
894 struct dri_drawable
*drawable
= dri_drawable(dPriv
);
895 struct gl_framebuffer
*fb
;
896 struct dri_swrast_renderbuffer
*frontrb
, *backrb
;
900 fb
= &drawable
->Base
;
903 dri_swrast_renderbuffer(fb
->Attachment
[BUFFER_FRONT_LEFT
].Renderbuffer
);
905 dri_swrast_renderbuffer(fb
->Attachment
[BUFFER_BACK_LEFT
].Renderbuffer
);
907 /* check for signle-buffered */
911 iy
= frontrb
->Base
.Base
.Height
- y
- h
;
912 data
= (char *)backrb
->Base
.Buffer
+ (iy
* backrb
->pitch
) + (x
* ((backrb
->bpp
+ 7) / 8));
913 sPriv
->swrast_loader
->putImage2(dPriv
, __DRI_SWRAST_IMAGE_OP_SWAP
,
917 dPriv
->loaderPrivate
);
921 static const struct __DriverAPIRec swrast_driver_api
= {
922 .InitScreen
= dri_init_screen
,
923 .DestroyScreen
= dri_destroy_screen
,
924 .CreateContext
= dri_create_context
,
925 .DestroyContext
= dri_destroy_context
,
926 .CreateBuffer
= dri_create_buffer
,
927 .DestroyBuffer
= dri_destroy_buffer
,
928 .SwapBuffers
= dri_swap_buffers
,
929 .MakeCurrent
= dri_make_current
,
930 .UnbindContext
= dri_unbind_context
,
931 .CopySubBuffer
= dri_copy_sub_buffer
,
934 static const struct __DRIDriverVtableExtensionRec swrast_vtable
= {
935 .base
= { __DRI_DRIVER_VTABLE
, 1 },
936 .vtable
= &swrast_driver_api
,
939 static const __DRIextension
*swrast_driver_extensions
[] = {
940 &driCoreExtension
.base
,
941 &driSWRastExtension
.base
,
942 &driCopySubBufferExtension
.base
,
947 PUBLIC
const __DRIextension
**__driDriverGetExtensions_swrast(void)
949 globalDriverAPI
= &swrast_driver_api
;
951 return swrast_driver_extensions
;