Chromium Code Reviews| Index: content/renderer/media/android/webmediaplayer_android.cc |
| diff --git a/content/renderer/media/android/webmediaplayer_android.cc b/content/renderer/media/android/webmediaplayer_android.cc |
| index 419aee199185af9de76345e7e2d198f60385c2f0..ae77a895cbed1870a7d5e25a854a64a2fe89c117 100644 |
| --- a/content/renderer/media/android/webmediaplayer_android.cc |
| +++ b/content/renderer/media/android/webmediaplayer_android.cc |
| @@ -39,6 +39,8 @@ |
| #include "media/base/media_switches.h" |
| #include "media/base/video_frame.h" |
| #include "net/base/mime_util.h" |
| +#include "third_party/WebKit/public/platform/Platform.h" |
| +#include "third_party/WebKit/public/platform/WebGraphicsContext3DProvider.h" |
| #include "third_party/WebKit/public/platform/WebMediaPlayerClient.h" |
| #include "third_party/WebKit/public/platform/WebString.h" |
| #include "third_party/WebKit/public/platform/WebURL.h" |
| @@ -47,7 +49,6 @@ |
| #include "third_party/WebKit/public/web/WebRuntimeFeatures.h" |
| #include "third_party/WebKit/public/web/WebSecurityOrigin.h" |
| #include "third_party/WebKit/public/web/WebView.h" |
| -#include "third_party/skia/include/core/SkBitmap.h" |
| #include "third_party/skia/include/core/SkCanvas.h" |
| #include "third_party/skia/include/core/SkPaint.h" |
| #include "third_party/skia/include/core/SkTypeface.h" |
| @@ -464,10 +465,69 @@ bool WebMediaPlayerAndroid::didLoadingProgress() { |
| return ret; |
| } |
| +bool WebMediaPlayerAndroid::ensureTextureBackedSkBitmap(GrContext* gr, |
| + SkBitmap& bitmap, |
|
qinmin
2014/07/25 17:01:09
align all the params
Srirama
2014/07/25 18:06:29
Done.
|
| + const WebSize& size, |
| + GrSurfaceOrigin origin, |
| + GrPixelConfig config) |
| +{ |
|
qinmin
2014/07/25 17:01:09
move this to the previous line
Srirama
2014/07/25 18:06:29
Done.
|
| + 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.
|
| + if (!gr) |
| + return false; |
| + GrTextureDesc desc; |
| + desc.fConfig = config; |
| + desc.fFlags = kRenderTarget_GrTextureFlagBit | kNoStencil_GrTextureFlagBit; |
| + desc.fSampleCnt = 0; |
| + desc.fOrigin = origin; |
| + desc.fWidth = size.width; |
| + desc.fHeight = size.height; |
| + skia::RefPtr<GrTexture> texture; |
| + texture = skia::AdoptRef(gr->createUncachedTexture(desc, 0, 0)); |
| + if (!texture.get()) |
| + return false; |
| + |
| + SkImageInfo info = SkImageInfo::MakeN32Premul(desc.fWidth, desc.fHeight); |
| + SkGrPixelRef* pixelRef = SkNEW_ARGS(SkGrPixelRef, (info, texture.get())); |
| + if (!pixelRef) |
| + return false; |
| + bitmap.setInfo(info); |
| + bitmap.setPixelRef(pixelRef)->unref(); |
| + } |
| + |
| + return true; |
| +} |
| + |
| void WebMediaPlayerAndroid::paint(blink::WebCanvas* canvas, |
| const blink::WebRect& rect, |
| unsigned char alpha) { |
| - NOTIMPLEMENTED(); |
| + if (player_type_ != MEDIA_PLAYER_TYPE_URL && player_type_ != MEDIA_PLAYER_TYPE_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.
|
| + return; |
| + scoped_ptr<blink::WebGraphicsContext3DProvider> provider = scoped_ptr<blink::WebGraphicsContext3DProvider>(blink::Platform::current()->createSharedOffscreenGraphicsContext3DProvider()); |
| + if (!provider) |
| + return; |
| + blink::WebGraphicsContext3D* context3D = provider->context3d(); |
| + if (!context3D || !context3D->makeContextCurrent()) |
| + return; |
| + |
| + // Copy video texture into a RGBA texture based bitmap first as video texture on Android is GL_TEXTURE_EXTERNAL_OES |
| + // which is not supported by Skia yet. The bitmap's size needs to be the same as the video and use naturalSize() here. |
| + // Check if we could reuse existing texture based bitmap. |
| + // Otherwise, release existing texture based bitmap and allocate a new one based on video size. |
| + if (!ensureTextureBackedSkBitmap(provider->grContext(), m_bitmap, naturalSize(), kTopLeft_GrSurfaceOrigin, kSkia8888_GrPixelConfig)) |
| + return; |
| + |
| + unsigned textureId = static_cast<unsigned>((m_bitmap.getTexture())->getTextureHandle()); |
| + if (!copyVideoTextureToPlatformTexture(context3D, textureId, 0, GL_RGBA, GL_UNSIGNED_BYTE, true, false)) |
| + return; |
| + |
| + // 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, |
| + // the texture based bitmap will be readbacked to system memory then draw onto the canvas. |
| + SkRect dest; |
| + dest.set(rect.x, rect.y, rect.x + rect.width, rect.y + rect.height); |
| + SkPaint paint; |
| + paint.setAlpha(alpha); |
| + // It is not necessary to pass the dest into the drawBitmap call since all the context have been set up before calling paintCurrentFrameInContext. |
| + canvas->drawBitmapRect(m_bitmap, 0, dest, &paint); |
| } |
| bool WebMediaPlayerAndroid::copyVideoTextureToPlatformTexture( |