Index: content/common/gpu/client/ipc/chrome/chrome_gpu_channel_host_ipc_transport.h |
diff --git a/content/common/gpu/client/ipc/chrome/chrome_gpu_channel_host_ipc_transport.h b/content/common/gpu/client/ipc/chrome/chrome_gpu_channel_host_ipc_transport.h |
new file mode 100644 |
index 0000000000000000000000000000000000000000..207b500ee15d21cbaa066836e97a70aee9b05791 |
--- /dev/null |
+++ b/content/common/gpu/client/ipc/chrome/chrome_gpu_channel_host_ipc_transport.h |
@@ -0,0 +1,141 @@ |
+// Copyright 2015 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_CLIENT_IPC_CHROME_CHROME_GPU_CHANNEL_HOST_IPC_TRANSPORT_H_ |
+#define CONTENT_COMMON_GPU_CLIENT_IPC_CHROME_CHROME_GPU_CHANNEL_HOST_IPC_TRANSPORT_H_ |
+ |
+#include "content/common/gpu/client/ipc/gpu_channel_host_ipc_transport.h" |
+ |
+#include "base/atomic_sequence_num.h" |
+#include "ipc/ipc_listener.h" |
+#include "ipc/ipc_sync_message_filter.h" |
+#include "ipc/message_filter.h" |
+ |
+namespace IPC { |
+struct ChannelHandle; |
+} |
+ |
+namespace content { |
+ |
+class GpuChannelHostFactory; |
+ |
+class ChromeGpuChannelHostIPCTransport : public GpuChannelHostIPCTransport { |
+ public: |
+ static scoped_ptr<GpuChannelHostIPCTransport> Create(); |
+ |
+ ~ChromeGpuChannelHostIPCTransport() override; |
+ |
+ void BindToService(GpuChannelHostFactory* factory, |
+ int channel_id, |
+ const IPC::ChannelHandle& channel_handle, |
+ base::WaitableEvent* shutdown_event); |
+ |
+ int channel_id() const { return channel_id_; } |
+ |
+ GpuChannelHostFactory* factory() const { return factory_; } |
+ |
+ bool Send(IPC::Message* msg); |
+ |
+ // Generate a route ID guaranteed to be unique for this channel. |
+ int32_t GenerateRouteID(); |
+ |
+ // Add a route for the current message loop. |
+ void AddRoute(int route_id, base::WeakPtr<IPC::Listener> listener); |
+ void AddRouteOnIO(int route_id, base::WeakPtr<IPC::Listener> listener); |
+ void RemoveRoute(int route_id); |
+ |
+ private: |
+ ChromeGpuChannelHostIPCTransport(); |
+ |
+ // GpuChannelHostIPCTransport implementation: |
+ bool AsyncFlush(CommandBufferIPCTransport* transport, |
+ int32_t put_offset, |
+ uint32_t flush_count, |
+ const std::vector<ui::LatencyInfo>& latency_info) override; |
+ bool CreateJpegDecoder( |
+ GpuJpegDecodeAcceleratorHostIPCTransport* jpeg_decode_transport, |
+ bool* succeeded) override; |
+ bool CreateViewCommandBuffer( |
+ uint32_t surface_id, |
+ const GpuCreateCommandBufferConfig& init_params, |
+ CommandBufferIPCTransport* command_buffer_transport, |
+ CreateCommandBufferResult* result) override; |
+ bool CreateOffscreenCommandBuffer( |
+ const gfx::Size& size, |
+ const GpuCreateCommandBufferConfig& init_params, |
+ CommandBufferIPCTransport* command_buffer_transport, |
+ bool* succeeded) override; |
+ bool DestroyCommandBuffer( |
+ CommandBufferIPCTransport* command_buffer_transport) override; |
+ bool IsLost() const override; |
+ bool Nop() override; |
+ base::SharedMemoryHandle ShareToGpuProcess( |
+ const base::SharedMemoryHandle& source_handle) override; |
+ |
+ // A filter used internally to route incoming messages from the IO thread |
+ // to the correct message loop. It also maintains some shared state between |
+ // all the contexts. |
+ class MessageFilter : public IPC::MessageFilter { |
+ public: |
+ MessageFilter(); |
+ |
+ // Called on the IO thread. |
+ void AddRoute(int32_t route_id, |
+ base::WeakPtr<IPC::Listener> listener, |
+ scoped_refptr<base::SingleThreadTaskRunner> task_runner); |
+ // Called on the IO thread. |
+ void RemoveRoute(int32_t route_id); |
+ |
+ // IPC::MessageFilter implementation |
+ // (called on the IO thread): |
+ bool OnMessageReceived(const IPC::Message& msg) override; |
+ void OnChannelError() override; |
+ |
+ // The following methods can be called on any thread. |
+ |
+ // Whether the channel is lost. |
+ bool IsLost() const; |
+ |
+ private: |
+ struct ListenerInfo { |
+ ListenerInfo(); |
+ ~ListenerInfo(); |
+ |
+ base::WeakPtr<IPC::Listener> listener; |
+ scoped_refptr<base::SingleThreadTaskRunner> task_runner; |
+ }; |
+ |
+ ~MessageFilter() override; |
+ |
+ // Threading notes: |listeners_| is only accessed on the IO thread. Every |
+ // other field is protected by |lock_|. |
+ base::hash_map<int32_t, ListenerInfo> listeners_; |
+ |
+ // Protects all fields below this one. |
+ mutable base::Lock lock_; |
+ |
+ // Whether the channel has been lost. |
+ bool lost_; |
+ }; |
+ |
+ GpuChannelHostFactory* factory_; |
+ |
+ int channel_id_; |
+ |
+ scoped_refptr<MessageFilter> channel_filter_; |
+ |
+ // A filter for sending messages from thread other than the main thread. |
+ scoped_refptr<IPC::SyncMessageFilter> sync_filter_; |
+ |
+ scoped_ptr<IPC::SyncChannel> channel_; |
+ |
+ // Route IDs are allocated in sequence. |
+ base::AtomicSequenceNumber next_route_id_; |
+ |
+ DISALLOW_COPY_AND_ASSIGN(ChromeGpuChannelHostIPCTransport); |
+}; |
+ |
+} // namespace content |
+ |
+#endif // CONTENT_COMMON_GPU_CLIENT_IPC_CHROME_CHROME_GPU_CHANNEL_HOST_IPC_TRANSPORT_H_ |