diff options
author | apatrick@chromium.org <apatrick@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2011-05-24 20:51:04 +0000 |
---|---|---|
committer | apatrick@chromium.org <apatrick@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2011-05-24 20:51:04 +0000 |
commit | 70725eb12f12a3349d0666613c43c2363136ae15 (patch) | |
tree | 665be9427e525c88f7130fba2ffa41ffcb4b5a38 | |
parent | 9e0b664271bfa31ed102b51812c65427587461a8 (diff) | |
download | chromium_src-70725eb12f12a3349d0666613c43c2363136ae15.zip chromium_src-70725eb12f12a3349d0666613c43c2363136ae15.tar.gz chromium_src-70725eb12f12a3349d0666613c43c2363136ae15.tar.bz2 |
Added proxy / stub pair for GPU surfaces.
This doesn't do anything useful yet beyond allowing the renderer process to manage the lifetime of an offscreen GLSurface in the GPU process. More to come.
Review URL: http://codereview.chromium.org/6992010
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@86482 0039d316-1c4b-4281-b951-d872f2087c98
-rw-r--r-- | content/common/gpu/gpu_channel.cc | 34 | ||||
-rw-r--r-- | content/common/gpu/gpu_channel.h | 9 | ||||
-rw-r--r-- | content/common/gpu/gpu_command_buffer_stub.cc | 4 | ||||
-rw-r--r-- | content/common/gpu/gpu_messages.h | 9 | ||||
-rw-r--r-- | content/common/gpu/gpu_surface_stub.cc | 37 | ||||
-rw-r--r-- | content/common/gpu/gpu_surface_stub.h | 49 | ||||
-rw-r--r-- | content/content_common.gypi | 2 | ||||
-rw-r--r-- | content/content_renderer.gypi | 2 | ||||
-rw-r--r-- | content/renderer/gpu_channel_host.cc | 24 | ||||
-rw-r--r-- | content/renderer/gpu_channel_host.h | 7 | ||||
-rw-r--r-- | content/renderer/gpu_surface_proxy.cc | 30 | ||||
-rw-r--r-- | content/renderer/gpu_surface_proxy.h | 45 |
12 files changed, 248 insertions, 4 deletions
diff --git a/content/common/gpu/gpu_channel.cc b/content/common/gpu/gpu_channel.cc index 94c2c06..338d426 100644 --- a/content/common/gpu/gpu_channel.cc +++ b/content/common/gpu/gpu_channel.cc @@ -18,6 +18,7 @@ #include "content/common/gpu/gpu_messages.h" #include "content/common/gpu/gpu_video_service.h" #include "content/common/gpu/transport_texture.h" +#include "ui/gfx/gl/gl_surface.h" #if defined(OS_POSIX) #include "ipc/ipc_channel_posix.h" @@ -184,6 +185,9 @@ bool GpuChannel::OnControlMessageReceived(const IPC::Message& msg) { OnCreateOffscreenCommandBuffer) IPC_MESSAGE_HANDLER(GpuChannelMsg_DestroyCommandBuffer, OnDestroyCommandBuffer) + IPC_MESSAGE_HANDLER(GpuChannelMsg_CreateOffscreenSurface, + OnCreateOffscreenSurface) + IPC_MESSAGE_HANDLER(GpuChannelMsg_DestroySurface, OnDestroySurface) IPC_MESSAGE_HANDLER(GpuChannelMsg_CreateVideoDecoder, OnCreateVideoDecoder) IPC_MESSAGE_HANDLER(GpuChannelMsg_DestroyVideoDecoder, @@ -250,6 +254,36 @@ void GpuChannel::OnDestroyCommandBuffer(int32 route_id) { #endif } +void GpuChannel::OnCreateOffscreenSurface(const gfx::Size& size, + int* route_id) { + *route_id = MSG_ROUTING_NONE; + +#if defined(ENABLE_GPU) + scoped_ptr<gfx::GLSurface> surface( + gfx::GLSurface::CreateOffscreenGLSurface(size)); + if (!surface.get()) + return; + + *route_id = GenerateRouteID(); + + scoped_ptr<GpuSurfaceStub> stub (new GpuSurfaceStub(this, + *route_id, + surface.release())); + + router_.AddRoute(*route_id, stub.get()); + surfaces_.AddWithID(stub.release(), *route_id); +#endif +} + +void GpuChannel::OnDestroySurface(int route_id) { +#if defined(ENABLE_GPU) + if (router_.ResolveRoute(route_id)) { + router_.RemoveRoute(route_id); + surfaces_.Remove(route_id); + } +#endif +} + void GpuChannel::OnCreateVideoDecoder( int32 decoder_host_id, const std::vector<uint32>& configs) { // TODO(cevans): do NOT re-enable this until GpuVideoService has been checked diff --git a/content/common/gpu/gpu_channel.h b/content/common/gpu/gpu_channel.h index d4025ae..da12ecd 100644 --- a/content/common/gpu/gpu_channel.h +++ b/content/common/gpu/gpu_channel.h @@ -15,6 +15,7 @@ #include "base/process.h" #include "build/build_config.h" #include "content/common/gpu/gpu_command_buffer_stub.h" +#include "content/common/gpu/gpu_surface_stub.h" #include "content/common/message_router.h" #include "ipc/ipc_sync_channel.h" #include "ui/gfx/native_widget_types.h" @@ -112,6 +113,10 @@ class GpuChannel : public IPC::Channel::Listener, int32* route_id); void OnDestroyCommandBuffer(int32 route_id); + void OnCreateOffscreenSurface(const gfx::Size& size, + int* route_id); + void OnDestroySurface(int route_id); + void OnCreateVideoDecoder(int32 decoder_host_id, const std::vector<uint32>& configs); void OnDestroyVideoDecoder(int32 decoder_id); @@ -139,6 +144,10 @@ class GpuChannel : public IPC::Channel::Listener, #if defined(ENABLE_GPU) typedef IDMap<GpuCommandBufferStub, IDMapOwnPointer> StubMap; StubMap stubs_; + + typedef IDMap<GpuSurfaceStub, IDMapOwnPointer> SurfaceMap; + SurfaceMap surfaces_; + std::set<int32> latched_routes_; #endif // defined (ENABLE_GPU) diff --git a/content/common/gpu/gpu_command_buffer_stub.cc b/content/common/gpu/gpu_command_buffer_stub.cc index 0c852ad..e207372 100644 --- a/content/common/gpu/gpu_command_buffer_stub.cc +++ b/content/common/gpu/gpu_command_buffer_stub.cc @@ -25,10 +25,6 @@ using gpu::Buffer; -#if defined(OS_WIN) -#define kCompositorWindowOwner L"CompositorWindowOwner" -#endif // defined(OS_WIN) - GpuCommandBufferStub::GpuCommandBufferStub( GpuChannel* channel, gfx::PluginWindowHandle handle, diff --git a/content/common/gpu/gpu_messages.h b/content/common/gpu/gpu_messages.h index 9c31376..c4db8f1 100644 --- a/content/common/gpu/gpu_messages.h +++ b/content/common/gpu/gpu_messages.h @@ -307,6 +307,15 @@ IPC_SYNC_MESSAGE_CONTROL4_1(GpuChannelMsg_CreateOffscreenCommandBuffer, IPC_SYNC_MESSAGE_CONTROL1_0(GpuChannelMsg_DestroyCommandBuffer, int32 /* instance_id */) +// Create a surface for offscreen rendering. +IPC_SYNC_MESSAGE_CONTROL1_1(GpuChannelMsg_CreateOffscreenSurface, + gfx::Size, /* size */ + int /* route_id */) + +// Destroy a surface by routing id. +IPC_MESSAGE_CONTROL1(GpuChannelMsg_DestroySurface, + int /* route_id */) + // Create hardware video decoder && associate it with the output |decoder_id|; // We need this to be control message because we had to map the GpuChannel and // |decoder_id|. diff --git a/content/common/gpu/gpu_surface_stub.cc b/content/common/gpu/gpu_surface_stub.cc new file mode 100644 index 0000000..389c624 --- /dev/null +++ b/content/common/gpu/gpu_surface_stub.cc @@ -0,0 +1,37 @@ +// 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. + +#if defined(ENABLE_GPU) + +#include "content/common/gpu/gpu_surface_stub.h" + +#include "content/common/gpu/gpu_channel.h" +#include "ipc/ipc_message_macros.h" + +GpuSurfaceStub::GpuSurfaceStub(GpuChannel* channel, + int route_id, + gfx::GLSurface* surface) + : channel_(channel), + route_id_(route_id), + surface_(surface) { +} + +GpuSurfaceStub::~GpuSurfaceStub() { +} + +bool GpuSurfaceStub::OnMessageReceived(const IPC::Message& message) { + bool handled = true; + //IPC_BEGIN_MESSAGE_MAP(GpuSurfaceStub, message) + // IPC_MESSAGE_UNHANDLED(handled = false) + //IPC_END_MESSAGE_MAP() + DCHECK(handled); + return handled; +} + +bool GpuSurfaceStub::Send(IPC::Message* message) { + return channel_->Send(message); +} + + +#endif // defined(ENABLE_GPU) diff --git a/content/common/gpu/gpu_surface_stub.h b/content/common/gpu/gpu_surface_stub.h new file mode 100644 index 0000000..1a9deb6 --- /dev/null +++ b/content/common/gpu/gpu_surface_stub.h @@ -0,0 +1,49 @@ +// 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_COMMON_GPU_GPU_SURFACE_STUB_H_ +#define CONTENT_COMMON_GPU_GPU_SURFACE_STUB_H_ +#pragma once + +#if defined(ENABLE_GPU) + +#include "base/memory/scoped_ptr.h" +#include "base/memory/weak_ptr.h" +#include "ipc/ipc_channel.h" +#include "ipc/ipc_message.h" +#include "ui/gfx/gl/gl_surface.h" + +class GpuChannel; + +class GpuSurfaceStub + : public IPC::Channel::Listener, + public IPC::Message::Sender, + public base::SupportsWeakPtr<GpuSurfaceStub> { + public: + // Takes ownership of surface. + GpuSurfaceStub(GpuChannel* channel, int route_id, gfx::GLSurface* surface); + virtual ~GpuSurfaceStub(); + + // IPC::Channel::Listener implementation: + virtual bool OnMessageReceived(const IPC::Message& message); + + // IPC::Message::Sender implementation: + virtual bool Send(IPC::Message* msg); + + private: + // Message handlers. + // None yet. + + // This is a weak pointer. The GpuChannel controls the lifetime of the + // GpuSurfaceStub and always outlives it. + GpuChannel* channel_; + + int route_id_; + scoped_ptr<gfx::GLSurface> surface_; + DISALLOW_COPY_AND_ASSIGN(GpuSurfaceStub); +}; + +#endif // defined(ENABLE_GPU) + +#endif // CONTENT_COMMON_GPU_GPU_SURFACE_STUB_H_ diff --git a/content/content_common.gypi b/content/content_common.gypi index 33e2578..a7d98ad 100644 --- a/content/content_common.gypi +++ b/content/content_common.gypi @@ -121,6 +121,8 @@ 'common/gpu/gpu_info.h', 'common/gpu/gpu_messages.h', 'common/gpu/gpu_process_launch_casues.h', + 'common/gpu/gpu_surface_stub.cc', + 'common/gpu/gpu_surface_stub.h', 'common/gpu/gpu_video_decode_accelerator.cc', 'common/gpu/gpu_video_decode_accelerator.h', 'common/gpu/gpu_video_service.cc', diff --git a/content/content_renderer.gypi b/content/content_renderer.gypi index 4dd51c2..04a0870 100644 --- a/content/content_renderer.gypi +++ b/content/content_renderer.gypi @@ -46,6 +46,8 @@ 'renderer/geolocation_dispatcher.h', 'renderer/gpu_channel_host.cc', 'renderer/gpu_channel_host.h', + 'renderer/gpu_surface_proxy.cc', + 'renderer/gpu_surface_proxy.h', 'renderer/gpu_video_decode_accelerator_host.cc', 'renderer/gpu_video_decode_accelerator_host.h', 'renderer/gpu_video_service_host.cc', diff --git a/content/renderer/gpu_channel_host.cc b/content/renderer/gpu_channel_host.cc index c73d32c..5ab0adc 100644 --- a/content/renderer/gpu_channel_host.cc +++ b/content/renderer/gpu_channel_host.cc @@ -7,6 +7,7 @@ #include "content/common/child_process.h" #include "content/common/gpu/gpu_messages.h" #include "content/renderer/command_buffer_proxy.h" +#include "content/renderer/gpu_surface_proxy.h" #include "content/renderer/gpu_video_service_host.h" #include "content/renderer/render_thread.h" #include "content/renderer/transport_texture_service.h" @@ -186,3 +187,26 @@ void GpuChannelHost::DestroyCommandBuffer(CommandBufferProxy* command_buffer) { delete command_buffer; #endif } + +GpuSurfaceProxy* GpuChannelHost::CreateOffscreenSurface(const gfx::Size& size) { +#if defined(ENABLE_GPU) + int route_id; + if (!Send(new GpuChannelMsg_CreateOffscreenSurface(size, &route_id))) + return NULL; + + scoped_ptr<GpuSurfaceProxy> surface(new GpuSurfaceProxy(this, route_id)); + router_.AddRoute(route_id, surface.get()); + + return surface.release(); +#endif +} + +void GpuChannelHost::DestroySurface(GpuSurfaceProxy* surface) { +#if defined(ENABLE_GPU) + Send(new GpuChannelMsg_DestroySurface(surface->route_id())); + if (router_.ResolveRoute(surface->route_id())) + router_.RemoveRoute(surface->route_id()); + + delete surface; +#endif +} diff --git a/content/renderer/gpu_channel_host.h b/content/renderer/gpu_channel_host.h index 4e50881..ba7ec84 100644 --- a/content/renderer/gpu_channel_host.h +++ b/content/renderer/gpu_channel_host.h @@ -20,6 +20,7 @@ #include "ui/gfx/size.h" class CommandBufferProxy; +class GpuSurfaceProxy; class GURL; class GpuVideoServiceHost; class TransportTextureService; @@ -85,6 +86,12 @@ class GpuChannelHost : public IPC::Channel::Listener, // Destroy a command buffer created by this channel. void DestroyCommandBuffer(CommandBufferProxy* command_buffer); + // Create a surface in the GPU process. Returns null on failure. + GpuSurfaceProxy* CreateOffscreenSurface(const gfx::Size& size); + + // Destroy a surface in the GPU process. + void DestroySurface(GpuSurfaceProxy* surface); + GpuVideoServiceHost* gpu_video_service_host() { return gpu_video_service_host_.get(); } diff --git a/content/renderer/gpu_surface_proxy.cc b/content/renderer/gpu_surface_proxy.cc new file mode 100644 index 0000000..b8dedeb --- /dev/null +++ b/content/renderer/gpu_surface_proxy.cc @@ -0,0 +1,30 @@ +// 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. + +#include "content/renderer/gpu_surface_proxy.h" +#include "ui/gfx/size.h" + +GpuSurfaceProxy::GpuSurfaceProxy( + IPC::Channel::Sender* channel, + int route_id) + : channel_(channel), + route_id_(route_id) { +} + +GpuSurfaceProxy::~GpuSurfaceProxy() { +} + +bool GpuSurfaceProxy::OnMessageReceived(const IPC::Message& message) { + bool handled = true; + //IPC_BEGIN_MESSAGE_MAP(GpuSurfaceProxy, message) + // IPC_MESSAGE_UNHANDLED(handled = false) + //IPC_END_MESSAGE_MAP() + DCHECK(handled); + return handled; +} + +void GpuSurfaceProxy::OnChannelError() { + // Prevent any further messages from being sent. + channel_ = NULL; +} diff --git a/content/renderer/gpu_surface_proxy.h b/content/renderer/gpu_surface_proxy.h new file mode 100644 index 0000000..e0bd354 --- /dev/null +++ b/content/renderer/gpu_surface_proxy.h @@ -0,0 +1,45 @@ +// 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_RENDERER_GPU_SURFACE_PROXY_H_ +#define CONTENT_RENDERER_GPU_SURFACE_PROXY_H_ +#pragma once + +#if defined(ENABLE_GPU) + +#include "ipc/ipc_channel.h" +#include "ipc/ipc_message.h" + +namespace gfx { +class Size; +} + +// Client side proxy that forwards messages to a GpuSurfaceStub. +class GpuSurfaceProxy : public IPC::Channel::Listener { + public: + GpuSurfaceProxy(IPC::Channel::Sender* channel, int route_id); + virtual ~GpuSurfaceProxy(); + + // IPC::Channel::Listener implementation: + virtual bool OnMessageReceived(const IPC::Message& message); + virtual void OnChannelError(); + + int route_id() const { return route_id_; } + + private: + + // Send an IPC message over the GPU channel. This is private to fully + // encapsulate the channel; all callers of this function must explicitly + // verify that the channel is still available. + bool Send(IPC::Message* msg); + + IPC::Channel::Sender* channel_; + int route_id_; + + DISALLOW_COPY_AND_ASSIGN(GpuSurfaceProxy); +}; + +#endif // ENABLE_GPU + +#endif // CONTENT_RENDERER_GPU_SURFACE_PROXY_H_ |