| OLD | NEW |
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "content/common/gpu/gles2_texture_to_egl_image_translator.h" | 5 #include "content/common/gpu/gles2_texture_to_egl_image_translator.h" |
| 6 | 6 |
| 7 #include "base/logging.h" | 7 #include "base/logging.h" |
| 8 | 8 |
| 9 // Get EGL extension functions. | 9 // Get EGL extension functions. |
| 10 static PFNEGLCREATEIMAGEKHRPROC egl_create_image_khr = | 10 static PFNEGLCREATEIMAGEKHRPROC egl_create_image_khr = |
| 11 reinterpret_cast<PFNEGLCREATEIMAGEKHRPROC>( | 11 reinterpret_cast<PFNEGLCREATEIMAGEKHRPROC>( |
| 12 eglGetProcAddress("eglCreateImageKHR")); | 12 eglGetProcAddress("eglCreateImageKHR")); |
| 13 static PFNEGLDESTROYIMAGEKHRPROC egl_destroy_image_khr = | 13 static PFNEGLDESTROYIMAGEKHRPROC egl_destroy_image_khr = |
| 14 reinterpret_cast<PFNEGLDESTROYIMAGEKHRPROC>( | 14 reinterpret_cast<PFNEGLDESTROYIMAGEKHRPROC>( |
| 15 eglGetProcAddress("eglDestroyImageKHR")); | 15 eglGetProcAddress("eglDestroyImageKHR")); |
| 16 | 16 |
| 17 static bool AreEGLExtensionsInitialized() { | 17 static bool AreEGLExtensionsInitialized() { |
| 18 return (egl_create_image_khr && egl_destroy_image_khr); | 18 return (egl_create_image_khr && egl_destroy_image_khr); |
| 19 } | 19 } |
| 20 | 20 |
| 21 Gles2TextureToEglImageTranslator::Gles2TextureToEglImageTranslator( | 21 Gles2TextureToEglImageTranslator::Gles2TextureToEglImageTranslator() { |
| 22 Display* display, | |
| 23 int32 gles2_context_id) | |
| 24 : size_(320, 240), | |
| 25 egl_display_((EGLDisplay)0x1/*display*/), | |
| 26 egl_context_((EGLContext)0x368b8001/*gles2_context_id*/) { | |
| 27 // TODO(vhiremath@nvidia.com) | |
| 28 // Replace the above hard coded values with appropriate variables. | |
| 29 // size_/egl_display_/egl_context_. | |
| 30 // These should be initiated from the App. | |
| 31 if (!AreEGLExtensionsInitialized()) { | 22 if (!AreEGLExtensionsInitialized()) { |
| 32 LOG(DFATAL) << "Failed to get EGL extensions"; | 23 LOG(DFATAL) << "Failed to get EGL extensions"; |
| 33 return; | 24 return; |
| 34 } | 25 } |
| 35 } | 26 } |
| 36 | 27 |
| 37 | 28 |
| 38 Gles2TextureToEglImageTranslator::~Gles2TextureToEglImageTranslator() { | 29 Gles2TextureToEglImageTranslator::~Gles2TextureToEglImageTranslator() { |
| 39 } | 30 } |
| 40 | 31 |
| 41 EGLImageKHR Gles2TextureToEglImageTranslator::TranslateToEglImage( | 32 EGLImageKHR Gles2TextureToEglImageTranslator::TranslateToEglImage( |
| 42 uint32 texture) { | 33 EGLDisplay egl_display, EGLContext egl_context, uint32 texture) { |
| 43 EGLint attrib = EGL_NONE; | 34 EGLint attrib = EGL_NONE; |
| 44 if (!egl_create_image_khr) | 35 if (!egl_create_image_khr) |
| 45 return EGL_NO_IMAGE_KHR; | 36 return EGL_NO_IMAGE_KHR; |
| 46 // Create an EGLImage | 37 // Create an EGLImage |
| 47 EGLImageKHR hEglImage = egl_create_image_khr( | 38 EGLImageKHR hEglImage = egl_create_image_khr( |
| 48 egl_display_, | 39 egl_display, |
| 49 egl_context_, | 40 egl_context, |
| 50 EGL_GL_TEXTURE_2D_KHR, | 41 EGL_GL_TEXTURE_2D_KHR, |
| 51 reinterpret_cast<EGLClientBuffer>(texture), | 42 reinterpret_cast<EGLClientBuffer>(texture), |
| 52 &attrib); | 43 &attrib); |
| 44 CHECK(hEglImage); |
| 53 return hEglImage; | 45 return hEglImage; |
| 54 } | 46 } |
| 55 | 47 |
| 56 uint32 Gles2TextureToEglImageTranslator::TranslateToTexture( | 48 uint32 Gles2TextureToEglImageTranslator::TranslateToTexture( |
| 57 EGLImageKHR egl_image) { | 49 EGLImageKHR egl_image) { |
| 58 // TODO(vhiremath@nvidia.com) | 50 // TODO(vhiremath@nvidia.com) |
| 59 // Fill in the appropriate implementation. | 51 // Fill in the appropriate implementation. |
| 60 GLuint texture = 0; | 52 GLuint texture = 0; |
| 61 NOTIMPLEMENTED(); | 53 NOTIMPLEMENTED(); |
| 62 return texture; | 54 return texture; |
| 63 } | 55 } |
| 64 | 56 |
| 65 void Gles2TextureToEglImageTranslator::DestroyEglImage(EGLImageKHR egl_image) { | 57 void Gles2TextureToEglImageTranslator::DestroyEglImage( |
| 58 EGLDisplay egl_display, EGLImageKHR egl_image) { |
| 66 // Clients of this class will call this method for each EGLImage handle. | 59 // Clients of this class will call this method for each EGLImage handle. |
| 67 // Actual destroying of the handles is done here. | 60 // Actual destroying of the handles is done here. |
| 68 if (!egl_destroy_image_khr) { | 61 if (!egl_destroy_image_khr) { |
| 69 LOG(ERROR) << "egl_destroy_image_khr failed"; | 62 LOG(ERROR) << "egl_destroy_image_khr failed"; |
| 70 return; | 63 return; |
| 71 } | 64 } |
| 72 egl_destroy_image_khr(egl_display_, egl_image); | 65 egl_destroy_image_khr(egl_display, egl_image); |
| 73 } | 66 } |
| OLD | NEW |