Chromium Code Reviews| 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..4c3ab7ab1be2d7e4340f783245f5bd15a5146c64 100644 |
| --- a/content/common/gpu/media/rendering_helper.cc |
| +++ b/content/common/gpu/media/rendering_helper.cc |
| @@ -20,7 +20,6 @@ |
| #include "ui/gl/gl_implementation.h" |
| #include "ui/gl/gl_surface.h" |
| #include "ui/gl/gl_surface_egl.h" |
|
Pawel Osciak
2014/11/03 01:36:51
Should this be under GL_VARIANT_EGL below?
|
| -#include "ui/gl/gl_surface_glx.h" |
| #if defined(OS_WIN) |
| #include <windows.h> |
| @@ -28,14 +27,19 @@ |
| #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 |
| #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,51 @@ static void CreateShader(GLuint program, |
| namespace content { |
| +#if defined(USE_OZONE) |
| + |
| +const int kTestWindowWidth = 800; |
|
Pawel Osciak
2014/11/03 01:36:51
I realized, could we use a fullscreen window?
Owen Lin
2014/11/03 06:59:05
The performance on a non-fullscreen window is not
|
| +const int kTestWindowHeight = 600; |
| + |
| +class RenderingHelper::StubOzoneDelegate : public ui::PlatformWindowDelegate { |
| + public: |
| + StubOzoneDelegate() : widget_(gfx::kNullAcceleratedWidget) { |
| + platform_window_ = ui::OzonePlatform::GetInstance()->CreatePlatformWindow( |
| + this, gfx::Rect(kTestWindowWidth, kTestWindowHeight)); |
| + } |
| + 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{}; |
|
Pawel Osciak
2014/11/03 01:36:51
Some methods have spaces after override and before
llandwerlin-old
2014/11/04 16:16:28
Acknowledged.
|
| + |
| + 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) { |
| } |
| @@ -87,13 +136,21 @@ RenderingHelper::RenderedVideo::~RenderedVideo() { |
| // static |
| bool RenderingHelper::InitializeOneOff() { |
| base::CommandLine* cmd_line = base::CommandLine::ForCurrentProcess(); |
| + |
| #if GL_VARIANT_GLX |
| cmd_line->AppendSwitchASCII(switches::kUseGL, |
| gfx::kGLImplementationDesktopName); |
| #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() { |
| @@ -170,6 +227,11 @@ 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(); |
|
Owen Lin
2014/11/03 06:59:05
How could you make sure the widget_ is available n
llandwerlin-old
2014/11/04 16:16:28
When the DriWindow is created and initialized, it
|
| + |
| + screen_size_ = platform_window_delegate_->GetSize(); |
| #else |
| #error unknown platform |
| #endif |
| @@ -304,14 +366,19 @@ 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); |
| + WarmUpRendering(params.warm_up_iterations); |
|
Pawel Osciak
2014/11/03 01:36:51
Why is that if not needed anymore?
llandwerlin-old
2014/11/03 09:30:10
That seems to be a workaround for drivers that are
Owen Lin
2014/11/04 08:47:49
I think you still need the if. We use frame_durati
|
| - // 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 this test doesn't do any rendering, just signal we're ready. |
| + if (params.suppress_rendering) |
|
Owen Lin
2014/11/03 06:59:06
We use "frame_duration == base::TimeDelta()" to de
llandwerlin-old
2014/11/03 09:30:10
To get a vsync_internal value, we need to render a
Owen Lin
2014/11/04 08:47:49
But it is not what I saw. In vda_unittest, there i
|
| + done->Signal(); |
| + else |
|
Pawel Osciak
2014/11/03 01:36:51
You could just drop else.
llandwerlin-old
2014/11/03 09:30:10
Ok, I would need to remove the done pointer too.
|
| + // 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 +530,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 +556,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_)); |
| @@ -559,9 +630,14 @@ void RenderingHelper::RenderContent() { |
| // In render_as_thumbnails_ mode, we render the FBO content on the |
| // screen instead of the decoded textures. |
| GLSetViewPort(videos_[0].render_area); |
| + glClearColor(0.0f, 0.0f, 0.0f, 1.0f); |
|
Owen Lin
2014/11/03 06:59:06
Why we need to clear the color buffer, (I think vi
llandwerlin-old
2014/11/03 09:30:10
This was to workaround a bug in Mesa :
http://cgi
llandwerlin-old
2014/11/04 16:16:28
I need to leave it for the non thumbnail case, oth
|
| + glClear(GL_COLOR_BUFFER_BIT); |
| RenderTexture(GL_TEXTURE_2D, thumbnails_texture_id_); |
| need_swap_buffer = true; |
| } else { |
| + GLSetViewPort(gfx::Rect(screen_size_)); |
| + glClearColor(0.0f, 0.0f, 0.0f, 1.0f); |
| + glClear(GL_COLOR_BUFFER_BIT); |
| for (RenderedVideo& video : videos_) { |
| if (video.pending_frames.empty()) |
| continue; |
| @@ -665,22 +741,27 @@ void RenderingHelper::DropOneFrameForAllVideos() { |
| void RenderingHelper::ScheduleNextRenderContent() { |
| scheduled_render_time_ += frame_duration_; |
| - // Schedules the next RenderContent() at latest VSYNC before the |
| - // |scheduled_render_time_|. |
| - base::TimeTicks now = base::TimeTicks::Now(); |
| - base::TimeTicks target = |
| - std::max(now + vsync_interval_, scheduled_render_time_); |
| - |
| - int64 intervals = (target - vsync_timebase_) / vsync_interval_; |
| - target = vsync_timebase_ + intervals * vsync_interval_; |
| - |
| - // When the rendering falls behind, drops frames. |
| - while (scheduled_render_time_ < target) { |
| - scheduled_render_time_ += frame_duration_; |
| - DropOneFrameForAllVideos(); |
| + // If we couldn't figure out the vsync interval, just render as |
| + // quick as possible. |
|
Pawel Osciak
2014/11/03 01:36:51
What if we are falling behind even if we are rende
Owen Lin
2014/11/03 06:59:05
Are you saying there won't be vsync info on ozone
llandwerlin-old
2014/11/03 09:30:10
As explained in another comment, we won't get a vs
Owen Lin
2014/11/04 08:47:49
We will wait forever on getting the vsync info in
|
| + if (vsync_interval_ > base::TimeDelta()) { |
| + // Schedules the next RenderContent() at latest VSYNC before the |
| + // |scheduled_render_time_|. |
| + base::TimeTicks now = base::TimeTicks::Now(); |
| + base::TimeTicks target = |
| + std::max(now + vsync_interval_, scheduled_render_time_); |
| + |
| + int64 intervals = (target - vsync_timebase_) / vsync_interval_; |
| + target = vsync_timebase_ + intervals * vsync_interval_; |
| + |
| + // When the rendering falls behind, drops frames. |
| + while (scheduled_render_time_ < target) { |
| + scheduled_render_time_ += frame_duration_; |
| + DropOneFrameForAllVideos(); |
| + } |
| + message_loop_->PostDelayedTask( |
| + FROM_HERE, render_task_.callback(), target - now); |
| + } else { |
| + message_loop_->PostTask(FROM_HERE, render_task_.callback()); |
| } |
| - |
| - message_loop_->PostDelayedTask( |
| - FROM_HERE, render_task_.callback(), target - now); |
| } |
| } // namespace content |