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

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

Issue 10827052: Extract Scoped{FrameBuffer,Texture}Binder and clean up TFP in VAVDA. (Closed) Base URL: https://git.chromium.org/git/chromium/src@master
Patch Set: Created 8 years, 5 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 unified diff | Download patch
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include <dlfcn.h> 5 #include <dlfcn.h>
6 6
7 #include <algorithm> 7 #include <algorithm>
8 8
9 #include "base/bind.h" 9 #include "base/bind.h"
10 #include "base/stl_util.h" 10 #include "base/stl_util.h"
11 #include "content/common/gpu/gl_scoped_binders.h"
11 #include "content/common/gpu/media/vaapi_h264_decoder.h" 12 #include "content/common/gpu/media/vaapi_h264_decoder.h"
12 #include "third_party/libva/va/va.h" 13 #include "third_party/libva/va/va.h"
13 #include "third_party/libva/va/va_x11.h" 14 #include "third_party/libva/va/va_x11.h"
14 #include "ui/gl/gl_bindings.h" 15 #include "ui/gl/gl_bindings.h"
15 16
16 #define VA_LOG_ON_ERROR(va_res, err_msg) \ 17 #define VA_LOG_ON_ERROR(va_res, err_msg) \
17 do { \ 18 do { \
18 if ((va_res) != VA_STATUS_SUCCESS) { \ 19 if ((va_res) != VA_STATUS_SUCCESS) { \
19 DVLOG(1) << err_msg \ 20 DVLOG(1) << err_msg \
20 << " VA error: " << VAAPI_ErrorStr(va_res); \ 21 << " VA error: " << VAAPI_ErrorStr(va_res); \
(...skipping 228 matching lines...) Expand 10 before | Expand all | Expand 10 after
249 height_(height), 250 height_(height),
250 available_(false), 251 available_(false),
251 poc_(0), 252 poc_(0),
252 x_pixmap_(0), 253 x_pixmap_(0),
253 glx_pixmap_(0) { 254 glx_pixmap_(0) {
254 // Bind the surface to a texture of the given width and height, 255 // Bind the surface to a texture of the given width and height,
255 // allocating pixmaps as needed. 256 // allocating pixmaps as needed.
256 if (!make_context_current_.Run()) 257 if (!make_context_current_.Run())
257 return; 258 return;
258 259
259 glEnable(GL_TEXTURE_2D); 260 gfx::ScopedTextureBinder texture_binder(texture_id_);
260 glBindTexture(GL_TEXTURE_2D, texture_id_);
261 glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); 261 glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
262 glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); 262 glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
263 263
264 XWindowAttributes win_attr; 264 XWindowAttributes win_attr;
265 int screen = DefaultScreen(x_display_); 265 int screen = DefaultScreen(x_display_);
266 XGetWindowAttributes(x_display_, RootWindow(x_display_, screen), &win_attr); 266 XGetWindowAttributes(x_display_, RootWindow(x_display_, screen), &win_attr);
267 //TODO(posciak): pass the depth required by libva, not the RootWindow's depth
267 x_pixmap_ = XCreatePixmap(x_display_, RootWindow(x_display_, screen), 268 x_pixmap_ = XCreatePixmap(x_display_, RootWindow(x_display_, screen),
268 width_, height_, win_attr.depth); 269 width_, height_, win_attr.depth);
269 if (!x_pixmap_) { 270 if (!x_pixmap_) {
270 DVLOG(1) << "Failed creating an X Pixmap for TFP"; 271 DVLOG(1) << "Failed creating an X Pixmap for TFP";
271 return; 272 return;
272 } 273 }
273 274
274 static const int pixmap_attr[] = { 275 static const int pixmap_attr[] = {
275 GLX_TEXTURE_TARGET_EXT, GLX_TEXTURE_2D_EXT, 276 GLX_TEXTURE_TARGET_EXT, GLX_TEXTURE_2D_EXT,
276 GLX_TEXTURE_FORMAT_EXT, GLX_TEXTURE_FORMAT_RGB_EXT, 277 GLX_TEXTURE_FORMAT_EXT, GLX_TEXTURE_FORMAT_RGB_EXT,
277 GL_NONE, 278 GL_NONE,
278 }; 279 };
279 280
280 glx_pixmap_ = glXCreatePixmap(x_display_, fb_config, x_pixmap_, pixmap_attr); 281 glx_pixmap_ = glXCreatePixmap(x_display_, fb_config, x_pixmap_, pixmap_attr);
281 if (!glx_pixmap_) { 282 if (!glx_pixmap_) {
282 // x_pixmap_ will be freed in the destructor. 283 // x_pixmap_ will be freed in the destructor.
283 DVLOG(1) << "Failed creating a GLX Pixmap for TFP"; 284 DVLOG(1) << "Failed creating a GLX Pixmap for TFP";
284 return; 285 return;
285 } 286 }
286 287
287 glBindTexture(GL_TEXTURE_2D, texture_id_);
288 glXBindTexImageEXT(x_display_, glx_pixmap_, GLX_FRONT_LEFT_EXT, NULL); 288 glXBindTexImageEXT(x_display_, glx_pixmap_, GLX_FRONT_LEFT_EXT, NULL);
289 289
290 available_ = true; 290 available_ = true;
291 } 291 }
292 292
293 VaapiH264Decoder::DecodeSurface::~DecodeSurface() { 293 VaapiH264Decoder::DecodeSurface::~DecodeSurface() {
294 // Unbind surface from texture and deallocate resources. 294 // Unbind surface from texture and deallocate resources.
295 if (glx_pixmap_ && make_context_current_.Run()) { 295 if (glx_pixmap_ && make_context_current_.Run()) {
296 glXReleaseTexImageEXT(x_display_, glx_pixmap_, GLX_FRONT_LEFT_EXT); 296 glXReleaseTexImageEXT(x_display_, glx_pixmap_, GLX_FRONT_LEFT_EXT);
297 glXDestroyGLXPixmap(x_display_, glx_pixmap_); 297 glXDestroyPixmap(x_display_, glx_pixmap_);
298 } 298 }
299 299
300 if (x_pixmap_) 300 if (x_pixmap_)
301 XFreePixmap(x_display_, x_pixmap_); 301 XFreePixmap(x_display_, x_pixmap_);
302 } 302 }
303 303
304 void VaapiH264Decoder::DecodeSurface::Acquire(int32 input_id, int poc) { 304 void VaapiH264Decoder::DecodeSurface::Acquire(int32 input_id, int poc) {
305 DCHECK_EQ(available_, true); 305 DCHECK_EQ(available_, true);
306 available_ = false; 306 available_ = false;
307 input_id_ = input_id; 307 input_id_ = input_id;
(...skipping 1787 matching lines...) Expand 10 before | Expand all | Expand 10 after
2095 } 2095 }
2096 } 2096 }
2097 } 2097 }
2098 2098
2099 // static 2099 // static
2100 size_t VaapiH264Decoder::GetRequiredNumOfPictures() { 2100 size_t VaapiH264Decoder::GetRequiredNumOfPictures() {
2101 return kNumReqPictures; 2101 return kNumReqPictures;
2102 } 2102 }
2103 2103
2104 } // namespace content 2104 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698