OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 "content/renderer/gpu/compositor_output_surface.h" | 5 #include "content/renderer/gpu/compositor_output_surface.h" |
6 | 6 |
7 #include "base/command_line.h" | 7 #include "base/command_line.h" |
8 #include "base/message_loop/message_loop_proxy.h" | 8 #include "base/message_loop/message_loop_proxy.h" |
9 #include "cc/output/compositor_frame.h" | 9 #include "cc/output/compositor_frame.h" |
10 #include "cc/output/compositor_frame_ack.h" | 10 #include "cc/output/compositor_frame_ack.h" |
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
56 bool use_swap_compositor_frame_message) | 56 bool use_swap_compositor_frame_message) |
57 : OutputSurface(context_provider, software_device.Pass()), | 57 : OutputSurface(context_provider, software_device.Pass()), |
58 output_surface_id_(output_surface_id), | 58 output_surface_id_(output_surface_id), |
59 use_swap_compositor_frame_message_(use_swap_compositor_frame_message), | 59 use_swap_compositor_frame_message_(use_swap_compositor_frame_message), |
60 output_surface_filter_( | 60 output_surface_filter_( |
61 RenderThreadImpl::current()->compositor_output_surface_filter()), | 61 RenderThreadImpl::current()->compositor_output_surface_filter()), |
62 routing_id_(routing_id), | 62 routing_id_(routing_id), |
63 prefers_smoothness_(false), | 63 prefers_smoothness_(false), |
64 #if defined(OS_WIN) | 64 #if defined(OS_WIN) |
65 // TODO(epenner): Implement PlatformThread::CurrentHandle() on windows. | 65 // TODO(epenner): Implement PlatformThread::CurrentHandle() on windows. |
66 main_thread_handle_(base::PlatformThreadHandle()) | 66 main_thread_handle_(base::PlatformThreadHandle()), |
67 #else | 67 #else |
68 main_thread_handle_(base::PlatformThread::CurrentHandle()) | 68 main_thread_handle_(base::PlatformThread::CurrentHandle()), |
69 #endif | 69 #endif |
70 { | 70 layout_test_mode_(RenderThreadImpl::current()->layout_test_mode()), |
| 71 weak_ptrs_(this) { |
71 DCHECK(output_surface_filter_.get()); | 72 DCHECK(output_surface_filter_.get()); |
72 DetachFromThread(); | 73 DetachFromThread(); |
73 message_sender_ = RenderThreadImpl::current()->sync_message_filter(); | 74 message_sender_ = RenderThreadImpl::current()->sync_message_filter(); |
74 DCHECK(message_sender_.get()); | 75 DCHECK(message_sender_.get()); |
75 if (OutputSurface::software_device()) | 76 if (OutputSurface::software_device()) |
76 capabilities_.max_frames_pending = 1; | 77 capabilities_.max_frames_pending = 1; |
77 } | 78 } |
78 | 79 |
79 CompositorOutputSurface::~CompositorOutputSurface() { | 80 CompositorOutputSurface::~CompositorOutputSurface() { |
80 DCHECK(CalledOnValidThread()); | 81 DCHECK(CalledOnValidThread()); |
(...skipping 23 matching lines...) Expand all Loading... |
104 // Without a GPU context, the memory policy otherwise wouldn't be set. | 105 // Without a GPU context, the memory policy otherwise wouldn't be set. |
105 client->SetMemoryPolicy(cc::ManagedMemoryPolicy( | 106 client->SetMemoryPolicy(cc::ManagedMemoryPolicy( |
106 64 * 1024 * 1024, | 107 64 * 1024 * 1024, |
107 gpu::MemoryAllocation::CUTOFF_ALLOW_NICE_TO_HAVE, | 108 gpu::MemoryAllocation::CUTOFF_ALLOW_NICE_TO_HAVE, |
108 cc::ManagedMemoryPolicy::kDefaultNumResourcesLimit)); | 109 cc::ManagedMemoryPolicy::kDefaultNumResourcesLimit)); |
109 } | 110 } |
110 | 111 |
111 return true; | 112 return true; |
112 } | 113 } |
113 | 114 |
| 115 void CompositorOutputSurface::ShortcutSwapAck( |
| 116 uint32 output_surface_id, |
| 117 scoped_ptr<cc::GLFrameData> gl_frame_data, |
| 118 scoped_ptr<cc::SoftwareFrameData> software_frame_data) { |
| 119 if (!layout_test_previous_frame_ack_) { |
| 120 layout_test_previous_frame_ack_.reset(new cc::CompositorFrameAck); |
| 121 layout_test_previous_frame_ack_->gl_frame_data.reset(new cc::GLFrameData); |
| 122 } |
| 123 |
| 124 OnSwapAck(output_surface_id, *layout_test_previous_frame_ack_); |
| 125 |
| 126 layout_test_previous_frame_ack_->gl_frame_data = gl_frame_data.Pass(); |
| 127 layout_test_previous_frame_ack_->last_software_frame_id = |
| 128 software_frame_data ? software_frame_data->id : 0; |
| 129 } |
| 130 |
114 void CompositorOutputSurface::SwapBuffers(cc::CompositorFrame* frame) { | 131 void CompositorOutputSurface::SwapBuffers(cc::CompositorFrame* frame) { |
| 132 if (layout_test_mode_ && use_swap_compositor_frame_message_) { |
| 133 // This code path is here to support layout tests that are currently |
| 134 // doing a readback in the renderer instead of the browser. So they |
| 135 // are using deprecated code paths in the renderer and don't need to |
| 136 // actually swap anything to the browser. We shortcut the swap to the |
| 137 // browser here and just ack directly within the renderer process. |
| 138 // Once crbug.com/311404 is fixed, this can be removed. |
| 139 |
| 140 // This would indicate that crbug.com/311404 is being fixed, and this |
| 141 // block needs to be removed. |
| 142 DCHECK(!frame->delegated_frame_data); |
| 143 |
| 144 base::MessageLoopProxy::current()->PostTask( |
| 145 FROM_HERE, |
| 146 base::Bind(&CompositorOutputSurface::ShortcutSwapAck, |
| 147 weak_ptrs_.GetWeakPtr(), |
| 148 output_surface_id_, |
| 149 base::Passed(&frame->gl_frame_data), |
| 150 base::Passed(&frame->software_frame_data))); |
| 151 DidSwapBuffers(); |
| 152 return; |
| 153 } |
| 154 |
115 if (use_swap_compositor_frame_message_) { | 155 if (use_swap_compositor_frame_message_) { |
116 Send(new ViewHostMsg_SwapCompositorFrame(routing_id_, | 156 Send(new ViewHostMsg_SwapCompositorFrame(routing_id_, |
117 output_surface_id_, | 157 output_surface_id_, |
118 *frame)); | 158 *frame)); |
119 DidSwapBuffers(); | 159 DidSwapBuffers(); |
120 return; | 160 return; |
121 } | 161 } |
122 | 162 |
123 if (frame->gl_frame_data) { | 163 if (frame->gl_frame_data) { |
124 context_provider_->ContextGL()->ShallowFlushCHROMIUM(); | 164 context_provider_->ContextGL()->ShallowFlushCHROMIUM(); |
(...skipping 103 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
228 // If this is the last surface to stop preferring smoothness, | 268 // If this is the last surface to stop preferring smoothness, |
229 // Reset the main thread's priority to the default. | 269 // Reset the main thread's priority to the default. |
230 if (prefers_smoothness_ == true && | 270 if (prefers_smoothness_ == true && |
231 --g_prefer_smoothness_count == 0) { | 271 --g_prefer_smoothness_count == 0) { |
232 SetThreadPriorityToDefault(main_thread_handle_); | 272 SetThreadPriorityToDefault(main_thread_handle_); |
233 } | 273 } |
234 prefers_smoothness_ = prefers_smoothness; | 274 prefers_smoothness_ = prefers_smoothness; |
235 } | 275 } |
236 | 276 |
237 } // namespace content | 277 } // namespace content |
OLD | NEW |