| 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 #include "chrome/plugin/command_buffer_stub.h" | |
| 6 | |
| 7 #include "base/callback.h" | |
| 8 #include "base/scoped_open_process.h" | |
| 9 #include "base/shared_memory.h" | |
| 10 #include "chrome/common/gpu_messages.h" | |
| 11 #include "chrome/common/plugin_messages.h" | |
| 12 #include "chrome/plugin/plugin_channel.h" | |
| 13 | |
| 14 using gpu::Buffer; | |
| 15 | |
| 16 CommandBufferStub::CommandBufferStub(PluginChannel* channel, | |
| 17 int plugin_host_route_id, | |
| 18 gfx::PluginWindowHandle window) | |
| 19 : channel_(channel), | |
| 20 plugin_host_route_id_(plugin_host_route_id), | |
| 21 window_(window) { | |
| 22 route_id_ = channel->GenerateRouteID(); | |
| 23 channel->AddRoute(route_id_, this, NULL); | |
| 24 } | |
| 25 | |
| 26 CommandBufferStub::~CommandBufferStub() { | |
| 27 Destroy(); | |
| 28 channel_->RemoveRoute(route_id_); | |
| 29 } | |
| 30 | |
| 31 bool CommandBufferStub::OnMessageReceived(const IPC::Message& message) { | |
| 32 bool handled = true; | |
| 33 IPC_BEGIN_MESSAGE_MAP(CommandBufferStub, message) | |
| 34 IPC_MESSAGE_HANDLER(GpuCommandBufferMsg_Initialize, OnInitialize); | |
| 35 IPC_MESSAGE_HANDLER(GpuCommandBufferMsg_GetState, OnGetState); | |
| 36 IPC_MESSAGE_HANDLER(GpuCommandBufferMsg_AsyncGetState, OnAsyncGetState); | |
| 37 IPC_MESSAGE_HANDLER(GpuCommandBufferMsg_Flush, OnFlush); | |
| 38 IPC_MESSAGE_HANDLER(GpuCommandBufferMsg_AsyncFlush, OnAsyncFlush); | |
| 39 IPC_MESSAGE_HANDLER(GpuCommandBufferMsg_CreateTransferBuffer, | |
| 40 OnCreateTransferBuffer); | |
| 41 IPC_MESSAGE_HANDLER(GpuCommandBufferMsg_DestroyTransferBuffer, | |
| 42 OnDestroyTransferBuffer); | |
| 43 IPC_MESSAGE_HANDLER(GpuCommandBufferMsg_GetTransferBuffer, | |
| 44 OnGetTransferBuffer); | |
| 45 #if defined(OS_MACOSX) | |
| 46 IPC_MESSAGE_HANDLER(GpuCommandBufferMsg_SetWindowSize, OnSetWindowSize); | |
| 47 #endif | |
| 48 IPC_MESSAGE_UNHANDLED(handled = false) | |
| 49 IPC_END_MESSAGE_MAP() | |
| 50 DCHECK(handled); | |
| 51 return handled; | |
| 52 } | |
| 53 | |
| 54 void CommandBufferStub::OnChannelError() { | |
| 55 NOTREACHED() << "CommandBufferService::OnChannelError called"; | |
| 56 } | |
| 57 | |
| 58 bool CommandBufferStub::Send(IPC::Message* message) { | |
| 59 if (!channel_) { | |
| 60 delete message; | |
| 61 return false; | |
| 62 } | |
| 63 | |
| 64 return channel_->Send(message); | |
| 65 } | |
| 66 | |
| 67 void CommandBufferStub::NotifyRepaint() { | |
| 68 Send(new GpuCommandBufferMsg_NotifyRepaint(route_id_)); | |
| 69 } | |
| 70 | |
| 71 void CommandBufferStub::OnInitialize(base::SharedMemoryHandle ring_buffer, | |
| 72 int32 size, | |
| 73 bool* result) { | |
| 74 // TODO(apatrick): Pepper3D v1 is not used anymore. This function is never | |
| 75 // called. Delete the GPU plugin. | |
| 76 NOTREACHED(); | |
| 77 *result = false; | |
| 78 } | |
| 79 | |
| 80 void CommandBufferStub::OnGetState(gpu::CommandBuffer::State* state) { | |
| 81 *state = command_buffer_->GetState(); | |
| 82 } | |
| 83 | |
| 84 void CommandBufferStub::OnAsyncGetState() { | |
| 85 gpu::CommandBuffer::State state = command_buffer_->GetState(); | |
| 86 Send(new GpuCommandBufferMsg_UpdateState(route_id_, state)); | |
| 87 } | |
| 88 | |
| 89 void CommandBufferStub::OnFlush(int32 put_offset, | |
| 90 gpu::CommandBuffer::State* state) { | |
| 91 *state = command_buffer_->FlushSync(put_offset); | |
| 92 } | |
| 93 | |
| 94 void CommandBufferStub::OnAsyncFlush(int32 put_offset) { | |
| 95 gpu::CommandBuffer::State state = command_buffer_->FlushSync(put_offset); | |
| 96 Send(new GpuCommandBufferMsg_UpdateState(route_id_, state)); | |
| 97 } | |
| 98 | |
| 99 void CommandBufferStub::OnCreateTransferBuffer(int32 size, int32* id) { | |
| 100 *id = command_buffer_->CreateTransferBuffer(size); | |
| 101 } | |
| 102 | |
| 103 void CommandBufferStub::OnDestroyTransferBuffer(int32 id) { | |
| 104 command_buffer_->DestroyTransferBuffer(id); | |
| 105 } | |
| 106 | |
| 107 void CommandBufferStub::OnGetTransferBuffer( | |
| 108 int32 id, | |
| 109 base::SharedMemoryHandle* transfer_buffer, | |
| 110 uint32* size) { | |
| 111 *transfer_buffer = base::SharedMemoryHandle(); | |
| 112 *size = 0; | |
| 113 | |
| 114 // Assume service is responsible for duplicating the handle to the calling | |
| 115 // process. | |
| 116 base::ProcessHandle peer_handle; | |
| 117 if (!base::OpenProcessHandle(channel_->peer_pid(), &peer_handle)) | |
| 118 return; | |
| 119 | |
| 120 Buffer buffer = command_buffer_->GetTransferBuffer(id); | |
| 121 if (buffer.shared_memory) { | |
| 122 buffer.shared_memory->ShareToProcess(peer_handle, transfer_buffer); | |
| 123 *size = buffer.shared_memory->created_size(); | |
| 124 } | |
| 125 | |
| 126 base::CloseProcessHandle(peer_handle); | |
| 127 } | |
| 128 | |
| 129 void CommandBufferStub::Destroy() { | |
| 130 processor_.reset(); | |
| 131 command_buffer_.reset(); | |
| 132 | |
| 133 DestroyPlatformSpecific(); | |
| 134 } | |
| 135 | |
| 136 #if !defined(OS_WIN) | |
| 137 bool CommandBufferStub::InitializePlatformSpecific() { | |
| 138 return true; | |
| 139 } | |
| 140 | |
| 141 void CommandBufferStub::DestroyPlatformSpecific() { | |
| 142 } | |
| 143 #endif // defined(OS_WIN) | |
| 144 | |
| 145 #if defined(OS_MACOSX) | |
| 146 void CommandBufferStub::OnSetWindowSize(const gfx::Size& size) { | |
| 147 // Try using the IOSurface version first. | |
| 148 bool notify_repaint = false; | |
| 149 uint64 new_backing_store = processor_->SetWindowSizeForIOSurface(size); | |
| 150 if (new_backing_store) { | |
| 151 Send(new PluginHostMsg_AcceleratedSurfaceSetIOSurface( | |
| 152 plugin_host_route_id_, | |
| 153 window_, | |
| 154 size.width(), | |
| 155 size.height(), | |
| 156 new_backing_store)); | |
| 157 notify_repaint = true; | |
| 158 } else { | |
| 159 // If |new_backing_store| is 0, it might mean that the IOSurface APIs are | |
| 160 // not available. In this case, see if TransportDIBs are supported. | |
| 161 TransportDIB::Handle transport_dib = | |
| 162 processor_->SetWindowSizeForTransportDIB(size); | |
| 163 if (TransportDIB::is_valid(transport_dib)) { | |
| 164 Send(new PluginHostMsg_AcceleratedSurfaceSetTransportDIB( | |
| 165 plugin_host_route_id_, | |
| 166 window_, | |
| 167 size.width(), | |
| 168 size.height(), | |
| 169 transport_dib)); | |
| 170 notify_repaint = true; | |
| 171 } | |
| 172 } | |
| 173 if (notify_repaint) { | |
| 174 // Indicate to the client that at least one repaint is needed. | |
| 175 NotifyRepaint(); | |
| 176 } | |
| 177 } | |
| 178 | |
| 179 void CommandBufferStub::SwapBuffersCallback() { | |
| 180 Send(new PluginHostMsg_AcceleratedSurfaceBuffersSwapped( | |
| 181 plugin_host_route_id_, window_, processor_->GetSurfaceId())); | |
| 182 } | |
| 183 | |
| 184 void CommandBufferStub::AllocTransportDIB(const size_t size, | |
| 185 TransportDIB::Handle* dib_handle) { | |
| 186 Send(new PluginHostMsg_AllocTransportDIB(plugin_host_route_id_, | |
| 187 size, | |
| 188 dib_handle)); | |
| 189 } | |
| 190 | |
| 191 void CommandBufferStub::FreeTransportDIB(TransportDIB::Id dib_id) { | |
| 192 Send(new PluginHostMsg_FreeTransportDIB(plugin_host_route_id_, | |
| 193 dib_id)); | |
| 194 } | |
| 195 #endif | |
| OLD | NEW |