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 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
61 prefers_smoothness_(false), | 61 prefers_smoothness_(false), |
62 main_thread_handle_(base::PlatformThread::CurrentHandle()) { | 62 main_thread_handle_(base::PlatformThread::CurrentHandle()) { |
63 DCHECK(output_surface_filter_.get()); | 63 DCHECK(output_surface_filter_.get()); |
64 DetachFromThread(); | 64 DetachFromThread(); |
65 message_sender_ = RenderThreadImpl::current()->sync_message_filter(); | 65 message_sender_ = RenderThreadImpl::current()->sync_message_filter(); |
66 DCHECK(message_sender_.get()); | 66 DCHECK(message_sender_.get()); |
67 } | 67 } |
68 | 68 |
69 CompositorOutputSurface::~CompositorOutputSurface() { | 69 CompositorOutputSurface::~CompositorOutputSurface() { |
70 DCHECK(CalledOnValidThread()); | 70 DCHECK(CalledOnValidThread()); |
71 if (!client_) | 71 if (!HasClient()) |
72 return; | 72 return; |
73 UpdateSmoothnessTakesPriority(false); | 73 UpdateSmoothnessTakesPriority(false); |
74 if (output_surface_proxy_.get()) | 74 if (output_surface_proxy_.get()) |
75 output_surface_proxy_->ClearOutputSurface(); | 75 output_surface_proxy_->ClearOutputSurface(); |
76 output_surface_filter_->RemoveRoute(routing_id_); | 76 output_surface_filter_->RemoveRoute(routing_id_); |
77 } | 77 } |
78 | 78 |
79 bool CompositorOutputSurface::BindToClient( | 79 bool CompositorOutputSurface::BindToClient( |
80 cc::OutputSurfaceClient* client) { | 80 cc::OutputSurfaceClient* client) { |
81 DCHECK(CalledOnValidThread()); | 81 DCHECK(CalledOnValidThread()); |
82 | 82 |
83 if (!cc::OutputSurface::BindToClient(client)) | 83 if (!cc::OutputSurface::BindToClient(client)) |
84 return false; | 84 return false; |
85 | 85 |
86 output_surface_proxy_ = new CompositorOutputSurfaceProxy(this); | 86 output_surface_proxy_ = new CompositorOutputSurfaceProxy(this); |
87 output_surface_filter_->AddRoute( | 87 output_surface_filter_->AddRoute( |
88 routing_id_, | 88 routing_id_, |
89 base::Bind(&CompositorOutputSurfaceProxy::OnMessageReceived, | 89 base::Bind(&CompositorOutputSurfaceProxy::OnMessageReceived, |
90 output_surface_proxy_)); | 90 output_surface_proxy_)); |
91 | 91 |
92 return true; | 92 return true; |
93 } | 93 } |
94 | 94 |
95 void CompositorOutputSurface::SwapBuffers(cc::CompositorFrame* frame) { | 95 void CompositorOutputSurface::SwapBuffers(cc::CompositorFrame* frame) { |
96 if (use_swap_compositor_frame_message_) { | 96 if (use_swap_compositor_frame_message_) { |
97 Send(new ViewHostMsg_SwapCompositorFrame(routing_id_, *frame)); | 97 Send(new ViewHostMsg_SwapCompositorFrame(routing_id_, *frame)); |
| 98 DidSwapBuffers(); |
98 return; | 99 return; |
99 } | 100 } |
100 | 101 |
101 if (frame->gl_frame_data) { | 102 if (frame->gl_frame_data) { |
102 WebGraphicsContext3DCommandBufferImpl* command_buffer = | 103 WebGraphicsContext3DCommandBufferImpl* command_buffer = |
103 static_cast<WebGraphicsContext3DCommandBufferImpl*>(context3d()); | 104 static_cast<WebGraphicsContext3DCommandBufferImpl*>(context3d()); |
104 CommandBufferProxyImpl* command_buffer_proxy = | 105 CommandBufferProxyImpl* command_buffer_proxy = |
105 command_buffer->GetCommandBufferProxy(); | 106 command_buffer->GetCommandBufferProxy(); |
106 DCHECK(command_buffer_proxy); | 107 DCHECK(command_buffer_proxy); |
107 context3d()->shallowFlushCHROMIUM(); | 108 context3d()->shallowFlushCHROMIUM(); |
108 command_buffer_proxy->SetLatencyInfo(frame->metadata.latency_info); | 109 command_buffer_proxy->SetLatencyInfo(frame->metadata.latency_info); |
109 } | 110 } |
110 | 111 |
111 OutputSurface::SwapBuffers(frame); | 112 OutputSurface::SwapBuffers(frame); |
112 } | 113 } |
113 | 114 |
114 void CompositorOutputSurface::OnMessageReceived(const IPC::Message& message) { | 115 void CompositorOutputSurface::OnMessageReceived(const IPC::Message& message) { |
115 DCHECK(CalledOnValidThread()); | 116 DCHECK(CalledOnValidThread()); |
116 if (!client_) | 117 if (!HasClient()) |
117 return; | 118 return; |
118 IPC_BEGIN_MESSAGE_MAP(CompositorOutputSurface, message) | 119 IPC_BEGIN_MESSAGE_MAP(CompositorOutputSurface, message) |
119 IPC_MESSAGE_HANDLER(ViewMsg_UpdateVSyncParameters, OnUpdateVSyncParameters); | 120 IPC_MESSAGE_HANDLER(ViewMsg_UpdateVSyncParameters, OnUpdateVSyncParameters); |
120 IPC_MESSAGE_HANDLER(ViewMsg_SwapCompositorFrameAck, OnSwapAck); | 121 IPC_MESSAGE_HANDLER(ViewMsg_SwapCompositorFrameAck, OnSwapAck); |
121 #if defined(OS_ANDROID) | 122 #if defined(OS_ANDROID) |
122 IPC_MESSAGE_HANDLER(ViewMsg_BeginFrame, OnBeginFrame); | 123 IPC_MESSAGE_HANDLER(ViewMsg_BeginFrame, OnBeginFrame); |
123 #endif | 124 #endif |
124 IPC_END_MESSAGE_MAP() | 125 IPC_END_MESSAGE_MAP() |
125 } | 126 } |
126 | 127 |
127 void CompositorOutputSurface::OnUpdateVSyncParameters( | 128 void CompositorOutputSurface::OnUpdateVSyncParameters( |
128 base::TimeTicks timebase, base::TimeDelta interval) { | 129 base::TimeTicks timebase, base::TimeDelta interval) { |
129 DCHECK(CalledOnValidThread()); | 130 DCHECK(CalledOnValidThread()); |
130 client_->OnVSyncParametersChanged(timebase, interval); | 131 OnVSyncParametersChanged(timebase, interval); |
131 } | 132 } |
132 | 133 |
133 #if defined(OS_ANDROID) | 134 #if defined(OS_ANDROID) |
134 void CompositorOutputSurface::SetNeedsBeginFrame(bool enable) { | 135 void CompositorOutputSurface::SetNeedsBeginFrame(bool enable) { |
135 DCHECK(CalledOnValidThread()); | 136 DCHECK(CalledOnValidThread()); |
136 Send(new ViewHostMsg_SetNeedsBeginFrame(routing_id_, enable)); | 137 Send(new ViewHostMsg_SetNeedsBeginFrame(routing_id_, enable)); |
| 138 OutputSurface::SetNeedsBeginFrame(enable); |
137 } | 139 } |
138 | 140 |
139 void CompositorOutputSurface::OnBeginFrame(base::TimeTicks frame_time) { | 141 void CompositorOutputSurface::OnBeginFrame(base::TimeTicks frame_time) { |
140 DCHECK(CalledOnValidThread()); | 142 DCHECK(CalledOnValidThread()); |
141 client_->BeginFrame(frame_time); | 143 BeginFrame(frame_time); |
142 } | 144 } |
143 #endif // defined(OS_ANDROID) | 145 #endif // defined(OS_ANDROID) |
144 | 146 |
145 void CompositorOutputSurface::OnSwapAck(const cc::CompositorFrameAck& ack) { | 147 void CompositorOutputSurface::OnSwapAck(const cc::CompositorFrameAck& ack) { |
146 client_->OnSwapBuffersComplete(&ack); | 148 OnSwapBuffersComplete(&ack); |
147 } | 149 } |
148 | 150 |
149 bool CompositorOutputSurface::Send(IPC::Message* message) { | 151 bool CompositorOutputSurface::Send(IPC::Message* message) { |
150 return message_sender_->Send(message); | 152 return message_sender_->Send(message); |
151 } | 153 } |
152 | 154 |
153 namespace { | 155 namespace { |
154 #if defined(OS_ANDROID) | 156 #if defined(OS_ANDROID) |
155 void SetThreadPriorityToIdle(base::PlatformThreadHandle handle) { | 157 void SetThreadPriorityToIdle(base::PlatformThreadHandle handle) { |
156 base::PlatformThread::SetThreadPriority( | 158 base::PlatformThread::SetThreadPriority( |
(...skipping 28 matching lines...) Expand all Loading... |
185 // If this is the last surface to stop preferring smoothness, | 187 // If this is the last surface to stop preferring smoothness, |
186 // Reset the main thread's priority to the default. | 188 // Reset the main thread's priority to the default. |
187 if (prefers_smoothness_ == true && | 189 if (prefers_smoothness_ == true && |
188 --g_prefer_smoothness_count == 0) { | 190 --g_prefer_smoothness_count == 0) { |
189 SetThreadPriorityToDefault(main_thread_handle_); | 191 SetThreadPriorityToDefault(main_thread_handle_); |
190 } | 192 } |
191 prefers_smoothness_ = prefers_smoothness; | 193 prefers_smoothness_ = prefers_smoothness; |
192 } | 194 } |
193 | 195 |
194 } // namespace content | 196 } // namespace content |
OLD | NEW |