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