Chromium Code Reviews| OLD | NEW |
|---|---|
| (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 const 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()), | |
|
piman
2014/12/16 20:46:43
It looks like the only reason you need the GLConte
llandwerlin-old
2014/12/17 11:46:37
Thanks, I can remove the gl context.
| |
| 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_, RootWindow(x_display_, screen), | |
| 51 size().width(), size().height(), win_attr.depth); | |
| 52 if (!x_pixmap_) { | |
| 53 LOG(ERROR) << "Failed creating an X Pixmap for TFP"; | |
| 54 return false; | |
| 55 } | |
| 56 | |
| 57 glx_image_ = new gfx::GLImageGLX(size(), GL_RGB); | |
| 58 if (!glx_image_->Initialize(x_pixmap_)) { | |
| 59 // x_pixmap_ will be freed in the destructor. | |
| 60 LOG(ERROR) << "Failed creating a GLX Pixmap for TFP"; | |
| 61 return false; | |
| 62 } | |
| 63 | |
| 64 gfx::ScopedTextureBinder texture_binder(GL_TEXTURE_2D, texture_id()); | |
| 65 if (!glx_image_->BindTexImage(GL_TEXTURE_2D)) { | |
| 66 LOG(ERROR) << "Failed to bind texture to glx image"; | |
| 67 return false; | |
| 68 } | |
| 69 | |
| 70 return true; | |
| 71 } | |
| 72 | |
| 73 bool VaapiTFPPicture::DownloadFromSurface( | |
| 74 const scoped_refptr<VASurface>& va_surface) { | |
| 75 return vaapi_wrapper_->PutSurfaceIntoPixmap(va_surface->id(), x_pixmap_, | |
| 76 va_surface->size()); | |
| 77 } | |
| 78 | |
| 79 } // namespace content | |
| OLD | NEW |