| 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 b3a8d3e7c13b4a7bfdcc97ac27ac5303c25555ad..61770046eb5cfe58219dd19e9524b3f3e719e7af 100644
|
| --- a/content/common/gpu/media/rendering_helper.cc
|
| +++ b/content/common/gpu/media/rendering_helper.cc
|
| @@ -97,8 +97,9 @@ void RenderingHelper::Initialize(const RenderingHelperParams& params,
|
| done.Wait();
|
| }
|
|
|
| - // TODO(owenlin): pass fps from params
|
| - frame_duration_ = base::TimeDelta::FromSeconds(1) / 60;
|
| + frame_duration_ = params.rendering_fps > 0
|
| + ? base::TimeDelta::FromSeconds(1) / params.rendering_fps
|
| + : base::TimeDelta();
|
|
|
| gfx::InitializeStaticGLBindings(kGLImplementation);
|
| scoped_refptr<gfx::GLContextStubWithExtensions> stub_context(
|
| @@ -187,6 +188,7 @@ void RenderingHelper::Initialize(const RenderingHelperParams& params,
|
| reinterpret_cast<const char*>(glGetString(GL_VERSION)));
|
| #endif
|
|
|
| + clients_.resize(params.num_windows);
|
| // Per-window/surface X11 & EGL initialization.
|
| for (int i = 0; i < params.num_windows; ++i) {
|
| // Arrange X windows whimsically, with some padding.
|
| @@ -199,11 +201,6 @@ void RenderingHelper::Initialize(const RenderingHelperParams& params,
|
| int top_left_y = (height + 12) * (i % 3);
|
| render_areas_.push_back(gfx::Rect(
|
| top_left_x, top_left_y, width, height));
|
| -
|
| - // Initialize to an invalid texture id: 0 to indicate no texture
|
| - // for rendering.
|
| - texture_ids_.push_back(0);
|
| - texture_targets_.push_back(0);
|
| }
|
|
|
| #if defined(OS_WIN)
|
| @@ -291,11 +288,6 @@ void RenderingHelper::Initialize(const RenderingHelperParams& params,
|
| glClearColor(0.0f, 0.0f, 0.0f, 1.0f);
|
| glClear(GL_COLOR_BUFFER_BIT);
|
| glBindFramebufferEXT(GL_FRAMEBUFFER, 0);
|
| -
|
| - // In render_as_thumbnails_ mode, we render the FBO content on the
|
| - // screen instead of the decoded textures.
|
| - texture_targets_[0] = GL_TEXTURE_2D;
|
| - texture_ids_[0] = thumbnails_texture_id_;
|
| }
|
|
|
| // These vertices and texture coords. map (0,0) in the texture to the
|
| @@ -375,8 +367,10 @@ void RenderingHelper::Initialize(const RenderingHelperParams& params,
|
| glEnableVertexAttribArray(tc_location);
|
| glVertexAttribPointer(tc_location, 2, GL_FLOAT, GL_FALSE, 0, kTextureCoords);
|
|
|
| - render_timer_.Start(FROM_HERE, frame_duration_, this,
|
| - &RenderingHelper::RenderContent);
|
| + if (frame_duration_ != base::TimeDelta()) {
|
| + render_timer_.Start(FROM_HERE, frame_duration_, this,
|
| + &RenderingHelper::RenderContent);
|
| + }
|
| done->Signal();
|
| }
|
|
|
| @@ -400,6 +394,17 @@ void RenderingHelper::UnInitialize(base::WaitableEvent* done) {
|
| done->Signal();
|
| }
|
|
|
| +void RenderingHelper::SetClient(int window_id, RenderingClient *client) {
|
| + if (base::MessageLoop::current() != message_loop_) {
|
| + message_loop_->PostTask(
|
| + FROM_HERE,
|
| + base::Bind(&RenderingHelper::SetClient, base::Unretained(this),
|
| + window_id, client));
|
| + return;
|
| + }
|
| + clients_[window_id] = client;
|
| +}
|
| +
|
| void RenderingHelper::CreateTexture(int window_id,
|
| uint32 texture_target,
|
| uint32* texture_id,
|
| @@ -436,40 +441,33 @@ void RenderingHelper::CreateTexture(int window_id,
|
| done->Signal();
|
| }
|
|
|
| +// Helper function to set GL viewport.
|
| +static inline void GLSetViewPort(const gfx::Rect& area) {
|
| + glViewport(area.x(), area.y(), area.width(), area.height());
|
| + glScissor(area.x(), area.y(), area.width(), area.height());
|
| +}
|
|
|
| -void RenderingHelper::RenderTexture(uint32 texture_target, uint32 texture_id) {
|
| +void RenderingHelper::RenderThumbnail(uint32 texture_target,
|
| + uint32 texture_id) {
|
| CHECK_EQ(base::MessageLoop::current(), message_loop_);
|
| - if (texture_id == 0)
|
| - return;
|
| -
|
| - if (render_as_thumbnails_) {
|
| - const int width = thumbnail_size_.width();
|
| - const int height = thumbnail_size_.height();
|
| - const int thumbnails_in_row = thumbnails_fbo_size_.width() / width;
|
| - const int thumbnails_in_column = thumbnails_fbo_size_.height() / height;
|
| - const int row = (frame_count_ / thumbnails_in_row) % thumbnails_in_column;
|
| - const int col = frame_count_ % thumbnails_in_row;
|
| + const int width = thumbnail_size_.width();
|
| + const int height = thumbnail_size_.height();
|
| + const int thumbnails_in_row = thumbnails_fbo_size_.width() / width;
|
| + const int thumbnails_in_column = thumbnails_fbo_size_.height() / height;
|
| + const int row = (frame_count_ / thumbnails_in_row) % thumbnails_in_column;
|
| + const int col = frame_count_ % thumbnails_in_row;
|
|
|
| - gfx::Rect area(col * width, row * height, width, height);
|
| + gfx::Rect area(col * width, row * height, width, height);
|
|
|
| - glUniform1i(glGetUniformLocation(program_, "tex_flip"), 0);
|
| - glBindFramebufferEXT(GL_FRAMEBUFFER, thumbnails_fbo_id_);
|
| - DrawTexture(area, texture_target, texture_id);
|
| - glBindFramebufferEXT(GL_FRAMEBUFFER, 0);
|
| - ++frame_count_;
|
| - } else {
|
| - size_t window_id = texture_id_to_surface_index_[texture_id];
|
| - texture_targets_[window_id] = texture_target;
|
| - texture_ids_[window_id] = texture_id;
|
| - }
|
| + glUniform1i(glGetUniformLocation(program_, "tex_flip"), 0);
|
| + glBindFramebufferEXT(GL_FRAMEBUFFER, thumbnails_fbo_id_);
|
| + GLSetViewPort(area);
|
| + RenderTexture(texture_target, texture_id);
|
| + glBindFramebufferEXT(GL_FRAMEBUFFER, 0);
|
| + ++frame_count_;
|
| }
|
|
|
| -void RenderingHelper::DrawTexture(const gfx::Rect& area,
|
| - uint32 texture_target,
|
| - uint32 texture_id) {
|
| - glViewport(area.x(), area.y(), area.width(), area.height());
|
| - glScissor(area.x(), area.y(), area.width(), area.height());
|
| -
|
| +void RenderingHelper::RenderTexture(uint32 texture_target, uint32 texture_id) {
|
| // Unbound texture samplers default to (0, 0, 0, 1). Use this fact to switch
|
| // between GL_TEXTURE_2D and GL_TEXTURE_EXTERNAL_OES as appopriate.
|
| if (texture_target == GL_TEXTURE_2D) {
|
| @@ -571,9 +569,22 @@ void RenderingHelper::GetThumbnailsAsRGB(std::vector<unsigned char>* rgb,
|
| }
|
|
|
| void RenderingHelper::RenderContent() {
|
| +
|
| glUniform1i(glGetUniformLocation(program_, "tex_flip"), 1);
|
| - for (size_t i = 0; i < render_areas_.size(); ++i) {
|
| - DrawTexture(render_areas_[i], texture_targets_[i], texture_ids_[i]);
|
| +
|
| + if (render_as_thumbnails_) {
|
| + // In render_as_thumbnails_ mode, we render the FBO content on the
|
| + // screen instead of the decoded textures.
|
| + GLSetViewPort(render_areas_[0]);
|
| + RenderTexture(GL_TEXTURE_2D, thumbnails_texture_id_);
|
| + } else {
|
| + for (size_t i = 0; i < clients_.size(); ++i) {
|
| + RenderingClient *client = clients_[i];
|
| + if (client != NULL) {
|
| + GLSetViewPort(render_areas_[i]);
|
| + client->RenderContent(this);
|
| + }
|
| + }
|
| }
|
|
|
| #if GL_VARIANT_GLX
|
|
|