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

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

Issue 490233002: VaapiVideoAccelerator: make Vaapi accelerator work with ozone (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Update after Pawel's review Created 6 years, 1 month 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_tfp_picture.cc
diff --git a/content/common/gpu/media/vaapi_tfp_picture.cc b/content/common/gpu/media/vaapi_tfp_picture.cc
new file mode 100644
index 0000000000000000000000000000000000000000..0524cbdfcc05cd42d87d59bbd82fb147fa427b03
--- /dev/null
+++ b/content/common/gpu/media/vaapi_tfp_picture.cc
@@ -0,0 +1,99 @@
+// Copyright 2014 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "content/common/gpu/media/va_surface.h"
+#include "content/common/gpu/media/vaapi_tfp_picture.h"
+#include "content/common/gpu/media/vaapi_wrapper.h"
+#include "ui/gl/gl_bindings.h"
+#include "ui/gl/gl_context_glx.h"
+#include "ui/gl/gl_image_glx.h"
+#include "ui/gl/scoped_binders.h"
+
+namespace content {
+
+VaapiTFPPicture::VaapiTFPPicture(
+ base::WeakPtr<VaapiWrapper> vaapi_wrapper,
+ gfx::GLContextGLX* glx_context,
+ const base::Callback<bool(void)> make_context_current,
+ int32 picture_buffer_id,
+ uint32 texture_id,
+ const gfx::Size& size)
+ : VaapiPicture(picture_buffer_id, texture_id, size),
+ vaapi_wrapper_(vaapi_wrapper),
+ glx_context_(glx_context),
+ make_context_current_(make_context_current),
+ x_display_(glx_context_->display()),
+ x_pixmap_(0) {
+}
+
+VaapiTFPPicture::~VaapiTFPPicture() {
+ // At this point |vaapi_wrapper_| shouldn't be available anymore.
+ DCHECK(!vaapi_wrapper_.get());
+
+ if (glx_image_.get() && make_context_current_.Run()) {
+ glx_image_->ReleaseTexImage(GL_TEXTURE_2D);
+ glx_image_->Destroy(true);
+ DCHECK_EQ(glGetError(), GL_NO_ERROR);
+ }
+
+ if (x_pixmap_)
+ XFreePixmap(x_display_, x_pixmap_);
+ XSync(x_display_, False); // Needed to work around buggy vdpau-driver.
marcheu 2014/11/14 19:35:47 Hmm, why do we need that at all? we don't support
llandwerlin-old 2014/11/15 00:15:39 I don't know either. I just kept the destruction s
+}
+
+bool VaapiTFPPicture::Initialize() {
+ if (!make_context_current_.Run())
+ return false;
+
+ XWindowAttributes win_attr;
+ int screen = DefaultScreen(x_display_);
+ XGetWindowAttributes(x_display_, RootWindow(x_display_, screen), &win_attr);
+ // TODO(posciak): pass the depth required by libva, not the RootWindow's
+ // depth
+ x_pixmap_ = XCreatePixmap(x_display_,
+ RootWindow(x_display_, screen),
+ size().width(),
+ size().height(),
+ win_attr.depth);
+ if (!x_pixmap_) {
+ LOG(ERROR) << "Failed creating an X Pixmap for TFP";
+ return false;
+ }
+
+ glx_image_ = new gfx::GLImageGLX(size(), GL_RGB);
+ if (!glx_image_->Initialize(x_pixmap_)) {
+ // x_pixmap_ will be freed in the destructor.
+ LOG(ERROR) << "Failed creating a GLX Pixmap for TFP";
+ return false;
+ }
+
+ gfx::ScopedTextureBinder texture_binder(GL_TEXTURE_2D, texture_id());
+ if (!glx_image_->BindTexImage(GL_TEXTURE_2D)) {
+ LOG(ERROR) << "Failed to bind texture to glx image";
+ return false;
+ }
+
+ return true;
+}
+
+bool VaapiTFPPicture::DownloadFromSurface(
+ const scoped_refptr<VASurface>& va_surface) {
+ if (!vaapi_wrapper_.get()) {
+ LOG(ERROR) << "VaapiWrapper not available";
+ return false;
+ }
+
+ return vaapi_wrapper_->PutSurfaceIntoPixmap(
+ va_surface->id(), x_pixmap_, va_surface->size());
+}
+
+void VaapiTFPPicture::DisposeVaapi() {
+}
+
+// static
+uint32 VaapiPicture::GetGLTextureTarget() {
+ return GL_TEXTURE_2D;
+}
+
+} // namespace content

Powered by Google App Engine
This is Rietveld 408576698