| 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/gfx/x/x11_types.h" | |
| 9 #include "ui/gl/gl_bindings.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 const MakeGLContextCurrentCallback& make_context_current_cb, | |
| 18 int32_t picture_buffer_id, | |
| 19 uint32_t texture_id, | |
| 20 const gfx::Size& size) | |
| 21 : VaapiPicture(picture_buffer_id, texture_id, size), | |
| 22 vaapi_wrapper_(vaapi_wrapper), | |
| 23 make_context_current_cb_(make_context_current_cb), | |
| 24 x_display_(gfx::GetXDisplay()), | |
| 25 x_pixmap_(0) {} | |
| 26 | |
| 27 VaapiTFPPicture::~VaapiTFPPicture() { | |
| 28 if (glx_image_.get() && make_context_current_cb_.Run()) { | |
| 29 glx_image_->ReleaseTexImage(GL_TEXTURE_2D); | |
| 30 glx_image_->Destroy(true); | |
| 31 DCHECK_EQ(glGetError(), static_cast<GLenum>(GL_NO_ERROR)); | |
| 32 } | |
| 33 | |
| 34 if (x_pixmap_) | |
| 35 XFreePixmap(x_display_, x_pixmap_); | |
| 36 } | |
| 37 | |
| 38 bool VaapiTFPPicture::Initialize() { | |
| 39 if (!make_context_current_cb_.Run()) | |
| 40 return false; | |
| 41 | |
| 42 XWindowAttributes win_attr; | |
| 43 int screen = DefaultScreen(x_display_); | |
| 44 XGetWindowAttributes(x_display_, RootWindow(x_display_, screen), &win_attr); | |
| 45 // TODO(posciak): pass the depth required by libva, not the RootWindow's | |
| 46 // depth | |
| 47 x_pixmap_ = XCreatePixmap(x_display_, RootWindow(x_display_, screen), | |
| 48 size().width(), size().height(), win_attr.depth); | |
| 49 if (!x_pixmap_) { | |
| 50 LOG(ERROR) << "Failed creating an X Pixmap for TFP"; | |
| 51 return false; | |
| 52 } | |
| 53 | |
| 54 glx_image_ = new gl::GLImageGLX(size(), GL_RGB); | |
| 55 if (!glx_image_->Initialize(x_pixmap_)) { | |
| 56 // x_pixmap_ will be freed in the destructor. | |
| 57 LOG(ERROR) << "Failed creating a GLX Pixmap for TFP"; | |
| 58 return false; | |
| 59 } | |
| 60 | |
| 61 gfx::ScopedTextureBinder texture_binder(GL_TEXTURE_2D, texture_id()); | |
| 62 if (!glx_image_->BindTexImage(GL_TEXTURE_2D)) { | |
| 63 LOG(ERROR) << "Failed to bind texture to glx image"; | |
| 64 return false; | |
| 65 } | |
| 66 | |
| 67 return true; | |
| 68 } | |
| 69 | |
| 70 bool VaapiTFPPicture::DownloadFromSurface( | |
| 71 const scoped_refptr<VASurface>& va_surface) { | |
| 72 return vaapi_wrapper_->PutSurfaceIntoPixmap(va_surface->id(), x_pixmap_, | |
| 73 va_surface->size()); | |
| 74 } | |
| 75 | |
| 76 scoped_refptr<gl::GLImage> VaapiTFPPicture::GetImageToBind() { | |
| 77 return nullptr; | |
| 78 } | |
| 79 | |
| 80 } // namespace content | |
| OLD | NEW |