Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(64)

Side by Side Diff: content/common/gpu/media/gles2_texture_to_egl_image_translator.cc

Issue 9346012: Video decode in hardware on ARM platform. (Closed) Base URL: http://src.chromium.org/svn/trunk/src/
Patch Set: '' Created 8 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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_image_targettexture_2does =
17 reinterpret_cast<PFNGLEGLIMAGETARGETTEXTURE2DOESPROC>(
18 eglGetProcAddress("glEGLImageTargetTexture2DOES"));
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);
19 } 22 }
20 23
21 Gles2TextureToEglImageTranslator::Gles2TextureToEglImageTranslator() { 24 Gles2TextureToEglImageTranslator::Gles2TextureToEglImageTranslator(
25 Display* x_display)
26 : x_display_(x_display) {
22 if (!AreEGLExtensionsInitialized()) { 27 if (!AreEGLExtensionsInitialized()) {
23 LOG(DFATAL) << "Failed to get EGL extensions"; 28 LOG(DFATAL) << "Failed to get EGL extensions";
24 return; 29 return;
25 } 30 }
26 CHECK_EQ(eglGetError(), EGL_SUCCESS); 31 CHECK_EQ(eglGetError(), EGL_SUCCESS);
27 } 32 }
28 33
29 34
30 Gles2TextureToEglImageTranslator::~Gles2TextureToEglImageTranslator() { 35 Gles2TextureToEglImageTranslator::~Gles2TextureToEglImageTranslator() {
31 } 36 }
32 37
33 EGLImageKHR Gles2TextureToEglImageTranslator::TranslateToEglImage( 38 EGLImageKHR Gles2TextureToEglImageTranslator::TranslateToEglImage(
34 EGLDisplay egl_display, EGLContext egl_context, uint32 texture) { 39 EGLDisplay egl_display, EGLContext egl_context,
35 EGLint attrib = EGL_NONE; 40 uint32 texture,
41 int width, int height) {
36 if (!egl_create_image_khr) 42 if (!egl_create_image_khr)
37 return EGL_NO_IMAGE_KHR; 43 return EGL_NO_IMAGE_KHR;
38 // Create an EGLImage 44 EGLImageKHR hEglImage;
39 EGLImageKHR hEglImage = egl_create_image_khr( 45 if (x_display_) {
Ami GONE FROM CHROMIUM 2012/02/18 00:00:25 This seems like a strange way to indicate which co
40 egl_display, 46 if (!glegl_image_targettexture_2does)
41 egl_context, 47 return EGL_NO_IMAGE_KHR;
42 EGL_GL_TEXTURE_2D_KHR, 48
43 reinterpret_cast<EGLClientBuffer>(texture), 49 EGLint image_attrs[] = { EGL_IMAGE_PRESERVED_KHR, 1 , EGL_NONE };
44 &attrib); 50
45 CHECK(hEglImage) << "Failed to eglCreateImageKHR for " << texture 51 glActiveTexture(GL_TEXTURE0);
46 << ", error: 0x" << std::hex << eglGetError(); 52 glBindTexture(GL_TEXTURE_2D, texture);
53
54 Pixmap pixmap = XCreatePixmap(x_display_, RootWindow(x_display_, 0),
55 width, height, 32);
56
57 hEglImage = egl_create_image_khr(egl_display,
58 EGL_NO_CONTEXT,
59 EGL_NATIVE_PIXMAP_KHR,
60 (EGLClientBuffer)pixmap,
61 image_attrs);
62 CHECK(hEglImage) << "Failed to eglCreateImageKHR for " << texture
63 << ", error: 0x" << std::hex << eglGetError();
64
65 glegl_image_targettexture_2does(GL_TEXTURE_2D, hEglImage);
66 eglimage_pixmap_.insert(std::make_pair(hEglImage, pixmap));
Ami GONE FROM CHROMIUM 2012/02/18 00:00:25 If you expect no collisions, the standard idiom is
67
68 } else {
69 EGLint attrib = EGL_NONE;
70 // Create an EGLImage
71 hEglImage = egl_create_image_khr(egl_display,
72 egl_context,
73 EGL_GL_TEXTURE_2D_KHR,
74 reinterpret_cast<EGLClientBuffer>(texture),
75 &attrib);
76 CHECK(hEglImage) << "Failed to eglCreateImageKHR for " << texture
Ami GONE FROM CHROMIUM 2012/02/18 00:00:25 This CHECK and the one at l.62 can be coallesced
77 << ", error: 0x" << std::hex << eglGetError();
78
79 }
47 return hEglImage; 80 return hEglImage;
48 } 81 }
49 82
50 uint32 Gles2TextureToEglImageTranslator::TranslateToTexture( 83 uint32 Gles2TextureToEglImageTranslator::TranslateToTexture(
51 EGLImageKHR egl_image) { 84 EGLImageKHR egl_image) {
52 // TODO(vhiremath@nvidia.com) 85 // TODO(vhiremath@nvidia.com)
53 // Fill in the appropriate implementation. 86 // Fill in the appropriate implementation.
54 GLuint texture = 0; 87 GLuint texture = 0;
55 NOTIMPLEMENTED(); 88 NOTIMPLEMENTED();
56 return texture; 89 return texture;
57 } 90 }
58 91
59 void Gles2TextureToEglImageTranslator::DestroyEglImage( 92 void Gles2TextureToEglImageTranslator::DestroyEglImage(
60 EGLDisplay egl_display, EGLImageKHR egl_image) { 93 EGLDisplay egl_display, EGLImageKHR egl_image) {
61 // Clients of this class will call this method for each EGLImage handle. 94 // Clients of this class will call this method for each EGLImage handle.
62 // Actual destroying of the handles is done here. 95 // Actual destroying of the handles is done here.
63 if (!egl_destroy_image_khr) { 96 if (!egl_destroy_image_khr) {
64 DLOG(ERROR) << "egl_destroy_image_khr failed"; 97 DLOG(ERROR) << "egl_destroy_image_khr failed";
65 return; 98 return;
66 } 99 }
67 egl_destroy_image_khr(egl_display, egl_image); 100 egl_destroy_image_khr(egl_display, egl_image);
101
102 if (x_display_) {
103 ImagePixmap::iterator it = eglimage_pixmap_.find(egl_image);
104 CHECK(it != eglimage_pixmap_.end());
105 Pixmap pixmap = it->second;
Ami GONE FROM CHROMIUM 2012/02/18 00:00:25 Also eglimage_pixmap_.erase(it); ?
106 if (pixmap)
Ami GONE FROM CHROMIUM 2012/02/18 00:00:25 When will this test be false?
107 XFreePixmap(x_display_, pixmap);
108 }
68 } 109 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698