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

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 #include "ui/gfx/gl/gl_surface_egl.h"
6 7
7 #include "base/logging.h" 8 #include "base/logging.h"
8 9
9 // Get EGL extension functions. 10 // Get EGL extension functions.
10 static PFNEGLCREATEIMAGEKHRPROC egl_create_image_khr = 11 static PFNEGLCREATEIMAGEKHRPROC egl_create_image_khr =
11 reinterpret_cast<PFNEGLCREATEIMAGEKHRPROC>( 12 reinterpret_cast<PFNEGLCREATEIMAGEKHRPROC>(
12 eglGetProcAddress("eglCreateImageKHR")); 13 eglGetProcAddress("eglCreateImageKHR"));
13 static PFNEGLDESTROYIMAGEKHRPROC egl_destroy_image_khr = 14 static PFNEGLDESTROYIMAGEKHRPROC egl_destroy_image_khr =
14 reinterpret_cast<PFNEGLDESTROYIMAGEKHRPROC>( 15 reinterpret_cast<PFNEGLDESTROYIMAGEKHRPROC>(
15 eglGetProcAddress("eglDestroyImageKHR")); 16 eglGetProcAddress("eglDestroyImageKHR"));
17 static PFNGLEGLIMAGETARGETTEXTURE2DOESPROC glegl_image_targettexture_2does =
18 reinterpret_cast<PFNGLEGLIMAGETARGETTEXTURE2DOESPROC>(
19 eglGetProcAddress("glEGLImageTargetTexture2DOES"));
16 20
17 static bool AreEGLExtensionsInitialized() { 21 static bool AreEGLExtensionsInitialized() {
18 return (egl_create_image_khr && egl_destroy_image_khr); 22 return (egl_create_image_khr && egl_destroy_image_khr);
19 } 23 }
20 24
21 Gles2TextureToEglImageTranslator::Gles2TextureToEglImageTranslator() { 25 Gles2TextureToEglImageTranslator::Gles2TextureToEglImageTranslator(
26 bool use_backing_pixmaps)
27 : use_backing_pixmaps_(use_backing_pixmaps) {
22 if (!AreEGLExtensionsInitialized()) { 28 if (!AreEGLExtensionsInitialized()) {
Ami GONE FROM CHROMIUM 2012/02/20 16:54:28 What happens if glegl_image_targettexture_2does is
23 LOG(DFATAL) << "Failed to get EGL extensions"; 29 LOG(DFATAL) << "Failed to get EGL extensions";
24 return; 30 return;
25 } 31 }
26 CHECK_EQ(eglGetError(), EGL_SUCCESS); 32 CHECK_EQ(eglGetError(), EGL_SUCCESS);
27 } 33 }
28 34
29 35
30 Gles2TextureToEglImageTranslator::~Gles2TextureToEglImageTranslator() { 36 Gles2TextureToEglImageTranslator::~Gles2TextureToEglImageTranslator() {
31 } 37 }
32 38
33 EGLImageKHR Gles2TextureToEglImageTranslator::TranslateToEglImage( 39 EGLImageKHR Gles2TextureToEglImageTranslator::TranslateToEglImage(
34 EGLDisplay egl_display, EGLContext egl_context, uint32 texture) { 40 EGLDisplay egl_display, EGLContext egl_context,
35 EGLint attrib = EGL_NONE; 41 uint32 texture,
42 gfx::Size* dimensions) {
36 if (!egl_create_image_khr) 43 if (!egl_create_image_khr)
37 return EGL_NO_IMAGE_KHR; 44 return EGL_NO_IMAGE_KHR;
38 // Create an EGLImage 45 EGLImageKHR hEglImage;
39 EGLImageKHR hEglImage = egl_create_image_khr( 46 if (use_backing_pixmaps_) {
40 egl_display, 47 if (!glegl_image_targettexture_2does)
41 egl_context, 48 return EGL_NO_IMAGE_KHR;
42 EGL_GL_TEXTURE_2D_KHR, 49
43 reinterpret_cast<EGLClientBuffer>(texture), 50 EGLint image_attrs[] = { EGL_IMAGE_PRESERVED_KHR, 1 , EGL_NONE };
44 &attrib); 51
52 glActiveTexture(GL_TEXTURE0);
53 glBindTexture(GL_TEXTURE_2D, texture);
54
55 Display* x_display = gfx::GLSurfaceEGL::GetNativeDisplay();
56 Pixmap pixmap = XCreatePixmap(x_display, RootWindow(x_display, 0),
57 dimensions->width(),
58 dimensions->height(), 32);
59
60 hEglImage = egl_create_image_khr(egl_display,
61 EGL_NO_CONTEXT,
62 EGL_NATIVE_PIXMAP_KHR,
63 (EGLClientBuffer)pixmap,
64 image_attrs);
65
66 glegl_image_targettexture_2does(GL_TEXTURE_2D, hEglImage);
67 bool inserted = eglimage_pixmap_.insert(std::make_pair(
68 hEglImage, pixmap)).second;
69 DCHECK(inserted);
70 } else {
71 EGLint attrib = EGL_NONE;
72 // Create an EGLImage
73 hEglImage = egl_create_image_khr(egl_display,
74 egl_context,
75 EGL_GL_TEXTURE_2D_KHR,
76 reinterpret_cast<EGLClientBuffer>(texture),
77 &attrib);
78 }
45 CHECK(hEglImage) << "Failed to eglCreateImageKHR for " << texture 79 CHECK(hEglImage) << "Failed to eglCreateImageKHR for " << texture
46 << ", error: 0x" << std::hex << eglGetError(); 80 << ", error: 0x" << std::hex << eglGetError();
47 return hEglImage; 81 return hEglImage;
48 } 82 }
49 83
50 uint32 Gles2TextureToEglImageTranslator::TranslateToTexture( 84 uint32 Gles2TextureToEglImageTranslator::TranslateToTexture(
51 EGLImageKHR egl_image) { 85 EGLImageKHR egl_image) {
52 // TODO(vhiremath@nvidia.com) 86 // TODO(vhiremath@nvidia.com)
53 // Fill in the appropriate implementation. 87 // Fill in the appropriate implementation.
54 GLuint texture = 0; 88 GLuint texture = 0;
55 NOTIMPLEMENTED(); 89 NOTIMPLEMENTED();
56 return texture; 90 return texture;
57 } 91 }
58 92
59 void Gles2TextureToEglImageTranslator::DestroyEglImage( 93 void Gles2TextureToEglImageTranslator::DestroyEglImage(
60 EGLDisplay egl_display, EGLImageKHR egl_image) { 94 EGLDisplay egl_display, EGLImageKHR egl_image) {
61 // Clients of this class will call this method for each EGLImage handle. 95 // Clients of this class will call this method for each EGLImage handle.
62 // Actual destroying of the handles is done here. 96 // Actual destroying of the handles is done here.
63 if (!egl_destroy_image_khr) { 97 if (!egl_destroy_image_khr) {
64 DLOG(ERROR) << "egl_destroy_image_khr failed"; 98 DLOG(ERROR) << "egl_destroy_image_khr failed";
65 return; 99 return;
66 } 100 }
67 egl_destroy_image_khr(egl_display, egl_image); 101 egl_destroy_image_khr(egl_display, egl_image);
102
103 if (use_backing_pixmaps_) {
104 ImagePixmap::iterator it = eglimage_pixmap_.find(egl_image);
105 CHECK(it != eglimage_pixmap_.end());
106 Pixmap pixmap = it->second;
107 eglimage_pixmap_.erase(it);
108 Display* x_display = gfx::GLSurfaceEGL::GetNativeDisplay();
109 XFreePixmap(x_display, pixmap);
110 }
68 } 111 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698