| OLD | NEW |
| (Empty) |
| 1 // Copyright (c) 2011 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 CONTENT_RENDERER_COMMAND_BUFFER_PROXY_H_ | |
| 6 #define CONTENT_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_old.h" | |
| 15 #include "base/memory/linked_ptr.h" | |
| 16 #include "base/memory/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, int32 last_known_get); | |
| 53 virtual void SetGetOffset(int32 get_offset); | |
| 54 virtual int32 CreateTransferBuffer(size_t size, int32 id_request); | |
| 55 virtual int32 RegisterTransferBuffer(base::SharedMemory* shared_memory, | |
| 56 size_t size, | |
| 57 int32 id_request); | |
| 58 virtual void DestroyTransferBuffer(int32 id); | |
| 59 virtual gpu::Buffer GetTransferBuffer(int32 handle); | |
| 60 virtual void SetToken(int32 token); | |
| 61 virtual void SetParseError(gpu::error::Error error); | |
| 62 virtual void OnSwapBuffers(); | |
| 63 | |
| 64 // Set a callback that will be invoked when the SwapBuffers call has been | |
| 65 // issued. | |
| 66 void SetSwapBuffersCallback(Callback0::Type* callback); | |
| 67 void SetChannelErrorCallback(Callback0::Type* callback); | |
| 68 | |
| 69 // Asynchronously resizes an offscreen frame buffer. | |
| 70 void ResizeOffscreenFrameBuffer(const gfx::Size& size); | |
| 71 | |
| 72 // Set a task that will be invoked the next time the window becomes invalid | |
| 73 // and needs to be repainted. Takes ownership of task. | |
| 74 void SetNotifyRepaintTask(Task* task); | |
| 75 | |
| 76 #if defined(OS_MACOSX) | |
| 77 virtual void SetWindowSize(const gfx::Size& size); | |
| 78 #endif | |
| 79 | |
| 80 // Get the last state received from the service without synchronizing. | |
| 81 State GetLastState() { | |
| 82 return last_state_; | |
| 83 } | |
| 84 | |
| 85 private: | |
| 86 | |
| 87 // Send an IPC message over the GPU channel. This is private to fully | |
| 88 // encapsulate the channel; all callers of this function must explicitly | |
| 89 // verify that the context has not been lost. | |
| 90 bool Send(IPC::Message* msg); | |
| 91 | |
| 92 // Message handlers: | |
| 93 void OnUpdateState(const gpu::CommandBuffer::State& state); | |
| 94 void OnNotifyRepaint(); | |
| 95 | |
| 96 // As with the service, the client takes ownership of the ring buffer. | |
| 97 int32 num_entries_; | |
| 98 scoped_ptr<base::SharedMemory> ring_buffer_; | |
| 99 | |
| 100 // Local cache of id to transfer buffer mapping. | |
| 101 typedef std::map<int32, gpu::Buffer> TransferBufferMap; | |
| 102 TransferBufferMap transfer_buffers_; | |
| 103 | |
| 104 // The last cached state received from the service. | |
| 105 State last_state_; | |
| 106 | |
| 107 IPC::Channel::Sender* channel_; | |
| 108 int route_id_; | |
| 109 | |
| 110 scoped_ptr<Task> notify_repaint_task_; | |
| 111 | |
| 112 scoped_ptr<Callback0::Type> swap_buffers_callback_; | |
| 113 scoped_ptr<Callback0::Type> channel_error_callback_; | |
| 114 | |
| 115 DISALLOW_COPY_AND_ASSIGN(CommandBufferProxy); | |
| 116 }; | |
| 117 | |
| 118 #endif // ENABLE_GPU | |
| 119 | |
| 120 #endif // CONTENT_RENDERER_COMMAND_BUFFER_PROXY_H_ | |
| OLD | NEW |