Index: content/common/gpu/media/vaapi_picture_provider_drm.cc |
diff --git a/content/common/gpu/media/vaapi_picture_provider_drm.cc b/content/common/gpu/media/vaapi_picture_provider_drm.cc |
new file mode 100644 |
index 0000000000000000000000000000000000000000..c51d165f6e2decfa747811796641c488e9c98663 |
--- /dev/null |
+++ b/content/common/gpu/media/vaapi_picture_provider_drm.cc |
@@ -0,0 +1,167 @@ |
+// Copyright (c) 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 "content/common/gpu/media/vaapi_picture_provider_drm.h" |
+#include "content/common/gpu/media/vaapi_wrapper.h" |
+#include "third_party/libva/va/drm/va_drm.h" |
+#include "third_party/libva/va/va_drmcommon.h" |
+#include "ui/gl/gl_bindings.h" |
+#include "ui/gl/gl_image.h" |
+#include "ui/gl/gl_image_egl.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 { |
+ |
+class DrmPicture : public VaapiPictureProvider::Picture { |
+ public: |
+ DrmPicture(scoped_refptr<VaapiWrapper> vaapi_wrapper, |
+ const base::Callback<bool(void)> make_context_current, |
+ int32 picture_buffer_id, |
+ uint32 texture_id, |
+ const gfx::Size& size) |
+ : Picture(picture_buffer_id, texture_id, size), |
+ vaapi_wrapper_(vaapi_wrapper), |
+ make_context_current_(make_context_current), |
+ va_surface_(VA_INVALID_SURFACE) {} |
+ |
+ virtual ~DrmPicture() { |
+ if (gl_image_ && make_context_current_.Run()) { |
+ // ReleaseTexImage on a GLImageEGL does nothing, to deassociate |
+ // the renderer's texture from the image, just set the storage |
+ // of that texture to NULL |
+ gfx::ScopedTextureBinder texture_binder(GL_TEXTURE_2D, texture_id()); |
+ glTexImage2D(GL_TEXTURE_2D, |
+ 0, |
+ GL_RGBA, |
+ size().width(), |
+ size().height(), |
+ 0, |
+ GL_RGBA, |
+ GL_UNSIGNED_BYTE, |
+ NULL); |
+ |
+ gl_image_->Destroy(true); |
+ |
+ DCHECK_EQ(glGetError(), GL_NO_ERROR); |
+ } |
+ |
+ if (va_surface_ != VA_INVALID_SURFACE) |
+ vaapi_wrapper_->DestroyOutputSurface(va_surface_); |
Pawel Osciak
2014/10/26 13:06:46
What is responsible for closing the fd? Will it be
llandwerlin-old
2014/10/29 13:52:48
Closing the fd here now.
|
+ } |
+ |
+ bool Initialize() { |
+ VASurfaceAttrib va_attribs[2]; |
+ VASurfaceAttribExternalBuffers va_attrib_extbuf; |
+ |
+ ui::OzonePlatform* platform = ui::OzonePlatform::GetInstance(); |
+ ui::SurfaceFactoryOzone* factory = platform->GetSurfaceFactoryOzone(); |
+ |
+ pixmap_ = |
+ factory->CreateNativePixmap(size(), ui::SurfaceFactoryOzone::RGBA_8888); |
+ if (!pixmap_) |
+ return false; |
+ |
+ unsigned long buffer_fd = pixmap_->GetDmaBufFd(); |
Pawel Osciak
2014/10/26 13:06:46
fd is an int.
llandwerlin-old
2014/10/29 13:52:48
Acknowledged.
|
+ if (buffer_fd < 0) |
+ return false; |
+ |
+ 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() * pixmap_->GetStride(); |
+ va_attrib_extbuf.num_planes = 1; |
+ va_attrib_extbuf.pitches[0] = pixmap_->GetStride(); |
+ va_attrib_extbuf.offsets[0] = 0; |
+ va_attrib_extbuf.buffers = &buffer_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; |
+ |
+ if (!vaapi_wrapper_->CreateOutputSurface(VA_RT_FORMAT_RGB32, |
+ size(), |
+ va_attribs, |
+ arraysize(va_attribs), |
+ &va_surface_)) |
+ return false; |
Pawel Osciak
2014/10/26 13:06:46
What happens to fd? I think we need to close it?
D
llandwerlin-old
2014/10/29 13:52:48
Closing in the destructor now.
|
+ |
+ if (!make_context_current_.Run()) |
+ return false; |
+ |
+ gl_image_ = new gfx::GLImageEGL(size()); |
+ EGLint attrs[] = {EGL_IMAGE_PRESERVED_KHR, EGL_TRUE, EGL_NONE}; |
+ if (!gl_image_->Initialize( |
+ EGL_NATIVE_PIXMAP_KHR, pixmap_->GetEGLClientBuffer(), attrs)) |
+ return false; |
+ |
+ return true; |
+ } |
+ |
+ virtual bool DownloadFromSurface(VASurfaceID va_surface_id, |
+ const gfx::Size& surface_size) OVERRIDE { |
+ if (!vaapi_wrapper_->PutSurfaceIntoSurface( |
+ va_surface_id, surface_size, va_surface_, size())) |
Pawel Osciak
2014/10/26 13:06:46
Indent is wrong.
llandwerlin-old
2014/10/29 13:52:48
I'm sure I run cl format... Will rerun.
|
+ return false; |
+ |
+ if (!make_context_current_.Run()) |
+ return false; |
+ |
+ gfx::ScopedTextureBinder texture_binder(GL_TEXTURE_2D, texture_id()); |
+ return gl_image_->BindTexImage(GL_TEXTURE_2D); |
+ } |
+ |
+ private: |
+ scoped_refptr<VaapiWrapper> vaapi_wrapper_; |
+ base::Callback<bool(void)> make_context_current_; |
+ VASurfaceID va_surface_; |
Pawel Osciak
2014/10/26 13:06:46
s/va_surface/va_surface_id_
llandwerlin-old
2014/10/29 13:52:48
Acknowledged.
|
+ scoped_refptr<ui::NativePixmap> pixmap_; |
+ scoped_refptr<gfx::GLImageEGL> gl_image_; |
+ |
+ DISALLOW_COPY_AND_ASSIGN(DrmPicture); |
+}; |
+ |
+DrmVaapiPictureProvider::DrmVaapiPictureProvider( |
+ scoped_refptr<VaapiWrapper> vaapi_wrapper, |
+ const base::Callback<bool(void)> make_context_current) |
+ : make_context_current_(make_context_current), |
+ vaapi_wrapper_(vaapi_wrapper) { |
+} |
+ |
+DrmVaapiPictureProvider::~DrmVaapiPictureProvider() { |
+} |
+ |
+linked_ptr<VaapiPictureProvider::Picture> |
+DrmVaapiPictureProvider::CreatePicture(int32 picture_buffer_id, |
+ uint32 texture_id, |
+ const gfx::Size& size) { |
+ DrmPicture* drm_picture = new DrmPicture(vaapi_wrapper_, |
+ make_context_current_, |
+ picture_buffer_id, |
+ texture_id, |
+ size); |
+ linked_ptr<VaapiPictureProvider::Picture> picture(drm_picture); |
+ |
+ if (!drm_picture->Initialize()) |
+ picture.reset(); |
+ |
+ return picture; |
+} |
+ |
+bool DrmVaapiPictureProvider::Initialize() { |
+ return true; |
+} |
+ |
+} // namespace |