Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(212)

Side by Side Diff: ppapi/proxy/resource_creation_proxy.cc

Issue 6905088: New thunk system for Pepper proxy and implementation (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: '' Created 9 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « ppapi/proxy/resource_creation_proxy.h ('k') | ppapi/shared_impl/function_group_base.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Property Changes:
Added: svn:eol-style
+ LF
OLDNEW
(Empty)
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
3 // found in the LICENSE file.
4
5 #include "ppapi/proxy/resource_creation_proxy.h"
6
7 #include "ppapi/c/pp_errors.h"
8 #include "ppapi/c/pp_size.h"
9 #include "ppapi/proxy/host_resource.h"
10 #include "ppapi/proxy/interface_id.h"
11 #include "ppapi/proxy/plugin_dispatcher.h"
12 #include "ppapi/proxy/plugin_resource_tracker.h"
13 #include "ppapi/proxy/ppapi_messages.h"
14 #include "ppapi/proxy/ppb_graphics_2d_proxy.h"
15 #include "ppapi/proxy/ppb_image_data_proxy.h"
16 #include "ppapi/c/trusted/ppb_image_data_trusted.h"
17 #include "ppapi/shared_impl/function_group_base.h"
18 #include "ppapi/thunk/enter.h"
19
20 using ::ppapi::thunk::ResourceCreationAPI;
21
22 namespace pp {
23 namespace proxy {
24
25 ResourceCreationProxy::ResourceCreationProxy(Dispatcher* dispatcher)
26 : dispatcher_(dispatcher) {
27 }
28
29 ResourceCreationProxy::~ResourceCreationProxy() {
30 }
31
32 ::ppapi::thunk::ResourceCreationAPI*
33 ResourceCreationProxy::AsResourceCreation() {
34 return this;
35 }
36
37 PP_Resource ResourceCreationProxy::CreateGraphics2D(PP_Instance pp_instance,
38 const PP_Size& size,
39 PP_Bool is_always_opaque) {
40 PluginDispatcher* dispatcher = PluginDispatcher::GetForInstance(pp_instance);
41 if (!dispatcher)
42 return PP_ERROR_BADARGUMENT;
43
44 HostResource result;
45 dispatcher->Send(new PpapiHostMsg_ResourceCreation_Graphics2D(
46 INTERFACE_ID_RESOURCE_CREATION, pp_instance, size, is_always_opaque,
47 &result));
48 if (result.is_null())
49 return 0;
50 linked_ptr<Graphics2D> graphics_2d(new Graphics2D(result, size,
51 is_always_opaque));
52 return PluginResourceTracker::GetInstance()->AddResource(graphics_2d);
53 }
54
55 PP_Resource ResourceCreationProxy::CreateImageData(PP_Instance instance,
56 PP_ImageDataFormat format,
57 const PP_Size& size,
58 PP_Bool init_to_zero) {
59 PluginDispatcher* dispatcher = PluginDispatcher::GetForInstance(instance);
60 if (!dispatcher)
61 return 0;
62
63 HostResource result;
64 std::string image_data_desc;
65 ImageHandle image_handle = ImageData::NullHandle;
66 dispatcher->Send(new PpapiHostMsg_ResourceCreation_ImageData(
67 INTERFACE_ID_RESOURCE_CREATION, instance, format, size, init_to_zero,
68 &result, &image_data_desc, &image_handle));
69
70 if (result.is_null() || image_data_desc.size() != sizeof(PP_ImageDataDesc))
71 return 0;
72
73 // We serialize the PP_ImageDataDesc just by copying to a string.
74 PP_ImageDataDesc desc;
75 memcpy(&desc, image_data_desc.data(), sizeof(PP_ImageDataDesc));
76
77 linked_ptr<ImageData> object(new ImageData(result, desc, image_handle));
78 return PluginResourceTracker::GetInstance()->AddResource(object);
79 }
80
81 bool ResourceCreationProxy::Send(IPC::Message* msg) {
82 return dispatcher_->Send(msg);
83 }
84
85 bool ResourceCreationProxy::OnMessageReceived(const IPC::Message& msg) {
86 bool handled = true;
87 IPC_BEGIN_MESSAGE_MAP(ResourceCreationProxy, msg)
88 IPC_MESSAGE_HANDLER(PpapiHostMsg_ResourceCreation_Graphics2D,
89 OnMsgCreateGraphics2D)
90 IPC_MESSAGE_HANDLER(PpapiHostMsg_ResourceCreation_ImageData,
91 OnMsgCreateImageData)
92 IPC_MESSAGE_UNHANDLED(handled = false)
93 IPC_END_MESSAGE_MAP()
94 return handled;
95 }
96
97 void ResourceCreationProxy::OnMsgCreateGraphics2D(PP_Instance instance,
98 const PP_Size& size,
99 PP_Bool is_always_opaque,
100 HostResource* result) {
101 ppapi::thunk::EnterFunction<ResourceCreationAPI> enter(instance, false);
102 if (enter.succeeded()) {
103 result->SetHostResource(instance, enter.functions()->CreateGraphics2D(
104 instance, size, is_always_opaque));
105 }
106 }
107
108 void ResourceCreationProxy::OnMsgCreateImageData(
109 PP_Instance instance,
110 int32_t format,
111 const PP_Size& size,
112 PP_Bool init_to_zero,
113 HostResource* result,
114 std::string* image_data_desc,
115 ImageHandle* result_image_handle) {
116 *result_image_handle = ImageData::NullHandle;
117
118 ppapi::thunk::EnterFunction<ResourceCreationAPI> enter(instance, false);
119 if (enter.failed())
120 return;
121
122 PP_Resource resource = enter.functions()->CreateImageData(
123 instance, static_cast<PP_ImageDataFormat>(format), size, init_to_zero);
124 if (!resource)
125 return;
126 result->SetHostResource(instance, resource);
127
128 // Get the description, it's just serialized as a string.
129 ppapi::thunk::EnterResource<PPB_ImageData> enter_resource(resource, false);
130 PP_ImageDataDesc desc;
131 if (enter_resource.object()->Describe(resource, &desc)) {
132 image_data_desc->resize(sizeof(PP_ImageDataDesc));
133 memcpy(&(*image_data_desc)[0], &desc, sizeof(PP_ImageDataDesc));
134 }
135
136 // Get the shared memory handle.
137 const PPB_ImageDataTrusted* trusted =
138 reinterpret_cast<const PPB_ImageDataTrusted*>(
139 dispatcher_->GetLocalInterface(PPB_IMAGEDATA_TRUSTED_INTERFACE));
140 uint32_t byte_count = 0;
141 if (trusted) {
142 int32_t handle;
143 if (trusted->GetSharedMemory(resource, &handle, &byte_count) == PP_OK) {
144 #if defined(OS_WIN)
145 pp::proxy::ImageHandle ih = ImageData::HandleFromInt(handle);
146 *result_image_handle = dispatcher()->ShareHandleWithRemote(ih, false);
147 #else
148 *result_image_handle = ImageData::HandleFromInt(handle);
149 #endif
150 }
151 }
152 }
153
154 } // namespace proxy
155 } // namespace pp
OLDNEW
« no previous file with comments | « ppapi/proxy/resource_creation_proxy.h ('k') | ppapi/shared_impl/function_group_base.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698