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

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 &&
23 glegl_image_targettexture_2does);
19 } 24 }
20 25
21 Gles2TextureToEglImageTranslator::Gles2TextureToEglImageTranslator() { 26 Gles2TextureToEglImageTranslator::Gles2TextureToEglImageTranslator(
27 bool use_backing_pixmaps)
28 : use_backing_pixmaps_(use_backing_pixmaps) {
22 if (!AreEGLExtensionsInitialized()) { 29 if (!AreEGLExtensionsInitialized()) {
23 LOG(DFATAL) << "Failed to get EGL extensions"; 30 LOG(DFATAL) << "Failed to get EGL extensions";
24 return; 31 return;
25 } 32 }
26 CHECK_EQ(eglGetError(), EGL_SUCCESS); 33 CHECK_EQ(eglGetError(), EGL_SUCCESS);
27 } 34 }
28 35
29 36
30 Gles2TextureToEglImageTranslator::~Gles2TextureToEglImageTranslator() { 37 Gles2TextureToEglImageTranslator::~Gles2TextureToEglImageTranslator() {
31 } 38 }
32 39
33 EGLImageKHR Gles2TextureToEglImageTranslator::TranslateToEglImage( 40 EGLImageKHR Gles2TextureToEglImageTranslator::TranslateToEglImage(
34 EGLDisplay egl_display, EGLContext egl_context, uint32 texture) { 41 EGLDisplay egl_display, EGLContext egl_context,
35 EGLint attrib = EGL_NONE; 42 uint32 texture,
43 const gfx::Size& dimensions) {
36 if (!egl_create_image_khr) 44 if (!egl_create_image_khr)
37 return EGL_NO_IMAGE_KHR; 45 return EGL_NO_IMAGE_KHR;
38 // Create an EGLImage 46 EGLImageKHR hEglImage;
39 EGLImageKHR hEglImage = egl_create_image_khr( 47 if (use_backing_pixmaps_) {
40 egl_display, 48 if (!glegl_image_targettexture_2does)
41 egl_context, 49 return EGL_NO_IMAGE_KHR;
42 EGL_GL_TEXTURE_2D_KHR, 50
43 reinterpret_cast<EGLClientBuffer>(texture), 51 EGLint image_attrs[] = { EGL_IMAGE_PRESERVED_KHR, 1 , EGL_NONE };
44 &attrib); 52
53 glActiveTexture(GL_TEXTURE0);
54 glBindTexture(GL_TEXTURE_2D, texture);
55
56 Display* x_display = gfx::GLSurfaceEGL::GetNativeDisplay();
57 Pixmap pixmap = XCreatePixmap(x_display, RootWindow(x_display, 0),
58 dimensions.width(),
59 dimensions.height(), 32);
60
61 hEglImage = egl_create_image_khr(egl_display,
62 EGL_NO_CONTEXT,
63 EGL_NATIVE_PIXMAP_KHR,
64 (EGLClientBuffer)pixmap,
65 image_attrs);
66
67 glegl_image_targettexture_2does(GL_TEXTURE_2D, hEglImage);
68 bool inserted = eglimage_pixmap_.insert(std::make_pair(
69 hEglImage, pixmap)).second;
70 DCHECK(inserted);
71 } else {
72 EGLint attrib = EGL_NONE;
73 // Create an EGLImage
74 hEglImage = egl_create_image_khr(egl_display,
75 egl_context,
76 EGL_GL_TEXTURE_2D_KHR,
77 reinterpret_cast<EGLClientBuffer>(texture),
78 &attrib);
79 }
45 CHECK(hEglImage) << "Failed to eglCreateImageKHR for " << texture 80 CHECK(hEglImage) << "Failed to eglCreateImageKHR for " << texture
46 << ", error: 0x" << std::hex << eglGetError(); 81 << ", error: 0x" << std::hex << eglGetError();
47 return hEglImage; 82 return hEglImage;
48 } 83 }
49 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 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.
63 if (!egl_destroy_image_khr) { 98 if (!egl_destroy_image_khr) {
64 DLOG(ERROR) << "egl_destroy_image_khr failed"; 99 DLOG(ERROR) << "egl_destroy_image_khr failed";
65 return; 100 return;
66 } 101 }
67 egl_destroy_image_khr(egl_display, egl_image); 102 egl_destroy_image_khr(egl_display, egl_image);
103
104 if (use_backing_pixmaps_) {
105 ImagePixmap::iterator it = eglimage_pixmap_.find(egl_image);
106 CHECK(it != eglimage_pixmap_.end());
107 Pixmap pixmap = it->second;
108 eglimage_pixmap_.erase(it);
109 Display* x_display = gfx::GLSurfaceEGL::GetNativeDisplay();
110 XFreePixmap(x_display, pixmap);
111 }
68 } 112 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698