Chromium Code Reviews| Index: content/common/gpu/media/vaapi_drm_picture.cc |
| diff --git a/content/common/gpu/media/vaapi_drm_picture.cc b/content/common/gpu/media/vaapi_drm_picture.cc |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..9572a91001e184c2a65a5dfe4267d29f0e280e50 |
| --- /dev/null |
| +++ b/content/common/gpu/media/vaapi_drm_picture.cc |
| @@ -0,0 +1,120 @@ |
| +// Copyright 2014 The Chromium Authors. All rights reserved. |
| +// Use of this source code is governed by a BSD-style license that can be |
| +// found in the LICENSE file. |
| + |
| +#include "base/file_descriptor_posix.h" |
| +#include "content/common/gpu/media/va_surface.h" |
| +#include "content/common/gpu/media/vaapi_drm_picture.h" |
| +#include "content/common/gpu/media/vaapi_wrapper.h" |
| +#include "third_party/libva/va/drm/va_drm.h" |
| +#include "third_party/libva/va/va.h" |
| +#include "third_party/libva/va/va_drmcommon.h" |
|
Pawel Osciak
2014/12/26 00:38:55
Not needed perhaps?
llandwerlin-old
2014/12/26 02:50:01
Needed for VA_SURFACE_ATTRIB_MEM_TYPE_DRM_PRIME.
Pawel Osciak
2014/12/29 00:08:00
Right, missed that, sorry.
|
| +#include "ui/gfx/gpu_memory_buffer.h" |
| +#include "ui/gl/gl_bindings.h" |
| +#include "ui/gl/gl_image_linux_dma_buffer.h" |
| +#include "ui/gl/scoped_binders.h" |
| +#include "ui/ozone/public/native_pixmap.h" |
| +#include "ui/ozone/public/ozone_platform.h" |
| +#include "ui/ozone/public/surface_factory_ozone.h" |
| + |
| +namespace content { |
| + |
| +VaapiDrmPicture::VaapiDrmPicture( |
| + VaapiWrapper* vaapi_wrapper, |
| + const base::Callback<bool(void)> make_context_current, |
|
Pawel Osciak
2014/12/26 00:38:55
reference please.
llandwerlin-old
2014/12/26 02:50:01
Done.
|
| + int32 picture_buffer_id, |
| + uint32 texture_id, |
| + const gfx::Size& size) |
| + : VaapiPicture(picture_buffer_id, texture_id, size), |
| + vaapi_wrapper_(vaapi_wrapper), |
| + make_context_current_(make_context_current) { |
| +} |
| + |
| +VaapiDrmPicture::~VaapiDrmPicture() { |
| + if (egl_image_.get() && make_context_current_.Run()) { |
|
Pawel Osciak
2014/12/26 00:38:55
get() not needed anymore.
llandwerlin-old
2014/12/26 02:50:01
Done.
|
| + egl_image_->ReleaseTexImage(GL_TEXTURE_EXTERNAL_OES); |
| + egl_image_->Destroy(true); |
| + |
| + DCHECK_EQ(glGetError(), static_cast<GLenum>(GL_NO_ERROR)); |
| + } |
| +} |
| + |
| +bool VaapiDrmPicture::Initialize() { |
|
Pawel Osciak
2014/12/26 00:38:55
Please add comments what is happening in this meth
llandwerlin-old
2014/12/26 02:50:01
Acknowledged.
|
| + VASurfaceAttrib va_attribs[2]; |
| + VASurfaceAttribExternalBuffers va_attrib_extbuf; |
|
Pawel Osciak
2014/12/26 00:38:55
Please define local variables immediately before u
llandwerlin-old
2014/12/26 02:50:01
Done.
|
| + |
| + ui::OzonePlatform* platform = ui::OzonePlatform::GetInstance(); |
|
Pawel Osciak
2014/12/26 00:38:55
Please check the return value.
llandwerlin-old
2014/12/26 02:50:01
I think we went through this before :
https://cod
Pawel Osciak
2014/12/29 00:08:00
Yes please. Sure something went really wrong, but
|
| + ui::SurfaceFactoryOzone* factory = platform->GetSurfaceFactoryOzone(); |
|
Pawel Osciak
2014/12/26 00:38:55
Ditto.
llandwerlin-old
2014/12/26 02:50:01
Same.
|
| + |
| + pixmap_ = factory->CreateNativePixmap(gfx::kNullAcceleratedWidget, size(), |
| + ui::SurfaceFactoryOzone::RGBA_8888, |
| + ui::SurfaceFactoryOzone::SCANOUT); |
| + if (!pixmap_.get()) { |
|
Pawel Osciak
2014/12/26 00:38:55
get() not needed anymore.
llandwerlin-old
2014/12/26 02:50:01
Done.
|
| + LOG(ERROR) << "Failed creating an Ozone NativePixmap"; |
| + return false; |
| + } |
| + |
| + int dmabuf_fd = pixmap_->GetDmaBufFd(); |
| + if (dmabuf_fd < 0) { |
| + LOG(ERROR) << "Failed get dmabuf from an Ozone NativePixmap"; |
|
Pawel Osciak
2014/12/26 00:38:55
s/get/to get/
llandwerlin-old
2014/12/26 02:50:01
Done.
|
| + return false; |
| + } |
| + int dmabuf_pitch = pixmap_->GetDmaBufPitch(); |
| + |
| + memset(&va_attrib_extbuf, 0, sizeof(va_attrib_extbuf)); |
| + va_attrib_extbuf.pixel_format = VA_FOURCC_BGRX; |
| + va_attrib_extbuf.width = size().width(); |
| + va_attrib_extbuf.height = size().height(); |
| + va_attrib_extbuf.data_size = size().height() * dmabuf_pitch; |
| + va_attrib_extbuf.num_planes = 1; |
| + va_attrib_extbuf.pitches[0] = dmabuf_pitch; |
| + va_attrib_extbuf.offsets[0] = 0; |
| + va_attrib_extbuf.buffers = reinterpret_cast<unsigned long*>(&dmabuf_fd); |
| + va_attrib_extbuf.num_buffers = 1; |
| + va_attrib_extbuf.flags = 0; |
| + va_attrib_extbuf.private_data = NULL; |
| + |
| + va_attribs[0].type = VASurfaceAttribMemoryType; |
| + va_attribs[0].flags = VA_SURFACE_ATTRIB_SETTABLE; |
| + va_attribs[0].value.type = VAGenericValueTypeInteger; |
| + va_attribs[0].value.value.i = VA_SURFACE_ATTRIB_MEM_TYPE_DRM_PRIME; |
| + |
| + va_attribs[1].type = VASurfaceAttribExternalBufferDescriptor; |
| + va_attribs[1].flags = VA_SURFACE_ATTRIB_SETTABLE; |
| + va_attribs[1].value.type = VAGenericValueTypePointer; |
| + va_attribs[1].value.value.p = &va_attrib_extbuf; |
| + |
| + va_surface_ = vaapi_wrapper_->CreateUnownedSurface( |
| + VA_RT_FORMAT_RGB32, size(), va_attribs, arraysize(va_attribs)); |
| + if (!va_surface_.get()) { |
|
Pawel Osciak
2014/12/26 00:38:55
get() not needed anymore.
llandwerlin-old
2014/12/26 02:50:01
Done.
|
| + LOG(ERROR) << "Failed to create VASurface for an Ozone NativePixmap"; |
| + return false; |
| + } |
| + |
| + if (!make_context_current_.Run()) |
| + return false; |
| + |
| + egl_image_ = new gfx::GLImageLinuxDMABuffer(size(), GL_RGBA); |
| + if (!egl_image_->Initialize(base::FileDescriptor(dmabuf_fd, false), |
|
Pawel Osciak
2014/12/26 00:38:55
Why not autoclose?
llandwerlin-old
2014/12/26 02:50:01
GbmPixmap does this for us : https://code.google.c
Pawel Osciak
2014/12/29 00:08:00
Acknowledged.
|
| + gfx::GpuMemoryBuffer::BGRA_8888, dmabuf_pitch)) { |
| + LOG(ERROR) << "Failed to create an EGLImage for an Ozone NativePixmap"; |
|
Pawel Osciak
2014/12/26 00:38:55
s/EGLImage/GLImageLinuxDMABuffer/
llandwerlin-old
2014/12/26 02:50:01
Done.
|
| + return false; |
| + } |
| + |
| + gfx::ScopedTextureBinder texture_binder(GL_TEXTURE_EXTERNAL_OES, |
| + texture_id()); |
| + if (!egl_image_->BindTexImage(GL_TEXTURE_EXTERNAL_OES)) { |
| + LOG(ERROR) << "Failed to bind texture to EGLImage"; |
|
Pawel Osciak
2014/12/26 00:38:55
s/EGLImage/GLImage/
llandwerlin-old
2014/12/26 02:50:01
Done.
|
| + return false; |
| + } |
| + |
| + return true; |
| +} |
| + |
| +bool VaapiDrmPicture::DownloadFromSurface( |
| + const scoped_refptr<VASurface>& va_surface) { |
| + return vaapi_wrapper_->BlitSurface(va_surface->id(), va_surface->size(), |
| + va_surface_->id(), va_surface_->size()); |
| +} |
| + |
| +} // namespace |