| OLD | NEW |
| (Empty) |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | |
| 2 // Use of this source code is governed by a BSD-style license that can be | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 #include "content/common/gpu/media/gles2_texture_to_egl_image_translator.h" | |
| 6 | |
| 7 #include "base/logging.h" | |
| 8 | |
| 9 #if defined(TOOLKIT_USES_GTK) | |
| 10 #include "base/message_loop/message_pump_gtk.h" | |
| 11 #elif defined(USE_AURA) | |
| 12 #include "base/message_loop/message_pump_aurax11.h" | |
| 13 #endif | |
| 14 | |
| 15 namespace content { | |
| 16 | |
| 17 Gles2TextureToEglImageTranslator::Gles2TextureToEglImageTranslator( | |
| 18 bool use_backing_pixmaps) | |
| 19 : use_backing_pixmaps_(use_backing_pixmaps) { | |
| 20 } | |
| 21 | |
| 22 | |
| 23 Gles2TextureToEglImageTranslator::~Gles2TextureToEglImageTranslator() { | |
| 24 } | |
| 25 | |
| 26 EGLImageKHR Gles2TextureToEglImageTranslator::TranslateToEglImage( | |
| 27 EGLDisplay egl_display, EGLContext egl_context, | |
| 28 uint32 texture, | |
| 29 const gfx::Size& dimensions) { | |
| 30 EGLImageKHR hEglImage; | |
| 31 if (use_backing_pixmaps_) { | |
| 32 EGLint image_attrs[] = { EGL_IMAGE_PRESERVED_KHR, 1 , EGL_NONE }; | |
| 33 | |
| 34 glActiveTexture(GL_TEXTURE0); | |
| 35 glBindTexture(GL_TEXTURE_2D, texture); | |
| 36 | |
| 37 Display* x_display = base::MessagePumpForUI::GetDefaultXDisplay(); | |
| 38 Pixmap pixmap = XCreatePixmap(x_display, RootWindow(x_display, 0), | |
| 39 dimensions.width(), | |
| 40 dimensions.height(), 32); | |
| 41 | |
| 42 hEglImage = eglCreateImageKHR(egl_display, | |
| 43 EGL_NO_CONTEXT, | |
| 44 EGL_NATIVE_PIXMAP_KHR, | |
| 45 (EGLClientBuffer)pixmap, | |
| 46 image_attrs); | |
| 47 | |
| 48 glEGLImageTargetTexture2DOES(GL_TEXTURE_2D, hEglImage); | |
| 49 bool inserted = eglimage_pixmap_.insert(std::make_pair( | |
| 50 hEglImage, pixmap)).second; | |
| 51 DCHECK(inserted); | |
| 52 } else { | |
| 53 EGLint attrib = EGL_NONE; | |
| 54 // Create an EGLImage | |
| 55 hEglImage = eglCreateImageKHR(egl_display, | |
| 56 egl_context, | |
| 57 EGL_GL_TEXTURE_2D_KHR, | |
| 58 reinterpret_cast<EGLClientBuffer>(texture), | |
| 59 &attrib); | |
| 60 } | |
| 61 CHECK(hEglImage) << "Failed to eglCreateImageKHR for " << texture | |
| 62 << ", error: 0x" << std::hex << eglGetError(); | |
| 63 return hEglImage; | |
| 64 } | |
| 65 | |
| 66 uint32 Gles2TextureToEglImageTranslator::TranslateToTexture( | |
| 67 EGLImageKHR egl_image) { | |
| 68 // TODO(vhiremath@nvidia.com) | |
| 69 // Fill in the appropriate implementation. | |
| 70 GLuint texture = 0; | |
| 71 NOTIMPLEMENTED(); | |
| 72 return texture; | |
| 73 } | |
| 74 | |
| 75 void Gles2TextureToEglImageTranslator::DestroyEglImage( | |
| 76 EGLDisplay egl_display, EGLImageKHR egl_image) { | |
| 77 // Clients of this class will call this method for each EGLImage handle. | |
| 78 // Actual destroying of the handles is done here. | |
| 79 eglDestroyImageKHR(egl_display, egl_image); | |
| 80 | |
| 81 if (use_backing_pixmaps_) { | |
| 82 ImagePixmap::iterator it = eglimage_pixmap_.find(egl_image); | |
| 83 CHECK(it != eglimage_pixmap_.end()); | |
| 84 Pixmap pixmap = it->second; | |
| 85 eglimage_pixmap_.erase(it); | |
| 86 Display* x_display = base::MessagePumpForUI::GetDefaultXDisplay(); | |
| 87 XFreePixmap(x_display, pixmap); | |
| 88 } | |
| 89 } | |
| 90 | |
| 91 } // namespace content | |
| OLD | NEW |