OLD | NEW |
1 // Copyright (c) 2014 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2014 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 <GLES2/gl2.h> | 5 #include <GLES2/gl2.h> |
6 #include <GLES2/gl2ext.h> | 6 #include <GLES2/gl2ext.h> |
7 #include <stdio.h> | 7 #include <stdio.h> |
8 #include <string.h> | 8 #include <string.h> |
9 | 9 |
10 #include <iostream> | 10 #include <iostream> |
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
46 ~Shader() {} | 46 ~Shader() {} |
47 | 47 |
48 GLuint program; | 48 GLuint program; |
49 GLint texcoord_scale_location; | 49 GLint texcoord_scale_location; |
50 }; | 50 }; |
51 | 51 |
52 class Decoder; | 52 class Decoder; |
53 class MyInstance; | 53 class MyInstance; |
54 | 54 |
55 struct PendingPicture { | 55 struct PendingPicture { |
56 PendingPicture(Decoder* decoder, const PP_VideoPicture& picture) | 56 PendingPicture(Decoder* decoder, |
57 : decoder(decoder), picture(picture) {} | 57 const PP_VideoPicture& picture, |
| 58 const PP_Rect& visible_rect) |
| 59 : decoder(decoder), picture(picture), visible_rect(visible_rect) {} |
58 ~PendingPicture() {} | 60 ~PendingPicture() {} |
59 | 61 |
60 Decoder* decoder; | 62 Decoder* decoder; |
61 PP_VideoPicture picture; | 63 PP_VideoPicture picture; |
| 64 PP_Rect visible_rect; |
62 }; | 65 }; |
63 | 66 |
64 class MyInstance : public pp::Instance, public pp::Graphics3DClient { | 67 class MyInstance : public pp::Instance, public pp::Graphics3DClient { |
65 public: | 68 public: |
66 MyInstance(PP_Instance instance, pp::Module* module); | 69 MyInstance(PP_Instance instance, pp::Module* module); |
67 virtual ~MyInstance(); | 70 virtual ~MyInstance(); |
68 | 71 |
69 // pp::Instance implementation. | 72 // pp::Instance implementation. |
70 virtual void DidChangeView(const pp::Rect& position, | 73 virtual void DidChangeView(const pp::Rect& position, |
71 const pp::Rect& clip_ignored); | 74 const pp::Rect& clip_ignored); |
72 virtual bool HandleInputEvent(const pp::InputEvent& event); | 75 virtual bool HandleInputEvent(const pp::InputEvent& event); |
73 | 76 |
74 // pp::Graphics3DClient implementation. | 77 // pp::Graphics3DClient implementation. |
75 virtual void Graphics3DContextLost() { | 78 virtual void Graphics3DContextLost() { |
76 // TODO(vrk/fischman): Properly reset after a lost graphics context. In | 79 // TODO(vrk/fischman): Properly reset after a lost graphics context. In |
77 // particular need to delete context_ and re-create textures. | 80 // particular need to delete context_ and re-create textures. |
78 // Probably have to recreate the decoder from scratch, because old textures | 81 // Probably have to recreate the decoder from scratch, because old textures |
79 // can still be outstanding in the decoder! | 82 // can still be outstanding in the decoder! |
80 assert(false && "Unexpectedly lost graphics context"); | 83 assert(false && "Unexpectedly lost graphics context"); |
81 } | 84 } |
82 | 85 |
83 void PaintPicture(Decoder* decoder, const PP_VideoPicture& picture); | 86 void PaintPicture(Decoder* decoder, |
| 87 const PP_VideoPicture& picture, |
| 88 const PP_Rect& visible_rect); |
84 | 89 |
85 private: | 90 private: |
86 // Log an error to the developer console and stderr by creating a temporary | 91 // Log an error to the developer console and stderr by creating a temporary |
87 // object of this type and streaming to it. Example usage: | 92 // object of this type and streaming to it. Example usage: |
88 // LogError(this).s() << "Hello world: " << 42; | 93 // LogError(this).s() << "Hello world: " << 42; |
89 class LogError { | 94 class LogError { |
90 public: | 95 public: |
91 LogError(MyInstance* instance) : instance_(instance) {} | 96 LogError(MyInstance* instance) : instance_(instance) {} |
92 ~LogError() { | 97 ~LogError() { |
93 const std::string& msg = stream_.str(); | 98 const std::string& msg = stream_.str(); |
(...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
172 void DecodeDone(int32_t result); | 177 void DecodeDone(int32_t result); |
173 void PictureReady(int32_t result, PP_VideoPicture picture); | 178 void PictureReady(int32_t result, PP_VideoPicture picture); |
174 void FlushDone(int32_t result); | 179 void FlushDone(int32_t result); |
175 void ResetDone(int32_t result); | 180 void ResetDone(int32_t result); |
176 | 181 |
177 MyInstance* instance_; | 182 MyInstance* instance_; |
178 int id_; | 183 int id_; |
179 | 184 |
180 pp::VideoDecoder* decoder_; | 185 pp::VideoDecoder* decoder_; |
181 pp::CompletionCallbackFactory<Decoder> callback_factory_; | 186 pp::CompletionCallbackFactory<Decoder> callback_factory_; |
| 187 PP_Rect picture_visible_rect_; |
182 | 188 |
183 size_t encoded_data_next_pos_to_decode_; | 189 size_t encoded_data_next_pos_to_decode_; |
184 int next_picture_id_; | 190 int next_picture_id_; |
185 bool flushing_; | 191 bool flushing_; |
186 bool resetting_; | 192 bool resetting_; |
187 | 193 |
188 const PPB_Core* core_if_; | 194 const PPB_Core* core_if_; |
189 static const int kMaxDecodeDelay = 128; | 195 static const int kMaxDecodeDelay = 128; |
190 PP_TimeTicks decode_time_[kMaxDecodeDelay]; | 196 PP_TimeTicks decode_time_[kMaxDecodeDelay]; |
191 PP_TimeTicks total_latency_; | 197 PP_TimeTicks total_latency_; |
(...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
269 } | 275 } |
270 | 276 |
271 void Decoder::Start() { | 277 void Decoder::Start() { |
272 assert(decoder_); | 278 assert(decoder_); |
273 | 279 |
274 encoded_data_next_pos_to_decode_ = 0; | 280 encoded_data_next_pos_to_decode_ = 0; |
275 | 281 |
276 // Register callback to get the first picture. We call GetPicture again in | 282 // Register callback to get the first picture. We call GetPicture again in |
277 // PictureReady to continuously receive pictures as they're decoded. | 283 // PictureReady to continuously receive pictures as they're decoded. |
278 decoder_->GetPicture( | 284 decoder_->GetPicture( |
| 285 &picture_visible_rect_, |
279 callback_factory_.NewCallbackWithOutput(&Decoder::PictureReady)); | 286 callback_factory_.NewCallbackWithOutput(&Decoder::PictureReady)); |
280 | 287 |
281 // Start the decode loop. | 288 // Start the decode loop. |
282 DecodeNextFrame(); | 289 DecodeNextFrame(); |
283 } | 290 } |
284 | 291 |
285 void Decoder::Reset() { | 292 void Decoder::Reset() { |
286 assert(decoder_); | 293 assert(decoder_); |
287 assert(!resetting_); | 294 assert(!resetting_); |
288 resetting_ = true; | 295 resetting_ = true; |
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
335 // Break out of the get picture loop on abort. | 342 // Break out of the get picture loop on abort. |
336 if (result == PP_ERROR_ABORTED) | 343 if (result == PP_ERROR_ABORTED) |
337 return; | 344 return; |
338 assert(result == PP_OK); | 345 assert(result == PP_OK); |
339 | 346 |
340 num_pictures_++; | 347 num_pictures_++; |
341 PP_TimeTicks latency = core_if_->GetTimeTicks() - | 348 PP_TimeTicks latency = core_if_->GetTimeTicks() - |
342 decode_time_[picture.decode_id % kMaxDecodeDelay]; | 349 decode_time_[picture.decode_id % kMaxDecodeDelay]; |
343 total_latency_ += latency; | 350 total_latency_ += latency; |
344 | 351 |
| 352 PP_Rect visible_rect = picture_visible_rect_; |
345 decoder_->GetPicture( | 353 decoder_->GetPicture( |
| 354 &picture_visible_rect_, |
346 callback_factory_.NewCallbackWithOutput(&Decoder::PictureReady)); | 355 callback_factory_.NewCallbackWithOutput(&Decoder::PictureReady)); |
347 instance_->PaintPicture(this, picture); | 356 instance_->PaintPicture(this, picture, visible_rect); |
348 } | 357 } |
349 | 358 |
350 void Decoder::FlushDone(int32_t result) { | 359 void Decoder::FlushDone(int32_t result) { |
351 assert(decoder_); | 360 assert(decoder_); |
352 assert(result == PP_OK || result == PP_ERROR_ABORTED); | 361 assert(result == PP_OK || result == PP_ERROR_ABORTED); |
353 assert(flushing_); | 362 assert(flushing_); |
354 flushing_ = false; | 363 flushing_ = false; |
355 } | 364 } |
356 | 365 |
357 void Decoder::ResetDone(int32_t result) { | 366 void Decoder::ResetDone(int32_t result) { |
(...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
439 } | 448 } |
440 | 449 |
441 void MyInstance::InitializeDecoders() { | 450 void MyInstance::InitializeDecoders() { |
442 assert(video_decoders_.empty()); | 451 assert(video_decoders_.empty()); |
443 // Create two decoders with ids 0 and 1. | 452 // Create two decoders with ids 0 and 1. |
444 video_decoders_.push_back(new Decoder(this, 0, *context_)); | 453 video_decoders_.push_back(new Decoder(this, 0, *context_)); |
445 video_decoders_.push_back(new Decoder(this, 1, *context_)); | 454 video_decoders_.push_back(new Decoder(this, 1, *context_)); |
446 } | 455 } |
447 | 456 |
448 void MyInstance::PaintPicture(Decoder* decoder, | 457 void MyInstance::PaintPicture(Decoder* decoder, |
449 const PP_VideoPicture& picture) { | 458 const PP_VideoPicture& picture, |
| 459 const PP_Rect& visible_rect) { |
450 if (first_frame_delivered_ticks_ == -1) | 460 if (first_frame_delivered_ticks_ == -1) |
451 assert((first_frame_delivered_ticks_ = core_if_->GetTimeTicks()) != -1); | 461 assert((first_frame_delivered_ticks_ = core_if_->GetTimeTicks()) != -1); |
452 | 462 |
453 pending_pictures_.push(PendingPicture(decoder, picture)); | 463 pending_pictures_.push(PendingPicture(decoder, picture, visible_rect)); |
454 if (!is_painting_) | 464 if (!is_painting_) |
455 PaintNextPicture(); | 465 PaintNextPicture(); |
456 } | 466 } |
457 | 467 |
458 void MyInstance::PaintNextPicture() { | 468 void MyInstance::PaintNextPicture() { |
459 assert(!is_painting_); | 469 assert(!is_painting_); |
460 is_painting_ = true; | 470 is_painting_ = true; |
461 | 471 |
462 const PendingPicture& next = pending_pictures_.front(); | 472 const PendingPicture& next = pending_pictures_.front(); |
463 Decoder* decoder = next.decoder; | 473 Decoder* decoder = next.decoder; |
(...skipping 262 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
726 }; | 736 }; |
727 | 737 |
728 } // anonymous namespace | 738 } // anonymous namespace |
729 | 739 |
730 namespace pp { | 740 namespace pp { |
731 // Factory function for your specialization of the Module object. | 741 // Factory function for your specialization of the Module object. |
732 Module* CreateModule() { | 742 Module* CreateModule() { |
733 return new MyModule(); | 743 return new MyModule(); |
734 } | 744 } |
735 } // namespace pp | 745 } // namespace pp |
OLD | NEW |