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 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
78 | 78 |
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 PaintStart(const PP_Picture_Dev& picture); |
89 void DeleteOutstandingBitstreamBuffers(); | 89 void DeleteOutstandingBitstreamBuffers(); |
90 | 90 |
91 // GL-related functions. | 91 // GL-related functions. |
92 void InitGL(); | 92 void InitGL(); |
93 GLuint CreateTexture(int32_t width, int32_t height); | 93 GLuint CreateTexture(int32_t width, int32_t height); |
94 void CreateGLObjects(); | 94 void CreateGLObjects(); |
95 void CreateShader(GLuint program, GLenum type, const char* source, int size); | 95 void CreateShader(GLuint program, GLenum type, const char* source, int size); |
96 void DeleteTexture(GLuint id); | 96 void DeleteTexture(GLuint id); |
97 void DeleteOutstandingTextures(); | 97 void DeleteOutstandingTextures(); |
98 void PaintFinished(int32_t result, int picture_buffer_id); | 98 void PaintFinished(int32_t result, int picture_buffer_id); |
(...skipping 218 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
317 assert(decoder == video_decoder_->pp_resource()); | 317 assert(decoder == video_decoder_->pp_resource()); |
318 PictureBufferMap::iterator it = buffers_by_id_.find(picture_buffer_id); | 318 PictureBufferMap::iterator it = buffers_by_id_.find(picture_buffer_id); |
319 assert(it != buffers_by_id_.end()); | 319 assert(it != buffers_by_id_.end()); |
320 DeleteTexture(it->second.texture_id); | 320 DeleteTexture(it->second.texture_id); |
321 buffers_by_id_.erase(it); | 321 buffers_by_id_.erase(it); |
322 } | 322 } |
323 | 323 |
324 void GLES2DemoInstance::PictureReady(PP_Resource decoder, | 324 void GLES2DemoInstance::PictureReady(PP_Resource decoder, |
325 const PP_Picture_Dev& picture) { | 325 const PP_Picture_Dev& picture) { |
326 assert(decoder == video_decoder_->pp_resource()); | 326 assert(decoder == video_decoder_->pp_resource()); |
| 327 PaintStart(picture); |
| 328 } |
| 329 |
| 330 void GLES2DemoInstance::PaintStart(const PP_Picture_Dev& picture) { |
327 if (first_frame_delivered_ticks_ == -1) | 331 if (first_frame_delivered_ticks_ == -1) |
328 assert((first_frame_delivered_ticks_ = core_if_->GetTimeTicks()) != -1); | 332 assert((first_frame_delivered_ticks_ = core_if_->GetTimeTicks()) != -1); |
329 if (is_painting_) { | 333 if (is_painting_) { |
330 pictures_pending_paint_.push_back(picture); | 334 pictures_pending_paint_.push_back(picture); |
331 return; | 335 return; |
332 } | 336 } |
333 PictureBufferMap::iterator it = | 337 PictureBufferMap::iterator it = |
334 buffers_by_id_.find(picture.picture_buffer_id); | 338 buffers_by_id_.find(picture.picture_buffer_id); |
335 assert(it != buffers_by_id_.end()); | 339 assert(it != buffers_by_id_.end()); |
336 Render(it->second); | 340 const PP_PictureBuffer_Dev& buffer = it->second; |
| 341 assert(!is_painting_); |
| 342 is_painting_ = true; |
| 343 gles2_if_->ActiveTexture(context_->pp_resource(), GL_TEXTURE0); |
| 344 gles2_if_->BindTexture( |
| 345 context_->pp_resource(), GL_TEXTURE_2D, buffer.texture_id); |
| 346 gles2_if_->DrawArrays(context_->pp_resource(), GL_TRIANGLE_STRIP, 0, 4); |
| 347 pp::CompletionCallback cb = |
| 348 callback_factory_.NewCallback( |
| 349 &GLES2DemoInstance::PaintFinished, buffer.id); |
| 350 last_swap_request_ticks_ = core_if_->GetTimeTicks(); |
| 351 assert(surface_->SwapBuffers(cb) == PP_OK_COMPLETIONPENDING); |
337 } | 352 } |
338 | 353 |
339 void GLES2DemoInstance::EndOfStream(PP_Resource decoder) { | 354 void GLES2DemoInstance::EndOfStream(PP_Resource decoder) { |
340 assert(decoder == video_decoder_->pp_resource()); | 355 assert(decoder == video_decoder_->pp_resource()); |
341 } | 356 } |
342 | 357 |
343 void GLES2DemoInstance::NotifyError(PP_Resource decoder, | 358 void GLES2DemoInstance::NotifyError(PP_Resource decoder, |
344 PP_VideoDecodeError_Dev error) { | 359 PP_VideoDecodeError_Dev error) { |
345 assert(decoder == video_decoder_->pp_resource()); | 360 assert(decoder == video_decoder_->pp_resource()); |
346 LogError(this).s() << "Received error: " << error; | 361 LogError(this).s() << "Received error: " << error; |
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
381 gles2_if_->Clear(context_->pp_resource(), GL_COLOR_BUFFER_BIT); | 396 gles2_if_->Clear(context_->pp_resource(), GL_COLOR_BUFFER_BIT); |
382 gles2_if_->Viewport(context_->pp_resource(), 0, 0, | 397 gles2_if_->Viewport(context_->pp_resource(), 0, 0, |
383 position_size_.width(), position_size_.height()); | 398 position_size_.width(), position_size_.height()); |
384 | 399 |
385 assert(BindGraphics(*surface_)); | 400 assert(BindGraphics(*surface_)); |
386 assertNoGLError(); | 401 assertNoGLError(); |
387 | 402 |
388 CreateGLObjects(); | 403 CreateGLObjects(); |
389 } | 404 } |
390 | 405 |
391 void GLES2DemoInstance::Render(const PP_PictureBuffer_Dev& buffer) { | |
392 assert(!is_painting_); | |
393 is_painting_ = true; | |
394 gles2_if_->ActiveTexture(context_->pp_resource(), GL_TEXTURE0); | |
395 gles2_if_->BindTexture( | |
396 context_->pp_resource(), GL_TEXTURE_2D, buffer.texture_id); | |
397 gles2_if_->DrawArrays(context_->pp_resource(), GL_TRIANGLE_STRIP, 0, 4); | |
398 pp::CompletionCallback cb = | |
399 callback_factory_.NewCallback( | |
400 &GLES2DemoInstance::PaintFinished, buffer.id); | |
401 last_swap_request_ticks_ = core_if_->GetTimeTicks(); | |
402 assert(surface_->SwapBuffers(cb) == PP_OK_COMPLETIONPENDING); | |
403 } | |
404 | |
405 void GLES2DemoInstance::PaintFinished(int32_t result, int picture_buffer_id) { | 406 void GLES2DemoInstance::PaintFinished(int32_t result, int picture_buffer_id) { |
406 swap_ticks_ += core_if_->GetTimeTicks() - last_swap_request_ticks_; | 407 swap_ticks_ += core_if_->GetTimeTicks() - last_swap_request_ticks_; |
407 is_painting_ = false; | 408 is_painting_ = false; |
408 ++num_frames_rendered_; | 409 ++num_frames_rendered_; |
409 if (num_frames_rendered_ % 50 == 0) { | 410 if (num_frames_rendered_ % 50 == 0) { |
410 double elapsed = core_if_->GetTimeTicks() - first_frame_delivered_ticks_; | 411 double elapsed = core_if_->GetTimeTicks() - first_frame_delivered_ticks_; |
411 double fps = (elapsed > 0) ? num_frames_rendered_ / elapsed : 1000; | 412 double fps = (elapsed > 0) ? num_frames_rendered_ / elapsed : 1000; |
412 double ms_per_swap = (swap_ticks_ * 1e3) / num_frames_rendered_; | 413 double ms_per_swap = (swap_ticks_ * 1e3) / num_frames_rendered_; |
413 LogError(this).s() << "Rendered frames: " << num_frames_rendered_ | 414 LogError(this).s() << "Rendered frames: " << num_frames_rendered_ |
414 << ", fps: " << fps << ", with average ms/swap of: " | 415 << ", fps: " << fps << ", with average ms/swap of: " |
415 << ms_per_swap; | 416 << ms_per_swap; |
416 } | 417 } |
417 if (video_decoder_) | 418 if (video_decoder_) |
418 video_decoder_->ReusePictureBuffer(picture_buffer_id); | 419 video_decoder_->ReusePictureBuffer(picture_buffer_id); |
419 while (!pictures_pending_paint_.empty() && !is_painting_) { | 420 if (!pictures_pending_paint_.empty()) { |
420 PP_Picture_Dev picture = pictures_pending_paint_.front(); | 421 PP_Picture_Dev picture = pictures_pending_paint_.front(); |
421 pictures_pending_paint_.pop_front(); | 422 pictures_pending_paint_.pop_front(); |
422 PictureReady(video_decoder_->pp_resource(), picture); | 423 PaintStart(picture); |
423 } | 424 } |
424 } | 425 } |
425 | 426 |
426 GLuint GLES2DemoInstance::CreateTexture(int32_t width, int32_t height) { | 427 GLuint GLES2DemoInstance::CreateTexture(int32_t width, int32_t height) { |
427 GLuint texture_id; | 428 GLuint texture_id; |
428 gles2_if_->GenTextures(context_->pp_resource(), 1, &texture_id); | 429 gles2_if_->GenTextures(context_->pp_resource(), 1, &texture_id); |
429 assertNoGLError(); | 430 assertNoGLError(); |
430 // Assign parameters. | 431 // Assign parameters. |
431 gles2_if_->ActiveTexture(context_->pp_resource(), GL_TEXTURE0); | 432 gles2_if_->ActiveTexture(context_->pp_resource(), GL_TEXTURE0); |
432 gles2_if_->BindTexture( | 433 gles2_if_->BindTexture( |
(...skipping 95 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
528 gles2_if_->DeleteShader(context_->pp_resource(), shader); | 529 gles2_if_->DeleteShader(context_->pp_resource(), shader); |
529 } | 530 } |
530 } // anonymous namespace | 531 } // anonymous namespace |
531 | 532 |
532 namespace pp { | 533 namespace pp { |
533 // Factory function for your specialization of the Module object. | 534 // Factory function for your specialization of the Module object. |
534 Module* CreateModule() { | 535 Module* CreateModule() { |
535 return new GLES2DemoModule(); | 536 return new GLES2DemoModule(); |
536 } | 537 } |
537 } // namespace pp | 538 } // namespace pp |
OLD | NEW |