| OLD | NEW |
| 1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #ifndef CHROME_GPU_GPU_CHANNEL_H_ | 5 #ifndef CHROME_GPU_GPU_CHANNEL_H_ |
| 6 #define CHROME_GPU_GPU_CHANNEL_H_ | 6 #define CHROME_GPU_GPU_CHANNEL_H_ |
| 7 | 7 |
| 8 #include <string> | 8 #include <string> |
| 9 | 9 |
| 10 #include "base/hash_tables.h" | 10 #include "base/hash_tables.h" |
| 11 #include "base/ref_counted.h" | 11 #include "base/ref_counted.h" |
| 12 #include "base/scoped_open_process.h" | 12 #include "base/scoped_open_process.h" |
| 13 #include "build/build_config.h" | 13 #include "build/build_config.h" |
| 14 #include "chrome/common/message_router.h" | 14 #include "chrome/common/message_router.h" |
| 15 #include "chrome/gpu/gpu_command_buffer_stub.h" | 15 #include "chrome/gpu/gpu_command_buffer_stub.h" |
| 16 #include "gfx/native_widget_types.h" |
| 17 #include "gfx/size.h" |
| 16 #include "ipc/ipc_channel.h" | 18 #include "ipc/ipc_channel.h" |
| 17 #include "ipc/ipc_message.h" | 19 #include "ipc/ipc_message.h" |
| 18 #include "ipc/ipc_sync_channel.h" | 20 #include "ipc/ipc_sync_channel.h" |
| 19 | 21 |
| 20 // Encapsulates an IPC channel between the GPU process and one renderer | 22 // Encapsulates an IPC channel between the GPU process and one renderer |
| 21 // process. On the renderer side there's a corresponding GpuChannelHost. | 23 // process. On the renderer side there's a corresponding GpuChannelHost. |
| 22 class GpuChannel : public IPC::Channel::Listener, | 24 class GpuChannel : public IPC::Channel::Listener, |
| 23 public IPC::Message::Sender, | 25 public IPC::Message::Sender, |
| 24 public base::RefCountedThreadSafe<GpuChannel> { | 26 public base::RefCountedThreadSafe<GpuChannel> { |
| 25 public: | 27 public: |
| 26 // Get a new GpuChannel object for the current process to talk to the | 28 explicit GpuChannel(int renderer_id); |
| 27 // given renderer process. The renderer ID is an opaque unique ID generated | |
| 28 // by the browser. | |
| 29 // | |
| 30 // POSIX only: If |channel_fd| > 0, use that file descriptor for the | |
| 31 // channel socket. | |
| 32 static GpuChannel* EstablishGpuChannel(int renderer_id); | |
| 33 | |
| 34 virtual ~GpuChannel(); | 29 virtual ~GpuChannel(); |
| 35 | 30 |
| 36 std::string channel_name() const { return channel_name_; } | 31 bool Init(); |
| 32 |
| 33 std::string GetChannelName(); |
| 37 | 34 |
| 38 base::ProcessHandle renderer_handle() const { | 35 base::ProcessHandle renderer_handle() const { |
| 39 return renderer_process_.handle(); | 36 return renderer_process_.handle(); |
| 40 } | 37 } |
| 41 | 38 |
| 42 #if defined(OS_POSIX) | 39 #if defined(OS_POSIX) |
| 43 // When first created, the GpuChannel gets assigned the file descriptor | 40 // When first created, the GpuChannel gets assigned the file descriptor |
| 44 // for the renderer. | 41 // for the renderer. |
| 45 // After the first time we pass it through the IPC, we don't need it anymore, | 42 // After the first time we pass it through the IPC, we don't need it anymore, |
| 46 // and we close it. At that time, we reset renderer_fd_ to -1. | 43 // and we close it. At that time, we reset renderer_fd_ to -1. |
| 47 int DisownRendererFd() { | 44 int DisownRendererFd() { |
| 48 int value = renderer_fd_; | 45 int value = renderer_fd_; |
| 49 renderer_fd_ = -1; | 46 renderer_fd_ = -1; |
| 50 return value; | 47 return value; |
| 51 } | 48 } |
| 52 #endif | 49 #endif |
| 53 | 50 |
| 54 // IPC::Channel::Listener implementation: | 51 // IPC::Channel::Listener implementation: |
| 55 virtual void OnMessageReceived(const IPC::Message& msg); | 52 virtual void OnMessageReceived(const IPC::Message& msg); |
| 56 virtual void OnChannelConnected(int32 peer_pid); | 53 virtual void OnChannelConnected(int32 peer_pid); |
| 57 virtual void OnChannelError(); | 54 virtual void OnChannelError(); |
| 58 | 55 |
| 59 // IPC::Message::Sender implementation: | 56 // IPC::Message::Sender implementation: |
| 60 virtual bool Send(IPC::Message* msg); | 57 virtual bool Send(IPC::Message* msg); |
| 61 | 58 |
| 62 private: | 59 private: |
| 63 // Called on the plugin thread | |
| 64 GpuChannel(); | |
| 65 | |
| 66 bool Init(const std::string& channel_name); | |
| 67 | |
| 68 void OnControlMessageReceived(const IPC::Message& msg); | 60 void OnControlMessageReceived(const IPC::Message& msg); |
| 69 | 61 |
| 70 int GenerateRouteID(); | 62 int GenerateRouteID(); |
| 71 | 63 |
| 72 // Message handlers. | 64 // Message handlers. |
| 73 void OnCreateCommandBuffer(int* instance_id); | 65 void OnCreateViewCommandBuffer(gfx::NativeViewId view, |
| 74 void OnDestroyCommandBuffer(int instance_id); | 66 int32* route_id); |
| 67 void OnCreateOffscreenCommandBuffer(int32 parent_route_id, |
| 68 const gfx::Size& size, |
| 69 uint32 parent_texture_id, |
| 70 int32* route_id); |
| 71 void OnDestroyCommandBuffer(int32 route_id); |
| 75 | 72 |
| 76 scoped_ptr<IPC::SyncChannel> channel_; | 73 scoped_ptr<IPC::SyncChannel> channel_; |
| 77 std::string channel_name_; | |
| 78 | 74 |
| 79 // Handle to the renderer process who is on the other side of the channel. | 75 // Handle to the renderer process who is on the other side of the channel. |
| 80 base::ScopedOpenProcess renderer_process_; | 76 base::ScopedOpenProcess renderer_process_; |
| 81 | 77 |
| 82 // The id of the renderer who is on the other side of the channel. | 78 // The id of the renderer who is on the other side of the channel. |
| 83 int renderer_id_; | 79 int renderer_id_; |
| 84 | 80 |
| 85 #if defined(OS_POSIX) | 81 #if defined(OS_POSIX) |
| 86 // FD for the renderer end of the pipe. It is stored until we send it over | 82 // FD for the renderer end of the pipe. It is stored until we send it over |
| 87 // IPC after which it is cleared. It will be closed by the IPC mechanism. | 83 // IPC after which it is cleared. It will be closed by the IPC mechanism. |
| 88 int renderer_fd_; | 84 int renderer_fd_; |
| 89 #endif | 85 #endif |
| 90 | 86 |
| 91 // Used to implement message routing functionality to CommandBuffer objects | 87 // Used to implement message routing functionality to CommandBuffer objects |
| 92 MessageRouter router_; | 88 MessageRouter router_; |
| 93 | 89 |
| 94 #if defined(ENABLE_GPU) | 90 #if defined(ENABLE_GPU) |
| 95 typedef base::hash_map<int, scoped_refptr<GpuCommandBufferStub> > StubMap; | 91 typedef base::hash_map<int32, scoped_refptr<GpuCommandBufferStub> > StubMap; |
| 96 StubMap stubs_; | 92 StubMap stubs_; |
| 97 #endif | 93 #endif |
| 98 | 94 |
| 99 bool log_messages_; // True if we should log sent and received messages. | 95 bool log_messages_; // True if we should log sent and received messages. |
| 100 | 96 |
| 101 DISALLOW_COPY_AND_ASSIGN(GpuChannel); | 97 DISALLOW_COPY_AND_ASSIGN(GpuChannel); |
| 102 }; | 98 }; |
| 103 | 99 |
| 104 #endif // CHROME_GPU_GPU_CHANNEL_H_ | 100 #endif // CHROME_GPU_GPU_CHANNEL_H_ |
| OLD | NEW |