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

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

Issue 14208016: Hookup RawVarData to SerializedVar (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: . Created 7 years, 8 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/raw_var_data.h ('k') | ppapi/proxy/serialized_var.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2013 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/raw_var_data.h" 5 #include "ppapi/proxy/raw_var_data.h"
6 6
7 #include <stack> 7 #include <stack>
8 8
9 #include "base/hash_tables.h" 9 #include "base/hash_tables.h"
10 #include "base/stl_util.h" 10 #include "base/stl_util.h"
(...skipping 10 matching lines...) Expand all
21 21
22 namespace ppapi { 22 namespace ppapi {
23 namespace proxy { 23 namespace proxy {
24 24
25 namespace { 25 namespace {
26 26
27 // When sending array buffers, if the size is over 256K, we use shared 27 // When sending array buffers, if the size is over 256K, we use shared
28 // memory instead of sending the data over IPC. Light testing suggests 28 // memory instead of sending the data over IPC. Light testing suggests
29 // shared memory is much faster for 256K and larger messages. 29 // shared memory is much faster for 256K and larger messages.
30 static const uint32 kMinimumArrayBufferSizeForShmem = 256 * 1024; 30 static const uint32 kMinimumArrayBufferSizeForShmem = 256 * 1024;
31 static uint32 g_minimum_array_buffer_size_for_shmem =
32 kMinimumArrayBufferSizeForShmem;
31 33
32 void DefaultHandleWriter(IPC::Message* m, const SerializedHandle& handle) { 34 void DefaultHandleWriter(IPC::Message* m, const SerializedHandle& handle) {
33 IPC::ParamTraits<SerializedHandle>::Write(m, handle); 35 IPC::ParamTraits<SerializedHandle>::Write(m, handle);
34 } 36 }
35 37
36 // For a given PP_Var, returns the RawVarData associated with it, or creates a 38 // For a given PP_Var, returns the RawVarData associated with it, or creates a
37 // new one if there is no existing one. The data is appended to |data| if it 39 // new one if there is no existing one. The data is appended to |data| if it
38 // is newly created. The index into |data| pointing to the result is returned. 40 // is newly created. The index into |data| pointing to the result is returned.
39 // |id_map| keeps track of RawVarDatas that have already been created. 41 // |id_map| keeps track of RawVarDatas that have already been created.
40 size_t GetOrCreateRawVarData(const PP_Var& var, 42 size_t GetOrCreateRawVarData(const PP_Var& var,
(...skipping 126 matching lines...) Expand 10 before | Expand all | Expand 10 after
167 if (!m->ReadInt(iter, &type)) 169 if (!m->ReadInt(iter, &type))
168 return scoped_ptr<RawVarDataGraph>(); 170 return scoped_ptr<RawVarDataGraph>();
169 PP_VarType var_type = static_cast<PP_VarType>(type); 171 PP_VarType var_type = static_cast<PP_VarType>(type);
170 result->data_.push_back(RawVarData::Create(var_type)); 172 result->data_.push_back(RawVarData::Create(var_type));
171 if (!result->data_.back()->Read(var_type, m, iter)) 173 if (!result->data_.back()->Read(var_type, m, iter))
172 return scoped_ptr<RawVarDataGraph>(); 174 return scoped_ptr<RawVarDataGraph>();
173 } 175 }
174 return result.Pass(); 176 return result.Pass();
175 } 177 }
176 178
179 std::vector<SerializedHandle*> RawVarDataGraph::GetHandles() {
180 std::vector<SerializedHandle*> result;
181 for (size_t i = 0; i < data_.size(); ++i) {
182 SerializedHandle* handle = data_[i]->GetHandle();
183 if (handle)
184 result.push_back(handle);
185 }
186 return result;
187 }
188
189 // static
190 void RawVarDataGraph::SetMinimumArrayBufferSizeForShmemForTest(
191 uint32 threshold) {
192 if (threshold == 0)
193 g_minimum_array_buffer_size_for_shmem = kMinimumArrayBufferSizeForShmem;
194 else
195 g_minimum_array_buffer_size_for_shmem = threshold;
196 }
197
177 // RawVarData ------------------------------------------------------------------ 198 // RawVarData ------------------------------------------------------------------
178 199
179 // static 200 // static
180 RawVarData* RawVarData::Create(PP_VarType type) { 201 RawVarData* RawVarData::Create(PP_VarType type) {
181 switch (type) { 202 switch (type) {
182 case PP_VARTYPE_UNDEFINED: 203 case PP_VARTYPE_UNDEFINED:
183 case PP_VARTYPE_NULL: 204 case PP_VARTYPE_NULL:
184 case PP_VARTYPE_BOOL: 205 case PP_VARTYPE_BOOL:
185 case PP_VARTYPE_INT32: 206 case PP_VARTYPE_INT32:
186 case PP_VARTYPE_DOUBLE: 207 case PP_VARTYPE_DOUBLE:
(...skipping 11 matching lines...) Expand all
198 NOTREACHED(); 219 NOTREACHED();
199 return NULL; 220 return NULL;
200 } 221 }
201 222
202 RawVarData::RawVarData() : initialized_(false) { 223 RawVarData::RawVarData() : initialized_(false) {
203 } 224 }
204 225
205 RawVarData::~RawVarData() { 226 RawVarData::~RawVarData() {
206 } 227 }
207 228
229 SerializedHandle* RawVarData::GetHandle() {
230 return NULL;
231 }
232
208 // BasicRawVarData ------------------------------------------------------------- 233 // BasicRawVarData -------------------------------------------------------------
209 BasicRawVarData::BasicRawVarData() { 234 BasicRawVarData::BasicRawVarData() {
210 } 235 }
211 236
212 BasicRawVarData::~BasicRawVarData() { 237 BasicRawVarData::~BasicRawVarData() {
213 } 238 }
214 239
215 PP_VarType BasicRawVarData::Type() { 240 PP_VarType BasicRawVarData::Type() {
216 return var_.type; 241 return var_.type;
217 } 242 }
(...skipping 130 matching lines...) Expand 10 before | Expand all | Expand 10 after
348 return PP_VARTYPE_ARRAY_BUFFER; 373 return PP_VARTYPE_ARRAY_BUFFER;
349 } 374 }
350 375
351 bool ArrayBufferRawVarData::Init(const PP_Var& var, 376 bool ArrayBufferRawVarData::Init(const PP_Var& var,
352 PP_Instance instance) { 377 PP_Instance instance) {
353 DCHECK(var.type == PP_VARTYPE_ARRAY_BUFFER); 378 DCHECK(var.type == PP_VARTYPE_ARRAY_BUFFER);
354 ArrayBufferVar* buffer_var = ArrayBufferVar::FromPPVar(var); 379 ArrayBufferVar* buffer_var = ArrayBufferVar::FromPPVar(var);
355 if (!buffer_var) 380 if (!buffer_var)
356 return false; 381 return false;
357 bool using_shmem = false; 382 bool using_shmem = false;
358 if (buffer_var->ByteLength() >= kMinimumArrayBufferSizeForShmem && 383 if (buffer_var->ByteLength() >= g_minimum_array_buffer_size_for_shmem &&
359 instance != 0) { 384 instance != 0) {
360 int host_handle_id; 385 int host_handle_id;
361 base::SharedMemoryHandle plugin_handle; 386 base::SharedMemoryHandle plugin_handle;
362 using_shmem = buffer_var->CopyToNewShmem(instance, 387 using_shmem = buffer_var->CopyToNewShmem(instance,
363 &host_handle_id, 388 &host_handle_id,
364 &plugin_handle); 389 &plugin_handle);
365 if (using_shmem) { 390 if (using_shmem) {
366 if (host_shm_handle_id_ != -1) { 391 if (host_handle_id != -1) {
367 DCHECK(!base::SharedMemory::IsHandleValid(plugin_handle)); 392 DCHECK(!base::SharedMemory::IsHandleValid(plugin_handle));
368 DCHECK(PpapiGlobals::Get()->IsPluginGlobals()); 393 DCHECK(PpapiGlobals::Get()->IsPluginGlobals());
369 type_ = ARRAY_BUFFER_SHMEM_HOST; 394 type_ = ARRAY_BUFFER_SHMEM_HOST;
370 host_shm_handle_id_ = host_handle_id; 395 host_shm_handle_id_ = host_handle_id;
371 } else { 396 } else {
372 DCHECK(base::SharedMemory::IsHandleValid(plugin_handle)); 397 DCHECK(base::SharedMemory::IsHandleValid(plugin_handle));
373 DCHECK(PpapiGlobals::Get()->IsHostGlobals()); 398 DCHECK(PpapiGlobals::Get()->IsHostGlobals());
374 type_ = ARRAY_BUFFER_SHMEM_PLUGIN; 399 type_ = ARRAY_BUFFER_SHMEM_PLUGIN;
375 plugin_shm_handle_ = SerializedHandle(plugin_handle, 400 plugin_shm_handle_ = SerializedHandle(plugin_handle,
376 buffer_var->ByteLength()); 401 buffer_var->ByteLength());
(...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after
469 return false; 494 return false;
470 break; 495 break;
471 default: 496 default:
472 // We read an invalid ID. 497 // We read an invalid ID.
473 NOTREACHED(); 498 NOTREACHED();
474 return false; 499 return false;
475 } 500 }
476 return true; 501 return true;
477 } 502 }
478 503
504 SerializedHandle* ArrayBufferRawVarData::GetHandle() {
505 if (type_ == ARRAY_BUFFER_SHMEM_PLUGIN && plugin_shm_handle_.size() != 0)
506 return &plugin_shm_handle_;
507 return NULL;
508 }
509
479 // ArrayRawVarData ------------------------------------------------------------- 510 // ArrayRawVarData -------------------------------------------------------------
480 ArrayRawVarData::ArrayRawVarData() { 511 ArrayRawVarData::ArrayRawVarData() {
481 } 512 }
482 513
483 ArrayRawVarData::~ArrayRawVarData() { 514 ArrayRawVarData::~ArrayRawVarData() {
484 } 515 }
485 516
486 void ArrayRawVarData::AddChild(size_t element) { 517 void ArrayRawVarData::AddChild(size_t element) {
487 children_.push_back(element); 518 children_.push_back(element);
488 } 519 }
(...skipping 111 matching lines...) Expand 10 before | Expand all | Expand 10 after
600 return false; 631 return false;
601 if (!m->ReadUInt32(iter, &value)) 632 if (!m->ReadUInt32(iter, &value))
602 return false; 633 return false;
603 children_.push_back(make_pair(key, value)); 634 children_.push_back(make_pair(key, value));
604 } 635 }
605 return true; 636 return true;
606 } 637 }
607 638
608 } // namespace proxy 639 } // namespace proxy
609 } // namespace ppapi 640 } // namespace ppapi
OLDNEW
« no previous file with comments | « ppapi/proxy/raw_var_data.h ('k') | ppapi/proxy/serialized_var.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698