summaryrefslogtreecommitdiff
path: root/src/mesa/drivers/dri/glamo/glamo_context.c
blob: f3c1dd32b8a7760cc9740e42199cd07a7e921088 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
/*
 * Direct Rendering Support for SMedia Glamo 336x/337x
 *
 * (c) 2009 Thomas White <taw@bitwiz.org.uk>
 * Roughly based on sis_context.c (c) 2003 Eric Anholt
 *              and radeon_common_context.c
 *
 * Permission is hereby granted, free of charge, to any person obtaining a
 * copy of this software and associated documentation files (the "Software"),
 * to deal in the Software without restriction, including without limitation
 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
 * and/or sell copies of the Software, and to permit persons to whom the
 * Software is furnished to do so, subject to the following conditions:
 *
 * The above copyright notice and this permission notice shall be included
 * in all copies or substantial portions of the Software.
 *
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
 * THE AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
 * AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
 * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
 */


#include "dri_util.h"
#include "utils.h"
#include "swrast/swrast.h"
#include "swrast_setup/swrast_setup.h"
#include "drivers/common/driverfuncs.h"
#include "vbo/vbo.h"
#include "tnl/tnl.h"
#include "tnl/t_pipeline.h"
#include "main/state.h"

#include "glamo_context.h"
#include "glamo_screen.h"
#include "glamo_state.h"
#include "glamo_fbo.h"
#include "glamo_tris.h"


#define DRIVER_DATE  "20090402"


static const GLubyte *glamoGetString(GLcontext *ctx, GLenum name)
{
   static char buffer[128];

   switch (name) {
      case GL_VENDOR:
         return (GLubyte *)"Thomas White";
      case GL_RENDERER: {
         driGetRendererString(buffer, "glamo", DRIVER_DATE, 0);
         return (GLubyte *) buffer;
      }
      default:
         return 0;
   }
}


/* Called when Mesa needs to know the size of the framebuffer */
static void glamoBufferSize(GLframebuffer *buffer,
                            GLuint *width, GLuint *height)
{
   GET_CURRENT_CONTEXT(ctx);
   glamoContextPtr glamo = GLAMO_CONTEXT(ctx);

   *width = glamo->driDrawable->w;
   *height = glamo->driDrawable->h;
}


GLboolean glamoCreateContext(const __GLcontextModes *glVisual,
                             __DRIcontext *driContextPriv,
                             void *sharedContextPrivate)
{
   GLcontext *ctx, *shareCtx;
   __DRIscreenPrivate *sPriv = driContextPriv->driScreenPriv;
   glamoContextPtr context;
   glamoScreenPtr glamoScreen;
   struct dd_function_table functions;

   context = (glamoContextPtr)CALLOC(sizeof(*context));
   if ( context == NULL ) return GL_FALSE;

   _mesa_init_driver_functions(&functions);

   /* Allocate the Mesa context */
   if ( sharedContextPrivate )
      shareCtx = ((glamoContextPtr)sharedContextPrivate)->glCtx;
   else
      shareCtx = NULL;
   context->glCtx = _mesa_create_context(glVisual, shareCtx,
                                        &functions, (void *)context);
   if ( context->glCtx == NULL ) {
      FREE(context);
      return GL_FALSE;
   }
   driContextPriv->driverPrivate = context;
   ctx = context->glCtx;

   glamoScreen = context->glamoScreen = (glamoScreenPtr)sPriv->private;

   ctx->Driver.GetString = glamoGetString;
   ctx->Driver.GetBufferSize = glamoBufferSize;

   context->driContext = driContextPriv;
   context->driScreen = sPriv;
   context->driDrawable = NULL;
   context->driFd = sPriv->fd;

   /* Initialize the software rasterizer and helper modules. */
   _swrast_CreateContext(ctx);
   _vbo_CreateContext(ctx);
   _tnl_CreateContext(ctx);
   _swsetup_CreateContext(ctx);

    /* use default TCL pipeline */
    {
      TNLcontext *tnl = TNL_CONTEXT(ctx);
      tnl->Driver.RunPipeline = _tnl_run_pipeline;
    }

   _swrast_allow_pixel_fog(ctx, GL_TRUE);
   _swrast_allow_vertex_fog(ctx, GL_FALSE);
   _tnl_allow_pixel_fog(ctx, GL_TRUE);
   _tnl_allow_vertex_fog(ctx, GL_FALSE);

   glamoInitStateFuncs(ctx);
   glamoInitTriFuncs(ctx);

   return GL_TRUE;
}


void glamoDestroyContext(__DRIcontext *driContextPriv)
{
   glamoContextPtr context;

   context = (glamoContextPtr)driContextPriv->driverPrivate;
   assert(context != NULL);

   if ( context != NULL ) {

      _swsetup_DestroyContext(context->glCtx);
      _tnl_DestroyContext(context->glCtx);
      _vbo_DestroyContext(context->glCtx);
      _swrast_DestroyContext(context->glCtx);

      _mesa_destroy_context(context->glCtx);

   }

   FREE(context);
}


static void glamo_update_renderbuffers(__DRIcontext *context,
                                       __DRIdrawable *drawable)
{
   unsigned int attachments[10];
   __DRIbuffer *buffers;
   __DRIscreen *screen;
   struct glamo_renderbuffer *grb;
   int i, count;
   struct glamo_framebuffer *draw;
   glamoContextPtr glamo;
   char *regname;

   fprintf(stderr, "enter %s, drawable %p\n", __func__, drawable);

   draw = drawable->driverPrivate;
   screen = context->driScreenPriv;
   glamo = (glamoContextPtr)context->driverPrivate;
   i = 0;
   if ( draw->color_rb[0] )
	   attachments[i++] = __DRI_BUFFER_FRONT_LEFT;
   if ( draw->color_rb[1] )
	   attachments[i++] = __DRI_BUFFER_BACK_LEFT;
printf("screen = %p\n", screen); fflush(stdout);
printf("screen->dri2.loader = %p\n", screen->dri2.loader); fflush(stdout);
printf("screen->dri2.loader->getBuffers = %p\n", screen->dri2.loader->getBuffers); fflush(stdout);
   buffers = (*screen->dri2.loader->getBuffers)(drawable,
					        &drawable->w,
					        &drawable->h,
					        attachments, i,
					        &count,
					        drawable->loaderPrivate);
printf("b\n"); fflush(stdout);
   if (buffers == NULL) return;
printf("c\n"); fflush(stdout);

   printf("%i, %i\n", drawable->w, drawable->h);
}


GLboolean glamoMakeCurrent(__DRIcontext *driContextPriv,
                                  __DRIdrawable *driDrawPriv,
                                  __DRIdrawable *driReadPriv)
{
   struct glamo_framebuffer *draw_fb;
   struct gl_framebuffer *read_fb;
   glamoContextPtr glamo;

   printf("glamoMakeCurrent\n"); fflush(stdout);

   if ( driContextPriv == NULL ) {
      _mesa_make_current(NULL, NULL, NULL);
      return GL_TRUE;
   }

   /* The Glamo context we're switching to */
   glamo = (glamoContextPtr)driContextPriv->driverPrivate;

   glamo->driDrawable = driDrawPriv;

   /* These two will probably be the same */
   draw_fb = (struct glamo_framebuffer *)driDrawPriv->driverPrivate;
   read_fb = (struct gl_framebuffer *)driReadPriv->driverPrivate;

   glamo_update_renderbuffers(driContextPriv, driDrawPriv);
   if (driDrawPriv != driReadPriv)
      glamo_update_renderbuffers(driContextPriv, driReadPriv);

printf("%p %p %p %p\n", glamo->glCtx, draw_fb, &draw_fb->base, read_fb);
fflush(stdout);
    _mesa_make_current(glamo->glCtx, &draw_fb->base, read_fb);
printf("BBB\n"); fflush(stdout);
    _mesa_update_state(glamo->glCtx);
printf("done\n"); fflush(stdout);

   return GL_TRUE;
}


GLboolean glamoUnbindContext(__DRIcontext *driContextPriv)
{
   return GL_TRUE;
}

/* kate: space-indent on; indent-width 3; mixedindent off; indent-mode cstyle; */