1 /*
2 * Mesa 3-D graphics library
3 *
4 * Copyright (C) 2010 LunarG Inc.
5 *
6 * Permission is hereby granted, free of charge, to any person obtaining a
7 * copy of this software and associated documentation files (the "Software"),
8 * to deal in the Software without restriction, including without limitation
9 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
10 * and/or sell copies of the Software, and to permit persons to whom the
11 * Software is furnished to do so, subject to the following conditions:
12 *
13 * The above copyright notice and this permission notice shall be included
14 * in all copies or substantial portions of the Software.
15 *
16 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
19 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
21 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
22 * DEALINGS IN THE SOFTWARE.
23 *
24 * Authors:
25 * Chia-I Wu <olv@lunarg.com>
26 */
27
28 #include "mesa_interface.h"
29 #include "main/errors.h"
30 #include "main/texobj.h"
31 #include "main/teximage.h"
32 #include "util/u_inlines.h"
33 #include "util/format/u_format.h"
34 #include "st_cb_eglimage.h"
35 #include "st_cb_texture.h"
36 #include "st_context.h"
37 #include "st_texture.h"
38 #include "st_format.h"
39 #include "st_manager.h"
40 #include "st_sampler_view.h"
41 #include "util/u_surface.h"
42
43 static bool
is_format_supported(struct pipe_screen * screen,enum pipe_format format,unsigned nr_samples,unsigned nr_storage_samples,unsigned usage,bool * native_supported)44 is_format_supported(struct pipe_screen *screen, enum pipe_format format,
45 unsigned nr_samples, unsigned nr_storage_samples,
46 unsigned usage, bool *native_supported)
47 {
48 bool supported = screen->is_format_supported(screen, format, PIPE_TEXTURE_2D,
49 nr_samples, nr_storage_samples,
50 usage);
51 *native_supported = supported;
52
53 /* for sampling, some formats can be emulated.. it doesn't matter that
54 * the surface will have a format that the driver can't cope with because
55 * we'll give it sampler view formats that it can deal with and generate
56 * a shader variant that converts.
57 */
58 if ((usage == PIPE_BIND_SAMPLER_VIEW) && !supported) {
59 switch (format) {
60 case PIPE_FORMAT_IYUV:
61 supported = screen->is_format_supported(screen, PIPE_FORMAT_R8_UNORM,
62 PIPE_TEXTURE_2D, nr_samples,
63 nr_storage_samples, usage);
64 break;
65 case PIPE_FORMAT_NV12:
66 case PIPE_FORMAT_NV21:
67 case PIPE_FORMAT_NV16:
68 supported = screen->is_format_supported(screen, PIPE_FORMAT_R8_UNORM,
69 PIPE_TEXTURE_2D, nr_samples,
70 nr_storage_samples, usage) &&
71 screen->is_format_supported(screen, PIPE_FORMAT_R8G8_UNORM,
72 PIPE_TEXTURE_2D, nr_samples,
73 nr_storage_samples, usage);
74 break;
75 case PIPE_FORMAT_P010:
76 case PIPE_FORMAT_P012:
77 case PIPE_FORMAT_P016:
78 case PIPE_FORMAT_P030:
79 supported = screen->is_format_supported(screen, PIPE_FORMAT_R16_UNORM,
80 PIPE_TEXTURE_2D, nr_samples,
81 nr_storage_samples, usage) &&
82 screen->is_format_supported(screen, PIPE_FORMAT_R16G16_UNORM,
83 PIPE_TEXTURE_2D, nr_samples,
84 nr_storage_samples, usage);
85 break;
86 case PIPE_FORMAT_Y210:
87 case PIPE_FORMAT_Y212:
88 case PIPE_FORMAT_Y216:
89 supported = screen->is_format_supported(screen, PIPE_FORMAT_R16G16_UNORM,
90 PIPE_TEXTURE_2D, nr_samples,
91 nr_storage_samples, usage) &&
92 screen->is_format_supported(screen, PIPE_FORMAT_R16G16B16A16_UNORM,
93 PIPE_TEXTURE_2D, nr_samples,
94 nr_storage_samples, usage);
95 break;
96 case PIPE_FORMAT_Y410:
97 supported = screen->is_format_supported(screen, PIPE_FORMAT_R10G10B10A2_UNORM,
98 PIPE_TEXTURE_2D, nr_samples,
99 nr_storage_samples, usage);
100 break;
101 case PIPE_FORMAT_Y412:
102 case PIPE_FORMAT_Y416:
103 supported = screen->is_format_supported(screen, PIPE_FORMAT_R16G16B16A16_UNORM,
104 PIPE_TEXTURE_2D, nr_samples,
105 nr_storage_samples, usage);
106 break;
107 case PIPE_FORMAT_YUYV:
108 supported = screen->is_format_supported(screen, PIPE_FORMAT_R8G8_R8B8_UNORM,
109 PIPE_TEXTURE_2D, nr_samples,
110 nr_storage_samples, usage) ||
111 (screen->is_format_supported(screen, PIPE_FORMAT_RG88_UNORM,
112 PIPE_TEXTURE_2D, nr_samples,
113 nr_storage_samples, usage) &&
114 screen->is_format_supported(screen, PIPE_FORMAT_BGRA8888_UNORM,
115 PIPE_TEXTURE_2D, nr_samples,
116 nr_storage_samples, usage));
117 break;
118 case PIPE_FORMAT_YVYU:
119 supported = screen->is_format_supported(screen, PIPE_FORMAT_R8B8_R8G8_UNORM,
120 PIPE_TEXTURE_2D, nr_samples,
121 nr_storage_samples, usage) ||
122 (screen->is_format_supported(screen, PIPE_FORMAT_RG88_UNORM,
123 PIPE_TEXTURE_2D, nr_samples,
124 nr_storage_samples, usage) &&
125 screen->is_format_supported(screen, PIPE_FORMAT_BGRA8888_UNORM,
126 PIPE_TEXTURE_2D, nr_samples,
127 nr_storage_samples, usage));
128 break;
129 case PIPE_FORMAT_UYVY:
130 supported = screen->is_format_supported(screen, PIPE_FORMAT_G8R8_B8R8_UNORM,
131 PIPE_TEXTURE_2D, nr_samples,
132 nr_storage_samples, usage) ||
133 (screen->is_format_supported(screen, PIPE_FORMAT_RG88_UNORM,
134 PIPE_TEXTURE_2D, nr_samples,
135 nr_storage_samples, usage) &&
136 screen->is_format_supported(screen, PIPE_FORMAT_RGBA8888_UNORM,
137 PIPE_TEXTURE_2D, nr_samples,
138 nr_storage_samples, usage));
139 break;
140 case PIPE_FORMAT_VYUY:
141 supported = screen->is_format_supported(screen, PIPE_FORMAT_B8R8_G8R8_UNORM,
142 PIPE_TEXTURE_2D, nr_samples,
143 nr_storage_samples, usage) ||
144 (screen->is_format_supported(screen, PIPE_FORMAT_RG88_UNORM,
145 PIPE_TEXTURE_2D, nr_samples,
146 nr_storage_samples, usage) &&
147 screen->is_format_supported(screen, PIPE_FORMAT_RGBA8888_UNORM,
148 PIPE_TEXTURE_2D, nr_samples,
149 nr_storage_samples, usage));
150 break;
151 case PIPE_FORMAT_AYUV:
152 supported = screen->is_format_supported(screen, PIPE_FORMAT_RGBA8888_UNORM,
153 PIPE_TEXTURE_2D, nr_samples,
154 nr_storage_samples, usage);
155 break;
156 case PIPE_FORMAT_XYUV:
157 supported = screen->is_format_supported(screen, PIPE_FORMAT_RGBX8888_UNORM,
158 PIPE_TEXTURE_2D, nr_samples,
159 nr_storage_samples, usage);
160 break;
161 default:
162 break;
163 }
164 }
165
166 return supported;
167 }
168
169 static bool
is_fmt_as_r8_g8b8_supported(struct pipe_screen * screen,struct st_egl_image * out,unsigned usage,bool * native_supported)170 is_fmt_as_r8_g8b8_supported(struct pipe_screen *screen, struct st_egl_image *out,
171 unsigned usage, bool *native_supported)
172 {
173 if (out->format == PIPE_FORMAT_NV12 &&
174 out->texture->format == PIPE_FORMAT_R8_G8B8_420_UNORM &&
175 screen->is_format_supported(screen, PIPE_FORMAT_R8_G8B8_420_UNORM,
176 PIPE_TEXTURE_2D,
177 out->texture->nr_samples,
178 out->texture->nr_storage_samples,
179 usage)) {
180 *native_supported = false;
181 return true;
182 }
183
184 if (out->format == PIPE_FORMAT_NV21 &&
185 out->texture->format == PIPE_FORMAT_R8_B8G8_420_UNORM &&
186 screen->is_format_supported(screen, PIPE_FORMAT_R8_B8G8_420_UNORM,
187 PIPE_TEXTURE_2D,
188 out->texture->nr_samples,
189 out->texture->nr_storage_samples,
190 usage)) {
191 *native_supported = false;
192 return true;
193 }
194 if (out->format == PIPE_FORMAT_NV16 &&
195 out->texture->format == PIPE_FORMAT_R8_G8B8_422_UNORM &&
196 screen->is_format_supported(screen, PIPE_FORMAT_R8_G8B8_422_UNORM,
197 PIPE_TEXTURE_2D,
198 out->texture->nr_samples,
199 out->texture->nr_storage_samples,
200 usage)) {
201 *native_supported = false;
202 return true;
203 }
204
205 return false;
206 }
207
208 static bool
is_fmt_as_r10_g10b10_supported(struct pipe_screen * screen,struct st_egl_image * out,unsigned usage,bool * native_supported)209 is_fmt_as_r10_g10b10_supported(struct pipe_screen *screen, struct st_egl_image *out,
210 unsigned usage, bool *native_supported)
211 {
212 if (out->format == PIPE_FORMAT_NV15 &&
213 out->texture->format == PIPE_FORMAT_R10_G10B10_420_UNORM &&
214 screen->is_format_supported(screen, PIPE_FORMAT_R10_G10B10_420_UNORM,
215 PIPE_TEXTURE_2D,
216 out->texture->nr_samples,
217 out->texture->nr_storage_samples,
218 usage)) {
219 *native_supported = false;
220 return true;
221 }
222 if (out->format == PIPE_FORMAT_NV20 &&
223 out->texture->format == PIPE_FORMAT_R10_G10B10_422_UNORM &&
224 screen->is_format_supported(screen, PIPE_FORMAT_R10_G10B10_422_UNORM,
225 PIPE_TEXTURE_2D,
226 out->texture->nr_samples,
227 out->texture->nr_storage_samples,
228 usage)) {
229 *native_supported = false;
230 return true;
231 }
232 return false;
233 }
234
235 static bool
is_i420_as_r8_g8_b8_420_supported(struct pipe_screen * screen,struct st_egl_image * out,unsigned usage,bool * native_supported)236 is_i420_as_r8_g8_b8_420_supported(struct pipe_screen *screen,
237 struct st_egl_image *out,
238 unsigned usage, bool *native_supported)
239 {
240 if (out->format == PIPE_FORMAT_IYUV &&
241 out->texture->format == PIPE_FORMAT_R8_G8_B8_420_UNORM &&
242 screen->is_format_supported(screen, PIPE_FORMAT_R8_G8_B8_420_UNORM,
243 PIPE_TEXTURE_2D,
244 out->texture->nr_samples,
245 out->texture->nr_storage_samples,
246 usage)) {
247 *native_supported = false;
248 return true;
249 }
250
251 if (out->format == PIPE_FORMAT_IYUV &&
252 out->texture->format == PIPE_FORMAT_R8_B8_G8_420_UNORM &&
253 screen->is_format_supported(screen, PIPE_FORMAT_R8_B8_G8_420_UNORM,
254 PIPE_TEXTURE_2D,
255 out->texture->nr_samples,
256 out->texture->nr_storage_samples,
257 usage)) {
258 *native_supported = false;
259 return true;
260 }
261
262 return false;
263 }
264
265 /**
266 * Return the gallium texture of an EGLImage.
267 */
268 bool
st_get_egl_image(struct gl_context * ctx,GLeglImageOES image_handle,unsigned usage,bool tex_compression,const char * error,struct st_egl_image * out,bool * native_supported)269 st_get_egl_image(struct gl_context *ctx, GLeglImageOES image_handle,
270 unsigned usage, bool tex_compression, const char *error,
271 struct st_egl_image *out, bool *native_supported)
272 {
273 struct st_context *st = st_context(ctx);
274 struct pipe_screen *screen = st->screen;
275 struct pipe_frontend_screen *fscreen = st->frontend_screen;
276
277 if (!fscreen || !fscreen->get_egl_image)
278 return false;
279
280 memset(out, 0, sizeof(*out));
281 if (!fscreen->get_egl_image(fscreen, (void *) image_handle, out)) {
282 /* image_handle does not refer to a valid EGL image object */
283 _mesa_error(ctx, GL_INVALID_VALUE, "%s(image handle not found)", error);
284 return false;
285 }
286
287 if (!is_fmt_as_r8_g8b8_supported(screen, out, usage, native_supported) &&
288 !is_fmt_as_r10_g10b10_supported(screen, out, usage, native_supported) &&
289 !is_i420_as_r8_g8_b8_420_supported(screen, out, usage, native_supported) &&
290 !is_format_supported(screen, out->format, out->texture->nr_samples,
291 out->texture->nr_storage_samples, usage,
292 native_supported)) {
293 /* unable to specify a texture object using the specified EGL image */
294 pipe_resource_reference(&out->texture, NULL);
295 _mesa_error(ctx, GL_INVALID_OPERATION, "%s(format not supported)", error);
296 return false;
297 }
298
299 if (out->texture->compression_rate != PIPE_COMPRESSION_FIXED_RATE_NONE &&
300 !tex_compression) {
301 /* texture is fixed-rate compressed but a uncompressed one is expected */
302 pipe_resource_reference(&out->texture, NULL);
303 _mesa_error(ctx, GL_INVALID_OPERATION, "%s(fixed-rate compression not enabled)", error);
304 return false;
305 }
306
307 ctx->Shared->HasExternallySharedImages = true;
308 return true;
309 }
310
311 /**
312 * Return the base format just like _mesa_base_fbo_format does.
313 */
314 static GLenum
st_pipe_format_to_base_format(enum pipe_format format)315 st_pipe_format_to_base_format(enum pipe_format format)
316 {
317 GLenum base_format;
318
319 if (util_format_is_depth_or_stencil(format)) {
320 if (util_format_is_depth_and_stencil(format)) {
321 base_format = GL_DEPTH_STENCIL;
322 }
323 else {
324 if (format == PIPE_FORMAT_S8_UINT)
325 base_format = GL_STENCIL_INDEX;
326 else
327 base_format = GL_DEPTH_COMPONENT;
328 }
329 }
330 else {
331 /* is this enough? */
332 if (util_format_has_alpha(format))
333 base_format = GL_RGBA;
334 else
335 base_format = GL_RGB;
336 }
337
338 return base_format;
339 }
340
341 void
st_egl_image_target_renderbuffer_storage(struct gl_context * ctx,struct gl_renderbuffer * rb,GLeglImageOES image_handle)342 st_egl_image_target_renderbuffer_storage(struct gl_context *ctx,
343 struct gl_renderbuffer *rb,
344 GLeglImageOES image_handle)
345 {
346 struct st_egl_image stimg;
347 bool native_supported;
348
349 if (st_get_egl_image(ctx, image_handle, PIPE_BIND_RENDER_TARGET, false,
350 "glEGLImageTargetRenderbufferStorage",
351 &stimg, &native_supported)) {
352 struct pipe_context *pipe = st_context(ctx)->pipe;
353 struct pipe_surface *ps, surf_tmpl;
354
355 u_surface_default_template(&surf_tmpl, stimg.texture);
356 surf_tmpl.format = stimg.format;
357 surf_tmpl.u.tex.level = stimg.level;
358 surf_tmpl.u.tex.first_layer = stimg.layer;
359 surf_tmpl.u.tex.last_layer = stimg.layer;
360 ps = pipe->create_surface(pipe, stimg.texture, &surf_tmpl);
361 pipe_resource_reference(&stimg.texture, NULL);
362
363 if (!ps)
364 return;
365
366 rb->Format = st_pipe_format_to_mesa_format(ps->format);
367 rb->_BaseFormat = st_pipe_format_to_base_format(ps->format);
368 rb->InternalFormat = rb->_BaseFormat;
369
370 st_set_ws_renderbuffer_surface(rb, ps);
371 pipe_surface_reference(&ps, NULL);
372 }
373 }
374
375 void
st_bind_egl_image(struct gl_context * ctx,struct gl_texture_object * texObj,struct gl_texture_image * texImage,struct st_egl_image * stimg,bool tex_storage,bool native_supported)376 st_bind_egl_image(struct gl_context *ctx,
377 struct gl_texture_object *texObj,
378 struct gl_texture_image *texImage,
379 struct st_egl_image *stimg,
380 bool tex_storage,
381 bool native_supported)
382 {
383 struct st_context *st = st_context(ctx);
384 GLenum internalFormat;
385 mesa_format texFormat;
386
387 if (stimg->texture->target != gl_target_to_pipe(texObj->Target)) {
388 _mesa_error(ctx, GL_INVALID_OPERATION, __func__);
389 return;
390 }
391
392 if (stimg->internalformat) {
393 internalFormat = stimg->internalformat;
394 } else {
395 /* map pipe format to base format */
396 if (util_format_get_component_bits(stimg->format,
397 UTIL_FORMAT_COLORSPACE_RGB, 3) > 0)
398 internalFormat = GL_RGBA;
399 else
400 internalFormat = GL_RGB;
401 }
402
403 /* switch to surface based */
404 if (!texObj->surface_based) {
405 _mesa_clear_texture_object(ctx, texObj, NULL);
406 texObj->surface_based = GL_TRUE;
407 }
408
409 /* TODO RequiredTextureImageUnits should probably be reset back
410 * to 1 somewhere if different texture is bound??
411 */
412 if (!native_supported) {
413 switch (stimg->format) {
414 case PIPE_FORMAT_NV12:
415 case PIPE_FORMAT_NV21:
416 if (stimg->texture->format == PIPE_FORMAT_R8_G8B8_420_UNORM ||
417 stimg->texture->format == PIPE_FORMAT_R8_B8G8_420_UNORM) {
418 texFormat = MESA_FORMAT_R8G8B8X8_UNORM;
419 texObj->RequiredTextureImageUnits = 1;
420 } else {
421 texFormat = MESA_FORMAT_R_UNORM8;
422 texObj->RequiredTextureImageUnits = 2;
423 }
424 break;
425 case PIPE_FORMAT_NV16:
426 if (stimg->texture->format == PIPE_FORMAT_R8_G8B8_422_UNORM ||
427 stimg->texture->format == PIPE_FORMAT_R8_B8G8_422_UNORM) {
428 texFormat = MESA_FORMAT_R8G8B8X8_UNORM;
429 texObj->RequiredTextureImageUnits = 1;
430 } else {
431 texFormat = MESA_FORMAT_R_UNORM8;
432 texObj->RequiredTextureImageUnits = 2;
433 }
434 break;
435 case PIPE_FORMAT_NV15:
436 if (stimg->texture->format == PIPE_FORMAT_R10_G10B10_420_UNORM) {
437 texFormat = MESA_FORMAT_R10G10B10X2_UNORM;
438 texObj->RequiredTextureImageUnits = 1;
439 } else {
440 unreachable("NV15 emulation requires R10_G10B10_420_UNORM support");
441 }
442 break;
443 case PIPE_FORMAT_NV20:
444 if (stimg->texture->format == PIPE_FORMAT_R10_G10B10_422_UNORM) {
445 texFormat = MESA_FORMAT_R10G10B10X2_UNORM;
446 texObj->RequiredTextureImageUnits = 1;
447 } else {
448 unreachable("NV20 emulation requires R10_G10B10_422_UNORM support");
449 }
450 break;
451 case PIPE_FORMAT_P010:
452 case PIPE_FORMAT_P012:
453 case PIPE_FORMAT_P016:
454 case PIPE_FORMAT_P030:
455 texFormat = MESA_FORMAT_R_UNORM16;
456 texObj->RequiredTextureImageUnits = 2;
457 break;
458 case PIPE_FORMAT_Y210:
459 case PIPE_FORMAT_Y212:
460 case PIPE_FORMAT_Y216:
461 texFormat = MESA_FORMAT_RG_UNORM16;
462 texObj->RequiredTextureImageUnits = 2;
463 break;
464 case PIPE_FORMAT_Y410:
465 texFormat = MESA_FORMAT_B10G10R10A2_UNORM;
466 internalFormat = GL_RGBA;
467 texObj->RequiredTextureImageUnits = 1;
468 break;
469 case PIPE_FORMAT_Y412:
470 case PIPE_FORMAT_Y416:
471 texFormat = MESA_FORMAT_RGBA_UNORM16;
472 internalFormat = GL_RGBA;
473 texObj->RequiredTextureImageUnits = 1;
474 break;
475 case PIPE_FORMAT_IYUV:
476 if (stimg->texture->format == PIPE_FORMAT_R8_G8_B8_420_UNORM ||
477 stimg->texture->format == PIPE_FORMAT_R8_B8_G8_420_UNORM) {
478 texFormat = MESA_FORMAT_R8G8B8X8_UNORM;
479 texObj->RequiredTextureImageUnits = 1;
480 } else {
481 texFormat = MESA_FORMAT_R_UNORM8;
482 texObj->RequiredTextureImageUnits = 3;
483 }
484 break;
485 case PIPE_FORMAT_YUYV:
486 case PIPE_FORMAT_YVYU:
487 case PIPE_FORMAT_UYVY:
488 case PIPE_FORMAT_VYUY:
489 if (stimg->texture->format == PIPE_FORMAT_R8G8_R8B8_UNORM) {
490 texFormat = MESA_FORMAT_RG_RB_UNORM8;
491 texObj->RequiredTextureImageUnits = 1;
492 } else if (stimg->texture->format == PIPE_FORMAT_R8B8_R8G8_UNORM) {
493 texFormat = MESA_FORMAT_RB_RG_UNORM8;
494 texObj->RequiredTextureImageUnits = 1;
495 } else if (stimg->texture->format == PIPE_FORMAT_G8R8_B8R8_UNORM) {
496 texFormat = MESA_FORMAT_GR_BR_UNORM8;
497 texObj->RequiredTextureImageUnits = 1;
498 } else if (stimg->texture->format == PIPE_FORMAT_B8R8_G8R8_UNORM) {
499 texFormat = MESA_FORMAT_BR_GR_UNORM8;
500 texObj->RequiredTextureImageUnits = 1;
501 } else {
502 texFormat = MESA_FORMAT_RG_UNORM8;
503 texObj->RequiredTextureImageUnits = 2;
504 }
505 break;
506 case PIPE_FORMAT_AYUV:
507 texFormat = MESA_FORMAT_R8G8B8A8_UNORM;
508 internalFormat = GL_RGBA;
509 texObj->RequiredTextureImageUnits = 1;
510 break;
511 case PIPE_FORMAT_XYUV:
512 texFormat = MESA_FORMAT_R8G8B8X8_UNORM;
513 texObj->RequiredTextureImageUnits = 1;
514 break;
515 default:
516 unreachable("unexpected emulated format");
517 break;
518 }
519 } else {
520 texFormat = st_pipe_format_to_mesa_format(stimg->format);
521 /* Use previously derived internalformat as specified by
522 * EXT_EGL_image_storage.
523 */
524 if (tex_storage && texObj->Target == GL_TEXTURE_2D
525 && stimg->internalformat) {
526 internalFormat = stimg->internalformat;
527 if (internalFormat == GL_NONE) {
528 _mesa_error(ctx, GL_INVALID_OPERATION, __func__);
529 return;
530 }
531 }
532 }
533 assert(texFormat != MESA_FORMAT_NONE);
534
535
536 /* Minify texture size based on level set on the EGLImage. */
537 uint32_t width = u_minify(stimg->texture->width0, stimg->level);
538 uint32_t height = u_minify(stimg->texture->height0, stimg->level);
539
540 _mesa_init_teximage_fields(ctx, texImage, width, height,
541 1, 0, internalFormat, texFormat);
542
543 pipe_resource_reference(&texObj->pt, stimg->texture);
544 st_texture_release_all_sampler_views(st, texObj);
545 pipe_resource_reference(&texImage->pt, texObj->pt);
546 if (st->screen->resource_changed)
547 st->screen->resource_changed(st->screen, texImage->pt);
548
549 texObj->surface_format = stimg->format;
550
551 switch (stimg->yuv_color_space) {
552 case __DRI_YUV_COLOR_SPACE_ITU_REC709:
553 texObj->yuv_color_space = GL_TEXTURE_YUV_COLOR_SPACE_REC709;
554 break;
555 case __DRI_YUV_COLOR_SPACE_ITU_REC2020:
556 texObj->yuv_color_space = GL_TEXTURE_YUV_COLOR_SPACE_REC2020;
557 break;
558 default:
559 texObj->yuv_color_space = GL_TEXTURE_YUV_COLOR_SPACE_REC601;
560 break;
561 }
562
563 if (stimg->yuv_range == __DRI_YUV_FULL_RANGE)
564 texObj->yuv_full_range = true;
565
566 texObj->CompressionRate = stimg->texture->compression_rate;
567
568 texObj->level_override = stimg->level;
569 texObj->layer_override = stimg->layer;
570 _mesa_update_texture_object_swizzle(ctx, texObj);
571
572 _mesa_dirty_texobj(ctx, texObj);
573 }
574
575 bool
st_validate_egl_image(struct gl_context * ctx,GLeglImageOES image_handle)576 st_validate_egl_image(struct gl_context *ctx, GLeglImageOES image_handle)
577 {
578 struct st_context *st = st_context(ctx);
579 struct pipe_frontend_screen *fscreen = st->frontend_screen;
580
581 return fscreen->validate_egl_image(fscreen, (void *)image_handle);
582 }
583