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 21 matching lines...) Expand all Loading... |
32 #include "gpu/GLES2/gl2extchromium.h" | 32 #include "gpu/GLES2/gl2extchromium.h" |
33 #include "gpu/command_buffer/client/gles2_interface.h" | 33 #include "gpu/command_buffer/client/gles2_interface.h" |
34 #include "gpu/command_buffer/common/mailbox_holder.h" | 34 #include "gpu/command_buffer/common/mailbox_holder.h" |
35 #include "media/base/android/media_player_android.h" | 35 #include "media/base/android/media_player_android.h" |
36 #include "media/base/bind_to_current_loop.h" | 36 #include "media/base/bind_to_current_loop.h" |
37 // TODO(xhwang): Remove when we remove prefixed EME implementation. | 37 // TODO(xhwang): Remove when we remove prefixed EME implementation. |
38 #include "media/base/media_keys.h" | 38 #include "media/base/media_keys.h" |
39 #include "media/base/media_switches.h" | 39 #include "media/base/media_switches.h" |
40 #include "media/base/video_frame.h" | 40 #include "media/base/video_frame.h" |
41 #include "net/base/mime_util.h" | 41 #include "net/base/mime_util.h" |
| 42 #include "third_party/WebKit/public/platform/Platform.h" |
| 43 #include "third_party/WebKit/public/platform/WebGraphicsContext3DProvider.h" |
42 #include "third_party/WebKit/public/platform/WebMediaPlayerClient.h" | 44 #include "third_party/WebKit/public/platform/WebMediaPlayerClient.h" |
43 #include "third_party/WebKit/public/platform/WebString.h" | 45 #include "third_party/WebKit/public/platform/WebString.h" |
44 #include "third_party/WebKit/public/platform/WebURL.h" | 46 #include "third_party/WebKit/public/platform/WebURL.h" |
45 #include "third_party/WebKit/public/web/WebDocument.h" | 47 #include "third_party/WebKit/public/web/WebDocument.h" |
46 #include "third_party/WebKit/public/web/WebFrame.h" | 48 #include "third_party/WebKit/public/web/WebFrame.h" |
47 #include "third_party/WebKit/public/web/WebRuntimeFeatures.h" | 49 #include "third_party/WebKit/public/web/WebRuntimeFeatures.h" |
48 #include "third_party/WebKit/public/web/WebSecurityOrigin.h" | 50 #include "third_party/WebKit/public/web/WebSecurityOrigin.h" |
49 #include "third_party/WebKit/public/web/WebView.h" | 51 #include "third_party/WebKit/public/web/WebView.h" |
50 #include "third_party/skia/include/core/SkBitmap.h" | |
51 #include "third_party/skia/include/core/SkCanvas.h" | 52 #include "third_party/skia/include/core/SkCanvas.h" |
52 #include "third_party/skia/include/core/SkPaint.h" | 53 #include "third_party/skia/include/core/SkPaint.h" |
53 #include "third_party/skia/include/core/SkTypeface.h" | 54 #include "third_party/skia/include/core/SkTypeface.h" |
54 #include "ui/gfx/image/image.h" | 55 #include "ui/gfx/image/image.h" |
55 | 56 |
56 static const uint32 kGLTextureExternalOES = 0x8D65; | 57 static const uint32 kGLTextureExternalOES = 0x8D65; |
57 | 58 |
58 using blink::WebMediaPlayer; | 59 using blink::WebMediaPlayer; |
59 using blink::WebSize; | 60 using blink::WebSize; |
60 using blink::WebString; | 61 using blink::WebString; |
(...skipping 392 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
453 | 454 |
454 return duration(); | 455 return duration(); |
455 } | 456 } |
456 | 457 |
457 bool WebMediaPlayerAndroid::didLoadingProgress() { | 458 bool WebMediaPlayerAndroid::didLoadingProgress() { |
458 bool ret = did_loading_progress_; | 459 bool ret = did_loading_progress_; |
459 did_loading_progress_ = false; | 460 did_loading_progress_ = false; |
460 return ret; | 461 return ret; |
461 } | 462 } |
462 | 463 |
| 464 bool WebMediaPlayerAndroid::EnsureTextureBackedSkBitmap(GrContext* gr, |
| 465 SkBitmap& bitmap, |
| 466 const WebSize& size, |
| 467 GrSurfaceOrigin origin, |
| 468 GrPixelConfig config) { |
| 469 if (!bitmap.getTexture() || bitmap.width() != size.width |
| 470 || bitmap.height() != size.height) { |
| 471 if (!gr) |
| 472 return false; |
| 473 GrTextureDesc desc; |
| 474 desc.fConfig = config; |
| 475 desc.fFlags = kRenderTarget_GrTextureFlagBit | kNoStencil_GrTextureFlagBit; |
| 476 desc.fSampleCnt = 0; |
| 477 desc.fOrigin = origin; |
| 478 desc.fWidth = size.width; |
| 479 desc.fHeight = size.height; |
| 480 skia::RefPtr<GrTexture> texture; |
| 481 texture = skia::AdoptRef(gr->createUncachedTexture(desc, 0, 0)); |
| 482 if (!texture.get()) |
| 483 return false; |
| 484 |
| 485 SkImageInfo info = SkImageInfo::MakeN32Premul(desc.fWidth, desc.fHeight); |
| 486 SkGrPixelRef* pixelRef = SkNEW_ARGS(SkGrPixelRef, (info, texture.get())); |
| 487 if (!pixelRef) |
| 488 return false; |
| 489 bitmap.setInfo(info); |
| 490 bitmap.setPixelRef(pixelRef)->unref(); |
| 491 } |
| 492 |
| 493 return true; |
| 494 } |
| 495 |
463 void WebMediaPlayerAndroid::paint(blink::WebCanvas* canvas, | 496 void WebMediaPlayerAndroid::paint(blink::WebCanvas* canvas, |
464 const blink::WebRect& rect, | 497 const blink::WebRect& rect, |
465 unsigned char alpha) { | 498 unsigned char alpha) { |
466 NOTIMPLEMENTED(); | 499 scoped_ptr<blink::WebGraphicsContext3DProvider> provider = |
| 500 scoped_ptr<blink::WebGraphicsContext3DProvider>(blink::Platform::current( |
| 501 )->createSharedOffscreenGraphicsContext3DProvider()); |
| 502 if (!provider) |
| 503 return; |
| 504 blink::WebGraphicsContext3D* context3D = provider->context3d(); |
| 505 if (!context3D || !context3D->makeContextCurrent()) |
| 506 return; |
| 507 |
| 508 // Copy video texture into a RGBA texture based bitmap first as video texture |
| 509 // on Android is GL_TEXTURE_EXTERNAL_OES which is not supported by Skia yet. |
| 510 // The bitmap's size needs to be the same as the video and use naturalSize() |
| 511 // here. Check if we could reuse existing texture based bitmap. |
| 512 // Otherwise, release existing texture based bitmap and allocate |
| 513 // a new one based on video size. |
| 514 if (!EnsureTextureBackedSkBitmap(provider->grContext(), bitmap_, |
| 515 naturalSize(), kTopLeft_GrSurfaceOrigin, kSkia8888_GrPixelConfig)) { |
| 516 return; |
| 517 } |
| 518 |
| 519 unsigned textureId = static_cast<unsigned>( |
| 520 (bitmap_.getTexture())->getTextureHandle()); |
| 521 if (!copyVideoTextureToPlatformTexture(context3D, textureId, 0, |
| 522 GL_RGBA, GL_UNSIGNED_BYTE, true, false)) { |
| 523 return; |
| 524 } |
| 525 |
| 526 // Draw the texture based bitmap onto the Canvas. If the canvas is |
| 527 // hardware based, this will do a GPU-GPU texture copy. |
| 528 // If the canvas is software based, the texture based bitmap will be |
| 529 // readbacked to system memory then draw onto the canvas. |
| 530 SkRect dest; |
| 531 dest.set(rect.x, rect.y, rect.x + rect.width, rect.y + rect.height); |
| 532 SkPaint paint; |
| 533 paint.setAlpha(alpha); |
| 534 // It is not necessary to pass the dest into the drawBitmap call since all |
| 535 // the context have been set up before calling paintCurrentFrameInContext. |
| 536 canvas->drawBitmapRect(bitmap_, 0, dest, &paint); |
467 } | 537 } |
468 | 538 |
469 bool WebMediaPlayerAndroid::copyVideoTextureToPlatformTexture( | 539 bool WebMediaPlayerAndroid::copyVideoTextureToPlatformTexture( |
470 blink::WebGraphicsContext3D* web_graphics_context, | 540 blink::WebGraphicsContext3D* web_graphics_context, |
471 unsigned int texture, | 541 unsigned int texture, |
472 unsigned int level, | 542 unsigned int level, |
473 unsigned int internal_format, | 543 unsigned int internal_format, |
474 unsigned int type, | 544 unsigned int type, |
475 bool premultiply_alpha, | 545 bool premultiply_alpha, |
476 bool flip_y) { | 546 bool flip_y) { |
(...skipping 22 matching lines...) Expand all Loading... |
499 cached_stream_texture_size_.height != natural_size_.height)) { | 569 cached_stream_texture_size_.height != natural_size_.height)) { |
500 stream_texture_factory_->SetStreamTextureSize( | 570 stream_texture_factory_->SetStreamTextureSize( |
501 stream_id_, gfx::Size(natural_size_.width, natural_size_.height)); | 571 stream_id_, gfx::Size(natural_size_.width, natural_size_.height)); |
502 cached_stream_texture_size_ = natural_size_; | 572 cached_stream_texture_size_ = natural_size_; |
503 } | 573 } |
504 | 574 |
505 web_graphics_context->waitSyncPoint(mailbox_holder->sync_point); | 575 web_graphics_context->waitSyncPoint(mailbox_holder->sync_point); |
506 | 576 |
507 // Ensure the target of texture is set before copyTextureCHROMIUM, otherwise | 577 // Ensure the target of texture is set before copyTextureCHROMIUM, otherwise |
508 // an invalid texture target may be used for copy texture. | 578 // an invalid texture target may be used for copy texture. |
509 uint32 source_texture = web_graphics_context->createAndConsumeTextureCHROMIUM( | 579 uint32 src_texture = web_graphics_context->createAndConsumeTextureCHROMIUM( |
510 mailbox_holder->texture_target, mailbox_holder->mailbox.name); | 580 mailbox_holder->texture_target, mailbox_holder->mailbox.name); |
511 | 581 |
512 // The video is stored in an unmultiplied format, so premultiply if | 582 // The video is stored in an unmultiplied format, so premultiply if |
513 // necessary. | 583 // necessary. |
514 web_graphics_context->pixelStorei(GL_UNPACK_PREMULTIPLY_ALPHA_CHROMIUM, | 584 web_graphics_context->pixelStorei(GL_UNPACK_PREMULTIPLY_ALPHA_CHROMIUM, |
515 premultiply_alpha); | 585 premultiply_alpha); |
516 | 586 |
517 // Application itself needs to take care of setting the right flip_y | 587 // Application itself needs to take care of setting the right flip_y |
518 // value down to get the expected result. | 588 // value down to get the expected result. |
519 // flip_y==true means to reverse the video orientation while | 589 // flip_y==true means to reverse the video orientation while |
520 // flip_y==false means to keep the intrinsic orientation. | 590 // flip_y==false means to keep the intrinsic orientation. |
521 web_graphics_context->pixelStorei(GL_UNPACK_FLIP_Y_CHROMIUM, flip_y); | 591 web_graphics_context->pixelStorei(GL_UNPACK_FLIP_Y_CHROMIUM, flip_y); |
522 web_graphics_context->copyTextureCHROMIUM(GL_TEXTURE_2D, source_texture, | 592 web_graphics_context->copyTextureCHROMIUM(GL_TEXTURE_2D, src_texture, |
523 texture, level, internal_format, | 593 texture, level, internal_format, |
524 type); | 594 type); |
525 web_graphics_context->pixelStorei(GL_UNPACK_FLIP_Y_CHROMIUM, false); | 595 web_graphics_context->pixelStorei(GL_UNPACK_FLIP_Y_CHROMIUM, false); |
526 web_graphics_context->pixelStorei(GL_UNPACK_PREMULTIPLY_ALPHA_CHROMIUM, | 596 web_graphics_context->pixelStorei(GL_UNPACK_PREMULTIPLY_ALPHA_CHROMIUM, |
527 false); | 597 false); |
528 | 598 |
529 web_graphics_context->deleteTexture(source_texture); | 599 web_graphics_context->deleteTexture(src_texture); |
530 web_graphics_context->flush(); | 600 web_graphics_context->flush(); |
531 | 601 |
532 SyncPointClientImpl client(web_graphics_context); | 602 SyncPointClientImpl client(web_graphics_context); |
533 video_frame->UpdateReleaseSyncPoint(&client); | 603 video_frame->UpdateReleaseSyncPoint(&client); |
534 return true; | 604 return true; |
535 } | 605 } |
536 | 606 |
537 bool WebMediaPlayerAndroid::hasSingleSecurityOrigin() const { | 607 bool WebMediaPlayerAndroid::hasSingleSecurityOrigin() const { |
538 if (info_loader_) | 608 if (info_loader_) |
539 return info_loader_->HasSingleOrigin(); | 609 return info_loader_->HasSingleOrigin(); |
(...skipping 992 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1532 player_manager_->EnterFullscreen(player_id_, frame_); | 1602 player_manager_->EnterFullscreen(player_id_, frame_); |
1533 SetNeedsEstablishPeer(false); | 1603 SetNeedsEstablishPeer(false); |
1534 } | 1604 } |
1535 } | 1605 } |
1536 | 1606 |
1537 bool WebMediaPlayerAndroid::canEnterFullscreen() const { | 1607 bool WebMediaPlayerAndroid::canEnterFullscreen() const { |
1538 return player_manager_->CanEnterFullscreen(frame_); | 1608 return player_manager_->CanEnterFullscreen(frame_); |
1539 } | 1609 } |
1540 | 1610 |
1541 } // namespace content | 1611 } // namespace content |
OLD | NEW |