OLD | NEW |
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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 "content/renderer/media/android/webmediaplayer_android.h" | 5 #include "content/renderer/media/android/webmediaplayer_android.h" |
6 | 6 |
7 #include <limits> | 7 #include <limits> |
8 | 8 |
9 #include "base/bind.h" | 9 #include "base/bind.h" |
10 #include "base/callback_helpers.h" | 10 #include "base/callback_helpers.h" |
(...skipping 412 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
423 } | 423 } |
424 | 424 |
425 bool WebMediaPlayerAndroid::copyVideoTextureToPlatformTexture( | 425 bool WebMediaPlayerAndroid::copyVideoTextureToPlatformTexture( |
426 blink::WebGraphicsContext3D* web_graphics_context, | 426 blink::WebGraphicsContext3D* web_graphics_context, |
427 unsigned int texture, | 427 unsigned int texture, |
428 unsigned int level, | 428 unsigned int level, |
429 unsigned int internal_format, | 429 unsigned int internal_format, |
430 unsigned int type, | 430 unsigned int type, |
431 bool premultiply_alpha, | 431 bool premultiply_alpha, |
432 bool flip_y) { | 432 bool flip_y) { |
433 if (is_remote_ || !texture_id_) | 433 // Don't allow clients to copy an encrypted video frame. |
| 434 if (needs_external_surface_) |
434 return false; | 435 return false; |
435 | 436 |
| 437 scoped_refptr<VideoFrame> video_frame; |
| 438 { |
| 439 base::AutoLock auto_lock(current_frame_lock_); |
| 440 video_frame = current_frame_; |
| 441 } |
| 442 |
| 443 if (!video_frame || |
| 444 video_frame->format() != media::VideoFrame::NATIVE_TEXTURE) |
| 445 return false; |
| 446 DCHECK((!is_remote_ && texture_id_) || |
| 447 (is_remote_ && remote_playback_texture_id_)); |
| 448 gpu::MailboxHolder* mailbox_holder = video_frame->mailbox_holder(); |
| 449 DCHECK((texture_id_ && |
| 450 mailbox_holder->texture_target == GL_TEXTURE_EXTERNAL_OES) || |
| 451 (remote_playback_texture_id_ && |
| 452 mailbox_holder->texture_target == GL_TEXTURE_2D)); |
| 453 |
436 // For hidden video element (with style "display:none"), ensure the texture | 454 // For hidden video element (with style "display:none"), ensure the texture |
437 // size is set. | 455 // size is set. |
438 if (cached_stream_texture_size_.width != natural_size_.width || | 456 if (!is_remote_ && |
439 cached_stream_texture_size_.height != natural_size_.height) { | 457 (cached_stream_texture_size_.width != natural_size_.width || |
| 458 cached_stream_texture_size_.height != natural_size_.height)) { |
440 stream_texture_factory_->SetStreamTextureSize( | 459 stream_texture_factory_->SetStreamTextureSize( |
441 stream_id_, gfx::Size(natural_size_.width, natural_size_.height)); | 460 stream_id_, gfx::Size(natural_size_.width, natural_size_.height)); |
442 cached_stream_texture_size_ = natural_size_; | 461 cached_stream_texture_size_ = natural_size_; |
443 } | 462 } |
444 | 463 |
445 uint32 source_texture = web_graphics_context->createTexture(); | 464 uint32 source_texture = web_graphics_context->createTexture(); |
446 // This is strictly not necessary, because we flush when we create the | 465 web_graphics_context->waitSyncPoint(mailbox_holder->sync_point); |
447 // one and only stream texture. | |
448 web_graphics_context->waitSyncPoint(texture_mailbox_sync_point_); | |
449 | 466 |
450 // Ensure the target of texture is set before copyTextureCHROMIUM, otherwise | 467 // Ensure the target of texture is set before copyTextureCHROMIUM, otherwise |
451 // an invalid texture target may be used for copy texture. | 468 // an invalid texture target may be used for copy texture. |
452 web_graphics_context->bindTexture(GL_TEXTURE_EXTERNAL_OES, source_texture); | 469 web_graphics_context->bindTexture(mailbox_holder->texture_target, |
453 web_graphics_context->consumeTextureCHROMIUM(GL_TEXTURE_EXTERNAL_OES, | 470 source_texture); |
454 texture_mailbox_.name); | 471 web_graphics_context->consumeTextureCHROMIUM(mailbox_holder->texture_target, |
| 472 mailbox_holder->mailbox.name); |
455 | 473 |
456 // The video is stored in an unmultiplied format, so premultiply if | 474 // The video is stored in an unmultiplied format, so premultiply if |
457 // necessary. | 475 // necessary. |
458 web_graphics_context->pixelStorei(GL_UNPACK_PREMULTIPLY_ALPHA_CHROMIUM, | 476 web_graphics_context->pixelStorei(GL_UNPACK_PREMULTIPLY_ALPHA_CHROMIUM, |
459 premultiply_alpha); | 477 premultiply_alpha); |
460 | 478 |
461 // Application itself needs to take care of setting the right flip_y | 479 // Application itself needs to take care of setting the right flip_y |
462 // value down to get the expected result. | 480 // value down to get the expected result. |
463 // flip_y==true means to reverse the video orientation while | 481 // flip_y==true means to reverse the video orientation while |
464 // flip_y==false means to keep the intrinsic orientation. | 482 // flip_y==false means to keep the intrinsic orientation. |
465 web_graphics_context->pixelStorei(GL_UNPACK_FLIP_Y_CHROMIUM, flip_y); | 483 web_graphics_context->pixelStorei(GL_UNPACK_FLIP_Y_CHROMIUM, flip_y); |
466 web_graphics_context->copyTextureCHROMIUM(GL_TEXTURE_2D, source_texture, | 484 web_graphics_context->copyTextureCHROMIUM(GL_TEXTURE_2D, source_texture, |
467 texture, level, internal_format, | 485 texture, level, internal_format, |
468 type); | 486 type); |
469 web_graphics_context->pixelStorei(GL_UNPACK_FLIP_Y_CHROMIUM, false); | 487 web_graphics_context->pixelStorei(GL_UNPACK_FLIP_Y_CHROMIUM, false); |
470 web_graphics_context->pixelStorei(GL_UNPACK_PREMULTIPLY_ALPHA_CHROMIUM, | 488 web_graphics_context->pixelStorei(GL_UNPACK_PREMULTIPLY_ALPHA_CHROMIUM, |
471 false); | 489 false); |
472 | 490 |
473 web_graphics_context->bindTexture(GL_TEXTURE_EXTERNAL_OES, 0); | 491 if (mailbox_holder->texture_target == GL_TEXTURE_EXTERNAL_OES) |
| 492 web_graphics_context->bindTexture(GL_TEXTURE_EXTERNAL_OES, 0); |
| 493 else |
| 494 web_graphics_context->bindTexture(GL_TEXTURE_2D, texture); |
474 web_graphics_context->deleteTexture(source_texture); | 495 web_graphics_context->deleteTexture(source_texture); |
475 web_graphics_context->flush(); | 496 web_graphics_context->flush(); |
476 return true; | 497 return true; |
477 } | 498 } |
478 | 499 |
479 bool WebMediaPlayerAndroid::hasSingleSecurityOrigin() const { | 500 bool WebMediaPlayerAndroid::hasSingleSecurityOrigin() const { |
480 if (info_loader_) | 501 if (info_loader_) |
481 return info_loader_->HasSingleOrigin(); | 502 return info_loader_->HasSingleOrigin(); |
482 // The info loader may have failed. | 503 // The info loader may have failed. |
483 if (player_type_ == MEDIA_PLAYER_TYPE_URL) | 504 if (player_type_ == MEDIA_PLAYER_TYPE_URL) |
(...skipping 1004 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1488 | 1509 |
1489 void WebMediaPlayerAndroid::exitFullscreen() { | 1510 void WebMediaPlayerAndroid::exitFullscreen() { |
1490 manager_->ExitFullscreen(player_id_); | 1511 manager_->ExitFullscreen(player_id_); |
1491 } | 1512 } |
1492 | 1513 |
1493 bool WebMediaPlayerAndroid::canEnterFullscreen() const { | 1514 bool WebMediaPlayerAndroid::canEnterFullscreen() const { |
1494 return manager_->CanEnterFullscreen(frame_); | 1515 return manager_->CanEnterFullscreen(frame_); |
1495 } | 1516 } |
1496 | 1517 |
1497 } // namespace content | 1518 } // namespace content |
OLD | NEW |