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

Side by Side Diff: content/browser/gpu/gpu_message_hub.h

Issue 7054005: Fix gpu acceleration with --in-process-gpu (Closed) Base URL: http://git.chromium.org/git/chromium.git@trunk
Patch Set: cleanup Created 9 years, 7 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
(Empty)
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 #ifndef CONTENT_BROWSER_GPU_GPU_MESSAGE_HUB_H_
6 #define CONTENT_BROWSER_GPU_GPU_MESSAGE_HUB_H_
7 #pragma once
8
9 #include <queue>
10 #include <map>
11
12 #include "base/callback_old.h"
13 #include "base/memory/linked_ptr.h"
14 #include "base/process.h"
15 #include "base/threading/non_thread_safe.h"
16 #include "content/common/gpu/gpu_process_launch_causes.h"
17 #include "ipc/ipc_channel.h"
18 #include "ui/gfx/native_widget_types.h"
19
20 namespace IPC {
21 class ChannelHandle;
22 class Message;
23 }
24
25 struct GPUCreateCommandBufferConfig;
26 struct GPUInfo;
27
28 // This class acts as a hub for messages between browser UI thread/shim,
29 // renderer (forwarded by GpuMessageFilter), and GPU process or thread.
30 // In the case of messages sent from the renderer to the GPU, it also
31 // is responsible for issuing the callbacks once replies from the GPU process
32 // or thread are received.
33 class GpuMessageHub : public IPC::Channel::Listener,
34 public base::NonThreadSafe {
35 public:
36 GpuMessageHub(int host_id);
37 ~GpuMessageHub();
38
39 void SetGPUProcess(base::ProcessHandle gpu_process);
40
41 // Used to send messages from the browser to the GPU process or thread.
42 static bool SendToGPU(int host_id, IPC::Message* msg);
43
44 // IPC::Channel::Listener implementation receiving messages from the GPU
45 // process or thread.
46 virtual bool OnMessageReceived(const IPC::Message& message);
47
48 typedef Callback3<const IPC::ChannelHandle&,
49 base::ProcessHandle,
50 const GPUInfo&>::Type EstablishChannelCallback;
51 typedef Callback0::Type SynchronizeCallback;
52 typedef Callback1<int32>::Type CreateCommandBufferCallback;
53
54 // Tells the GPU process to create a new channel for communication with a
55 // renderer. Once the GPU process responds asynchronously with the IPC handle
56 // and GPUInfo, we call the callback.
57 static bool EstablishGpuChannel(int renderer_id,
58 content::CauseForGpuLaunch cause,
59 EstablishChannelCallback* callback,
60 int& host_id);
61
62 // Tells the GPU process to create a new command buffer that draws into the
63 // window associated with the given renderer.
64 static void CreateViewCommandBuffer(
65 int host_id,
66 gfx::PluginWindowHandle compositing_surface,
67 int32 render_view_id,
68 int32 renderer_id,
69 const GPUCreateCommandBufferConfig& init_params,
70 CreateCommandBufferCallback* callback);
71
72 // Sends a reply message later when the next GpuHostMsg_SynchronizeReply comes
73 // in.
74 static void Synchronize(int host_id, SynchronizeCallback* callback);
75
76 void SendOutstandingReplies();
77
78 private:
79 // Returns the GpuProcess(|Thread)Host,GpuMessageHub pair for a given host id.
80 static bool FromID(int host_id,
81 IPC::Message::Sender*& host,
82 GpuMessageHub*& hub);
83
84 // Returns a sender to the GPU process/thread.
85 IPC::Message::Sender* FromID(int host_id);
86
87 // Message handlers.
88 void OnChannelEstablished(const IPC::ChannelHandle& channel_handle);
89 void OnSynchronizeReply();
90 void OnCommandBufferCreated(const int32 route_id);
91 void OnDestroyCommandBuffer(gfx::PluginWindowHandle window,
92 int32 renderer_id,
93 int32 render_view_id);
94 void OnGraphicsInfoCollected(const GPUInfo& gpu_info);
95
96 static void EstablishChannelError(EstablishChannelCallback* callback);
97 static void SynchronizeError(SynchronizeCallback* callback);
98 static void CreateCommandBufferError(CreateCommandBufferCallback* callback);
99
100 void ExpectChannelEstablished(linked_ptr<EstablishChannelCallback>& callback);
101 void ExpectSynchronizeReply(linked_ptr<SynchronizeCallback>& callback);
102 void ExpectCommandBufferCreated(gfx::PluginWindowHandle compositing_surface,
103 int32 render_view_id,
104 int32 renderer_id,
105 linked_ptr<CreateCommandBufferCallback>& callback);
106
107 // IPC::Message::Sender implementation used to forward messages originating
108 // from the GPU process/thread to GpuProcessHostUIShim.
109 virtual bool RouteToUIThread(IPC::Message* message);
110
111 // The GPU host id
112 int host_id_;
113
114 // The GPU process handle
115 base::ProcessHandle gpu_process_;
116
117 // These are the channel requests that we have already sent to
118 // the GPU process, but haven't heard back about yet.
119 std::queue<linked_ptr<EstablishChannelCallback> > channel_requests_;
120
121 // The pending synchronization requests we need to reply to.
122 std::queue<linked_ptr<SynchronizeCallback> > synchronize_requests_;
123
124 // The pending create command buffer requests we need to reply to.
125 std::queue<linked_ptr<CreateCommandBufferCallback> >
126 create_command_buffer_requests_;
127
128 #if defined(OS_LINUX)
129 typedef std::pair<int32 /* renderer_id */,
130 int32 /* render_view_id */> ViewID;
131
132 // Encapsulates surfaces that we lock when creating view command buffers.
133 // We release this lock once the command buffer (or associated GPU process)
134 // is destroyed. This prevents the browser from destroying the surface
135 // while the GPU process is drawing to it.
136
137 // Multimap is used to simulate reference counting, see comment in
138 // GpuProcessHostUIShim::CreateViewCommandBuffer.
139 class SurfaceRef;
140 typedef std::multimap<ViewID, linked_ptr<SurfaceRef> > SurfaceRefMap;
141 SurfaceRefMap surface_refs_;
142 #endif
143
144 DISALLOW_COPY_AND_ASSIGN(GpuMessageHub);
145 };
146
147 #endif // CONTENT_BROWSER_GPU_GPU_MESSAGE_HUB_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698