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 "base/bind.h" | 5 #include "base/bind.h" |
6 #include "base/bind_helpers.h" | 6 #include "base/bind_helpers.h" |
7 #include "base/command_line.h" | 7 #include "base/command_line.h" |
8 #include "base/hash.h" | 8 #include "base/hash.h" |
9 #include "base/json/json_writer.h" | 9 #include "base/json/json_writer.h" |
10 #include "base/memory/shared_memory.h" | 10 #include "base/memory/shared_memory.h" |
(...skipping 187 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
198 initial_size_(size), | 198 initial_size_(size), |
199 disallowed_features_(disallowed_features), | 199 disallowed_features_(disallowed_features), |
200 requested_attribs_(attribs), | 200 requested_attribs_(attribs), |
201 gpu_preference_(gpu_preference), | 201 gpu_preference_(gpu_preference), |
202 use_virtualized_gl_context_(false), | 202 use_virtualized_gl_context_(false), |
203 command_buffer_id_(GetCommandBufferID(channel->client_id(), route_id)), | 203 command_buffer_id_(GetCommandBufferID(channel->client_id(), route_id)), |
204 stream_id_(stream_id), | 204 stream_id_(stream_id), |
205 route_id_(route_id), | 205 route_id_(route_id), |
206 offscreen_(offscreen), | 206 offscreen_(offscreen), |
207 last_flush_count_(0), | 207 last_flush_count_(0), |
| 208 last_memory_allocation_valid_(false), |
208 watchdog_(watchdog), | 209 watchdog_(watchdog), |
209 waiting_for_sync_point_(false), | 210 waiting_for_sync_point_(false), |
210 previous_processed_num_(0), | 211 previous_processed_num_(0), |
211 preemption_flag_(preempt_by_flag), | 212 preemption_flag_(preempt_by_flag), |
212 active_url_(active_url), | 213 active_url_(active_url), |
213 total_gpu_memory_(0) { | 214 total_gpu_memory_(0) { |
214 active_url_hash_ = base::Hash(active_url.possibly_invalid_spec()); | 215 active_url_hash_ = base::Hash(active_url.possibly_invalid_spec()); |
215 FastSetActiveURL(active_url_, active_url_hash_); | 216 FastSetActiveURL(active_url_, active_url_hash_); |
216 | 217 |
217 gpu::gles2::ContextCreationAttribHelper attrib_parser; | 218 gpu::gles2::ContextCreationAttribHelper attrib_parser; |
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
270 // messages directed at the command buffer. This ensures that the message | 271 // messages directed at the command buffer. This ensures that the message |
271 // handler can assume that the context is current (not necessary for | 272 // handler can assume that the context is current (not necessary for |
272 // RetireSyncPoint or WaitSyncPoint). | 273 // RetireSyncPoint or WaitSyncPoint). |
273 if (decoder_.get() && | 274 if (decoder_.get() && |
274 message.type() != GpuCommandBufferMsg_SetGetBuffer::ID && | 275 message.type() != GpuCommandBufferMsg_SetGetBuffer::ID && |
275 message.type() != GpuCommandBufferMsg_WaitForTokenInRange::ID && | 276 message.type() != GpuCommandBufferMsg_WaitForTokenInRange::ID && |
276 message.type() != GpuCommandBufferMsg_WaitForGetOffsetInRange::ID && | 277 message.type() != GpuCommandBufferMsg_WaitForGetOffsetInRange::ID && |
277 message.type() != GpuCommandBufferMsg_RegisterTransferBuffer::ID && | 278 message.type() != GpuCommandBufferMsg_RegisterTransferBuffer::ID && |
278 message.type() != GpuCommandBufferMsg_DestroyTransferBuffer::ID && | 279 message.type() != GpuCommandBufferMsg_DestroyTransferBuffer::ID && |
279 message.type() != GpuCommandBufferMsg_RetireSyncPoint::ID && | 280 message.type() != GpuCommandBufferMsg_RetireSyncPoint::ID && |
280 message.type() != GpuCommandBufferMsg_SignalSyncPoint::ID) { | 281 message.type() != GpuCommandBufferMsg_SignalSyncPoint::ID && |
| 282 message.type() != |
| 283 GpuCommandBufferMsg_SetClientHasMemoryAllocationChangedCallback::ID) { |
281 if (!MakeCurrent()) | 284 if (!MakeCurrent()) |
282 return false; | 285 return false; |
283 have_context = true; | 286 have_context = true; |
284 } | 287 } |
285 | 288 |
286 // Always use IPC_MESSAGE_HANDLER_DELAY_REPLY for synchronous message handlers | 289 // Always use IPC_MESSAGE_HANDLER_DELAY_REPLY for synchronous message handlers |
287 // here. This is so the reply can be delayed if the scheduler is unscheduled. | 290 // here. This is so the reply can be delayed if the scheduler is unscheduled. |
288 bool handled = true; | 291 bool handled = true; |
289 IPC_BEGIN_MESSAGE_MAP(GpuCommandBufferStub, message) | 292 IPC_BEGIN_MESSAGE_MAP(GpuCommandBufferStub, message) |
290 IPC_MESSAGE_HANDLER_DELAY_REPLY(GpuCommandBufferMsg_Initialize, | 293 IPC_MESSAGE_HANDLER_DELAY_REPLY(GpuCommandBufferMsg_Initialize, |
(...skipping 18 matching lines...) Expand all Loading... |
309 IPC_MESSAGE_HANDLER(GpuCommandBufferMsg_SetSurfaceVisible, | 312 IPC_MESSAGE_HANDLER(GpuCommandBufferMsg_SetSurfaceVisible, |
310 OnSetSurfaceVisible) | 313 OnSetSurfaceVisible) |
311 IPC_MESSAGE_HANDLER(GpuCommandBufferMsg_RetireSyncPoint, | 314 IPC_MESSAGE_HANDLER(GpuCommandBufferMsg_RetireSyncPoint, |
312 OnRetireSyncPoint) | 315 OnRetireSyncPoint) |
313 IPC_MESSAGE_HANDLER(GpuCommandBufferMsg_SignalSyncPoint, | 316 IPC_MESSAGE_HANDLER(GpuCommandBufferMsg_SignalSyncPoint, |
314 OnSignalSyncPoint) | 317 OnSignalSyncPoint) |
315 IPC_MESSAGE_HANDLER(GpuCommandBufferMsg_SignalSyncToken, | 318 IPC_MESSAGE_HANDLER(GpuCommandBufferMsg_SignalSyncToken, |
316 OnSignalSyncToken) | 319 OnSignalSyncToken) |
317 IPC_MESSAGE_HANDLER(GpuCommandBufferMsg_SignalQuery, | 320 IPC_MESSAGE_HANDLER(GpuCommandBufferMsg_SignalQuery, |
318 OnSignalQuery) | 321 OnSignalQuery) |
| 322 IPC_MESSAGE_HANDLER( |
| 323 GpuCommandBufferMsg_SetClientHasMemoryAllocationChangedCallback, |
| 324 OnSetClientHasMemoryAllocationChangedCallback) |
319 IPC_MESSAGE_HANDLER(GpuCommandBufferMsg_CreateImage, OnCreateImage); | 325 IPC_MESSAGE_HANDLER(GpuCommandBufferMsg_CreateImage, OnCreateImage); |
320 IPC_MESSAGE_HANDLER(GpuCommandBufferMsg_DestroyImage, OnDestroyImage); | 326 IPC_MESSAGE_HANDLER(GpuCommandBufferMsg_DestroyImage, OnDestroyImage); |
321 IPC_MESSAGE_HANDLER(GpuCommandBufferMsg_CreateStreamTexture, | 327 IPC_MESSAGE_HANDLER(GpuCommandBufferMsg_CreateStreamTexture, |
322 OnCreateStreamTexture) | 328 OnCreateStreamTexture) |
323 IPC_MESSAGE_UNHANDLED(handled = false) | 329 IPC_MESSAGE_UNHANDLED(handled = false) |
324 IPC_END_MESSAGE_MAP() | 330 IPC_END_MESSAGE_MAP() |
325 | 331 |
326 CheckCompleteWaits(); | 332 CheckCompleteWaits(); |
327 | 333 |
328 // Ensure that any delayed work that was created will be handled. | 334 // Ensure that any delayed work that was created will be handled. |
(...skipping 137 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
466 } | 472 } |
467 | 473 |
468 if (initialized_) { | 474 if (initialized_) { |
469 GpuChannelManager* gpu_channel_manager = channel_->gpu_channel_manager(); | 475 GpuChannelManager* gpu_channel_manager = channel_->gpu_channel_manager(); |
470 if (handle_.is_null() && !active_url_.is_empty()) { | 476 if (handle_.is_null() && !active_url_.is_empty()) { |
471 gpu_channel_manager->Send( | 477 gpu_channel_manager->Send( |
472 new GpuHostMsg_DidDestroyOffscreenContext(active_url_)); | 478 new GpuHostMsg_DidDestroyOffscreenContext(active_url_)); |
473 } | 479 } |
474 } | 480 } |
475 | 481 |
| 482 memory_manager_client_state_.reset(); |
| 483 |
476 while (!sync_points_.empty()) | 484 while (!sync_points_.empty()) |
477 OnRetireSyncPoint(sync_points_.front()); | 485 OnRetireSyncPoint(sync_points_.front()); |
478 | 486 |
479 if (decoder_) | 487 if (decoder_) |
480 decoder_->set_engine(NULL); | 488 decoder_->set_engine(NULL); |
481 | 489 |
482 // The scheduler has raw references to the decoder and the command buffer so | 490 // The scheduler has raw references to the decoder and the command buffer so |
483 // destroy it before those. | 491 // destroy it before those. |
484 scheduler_.reset(); | 492 scheduler_.reset(); |
485 | 493 |
(...skipping 424 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
910 new GpuVideoEncodeAccelerator(encoder_route_id, this); | 918 new GpuVideoEncodeAccelerator(encoder_route_id, this); |
911 encoder->Initialize(input_format, | 919 encoder->Initialize(input_format, |
912 input_visible_size, | 920 input_visible_size, |
913 output_profile, | 921 output_profile, |
914 initial_bitrate, | 922 initial_bitrate, |
915 reply_message); | 923 reply_message); |
916 // encoder is registered as a DestructionObserver of this stub and will | 924 // encoder is registered as a DestructionObserver of this stub and will |
917 // self-delete during destruction of this stub. | 925 // self-delete during destruction of this stub. |
918 } | 926 } |
919 | 927 |
920 // TODO(sohanjg): cleanup this and the client side too. | |
921 void GpuCommandBufferStub::OnSetSurfaceVisible(bool visible) { | 928 void GpuCommandBufferStub::OnSetSurfaceVisible(bool visible) { |
922 TRACE_EVENT0("gpu", "GpuCommandBufferStub::OnSetSurfaceVisible"); | 929 TRACE_EVENT0("gpu", "GpuCommandBufferStub::OnSetSurfaceVisible"); |
| 930 if (memory_manager_client_state_) |
| 931 memory_manager_client_state_->SetVisible(visible); |
923 } | 932 } |
924 | 933 |
925 void GpuCommandBufferStub::InsertSyncPoint(uint32 sync_point, bool retire) { | 934 void GpuCommandBufferStub::InsertSyncPoint(uint32 sync_point, bool retire) { |
926 sync_points_.push_back(sync_point); | 935 sync_points_.push_back(sync_point); |
927 if (retire) { | 936 if (retire) { |
928 OnMessageReceived( | 937 OnMessageReceived( |
929 GpuCommandBufferMsg_RetireSyncPoint(route_id_, sync_point)); | 938 GpuCommandBufferMsg_RetireSyncPoint(route_id_, sync_point)); |
930 } | 939 } |
931 } | 940 } |
932 | 941 |
(...skipping 167 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1100 uint64_t release) { | 1109 uint64_t release) { |
1101 DCHECK(waiting_for_sync_point_); | 1110 DCHECK(waiting_for_sync_point_); |
1102 DCHECK(!scheduler_->scheduled()); | 1111 DCHECK(!scheduler_->scheduled()); |
1103 TRACE_EVENT_ASYNC_END1("gpu", "WaitFenceSync", this, "GpuCommandBufferStub", | 1112 TRACE_EVENT_ASYNC_END1("gpu", "WaitFenceSync", this, "GpuCommandBufferStub", |
1104 this); | 1113 this); |
1105 PullTextureUpdates(namespace_id, command_buffer_id, release); | 1114 PullTextureUpdates(namespace_id, command_buffer_id, release); |
1106 waiting_for_sync_point_ = false; | 1115 waiting_for_sync_point_ = false; |
1107 scheduler_->SetScheduled(true); | 1116 scheduler_->SetScheduled(true); |
1108 } | 1117 } |
1109 | 1118 |
| 1119 |
| 1120 void GpuCommandBufferStub::OnSetClientHasMemoryAllocationChangedCallback( |
| 1121 bool has_callback) { |
| 1122 TRACE_EVENT0( |
| 1123 "gpu", |
| 1124 "GpuCommandBufferStub::OnSetClientHasMemoryAllocationChangedCallback"); |
| 1125 if (has_callback) { |
| 1126 if (!memory_manager_client_state_) { |
| 1127 memory_manager_client_state_.reset( |
| 1128 GetMemoryManager()->CreateClientState(this, !offscreen_, true)); |
| 1129 } |
| 1130 } else { |
| 1131 memory_manager_client_state_.reset(); |
| 1132 } |
| 1133 } |
| 1134 |
1110 void GpuCommandBufferStub::OnCreateImage(int32 id, | 1135 void GpuCommandBufferStub::OnCreateImage(int32 id, |
1111 gfx::GpuMemoryBufferHandle handle, | 1136 gfx::GpuMemoryBufferHandle handle, |
1112 gfx::Size size, | 1137 gfx::Size size, |
1113 gfx::BufferFormat format, | 1138 gfx::BufferFormat format, |
1114 uint32 internalformat) { | 1139 uint32 internalformat) { |
1115 TRACE_EVENT0("gpu", "GpuCommandBufferStub::OnCreateImage"); | 1140 TRACE_EVENT0("gpu", "GpuCommandBufferStub::OnCreateImage"); |
1116 | 1141 |
1117 if (!decoder_) | 1142 if (!decoder_) |
1118 return; | 1143 return; |
1119 | 1144 |
(...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1205 } | 1230 } |
1206 | 1231 |
1207 const gpu::gles2::FeatureInfo* GpuCommandBufferStub::GetFeatureInfo() const { | 1232 const gpu::gles2::FeatureInfo* GpuCommandBufferStub::GetFeatureInfo() const { |
1208 return context_group_->feature_info(); | 1233 return context_group_->feature_info(); |
1209 } | 1234 } |
1210 | 1235 |
1211 gpu::gles2::MemoryTracker* GpuCommandBufferStub::GetMemoryTracker() const { | 1236 gpu::gles2::MemoryTracker* GpuCommandBufferStub::GetMemoryTracker() const { |
1212 return context_group_->memory_tracker(); | 1237 return context_group_->memory_tracker(); |
1213 } | 1238 } |
1214 | 1239 |
| 1240 void GpuCommandBufferStub::SetMemoryAllocation( |
| 1241 const gpu::MemoryAllocation& allocation) { |
| 1242 if (!last_memory_allocation_valid_ || |
| 1243 !allocation.Equals(last_memory_allocation_)) { |
| 1244 Send(new GpuCommandBufferMsg_SetMemoryAllocation( |
| 1245 route_id_, allocation)); |
| 1246 } |
| 1247 |
| 1248 last_memory_allocation_valid_ = true; |
| 1249 last_memory_allocation_ = allocation; |
| 1250 } |
| 1251 |
1215 void GpuCommandBufferStub::SuggestHaveFrontBuffer( | 1252 void GpuCommandBufferStub::SuggestHaveFrontBuffer( |
1216 bool suggest_have_frontbuffer) { | 1253 bool suggest_have_frontbuffer) { |
1217 // This can be called outside of OnMessageReceived, so the context needs | 1254 // This can be called outside of OnMessageReceived, so the context needs |
1218 // to be made current before calling methods on the surface. | 1255 // to be made current before calling methods on the surface. |
1219 if (surface_.get() && MakeCurrent()) | 1256 if (surface_.get() && MakeCurrent()) |
1220 surface_->SetFrontbufferAllocation(suggest_have_frontbuffer); | 1257 surface_->SetFrontbufferAllocation(suggest_have_frontbuffer); |
1221 } | 1258 } |
1222 | 1259 |
1223 bool GpuCommandBufferStub::CheckContextLost() { | 1260 bool GpuCommandBufferStub::CheckContextLost() { |
1224 DCHECK(command_buffer_); | 1261 DCHECK(command_buffer_); |
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1275 result)); | 1312 result)); |
1276 } | 1313 } |
1277 | 1314 |
1278 void GpuCommandBufferStub::SendUpdateVSyncParameters(base::TimeTicks timebase, | 1315 void GpuCommandBufferStub::SendUpdateVSyncParameters(base::TimeTicks timebase, |
1279 base::TimeDelta interval) { | 1316 base::TimeDelta interval) { |
1280 Send(new GpuCommandBufferMsg_UpdateVSyncParameters(route_id_, timebase, | 1317 Send(new GpuCommandBufferMsg_UpdateVSyncParameters(route_id_, timebase, |
1281 interval)); | 1318 interval)); |
1282 } | 1319 } |
1283 | 1320 |
1284 } // namespace content | 1321 } // namespace content |
OLD | NEW |