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

Side by Side 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: Removed commented code from VaapiWrapper 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 unified diff | Download patch
OLDNEW
(Empty)
1 // Copyright (c) 2014 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 #include "content/common/gpu/media/va_surface.h"
6 #include "content/common/gpu/media/vaapi_tfp_picture.h"
7 #include "content/common/gpu/media/vaapi_wrapper.h"
8 #include "ui/gl/gl_bindings.h"
9 #include "ui/gl/gl_context_glx.h"
10 #include "ui/gl/gl_image_glx.h"
11 #include "ui/gl/scoped_binders.h"
12
13 namespace content {
14
15 VaapiTFPPicture::VaapiTFPPicture(
16 base::WeakPtr<VaapiWrapper> vaapi_wrapper,
17 gfx::GLContextGLX* glx_context,
18 const base::Callback<bool(void)> make_context_current,
19 int32 picture_buffer_id,
20 uint32 texture_id,
21 const gfx::Size& size)
22 : VaapiPicture(picture_buffer_id, texture_id, size),
23 vaapi_wrapper_(vaapi_wrapper),
24 glx_context_(glx_context),
25 make_context_current_(make_context_current),
26 x_display_(glx_context_->display()),
27 x_pixmap_(0) {
28 }
29
30 VaapiTFPPicture::~VaapiTFPPicture() {
31 // At this point |vaapi_wrapper_| shouldn't be available anymore.
32 DCHECK(!vaapi_wrapper_.get());
33
34 if (glx_image_.get() && make_context_current_.Run()) {
35 glx_image_->ReleaseTexImage(GL_TEXTURE_2D);
36 glx_image_->Destroy(true);
37 DCHECK_EQ(glGetError(), GL_NO_ERROR);
38 }
39
40 if (x_pixmap_)
41 XFreePixmap(x_display_, x_pixmap_);
42 XSync(x_display_, False); // Needed to work around buggy vdpau-driver.
43 }
44
45 bool VaapiTFPPicture::Initialize() {
46 if (!make_context_current_.Run())
47 return false;
48
49 XWindowAttributes win_attr;
50 int screen = DefaultScreen(x_display_);
51 XGetWindowAttributes(x_display_, RootWindow(x_display_, screen), &win_attr);
52 // TODO(posciak): pass the depth required by libva, not the RootWindow's
53 // depth
54 x_pixmap_ = XCreatePixmap(x_display_,
55 RootWindow(x_display_, screen),
56 size().width(),
57 size().height(),
58 win_attr.depth);
59 if (!x_pixmap_) {
60 LOG(ERROR) << "Failed creating an X Pixmap for TFP";
61 return false;
62 }
63
64 glx_image_ = new gfx::GLImageGLX(size(), GL_RGB);
65 if (!glx_image_->Initialize(x_pixmap_)) {
66 // x_pixmap_ will be freed in the destructor.
67 LOG(ERROR) << "Failed creating a GLX Pixmap for TFP";
68 return false;
69 }
70
71 gfx::ScopedTextureBinder texture_binder(GL_TEXTURE_2D, texture_id());
72 if (!glx_image_->BindTexImage(GL_TEXTURE_2D)) {
73 LOG(ERROR) << "Failed to bind texture to glx image";
74 return false;
75 }
76
77 return true;
78 }
79
80 bool VaapiTFPPicture::DownloadFromSurface(
81 const scoped_refptr<VASurface>& va_surface) {
82 return vaapi_wrapper_->PutSurfaceIntoPixmap(
83 va_surface->id(), x_pixmap_, va_surface->size());
84 }
85
86 void VaapiTFPPicture::DisposeVaapi() {
87 }
88
89 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698