| OLD | NEW |
| (Empty) |
| 1 // Copyright (c) 2009 The Chromium Authors. All rights reserved. | |
| 2 // Use of this source code is governed by a BSD-style license that can be | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 #ifndef CHROME_RENDERER_COMMAND_BUFFER_PROXY_H_ | |
| 6 #define CHROME_RENDERER_COMMAND_BUFFER_PROXY_H_ | |
| 7 #pragma once | |
| 8 | |
| 9 #if defined(ENABLE_GPU) | |
| 10 | |
| 11 #include <map> | |
| 12 #include <queue> | |
| 13 | |
| 14 #include "base/callback.h" | |
| 15 #include "base/linked_ptr.h" | |
| 16 #include "base/scoped_ptr.h" | |
| 17 #include "gpu/command_buffer/common/command_buffer.h" | |
| 18 #include "ipc/ipc_channel.h" | |
| 19 #include "ipc/ipc_message.h" | |
| 20 | |
| 21 namespace base { | |
| 22 class SharedMemory; | |
| 23 } | |
| 24 | |
| 25 namespace gfx { | |
| 26 class Size; | |
| 27 } | |
| 28 | |
| 29 class PluginChannelHost; | |
| 30 class Task; | |
| 31 | |
| 32 // Client side proxy that forwards messages synchronously to a | |
| 33 // CommandBufferStub. | |
| 34 class CommandBufferProxy : public gpu::CommandBuffer, | |
| 35 public IPC::Channel::Listener { | |
| 36 public: | |
| 37 CommandBufferProxy(IPC::Channel::Sender* channel, int route_id); | |
| 38 virtual ~CommandBufferProxy(); | |
| 39 | |
| 40 // IPC::Channel::Listener implementation: | |
| 41 virtual bool OnMessageReceived(const IPC::Message& message); | |
| 42 virtual void OnChannelError(); | |
| 43 | |
| 44 int route_id() const { return route_id_; } | |
| 45 | |
| 46 // CommandBuffer implementation: | |
| 47 virtual bool Initialize(int32 size); | |
| 48 virtual bool Initialize(base::SharedMemory* buffer, int32 size); | |
| 49 virtual gpu::Buffer GetRingBuffer(); | |
| 50 virtual State GetState(); | |
| 51 virtual void Flush(int32 put_offset); | |
| 52 virtual State FlushSync(int32 put_offset); | |
| 53 virtual void SetGetOffset(int32 get_offset); | |
| 54 virtual int32 CreateTransferBuffer(size_t size); | |
| 55 virtual int32 RegisterTransferBuffer(base::SharedMemory* shared_memory, | |
| 56 size_t size); | |
| 57 virtual void DestroyTransferBuffer(int32 id); | |
| 58 virtual gpu::Buffer GetTransferBuffer(int32 handle); | |
| 59 virtual void SetToken(int32 token); | |
| 60 virtual void SetParseError(gpu::error::Error error); | |
| 61 virtual void OnSwapBuffers(); | |
| 62 | |
| 63 // Set a callback that will be invoked when the SwapBuffers call has been | |
| 64 // issued. | |
| 65 void SetSwapBuffersCallback(Callback0::Type* callback); | |
| 66 void SetChannelErrorCallback(Callback0::Type* callback); | |
| 67 | |
| 68 // Asynchronously resizes an offscreen frame buffer. | |
| 69 void ResizeOffscreenFrameBuffer(const gfx::Size& size); | |
| 70 | |
| 71 // Set a task that will be invoked the next time the window becomes invalid | |
| 72 // and needs to be repainted. Takes ownership of task. | |
| 73 void SetNotifyRepaintTask(Task* task); | |
| 74 | |
| 75 #if defined(OS_MACOSX) | |
| 76 virtual void SetWindowSize(const gfx::Size& size); | |
| 77 #endif | |
| 78 | |
| 79 // Get the last state received from the service without synchronizing. | |
| 80 State GetLastState() { | |
| 81 return last_state_; | |
| 82 } | |
| 83 | |
| 84 // Get the state asynchronously. The task is posted when the state is | |
| 85 // updated. Takes ownership of the task object. | |
| 86 void AsyncGetState(Task* completion_task); | |
| 87 | |
| 88 // Flush the command buffer asynchronously. The task is posted when the flush | |
| 89 // completes. Takes ownership of the task object. | |
| 90 void AsyncFlush(int32 put_offset, Task* completion_task); | |
| 91 | |
| 92 private: | |
| 93 | |
| 94 // Send an IPC message over the GPU channel. This is private to fully | |
| 95 // encapsulate the channel; all callers of this function must explicitly | |
| 96 // verify that the context has not been lost. | |
| 97 bool Send(IPC::Message* msg); | |
| 98 | |
| 99 // Message handlers: | |
| 100 void OnUpdateState(const gpu::CommandBuffer::State& state); | |
| 101 void OnNotifyRepaint(); | |
| 102 | |
| 103 // As with the service, the client takes ownership of the ring buffer. | |
| 104 int32 num_entries_; | |
| 105 scoped_ptr<base::SharedMemory> ring_buffer_; | |
| 106 | |
| 107 // Local cache of id to transfer buffer mapping. | |
| 108 typedef std::map<int32, gpu::Buffer> TransferBufferMap; | |
| 109 TransferBufferMap transfer_buffers_; | |
| 110 | |
| 111 // The last cached state received from the service. | |
| 112 State last_state_; | |
| 113 | |
| 114 IPC::Channel::Sender* channel_; | |
| 115 int route_id_; | |
| 116 | |
| 117 // Pending asynchronous flush callbacks. | |
| 118 typedef std::queue<linked_ptr<Task> > AsyncFlushTaskQueue; | |
| 119 AsyncFlushTaskQueue pending_async_flush_tasks_; | |
| 120 | |
| 121 scoped_ptr<Task> notify_repaint_task_; | |
| 122 | |
| 123 scoped_ptr<Callback0::Type> swap_buffers_callback_; | |
| 124 scoped_ptr<Callback0::Type> channel_error_callback_; | |
| 125 | |
| 126 DISALLOW_COPY_AND_ASSIGN(CommandBufferProxy); | |
| 127 }; | |
| 128 | |
| 129 #endif // ENABLE_GPU | |
| 130 | |
| 131 #endif // CHROME_RENDERER_COMMAND_BUFFER_PROXY_H_ | |
| OLD | NEW |