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
|
/**************************************************************************
*
* Copyright 2009, VMware, Inc.
* All Rights Reserved.
*
* 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, sub license, 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 (including the
* next paragraph) 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 NON-INFRINGEMENT.
* IN NO EVENT SHALL VMWARE AND/OR ITS SUPPLIERS 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.
*
**************************************************************************/
/*
* Author: Keith Whitwell <keithw@vmware.com>
* Author: Jakob Bornecrantz <wallbraker@gmail.com>
*/
#include "dri_screen.h"
#include "dri_drawable.h"
#include "state_tracker/drm_api.h"
#include "state_tracker/dri1_api.h"
#include "state_tracker/st_public.h"
#include "state_tracker/st_context.h"
#include "pipe/p_context.h"
#include "dri_context.h"
#include "util/u_memory.h"
GLboolean
dri_create_context(const __GLcontextModes * visual,
__DRIcontextPrivate * cPriv, void *sharedContextPrivate)
{
__DRIscreenPrivate *sPriv = cPriv->driScreenPriv;
struct dri_screen *screen = dri_screen(sPriv);
struct dri_context *ctx = NULL;
struct st_context *st_share = NULL;
if (sharedContextPrivate) {
st_share = ((struct dri_context *)sharedContextPrivate)->st;
}
ctx = CALLOC_STRUCT(dri_context);
if (ctx == NULL)
goto fail;
cPriv->driverPrivate = ctx;
ctx->cPriv = cPriv;
ctx->sPriv = sPriv;
ctx->lock = screen->drmLock;
ctx->d_stamp = -1;
ctx->r_stamp = -1;
driParseConfigFiles(&ctx->optionCache,
&screen->optionCache, sPriv->myNum, "dri");
ctx->pipe = drm_api_hooks.create_context(screen->pipe_screen);
if (ctx->pipe == NULL)
goto fail;
/* used in dri_flush_frontbuffer */
ctx->pipe->priv = ctx;
ctx->st = st_create_context(ctx->pipe, visual, st_share);
if (ctx->st == NULL)
goto fail;
dri_init_extensions(ctx);
return GL_TRUE;
fail:
if (ctx && ctx->st)
st_destroy_context(ctx->st);
if (ctx && ctx->pipe)
ctx->pipe->destroy(ctx->pipe);
FREE(ctx);
return FALSE;
}
void
dri_destroy_context(__DRIcontextPrivate * cPriv)
{
struct dri_context *ctx = dri_context(cPriv);
struct dri_screen *screen = dri_screen(cPriv->driScreenPriv);
/* No particular reason to wait for command completion before
* destroying a context, but it is probably worthwhile flushing it
* to avoid having to add code elsewhere to cope with flushing a
* partially destroyed context.
*/
st_flush(ctx->st, 0, NULL);
if (screen->dummyContext == ctx)
screen->dummyContext = NULL;
/* Also frees ctx->pipe?
*/
st_destroy_context(ctx->st);
FREE(ctx);
}
GLboolean
dri_unbind_context(__DRIcontextPrivate * cPriv)
{
if (cPriv) {
struct dri_context *ctx = dri_context(cPriv);
if (--ctx->bind_count == 0) {
GET_CURRENT_CONTEXT(curGLCtx);
if (ctx->st == curGLCtx->st) {
st_flush(ctx->st, PIPE_FLUSH_RENDER_CACHE, NULL);
st_make_current(NULL, NULL, NULL);
}
}
}
return GL_TRUE;
}
GLboolean
dri_make_current(__DRIcontextPrivate * cPriv,
__DRIdrawablePrivate * driDrawPriv,
__DRIdrawablePrivate * driReadPriv)
{
if (cPriv) {
struct dri_context *ctx = dri_context(cPriv);
struct dri_screen *screen = dri_screen(cPriv->driScreenPriv);
struct dri_drawable *draw = dri_drawable(driDrawPriv);
struct dri_drawable *read = dri_drawable(driReadPriv);
GET_CURRENT_CONTEXT(oldGLCtx);
if (oldGLCtx && oldGLCtx->st != ctx->st)
st_flush(oldGLCtx->st, PIPE_FLUSH_RENDER_CACHE, NULL);
++ctx->bind_count;
/* This is for situations in which we need a rendering context but
* there may not be any currently bound.
*/
screen->dummyContext = ctx;
/* used in dri_flush_frontbuffer */
ctx->dPriv = driDrawPriv;
ctx->rPriv = driReadPriv;
st_make_current(ctx->st, draw->stfb, read->stfb);
if (__dri1_api_hooks) {
dri1_update_drawables(ctx, draw, read);
} else {
if (driDrawPriv)
dri_get_buffers(driDrawPriv);
if (driDrawPriv != driReadPriv && driReadPriv)
dri_get_buffers(driReadPriv);
}
} else {
st_make_current(NULL, NULL, NULL);
}
return GL_TRUE;
}
static void
st_dri_lock(struct pipe_context *pipe)
{
dri_lock((struct dri_context *)pipe->priv);
}
static void
st_dri_unlock(struct pipe_context *pipe)
{
dri_unlock((struct dri_context *)pipe->priv);
}
static boolean
st_dri_is_locked(struct pipe_context *pipe)
{
return ((struct dri_context *)pipe->priv)->isLocked;
}
static boolean
st_dri_lost_lock(struct pipe_context *pipe)
{
return ((struct dri_context *)pipe->priv)->wsLostLock;
}
static void
st_dri_clear_lost_lock(struct pipe_context *pipe)
{
((struct dri_context *)pipe->priv)->wsLostLock = FALSE;
}
struct dri1_api_lock_funcs dri1_lf = {
.lock = st_dri_lock,
.unlock = st_dri_unlock,
.is_locked = st_dri_is_locked,
.is_lock_lost = st_dri_lost_lock,
.clear_lost_lock = st_dri_clear_lost_lock
};
/* vim: set sw=3 ts=8 sts=3 expandtab: */
|