Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "content/common/gpu/media/rendering_helper.h" | 5 #include "content/common/gpu/media/rendering_helper.h" |
| 6 | 6 |
| 7 #include <algorithm> | 7 #include <algorithm> |
| 8 #include <numeric> | 8 #include <numeric> |
| 9 #include <vector> | 9 #include <vector> |
| 10 | 10 |
| (...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 87 return gfx::GLSurface::InitializeOneOff(); | 87 return gfx::GLSurface::InitializeOneOff(); |
| 88 } | 88 } |
| 89 | 89 |
| 90 RenderingHelper::RenderingHelper() { | 90 RenderingHelper::RenderingHelper() { |
| 91 window_ = gfx::kNullAcceleratedWidget; | 91 window_ = gfx::kNullAcceleratedWidget; |
| 92 Clear(); | 92 Clear(); |
| 93 } | 93 } |
| 94 | 94 |
| 95 RenderingHelper::~RenderingHelper() { | 95 RenderingHelper::~RenderingHelper() { |
| 96 CHECK_EQ(clients_.size(), 0U) << "Must call UnInitialize before dtor."; | 96 CHECK_EQ(clients_.size(), 0U) << "Must call UnInitialize before dtor."; |
| 97 Clear(); | 97 Clear(); |
|
Pawel Osciak
2014/08/14 05:11:07
Should we assert that pending frames are empty?
Owen Lin
2014/08/14 10:55:35
It's OK to have pending frames, Clear() will also
| |
| 98 } | 98 } |
| 99 | 99 |
| 100 void RenderingHelper::Initialize(const RenderingHelperParams& params, | 100 void RenderingHelper::Initialize(const RenderingHelperParams& params, |
| 101 base::WaitableEvent* done) { | 101 base::WaitableEvent* done) { |
| 102 // Use clients_.size() != 0 as a proxy for the class having already been | 102 // Use clients_.size() != 0 as a proxy for the class having already been |
| 103 // Initialize()'d, and UnInitialize() before continuing. | 103 // Initialize()'d, and UnInitialize() before continuing. |
| 104 if (clients_.size()) { | 104 if (clients_.size()) { |
| 105 base::WaitableEvent done(false, false); | 105 base::WaitableEvent done(false, false); |
| 106 UnInitialize(&done); | 106 UnInitialize(&done); |
| 107 done.Wait(); | 107 done.Wait(); |
| (...skipping 375 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 483 *rgb_ptr++ = *rgba_ptr++; | 483 *rgb_ptr++ = *rgba_ptr++; |
| 484 *rgb_ptr++ = *rgba_ptr++; | 484 *rgb_ptr++ = *rgba_ptr++; |
| 485 solid = solid && (*rgba_ptr == 0xff); | 485 solid = solid && (*rgba_ptr == 0xff); |
| 486 rgba_ptr++; | 486 rgba_ptr++; |
| 487 } | 487 } |
| 488 *alpha_solid = solid; | 488 *alpha_solid = solid; |
| 489 | 489 |
| 490 done->Signal(); | 490 done->Signal(); |
| 491 } | 491 } |
| 492 | 492 |
| 493 void RenderingHelper::SetWaitRenderingCB( | |
| 494 size_t window_id, | |
| 495 const base::Closure& wait_rendering_cb) { | |
| 496 RenderingClient* client = &clients_[window_id]; | |
| 497 if (client->pending_frames.empty() || client->last_frame_rendered) { | |
| 498 // The rendering has been completed. | |
| 499 wait_rendering_cb.Run(); | |
| 500 return; | |
| 501 } | |
| 502 client->wait_rendering_cb = wait_rendering_cb; | |
| 503 } | |
| 504 | |
| 493 void RenderingHelper::RenderContent() { | 505 void RenderingHelper::RenderContent() { |
| 494 CHECK_EQ(base::MessageLoop::current(), message_loop_); | 506 CHECK_EQ(base::MessageLoop::current(), message_loop_); |
| 495 glUniform1i(glGetUniformLocation(program_, "tex_flip"), 1); | 507 glUniform1i(glGetUniformLocation(program_, "tex_flip"), 1); |
| 496 | 508 |
| 497 if (render_as_thumbnails_) { | 509 if (render_as_thumbnails_) { |
| 498 // In render_as_thumbnails_ mode, we render the FBO content on the | 510 // In render_as_thumbnails_ mode, we render the FBO content on the |
| 499 // screen instead of the decoded textures. | 511 // screen instead of the decoded textures. |
| 500 GLSetViewPort(clients_[0].render_area); | 512 GLSetViewPort(clients_[0].render_area); |
| 501 RenderTexture(GL_TEXTURE_2D, thumbnails_texture_id_); | 513 RenderTexture(GL_TEXTURE_2D, thumbnails_texture_id_); |
| 502 gl_surface_->SwapBuffers(); | 514 gl_surface_->SwapBuffers(); |
| (...skipping 14 matching lines...) Expand all Loading... | |
| 517 // Releases the rendered frame after SwapBuffers() if it is not the last one. | 529 // Releases the rendered frame after SwapBuffers() if it is not the last one. |
| 518 for (size_t i = 0; i < clients_.size(); ++i) { | 530 for (size_t i = 0; i < clients_.size(); ++i) { |
| 519 RenderingClient* client = &clients_[i]; | 531 RenderingClient* client = &clients_[i]; |
| 520 if (client->pending_frames.size() > 1) { | 532 if (client->pending_frames.size() > 1) { |
| 521 delete client->pending_frames.front(); | 533 delete client->pending_frames.front(); |
| 522 client->pending_frames.pop_front(); | 534 client->pending_frames.pop_front(); |
| 523 client->last_frame_rendered = false; | 535 client->last_frame_rendered = false; |
| 524 continue; | 536 continue; |
| 525 } | 537 } |
| 526 client->last_frame_rendered = true; | 538 client->last_frame_rendered = true; |
| 539 if (!client->wait_rendering_cb.is_null()) | |
| 540 base::ResetAndReturn(&client->wait_rendering_cb).Run(); | |
|
Pawel Osciak
2014/08/14 05:11:07
I think we have to pop the last frame here?
Owen Lin
2014/08/14 10:55:35
Done.
| |
| 527 } | 541 } |
| 528 } | 542 } |
| 529 | 543 |
| 530 // Helper function for the LayoutRenderingAreas(). The |lengths| are the | 544 // Helper function for the LayoutRenderingAreas(). The |lengths| are the |
| 531 // heights(widths) of the rows(columns). It scales the elements in | 545 // heights(widths) of the rows(columns). It scales the elements in |
| 532 // |lengths| proportionally so that the sum of them equal to |total_length|. | 546 // |lengths| proportionally so that the sum of them equal to |total_length|. |
| 533 // It also outputs the coordinates of the rows(columns) to |offsets|. | 547 // It also outputs the coordinates of the rows(columns) to |offsets|. |
| 534 static void ScaleAndCalculateOffsets(std::vector<int>* lengths, | 548 static void ScaleAndCalculateOffsets(std::vector<int>* lengths, |
| 535 std::vector<int>* offsets, | 549 std::vector<int>* offsets, |
| 536 int total_length) { | 550 int total_length) { |
| (...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 574 scale = std::min(1.0f, scale); | 588 scale = std::min(1.0f, scale); |
| 575 | 589 |
| 576 size_t w = scale * size.width(); | 590 size_t w = scale * size.width(); |
| 577 size_t h = scale * size.height(); | 591 size_t h = scale * size.height(); |
| 578 size_t x = offset_x[i % cols] + (widths[i % cols] - w) / 2; | 592 size_t x = offset_x[i % cols] + (widths[i % cols] - w) / 2; |
| 579 size_t y = offset_y[i / cols] + (heights[i / cols] - h) / 2; | 593 size_t y = offset_y[i / cols] + (heights[i / cols] - h) / 2; |
| 580 clients_[i].render_area = gfx::Rect(x, y, w, h); | 594 clients_[i].render_area = gfx::Rect(x, y, w, h); |
| 581 } | 595 } |
| 582 } | 596 } |
| 583 } // namespace content | 597 } // namespace content |
| OLD | NEW |