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

Side by Side Diff: ppapi/examples/gles2/gles2.cc

Issue 7467037: Made Destroy() followup more aggressive to test for races. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: . Created 9 years, 4 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) 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 <string.h> 5 #include <string.h>
6 6
7 #include <iostream> 7 #include <iostream>
8 #include <sstream> 8 #include <sstream>
9 #include <list> 9 #include <list>
10 #include <map> 10 #include <map>
(...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after
79 // Callbacks passed into pp:VideoDecoder_Dev functions. 79 // Callbacks passed into pp:VideoDecoder_Dev functions.
80 void DecoderInitDone(int32_t result); 80 void DecoderInitDone(int32_t result);
81 void DecoderBitstreamDone(int32_t result, int bitstream_buffer_id); 81 void DecoderBitstreamDone(int32_t result, int bitstream_buffer_id);
82 void DecoderFlushDone(int32_t result); 82 void DecoderFlushDone(int32_t result);
83 83
84 // Decode helpers. 84 // Decode helpers.
85 void DecodeNextNALUs(); 85 void DecodeNextNALUs();
86 void DecodeNextNALU(); 86 void DecodeNextNALU();
87 void GetNextNALUBoundary(size_t start_pos, size_t* end_pos); 87 void GetNextNALUBoundary(size_t start_pos, size_t* end_pos);
88 void Render(const PP_PictureBuffer_Dev& buffer); 88 void Render(const PP_PictureBuffer_Dev& buffer);
89 void DeleteOutstandingBitstreamBuffers();
89 90
90 // GL-related functions. 91 // GL-related functions.
91 void InitGL(); 92 void InitGL();
92 GLuint CreateTexture(int32_t width, int32_t height); 93 GLuint CreateTexture(int32_t width, int32_t height);
93 void CreateGLObjects(); 94 void CreateGLObjects();
94 void CreateShader(GLuint program, GLenum type, const char* source, int size); 95 void CreateShader(GLuint program, GLenum type, const char* source, int size);
95 void DeleteTexture(GLuint id); 96 void DeleteTexture(GLuint id);
97 void DeleteOutstandingTextures();
96 void PaintFinished(int32_t result, int picture_buffer_id); 98 void PaintFinished(int32_t result, int picture_buffer_id);
97 99
98 // Log an error to the developer console and stderr (though the latter may be 100 // Log an error to the developer console and stderr (though the latter may be
99 // closed due to sandboxing or blackholed for other reasons) by creating a 101 // closed due to sandboxing or blackholed for other reasons) by creating a
100 // temporary of this type and streaming to it. Example usage: 102 // temporary of this type and streaming to it. Example usage:
101 // LogError(this).s() << "Hello world: " << 42; 103 // LogError(this).s() << "Hello world: " << 42;
102 class LogError { 104 class LogError {
103 public: 105 public:
104 LogError(GLES2DemoInstance* demo) : demo_(demo) {} 106 LogError(GLES2DemoInstance* demo) : demo_(demo) {}
105 ~LogError() { 107 ~LogError() {
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after
166 assert((console_if_ = static_cast<const struct PPB_Console_Dev*>( 168 assert((console_if_ = static_cast<const struct PPB_Console_Dev*>(
167 module->GetBrowserInterface(PPB_CONSOLE_DEV_INTERFACE)))); 169 module->GetBrowserInterface(PPB_CONSOLE_DEV_INTERFACE))));
168 assert((core_if_ = static_cast<const struct PPB_Core*>( 170 assert((core_if_ = static_cast<const struct PPB_Core*>(
169 module->GetBrowserInterface(PPB_CORE_INTERFACE)))); 171 module->GetBrowserInterface(PPB_CORE_INTERFACE))));
170 assert((gles2_if_ = static_cast<const struct PPB_OpenGLES2_Dev*>( 172 assert((gles2_if_ = static_cast<const struct PPB_OpenGLES2_Dev*>(
171 module->GetBrowserInterface(PPB_OPENGLES2_DEV_INTERFACE)))); 173 module->GetBrowserInterface(PPB_OPENGLES2_DEV_INTERFACE))));
172 } 174 }
173 175
174 GLES2DemoInstance::~GLES2DemoInstance() { 176 GLES2DemoInstance::~GLES2DemoInstance() {
175 delete video_decoder_; // May be NULL, which is fine. 177 delete video_decoder_; // May be NULL, which is fine.
178 DeleteOutstandingBitstreamBuffers();
179 DeleteOutstandingTextures();
176 delete surface_; 180 delete surface_;
177 delete context_; 181 delete context_;
178 } 182 }
179 183
184 void GLES2DemoInstance::DeleteOutstandingTextures() {
185 for (PictureBufferMap::iterator it = buffers_by_id_.begin();
186 it != buffers_by_id_.end(); ++it) {
187 DeleteTexture(it->second.texture_id);
188 }
189 buffers_by_id_.clear();
190 }
191
192 void GLES2DemoInstance::DeleteOutstandingBitstreamBuffers() {
193 for (BitstreamBufferMap::iterator it = bitstream_buffers_by_id_.begin();
194 it != bitstream_buffers_by_id_.end(); ++it) {
195 delete it->second;
196 }
197 bitstream_buffers_by_id_.clear();
198 }
199
180 void GLES2DemoInstance::DidChangeView( 200 void GLES2DemoInstance::DidChangeView(
181 const pp::Rect& position, const pp::Rect& clip_ignored) { 201 const pp::Rect& position, const pp::Rect& clip_ignored) {
182 if (position.width() == 0 || position.height() == 0) 202 if (position.width() == 0 || position.height() == 0)
183 return; 203 return;
184 if (position_size_.width()) { 204 if (position_size_.width()) {
185 assert(position.size() == position_size_); 205 assert(position.size() == position_size_);
186 return; 206 return;
187 } 207 }
188 position_size_ = position.size(); 208 position_size_ = position.size();
189 209
(...skipping 16 matching lines...) Expand all
206 DecodeNextNALUs(); 226 DecodeNextNALUs();
207 } 227 }
208 228
209 void GLES2DemoInstance::DecoderBitstreamDone( 229 void GLES2DemoInstance::DecoderBitstreamDone(
210 int32_t result, int bitstream_buffer_id) { 230 int32_t result, int bitstream_buffer_id) {
211 assert(bitstream_ids_at_decoder_.erase(bitstream_buffer_id) == 1); 231 assert(bitstream_ids_at_decoder_.erase(bitstream_buffer_id) == 1);
212 BitstreamBufferMap::iterator it = 232 BitstreamBufferMap::iterator it =
213 bitstream_buffers_by_id_.find(bitstream_buffer_id); 233 bitstream_buffers_by_id_.find(bitstream_buffer_id);
214 assert(it != bitstream_buffers_by_id_.end()); 234 assert(it != bitstream_buffers_by_id_.end());
215 delete it->second; 235 delete it->second;
236 bitstream_buffers_by_id_.erase(it);
216 DecodeNextNALUs(); 237 DecodeNextNALUs();
217 } 238 }
218 239
219 void GLES2DemoInstance::DecoderFlushDone(int32_t result) { 240 void GLES2DemoInstance::DecoderFlushDone(int32_t result) {
220 // Check that each bitstream buffer ID we handed to the decoder got handed 241 // Check that each bitstream buffer ID we handed to the decoder got handed
221 // back to us. 242 // back to us.
222 assert(bitstream_ids_at_decoder_.empty()); 243 assert(bitstream_ids_at_decoder_.empty());
223 delete video_decoder_; 244 delete video_decoder_;
224 video_decoder_ = NULL; 245 video_decoder_ = NULL;
225 } 246 }
(...skipping 30 matching lines...) Expand all
256 if (encoded_data_next_pos_to_decode_ == kDataLen) { 277 if (encoded_data_next_pos_to_decode_ == kDataLen) {
257 ++encoded_data_next_pos_to_decode_; 278 ++encoded_data_next_pos_to_decode_;
258 pp::CompletionCallback cb = 279 pp::CompletionCallback cb =
259 callback_factory_.NewCallback(&GLES2DemoInstance::DecoderFlushDone); 280 callback_factory_.NewCallback(&GLES2DemoInstance::DecoderFlushDone);
260 video_decoder_->Flush(cb); 281 video_decoder_->Flush(cb);
261 return; 282 return;
262 } 283 }
263 size_t start_pos = encoded_data_next_pos_to_decode_; 284 size_t start_pos = encoded_data_next_pos_to_decode_;
264 size_t end_pos; 285 size_t end_pos;
265 GetNextNALUBoundary(start_pos, &end_pos); 286 GetNextNALUBoundary(start_pos, &end_pos);
266 pp::Buffer_Dev* buffer = new pp::Buffer_Dev (this, end_pos - start_pos); 287 pp::Buffer_Dev* buffer = new pp::Buffer_Dev(this, end_pos - start_pos);
267 PP_VideoBitstreamBuffer_Dev bitstream_buffer; 288 PP_VideoBitstreamBuffer_Dev bitstream_buffer;
268 int id = ++next_bitstream_buffer_id_; 289 int id = ++next_bitstream_buffer_id_;
269 bitstream_buffer.id = id; 290 bitstream_buffer.id = id;
270 bitstream_buffer.size = end_pos - start_pos; 291 bitstream_buffer.size = end_pos - start_pos;
271 bitstream_buffer.data = buffer->pp_resource(); 292 bitstream_buffer.data = buffer->pp_resource();
272 memcpy(buffer->data(), kData + start_pos, end_pos - start_pos); 293 memcpy(buffer->data(), kData + start_pos, end_pos - start_pos);
273 assert(bitstream_buffers_by_id_.insert(std::make_pair(id, buffer)).second); 294 assert(bitstream_buffers_by_id_.insert(std::make_pair(id, buffer)).second);
274 295
275 pp::CompletionCallback cb = 296 pp::CompletionCallback cb =
276 callback_factory_.NewCallback( 297 callback_factory_.NewCallback(
(...skipping 229 matching lines...) Expand 10 before | Expand all | Expand 10 after
506 gles2_if_->DeleteShader(context_->pp_resource(), shader); 527 gles2_if_->DeleteShader(context_->pp_resource(), shader);
507 } 528 }
508 } // anonymous namespace 529 } // anonymous namespace
509 530
510 namespace pp { 531 namespace pp {
511 // Factory function for your specialization of the Module object. 532 // Factory function for your specialization of the Module object.
512 Module* CreateModule() { 533 Module* CreateModule() {
513 return new GLES2DemoModule(); 534 return new GLES2DemoModule();
514 } 535 }
515 } // namespace pp 536 } // namespace pp
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698