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.
36 #include "main/api_exec.h"
37 #include "main/context.h"
38 #include "main/extensions.h"
39 #include "main/formats.h"
40 #include "main/framebuffer.h"
41 #include "main/imports.h"
42 #include "main/renderbuffer.h"
43 #include "main/version.h"
44 #include "main/vtxfmt.h"
45 #include "swrast/swrast.h"
46 #include "swrast/s_renderbuffer.h"
47 #include "swrast_setup/swrast_setup.h"
49 #include "tnl/t_context.h"
50 #include "tnl/t_pipeline.h"
52 #include "drivers/common/driverfuncs.h"
53 #include "drivers/common/meta.h"
56 #include "main/teximage.h"
57 #include "main/texformat.h"
58 #include "main/texobj.h"
59 #include "main/texstate.h"
61 #include "swrast_priv.h"
62 #include "swrast/s_context.h"
64 #include <sys/types.h>
65 #ifdef HAVE_SYS_SYSCTL_H
66 # include <sys/sysctl.h>
69 const __DRIextension
**__driDriverGetExtensions_swrast(void);
71 const char * const swrast_vendor_string
= "Mesa Project";
72 const char * const swrast_renderer_string
= "Software Rasterizer";
75 * Screen and config-related functions
78 static void swrastSetTexBuffer2(__DRIcontext
*pDRICtx
, GLint target
,
79 GLint texture_format
, __DRIdrawable
*dPriv
)
81 struct dri_context
*dri_ctx
;
83 __DRIscreen
*sPriv
= dPriv
->driScreenPriv
;
84 struct gl_texture_object
*texObj
;
85 struct gl_texture_image
*texImage
;
86 struct swrast_texture_image
*swImage
;
87 uint32_t internalFormat
;
88 mesa_format texFormat
;
90 dri_ctx
= pDRICtx
->driverPrivate
;
92 internalFormat
= (texture_format
== __DRI_TEXTURE_FORMAT_RGB
? 3 : 4);
94 texObj
= _mesa_get_current_tex_object(&dri_ctx
->Base
, target
);
95 texImage
= _mesa_get_tex_image(&dri_ctx
->Base
, texObj
, target
, 0);
96 swImage
= swrast_texture_image(texImage
);
98 _mesa_lock_texture(&dri_ctx
->Base
, texObj
);
100 sPriv
->swrast_loader
->getDrawableInfo(dPriv
, &x
, &y
, &w
, &h
, dPriv
->loaderPrivate
);
102 if (texture_format
== __DRI_TEXTURE_FORMAT_RGB
)
103 texFormat
= MESA_FORMAT_B8G8R8X8_UNORM
;
105 texFormat
= MESA_FORMAT_B8G8R8A8_UNORM
;
107 _mesa_init_teximage_fields(&dri_ctx
->Base
, texImage
,
108 w
, h
, 1, 0, internalFormat
, texFormat
);
110 sPriv
->swrast_loader
->getImage(dPriv
, x
, y
, w
, h
, (char *)swImage
->Buffer
,
111 dPriv
->loaderPrivate
);
113 _mesa_unlock_texture(&dri_ctx
->Base
, texObj
);
116 static void swrastSetTexBuffer(__DRIcontext
*pDRICtx
, GLint target
,
117 __DRIdrawable
*dPriv
)
119 swrastSetTexBuffer2(pDRICtx
, target
, __DRI_TEXTURE_FORMAT_RGBA
, dPriv
);
122 static const __DRItexBufferExtension swrastTexBufferExtension
= {
123 .base
= { __DRI_TEX_BUFFER
, 3 },
125 .setTexBuffer
= swrastSetTexBuffer
,
126 .setTexBuffer2
= swrastSetTexBuffer2
,
127 .releaseTexBuffer
= NULL
,
132 swrast_query_renderer_integer(__DRIscreen
*psp
, int param
,
136 case __DRI2_RENDERER_VENDOR_ID
:
137 case __DRI2_RENDERER_DEVICE_ID
:
138 /* Return 0xffffffff for both vendor and device id */
139 value
[0] = 0xffffffff;
141 case __DRI2_RENDERER_ACCELERATED
:
144 case __DRI2_RENDERER_VIDEO_MEMORY
: {
145 /* This should probably share code with os_get_total_physical_memory()
146 * from src/gallium/auxiliary/os/os_misc.c
148 #if defined(CTL_HW) && defined(HW_MEMSIZE)
149 int mib
[2] = { CTL_HW
, HW_MEMSIZE
};
150 unsigned long system_memory_bytes
;
151 size_t len
= sizeof(system_memory_bytes
);
152 if (sysctl(mib
, 2, &system_memory_bytes
, &len
, NULL
, 0) != 0)
154 #elif defined(_SC_PHYS_PAGES) && defined(_SC_PAGE_SIZE)
155 /* XXX: Do we want to return the full amount of system memory ? */
156 const long system_memory_pages
= sysconf(_SC_PHYS_PAGES
);
157 const long system_page_size
= sysconf(_SC_PAGE_SIZE
);
159 if (system_memory_pages
<= 0 || system_page_size
<= 0)
162 const uint64_t system_memory_bytes
= (uint64_t) system_memory_pages
163 * (uint64_t) system_page_size
;
165 #error "Unsupported platform"
168 const unsigned system_memory_megabytes
=
169 (unsigned) (system_memory_bytes
/ (1024 * 1024));
171 value
[0] = system_memory_megabytes
;
174 case __DRI2_RENDERER_UNIFIED_MEMORY_ARCHITECTURE
:
176 * XXX: Perhaps we should return 1 ?
177 * See issue #7 from the spec, currently UNRESOLVED.
182 return driQueryRendererIntegerCommon(psp
, param
, value
);
187 swrast_query_renderer_string(__DRIscreen
*psp
, int param
, const char **value
)
190 case __DRI2_RENDERER_VENDOR_ID
:
191 value
[0] = swrast_vendor_string
;
193 case __DRI2_RENDERER_DEVICE_ID
:
194 value
[0] = swrast_renderer_string
;
201 static const __DRI2rendererQueryExtension swrast_query_renderer_extension
= {
202 .base
= { __DRI2_RENDERER_QUERY
, 1 },
204 .queryInteger
= swrast_query_renderer_integer
,
205 .queryString
= swrast_query_renderer_string
208 static const __DRIextension
*dri_screen_extensions
[] = {
209 &swrastTexBufferExtension
.base
,
210 &swrast_query_renderer_extension
.base
,
214 static __DRIconfig
**
215 swrastFillInModes(__DRIscreen
*psp
,
216 unsigned pixel_bits
, unsigned depth_bits
,
217 unsigned stencil_bits
, GLboolean have_back_buffer
)
219 __DRIconfig
**configs
;
220 unsigned depth_buffer_factor
;
221 unsigned back_buffer_factor
;
224 /* GLX_SWAP_COPY_OML is only supported because the Intel driver doesn't
225 * support pageflipping at all.
227 static const GLenum back_buffer_modes
[] = {
228 GLX_NONE
, GLX_SWAP_UNDEFINED_OML
231 uint8_t depth_bits_array
[4];
232 uint8_t stencil_bits_array
[4];
233 uint8_t msaa_samples_array
[1];
236 (void) have_back_buffer
;
238 depth_bits_array
[0] = 0;
239 depth_bits_array
[1] = 0;
240 depth_bits_array
[2] = depth_bits
;
241 depth_bits_array
[3] = depth_bits
;
243 /* Just like with the accumulation buffer, always provide some modes
244 * with a stencil buffer.
246 stencil_bits_array
[0] = 0;
247 stencil_bits_array
[1] = (stencil_bits
== 0) ? 8 : stencil_bits
;
248 stencil_bits_array
[2] = 0;
249 stencil_bits_array
[3] = (stencil_bits
== 0) ? 8 : stencil_bits
;
251 msaa_samples_array
[0] = 0;
253 depth_buffer_factor
= 4;
254 back_buffer_factor
= 2;
256 switch (pixel_bits
) {
258 format
= MESA_FORMAT_B5G6R5_UNORM
;
261 format
= MESA_FORMAT_B8G8R8X8_UNORM
;
264 format
= MESA_FORMAT_B8G8R8A8_UNORM
;
267 fprintf(stderr
, "[%s:%u] bad depth %d\n", __func__
, __LINE__
,
272 configs
= driCreateConfigs(format
,
273 depth_bits_array
, stencil_bits_array
,
274 depth_buffer_factor
, back_buffer_modes
,
275 back_buffer_factor
, msaa_samples_array
, 1,
277 if (configs
== NULL
) {
278 fprintf(stderr
, "[%s:%u] Error creating FBConfig!\n", __func__
,
286 static const __DRIconfig
**
287 dri_init_screen(__DRIscreen
* psp
)
289 __DRIconfig
**configs16
, **configs24
, **configs32
;
293 psp
->max_gl_compat_version
= 21;
294 psp
->max_gl_es1_version
= 11;
295 psp
->max_gl_es2_version
= 20;
297 psp
->extensions
= dri_screen_extensions
;
299 configs16
= swrastFillInModes(psp
, 16, 16, 0, 1);
300 configs24
= swrastFillInModes(psp
, 24, 24, 8, 1);
301 configs32
= swrastFillInModes(psp
, 32, 24, 8, 1);
303 configs24
= driConcatConfigs(configs16
, configs24
);
304 configs32
= driConcatConfigs(configs24
, configs32
);
306 return (const __DRIconfig
**)configs32
;
310 dri_destroy_screen(__DRIscreen
* sPriv
)
318 * Framebuffer and renderbuffer-related functions.
322 choose_pixel_format(const struct gl_config
*v
)
324 int depth
= v
->rgbBits
;
327 && v
->redMask
== 0xff0000
328 && v
->greenMask
== 0x00ff00
329 && v
->blueMask
== 0x0000ff)
332 && v
->redMask
== 0xff0000
333 && v
->greenMask
== 0x00ff00
334 && v
->blueMask
== 0x0000ff)
337 && v
->redMask
== 0xf800
338 && v
->greenMask
== 0x07e0
339 && v
->blueMask
== 0x001f)
342 && v
->redMask
== 0x07
343 && v
->greenMask
== 0x38
344 && v
->blueMask
== 0xc0)
347 _mesa_problem( NULL
, "unexpected format in %s", __func__
);
352 swrast_delete_renderbuffer(struct gl_context
*ctx
, struct gl_renderbuffer
*rb
)
354 struct dri_swrast_renderbuffer
*xrb
= dri_swrast_renderbuffer(rb
);
358 free(xrb
->Base
.Buffer
);
359 _mesa_delete_renderbuffer(ctx
, rb
);
362 /* see bytes_per_line in libGL */
364 bytes_per_line(unsigned pitch_bits
, unsigned mul
)
366 unsigned mask
= mul
- 1;
368 return ((pitch_bits
+ mask
) & ~mask
) / 8;
372 swrast_alloc_front_storage(struct gl_context
*ctx
, struct gl_renderbuffer
*rb
,
373 GLenum internalFormat
, GLuint width
, GLuint height
)
375 struct dri_swrast_renderbuffer
*xrb
= dri_swrast_renderbuffer(rb
);
380 (void) internalFormat
;
382 xrb
->Base
.Buffer
= NULL
;
385 xrb
->pitch
= bytes_per_line(width
* xrb
->bpp
, 32);
391 swrast_alloc_back_storage(struct gl_context
*ctx
, struct gl_renderbuffer
*rb
,
392 GLenum internalFormat
, GLuint width
, GLuint height
)
394 struct dri_swrast_renderbuffer
*xrb
= dri_swrast_renderbuffer(rb
);
398 free(xrb
->Base
.Buffer
);
400 swrast_alloc_front_storage(ctx
, rb
, internalFormat
, width
, height
);
402 xrb
->Base
.Buffer
= malloc(height
* xrb
->pitch
);
407 static struct dri_swrast_renderbuffer
*
408 swrast_new_renderbuffer(const struct gl_config
*visual
, __DRIdrawable
*dPriv
,
411 struct dri_swrast_renderbuffer
*xrb
= calloc(1, sizeof *xrb
);
412 struct gl_renderbuffer
*rb
;
420 rb
= &xrb
->Base
.Base
;
422 _mesa_init_renderbuffer(rb
, 0);
424 pixel_format
= choose_pixel_format(visual
);
427 xrb
->Base
.Base
.Delete
= swrast_delete_renderbuffer
;
429 rb
->AllocStorage
= swrast_alloc_front_storage
;
432 rb
->AllocStorage
= swrast_alloc_back_storage
;
435 switch (pixel_format
) {
437 rb
->Format
= MESA_FORMAT_B8G8R8A8_UNORM
;
438 rb
->InternalFormat
= GL_RGBA
;
439 rb
->_BaseFormat
= GL_RGBA
;
443 rb
->Format
= MESA_FORMAT_B8G8R8A8_UNORM
; /* XXX */
444 rb
->InternalFormat
= GL_RGB
;
445 rb
->_BaseFormat
= GL_RGB
;
449 rb
->Format
= MESA_FORMAT_B5G6R5_UNORM
;
450 rb
->InternalFormat
= GL_RGB
;
451 rb
->_BaseFormat
= GL_RGB
;
455 rb
->Format
= MESA_FORMAT_B2G3R3_UNORM
;
456 rb
->InternalFormat
= GL_RGB
;
457 rb
->_BaseFormat
= GL_RGB
;
469 swrast_map_renderbuffer(struct gl_context
*ctx
,
470 struct gl_renderbuffer
*rb
,
471 GLuint x
, GLuint y
, GLuint w
, GLuint h
,
476 struct dri_swrast_renderbuffer
*xrb
= dri_swrast_renderbuffer(rb
);
477 GLubyte
*map
= xrb
->Base
.Buffer
;
478 int cpp
= _mesa_get_format_bytes(rb
->Format
);
479 int stride
= rb
->Width
* cpp
;
481 if (rb
->AllocStorage
== swrast_alloc_front_storage
) {
482 __DRIdrawable
*dPriv
= xrb
->dPriv
;
483 __DRIscreen
*sPriv
= dPriv
->driScreenPriv
;
485 xrb
->map_mode
= mode
;
492 xrb
->Base
.Buffer
= malloc(h
* stride
);
494 sPriv
->swrast_loader
->getImage(dPriv
, x
, rb
->Height
- y
- h
, w
, h
,
495 (char *) xrb
->Base
.Buffer
,
496 dPriv
->loaderPrivate
);
498 *out_map
= xrb
->Base
.Buffer
+ (h
- 1) * stride
;
499 *out_stride
= -stride
;
503 assert(xrb
->Base
.Buffer
);
505 if (rb
->AllocStorage
== swrast_alloc_back_storage
) {
506 map
+= (rb
->Height
- 1) * stride
;
510 map
+= (GLsizei
)y
* stride
;
511 map
+= (GLsizei
)x
* cpp
;
514 *out_stride
= stride
;
518 swrast_unmap_renderbuffer(struct gl_context
*ctx
,
519 struct gl_renderbuffer
*rb
)
521 struct dri_swrast_renderbuffer
*xrb
= dri_swrast_renderbuffer(rb
);
523 if (rb
->AllocStorage
== swrast_alloc_front_storage
) {
524 __DRIdrawable
*dPriv
= xrb
->dPriv
;
525 __DRIscreen
*sPriv
= dPriv
->driScreenPriv
;
527 if (xrb
->map_mode
& GL_MAP_WRITE_BIT
) {
528 sPriv
->swrast_loader
->putImage(dPriv
, __DRI_SWRAST_IMAGE_OP_DRAW
,
529 xrb
->map_x
, xrb
->map_y
,
530 xrb
->map_w
, xrb
->map_h
,
531 (char *) xrb
->Base
.Buffer
,
532 dPriv
->loaderPrivate
);
535 free(xrb
->Base
.Buffer
);
536 xrb
->Base
.Buffer
= NULL
;
541 dri_create_buffer(__DRIscreen
* sPriv
,
542 __DRIdrawable
* dPriv
,
543 const struct gl_config
* visual
, GLboolean isPixmap
)
545 struct dri_drawable
*drawable
= NULL
;
546 struct gl_framebuffer
*fb
;
547 struct dri_swrast_renderbuffer
*frontrb
, *backrb
;
554 drawable
= CALLOC_STRUCT(dri_drawable
);
555 if (drawable
== NULL
)
558 dPriv
->driverPrivate
= drawable
;
559 drawable
->dPriv
= dPriv
;
561 drawable
->row
= malloc(SWRAST_MAX_WIDTH
* 4);
562 if (drawable
->row
== NULL
)
565 fb
= &drawable
->Base
;
567 /* basic framebuffer setup */
568 _mesa_initialize_window_framebuffer(fb
, visual
);
570 /* add front renderbuffer */
571 frontrb
= swrast_new_renderbuffer(visual
, dPriv
, GL_TRUE
);
572 _mesa_add_renderbuffer(fb
, BUFFER_FRONT_LEFT
, &frontrb
->Base
.Base
);
574 /* add back renderbuffer */
575 if (visual
->doubleBufferMode
) {
576 backrb
= swrast_new_renderbuffer(visual
, dPriv
, GL_FALSE
);
577 _mesa_add_renderbuffer(fb
, BUFFER_BACK_LEFT
, &backrb
->Base
.Base
);
580 /* add software renderbuffers */
581 _swrast_add_soft_renderbuffers(fb
,
582 GL_FALSE
, /* color */
583 visual
->haveDepthBuffer
,
584 visual
->haveStencilBuffer
,
585 visual
->haveAccumBuffer
,
586 GL_FALSE
, /* alpha */
587 GL_FALSE
/* aux bufs */);
602 dri_destroy_buffer(__DRIdrawable
* dPriv
)
607 struct dri_drawable
*drawable
= dri_drawable(dPriv
);
608 struct gl_framebuffer
*fb
;
612 fb
= &drawable
->Base
;
614 fb
->DeletePending
= GL_TRUE
;
615 _mesa_reference_framebuffer(&fb
, NULL
);
620 dri_swap_buffers(__DRIdrawable
* dPriv
)
622 __DRIscreen
*sPriv
= dPriv
->driScreenPriv
;
624 GET_CURRENT_CONTEXT(ctx
);
626 struct dri_drawable
*drawable
= dri_drawable(dPriv
);
627 struct gl_framebuffer
*fb
;
628 struct dri_swrast_renderbuffer
*frontrb
, *backrb
;
632 fb
= &drawable
->Base
;
635 dri_swrast_renderbuffer(fb
->Attachment
[BUFFER_FRONT_LEFT
].Renderbuffer
);
637 dri_swrast_renderbuffer(fb
->Attachment
[BUFFER_BACK_LEFT
].Renderbuffer
);
639 /* check for signle-buffered */
643 /* check if swapping currently bound buffer */
644 if (ctx
&& ctx
->DrawBuffer
== fb
) {
645 /* flush pending rendering */
646 _mesa_notifySwapBuffers(ctx
);
649 sPriv
->swrast_loader
->putImage(dPriv
, __DRI_SWRAST_IMAGE_OP_SWAP
,
651 frontrb
->Base
.Base
.Width
,
652 frontrb
->Base
.Base
.Height
,
653 (char *) backrb
->Base
.Buffer
,
654 dPriv
->loaderPrivate
);
659 * General device driver functions.
663 get_window_size( struct gl_framebuffer
*fb
, GLsizei
*w
, GLsizei
*h
)
665 __DRIdrawable
*dPriv
= swrast_drawable(fb
)->dPriv
;
666 __DRIscreen
*sPriv
= dPriv
->driScreenPriv
;
669 sPriv
->swrast_loader
->getDrawableInfo(dPriv
,
671 dPriv
->loaderPrivate
);
675 swrast_check_and_update_window_size( struct gl_context
*ctx
, struct gl_framebuffer
*fb
)
677 GLsizei width
, height
;
679 get_window_size(fb
, &width
, &height
);
680 if (fb
->Width
!= width
|| fb
->Height
!= height
) {
681 _mesa_resize_framebuffer(ctx
, fb
, width
, height
);
685 static const GLubyte
*
686 get_string(struct gl_context
*ctx
, GLenum pname
)
691 return (const GLubyte
*) swrast_vendor_string
;
693 return (const GLubyte
*) swrast_renderer_string
;
700 update_state( struct gl_context
*ctx
, GLuint new_state
)
702 /* not much to do here - pass it on */
703 _swrast_InvalidateState( ctx
, new_state
);
704 _swsetup_InvalidateState( ctx
, new_state
);
705 _vbo_InvalidateState( ctx
, new_state
);
706 _tnl_InvalidateState( ctx
, new_state
);
710 viewport(struct gl_context
*ctx
)
712 struct gl_framebuffer
*draw
= ctx
->WinSysDrawBuffer
;
713 struct gl_framebuffer
*read
= ctx
->WinSysReadBuffer
;
715 swrast_check_and_update_window_size(ctx
, draw
);
716 swrast_check_and_update_window_size(ctx
, read
);
719 static mesa_format
swrastChooseTextureFormat(struct gl_context
* ctx
,
721 GLint internalFormat
,
725 if (internalFormat
== GL_RGB
)
726 return MESA_FORMAT_B8G8R8X8_UNORM
;
727 return _mesa_choose_tex_format(ctx
, target
, internalFormat
, format
, type
);
731 swrast_init_driver_functions(struct dd_function_table
*driver
)
733 driver
->GetString
= get_string
;
734 driver
->UpdateState
= update_state
;
735 driver
->Viewport
= viewport
;
736 driver
->ChooseTextureFormat
= swrastChooseTextureFormat
;
737 driver
->MapRenderbuffer
= swrast_map_renderbuffer
;
738 driver
->UnmapRenderbuffer
= swrast_unmap_renderbuffer
;
742 * Context-related functions.
746 dri_create_context(gl_api api
,
747 const struct gl_config
* visual
,
748 __DRIcontext
* cPriv
,
749 unsigned major_version
,
750 unsigned minor_version
,
754 void *sharedContextPrivate
)
756 struct dri_context
*ctx
= NULL
;
757 struct dri_context
*share
= (struct dri_context
*)sharedContextPrivate
;
758 struct gl_context
*mesaCtx
= NULL
;
759 struct gl_context
*sharedCtx
= NULL
;
760 struct dd_function_table functions
;
764 /* Flag filtering is handled in dri2CreateContextAttribs.
768 ctx
= CALLOC_STRUCT(dri_context
);
770 *error
= __DRI_CTX_ERROR_NO_MEMORY
;
774 cPriv
->driverPrivate
= ctx
;
777 /* build table of device driver functions */
778 _mesa_init_driver_functions(&functions
);
779 swrast_init_driver_functions(&functions
);
782 sharedCtx
= &share
->Base
;
785 mesaCtx
= &ctx
->Base
;
787 /* basic context setup */
788 if (!_mesa_initialize_context(mesaCtx
, api
, visual
, sharedCtx
, &functions
)) {
789 *error
= __DRI_CTX_ERROR_NO_MEMORY
;
793 driContextSetFlags(mesaCtx
, flags
);
795 /* create module contexts */
796 _swrast_CreateContext( mesaCtx
);
797 _vbo_CreateContext( mesaCtx
);
798 _tnl_CreateContext( mesaCtx
);
799 _swsetup_CreateContext( mesaCtx
);
800 _swsetup_Wakeup( mesaCtx
);
802 /* use default TCL pipeline */
804 TNLcontext
*tnl
= TNL_CONTEXT(mesaCtx
);
805 tnl
->Driver
.RunPipeline
= _tnl_run_pipeline
;
808 _mesa_meta_init(mesaCtx
);
809 _mesa_enable_sw_extensions(mesaCtx
);
811 _mesa_compute_version(mesaCtx
);
813 _mesa_initialize_dispatch_tables(mesaCtx
);
814 _mesa_initialize_vbo_vtxfmt(mesaCtx
);
816 *error
= __DRI_CTX_ERROR_SUCCESS
;
827 dri_destroy_context(__DRIcontext
* cPriv
)
832 struct dri_context
*ctx
= dri_context(cPriv
);
833 struct gl_context
*mesaCtx
;
835 mesaCtx
= &ctx
->Base
;
837 _mesa_meta_free(mesaCtx
);
838 _swsetup_DestroyContext( mesaCtx
);
839 _swrast_DestroyContext( mesaCtx
);
840 _tnl_DestroyContext( mesaCtx
);
841 _vbo_DestroyContext( mesaCtx
);
842 _mesa_destroy_context( mesaCtx
);
847 dri_make_current(__DRIcontext
* cPriv
,
848 __DRIdrawable
* driDrawPriv
,
849 __DRIdrawable
* driReadPriv
)
851 struct gl_context
*mesaCtx
;
852 struct gl_framebuffer
*mesaDraw
;
853 struct gl_framebuffer
*mesaRead
;
857 struct dri_context
*ctx
= dri_context(cPriv
);
858 struct dri_drawable
*draw
;
859 struct dri_drawable
*read
;
861 if (!driDrawPriv
|| !driReadPriv
)
864 draw
= dri_drawable(driDrawPriv
);
865 read
= dri_drawable(driReadPriv
);
866 mesaCtx
= &ctx
->Base
;
867 mesaDraw
= &draw
->Base
;
868 mesaRead
= &read
->Base
;
870 /* check for same context and buffer */
871 if (mesaCtx
== _mesa_get_current_context()
872 && mesaCtx
->DrawBuffer
== mesaDraw
873 && mesaCtx
->ReadBuffer
== mesaRead
) {
877 _glapi_check_multithread();
879 swrast_check_and_update_window_size(mesaCtx
, mesaDraw
);
880 if (mesaRead
!= mesaDraw
)
881 swrast_check_and_update_window_size(mesaCtx
, mesaRead
);
883 _mesa_make_current( mesaCtx
,
889 _mesa_make_current( NULL
, NULL
, NULL
);
896 dri_unbind_context(__DRIcontext
* cPriv
)
901 /* Unset current context and dispath table */
902 _mesa_make_current(NULL
, NULL
, NULL
);
908 dri_copy_sub_buffer(__DRIdrawable
*dPriv
, int x
, int y
,
911 __DRIscreen
*sPriv
= dPriv
->driScreenPriv
;
914 struct dri_drawable
*drawable
= dri_drawable(dPriv
);
915 struct gl_framebuffer
*fb
;
916 struct dri_swrast_renderbuffer
*frontrb
, *backrb
;
920 fb
= &drawable
->Base
;
923 dri_swrast_renderbuffer(fb
->Attachment
[BUFFER_FRONT_LEFT
].Renderbuffer
);
925 dri_swrast_renderbuffer(fb
->Attachment
[BUFFER_BACK_LEFT
].Renderbuffer
);
927 /* check for signle-buffered */
931 iy
= frontrb
->Base
.Base
.Height
- y
- h
;
932 data
= (char *)backrb
->Base
.Buffer
+ (iy
* backrb
->pitch
) + (x
* ((backrb
->bpp
+ 7) / 8));
933 sPriv
->swrast_loader
->putImage2(dPriv
, __DRI_SWRAST_IMAGE_OP_SWAP
,
937 dPriv
->loaderPrivate
);
941 static const struct __DriverAPIRec swrast_driver_api
= {
942 .InitScreen
= dri_init_screen
,
943 .DestroyScreen
= dri_destroy_screen
,
944 .CreateContext
= dri_create_context
,
945 .DestroyContext
= dri_destroy_context
,
946 .CreateBuffer
= dri_create_buffer
,
947 .DestroyBuffer
= dri_destroy_buffer
,
948 .SwapBuffers
= dri_swap_buffers
,
949 .MakeCurrent
= dri_make_current
,
950 .UnbindContext
= dri_unbind_context
,
951 .CopySubBuffer
= dri_copy_sub_buffer
,
954 static const struct __DRIDriverVtableExtensionRec swrast_vtable
= {
955 .base
= { __DRI_DRIVER_VTABLE
, 1 },
956 .vtable
= &swrast_driver_api
,
959 static const __DRIextension
*swrast_driver_extensions
[] = {
960 &driCoreExtension
.base
,
961 &driSWRastExtension
.base
,
962 &driCopySubBufferExtension
.base
,
963 &dri2ConfigQueryExtension
.base
,
968 PUBLIC
const __DRIextension
**__driDriverGetExtensions_swrast(void)
970 globalDriverAPI
= &swrast_driver_api
;
972 return swrast_driver_extensions
;