| Index: chrome/gpu/gpu_channel.cc
|
| ===================================================================
|
| --- chrome/gpu/gpu_channel.cc (revision 42644)
|
| +++ chrome/gpu/gpu_channel.cc (working copy)
|
| @@ -2,6 +2,10 @@
|
| // Use of this source code is governed by a BSD-style license that can be
|
| // found in the LICENSE file.
|
|
|
| +#if defined(OS_WIN)
|
| +#include <windows.h>
|
| +#endif
|
| +
|
| #include "chrome/gpu/gpu_channel.h"
|
|
|
| #include "base/command_line.h"
|
| @@ -11,6 +15,7 @@
|
| #include "base/waitable_event.h"
|
| #include "build/build_config.h"
|
| #include "chrome/common/child_process.h"
|
| +#include "chrome/common/chrome_constants.h"
|
| #include "chrome/common/chrome_switches.h"
|
| #include "chrome/common/gpu_messages.h"
|
| #include "chrome/gpu/gpu_thread.h"
|
| @@ -27,44 +32,12 @@
|
| }
|
| };
|
|
|
| -typedef base::hash_map<std::string, scoped_refptr<GpuChannel> >
|
| - GpuChannelMap;
|
| -
|
| // How long we wait before releasing the GPU process.
|
| const int kGpuReleaseTimeMS = 10000;
|
| -
|
| -GpuChannelMap g_gpu_channels;
|
| } // namespace anonymous
|
|
|
| -GpuChannel* GpuChannel::EstablishGpuChannel(int renderer_id) {
|
| - // Map renderer ID to a (single) channel to that process.
|
| - std::string channel_name = StringPrintf(
|
| - "%d.r%d", base::GetCurrentProcId(), renderer_id);
|
| -
|
| - scoped_refptr<GpuChannel> channel;
|
| -
|
| - GpuChannelMap::const_iterator iter = g_gpu_channels.find(channel_name);
|
| - if (iter == g_gpu_channels.end()) {
|
| - channel = new GpuChannel;
|
| - } else {
|
| - channel = iter->second;
|
| - }
|
| -
|
| - DCHECK(channel != NULL);
|
| -
|
| - if (!channel->channel_.get()) {
|
| - if (channel->Init(channel_name)) {
|
| - g_gpu_channels[channel_name] = channel;
|
| - } else {
|
| - channel = NULL;
|
| - }
|
| - }
|
| -
|
| - return channel.get();
|
| -}
|
| -
|
| -GpuChannel::GpuChannel()
|
| - : renderer_id_(-1)
|
| +GpuChannel::GpuChannel(int renderer_id)
|
| + : renderer_id_(renderer_id)
|
| #if defined(OS_POSIX)
|
| , renderer_fd_(-1)
|
| #endif
|
| @@ -141,8 +114,10 @@
|
|
|
| void GpuChannel::OnControlMessageReceived(const IPC::Message& msg) {
|
| IPC_BEGIN_MESSAGE_MAP(GpuChannel, msg)
|
| - IPC_MESSAGE_HANDLER(GpuChannelMsg_CreateCommandBuffer,
|
| - OnCreateCommandBuffer)
|
| + IPC_MESSAGE_HANDLER(GpuChannelMsg_CreateViewCommandBuffer,
|
| + OnCreateViewCommandBuffer)
|
| + IPC_MESSAGE_HANDLER(GpuChannelMsg_CreateOffscreenCommandBuffer,
|
| + OnCreateOffscreenCommandBuffer)
|
| IPC_MESSAGE_HANDLER(GpuChannelMsg_DestroyCommandBuffer,
|
| OnDestroyCommandBuffer)
|
| IPC_MESSAGE_UNHANDLED_ERROR()
|
| @@ -154,19 +129,65 @@
|
| return ++last_id;
|
| }
|
|
|
| -void GpuChannel::OnCreateCommandBuffer(int* route_id) {
|
| +void GpuChannel::OnCreateViewCommandBuffer(gfx::NativeViewId view_id,
|
| + int32* route_id) {
|
| + *route_id = 0;
|
| +
|
| #if defined(ENABLE_GPU)
|
| +
|
| +#if defined(OS_WIN)
|
| + gfx::NativeView view = gfx::NativeViewFromId(view_id);
|
| +
|
| + // Check that the calling renderer is allowed to render to this window.
|
| + // TODO(apatrick): consider killing the renderer process rather than failing.
|
| + int view_renderer_id = reinterpret_cast<int>(
|
| + GetProp(view, chrome::kChromiumRendererIdProperty));
|
| + if (view_renderer_id != renderer_id_)
|
| + return;
|
| +#else
|
| + // TODO(apatrick): This needs to be something valid for mac and linux.
|
| + // Offscreen rendering will work on these platforms but not rendering to the
|
| + // window.
|
| + DCHECK_EQ(view_id, 0);
|
| + gfx::NativeView view = 0;
|
| +#endif
|
| +
|
| *route_id = GenerateRouteID();
|
| scoped_refptr<GpuCommandBufferStub> stub = new GpuCommandBufferStub(
|
| - this, *route_id);
|
| + this, view, NULL, gfx::Size(), 0, *route_id);
|
| router_.AddRoute(*route_id, stub);
|
| stubs_[*route_id] = stub;
|
| +#endif // ENABLE_GPU
|
| +}
|
| +
|
| +void GpuChannel::OnCreateOffscreenCommandBuffer(int32 parent_route_id,
|
| + const gfx::Size& size,
|
| + uint32 parent_texture_id,
|
| + int32* route_id) {
|
| +#if defined(ENABLE_GPU)
|
| + *route_id = GenerateRouteID();
|
| + scoped_refptr<GpuCommandBufferStub> parent_stub;
|
| + if (parent_route_id != 0) {
|
| + StubMap::iterator it = stubs_.find(parent_route_id);
|
| + DCHECK(it != stubs_.end());
|
| + parent_stub = it->second;
|
| + }
|
| +
|
| + scoped_refptr<GpuCommandBufferStub> stub = new GpuCommandBufferStub(
|
| + this,
|
| + NULL,
|
| + parent_stub.get(),
|
| + size,
|
| + parent_texture_id,
|
| + *route_id);
|
| + router_.AddRoute(*route_id, stub);
|
| + stubs_[*route_id] = stub;
|
| #else
|
| *route_id = 0;
|
| #endif
|
| }
|
|
|
| -void GpuChannel::OnDestroyCommandBuffer(int route_id) {
|
| +void GpuChannel::OnDestroyCommandBuffer(int32 route_id) {
|
| #if defined(ENABLE_GPU)
|
| StubMap::iterator it = stubs_.find(route_id);
|
| DCHECK(it != stubs_.end());
|
| @@ -175,8 +196,13 @@
|
| #endif
|
| }
|
|
|
| -bool GpuChannel::Init(const std::string& channel_name) {
|
| - channel_name_ = channel_name;
|
| +bool GpuChannel::Init() {
|
| + // Check whether we're already initialized.
|
| + if (channel_.get())
|
| + return true;
|
| +
|
| + // Map renderer ID to a (single) channel to that process.
|
| + std::string channel_name = GetChannelName();
|
| #if defined(OS_POSIX)
|
| // This gets called when the GpuChannel is initially created. At this
|
| // point, create the socketpair and assign the GPU side FD to the channel
|
| @@ -192,3 +218,7 @@
|
| ChildProcess::current()->GetShutDownEvent()));
|
| return true;
|
| }
|
| +
|
| +std::string GpuChannel::GetChannelName() {
|
| + return StringPrintf("%d.r%d", base::GetCurrentProcId(), renderer_id_);
|
| +}
|
|
|