| Index: content/common/gpu/media/rendering_helper.cc
|
| diff --git a/content/common/gpu/media/rendering_helper.cc b/content/common/gpu/media/rendering_helper.cc
|
| index 5870ceef564638b48b1c5c9b19c132a95c6f80bb..d502be323de96b904f6dc3576037904b35c646b5 100644
|
| --- a/content/common/gpu/media/rendering_helper.cc
|
| +++ b/content/common/gpu/media/rendering_helper.cc
|
| @@ -19,8 +19,6 @@
|
| #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,14 +26,20 @@
|
|
|
| #if defined(USE_X11)
|
| #include "ui/gfx/x/x11_types.h"
|
| -#endif
|
| -
|
| -#if !defined(OS_WIN) && defined(ARCH_CPU_X86_FAMILY)
|
| +#include "ui/gl/gl_surface_glx.h"
|
| #define GL_VARIANT_GLX 1
|
| #else
|
| +#include "ui/gl/gl_surface_egl.h"
|
| #define GL_VARIANT_EGL 1
|
| #endif
|
|
|
| +#if defined(USE_OZONE)
|
| +#include "ui/ozone/public/ozone_platform.h"
|
| +#include "ui/ozone/public/ui_thread_gpu.h"
|
| +#include "ui/platform_window/platform_window.h"
|
| +#include "ui/platform_window/platform_window_delegate.h"
|
| +#endif
|
| +
|
| // Helper for Shader creation.
|
| static void CreateShader(GLuint program,
|
| GLenum type,
|
| @@ -58,6 +62,48 @@ static void CreateShader(GLuint program,
|
|
|
| namespace content {
|
|
|
| +#if defined(USE_OZONE)
|
| +
|
| +class RenderingHelper::StubOzoneDelegate : public ui::PlatformWindowDelegate {
|
| + public:
|
| + StubOzoneDelegate() : widget_(gfx::kNullAcceleratedWidget) {
|
| + platform_window_ = ui::OzonePlatform::GetInstance()->CreatePlatformWindow(
|
| + this, gfx::Rect());
|
| + }
|
| + virtual ~StubOzoneDelegate() {}
|
| +
|
| + virtual void OnBoundsChanged(const gfx::Rect& new_bounds) override {}
|
| +
|
| + virtual void OnDamageRect(const gfx::Rect& damaged_region) override {}
|
| +
|
| + virtual void DispatchEvent(ui::Event* event) override {}
|
| +
|
| + virtual void OnCloseRequest() override {}
|
| + virtual void OnClosed() override {}
|
| +
|
| + virtual void OnWindowStateChanged(
|
| + ui::PlatformWindowState new_state) override {};
|
| +
|
| + virtual void OnLostCapture() override {};
|
| +
|
| + virtual void OnAcceleratedWidgetAvailable(
|
| + gfx::AcceleratedWidget widget) override {
|
| + widget_ = widget;
|
| + };
|
| +
|
| + virtual void OnActivationChanged(bool active) override {};
|
| +
|
| + gfx::AcceleratedWidget GetAcceleratedWidget() const { return widget_; }
|
| +
|
| + gfx::Size GetSize() { return platform_window_->GetBounds().size(); }
|
| +
|
| + private:
|
| + scoped_ptr<ui::PlatformWindow> platform_window_;
|
| + gfx::AcceleratedWidget widget_;
|
| +};
|
| +
|
| +#endif // defined(USE_OZONE)
|
| +
|
| RenderingHelperParams::RenderingHelperParams()
|
| : rendering_fps(0), warm_up_iterations(0), render_as_thumbnails(false) {
|
| }
|
| @@ -93,7 +139,14 @@ bool RenderingHelper::InitializeOneOff() {
|
| #else
|
| cmd_line->AppendSwitchASCII(switches::kUseGL, gfx::kGLImplementationEGLName);
|
| #endif
|
| +
|
| +#if defined(USE_OZONE)
|
| + static ui::UiThreadGpu ui_thread_gpu;
|
| + ui::OzonePlatform::InitializeForUI();
|
| + return gfx::GLSurface::InitializeOneOff() && ui_thread_gpu.Initialize();
|
| +#else
|
| return gfx::GLSurface::InitializeOneOff();
|
| +#endif
|
| }
|
|
|
| RenderingHelper::RenderingHelper() {
|
| @@ -127,16 +180,14 @@ 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,
|
| - screen_size_.width(),
|
| - screen_size_.height(),
|
| + GetSystemMetrics(SM_CXSCREEN),
|
| + GetSystemMetrics(SM_CYSCREEN),
|
| NULL,
|
| NULL,
|
| NULL,
|
| @@ -144,7 +195,6 @@ 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);
|
|
|
| @@ -159,8 +209,8 @@ void RenderingHelper::Initialize(const RenderingHelperParams& params,
|
| DefaultRootWindow(display),
|
| 0,
|
| 0,
|
| - screen_size_.width(),
|
| - screen_size_.height(),
|
| + XWidthOfScreen(screen),
|
| + XHeightOfScreen(screen),
|
| 0 /* border width */,
|
| depth,
|
| CopyFromParent /* class */,
|
| @@ -170,15 +220,20 @@ void RenderingHelper::Initialize(const RenderingHelperParams& params,
|
| XStoreName(display, window_, "VideoDecodeAcceleratorTest");
|
| XSelectInput(display, window_, ExposureMask);
|
| XMapWindow(display, window_);
|
| +#elif defined(USE_OZONE)
|
| + platform_window_delegate_.reset(new RenderingHelper::StubOzoneDelegate());
|
| + window_ = platform_window_delegate_->GetAcceleratedWidget();
|
| #else
|
| #error unknown platform
|
| #endif
|
| 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);
|
| - gl_context_->MakeCurrent(gl_surface_.get());
|
| + CHECK(gl_context_->MakeCurrent(gl_surface_.get()));
|
|
|
| CHECK_GT(params.window_sizes.size(), 0U);
|
| videos_.resize(params.window_sizes.size());
|
| @@ -304,14 +359,30 @@ void RenderingHelper::Initialize(const RenderingHelperParams& params,
|
| glEnableVertexAttribArray(tc_location);
|
| glVertexAttribPointer(tc_location, 2, GL_FLOAT, GL_FALSE, 0, kTextureCoords);
|
|
|
| - 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.)
|
| - gl_surface_->GetVSyncProvider()->GetVSyncParameters(base::Bind(
|
| - &RenderingHelper::UpdateVSyncParameters, base::Unretained(this), done));
|
| + if (frame_duration_ == base::TimeDelta())
|
| + done->Signal();
|
| + else {
|
| + int warm_up_iterations = params.warm_up_iterations;
|
| +#if defined(USE_OZONE)
|
| + // On Ozone the VSyncProvider can't provide a vsync_internal until
|
| + // we render at least a frame, so we warm up with at least one
|
| + // frame.
|
| + // On top of this, we want to make sure all the buffers backing
|
| + // the GL surface are cleared, otherwise we can see the previous
|
| + // test's last frames, so we set warm up iterations to 2, to clear
|
| + // the front and back buffers.
|
| + warm_up_iterations = std::max(2, warm_up_iterations);
|
| +#endif
|
| + if (warm_up_iterations > 0)
|
| + WarmUpRendering(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.)
|
| + gl_surface_->GetVSyncProvider()->GetVSyncParameters(base::Bind(
|
| + &RenderingHelper::UpdateVSyncParameters, base::Unretained(this), done));
|
| + }
|
| }
|
|
|
| // The rendering for the first few frames is slow (e.g., 100ms on Peach Pit).
|
| @@ -463,7 +534,11 @@ void RenderingHelper::DeleteTexture(uint32 texture_id) {
|
| CHECK_EQ(static_cast<int>(glGetError()), GL_NO_ERROR);
|
| }
|
|
|
| -void* RenderingHelper::GetGLContext() {
|
| +scoped_refptr<gfx::GLContext> RenderingHelper::GetGLContext() {
|
| + return gl_context_;
|
| +}
|
| +
|
| +void* RenderingHelper::GetGLContextHandle() {
|
| return gl_context_->GetHandle();
|
| }
|
|
|
| @@ -485,7 +560,7 @@ void RenderingHelper::Clear() {
|
| #if defined(OS_WIN)
|
| if (window_)
|
| DestroyWindow(window_);
|
| -#else
|
| +#elif defined(USE_X11)
|
| // Destroy resources acquired in Initialize, in reverse-acquisition order.
|
| if (window_) {
|
| CHECK(XUnmapWindow(gfx::GetXDisplay(), window_));
|
|
|