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

Unified Diff: content/common/gpu/media/vaapi_video_decode_accelerator.cc

Issue 43283002: Enable GLX/EGL backend switching while run HW video decode with libva. (Closed) Base URL: https://git.chromium.org/chromium/src.git@master
Patch Set: Created 7 years, 2 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 side-by-side diff with in-line comments
Download patch
Index: content/common/gpu/media/vaapi_video_decode_accelerator.cc
diff --git a/content/common/gpu/media/vaapi_video_decode_accelerator.cc b/content/common/gpu/media/vaapi_video_decode_accelerator.cc
index cd18574a8d8142d65f6fb5485444a60218d62a25..64d30da3c2c5e28cb3227ae5aff1550aa7294aad 100644
--- a/content/common/gpu/media/vaapi_video_decode_accelerator.cc
+++ b/content/common/gpu/media/vaapi_video_decode_accelerator.cc
@@ -74,7 +74,11 @@ class VaapiVideoDecodeAccelerator::TFPPicture {
static linked_ptr<TFPPicture> Create(
const base::Callback<bool(void)>& make_context_current,
+#if defined(VIDEO_TEXTURE_GLX_BACKEND)
const GLXFBConfig& fb_config,
+#elif defined(VIDEO_TEXTURE_EGL_BACKEND)
+ EGLDisplay egl_display,
+#endif
Display* x_display,
int32 picture_buffer_id,
uint32 texture_id,
@@ -105,8 +109,11 @@ class VaapiVideoDecodeAccelerator::TFPPicture {
int32 picture_buffer_id,
uint32 texture_id,
gfx::Size size);
-
+#if defined(VIDEO_TEXTURE_GLX_BACKEND)
bool Initialize(const GLXFBConfig& fb_config);
+#elif defined(VIDEO_TEXTURE_EGL_BACKEND)
+ bool Initialize(EGLDisplay egl_display);
+#endif
base::Callback<bool(void)> make_context_current_;
@@ -120,8 +127,12 @@ class VaapiVideoDecodeAccelerator::TFPPicture {
// Pixmaps bound to this texture.
Pixmap x_pixmap_;
+#if defined(VIDEO_TEXTURE_GLX_BACKEND)
GLXPixmap glx_pixmap_;
-
+#elif defined(VIDEO_TEXTURE_EGL_BACKEND)
+ EGLDisplay egl_display_;
+ EGLImageKHR egl_image_;
+#endif
DISALLOW_COPY_AND_ASSIGN(TFPPicture);
};
@@ -137,14 +148,24 @@ VaapiVideoDecodeAccelerator::TFPPicture::TFPPicture(
texture_id_(texture_id),
size_(size),
x_pixmap_(0),
- glx_pixmap_(0) {
+#if defined(VIDEO_TEXTURE_GLX_BACKEND)
+ glx_pixmap_(0)
+#elif defined(VIDEO_TEXTURE_EGL_BACKEND)
+ egl_display_(0),
+ egl_image_(0)
+#endif
+ {
DCHECK(!make_context_current_.is_null());
};
linked_ptr<VaapiVideoDecodeAccelerator::TFPPicture>
VaapiVideoDecodeAccelerator::TFPPicture::Create(
const base::Callback<bool(void)>& make_context_current,
+#if defined(VIDEO_TEXTURE_GLX_BACKEND)
const GLXFBConfig& fb_config,
+#elif defined(VIDEO_TEXTURE_EGL_BACKEND)
+ EGLDisplay egl_display,
+#endif
Display* x_display,
int32 picture_buffer_id,
uint32 texture_id,
@@ -154,14 +175,22 @@ VaapiVideoDecodeAccelerator::TFPPicture::Create(
new TFPPicture(make_context_current, x_display, picture_buffer_id,
texture_id, size));
+#if defined(VIDEO_TEXTURE_GLX_BACKEND)
if (!tfp_picture->Initialize(fb_config))
+#elif defined(VIDEO_TEXTURE_EGL_BACKEND)
+ if (!tfp_picture->Initialize(egl_display))
+#endif
tfp_picture.reset();
return tfp_picture;
}
bool VaapiVideoDecodeAccelerator::TFPPicture::Initialize(
+#if defined(VIDEO_TEXTURE_GLX_BACKEND)
const GLXFBConfig& fb_config) {
+#elif defined(VIDEO_TEXTURE_EGL_BACKEND)
+ EGLDisplay egl_display) {
+#endif
// Check for NULL prevents unittests from crashing on nonexistent ChildThread.
DCHECK(ChildThread::current() == NULL ||
ChildThread::current()->message_loop() == base::MessageLoop::current());
@@ -179,7 +208,7 @@ bool VaapiVideoDecodeAccelerator::TFPPicture::Initialize(
DVLOG(1) << "Failed creating an X Pixmap for TFP";
return false;
}
-
+#if defined(VIDEO_TEXTURE_GLX_BACKEND)
static const int pixmap_attr[] = {
GLX_TEXTURE_TARGET_EXT, GLX_TEXTURE_2D_EXT,
GLX_TEXTURE_FORMAT_EXT, GLX_TEXTURE_FORMAT_RGB_EXT,
@@ -192,6 +221,20 @@ bool VaapiVideoDecodeAccelerator::TFPPicture::Initialize(
DVLOG(1) << "Failed creating a GLX Pixmap for TFP";
return false;
}
+#elif defined(VIDEO_TEXTURE_EGL_BACKEND)
+ egl_display_ = egl_display;
+ EGLint image_attrs[] = { EGL_IMAGE_PRESERVED_KHR, 1 , EGL_NONE };
+
+ egl_image_ = eglCreateImageKHR(egl_display_,
+ EGL_NO_CONTEXT,
+ EGL_NATIVE_PIXMAP_KHR,
+ (EGLClientBuffer)x_pixmap_,
+ image_attrs);
+ if (!egl_image_) {
+ DVLOG(1) << "Failed creating a EGLImage from Pixmap for KHR";
+ return false;
+ }
+#endif
return true;
}
@@ -202,10 +245,16 @@ VaapiVideoDecodeAccelerator::TFPPicture::~TFPPicture() {
ChildThread::current()->message_loop() == base::MessageLoop::current());
// Unbind surface from texture and deallocate resources.
+#if defined(VIDEO_TEXTURE_GLX_BACKEND)
if (glx_pixmap_ && make_context_current_.Run()) {
glXReleaseTexImageEXT(x_display_, glx_pixmap_, GLX_FRONT_LEFT_EXT);
glXDestroyPixmap(x_display_, glx_pixmap_);
}
+#elif defined(VIDEO_TEXTURE_EGL_BACKEND)
+ if (egl_image_ && make_context_current_.Run()) {
+ eglDestroyImageKHR(egl_display_, egl_image_);
+ }
+#endif
if (x_pixmap_)
XFreePixmap(x_display_, x_pixmap_);
@@ -214,7 +263,11 @@ VaapiVideoDecodeAccelerator::TFPPicture::~TFPPicture() {
bool VaapiVideoDecodeAccelerator::TFPPicture::Bind() {
DCHECK(x_pixmap_);
+#if defined(VIDEO_TEXTURE_GLX_BACKEND)
DCHECK(glx_pixmap_);
+#elif defined(VIDEO_TEXTURE_EGL_BACKEND)
+ DCHECK(egl_image_);
+#endif
// Check for NULL prevents unittests from crashing on nonexistent ChildThread.
DCHECK(ChildThread::current() == NULL ||
ChildThread::current()->message_loop() == base::MessageLoop::current());
@@ -223,8 +276,11 @@ bool VaapiVideoDecodeAccelerator::TFPPicture::Bind() {
return false;
gfx::ScopedTextureBinder texture_binder(GL_TEXTURE_2D, texture_id_);
+#if defined(VIDEO_TEXTURE_GLX_BACKEND)
glXBindTexImageEXT(x_display_, glx_pixmap_, GLX_FRONT_LEFT_EXT, NULL);
-
+#elif defined(VIDEO_TEXTURE_EGL_BACKEND)
+ glEGLImageTargetTexture2DOES(GL_TEXTURE_2D, egl_image_);
+#endif
return true;
}
@@ -240,11 +296,21 @@ VaapiVideoDecodeAccelerator::TFPPicture*
}
VaapiVideoDecodeAccelerator::VaapiVideoDecodeAccelerator(
+#if defined(VIDEO_TEXTURE_GLX_BACKEND)
Display* x_display, GLXContext glx_context,
+#elif defined(VIDEO_TEXTURE_EGL_BACKEND)
+ EGLDisplay egl_display, EGLContext egl_context,
+#endif
Client* client,
const base::Callback<bool(void)>& make_context_current)
+#if defined(VIDEO_TEXTURE_GLX_BACKEND)
: x_display_(x_display),
glx_context_(glx_context),
+#elif defined(VIDEO_TEXTURE_EGL_BACKEND)
+ : x_display_(0),
+ egl_display_(egl_display),
+ egl_context_(egl_context),
+#endif
make_context_current_(make_context_current),
state_(kUninitialized),
input_ready_(&lock_),
@@ -272,7 +338,7 @@ class ScopedPtrXFree {
::XFree(x);
}
};
-
+#if defined(VIDEO_TEXTURE_GLX_BACKEND)
bool VaapiVideoDecodeAccelerator::InitializeFBConfig() {
const int fbconfig_attr[] = {
GLX_DRAWABLE_TYPE, GLX_PIXMAP_BIT,
@@ -294,7 +360,7 @@ bool VaapiVideoDecodeAccelerator::InitializeFBConfig() {
fb_config_ = glx_fb_configs.get()[0];
return true;
}
-
+#endif
bool VaapiVideoDecodeAccelerator::Initialize(
media::VideoCodecProfile profile) {
DCHECK_EQ(message_loop_, base::MessageLoop::current());
@@ -306,10 +372,14 @@ bool VaapiVideoDecodeAccelerator::Initialize(
if (!make_context_current_.Run())
return false;
+#if defined(VIDEO_TEXTURE_GLX_BACKEND)
if (!InitializeFBConfig()) {
DVLOG(1) << "Could not get a usable FBConfig";
return false;
}
+#elif defined(VIDEO_TEXTURE_EGL_BACKEND)
+ x_display_ = base::MessagePumpForUI::GetDefaultXDisplay();
+#endif
vaapi_wrapper_ = VaapiWrapper::Create(
profile, x_display_,
@@ -718,7 +788,11 @@ void VaapiVideoDecodeAccelerator::AssignPictureBuffers(
<< " VASurfaceID: " << va_surface_ids[i];
linked_ptr<TFPPicture> tfp_picture(
+#if defined(VIDEO_TEXTURE_GLX_BACKEND)
TFPPicture::Create(make_context_current_, fb_config_, x_display_,
+#elif defined(VIDEO_TEXTURE_EGL_BACKEND)
+ TFPPicture::Create(make_context_current_, egl_display_, x_display_,
+#endif
buffers[i].id(), buffers[i].texture_id(),
requested_pic_size_));

Powered by Google App Engine
This is Rietveld 408576698