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

Side by Side Diff: webkit/glue/plugins/pepper_buffer.cc

Issue 5410001: Change trusted shared memory interface to match audio.... (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: '' Created 10 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
« no previous file with comments | « webkit/glue/plugins/pepper_buffer.h ('k') | webkit/glue/plugins/pepper_image_data.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) 2010 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2010 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 "webkit/glue/plugins/pepper_buffer.h" 5 #include "webkit/glue/plugins/pepper_buffer.h"
6 6
7 #include <algorithm> 7 #include <algorithm>
8 8
9 #include "base/logging.h" 9 #include "base/logging.h"
10 #include "base/scoped_ptr.h" 10 #include "base/scoped_ptr.h"
11 #include "ppapi/c/dev/ppb_buffer_dev.h" 11 #include "ppapi/c/dev/ppb_buffer_dev.h"
12 #include "ppapi/c/pp_instance.h" 12 #include "ppapi/c/pp_instance.h"
13 #include "ppapi/c/pp_module.h" 13 #include "ppapi/c/pp_module.h"
14 #include "ppapi/c/pp_resource.h" 14 #include "ppapi/c/pp_resource.h"
15 #include "webkit/glue/plugins/pepper_common.h" 15 #include "webkit/glue/plugins/pepper_common.h"
16 #include "webkit/glue/plugins/pepper_plugin_instance.h" 16 #include "webkit/glue/plugins/pepper_plugin_instance.h"
17 #include "webkit/glue/plugins/pepper_plugin_module.h" 17 #include "webkit/glue/plugins/pepper_plugin_module.h"
18 18
19 namespace pepper { 19 namespace pepper {
20 20
21 namespace { 21 namespace {
22 22
23 PP_Resource Create(PP_Module module_id, int32_t size) { 23 PP_Resource Create(PP_Module module_id, uint32_t size) {
24 PluginModule* module = ResourceTracker::Get()->GetModule(module_id); 24 PluginModule* module = ResourceTracker::Get()->GetModule(module_id);
25 if (!module) 25 if (!module)
26 return 0; 26 return 0;
27 27
28 scoped_refptr<Buffer> buffer(new Buffer(module)); 28 scoped_refptr<Buffer> buffer(new Buffer(module));
29 if (!buffer->Init(size)) 29 if (!buffer->Init(size))
30 return 0; 30 return 0;
31 31
32 return buffer->GetReference(); 32 return buffer->GetReference();
33 } 33 }
34 34
35 PP_Bool IsBuffer(PP_Resource resource) { 35 PP_Bool IsBuffer(PP_Resource resource) {
36 return BoolToPPBool(!!Resource::GetAs<Buffer>(resource)); 36 return BoolToPPBool(!!Resource::GetAs<Buffer>(resource));
37 } 37 }
38 38
39 PP_Bool Describe(PP_Resource resource, int32_t* size_in_bytes) { 39 PP_Bool Describe(PP_Resource resource, uint32_t* size_in_bytes) {
40 scoped_refptr<Buffer> buffer(Resource::GetAs<Buffer>(resource)); 40 scoped_refptr<Buffer> buffer(Resource::GetAs<Buffer>(resource));
41 if (!buffer) 41 if (!buffer)
42 return PP_FALSE; 42 return PP_FALSE;
43 buffer->Describe(size_in_bytes); 43 buffer->Describe(size_in_bytes);
44 return PP_TRUE; 44 return PP_TRUE;
45 } 45 }
46 46
47 void* Map(PP_Resource resource) { 47 void* Map(PP_Resource resource) {
48 scoped_refptr<Buffer> buffer(Resource::GetAs<Buffer>(resource)); 48 scoped_refptr<Buffer> buffer(Resource::GetAs<Buffer>(resource));
49 if (!buffer) 49 if (!buffer)
(...skipping 24 matching lines...) Expand all
74 } 74 }
75 75
76 Buffer::~Buffer() { 76 Buffer::~Buffer() {
77 } 77 }
78 78
79 // static 79 // static
80 const PPB_Buffer_Dev* Buffer::GetInterface() { 80 const PPB_Buffer_Dev* Buffer::GetInterface() {
81 return &ppb_buffer; 81 return &ppb_buffer;
82 } 82 }
83 83
84 bool Buffer::Init(int size) { 84 bool Buffer::Init(uint32_t size) {
85 if (size == 0) 85 if (size == 0)
86 return false; 86 return false;
87 Unmap(); 87 Unmap();
88 size_ = size; 88 size_ = size;
89 return true; 89 return true;
90 } 90 }
91 91
92 void Buffer::Describe(int* size_in_bytes) const { 92 void Buffer::Describe(uint32_t* size_in_bytes) const {
93 *size_in_bytes = size_; 93 *size_in_bytes = size_;
94 } 94 }
95 95
96 void* Buffer::Map() { 96 void* Buffer::Map() {
97 if (size_ == 0) 97 if (size_ == 0)
98 return NULL; 98 return NULL;
99 99
100 if (!is_mapped()) { 100 if (!is_mapped()) {
101 mem_buffer_.reset(new unsigned char[size_]); 101 mem_buffer_.reset(new unsigned char[size_]);
102 memset(mem_buffer_.get(), 0, size_); 102 memset(mem_buffer_.get(), 0, size_);
103 } 103 }
104 return mem_buffer_.get(); 104 return mem_buffer_.get();
105 } 105 }
106 106
107 void Buffer::Unmap() { 107 void Buffer::Unmap() {
108 mem_buffer_.reset(); 108 mem_buffer_.reset();
109 } 109 }
110 110
111 void Buffer::Swap(Buffer* other) { 111 void Buffer::Swap(Buffer* other) {
112 swap(other->mem_buffer_, mem_buffer_); 112 swap(other->mem_buffer_, mem_buffer_);
113 std::swap(other->size_, size_); 113 std::swap(other->size_, size_);
114 } 114 }
115 115
116 } // namespace pepper 116 } // namespace pepper
117 117
OLDNEW
« no previous file with comments | « webkit/glue/plugins/pepper_buffer.h ('k') | webkit/glue/plugins/pepper_image_data.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698