diff options
author | apatrick@chromium.org <apatrick@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2011-05-09 20:09:24 +0000 |
---|---|---|
committer | apatrick@chromium.org <apatrick@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2011-05-09 20:09:24 +0000 |
commit | d9f3793208dcf490b447869bfa5cb117c45abab9 (patch) | |
tree | 6262ec1c26f7f0639257db3f452d587428224add /content/browser/gpu/gpu_process_host.h | |
parent | d7ca1babe5496783d02b38c735e39f416126e613 (diff) | |
download | chromium_src-d9f3793208dcf490b447869bfa5cb117c45abab9.zip chromium_src-d9f3793208dcf490b447869bfa5cb117c45abab9.tar.gz chromium_src-d9f3793208dcf490b447869bfa5cb117c45abab9.tar.bz2 |
Moved content/browser/gpu_* to content/browser/gpu/.
Also added an OWNERS file with myself and kbr.
TEST=build locally, try
BUG=none
Review URL: http://codereview.chromium.org/6931017
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@84661 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'content/browser/gpu/gpu_process_host.h')
-rw-r--r-- | content/browser/gpu/gpu_process_host.h | 157 |
1 files changed, 157 insertions, 0 deletions
diff --git a/content/browser/gpu/gpu_process_host.h b/content/browser/gpu/gpu_process_host.h new file mode 100644 index 0000000..17ba8fe --- /dev/null +++ b/content/browser/gpu/gpu_process_host.h @@ -0,0 +1,157 @@ +// 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_PROCESS_HOST_H_ +#define CONTENT_BROWSER_GPU_GPU_PROCESS_HOST_H_ +#pragma once + +#include <map> +#include <queue> + +#include "base/callback.h" +#include "base/memory/linked_ptr.h" +#include "base/threading/non_thread_safe.h" +#include "content/browser/browser_child_process_host.h" +#include "content/common/gpu/gpu_info.h" +#include "content/common/gpu/gpu_process_launch_causes.h" +#include "ui/gfx/native_widget_types.h" + +struct GPUCreateCommandBufferConfig; + +namespace IPC { +class Message; +} + +class GpuProcessHost : public BrowserChildProcessHost, + public base::NonThreadSafe { + public: + // Creates a new GpuProcessHost or gets one for a particular + // renderer process, resulting in the launching of a GPU process if required. + // Returns null on failure. It is not safe to store the pointer once control + // has returned to the message loop as it can be destroyed. Instead store the + // associated GPU host ID. A renderer ID of zero means the browser process. + // This could return NULL if GPU access is not allowed (blacklisted). + static GpuProcessHost* GetForRenderer(int renderer_id, + content::CauseForGpuLaunch cause); + + // Helper function to send the given message to the GPU process on the IO + // thread. Calls GetForRenderer and if a host is returned, sends it. + // Can be called from any thread. + static void SendOnIO(int renderer_id, + content::CauseForGpuLaunch cause, + IPC::Message* message); + + // Get the GPU process host for the GPU process with the given ID. Returns + // null if the process no longer exists. + static GpuProcessHost* FromID(int host_id); + int host_id() const { return host_id_; } + + virtual bool Send(IPC::Message* msg); + + // ChildProcessHost implementation. + virtual bool OnMessageReceived(const IPC::Message& message); + virtual void OnChannelConnected(int32 peer_pid); + + typedef Callback3<const IPC::ChannelHandle&, + base::ProcessHandle, + const GPUInfo&>::Type + EstablishChannelCallback; + + // 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. + void EstablishGpuChannel( + int renderer_id, EstablishChannelCallback* callback); + + typedef Callback0::Type SynchronizeCallback; + + // Sends a reply message later when the next GpuHostMsg_SynchronizeReply comes + // in. + void Synchronize(SynchronizeCallback* callback); + + typedef Callback1<int32>::Type CreateCommandBufferCallback; + + // Tells the GPU process to create a new command buffer that draws into the + // window associated with the given renderer. + void CreateViewCommandBuffer( + gfx::PluginWindowHandle compositing_surface, + int32 render_view_id, + int32 renderer_id, + const GPUCreateCommandBufferConfig& init_params, + CreateCommandBufferCallback* callback); + + private: + GpuProcessHost(int host_id); + virtual ~GpuProcessHost(); + + bool Init(); + + // Post an IPC message to the UI shim's message handler on the UI thread. + void RouteOnUIThread(const IPC::Message& message); + + virtual bool CanShutdown(); + virtual void OnProcessLaunched(); + virtual void OnChildDied(); + virtual void OnProcessCrashed(int exit_code); + + // 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); + + bool LaunchGpuProcess(); + + void SendOutstandingReplies(); + void EstablishChannelError( + EstablishChannelCallback* callback, + const IPC::ChannelHandle& channel_handle, + base::ProcessHandle renderer_process_for_gpu, + const GPUInfo& gpu_info); + void CreateCommandBufferError(CreateCommandBufferCallback* callback, + int32 route_id); + void SynchronizeError(SynchronizeCallback* callback); + + // The serial number of the GpuProcessHost / GpuProcessHostUIShim pair. + int host_id_; + + // 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 + + // Qeueud messages to send when the process launches. + std::queue<IPC::Message*> queued_messages_; + + // The handle for the GPU process or null if it is not known to be launched. + base::ProcessHandle gpu_process_; + + DISALLOW_COPY_AND_ASSIGN(GpuProcessHost); +}; + +#endif // CONTENT_BROWSER_GPU_GPU_PROCESS_HOST_H_ |