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

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

Powered by Google App Engine
This is Rietveld 408576698