[email protected] | aaa11b3 | 2012-03-08 12:30:13 | [diff] [blame] | 1 | // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
[email protected] | eeb4e4a | 2011-07-19 16:22:06 | [diff] [blame] | 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 "ppapi/proxy/ppb_graphics_3d_proxy.h" |
| 6 | |
brettw | 669d47b1 | 2015-02-13 21:17:38 | [diff] [blame] | 7 | #include "base/numerics/safe_conversions.h" |
avi | e029c413 | 2015-12-23 06:45:22 | [diff] [blame] | 8 | #include "build/build_config.h" |
[email protected] | eeb4e4a | 2011-07-19 16:22:06 | [diff] [blame] | 9 | #include "gpu/command_buffer/client/gles2_implementation.h" |
[email protected] | 84b44c55 | 2012-10-15 20:58:17 | [diff] [blame] | 10 | #include "gpu/command_buffer/common/command_buffer.h" |
dyen | ddfdbbb | 2016-01-14 22:21:38 | [diff] [blame] | 11 | #include "gpu/command_buffer/common/sync_token.h" |
[email protected] | eeb4e4a | 2011-07-19 16:22:06 | [diff] [blame] | 12 | #include "ppapi/c/pp_errors.h" |
| 13 | #include "ppapi/proxy/enter_proxy.h" |
| 14 | #include "ppapi/proxy/plugin_dispatcher.h" |
[email protected] | aaa11b3 | 2012-03-08 12:30:13 | [diff] [blame] | 15 | #include "ppapi/proxy/ppapi_command_buffer_proxy.h" |
[email protected] | eeb4e4a | 2011-07-19 16:22:06 | [diff] [blame] | 16 | #include "ppapi/proxy/ppapi_messages.h" |
[email protected] | 84b44c55 | 2012-10-15 20:58:17 | [diff] [blame] | 17 | #include "ppapi/shared_impl/ppapi_globals.h" |
[email protected] | eeb4e4a | 2011-07-19 16:22:06 | [diff] [blame] | 18 | #include "ppapi/thunk/enter.h" |
| 19 | #include "ppapi/thunk/resource_creation_api.h" |
| 20 | #include "ppapi/thunk/thunk.h" |
| 21 | |
[email protected] | eeb4e4a | 2011-07-19 16:22:06 | [diff] [blame] | 22 | using ppapi::thunk::EnterResourceNoLock; |
| 23 | using ppapi::thunk::PPB_Graphics3D_API; |
| 24 | using ppapi::thunk::ResourceCreationAPI; |
| 25 | |
[email protected] | 4d2efd2 | 2011-08-18 21:58:02 | [diff] [blame] | 26 | namespace ppapi { |
[email protected] | eeb4e4a | 2011-07-19 16:22:06 | [diff] [blame] | 27 | namespace proxy { |
| 28 | |
| 29 | namespace { |
[email protected] | 84b44c55 | 2012-10-15 20:58:17 | [diff] [blame] | 30 | |
mazda | 9cfbcfb | 2014-11-12 17:07:11 | [diff] [blame] | 31 | #if !defined(OS_NACL) |
Alexandr Ilin | 15bb703 | 2018-07-13 10:09:06 | [diff] [blame] | 32 | base::UnsafeSharedMemoryRegion TransportSHMHandle( |
penghuang | a206fb49 | 2014-09-09 21:27:32 | [diff] [blame] | 33 | Dispatcher* dispatcher, |
Alexandr Ilin | 15bb703 | 2018-07-13 10:09:06 | [diff] [blame] | 34 | const base::UnsafeSharedMemoryRegion& region) { |
| 35 | return dispatcher->ShareUnsafeSharedMemoryRegionWithRemote(region); |
[email protected] | eeb4e4a | 2011-07-19 16:22:06 | [diff] [blame] | 36 | } |
mazda | 9cfbcfb | 2014-11-12 17:07:11 | [diff] [blame] | 37 | #endif // !defined(OS_NACL) |
[email protected] | eeb4e4a | 2011-07-19 16:22:06 | [diff] [blame] | 38 | |
[email protected] | 914f526 | 2013-06-01 00:17:22 | [diff] [blame] | 39 | gpu::CommandBuffer::State GetErrorState() { |
| 40 | gpu::CommandBuffer::State error_state; |
| 41 | error_state.error = gpu::error::kGenericError; |
[email protected] | eeb4e4a | 2011-07-19 16:22:06 | [diff] [blame] | 42 | return error_state; |
| 43 | } |
| 44 | |
[email protected] | eeb4e4a | 2011-07-19 16:22:06 | [diff] [blame] | 45 | } // namespace |
| 46 | |
Daniele Castagna | 141a88a | 2018-07-30 19:41:23 | [diff] [blame] | 47 | Graphics3D::Graphics3D(const HostResource& resource, |
| 48 | const gfx::Size& size, |
| 49 | const bool single_buffer) |
| 50 | : PPB_Graphics3D_Shared(resource, size), single_buffer(single_buffer) {} |
[email protected] | eeb4e4a | 2011-07-19 16:22:06 | [diff] [blame] | 51 | |
| 52 | Graphics3D::~Graphics3D() { |
[email protected] | edccb56 | 2013-10-02 00:01:20 | [diff] [blame] | 53 | DestroyGLES2Impl(); |
[email protected] | eeb4e4a | 2011-07-19 16:22:06 | [diff] [blame] | 54 | } |
| 55 | |
penghuang | a206fb49 | 2014-09-09 21:27:32 | [diff] [blame] | 56 | bool Graphics3D::Init(gpu::gles2::GLES2Implementation* share_gles2, |
piman | 360175c | 2014-11-07 02:30:01 | [diff] [blame] | 57 | const gpu::Capabilities& capabilities, |
Alexandr Ilin | 15bb703 | 2018-07-13 10:09:06 | [diff] [blame] | 58 | SerializedHandle shared_state, |
lukasza | 2573ce7d | 2016-02-16 19:17:22 | [diff] [blame] | 59 | gpu::CommandBufferId command_buffer_id) { |
[email protected] | 7f8b26b | 2011-08-18 15:41:01 | [diff] [blame] | 60 | PluginDispatcher* dispatcher = PluginDispatcher::GetForResource(this); |
[email protected] | eeb4e4a | 2011-07-19 16:22:06 | [diff] [blame] | 61 | if (!dispatcher) |
| 62 | return false; |
| 63 | |
Sunny Sachanandani | fd979a8 | 2018-03-27 00:26:03 | [diff] [blame] | 64 | InstanceData* data = dispatcher->GetInstanceData(host_resource().instance()); |
| 65 | DCHECK(data); |
| 66 | |
piman | 360175c | 2014-11-07 02:30:01 | [diff] [blame] | 67 | command_buffer_.reset(new PpapiCommandBufferProxy( |
Sunny Sachanandani | fd979a8 | 2018-03-27 00:26:03 | [diff] [blame] | 68 | host_resource(), &data->flush_info, dispatcher, capabilities, |
Alexandr Ilin | 15bb703 | 2018-07-13 10:09:06 | [diff] [blame] | 69 | std::move(shared_state), command_buffer_id)); |
[email protected] | 84b44c55 | 2012-10-15 20:58:17 | [diff] [blame] | 70 | |
Eric Karl | 2fc4409b9 | 2017-08-18 18:48:39 | [diff] [blame] | 71 | return CreateGLES2Impl(share_gles2); |
[email protected] | eeb4e4a | 2011-07-19 16:22:06 | [diff] [blame] | 72 | } |
| 73 | |
[email protected] | 503b3a2 | 2011-12-12 23:29:40 | [diff] [blame] | 74 | PP_Bool Graphics3D::SetGetBuffer(int32_t /* transfer_buffer_id */) { |
[email protected] | eeb4e4a | 2011-07-19 16:22:06 | [diff] [blame] | 75 | return PP_FALSE; |
| 76 | } |
| 77 | |
[email protected] | eeb4e4a | 2011-07-19 16:22:06 | [diff] [blame] | 78 | PP_Bool Graphics3D::Flush(int32_t put_offset) { |
| 79 | return PP_FALSE; |
| 80 | } |
| 81 | |
[email protected] | 046fa1ac | 2014-04-01 09:06:43 | [diff] [blame] | 82 | scoped_refptr<gpu::Buffer> Graphics3D::CreateTransferBuffer( |
| 83 | uint32_t size, |
| 84 | int32_t* id) { |
| 85 | *id = -1; |
kylechar | 8b8ecebb | 2019-10-29 20:08:10 | [diff] [blame^] | 86 | return nullptr; |
[email protected] | eeb4e4a | 2011-07-19 16:22:06 | [diff] [blame] | 87 | } |
| 88 | |
| 89 | PP_Bool Graphics3D::DestroyTransferBuffer(int32_t id) { |
| 90 | return PP_FALSE; |
| 91 | } |
| 92 | |
[email protected] | 7fe4198b | 2014-03-18 21:52:36 | [diff] [blame] | 93 | gpu::CommandBuffer::State Graphics3D::WaitForTokenInRange(int32_t start, |
| 94 | int32_t end) { |
| 95 | return GetErrorState(); |
| 96 | } |
| 97 | |
Antoine Labour | d346994 | 2017-05-16 21:23:42 | [diff] [blame] | 98 | gpu::CommandBuffer::State Graphics3D::WaitForGetOffsetInRange( |
| 99 | uint32_t set_get_buffer_count, |
| 100 | int32_t start, |
| 101 | int32_t end) { |
[email protected] | eeb4e4a | 2011-07-19 16:22:06 | [diff] [blame] | 102 | return GetErrorState(); |
| 103 | } |
| 104 | |
dyen | 4de3d345f | 2016-01-12 18:30:42 | [diff] [blame] | 105 | void Graphics3D::EnsureWorkVisible() { |
| 106 | NOTREACHED(); |
| 107 | } |
| 108 | |
erikchen | 438b044 | 2016-05-11 18:33:30 | [diff] [blame] | 109 | void Graphics3D::TakeFrontBuffer() { |
| 110 | NOTREACHED(); |
| 111 | } |
| 112 | |
[email protected] | eeb4e4a | 2011-07-19 16:22:06 | [diff] [blame] | 113 | gpu::CommandBuffer* Graphics3D::GetCommandBuffer() { |
[email protected] | 4e46a73 | 2013-09-30 18:35:59 | [diff] [blame] | 114 | return command_buffer_.get(); |
[email protected] | eeb4e4a | 2011-07-19 16:22:06 | [diff] [blame] | 115 | } |
| 116 | |
[email protected] | 744e079 | 2013-09-27 01:18:35 | [diff] [blame] | 117 | gpu::GpuControl* Graphics3D::GetGpuControl() { |
| 118 | return command_buffer_.get(); |
| 119 | } |
| 120 | |
erikchen | b13637b | 2016-07-08 09:38:56 | [diff] [blame] | 121 | int32_t Graphics3D::DoSwapBuffers(const gpu::SyncToken& sync_token, |
piman | b36392c2 | 2016-07-13 02:11:36 | [diff] [blame] | 122 | const gfx::Size& size) { |
dyen | ddfdbbb | 2016-01-14 22:21:38 | [diff] [blame] | 123 | // A valid sync token would indicate a swap buffer already happened somehow. |
| 124 | DCHECK(!sync_token.HasData()); |
| 125 | |
| 126 | gpu::gles2::GLES2Implementation* gl = gles2_impl(); |
Eric Karl | b6b2c63 | 2018-05-07 22:45:04 | [diff] [blame] | 127 | gl->SwapBuffers(swap_id_++); |
erikchen | 438b044 | 2016-05-11 18:33:30 | [diff] [blame] | 128 | |
Daniele Castagna | 141a88a | 2018-07-30 19:41:23 | [diff] [blame] | 129 | if (!single_buffer || swap_id_ == 1) { |
| 130 | PluginDispatcher::GetForResource(this)->Send( |
| 131 | new PpapiHostMsg_PPBGraphics3D_TakeFrontBuffer(API_ID_PPB_GRAPHICS_3D, |
| 132 | host_resource())); |
| 133 | } |
erikchen | 438b044 | 2016-05-11 18:33:30 | [diff] [blame] | 134 | |
dyen | ddfdbbb | 2016-01-14 22:21:38 | [diff] [blame] | 135 | gpu::SyncToken new_sync_token; |
Sunny Sachanandani | c94b8de | 2017-12-16 03:30:30 | [diff] [blame] | 136 | gl->GenSyncTokenCHROMIUM(new_sync_token.GetData()); |
dyen | ddfdbbb | 2016-01-14 22:21:38 | [diff] [blame] | 137 | |
[email protected] | eeb4e4a | 2011-07-19 16:22:06 | [diff] [blame] | 138 | IPC::Message* msg = new PpapiHostMsg_PPBGraphics3D_SwapBuffers( |
piman | b36392c2 | 2016-07-13 02:11:36 | [diff] [blame] | 139 | API_ID_PPB_GRAPHICS_3D, host_resource(), new_sync_token, size); |
[email protected] | eeb4e4a | 2011-07-19 16:22:06 | [diff] [blame] | 140 | msg->set_unblock(true); |
[email protected] | 7f8b26b | 2011-08-18 15:41:01 | [diff] [blame] | 141 | PluginDispatcher::GetForResource(this)->Send(msg); |
[email protected] | eeb4e4a | 2011-07-19 16:22:06 | [diff] [blame] | 142 | |
[email protected] | eeb4e4a | 2011-07-19 16:22:06 | [diff] [blame] | 143 | return PP_OK_COMPLETIONPENDING; |
| 144 | } |
| 145 | |
[email protected] | 5c96602 | 2011-09-13 18:09:37 | [diff] [blame] | 146 | PPB_Graphics3D_Proxy::PPB_Graphics3D_Proxy(Dispatcher* dispatcher) |
| 147 | : InterfaceProxy(dispatcher), |
[email protected] | a2f53dc | 2013-04-30 01:06:35 | [diff] [blame] | 148 | callback_factory_(this) { |
[email protected] | eeb4e4a | 2011-07-19 16:22:06 | [diff] [blame] | 149 | } |
| 150 | |
| 151 | PPB_Graphics3D_Proxy::~PPB_Graphics3D_Proxy() { |
| 152 | } |
| 153 | |
| 154 | // static |
[email protected] | eeb4e4a | 2011-07-19 16:22:06 | [diff] [blame] | 155 | PP_Resource PPB_Graphics3D_Proxy::CreateProxyResource( |
| 156 | PP_Instance instance, |
[email protected] | eeb4e4a | 2011-07-19 16:22:06 | [diff] [blame] | 157 | PP_Resource share_context, |
| 158 | const int32_t* attrib_list) { |
| 159 | PluginDispatcher* dispatcher = PluginDispatcher::GetForInstance(instance); |
| 160 | if (!dispatcher) |
| 161 | return PP_ERROR_BADARGUMENT; |
| 162 | |
[email protected] | 9ed07f8 | 2012-05-29 21:54:55 | [diff] [blame] | 163 | HostResource share_host; |
kylechar | 8b8ecebb | 2019-10-29 20:08:10 | [diff] [blame^] | 164 | gpu::gles2::GLES2Implementation* share_gles2 = nullptr; |
[email protected] | 9ed07f8 | 2012-05-29 21:54:55 | [diff] [blame] | 165 | if (share_context != 0) { |
| 166 | EnterResourceNoLock<PPB_Graphics3D_API> enter(share_context, true); |
| 167 | if (enter.failed()) |
| 168 | return PP_ERROR_BADARGUMENT; |
| 169 | |
| 170 | PPB_Graphics3D_Shared* share_graphics = |
| 171 | static_cast<PPB_Graphics3D_Shared*>(enter.object()); |
| 172 | share_host = share_graphics->host_resource(); |
| 173 | share_gles2 = share_graphics->gles2_impl(); |
| 174 | } |
[email protected] | eeb4e4a | 2011-07-19 16:22:06 | [diff] [blame] | 175 | |
Antoine Labour | feab239 | 2017-12-21 20:28:39 | [diff] [blame] | 176 | gpu::ContextCreationAttribs attrib_helper; |
[email protected] | eeb4e4a | 2011-07-19 16:22:06 | [diff] [blame] | 177 | if (attrib_list) { |
piman | fe4e488 | 2016-07-09 01:18:21 | [diff] [blame] | 178 | for (const int32_t* attr = attrib_list; attr[0] != PP_GRAPHICS3DATTRIB_NONE; |
[email protected] | 0e50fc4d | 2011-08-01 15:33:51 | [diff] [blame] | 179 | attr += 2) { |
Antoine Labour | 492d57a1 | 2017-12-21 02:42:11 | [diff] [blame] | 180 | int32_t key = attr[0]; |
| 181 | int32_t value = attr[1]; |
| 182 | switch (key) { |
| 183 | case PP_GRAPHICS3DATTRIB_ALPHA_SIZE: |
| 184 | attrib_helper.alpha_size = value; |
| 185 | break; |
| 186 | case PP_GRAPHICS3DATTRIB_BLUE_SIZE: |
| 187 | attrib_helper.blue_size = value; |
| 188 | break; |
| 189 | case PP_GRAPHICS3DATTRIB_GREEN_SIZE: |
| 190 | attrib_helper.green_size = value; |
| 191 | break; |
| 192 | case PP_GRAPHICS3DATTRIB_RED_SIZE: |
| 193 | attrib_helper.red_size = value; |
| 194 | break; |
| 195 | case PP_GRAPHICS3DATTRIB_DEPTH_SIZE: |
| 196 | attrib_helper.depth_size = value; |
| 197 | break; |
| 198 | case PP_GRAPHICS3DATTRIB_STENCIL_SIZE: |
| 199 | attrib_helper.stencil_size = value; |
| 200 | break; |
| 201 | case PP_GRAPHICS3DATTRIB_SAMPLES: |
| 202 | attrib_helper.samples = value; |
| 203 | break; |
| 204 | case PP_GRAPHICS3DATTRIB_SAMPLE_BUFFERS: |
| 205 | attrib_helper.sample_buffers = value; |
| 206 | break; |
| 207 | case PP_GRAPHICS3DATTRIB_SWAP_BEHAVIOR: |
| 208 | attrib_helper.buffer_preserved = |
| 209 | value == PP_GRAPHICS3DATTRIB_BUFFER_PRESERVED; |
| 210 | break; |
piman | fe4e488 | 2016-07-09 01:18:21 | [diff] [blame] | 211 | case PP_GRAPHICS3DATTRIB_WIDTH: |
Antoine Labour | 492d57a1 | 2017-12-21 02:42:11 | [diff] [blame] | 212 | attrib_helper.offscreen_framebuffer_size.set_width(value); |
piman | fe4e488 | 2016-07-09 01:18:21 | [diff] [blame] | 213 | break; |
| 214 | case PP_GRAPHICS3DATTRIB_HEIGHT: |
Antoine Labour | 492d57a1 | 2017-12-21 02:42:11 | [diff] [blame] | 215 | attrib_helper.offscreen_framebuffer_size.set_height(value); |
piman | fe4e488 | 2016-07-09 01:18:21 | [diff] [blame] | 216 | break; |
| 217 | case PP_GRAPHICS3DATTRIB_GPU_PREFERENCE: |
| 218 | attrib_helper.gpu_preference = |
Antoine Labour | 492d57a1 | 2017-12-21 02:42:11 | [diff] [blame] | 219 | (value == PP_GRAPHICS3DATTRIB_GPU_PREFERENCE_LOW_POWER) |
Zhenyao Mo | dd6173b0 | 2019-05-23 23:04:27 | [diff] [blame] | 220 | ? gl::GpuPreference::kLowPower |
| 221 | : gl::GpuPreference::kHighPerformance; |
piman | fe4e488 | 2016-07-09 01:18:21 | [diff] [blame] | 222 | break; |
David Reveman | ca46de73 | 2017-06-09 19:48:19 | [diff] [blame] | 223 | case PP_GRAPHICS3DATTRIB_SINGLE_BUFFER: |
Antoine Labour | 492d57a1 | 2017-12-21 02:42:11 | [diff] [blame] | 224 | attrib_helper.single_buffer = !!value; |
David Reveman | ca46de73 | 2017-06-09 19:48:19 | [diff] [blame] | 225 | break; |
piman | fe4e488 | 2016-07-09 01:18:21 | [diff] [blame] | 226 | default: |
Antoine Labour | 492d57a1 | 2017-12-21 02:42:11 | [diff] [blame] | 227 | DLOG(ERROR) << "Invalid context creation attribute: " << attr[0]; |
| 228 | return 0; |
piman | fe4e488 | 2016-07-09 01:18:21 | [diff] [blame] | 229 | } |
[email protected] | eeb4e4a | 2011-07-19 16:22:06 | [diff] [blame] | 230 | } |
[email protected] | eeb4e4a | 2011-07-19 16:22:06 | [diff] [blame] | 231 | } |
[email protected] | eeb4e4a | 2011-07-19 16:22:06 | [diff] [blame] | 232 | |
| 233 | HostResource result; |
piman | 360175c | 2014-11-07 02:30:01 | [diff] [blame] | 234 | gpu::Capabilities capabilities; |
penghuang | a206fb49 | 2014-09-09 21:27:32 | [diff] [blame] | 235 | ppapi::proxy::SerializedHandle shared_state; |
lukasza | 2573ce7d | 2016-02-16 19:17:22 | [diff] [blame] | 236 | gpu::CommandBufferId command_buffer_id; |
piman | fe4e488 | 2016-07-09 01:18:21 | [diff] [blame] | 237 | dispatcher->Send(new PpapiHostMsg_PPBGraphics3D_Create( |
| 238 | API_ID_PPB_GRAPHICS_3D, instance, share_host, attrib_helper, &result, |
| 239 | &capabilities, &shared_state, &command_buffer_id)); |
penghuang | a206fb49 | 2014-09-09 21:27:32 | [diff] [blame] | 240 | |
[email protected] | eeb4e4a | 2011-07-19 16:22:06 | [diff] [blame] | 241 | if (result.is_null()) |
| 242 | return 0; |
| 243 | |
piman | b36392c2 | 2016-07-13 02:11:36 | [diff] [blame] | 244 | scoped_refptr<Graphics3D> graphics_3d( |
Daniele Castagna | 141a88a | 2018-07-30 19:41:23 | [diff] [blame] | 245 | new Graphics3D(result, attrib_helper.offscreen_framebuffer_size, |
| 246 | attrib_helper.single_buffer)); |
Alexandr Ilin | 15bb703 | 2018-07-13 10:09:06 | [diff] [blame] | 247 | if (!graphics_3d->Init(share_gles2, capabilities, std::move(shared_state), |
dyen | 12e4596 | 2015-09-18 00:13:51 | [diff] [blame] | 248 | command_buffer_id)) { |
[email protected] | eeb4e4a | 2011-07-19 16:22:06 | [diff] [blame] | 249 | return 0; |
dyen | 12e4596 | 2015-09-18 00:13:51 | [diff] [blame] | 250 | } |
[email protected] | 7f8b26b | 2011-08-18 15:41:01 | [diff] [blame] | 251 | return graphics_3d->GetReference(); |
[email protected] | eeb4e4a | 2011-07-19 16:22:06 | [diff] [blame] | 252 | } |
| 253 | |
| 254 | bool PPB_Graphics3D_Proxy::OnMessageReceived(const IPC::Message& msg) { |
| 255 | bool handled = true; |
| 256 | IPC_BEGIN_MESSAGE_MAP(PPB_Graphics3D_Proxy, msg) |
[email protected] | 11494c5c | 2012-11-13 02:50:57 | [diff] [blame] | 257 | #if !defined(OS_NACL) |
[email protected] | eeb4e4a | 2011-07-19 16:22:06 | [diff] [blame] | 258 | IPC_MESSAGE_HANDLER(PpapiHostMsg_PPBGraphics3D_Create, |
| 259 | OnMsgCreate) |
[email protected] | 503b3a2 | 2011-12-12 23:29:40 | [diff] [blame] | 260 | IPC_MESSAGE_HANDLER(PpapiHostMsg_PPBGraphics3D_SetGetBuffer, |
| 261 | OnMsgSetGetBuffer) |
[email protected] | 7fe4198b | 2014-03-18 21:52:36 | [diff] [blame] | 262 | IPC_MESSAGE_HANDLER(PpapiHostMsg_PPBGraphics3D_WaitForTokenInRange, |
| 263 | OnMsgWaitForTokenInRange) |
| 264 | IPC_MESSAGE_HANDLER(PpapiHostMsg_PPBGraphics3D_WaitForGetOffsetInRange, |
| 265 | OnMsgWaitForGetOffsetInRange) |
| 266 | IPC_MESSAGE_HANDLER(PpapiHostMsg_PPBGraphics3D_AsyncFlush, OnMsgAsyncFlush) |
[email protected] | eeb4e4a | 2011-07-19 16:22:06 | [diff] [blame] | 267 | IPC_MESSAGE_HANDLER(PpapiHostMsg_PPBGraphics3D_CreateTransferBuffer, |
| 268 | OnMsgCreateTransferBuffer) |
| 269 | IPC_MESSAGE_HANDLER(PpapiHostMsg_PPBGraphics3D_DestroyTransferBuffer, |
| 270 | OnMsgDestroyTransferBuffer) |
[email protected] | eeb4e4a | 2011-07-19 16:22:06 | [diff] [blame] | 271 | IPC_MESSAGE_HANDLER(PpapiHostMsg_PPBGraphics3D_SwapBuffers, |
| 272 | OnMsgSwapBuffers) |
erikchen | 438b044 | 2016-05-11 18:33:30 | [diff] [blame] | 273 | IPC_MESSAGE_HANDLER(PpapiHostMsg_PPBGraphics3D_TakeFrontBuffer, |
| 274 | OnMsgTakeFrontBuffer) |
dyen | 4de3d345f | 2016-01-12 18:30:42 | [diff] [blame] | 275 | IPC_MESSAGE_HANDLER(PpapiHostMsg_PPBGraphics3D_EnsureWorkVisible, |
| 276 | OnMsgEnsureWorkVisible) |
[email protected] | 11494c5c | 2012-11-13 02:50:57 | [diff] [blame] | 277 | #endif // !defined(OS_NACL) |
[email protected] | eeb4e4a | 2011-07-19 16:22:06 | [diff] [blame] | 278 | |
| 279 | IPC_MESSAGE_HANDLER(PpapiMsg_PPBGraphics3D_SwapBuffersACK, |
| 280 | OnMsgSwapBuffersACK) |
| 281 | IPC_MESSAGE_UNHANDLED(handled = false) |
| 282 | |
| 283 | IPC_END_MESSAGE_MAP() |
| 284 | // FIXME(brettw) handle bad messages! |
| 285 | return handled; |
| 286 | } |
| 287 | |
[email protected] | 11494c5c | 2012-11-13 02:50:57 | [diff] [blame] | 288 | #if !defined(OS_NACL) |
lukasza | 2573ce7d | 2016-02-16 19:17:22 | [diff] [blame] | 289 | void PPB_Graphics3D_Proxy::OnMsgCreate( |
| 290 | PP_Instance instance, |
| 291 | HostResource share_context, |
Antoine Labour | feab239 | 2017-12-21 20:28:39 | [diff] [blame] | 292 | const gpu::ContextCreationAttribs& attrib_helper, |
lukasza | 2573ce7d | 2016-02-16 19:17:22 | [diff] [blame] | 293 | HostResource* result, |
| 294 | gpu::Capabilities* capabilities, |
| 295 | SerializedHandle* shared_state, |
| 296 | gpu::CommandBufferId* command_buffer_id) { |
Matthew Cary | fc3757f | 2019-07-30 21:32:46 | [diff] [blame] | 297 | shared_state->set_null_shmem_region(); |
[email protected] | eeb4e4a | 2011-07-19 16:22:06 | [diff] [blame] | 298 | |
[email protected] | 5c96602 | 2011-09-13 18:09:37 | [diff] [blame] | 299 | thunk::EnterResourceCreation enter(instance); |
[email protected] | 9ed07f8 | 2012-05-29 21:54:55 | [diff] [blame] | 300 | |
penghuang | a206fb49 | 2014-09-09 21:27:32 | [diff] [blame] | 301 | if (!enter.succeeded()) |
| 302 | return; |
| 303 | |
Alexandr Ilin | 15bb703 | 2018-07-13 10:09:06 | [diff] [blame] | 304 | const base::UnsafeSharedMemoryRegion* region = nullptr; |
penghuang | a206fb49 | 2014-09-09 21:27:32 | [diff] [blame] | 305 | result->SetHostResource( |
piman | fe4e488 | 2016-07-09 01:18:21 | [diff] [blame] | 306 | instance, enter.functions()->CreateGraphics3DRaw( |
| 307 | instance, share_context.host_resource(), attrib_helper, |
Alexandr Ilin | 15bb703 | 2018-07-13 10:09:06 | [diff] [blame] | 308 | capabilities, ®ion, command_buffer_id)); |
penghuang | a206fb49 | 2014-09-09 21:27:32 | [diff] [blame] | 309 | if (!result->is_null()) { |
Alexandr Ilin | 15bb703 | 2018-07-13 10:09:06 | [diff] [blame] | 310 | shared_state->set_shmem_region( |
| 311 | base::UnsafeSharedMemoryRegion::TakeHandleForSerialization( |
| 312 | TransportSHMHandle(dispatcher(), *region))); |
[email protected] | eeb4e4a | 2011-07-19 16:22:06 | [diff] [blame] | 313 | } |
| 314 | } |
| 315 | |
avi | e029c413 | 2015-12-23 06:45:22 | [diff] [blame] | 316 | void PPB_Graphics3D_Proxy::OnMsgSetGetBuffer(const HostResource& context, |
| 317 | int32_t transfer_buffer_id) { |
[email protected] | 503b3a2 | 2011-12-12 23:29:40 | [diff] [blame] | 318 | EnterHostFromHostResource<PPB_Graphics3D_API> enter(context); |
| 319 | if (enter.succeeded()) |
| 320 | enter.object()->SetGetBuffer(transfer_buffer_id); |
[email protected] | eeb4e4a | 2011-07-19 16:22:06 | [diff] [blame] | 321 | } |
| 322 | |
[email protected] | 7fe4198b | 2014-03-18 21:52:36 | [diff] [blame] | 323 | void PPB_Graphics3D_Proxy::OnMsgWaitForTokenInRange( |
| 324 | const HostResource& context, |
avi | e029c413 | 2015-12-23 06:45:22 | [diff] [blame] | 325 | int32_t start, |
| 326 | int32_t end, |
[email protected] | 7fe4198b | 2014-03-18 21:52:36 | [diff] [blame] | 327 | gpu::CommandBuffer::State* state, |
| 328 | bool* success) { |
[email protected] | eeb4e4a | 2011-07-19 16:22:06 | [diff] [blame] | 329 | EnterHostFromHostResource<PPB_Graphics3D_API> enter(context); |
[email protected] | 571b35e8 | 2012-05-19 00:04:35 | [diff] [blame] | 330 | if (enter.failed()) { |
| 331 | *success = false; |
[email protected] | eeb4e4a | 2011-07-19 16:22:06 | [diff] [blame] | 332 | return; |
[email protected] | 571b35e8 | 2012-05-19 00:04:35 | [diff] [blame] | 333 | } |
[email protected] | 7fe4198b | 2014-03-18 21:52:36 | [diff] [blame] | 334 | *state = enter.object()->WaitForTokenInRange(start, end); |
| 335 | *success = true; |
| 336 | } |
| 337 | |
| 338 | void PPB_Graphics3D_Proxy::OnMsgWaitForGetOffsetInRange( |
| 339 | const HostResource& context, |
Antoine Labour | d346994 | 2017-05-16 21:23:42 | [diff] [blame] | 340 | uint32_t set_get_buffer_count, |
avi | e029c413 | 2015-12-23 06:45:22 | [diff] [blame] | 341 | int32_t start, |
| 342 | int32_t end, |
[email protected] | 7fe4198b | 2014-03-18 21:52:36 | [diff] [blame] | 343 | gpu::CommandBuffer::State* state, |
| 344 | bool* success) { |
| 345 | EnterHostFromHostResource<PPB_Graphics3D_API> enter(context); |
| 346 | if (enter.failed()) { |
| 347 | *success = false; |
| 348 | return; |
| 349 | } |
Antoine Labour | d346994 | 2017-05-16 21:23:42 | [diff] [blame] | 350 | *state = |
| 351 | enter.object()->WaitForGetOffsetInRange(set_get_buffer_count, start, end); |
[email protected] | 571b35e8 | 2012-05-19 00:04:35 | [diff] [blame] | 352 | *success = true; |
[email protected] | eeb4e4a | 2011-07-19 16:22:06 | [diff] [blame] | 353 | } |
| 354 | |
| 355 | void PPB_Graphics3D_Proxy::OnMsgAsyncFlush(const HostResource& context, |
avi | e029c413 | 2015-12-23 06:45:22 | [diff] [blame] | 356 | int32_t put_offset) { |
[email protected] | eeb4e4a | 2011-07-19 16:22:06 | [diff] [blame] | 357 | EnterHostFromHostResource<PPB_Graphics3D_API> enter(context); |
| 358 | if (enter.succeeded()) |
| 359 | enter.object()->Flush(put_offset); |
| 360 | } |
| 361 | |
| 362 | void PPB_Graphics3D_Proxy::OnMsgCreateTransferBuffer( |
| 363 | const HostResource& context, |
avi | e029c413 | 2015-12-23 06:45:22 | [diff] [blame] | 364 | uint32_t size, |
| 365 | int32_t* id, |
penghuang | a206fb49 | 2014-09-09 21:27:32 | [diff] [blame] | 366 | SerializedHandle* transfer_buffer) { |
Alexandr Ilin | 15bb703 | 2018-07-13 10:09:06 | [diff] [blame] | 367 | transfer_buffer->set_null_shmem_region(); |
[email protected] | eeb4e4a | 2011-07-19 16:22:06 | [diff] [blame] | 368 | EnterHostFromHostResource<PPB_Graphics3D_API> enter(context); |
[email protected] | 046fa1ac | 2014-04-01 09:06:43 | [diff] [blame] | 369 | if (enter.succeeded()) { |
| 370 | scoped_refptr<gpu::Buffer> buffer = |
| 371 | enter.object()->CreateTransferBuffer(size, id); |
Daniel Cheng | 6d3ae97 | 2014-08-26 00:27:38 | [diff] [blame] | 372 | if (!buffer.get()) |
[email protected] | 046fa1ac | 2014-04-01 09:06:43 | [diff] [blame] | 373 | return; |
[email protected] | 8a978df | 2014-04-02 23:54:09 | [diff] [blame] | 374 | gpu::SharedMemoryBufferBacking* backing = |
| 375 | static_cast<gpu::SharedMemoryBufferBacking*>(buffer->backing()); |
Alexandr Ilin | 15bb703 | 2018-07-13 10:09:06 | [diff] [blame] | 376 | DCHECK(backing && backing->shared_memory_region().IsValid()); |
| 377 | transfer_buffer->set_shmem_region( |
| 378 | base::UnsafeSharedMemoryRegion::TakeHandleForSerialization( |
| 379 | TransportSHMHandle(dispatcher(), backing->shared_memory_region()))); |
[email protected] | 046fa1ac | 2014-04-01 09:06:43 | [diff] [blame] | 380 | } else { |
[email protected] | 67c8078 | 2012-12-21 01:16:52 | [diff] [blame] | 381 | *id = -1; |
[email protected] | 046fa1ac | 2014-04-01 09:06:43 | [diff] [blame] | 382 | } |
[email protected] | eeb4e4a | 2011-07-19 16:22:06 | [diff] [blame] | 383 | } |
| 384 | |
| 385 | void PPB_Graphics3D_Proxy::OnMsgDestroyTransferBuffer( |
| 386 | const HostResource& context, |
avi | e029c413 | 2015-12-23 06:45:22 | [diff] [blame] | 387 | int32_t id) { |
[email protected] | eeb4e4a | 2011-07-19 16:22:06 | [diff] [blame] | 388 | EnterHostFromHostResource<PPB_Graphics3D_API> enter(context); |
| 389 | if (enter.succeeded()) |
| 390 | enter.object()->DestroyTransferBuffer(id); |
| 391 | } |
| 392 | |
dyen | ddfdbbb | 2016-01-14 22:21:38 | [diff] [blame] | 393 | void PPB_Graphics3D_Proxy::OnMsgSwapBuffers(const HostResource& context, |
erikchen | b13637b | 2016-07-08 09:38:56 | [diff] [blame] | 394 | const gpu::SyncToken& sync_token, |
piman | b36392c2 | 2016-07-13 02:11:36 | [diff] [blame] | 395 | const gfx::Size& size) { |
[email protected] | 79d23c7 | 2011-08-08 19:40:40 | [diff] [blame] | 396 | EnterHostFromHostResourceForceCallback<PPB_Graphics3D_API> enter( |
| 397 | context, callback_factory_, |
[email protected] | eeb4e4a | 2011-07-19 16:22:06 | [diff] [blame] | 398 | &PPB_Graphics3D_Proxy::SendSwapBuffersACKToPlugin, context); |
[email protected] | eeb4e4a | 2011-07-19 16:22:06 | [diff] [blame] | 399 | if (enter.succeeded()) |
erikchen | b13637b | 2016-07-08 09:38:56 | [diff] [blame] | 400 | enter.SetResult(enter.object()->SwapBuffersWithSyncToken( |
piman | b36392c2 | 2016-07-13 02:11:36 | [diff] [blame] | 401 | enter.callback(), sync_token, size)); |
[email protected] | eeb4e4a | 2011-07-19 16:22:06 | [diff] [blame] | 402 | } |
[email protected] | b096d03 | 2013-03-08 03:08:01 | [diff] [blame] | 403 | |
erikchen | 438b044 | 2016-05-11 18:33:30 | [diff] [blame] | 404 | void PPB_Graphics3D_Proxy::OnMsgTakeFrontBuffer(const HostResource& context) { |
| 405 | EnterHostFromHostResource<PPB_Graphics3D_API> enter(context); |
| 406 | if (enter.succeeded()) |
| 407 | enter.object()->TakeFrontBuffer(); |
| 408 | } |
| 409 | |
dyen | 4de3d345f | 2016-01-12 18:30:42 | [diff] [blame] | 410 | void PPB_Graphics3D_Proxy::OnMsgEnsureWorkVisible(const HostResource& context) { |
| 411 | EnterHostFromHostResource<PPB_Graphics3D_API> enter(context); |
| 412 | if (enter.succeeded()) |
| 413 | enter.object()->EnsureWorkVisible(); |
| 414 | } |
[email protected] | 11494c5c | 2012-11-13 02:50:57 | [diff] [blame] | 415 | #endif // !defined(OS_NACL) |
[email protected] | eeb4e4a | 2011-07-19 16:22:06 | [diff] [blame] | 416 | |
| 417 | void PPB_Graphics3D_Proxy::OnMsgSwapBuffersACK(const HostResource& resource, |
| 418 | int32_t pp_error) { |
| 419 | EnterPluginFromHostResource<PPB_Graphics3D_API> enter(resource); |
| 420 | if (enter.succeeded()) |
| 421 | static_cast<Graphics3D*>(enter.object())->SwapBuffersACK(pp_error); |
| 422 | } |
| 423 | |
[email protected] | 11494c5c | 2012-11-13 02:50:57 | [diff] [blame] | 424 | #if !defined(OS_NACL) |
[email protected] | eeb4e4a | 2011-07-19 16:22:06 | [diff] [blame] | 425 | void PPB_Graphics3D_Proxy::SendSwapBuffersACKToPlugin( |
| 426 | int32_t result, |
| 427 | const HostResource& context) { |
| 428 | dispatcher()->Send(new PpapiMsg_PPBGraphics3D_SwapBuffersACK( |
[email protected] | ac4b54d | 2011-10-20 23:09:28 | [diff] [blame] | 429 | API_ID_PPB_GRAPHICS_3D, context, result)); |
[email protected] | eeb4e4a | 2011-07-19 16:22:06 | [diff] [blame] | 430 | } |
[email protected] | 11494c5c | 2012-11-13 02:50:57 | [diff] [blame] | 431 | #endif // !defined(OS_NACL) |
[email protected] | eeb4e4a | 2011-07-19 16:22:06 | [diff] [blame] | 432 | |
| 433 | } // namespace proxy |
[email protected] | 4d2efd2 | 2011-08-18 21:58:02 | [diff] [blame] | 434 | } // namespace ppapi |