summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authordcheng <dcheng@chromium.org>2014-12-20 10:51:11 -0800
committerCommit bot <commit-bot@chromium.org>2014-12-20 18:51:47 +0000
commit6dc14e495d4ca089c096ba0263fd5269647de838 (patch)
treebb317610ec2f9a4f1ab78beb736a31b3ac5c6774
parent289e96375e75be0d9158b86df2bd4faf2d7b2a64 (diff)
downloadchromium_src-6dc14e495d4ca089c096ba0263fd5269647de838.zip
chromium_src-6dc14e495d4ca089c096ba0263fd5269647de838.tar.gz
chromium_src-6dc14e495d4ca089c096ba0263fd5269647de838.tar.bz2
Revert of Refactor Vaapi video decoder/encoder in preparation of Freon support (patchset #6 id:100001 of https://codereview.chromium.org/807853005/)
Reason for revert: Caused build failure on Linux ChromiumOS GN: ninja: error: '../../content/common/content/common/gpu/media/va_x11.sigs', needed by 'obj/content/common/libva_generate_stubs.inputdeps.stamp', missing and no known rule to make it Original issue's description: > Refactor Vaapi video decoder/encoder in preparation of Freon support > > This introduces VaapiPicture which abstracts the output picture for the VaapiVideoDecodeAccelerator. > This also splits out the x11 specific functions of LibVA into their own signature file. > And finally this adds back GLImageGLX to match the code path that will be used on Freon, using GLImageLinuxDMABuffer. > > BUG=403058 > TEST=video_decode_accelerator_unittest and video_encode_accelerator_unittest > > Committed: https://crrev.com/289e96375e75be0d9158b86df2bd4faf2d7b2a64 > Cr-Commit-Position: refs/heads/master@{#309355} TBR=reveman@chromium.org,posciak@chromium.org,scherkus@chromium.org,piman@chromium.org,lionel.g.landwerlin@intel.com NOTREECHECKS=true NOTRY=true BUG=403058 Review URL: https://codereview.chromium.org/804353003 Cr-Commit-Position: refs/heads/master@{#309356}
-rw-r--r--content/common/BUILD.gn20
-rw-r--r--content/common/gpu/media/gpu_video_decode_accelerator.cc17
-rw-r--r--content/common/gpu/media/gpu_video_encode_accelerator.cc11
-rw-r--r--content/common/gpu/media/rendering_helper.cc39
-rw-r--r--content/common/gpu/media/rendering_helper.h5
-rw-r--r--content/common/gpu/media/va.sigs7
-rw-r--r--content/common/gpu/media/va_surface.h17
-rw-r--r--content/common/gpu/media/va_x11.sigs9
-rw-r--r--content/common/gpu/media/vaapi_h264_decoder_unittest.cc30
-rw-r--r--content/common/gpu/media/vaapi_picture.cc40
-rw-r--r--content/common/gpu/media/vaapi_picture.h73
-rw-r--r--content/common/gpu/media/vaapi_tfp_picture.cc77
-rw-r--r--content/common/gpu/media/vaapi_tfp_picture.h56
-rw-r--r--content/common/gpu/media/vaapi_video_decode_accelerator.cc264
-rw-r--r--content/common/gpu/media/vaapi_video_decode_accelerator.h38
-rw-r--r--content/common/gpu/media/vaapi_video_encode_accelerator.cc17
-rw-r--r--content/common/gpu/media/vaapi_video_encode_accelerator.h6
-rw-r--r--content/common/gpu/media/vaapi_wrapper.cc93
-rw-r--r--content/common/gpu/media/vaapi_wrapper.h41
-rw-r--r--content/common/gpu/media/video_decode_accelerator_unittest.cc16
-rw-r--r--content/common/gpu/media/video_encode_accelerator_unittest.cc10
-rw-r--r--content/content_common.gypi25
-rw-r--r--media/BUILD.gn2
-rw-r--r--media/media.gyp2
-rw-r--r--ui/gl/gl_image_glx.cc2
25 files changed, 425 insertions, 492 deletions
diff --git a/content/common/BUILD.gn b/content/common/BUILD.gn
index e4fcad6..03a594d 100644
--- a/content/common/BUILD.gn
+++ b/content/common/BUILD.gn
@@ -7,7 +7,7 @@ import("//build/config/ui.gni")
import("//content/common/common.gni")
import("//mojo/public/tools/bindings/mojom.gni")
-if (is_chromeos && cpu_arch != "arm") {
+if (is_chromeos && use_x11 && cpu_arch != "arm") {
action("libva_generate_stubs") {
extra_header = "gpu/media/va_stub_header.fragment"
@@ -18,9 +18,6 @@ if (is_chromeos && cpu_arch != "arm") {
inputs = [
extra_header,
]
- if (use_x11) {
- sources += [ "content/common/gpu/media/va_x11.sigs" ]
- }
stubs_filename_root = "va_stubs"
outputs = [
@@ -277,8 +274,8 @@ source_set("common") {
}
}
- if (is_chromeos) {
- if (cpu_arch == "arm" && use_x11) {
+ if (is_chromeos && use_x11) {
+ if (cpu_arch == "arm") {
sources += [
"gpu/media/exynos_v4l2_video_device.cc",
"gpu/media/exynos_v4l2_video_device.h",
@@ -297,16 +294,13 @@ source_set("common") {
"EGL",
"GLESv2",
]
- }
- if (cpu_arch != "arm") {
+ } else { # !arm
sources += [
"gpu/media/h264_dpb.cc",
"gpu/media/h264_dpb.h",
"gpu/media/va_surface.h",
"gpu/media/vaapi_h264_decoder.cc",
"gpu/media/vaapi_h264_decoder.h",
- "gpu/media/vaapi_picture.cc",
- "gpu/media/vaapi_picture.h",
"gpu/media/vaapi_video_decode_accelerator.cc",
"gpu/media/vaapi_video_decode_accelerator.h",
"gpu/media/vaapi_video_encode_accelerator.cc",
@@ -323,12 +317,6 @@ source_set("common") {
"//media",
"//third_party/libyuv",
]
- if (use_x11) {
- sources += [
- "gpu/media/vaapi_tfp_picture.cc",
- "gpu/media/vaapi_tfp_picture.h",
- ]
- }
}
}
diff --git a/content/common/gpu/media/gpu_video_decode_accelerator.cc b/content/common/gpu/media/gpu_video_decode_accelerator.cc
index 3d3a437..f741cb2 100644
--- a/content/common/gpu/media/gpu_video_decode_accelerator.cc
+++ b/content/common/gpu/media/gpu_video_decode_accelerator.cc
@@ -31,8 +31,9 @@
#elif defined(OS_CHROMEOS) && defined(ARCH_CPU_ARMEL) && defined(USE_X11)
#include "content/common/gpu/media/v4l2_video_decode_accelerator.h"
#include "content/common/gpu/media/v4l2_video_device.h"
-#elif defined(OS_CHROMEOS) && defined(ARCH_CPU_X86_FAMILY)
+#elif defined(OS_CHROMEOS) && defined(ARCH_CPU_X86_FAMILY) && defined(USE_X11)
#include "content/common/gpu/media/vaapi_video_decode_accelerator.h"
+#include "ui/gl/gl_context_glx.h"
#include "ui/gl/gl_implementation.h"
#elif defined(USE_OZONE)
#include "media/ozone/media_ozone_platform.h"
@@ -271,9 +272,17 @@ void GpuVideoDecodeAccelerator::Initialize(
make_context_current_,
device.Pass(),
io_message_loop_));
-#elif defined(OS_CHROMEOS) && defined(ARCH_CPU_X86_FAMILY)
- video_decode_accelerator_.reset(
- new VaapiVideoDecodeAccelerator(make_context_current_));
+#elif defined(OS_CHROMEOS) && defined(ARCH_CPU_X86_FAMILY) && defined(USE_X11)
+ if (gfx::GetGLImplementation() != gfx::kGLImplementationDesktopGL) {
+ VLOG(1) << "HW video decode acceleration not available without "
+ "DesktopGL (GLX).";
+ SendCreateDecoderReply(init_done_msg, false);
+ return;
+ }
+ gfx::GLContextGLX* glx_context =
+ static_cast<gfx::GLContextGLX*>(stub_->decoder()->GetGLContext());
+ video_decode_accelerator_.reset(new VaapiVideoDecodeAccelerator(
+ glx_context->display(), make_context_current_));
#elif defined(USE_OZONE)
media::MediaOzonePlatform* platform =
media::MediaOzonePlatform::GetInstance();
diff --git a/content/common/gpu/media/gpu_video_encode_accelerator.cc b/content/common/gpu/media/gpu_video_encode_accelerator.cc
index 639d1d8..12b473f 100644
--- a/content/common/gpu/media/gpu_video_encode_accelerator.cc
+++ b/content/common/gpu/media/gpu_video_encode_accelerator.cc
@@ -17,12 +17,13 @@
#include "media/base/limits.h"
#include "media/base/video_frame.h"
-#if defined(OS_CHROMEOS)
+#if defined(OS_CHROMEOS) && defined(USE_X11)
-#if defined(ARCH_CPU_ARMEL) && defined(USE_X11)
+#if defined(ARCH_CPU_ARMEL)
#include "content/common/gpu/media/v4l2_video_encode_accelerator.h"
#elif defined(ARCH_CPU_X86_FAMILY)
#include "content/common/gpu/media/vaapi_video_encode_accelerator.h"
+#include "ui/gfx/x/x11_types.h"
#endif
#elif defined(OS_ANDROID) && defined(ENABLE_WEBRTC)
@@ -190,15 +191,15 @@ GpuVideoEncodeAccelerator::ConvertMediaToGpuProfiles(const std::vector<
scoped_ptr<media::VideoEncodeAccelerator>
GpuVideoEncodeAccelerator::CreateEncoder() {
scoped_ptr<media::VideoEncodeAccelerator> encoder;
-#if defined(OS_CHROMEOS)
-#if defined(ARCH_CPU_ARMEL) && defined(USE_X11)
+#if defined(OS_CHROMEOS) && defined(USE_X11)
+#if defined(ARCH_CPU_ARMEL)
scoped_ptr<V4L2Device> device = V4L2Device::Create(V4L2Device::kEncoder);
if (device)
encoder.reset(new V4L2VideoEncodeAccelerator(device.Pass()));
#elif defined(ARCH_CPU_X86_FAMILY)
const base::CommandLine* cmd_line = base::CommandLine::ForCurrentProcess();
if (!cmd_line->HasSwitch(switches::kDisableVaapiAcceleratedVideoEncode))
- encoder.reset(new VaapiVideoEncodeAccelerator());
+ encoder.reset(new VaapiVideoEncodeAccelerator(gfx::GetXDisplay()));
#endif
#elif defined(OS_ANDROID) && defined(ENABLE_WEBRTC)
encoder.reset(new AndroidVideoEncodeAccelerator());
diff --git a/content/common/gpu/media/rendering_helper.cc b/content/common/gpu/media/rendering_helper.cc
index 4e9b60c..fcd0307 100644
--- a/content/common/gpu/media/rendering_helper.cc
+++ b/content/common/gpu/media/rendering_helper.cc
@@ -19,6 +19,8 @@
#include "ui/gl/gl_context.h"
#include "ui/gl/gl_implementation.h"
#include "ui/gl/gl_surface.h"
+#include "ui/gl/gl_surface_egl.h"
+#include "ui/gl/gl_surface_glx.h"
#if defined(OS_WIN)
#include <windows.h>
@@ -28,11 +30,9 @@
#include "ui/gfx/x/x11_types.h"
#endif
-#if defined(ARCH_CPU_X86_FAMILY) && defined(USE_X11)
-#include "ui/gl/gl_surface_glx.h"
+#if !defined(OS_WIN) && defined(ARCH_CPU_X86_FAMILY)
#define GL_VARIANT_GLX 1
#else
-#include "ui/gl/gl_surface_egl.h"
#define GL_VARIANT_EGL 1
#endif
@@ -127,14 +127,16 @@ void RenderingHelper::Initialize(const RenderingHelperParams& params,
message_loop_ = base::MessageLoop::current();
#if defined(OS_WIN)
+ screen_size_ =
+ gfx::Size(GetSystemMetrics(SM_CXSCREEN), GetSystemMetrics(SM_CYSCREEN));
window_ = CreateWindowEx(0,
L"Static",
L"VideoDecodeAcceleratorTest",
WS_OVERLAPPEDWINDOW | WS_VISIBLE,
0,
0,
- GetSystemMetrics(SM_CXSCREEN),
- GetSystemMetrics(SM_CYSCREEN),
+ screen_size_.width(),
+ screen_size_.height(),
NULL,
NULL,
NULL,
@@ -142,6 +144,7 @@ void RenderingHelper::Initialize(const RenderingHelperParams& params,
#elif defined(USE_X11)
Display* display = gfx::GetXDisplay();
Screen* screen = DefaultScreenOfDisplay(display);
+ screen_size_ = gfx::Size(XWidthOfScreen(screen), XHeightOfScreen(screen));
CHECK(display);
@@ -156,8 +159,8 @@ void RenderingHelper::Initialize(const RenderingHelperParams& params,
DefaultRootWindow(display),
0,
0,
- XWidthOfScreen(screen),
- XHeightOfScreen(screen),
+ screen_size_.width(),
+ screen_size_.height(),
0 /* border width */,
depth,
CopyFromParent /* class */,
@@ -173,11 +176,9 @@ void RenderingHelper::Initialize(const RenderingHelperParams& params,
CHECK(window_ != gfx::kNullAcceleratedWidget);
gl_surface_ = gfx::GLSurface::CreateViewGLSurface(window_);
- screen_size_ = gl_surface_->GetSize();
-
gl_context_ = gfx::GLContext::CreateGLContext(
NULL, gl_surface_.get(), gfx::PreferIntegratedGpu);
- CHECK(gl_context_->MakeCurrent(gl_surface_.get()));
+ gl_context_->MakeCurrent(gl_surface_.get());
CHECK_GT(params.window_sizes.size(), 0U);
videos_.resize(params.window_sizes.size());
@@ -303,16 +304,14 @@ void RenderingHelper::Initialize(const RenderingHelperParams& params,
glEnableVertexAttribArray(tc_location);
glVertexAttribPointer(tc_location, 2, GL_FLOAT, GL_FALSE, 0, kTextureCoords);
- if (frame_duration_ != base::TimeDelta()) {
- int warm_up_iterations = params.warm_up_iterations;
- WarmUpRendering(warm_up_iterations);
- }
+ if (frame_duration_ != base::TimeDelta())
+ WarmUpRendering(params.warm_up_iterations);
// It's safe to use Unretained here since |rendering_thread_| will be stopped
// in VideoDecodeAcceleratorTest.TearDown(), while the |rendering_helper_| is
// a member of that class. (See video_decode_accelerator_unittest.cc.)
gfx::VSyncProvider* vsync_provider = gl_surface_->GetVSyncProvider();
- if (vsync_provider && frame_duration_ != base::TimeDelta())
+ if (vsync_provider)
vsync_provider->GetVSyncParameters(base::Bind(
&RenderingHelper::UpdateVSyncParameters, base::Unretained(this), done));
else
@@ -324,7 +323,7 @@ void RenderingHelper::Initialize(const RenderingHelperParams& params,
// several frames here to warm up the rendering.
void RenderingHelper::WarmUpRendering(int warm_up_iterations) {
unsigned int texture_id;
- scoped_ptr<GLubyte[]> emptyData(new GLubyte[screen_size_.GetArea() * 2]());
+ scoped_ptr<GLubyte[]> emptyData(new GLubyte[screen_size_.GetArea() * 2]);
glGenTextures(1, &texture_id);
glBindTexture(GL_TEXTURE_2D, texture_id);
glTexImage2D(GL_TEXTURE_2D,
@@ -468,11 +467,7 @@ void RenderingHelper::DeleteTexture(uint32 texture_id) {
CHECK_EQ(static_cast<int>(glGetError()), GL_NO_ERROR);
}
-scoped_refptr<gfx::GLContext> RenderingHelper::GetGLContext() {
- return gl_context_;
-}
-
-void* RenderingHelper::GetGLContextHandle() {
+void* RenderingHelper::GetGLContext() {
return gl_context_->GetHandle();
}
@@ -494,7 +489,7 @@ void RenderingHelper::Clear() {
#if defined(OS_WIN)
if (window_)
DestroyWindow(window_);
-#elif defined(USE_X11)
+#else
// Destroy resources acquired in Initialize, in reverse-acquisition order.
if (window_) {
CHECK(XUnmapWindow(gfx::GetXDisplay(), window_));
diff --git a/content/common/gpu/media/rendering_helper.h b/content/common/gpu/media/rendering_helper.h
index e013fa7..e66c8d5 100644
--- a/content/common/gpu/media/rendering_helper.h
+++ b/content/common/gpu/media/rendering_helper.h
@@ -114,11 +114,8 @@ class RenderingHelper {
// Get the platform specific handle to the OpenGL display.
void* GetGLDisplay();
- // Get the GL context.
- scoped_refptr<gfx::GLContext> GetGLContext();
-
// Get the platform specific handle to the OpenGL context.
- void* GetGLContextHandle();
+ void* GetGLContext();
// Get rendered thumbnails as RGB.
// Sets alpha_solid to true if the alpha channel is entirely 0xff.
diff --git a/content/common/gpu/media/va.sigs b/content/common/gpu/media/va.sigs
index ffcf7b3..9906f9f 100644
--- a/content/common/gpu/media/va.sigs
+++ b/content/common/gpu/media/va.sigs
@@ -31,3 +31,10 @@ VAStatus vaSetDisplayAttributes(VADisplay dpy, VADisplayAttribute *attr_list, in
VAStatus vaSyncSurface(VADisplay dpy, VASurfaceID render_target);
VAStatus vaTerminate(VADisplay dpy);
VAStatus vaUnmapBuffer(VADisplay dpy, VABufferID buf_id);
+
+
+//------------------------------------------------
+// Functions from libva-x11 used in chromium code.
+//------------------------------------------------
+VADisplay vaGetDisplay(Display *dpy);
+VAStatus vaPutSurface(VADisplay dpy, VASurfaceID surface, Drawable draw, short srcx, short srcy, unsigned short srcw, unsigned short srch, short destx, short desty, unsigned short destw, unsigned short desth, VARectangle *cliprects, unsigned int number_cliprects, unsigned int flags);
diff --git a/content/common/gpu/media/va_surface.h b/content/common/gpu/media/va_surface.h
index 5934bc5..88dfc2a 100644
--- a/content/common/gpu/media/va_surface.h
+++ b/content/common/gpu/media/va_surface.h
@@ -8,11 +8,7 @@
#ifndef CONTENT_COMMON_GPU_MEDIA_VA_SURFACE_H_
#define CONTENT_COMMON_GPU_MEDIA_VA_SURFACE_H_
-#include "base/callback.h"
-#include "base/memory/ref_counted.h"
-#include "content/common/content_export.h"
#include "third_party/libva/va/va.h"
-#include "ui/gfx/size.h"
namespace content {
@@ -20,7 +16,7 @@ namespace content {
// and use as reference for decoding other surfaces. It is also handed by the
// decoder to VaapiVideoDecodeAccelerator when the contents of the surface are
// ready and should be displayed. VAVDA converts the surface contents into an
-// X/Drm Pixmap bound to a texture for display and releases its reference to it.
+// X Pixmap bound to a texture for display and releases its reference to it.
// Decoder releases its references to the surface when it's done decoding and
// using it as reference. Note that a surface may still be used for reference
// after it's been sent to output and also after it is no longer used by VAVDA.
@@ -60,11 +56,11 @@ namespace content {
// | VASurface to VaapiVideoDecodeAccelerator, VASurface as reference for
// | which stores it (taking a ref) on decoding more frames.
// | pending_output_cbs_ queue until an output |
-// | VaapiPicture becomes available. v
+// | TFPPicture becomes available. v
// | | Once the DecodeSurface is not
// | | needed as reference anymore,
// | v it is released, releasing the
-// | A VaapiPicture becomes available after associated VASurface reference.
+// | A TFPPicture becomes available after associated VASurface reference.
// | the client of VVDA returns |
// | a PictureBuffer associated with it. VVDA |
// | puts the contents of the VASurface into |
@@ -88,22 +84,17 @@ class CONTENT_EXPORT VASurface : public base::RefCountedThreadSafe<VASurface> {
// are released.
typedef base::Callback<void(VASurfaceID)> ReleaseCB;
- VASurface(VASurfaceID va_surface_id,
- const gfx::Size& size,
- const ReleaseCB& release_cb);
+ VASurface(VASurfaceID va_surface_id, const ReleaseCB& release_cb);
VASurfaceID id() {
return va_surface_id_;
}
- const gfx::Size& size() const { return size_; }
-
private:
friend class base::RefCountedThreadSafe<VASurface>;
~VASurface();
const VASurfaceID va_surface_id_;
- gfx::Size size_;
ReleaseCB release_cb_;
DISALLOW_COPY_AND_ASSIGN(VASurface);
diff --git a/content/common/gpu/media/va_x11.sigs b/content/common/gpu/media/va_x11.sigs
deleted file mode 100644
index d87356b..0000000
--- a/content/common/gpu/media/va_x11.sigs
+++ /dev/null
@@ -1,9 +0,0 @@
-// 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.
-
-//------------------------------------------------
-// Functions from libva-x11 used in chromium code.
-//------------------------------------------------
-VADisplay vaGetDisplay(Display *dpy);
-VAStatus vaPutSurface(VADisplay dpy, VASurfaceID surface, Drawable draw, short srcx, short srcy, unsigned short srcw, unsigned short srch, short destx, short desty, unsigned short destw, unsigned short desth, VARectangle *cliprects, unsigned int number_cliprects, unsigned int flags);
diff --git a/content/common/gpu/media/vaapi_h264_decoder_unittest.cc b/content/common/gpu/media/vaapi_h264_decoder_unittest.cc
index 244c9ac..becfd42 100644
--- a/content/common/gpu/media/vaapi_h264_decoder_unittest.cc
+++ b/content/common/gpu/media/vaapi_h264_decoder_unittest.cc
@@ -81,25 +81,35 @@ class VaapiH264DecoderLoop {
// Use the data in the frame: write to file and update MD5 sum.
bool ProcessVideoFrame(const scoped_refptr<media::VideoFrame>& frame);
- scoped_refptr<VaapiWrapper> wrapper_;
+ scoped_ptr<VaapiWrapper> wrapper_;
scoped_ptr<VaapiH264Decoder> decoder_;
std::string data_; // data read from input_file
base::FilePath output_file_; // output data is written to this file
std::vector<VASurfaceID> available_surfaces_;
- // These members (num_outputted_pictures_, num_surfaces_)
+ // These members (x_display_, num_outputted_pictures_, num_surfaces_)
// need to be initialized and possibly freed manually.
+ Display* x_display_;
int num_outputted_pictures_; // number of pictures already outputted
size_t num_surfaces_; // number of surfaces in the current set of surfaces
base::MD5Context md5_context_;
};
VaapiH264DecoderLoop::VaapiH264DecoderLoop()
- : num_outputted_pictures_(0), num_surfaces_(0) {
+ : x_display_(NULL), num_outputted_pictures_(0), num_surfaces_(0) {
base::MD5Init(&md5_context_);
}
VaapiH264DecoderLoop::~VaapiH264DecoderLoop() {
+ // We need to destruct decoder and wrapper first because:
+ // (1) The decoder has a reference to the wrapper.
+ // (2) The wrapper has a reference to x_display_.
+ decoder_.reset();
+ wrapper_.reset();
+
+ if (x_display_) {
+ XCloseDisplay(x_display_);
+ }
}
void LogOnError(VaapiH264Decoder::VAVDAH264DecoderFailure error) {
@@ -108,11 +118,17 @@ void LogOnError(VaapiH264Decoder::VAVDAH264DecoderFailure error) {
bool VaapiH264DecoderLoop::Initialize(base::FilePath input_file,
base::FilePath output_file) {
+ x_display_ = XOpenDisplay(NULL);
+ if (!x_display_) {
+ LOG(ERROR) << "Can't open X display";
+ return false;
+ }
+
media::VideoCodecProfile profile = media::H264PROFILE_BASELINE;
base::Closure report_error_cb =
base::Bind(&LogOnError, VaapiH264Decoder::VAAPI_ERROR);
- wrapper_ =
- VaapiWrapper::Create(VaapiWrapper::kDecode, profile, report_error_cb);
+ wrapper_ = VaapiWrapper::Create(
+ VaapiWrapper::kDecode, profile, x_display_, report_error_cb);
if (!wrapper_.get()) {
LOG(ERROR) << "Can't create vaapi wrapper";
return false;
@@ -280,8 +296,8 @@ void VaapiH264DecoderLoop::RefillSurfaces() {
for (size_t i = 0; i < available_surfaces_.size(); i++) {
VASurface::ReleaseCB release_cb = base::Bind(
&VaapiH264DecoderLoop::RecycleSurface, base::Unretained(this));
- scoped_refptr<VASurface> surface(new VASurface(
- available_surfaces_[i], decoder_->GetPicSize(), release_cb));
+ scoped_refptr<VASurface> surface(
+ new VASurface(available_surfaces_[i], release_cb));
decoder_->ReuseSurface(surface);
}
available_surfaces_.clear();
diff --git a/content/common/gpu/media/vaapi_picture.cc b/content/common/gpu/media/vaapi_picture.cc
deleted file mode 100644
index 10de50b..0000000
--- a/content/common/gpu/media/vaapi_picture.cc
+++ /dev/null
@@ -1,40 +0,0 @@
-// 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 "content/common/gpu/media/vaapi_picture.h"
-#include "content/common/gpu/media/vaapi_wrapper.h"
-#include "ui/gl/gl_bindings.h"
-#include "ui/gl/gl_implementation.h"
-
-#if defined(USE_X11)
-#include "content/common/gpu/media/vaapi_tfp_picture.h"
-#endif
-
-namespace content {
-
-// static
-linked_ptr<VaapiPicture> VaapiPicture::CreatePicture(
- const scoped_refptr<VaapiWrapper>& vaapi_wrapper,
- const base::Callback<bool(void)> make_context_current,
- int32 picture_buffer_id,
- uint32 texture_id,
- const gfx::Size& size) {
- linked_ptr<VaapiPicture> picture;
-#if defined(USE_X11)
- picture.reset(new VaapiTFPPicture(vaapi_wrapper, make_context_current,
- picture_buffer_id, texture_id, size));
-#endif // USE_X11
-
- if (picture.get() && !picture->Initialize())
- picture.reset();
-
- return picture;
-}
-
-// static
-uint32 VaapiPicture::GetGLTextureTarget() {
- return GL_TEXTURE_2D;
-}
-
-} // namespace content
diff --git a/content/common/gpu/media/vaapi_picture.h b/content/common/gpu/media/vaapi_picture.h
deleted file mode 100644
index fdb7a7e..0000000
--- a/content/common/gpu/media/vaapi_picture.h
+++ /dev/null
@@ -1,73 +0,0 @@
-// 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.
-//
-// This file contains an interface of output pictures for the Vaapi
-// video decoder. This is implemented by different window system
-// (X11/Ozone) and used by VaapiVideoDecodeAccelerator to produce
-// output pictures.
-
-#ifndef CONTENT_COMMON_GPU_MEDIA_VAAPI_PICTURE_H_
-#define CONTENT_COMMON_GPU_MEDIA_VAAPI_PICTURE_H_
-
-#include "base/callback.h"
-#include "base/memory/linked_ptr.h"
-#include "base/memory/ref_counted.h"
-#include "base/threading/non_thread_safe.h"
-#include "ui/gfx/size.h"
-
-namespace content {
-
-class VASurface;
-class VaapiWrapper;
-
-// Picture is native pixmap abstraction (X11/Ozone).
-class VaapiPicture : public base::NonThreadSafe {
- public:
- virtual ~VaapiPicture() {}
-
- // Try to allocate the underlying resources for the picture.
- virtual bool Initialize() = 0;
-
- int32 picture_buffer_id() const { return picture_buffer_id_; }
- uint32 texture_id() const { return texture_id_; }
- const gfx::Size& size() const { return size_; }
-
- // Downloads the |va_surface| into the picture, potentially scaling
- // it if needed.
- virtual bool DownloadFromSurface(
- const scoped_refptr<VASurface>& va_surface) = 0;
-
- // Create a VaapiPicture of |size| to be associated with
- // |picture_buffer_id| and bound to |texture_id|.
- // |make_context_current| is provided for the GL operations.
- static linked_ptr<VaapiPicture> CreatePicture(
- const scoped_refptr<VaapiWrapper>& vaapi_wrapper,
- const base::Callback<bool(void)> make_context_current,
- int32 picture_buffer_id,
- uint32 texture_id,
- const gfx::Size& size);
-
- // Get the texture target used to bind EGLImages (either
- // GL_TEXTURE_2D on X11 or GL_TEXTURE_EXTERNAL_OES on DRM).
- static uint32 GetGLTextureTarget();
-
- protected:
- VaapiPicture(int32 picture_buffer_id,
- uint32 texture_id,
- const gfx::Size& size)
- : picture_buffer_id_(picture_buffer_id),
- texture_id_(texture_id),
- size_(size) {}
-
- private:
- int32 picture_buffer_id_;
- uint32 texture_id_;
- gfx::Size size_;
-
- DISALLOW_COPY_AND_ASSIGN(VaapiPicture);
-};
-
-} // namespace content
-
-#endif // CONTENT_COMMON_GPU_MEDIA_VAAPI_PICTURE_H_
diff --git a/content/common/gpu/media/vaapi_tfp_picture.cc b/content/common/gpu/media/vaapi_tfp_picture.cc
deleted file mode 100644
index e914418..0000000
--- a/content/common/gpu/media/vaapi_tfp_picture.cc
+++ /dev/null
@@ -1,77 +0,0 @@
-// 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 "content/common/gpu/media/va_surface.h"
-#include "content/common/gpu/media/vaapi_tfp_picture.h"
-#include "content/common/gpu/media/vaapi_wrapper.h"
-#include "ui/gfx/x/x11_types.h"
-#include "ui/gl/gl_bindings.h"
-#include "ui/gl/gl_image_glx.h"
-#include "ui/gl/scoped_binders.h"
-
-namespace content {
-
-VaapiTFPPicture::VaapiTFPPicture(
- const scoped_refptr<VaapiWrapper>& vaapi_wrapper,
- const base::Callback<bool(void)> make_context_current,
- 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),
- x_display_(gfx::GetXDisplay()),
- x_pixmap_(0) {
-}
-
-VaapiTFPPicture::~VaapiTFPPicture() {
- if (glx_image_.get() && make_context_current_.Run()) {
- glx_image_->ReleaseTexImage(GL_TEXTURE_2D);
- glx_image_->Destroy(true);
- DCHECK_EQ(glGetError(), static_cast<GLenum>(GL_NO_ERROR));
- }
-
- if (x_pixmap_)
- XFreePixmap(x_display_, x_pixmap_);
-}
-
-bool VaapiTFPPicture::Initialize() {
- if (!make_context_current_.Run())
- return false;
-
- XWindowAttributes win_attr;
- int screen = DefaultScreen(x_display_);
- XGetWindowAttributes(x_display_, RootWindow(x_display_, screen), &win_attr);
- // TODO(posciak): pass the depth required by libva, not the RootWindow's
- // depth
- x_pixmap_ = XCreatePixmap(x_display_, RootWindow(x_display_, screen),
- size().width(), size().height(), win_attr.depth);
- if (!x_pixmap_) {
- LOG(ERROR) << "Failed creating an X Pixmap for TFP";
- return false;
- }
-
- glx_image_ = new gfx::GLImageGLX(size(), GL_RGB);
- if (!glx_image_->Initialize(x_pixmap_)) {
- // x_pixmap_ will be freed in the destructor.
- LOG(ERROR) << "Failed creating a GLX Pixmap for TFP";
- return false;
- }
-
- gfx::ScopedTextureBinder texture_binder(GL_TEXTURE_2D, texture_id());
- if (!glx_image_->BindTexImage(GL_TEXTURE_2D)) {
- LOG(ERROR) << "Failed to bind texture to glx image";
- return false;
- }
-
- return true;
-}
-
-bool VaapiTFPPicture::DownloadFromSurface(
- const scoped_refptr<VASurface>& va_surface) {
- return vaapi_wrapper_->PutSurfaceIntoPixmap(va_surface->id(), x_pixmap_,
- va_surface->size());
-}
-
-} // namespace content
diff --git a/content/common/gpu/media/vaapi_tfp_picture.h b/content/common/gpu/media/vaapi_tfp_picture.h
deleted file mode 100644
index a3208da..0000000
--- a/content/common/gpu/media/vaapi_tfp_picture.h
+++ /dev/null
@@ -1,56 +0,0 @@
-// 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.
-//
-// This file contains an implementation of picture allocation for the
-// X11 window system used by VaapiVideoDecodeAccelerator to produce
-// output pictures.
-
-#ifndef CONTENT_COMMON_GPU_MEDIA_VAAPI_TFP_PICTURE_H_
-#define CONTENT_COMMON_GPU_MEDIA_VAAPI_TFP_PICTURE_H_
-
-#include "base/callback.h"
-#include "base/memory/ref_counted.h"
-#include "content/common/gpu/media/vaapi_picture.h"
-#include "ui/gfx/size.h"
-#include "ui/gl/gl_bindings.h"
-
-namespace gfx {
-class GLImageGLX;
-class GLContextGLX;
-}
-
-namespace content {
-
-class VaapiWrapper;
-
-// Implementation of VaapiPicture for the X11 backed chromium.
-class VaapiTFPPicture : public VaapiPicture {
- public:
- VaapiTFPPicture(const scoped_refptr<VaapiWrapper>& vaapi_wrapper,
- const base::Callback<bool(void)> make_context_current,
- int32 picture_buffer_id,
- uint32 texture_id,
- const gfx::Size& size);
-
- ~VaapiTFPPicture() override;
-
- bool Initialize() override;
-
- bool DownloadFromSurface(const scoped_refptr<VASurface>& va_surface) override;
-
- private:
- scoped_refptr<VaapiWrapper> vaapi_wrapper_;
-
- base::Callback<bool(void)> make_context_current_;
- Display* x_display_;
-
- Pixmap x_pixmap_;
- scoped_refptr<gfx::GLImageGLX> glx_image_;
-
- DISALLOW_COPY_AND_ASSIGN(VaapiTFPPicture);
-};
-
-} // namespace content
-
-#endif // CONTENT_COMMON_GPU_MEDIA_VAAPI_TFP_PICTURE_H_
diff --git a/content/common/gpu/media/vaapi_video_decode_accelerator.cc b/content/common/gpu/media/vaapi_video_decode_accelerator.cc
index df9ec59..df1f644 100644
--- a/content/common/gpu/media/vaapi_video_decode_accelerator.cc
+++ b/content/common/gpu/media/vaapi_video_decode_accelerator.cc
@@ -9,12 +9,13 @@
#include "base/stl_util.h"
#include "base/strings/string_util.h"
#include "base/synchronization/waitable_event.h"
+#include "base/threading/non_thread_safe.h"
#include "content/common/gpu/gpu_channel.h"
-#include "content/common/gpu/media/vaapi_picture.h"
#include "content/common/gpu/media/vaapi_video_decode_accelerator.h"
#include "media/base/bind_to_current_loop.h"
#include "media/video/picture.h"
#include "ui/gl/gl_bindings.h"
+#include "ui/gl/scoped_binders.h"
static void ReportToUMA(
content::VaapiH264Decoder::VAVDAH264DecoderFailure failure) {
@@ -60,10 +61,164 @@ void VaapiVideoDecodeAccelerator::NotifyError(Error error) {
}
}
-VaapiPicture* VaapiVideoDecodeAccelerator::PictureById(
- int32 picture_buffer_id) {
- Pictures::iterator it = pictures_.find(picture_buffer_id);
- if (it == pictures_.end()) {
+// TFPPicture allocates X Pixmaps and binds them to textures passed
+// in PictureBuffers from clients to them. TFPPictures are created as
+// a consequence of receiving a set of PictureBuffers from clients and released
+// at the end of decode (or when a new set of PictureBuffers is required).
+//
+// TFPPictures are used for output, contents of VASurfaces passed from decoder
+// are put into the associated pixmap memory and sent to client.
+class VaapiVideoDecodeAccelerator::TFPPicture : public base::NonThreadSafe {
+ public:
+ ~TFPPicture();
+
+ static linked_ptr<TFPPicture> Create(
+ const base::Callback<bool(void)>& make_context_current,
+ const GLXFBConfig& fb_config,
+ Display* x_display,
+ int32 picture_buffer_id,
+ uint32 texture_id,
+ gfx::Size size);
+
+ int32 picture_buffer_id() {
+ return picture_buffer_id_;
+ }
+
+ gfx::Size size() {
+ return size_;
+ }
+
+ int x_pixmap() {
+ return x_pixmap_;
+ }
+
+ // Bind texture to pixmap. Needs to be called every frame.
+ bool Bind();
+
+ private:
+ TFPPicture(const base::Callback<bool(void)>& make_context_current,
+ Display* x_display,
+ int32 picture_buffer_id,
+ uint32 texture_id,
+ gfx::Size size);
+
+ bool Initialize(const GLXFBConfig& fb_config);
+
+ base::Callback<bool(void)> make_context_current_;
+
+ Display* x_display_;
+
+ // Output id for the client.
+ int32 picture_buffer_id_;
+ uint32 texture_id_;
+
+ gfx::Size size_;
+
+ // Pixmaps bound to this texture.
+ Pixmap x_pixmap_;
+ GLXPixmap glx_pixmap_;
+
+ DISALLOW_COPY_AND_ASSIGN(TFPPicture);
+};
+
+VaapiVideoDecodeAccelerator::TFPPicture::TFPPicture(
+ const base::Callback<bool(void)>& make_context_current,
+ Display* x_display,
+ int32 picture_buffer_id,
+ uint32 texture_id,
+ gfx::Size size)
+ : make_context_current_(make_context_current),
+ x_display_(x_display),
+ picture_buffer_id_(picture_buffer_id),
+ texture_id_(texture_id),
+ size_(size),
+ x_pixmap_(0),
+ glx_pixmap_(0) {
+ DCHECK(!make_context_current_.is_null());
+};
+
+linked_ptr<VaapiVideoDecodeAccelerator::TFPPicture>
+VaapiVideoDecodeAccelerator::TFPPicture::Create(
+ const base::Callback<bool(void)>& make_context_current,
+ const GLXFBConfig& fb_config,
+ Display* x_display,
+ int32 picture_buffer_id,
+ uint32 texture_id,
+ gfx::Size size) {
+
+ linked_ptr<TFPPicture> tfp_picture(
+ new TFPPicture(make_context_current, x_display, picture_buffer_id,
+ texture_id, size));
+
+ if (!tfp_picture->Initialize(fb_config))
+ tfp_picture.reset();
+
+ return tfp_picture;
+}
+
+bool VaapiVideoDecodeAccelerator::TFPPicture::Initialize(
+ const GLXFBConfig& fb_config) {
+ DCHECK(CalledOnValidThread());
+ if (!make_context_current_.Run())
+ return false;
+
+ XWindowAttributes win_attr;
+ int screen = DefaultScreen(x_display_);
+ XGetWindowAttributes(x_display_, RootWindow(x_display_, screen), &win_attr);
+ //TODO(posciak): pass the depth required by libva, not the RootWindow's depth
+ x_pixmap_ = XCreatePixmap(x_display_, RootWindow(x_display_, screen),
+ size_.width(), size_.height(), win_attr.depth);
+ if (!x_pixmap_) {
+ LOG(ERROR) << "Failed creating an X Pixmap for TFP";
+ return false;
+ }
+
+ static const int pixmap_attr[] = {
+ GLX_TEXTURE_TARGET_EXT, GLX_TEXTURE_2D_EXT,
+ GLX_TEXTURE_FORMAT_EXT, GLX_TEXTURE_FORMAT_RGB_EXT,
+ GL_NONE,
+ };
+
+ glx_pixmap_ = glXCreatePixmap(x_display_, fb_config, x_pixmap_, pixmap_attr);
+ if (!glx_pixmap_) {
+ // x_pixmap_ will be freed in the destructor.
+ LOG(ERROR) << "Failed creating a GLX Pixmap for TFP";
+ return false;
+ }
+
+ return true;
+}
+
+VaapiVideoDecodeAccelerator::TFPPicture::~TFPPicture() {
+ DCHECK(CalledOnValidThread());
+ // Unbind surface from texture and deallocate resources.
+ if (glx_pixmap_ && make_context_current_.Run()) {
+ glXReleaseTexImageEXT(x_display_, glx_pixmap_, GLX_FRONT_LEFT_EXT);
+ glXDestroyPixmap(x_display_, glx_pixmap_);
+ }
+
+ if (x_pixmap_)
+ XFreePixmap(x_display_, x_pixmap_);
+ XSync(x_display_, False); // Needed to work around buggy vdpau-driver.
+}
+
+bool VaapiVideoDecodeAccelerator::TFPPicture::Bind() {
+ DCHECK(CalledOnValidThread());
+ DCHECK(x_pixmap_);
+ DCHECK(glx_pixmap_);
+ if (!make_context_current_.Run())
+ return false;
+
+ gfx::ScopedTextureBinder texture_binder(GL_TEXTURE_2D, texture_id_);
+ glXBindTexImageEXT(x_display_, glx_pixmap_, GLX_FRONT_LEFT_EXT, NULL);
+
+ return true;
+}
+
+VaapiVideoDecodeAccelerator::TFPPicture*
+ VaapiVideoDecodeAccelerator::TFPPictureById(int32 picture_buffer_id) {
+ TFPPictures::iterator it = tfp_pictures_.find(picture_buffer_id);
+ if (it == tfp_pictures_.end()) {
LOG(ERROR) << "Picture id " << picture_buffer_id << " does not exist";
return NULL;
}
@@ -72,8 +227,10 @@ VaapiPicture* VaapiVideoDecodeAccelerator::PictureById(
}
VaapiVideoDecodeAccelerator::VaapiVideoDecodeAccelerator(
+ Display* x_display,
const base::Callback<bool(void)>& make_context_current)
- : make_context_current_(make_context_current),
+ : x_display_(x_display),
+ make_context_current_(make_context_current),
state_(kUninitialized),
input_ready_(&lock_),
surfaces_available_(&lock_),
@@ -94,6 +251,35 @@ VaapiVideoDecodeAccelerator::~VaapiVideoDecodeAccelerator() {
DCHECK_EQ(message_loop_, base::MessageLoop::current());
}
+class XFreeDeleter {
+ public:
+ void operator()(void* x) const {
+ ::XFree(x);
+ }
+};
+
+bool VaapiVideoDecodeAccelerator::InitializeFBConfig() {
+ const int fbconfig_attr[] = {
+ GLX_DRAWABLE_TYPE, GLX_PIXMAP_BIT,
+ GLX_BIND_TO_TEXTURE_TARGETS_EXT, GLX_TEXTURE_2D_BIT_EXT,
+ GLX_BIND_TO_TEXTURE_RGB_EXT, GL_TRUE,
+ GLX_Y_INVERTED_EXT, GL_TRUE,
+ GL_NONE,
+ };
+
+ int num_fbconfigs;
+ scoped_ptr<GLXFBConfig, XFreeDeleter> glx_fb_configs(
+ glXChooseFBConfig(x_display_, DefaultScreen(x_display_), fbconfig_attr,
+ &num_fbconfigs));
+ if (!glx_fb_configs)
+ return false;
+ if (!num_fbconfigs)
+ return false;
+
+ fb_config_ = glx_fb_configs.get()[0];
+ return true;
+}
+
bool VaapiVideoDecodeAccelerator::Initialize(media::VideoCodecProfile profile,
Client* client) {
DCHECK_EQ(message_loop_, base::MessageLoop::current());
@@ -105,17 +291,18 @@ bool VaapiVideoDecodeAccelerator::Initialize(media::VideoCodecProfile profile,
DCHECK_EQ(state_, kUninitialized);
DVLOG(2) << "Initializing VAVDA, profile: " << profile;
-#if defined(USE_X11)
- if (gfx::GetGLImplementation() != gfx::kGLImplementationDesktopGL) {
- DVLOG(1) << "HW video decode acceleration not available without "
- "DesktopGL (GLX).";
+ if (!make_context_current_.Run())
+ return false;
+
+ if (!InitializeFBConfig()) {
+ LOG(ERROR) << "Could not get a usable FBConfig";
return false;
}
-#endif // USE_X11
vaapi_wrapper_ = VaapiWrapper::Create(
VaapiWrapper::kDecode,
profile,
+ x_display_,
base::Bind(&ReportToUMA, content::VaapiH264Decoder::VAAPI_ERROR));
if (!vaapi_wrapper_.get()) {
@@ -157,10 +344,10 @@ void VaapiVideoDecodeAccelerator::SurfaceReady(
void VaapiVideoDecodeAccelerator::OutputPicture(
const scoped_refptr<VASurface>& va_surface,
int32 input_id,
- VaapiPicture* picture) {
+ TFPPicture* tfp_picture) {
DCHECK_EQ(message_loop_, base::MessageLoop::current());
- int32 output_id = picture->picture_buffer_id();
+ int32 output_id = tfp_picture->picture_buffer_id();
TRACE_EVENT2("Video Decoder", "VAVDA::OutputSurface",
"input_id", input_id,
@@ -169,10 +356,16 @@ void VaapiVideoDecodeAccelerator::OutputPicture(
DVLOG(3) << "Outputting VASurface " << va_surface->id()
<< " into pixmap bound to picture buffer id " << output_id;
- RETURN_AND_NOTIFY_ON_FAILURE(picture->DownloadFromSurface(va_surface),
- "Failed putting surface into pixmap",
+ RETURN_AND_NOTIFY_ON_FAILURE(tfp_picture->Bind(),
+ "Failed binding texture to pixmap",
PLATFORM_FAILURE, );
+ RETURN_AND_NOTIFY_ON_FAILURE(
+ vaapi_wrapper_->PutSurfaceIntoPixmap(va_surface->id(),
+ tfp_picture->x_pixmap(),
+ tfp_picture->size()),
+ "Failed putting surface into pixmap", PLATFORM_FAILURE, );
+
// Notify the client a picture is ready to be displayed.
++num_frames_at_client_;
TRACE_COUNTER1("Video Decoder", "Textures at client", num_frames_at_client_);
@@ -182,7 +375,7 @@ void VaapiVideoDecodeAccelerator::OutputPicture(
// (crbug.com/402760).
if (client_)
client_->PictureReady(
- media::Picture(output_id, input_id, gfx::Rect(picture->size())));
+ media::Picture(output_id, input_id, gfx::Rect(tfp_picture->size())));
}
void VaapiVideoDecodeAccelerator::TryOutputSurface() {
@@ -198,11 +391,11 @@ void VaapiVideoDecodeAccelerator::TryOutputSurface() {
OutputCB output_cb = pending_output_cbs_.front();
pending_output_cbs_.pop();
- VaapiPicture* picture = PictureById(output_buffers_.front());
- DCHECK(picture);
+ TFPPicture* tfp_picture = TFPPictureById(output_buffers_.front());
+ DCHECK(tfp_picture);
output_buffers_.pop();
- output_cb.Run(picture);
+ output_cb.Run(tfp_picture);
if (finish_flush_pending_ && pending_output_cbs_.empty())
FinishFlush();
@@ -313,8 +506,7 @@ bool VaapiVideoDecodeAccelerator::FeedDecoderWithOutputSurfaces_Locked() {
while (!available_va_surfaces_.empty()) {
scoped_refptr<VASurface> va_surface(
- new VASurface(available_va_surfaces_.front(), requested_pic_size_,
- va_surface_release_cb_));
+ new VASurface(available_va_surfaces_.front(), va_surface_release_cb_));
available_va_surfaces_.pop_front();
decoder_->ReuseSurface(va_surface);
}
@@ -406,7 +598,7 @@ void VaapiVideoDecodeAccelerator::TryFinishSurfaceSetChange() {
return;
if (!pending_output_cbs_.empty() ||
- pictures_.size() != available_va_surfaces_.size()) {
+ tfp_pictures_.size() != available_va_surfaces_.size()) {
// Either:
// 1. Not all pending pending output callbacks have been executed yet.
// Wait for the client to return enough pictures and retry later.
@@ -424,22 +616,21 @@ void VaapiVideoDecodeAccelerator::TryFinishSurfaceSetChange() {
available_va_surfaces_.clear();
vaapi_wrapper_->DestroySurfaces();
- for (Pictures::iterator iter = pictures_.begin(); iter != pictures_.end();
- ++iter) {
+ for (TFPPictures::iterator iter = tfp_pictures_.begin();
+ iter != tfp_pictures_.end(); ++iter) {
DVLOG(2) << "Dismissing picture id: " << iter->first;
if (client_)
client_->DismissPictureBuffer(iter->first);
}
- pictures_.clear();
+ tfp_pictures_.clear();
// And ask for a new set as requested.
DVLOG(1) << "Requesting " << requested_num_pics_ << " pictures of size: "
<< requested_pic_size_.ToString();
- message_loop_->PostTask(
- FROM_HERE,
- base::Bind(&Client::ProvidePictureBuffers, client_, requested_num_pics_,
- requested_pic_size_, VaapiPicture::GetGLTextureTarget()));
+ message_loop_->PostTask(FROM_HERE, base::Bind(
+ &Client::ProvidePictureBuffers, client_,
+ requested_num_pics_, requested_pic_size_, GL_TEXTURE_2D));
}
void VaapiVideoDecodeAccelerator::Decode(
@@ -491,7 +682,7 @@ void VaapiVideoDecodeAccelerator::AssignPictureBuffers(
DCHECK_EQ(message_loop_, base::MessageLoop::current());
base::AutoLock auto_lock(lock_);
- DCHECK(pictures_.empty());
+ DCHECK(tfp_pictures_.empty());
while (!output_buffers_.empty())
output_buffers_.pop();
@@ -515,16 +706,17 @@ void VaapiVideoDecodeAccelerator::AssignPictureBuffers(
<< " to texture id: " << buffers[i].texture_id()
<< " VASurfaceID: " << va_surface_ids[i];
- linked_ptr<VaapiPicture> picture(VaapiPicture::CreatePicture(
- vaapi_wrapper_, make_context_current_, buffers[i].id(),
- buffers[i].texture_id(), requested_pic_size_));
+ linked_ptr<TFPPicture> tfp_picture(
+ TFPPicture::Create(make_context_current_, fb_config_, x_display_,
+ buffers[i].id(), buffers[i].texture_id(),
+ requested_pic_size_));
RETURN_AND_NOTIFY_ON_FAILURE(
- picture.get(), "Failed assigning picture buffer to a texture.",
+ tfp_picture.get(), "Failed assigning picture buffer to a texture.",
PLATFORM_FAILURE, );
- bool inserted =
- pictures_.insert(std::make_pair(buffers[i].id(), picture)).second;
+ bool inserted = tfp_pictures_.insert(std::make_pair(
+ buffers[i].id(), tfp_picture)).second;
DCHECK(inserted);
output_buffers_.push(buffers[i].id());
diff --git a/content/common/gpu/media/vaapi_video_decode_accelerator.h b/content/common/gpu/media/vaapi_video_decode_accelerator.h
index afd0a1c..5d65da7 100644
--- a/content/common/gpu/media/vaapi_video_decode_accelerator.h
+++ b/content/common/gpu/media/vaapi_video_decode_accelerator.h
@@ -20,6 +20,7 @@
#include "base/message_loop/message_loop.h"
#include "base/synchronization/condition_variable.h"
#include "base/synchronization/lock.h"
+#include "base/threading/non_thread_safe.h"
#include "base/threading/thread.h"
#include "content/common/content_export.h"
#include "content/common/gpu/media/vaapi_h264_decoder.h"
@@ -27,11 +28,10 @@
#include "media/base/bitstream_buffer.h"
#include "media/video/picture.h"
#include "media/video/video_decode_accelerator.h"
+#include "ui/gl/gl_bindings.h"
namespace content {
-class VaapiPicture;
-
// Class to provide video decode acceleration for Intel systems with hardware
// support for it, and on which libva is available.
// Decoding tasks are performed in a separate decoding thread.
@@ -44,6 +44,7 @@ class CONTENT_EXPORT VaapiVideoDecodeAccelerator
: public media::VideoDecodeAccelerator {
public:
VaapiVideoDecodeAccelerator(
+ Display* x_display,
const base::Callback<bool(void)>& make_context_current);
virtual ~VaapiVideoDecodeAccelerator();
@@ -122,13 +123,16 @@ private:
// |va_surface|.
void SurfaceReady(int32 input_id, const scoped_refptr<VASurface>& va_surface);
+ // Represents a texture bound to an X Pixmap for output purposes.
+ class TFPPicture;
+
// Callback to be executed once we have a |va_surface| to be output and
- // an available |picture| to use for output.
- // Puts contents of |va_surface| into given |picture|, releases the
+ // an available |tfp_picture| to use for output.
+ // Puts contents of |va_surface| into given |tfp_picture|, releases the
// surface and passes the resulting picture to client for output.
void OutputPicture(const scoped_refptr<VASurface>& va_surface,
int32 input_id,
- VaapiPicture* picture);
+ TFPPicture* tfp_picture);
// Try to OutputPicture() if we have both a ready surface and picture.
void TryOutputSurface();
@@ -144,8 +148,10 @@ private:
// Check if the surfaces have been released or post ourselves for later.
void TryFinishSurfaceSetChange();
- // Client-provided GL state.
+ // Client-provided X/GLX state.
+ Display* x_display_;
base::Callback<bool(void)> make_context_current_;
+ GLXFBConfig fb_config_;
// VAVDA state.
enum State {
@@ -190,13 +196,13 @@ private:
typedef std::queue<int32> OutputBuffers;
OutputBuffers output_buffers_;
- typedef std::map<int32, linked_ptr<VaapiPicture>> Pictures;
- // All allocated Pictures, regardless of their current state.
- // Pictures are allocated once and destroyed at the end of decode.
- Pictures pictures_;
+ typedef std::map<int32, linked_ptr<TFPPicture> > TFPPictures;
+ // All allocated TFPPictures, regardless of their current state. TFPPictures
+ // are allocated once and destroyed at the end of decode.
+ TFPPictures tfp_pictures_;
// Return a TFPPicture associated with given client-provided id.
- VaapiPicture* PictureById(int32 picture_buffer_id);
+ TFPPicture* TFPPictureById(int32 picture_buffer_id);
// VA Surfaces no longer in use that can be passed back to the decoder for
// reuse, once it requests them.
@@ -206,15 +212,15 @@ private:
base::ConditionVariable surfaces_available_;
// Pending output requests from the decoder. When it indicates that we should
- // output a surface and we have an available Picture (i.e. texture) ready
- // to use, we'll execute the callback passing the Picture. The callback
+ // output a surface and we have an available TFPPicture (i.e. texture) ready
+ // to use, we'll execute the callback passing the TFPPicture. The callback
// will put the contents of the surface into the picture and return it to
// the client, releasing the surface as well.
- // If we don't have any available Pictures at the time when the decoder
+ // If we don't have any available TFPPictures at the time when the decoder
// requests output, we'll store the request on pending_output_cbs_ queue for
// later and run it once the client gives us more textures
// via ReusePictureBuffer().
- typedef base::Callback<void(VaapiPicture*)> OutputCB;
+ typedef base::Callback<void(TFPPicture*)> OutputCB;
std::queue<OutputCB> pending_output_cbs_;
// ChildThread's message loop
@@ -236,7 +242,7 @@ private:
scoped_ptr<base::WeakPtrFactory<Client> > client_ptr_factory_;
base::WeakPtr<Client> client_;
- scoped_refptr<VaapiWrapper> vaapi_wrapper_;
+ scoped_ptr<VaapiWrapper> vaapi_wrapper_;
// Comes after vaapi_wrapper_ to ensure its destructor is executed before
// vaapi_wrapper_ is destroyed.
diff --git a/content/common/gpu/media/vaapi_video_encode_accelerator.cc b/content/common/gpu/media/vaapi_video_encode_accelerator.cc
index fa3a600..19e1c08 100644
--- a/content/common/gpu/media/vaapi_video_encode_accelerator.cc
+++ b/content/common/gpu/media/vaapi_video_encode_accelerator.cc
@@ -113,7 +113,8 @@ VaapiVideoEncodeAccelerator::GetSupportedProfiles() {
return profiles;
std::vector<media::VideoCodecProfile> hw_profiles =
- VaapiWrapper::GetSupportedEncodeProfiles(base::Bind(&base::DoNothing));
+ VaapiWrapper::GetSupportedEncodeProfiles(
+ x_display_, base::Bind(&base::DoNothing));
media::VideoEncodeAccelerator::SupportedProfile profile;
profile.max_resolution.SetSize(1920, 1088);
@@ -138,11 +139,12 @@ static unsigned int Log2OfPowerOf2(unsigned int x) {
return log;
}
-VaapiVideoEncodeAccelerator::VaapiVideoEncodeAccelerator()
+VaapiVideoEncodeAccelerator::VaapiVideoEncodeAccelerator(Display* x_display)
: profile_(media::VIDEO_CODEC_PROFILE_UNKNOWN),
mb_width_(0),
mb_height_(0),
output_buffer_byte_size_(0),
+ x_display_(x_display),
state_(kUninitialized),
frame_num_(0),
last_idr_frame_num_(0),
@@ -215,8 +217,9 @@ bool VaapiVideoEncodeAccelerator::Initialize(
vaapi_wrapper_ = VaapiWrapper::Create(VaapiWrapper::kEncode,
output_profile,
+ x_display_,
base::Bind(&ReportToUMA, VAAPI_ERROR));
- if (!vaapi_wrapper_.get()) {
+ if (!vaapi_wrapper_) {
LOG(ERROR) << "Failed initializing VAAPI";
return false;
}
@@ -601,12 +604,12 @@ bool VaapiVideoEncodeAccelerator::PrepareNextJob() {
return false;
}
- current_encode_job_->input_surface = new VASurface(
- available_va_surface_ids_.back(), coded_size_, va_surface_release_cb_);
+ current_encode_job_->input_surface =
+ new VASurface(available_va_surface_ids_.back(), va_surface_release_cb_);
available_va_surface_ids_.pop_back();
- current_encode_job_->recon_surface = new VASurface(
- available_va_surface_ids_.back(), coded_size_, va_surface_release_cb_);
+ current_encode_job_->recon_surface =
+ new VASurface(available_va_surface_ids_.back(), va_surface_release_cb_);
available_va_surface_ids_.pop_back();
// Reference surfaces are needed until the job is done, but they get
diff --git a/content/common/gpu/media/vaapi_video_encode_accelerator.h b/content/common/gpu/media/vaapi_video_encode_accelerator.h
index a12bb63..520228c 100644
--- a/content/common/gpu/media/vaapi_video_encode_accelerator.h
+++ b/content/common/gpu/media/vaapi_video_encode_accelerator.h
@@ -25,7 +25,7 @@ namespace content {
class CONTENT_EXPORT VaapiVideoEncodeAccelerator
: public media::VideoEncodeAccelerator {
public:
- VaapiVideoEncodeAccelerator();
+ explicit VaapiVideoEncodeAccelerator(Display* x_display);
virtual ~VaapiVideoEncodeAccelerator();
// media::VideoEncodeAccelerator implementation.
@@ -151,7 +151,7 @@ class CONTENT_EXPORT VaapiVideoEncodeAccelerator
// VaapiWrapper is the owner of all HW resources (surfaces and buffers)
// and will free them on destruction.
- scoped_refptr<VaapiWrapper> vaapi_wrapper_;
+ scoped_ptr<VaapiWrapper> vaapi_wrapper_;
// Input profile and sizes.
media::VideoCodecProfile profile_;
@@ -178,6 +178,8 @@ class CONTENT_EXPORT VaapiVideoEncodeAccelerator
// Size in bytes required for input bitstream buffers.
size_t output_buffer_byte_size_;
+ Display* x_display_;
+
// All of the members below must be accessed on the encoder_thread_,
// while it is running.
diff --git a/content/common/gpu/media/vaapi_wrapper.cc b/content/common/gpu/media/vaapi_wrapper.cc
index f554be9..93f1b61 100644
--- a/content/common/gpu/media/vaapi_wrapper.cc
+++ b/content/common/gpu/media/vaapi_wrapper.cc
@@ -13,20 +13,16 @@
#include "base/sys_info.h"
// Auto-generated for dlopen libva libraries
#include "content/common/gpu/media/va_stubs.h"
-#include "content/common/gpu/media/vaapi_picture.h"
#include "third_party/libyuv/include/libyuv.h"
-#include "ui/gl/gl_bindings.h"
-#if defined(USE_X11)
-#include "ui/gfx/x/x11_types.h"
-#endif // USE_X11
using content_common_gpu_media::kModuleVa;
-#if defined(USE_X11)
-using content_common_gpu_media::kModuleVa_x11;
-#endif // USE_X11
using content_common_gpu_media::InitializeStubs;
using content_common_gpu_media::StubPathMap;
+// libva-x11 depends on libva, so dlopen libva-x11 is enough
+static const base::FilePath::CharType kVaLib[] =
+ FILE_PATH_LITERAL("libva-x11.so.1");
+
#define LOG_VA_ERROR_AND_REPORT(va_error, err_msg) \
do { \
LOG(ERROR) << err_msg \
@@ -127,10 +123,9 @@ static VAProfile ProfileToVAProfile(
return va_profile;
}
-VASurface::VASurface(VASurfaceID va_surface_id,
- const gfx::Size& size,
- const ReleaseCB& release_cb)
- : va_surface_id_(va_surface_id), size_(size), release_cb_(release_cb) {
+VASurface::VASurface(VASurfaceID va_surface_id, const ReleaseCB& release_cb)
+ : va_surface_id_(va_surface_id),
+ release_cb_(release_cb) {
DCHECK(!release_cb_.is_null());
}
@@ -152,24 +147,27 @@ VaapiWrapper::~VaapiWrapper() {
Deinitialize();
}
-scoped_refptr<VaapiWrapper> VaapiWrapper::Create(
+scoped_ptr<VaapiWrapper> VaapiWrapper::Create(
CodecMode mode,
media::VideoCodecProfile profile,
+ Display* x_display,
const base::Closure& report_error_to_uma_cb) {
- scoped_refptr<VaapiWrapper> vaapi_wrapper(new VaapiWrapper());
+ scoped_ptr<VaapiWrapper> vaapi_wrapper(new VaapiWrapper());
- if (!vaapi_wrapper->Initialize(mode, profile, report_error_to_uma_cb))
- vaapi_wrapper = NULL;
+ if (!vaapi_wrapper->Initialize(
+ mode, profile, x_display, report_error_to_uma_cb))
+ vaapi_wrapper.reset();
- return vaapi_wrapper;
+ return vaapi_wrapper.Pass();
}
std::vector<media::VideoCodecProfile> VaapiWrapper::GetSupportedEncodeProfiles(
+ Display* x_display,
const base::Closure& report_error_to_uma_cb) {
std::vector<media::VideoCodecProfile> supported_profiles;
- scoped_refptr<VaapiWrapper> wrapper(new VaapiWrapper());
- if (!wrapper->VaInitialize(report_error_to_uma_cb)) {
+ scoped_ptr<VaapiWrapper> wrapper(new VaapiWrapper());
+ if (!wrapper->VaInitialize(x_display, report_error_to_uma_cb)) {
return supported_profiles;
}
@@ -204,7 +202,8 @@ void VaapiWrapper::TryToSetVADisplayAttributeToLocalGPU() {
DVLOG(2) << "vaSetDisplayAttributes unsupported, ignoring by default.";
}
-bool VaapiWrapper::VaInitialize(const base::Closure& report_error_to_uma_cb) {
+bool VaapiWrapper::VaInitialize(Display* x_display,
+ const base::Closure& report_error_to_uma_cb) {
static bool vaapi_functions_initialized = PostSandboxInitialization();
if (!vaapi_functions_initialized) {
bool running_on_chromeos = false;
@@ -225,10 +224,7 @@ bool VaapiWrapper::VaInitialize(const base::Closure& report_error_to_uma_cb) {
base::AutoLock auto_lock(va_lock_);
-#if defined(USE_X11)
- va_display_ = vaGetDisplay(gfx::GetXDisplay());
-#endif // USE_X11
-
+ va_display_ = vaGetDisplay(x_display);
if (!vaDisplayIsValid(va_display_)) {
LOG(ERROR) << "Could not get a valid VA display";
return false;
@@ -325,8 +321,9 @@ bool VaapiWrapper::AreAttribsSupported(
bool VaapiWrapper::Initialize(CodecMode mode,
media::VideoCodecProfile profile,
+ Display* x_display,
const base::Closure& report_error_to_uma_cb) {
- if (!VaInitialize(report_error_to_uma_cb))
+ if (!VaInitialize(x_display, report_error_to_uma_cb))
return false;
std::vector<VAProfile> supported_va_profiles;
if (!GetSupportedVaProfiles(&supported_va_profiles))
@@ -386,7 +383,7 @@ bool VaapiWrapper::VAAPIVersionLessThan(int major, int minor) {
(major_version_ == major && minor_version_ < minor);
}
-bool VaapiWrapper::CreateSurfaces(const gfx::Size& size,
+bool VaapiWrapper::CreateSurfaces(gfx::Size size,
size_t num_surfaces,
std::vector<VASurfaceID>* va_surfaces) {
base::AutoLock auto_lock(va_lock_);
@@ -596,6 +593,25 @@ bool VaapiWrapper::ExecuteAndDestroyPendingBuffers(VASurfaceID va_surface_id) {
return result;
}
+bool VaapiWrapper::PutSurfaceIntoPixmap(VASurfaceID va_surface_id,
+ Pixmap x_pixmap,
+ gfx::Size dest_size) {
+ base::AutoLock auto_lock(va_lock_);
+
+ VAStatus va_res = vaSyncSurface(va_display_, va_surface_id);
+ VA_SUCCESS_OR_RETURN(va_res, "Failed syncing surface", false);
+
+ // Put the data into an X Pixmap.
+ va_res = vaPutSurface(va_display_,
+ va_surface_id,
+ x_pixmap,
+ 0, 0, dest_size.width(), dest_size.height(),
+ 0, 0, dest_size.width(), dest_size.height(),
+ NULL, 0, 0);
+ VA_SUCCESS_OR_RETURN(va_res, "Failed putting surface to pixmap", false);
+ return true;
+}
+
bool VaapiWrapper::GetVaImageForTesting(VASurfaceID va_surface_id,
VAImage* image,
void** mem) {
@@ -736,33 +752,10 @@ bool VaapiWrapper::DownloadAndDestroyCodedBuffer(VABufferID buffer_id,
return buffer_segment == NULL;
}
-#if defined(USE_X11)
-bool VaapiWrapper::PutSurfaceIntoPixmap(VASurfaceID va_surface_id,
- Pixmap x_pixmap,
- gfx::Size dest_size) {
- base::AutoLock auto_lock(va_lock_);
-
- VAStatus va_res = vaSyncSurface(va_display_, va_surface_id);
- VA_SUCCESS_OR_RETURN(va_res, "Failed syncing surface", false);
-
- // Put the data into an X Pixmap.
- va_res = vaPutSurface(va_display_, va_surface_id, x_pixmap, 0, 0,
- dest_size.width(), dest_size.height(), 0, 0,
- dest_size.width(), dest_size.height(), NULL, 0, 0);
- VA_SUCCESS_OR_RETURN(va_res, "Failed putting surface to pixmap", false);
- return true;
-}
-#endif // USE_X11
-
// static
bool VaapiWrapper::PostSandboxInitialization() {
StubPathMap paths;
-
- paths[kModuleVa].push_back("libva.so.1");
-
-#if defined(USE_X11)
- paths[kModuleVa_x11].push_back("libva-x11.so.1");
-#endif
+ paths[kModuleVa].push_back(kVaLib);
return InitializeStubs(paths);
}
diff --git a/content/common/gpu/media/vaapi_wrapper.h b/content/common/gpu/media/vaapi_wrapper.h
index ad0e807..4efb558 100644
--- a/content/common/gpu/media/vaapi_wrapper.h
+++ b/content/common/gpu/media/vaapi_wrapper.h
@@ -13,17 +13,15 @@
#include <set>
#include <vector>
+#include "base/callback.h"
#include "base/memory/ref_counted.h"
#include "base/synchronization/lock.h"
#include "content/common/content_export.h"
#include "content/common/gpu/media/va_surface.h"
#include "media/base/video_decoder_config.h"
#include "media/base/video_frame.h"
-#include "third_party/libva/va/va.h"
-#include "ui/gfx/size.h"
-#if defined(USE_X11)
#include "third_party/libva/va/va_x11.h"
-#endif // USE_X11
+#include "ui/gfx/size.h"
namespace content {
@@ -37,8 +35,7 @@ namespace content {
// It is also responsible for managing and freeing VABuffers (not VASurfaces),
// which are used to queue parameters and slice data to the HW codec,
// as well as underlying memory for VASurfaces themselves.
-class CONTENT_EXPORT VaapiWrapper
- : public base::RefCountedThreadSafe<VaapiWrapper> {
+class CONTENT_EXPORT VaapiWrapper {
public:
enum CodecMode {
kDecode,
@@ -47,15 +44,19 @@ class CONTENT_EXPORT VaapiWrapper
// |report_error_to_uma_cb| will be called independently from reporting
// errors to clients via method return values.
- static scoped_refptr<VaapiWrapper> Create(
+ static scoped_ptr<VaapiWrapper> Create(
CodecMode mode,
media::VideoCodecProfile profile,
+ Display* x_display,
const base::Closure& report_error_to_uma_cb);
// Return the supported encode profiles.
static std::vector<media::VideoCodecProfile> GetSupportedEncodeProfiles(
+ Display* x_display,
const base::Closure& report_error_to_uma_cb);
+ ~VaapiWrapper();
+
// Create |num_surfaces| backing surfaces in driver for VASurfaces, each
// of size |size|. Returns true when successful, with the created IDs in
// |va_surfaces| to be managed and later wrapped in VASurfaces.
@@ -63,7 +64,7 @@ class CONTENT_EXPORT VaapiWrapper
// again to free the allocated surfaces first, but is not required to do so
// at destruction time, as this will be done automatically from
// the destructor.
- bool CreateSurfaces(const gfx::Size& size,
+ bool CreateSurfaces(gfx::Size size,
size_t num_surfaces,
std::vector<VASurfaceID>* va_surfaces);
@@ -96,6 +97,12 @@ class CONTENT_EXPORT VaapiWrapper
// buffers. Return false if Execute() fails.
bool ExecuteAndDestroyPendingBuffers(VASurfaceID va_surface_id);
+ // Put data from |va_surface_id| into |x_pixmap| of size |size|,
+ // converting/scaling to it.
+ bool PutSurfaceIntoPixmap(VASurfaceID va_surface_id,
+ Pixmap x_pixmap,
+ gfx::Size dest_size);
+
// Returns true if the VAAPI version is less than the specified version.
bool VAAPIVersionLessThan(int major, int minor);
@@ -132,24 +139,16 @@ class CONTENT_EXPORT VaapiWrapper
// Destroy all previously-allocated (and not yet destroyed) coded buffers.
void DestroyCodedBuffers();
-#if defined(USE_X11)
- // Put data from |va_surface_id| into |x_pixmap| of size
- // |dest_size|, converting/scaling to it.
- bool PutSurfaceIntoPixmap(VASurfaceID va_surface_id,
- Pixmap x_pixmap,
- gfx::Size dest_size);
-#endif // USE_X11
-
private:
- friend class base::RefCountedThreadSafe<VaapiWrapper>;
VaapiWrapper();
- ~VaapiWrapper();
bool Initialize(CodecMode mode,
media::VideoCodecProfile profile,
- const base::Closure& report_error__to_uma_cb);
+ Display* x_display,
+ const base::Closure& report_error_to_uma_cb);
void Deinitialize();
- bool VaInitialize(const base::Closure& report_error_to_uma_cb);
+ bool VaInitialize(Display* x_display,
+ const base::Closure& report_error_to_uma_cb);
bool GetSupportedVaProfiles(std::vector<VAProfile>* profiles);
bool IsEntrypointSupported(VAProfile va_profile, VAEntrypoint entrypoint);
bool AreAttribsSupported(VAProfile va_profile,
@@ -180,7 +179,7 @@ class CONTENT_EXPORT VaapiWrapper
int major_version_, minor_version_;
// VA handles.
- // All valid after successful Initialize() and until Deinitialize().
+ // Both valid after successful Initialize() and until Deinitialize().
VADisplay va_display_;
VAConfigID va_config_id_;
// Created for the current set of va_surface_ids_ in CreateSurfaces() and
diff --git a/content/common/gpu/media/video_decode_accelerator_unittest.cc b/content/common/gpu/media/video_decode_accelerator_unittest.cc
index 382f7b5..b9fc7de5 100644
--- a/content/common/gpu/media/video_decode_accelerator_unittest.cc
+++ b/content/common/gpu/media/video_decode_accelerator_unittest.cc
@@ -60,6 +60,9 @@
#elif defined(OS_CHROMEOS) && defined(ARCH_CPU_X86_FAMILY)
#include "content/common/gpu/media/vaapi_video_decode_accelerator.h"
#include "content/common/gpu/media/vaapi_wrapper.h"
+#if defined(USE_X11)
+#include "ui/gl/gl_implementation.h"
+#endif // USE_X11
#else
#error The VideoAccelerator tests are not supported on this platform.
#endif // OS_WIN
@@ -408,12 +411,17 @@ void GLRenderingVDAClient::CreateAndStartDecoder() {
}
decoder_.reset(new V4L2VideoDecodeAccelerator(
static_cast<EGLDisplay>(rendering_helper_->GetGLDisplay()),
- static_cast<EGLContext>(rendering_helper_->GetGLContextHandle()),
- weak_client, base::Bind(&DoNothingReturnTrue), device.Pass(),
+ static_cast<EGLContext>(rendering_helper_->GetGLContext()),
+ weak_client,
+ base::Bind(&DoNothingReturnTrue),
+ device.Pass(),
base::MessageLoopProxy::current()));
#elif defined(OS_CHROMEOS) && defined(ARCH_CPU_X86_FAMILY)
- decoder_.reset(
- new VaapiVideoDecodeAccelerator(base::Bind(&DoNothingReturnTrue)));
+ CHECK_EQ(gfx::kGLImplementationDesktopGL, gfx::GetGLImplementation())
+ << "Hardware video decode does not work with OSMesa";
+ decoder_.reset(new VaapiVideoDecodeAccelerator(
+ static_cast<Display*>(rendering_helper_->GetGLDisplay()),
+ base::Bind(&DoNothingReturnTrue)));
#endif // OS_WIN
CHECK(decoder_.get());
weak_decoder_factory_.reset(
diff --git a/content/common/gpu/media/video_encode_accelerator_unittest.cc b/content/common/gpu/media/video_encode_accelerator_unittest.cc
index cc3779b..4c57f4f 100644
--- a/content/common/gpu/media/video_encode_accelerator_unittest.cc
+++ b/content/common/gpu/media/video_encode_accelerator_unittest.cc
@@ -22,9 +22,13 @@
#include "media/video/video_encode_accelerator.h"
#include "testing/gtest/include/gtest/gtest.h"
+#if defined(USE_X11)
+#include "ui/gfx/x/x11_types.h"
+#endif
+
#if defined(OS_CHROMEOS) && defined(ARCH_CPU_ARMEL)
#include "content/common/gpu/media/v4l2_video_encode_accelerator.h"
-#elif defined(OS_CHROMEOS) && defined(ARCH_CPU_X86_FAMILY)
+#elif defined(OS_CHROMEOS) && defined(ARCH_CPU_X86_FAMILY) && defined(USE_X11)
#include "content/common/gpu/media/vaapi_video_encode_accelerator.h"
#else
#error The VideoEncodeAcceleratorUnittest is not supported on this platform.
@@ -716,8 +720,8 @@ void VEAClient::CreateEncoder() {
#if defined(OS_CHROMEOS) && defined(ARCH_CPU_ARMEL)
scoped_ptr<V4L2Device> device = V4L2Device::Create(V4L2Device::kEncoder);
encoder_.reset(new V4L2VideoEncodeAccelerator(device.Pass()));
-#elif defined(OS_CHROMEOS) && defined(ARCH_CPU_X86_FAMILY)
- encoder_.reset(new VaapiVideoEncodeAccelerator());
+#elif defined(OS_CHROMEOS) && defined(ARCH_CPU_X86_FAMILY) && defined(USE_X11)
+ encoder_.reset(new VaapiVideoEncodeAccelerator(gfx::GetXDisplay()));
#endif
SetState(CS_ENCODER_SET);
diff --git a/content/content_common.gypi b/content/content_common.gypi
index f62387e..4944e98 100644
--- a/content/content_common.gypi
+++ b/content/content_common.gypi
@@ -779,7 +779,7 @@
'<(DEPTH)/third_party/khronos',
],
}],
- ['target_arch != "arm" and chromeos == 1', {
+ ['target_arch != "arm" and chromeos == 1 and use_x11 == 1', {
'dependencies': [
'../media/media.gyp:media',
'../third_party/libyuv/libyuv.gyp:libyuv',
@@ -790,8 +790,6 @@
'common/gpu/media/va_surface.h',
'common/gpu/media/vaapi_h264_decoder.cc',
'common/gpu/media/vaapi_h264_decoder.h',
- 'common/gpu/media/vaapi_picture.cc',
- 'common/gpu/media/vaapi_picture.h',
'common/gpu/media/vaapi_video_decode_accelerator.cc',
'common/gpu/media/vaapi_video_decode_accelerator.h',
'common/gpu/media/vaapi_video_encode_accelerator.cc',
@@ -799,29 +797,10 @@
'common/gpu/media/vaapi_wrapper.cc',
'common/gpu/media/vaapi_wrapper.h',
],
- 'conditions': [
- ['use_x11 == 1', {
- 'variables': {
- 'sig_files': [
- 'common/gpu/media/va.sigs',
- 'common/gpu/media/va_x11.sigs',
- ],
- },
- 'sources': [
- 'common/gpu/media/vaapi_tfp_picture.cc',
- 'common/gpu/media/vaapi_tfp_picture.h',
- ],
- }, {
- 'variables': {
- 'sig_files': [
- 'common/gpu/media/va.sigs',
- ],
- },
- }],
- ],
'variables': {
'generate_stubs_script': '../tools/generate_stubs/generate_stubs.py',
'extra_header': 'common/gpu/media/va_stub_header.fragment',
+ 'sig_files': ['common/gpu/media/va.sigs'],
'outfile_type': 'posix_stubs',
'stubs_filename_root': 'va_stubs',
'project_path': 'content/common/gpu/media',
diff --git a/media/BUILD.gn b/media/BUILD.gn
index f78c2df..33a4799 100644
--- a/media/BUILD.gn
+++ b/media/BUILD.gn
@@ -576,7 +576,7 @@ test("media_unittests") {
]
}
- if (cpu_arch != "arm" && is_chromeos) {
+ if (cpu_arch != "arm" && is_chromeos && use_x11) {
sources += [ "filters/h264_bitstream_buffer_unittest.cc" ]
}
diff --git a/media/media.gyp b/media/media.gyp
index 1aa2556..c16a880 100644
--- a/media/media.gyp
+++ b/media/media.gyp
@@ -697,7 +697,7 @@
],
}],
# For VaapiVideoEncodeAccelerator.
- ['target_arch != "arm" and chromeos == 1', {
+ ['target_arch != "arm" and chromeos == 1 and use_x11 == 1', {
'sources': [
'filters/h264_bitstream_buffer.cc',
'filters/h264_bitstream_buffer.h',
diff --git a/ui/gl/gl_image_glx.cc b/ui/gl/gl_image_glx.cc
index 84c4d0c..dadf494 100644
--- a/ui/gl/gl_image_glx.cc
+++ b/ui/gl/gl_image_glx.cc
@@ -61,8 +61,6 @@ unsigned PixmapDepth(unsigned internalformat) {
switch (internalformat) {
case GL_RGBA:
return 32u;
- case GL_RGB:
- return 24u;
default:
NOTREACHED();
return 0u;