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

Side by Side Diff: ppapi/cpp/array_output.h

Issue 9728001: Make the file chooser use PP_ArrayOutput (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 8 years, 9 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/c/trusted/ppb_file_chooser_trusted.h ('k') | ppapi/cpp/completion_callback.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) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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 #ifndef PPAPI_CPP_ARRAY_OUTPUT_H_ 5 #ifndef PPAPI_CPP_ARRAY_OUTPUT_H_
6 #define PPAPI_CPP_ARRAY_OUTPUT_H_ 6 #define PPAPI_CPP_ARRAY_OUTPUT_H_
7 7
8 #include <vector> 8 #include <vector>
9 9
10 #include "ppapi/c/pp_array_output.h" 10 #include "ppapi/c/pp_array_output.h"
(...skipping 29 matching lines...) Expand all
40 // derived classes below. 40 // derived classes below.
41 class ArrayOutputAdapterBase { 41 class ArrayOutputAdapterBase {
42 public: 42 public:
43 ArrayOutputAdapterBase() { 43 ArrayOutputAdapterBase() {
44 pp_array_output_.GetDataBuffer = 44 pp_array_output_.GetDataBuffer =
45 &ArrayOutputAdapterBase::GetDataBufferThunk; 45 &ArrayOutputAdapterBase::GetDataBufferThunk;
46 pp_array_output_.user_data = this; 46 pp_array_output_.user_data = this;
47 } 47 }
48 virtual ~ArrayOutputAdapterBase() {} 48 virtual ~ArrayOutputAdapterBase() {}
49 49
50 PP_ArrayOutput* pp_array_output() { return &pp_array_output_; } 50 const PP_ArrayOutput& pp_array_output() { return pp_array_output_; }
51 51
52 protected: 52 protected:
53 virtual void* GetDataBuffer(uint32_t element_count, 53 virtual void* GetDataBuffer(uint32_t element_count,
54 uint32_t element_size) = 0; 54 uint32_t element_size) = 0;
55 55
56 private: 56 private:
57 static void* GetDataBufferThunk(void* user_data, 57 static void* GetDataBufferThunk(void* user_data,
58 uint32_t element_count, 58 uint32_t element_count,
59 uint32_t element_size); 59 uint32_t element_size);
60 60
(...skipping 24 matching lines...) Expand all
85 public: 85 public:
86 ArrayOutputAdapter(std::vector<T>* output) : output_(output) {} 86 ArrayOutputAdapter(std::vector<T>* output) : output_(output) {}
87 87
88 protected: 88 protected:
89 // Two-step init for the "with storage" version below. 89 // Two-step init for the "with storage" version below.
90 ArrayOutputAdapter() : output_(NULL) {} 90 ArrayOutputAdapter() : output_(NULL) {}
91 void set_output(std::vector<T>* output) { output_ = output; } 91 void set_output(std::vector<T>* output) { output_ = output; }
92 92
93 // ArrayOutputAdapterBase implementation. 93 // ArrayOutputAdapterBase implementation.
94 virtual void* GetDataBuffer(uint32_t element_count, uint32_t element_size) { 94 virtual void* GetDataBuffer(uint32_t element_count, uint32_t element_size) {
95 if (element_count == 0)
96 return NULL;
95 PP_DCHECK(element_size == sizeof(T)); 97 PP_DCHECK(element_size == sizeof(T));
96 if (element_size != sizeof(T)) 98 if (element_size != sizeof(T))
97 return NULL; 99 return NULL;
98 output_->resize(element_count); 100 output_->resize(element_count);
99 return &(*output_)[0]; 101 return &(*output_)[0];
100 } 102 }
101 103
102 private: 104 private:
103 std::vector<T>* output_; 105 std::vector<T>* output_;
104 }; 106 };
(...skipping 28 matching lines...) Expand all
133 } 135 }
134 136
135 protected: 137 protected:
136 // Two-step init for the "with storage" version below. 138 // Two-step init for the "with storage" version below.
137 ResourceArrayOutputAdapter() : output_(NULL) {} 139 ResourceArrayOutputAdapter() : output_(NULL) {}
138 void set_output(T* output) { output_ = output; } 140 void set_output(T* output) { output_ = output; }
139 141
140 // ArrayOutputAdapterBase implementation. 142 // ArrayOutputAdapterBase implementation.
141 virtual void* GetDataBuffer(uint32_t element_count, 143 virtual void* GetDataBuffer(uint32_t element_count,
142 uint32_t element_size) { 144 uint32_t element_size) {
145 if (element_count == 0)
146 return NULL;
143 PP_DCHECK(element_size == sizeof(PP_Resource)); 147 PP_DCHECK(element_size == sizeof(PP_Resource));
144 if (element_size != sizeof(PP_Resource)) 148 if (element_size != sizeof(PP_Resource))
145 return NULL; 149 return NULL;
146 intermediate_output_.resize(element_count); 150 intermediate_output_.resize(element_count);
147 return &intermediate_output_[0]; 151 return &intermediate_output_[0];
148 } 152 }
149 153
150 private: 154 private:
151 std::vector<PP_Resource> intermediate_output_; 155 std::vector<PP_Resource> intermediate_output_;
152 std::vector<T>* output_; 156 std::vector<T>* output_;
(...skipping 98 matching lines...) Expand 10 before | Expand all | Expand 10 after
251 std::vector<PP_Resource> temp_storage_; 255 std::vector<PP_Resource> temp_storage_;
252 256
253 // When asked for the output, the resources above will be converted to the 257 // When asked for the output, the resources above will be converted to the
254 // C++ resource objects in this array for passing to the calling code. 258 // C++ resource objects in this array for passing to the calling code.
255 std::vector<T> output_storage_; 259 std::vector<T> output_storage_;
256 }; 260 };
257 261
258 } // namespace pp 262 } // namespace pp
259 263
260 #endif // PPAPI_CPP_ARRAY_OUTPUT_H_ 264 #endif // PPAPI_CPP_ARRAY_OUTPUT_H_
OLDNEW
« no previous file with comments | « ppapi/c/trusted/ppb_file_chooser_trusted.h ('k') | ppapi/cpp/completion_callback.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698