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

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

Issue 10510013: GPU: Adding sync points for cross-channel synchronization (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: review comments Created 8 years, 6 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 | Annotate | Revision Log
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 #if defined(OS_WIN) 5 #if defined(OS_WIN)
6 #include <windows.h> 6 #include <windows.h>
7 #endif 7 #endif
8 8
9 #include "content/common/gpu/gpu_channel.h" 9 #include "content/common/gpu/gpu_channel.h"
10 10
11 #include "base/bind.h" 11 #include "base/bind.h"
12 #include "base/command_line.h" 12 #include "base/command_line.h"
13 #include "base/debug/trace_event.h" 13 #include "base/debug/trace_event.h"
14 #include "base/message_loop_proxy.h"
14 #include "base/process_util.h" 15 #include "base/process_util.h"
15 #include "base/string_util.h" 16 #include "base/string_util.h"
16 #include "content/common/child_process.h" 17 #include "content/common/child_process.h"
17 #include "content/common/gpu/gpu_channel_manager.h" 18 #include "content/common/gpu/gpu_channel_manager.h"
18 #include "content/common/gpu/gpu_messages.h" 19 #include "content/common/gpu/gpu_messages.h"
20 #include "content/common/gpu/sync_point_manager.h"
19 #include "content/public/common/content_client.h" 21 #include "content/public/common/content_client.h"
20 #include "content/public/common/content_switches.h" 22 #include "content/public/common/content_switches.h"
21 #include "gpu/command_buffer/service/mailbox_manager.h" 23 #include "gpu/command_buffer/service/mailbox_manager.h"
24 #include "ipc/ipc_channel.h"
25 #include "ipc/ipc_channel_proxy.h"
22 #include "ui/gl/gl_context.h" 26 #include "ui/gl/gl_context.h"
23 #include "ui/gl/gl_surface.h" 27 #include "ui/gl/gl_surface.h"
24 28
25 #if defined(OS_POSIX) 29 #if defined(OS_POSIX)
26 #include "ipc/ipc_channel_posix.h" 30 #include "ipc/ipc_channel_posix.h"
27 #endif 31 #endif
28 32
29 namespace { 33 namespace {
30 // The first time polling a fence, delay some extra time to allow other 34 // The first time polling a fence, delay some extra time to allow other
31 // stubs to process some work, or else the timing of the fences could 35 // stubs to process some work, or else the timing of the fences could
32 // allow a pattern of alternating fast and slow frames to occur. 36 // allow a pattern of alternating fast and slow frames to occur.
33 const int64 kHandleMoreWorkPeriodMs = 2; 37 const int64 kHandleMoreWorkPeriodMs = 2;
34 const int64 kHandleMoreWorkPeriodBusyMs = 1; 38 const int64 kHandleMoreWorkPeriodBusyMs = 1;
35 } 39
40 // This filter handles the GpuCommandBufferMsg_InsertSyncPoint message on the IO
41 // thread, generating the sync point ID and responding immediately, and then
42 // posting a task to insert the GpuCommandBufferMsg_RetireSyncPoint message into
43 // the channel's queue.
44 class SyncPointMessageFilter : public IPC::ChannelProxy::MessageFilter {
45 public:
46 // Takes ownership of gpu_channel (see below).
47 SyncPointMessageFilter(base::WeakPtr<GpuChannel>* gpu_channel,
48 scoped_refptr<SyncPointManager> sync_point_manager,
49 scoped_refptr<base::MessageLoopProxy> message_loop)
50 : gpu_channel_(gpu_channel),
51 channel_(NULL),
52 sync_point_manager_(sync_point_manager),
53 message_loop_(message_loop) {
54 }
55
56 virtual void OnFilterAdded(IPC::Channel* channel) {
57 DCHECK(!channel_);
58 channel_ = channel;
59 }
60
61 virtual void OnFilterRemoved() {
62 DCHECK(channel_);
63 channel_ = NULL;
64 }
65
66 virtual bool OnMessageReceived(const IPC::Message& message) {
67 DCHECK(channel_);
68 if (message.type() == GpuCommandBufferMsg_InsertSyncPoint::ID) {
69 uint32 sync_point = sync_point_manager_->GenerateSyncPoint();
70 IPC::Message* reply = IPC::SyncMessage::GenerateReply(&message);
71 GpuCommandBufferMsg_InsertSyncPoint::WriteReplyParams(reply, sync_point);
72 channel_->Send(reply);
73 message_loop_->PostTask(FROM_HERE, base::Bind(
74 &SyncPointMessageFilter::InsertSyncPointOnMainThread,
75 gpu_channel_,
76 sync_point_manager_,
77 message.routing_id(),
78 sync_point));
79 return true;
80 } else if (message.type() == GpuCommandBufferMsg_RetireSyncPoint::ID) {
81 // This message should not be sent explicitly by the renderer.
82 NOTREACHED();
83 return true;
84 } else {
85 return false;
86 }
87 }
88
89 protected:
90 virtual ~SyncPointMessageFilter() {
91 message_loop_->PostTask(FROM_HERE, base::Bind(
92 &SyncPointMessageFilter::DeleteWeakPtrOnMainThread, gpu_channel_));
93 }
94
95 private:
96 static void InsertSyncPointOnMainThread(
97 base::WeakPtr<GpuChannel>* gpu_channel,
98 scoped_refptr<SyncPointManager> manager,
99 int32 routing_id,
100 uint32 sync_point) {
101 // This function must ensure that the sync point will be retired. Normally
102 // we'll find the stub based on the routing ID, and associate the sync point
103 // with it, but if that fails for any reason (channel or stub already
104 // deleted, invalid routing id), we need to retire the sync point
105 // immediately.
106 if (gpu_channel->get()) {
107 GpuCommandBufferStub* stub = gpu_channel->get()->LookupCommandBuffer(
108 routing_id);
109 if (stub) {
110 stub->AddSyncPoint(sync_point);
111 GpuCommandBufferMsg_RetireSyncPoint message(routing_id, sync_point);
112 gpu_channel->get()->OnMessageReceived(message);
113 return;
114 }
115 }
116 manager->RetireSyncPoint(sync_point);
117 }
118
119 static void DeleteWeakPtrOnMainThread(
120 base::WeakPtr<GpuChannel>* gpu_channel) {
121 delete gpu_channel;
122 }
123
124 // NOTE: this is a pointer to a weak pointer. It is never dereferenced on the
125 // IO thread, it's only passed through - therefore the WeakPtr assumptions are
126 // respected.
127 base::WeakPtr<GpuChannel>* gpu_channel_;
128 IPC::Channel* channel_;
129 scoped_refptr<SyncPointManager> sync_point_manager_;
130 scoped_refptr<base::MessageLoopProxy> message_loop_;
131 };
132
133 } // anonymous namespace
36 134
37 GpuChannel::GpuChannel(GpuChannelManager* gpu_channel_manager, 135 GpuChannel::GpuChannel(GpuChannelManager* gpu_channel_manager,
38 GpuWatchdog* watchdog, 136 GpuWatchdog* watchdog,
39 gfx::GLShareGroup* share_group, 137 gfx::GLShareGroup* share_group,
40 int client_id, 138 int client_id,
41 bool software) 139 bool software)
42 : gpu_channel_manager_(gpu_channel_manager), 140 : gpu_channel_manager_(gpu_channel_manager),
43 client_id_(client_id), 141 client_id_(client_id),
44 share_group_(share_group ? share_group : new gfx::GLShareGroup), 142 share_group_(share_group ? share_group : new gfx::GLShareGroup),
45 mailbox_manager_(new gpu::gles2::MailboxManager), 143 mailbox_manager_(new gpu::gles2::MailboxManager),
(...skipping 20 matching lines...) Expand all
66 164
67 // Map renderer ID to a (single) channel to that process. 165 // Map renderer ID to a (single) channel to that process.
68 channel_.reset(new IPC::SyncChannel( 166 channel_.reset(new IPC::SyncChannel(
69 channel_id_, 167 channel_id_,
70 IPC::Channel::MODE_SERVER, 168 IPC::Channel::MODE_SERVER,
71 this, 169 this,
72 io_message_loop, 170 io_message_loop,
73 false, 171 false,
74 shutdown_event)); 172 shutdown_event));
75 173
174 base::WeakPtr<GpuChannel>* weak_ptr(new base::WeakPtr<GpuChannel>(
175 weak_factory_.GetWeakPtr()));
176 scoped_refptr<SyncPointMessageFilter> filter(new SyncPointMessageFilter(
177 weak_ptr,
178 gpu_channel_manager_->sync_point_manager(),
179 base::MessageLoopProxy::current()));
180 channel_->AddFilter(filter);
181
76 return true; 182 return true;
77 } 183 }
78 184
79 std::string GpuChannel::GetChannelName() { 185 std::string GpuChannel::GetChannelName() {
80 return channel_id_; 186 return channel_id_;
81 } 187 }
82 188
83 #if defined(OS_POSIX) 189 #if defined(OS_POSIX)
84 int GpuChannel::TakeRendererFileDescriptor() { 190 int GpuChannel::TakeRendererFileDescriptor() {
85 if (!channel_.get()) { 191 if (!channel_.get()) {
(...skipping 346 matching lines...) Expand 10 before | Expand all | Expand 10 after
432 void GpuChannel::WillCreateCommandBuffer(gfx::GpuPreference gpu_preference) { 538 void GpuChannel::WillCreateCommandBuffer(gfx::GpuPreference gpu_preference) {
433 if (gpu_preference == gfx::PreferDiscreteGpu) 539 if (gpu_preference == gfx::PreferDiscreteGpu)
434 ++num_contexts_preferring_discrete_gpu_; 540 ++num_contexts_preferring_discrete_gpu_;
435 } 541 }
436 542
437 void GpuChannel::DidDestroyCommandBuffer(gfx::GpuPreference gpu_preference) { 543 void GpuChannel::DidDestroyCommandBuffer(gfx::GpuPreference gpu_preference) {
438 if (gpu_preference == gfx::PreferDiscreteGpu) 544 if (gpu_preference == gfx::PreferDiscreteGpu)
439 --num_contexts_preferring_discrete_gpu_; 545 --num_contexts_preferring_discrete_gpu_;
440 DCHECK_GE(num_contexts_preferring_discrete_gpu_, 0); 546 DCHECK_GE(num_contexts_preferring_discrete_gpu_, 0);
441 } 547 }
OLDNEW
« no previous file with comments | « content/common/gpu/client/webgraphicscontext3d_command_buffer_impl.cc ('k') | content/common/gpu/gpu_channel_manager.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698