[email protected] | f24448db | 2011-01-27 20:40:39 | [diff] [blame^] | 1 | // Copyright (c) 2011 The Chromium Authors. All rights reserved. |
[email protected] | 1054c07 | 2010-11-05 22:52:48 | [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_testing_proxy.h" |
| 6 | |
| 7 | #include "base/message_loop.h" |
| 8 | #include "ppapi/c/dev/ppb_testing_dev.h" |
| 9 | #include "ppapi/proxy/plugin_dispatcher.h" |
[email protected] | f24448db | 2011-01-27 20:40:39 | [diff] [blame^] | 10 | #include "ppapi/proxy/plugin_resource.h" |
| 11 | #include "ppapi/proxy/plugin_resource_tracker.h" |
[email protected] | 1054c07 | 2010-11-05 22:52:48 | [diff] [blame] | 12 | #include "ppapi/proxy/ppapi_messages.h" |
| 13 | |
| 14 | namespace pp { |
| 15 | namespace proxy { |
| 16 | |
| 17 | namespace { |
| 18 | |
[email protected] | f24448db | 2011-01-27 20:40:39 | [diff] [blame^] | 19 | PP_Bool ReadImageData(PP_Resource graphics_2d, |
[email protected] | 19d2b01 | 2010-11-08 16:32:18 | [diff] [blame] | 20 | PP_Resource image, |
| 21 | const PP_Point* top_left) { |
[email protected] | f24448db | 2011-01-27 20:40:39 | [diff] [blame^] | 22 | PluginResource* image_object = PluginResourceTracker::GetInstance()-> |
| 23 | GetResourceObject(image); |
[email protected] | 4614f19 | 2011-01-21 00:26:43 | [diff] [blame] | 24 | if (!image_object) |
| 25 | return PP_FALSE; |
[email protected] | f24448db | 2011-01-27 20:40:39 | [diff] [blame^] | 26 | PluginResource* graphics_2d_object = |
| 27 | PluginResourceTracker::GetInstance()->GetResourceObject(graphics_2d); |
| 28 | if (!graphics_2d_object || |
| 29 | image_object->instance() != graphics_2d_object->instance()) |
| 30 | return PP_FALSE; |
| 31 | |
[email protected] | 4614f19 | 2011-01-21 00:26:43 | [diff] [blame] | 32 | PluginDispatcher* dispatcher = PluginDispatcher::GetForInstance( |
| 33 | image_object->instance()); |
| 34 | if (!dispatcher) |
| 35 | return PP_FALSE; |
| 36 | |
[email protected] | 19d2b01 | 2010-11-08 16:32:18 | [diff] [blame] | 37 | PP_Bool result = PP_FALSE; |
[email protected] | 4614f19 | 2011-01-21 00:26:43 | [diff] [blame] | 38 | dispatcher->Send(new PpapiHostMsg_PPBTesting_ReadImageData( |
[email protected] | f24448db | 2011-01-27 20:40:39 | [diff] [blame^] | 39 | INTERFACE_ID_PPB_TESTING, graphics_2d_object->host_resource(), |
| 40 | image_object->host_resource(), *top_left, &result)); |
[email protected] | 1054c07 | 2010-11-05 22:52:48 | [diff] [blame] | 41 | return result; |
| 42 | } |
| 43 | |
| 44 | void RunMessageLoop() { |
| 45 | bool old_state = MessageLoop::current()->NestableTasksAllowed(); |
| 46 | MessageLoop::current()->SetNestableTasksAllowed(true); |
| 47 | MessageLoop::current()->Run(); |
| 48 | MessageLoop::current()->SetNestableTasksAllowed(old_state); |
| 49 | } |
| 50 | |
| 51 | void QuitMessageLoop() { |
| 52 | MessageLoop::current()->QuitNow(); |
| 53 | } |
| 54 | |
[email protected] | 4614f19 | 2011-01-21 00:26:43 | [diff] [blame] | 55 | uint32_t GetLiveObjectsForInstance(PP_Instance instance_id) { |
| 56 | PluginDispatcher* dispatcher = PluginDispatcher::GetForInstance(instance_id); |
| 57 | if (!dispatcher) |
| 58 | return static_cast<uint32_t>(-1); |
| 59 | |
[email protected] | 1054c07 | 2010-11-05 22:52:48 | [diff] [blame] | 60 | uint32_t result = 0; |
[email protected] | 4614f19 | 2011-01-21 00:26:43 | [diff] [blame] | 61 | dispatcher->Send(new PpapiHostMsg_PPBTesting_GetLiveObjectsForInstance( |
| 62 | INTERFACE_ID_PPB_TESTING, instance_id, &result)); |
[email protected] | 1054c07 | 2010-11-05 22:52:48 | [diff] [blame] | 63 | return result; |
| 64 | } |
| 65 | |
| 66 | const PPB_Testing_Dev testing_interface = { |
| 67 | &ReadImageData, |
| 68 | &RunMessageLoop, |
| 69 | &QuitMessageLoop, |
[email protected] | 4614f19 | 2011-01-21 00:26:43 | [diff] [blame] | 70 | &GetLiveObjectsForInstance |
[email protected] | 1054c07 | 2010-11-05 22:52:48 | [diff] [blame] | 71 | }; |
| 72 | |
| 73 | } // namespace |
| 74 | |
| 75 | PPB_Testing_Proxy::PPB_Testing_Proxy(Dispatcher* dispatcher, |
| 76 | const void* target_interface) |
| 77 | : InterfaceProxy(dispatcher, target_interface) { |
| 78 | } |
| 79 | |
| 80 | PPB_Testing_Proxy::~PPB_Testing_Proxy() { |
| 81 | } |
| 82 | |
| 83 | const void* PPB_Testing_Proxy::GetSourceInterface() const { |
| 84 | return &testing_interface; |
| 85 | } |
| 86 | |
| 87 | InterfaceID PPB_Testing_Proxy::GetInterfaceId() const { |
| 88 | return INTERFACE_ID_PPB_TESTING; |
| 89 | } |
| 90 | |
[email protected] | a95986a8 | 2010-12-24 06:19:28 | [diff] [blame] | 91 | bool PPB_Testing_Proxy::OnMessageReceived(const IPC::Message& msg) { |
| 92 | bool handled = true; |
[email protected] | 1054c07 | 2010-11-05 22:52:48 | [diff] [blame] | 93 | IPC_BEGIN_MESSAGE_MAP(PPB_Testing_Proxy, msg) |
| 94 | IPC_MESSAGE_HANDLER(PpapiHostMsg_PPBTesting_ReadImageData, |
| 95 | OnMsgReadImageData) |
| 96 | IPC_MESSAGE_HANDLER(PpapiHostMsg_PPBTesting_RunMessageLoop, |
| 97 | OnMsgRunMessageLoop) |
| 98 | IPC_MESSAGE_HANDLER(PpapiHostMsg_PPBTesting_QuitMessageLoop, |
| 99 | OnMsgQuitMessageLoop) |
[email protected] | 4614f19 | 2011-01-21 00:26:43 | [diff] [blame] | 100 | IPC_MESSAGE_HANDLER(PpapiHostMsg_PPBTesting_GetLiveObjectsForInstance, |
| 101 | OnMsgGetLiveObjectsForInstance) |
[email protected] | a95986a8 | 2010-12-24 06:19:28 | [diff] [blame] | 102 | IPC_MESSAGE_UNHANDLED(handled = false) |
[email protected] | 1054c07 | 2010-11-05 22:52:48 | [diff] [blame] | 103 | IPC_END_MESSAGE_MAP() |
[email protected] | a95986a8 | 2010-12-24 06:19:28 | [diff] [blame] | 104 | return handled; |
[email protected] | 1054c07 | 2010-11-05 22:52:48 | [diff] [blame] | 105 | } |
| 106 | |
[email protected] | f24448db | 2011-01-27 20:40:39 | [diff] [blame^] | 107 | void PPB_Testing_Proxy::OnMsgReadImageData( |
| 108 | const HostResource& device_context_2d, |
| 109 | const HostResource& image, |
| 110 | const PP_Point& top_left, |
| 111 | PP_Bool* result) { |
[email protected] | 1054c07 | 2010-11-05 22:52:48 | [diff] [blame] | 112 | *result = ppb_testing_target()->ReadImageData( |
[email protected] | f24448db | 2011-01-27 20:40:39 | [diff] [blame^] | 113 | device_context_2d.host_resource(), image.host_resource(), &top_left); |
[email protected] | 1054c07 | 2010-11-05 22:52:48 | [diff] [blame] | 114 | } |
| 115 | |
| 116 | void PPB_Testing_Proxy::OnMsgRunMessageLoop(bool* dummy) { |
| 117 | ppb_testing_target()->RunMessageLoop(); |
| 118 | *dummy = false; |
| 119 | } |
| 120 | |
| 121 | void PPB_Testing_Proxy::OnMsgQuitMessageLoop() { |
| 122 | ppb_testing_target()->QuitMessageLoop(); |
| 123 | } |
| 124 | |
[email protected] | 4614f19 | 2011-01-21 00:26:43 | [diff] [blame] | 125 | void PPB_Testing_Proxy::OnMsgGetLiveObjectsForInstance(PP_Instance instance, |
[email protected] | f24448db | 2011-01-27 20:40:39 | [diff] [blame^] | 126 | uint32_t* result) { |
[email protected] | 4614f19 | 2011-01-21 00:26:43 | [diff] [blame] | 127 | *result = ppb_testing_target()->GetLiveObjectsForInstance(instance); |
[email protected] | 1054c07 | 2010-11-05 22:52:48 | [diff] [blame] | 128 | } |
| 129 | |
| 130 | } // namespace proxy |
| 131 | } // namespace pp |