| OLD | NEW |
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 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 | 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/resource_creation_proxy.h" | 5 #include "ppapi/proxy/resource_creation_proxy.h" |
| 6 | 6 |
| 7 #include "ppapi/c/pp_errors.h" | 7 #include "ppapi/c/pp_errors.h" |
| 8 #include "ppapi/c/pp_size.h" | 8 #include "ppapi/c/pp_size.h" |
| 9 #include "ppapi/c/trusted/ppb_image_data_trusted.h" | 9 #include "ppapi/c/trusted/ppb_image_data_trusted.h" |
| 10 #include "ppapi/proxy/plugin_dispatcher.h" | 10 #include "ppapi/proxy/plugin_dispatcher.h" |
| (...skipping 150 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 161 const PP_Size& size, | 161 const PP_Size& size, |
| 162 PP_Bool is_always_opaque) { | 162 PP_Bool is_always_opaque) { |
| 163 return PPB_Graphics2D_Proxy::CreateProxyResource(instance, size, | 163 return PPB_Graphics2D_Proxy::CreateProxyResource(instance, size, |
| 164 is_always_opaque); | 164 is_always_opaque); |
| 165 } | 165 } |
| 166 | 166 |
| 167 PP_Resource ResourceCreationProxy::CreateImageData(PP_Instance instance, | 167 PP_Resource ResourceCreationProxy::CreateImageData(PP_Instance instance, |
| 168 PP_ImageDataFormat format, | 168 PP_ImageDataFormat format, |
| 169 const PP_Size& size, | 169 const PP_Size& size, |
| 170 PP_Bool init_to_zero) { | 170 PP_Bool init_to_zero) { |
| 171 PluginDispatcher* dispatcher = PluginDispatcher::GetForInstance(instance); | 171 return PPB_ImageData_Proxy::CreateProxyResource(instance, format, size, |
| 172 if (!dispatcher) | 172 init_to_zero); |
| 173 return 0; | |
| 174 | |
| 175 HostResource result; | |
| 176 std::string image_data_desc; | |
| 177 ImageHandle image_handle = ImageData::NullHandle; | |
| 178 dispatcher->Send(new PpapiHostMsg_ResourceCreation_ImageData( | |
| 179 API_ID_RESOURCE_CREATION, instance, format, size, init_to_zero, | |
| 180 &result, &image_data_desc, &image_handle)); | |
| 181 | |
| 182 if (result.is_null() || image_data_desc.size() != sizeof(PP_ImageDataDesc)) | |
| 183 return 0; | |
| 184 | |
| 185 // We serialize the PP_ImageDataDesc just by copying to a string. | |
| 186 PP_ImageDataDesc desc; | |
| 187 memcpy(&desc, image_data_desc.data(), sizeof(PP_ImageDataDesc)); | |
| 188 | |
| 189 return (new ImageData(result, desc, image_handle))->GetReference(); | |
| 190 } | 173 } |
| 191 | 174 |
| 192 PP_Resource ResourceCreationProxy::CreateKeyboardInputEvent( | 175 PP_Resource ResourceCreationProxy::CreateKeyboardInputEvent( |
| 193 PP_Instance instance, | 176 PP_Instance instance, |
| 194 PP_InputEvent_Type type, | 177 PP_InputEvent_Type type, |
| 195 PP_TimeTicks time_stamp, | 178 PP_TimeTicks time_stamp, |
| 196 uint32_t modifiers, | 179 uint32_t modifiers, |
| 197 uint32_t key_code, | 180 uint32_t key_code, |
| 198 struct PP_Var character_text) { | 181 struct PP_Var character_text) { |
| 199 if (type != PP_INPUTEVENT_TYPE_RAWKEYDOWN && | 182 if (type != PP_INPUTEVENT_TYPE_RAWKEYDOWN && |
| (...skipping 138 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 338 | 321 |
| 339 return (new InputEventImpl(InputEventImpl::InitAsProxy(), | 322 return (new InputEventImpl(InputEventImpl::InitAsProxy(), |
| 340 instance, data))->GetReference(); | 323 instance, data))->GetReference(); |
| 341 } | 324 } |
| 342 | 325 |
| 343 bool ResourceCreationProxy::Send(IPC::Message* msg) { | 326 bool ResourceCreationProxy::Send(IPC::Message* msg) { |
| 344 return dispatcher()->Send(msg); | 327 return dispatcher()->Send(msg); |
| 345 } | 328 } |
| 346 | 329 |
| 347 bool ResourceCreationProxy::OnMessageReceived(const IPC::Message& msg) { | 330 bool ResourceCreationProxy::OnMessageReceived(const IPC::Message& msg) { |
| 348 bool handled = true; | 331 return false; |
| 349 IPC_BEGIN_MESSAGE_MAP(ResourceCreationProxy, msg) | |
| 350 IPC_MESSAGE_HANDLER(PpapiHostMsg_ResourceCreation_Graphics2D, | |
| 351 OnMsgCreateGraphics2D) | |
| 352 IPC_MESSAGE_HANDLER(PpapiHostMsg_ResourceCreation_ImageData, | |
| 353 OnMsgCreateImageData) | |
| 354 IPC_MESSAGE_UNHANDLED(handled = false) | |
| 355 IPC_END_MESSAGE_MAP() | |
| 356 return handled; | |
| 357 } | |
| 358 | |
| 359 void ResourceCreationProxy::OnMsgCreateGraphics2D(PP_Instance instance, | |
| 360 const PP_Size& size, | |
| 361 PP_Bool is_always_opaque, | |
| 362 HostResource* result) { | |
| 363 ppapi::thunk::EnterFunction<ResourceCreationAPI> enter(instance, false); | |
| 364 if (enter.succeeded()) { | |
| 365 result->SetHostResource(instance, enter.functions()->CreateGraphics2D( | |
| 366 instance, size, is_always_opaque)); | |
| 367 } | |
| 368 } | |
| 369 | |
| 370 void ResourceCreationProxy::OnMsgCreateImageData( | |
| 371 PP_Instance instance, | |
| 372 int32_t format, | |
| 373 const PP_Size& size, | |
| 374 PP_Bool init_to_zero, | |
| 375 HostResource* result, | |
| 376 std::string* image_data_desc, | |
| 377 ImageHandle* result_image_handle) { | |
| 378 *result_image_handle = ImageData::NullHandle; | |
| 379 | |
| 380 ppapi::thunk::EnterFunction<ResourceCreationAPI> enter(instance, false); | |
| 381 if (enter.failed()) | |
| 382 return; | |
| 383 | |
| 384 PP_Resource resource = enter.functions()->CreateImageData( | |
| 385 instance, static_cast<PP_ImageDataFormat>(format), size, init_to_zero); | |
| 386 if (!resource) | |
| 387 return; | |
| 388 result->SetHostResource(instance, resource); | |
| 389 | |
| 390 // Get the description, it's just serialized as a string. | |
| 391 ppapi::thunk::EnterResourceNoLock<ppapi::thunk::PPB_ImageData_API> | |
| 392 enter_resource(resource, false); | |
| 393 PP_ImageDataDesc desc; | |
| 394 if (enter_resource.object()->Describe(&desc) == PP_TRUE) { | |
| 395 image_data_desc->resize(sizeof(PP_ImageDataDesc)); | |
| 396 memcpy(&(*image_data_desc)[0], &desc, sizeof(PP_ImageDataDesc)); | |
| 397 } | |
| 398 | |
| 399 // Get the shared memory handle. | |
| 400 const PPB_ImageDataTrusted* trusted = | |
| 401 reinterpret_cast<const PPB_ImageDataTrusted*>( | |
| 402 dispatcher()->local_get_interface()(PPB_IMAGEDATA_TRUSTED_INTERFACE)); | |
| 403 uint32_t byte_count = 0; | |
| 404 if (trusted) { | |
| 405 int32_t handle; | |
| 406 if (trusted->GetSharedMemory(resource, &handle, &byte_count) == PP_OK) { | |
| 407 #if defined(OS_WIN) | |
| 408 ImageHandle ih = ImageData::HandleFromInt(handle); | |
| 409 *result_image_handle = dispatcher()->ShareHandleWithRemote(ih, false); | |
| 410 #else | |
| 411 *result_image_handle = ImageData::HandleFromInt(handle); | |
| 412 #endif | |
| 413 } | |
| 414 } | |
| 415 } | 332 } |
| 416 | 333 |
| 417 } // namespace proxy | 334 } // namespace proxy |
| 418 } // namespace ppapi | 335 } // namespace ppapi |
| OLD | NEW |