OLD | NEW |
---|---|
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 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 | 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/media/gles2_texture_to_egl_image_translator.h" | 5 #include "content/common/gpu/media/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 static PFNGLEGLIMAGETARGETTEXTURE2DOESPROC glEGL_ImageTargetTexture2DOES = | |
Ami GONE FROM CHROMIUM
2012/02/07 17:05:40
please follow the naming conventions above.
| |
17 reinterpret_cast<PFNGLEGLIMAGETARGETTEXTURE2DOESPROC>( | |
18 eglGetProcAddress("glEGLImageTargetTexture2DOES")); | |
Ami GONE FROM CHROMIUM
2012/02/07 17:05:40
This is an extension that's not guaranteed to exis
| |
16 | 19 |
17 static bool AreEGLExtensionsInitialized() { | 20 static bool AreEGLExtensionsInitialized() { |
18 return (egl_create_image_khr && egl_destroy_image_khr); | 21 return (egl_create_image_khr && egl_destroy_image_khr |
22 && glEGL_ImageTargetTexture2DOES); | |
Ami GONE FROM CHROMIUM
2012/02/07 17:05:40
&& goes on previous line, and indent is wrong.
Ple
| |
19 } | 23 } |
20 | 24 |
21 Gles2TextureToEglImageTranslator::Gles2TextureToEglImageTranslator() { | 25 Gles2TextureToEglImageTranslator::Gles2TextureToEglImageTranslator() { |
22 if (!AreEGLExtensionsInitialized()) { | 26 if (!AreEGLExtensionsInitialized()) { |
23 LOG(DFATAL) << "Failed to get EGL extensions"; | 27 LOG(DFATAL) << "Failed to get EGL extensions"; |
24 return; | 28 return; |
25 } | 29 } |
26 CHECK_EQ(eglGetError(), EGL_SUCCESS); | 30 CHECK_EQ(eglGetError(), EGL_SUCCESS); |
27 } | 31 } |
28 | 32 |
(...skipping 11 matching lines...) Expand all Loading... | |
40 egl_display, | 44 egl_display, |
41 egl_context, | 45 egl_context, |
42 EGL_GL_TEXTURE_2D_KHR, | 46 EGL_GL_TEXTURE_2D_KHR, |
43 reinterpret_cast<EGLClientBuffer>(texture), | 47 reinterpret_cast<EGLClientBuffer>(texture), |
44 &attrib); | 48 &attrib); |
45 CHECK(hEglImage) << "Failed to eglCreateImageKHR for " << texture | 49 CHECK(hEglImage) << "Failed to eglCreateImageKHR for " << texture |
46 << ", error: 0x" << std::hex << eglGetError(); | 50 << ", error: 0x" << std::hex << eglGetError(); |
47 return hEglImage; | 51 return hEglImage; |
48 } | 52 } |
49 | 53 |
54 EGLImageKHR Gles2TextureToEglImageTranslator::CreateEglImage( | |
55 Display* x_display, EGLDisplay egl_display, EGLContext egl_context, | |
56 EGLSurface egl_surface, uint32 texture, int width, int height) { | |
57 | |
58 if (!egl_create_image_khr) | |
59 return EGL_NO_IMAGE_KHR; | |
60 eglMakeCurrent(egl_display, egl_surface, egl_surface, egl_context); | |
61 | |
62 EGLint image_attrs[] = { EGL_IMAGE_PRESERVED_KHR, 1 , EGL_NONE }; | |
63 | |
64 glActiveTexture(GL_TEXTURE0); | |
65 glBindTexture(GL_TEXTURE_2D, texture); | |
Ami GONE FROM CHROMIUM
2012/02/07 17:05:40
Given the calls below (which seem to bind the eglI
| |
66 | |
67 Pixmap pixmap = XCreatePixmap(x_display, RootWindow(x_display, 0), | |
68 width, height, 32); | |
69 | |
70 pixmap_.push_back(pixmap); | |
71 | |
72 EGLImageKHR hEglImage = egl_create_image_khr( egl_display, | |
73 EGL_NO_CONTEXT, | |
74 EGL_NATIVE_PIXMAP_KHR, | |
75 (EGLClientBuffer)pixmap, | |
76 image_attrs); | |
77 CHECK(hEglImage) << "Failed to eglCreateImageKHR for " << texture | |
78 << ", error: 0x" << std::hex << eglGetError(); | |
79 | |
80 glEGL_ImageTargetTexture2DOES( GL_TEXTURE_2D, hEglImage ); | |
81 | |
82 return hEglImage; | |
83 } | |
84 | |
50 uint32 Gles2TextureToEglImageTranslator::TranslateToTexture( | 85 uint32 Gles2TextureToEglImageTranslator::TranslateToTexture( |
51 EGLImageKHR egl_image) { | 86 EGLImageKHR egl_image) { |
52 // TODO(vhiremath@nvidia.com) | 87 // TODO(vhiremath@nvidia.com) |
53 // Fill in the appropriate implementation. | 88 // Fill in the appropriate implementation. |
54 GLuint texture = 0; | 89 GLuint texture = 0; |
55 NOTIMPLEMENTED(); | 90 NOTIMPLEMENTED(); |
56 return texture; | 91 return texture; |
57 } | 92 } |
58 | 93 |
59 void Gles2TextureToEglImageTranslator::DestroyEglImage( | 94 void Gles2TextureToEglImageTranslator::DestroyEglImage( |
60 EGLDisplay egl_display, EGLImageKHR egl_image) { | 95 Display* x_display, EGLDisplay egl_display, EGLImageKHR egl_image) { |
61 // Clients of this class will call this method for each EGLImage handle. | 96 // Clients of this class will call this method for each EGLImage handle. |
62 // Actual destroying of the handles is done here. | 97 // Actual destroying of the handles is done here. |
98 unsigned int i; | |
63 if (!egl_destroy_image_khr) { | 99 if (!egl_destroy_image_khr) { |
64 DLOG(ERROR) << "egl_destroy_image_khr failed"; | 100 DLOG(ERROR) << "egl_destroy_image_khr failed"; |
65 return; | 101 return; |
66 } | 102 } |
67 egl_destroy_image_khr(egl_display, egl_image); | 103 egl_destroy_image_khr(egl_display, egl_image); |
104 | |
105 for(i=0; i<pixmap_.size(); i++) | |
Ami GONE FROM CHROMIUM
2012/02/07 17:05:40
IIUC, this is completely broken.
Why not instead s
| |
106 { | |
107 if(pixmap_[i]) | |
108 { | |
109 XFreePixmap(x_display, pixmap_[i]); | |
110 pixmap_[i++] = 0; | |
111 break; | |
112 } | |
113 } | |
114 | |
115 if(i == pixmap_.size()) | |
116 pixmap_.clear(); | |
117 | |
68 } | 118 } |
OLD | NEW |