| 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::GetThumbnailsAsRGB(std::vector<unsigned char>* rgb, | 713 void RenderingHelper::GetThumbnailsAsRGBA(std::vector<unsigned char>* rgba, |
| 714 bool* alpha_solid, | 714 base::WaitableEvent* done) { |
| 715 base::WaitableEvent* done) { | |
| 716 CHECK(render_as_thumbnails_); | 715 CHECK(render_as_thumbnails_); |
| 717 | 716 |
| 718 const size_t num_pixels = thumbnails_fbo_size_.GetArea(); | 717 const size_t num_pixels = thumbnails_fbo_size_.GetArea(); |
| 719 std::vector<unsigned char> rgba; | 718 rgba->resize(num_pixels * 4); |
| 720 rgba.resize(num_pixels * 4); | |
| 721 glBindFramebufferEXT(GL_FRAMEBUFFER, thumbnails_fbo_id_); | 719 glBindFramebufferEXT(GL_FRAMEBUFFER, thumbnails_fbo_id_); |
| 722 glPixelStorei(GL_PACK_ALIGNMENT, 1); | 720 glPixelStorei(GL_PACK_ALIGNMENT, 1); |
| 723 // We can only count on GL_RGBA/GL_UNSIGNED_BYTE support. | 721 // We can only count on GL_RGBA/GL_UNSIGNED_BYTE support. |
| 724 glReadPixels(0, 0, | 722 glReadPixels(0, 0, thumbnails_fbo_size_.width(), |
| 725 thumbnails_fbo_size_.width(), thumbnails_fbo_size_.height(), | 723 thumbnails_fbo_size_.height(), GL_RGBA, GL_UNSIGNED_BYTE, |
| 726 GL_RGBA, | 724 &(*rgba)[0]); |
| 727 GL_UNSIGNED_BYTE, | |
| 728 &rgba[0]); | |
| 729 glBindFramebufferEXT(GL_FRAMEBUFFER, | 725 glBindFramebufferEXT(GL_FRAMEBUFFER, |
| 730 gl_surface_->GetBackingFramebufferObject()); | 726 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; | |
| 744 | 727 |
| 745 done->Signal(); | 728 done->Signal(); |
| 746 } | 729 } |
| 747 | 730 |
| 748 void RenderingHelper::Flush(size_t window_id) { | 731 void RenderingHelper::Flush(size_t window_id) { |
| 749 videos_[window_id].is_flushing = true; | 732 videos_[window_id].is_flushing = true; |
| 750 } | 733 } |
| 751 | 734 |
| 752 void RenderingHelper::RenderContent() { | 735 void RenderingHelper::RenderContent() { |
| 753 CHECK(task_runner_->BelongsToCurrentThread()); | 736 CHECK(task_runner_->BelongsToCurrentThread()); |
| (...skipping 158 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 912 // When the rendering falls behind, drops frames. | 895 // When the rendering falls behind, drops frames. |
| 913 while (scheduled_render_time_ < target) { | 896 while (scheduled_render_time_ < target) { |
| 914 scheduled_render_time_ += frame_duration_; | 897 scheduled_render_time_ += frame_duration_; |
| 915 DropOneFrameForAllVideos(); | 898 DropOneFrameForAllVideos(); |
| 916 } | 899 } |
| 917 | 900 |
| 918 task_runner_->PostDelayedTask(FROM_HERE, render_task_.callback(), | 901 task_runner_->PostDelayedTask(FROM_HERE, render_task_.callback(), |
| 919 target - now); | 902 target - now); |
| 920 } | 903 } |
| 921 } // namespace media | 904 } // namespace media |
| OLD | NEW |