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 "media/gpu/rendering_helper.h" | 5 #include "media/gpu/rendering_helper.h" |
6 | 6 |
7 #include <string.h> | 7 #include <string.h> |
8 | 8 |
9 #include <algorithm> | 9 #include <algorithm> |
10 #include <memory> | 10 #include <memory> |
11 #include <numeric> | 11 #include <numeric> |
12 #include <vector> | 12 #include <vector> |
13 | 13 |
14 #include "base/bind.h" | 14 #include "base/bind.h" |
15 #include "base/callback_helpers.h" | 15 #include "base/callback_helpers.h" |
16 #include "base/command_line.h" | 16 #include "base/command_line.h" |
17 #include "base/mac/scoped_nsautorelease_pool.h" | 17 #include "base/mac/scoped_nsautorelease_pool.h" |
18 #include "base/macros.h" | 18 #include "base/macros.h" |
19 #include "base/message_loop/message_loop.h" | 19 #include "base/message_loop/message_loop.h" |
20 #include "base/run_loop.h" | 20 #include "base/run_loop.h" |
| 21 #include "base/single_thread_task_runner.h" |
21 #include "base/strings/stringize_macros.h" | 22 #include "base/strings/stringize_macros.h" |
22 #include "base/synchronization/waitable_event.h" | 23 #include "base/synchronization/waitable_event.h" |
23 #include "base/time/time.h" | 24 #include "base/time/time.h" |
24 #include "build/build_config.h" | 25 #include "build/build_config.h" |
25 #include "ui/gl/gl_context.h" | 26 #include "ui/gl/gl_context.h" |
26 #include "ui/gl/gl_implementation.h" | 27 #include "ui/gl/gl_implementation.h" |
27 #include "ui/gl/gl_surface.h" | 28 #include "ui/gl/gl_surface.h" |
28 #include "ui/gl/init/gl_factory.h" | 29 #include "ui/gl/init/gl_factory.h" |
29 | 30 |
30 #if defined(OS_WIN) | 31 #if defined(OS_WIN) |
(...skipping 522 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
553 | 554 |
554 Clear(); | 555 Clear(); |
555 done->Signal(); | 556 done->Signal(); |
556 } | 557 } |
557 | 558 |
558 void RenderingHelper::CreateTexture(uint32_t texture_target, | 559 void RenderingHelper::CreateTexture(uint32_t texture_target, |
559 uint32_t* texture_id, | 560 uint32_t* texture_id, |
560 const gfx::Size& size, | 561 const gfx::Size& size, |
561 base::WaitableEvent* done) { | 562 base::WaitableEvent* done) { |
562 if (base::MessageLoop::current() != message_loop_) { | 563 if (base::MessageLoop::current() != message_loop_) { |
563 message_loop_->PostTask( | 564 message_loop_->task_runner()->PostTask( |
564 FROM_HERE, | 565 FROM_HERE, |
565 base::Bind(&RenderingHelper::CreateTexture, base::Unretained(this), | 566 base::Bind(&RenderingHelper::CreateTexture, base::Unretained(this), |
566 texture_target, texture_id, size, done)); | 567 texture_target, texture_id, size, done)); |
567 return; | 568 return; |
568 } | 569 } |
569 glGenTextures(1, texture_id); | 570 glGenTextures(1, texture_id); |
570 glBindTexture(texture_target, *texture_id); | 571 glBindTexture(texture_target, *texture_id); |
571 if (texture_target == GL_TEXTURE_2D) { | 572 if (texture_target == GL_TEXTURE_2D) { |
572 glTexImage2D(GL_TEXTURE_2D, | 573 glTexImage2D(GL_TEXTURE_2D, |
573 0, | 574 0, |
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
628 video->pending_frames.push(video_frame); | 629 video->pending_frames.push(video_frame); |
629 | 630 |
630 if (video->frames_to_drop > 0 && video->pending_frames.size() > 1) { | 631 if (video->frames_to_drop > 0 && video->pending_frames.size() > 1) { |
631 --video->frames_to_drop; | 632 --video->frames_to_drop; |
632 video->pending_frames.pop(); | 633 video->pending_frames.pop(); |
633 } | 634 } |
634 | 635 |
635 // Schedules the first RenderContent() if need. | 636 // Schedules the first RenderContent() if need. |
636 if (scheduled_render_time_.is_null()) { | 637 if (scheduled_render_time_.is_null()) { |
637 scheduled_render_time_ = base::TimeTicks::Now(); | 638 scheduled_render_time_ = base::TimeTicks::Now(); |
638 message_loop_->PostTask(FROM_HERE, render_task_.callback()); | 639 message_loop_->task_runner()->PostTask(FROM_HERE, render_task_.callback()); |
639 } | 640 } |
640 } | 641 } |
641 | 642 |
642 void RenderingHelper::RenderTexture(uint32_t texture_target, | 643 void RenderingHelper::RenderTexture(uint32_t texture_target, |
643 uint32_t texture_id) { | 644 uint32_t texture_id) { |
644 // The ExternalOES sampler is bound to GL_TEXTURE1 and the Texture2D sampler | 645 // The ExternalOES sampler is bound to GL_TEXTURE1 and the Texture2D sampler |
645 // is bound to GL_TEXTURE0. | 646 // is bound to GL_TEXTURE0. |
646 if (texture_target == GL_TEXTURE_2D) { | 647 if (texture_target == GL_TEXTURE_2D) { |
647 glActiveTexture(GL_TEXTURE0 + 0); | 648 glActiveTexture(GL_TEXTURE0 + 0); |
648 } else if (texture_target == GL_TEXTURE_EXTERNAL_OES) { | 649 } else if (texture_target == GL_TEXTURE_EXTERNAL_OES) { |
(...skipping 229 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
878 int64_t intervals = (target - vsync_timebase_) / vsync_interval_; | 879 int64_t intervals = (target - vsync_timebase_) / vsync_interval_; |
879 target = vsync_timebase_ + intervals * vsync_interval_; | 880 target = vsync_timebase_ + intervals * vsync_interval_; |
880 } | 881 } |
881 | 882 |
882 // When the rendering falls behind, drops frames. | 883 // When the rendering falls behind, drops frames. |
883 while (scheduled_render_time_ < target) { | 884 while (scheduled_render_time_ < target) { |
884 scheduled_render_time_ += frame_duration_; | 885 scheduled_render_time_ += frame_duration_; |
885 DropOneFrameForAllVideos(); | 886 DropOneFrameForAllVideos(); |
886 } | 887 } |
887 | 888 |
888 message_loop_->PostDelayedTask(FROM_HERE, render_task_.callback(), | 889 message_loop_->task_runner()->PostDelayedTask( |
889 target - now); | 890 FROM_HERE, render_task_.callback(), target - now); |
890 } | 891 } |
891 } // namespace media | 892 } // namespace media |
OLD | NEW |