Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(117)

Side by Side Diff: content/common/gpu/gpu_command_buffer_stub.cc

Issue 1324413003: Move gpu memory calculations to Compositor. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: remove more redundant code. Created 5 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 178 matching lines...) Expand 10 before | Expand all | Expand 10 after
189 initial_size_(size), 189 initial_size_(size),
190 disallowed_features_(disallowed_features), 190 disallowed_features_(disallowed_features),
191 requested_attribs_(attribs), 191 requested_attribs_(attribs),
192 gpu_preference_(gpu_preference), 192 gpu_preference_(gpu_preference),
193 use_virtualized_gl_context_(use_virtualized_gl_context), 193 use_virtualized_gl_context_(use_virtualized_gl_context),
194 stream_id_(stream_id), 194 stream_id_(stream_id),
195 route_id_(route_id), 195 route_id_(route_id),
196 surface_id_(surface_id), 196 surface_id_(surface_id),
197 software_(software), 197 software_(software),
198 last_flush_count_(0), 198 last_flush_count_(0),
199 last_memory_allocation_valid_(false),
200 watchdog_(watchdog), 199 watchdog_(watchdog),
201 sync_point_wait_count_(0), 200 sync_point_wait_count_(0),
202 delayed_work_scheduled_(false), 201 delayed_work_scheduled_(false),
203 previous_messages_processed_(0), 202 previous_messages_processed_(0),
204 active_url_(active_url), 203 active_url_(active_url),
205 total_gpu_memory_(0) { 204 total_gpu_memory_(0) {
206 active_url_hash_ = base::Hash(active_url.possibly_invalid_spec()); 205 active_url_hash_ = base::Hash(active_url.possibly_invalid_spec());
207 FastSetActiveURL(active_url_, active_url_hash_); 206 FastSetActiveURL(active_url_, active_url_hash_);
208 207
209 gpu::gles2::ContextCreationAttribHelper attrib_parser; 208 gpu::gles2::ContextCreationAttribHelper attrib_parser;
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after
254 // messages directed at the command buffer. This ensures that the message 253 // messages directed at the command buffer. This ensures that the message
255 // handler can assume that the context is current (not necessary for 254 // handler can assume that the context is current (not necessary for
256 // RetireSyncPoint or WaitSyncPoint). 255 // RetireSyncPoint or WaitSyncPoint).
257 if (decoder_.get() && 256 if (decoder_.get() &&
258 message.type() != GpuCommandBufferMsg_SetGetBuffer::ID && 257 message.type() != GpuCommandBufferMsg_SetGetBuffer::ID &&
259 message.type() != GpuCommandBufferMsg_WaitForTokenInRange::ID && 258 message.type() != GpuCommandBufferMsg_WaitForTokenInRange::ID &&
260 message.type() != GpuCommandBufferMsg_WaitForGetOffsetInRange::ID && 259 message.type() != GpuCommandBufferMsg_WaitForGetOffsetInRange::ID &&
261 message.type() != GpuCommandBufferMsg_RegisterTransferBuffer::ID && 260 message.type() != GpuCommandBufferMsg_RegisterTransferBuffer::ID &&
262 message.type() != GpuCommandBufferMsg_DestroyTransferBuffer::ID && 261 message.type() != GpuCommandBufferMsg_DestroyTransferBuffer::ID &&
263 message.type() != GpuCommandBufferMsg_RetireSyncPoint::ID && 262 message.type() != GpuCommandBufferMsg_RetireSyncPoint::ID &&
264 message.type() != GpuCommandBufferMsg_SignalSyncPoint::ID && 263 message.type() != GpuCommandBufferMsg_SignalSyncPoint::ID) {
265 message.type() !=
266 GpuCommandBufferMsg_SetClientHasMemoryAllocationChangedCallback::ID) {
267 if (!MakeCurrent()) 264 if (!MakeCurrent())
268 return false; 265 return false;
269 have_context = true; 266 have_context = true;
270 } 267 }
271 268
272 // Always use IPC_MESSAGE_HANDLER_DELAY_REPLY for synchronous message handlers 269 // Always use IPC_MESSAGE_HANDLER_DELAY_REPLY for synchronous message handlers
273 // here. This is so the reply can be delayed if the scheduler is unscheduled. 270 // here. This is so the reply can be delayed if the scheduler is unscheduled.
274 bool handled = true; 271 bool handled = true;
275 IPC_BEGIN_MESSAGE_MAP(GpuCommandBufferStub, message) 272 IPC_BEGIN_MESSAGE_MAP(GpuCommandBufferStub, message)
276 IPC_MESSAGE_HANDLER_DELAY_REPLY(GpuCommandBufferMsg_Initialize, 273 IPC_MESSAGE_HANDLER_DELAY_REPLY(GpuCommandBufferMsg_Initialize,
(...skipping 17 matching lines...) Expand all
294 IPC_MESSAGE_HANDLER_DELAY_REPLY(GpuCommandBufferMsg_CreateVideoEncoder, 291 IPC_MESSAGE_HANDLER_DELAY_REPLY(GpuCommandBufferMsg_CreateVideoEncoder,
295 OnCreateVideoEncoder) 292 OnCreateVideoEncoder)
296 IPC_MESSAGE_HANDLER(GpuCommandBufferMsg_SetSurfaceVisible, 293 IPC_MESSAGE_HANDLER(GpuCommandBufferMsg_SetSurfaceVisible,
297 OnSetSurfaceVisible) 294 OnSetSurfaceVisible)
298 IPC_MESSAGE_HANDLER(GpuCommandBufferMsg_RetireSyncPoint, 295 IPC_MESSAGE_HANDLER(GpuCommandBufferMsg_RetireSyncPoint,
299 OnRetireSyncPoint) 296 OnRetireSyncPoint)
300 IPC_MESSAGE_HANDLER(GpuCommandBufferMsg_SignalSyncPoint, 297 IPC_MESSAGE_HANDLER(GpuCommandBufferMsg_SignalSyncPoint,
301 OnSignalSyncPoint) 298 OnSignalSyncPoint)
302 IPC_MESSAGE_HANDLER(GpuCommandBufferMsg_SignalQuery, 299 IPC_MESSAGE_HANDLER(GpuCommandBufferMsg_SignalQuery,
303 OnSignalQuery) 300 OnSignalQuery)
304 IPC_MESSAGE_HANDLER(
305 GpuCommandBufferMsg_SetClientHasMemoryAllocationChangedCallback,
306 OnSetClientHasMemoryAllocationChangedCallback)
307 IPC_MESSAGE_HANDLER(GpuCommandBufferMsg_CreateImage, OnCreateImage); 301 IPC_MESSAGE_HANDLER(GpuCommandBufferMsg_CreateImage, OnCreateImage);
308 IPC_MESSAGE_HANDLER(GpuCommandBufferMsg_DestroyImage, OnDestroyImage); 302 IPC_MESSAGE_HANDLER(GpuCommandBufferMsg_DestroyImage, OnDestroyImage);
309 IPC_MESSAGE_HANDLER(GpuCommandBufferMsg_CreateStreamTexture, 303 IPC_MESSAGE_HANDLER(GpuCommandBufferMsg_CreateStreamTexture,
310 OnCreateStreamTexture) 304 OnCreateStreamTexture)
311 IPC_MESSAGE_UNHANDLED(handled = false) 305 IPC_MESSAGE_UNHANDLED(handled = false)
312 IPC_END_MESSAGE_MAP() 306 IPC_END_MESSAGE_MAP()
313 307
314 CheckCompleteWaits(); 308 CheckCompleteWaits();
315 309
316 if (have_context) { 310 if (have_context) {
(...skipping 116 matching lines...) Expand 10 before | Expand all | Expand 10 after
433 if (initialized_) { 427 if (initialized_) {
434 GpuChannelManager* gpu_channel_manager = channel_->gpu_channel_manager(); 428 GpuChannelManager* gpu_channel_manager = channel_->gpu_channel_manager();
435 if (handle_.is_null() && !active_url_.is_empty()) { 429 if (handle_.is_null() && !active_url_.is_empty()) {
436 gpu_channel_manager->Send( 430 gpu_channel_manager->Send(
437 new GpuHostMsg_DidDestroyOffscreenContext(active_url_)); 431 new GpuHostMsg_DidDestroyOffscreenContext(active_url_));
438 } 432 }
439 gpu_channel_manager->Send( 433 gpu_channel_manager->Send(
440 new GpuHostMsg_DestroyCommandBuffer(surface_id())); 434 new GpuHostMsg_DestroyCommandBuffer(surface_id()));
441 } 435 }
442 436
443 memory_manager_client_state_.reset();
444
445 while (!sync_points_.empty()) 437 while (!sync_points_.empty())
446 OnRetireSyncPoint(sync_points_.front()); 438 OnRetireSyncPoint(sync_points_.front());
447 439
448 if (decoder_) 440 if (decoder_)
449 decoder_->set_engine(NULL); 441 decoder_->set_engine(NULL);
450 442
451 // The scheduler has raw references to the decoder and the command buffer so 443 // The scheduler has raw references to the decoder and the command buffer so
452 // destroy it before those. 444 // destroy it before those.
453 scheduler_.reset(); 445 scheduler_.reset();
454 446
(...skipping 420 matching lines...) Expand 10 before | Expand all | Expand 10 after
875 new GpuVideoEncodeAccelerator(encoder_route_id, this); 867 new GpuVideoEncodeAccelerator(encoder_route_id, this);
876 encoder->Initialize(input_format, 868 encoder->Initialize(input_format,
877 input_visible_size, 869 input_visible_size,
878 output_profile, 870 output_profile,
879 initial_bitrate, 871 initial_bitrate,
880 reply_message); 872 reply_message);
881 // encoder is registered as a DestructionObserver of this stub and will 873 // encoder is registered as a DestructionObserver of this stub and will
882 // self-delete during destruction of this stub. 874 // self-delete during destruction of this stub.
883 } 875 }
884 876
885 void GpuCommandBufferStub::OnSetSurfaceVisible(bool visible) { 877 void GpuCommandBufferStub::OnSetSurfaceVisible(bool visible) {
piman 2015/09/28 18:32:38 Sounds like we can remove the IPC too then. maybe
sohanjg 2015/09/29 14:19:26 Acknowledged.
886 TRACE_EVENT0("gpu", "GpuCommandBufferStub::OnSetSurfaceVisible"); 878 TRACE_EVENT0("gpu", "GpuCommandBufferStub::OnSetSurfaceVisible");
887 if (memory_manager_client_state_)
888 memory_manager_client_state_->SetVisible(visible);
889 } 879 }
890 880
891 void GpuCommandBufferStub::AddSyncPoint(uint32 sync_point) { 881 void GpuCommandBufferStub::AddSyncPoint(uint32 sync_point) {
892 sync_points_.push_back(sync_point); 882 sync_points_.push_back(sync_point);
893 } 883 }
894 884
895 void GpuCommandBufferStub::OnRetireSyncPoint(uint32 sync_point) { 885 void GpuCommandBufferStub::OnRetireSyncPoint(uint32 sync_point) {
896 DCHECK(!sync_points_.empty() && sync_points_.front() == sync_point); 886 DCHECK(!sync_points_.empty() && sync_points_.front() == sync_point);
897 sync_points_.pop_front(); 887 sync_points_.pop_front();
898 888
(...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after
970 this->AsWeakPtr(), 960 this->AsWeakPtr(),
971 id)); 961 id));
972 return; 962 return;
973 } 963 }
974 } 964 }
975 } 965 }
976 // Something went wrong, run callback immediately. 966 // Something went wrong, run callback immediately.
977 OnSignalSyncPointAck(id); 967 OnSignalSyncPointAck(id);
978 } 968 }
979 969
980
981 void GpuCommandBufferStub::OnSetClientHasMemoryAllocationChangedCallback(
982 bool has_callback) {
983 TRACE_EVENT0(
984 "gpu",
985 "GpuCommandBufferStub::OnSetClientHasMemoryAllocationChangedCallback");
986 if (has_callback) {
987 if (!memory_manager_client_state_) {
988 memory_manager_client_state_.reset(GetMemoryManager()->CreateClientState(
989 this, surface_id_ != 0, true));
990 }
991 } else {
992 memory_manager_client_state_.reset();
993 }
994 }
995
996 void GpuCommandBufferStub::OnCreateImage(int32 id, 970 void GpuCommandBufferStub::OnCreateImage(int32 id,
997 gfx::GpuMemoryBufferHandle handle, 971 gfx::GpuMemoryBufferHandle handle,
998 gfx::Size size, 972 gfx::Size size,
999 gfx::BufferFormat format, 973 gfx::BufferFormat format,
1000 uint32 internalformat) { 974 uint32 internalformat) {
1001 TRACE_EVENT0("gpu", "GpuCommandBufferStub::OnCreateImage"); 975 TRACE_EVENT0("gpu", "GpuCommandBufferStub::OnCreateImage");
1002 976
1003 if (!decoder_) 977 if (!decoder_)
1004 return; 978 return;
1005 979
(...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after
1098 } 1072 }
1099 1073
1100 const gpu::gles2::FeatureInfo* GpuCommandBufferStub::GetFeatureInfo() const { 1074 const gpu::gles2::FeatureInfo* GpuCommandBufferStub::GetFeatureInfo() const {
1101 return context_group_->feature_info(); 1075 return context_group_->feature_info();
1102 } 1076 }
1103 1077
1104 gpu::gles2::MemoryTracker* GpuCommandBufferStub::GetMemoryTracker() const { 1078 gpu::gles2::MemoryTracker* GpuCommandBufferStub::GetMemoryTracker() const {
1105 return context_group_->memory_tracker(); 1079 return context_group_->memory_tracker();
1106 } 1080 }
1107 1081
1108 void GpuCommandBufferStub::SetMemoryAllocation(
1109 const gpu::MemoryAllocation& allocation) {
1110 if (!last_memory_allocation_valid_ ||
1111 !allocation.Equals(last_memory_allocation_)) {
1112 Send(new GpuCommandBufferMsg_SetMemoryAllocation(
1113 route_id_, allocation));
1114 }
1115
1116 last_memory_allocation_valid_ = true;
1117 last_memory_allocation_ = allocation;
1118 }
1119
1120 void GpuCommandBufferStub::SuggestHaveFrontBuffer( 1082 void GpuCommandBufferStub::SuggestHaveFrontBuffer(
1121 bool suggest_have_frontbuffer) { 1083 bool suggest_have_frontbuffer) {
1122 // This can be called outside of OnMessageReceived, so the context needs 1084 // This can be called outside of OnMessageReceived, so the context needs
1123 // to be made current before calling methods on the surface. 1085 // to be made current before calling methods on the surface.
1124 if (surface_.get() && MakeCurrent()) 1086 if (surface_.get() && MakeCurrent())
1125 surface_->SetFrontbufferAllocation(suggest_have_frontbuffer); 1087 surface_->SetFrontbufferAllocation(suggest_have_frontbuffer);
1126 } 1088 }
1127 1089
1128 bool GpuCommandBufferStub::CheckContextLost() { 1090 bool GpuCommandBufferStub::CheckContextLost() {
1129 DCHECK(command_buffer_); 1091 DCHECK(command_buffer_);
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after
1180 result)); 1142 result));
1181 } 1143 }
1182 1144
1183 void GpuCommandBufferStub::SendUpdateVSyncParameters(base::TimeTicks timebase, 1145 void GpuCommandBufferStub::SendUpdateVSyncParameters(base::TimeTicks timebase,
1184 base::TimeDelta interval) { 1146 base::TimeDelta interval) {
1185 Send(new GpuCommandBufferMsg_UpdateVSyncParameters(route_id_, timebase, 1147 Send(new GpuCommandBufferMsg_UpdateVSyncParameters(route_id_, timebase,
1186 interval)); 1148 interval));
1187 } 1149 }
1188 1150
1189 } // namespace content 1151 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698