| 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 cf836113e79e192afeff70303b3b4ca64d4fdab8..d55e0d052a0685c17370edc217a5b3d96828eddb 100644
|
| --- a/content/common/gpu/media/rendering_helper.cc
|
| +++ b/content/common/gpu/media/rendering_helper.cc
|
| @@ -17,6 +17,7 @@
|
| #include "base/strings/stringize_macros.h"
|
| #include "base/synchronization/waitable_event.h"
|
| #include "base/time/time.h"
|
| +#include "content/common/gpu/media/gl_renderer.h"
|
| #include "ui/gl/gl_context.h"
|
| #include "ui/gl/gl_implementation.h"
|
| #include "ui/gl/gl_surface.h"
|
| @@ -38,10 +39,13 @@
|
| #endif
|
|
|
| #if defined(USE_OZONE)
|
| +#include "content/common/gpu/media/surfaceless_gl_renderer.h"
|
| #if defined(OS_CHROMEOS)
|
| #include "ui/display/chromeos/display_configurator.h"
|
| #endif // defined(OS_CHROMEOS)
|
| +#include "ui/ozone/gpu/gpu_memory_buffer_factory_ozone_native_buffer.h"
|
| #include "ui/ozone/public/ozone_platform.h"
|
| +#include "ui/ozone/public/ozone_switches.h"
|
| #include "ui/platform_window/platform_window.h"
|
| #include "ui/platform_window/platform_window_delegate.h"
|
| #endif // defined(USE_OZONE)
|
| @@ -130,7 +134,14 @@ class RenderingHelper::StubOzoneDelegate : public ui::PlatformWindowDelegate {
|
|
|
| ui::PlatformWindow* platform_window() const { return platform_window_.get(); }
|
|
|
| + ui::GpuMemoryBufferFactoryOzoneNativeBuffer* buffer_factory() {
|
| + return &buffer_factory_;
|
| + }
|
| +
|
| private:
|
| + // Used by the surfaceless renderers to allocate buffers.
|
| + ui::GpuMemoryBufferFactoryOzoneNativeBuffer buffer_factory_;
|
| +
|
| scoped_ptr<ui::PlatformWindow> platform_window_;
|
| gfx::AcceleratedWidget accelerated_widget_;
|
|
|
| @@ -187,19 +198,21 @@ RenderingHelper::RenderingHelper() {
|
|
|
| RenderingHelper::~RenderingHelper() {
|
| CHECK_EQ(videos_.size(), 0U) << "Must call UnInitialize before dtor.";
|
| - Clear();
|
| + CHECK(!gl_renderer_);
|
| }
|
|
|
| void RenderingHelper::Setup() {
|
| #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,
|
| @@ -217,12 +230,14 @@ void RenderingHelper::Setup() {
|
| window_attributes.override_redirect = true;
|
| int depth = DefaultDepth(display, DefaultScreen(display));
|
|
|
| + screen_size_ = gfx::Size(XWidthOfScreen(screen), XHeightOfScreen(screen));
|
| +
|
| window_ = XCreateWindow(display,
|
| DefaultRootWindow(display),
|
| 0,
|
| 0,
|
| - XWidthOfScreen(screen),
|
| - XHeightOfScreen(screen),
|
| + screen_size_.width(),
|
| + screen_size_.height(),
|
| 0 /* border width */,
|
| depth,
|
| CopyFromParent /* class */,
|
| @@ -253,11 +268,12 @@ void RenderingHelper::Setup() {
|
| wait_display_setup.Run();
|
| display_configurator_->RemoveObserver(&display_setup_observer);
|
|
|
| - platform_window_delegate_->platform_window()->SetBounds(
|
| - gfx::Rect(display_configurator_->framebuffer_size()));
|
| + screen_size_ = display_configurator_->framebuffer_size();
|
| #else
|
| - platform_window_delegate_->platform_window()->SetBounds(gfx::Rect(800, 600));
|
| + screen_size_ = gfx::Size(800, 600));
|
| #endif
|
| + platform_window_delegate_->platform_window()->SetBounds(
|
| + gfx::Rect(screen_size_));
|
|
|
| // On Ozone/DRI, platform windows are associated with the physical
|
| // outputs. Association is achieved by matching the bounds of the
|
| @@ -303,6 +319,19 @@ void RenderingHelper::Initialize(const RenderingHelperParams& params,
|
| done.Wait();
|
| }
|
|
|
| +#if defined(USE_OZONE)
|
| + base::CommandLine* command_line = base::CommandLine::ForCurrentProcess();
|
| + if (command_line->HasSwitch(switches::kOzoneUseSurfaceless))
|
| + gl_renderer_.reset(new SurfacelessGlRenderer(
|
| + window_, screen_size_, platform_window_delegate_->buffer_factory()));
|
| + else
|
| + gl_renderer_.reset(new GlRenderer(window_, screen_size_));
|
| +#else
|
| + gl_renderer_.reset(new GlRenderer(window_, screen_size_));
|
| +#endif
|
| +
|
| + CHECK(gl_renderer_->Initialize());
|
| +
|
| render_task_.Reset(
|
| base::Bind(&RenderingHelper::RenderContent, base::Unretained(this)));
|
|
|
| @@ -313,12 +342,7 @@ void RenderingHelper::Initialize(const RenderingHelperParams& params,
|
| render_as_thumbnails_ = params.render_as_thumbnails;
|
| message_loop_ = base::MessageLoop::current();
|
|
|
| - 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()));
|
| + CHECK(gl_renderer_->MakeCurrent());
|
|
|
| CHECK_GT(params.window_sizes.size(), 0U);
|
| videos_.resize(params.window_sizes.size());
|
| @@ -353,7 +377,7 @@ void RenderingHelper::Initialize(const RenderingHelperParams& params,
|
| glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
|
| glBindTexture(GL_TEXTURE_2D, 0);
|
|
|
| - glBindFramebufferEXT(GL_FRAMEBUFFER, thumbnails_fbo_id_);
|
| + gl_renderer_->BindFramebuffer(thumbnails_fbo_id_);
|
| glFramebufferTexture2DEXT(GL_FRAMEBUFFER,
|
| GL_COLOR_ATTACHMENT0,
|
| GL_TEXTURE_2D,
|
| @@ -364,7 +388,7 @@ void RenderingHelper::Initialize(const RenderingHelperParams& params,
|
| CHECK(fb_status == GL_FRAMEBUFFER_COMPLETE) << fb_status;
|
| glClearColor(0.0f, 0.0f, 0.0f, 1.0f);
|
| glClear(GL_COLOR_BUFFER_BIT);
|
| - glBindFramebufferEXT(GL_FRAMEBUFFER, 0);
|
| + gl_renderer_->UnbindFramebuffer();
|
| }
|
|
|
| // These vertices and texture coords. map (0,0) in the texture to the
|
| @@ -431,7 +455,8 @@ void RenderingHelper::Initialize(const RenderingHelperParams& params,
|
| glUseProgram(program_);
|
| glDeleteProgram(program_);
|
|
|
| - glUniform1i(glGetUniformLocation(program_, "tex_flip"), 0);
|
| + glUniform1i(glGetUniformLocation(program_, "tex_flip"),
|
| + gl_renderer_->IsFlipped() ? 0 : 1);
|
| glUniform1i(glGetUniformLocation(program_, "tex"), 0);
|
| GLint tex_external = glGetUniformLocation(program_, "tex_external");
|
| if (tex_external != -1) {
|
| @@ -462,7 +487,8 @@ void RenderingHelper::Initialize(const RenderingHelperParams& params,
|
| // 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();
|
| + gfx::VSyncProvider* vsync_provider =
|
| + gl_renderer_->gl_surface()->GetVSyncProvider();
|
| if (vsync_provider && frame_duration_ != base::TimeDelta())
|
| vsync_provider->GetVSyncParameters(base::Bind(
|
| &RenderingHelper::UpdateVSyncParameters, base::Unretained(this), done));
|
| @@ -489,7 +515,7 @@ void RenderingHelper::WarmUpRendering(int warm_up_iterations) {
|
| emptyData.get());
|
| for (int i = 0; i < warm_up_iterations; ++i) {
|
| RenderTexture(GL_TEXTURE_2D, texture_id);
|
| - gl_surface_->SwapBuffers();
|
| + gl_renderer_->SwapBuffers();
|
| }
|
| glDeleteTextures(1, &texture_id);
|
| }
|
| @@ -504,11 +530,8 @@ void RenderingHelper::UnInitialize(base::WaitableEvent* done) {
|
| glDeleteFramebuffersEXT(1, &thumbnails_fbo_id_);
|
| }
|
|
|
| - gl_context_->ReleaseCurrent(gl_surface_.get());
|
| - gl_context_ = NULL;
|
| - gl_surface_ = NULL;
|
| -
|
| Clear();
|
| +
|
| done->Signal();
|
| }
|
|
|
| @@ -567,10 +590,10 @@ void RenderingHelper::RenderThumbnail(uint32 texture_target,
|
| gfx::Rect area(col * width, row * height, width, height);
|
|
|
| glUniform1i(glGetUniformLocation(program_, "tex_flip"), 0);
|
| - glBindFramebufferEXT(GL_FRAMEBUFFER, thumbnails_fbo_id_);
|
| + gl_renderer_->BindFramebuffer(thumbnails_fbo_id_);
|
| GLSetViewPort(area);
|
| RenderTexture(texture_target, texture_id);
|
| - glBindFramebufferEXT(GL_FRAMEBUFFER, 0);
|
| + gl_renderer_->UnbindFramebuffer();
|
|
|
| // Need to flush the GL commands before we return the tnumbnail texture to
|
| // the decoder.
|
| @@ -620,27 +643,27 @@ void RenderingHelper::DeleteTexture(uint32 texture_id) {
|
| }
|
|
|
| scoped_refptr<gfx::GLContext> RenderingHelper::GetGLContext() {
|
| - return gl_context_;
|
| + return gl_renderer_->gl_context();
|
| }
|
|
|
| void* RenderingHelper::GetGLContextHandle() {
|
| - return gl_context_->GetHandle();
|
| + return gl_renderer_->gl_context()->GetHandle();
|
| }
|
|
|
| void* RenderingHelper::GetGLDisplay() {
|
| - return gl_surface_->GetDisplay();
|
| + return gl_renderer_->gl_surface()->GetDisplay();
|
| }
|
|
|
| void RenderingHelper::Clear() {
|
| videos_.clear();
|
| message_loop_ = NULL;
|
| - gl_context_ = NULL;
|
| - gl_surface_ = NULL;
|
|
|
| render_as_thumbnails_ = false;
|
| frame_count_ = 0;
|
| thumbnails_fbo_id_ = 0;
|
| thumbnails_texture_id_ = 0;
|
| +
|
| + gl_renderer_.reset();
|
| }
|
|
|
| void RenderingHelper::GetThumbnailsAsRGB(std::vector<unsigned char>* rgb,
|
| @@ -651,7 +674,7 @@ void RenderingHelper::GetThumbnailsAsRGB(std::vector<unsigned char>* rgb,
|
| const size_t num_pixels = thumbnails_fbo_size_.GetArea();
|
| std::vector<unsigned char> rgba;
|
| rgba.resize(num_pixels * 4);
|
| - glBindFramebufferEXT(GL_FRAMEBUFFER, thumbnails_fbo_id_);
|
| + gl_renderer_->BindFramebuffer(thumbnails_fbo_id_);
|
| glPixelStorei(GL_PACK_ALIGNMENT, 1);
|
| // We can only count on GL_RGBA/GL_UNSIGNED_BYTE support.
|
| glReadPixels(0,
|
| @@ -661,7 +684,7 @@ void RenderingHelper::GetThumbnailsAsRGB(std::vector<unsigned char>* rgb,
|
| GL_RGBA,
|
| GL_UNSIGNED_BYTE,
|
| &rgba[0]);
|
| - glBindFramebufferEXT(GL_FRAMEBUFFER, 0);
|
| + gl_renderer_->UnbindFramebuffer();
|
| rgb->resize(num_pixels * 3);
|
| // Drop the alpha channel, but check as we go that it is all 0xff.
|
| bool solid = true;
|
| @@ -691,14 +714,16 @@ void RenderingHelper::RenderContent() {
|
| // 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();
|
| + gfx::VSyncProvider* vsync_provider =
|
| + gl_renderer_->gl_surface()->GetVSyncProvider();
|
| if (vsync_provider) {
|
| vsync_provider->GetVSyncParameters(base::Bind(
|
| &RenderingHelper::UpdateVSyncParameters, base::Unretained(this),
|
| static_cast<base::WaitableEvent*>(NULL)));
|
| }
|
|
|
| - glUniform1i(glGetUniformLocation(program_, "tex_flip"), 1);
|
| + glUniform1i(glGetUniformLocation(program_, "tex_flip"),
|
| + gl_renderer_->IsFlipped() ? 0 : 1);
|
|
|
| // Frames that will be returned to the client (via the no_longer_needed_cb)
|
| // after this vector falls out of scope at the end of this method. We need
|
| @@ -730,7 +755,7 @@ void RenderingHelper::RenderContent() {
|
| }
|
|
|
| if (need_swap_buffer)
|
| - gl_surface_->SwapBuffers();
|
| + gl_renderer_->SwapBuffers();
|
|
|
| ScheduleNextRenderContent();
|
| }
|
|
|