Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(151)

Side by Side Diff: content/renderer/media/android/webmediaplayer_android.cc

Issue 212183005: Android video: support copying video to WebGL for remote texture. (Closed) Base URL: https://git.chromium.org/chromium/src.git@master
Patch Set: Created 6 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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
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 the texture of encrypted video.
no sievers 2014/03/26 23:51:22 Do we need to do this? There is no texture here to
dshwang 2014/03/27 19:42:57 The result is the same. If return false, WebGLRend
dshwang 2014/03/28 19:19:57 After rethinking, I find 1x1 texture breaks webgl.
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 // This is strictly not necessary, because we flush when we create the
447 // one and only stream texture. 466 // one and only stream texture.
448 web_graphics_context->waitSyncPoint(texture_mailbox_sync_point_); 467 web_graphics_context->waitSyncPoint(mailbox_holder->sync_point);
no sievers 2014/03/26 23:51:22 Doesn't this change the behavior in that we synchr
dshwang 2014/03/27 19:42:57 We can not make sure web_graphics_context and stre
no sievers 2014/03/28 18:10:25 I think he's talking about possible future semanti
dshwang 2014/03/28 18:30:23 That's good question. mailbox_holder is updated by
dshwang 2014/03/28 19:19:57 In addition, if https://codereview.chromium.org/17
no sievers 2014/03/28 19:47:59 Great, thanks for fixing that!
449 468
450 // Ensure the target of texture is set before copyTextureCHROMIUM, otherwise 469 // Ensure the target of texture is set before copyTextureCHROMIUM, otherwise
451 // an invalid texture target may be used for copy texture. 470 // an invalid texture target may be used for copy texture.
452 web_graphics_context->bindTexture(GL_TEXTURE_EXTERNAL_OES, source_texture); 471 web_graphics_context->bindTexture(mailbox_holder->texture_target,
453 web_graphics_context->consumeTextureCHROMIUM(GL_TEXTURE_EXTERNAL_OES, 472 source_texture);
454 texture_mailbox_.name); 473 web_graphics_context->consumeTextureCHROMIUM(mailbox_holder->texture_target,
474 mailbox_holder->mailbox.name);
455 475
456 // The video is stored in an unmultiplied format, so premultiply if 476 // The video is stored in an unmultiplied format, so premultiply if
457 // necessary. 477 // necessary.
458 web_graphics_context->pixelStorei(GL_UNPACK_PREMULTIPLY_ALPHA_CHROMIUM, 478 web_graphics_context->pixelStorei(GL_UNPACK_PREMULTIPLY_ALPHA_CHROMIUM,
459 premultiply_alpha); 479 premultiply_alpha);
460 480
461 // Application itself needs to take care of setting the right flip_y 481 // Application itself needs to take care of setting the right flip_y
462 // value down to get the expected result. 482 // value down to get the expected result.
463 // flip_y==true means to reverse the video orientation while 483 // flip_y==true means to reverse the video orientation while
464 // flip_y==false means to keep the intrinsic orientation. 484 // flip_y==false means to keep the intrinsic orientation.
465 web_graphics_context->pixelStorei(GL_UNPACK_FLIP_Y_CHROMIUM, flip_y); 485 web_graphics_context->pixelStorei(GL_UNPACK_FLIP_Y_CHROMIUM, flip_y);
no sievers 2014/03/26 23:51:22 Aren't flip_y and premultiply_alpha incorrect here
dshwang 2014/03/27 19:42:57 both stream texture and remote playback texture ha
466 web_graphics_context->copyTextureCHROMIUM(GL_TEXTURE_2D, source_texture, 486 web_graphics_context->copyTextureCHROMIUM(GL_TEXTURE_2D, source_texture,
467 texture, level, internal_format, 487 texture, level, internal_format,
468 type); 488 type);
469 web_graphics_context->pixelStorei(GL_UNPACK_FLIP_Y_CHROMIUM, false); 489 web_graphics_context->pixelStorei(GL_UNPACK_FLIP_Y_CHROMIUM, false);
470 web_graphics_context->pixelStorei(GL_UNPACK_PREMULTIPLY_ALPHA_CHROMIUM, 490 web_graphics_context->pixelStorei(GL_UNPACK_PREMULTIPLY_ALPHA_CHROMIUM,
471 false); 491 false);
472 492
473 web_graphics_context->bindTexture(GL_TEXTURE_EXTERNAL_OES, 0); 493 if (mailbox_holder->texture_target == GL_TEXTURE_EXTERNAL_OES)
494 web_graphics_context->bindTexture(GL_TEXTURE_EXTERNAL_OES, 0);
495 else
496 web_graphics_context->bindTexture(GL_TEXTURE_2D, texture);
474 web_graphics_context->deleteTexture(source_texture); 497 web_graphics_context->deleteTexture(source_texture);
475 web_graphics_context->flush(); 498 web_graphics_context->flush();
476 return true; 499 return true;
477 } 500 }
478 501
479 bool WebMediaPlayerAndroid::hasSingleSecurityOrigin() const { 502 bool WebMediaPlayerAndroid::hasSingleSecurityOrigin() const {
480 if (info_loader_) 503 if (info_loader_)
481 return info_loader_->HasSingleOrigin(); 504 return info_loader_->HasSingleOrigin();
482 // The info loader may have failed. 505 // The info loader may have failed.
483 if (player_type_ == MEDIA_PLAYER_TYPE_URL) 506 if (player_type_ == MEDIA_PLAYER_TYPE_URL)
(...skipping 1004 matching lines...) Expand 10 before | Expand all | Expand 10 after
1488 1511
1489 void WebMediaPlayerAndroid::exitFullscreen() { 1512 void WebMediaPlayerAndroid::exitFullscreen() {
1490 manager_->ExitFullscreen(player_id_); 1513 manager_->ExitFullscreen(player_id_);
1491 } 1514 }
1492 1515
1493 bool WebMediaPlayerAndroid::canEnterFullscreen() const { 1516 bool WebMediaPlayerAndroid::canEnterFullscreen() const {
1494 return manager_->CanEnterFullscreen(frame_); 1517 return manager_->CanEnterFullscreen(frame_);
1495 } 1518 }
1496 1519
1497 } // namespace content 1520 } // namespace content
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698