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

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

Issue 8790009: Regularize how ImageData and Graphics2D are created. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Fix comment Created 9 years 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
OLDNEW
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/ppb_image_data_proxy.h" 5 #include "ppapi/proxy/ppb_image_data_proxy.h"
6 6
7 #include <string.h> // For memcpy 7 #include <string.h> // For memcpy
8 8
9 #include <vector> 9 #include <vector>
10 10
11 #include "base/logging.h" 11 #include "base/logging.h"
12 #include "build/build_config.h" 12 #include "build/build_config.h"
13 #include "ppapi/c/pp_completion_callback.h" 13 #include "ppapi/c/pp_completion_callback.h"
14 #include "ppapi/c/pp_errors.h" 14 #include "ppapi/c/pp_errors.h"
15 #include "ppapi/c/pp_resource.h" 15 #include "ppapi/c/pp_resource.h"
16 #include "ppapi/proxy/plugin_dispatcher.h" 16 #include "ppapi/proxy/plugin_dispatcher.h"
17 #include "ppapi/proxy/plugin_resource_tracker.h" 17 #include "ppapi/proxy/plugin_resource_tracker.h"
18 #include "ppapi/proxy/ppapi_messages.h" 18 #include "ppapi/proxy/ppapi_messages.h"
19 #include "ppapi/shared_impl/host_resource.h" 19 #include "ppapi/shared_impl/host_resource.h"
20 #include "ppapi/shared_impl/resource.h" 20 #include "ppapi/shared_impl/resource.h"
21 #include "ppapi/thunk/enter.h"
21 #include "ppapi/thunk/thunk.h" 22 #include "ppapi/thunk/thunk.h"
22 #include "skia/ext/platform_canvas.h" 23 #include "skia/ext/platform_canvas.h"
23 #include "ui/gfx/surface/transport_dib.h" 24 #include "ui/gfx/surface/transport_dib.h"
24 25
25 namespace ppapi { 26 namespace ppapi {
26 namespace proxy { 27 namespace proxy {
27 28
28 ImageData::ImageData(const HostResource& resource, 29 ImageData::ImageData(const HostResource& resource,
29 const PP_ImageDataDesc& desc, 30 const PP_ImageDataDesc& desc,
30 ImageHandle handle) 31 ImageHandle handle)
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after
87 ImageHandle ImageData::HandleFromInt(int32_t i) { 88 ImageHandle ImageData::HandleFromInt(int32_t i) {
88 #if defined(OS_WIN) 89 #if defined(OS_WIN)
89 return reinterpret_cast<ImageHandle>(i); 90 return reinterpret_cast<ImageHandle>(i);
90 #elif defined(OS_MACOSX) 91 #elif defined(OS_MACOSX)
91 return ImageHandle(i, false); 92 return ImageHandle(i, false);
92 #else 93 #else
93 return static_cast<ImageHandle>(i); 94 return static_cast<ImageHandle>(i);
94 #endif 95 #endif
95 } 96 }
96 97
98 PPB_ImageData_Proxy::PPB_ImageData_Proxy(Dispatcher* dispatcher)
99 : InterfaceProxy(dispatcher) {
100 }
101
102 PPB_ImageData_Proxy::~PPB_ImageData_Proxy() {
103 }
104
105 // static
106 PP_Resource PPB_ImageData_Proxy::CreateProxyResource(PP_Instance instance,
107 PP_ImageDataFormat format,
108 const PP_Size& size,
109 PP_Bool init_to_zero) {
110 PluginDispatcher* dispatcher = PluginDispatcher::GetForInstance(instance);
111 if (!dispatcher)
112 return 0;
113
114 HostResource result;
115 std::string image_data_desc;
116 ImageHandle image_handle = ImageData::NullHandle;
117 dispatcher->Send(new PpapiHostMsg_PPBImageData_Create(
118 kApiID, instance, format, size, init_to_zero,
119 &result, &image_data_desc, &image_handle));
120
121 if (result.is_null() || image_data_desc.size() != sizeof(PP_ImageDataDesc))
122 return 0;
123
124 // We serialize the PP_ImageDataDesc just by copying to a string.
125 PP_ImageDataDesc desc;
126 memcpy(&desc, image_data_desc.data(), sizeof(PP_ImageDataDesc));
127
128 return (new ImageData(result, desc, image_handle))->GetReference();
129 }
130
131 bool PPB_ImageData_Proxy::OnMessageReceived(const IPC::Message& msg) {
132 bool handled = true;
133 IPC_BEGIN_MESSAGE_MAP(PPB_ImageData_Proxy, msg)
134 IPC_MESSAGE_HANDLER(PpapiHostMsg_PPBImageData_Create, OnHostMsgCreate)
135 IPC_MESSAGE_UNHANDLED(handled = false)
136 IPC_END_MESSAGE_MAP()
137 return handled;
138 }
139
140 void PPB_ImageData_Proxy::OnHostMsgCreate(PP_Instance instance,
141 int32_t format,
142 const PP_Size& size,
143 PP_Bool init_to_zero,
144 HostResource* result,
145 std::string* image_data_desc,
146 ImageHandle* result_image_handle) {
147 *result_image_handle = ImageData::NullHandle;
148
149 thunk::EnterResourceCreation enter(instance);
150 if (enter.failed())
151 return;
152
153 PP_Resource resource = enter.functions()->CreateImageData(
154 instance, static_cast<PP_ImageDataFormat>(format), size, init_to_zero);
155 if (!resource)
156 return;
157 result->SetHostResource(instance, resource);
158
159 // Get the description, it's just serialized as a string.
160 thunk::EnterResourceNoLock<thunk::PPB_ImageData_API> enter_resource(
161 resource, false);
162 PP_ImageDataDesc desc;
163 if (enter_resource.object()->Describe(&desc) == PP_TRUE) {
164 image_data_desc->resize(sizeof(PP_ImageDataDesc));
165 memcpy(&(*image_data_desc)[0], &desc, sizeof(PP_ImageDataDesc));
166 }
167
168 // Get the shared memory handle.
169 uint32_t byte_count = 0;
170 int32_t handle = 0;
171 if (enter_resource.object()->GetSharedMemory(&handle, &byte_count) == PP_OK) {
172 #if defined(OS_WIN)
173 ImageHandle ih = ImageData::HandleFromInt(handle);
174 *result_image_handle = dispatcher()->ShareHandleWithRemote(ih, false);
175 #else
176 *result_image_handle = ImageData::HandleFromInt(handle);
177 #endif
178 }
179 }
180
97 } // namespace proxy 181 } // namespace proxy
98 } // namespace ppapi 182 } // namespace ppapi
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698