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

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

Issue 6282007: First pass at making the proxy handle multiple renderers. This associates the... (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: '' Created 9 years, 11 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
OLDNEW
1 // Copyright (c) 2010 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/c/trusted/ppb_image_data_trusted.h" 16 #include "ppapi/c/trusted/ppb_image_data_trusted.h"
17 #include "ppapi/proxy/image_data.h" 17 #include "ppapi/proxy/image_data.h"
18 #include "ppapi/proxy/plugin_dispatcher.h" 18 #include "ppapi/proxy/plugin_dispatcher.h"
19 #include "ppapi/proxy/plugin_resource_tracker.h"
19 #include "ppapi/proxy/ppapi_messages.h" 20 #include "ppapi/proxy/ppapi_messages.h"
20 21
21 namespace pp { 22 namespace pp {
22 namespace proxy { 23 namespace proxy {
23 24
24 namespace { 25 namespace {
25 26
26 PP_ImageDataFormat GetNativeImageDataFormat() { 27 PP_ImageDataFormat GetNativeImageDataFormat() {
piman 2011/01/20 00:26:23 Here too, it sounds like we should pass a PP_Insta
brettw 2011/01/20 00:48:45 I was less sure what to do about these ones. Since
piman 2011/01/20 01:05:12 I just want to make sure we don't design ourselves
brettw 2011/01/20 05:52:13 This flag means more than just the fast compositin
27 int32 format = 0; 28 return ImageData::GetNativeImageDataFormat();
28 PluginDispatcher::Get()->Send(
29 new PpapiHostMsg_PPBImageData_GetNativeImageDataFormat(
30 INTERFACE_ID_PPB_IMAGE_DATA, &format));
31 return static_cast<PP_ImageDataFormat>(format);
32 } 29 }
33 30
34 PP_Bool IsImageDataFormatSupported(PP_ImageDataFormat format) { 31 PP_Bool IsImageDataFormatSupported(PP_ImageDataFormat format) {
35 PP_Bool supported = PP_FALSE; 32 return BoolToPPBool(ImageData::IsImageDataFormatSupported(format));
36 PluginDispatcher::Get()->Send(
37 new PpapiHostMsg_PPBImageData_IsImageDataFormatSupported(
38 INTERFACE_ID_PPB_IMAGE_DATA, static_cast<int32_t>(format),
39 &supported));
40 return supported;
41 } 33 }
42 34
43 PP_Resource Create(PP_Instance instance, 35 PP_Resource Create(PP_Instance instance,
44 PP_ImageDataFormat format, 36 PP_ImageDataFormat format,
45 const PP_Size* size, 37 const PP_Size* size,
46 PP_Bool init_to_zero) { 38 PP_Bool init_to_zero) {
39 PluginDispatcher* dispatcher = PluginDispatcher::GetForInstance(instance);
40 if (!dispatcher)
41 return PP_ERROR_BADARGUMENT;
42
47 PP_Resource result = 0; 43 PP_Resource result = 0;
48 std::string image_data_desc; 44 std::string image_data_desc;
49 ImageHandle image_handle = ImageData::NullHandle; 45 ImageHandle image_handle = ImageData::NullHandle;
50 PluginDispatcher::Get()->Send( 46 dispatcher->Send(new PpapiHostMsg_PPBImageData_Create(
51 new PpapiHostMsg_PPBImageData_Create( 47 INTERFACE_ID_PPB_IMAGE_DATA, instance, format, *size, init_to_zero,
52 INTERFACE_ID_PPB_IMAGE_DATA, instance, format, *size, init_to_zero, 48 &result, &image_data_desc, &image_handle));
53 &result, &image_data_desc, &image_handle));
54 49
55 if (result && image_data_desc.size() == sizeof(PP_ImageDataDesc)) { 50 if (result && image_data_desc.size() == sizeof(PP_ImageDataDesc)) {
56 // We serialize the PP_ImageDataDesc just by copying to a string. 51 // We serialize the PP_ImageDataDesc just by copying to a string.
57 PP_ImageDataDesc desc; 52 PP_ImageDataDesc desc;
58 memcpy(&desc, image_data_desc.data(), sizeof(PP_ImageDataDesc)); 53 memcpy(&desc, image_data_desc.data(), sizeof(PP_ImageDataDesc));
59 54
60 linked_ptr<ImageData> object( 55 linked_ptr<ImageData> object(new ImageData(instance, desc, image_handle));
61 new ImageData(desc, image_handle)); 56 PluginResourceTracker::GetInstance()->AddResource(result, object);
62 PluginDispatcher::Get()->plugin_resource_tracker()->AddResource(
63 result, object);
64 } 57 }
65 return result; 58 return result;
66 } 59 }
67 60
68 PP_Bool IsImageData(PP_Resource resource) { 61 PP_Bool IsImageData(PP_Resource resource) {
69 ImageData* object = PluginResource::GetAs<ImageData>(resource); 62 ImageData* object = PluginResource::GetAs<ImageData>(resource);
70 return BoolToPPBool(!!object); 63 return BoolToPPBool(!!object);
71 } 64 }
72 65
73 PP_Bool Describe(PP_Resource resource, PP_ImageDataDesc* desc) { 66 PP_Bool Describe(PP_Resource resource, PP_ImageDataDesc* desc) {
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
115 return &ppb_imagedata; 108 return &ppb_imagedata;
116 } 109 }
117 110
118 InterfaceID PPB_ImageData_Proxy::GetInterfaceId() const { 111 InterfaceID PPB_ImageData_Proxy::GetInterfaceId() const {
119 return INTERFACE_ID_PPB_IMAGE_DATA; 112 return INTERFACE_ID_PPB_IMAGE_DATA;
120 } 113 }
121 114
122 bool PPB_ImageData_Proxy::OnMessageReceived(const IPC::Message& msg) { 115 bool PPB_ImageData_Proxy::OnMessageReceived(const IPC::Message& msg) {
123 bool handled = true; 116 bool handled = true;
124 IPC_BEGIN_MESSAGE_MAP(PPB_ImageData_Proxy, msg) 117 IPC_BEGIN_MESSAGE_MAP(PPB_ImageData_Proxy, msg)
125 IPC_MESSAGE_HANDLER(PpapiHostMsg_PPBImageData_GetNativeImageDataFormat,
126 OnMsgGetNativeImageDataFormat)
127 IPC_MESSAGE_HANDLER(PpapiHostMsg_PPBImageData_IsImageDataFormatSupported,
128 OnMsgIsImageDataFormatSupported)
129 IPC_MESSAGE_HANDLER(PpapiHostMsg_PPBImageData_Create, OnMsgCreate) 118 IPC_MESSAGE_HANDLER(PpapiHostMsg_PPBImageData_Create, OnMsgCreate)
130 IPC_MESSAGE_UNHANDLED(handled = false) 119 IPC_MESSAGE_UNHANDLED(handled = false)
131 IPC_END_MESSAGE_MAP() 120 IPC_END_MESSAGE_MAP()
132 // FIXME(brettw) handle bad messages! 121 // FIXME(brettw) handle bad messages!
133 return handled; 122 return handled;
134 } 123 }
135 124
136 void PPB_ImageData_Proxy::OnMsgGetNativeImageDataFormat(int32* result) {
137 *result = ppb_image_data_target()->GetNativeImageDataFormat();
138 }
139
140 void PPB_ImageData_Proxy::OnMsgIsImageDataFormatSupported(int32 format,
141 PP_Bool* result) {
142 *result = ppb_image_data_target()->IsImageDataFormatSupported(
143 static_cast<PP_ImageDataFormat>(format));
144 }
145
146 void PPB_ImageData_Proxy::OnMsgCreate(PP_Instance instance, 125 void PPB_ImageData_Proxy::OnMsgCreate(PP_Instance instance,
147 int32_t format, 126 int32_t format,
148 const PP_Size& size, 127 const PP_Size& size,
149 PP_Bool init_to_zero, 128 PP_Bool init_to_zero,
150 PP_Resource* result, 129 PP_Resource* result,
151 std::string* image_data_desc, 130 std::string* image_data_desc,
152 ImageHandle* result_image_handle) { 131 ImageHandle* result_image_handle) {
153 *result = ppb_image_data_target()->Create( 132 *result = ppb_image_data_target()->Create(
154 instance, static_cast<PP_ImageDataFormat>(format), &size, init_to_zero); 133 instance, static_cast<PP_ImageDataFormat>(format), &size, init_to_zero);
155 *result_image_handle = ImageData::NullHandle; 134 *result_image_handle = ImageData::NullHandle;
(...skipping 13 matching lines...) Expand all
169 if (trusted) { 148 if (trusted) {
170 int32_t handle; 149 int32_t handle;
171 if (trusted->GetSharedMemory(*result, &handle, &byte_count) == PP_OK) 150 if (trusted->GetSharedMemory(*result, &handle, &byte_count) == PP_OK)
172 *result_image_handle = ImageData::HandleFromInt(handle); 151 *result_image_handle = ImageData::HandleFromInt(handle);
173 } 152 }
174 } 153 }
175 } 154 }
176 155
177 } // namespace proxy 156 } // namespace proxy
178 } // namespace pp 157 } // namespace pp
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698