Commit 89caee51 authored by Miguel Casas's avatar Miguel Casas Committed by Commit Bot

Revert "vaapi: split VaapiDrmPicture into common and ozone/egl parts"

This reverts commit e330bcb6.

Reason for revert: typo forced using EGL VaapiPictures, bad!

Original change's description:
> vaapi: split VaapiDrmPicture into common and ozone/egl parts
> 
> This CL splits VaapiDrmPicture into a common part named
> VaapiPictureNativePixmap, and two subclasses, namely:
> - VaapiPictureNativePixmapOzone, containing the current
>  #if defined(USE_OZONE) sandwiched parts, and
> - VaapiPixtureNativePixmapEgl with the other parts.
> 
> So the class tree should look like:
> 
>   +-----------------+
>   |   VaapiPicture  |
>   +-----------------+
>    ^               ^
>    |               +----+
>   +--------------+    +------------------+
>   | VaapiPicture |    | VaapiPictureTFP  |
>   | NativePixmap |    | (existing on ToT)|
>   +--------------+    +------------------+
>    ^
>    +---------------+
>    |               |
>  +-------+    +-------+
>  | VPNP  |    | VPNP  |
>  | Ozone |    | Egl   |
>  +-------+    +-------+
> 
> The point here is to reduce the amount of if-defs to one single
> point, the VaapiPictureFactory.
> 
> BUILD.gn is changed to reflect that VaapiDrmPicture is
> egl-specific (see bug, |use_egl| definition in [1]), while
> VaapiDrmPictureOzone is |use_ozone| [2] specific. Note
> that |use_egl| can coexist with |use_x11| [3].
> 
> This CL just moves code around, no new code introduced in
> either vaapi_picture*.cc.
> 
> [1] https://cs.chromium.org/chromium/src/ui/gl/features.gni?q=ui/gl/features.gni&sq=package:chromium&dr&l=16
> [2] https://cs.chromium.org/chromium/src/build/config/ui.gni?q=build/config/ui.gni&sq=package:chromium&dr&l=26
> [3] https://cs.chromium.org/chromium/src/build/config/ui.gni?type=cs&sq=package:chromium&l=47
> 
> Bug: 785201
> Cq-Include-Trybots: master.tryserver.chromium.android:android_optional_gpu_tests_rel;master.tryserver.chromium.linux:linux_optional_gpu_tests_rel;master.tryserver.chromium.mac:mac_optional_gpu_tests_rel;master.tryserver.chromium.win:win_optional_gpu_tests_rel
> Change-Id: I67f6f4d994322ef7f23a8ed255405963a4be0152
> Reviewed-on: https://chromium-review.googlesource.com/951928
> Reviewed-by: Julien Isorce <julien.isorce@chromium.org>
> Commit-Queue: Miguel Casas <mcasas@chromium.org>
> Cr-Commit-Position: refs/heads/master@{#542107}

TBR=posciak@chromium.org,kcwu@chromium.org,mcasas@chromium.org,chcunningham@chromium.org,acourbot@chromium.org,julien.isorce@chromium.org

Change-Id: If5103a891bcf6f758feea44cc514503457f00fbc
No-Presubmit: true
No-Tree-Checks: true
No-Try: true
Bug: 785201
Cq-Include-Trybots: master.tryserver.chromium.android:android_optional_gpu_tests_rel;master.tryserver.chromium.linux:linux_optional_gpu_tests_rel;master.tryserver.chromium.mac:mac_optional_gpu_tests_rel;master.tryserver.chromium.win:win_optional_gpu_tests_rel
Reviewed-on: https://chromium-review.googlesource.com/957322Reviewed-by: default avatarMiguel Casas <mcasas@chromium.org>
Commit-Queue: Miguel Casas <mcasas@chromium.org>
Cr-Commit-Position: refs/heads/master@{#542148}
parent 8d0e11cc
...@@ -5,8 +5,6 @@ ...@@ -5,8 +5,6 @@
import("//build/config/features.gni") import("//build/config/features.gni")
import("//build/config/ui.gni") import("//build/config/ui.gni")
import("//media/gpu/args.gni") import("//media/gpu/args.gni")
import("//ui/gl/features.gni")
import("//ui/ozone/ozone.gni")
assert(use_vaapi) assert(use_vaapi)
...@@ -57,8 +55,6 @@ source_set("vaapi") { ...@@ -57,8 +55,6 @@ source_set("vaapi") {
"va_surface.h", "va_surface.h",
"vaapi_decode_surface.cc", "vaapi_decode_surface.cc",
"vaapi_decode_surface.h", "vaapi_decode_surface.h",
"vaapi_h264_accelerator.cc",
"vaapi_h264_accelerator.h",
"vaapi_jpeg_decode_accelerator.cc", "vaapi_jpeg_decode_accelerator.cc",
"vaapi_jpeg_decode_accelerator.h", "vaapi_jpeg_decode_accelerator.h",
"vaapi_jpeg_decoder.cc", "vaapi_jpeg_decoder.cc",
...@@ -75,14 +71,15 @@ source_set("vaapi") { ...@@ -75,14 +71,15 @@ source_set("vaapi") {
"vaapi_video_decode_accelerator.h", "vaapi_video_decode_accelerator.h",
"vaapi_video_encode_accelerator.cc", "vaapi_video_encode_accelerator.cc",
"vaapi_video_encode_accelerator.h", "vaapi_video_encode_accelerator.h",
"vaapi_h264_accelerator.cc",
"vaapi_h264_accelerator.h",
"vaapi_vp8_accelerator.cc", "vaapi_vp8_accelerator.cc",
"vaapi_vp8_accelerator.h", "vaapi_vp8_accelerator.h",
"vaapi_vp9_accelerator.cc", "vaapi_vp9_accelerator.cc",
"vaapi_vp9_accelerator.h", "vaapi_vp9_accelerator.h",
"vaapi_wrapper.cc", "vaapi_wrapper.cc",
"vaapi_wrapper.h", "vaapi_wrapper.h",
] ] + get_target_outputs(":libva_generate_stubs")
sources += get_target_outputs(":libva_generate_stubs")
configs += [ "//third_party/libyuv:libyuv_config" ] configs += [ "//third_party/libyuv:libyuv_config" ]
...@@ -93,34 +90,24 @@ source_set("vaapi") { ...@@ -93,34 +90,24 @@ source_set("vaapi") {
"//media/gpu:common", "//media/gpu:common",
"//third_party/libyuv", "//third_party/libyuv",
] ]
if (use_x11) { if (use_x11) {
configs += [ "//build/config/linux:x11" ] configs += [ "//build/config/linux:x11" ]
deps += [ "//ui/gfx/x" ] deps += [ "//ui/gfx/x" ]
sources += [ sources += [
"vaapi_picture_tfp.cc", "vaapi_tfp_picture.cc",
"vaapi_picture_tfp.h", "vaapi_tfp_picture.h",
] ]
} }
if (ozone_platform_gbm || use_egl) { if (is_linux) {
sources += [
"vaapi_picture_native_pixmap.cc",
"vaapi_picture_native_pixmap.h",
]
if (ozone_platform_gbm) {
sources += [
"vaapi_picture_native_pixmap_ozone.cc",
"vaapi_picture_native_pixmap_ozone.h",
]
deps += [ "//ui/ozone" ]
}
if (use_egl) {
sources += [ sources += [
"vaapi_picture_native_pixmap_egl.cc", "vaapi_drm_picture.cc",
"vaapi_picture_native_pixmap_egl.h", "vaapi_drm_picture.h",
] ]
} }
if (use_ozone) {
deps += [ "//ui/ozone" ]
} }
} }
......
...@@ -2,8 +2,9 @@ ...@@ -2,8 +2,9 @@
// Use of this source code is governed by a BSD-style license that can be // Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file. // found in the LICENSE file.
#include "media/gpu/vaapi/vaapi_picture_native_pixmap_ozone.h" #include "media/gpu/vaapi/vaapi_drm_picture.h"
#include "base/file_descriptor_posix.h"
#include "media/gpu/vaapi/va_surface.h" #include "media/gpu/vaapi/va_surface.h"
#include "media/gpu/vaapi/vaapi_wrapper.h" #include "media/gpu/vaapi/vaapi_wrapper.h"
#include "ui/gfx/gpu_memory_buffer.h" #include "ui/gfx/gpu_memory_buffer.h"
...@@ -12,12 +13,37 @@ ...@@ -12,12 +13,37 @@
#include "ui/gl/gl_bindings.h" #include "ui/gl/gl_bindings.h"
#include "ui/gl/gl_image_native_pixmap.h" #include "ui/gl/gl_image_native_pixmap.h"
#include "ui/gl/scoped_binders.h" #include "ui/gl/scoped_binders.h"
#if defined(USE_OZONE)
#include "ui/ozone/public/ozone_platform.h" #include "ui/ozone/public/ozone_platform.h"
#include "ui/ozone/public/surface_factory_ozone.h" #include "ui/ozone/public/surface_factory_ozone.h"
#endif
namespace media { namespace media {
VaapiPictureNativePixmapOzone::VaapiPictureNativePixmapOzone( namespace {
static unsigned BufferFormatToInternalFormat(gfx::BufferFormat format) {
switch (format) {
case gfx::BufferFormat::BGRX_8888:
case gfx::BufferFormat::RGBX_8888:
return GL_RGB;
case gfx::BufferFormat::BGRA_8888:
return GL_BGRA_EXT;
case gfx::BufferFormat::YVU_420:
return GL_RGB_YCRCB_420_CHROMIUM;
default:
NOTREACHED();
return GL_BGRA_EXT;
}
}
} // anonymous namespace
VaapiDrmPicture::VaapiDrmPicture(
const scoped_refptr<VaapiWrapper>& vaapi_wrapper, const scoped_refptr<VaapiWrapper>& vaapi_wrapper,
const MakeGLContextCurrentCallback& make_context_current_cb, const MakeGLContextCurrentCallback& make_context_current_cb,
const BindGLImageCallback& bind_image_cb, const BindGLImageCallback& bind_image_cb,
...@@ -26,7 +52,7 @@ VaapiPictureNativePixmapOzone::VaapiPictureNativePixmapOzone( ...@@ -26,7 +52,7 @@ VaapiPictureNativePixmapOzone::VaapiPictureNativePixmapOzone(
uint32_t texture_id, uint32_t texture_id,
uint32_t client_texture_id, uint32_t client_texture_id,
uint32_t texture_target) uint32_t texture_target)
: VaapiPictureNativePixmap(vaapi_wrapper, : VaapiPicture(vaapi_wrapper,
make_context_current_cb, make_context_current_cb,
bind_image_cb, bind_image_cb,
picture_buffer_id, picture_buffer_id,
...@@ -37,7 +63,7 @@ VaapiPictureNativePixmapOzone::VaapiPictureNativePixmapOzone( ...@@ -37,7 +63,7 @@ VaapiPictureNativePixmapOzone::VaapiPictureNativePixmapOzone(
DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_); DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_);
} }
VaapiPictureNativePixmapOzone::~VaapiPictureNativePixmapOzone() { VaapiDrmPicture::~VaapiDrmPicture() {
DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_); DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_);
if (gl_image_ && make_context_current_cb_.Run()) { if (gl_image_ && make_context_current_cb_.Run()) {
gl_image_->ReleaseTexImage(texture_target_); gl_image_->ReleaseTexImage(texture_target_);
...@@ -45,7 +71,7 @@ VaapiPictureNativePixmapOzone::~VaapiPictureNativePixmapOzone() { ...@@ -45,7 +71,7 @@ VaapiPictureNativePixmapOzone::~VaapiPictureNativePixmapOzone() {
} }
} }
bool VaapiPictureNativePixmapOzone::Initialize() { bool VaapiDrmPicture::Initialize() {
DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_); DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_);
DCHECK(pixmap_); DCHECK(pixmap_);
...@@ -56,6 +82,7 @@ bool VaapiPictureNativePixmapOzone::Initialize() { ...@@ -56,6 +82,7 @@ bool VaapiPictureNativePixmapOzone::Initialize() {
return false; return false;
} }
#if defined(USE_OZONE)
// Import dmabuf fds into the output gl texture through EGLImage. // Import dmabuf fds into the output gl texture through EGLImage.
if (texture_id_ != 0 && !make_context_current_cb_.is_null()) { if (texture_id_ != 0 && !make_context_current_cb_.is_null()) {
if (!make_context_current_cb_.Run()) if (!make_context_current_cb_.Run())
...@@ -77,6 +104,11 @@ bool VaapiPictureNativePixmapOzone::Initialize() { ...@@ -77,6 +104,11 @@ bool VaapiPictureNativePixmapOzone::Initialize() {
return false; return false;
} }
} }
#else
// On non-ozone, no need to import dmabuf fds into output the gl texture
// because the dmabuf fds have been made from it.
DCHECK(pixmap_->AreDmaBufFdsValid());
#endif
if (client_texture_id_ != 0 && !bind_image_cb_.is_null()) { if (client_texture_id_ != 0 && !bind_image_cb_.is_null()) {
if (!bind_image_cb_.Run(client_texture_id_, texture_target_, gl_image_, if (!bind_image_cb_.Run(client_texture_id_, texture_target_, gl_image_,
...@@ -89,13 +121,59 @@ bool VaapiPictureNativePixmapOzone::Initialize() { ...@@ -89,13 +121,59 @@ bool VaapiPictureNativePixmapOzone::Initialize() {
return true; return true;
} }
bool VaapiPictureNativePixmapOzone::Allocate(gfx::BufferFormat format) { bool VaapiDrmPicture::Allocate(gfx::BufferFormat format) {
DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_); DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_);
// The goal of this method (ozone and non-ozone) is to allocate the
// |pixmap_| which is a gl::GLImageNativePixmap.
#if defined(USE_OZONE)
ui::OzonePlatform* platform = ui::OzonePlatform::GetInstance(); ui::OzonePlatform* platform = ui::OzonePlatform::GetInstance();
ui::SurfaceFactoryOzone* factory = platform->GetSurfaceFactoryOzone(); ui::SurfaceFactoryOzone* factory = platform->GetSurfaceFactoryOzone();
pixmap_ = factory->CreateNativePixmap(gfx::kNullAcceleratedWidget, size_, pixmap_ = factory->CreateNativePixmap(gfx::kNullAcceleratedWidget, size_,
format, gfx::BufferUsage::SCANOUT); format, gfx::BufferUsage::SCANOUT);
#else
// Export the gl texture as dmabuf.
if (texture_id_ != 0 && !make_context_current_cb_.is_null()) {
if (!make_context_current_cb_.Run())
return false;
scoped_refptr<gl::GLImageNativePixmap> image(new gl::GLImageNativePixmap(
size_, BufferFormatToInternalFormat(format)));
// Create an EGLImage from a gl texture
if (!image->InitializeFromTexture(texture_id_)) {
DLOG(ERROR) << "Failed to initialize eglimage from texture id: "
<< texture_id_;
return false;
}
// Export the EGLImage as dmabuf.
gfx::NativePixmapHandle native_pixmap_handle = image->ExportHandle();
if (!native_pixmap_handle.planes.size()) {
DLOG(ERROR) << "Failed to export EGLImage as dmabuf fds";
return false;
}
// Convert NativePixmapHandle to NativePixmapDmaBuf.
scoped_refptr<gfx::NativePixmap> native_pixmap_dmabuf(
new gfx::NativePixmapDmaBuf(size_, format, native_pixmap_handle));
if (!native_pixmap_dmabuf->AreDmaBufFdsValid()) {
DLOG(ERROR) << "Invalid dmabuf fds";
return false;
}
if (!image->BindTexImage(texture_target_)) {
DLOG(ERROR) << "Failed to bind texture to GLImage";
return false;
}
// The |pixmap_| takes ownership of the dmabuf fds. So the only reason to
// to keep a reference on the image is because the GPU service needs to
// track this image as it will be attached to a client texture.
pixmap_ = native_pixmap_dmabuf;
gl_image_ = image;
}
#endif // USE_OZONE
if (!pixmap_) { if (!pixmap_) {
DVLOG(1) << "Failed allocating a pixmap"; DVLOG(1) << "Failed allocating a pixmap";
...@@ -105,18 +183,20 @@ bool VaapiPictureNativePixmapOzone::Allocate(gfx::BufferFormat format) { ...@@ -105,18 +183,20 @@ bool VaapiPictureNativePixmapOzone::Allocate(gfx::BufferFormat format) {
return Initialize(); return Initialize();
} }
bool VaapiPictureNativePixmapOzone::ImportGpuMemoryBufferHandle( bool VaapiDrmPicture::ImportGpuMemoryBufferHandle(
gfx::BufferFormat format, gfx::BufferFormat format,
const gfx::GpuMemoryBufferHandle& gpu_memory_buffer_handle) { const gfx::GpuMemoryBufferHandle& gpu_memory_buffer_handle) {
DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_); DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_);
#if defined(USE_OZONE)
ui::OzonePlatform* platform = ui::OzonePlatform::GetInstance(); ui::OzonePlatform* platform = ui::OzonePlatform::GetInstance();
ui::SurfaceFactoryOzone* factory = platform->GetSurfaceFactoryOzone(); ui::SurfaceFactoryOzone* factory = platform->GetSurfaceFactoryOzone();
// CreateNativePixmapFromHandle() will take ownership of the handle. // CreateNativePixmapFromHandle() will take ownership of the handle.
pixmap_ = factory->CreateNativePixmapFromHandle( pixmap_ = factory->CreateNativePixmapFromHandle(
gfx::kNullAcceleratedWidget, size_, format, gfx::kNullAcceleratedWidget, size_, format,
gpu_memory_buffer_handle.native_pixmap_handle); gpu_memory_buffer_handle.native_pixmap_handle);
#else
NOTIMPLEMENTED();
#endif
if (!pixmap_) { if (!pixmap_) {
DVLOG(1) << "Failed creating a pixmap from a native handle"; DVLOG(1) << "Failed creating a pixmap from a native handle";
return false; return false;
...@@ -125,13 +205,13 @@ bool VaapiPictureNativePixmapOzone::ImportGpuMemoryBufferHandle( ...@@ -125,13 +205,13 @@ bool VaapiPictureNativePixmapOzone::ImportGpuMemoryBufferHandle(
return Initialize(); return Initialize();
} }
bool VaapiPictureNativePixmapOzone::DownloadFromSurface( bool VaapiDrmPicture::DownloadFromSurface(
const scoped_refptr<VASurface>& va_surface) { const scoped_refptr<VASurface>& va_surface) {
DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_); DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_);
return vaapi_wrapper_->BlitSurface(va_surface, va_surface_); return vaapi_wrapper_->BlitSurface(va_surface, va_surface_);
} }
bool VaapiPictureNativePixmapOzone::AllowOverlay() const { bool VaapiDrmPicture::AllowOverlay() const {
DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_); DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_);
return true; return true;
} }
......
// Copyright 2014 The Chromium Authors. All rights reserved. // Copyright 2014 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be // Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file. // found in the LICENSE file.
//
// This file contains an implementation of picture allocation for the
// Ozone window system used by VaapiVideoDecodeAccelerator to produce
// output pictures.
#ifndef MEDIA_GPU_VAAPI_VAAPI_PICTURE_NATIVE_PIXMAP_OZONE_H_ #ifndef MEDIA_GPU_VAAPI_VAAPI_DRM_PICTURE_H_
#define MEDIA_GPU_VAAPI_VAAPI_PICTURE_NATIVE_PIXMAP_OZONE_H_ #define MEDIA_GPU_VAAPI_VAAPI_DRM_PICTURE_H_
#include <stdint.h> #include <stdint.h>
#include "base/macros.h" #include "base/macros.h"
#include "base/memory/ref_counted.h" #include "base/memory/ref_counted.h"
#include "base/memory/weak_ptr.h" #include "base/memory/weak_ptr.h"
#include "media/gpu/vaapi/vaapi_picture_native_pixmap.h" #include "media/gpu/vaapi/vaapi_picture.h"
#include "ui/gfx/buffer_types.h" #include "ui/gfx/buffer_types.h"
#include "ui/gfx/geometry/size.h" #include "ui/gfx/geometry/size.h"
namespace gl {
class GLImage;
}
namespace gfx {
class NativePixmap;
}
namespace media { namespace media {
class VaapiWrapper; class VaapiWrapper;
// Implementation of VaapiPictureNativePixmap using Ozone. // Implementation of VaapiPicture for the ozone/drm backed chromium.
class VaapiPictureNativePixmapOzone : public VaapiPictureNativePixmap { class VaapiDrmPicture : public VaapiPicture {
public: public:
VaapiPictureNativePixmapOzone( VaapiDrmPicture(const scoped_refptr<VaapiWrapper>& vaapi_wrapper,
const scoped_refptr<VaapiWrapper>& vaapi_wrapper,
const MakeGLContextCurrentCallback& make_context_current_cb, const MakeGLContextCurrentCallback& make_context_current_cb,
const BindGLImageCallback& bind_image_cb_, const BindGLImageCallback& bind_image_cb_,
int32_t picture_buffer_id, int32_t picture_buffer_id,
...@@ -31,22 +42,32 @@ class VaapiPictureNativePixmapOzone : public VaapiPictureNativePixmap { ...@@ -31,22 +42,32 @@ class VaapiPictureNativePixmapOzone : public VaapiPictureNativePixmap {
uint32_t client_texture_id, uint32_t client_texture_id,
uint32_t texture_target); uint32_t texture_target);
~VaapiPictureNativePixmapOzone() override; ~VaapiDrmPicture() override;
// VaapiPicture implementation.
bool Allocate(gfx::BufferFormat format) override; bool Allocate(gfx::BufferFormat format) override;
bool ImportGpuMemoryBufferHandle( bool ImportGpuMemoryBufferHandle(
gfx::BufferFormat format, gfx::BufferFormat format,
const gfx::GpuMemoryBufferHandle& gpu_memory_buffer_handle) override; const gfx::GpuMemoryBufferHandle& gpu_memory_buffer_handle) override;
bool DownloadFromSurface(const scoped_refptr<VASurface>& va_surface) override; bool DownloadFromSurface(const scoped_refptr<VASurface>& va_surface) override;
bool AllowOverlay() const override; bool AllowOverlay() const override;
private: private:
bool Initialize(); bool Initialize();
DISALLOW_COPY_AND_ASSIGN(VaapiPictureNativePixmapOzone); // Ozone buffer, the storage of the EGLImage and the VASurface.
scoped_refptr<gfx::NativePixmap> pixmap_;
// EGLImage bound to the GL textures used by the VDA client.
scoped_refptr<gl::GLImage> gl_image_;
// VASurface used to transfer from the decoder's pixel format.
scoped_refptr<VASurface> va_surface_;
DISALLOW_COPY_AND_ASSIGN(VaapiDrmPicture);
}; };
} // namespace media } // namespace media
#endif // MEDIA_GPU_VAAPI_VAAPI_PICTURE_NATIVE_PIXMAP_OZONE_H_ #endif // MEDIA_GPU_VAAPI_VAAPI_DRM_PICTURE_H_
...@@ -7,14 +7,10 @@ ...@@ -7,14 +7,10 @@
#include "media/gpu/vaapi/vaapi_wrapper.h" #include "media/gpu/vaapi/vaapi_wrapper.h"
#include "ui/gl/gl_bindings.h" #include "ui/gl/gl_bindings.h"
#include "media/gpu/vaapi/vaapi_drm_picture.h"
#if defined(USE_X11) #if defined(USE_X11)
#include "media/gpu/vaapi/vaapi_picture_tfp.h" #include "media/gpu/vaapi/vaapi_tfp_picture.h"
#endif
#if defined(USE_OZONE)
#include "media/gpu/vaapi/vaapi_picture_native_pixmap_ozone.h"
#endif
#if defined(USE_EGL)
#include "media/gpu/vaapi/vaapi_picture_native_pixmap_egl.h"
#endif #endif
namespace media { namespace media {
...@@ -55,18 +51,10 @@ std::unique_ptr<VaapiPicture> VaapiPictureFactory::Create( ...@@ -55,18 +51,10 @@ std::unique_ptr<VaapiPicture> VaapiPictureFactory::Create(
// Select DRM(egl) / TFP(glx) at runtime with --use-gl=egl / --use-gl=desktop // Select DRM(egl) / TFP(glx) at runtime with --use-gl=egl / --use-gl=desktop
switch (GetVaapiImplementation(gl::GetGLImplementation())) { switch (GetVaapiImplementation(gl::GetGLImplementation())) {
case kVaapiImplementationDrm: case kVaapiImplementationDrm:
#if defined(USE_OZONE) picture.reset(new VaapiDrmPicture(vaapi_wrapper, make_context_current_cb,
picture.reset(new VaapiPictureNativePixmapOzone( bind_image_cb, picture_buffer_id, size,
vaapi_wrapper, make_context_current_cb, bind_image_cb, texture_id, client_texture_id,
picture_buffer_id, size, texture_id, client_texture_id,
texture_target));
#endif
#if defined(USE_EGL)
picture.reset(new VaapiPictureNativePixmapEgl(
vaapi_wrapper, make_context_current_cb, bind_image_cb,
picture_buffer_id, size, texture_id, client_texture_id,
texture_target)); texture_target));
#endif
break; break;
#if defined(USE_X11) #if defined(USE_X11)
......
// Copyright 2018 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 "media/gpu/vaapi/vaapi_picture_native_pixmap.h"
#include "media/gpu/vaapi/va_surface.h"
#include "ui/gfx/buffer_format_util.h"
#include "ui/gfx/gpu_memory_buffer.h"
#include "ui/gfx/linux/native_pixmap_dmabuf.h"
#include "ui/gfx/native_pixmap.h"
#include "ui/gl/gl_image_native_pixmap.h"
namespace media {
VaapiPictureNativePixmap::VaapiPictureNativePixmap(
const scoped_refptr<VaapiWrapper>& vaapi_wrapper,
const MakeGLContextCurrentCallback& make_context_current_cb,
const BindGLImageCallback& bind_image_cb,
int32_t picture_buffer_id,
const gfx::Size& size,
uint32_t texture_id,
uint32_t client_texture_id,
uint32_t texture_target)
: VaapiPicture(vaapi_wrapper,
make_context_current_cb,
bind_image_cb,
picture_buffer_id,
size,
texture_id,
client_texture_id,
texture_target) {}
VaapiPictureNativePixmap::~VaapiPictureNativePixmap() = default;
unsigned VaapiPictureNativePixmap::BufferFormatToInternalFormat(
gfx::BufferFormat format) const {
switch (format) {
case gfx::BufferFormat::BGRX_8888:
case gfx::BufferFormat::RGBX_8888:
return GL_RGB;
case gfx::BufferFormat::BGRA_8888:
return GL_BGRA_EXT;
case gfx::BufferFormat::YVU_420:
return GL_RGB_YCRCB_420_CHROMIUM;
default:
NOTREACHED() << gfx::BufferFormatToString(format);
return GL_BGRA_EXT;
}
}
} // namespace media
// Copyright 2018 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.
#ifndef MEDIA_GPU_VAAPI_VAAPI_PICTURE_NATIVE_PIXMAP_H_
#define MEDIA_GPU_VAAPI_VAAPI_PICTURE_NATIVE_PIXMAP_H_
#include <stdint.h>
#include "base/memory/ref_counted.h"
#include "media/gpu/vaapi/vaapi_picture.h"
#include "ui/gfx/buffer_types.h"
#include "ui/gfx/geometry/size.h"
namespace gl {
class GLImage;
}
namespace gfx {
class NativePixmap;
}
namespace media {
class VaapiWrapper;
// Implementation of VaapiPicture based on NativePixmaps.
class VaapiPictureNativePixmap : public VaapiPicture {
public:
VaapiPictureNativePixmap(
const scoped_refptr<VaapiWrapper>& vaapi_wrapper,
const MakeGLContextCurrentCallback& make_context_current_cb,
const BindGLImageCallback& bind_image_cb_,
int32_t picture_buffer_id,
const gfx::Size& size,
uint32_t texture_id,
uint32_t client_texture_id,
uint32_t texture_target);
~VaapiPictureNativePixmap() override;
unsigned BufferFormatToInternalFormat(gfx::BufferFormat format) const;
protected:
// Ozone buffer, the storage of the EGLImage and the VASurface.
scoped_refptr<gfx::NativePixmap> pixmap_;
// GLImage bound to the GL textures used by the VDA client.
scoped_refptr<gl::GLImage> gl_image_;
// VASurface used to transfer from the decoder's pixel format.
scoped_refptr<VASurface> va_surface_;
private:
DISALLOW_COPY_AND_ASSIGN(VaapiPictureNativePixmap);
};
} // namespace media
#endif // MEDIA_GPU_VAAPI_VAAPI_PICTURE_NATIVE_PIXMAP_H_
// Copyright 2018 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 "media/gpu/vaapi/vaapi_picture_native_pixmap_egl.h"
#include "base/file_descriptor_posix.h"
#include "media/gpu/vaapi/va_surface.h"
#include "media/gpu/vaapi/vaapi_wrapper.h"
#include "ui/gfx/linux/native_pixmap_dmabuf.h"
#include "ui/gfx/native_pixmap.h"
#include "ui/gl/gl_bindings.h"
#include "ui/gl/gl_image_native_pixmap.h"
#include "ui/gl/scoped_binders.h"
namespace media {
VaapiPictureNativePixmapEgl::VaapiPictureNativePixmapEgl(
const scoped_refptr<VaapiWrapper>& vaapi_wrapper,
const MakeGLContextCurrentCallback& make_context_current_cb,
const BindGLImageCallback& bind_image_cb,
int32_t picture_buffer_id,
const gfx::Size& size,
uint32_t texture_id,
uint32_t client_texture_id,
uint32_t texture_target)
: VaapiPictureNativePixmap(vaapi_wrapper,
make_context_current_cb,
bind_image_cb,
picture_buffer_id,
size,
texture_id,
client_texture_id,
texture_target) {
DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_);
}
VaapiPictureNativePixmapEgl::~VaapiPictureNativePixmapEgl() {
DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_);
if (gl_image_ && make_context_current_cb_.Run()) {
gl_image_->ReleaseTexImage(texture_target_);
DCHECK_EQ(glGetError(), static_cast<GLenum>(GL_NO_ERROR));
}
}
bool VaapiPictureNativePixmapEgl::Initialize() {
DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_);
DCHECK(pixmap_);
// Create a |va_surface_| from dmabuf fds (pixmap->GetDmaBufFd)
va_surface_ = vaapi_wrapper_->CreateVASurfaceForPixmap(pixmap_);
if (!va_surface_) {
LOG(ERROR) << "Failed creating VASurface for NativePixmap";
return false;
}
// On non-ozone, no need to import dmabuf fds into output the gl texture
// because the dmabuf fds have been made from it.
DCHECK(pixmap_->AreDmaBufFdsValid());
if (client_texture_id_ != 0 && !bind_image_cb_.is_null()) {
if (!bind_image_cb_.Run(client_texture_id_, texture_target_, gl_image_,
true)) {
LOG(ERROR) << "Failed to bind client_texture_id";
return false;
}
}
return true;
}
bool VaapiPictureNativePixmapEgl::Allocate(gfx::BufferFormat format) {
DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_);
// Export the gl texture as dmabuf.
if (texture_id_ != 0 && !make_context_current_cb_.is_null()) {
if (!make_context_current_cb_.Run())
return false;
scoped_refptr<gl::GLImageNativePixmap> image(new gl::GLImageNativePixmap(
size_, BufferFormatToInternalFormat(format)));
// Create an EGLImage from a gl texture
if (!image->InitializeFromTexture(texture_id_)) {
DLOG(ERROR) << "Failed to initialize eglimage from texture id: "
<< texture_id_;
return false;
}
// Export the EGLImage as dmabuf.
gfx::NativePixmapHandle native_pixmap_handle = image->ExportHandle();
if (!native_pixmap_handle.planes.size()) {
DLOG(ERROR) << "Failed to export EGLImage as dmabuf fds";
return false;
}
// Convert NativePixmapHandle to NativePixmapDmaBuf.
scoped_refptr<gfx::NativePixmap> native_pixmap_dmabuf(
new gfx::NativePixmapDmaBuf(size_, format, native_pixmap_handle));
if (!native_pixmap_dmabuf->AreDmaBufFdsValid()) {
DLOG(ERROR) << "Invalid dmabuf fds";
return false;
}
if (!image->BindTexImage(texture_target_)) {
DLOG(ERROR) << "Failed to bind texture to GLImage";
return false;
}
// The |pixmap_| takes ownership of the dmabuf fds. So the only reason
// to keep a reference on the image is because the GPU service needs to
// track this image as it will be attached to a client texture.
pixmap_ = native_pixmap_dmabuf;
gl_image_ = image;
}
if (!pixmap_) {
DVLOG(1) << "Failed allocating a pixmap";
return false;
}
return Initialize();
}
bool VaapiPictureNativePixmapEgl::ImportGpuMemoryBufferHandle(
gfx::BufferFormat format,
const gfx::GpuMemoryBufferHandle& gpu_memory_buffer_handle) {
DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_);
NOTIMPLEMENTED();
return false;
}
bool VaapiPictureNativePixmapEgl::DownloadFromSurface(
const scoped_refptr<VASurface>& va_surface) {
DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_);
return vaapi_wrapper_->BlitSurface(va_surface, va_surface_);
}
bool VaapiPictureNativePixmapEgl::AllowOverlay() const {
DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_);
return true;
}
} // namespace media
// Copyright 2018 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.
#ifndef MEDIA_GPU_VAAPI_VAAPI_PICTURE_NATIVE_PIXMAP_EGL_H_
#define MEDIA_GPU_VAAPI_VAAPI_PICTURE_NATIVE_PIXMAP_EGL_H_
#include <stdint.h>
#include "base/macros.h"
#include "base/memory/ref_counted.h"
#include "base/memory/weak_ptr.h"
#include "media/gpu/vaapi/vaapi_picture_native_pixmap.h"
#include "ui/gfx/buffer_types.h"
#include "ui/gfx/geometry/size.h"
namespace media {
class VaapiWrapper;
// Implementation of VaapiPictureNativePixmap for EGL backends, see
// https://crbug.com/785201.
class VaapiPictureNativePixmapEgl : public VaapiPictureNativePixmap {
public:
VaapiPictureNativePixmapEgl(
const scoped_refptr<VaapiWrapper>& vaapi_wrapper,
const MakeGLContextCurrentCallback& make_context_current_cb,
const BindGLImageCallback& bind_image_cb_,
int32_t picture_buffer_id,
const gfx::Size& size,
uint32_t texture_id,
uint32_t client_texture_id,
uint32_t texture_target);
~VaapiPictureNativePixmapEgl() override;
// VaapiPicture implementation.
bool Allocate(gfx::BufferFormat format) override;
bool ImportGpuMemoryBufferHandle(
gfx::BufferFormat format,
const gfx::GpuMemoryBufferHandle& gpu_memory_buffer_handle) override;
bool DownloadFromSurface(const scoped_refptr<VASurface>& va_surface) override;
bool AllowOverlay() const override;
private:
bool Initialize();
DISALLOW_COPY_AND_ASSIGN(VaapiPictureNativePixmapEgl);
};
} // namespace media
#endif // MEDIA_GPU_VAAPI_VAAPI_PICTURE_NATIVE_PIXMAP_EGL_H_
...@@ -2,7 +2,7 @@ ...@@ -2,7 +2,7 @@
// Use of this source code is governed by a BSD-style license that can be // Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file. // found in the LICENSE file.
#include "media/gpu/vaapi/vaapi_picture_tfp.h" #include "media/gpu/vaapi/vaapi_tfp_picture.h"
#include "media/gpu/vaapi/va_surface.h" #include "media/gpu/vaapi/va_surface.h"
#include "media/gpu/vaapi/vaapi_wrapper.h" #include "media/gpu/vaapi/vaapi_wrapper.h"
......
// Copyright 2014 The Chromium Authors. All rights reserved. // Copyright 2014 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be // Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file. // found in the LICENSE file.
//
// This file contains an implementation of picture allocation for the
// X11 window system used by VaapiVideoDecodeAccelerator to produce
// output pictures.
#ifndef MEDIA_GPU_VAAPI_VAAPI_PICTURE_TFP_H_ #ifndef MEDIA_GPU_VAAPI_VAAPI_TFP_PICTURE_H_
#define MEDIA_GPU_VAAPI_VAAPI_PICTURE_TFP_H_ #define MEDIA_GPU_VAAPI_VAAPI_TFP_PICTURE_H_
#include <stdint.h> #include <stdint.h>
...@@ -21,8 +25,7 @@ namespace media { ...@@ -21,8 +25,7 @@ namespace media {
class VaapiWrapper; class VaapiWrapper;
// Implementation of VaapiPicture for the X11 backends with Texture-From-Pixmap // Implementation of VaapiPicture for the X11 backed chromium.
// extension.
class VaapiTFPPicture : public VaapiPicture { class VaapiTFPPicture : public VaapiPicture {
public: public:
VaapiTFPPicture(const scoped_refptr<VaapiWrapper>& vaapi_wrapper, VaapiTFPPicture(const scoped_refptr<VaapiWrapper>& vaapi_wrapper,
...@@ -36,11 +39,11 @@ class VaapiTFPPicture : public VaapiPicture { ...@@ -36,11 +39,11 @@ class VaapiTFPPicture : public VaapiPicture {
~VaapiTFPPicture() override; ~VaapiTFPPicture() override;
// VaapiPicture implementation.
bool Allocate(gfx::BufferFormat format) override; bool Allocate(gfx::BufferFormat format) override;
bool ImportGpuMemoryBufferHandle( bool ImportGpuMemoryBufferHandle(
gfx::BufferFormat format, gfx::BufferFormat format,
const gfx::GpuMemoryBufferHandle& gpu_memory_buffer_handle) override; const gfx::GpuMemoryBufferHandle& gpu_memory_buffer_handle) override;
bool DownloadFromSurface(const scoped_refptr<VASurface>& va_surface) override; bool DownloadFromSurface(const scoped_refptr<VASurface>& va_surface) override;
private: private:
...@@ -56,4 +59,4 @@ class VaapiTFPPicture : public VaapiPicture { ...@@ -56,4 +59,4 @@ class VaapiTFPPicture : public VaapiPicture {
} // namespace media } // namespace media
#endif // MEDIA_GPU_VAAPI_VAAPI_PICTURE_TFP_H_ #endif // MEDIA_GPU_VAAPI_VAAPI_TFP_PICTURE_H_
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment