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( | |
qinmin
2014/07/30 05:25:52
nit: +2 indent
Srirama
2014/07/30 05:45:03
Done.
Srirama
2014/07/30 05:45:03
Done.
| |
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 unsigned textureId = static_cast<unsigned>( | |
519 (bitmap_.getTexture())->getTextureHandle()); | |
520 if (!copyVideoTextureToPlatformTexture(context3D, textureId, 0, | |
521 GL_RGBA, GL_UNSIGNED_BYTE, true, false)) | |
522 return; | |
qinmin
2014/07/30 05:25:52
nit: you need {} if the if statement spans multipl
Srirama
2014/07/30 05:45:03
Done.
| |
523 | |
524 // Draw the texture based bitmap onto the Canvas. If the canvas is | |
525 // hardware based, this will do a GPU-GPU texture copy. | |
526 // If the canvas is software based, the texture based bitmap will be | |
527 // readbacked to system memory then draw onto the canvas. | |
528 SkRect dest; | |
529 dest.set(rect.x, rect.y, rect.x + rect.width, rect.y + rect.height); | |
530 SkPaint paint; | |
531 paint.setAlpha(alpha); | |
532 // It is not necessary to pass the dest into the drawBitmap call since all | |
533 // the context have been set up before calling paintCurrentFrameInContext. | |
534 canvas->drawBitmapRect(bitmap_, 0, dest, &paint); | |
467 } | 535 } |
468 | 536 |
469 bool WebMediaPlayerAndroid::copyVideoTextureToPlatformTexture( | 537 bool WebMediaPlayerAndroid::copyVideoTextureToPlatformTexture( |
470 blink::WebGraphicsContext3D* web_graphics_context, | 538 blink::WebGraphicsContext3D* web_graphics_context, |
471 unsigned int texture, | 539 unsigned int texture, |
472 unsigned int level, | 540 unsigned int level, |
473 unsigned int internal_format, | 541 unsigned int internal_format, |
474 unsigned int type, | 542 unsigned int type, |
475 bool premultiply_alpha, | 543 bool premultiply_alpha, |
476 bool flip_y) { | 544 bool flip_y) { |
(...skipping 22 matching lines...) Expand all Loading... | |
499 cached_stream_texture_size_.height != natural_size_.height)) { | 567 cached_stream_texture_size_.height != natural_size_.height)) { |
500 stream_texture_factory_->SetStreamTextureSize( | 568 stream_texture_factory_->SetStreamTextureSize( |
501 stream_id_, gfx::Size(natural_size_.width, natural_size_.height)); | 569 stream_id_, gfx::Size(natural_size_.width, natural_size_.height)); |
502 cached_stream_texture_size_ = natural_size_; | 570 cached_stream_texture_size_ = natural_size_; |
503 } | 571 } |
504 | 572 |
505 web_graphics_context->waitSyncPoint(mailbox_holder->sync_point); | 573 web_graphics_context->waitSyncPoint(mailbox_holder->sync_point); |
506 | 574 |
507 // Ensure the target of texture is set before copyTextureCHROMIUM, otherwise | 575 // Ensure the target of texture is set before copyTextureCHROMIUM, otherwise |
508 // an invalid texture target may be used for copy texture. | 576 // an invalid texture target may be used for copy texture. |
509 uint32 source_texture = web_graphics_context->createAndConsumeTextureCHROMIUM( | 577 uint32 src_texture = web_graphics_context->createAndConsumeTextureCHROMIUM( |
510 mailbox_holder->texture_target, mailbox_holder->mailbox.name); | 578 mailbox_holder->texture_target, mailbox_holder->mailbox.name); |
511 | 579 |
512 // The video is stored in an unmultiplied format, so premultiply if | 580 // The video is stored in an unmultiplied format, so premultiply if |
513 // necessary. | 581 // necessary. |
514 web_graphics_context->pixelStorei(GL_UNPACK_PREMULTIPLY_ALPHA_CHROMIUM, | 582 web_graphics_context->pixelStorei(GL_UNPACK_PREMULTIPLY_ALPHA_CHROMIUM, |
515 premultiply_alpha); | 583 premultiply_alpha); |
516 | 584 |
517 // Application itself needs to take care of setting the right flip_y | 585 // Application itself needs to take care of setting the right flip_y |
518 // value down to get the expected result. | 586 // value down to get the expected result. |
519 // flip_y==true means to reverse the video orientation while | 587 // flip_y==true means to reverse the video orientation while |
520 // flip_y==false means to keep the intrinsic orientation. | 588 // flip_y==false means to keep the intrinsic orientation. |
521 web_graphics_context->pixelStorei(GL_UNPACK_FLIP_Y_CHROMIUM, flip_y); | 589 web_graphics_context->pixelStorei(GL_UNPACK_FLIP_Y_CHROMIUM, flip_y); |
522 web_graphics_context->copyTextureCHROMIUM(GL_TEXTURE_2D, source_texture, | 590 web_graphics_context->copyTextureCHROMIUM(GL_TEXTURE_2D, src_texture, |
523 texture, level, internal_format, | 591 texture, level, internal_format, |
524 type); | 592 type); |
525 web_graphics_context->pixelStorei(GL_UNPACK_FLIP_Y_CHROMIUM, false); | 593 web_graphics_context->pixelStorei(GL_UNPACK_FLIP_Y_CHROMIUM, false); |
526 web_graphics_context->pixelStorei(GL_UNPACK_PREMULTIPLY_ALPHA_CHROMIUM, | 594 web_graphics_context->pixelStorei(GL_UNPACK_PREMULTIPLY_ALPHA_CHROMIUM, |
527 false); | 595 false); |
528 | 596 |
529 web_graphics_context->deleteTexture(source_texture); | 597 web_graphics_context->deleteTexture(src_texture); |
530 web_graphics_context->flush(); | 598 web_graphics_context->flush(); |
531 | 599 |
532 SyncPointClientImpl client(web_graphics_context); | 600 SyncPointClientImpl client(web_graphics_context); |
533 video_frame->UpdateReleaseSyncPoint(&client); | 601 video_frame->UpdateReleaseSyncPoint(&client); |
534 return true; | 602 return true; |
535 } | 603 } |
536 | 604 |
537 bool WebMediaPlayerAndroid::hasSingleSecurityOrigin() const { | 605 bool WebMediaPlayerAndroid::hasSingleSecurityOrigin() const { |
538 if (info_loader_) | 606 if (info_loader_) |
539 return info_loader_->HasSingleOrigin(); | 607 return info_loader_->HasSingleOrigin(); |
(...skipping 992 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1532 player_manager_->EnterFullscreen(player_id_, frame_); | 1600 player_manager_->EnterFullscreen(player_id_, frame_); |
1533 SetNeedsEstablishPeer(false); | 1601 SetNeedsEstablishPeer(false); |
1534 } | 1602 } |
1535 } | 1603 } |
1536 | 1604 |
1537 bool WebMediaPlayerAndroid::canEnterFullscreen() const { | 1605 bool WebMediaPlayerAndroid::canEnterFullscreen() const { |
1538 return player_manager_->CanEnterFullscreen(frame_); | 1606 return player_manager_->CanEnterFullscreen(frame_); |
1539 } | 1607 } |
1540 | 1608 |
1541 } // namespace content | 1609 } // namespace content |
OLD | NEW |