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

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

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

Powered by Google App Engine
This is Rietveld 408576698