| OLD | NEW |
| 1 // Copyright 2010 The Chromium Authors. All rights reserved. | 1 // Copyright 2010 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 "cc/output/gl_renderer.h" | 5 #include "cc/output/gl_renderer.h" |
| 6 | 6 |
| 7 #include <stddef.h> | 7 #include <stddef.h> |
| 8 #include <stdint.h> | 8 #include <stdint.h> |
| 9 | 9 |
| 10 #include <algorithm> | 10 #include <algorithm> |
| (...skipping 2767 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2778 swap_buffer_rect_ = gfx::Rect(surface_size); | 2778 swap_buffer_rect_ = gfx::Rect(surface_size); |
| 2779 } | 2779 } |
| 2780 compositor_frame.gl_frame_data->sub_buffer_rect = swap_buffer_rect_; | 2780 compositor_frame.gl_frame_data->sub_buffer_rect = swap_buffer_rect_; |
| 2781 } | 2781 } |
| 2782 | 2782 |
| 2783 swapping_overlay_resources_.push_back(std::move(pending_overlay_resources_)); | 2783 swapping_overlay_resources_.push_back(std::move(pending_overlay_resources_)); |
| 2784 pending_overlay_resources_.clear(); | 2784 pending_overlay_resources_.clear(); |
| 2785 | 2785 |
| 2786 // We always hold onto resources until an extra frame has swapped, to make | 2786 // We always hold onto resources until an extra frame has swapped, to make |
| 2787 // sure we don't update the buffer while it's being scanned out. | 2787 // sure we don't update the buffer while it's being scanned out. |
| 2788 if (!settings_->release_overlay_resources_on_swap_complete && | 2788 if (!settings_->release_overlay_resources_after_gpu_query && |
| 2789 swapping_overlay_resources_.size() > 2) { | 2789 swapping_overlay_resources_.size() > 2) { |
| 2790 swapping_overlay_resources_.pop_front(); | 2790 swapping_overlay_resources_.pop_front(); |
| 2791 } | 2791 } |
| 2792 | 2792 |
| 2793 output_surface_->SwapBuffers(&compositor_frame); | 2793 output_surface_->SwapBuffers(&compositor_frame); |
| 2794 | 2794 |
| 2795 swap_buffer_rect_ = gfx::Rect(); | 2795 swap_buffer_rect_ = gfx::Rect(); |
| 2796 } | 2796 } |
| 2797 | 2797 |
| 2798 void GLRenderer::SwapBuffersComplete() { | 2798 void GLRenderer::SwapBuffersComplete() { |
| 2799 // On OS X, the logic in this block moves resources into | 2799 // Once a resouce has been swap-ACKed, send a query to the GPU process to ask |
| 2800 // |swapped_and_acked_overlay_resources_|, and then erases resources from | 2800 // if the resource is no longer being consumed by the system compositor. The |
| 2801 // |swapped_and_acked_overlay_resources_| that are no longer in use by the | 2801 // response will come with the next swap-ACK. |
| 2802 // Window Server. On other platforms, since resources are never in use by the | 2802 if (settings_->release_overlay_resources_after_gpu_query) { |
| 2803 // Window Server, this is equivalent to just erasing all resources from the | |
| 2804 // first element of |swapping_overlay_resources_|. | |
| 2805 if (settings_->release_overlay_resources_on_swap_complete) { | |
| 2806 // Move resources known to be acked into | |
| 2807 // |swapped_and_acked_overlay_resources_|. | |
| 2808 if (!swapping_overlay_resources_.empty()) { | 2803 if (!swapping_overlay_resources_.empty()) { |
| 2809 for (OverlayResourceLock& lock : swapping_overlay_resources_.front()) { | 2804 for (OverlayResourceLock& lock : swapping_overlay_resources_.front()) { |
| 2810 swapped_and_acked_overlay_resources_[lock->resource_id()] = | 2805 unsigned texture = lock->texture_id(); |
| 2811 std::move(lock); | 2806 if (swapped_and_acked_overlay_resources_.find(texture) == |
| 2807 swapped_and_acked_overlay_resources_.end()) { |
| 2808 swapped_and_acked_overlay_resources_[texture] = std::move(lock); |
| 2809 } |
| 2812 } | 2810 } |
| 2813 swapping_overlay_resources_.pop_front(); | 2811 swapping_overlay_resources_.pop_front(); |
| 2814 } | 2812 } |
| 2815 | 2813 |
| 2816 // Release resources that are no longer in use by the Window Server. | 2814 if (!swapped_and_acked_overlay_resources_.empty()) { |
| 2817 auto it = swapped_and_acked_overlay_resources_.begin(); | 2815 std::vector<unsigned> textures; |
| 2818 while (it != swapped_and_acked_overlay_resources_.end()) { | 2816 textures.reserve(swapped_and_acked_overlay_resources_.size()); |
| 2819 if (it->second->gpu_memory_buffer() && | 2817 for (auto& pair : swapped_and_acked_overlay_resources_) { |
| 2820 it->second->gpu_memory_buffer()->IsInUseByMacOSWindowServer()) { | 2818 textures.push_back(pair.first); |
| 2821 ++it; | |
| 2822 continue; | |
| 2823 } | 2819 } |
| 2824 | 2820 gl_->ScheduleCALayerInUseQueryCHROMIUM(textures.size(), textures.data()); |
| 2825 it = swapped_and_acked_overlay_resources_.erase(it); | |
| 2826 } | 2821 } |
| 2827 } | 2822 } |
| 2828 } | 2823 } |
| 2824 |
| 2825 void GLRenderer::DidReceiveTextureInUseResponses( |
| 2826 const gpu::TextureInUseResponses& responses) { |
| 2827 DCHECK(settings_->release_overlay_resources_after_gpu_query); |
| 2828 for (const gpu::TextureInUseResponse& response : responses) { |
| 2829 if (!response.in_use) { |
| 2830 swapped_and_acked_overlay_resources_.erase(response.texture); |
| 2831 } |
| 2832 } |
| 2833 } |
| 2829 | 2834 |
| 2830 void GLRenderer::EnforceMemoryPolicy() { | 2835 void GLRenderer::EnforceMemoryPolicy() { |
| 2831 if (!visible()) { | 2836 if (!visible()) { |
| 2832 TRACE_EVENT0("cc", "GLRenderer::EnforceMemoryPolicy dropping resources"); | 2837 TRACE_EVENT0("cc", "GLRenderer::EnforceMemoryPolicy dropping resources"); |
| 2833 ReleaseRenderPassTextures(); | 2838 ReleaseRenderPassTextures(); |
| 2834 DiscardBackbuffer(); | 2839 DiscardBackbuffer(); |
| 2835 output_surface_->context_provider()->DeleteCachedResources(); | 2840 output_surface_->context_provider()->DeleteCachedResources(); |
| 2836 gl_->Flush(); | 2841 gl_->Flush(); |
| 2837 } | 2842 } |
| 2838 PrepareGeometry(NO_BINDING); | 2843 PrepareGeometry(NO_BINDING); |
| (...skipping 889 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3728 texture_id = pending_overlay_resources_.back()->texture_id(); | 3733 texture_id = pending_overlay_resources_.back()->texture_id(); |
| 3729 } | 3734 } |
| 3730 | 3735 |
| 3731 context_support_->ScheduleOverlayPlane( | 3736 context_support_->ScheduleOverlayPlane( |
| 3732 overlay.plane_z_order, overlay.transform, texture_id, | 3737 overlay.plane_z_order, overlay.transform, texture_id, |
| 3733 ToNearestRect(overlay.display_rect), overlay.uv_rect); | 3738 ToNearestRect(overlay.display_rect), overlay.uv_rect); |
| 3734 } | 3739 } |
| 3735 } | 3740 } |
| 3736 | 3741 |
| 3737 } // namespace cc | 3742 } // namespace cc |
| OLD | NEW |