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 8275fb9e2ed83e5694bc6429d2e613176247b1ef..b728bd7874a70790cd3b9b8354dfdf24183c68ae 100644 |
| --- a/content/renderer/media/android/webmediaplayer_android.cc |
| +++ b/content/renderer/media/android/webmediaplayer_android.cc |
| @@ -57,6 +57,8 @@ |
| #include "third_party/skia/include/core/SkCanvas.h" |
| #include "third_party/skia/include/core/SkPaint.h" |
| #include "third_party/skia/include/core/SkTypeface.h" |
| +#include "third_party/skia/include/gpu/GrContext.h" |
| +#include "third_party/skia/include/gpu/SkGrPixelRef.h" |
| #include "ui/gfx/image/image.h" |
| static const uint32 kGLTextureExternalOES = 0x8D65; |
| @@ -84,6 +86,39 @@ void OnReleaseTexture( |
| gl->DeleteTextures(1, &texture_id); |
| } |
| +bool IsSkBitmapProperlySizedTexture(const SkBitmap* bitmap, |
|
dshwang
2014/12/12 17:06:59
EnsureTextureBackedSkBitmap was separated into two
|
| + const gfx::Size& size) { |
| + return bitmap->getTexture() && bitmap->width() == size.width() && |
| + bitmap->height() == size.height(); |
| +} |
| + |
| +bool AllocateSkBitmapTexture(GrContext* gr, |
| + SkBitmap* bitmap, |
| + const gfx::Size& size) { |
| + DCHECK(gr); |
| + GrTextureDesc desc; |
| + // Use kRGBA_8888_GrPixelConfig, not kSkia8888_GrPixelConfig, to avoid |
| + // RGBA to BGRA conversion. |
|
dshwang
2014/12/12 17:06:59
Android can use kSkia8888_GrPixelConfig because RG
no sievers
2014/12/18 23:12:31
You probably know since you are on bug 358198, but
dshwang
2014/12/19 10:15:43
Yes, I tested both video to webgl and video to can
|
| + desc.fConfig = kRGBA_8888_GrPixelConfig; |
| + desc.fFlags = kRenderTarget_GrTextureFlagBit | kNoStencil_GrTextureFlagBit; |
|
no sievers
2014/12/18 23:12:31
while you are in here: mind putting a comment that
dshwang
2014/12/19 10:15:43
I didn't consider about kRenderTarget because I bl
|
| + desc.fSampleCnt = 0; |
| + desc.fOrigin = kTopLeft_GrSurfaceOrigin; |
| + desc.fWidth = size.width(); |
| + desc.fHeight = size.height(); |
| + skia::RefPtr<GrTexture> texture = skia::AdoptRef( |
| + gr->refScratchTexture(desc, GrContext::kExact_ScratchTexMatch)); |
| + if (!texture.get()) |
| + return false; |
| + |
| + SkImageInfo info = SkImageInfo::MakeN32Premul(desc.fWidth, desc.fHeight); |
| + SkGrPixelRef* pixel_ref = SkNEW_ARGS(SkGrPixelRef, (info, texture.get())); |
| + if (!pixel_ref) |
| + return false; |
| + bitmap->setInfo(info); |
| + bitmap->setPixelRef(pixel_ref)->unref(); |
| + return true; |
| +} |
| + |
| class SyncPointClientImpl : public media::VideoFrame::SyncPointClient { |
| public: |
| explicit SyncPointClientImpl( |
| @@ -539,39 +574,6 @@ bool WebMediaPlayerAndroid::didLoadingProgress() { |
| return ret; |
| } |
| -bool WebMediaPlayerAndroid::EnsureTextureBackedSkBitmap(GrContext* gr, |
| - SkBitmap& bitmap, |
| - const WebSize& size, |
| - GrSurfaceOrigin origin, |
| - GrPixelConfig config) { |
| - DCHECK(main_thread_checker_.CalledOnValidThread()); |
| - if (!bitmap.getTexture() || bitmap.width() != size.width |
| - || bitmap.height() != size.height) { |
| - 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, |
| @@ -592,9 +594,11 @@ void WebMediaPlayerAndroid::paint(blink::WebCanvas* canvas, |
| // 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(), bitmap_, |
| - naturalSize(), kTopLeft_GrSurfaceOrigin, kSkia8888_GrPixelConfig)) { |
| - return; |
| + if (!IsSkBitmapProperlySizedTexture(&bitmap_, naturalSize())) { |
| + if (!AllocateSkBitmapTexture(provider->grContext(), &bitmap_, |
| + naturalSize())) { |
| + return; |
| + } |
| } |
| unsigned textureId = static_cast<unsigned>( |