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), | |
209 watchdog_(watchdog), | 208 watchdog_(watchdog), |
210 waiting_for_sync_point_(false), | 209 waiting_for_sync_point_(false), |
211 previous_processed_num_(0), | 210 previous_processed_num_(0), |
212 preemption_flag_(preempt_by_flag), | 211 preemption_flag_(preempt_by_flag), |
213 active_url_(active_url), | 212 active_url_(active_url), |
214 total_gpu_memory_(0) { | 213 total_gpu_memory_(0) { |
215 active_url_hash_ = base::Hash(active_url.possibly_invalid_spec()); | 214 active_url_hash_ = base::Hash(active_url.possibly_invalid_spec()); |
216 FastSetActiveURL(active_url_, active_url_hash_); | 215 FastSetActiveURL(active_url_, active_url_hash_); |
217 | 216 |
218 gpu::gles2::ContextCreationAttribHelper attrib_parser; | 217 gpu::gles2::ContextCreationAttribHelper attrib_parser; |
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
271 // messages directed at the command buffer. This ensures that the message | 270 // messages directed at the command buffer. This ensures that the message |
272 // handler can assume that the context is current (not necessary for | 271 // handler can assume that the context is current (not necessary for |
273 // RetireSyncPoint or WaitSyncPoint). | 272 // RetireSyncPoint or WaitSyncPoint). |
274 if (decoder_.get() && | 273 if (decoder_.get() && |
275 message.type() != GpuCommandBufferMsg_SetGetBuffer::ID && | 274 message.type() != GpuCommandBufferMsg_SetGetBuffer::ID && |
276 message.type() != GpuCommandBufferMsg_WaitForTokenInRange::ID && | 275 message.type() != GpuCommandBufferMsg_WaitForTokenInRange::ID && |
277 message.type() != GpuCommandBufferMsg_WaitForGetOffsetInRange::ID && | 276 message.type() != GpuCommandBufferMsg_WaitForGetOffsetInRange::ID && |
278 message.type() != GpuCommandBufferMsg_RegisterTransferBuffer::ID && | 277 message.type() != GpuCommandBufferMsg_RegisterTransferBuffer::ID && |
279 message.type() != GpuCommandBufferMsg_DestroyTransferBuffer::ID && | 278 message.type() != GpuCommandBufferMsg_DestroyTransferBuffer::ID && |
280 message.type() != GpuCommandBufferMsg_RetireSyncPoint::ID && | 279 message.type() != GpuCommandBufferMsg_RetireSyncPoint::ID && |
281 message.type() != GpuCommandBufferMsg_SignalSyncPoint::ID && | 280 message.type() != GpuCommandBufferMsg_SignalSyncPoint::ID) { |
282 message.type() != | |
283 GpuCommandBufferMsg_SetClientHasMemoryAllocationChangedCallback::ID) { | |
284 if (!MakeCurrent()) | 281 if (!MakeCurrent()) |
285 return false; | 282 return false; |
286 have_context = true; | 283 have_context = true; |
287 } | 284 } |
288 | 285 |
289 // Always use IPC_MESSAGE_HANDLER_DELAY_REPLY for synchronous message handlers | 286 // Always use IPC_MESSAGE_HANDLER_DELAY_REPLY for synchronous message handlers |
290 // here. This is so the reply can be delayed if the scheduler is unscheduled. | 287 // here. This is so the reply can be delayed if the scheduler is unscheduled. |
291 bool handled = true; | 288 bool handled = true; |
292 IPC_BEGIN_MESSAGE_MAP(GpuCommandBufferStub, message) | 289 IPC_BEGIN_MESSAGE_MAP(GpuCommandBufferStub, message) |
293 IPC_MESSAGE_HANDLER_DELAY_REPLY(GpuCommandBufferMsg_Initialize, | 290 IPC_MESSAGE_HANDLER_DELAY_REPLY(GpuCommandBufferMsg_Initialize, |
(...skipping 16 matching lines...) Expand all Loading... |
310 IPC_MESSAGE_HANDLER_DELAY_REPLY(GpuCommandBufferMsg_CreateVideoEncoder, | 307 IPC_MESSAGE_HANDLER_DELAY_REPLY(GpuCommandBufferMsg_CreateVideoEncoder, |
311 OnCreateVideoEncoder) | 308 OnCreateVideoEncoder) |
312 IPC_MESSAGE_HANDLER(GpuCommandBufferMsg_SetSurfaceVisible, | 309 IPC_MESSAGE_HANDLER(GpuCommandBufferMsg_SetSurfaceVisible, |
313 OnSetSurfaceVisible) | 310 OnSetSurfaceVisible) |
314 IPC_MESSAGE_HANDLER(GpuCommandBufferMsg_RetireSyncPoint, | 311 IPC_MESSAGE_HANDLER(GpuCommandBufferMsg_RetireSyncPoint, |
315 OnRetireSyncPoint) | 312 OnRetireSyncPoint) |
316 IPC_MESSAGE_HANDLER(GpuCommandBufferMsg_SignalSyncPoint, | 313 IPC_MESSAGE_HANDLER(GpuCommandBufferMsg_SignalSyncPoint, |
317 OnSignalSyncPoint) | 314 OnSignalSyncPoint) |
318 IPC_MESSAGE_HANDLER(GpuCommandBufferMsg_SignalQuery, | 315 IPC_MESSAGE_HANDLER(GpuCommandBufferMsg_SignalQuery, |
319 OnSignalQuery) | 316 OnSignalQuery) |
320 IPC_MESSAGE_HANDLER( | |
321 GpuCommandBufferMsg_SetClientHasMemoryAllocationChangedCallback, | |
322 OnSetClientHasMemoryAllocationChangedCallback) | |
323 IPC_MESSAGE_HANDLER(GpuCommandBufferMsg_CreateImage, OnCreateImage); | 317 IPC_MESSAGE_HANDLER(GpuCommandBufferMsg_CreateImage, OnCreateImage); |
324 IPC_MESSAGE_HANDLER(GpuCommandBufferMsg_DestroyImage, OnDestroyImage); | 318 IPC_MESSAGE_HANDLER(GpuCommandBufferMsg_DestroyImage, OnDestroyImage); |
325 IPC_MESSAGE_HANDLER(GpuCommandBufferMsg_CreateStreamTexture, | 319 IPC_MESSAGE_HANDLER(GpuCommandBufferMsg_CreateStreamTexture, |
326 OnCreateStreamTexture) | 320 OnCreateStreamTexture) |
327 IPC_MESSAGE_UNHANDLED(handled = false) | 321 IPC_MESSAGE_UNHANDLED(handled = false) |
328 IPC_END_MESSAGE_MAP() | 322 IPC_END_MESSAGE_MAP() |
329 | 323 |
330 CheckCompleteWaits(); | 324 CheckCompleteWaits(); |
331 | 325 |
332 // Ensure that any delayed work that was created will be handled. | 326 // Ensure that any delayed work that was created will be handled. |
(...skipping 137 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
470 } | 464 } |
471 | 465 |
472 if (initialized_) { | 466 if (initialized_) { |
473 GpuChannelManager* gpu_channel_manager = channel_->gpu_channel_manager(); | 467 GpuChannelManager* gpu_channel_manager = channel_->gpu_channel_manager(); |
474 if (handle_.is_null() && !active_url_.is_empty()) { | 468 if (handle_.is_null() && !active_url_.is_empty()) { |
475 gpu_channel_manager->Send( | 469 gpu_channel_manager->Send( |
476 new GpuHostMsg_DidDestroyOffscreenContext(active_url_)); | 470 new GpuHostMsg_DidDestroyOffscreenContext(active_url_)); |
477 } | 471 } |
478 } | 472 } |
479 | 473 |
480 memory_manager_client_state_.reset(); | |
481 | |
482 while (!sync_points_.empty()) | 474 while (!sync_points_.empty()) |
483 OnRetireSyncPoint(sync_points_.front()); | 475 OnRetireSyncPoint(sync_points_.front()); |
484 | 476 |
485 if (decoder_) | 477 if (decoder_) |
486 decoder_->set_engine(NULL); | 478 decoder_->set_engine(NULL); |
487 | 479 |
488 // The scheduler has raw references to the decoder and the command buffer so | 480 // The scheduler has raw references to the decoder and the command buffer so |
489 // destroy it before those. | 481 // destroy it before those. |
490 scheduler_.reset(); | 482 scheduler_.reset(); |
491 | 483 |
(...skipping 425 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
917 new GpuVideoEncodeAccelerator(encoder_route_id, this); | 909 new GpuVideoEncodeAccelerator(encoder_route_id, this); |
918 encoder->Initialize(input_format, | 910 encoder->Initialize(input_format, |
919 input_visible_size, | 911 input_visible_size, |
920 output_profile, | 912 output_profile, |
921 initial_bitrate, | 913 initial_bitrate, |
922 reply_message); | 914 reply_message); |
923 // encoder is registered as a DestructionObserver of this stub and will | 915 // encoder is registered as a DestructionObserver of this stub and will |
924 // self-delete during destruction of this stub. | 916 // self-delete during destruction of this stub. |
925 } | 917 } |
926 | 918 |
| 919 // TODO(sohanjg): cleanup this and the client side too. |
927 void GpuCommandBufferStub::OnSetSurfaceVisible(bool visible) { | 920 void GpuCommandBufferStub::OnSetSurfaceVisible(bool visible) { |
928 TRACE_EVENT0("gpu", "GpuCommandBufferStub::OnSetSurfaceVisible"); | 921 TRACE_EVENT0("gpu", "GpuCommandBufferStub::OnSetSurfaceVisible"); |
929 if (memory_manager_client_state_) | |
930 memory_manager_client_state_->SetVisible(visible); | |
931 } | 922 } |
932 | 923 |
933 void GpuCommandBufferStub::AddSyncPoint(uint32 sync_point, bool retire) { | 924 void GpuCommandBufferStub::AddSyncPoint(uint32 sync_point, bool retire) { |
934 sync_points_.push_back(sync_point); | 925 sync_points_.push_back(sync_point); |
935 if (retire) | 926 if (retire) |
936 OnRetireSyncPoint(sync_point); | 927 OnRetireSyncPoint(sync_point); |
937 } | 928 } |
938 | 929 |
939 void GpuCommandBufferStub::OnRetireSyncPoint(uint32 sync_point) { | 930 void GpuCommandBufferStub::OnRetireSyncPoint(uint32 sync_point) { |
940 DCHECK(!sync_points_.empty() && sync_points_.front() == sync_point); | 931 DCHECK(!sync_points_.empty() && sync_points_.front() == sync_point); |
(...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1015 this->AsWeakPtr(), | 1006 this->AsWeakPtr(), |
1016 id)); | 1007 id)); |
1017 return; | 1008 return; |
1018 } | 1009 } |
1019 } | 1010 } |
1020 } | 1011 } |
1021 // Something went wrong, run callback immediately. | 1012 // Something went wrong, run callback immediately. |
1022 OnSignalSyncPointAck(id); | 1013 OnSignalSyncPointAck(id); |
1023 } | 1014 } |
1024 | 1015 |
1025 | |
1026 void GpuCommandBufferStub::OnSetClientHasMemoryAllocationChangedCallback( | |
1027 bool has_callback) { | |
1028 TRACE_EVENT0( | |
1029 "gpu", | |
1030 "GpuCommandBufferStub::OnSetClientHasMemoryAllocationChangedCallback"); | |
1031 if (has_callback) { | |
1032 if (!memory_manager_client_state_) { | |
1033 memory_manager_client_state_.reset( | |
1034 GetMemoryManager()->CreateClientState(this, !offscreen_, true)); | |
1035 } | |
1036 } else { | |
1037 memory_manager_client_state_.reset(); | |
1038 } | |
1039 } | |
1040 | |
1041 void GpuCommandBufferStub::OnCreateImage(int32 id, | 1016 void GpuCommandBufferStub::OnCreateImage(int32 id, |
1042 gfx::GpuMemoryBufferHandle handle, | 1017 gfx::GpuMemoryBufferHandle handle, |
1043 gfx::Size size, | 1018 gfx::Size size, |
1044 gfx::BufferFormat format, | 1019 gfx::BufferFormat format, |
1045 uint32 internalformat) { | 1020 uint32 internalformat) { |
1046 TRACE_EVENT0("gpu", "GpuCommandBufferStub::OnCreateImage"); | 1021 TRACE_EVENT0("gpu", "GpuCommandBufferStub::OnCreateImage"); |
1047 | 1022 |
1048 if (!decoder_) | 1023 if (!decoder_) |
1049 return; | 1024 return; |
1050 | 1025 |
(...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1136 } | 1111 } |
1137 | 1112 |
1138 const gpu::gles2::FeatureInfo* GpuCommandBufferStub::GetFeatureInfo() const { | 1113 const gpu::gles2::FeatureInfo* GpuCommandBufferStub::GetFeatureInfo() const { |
1139 return context_group_->feature_info(); | 1114 return context_group_->feature_info(); |
1140 } | 1115 } |
1141 | 1116 |
1142 gpu::gles2::MemoryTracker* GpuCommandBufferStub::GetMemoryTracker() const { | 1117 gpu::gles2::MemoryTracker* GpuCommandBufferStub::GetMemoryTracker() const { |
1143 return context_group_->memory_tracker(); | 1118 return context_group_->memory_tracker(); |
1144 } | 1119 } |
1145 | 1120 |
1146 void GpuCommandBufferStub::SetMemoryAllocation( | |
1147 const gpu::MemoryAllocation& allocation) { | |
1148 if (!last_memory_allocation_valid_ || | |
1149 !allocation.Equals(last_memory_allocation_)) { | |
1150 Send(new GpuCommandBufferMsg_SetMemoryAllocation( | |
1151 route_id_, allocation)); | |
1152 } | |
1153 | |
1154 last_memory_allocation_valid_ = true; | |
1155 last_memory_allocation_ = allocation; | |
1156 } | |
1157 | |
1158 void GpuCommandBufferStub::SuggestHaveFrontBuffer( | 1121 void GpuCommandBufferStub::SuggestHaveFrontBuffer( |
1159 bool suggest_have_frontbuffer) { | 1122 bool suggest_have_frontbuffer) { |
1160 // This can be called outside of OnMessageReceived, so the context needs | 1123 // This can be called outside of OnMessageReceived, so the context needs |
1161 // to be made current before calling methods on the surface. | 1124 // to be made current before calling methods on the surface. |
1162 if (surface_.get() && MakeCurrent()) | 1125 if (surface_.get() && MakeCurrent()) |
1163 surface_->SetFrontbufferAllocation(suggest_have_frontbuffer); | 1126 surface_->SetFrontbufferAllocation(suggest_have_frontbuffer); |
1164 } | 1127 } |
1165 | 1128 |
1166 bool GpuCommandBufferStub::CheckContextLost() { | 1129 bool GpuCommandBufferStub::CheckContextLost() { |
1167 DCHECK(command_buffer_); | 1130 DCHECK(command_buffer_); |
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1218 result)); | 1181 result)); |
1219 } | 1182 } |
1220 | 1183 |
1221 void GpuCommandBufferStub::SendUpdateVSyncParameters(base::TimeTicks timebase, | 1184 void GpuCommandBufferStub::SendUpdateVSyncParameters(base::TimeTicks timebase, |
1222 base::TimeDelta interval) { | 1185 base::TimeDelta interval) { |
1223 Send(new GpuCommandBufferMsg_UpdateVSyncParameters(route_id_, timebase, | 1186 Send(new GpuCommandBufferMsg_UpdateVSyncParameters(route_id_, timebase, |
1224 interval)); | 1187 interval)); |
1225 } | 1188 } |
1226 | 1189 |
1227 } // namespace content | 1190 } // namespace content |
OLD | NEW |