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

Unified 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 side-by-side diff with in-line comments
Download patch
Index: content/browser/gpu/gpu_message_hub.h
diff --git a/content/browser/gpu/gpu_message_hub.h b/content/browser/gpu/gpu_message_hub.h
new file mode 100644
index 0000000000000000000000000000000000000000..90b8f9909d4355eea831990da058251c1a31c8f1
--- /dev/null
+++ b/content/browser/gpu/gpu_message_hub.h
@@ -0,0 +1,147 @@
+// Copyright (c) 2011 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#ifndef CONTENT_BROWSER_GPU_GPU_MESSAGE_HUB_H_
+#define CONTENT_BROWSER_GPU_GPU_MESSAGE_HUB_H_
+#pragma once
+
+#include <queue>
+#include <map>
+
+#include "base/callback_old.h"
+#include "base/memory/linked_ptr.h"
+#include "base/process.h"
+#include "base/threading/non_thread_safe.h"
+#include "content/common/gpu/gpu_process_launch_causes.h"
+#include "ipc/ipc_channel.h"
+#include "ui/gfx/native_widget_types.h"
+
+namespace IPC {
+class ChannelHandle;
+class Message;
+}
+
+struct GPUCreateCommandBufferConfig;
+struct GPUInfo;
+
+// This class acts as a hub for messages between browser UI thread/shim,
+// renderer (forwarded by GpuMessageFilter), and GPU process or thread.
+// In the case of messages sent from the renderer to the GPU, it also
+// is responsible for issuing the callbacks once replies from the GPU process
+// or thread are received.
+class GpuMessageHub : public IPC::Channel::Listener,
+ public base::NonThreadSafe {
+ public:
+ GpuMessageHub(int host_id);
+ ~GpuMessageHub();
+
+ void SetGPUProcess(base::ProcessHandle gpu_process);
+
+ // Used to send messages from the browser to the GPU process or thread.
+ static bool SendToGPU(int host_id, IPC::Message* msg);
+
+ // IPC::Channel::Listener implementation receiving messages from the GPU
+ // process or thread.
+ virtual bool OnMessageReceived(const IPC::Message& message);
+
+ typedef Callback3<const IPC::ChannelHandle&,
+ base::ProcessHandle,
+ const GPUInfo&>::Type EstablishChannelCallback;
+ typedef Callback0::Type SynchronizeCallback;
+ typedef Callback1<int32>::Type CreateCommandBufferCallback;
+
+ // Tells the GPU process to create a new channel for communication with a
+ // renderer. Once the GPU process responds asynchronously with the IPC handle
+ // and GPUInfo, we call the callback.
+ static bool EstablishGpuChannel(int renderer_id,
+ content::CauseForGpuLaunch cause,
+ EstablishChannelCallback* callback,
+ int& host_id);
+
+ // Tells the GPU process to create a new command buffer that draws into the
+ // window associated with the given renderer.
+ static void CreateViewCommandBuffer(
+ int host_id,
+ gfx::PluginWindowHandle compositing_surface,
+ int32 render_view_id,
+ int32 renderer_id,
+ const GPUCreateCommandBufferConfig& init_params,
+ CreateCommandBufferCallback* callback);
+
+ // Sends a reply message later when the next GpuHostMsg_SynchronizeReply comes
+ // in.
+ static void Synchronize(int host_id, SynchronizeCallback* callback);
+
+ void SendOutstandingReplies();
+
+ private:
+ // Returns the GpuProcess(|Thread)Host,GpuMessageHub pair for a given host id.
+ static bool FromID(int host_id,
+ IPC::Message::Sender*& host,
+ GpuMessageHub*& hub);
+
+ // Returns a sender to the GPU process/thread.
+ IPC::Message::Sender* FromID(int host_id);
+
+ // Message handlers.
+ void OnChannelEstablished(const IPC::ChannelHandle& channel_handle);
+ void OnSynchronizeReply();
+ void OnCommandBufferCreated(const int32 route_id);
+ void OnDestroyCommandBuffer(gfx::PluginWindowHandle window,
+ int32 renderer_id,
+ int32 render_view_id);
+ void OnGraphicsInfoCollected(const GPUInfo& gpu_info);
+
+ static void EstablishChannelError(EstablishChannelCallback* callback);
+ static void SynchronizeError(SynchronizeCallback* callback);
+ static void CreateCommandBufferError(CreateCommandBufferCallback* callback);
+
+ void ExpectChannelEstablished(linked_ptr<EstablishChannelCallback>& callback);
+ void ExpectSynchronizeReply(linked_ptr<SynchronizeCallback>& callback);
+ void ExpectCommandBufferCreated(gfx::PluginWindowHandle compositing_surface,
+ int32 render_view_id,
+ int32 renderer_id,
+ linked_ptr<CreateCommandBufferCallback>& callback);
+
+ // IPC::Message::Sender implementation used to forward messages originating
+ // from the GPU process/thread to GpuProcessHostUIShim.
+ virtual bool RouteToUIThread(IPC::Message* message);
+
+ // The GPU host id
+ int host_id_;
+
+ // The GPU process handle
+ base::ProcessHandle gpu_process_;
+
+ // These are the channel requests that we have already sent to
+ // the GPU process, but haven't heard back about yet.
+ std::queue<linked_ptr<EstablishChannelCallback> > channel_requests_;
+
+ // The pending synchronization requests we need to reply to.
+ std::queue<linked_ptr<SynchronizeCallback> > synchronize_requests_;
+
+ // The pending create command buffer requests we need to reply to.
+ std::queue<linked_ptr<CreateCommandBufferCallback> >
+ create_command_buffer_requests_;
+
+#if defined(OS_LINUX)
+ typedef std::pair<int32 /* renderer_id */,
+ int32 /* render_view_id */> ViewID;
+
+ // Encapsulates surfaces that we lock when creating view command buffers.
+ // We release this lock once the command buffer (or associated GPU process)
+ // is destroyed. This prevents the browser from destroying the surface
+ // while the GPU process is drawing to it.
+
+ // Multimap is used to simulate reference counting, see comment in
+ // GpuProcessHostUIShim::CreateViewCommandBuffer.
+ class SurfaceRef;
+ typedef std::multimap<ViewID, linked_ptr<SurfaceRef> > SurfaceRefMap;
+ SurfaceRefMap surface_refs_;
+#endif
+
+ DISALLOW_COPY_AND_ASSIGN(GpuMessageHub);
+};
+
+#endif // CONTENT_BROWSER_GPU_GPU_MESSAGE_HUB_H_

Powered by Google App Engine
This is Rietveld 408576698