| OLD | NEW |
| 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 280 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 291 | 291 |
| 292 pp::CompletionCallback cb = | 292 pp::CompletionCallback cb = |
| 293 callback_factory_.NewCallback( | 293 callback_factory_.NewCallback( |
| 294 &GLES2DemoInstance::DecoderBitstreamDone, id); | 294 &GLES2DemoInstance::DecoderBitstreamDone, id); |
| 295 assert(bitstream_ids_at_decoder_.insert(id).second); | 295 assert(bitstream_ids_at_decoder_.insert(id).second); |
| 296 video_decoder_->Decode(bitstream_buffer, cb); | 296 video_decoder_->Decode(bitstream_buffer, cb); |
| 297 encoded_data_next_pos_to_decode_ = end_pos; | 297 encoded_data_next_pos_to_decode_ = end_pos; |
| 298 } | 298 } |
| 299 | 299 |
| 300 void GLES2DemoInstance::ProvidePictureBuffers( | 300 void GLES2DemoInstance::ProvidePictureBuffers( |
| 301 PP_Resource /* decoder */, uint32_t req_num_of_bufs, PP_Size dimensions) { | 301 PP_Resource decoder, uint32_t req_num_of_bufs, PP_Size dimensions) { |
| 302 assert(decoder == video_decoder_->pp_resource()); |
| 302 std::vector<PP_PictureBuffer_Dev> buffers; | 303 std::vector<PP_PictureBuffer_Dev> buffers; |
| 303 for (uint32_t i = 0; i < req_num_of_bufs; i++) { | 304 for (uint32_t i = 0; i < req_num_of_bufs; i++) { |
| 304 PP_PictureBuffer_Dev buffer; | 305 PP_PictureBuffer_Dev buffer; |
| 305 buffer.texture_id = CreateTexture(dimensions.width, dimensions.height); | 306 buffer.texture_id = CreateTexture(dimensions.width, dimensions.height); |
| 306 int id = ++next_picture_buffer_id_; | 307 int id = ++next_picture_buffer_id_; |
| 307 buffer.id = id; | 308 buffer.id = id; |
| 308 buffers.push_back(buffer); | 309 buffers.push_back(buffer); |
| 309 assert(buffers_by_id_.insert(std::make_pair(id, buffer)).second); | 310 assert(buffers_by_id_.insert(std::make_pair(id, buffer)).second); |
| 310 } | 311 } |
| 311 video_decoder_->AssignPictureBuffers(buffers); | 312 video_decoder_->AssignPictureBuffers(buffers); |
| 312 } | 313 } |
| 313 | 314 |
| 314 void GLES2DemoInstance::DismissPictureBuffer(PP_Resource /* decoder */, | 315 void GLES2DemoInstance::DismissPictureBuffer(PP_Resource decoder, |
| 315 int32_t picture_buffer_id) { | 316 int32_t picture_buffer_id) { |
| 317 assert(decoder == video_decoder_->pp_resource()); |
| 316 PictureBufferMap::iterator it = buffers_by_id_.find(picture_buffer_id); | 318 PictureBufferMap::iterator it = buffers_by_id_.find(picture_buffer_id); |
| 317 assert(it != buffers_by_id_.end()); | 319 assert(it != buffers_by_id_.end()); |
| 318 DeleteTexture(it->second.texture_id); | 320 DeleteTexture(it->second.texture_id); |
| 319 buffers_by_id_.erase(it); | 321 buffers_by_id_.erase(it); |
| 320 } | 322 } |
| 321 | 323 |
| 322 void GLES2DemoInstance::PictureReady(PP_Resource /* decoder */, | 324 void GLES2DemoInstance::PictureReady(PP_Resource decoder, |
| 323 const PP_Picture_Dev& picture) { | 325 const PP_Picture_Dev& picture) { |
| 326 assert(decoder == video_decoder_->pp_resource()); |
| 324 if (first_frame_delivered_ticks_ == -1) | 327 if (first_frame_delivered_ticks_ == -1) |
| 325 assert((first_frame_delivered_ticks_ = core_if_->GetTimeTicks()) != -1); | 328 assert((first_frame_delivered_ticks_ = core_if_->GetTimeTicks()) != -1); |
| 326 if (is_painting_) { | 329 if (is_painting_) { |
| 327 pictures_pending_paint_.push_back(picture); | 330 pictures_pending_paint_.push_back(picture); |
| 328 return; | 331 return; |
| 329 } | 332 } |
| 330 PictureBufferMap::iterator it = | 333 PictureBufferMap::iterator it = |
| 331 buffers_by_id_.find(picture.picture_buffer_id); | 334 buffers_by_id_.find(picture.picture_buffer_id); |
| 332 assert(it != buffers_by_id_.end()); | 335 assert(it != buffers_by_id_.end()); |
| 333 Render(it->second); | 336 Render(it->second); |
| 334 } | 337 } |
| 335 | 338 |
| 336 void GLES2DemoInstance::EndOfStream(PP_Resource /* decoder */) { | 339 void GLES2DemoInstance::EndOfStream(PP_Resource decoder) { |
| 340 assert(decoder == video_decoder_->pp_resource()); |
| 337 } | 341 } |
| 338 | 342 |
| 339 void GLES2DemoInstance::NotifyError(PP_Resource /* decoder */, | 343 void GLES2DemoInstance::NotifyError(PP_Resource decoder, |
| 340 PP_VideoDecodeError_Dev error) { | 344 PP_VideoDecodeError_Dev error) { |
| 345 assert(decoder == video_decoder_->pp_resource()); |
| 341 LogError(this).s() << "Received error: " << error; | 346 LogError(this).s() << "Received error: " << error; |
| 342 assert(!"Unexpected error; see stderr for details"); | 347 assert(!"Unexpected error; see stderr for details"); |
| 343 } | 348 } |
| 344 | 349 |
| 345 // This object is the global object representing this plugin library as long | 350 // This object is the global object representing this plugin library as long |
| 346 // as it is loaded. | 351 // as it is loaded. |
| 347 class GLES2DemoModule : public pp::Module { | 352 class GLES2DemoModule : public pp::Module { |
| 348 public: | 353 public: |
| 349 GLES2DemoModule() : pp::Module() {} | 354 GLES2DemoModule() : pp::Module() {} |
| 350 virtual ~GLES2DemoModule() {} | 355 virtual ~GLES2DemoModule() {} |
| (...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 407 double ms_per_swap = (swap_ticks_ * 1e3) / num_frames_rendered_; | 412 double ms_per_swap = (swap_ticks_ * 1e3) / num_frames_rendered_; |
| 408 LogError(this).s() << "Rendered frames: " << num_frames_rendered_ | 413 LogError(this).s() << "Rendered frames: " << num_frames_rendered_ |
| 409 << ", fps: " << fps << ", with average ms/swap of: " | 414 << ", fps: " << fps << ", with average ms/swap of: " |
| 410 << ms_per_swap; | 415 << ms_per_swap; |
| 411 } | 416 } |
| 412 if (video_decoder_) | 417 if (video_decoder_) |
| 413 video_decoder_->ReusePictureBuffer(picture_buffer_id); | 418 video_decoder_->ReusePictureBuffer(picture_buffer_id); |
| 414 while (!pictures_pending_paint_.empty() && !is_painting_) { | 419 while (!pictures_pending_paint_.empty() && !is_painting_) { |
| 415 PP_Picture_Dev picture = pictures_pending_paint_.front(); | 420 PP_Picture_Dev picture = pictures_pending_paint_.front(); |
| 416 pictures_pending_paint_.pop_front(); | 421 pictures_pending_paint_.pop_front(); |
| 417 PictureReady(0 /* ignored */, picture); | 422 PictureReady(video_decoder_->pp_resource(), picture); |
| 418 } | 423 } |
| 419 } | 424 } |
| 420 | 425 |
| 421 GLuint GLES2DemoInstance::CreateTexture(int32_t width, int32_t height) { | 426 GLuint GLES2DemoInstance::CreateTexture(int32_t width, int32_t height) { |
| 422 GLuint texture_id; | 427 GLuint texture_id; |
| 423 gles2_if_->GenTextures(context_->pp_resource(), 1, &texture_id); | 428 gles2_if_->GenTextures(context_->pp_resource(), 1, &texture_id); |
| 424 assertNoGLError(); | 429 assertNoGLError(); |
| 425 // Assign parameters. | 430 // Assign parameters. |
| 426 gles2_if_->ActiveTexture(context_->pp_resource(), GL_TEXTURE0); | 431 gles2_if_->ActiveTexture(context_->pp_resource(), GL_TEXTURE0); |
| 427 gles2_if_->BindTexture( | 432 gles2_if_->BindTexture( |
| (...skipping 95 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 523 gles2_if_->DeleteShader(context_->pp_resource(), shader); | 528 gles2_if_->DeleteShader(context_->pp_resource(), shader); |
| 524 } | 529 } |
| 525 } // anonymous namespace | 530 } // anonymous namespace |
| 526 | 531 |
| 527 namespace pp { | 532 namespace pp { |
| 528 // Factory function for your specialization of the Module object. | 533 // Factory function for your specialization of the Module object. |
| 529 Module* CreateModule() { | 534 Module* CreateModule() { |
| 530 return new GLES2DemoModule(); | 535 return new GLES2DemoModule(); |
| 531 } | 536 } |
| 532 } // namespace pp | 537 } // namespace pp |
| OLD | NEW |