Chromium Code Reviews| 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 396 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 457 | 458 |
| 458 return duration(); | 459 return duration(); |
| 459 } | 460 } |
| 460 | 461 |
| 461 bool WebMediaPlayerAndroid::didLoadingProgress() { | 462 bool WebMediaPlayerAndroid::didLoadingProgress() { |
| 462 bool ret = did_loading_progress_; | 463 bool ret = did_loading_progress_; |
| 463 did_loading_progress_ = false; | 464 did_loading_progress_ = false; |
| 464 return ret; | 465 return ret; |
| 465 } | 466 } |
| 466 | 467 |
| 468 bool WebMediaPlayerAndroid::ensureTextureBackedSkBitmap(GrContext* gr, | |
| 469 SkBitmap& bitmap, | |
|
qinmin
2014/07/25 17:01:09
align all the params
Srirama
2014/07/25 18:06:29
Done.
| |
| 470 const WebSize& size, | |
| 471 GrSurfaceOrigin origin, | |
| 472 GrPixelConfig config) | |
| 473 { | |
|
qinmin
2014/07/25 17:01:09
move this to the previous line
Srirama
2014/07/25 18:06:29
Done.
| |
| 474 if (!bitmap.getTexture() || bitmap.width() != size.width || bitmap.height() != size.height) { | |
|
qinmin
2014/07/25 17:01:09
fix all the indent here, chromium uses 2 spaces, n
Srirama
2014/07/25 18:06:29
Done.
| |
| 475 if (!gr) | |
| 476 return false; | |
| 477 GrTextureDesc desc; | |
| 478 desc.fConfig = config; | |
| 479 desc.fFlags = kRenderTarget_GrTextureFlagBit | kNoStencil_GrTextureFlagB it; | |
| 480 desc.fSampleCnt = 0; | |
| 481 desc.fOrigin = origin; | |
| 482 desc.fWidth = size.width; | |
| 483 desc.fHeight = size.height; | |
| 484 skia::RefPtr<GrTexture> texture; | |
| 485 texture = skia::AdoptRef(gr->createUncachedTexture(desc, 0, 0)); | |
| 486 if (!texture.get()) | |
| 487 return false; | |
| 488 | |
| 489 SkImageInfo info = SkImageInfo::MakeN32Premul(desc.fWidth, desc.fHeight) ; | |
| 490 SkGrPixelRef* pixelRef = SkNEW_ARGS(SkGrPixelRef, (info, texture.get())) ; | |
| 491 if (!pixelRef) | |
| 492 return false; | |
| 493 bitmap.setInfo(info); | |
| 494 bitmap.setPixelRef(pixelRef)->unref(); | |
| 495 } | |
| 496 | |
| 497 return true; | |
| 498 } | |
| 499 | |
| 467 void WebMediaPlayerAndroid::paint(blink::WebCanvas* canvas, | 500 void WebMediaPlayerAndroid::paint(blink::WebCanvas* canvas, |
| 468 const blink::WebRect& rect, | 501 const blink::WebRect& rect, |
| 469 unsigned char alpha) { | 502 unsigned char alpha) { |
| 470 NOTIMPLEMENTED(); | 503 if (player_type_ != MEDIA_PLAYER_TYPE_URL && player_type_ != MEDIA_PLAYER_TY PE_MEDIA_SOURCE) |
|
qinmin
2014/07/25 17:01:09
there are only 2 enums defined for player type, th
Srirama
2014/07/25 18:06:29
Done.
| |
| 504 return; | |
| 505 scoped_ptr<blink::WebGraphicsContext3DProvider> provider = scoped_ptr<blink: :WebGraphicsContext3DProvider>(blink::Platform::current()->createSharedOffscreen GraphicsContext3DProvider()); | |
| 506 if (!provider) | |
| 507 return; | |
| 508 blink::WebGraphicsContext3D* context3D = provider->context3d(); | |
| 509 if (!context3D || !context3D->makeContextCurrent()) | |
| 510 return; | |
| 511 | |
| 512 // Copy video texture into a RGBA texture based bitmap first as video textur e on Android is GL_TEXTURE_EXTERNAL_OES | |
| 513 // which is not supported by Skia yet. The bitmap's size needs to be the sam e as the video and use naturalSize() here. | |
| 514 // Check if we could reuse existing texture based bitmap. | |
| 515 // Otherwise, release existing texture based bitmap and allocate a new one b ased on video size. | |
| 516 if (!ensureTextureBackedSkBitmap(provider->grContext(), m_bitmap, naturalSiz e(), kTopLeft_GrSurfaceOrigin, kSkia8888_GrPixelConfig)) | |
| 517 return; | |
| 518 | |
| 519 unsigned textureId = static_cast<unsigned>((m_bitmap.getTexture())->getTextu reHandle()); | |
| 520 if (!copyVideoTextureToPlatformTexture(context3D, textureId, 0, GL_RGBA, GL_ UNSIGNED_BYTE, true, false)) | |
| 521 return; | |
| 522 | |
| 523 // Draw the texture based bitmap onto the Canvas. If the canvas is hardware based, this will do a GPU-GPU texture copy. If the canvas is software based, | |
| 524 // the texture based bitmap will be readbacked to system memory then draw on to the canvas. | |
| 525 SkRect dest; | |
| 526 dest.set(rect.x, rect.y, rect.x + rect.width, rect.y + rect.height); | |
| 527 SkPaint paint; | |
| 528 paint.setAlpha(alpha); | |
| 529 // It is not necessary to pass the dest into the drawBitmap call since all t he context have been set up before calling paintCurrentFrameInContext. | |
| 530 canvas->drawBitmapRect(m_bitmap, 0, dest, &paint); | |
| 471 } | 531 } |
| 472 | 532 |
| 473 bool WebMediaPlayerAndroid::copyVideoTextureToPlatformTexture( | 533 bool WebMediaPlayerAndroid::copyVideoTextureToPlatformTexture( |
| 474 blink::WebGraphicsContext3D* web_graphics_context, | 534 blink::WebGraphicsContext3D* web_graphics_context, |
| 475 unsigned int texture, | 535 unsigned int texture, |
| 476 unsigned int level, | 536 unsigned int level, |
| 477 unsigned int internal_format, | 537 unsigned int internal_format, |
| 478 unsigned int type, | 538 unsigned int type, |
| 479 bool premultiply_alpha, | 539 bool premultiply_alpha, |
| 480 bool flip_y) { | 540 bool flip_y) { |
| (...skipping 1056 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1537 player_manager_->EnterFullscreen(player_id_, frame_); | 1597 player_manager_->EnterFullscreen(player_id_, frame_); |
| 1538 SetNeedsEstablishPeer(false); | 1598 SetNeedsEstablishPeer(false); |
| 1539 } | 1599 } |
| 1540 } | 1600 } |
| 1541 | 1601 |
| 1542 bool WebMediaPlayerAndroid::canEnterFullscreen() const { | 1602 bool WebMediaPlayerAndroid::canEnterFullscreen() const { |
| 1543 return player_manager_->CanEnterFullscreen(frame_); | 1603 return player_manager_->CanEnterFullscreen(frame_); |
| 1544 } | 1604 } |
| 1545 | 1605 |
| 1546 } // namespace content | 1606 } // namespace content |
| OLD | NEW |