3b173bc257e030125f581fcb61290370c9f14860
[mesa.git] / src / mesa / drivers / dri / intel / intel_tex_image.c
1
2 #include "main/glheader.h"
3 #include "main/macros.h"
4 #include "main/mfeatures.h"
5 #include "main/mtypes.h"
6 #include "main/enums.h"
7 #include "main/bufferobj.h"
8 #include "main/context.h"
9 #include "main/formats.h"
10 #include "main/texcompress.h"
11 #include "main/texstore.h"
12 #include "main/texgetimage.h"
13 #include "main/texobj.h"
14 #include "main/teximage.h"
15
16 #include "intel_context.h"
17 #include "intel_mipmap_tree.h"
18 #include "intel_buffer_objects.h"
19 #include "intel_batchbuffer.h"
20 #include "intel_tex.h"
21 #include "intel_blit.h"
22 #include "intel_fbo.h"
23
24 #define FILE_DEBUG_FLAG DEBUG_TEXTURE
25
26 /* Functions to store texture images. Where possible, mipmap_tree's
27 * will be created or further instantiated with image data, otherwise
28 * images will be stored in malloc'd memory. A validation step is
29 * required to pull those images into a mipmap tree, or otherwise
30 * decide a fallback is required.
31 */
32
33
34 static int
35 logbase2(int n)
36 {
37 GLint i = 1;
38 GLint log2 = 0;
39
40 while (n > i) {
41 i *= 2;
42 log2++;
43 }
44
45 return log2;
46 }
47
48 struct intel_mipmap_tree *
49 intel_miptree_create_for_teximage(struct intel_context *intel,
50 struct intel_texture_object *intelObj,
51 struct intel_texture_image *intelImage,
52 GLboolean expect_accelerated_upload)
53 {
54 GLuint lastLevel;
55 GLuint width = intelImage->base.Width;
56 GLuint height = intelImage->base.Height;
57 GLuint depth = intelImage->base.Depth;
58 GLuint i, comp_byte = 0;
59 GLuint texelBytes;
60
61 DBG("%s\n", __FUNCTION__);
62
63 if (intelImage->base.Border)
64 return NULL;
65
66 /* Figure out image dimensions at start level.
67 */
68 for (i = intelImage->level; i > 0; i--) {
69 width <<= 1;
70 if (height != 1)
71 height <<= 1;
72 if (depth != 1)
73 depth <<= 1;
74 }
75
76 /* Guess a reasonable value for lastLevel. This is probably going
77 * to be wrong fairly often and might mean that we have to look at
78 * resizable buffers, or require that buffers implement lazy
79 * pagetable arrangements.
80 */
81 if ((intelObj->base.MinFilter == GL_NEAREST ||
82 intelObj->base.MinFilter == GL_LINEAR) &&
83 intelImage->level == 0) {
84 lastLevel = 0;
85 }
86 else {
87 lastLevel = logbase2(MAX2(MAX2(width, height), depth));
88 }
89
90 if (_mesa_is_format_compressed(intelImage->base.TexFormat))
91 comp_byte = intel_compressed_num_bytes(intelImage->base.TexFormat);
92
93 texelBytes = _mesa_get_format_bytes(intelImage->base.TexFormat);
94
95 return intel_miptree_create(intel,
96 intelObj->base.Target,
97 intelImage->base._BaseFormat,
98 intelImage->base.InternalFormat,
99 lastLevel + 1,
100 width,
101 height,
102 depth,
103 texelBytes,
104 comp_byte,
105 expect_accelerated_upload);
106 }
107
108
109
110
111 static GLuint
112 target_to_face(GLenum target)
113 {
114 switch (target) {
115 case GL_TEXTURE_CUBE_MAP_POSITIVE_X_ARB:
116 case GL_TEXTURE_CUBE_MAP_NEGATIVE_X_ARB:
117 case GL_TEXTURE_CUBE_MAP_POSITIVE_Y_ARB:
118 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Y_ARB:
119 case GL_TEXTURE_CUBE_MAP_POSITIVE_Z_ARB:
120 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Z_ARB:
121 return ((GLuint) target - (GLuint) GL_TEXTURE_CUBE_MAP_POSITIVE_X);
122 default:
123 return 0;
124 }
125 }
126
127 /* There are actually quite a few combinations this will work for,
128 * more than what I've listed here.
129 */
130 static GLboolean
131 check_pbo_format(GLint internalFormat,
132 GLenum format, GLenum type,
133 gl_format mesa_format)
134 {
135 switch (internalFormat) {
136 case 4:
137 case GL_RGBA:
138 case GL_RGBA8:
139 return (format == GL_BGRA &&
140 (type == GL_UNSIGNED_BYTE ||
141 type == GL_UNSIGNED_INT_8_8_8_8_REV) &&
142 mesa_format == MESA_FORMAT_ARGB8888);
143 case 3:
144 case GL_RGB:
145 return (format == GL_RGB &&
146 type == GL_UNSIGNED_SHORT_5_6_5 &&
147 mesa_format == MESA_FORMAT_RGB565);
148 case 1:
149 case GL_LUMINANCE:
150 return (format == GL_LUMINANCE &&
151 type == GL_UNSIGNED_BYTE &&
152 mesa_format == MESA_FORMAT_L8);
153 case GL_YCBCR_MESA:
154 return (type == GL_UNSIGNED_SHORT_8_8_MESA || type == GL_UNSIGNED_BYTE);
155 default:
156 return GL_FALSE;
157 }
158 }
159
160
161 /* XXX: Do this for TexSubImage also:
162 */
163 static GLboolean
164 try_pbo_upload(struct intel_context *intel,
165 struct intel_texture_image *intelImage,
166 const struct gl_pixelstore_attrib *unpack,
167 GLint internalFormat,
168 GLint width, GLint height,
169 GLenum format, GLenum type, const void *pixels)
170 {
171 struct intel_buffer_object *pbo = intel_buffer_object(unpack->BufferObj);
172 GLuint src_offset, src_stride;
173 GLuint dst_x, dst_y, dst_stride;
174 drm_intel_bo *dst_buffer = intel_region_buffer(intel,
175 intelImage->mt->region,
176 INTEL_WRITE_FULL);
177
178 if (!_mesa_is_bufferobj(unpack->BufferObj) ||
179 intel->ctx._ImageTransferState ||
180 unpack->SkipPixels || unpack->SkipRows) {
181 DBG("%s: failure 1\n", __FUNCTION__);
182 return GL_FALSE;
183 }
184
185 /* note: potential 64-bit ptr to 32-bit int cast */
186 src_offset = (GLuint) (unsigned long) pixels;
187
188 if (unpack->RowLength > 0)
189 src_stride = unpack->RowLength;
190 else
191 src_stride = width;
192
193 intel_miptree_get_image_offset(intelImage->mt, intelImage->level,
194 intelImage->face, 0,
195 &dst_x, &dst_y);
196
197 dst_stride = intelImage->mt->region->pitch;
198
199 if (drm_intel_bo_references(intel->batch->buf, dst_buffer))
200 intel_flush(&intel->ctx);
201
202 {
203 drm_intel_bo *src_buffer = intel_bufferobj_buffer(intel, pbo, INTEL_READ);
204
205 if (!intelEmitCopyBlit(intel,
206 intelImage->mt->cpp,
207 src_stride, src_buffer, src_offset, GL_FALSE,
208 dst_stride, dst_buffer, 0,
209 intelImage->mt->region->tiling,
210 0, 0, dst_x, dst_y, width, height,
211 GL_COPY)) {
212 return GL_FALSE;
213 }
214 }
215
216 return GL_TRUE;
217 }
218
219
220 static GLboolean
221 try_pbo_zcopy(struct intel_context *intel,
222 struct intel_texture_image *intelImage,
223 const struct gl_pixelstore_attrib *unpack,
224 GLint internalFormat,
225 GLint width, GLint height,
226 GLenum format, GLenum type, const void *pixels)
227 {
228 struct intel_buffer_object *pbo = intel_buffer_object(unpack->BufferObj);
229 GLuint src_offset, src_stride;
230 GLuint dst_x, dst_y, dst_stride;
231
232 if (!_mesa_is_bufferobj(unpack->BufferObj) ||
233 intel->ctx._ImageTransferState ||
234 unpack->SkipPixels || unpack->SkipRows) {
235 DBG("%s: failure 1\n", __FUNCTION__);
236 return GL_FALSE;
237 }
238
239 /* note: potential 64-bit ptr to 32-bit int cast */
240 src_offset = (GLuint) (unsigned long) pixels;
241
242 if (unpack->RowLength > 0)
243 src_stride = unpack->RowLength;
244 else
245 src_stride = width;
246
247 intel_miptree_get_image_offset(intelImage->mt, intelImage->level,
248 intelImage->face, 0,
249 &dst_x, &dst_y);
250
251 dst_stride = intelImage->mt->region->pitch;
252
253 if (src_stride != dst_stride || dst_x != 0 || dst_y != 0 ||
254 src_offset != 0) {
255 DBG("%s: failure 2\n", __FUNCTION__);
256 return GL_FALSE;
257 }
258
259 intel_region_attach_pbo(intel, intelImage->mt->region, pbo);
260
261 return GL_TRUE;
262 }
263
264
265 static void
266 intelTexImage(struct gl_context * ctx,
267 GLint dims,
268 GLenum target, GLint level,
269 GLint internalFormat,
270 GLint width, GLint height, GLint depth,
271 GLint border,
272 GLenum format, GLenum type, const void *pixels,
273 const struct gl_pixelstore_attrib *unpack,
274 struct gl_texture_object *texObj,
275 struct gl_texture_image *texImage, GLsizei imageSize,
276 GLboolean compressed)
277 {
278 struct intel_context *intel = intel_context(ctx);
279 struct intel_texture_object *intelObj = intel_texture_object(texObj);
280 struct intel_texture_image *intelImage = intel_texture_image(texImage);
281 GLint texelBytes, sizeInBytes;
282 GLuint dstRowStride = 0, srcRowStride = texImage->RowStride;
283
284 DBG("%s target %s level %d %dx%dx%d border %d\n", __FUNCTION__,
285 _mesa_lookup_enum_by_nr(target), level, width, height, depth, border);
286
287 intelImage->face = target_to_face(target);
288 intelImage->level = level;
289
290 if (_mesa_is_format_compressed(texImage->TexFormat)) {
291 texelBytes = 0;
292 }
293 else {
294 texelBytes = _mesa_get_format_bytes(texImage->TexFormat);
295
296 if (!intelImage->mt) {
297 assert(texImage->RowStride == width);
298 }
299 }
300
301 /* Release the reference to a potentially orphaned buffer.
302 * Release any old malloced memory.
303 */
304 if (intelImage->mt) {
305 intel_miptree_release(intel, &intelImage->mt);
306 assert(!texImage->Data);
307 }
308 else if (texImage->Data) {
309 _mesa_free_texmemory(texImage->Data);
310 texImage->Data = NULL;
311 }
312
313 if (intelObj->mt && intel_miptree_match_image(intelObj->mt,
314 &intelImage->base)) {
315 intel_miptree_reference(&intelImage->mt, intelObj->mt);
316 } else {
317 intel_miptree_release(intel, &intelImage->mt);
318 intelImage->mt = intel_miptree_create_for_teximage(intel, intelObj,
319 intelImage,
320 pixels == NULL);
321 if (!intelImage->mt) {
322 DBG("guess_and_alloc_mipmap_tree: failed\n");
323 }
324
325 /* Speculatively set up the object with this miptree so that the
326 * later levels can just load into the miptree we just made.
327 */
328 if (!intelObj->mt && intelImage->mt)
329 intel_miptree_reference(&intelObj->mt, intelImage->mt);
330 }
331
332 /* PBO fastpaths:
333 */
334 if (dims <= 2 &&
335 intelImage->mt &&
336 _mesa_is_bufferobj(unpack->BufferObj) &&
337 check_pbo_format(internalFormat, format,
338 type, intelImage->base.TexFormat)) {
339
340 DBG("trying pbo upload\n");
341
342 /* Attempt to texture directly from PBO data (zero copy upload).
343 *
344 * Currently disable as it can lead to worse as well as better
345 * performance (in particular when intel_region_cow() is
346 * required).
347 */
348 if (intelImage->mt->levels == 1) {
349 if (try_pbo_zcopy(intel, intelImage, unpack,
350 internalFormat,
351 width, height, format, type, pixels)) {
352
353 DBG("pbo zcopy upload succeeded\n");
354 return;
355 }
356 }
357
358
359 /* Otherwise, attempt to use the blitter for PBO image uploads.
360 */
361 if (try_pbo_upload(intel, intelImage, unpack,
362 internalFormat,
363 width, height, format, type, pixels)) {
364 DBG("pbo upload succeeded\n");
365 return;
366 }
367
368 DBG("pbo upload failed\n");
369 }
370
371 /* intelCopyTexImage calls this function with pixels == NULL, with
372 * the expectation that the mipmap tree will be set up but nothing
373 * more will be done. This is where those calls return:
374 */
375 if (compressed) {
376 pixels = _mesa_validate_pbo_compressed_teximage(ctx, imageSize, pixels,
377 unpack,
378 "glCompressedTexImage");
379 } else {
380 pixels = _mesa_validate_pbo_teximage(ctx, dims, width, height, 1,
381 format, type,
382 pixels, unpack, "glTexImage");
383 }
384
385 if (intelImage->mt) {
386 if (pixels != NULL) {
387 /* Flush any queued rendering with the texture before mapping. */
388 if (drm_intel_bo_references(intel->batch->buf,
389 intelImage->mt->region->buffer)) {
390 intel_flush(ctx);
391 }
392 texImage->Data = intel_miptree_image_map(intel,
393 intelImage->mt,
394 intelImage->face,
395 intelImage->level,
396 &dstRowStride,
397 intelImage->base.ImageOffsets);
398 }
399
400 texImage->RowStride = dstRowStride / intelImage->mt->cpp;
401 }
402 else {
403 /* Allocate regular memory and store the image there temporarily. */
404 if (_mesa_is_format_compressed(texImage->TexFormat)) {
405 sizeInBytes = _mesa_format_image_size(texImage->TexFormat,
406 texImage->Width,
407 texImage->Height,
408 texImage->Depth);
409 dstRowStride =
410 _mesa_format_row_stride(texImage->TexFormat, width);
411 assert(dims != 3);
412 }
413 else {
414 dstRowStride = width * texelBytes;
415 sizeInBytes = depth * dstRowStride * height;
416 }
417
418 texImage->Data = _mesa_alloc_texmemory(sizeInBytes);
419 }
420
421 DBG("Upload image %dx%dx%d row_len %d "
422 "pitch %d pixels %d compressed %d\n",
423 width, height, depth, width * texelBytes, dstRowStride,
424 pixels ? 1 : 0, compressed);
425
426 /* Copy data. Would like to know when it's ok for us to eg. use
427 * the blitter to copy. Or, use the hardware to do the format
428 * conversion and copy:
429 */
430 if (pixels) {
431 if (compressed) {
432 if (intelImage->mt) {
433 struct intel_region *dst = intelImage->mt->region;
434 _mesa_copy_rect(texImage->Data, dst->cpp, dst->pitch,
435 0, 0,
436 intelImage->mt->level[level].width,
437 (intelImage->mt->level[level].height+3)/4,
438 pixels,
439 srcRowStride,
440 0, 0);
441 }
442 else {
443 memcpy(texImage->Data, pixels, imageSize);
444 }
445 }
446 else if (!_mesa_texstore(ctx, dims,
447 texImage->_BaseFormat,
448 texImage->TexFormat,
449 texImage->Data, 0, 0, 0, /* dstX/Y/Zoffset */
450 dstRowStride,
451 texImage->ImageOffsets,
452 width, height, depth,
453 format, type, pixels, unpack)) {
454 _mesa_error(ctx, GL_OUT_OF_MEMORY, "glTexImage");
455 }
456 }
457
458 _mesa_unmap_teximage_pbo(ctx, unpack);
459
460 if (intelImage->mt) {
461 if (pixels != NULL)
462 intel_miptree_image_unmap(intel, intelImage->mt);
463 texImage->Data = NULL;
464 }
465 }
466
467
468 static void
469 intelTexImage3D(struct gl_context * ctx,
470 GLenum target, GLint level,
471 GLint internalFormat,
472 GLint width, GLint height, GLint depth,
473 GLint border,
474 GLenum format, GLenum type, const void *pixels,
475 const struct gl_pixelstore_attrib *unpack,
476 struct gl_texture_object *texObj,
477 struct gl_texture_image *texImage)
478 {
479 intelTexImage(ctx, 3, target, level,
480 internalFormat, width, height, depth, border,
481 format, type, pixels, unpack, texObj, texImage, 0, GL_FALSE);
482 }
483
484
485 static void
486 intelTexImage2D(struct gl_context * ctx,
487 GLenum target, GLint level,
488 GLint internalFormat,
489 GLint width, GLint height, GLint border,
490 GLenum format, GLenum type, const void *pixels,
491 const struct gl_pixelstore_attrib *unpack,
492 struct gl_texture_object *texObj,
493 struct gl_texture_image *texImage)
494 {
495 intelTexImage(ctx, 2, target, level,
496 internalFormat, width, height, 1, border,
497 format, type, pixels, unpack, texObj, texImage, 0, GL_FALSE);
498 }
499
500
501 static void
502 intelTexImage1D(struct gl_context * ctx,
503 GLenum target, GLint level,
504 GLint internalFormat,
505 GLint width, GLint border,
506 GLenum format, GLenum type, const void *pixels,
507 const struct gl_pixelstore_attrib *unpack,
508 struct gl_texture_object *texObj,
509 struct gl_texture_image *texImage)
510 {
511 intelTexImage(ctx, 1, target, level,
512 internalFormat, width, 1, 1, border,
513 format, type, pixels, unpack, texObj, texImage, 0, GL_FALSE);
514 }
515
516
517 static void
518 intelCompressedTexImage2D( struct gl_context *ctx, GLenum target, GLint level,
519 GLint internalFormat,
520 GLint width, GLint height, GLint border,
521 GLsizei imageSize, const GLvoid *data,
522 struct gl_texture_object *texObj,
523 struct gl_texture_image *texImage )
524 {
525 intelTexImage(ctx, 2, target, level,
526 internalFormat, width, height, 1, border,
527 0, 0, data, &ctx->Unpack, texObj, texImage, imageSize, GL_TRUE);
528 }
529
530
531 /**
532 * Need to map texture image into memory before copying image data,
533 * then unmap it.
534 */
535 static void
536 intel_get_tex_image(struct gl_context * ctx, GLenum target, GLint level,
537 GLenum format, GLenum type, GLvoid * pixels,
538 struct gl_texture_object *texObj,
539 struct gl_texture_image *texImage, GLboolean compressed)
540 {
541 struct intel_context *intel = intel_context(ctx);
542 struct intel_texture_image *intelImage = intel_texture_image(texImage);
543
544 /* If we're reading from a texture that has been rendered to, need to
545 * make sure rendering is complete.
546 * We could probably predicate this on texObj->_RenderToTexture
547 */
548 intel_flush(ctx);
549
550 /* Map */
551 if (intelImage->mt) {
552 /* Image is stored in hardware format in a buffer managed by the
553 * kernel. Need to explicitly map and unmap it.
554 */
555 intelImage->base.Data =
556 intel_miptree_image_map(intel,
557 intelImage->mt,
558 intelImage->face,
559 intelImage->level,
560 &intelImage->base.RowStride,
561 intelImage->base.ImageOffsets);
562 intelImage->base.RowStride /= intelImage->mt->cpp;
563 }
564 else {
565 /* Otherwise, the image should actually be stored in
566 * intelImage->base.Data. This is pretty confusing for
567 * everybody, I'd much prefer to separate the two functions of
568 * texImage->Data - storage for texture images in main memory
569 * and access (ie mappings) of images. In other words, we'd
570 * create a new texImage->Map field and leave Data simply for
571 * storage.
572 */
573 assert(intelImage->base.Data);
574 }
575
576
577 if (compressed) {
578 _mesa_get_compressed_teximage(ctx, target, level, pixels,
579 texObj, texImage);
580 }
581 else {
582 _mesa_get_teximage(ctx, target, level, format, type, pixels,
583 texObj, texImage);
584 }
585
586
587 /* Unmap */
588 if (intelImage->mt) {
589 intel_miptree_image_unmap(intel, intelImage->mt);
590 intelImage->base.Data = NULL;
591 }
592 }
593
594
595 static void
596 intelGetTexImage(struct gl_context * ctx, GLenum target, GLint level,
597 GLenum format, GLenum type, GLvoid * pixels,
598 struct gl_texture_object *texObj,
599 struct gl_texture_image *texImage)
600 {
601 intel_get_tex_image(ctx, target, level, format, type, pixels,
602 texObj, texImage, GL_FALSE);
603 }
604
605
606 static void
607 intelGetCompressedTexImage(struct gl_context *ctx, GLenum target, GLint level,
608 GLvoid *pixels,
609 struct gl_texture_object *texObj,
610 struct gl_texture_image *texImage)
611 {
612 intel_get_tex_image(ctx, target, level, 0, 0, pixels,
613 texObj, texImage, GL_TRUE);
614 }
615
616 void
617 intelSetTexBuffer2(__DRIcontext *pDRICtx, GLint target,
618 GLint texture_format,
619 __DRIdrawable *dPriv)
620 {
621 struct gl_framebuffer *fb = dPriv->driverPrivate;
622 struct intel_context *intel = pDRICtx->driverPrivate;
623 struct gl_context *ctx = &intel->ctx;
624 struct intel_texture_object *intelObj;
625 struct intel_texture_image *intelImage;
626 struct intel_mipmap_tree *mt;
627 struct intel_renderbuffer *rb;
628 struct gl_texture_object *texObj;
629 struct gl_texture_image *texImage;
630 int level = 0, internalFormat;
631 gl_format texFormat;
632
633 texObj = _mesa_get_current_tex_object(ctx, target);
634 intelObj = intel_texture_object(texObj);
635
636 if (!intelObj)
637 return;
638
639 if (dPriv->lastStamp != dPriv->dri2.stamp ||
640 !pDRICtx->driScreenPriv->dri2.useInvalidate)
641 intel_update_renderbuffers(pDRICtx, dPriv);
642
643 rb = intel_get_renderbuffer(fb, BUFFER_FRONT_LEFT);
644 /* If the region isn't set, then intel_update_renderbuffers was unable
645 * to get the buffers for the drawable.
646 */
647 if (rb->region == NULL)
648 return;
649
650 if (texture_format == __DRI_TEXTURE_FORMAT_RGB) {
651 internalFormat = GL_RGB;
652 texFormat = MESA_FORMAT_XRGB8888;
653 }
654 else {
655 internalFormat = GL_RGBA;
656 texFormat = MESA_FORMAT_ARGB8888;
657 }
658
659 mt = intel_miptree_create_for_region(intel, target,
660 internalFormat, rb->region, 1, 0);
661 if (mt == NULL)
662 return;
663
664 _mesa_lock_texture(&intel->ctx, texObj);
665
666 texImage = _mesa_get_tex_image(&intel->ctx, texObj, target, level);
667 intelImage = intel_texture_image(texImage);
668
669 if (intelImage->mt) {
670 intel_miptree_release(intel, &intelImage->mt);
671 assert(!texImage->Data);
672 }
673 if (intelObj->mt)
674 intel_miptree_release(intel, &intelObj->mt);
675
676 intelObj->mt = mt;
677
678 _mesa_init_teximage_fields(&intel->ctx, target, texImage,
679 rb->region->width, rb->region->height, 1,
680 0, internalFormat, texFormat);
681
682 intelImage->face = target_to_face(target);
683 intelImage->level = level;
684 texImage->RowStride = rb->region->pitch;
685 intel_miptree_reference(&intelImage->mt, intelObj->mt);
686
687 if (!intel_miptree_match_image(intelObj->mt, &intelImage->base)) {
688 fprintf(stderr, "miptree doesn't match image\n");
689 }
690
691 _mesa_unlock_texture(&intel->ctx, texObj);
692 }
693
694 void
695 intelSetTexBuffer(__DRIcontext *pDRICtx, GLint target, __DRIdrawable *dPriv)
696 {
697 /* The old interface didn't have the format argument, so copy our
698 * implementation's behavior at the time.
699 */
700 intelSetTexBuffer2(pDRICtx, target, __DRI_TEXTURE_FORMAT_RGBA, dPriv);
701 }
702
703 #if FEATURE_OES_EGL_image
704 static void
705 intel_image_target_texture_2d(struct gl_context *ctx, GLenum target,
706 struct gl_texture_object *texObj,
707 struct gl_texture_image *texImage,
708 GLeglImageOES image_handle)
709 {
710 struct intel_context *intel = intel_context(ctx);
711 struct intel_texture_object *intelObj = intel_texture_object(texObj);
712 struct intel_texture_image *intelImage = intel_texture_image(texImage);
713 struct intel_mipmap_tree *mt;
714 __DRIscreen *screen;
715 __DRIimage *image;
716
717 screen = intel->intelScreen->driScrnPriv;
718 image = screen->dri2.image->lookupEGLImage(screen, image_handle,
719 screen->loaderPrivate);
720 if (image == NULL)
721 return;
722
723 mt = intel_miptree_create_for_region(intel, target,
724 image->internal_format,
725 image->region, 1, 0);
726 if (mt == NULL)
727 return;
728
729 if (intelImage->mt) {
730 intel_miptree_release(intel, &intelImage->mt);
731 assert(!texImage->Data);
732 }
733 if (intelObj->mt)
734 intel_miptree_release(intel, &intelObj->mt);
735
736 intelObj->mt = mt;
737 _mesa_init_teximage_fields(&intel->ctx, target, texImage,
738 image->region->width, image->region->height, 1,
739 0, image->internal_format, image->format);
740
741 intelImage->face = target_to_face(target);
742 intelImage->level = 0;
743 texImage->RowStride = image->region->pitch;
744 intel_miptree_reference(&intelImage->mt, intelObj->mt);
745
746 if (!intel_miptree_match_image(intelObj->mt, &intelImage->base))
747 fprintf(stderr, "miptree doesn't match image\n");
748 }
749 #endif
750
751 void
752 intelInitTextureImageFuncs(struct dd_function_table *functions)
753 {
754 functions->TexImage1D = intelTexImage1D;
755 functions->TexImage2D = intelTexImage2D;
756 functions->TexImage3D = intelTexImage3D;
757 functions->GetTexImage = intelGetTexImage;
758
759 functions->CompressedTexImage2D = intelCompressedTexImage2D;
760 functions->GetCompressedTexImage = intelGetCompressedTexImage;
761
762 #if FEATURE_OES_EGL_image
763 functions->EGLImageTargetTexture2D = intel_image_target_texture_2d;
764 #endif
765 }