Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(197)

Side by Side Diff: content/common/gpu/media/rendering_helper.cc

Issue 465293002: rendering_helper - Wait for rendering before resetting the decoder. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: address review comments Created 6 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 370 matching lines...) Expand 10 before | Expand all | Expand 10 after
381 381
382 // Need to flush the GL commands before we return the tnumbnail texture to 382 // Need to flush the GL commands before we return the tnumbnail texture to
383 // the decoder. 383 // the decoder.
384 glFlush(); 384 glFlush();
385 ++frame_count_; 385 ++frame_count_;
386 } 386 }
387 387
388 void RenderingHelper::QueueVideoFrame(size_t window_id, 388 void RenderingHelper::QueueVideoFrame(size_t window_id,
389 scoped_refptr<VideoFrame> video_frame) { 389 scoped_refptr<VideoFrame> video_frame) {
390 RenderedVideo* video = &videos_[window_id]; 390 RenderedVideo* video = &videos_[window_id];
391 DCHECK(!video->is_flushing);
391 392
392 // Pop the front if it has been rendered. 393 // Pop the front if it has been rendered.
393 if (video->last_frame_rendered) { 394 if (video->last_frame_rendered) {
394 DCHECK(!video->pending_frames.empty()); 395 DCHECK(!video->pending_frames.empty());
395 video->pending_frames.pop_front(); 396 video->pending_frames.pop_front();
396 video->last_frame_rendered = false; 397 video->last_frame_rendered = false;
397 } 398 }
398 399
399 video->pending_frames.push_back(video_frame); 400 video->pending_frames.push_back(video_frame);
400 } 401 }
(...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after
485 *rgb_ptr++ = *rgba_ptr++; 486 *rgb_ptr++ = *rgba_ptr++;
486 *rgb_ptr++ = *rgba_ptr++; 487 *rgb_ptr++ = *rgba_ptr++;
487 solid = solid && (*rgba_ptr == 0xff); 488 solid = solid && (*rgba_ptr == 0xff);
488 rgba_ptr++; 489 rgba_ptr++;
489 } 490 }
490 *alpha_solid = solid; 491 *alpha_solid = solid;
491 492
492 done->Signal(); 493 done->Signal();
493 } 494 }
494 495
496 void RenderingHelper::Flush(size_t window_id,
497 const base::Closure& flush_done_cb) {
498 RenderedVideo* video = &videos_[window_id];
499 if (video->pending_frames.empty()) {
500 // The rendering has been completed.
501 flush_done_cb.Run();
502 return;
503 }
504 video->is_flushing = true;
505 video->flush_done_cb = flush_done_cb;
506 }
507
495 void RenderingHelper::RenderContent() { 508 void RenderingHelper::RenderContent() {
496 CHECK_EQ(base::MessageLoop::current(), message_loop_); 509 CHECK_EQ(base::MessageLoop::current(), message_loop_);
497 glUniform1i(glGetUniformLocation(program_, "tex_flip"), 1); 510 glUniform1i(glGetUniformLocation(program_, "tex_flip"), 1);
498 511
499 // To keep the frame before SwapBuffers() 512 // To keep the frame before SwapBuffers()
500 std::vector<scoped_refptr<VideoFrame> > frames_to_be_returned; 513 std::vector<scoped_refptr<VideoFrame> > frames_to_be_returned;
501 514
502 if (render_as_thumbnails_) { 515 if (render_as_thumbnails_) {
503 // In render_as_thumbnails_ mode, we render the FBO content on the 516 // In render_as_thumbnails_ mode, we render the FBO content on the
504 // screen instead of the decoded textures. 517 // screen instead of the decoded textures.
505 GLSetViewPort(videos_[0].render_area); 518 GLSetViewPort(videos_[0].render_area);
506 RenderTexture(GL_TEXTURE_2D, thumbnails_texture_id_); 519 RenderTexture(GL_TEXTURE_2D, thumbnails_texture_id_);
507 } else { 520 } else {
508 for (size_t i = 0; i < videos_.size(); ++i) { 521 for (size_t i = 0; i < videos_.size(); ++i) {
509 RenderedVideo* video = &videos_[i]; 522 RenderedVideo* video = &videos_[i];
510 if (video->pending_frames.empty()) 523 if (video->pending_frames.empty())
511 continue; 524 continue;
512 scoped_refptr<VideoFrame> frame = video->pending_frames.front(); 525 scoped_refptr<VideoFrame> frame = video->pending_frames.front();
513 GLSetViewPort(video->render_area); 526 GLSetViewPort(video->render_area);
514 RenderTexture(frame->texture_target(), frame->texture_id()); 527 RenderTexture(frame->texture_target(), frame->texture_id());
515 528
516 if (video->pending_frames.size() > 1) { 529 if (video->pending_frames.size() > 1 || video->is_flushing) {
517 frames_to_be_returned.push_back(video->pending_frames.front()); 530 frames_to_be_returned.push_back(video->pending_frames.front());
518 video->pending_frames.pop_front(); 531 video->pending_frames.pop_front();
519 } else { 532 } else {
520 video->last_frame_rendered = true; 533 video->last_frame_rendered = true;
521 } 534 }
535
536 if (video->is_flushing && video->pending_frames.empty() &&
537 !video->flush_done_cb.is_null())
538 base::ResetAndReturn(&video->flush_done_cb).Run();
522 } 539 }
523 } 540 }
524 541
525 gl_surface_->SwapBuffers(); 542 gl_surface_->SwapBuffers();
526 } 543 }
527 544
528 // Helper function for the LayoutRenderingAreas(). The |lengths| are the 545 // Helper function for the LayoutRenderingAreas(). The |lengths| are the
529 // heights(widths) of the rows(columns). It scales the elements in 546 // heights(widths) of the rows(columns). It scales the elements in
530 // |lengths| proportionally so that the sum of them equal to |total_length|. 547 // |lengths| proportionally so that the sum of them equal to |total_length|.
531 // It also outputs the coordinates of the rows(columns) to |offsets|. 548 // It also outputs the coordinates of the rows(columns) to |offsets|.
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after
572 scale = std::min(1.0f, scale); 589 scale = std::min(1.0f, scale);
573 590
574 size_t w = scale * size.width(); 591 size_t w = scale * size.width();
575 size_t h = scale * size.height(); 592 size_t h = scale * size.height();
576 size_t x = offset_x[i % cols] + (widths[i % cols] - w) / 2; 593 size_t x = offset_x[i % cols] + (widths[i % cols] - w) / 2;
577 size_t y = offset_y[i / cols] + (heights[i / cols] - h) / 2; 594 size_t y = offset_y[i / cols] + (heights[i / cols] - h) / 2;
578 videos_[i].render_area = gfx::Rect(x, y, w, h); 595 videos_[i].render_area = gfx::Rect(x, y, w, h);
579 } 596 }
580 } 597 }
581 } // namespace content 598 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698