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/proxy/host_resource.h" | 9 #include "ppapi/proxy/host_resource.h" |
10 #include "ppapi/proxy/interface_id.h" | 10 #include "ppapi/proxy/interface_id.h" |
11 #include "ppapi/proxy/plugin_dispatcher.h" | 11 #include "ppapi/proxy/plugin_dispatcher.h" |
12 #include "ppapi/proxy/plugin_resource_tracker.h" | 12 #include "ppapi/proxy/plugin_resource_tracker.h" |
13 #include "ppapi/proxy/ppapi_messages.h" | 13 #include "ppapi/proxy/ppapi_messages.h" |
14 #include "ppapi/proxy/ppb_graphics_2d_proxy.h" | 14 #include "ppapi/proxy/ppb_graphics_2d_proxy.h" |
| 15 #include "ppapi/proxy/ppb_font_proxy.h" |
15 #include "ppapi/proxy/ppb_image_data_proxy.h" | 16 #include "ppapi/proxy/ppb_image_data_proxy.h" |
16 #include "ppapi/c/trusted/ppb_image_data_trusted.h" | 17 #include "ppapi/c/trusted/ppb_image_data_trusted.h" |
17 #include "ppapi/shared_impl/function_group_base.h" | 18 #include "ppapi/shared_impl/function_group_base.h" |
18 #include "ppapi/thunk/enter.h" | 19 #include "ppapi/thunk/enter.h" |
19 | 20 |
20 using ::ppapi::thunk::ResourceCreationAPI; | 21 using ::ppapi::thunk::ResourceCreationAPI; |
21 | 22 |
22 namespace pp { | 23 namespace pp { |
23 namespace proxy { | 24 namespace proxy { |
24 | 25 |
25 ResourceCreationProxy::ResourceCreationProxy(Dispatcher* dispatcher) | 26 ResourceCreationProxy::ResourceCreationProxy(Dispatcher* dispatcher) |
26 : dispatcher_(dispatcher) { | 27 : dispatcher_(dispatcher) { |
27 } | 28 } |
28 | 29 |
29 ResourceCreationProxy::~ResourceCreationProxy() { | 30 ResourceCreationProxy::~ResourceCreationProxy() { |
30 } | 31 } |
31 | 32 |
32 ::ppapi::thunk::ResourceCreationAPI* | 33 ::ppapi::thunk::ResourceCreationAPI* |
33 ResourceCreationProxy::AsResourceCreation() { | 34 ResourceCreationProxy::AsResourceCreation() { |
34 return this; | 35 return this; |
35 } | 36 } |
36 | 37 |
| 38 PP_Resource ResourceCreationProxy::CreateFont( |
| 39 PP_Instance instance, |
| 40 const PP_FontDescription_Dev* description) { |
| 41 if (!Font::IsPPFontDescriptionValid(*description)) |
| 42 return 0; |
| 43 |
| 44 // See the comment above Font's constructor for why we do this. |
| 45 HostResource resource; |
| 46 resource.SetHostResource(instance, 0); |
| 47 |
| 48 linked_ptr<Font> object(new Font(resource, *description)); |
| 49 return PluginResourceTracker::GetInstance()->AddResource(object); |
| 50 } |
| 51 |
37 PP_Resource ResourceCreationProxy::CreateGraphics2D(PP_Instance pp_instance, | 52 PP_Resource ResourceCreationProxy::CreateGraphics2D(PP_Instance pp_instance, |
38 const PP_Size& size, | 53 const PP_Size& size, |
39 PP_Bool is_always_opaque) { | 54 PP_Bool is_always_opaque) { |
40 PluginDispatcher* dispatcher = PluginDispatcher::GetForInstance(pp_instance); | 55 PluginDispatcher* dispatcher = PluginDispatcher::GetForInstance(pp_instance); |
41 if (!dispatcher) | 56 if (!dispatcher) |
42 return PP_ERROR_BADARGUMENT; | 57 return PP_ERROR_BADARGUMENT; |
43 | 58 |
44 HostResource result; | 59 HostResource result; |
45 dispatcher->Send(new PpapiHostMsg_ResourceCreation_Graphics2D( | 60 dispatcher->Send(new PpapiHostMsg_ResourceCreation_Graphics2D( |
46 INTERFACE_ID_RESOURCE_CREATION, pp_instance, size, is_always_opaque, | 61 INTERFACE_ID_RESOURCE_CREATION, pp_instance, size, is_always_opaque, |
(...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
119 if (enter.failed()) | 134 if (enter.failed()) |
120 return; | 135 return; |
121 | 136 |
122 PP_Resource resource = enter.functions()->CreateImageData( | 137 PP_Resource resource = enter.functions()->CreateImageData( |
123 instance, static_cast<PP_ImageDataFormat>(format), size, init_to_zero); | 138 instance, static_cast<PP_ImageDataFormat>(format), size, init_to_zero); |
124 if (!resource) | 139 if (!resource) |
125 return; | 140 return; |
126 result->SetHostResource(instance, resource); | 141 result->SetHostResource(instance, resource); |
127 | 142 |
128 // Get the description, it's just serialized as a string. | 143 // Get the description, it's just serialized as a string. |
129 ppapi::thunk::EnterResource<PPB_ImageData> enter_resource(resource, false); | 144 ppapi::thunk::EnterResource<ppapi::thunk::PPB_ImageData_API> enter_resource( |
| 145 resource, false); |
130 PP_ImageDataDesc desc; | 146 PP_ImageDataDesc desc; |
131 if (enter_resource.object()->Describe(resource, &desc)) { | 147 if (enter_resource.object()->Describe(&desc) == PP_TRUE) { |
132 image_data_desc->resize(sizeof(PP_ImageDataDesc)); | 148 image_data_desc->resize(sizeof(PP_ImageDataDesc)); |
133 memcpy(&(*image_data_desc)[0], &desc, sizeof(PP_ImageDataDesc)); | 149 memcpy(&(*image_data_desc)[0], &desc, sizeof(PP_ImageDataDesc)); |
134 } | 150 } |
135 | 151 |
136 // Get the shared memory handle. | 152 // Get the shared memory handle. |
137 const PPB_ImageDataTrusted* trusted = | 153 const PPB_ImageDataTrusted* trusted = |
138 reinterpret_cast<const PPB_ImageDataTrusted*>( | 154 reinterpret_cast<const PPB_ImageDataTrusted*>( |
139 dispatcher_->GetLocalInterface(PPB_IMAGEDATA_TRUSTED_INTERFACE)); | 155 dispatcher_->GetLocalInterface(PPB_IMAGEDATA_TRUSTED_INTERFACE)); |
140 uint32_t byte_count = 0; | 156 uint32_t byte_count = 0; |
141 if (trusted) { | 157 if (trusted) { |
142 int32_t handle; | 158 int32_t handle; |
143 if (trusted->GetSharedMemory(resource, &handle, &byte_count) == PP_OK) { | 159 if (trusted->GetSharedMemory(resource, &handle, &byte_count) == PP_OK) { |
144 #if defined(OS_WIN) | 160 #if defined(OS_WIN) |
145 pp::proxy::ImageHandle ih = ImageData::HandleFromInt(handle); | 161 pp::proxy::ImageHandle ih = ImageData::HandleFromInt(handle); |
146 *result_image_handle = dispatcher_->ShareHandleWithRemote(ih, false); | 162 *result_image_handle = dispatcher_->ShareHandleWithRemote(ih, false); |
147 #else | 163 #else |
148 *result_image_handle = ImageData::HandleFromInt(handle); | 164 *result_image_handle = ImageData::HandleFromInt(handle); |
149 #endif | 165 #endif |
150 } | 166 } |
151 } | 167 } |
152 } | 168 } |
153 | 169 |
154 } // namespace proxy | 170 } // namespace proxy |
155 } // namespace pp | 171 } // namespace pp |
OLD | NEW |