OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 #include "ppapi/proxy/ppb_graphics_3d_proxy.h" | 5 #include "ppapi/proxy/ppb_graphics_3d_proxy.h" |
6 | 6 |
7 #include "base/numerics/safe_conversions.h" | 7 #include "base/numerics/safe_conversions.h" |
8 #include "build/build_config.h" | 8 #include "build/build_config.h" |
9 #include "gpu/command_buffer/client/gles2_implementation.h" | 9 #include "gpu/command_buffer/client/gles2_implementation.h" |
10 #include "gpu/command_buffer/common/command_buffer.h" | 10 #include "gpu/command_buffer/common/command_buffer.h" |
(...skipping 30 matching lines...) Expand all Loading... |
41 #endif // !defined(OS_NACL) | 41 #endif // !defined(OS_NACL) |
42 | 42 |
43 gpu::CommandBuffer::State GetErrorState() { | 43 gpu::CommandBuffer::State GetErrorState() { |
44 gpu::CommandBuffer::State error_state; | 44 gpu::CommandBuffer::State error_state; |
45 error_state.error = gpu::error::kGenericError; | 45 error_state.error = gpu::error::kGenericError; |
46 return error_state; | 46 return error_state; |
47 } | 47 } |
48 | 48 |
49 } // namespace | 49 } // namespace |
50 | 50 |
51 Graphics3D::Graphics3D(const HostResource& resource, const gfx::Size& size) | 51 Graphics3D::Graphics3D(const HostResource& resource) |
52 : PPB_Graphics3D_Shared(resource, size) { | 52 : PPB_Graphics3D_Shared(resource) { |
53 } | 53 } |
54 | 54 |
55 Graphics3D::~Graphics3D() { | 55 Graphics3D::~Graphics3D() { |
56 DestroyGLES2Impl(); | 56 DestroyGLES2Impl(); |
57 } | 57 } |
58 | 58 |
59 bool Graphics3D::Init(gpu::gles2::GLES2Implementation* share_gles2, | 59 bool Graphics3D::Init(gpu::gles2::GLES2Implementation* share_gles2, |
60 const gpu::Capabilities& capabilities, | 60 const gpu::Capabilities& capabilities, |
61 const SerializedHandle& shared_state, | 61 const SerializedHandle& shared_state, |
62 gpu::CommandBufferId command_buffer_id) { | 62 gpu::CommandBufferId command_buffer_id) { |
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
111 | 111 |
112 gpu::CommandBuffer* Graphics3D::GetCommandBuffer() { | 112 gpu::CommandBuffer* Graphics3D::GetCommandBuffer() { |
113 return command_buffer_.get(); | 113 return command_buffer_.get(); |
114 } | 114 } |
115 | 115 |
116 gpu::GpuControl* Graphics3D::GetGpuControl() { | 116 gpu::GpuControl* Graphics3D::GetGpuControl() { |
117 return command_buffer_.get(); | 117 return command_buffer_.get(); |
118 } | 118 } |
119 | 119 |
120 int32_t Graphics3D::DoSwapBuffers(const gpu::SyncToken& sync_token, | 120 int32_t Graphics3D::DoSwapBuffers(const gpu::SyncToken& sync_token, |
121 const gfx::Size& size) { | 121 int32_t width, |
| 122 int32_t height) { |
122 // A valid sync token would indicate a swap buffer already happened somehow. | 123 // A valid sync token would indicate a swap buffer already happened somehow. |
123 DCHECK(!sync_token.HasData()); | 124 DCHECK(!sync_token.HasData()); |
124 | 125 |
125 gpu::gles2::GLES2Implementation* gl = gles2_impl(); | 126 gpu::gles2::GLES2Implementation* gl = gles2_impl(); |
126 gl->SwapBuffers(); | 127 gl->SwapBuffers(); |
127 | 128 |
128 PluginDispatcher::GetForResource(this)->Send( | 129 PluginDispatcher::GetForResource(this)->Send( |
129 new PpapiHostMsg_PPBGraphics3D_TakeFrontBuffer(API_ID_PPB_GRAPHICS_3D, | 130 new PpapiHostMsg_PPBGraphics3D_TakeFrontBuffer(API_ID_PPB_GRAPHICS_3D, |
130 host_resource())); | 131 host_resource())); |
131 | 132 |
132 const GLuint64 fence_sync = gl->InsertFenceSyncCHROMIUM(); | 133 const GLuint64 fence_sync = gl->InsertFenceSyncCHROMIUM(); |
133 gl->ShallowFlushCHROMIUM(); | 134 gl->ShallowFlushCHROMIUM(); |
134 | 135 |
135 gpu::SyncToken new_sync_token; | 136 gpu::SyncToken new_sync_token; |
136 gl->GenSyncTokenCHROMIUM(fence_sync, new_sync_token.GetData()); | 137 gl->GenSyncTokenCHROMIUM(fence_sync, new_sync_token.GetData()); |
137 | 138 |
138 IPC::Message* msg = new PpapiHostMsg_PPBGraphics3D_SwapBuffers( | 139 IPC::Message* msg = new PpapiHostMsg_PPBGraphics3D_SwapBuffers( |
139 API_ID_PPB_GRAPHICS_3D, host_resource(), new_sync_token, size); | 140 API_ID_PPB_GRAPHICS_3D, host_resource(), new_sync_token, width, |
| 141 height); |
140 msg->set_unblock(true); | 142 msg->set_unblock(true); |
141 PluginDispatcher::GetForResource(this)->Send(msg); | 143 PluginDispatcher::GetForResource(this)->Send(msg); |
142 | 144 |
143 return PP_OK_COMPLETIONPENDING; | 145 return PP_OK_COMPLETIONPENDING; |
144 } | 146 } |
145 | 147 |
146 PPB_Graphics3D_Proxy::PPB_Graphics3D_Proxy(Dispatcher* dispatcher) | 148 PPB_Graphics3D_Proxy::PPB_Graphics3D_Proxy(Dispatcher* dispatcher) |
147 : InterfaceProxy(dispatcher), | 149 : InterfaceProxy(dispatcher), |
148 callback_factory_(this) { | 150 callback_factory_(this) { |
149 } | 151 } |
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
206 gpu::Capabilities capabilities; | 208 gpu::Capabilities capabilities; |
207 ppapi::proxy::SerializedHandle shared_state; | 209 ppapi::proxy::SerializedHandle shared_state; |
208 gpu::CommandBufferId command_buffer_id; | 210 gpu::CommandBufferId command_buffer_id; |
209 dispatcher->Send(new PpapiHostMsg_PPBGraphics3D_Create( | 211 dispatcher->Send(new PpapiHostMsg_PPBGraphics3D_Create( |
210 API_ID_PPB_GRAPHICS_3D, instance, share_host, attrib_helper, &result, | 212 API_ID_PPB_GRAPHICS_3D, instance, share_host, attrib_helper, &result, |
211 &capabilities, &shared_state, &command_buffer_id)); | 213 &capabilities, &shared_state, &command_buffer_id)); |
212 | 214 |
213 if (result.is_null()) | 215 if (result.is_null()) |
214 return 0; | 216 return 0; |
215 | 217 |
216 scoped_refptr<Graphics3D> graphics_3d( | 218 scoped_refptr<Graphics3D> graphics_3d(new Graphics3D(result)); |
217 new Graphics3D(result, attrib_helper.offscreen_framebuffer_size)); | |
218 if (!graphics_3d->Init(share_gles2, capabilities, shared_state, | 219 if (!graphics_3d->Init(share_gles2, capabilities, shared_state, |
219 command_buffer_id)) { | 220 command_buffer_id)) { |
220 return 0; | 221 return 0; |
221 } | 222 } |
222 return graphics_3d->GetReference(); | 223 return graphics_3d->GetReference(); |
223 } | 224 } |
224 | 225 |
225 bool PPB_Graphics3D_Proxy::OnMessageReceived(const IPC::Message& msg) { | 226 bool PPB_Graphics3D_Proxy::OnMessageReceived(const IPC::Message& msg) { |
226 bool handled = true; | 227 bool handled = true; |
227 IPC_BEGIN_MESSAGE_MAP(PPB_Graphics3D_Proxy, msg) | 228 IPC_BEGIN_MESSAGE_MAP(PPB_Graphics3D_Proxy, msg) |
(...skipping 125 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
353 void PPB_Graphics3D_Proxy::OnMsgDestroyTransferBuffer( | 354 void PPB_Graphics3D_Proxy::OnMsgDestroyTransferBuffer( |
354 const HostResource& context, | 355 const HostResource& context, |
355 int32_t id) { | 356 int32_t id) { |
356 EnterHostFromHostResource<PPB_Graphics3D_API> enter(context); | 357 EnterHostFromHostResource<PPB_Graphics3D_API> enter(context); |
357 if (enter.succeeded()) | 358 if (enter.succeeded()) |
358 enter.object()->DestroyTransferBuffer(id); | 359 enter.object()->DestroyTransferBuffer(id); |
359 } | 360 } |
360 | 361 |
361 void PPB_Graphics3D_Proxy::OnMsgSwapBuffers(const HostResource& context, | 362 void PPB_Graphics3D_Proxy::OnMsgSwapBuffers(const HostResource& context, |
362 const gpu::SyncToken& sync_token, | 363 const gpu::SyncToken& sync_token, |
363 const gfx::Size& size) { | 364 int32_t width, |
| 365 int32_t height) { |
364 EnterHostFromHostResourceForceCallback<PPB_Graphics3D_API> enter( | 366 EnterHostFromHostResourceForceCallback<PPB_Graphics3D_API> enter( |
365 context, callback_factory_, | 367 context, callback_factory_, |
366 &PPB_Graphics3D_Proxy::SendSwapBuffersACKToPlugin, context); | 368 &PPB_Graphics3D_Proxy::SendSwapBuffersACKToPlugin, context); |
367 if (enter.succeeded()) | 369 if (enter.succeeded()) |
368 enter.SetResult(enter.object()->SwapBuffersWithSyncToken( | 370 enter.SetResult(enter.object()->SwapBuffersWithSyncToken( |
369 enter.callback(), sync_token, size)); | 371 enter.callback(), sync_token, width, height)); |
370 } | 372 } |
371 | 373 |
372 void PPB_Graphics3D_Proxy::OnMsgTakeFrontBuffer(const HostResource& context) { | 374 void PPB_Graphics3D_Proxy::OnMsgTakeFrontBuffer(const HostResource& context) { |
373 EnterHostFromHostResource<PPB_Graphics3D_API> enter(context); | 375 EnterHostFromHostResource<PPB_Graphics3D_API> enter(context); |
374 if (enter.succeeded()) | 376 if (enter.succeeded()) |
375 enter.object()->TakeFrontBuffer(); | 377 enter.object()->TakeFrontBuffer(); |
376 } | 378 } |
377 | 379 |
378 void PPB_Graphics3D_Proxy::OnMsgEnsureWorkVisible(const HostResource& context) { | 380 void PPB_Graphics3D_Proxy::OnMsgEnsureWorkVisible(const HostResource& context) { |
379 EnterHostFromHostResource<PPB_Graphics3D_API> enter(context); | 381 EnterHostFromHostResource<PPB_Graphics3D_API> enter(context); |
(...skipping 13 matching lines...) Expand all Loading... |
393 void PPB_Graphics3D_Proxy::SendSwapBuffersACKToPlugin( | 395 void PPB_Graphics3D_Proxy::SendSwapBuffersACKToPlugin( |
394 int32_t result, | 396 int32_t result, |
395 const HostResource& context) { | 397 const HostResource& context) { |
396 dispatcher()->Send(new PpapiMsg_PPBGraphics3D_SwapBuffersACK( | 398 dispatcher()->Send(new PpapiMsg_PPBGraphics3D_SwapBuffersACK( |
397 API_ID_PPB_GRAPHICS_3D, context, result)); | 399 API_ID_PPB_GRAPHICS_3D, context, result)); |
398 } | 400 } |
399 #endif // !defined(OS_NACL) | 401 #endif // !defined(OS_NACL) |
400 | 402 |
401 } // namespace proxy | 403 } // namespace proxy |
402 } // namespace ppapi | 404 } // namespace ppapi |
OLD | NEW |