OLD | NEW |
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 #include "ppapi/proxy/video_decoder_resource.h" | 5 #include "ppapi/proxy/video_decoder_resource.h" |
6 | 6 |
7 #include "base/bind.h" | 7 #include "base/bind.h" |
8 #include "gpu/command_buffer/client/gles2_cmd_helper.h" | 8 #include "gpu/command_buffer/client/gles2_cmd_helper.h" |
9 #include "gpu/command_buffer/client/gles2_implementation.h" | 9 #include "gpu/command_buffer/client/gles2_implementation.h" |
10 #include "gpu/command_buffer/common/mailbox.h" | 10 #include "gpu/command_buffer/common/mailbox.h" |
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
42 } | 42 } |
43 | 43 |
44 VideoDecoderResource::Texture::Texture(uint32_t texture_target, | 44 VideoDecoderResource::Texture::Texture(uint32_t texture_target, |
45 const PP_Size& size) | 45 const PP_Size& size) |
46 : texture_target(texture_target), size(size) { | 46 : texture_target(texture_target), size(size) { |
47 } | 47 } |
48 | 48 |
49 VideoDecoderResource::Texture::~Texture() { | 49 VideoDecoderResource::Texture::~Texture() { |
50 } | 50 } |
51 | 51 |
52 VideoDecoderResource::Picture::Picture(int32_t decode_id, uint32_t texture_id) | 52 VideoDecoderResource::Picture::Picture(int32_t decode_id, |
53 : decode_id(decode_id), texture_id(texture_id) { | 53 uint32_t texture_id, |
| 54 const PP_Rect& visible_rect) |
| 55 : decode_id(decode_id), texture_id(texture_id), visible_rect(visible_rect) { |
54 } | 56 } |
55 | 57 |
56 VideoDecoderResource::Picture::~Picture() { | 58 VideoDecoderResource::Picture::~Picture() { |
57 } | 59 } |
58 | 60 |
59 VideoDecoderResource::VideoDecoderResource(Connection connection, | 61 VideoDecoderResource::VideoDecoderResource(Connection connection, |
60 PP_Instance instance) | 62 PP_Instance instance) |
61 : PluginResource(connection, instance), | 63 : PluginResource(connection, instance), |
62 num_decodes_(0), | 64 num_decodes_(0), |
63 get_picture_(NULL), | 65 get_picture_(NULL), |
| 66 get_visible_rect_(NULL), |
64 gles2_impl_(NULL), | 67 gles2_impl_(NULL), |
65 initialized_(false), | 68 initialized_(false), |
66 testing_(false), | 69 testing_(false), |
67 // Set |decoder_last_error_| to PP_OK after successful initialization. | 70 // Set |decoder_last_error_| to PP_OK after successful initialization. |
68 // This makes error checking a little more concise, since we can check | 71 // This makes error checking a little more concise, since we can check |
69 // that the decoder has been initialized and hasn't returned an error by | 72 // that the decoder has been initialized and hasn't returned an error by |
70 // just testing |decoder_last_error_|. | 73 // just testing |decoder_last_error_|. |
71 decoder_last_error_(PP_ERROR_FAILED) { | 74 decoder_last_error_(PP_ERROR_FAILED) { |
72 // Clear the decode_ids_ array. | 75 // Clear the decode_ids_ array. |
73 memset(decode_ids_, 0, arraysize(decode_ids_)); | 76 memset(decode_ids_, 0, arraysize(decode_ids_)); |
(...skipping 168 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
242 if (!available_shm_buffers_.empty() || | 245 if (!available_shm_buffers_.empty() || |
243 shm_buffers_.size() < kMaximumPendingDecodes) | 246 shm_buffers_.size() < kMaximumPendingDecodes) |
244 return PP_OK; | 247 return PP_OK; |
245 | 248 |
246 // All buffers are busy and we can't create more. Delay completion until a | 249 // All buffers are busy and we can't create more. Delay completion until a |
247 // buffer is available. | 250 // buffer is available. |
248 decode_callback_ = callback; | 251 decode_callback_ = callback; |
249 return PP_OK_COMPLETIONPENDING; | 252 return PP_OK_COMPLETIONPENDING; |
250 } | 253 } |
251 | 254 |
| 255 int32_t VideoDecoderResource::GetPicture0_1( |
| 256 PP_VideoPicture* picture, |
| 257 scoped_refptr<TrackedCallback> callback) { |
| 258 return GetPicture(picture, NULL, callback); |
| 259 } |
| 260 |
252 int32_t VideoDecoderResource::GetPicture( | 261 int32_t VideoDecoderResource::GetPicture( |
253 PP_VideoPicture* picture, | 262 PP_VideoPicture* picture, |
| 263 PP_Rect* visible_rect, |
254 scoped_refptr<TrackedCallback> callback) { | 264 scoped_refptr<TrackedCallback> callback) { |
255 if (decoder_last_error_) | 265 if (decoder_last_error_) |
256 return decoder_last_error_; | 266 return decoder_last_error_; |
257 if (reset_callback_.get()) | 267 if (reset_callback_.get()) |
258 return PP_ERROR_FAILED; | 268 return PP_ERROR_FAILED; |
259 if (get_picture_callback_.get()) | 269 if (get_picture_callback_.get()) |
260 return PP_ERROR_INPROGRESS; | 270 return PP_ERROR_INPROGRESS; |
261 | 271 |
| 272 get_picture_ = picture; |
| 273 get_visible_rect_ = visible_rect; |
| 274 |
262 // If the next picture is ready, return it synchronously. | 275 // If the next picture is ready, return it synchronously. |
263 if (!received_pictures_.empty()) { | 276 if (!received_pictures_.empty()) { |
264 WriteNextPicture(picture); | 277 WriteNextPicture(); |
265 return PP_OK; | 278 return PP_OK; |
266 } | 279 } |
267 | 280 |
268 get_picture_callback_ = callback; | 281 get_picture_callback_ = callback; |
269 get_picture_ = picture; | 282 |
270 return PP_OK_COMPLETIONPENDING; | 283 return PP_OK_COMPLETIONPENDING; |
271 } | 284 } |
272 | 285 |
273 void VideoDecoderResource::RecyclePicture(const PP_VideoPicture* picture) { | 286 void VideoDecoderResource::RecyclePicture(const PP_VideoPicture* picture) { |
274 if (decoder_last_error_) | 287 if (decoder_last_error_) |
275 return; | 288 return; |
276 | 289 |
277 Post(RENDERER, PpapiHostMsg_VideoDecoder_RecyclePicture(picture->texture_id)); | 290 Post(RENDERER, PpapiHostMsg_VideoDecoder_RecyclePicture(picture->texture_id)); |
278 } | 291 } |
279 | 292 |
(...skipping 112 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
392 std::make_pair(texture_ids[i], Texture(texture_target, size))); | 405 std::make_pair(texture_ids[i], Texture(texture_target, size))); |
393 } | 406 } |
394 } | 407 } |
395 | 408 |
396 Post(RENDERER, PpapiHostMsg_VideoDecoder_AssignTextures(size, texture_ids)); | 409 Post(RENDERER, PpapiHostMsg_VideoDecoder_AssignTextures(size, texture_ids)); |
397 } | 410 } |
398 | 411 |
399 void VideoDecoderResource::OnPluginMsgPictureReady( | 412 void VideoDecoderResource::OnPluginMsgPictureReady( |
400 const ResourceMessageReplyParams& params, | 413 const ResourceMessageReplyParams& params, |
401 int32_t decode_id, | 414 int32_t decode_id, |
402 uint32_t texture_id) { | 415 uint32_t texture_id, |
403 received_pictures_.push(Picture(decode_id, texture_id)); | 416 const PP_Rect& visible_rect) { |
| 417 received_pictures_.push(Picture(decode_id, texture_id, visible_rect)); |
404 | 418 |
405 if (TrackedCallback::IsPending(get_picture_callback_)) { | 419 if (TrackedCallback::IsPending(get_picture_callback_)) { |
406 // The plugin may call GetPicture in its callback. | 420 // The plugin may call GetPicture in its callback. |
407 scoped_refptr<TrackedCallback> callback; | 421 scoped_refptr<TrackedCallback> callback; |
408 callback.swap(get_picture_callback_); | 422 callback.swap(get_picture_callback_); |
409 PP_VideoPicture* picture = get_picture_; | 423 WriteNextPicture(); |
410 get_picture_ = NULL; | |
411 WriteNextPicture(picture); | |
412 callback->Run(PP_OK); | 424 callback->Run(PP_OK); |
413 } | 425 } |
414 } | 426 } |
415 | 427 |
416 void VideoDecoderResource::OnPluginMsgDismissPicture( | 428 void VideoDecoderResource::OnPluginMsgDismissPicture( |
417 const ResourceMessageReplyParams& params, | 429 const ResourceMessageReplyParams& params, |
418 uint32_t texture_id) { | 430 uint32_t texture_id) { |
419 DeleteGLTexture(texture_id); | 431 DeleteGLTexture(texture_id); |
420 textures_.erase(texture_id); | 432 textures_.erase(texture_id); |
421 } | 433 } |
(...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
503 } | 515 } |
504 } | 516 } |
505 | 517 |
506 void VideoDecoderResource::DeleteGLTexture(uint32_t id) { | 518 void VideoDecoderResource::DeleteGLTexture(uint32_t id) { |
507 if (gles2_impl_) { | 519 if (gles2_impl_) { |
508 gles2_impl_->DeleteTextures(1, &id); | 520 gles2_impl_->DeleteTextures(1, &id); |
509 gles2_impl_->Flush(); | 521 gles2_impl_->Flush(); |
510 } | 522 } |
511 } | 523 } |
512 | 524 |
513 void VideoDecoderResource::WriteNextPicture(PP_VideoPicture* pp_picture) { | 525 void VideoDecoderResource::WriteNextPicture() { |
514 DCHECK(!received_pictures_.empty()); | 526 DCHECK(!received_pictures_.empty()); |
515 Picture& picture = received_pictures_.front(); | 527 Picture& picture = received_pictures_.front(); |
| 528 |
516 // Internally, we identify decodes by a unique id, which the host returns | 529 // Internally, we identify decodes by a unique id, which the host returns |
517 // to us in the picture. Use this to get the plugin's decode_id. | 530 // to us in the picture. Use this to get the plugin's decode_id. |
518 pp_picture->decode_id = decode_ids_[picture.decode_id % kMaximumPictureDelay]; | 531 get_picture_->decode_id = |
519 pp_picture->texture_id = picture.texture_id; | 532 decode_ids_[picture.decode_id % kMaximumPictureDelay]; |
| 533 get_picture_->texture_id = picture.texture_id; |
520 TextureMap::iterator it = textures_.find(picture.texture_id); | 534 TextureMap::iterator it = textures_.find(picture.texture_id); |
521 if (it != textures_.end()) { | 535 if (it != textures_.end()) { |
522 pp_picture->texture_target = it->second.texture_target; | 536 get_picture_->texture_target = it->second.texture_target; |
523 pp_picture->texture_size = it->second.size; | 537 get_picture_->texture_size = it->second.size; |
524 } else { | 538 } else { |
525 NOTREACHED(); | 539 NOTREACHED(); |
526 } | 540 } |
| 541 |
| 542 if (get_visible_rect_) |
| 543 *get_visible_rect_ = picture.visible_rect; |
| 544 |
| 545 get_picture_ = NULL; |
| 546 get_visible_rect_ = NULL; |
| 547 |
527 received_pictures_.pop(); | 548 received_pictures_.pop(); |
528 } | 549 } |
529 | 550 |
530 } // namespace proxy | 551 } // namespace proxy |
531 } // namespace ppapi | 552 } // namespace ppapi |
OLD | NEW |