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 bool* alpha_solid, |
715 base::WaitableEvent* done) { | 715 base::WaitableEvent* done) { |
716 CHECK(render_as_thumbnails_); | 716 CHECK(render_as_thumbnails_); |
717 | 717 |
718 const size_t num_pixels = thumbnails_fbo_size_.GetArea(); | 718 const size_t num_pixels = thumbnails_fbo_size_.GetArea(); |
719 std::vector<unsigned char> rgba; | 719 rgba->resize(num_pixels * 4); |
720 rgba.resize(num_pixels * 4); | |
721 glBindFramebufferEXT(GL_FRAMEBUFFER, thumbnails_fbo_id_); | 720 glBindFramebufferEXT(GL_FRAMEBUFFER, thumbnails_fbo_id_); |
722 glPixelStorei(GL_PACK_ALIGNMENT, 1); | 721 glPixelStorei(GL_PACK_ALIGNMENT, 1); |
723 // We can only count on GL_RGBA/GL_UNSIGNED_BYTE support. | 722 // We can only count on GL_RGBA/GL_UNSIGNED_BYTE support. |
724 glReadPixels(0, 0, | 723 glReadPixels(0, 0, |
725 thumbnails_fbo_size_.width(), thumbnails_fbo_size_.height(), | 724 thumbnails_fbo_size_.width(), thumbnails_fbo_size_.height(), |
726 GL_RGBA, | 725 GL_RGBA, |
727 GL_UNSIGNED_BYTE, | 726 GL_UNSIGNED_BYTE, |
728 &rgba[0]); | 727 &rgba[0]); |
729 glBindFramebufferEXT(GL_FRAMEBUFFER, | 728 glBindFramebufferEXT(GL_FRAMEBUFFER, |
730 gl_surface_->GetBackingFramebufferObject()); | 729 gl_surface_->GetBackingFramebufferObject()); |
731 rgb->resize(num_pixels * 3); | 730 |
732 // Drop the alpha channel, but check as we go that it is all 0xff. | 731 // Check if the alpha channel is all 0xff. |
733 bool solid = true; | 732 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) { | 733 for (size_t i = 0; i < num_pixels; ++i) { |
737 *rgb_ptr++ = *rgba_ptr++; | 734 solid = solid && ((*rgba)[4 * i + 3] == 0xff); |
scroggo_chromium
2017/06/13 14:54:00
Once solid is false, there's no need to continue t
msarett1
2017/06/13 16:32:03
sgtm, done.
| |
738 *rgb_ptr++ = *rgba_ptr++; | |
739 *rgb_ptr++ = *rgba_ptr++; | |
740 solid = solid && (*rgba_ptr == 0xff); | |
741 rgba_ptr++; | |
742 } | 735 } |
743 *alpha_solid = solid; | 736 *alpha_solid = solid; |
744 | 737 |
745 done->Signal(); | 738 done->Signal(); |
746 } | 739 } |
747 | 740 |
748 void RenderingHelper::Flush(size_t window_id) { | 741 void RenderingHelper::Flush(size_t window_id) { |
749 videos_[window_id].is_flushing = true; | 742 videos_[window_id].is_flushing = true; |
750 } | 743 } |
751 | 744 |
(...skipping 160 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
912 // When the rendering falls behind, drops frames. | 905 // When the rendering falls behind, drops frames. |
913 while (scheduled_render_time_ < target) { | 906 while (scheduled_render_time_ < target) { |
914 scheduled_render_time_ += frame_duration_; | 907 scheduled_render_time_ += frame_duration_; |
915 DropOneFrameForAllVideos(); | 908 DropOneFrameForAllVideos(); |
916 } | 909 } |
917 | 910 |
918 task_runner_->PostDelayedTask(FROM_HERE, render_task_.callback(), | 911 task_runner_->PostDelayedTask(FROM_HERE, render_task_.callback(), |
919 target - now); | 912 target - now); |
920 } | 913 } |
921 } // namespace media | 914 } // namespace media |
OLD | NEW |