| 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 "base/file_descriptor_posix.h" | |
| 6 #include "content/common/gpu/media/va_surface.h" | |
| 7 #include "content/common/gpu/media/vaapi_drm_picture.h" | |
| 8 #include "content/common/gpu/media/vaapi_wrapper.h" | |
| 9 #include "third_party/libva/va/drm/va_drm.h" | |
| 10 #include "third_party/libva/va/va.h" | |
| 11 #include "ui/gfx/gpu_memory_buffer.h" | |
| 12 #include "ui/gl/gl_bindings.h" | |
| 13 #include "ui/gl/gl_image_ozone_native_pixmap.h" | |
| 14 #include "ui/gl/scoped_binders.h" | |
| 15 #include "ui/ozone/public/native_pixmap.h" | |
| 16 #include "ui/ozone/public/ozone_platform.h" | |
| 17 #include "ui/ozone/public/surface_factory_ozone.h" | |
| 18 | |
| 19 namespace { | |
| 20 // We decode video into YUV420, but for usage with GLImages we have to convert | |
| 21 // to BGRX_8888. | |
| 22 const gfx::BufferFormat kPictureForGLImageFormat = gfx::BufferFormat::BGRX_8888; | |
| 23 | |
| 24 } // namespace | |
| 25 | |
| 26 namespace content { | |
| 27 | |
| 28 VaapiDrmPicture::VaapiDrmPicture( | |
| 29 const scoped_refptr<VaapiWrapper>& vaapi_wrapper, | |
| 30 const MakeGLContextCurrentCallback& make_context_current_cb, | |
| 31 int32_t picture_buffer_id, | |
| 32 uint32_t texture_id, | |
| 33 const gfx::Size& size) | |
| 34 : VaapiPicture(picture_buffer_id, texture_id, size), | |
| 35 vaapi_wrapper_(vaapi_wrapper), | |
| 36 make_context_current_cb_(make_context_current_cb) {} | |
| 37 | |
| 38 VaapiDrmPicture::~VaapiDrmPicture() { | |
| 39 if (gl_image_ && make_context_current_cb_.Run()) { | |
| 40 gl_image_->ReleaseTexImage(GL_TEXTURE_EXTERNAL_OES); | |
| 41 gl_image_->Destroy(true); | |
| 42 | |
| 43 DCHECK_EQ(glGetError(), static_cast<GLenum>(GL_NO_ERROR)); | |
| 44 } | |
| 45 } | |
| 46 | |
| 47 bool VaapiDrmPicture::Initialize() { | |
| 48 // We want to create a VASurface and an EGLImage out of the same | |
| 49 // memory buffer, so we can output decoded pictures to it using | |
| 50 // VAAPI and also use it to paint with GL. | |
| 51 ui::OzonePlatform* platform = ui::OzonePlatform::GetInstance(); | |
| 52 ui::SurfaceFactoryOzone* factory = platform->GetSurfaceFactoryOzone(); | |
| 53 pixmap_ = factory->CreateNativePixmap(gfx::kNullAcceleratedWidget, size(), | |
| 54 kPictureForGLImageFormat, | |
| 55 gfx::BufferUsage::SCANOUT); | |
| 56 if (!pixmap_) { | |
| 57 LOG(ERROR) << "Failed creating an Ozone NativePixmap"; | |
| 58 return false; | |
| 59 } | |
| 60 | |
| 61 va_surface_ = vaapi_wrapper_->CreateVASurfaceForPixmap(pixmap_); | |
| 62 if (!va_surface_) { | |
| 63 LOG(ERROR) << "Failed creating VASurface for NativePixmap"; | |
| 64 return false; | |
| 65 } | |
| 66 | |
| 67 pixmap_->SetProcessingCallback( | |
| 68 base::Bind(&VaapiWrapper::ProcessPixmap, vaapi_wrapper_)); | |
| 69 | |
| 70 if (!make_context_current_cb_.Run()) | |
| 71 return false; | |
| 72 | |
| 73 gfx::ScopedTextureBinder texture_binder(GL_TEXTURE_EXTERNAL_OES, | |
| 74 texture_id()); | |
| 75 scoped_refptr<gfx::GLImageOzoneNativePixmap> image( | |
| 76 new gfx::GLImageOzoneNativePixmap(size(), GL_BGRA_EXT)); | |
| 77 if (!image->Initialize(pixmap_.get(), pixmap_->GetBufferFormat())) { | |
| 78 LOG(ERROR) << "Failed to create GLImage"; | |
| 79 return false; | |
| 80 } | |
| 81 gl_image_ = image; | |
| 82 if (!gl_image_->BindTexImage(GL_TEXTURE_EXTERNAL_OES)) { | |
| 83 LOG(ERROR) << "Failed to bind texture to GLImage"; | |
| 84 return false; | |
| 85 } | |
| 86 | |
| 87 return true; | |
| 88 } | |
| 89 | |
| 90 bool VaapiDrmPicture::DownloadFromSurface( | |
| 91 const scoped_refptr<VASurface>& va_surface) { | |
| 92 return vaapi_wrapper_->BlitSurface(va_surface, va_surface_); | |
| 93 } | |
| 94 | |
| 95 scoped_refptr<gl::GLImage> VaapiDrmPicture::GetImageToBind() { | |
| 96 return gl_image_; | |
| 97 } | |
| 98 | |
| 99 bool VaapiDrmPicture::AllowOverlay() const { | |
| 100 return true; | |
| 101 } | |
| 102 | |
| 103 } // namespace | |
| OLD | NEW |