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

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: Update after Pawel's review Created 6 years 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 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 scoped_refptr<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 if (glx_image_.get() && make_context_current_.Run()) {
32 glx_image_->ReleaseTexImage(GL_TEXTURE_2D);
33 glx_image_->Destroy(true);
34 DCHECK_EQ(glGetError(), static_cast<GLenum>(GL_NO_ERROR));
35 }
36
37 if (x_pixmap_)
38 XFreePixmap(x_display_, x_pixmap_);
39 }
40
41 bool VaapiTFPPicture::Initialize() {
42 if (!make_context_current_.Run())
43 return false;
44
45 XWindowAttributes win_attr;
46 int screen = DefaultScreen(x_display_);
47 XGetWindowAttributes(x_display_, RootWindow(x_display_, screen), &win_attr);
48 // TODO(posciak): pass the depth required by libva, not the RootWindow's
49 // depth
50 x_pixmap_ = XCreatePixmap(x_display_,
51 RootWindow(x_display_, screen),
52 size().width(),
53 size().height(),
54 win_attr.depth);
55 if (!x_pixmap_) {
56 LOG(ERROR) << "Failed creating an X Pixmap for TFP";
57 return false;
58 }
59
60 glx_image_ = new gfx::GLImageGLX(size(), GL_RGB);
61 if (!glx_image_->Initialize(x_pixmap_)) {
62 // x_pixmap_ will be freed in the destructor.
63 LOG(ERROR) << "Failed creating a GLX Pixmap for TFP";
64 return false;
65 }
66
67 gfx::ScopedTextureBinder texture_binder(GL_TEXTURE_2D, texture_id());
68 if (!glx_image_->BindTexImage(GL_TEXTURE_2D)) {
69 LOG(ERROR) << "Failed to bind texture to glx image";
70 return false;
71 }
72
73 return true;
74 }
75
76 bool VaapiTFPPicture::DownloadFromSurface(
77 const scoped_refptr<VASurface>& va_surface) {
78 return vaapi_wrapper_->PutSurfaceIntoPixmap(
79 va_surface->id(), x_pixmap_, va_surface->size());
80 }
81
82 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698