Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "base/file_descriptor_posix.h" | 5 #include "base/file_descriptor_posix.h" |
| 6 #include "content/common/gpu/media/va_surface.h" | 6 #include "content/common/gpu/media/va_surface.h" |
| 7 #include "content/common/gpu/media/vaapi_drm_picture.h" | 7 #include "content/common/gpu/media/vaapi_drm_picture.h" |
| 8 #include "content/common/gpu/media/vaapi_wrapper.h" | 8 #include "content/common/gpu/media/vaapi_wrapper.h" |
| 9 #include "gpu/command_buffer/service/texture_manager.h" | |
| 9 #include "third_party/libva/va/drm/va_drm.h" | 10 #include "third_party/libva/va/drm/va_drm.h" |
| 10 #include "third_party/libva/va/va.h" | 11 #include "third_party/libva/va/va.h" |
| 11 #include "third_party/libva/va/va_drmcommon.h" | 12 #include "third_party/libva/va/va_drmcommon.h" |
| 12 #include "ui/gfx/gpu_memory_buffer.h" | 13 #include "ui/gfx/gpu_memory_buffer.h" |
| 13 #include "ui/gl/gl_bindings.h" | 14 #include "ui/gl/gl_bindings.h" |
| 14 #include "ui/gl/gl_image_linux_dma_buffer.h" | 15 #include "ui/gl/gl_image_linux_dma_buffer.h" |
| 15 #include "ui/gl/scoped_binders.h" | 16 #include "ui/gl/scoped_binders.h" |
| 17 #include "ui/ozone/gpu/gpu_memory_buffer_factory_ozone_native_buffer.h" | |
| 16 #include "ui/ozone/public/native_pixmap.h" | 18 #include "ui/ozone/public/native_pixmap.h" |
| 17 #include "ui/ozone/public/ozone_platform.h" | 19 #include "ui/ozone/public/ozone_platform.h" |
| 18 #include "ui/ozone/public/surface_factory_ozone.h" | 20 #include "ui/ozone/public/surface_factory_ozone.h" |
| 19 | 21 |
| 20 namespace content { | 22 namespace content { |
| 21 | 23 |
| 22 VaapiDrmPicture::VaapiDrmPicture( | 24 VaapiDrmPicture::VaapiDrmPicture( |
| 23 VaapiWrapper* vaapi_wrapper, | 25 VaapiWrapper* vaapi_wrapper, |
| 24 const base::Callback<bool(void)>& make_context_current, | 26 const base::Callback<bool(void)>& make_context_current, |
| 25 int32 picture_buffer_id, | 27 int32 picture_buffer_id, |
| 26 uint32 texture_id, | 28 uint32 texture_id, |
| 27 const gfx::Size& size) | 29 const gfx::Size& size) |
| 28 : VaapiPicture(picture_buffer_id, texture_id, size), | 30 : VaapiPicture(picture_buffer_id, texture_id, size, true), |
| 29 vaapi_wrapper_(vaapi_wrapper), | 31 vaapi_wrapper_(vaapi_wrapper), |
| 30 make_context_current_(make_context_current) { | 32 make_context_current_(make_context_current) { |
| 31 } | 33 } |
| 32 | 34 |
| 33 VaapiDrmPicture::~VaapiDrmPicture() { | 35 VaapiDrmPicture::~VaapiDrmPicture() { |
| 34 if (gl_image_ && make_context_current_.Run()) { | 36 if (gl_image_ && make_context_current_.Run()) { |
| 35 gl_image_->ReleaseTexImage(GL_TEXTURE_EXTERNAL_OES); | 37 gl_image_->ReleaseTexImage(GL_TEXTURE_EXTERNAL_OES); |
| 36 gl_image_->Destroy(true); | 38 gl_image_->Destroy(true); |
| 37 | 39 |
| 38 DCHECK_EQ(glGetError(), static_cast<GLenum>(GL_NO_ERROR)); | 40 DCHECK_EQ(glGetError(), static_cast<GLenum>(GL_NO_ERROR)); |
| 39 } | 41 } |
| 40 } | 42 } |
| 41 | 43 |
| 42 bool VaapiDrmPicture::Initialize() { | 44 bool VaapiDrmPicture::Initialize(gpu::gles2::TextureManager* texture_manager, |
| 45 gpu::gles2::TextureRef* texture_ref) { | |
| 43 // We want to create a VASurface and an EGLImage out of the same | 46 // We want to create a VASurface and an EGLImage out of the same |
| 44 // memory buffer, so we can output decoded pictures to it using | 47 // memory buffer, so we can output decoded pictures to it using |
| 45 // VAAPI and also use it to paint with GL. | 48 // VAAPI and also use it to paint with GL. |
| 46 ui::OzonePlatform* platform = ui::OzonePlatform::GetInstance(); | 49 ui::OzonePlatform* platform = ui::OzonePlatform::GetInstance(); |
| 47 ui::SurfaceFactoryOzone* factory = platform->GetSurfaceFactoryOzone(); | 50 ui::SurfaceFactoryOzone* factory = platform->GetSurfaceFactoryOzone(); |
| 48 | 51 |
| 49 // Create a buffer from Ozone. | 52 // Create a buffer from Ozone. |
| 50 pixmap_ = factory->CreateNativePixmap(gfx::kNullAcceleratedWidget, size(), | 53 pixmap_ = factory->CreateNativePixmap(gfx::kNullAcceleratedWidget, size(), |
| 51 ui::SurfaceFactoryOzone::RGBA_8888, | 54 ui::SurfaceFactoryOzone::RGBA_8888, |
| 52 ui::SurfaceFactoryOzone::SCANOUT); | 55 ui::SurfaceFactoryOzone::SCANOUT); |
| (...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 94 va_surface_ = vaapi_wrapper_->CreateUnownedSurface(VA_RT_FORMAT_RGB32, size(), | 97 va_surface_ = vaapi_wrapper_->CreateUnownedSurface(VA_RT_FORMAT_RGB32, size(), |
| 95 va_attribs); | 98 va_attribs); |
| 96 if (!va_surface_) { | 99 if (!va_surface_) { |
| 97 LOG(ERROR) << "Failed to create VASurface for an Ozone NativePixmap"; | 100 LOG(ERROR) << "Failed to create VASurface for an Ozone NativePixmap"; |
| 98 return false; | 101 return false; |
| 99 } | 102 } |
| 100 | 103 |
| 101 if (!make_context_current_.Run()) | 104 if (!make_context_current_.Run()) |
| 102 return false; | 105 return false; |
| 103 | 106 |
| 104 // Create an EGLImage out of the same buffer. | 107 gfx::ScopedTextureBinder texture_binder(GL_TEXTURE_EXTERNAL_OES, |
| 105 gl_image_ = new gfx::GLImageLinuxDMABuffer(size(), GL_RGBA); | 108 texture_id()); |
| 106 if (!gl_image_->Initialize(base::FileDescriptor(dmabuf_fd, false), | 109 gl_image_ = ui::GpuMemoryBufferFactoryOzoneNativeBuffer::CreateImageForPixmap( |
| 107 gfx::GpuMemoryBuffer::BGRA_8888, dmabuf_pitch)) { | 110 pixmap_, size(), gfx::GpuMemoryBuffer::RGBA_8888, GL_RGBA); |
| 108 LOG(ERROR) << "Failed to create a GLImageLinuxDMABuffer for a NativePixmap"; | 111 if (!gl_image_) { |
| 112 LOG(ERROR) << "Failed to create GLImage"; | |
| 109 return false; | 113 return false; |
| 110 } | 114 } |
| 111 | |
| 112 // Bind the EGLImage to the given GL texture. | |
| 113 gfx::ScopedTextureBinder texture_binder(GL_TEXTURE_EXTERNAL_OES, | |
| 114 texture_id()); | |
| 115 if (!gl_image_->BindTexImage(GL_TEXTURE_EXTERNAL_OES)) { | 115 if (!gl_image_->BindTexImage(GL_TEXTURE_EXTERNAL_OES)) { |
| 116 LOG(ERROR) << "Failed to bind texture to GLImage"; | 116 LOG(ERROR) << "Failed to bind texture to GLImage"; |
| 117 return false; | 117 return false; |
| 118 } | 118 } |
| 119 texture_manager->SetLevelImage(texture_ref, GL_TEXTURE_EXTERNAL_OES, 0, | |
|
Pawel Osciak
2015/01/21 13:07:08
I think we can get texture_ref from texture_manage
achaulk
2015/01/21 17:10:03
Unfortunately, it's the wrong texture_id, we need
| |
| 120 gl_image_.get()); | |
| 119 | 121 |
| 120 return true; | 122 return true; |
| 121 } | 123 } |
| 122 | 124 |
| 123 bool VaapiDrmPicture::DownloadFromSurface( | 125 bool VaapiDrmPicture::DownloadFromSurface( |
| 124 const scoped_refptr<VASurface>& va_surface) { | 126 const scoped_refptr<VASurface>& va_surface) { |
| 125 return vaapi_wrapper_->BlitSurface(va_surface->id(), va_surface->size(), | 127 return vaapi_wrapper_->BlitSurface(va_surface->id(), va_surface->size(), |
| 126 va_surface_->id(), va_surface_->size()); | 128 va_surface_->id(), va_surface_->size()); |
| 127 } | 129 } |
| 128 | 130 |
| 129 } // namespace | 131 } // namespace |
| OLD | NEW |