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> |
(...skipping 692 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
703 task_runner_ = nullptr; | 703 task_runner_ = nullptr; |
704 gl_context_ = NULL; | 704 gl_context_ = NULL; |
705 gl_surface_ = NULL; | 705 gl_surface_ = NULL; |
706 | 706 |
707 render_as_thumbnails_ = false; | 707 render_as_thumbnails_ = false; |
708 frame_count_ = 0; | 708 frame_count_ = 0; |
709 thumbnails_fbo_id_ = 0; | 709 thumbnails_fbo_id_ = 0; |
710 thumbnails_texture_id_ = 0; | 710 thumbnails_texture_id_ = 0; |
711 } | 711 } |
712 | 712 |
713 void RenderingHelper::GetThumbnailsAsRGBA(std::vector<unsigned char>* rgba, | 713 void RenderingHelper::GetThumbnailsAsRGB(std::vector<unsigned char>* rgb, |
714 base::WaitableEvent* done) { | 714 bool* alpha_solid, |
| 715 base::WaitableEvent* done) { |
715 CHECK(render_as_thumbnails_); | 716 CHECK(render_as_thumbnails_); |
716 | 717 |
717 const size_t num_pixels = thumbnails_fbo_size_.GetArea(); | 718 const size_t num_pixels = thumbnails_fbo_size_.GetArea(); |
718 rgba->resize(num_pixels * 4); | 719 std::vector<unsigned char> rgba; |
| 720 rgba.resize(num_pixels * 4); |
719 glBindFramebufferEXT(GL_FRAMEBUFFER, thumbnails_fbo_id_); | 721 glBindFramebufferEXT(GL_FRAMEBUFFER, thumbnails_fbo_id_); |
720 glPixelStorei(GL_PACK_ALIGNMENT, 1); | 722 glPixelStorei(GL_PACK_ALIGNMENT, 1); |
721 // We can only count on GL_RGBA/GL_UNSIGNED_BYTE support. | 723 // We can only count on GL_RGBA/GL_UNSIGNED_BYTE support. |
722 glReadPixels(0, 0, | 724 glReadPixels(0, 0, |
723 thumbnails_fbo_size_.width(), thumbnails_fbo_size_.height(), | 725 thumbnails_fbo_size_.width(), thumbnails_fbo_size_.height(), |
724 GL_RGBA, | 726 GL_RGBA, |
725 GL_UNSIGNED_BYTE, | 727 GL_UNSIGNED_BYTE, |
726 &rgba[0]); | 728 &rgba[0]); |
727 glBindFramebufferEXT(GL_FRAMEBUFFER, | 729 glBindFramebufferEXT(GL_FRAMEBUFFER, |
728 gl_surface_->GetBackingFramebufferObject()); | 730 gl_surface_->GetBackingFramebufferObject()); |
| 731 rgb->resize(num_pixels * 3); |
| 732 // Drop the alpha channel, but check as we go that it is all 0xff. |
| 733 bool solid = true; |
| 734 unsigned char* rgb_ptr = &((*rgb)[0]); |
| 735 unsigned char* rgba_ptr = &rgba[0]; |
| 736 for (size_t i = 0; i < num_pixels; ++i) { |
| 737 *rgb_ptr++ = *rgba_ptr++; |
| 738 *rgb_ptr++ = *rgba_ptr++; |
| 739 *rgb_ptr++ = *rgba_ptr++; |
| 740 solid = solid && (*rgba_ptr == 0xff); |
| 741 rgba_ptr++; |
| 742 } |
| 743 *alpha_solid = solid; |
729 | 744 |
730 done->Signal(); | 745 done->Signal(); |
731 } | 746 } |
732 | 747 |
733 void RenderingHelper::Flush(size_t window_id) { | 748 void RenderingHelper::Flush(size_t window_id) { |
734 videos_[window_id].is_flushing = true; | 749 videos_[window_id].is_flushing = true; |
735 } | 750 } |
736 | 751 |
737 void RenderingHelper::RenderContent() { | 752 void RenderingHelper::RenderContent() { |
738 CHECK(task_runner_->BelongsToCurrentThread()); | 753 CHECK(task_runner_->BelongsToCurrentThread()); |
(...skipping 158 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
897 // When the rendering falls behind, drops frames. | 912 // When the rendering falls behind, drops frames. |
898 while (scheduled_render_time_ < target) { | 913 while (scheduled_render_time_ < target) { |
899 scheduled_render_time_ += frame_duration_; | 914 scheduled_render_time_ += frame_duration_; |
900 DropOneFrameForAllVideos(); | 915 DropOneFrameForAllVideos(); |
901 } | 916 } |
902 | 917 |
903 task_runner_->PostDelayedTask(FROM_HERE, render_task_.callback(), | 918 task_runner_->PostDelayedTask(FROM_HERE, render_task_.callback(), |
904 target - now); | 919 target - now); |
905 } | 920 } |
906 } // namespace media | 921 } // namespace media |
OLD | NEW |