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
,
211 &dri2ConfigQueryExtension
.base
,
212 &dri2NoErrorExtension
.base
,
216 static __DRIconfig
**
217 swrastFillInModes(__DRIscreen
*psp
,
218 unsigned pixel_bits
, unsigned depth_bits
,
219 unsigned stencil_bits
, GLboolean have_back_buffer
)
221 __DRIconfig
**configs
;
222 unsigned depth_buffer_factor
;
223 unsigned back_buffer_factor
;
226 static const GLenum back_buffer_modes
[] = {
227 __DRI_ATTRIB_SWAP_NONE
, __DRI_ATTRIB_SWAP_UNDEFINED
230 uint8_t depth_bits_array
[4];
231 uint8_t stencil_bits_array
[4];
232 uint8_t msaa_samples_array
[1];
235 (void) have_back_buffer
;
237 depth_bits_array
[0] = 0;
238 depth_bits_array
[1] = 0;
239 depth_bits_array
[2] = depth_bits
;
240 depth_bits_array
[3] = depth_bits
;
242 /* Just like with the accumulation buffer, always provide some modes
243 * with a stencil buffer.
245 stencil_bits_array
[0] = 0;
246 stencil_bits_array
[1] = (stencil_bits
== 0) ? 8 : stencil_bits
;
247 stencil_bits_array
[2] = 0;
248 stencil_bits_array
[3] = (stencil_bits
== 0) ? 8 : stencil_bits
;
250 msaa_samples_array
[0] = 0;
252 depth_buffer_factor
= 4;
253 back_buffer_factor
= 2;
255 switch (pixel_bits
) {
257 format
= MESA_FORMAT_B5G6R5_UNORM
;
260 format
= MESA_FORMAT_B8G8R8X8_UNORM
;
263 format
= MESA_FORMAT_B8G8R8A8_UNORM
;
266 fprintf(stderr
, "[%s:%u] bad depth %d\n", __func__
, __LINE__
,
271 configs
= driCreateConfigs(format
,
272 depth_bits_array
, stencil_bits_array
,
273 depth_buffer_factor
, back_buffer_modes
,
274 back_buffer_factor
, msaa_samples_array
, 1,
276 if (configs
== NULL
) {
277 fprintf(stderr
, "[%s:%u] Error creating FBConfig!\n", __func__
,
285 static const __DRIconfig
**
286 dri_init_screen(__DRIscreen
* psp
)
288 __DRIconfig
**configs16
, **configs24
, **configs32
;
292 psp
->max_gl_compat_version
= 21;
293 psp
->max_gl_es1_version
= 11;
294 psp
->max_gl_es2_version
= 20;
296 psp
->extensions
= dri_screen_extensions
;
298 configs16
= swrastFillInModes(psp
, 16, 16, 0, 1);
299 configs24
= swrastFillInModes(psp
, 24, 24, 8, 1);
300 configs32
= swrastFillInModes(psp
, 32, 24, 8, 1);
302 configs24
= driConcatConfigs(configs16
, configs24
);
303 configs32
= driConcatConfigs(configs24
, configs32
);
305 return (const __DRIconfig
**)configs32
;
309 dri_destroy_screen(__DRIscreen
* sPriv
)
317 * Framebuffer and renderbuffer-related functions.
321 choose_pixel_format(const struct gl_config
*v
)
323 int depth
= v
->rgbBits
;
326 && v
->redMask
== 0xff0000
327 && v
->greenMask
== 0x00ff00
328 && v
->blueMask
== 0x0000ff)
331 && v
->redMask
== 0xff0000
332 && v
->greenMask
== 0x00ff00
333 && v
->blueMask
== 0x0000ff)
336 && v
->redMask
== 0xf800
337 && v
->greenMask
== 0x07e0
338 && v
->blueMask
== 0x001f)
341 && v
->redMask
== 0x07
342 && v
->greenMask
== 0x38
343 && v
->blueMask
== 0xc0)
346 _mesa_problem( NULL
, "unexpected format in %s", __func__
);
351 swrast_delete_renderbuffer(struct gl_context
*ctx
, struct gl_renderbuffer
*rb
)
353 struct dri_swrast_renderbuffer
*xrb
= dri_swrast_renderbuffer(rb
);
357 free(xrb
->Base
.Buffer
);
358 _mesa_delete_renderbuffer(ctx
, rb
);
361 /* see bytes_per_line in libGL */
363 bytes_per_line(unsigned pitch_bits
, unsigned mul
)
365 unsigned mask
= mul
- 1;
367 return ((pitch_bits
+ mask
) & ~mask
) / 8;
371 swrast_alloc_front_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
);
379 (void) internalFormat
;
381 xrb
->Base
.Buffer
= NULL
;
384 xrb
->pitch
= bytes_per_line(width
* xrb
->bpp
, 32);
390 swrast_alloc_back_storage(struct gl_context
*ctx
, struct gl_renderbuffer
*rb
,
391 GLenum internalFormat
, GLuint width
, GLuint height
)
393 struct dri_swrast_renderbuffer
*xrb
= dri_swrast_renderbuffer(rb
);
397 free(xrb
->Base
.Buffer
);
399 swrast_alloc_front_storage(ctx
, rb
, internalFormat
, width
, height
);
401 xrb
->Base
.Buffer
= malloc(height
* xrb
->pitch
);
406 static struct dri_swrast_renderbuffer
*
407 swrast_new_renderbuffer(const struct gl_config
*visual
, __DRIdrawable
*dPriv
,
410 struct dri_swrast_renderbuffer
*xrb
= calloc(1, sizeof *xrb
);
411 struct gl_renderbuffer
*rb
;
419 rb
= &xrb
->Base
.Base
;
421 _mesa_init_renderbuffer(rb
, 0);
423 pixel_format
= choose_pixel_format(visual
);
426 xrb
->Base
.Base
.Delete
= swrast_delete_renderbuffer
;
428 rb
->AllocStorage
= swrast_alloc_front_storage
;
431 rb
->AllocStorage
= swrast_alloc_back_storage
;
434 switch (pixel_format
) {
436 rb
->Format
= MESA_FORMAT_B8G8R8A8_UNORM
;
437 rb
->InternalFormat
= GL_RGBA
;
438 rb
->_BaseFormat
= GL_RGBA
;
442 rb
->Format
= MESA_FORMAT_B8G8R8A8_UNORM
; /* XXX */
443 rb
->InternalFormat
= GL_RGB
;
444 rb
->_BaseFormat
= GL_RGB
;
448 rb
->Format
= MESA_FORMAT_B5G6R5_UNORM
;
449 rb
->InternalFormat
= GL_RGB
;
450 rb
->_BaseFormat
= GL_RGB
;
454 rb
->Format
= MESA_FORMAT_B2G3R3_UNORM
;
455 rb
->InternalFormat
= GL_RGB
;
456 rb
->_BaseFormat
= GL_RGB
;
468 swrast_map_renderbuffer(struct gl_context
*ctx
,
469 struct gl_renderbuffer
*rb
,
470 GLuint x
, GLuint y
, GLuint w
, GLuint h
,
475 struct dri_swrast_renderbuffer
*xrb
= dri_swrast_renderbuffer(rb
);
476 GLubyte
*map
= xrb
->Base
.Buffer
;
477 int cpp
= _mesa_get_format_bytes(rb
->Format
);
478 int stride
= rb
->Width
* cpp
;
480 if (rb
->AllocStorage
== swrast_alloc_front_storage
) {
481 __DRIdrawable
*dPriv
= xrb
->dPriv
;
482 __DRIscreen
*sPriv
= dPriv
->driScreenPriv
;
484 xrb
->map_mode
= mode
;
486 xrb
->map_y
= rb
->Height
- y
- h
;
491 xrb
->Base
.Buffer
= malloc(h
* stride
);
493 sPriv
->swrast_loader
->getImage(dPriv
, x
, xrb
->map_y
, w
, h
,
494 (char *) xrb
->Base
.Buffer
,
495 dPriv
->loaderPrivate
);
497 *out_map
= xrb
->Base
.Buffer
+ (h
- 1) * stride
;
498 *out_stride
= -stride
;
502 assert(xrb
->Base
.Buffer
);
504 if (rb
->AllocStorage
== swrast_alloc_back_storage
) {
505 map
+= (rb
->Height
- 1) * stride
;
509 map
+= (GLsizei
)y
* stride
;
510 map
+= (GLsizei
)x
* cpp
;
513 *out_stride
= stride
;
517 swrast_unmap_renderbuffer(struct gl_context
*ctx
,
518 struct gl_renderbuffer
*rb
)
520 struct dri_swrast_renderbuffer
*xrb
= dri_swrast_renderbuffer(rb
);
522 if (rb
->AllocStorage
== swrast_alloc_front_storage
) {
523 __DRIdrawable
*dPriv
= xrb
->dPriv
;
524 __DRIscreen
*sPriv
= dPriv
->driScreenPriv
;
526 if (xrb
->map_mode
& GL_MAP_WRITE_BIT
) {
527 sPriv
->swrast_loader
->putImage(dPriv
, __DRI_SWRAST_IMAGE_OP_DRAW
,
528 xrb
->map_x
, xrb
->map_y
,
529 xrb
->map_w
, xrb
->map_h
,
530 (char *) xrb
->Base
.Buffer
,
531 dPriv
->loaderPrivate
);
534 free(xrb
->Base
.Buffer
);
535 xrb
->Base
.Buffer
= NULL
;
540 dri_create_buffer(__DRIscreen
* sPriv
,
541 __DRIdrawable
* dPriv
,
542 const struct gl_config
* visual
, GLboolean isPixmap
)
544 struct dri_drawable
*drawable
= NULL
;
545 struct gl_framebuffer
*fb
;
546 struct dri_swrast_renderbuffer
*frontrb
, *backrb
;
553 drawable
= CALLOC_STRUCT(dri_drawable
);
554 if (drawable
== NULL
)
557 dPriv
->driverPrivate
= drawable
;
558 drawable
->dPriv
= dPriv
;
560 drawable
->row
= malloc(SWRAST_MAX_WIDTH
* 4);
561 if (drawable
->row
== NULL
)
564 fb
= &drawable
->Base
;
566 /* basic framebuffer setup */
567 _mesa_initialize_window_framebuffer(fb
, visual
);
569 /* add front renderbuffer */
570 frontrb
= swrast_new_renderbuffer(visual
, dPriv
, GL_TRUE
);
571 _mesa_attach_and_own_rb(fb
, BUFFER_FRONT_LEFT
, &frontrb
->Base
.Base
);
573 /* add back renderbuffer */
574 if (visual
->doubleBufferMode
) {
575 backrb
= swrast_new_renderbuffer(visual
, dPriv
, GL_FALSE
);
576 _mesa_attach_and_own_rb(fb
, BUFFER_BACK_LEFT
, &backrb
->Base
.Base
);
579 /* add software renderbuffers */
580 _swrast_add_soft_renderbuffers(fb
,
581 GL_FALSE
, /* color */
582 visual
->haveDepthBuffer
,
583 visual
->haveStencilBuffer
,
584 visual
->haveAccumBuffer
,
585 GL_FALSE
, /* alpha */
586 GL_FALSE
/* aux bufs */);
601 dri_destroy_buffer(__DRIdrawable
* dPriv
)
606 struct dri_drawable
*drawable
= dri_drawable(dPriv
);
607 struct gl_framebuffer
*fb
;
611 fb
= &drawable
->Base
;
613 fb
->DeletePending
= GL_TRUE
;
614 _mesa_reference_framebuffer(&fb
, NULL
);
619 dri_swap_buffers(__DRIdrawable
* dPriv
)
621 __DRIscreen
*sPriv
= dPriv
->driScreenPriv
;
623 GET_CURRENT_CONTEXT(ctx
);
625 struct dri_drawable
*drawable
= dri_drawable(dPriv
);
626 struct gl_framebuffer
*fb
;
627 struct dri_swrast_renderbuffer
*frontrb
, *backrb
;
631 fb
= &drawable
->Base
;
634 dri_swrast_renderbuffer(fb
->Attachment
[BUFFER_FRONT_LEFT
].Renderbuffer
);
636 dri_swrast_renderbuffer(fb
->Attachment
[BUFFER_BACK_LEFT
].Renderbuffer
);
638 /* check for signle-buffered */
642 /* check if swapping currently bound buffer */
643 if (ctx
&& ctx
->DrawBuffer
== fb
) {
644 /* flush pending rendering */
645 _mesa_notifySwapBuffers(ctx
);
648 sPriv
->swrast_loader
->putImage(dPriv
, __DRI_SWRAST_IMAGE_OP_SWAP
,
650 frontrb
->Base
.Base
.Width
,
651 frontrb
->Base
.Base
.Height
,
652 (char *) backrb
->Base
.Buffer
,
653 dPriv
->loaderPrivate
);
658 * General device driver functions.
662 get_window_size( struct gl_framebuffer
*fb
, GLsizei
*w
, GLsizei
*h
)
664 __DRIdrawable
*dPriv
= swrast_drawable(fb
)->dPriv
;
665 __DRIscreen
*sPriv
= dPriv
->driScreenPriv
;
668 sPriv
->swrast_loader
->getDrawableInfo(dPriv
,
670 dPriv
->loaderPrivate
);
674 swrast_check_and_update_window_size( struct gl_context
*ctx
, struct gl_framebuffer
*fb
)
676 GLsizei width
, height
;
678 get_window_size(fb
, &width
, &height
);
679 if (fb
->Width
!= width
|| fb
->Height
!= height
) {
680 _mesa_resize_framebuffer(ctx
, fb
, width
, height
);
684 static const GLubyte
*
685 get_string(struct gl_context
*ctx
, GLenum pname
)
690 return (const GLubyte
*) swrast_vendor_string
;
692 return (const GLubyte
*) swrast_renderer_string
;
699 update_state(struct gl_context
*ctx
)
701 GLuint new_state
= ctx
->NewState
;
703 if (new_state
& (_NEW_SCISSOR
| _NEW_BUFFERS
| _NEW_VIEWPORT
))
704 _mesa_update_draw_buffer_bounds(ctx
, ctx
->DrawBuffer
);
706 /* not much to do here - pass it on */
707 _swrast_InvalidateState( ctx
, new_state
);
708 _swsetup_InvalidateState( ctx
, new_state
);
709 _tnl_InvalidateState( ctx
, new_state
);
713 viewport(struct gl_context
*ctx
)
715 struct gl_framebuffer
*draw
= ctx
->WinSysDrawBuffer
;
716 struct gl_framebuffer
*read
= ctx
->WinSysReadBuffer
;
718 swrast_check_and_update_window_size(ctx
, draw
);
719 swrast_check_and_update_window_size(ctx
, read
);
722 static mesa_format
swrastChooseTextureFormat(struct gl_context
* ctx
,
724 GLint internalFormat
,
728 if (internalFormat
== GL_RGB
)
729 return MESA_FORMAT_B8G8R8X8_UNORM
;
730 return _mesa_choose_tex_format(ctx
, target
, internalFormat
, format
, type
);
734 swrast_init_driver_functions(struct dd_function_table
*driver
)
736 driver
->GetString
= get_string
;
737 driver
->UpdateState
= update_state
;
738 driver
->Viewport
= viewport
;
739 driver
->ChooseTextureFormat
= swrastChooseTextureFormat
;
740 driver
->MapRenderbuffer
= swrast_map_renderbuffer
;
741 driver
->UnmapRenderbuffer
= swrast_unmap_renderbuffer
;
745 * Context-related functions.
749 dri_create_context(gl_api api
,
750 const struct gl_config
* visual
,
751 __DRIcontext
* cPriv
,
752 const struct __DriverContextConfig
*ctx_config
,
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.
766 (void) ctx_config
->flags
;
768 /* The swrast driver doesn't understand any of the attributes */
769 if (ctx_config
->attribute_mask
!= 0) {
770 *error
= __DRI_CTX_ERROR_UNKNOWN_ATTRIBUTE
;
774 ctx
= CALLOC_STRUCT(dri_context
);
776 *error
= __DRI_CTX_ERROR_NO_MEMORY
;
780 cPriv
->driverPrivate
= ctx
;
783 /* build table of device driver functions */
784 _mesa_init_driver_functions(&functions
);
785 swrast_init_driver_functions(&functions
);
788 sharedCtx
= &share
->Base
;
791 mesaCtx
= &ctx
->Base
;
793 /* basic context setup */
794 if (!_mesa_initialize_context(mesaCtx
, api
, visual
, sharedCtx
, &functions
)) {
795 *error
= __DRI_CTX_ERROR_NO_MEMORY
;
799 driContextSetFlags(mesaCtx
, ctx_config
->flags
);
801 /* create module contexts */
802 _swrast_CreateContext( mesaCtx
);
803 _vbo_CreateContext( mesaCtx
);
804 _tnl_CreateContext( mesaCtx
);
805 _swsetup_CreateContext( mesaCtx
);
806 _swsetup_Wakeup( mesaCtx
);
808 /* use default TCL pipeline */
810 TNLcontext
*tnl
= TNL_CONTEXT(mesaCtx
);
811 tnl
->Driver
.RunPipeline
= _tnl_run_pipeline
;
814 _mesa_meta_init(mesaCtx
);
815 _mesa_enable_sw_extensions(mesaCtx
);
817 _mesa_override_extensions(mesaCtx
);
818 _mesa_compute_version(mesaCtx
);
820 _mesa_initialize_dispatch_tables(mesaCtx
);
821 _mesa_initialize_vbo_vtxfmt(mesaCtx
);
823 *error
= __DRI_CTX_ERROR_SUCCESS
;
834 dri_destroy_context(__DRIcontext
* cPriv
)
839 struct dri_context
*ctx
= dri_context(cPriv
);
840 struct gl_context
*mesaCtx
;
842 mesaCtx
= &ctx
->Base
;
844 _mesa_meta_free(mesaCtx
);
845 _swsetup_DestroyContext( mesaCtx
);
846 _swrast_DestroyContext( mesaCtx
);
847 _tnl_DestroyContext( mesaCtx
);
848 _vbo_DestroyContext( mesaCtx
);
849 _mesa_destroy_context( mesaCtx
);
854 dri_make_current(__DRIcontext
* cPriv
,
855 __DRIdrawable
* driDrawPriv
,
856 __DRIdrawable
* driReadPriv
)
858 struct gl_context
*mesaCtx
;
859 struct gl_framebuffer
*mesaDraw
;
860 struct gl_framebuffer
*mesaRead
;
864 struct dri_context
*ctx
= dri_context(cPriv
);
865 struct dri_drawable
*draw
;
866 struct dri_drawable
*read
;
868 if (!driDrawPriv
|| !driReadPriv
)
871 draw
= dri_drawable(driDrawPriv
);
872 read
= dri_drawable(driReadPriv
);
873 mesaCtx
= &ctx
->Base
;
874 mesaDraw
= &draw
->Base
;
875 mesaRead
= &read
->Base
;
877 /* check for same context and buffer */
878 if (mesaCtx
== _mesa_get_current_context()
879 && mesaCtx
->DrawBuffer
== mesaDraw
880 && mesaCtx
->ReadBuffer
== mesaRead
) {
884 _glapi_check_multithread();
886 swrast_check_and_update_window_size(mesaCtx
, mesaDraw
);
887 if (mesaRead
!= mesaDraw
)
888 swrast_check_and_update_window_size(mesaCtx
, mesaRead
);
890 _mesa_make_current( mesaCtx
,
896 _mesa_make_current( NULL
, NULL
, NULL
);
903 dri_unbind_context(__DRIcontext
* cPriv
)
908 /* Unset current context and dispath table */
909 _mesa_make_current(NULL
, NULL
, NULL
);
915 dri_copy_sub_buffer(__DRIdrawable
*dPriv
, int x
, int y
,
918 __DRIscreen
*sPriv
= dPriv
->driScreenPriv
;
921 struct dri_drawable
*drawable
= dri_drawable(dPriv
);
922 struct gl_framebuffer
*fb
;
923 struct dri_swrast_renderbuffer
*frontrb
, *backrb
;
927 fb
= &drawable
->Base
;
930 dri_swrast_renderbuffer(fb
->Attachment
[BUFFER_FRONT_LEFT
].Renderbuffer
);
932 dri_swrast_renderbuffer(fb
->Attachment
[BUFFER_BACK_LEFT
].Renderbuffer
);
934 /* check for signle-buffered */
938 iy
= frontrb
->Base
.Base
.Height
- y
- h
;
939 data
= (char *)backrb
->Base
.Buffer
+ (iy
* backrb
->pitch
) + (x
* ((backrb
->bpp
+ 7) / 8));
940 sPriv
->swrast_loader
->putImage2(dPriv
, __DRI_SWRAST_IMAGE_OP_SWAP
,
944 dPriv
->loaderPrivate
);
948 static const struct __DriverAPIRec swrast_driver_api
= {
949 .InitScreen
= dri_init_screen
,
950 .DestroyScreen
= dri_destroy_screen
,
951 .CreateContext
= dri_create_context
,
952 .DestroyContext
= dri_destroy_context
,
953 .CreateBuffer
= dri_create_buffer
,
954 .DestroyBuffer
= dri_destroy_buffer
,
955 .SwapBuffers
= dri_swap_buffers
,
956 .MakeCurrent
= dri_make_current
,
957 .UnbindContext
= dri_unbind_context
,
958 .CopySubBuffer
= dri_copy_sub_buffer
,
961 static const struct __DRIDriverVtableExtensionRec swrast_vtable
= {
962 .base
= { __DRI_DRIVER_VTABLE
, 1 },
963 .vtable
= &swrast_driver_api
,
966 static const __DRIextension
*swrast_driver_extensions
[] = {
967 &driCoreExtension
.base
,
968 &driSWRastExtension
.base
,
969 &driCopySubBufferExtension
.base
,
974 PUBLIC
const __DRIextension
**__driDriverGetExtensions_swrast(void)
976 globalDriverAPI
= &swrast_driver_api
;
978 return swrast_driver_extensions
;