~mmach/netext73/mesa-haswell

« back to all changes in this revision

Viewing changes to src/mesa/main/objectpurge.c

  • Committer: mmach
  • Date: 2022-09-22 19:56:13 UTC
  • Revision ID: netbit73@gmail.com-20220922195613-wtik9mmy20tmor0i
2022-09-22 21:17:09

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/*
2
 
 * Mesa 3-D graphics library
3
 
 *
4
 
 * Copyright (C) 1999-2008  Brian Paul   All Rights Reserved.
5
 
 * Copyright (C) 2009  VMware, Inc.  All Rights Reserved.
6
 
 *
7
 
 * Permission is hereby granted, free of charge, to any person obtaining a
8
 
 * copy of this software and associated documentation files (the "Software"),
9
 
 * to deal in the Software without restriction, including without limitation
10
 
 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
11
 
 * and/or sell copies of the Software, and to permit persons to whom the
12
 
 * Software is furnished to do so, subject to the following conditions:
13
 
 *
14
 
 * The above copyright notice and this permission notice shall be included
15
 
 * in all copies or substantial portions of the Software.
16
 
 *
17
 
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
18
 
 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19
 
 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
20
 
 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR
21
 
 * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
22
 
 * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
23
 
 * OTHER DEALINGS IN THE SOFTWARE.
24
 
 */
25
 
 
26
 
/**
27
 
 * Code related to the GL_APPLE_object_purgeable extension.
28
 
 */
29
 
 
30
 
 
31
 
#include "glheader.h"
32
 
#include "enums.h"
33
 
#include "hash.h"
34
 
 
35
 
#include "context.h"
36
 
#include "bufferobj.h"
37
 
#include "fbobject.h"
38
 
#include "mtypes.h"
39
 
#include "texobj.h"
40
 
#include "teximage.h"
41
 
#include "api_exec_decl.h"
42
 
 
43
 
 
44
 
static GLenum
45
 
buffer_object_purgeable(struct gl_context *ctx, GLuint name, GLenum option)
46
 
{
47
 
   struct gl_buffer_object *bufObj;
48
 
   GLenum retval;
49
 
 
50
 
   bufObj = _mesa_lookup_bufferobj(ctx, name);
51
 
   if (!bufObj) {
52
 
      _mesa_error(ctx, GL_INVALID_VALUE,
53
 
                  "glObjectPurgeable(name = 0x%x)", name);
54
 
      return 0;
55
 
   }
56
 
 
57
 
   if (bufObj->Purgeable) {
58
 
      _mesa_error(ctx, GL_INVALID_OPERATION,
59
 
                  "glObjectPurgeable(name = 0x%x) is already purgeable", name);
60
 
      return GL_VOLATILE_APPLE;
61
 
   }
62
 
 
63
 
   bufObj->Purgeable = GL_TRUE;
64
 
 
65
 
   retval = GL_VOLATILE_APPLE;
66
 
 
67
 
   return retval;
68
 
}
69
 
 
70
 
 
71
 
static GLenum
72
 
renderbuffer_purgeable(struct gl_context *ctx, GLuint name, GLenum option)
73
 
{
74
 
   struct gl_renderbuffer *bufObj;
75
 
   GLenum retval;
76
 
 
77
 
   bufObj = _mesa_lookup_renderbuffer(ctx, name);
78
 
   if (!bufObj) {
79
 
      _mesa_error(ctx, GL_INVALID_VALUE,
80
 
                  "glObjectUnpurgeable(name = 0x%x)", name);
81
 
      return 0;
82
 
   }
83
 
 
84
 
   if (bufObj->Purgeable) {
85
 
      _mesa_error(ctx, GL_INVALID_OPERATION,
86
 
                  "glObjectPurgeable(name = 0x%x) is already purgeable", name);
87
 
      return GL_VOLATILE_APPLE;
88
 
   }
89
 
 
90
 
   bufObj->Purgeable = GL_TRUE;
91
 
 
92
 
   retval = GL_VOLATILE_APPLE;
93
 
 
94
 
   return retval;
95
 
}
96
 
 
97
 
 
98
 
static GLenum
99
 
texture_object_purgeable(struct gl_context *ctx, GLuint name, GLenum option)
100
 
{
101
 
   struct gl_texture_object *bufObj;
102
 
   GLenum retval;
103
 
 
104
 
   bufObj = _mesa_lookup_texture(ctx, name);
105
 
   if (!bufObj) {
106
 
      _mesa_error(ctx, GL_INVALID_VALUE,
107
 
                  "glObjectPurgeable(name = 0x%x)", name);
108
 
      return 0;
109
 
   }
110
 
 
111
 
   if (bufObj->Purgeable) {
112
 
      _mesa_error(ctx, GL_INVALID_OPERATION,
113
 
                  "glObjectPurgeable(name = 0x%x) is already purgeable", name);
114
 
      return GL_VOLATILE_APPLE;
115
 
   }
116
 
 
117
 
   bufObj->Purgeable = GL_TRUE;
118
 
 
119
 
   retval = GL_VOLATILE_APPLE;
120
 
 
121
 
   return retval;
122
 
}
123
 
 
124
 
 
125
 
GLenum GLAPIENTRY
126
 
_mesa_ObjectPurgeableAPPLE(GLenum objectType, GLuint name, GLenum option)
127
 
{
128
 
   GLenum retval;
129
 
 
130
 
   GET_CURRENT_CONTEXT(ctx);
131
 
   ASSERT_OUTSIDE_BEGIN_END_WITH_RETVAL(ctx, 0);
132
 
 
133
 
   if (name == 0) {
134
 
      _mesa_error(ctx, GL_INVALID_VALUE,
135
 
                  "glObjectPurgeable(name = 0x%x)", name);
136
 
      return 0;
137
 
   }
138
 
 
139
 
   switch (option) {
140
 
   case GL_VOLATILE_APPLE:
141
 
   case GL_RELEASED_APPLE:
142
 
      /* legal */
143
 
      break;
144
 
   default:
145
 
      _mesa_error(ctx, GL_INVALID_ENUM,
146
 
                  "glObjectPurgeable(name = 0x%x) invalid option: %d",
147
 
                  name, option);
148
 
      return 0;
149
 
   }
150
 
 
151
 
   switch (objectType) {
152
 
   case GL_TEXTURE:
153
 
      retval = texture_object_purgeable(ctx, name, option);
154
 
      break;
155
 
   case GL_RENDERBUFFER_EXT:
156
 
      retval = renderbuffer_purgeable(ctx, name, option);
157
 
      break;
158
 
   case GL_BUFFER_OBJECT_APPLE:
159
 
      retval = buffer_object_purgeable(ctx, name, option);
160
 
      break;
161
 
   default:
162
 
      _mesa_error(ctx, GL_INVALID_ENUM,
163
 
                  "glObjectPurgeable(name = 0x%x) invalid type: %d",
164
 
                  name, objectType);
165
 
      return 0;
166
 
   }
167
 
 
168
 
   /* In strict conformance to the spec, we must only return VOLATILE when
169
 
    * when passed the VOLATILE option. Madness.
170
 
    *
171
 
    * XXX First fix the spec, then fix me.
172
 
    */
173
 
   return option == GL_VOLATILE_APPLE ? GL_VOLATILE_APPLE : retval;
174
 
}
175
 
 
176
 
 
177
 
static GLenum
178
 
buffer_object_unpurgeable(struct gl_context *ctx, GLuint name, GLenum option)
179
 
{
180
 
   struct gl_buffer_object *bufObj;
181
 
   GLenum retval;
182
 
 
183
 
   bufObj = _mesa_lookup_bufferobj(ctx, name);
184
 
   if (!bufObj) {
185
 
      _mesa_error(ctx, GL_INVALID_VALUE,
186
 
                  "glObjectUnpurgeable(name = 0x%x)", name);
187
 
      return 0;
188
 
   }
189
 
 
190
 
   if (! bufObj->Purgeable) {
191
 
      _mesa_error(ctx, GL_INVALID_OPERATION,
192
 
                  "glObjectUnpurgeable(name = 0x%x) object is "
193
 
                  " already \"unpurged\"", name);
194
 
      return 0;
195
 
   }
196
 
 
197
 
   bufObj->Purgeable = GL_FALSE;
198
 
 
199
 
   retval = option;
200
 
 
201
 
   return retval;
202
 
}
203
 
 
204
 
 
205
 
static GLenum
206
 
renderbuffer_unpurgeable(struct gl_context *ctx, GLuint name, GLenum option)
207
 
{
208
 
   struct gl_renderbuffer *bufObj;
209
 
   GLenum retval;
210
 
 
211
 
   bufObj = _mesa_lookup_renderbuffer(ctx, name);
212
 
   if (!bufObj) {
213
 
      _mesa_error(ctx, GL_INVALID_VALUE,
214
 
                  "glObjectUnpurgeable(name = 0x%x)", name);
215
 
      return 0;
216
 
   }
217
 
 
218
 
   if (! bufObj->Purgeable) {
219
 
      _mesa_error(ctx, GL_INVALID_OPERATION,
220
 
                  "glObjectUnpurgeable(name = 0x%x) object is "
221
 
                  " already \"unpurged\"", name);
222
 
      return 0;
223
 
   }
224
 
 
225
 
   bufObj->Purgeable = GL_FALSE;
226
 
 
227
 
   retval = option;
228
 
 
229
 
   return retval;
230
 
}
231
 
 
232
 
 
233
 
static GLenum
234
 
texture_object_unpurgeable(struct gl_context *ctx, GLuint name, GLenum option)
235
 
{
236
 
   struct gl_texture_object *bufObj;
237
 
   GLenum retval;
238
 
 
239
 
   bufObj = _mesa_lookup_texture(ctx, name);
240
 
   if (!bufObj) {
241
 
      _mesa_error(ctx, GL_INVALID_VALUE,
242
 
                  "glObjectUnpurgeable(name = 0x%x)", name);
243
 
      return 0;
244
 
   }
245
 
 
246
 
   if (! bufObj->Purgeable) {
247
 
      _mesa_error(ctx, GL_INVALID_OPERATION,
248
 
                  "glObjectUnpurgeable(name = 0x%x) object is"
249
 
                  " already \"unpurged\"", name);
250
 
      return 0;
251
 
   }
252
 
 
253
 
   bufObj->Purgeable = GL_FALSE;
254
 
 
255
 
   retval = option;
256
 
 
257
 
   return retval;
258
 
}
259
 
 
260
 
 
261
 
GLenum GLAPIENTRY
262
 
_mesa_ObjectUnpurgeableAPPLE(GLenum objectType, GLuint name, GLenum option)
263
 
{
264
 
   GET_CURRENT_CONTEXT(ctx);
265
 
   ASSERT_OUTSIDE_BEGIN_END_WITH_RETVAL(ctx, 0);
266
 
 
267
 
   if (name == 0) {
268
 
      _mesa_error(ctx, GL_INVALID_VALUE,
269
 
                  "glObjectUnpurgeable(name = 0x%x)", name);
270
 
      return 0;
271
 
   }
272
 
 
273
 
   switch (option) {
274
 
   case GL_RETAINED_APPLE:
275
 
   case GL_UNDEFINED_APPLE:
276
 
      /* legal */
277
 
      break;
278
 
   default:
279
 
      _mesa_error(ctx, GL_INVALID_ENUM,
280
 
                  "glObjectUnpurgeable(name = 0x%x) invalid option: %d",
281
 
                  name, option);
282
 
      return 0;
283
 
   }
284
 
 
285
 
   switch (objectType) {
286
 
   case GL_BUFFER_OBJECT_APPLE:
287
 
      return buffer_object_unpurgeable(ctx, name, option);
288
 
   case GL_TEXTURE:
289
 
      return texture_object_unpurgeable(ctx, name, option);
290
 
   case GL_RENDERBUFFER_EXT:
291
 
      return renderbuffer_unpurgeable(ctx, name, option);
292
 
   default:
293
 
      _mesa_error(ctx, GL_INVALID_ENUM,
294
 
                  "glObjectUnpurgeable(name = 0x%x) invalid type: %d",
295
 
                  name, objectType);
296
 
      return 0;
297
 
   }
298
 
}
299
 
 
300
 
 
301
 
static void
302
 
get_buffer_object_parameteriv(struct gl_context *ctx, GLuint name,
303
 
                              GLenum pname, GLint *params)
304
 
{
305
 
   struct gl_buffer_object *bufObj = _mesa_lookup_bufferobj(ctx, name);
306
 
   if (!bufObj) {
307
 
      _mesa_error(ctx, GL_INVALID_VALUE,
308
 
                  "glGetObjectParameteriv(name = 0x%x) invalid object", name);
309
 
      return;
310
 
   }
311
 
 
312
 
   switch (pname) {
313
 
   case GL_PURGEABLE_APPLE:
314
 
      *params = bufObj->Purgeable;
315
 
      break;
316
 
   default:
317
 
      _mesa_error(ctx, GL_INVALID_ENUM,
318
 
                  "glGetObjectParameteriv(name = 0x%x) invalid enum: %d",
319
 
                  name, pname);
320
 
      break;
321
 
   }
322
 
}
323
 
 
324
 
 
325
 
static void
326
 
get_renderbuffer_parameteriv(struct gl_context *ctx, GLuint name,
327
 
                             GLenum pname, GLint *params)
328
 
{
329
 
   struct gl_renderbuffer *rb = _mesa_lookup_renderbuffer(ctx, name);
330
 
   if (!rb) {
331
 
      _mesa_error(ctx, GL_INVALID_VALUE,
332
 
                  "glObjectUnpurgeable(name = 0x%x)", name);
333
 
      return;
334
 
   }
335
 
 
336
 
   switch (pname) {
337
 
   case GL_PURGEABLE_APPLE:
338
 
      *params = rb->Purgeable;
339
 
      break;
340
 
   default:
341
 
      _mesa_error(ctx, GL_INVALID_ENUM,
342
 
                  "glGetObjectParameteriv(name = 0x%x) invalid enum: %d",
343
 
                  name, pname);
344
 
      break;
345
 
   }
346
 
}
347
 
 
348
 
 
349
 
static void
350
 
get_texture_object_parameteriv(struct gl_context *ctx, GLuint name,
351
 
                               GLenum pname, GLint *params)
352
 
{
353
 
   struct gl_texture_object *texObj = _mesa_lookup_texture(ctx, name);
354
 
   if (!texObj) {
355
 
      _mesa_error(ctx, GL_INVALID_VALUE,
356
 
                  "glObjectUnpurgeable(name = 0x%x)", name);
357
 
      return;
358
 
   }
359
 
 
360
 
   switch (pname) {
361
 
   case GL_PURGEABLE_APPLE:
362
 
      *params = texObj->Purgeable;
363
 
      break;
364
 
   default:
365
 
      _mesa_error(ctx, GL_INVALID_ENUM,
366
 
                  "glGetObjectParameteriv(name = 0x%x) invalid enum: %d",
367
 
                  name, pname);
368
 
      break;
369
 
   }
370
 
}
371
 
 
372
 
 
373
 
void GLAPIENTRY
374
 
_mesa_GetObjectParameterivAPPLE(GLenum objectType, GLuint name, GLenum pname,
375
 
                                GLint *params)
376
 
{
377
 
   GET_CURRENT_CONTEXT(ctx);
378
 
 
379
 
   if (name == 0) {
380
 
      _mesa_error(ctx, GL_INVALID_VALUE,
381
 
                  "glGetObjectParameteriv(name = 0x%x)", name);
382
 
      return;
383
 
   }
384
 
 
385
 
   switch (objectType) {
386
 
   case GL_TEXTURE:
387
 
      get_texture_object_parameteriv(ctx, name, pname, params);
388
 
      break;
389
 
   case GL_BUFFER_OBJECT_APPLE:
390
 
      get_buffer_object_parameteriv(ctx, name, pname, params);
391
 
      break;
392
 
   case GL_RENDERBUFFER_EXT:
393
 
      get_renderbuffer_parameteriv(ctx, name, pname, params);
394
 
      break;
395
 
   default:
396
 
      _mesa_error(ctx, GL_INVALID_ENUM,
397
 
                  "glGetObjectParameteriv(name = 0x%x) invalid type: %d",
398
 
                  name, objectType);
399
 
   }
400
 
}