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

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

Issue 490233002: VaapiVideoAccelerator: make Vaapi accelerator work with ozone (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Enable vaapi_h264_decoder_unittest on Ozone 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/vaapi_picture_provider_x11.h"
6 #include "ui/gl/gl_bindings.h"
7 #include "ui/gl/gl_context_glx.h"
8 #include "ui/gl/gl_image.h"
9 #include "ui/gl/scoped_binders.h"
10
11 namespace content {
12
13 class TFPPicture : public VaapiPictureProvider::Picture {
14 public:
15 TFPPicture(scoped_refptr<VaapiWrapper> vaapi_wrapper,
16 gfx::GLContextGLX* glx_context,
17 const base::Callback<bool(void)> make_context_current,
18 GLXFBConfig fb_config,
19 int32 picture_buffer_id,
20 uint32 texture_id,
21 const gfx::Size& size)
22 : Picture(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 fb_config_(fb_config) {}
28
29 virtual ~TFPPicture();
30
31 bool Initialize() override;
32
33 bool DownloadFromSurface(VASurfaceID va_surface_id,
34 const gfx::Size& surface_size) override;
35
36 private:
37 scoped_refptr<VaapiWrapper> vaapi_wrapper_;
38
39 gfx::GLContextGLX* glx_context_;
40 base::Callback<bool(void)> make_context_current_;
41 Display* x_display_;
42 GLXFBConfig fb_config_;
43
44 Pixmap x_pixmap_;
45 GLXPixmap glx_pixmap_;
46
47 DISALLOW_COPY_AND_ASSIGN(TFPPicture);
48 };
49
50 TFPPicture::~TFPPicture() {
51 if (glx_pixmap_ && make_context_current_.Run()) {
52 glXReleaseTexImageEXT(x_display_, glx_pixmap_, GLX_FRONT_LEFT_EXT);
53 glXDestroyPixmap(x_display_, glx_pixmap_);
54 }
55
56 if (x_pixmap_)
57 XFreePixmap(x_display_, x_pixmap_);
58 XSync(x_display_, False); // Needed to work around buggy vdpau-driver.
59 }
60
61 bool TFPPicture::Initialize() {
62 if (!make_context_current_.Run())
63 return false;
64
65 XWindowAttributes win_attr;
66 int screen = DefaultScreen(x_display_);
67 XGetWindowAttributes(x_display_, RootWindow(x_display_, screen), &win_attr);
68 // TODO(posciak): pass the depth required by libva, not the RootWindow's
69 // depth
70 x_pixmap_ = XCreatePixmap(x_display_,
71 RootWindow(x_display_, screen),
72 size().width(),
73 size().height(),
74 win_attr.depth);
75 if (!x_pixmap_) {
76 LOG(ERROR) << "Failed creating an X Pixmap for TFP";
77 return false;
78 }
79
80 static const int pixmap_attr[] = {
81 GLX_TEXTURE_TARGET_EXT,
82 GLX_TEXTURE_2D_EXT,
83 GLX_TEXTURE_FORMAT_EXT,
84 GLX_TEXTURE_FORMAT_RGB_EXT,
85 GL_NONE,
86 };
87
88 glx_pixmap_ = glXCreatePixmap(x_display_, fb_config_, x_pixmap_, pixmap_attr);
89 if (!glx_pixmap_) {
90 // x_pixmap_ will be freed in the destructor.
91 LOG(ERROR) << "Failed creating a GLX Pixmap for TFP";
92 return false;
93 }
94
95 return true;
96 }
97
98 bool TFPPicture::DownloadFromSurface(VASurfaceID va_surface_id,
99 const gfx::Size& surface_size) {
100 if (!make_context_current_.Run()) {
101 DVLOG(1) << "Failed making gl context current";
102 return false;
103 }
104
105 gfx::ScopedTextureBinder texture_binder(GL_TEXTURE_2D, texture_id());
106 glXBindTexImageEXT(x_display_, glx_pixmap_, GLX_FRONT_LEFT_EXT, NULL);
107 if (glGetError() != GL_NO_ERROR)
108 return false;
109
110 return vaapi_wrapper_->PutSurfaceIntoPixmap(va_surface_id, x_pixmap_, size());
111 }
112
113 class XFreeDeleter {
114 public:
115 void operator()(void* x) const { ::XFree(x); }
116 };
117
118 X11VaapiPictureProvider::X11VaapiPictureProvider(
119 scoped_refptr<VaapiWrapper> vaapi_wrapper,
120 gfx::GLContextGLX* glx_context,
121 const base::Callback<bool(void)> make_context_current)
122 : glx_context_(glx_context),
123 make_context_current_(make_context_current),
124 x_display_(glx_context_->display()),
125 vaapi_wrapper_(vaapi_wrapper) {
126 }
127
128 X11VaapiPictureProvider::~X11VaapiPictureProvider() {
129 }
130
131 linked_ptr<VaapiPictureProvider::Picture>
132 X11VaapiPictureProvider::AllocatePicture(int32 picture_buffer_id,
133 uint32 texture_id,
134 const gfx::Size& size) {
135 return linked_ptr<VaapiPictureProvider::Picture>(
136 new TFPPicture(vaapi_wrapper_,
137 glx_context_,
138 make_context_current_,
139 fb_config_,
140 picture_buffer_id,
141 texture_id,
142 size));
143 }
144
145 bool X11VaapiPictureProvider::Initialize() {
146 if (!make_context_current_.Run()) {
147 DVLOG(1) << "Couldn't make context current";
148 return false;
149 }
150
151 const int fbconfig_attr[] = {
152 GLX_DRAWABLE_TYPE,
153 GLX_PIXMAP_BIT,
154 GLX_BIND_TO_TEXTURE_TARGETS_EXT,
155 GLX_TEXTURE_2D_BIT_EXT,
156 GLX_BIND_TO_TEXTURE_RGB_EXT,
157 GL_TRUE,
158 GLX_Y_INVERTED_EXT,
159 GL_TRUE,
160 GL_NONE,
161 };
162
163 int num_fbconfigs;
164 scoped_ptr<GLXFBConfig, XFreeDeleter> glx_fb_configs(glXChooseFBConfig(
165 x_display_, DefaultScreen(x_display_), fbconfig_attr, &num_fbconfigs));
166
167 if (!glx_fb_configs) {
168 DVLOG(1) << "Couldn't get glx configs";
169 return false;
170 }
171 if (!num_fbconfigs) {
172 DVLOG(1) << "Couldn't get at least a glx config";
173 return false;
174 }
175
176 fb_config_ = glx_fb_configs.get()[0];
177 return true;
178 }
179
180 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698