Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1752)

Unified Diff: content/renderer/media/android/webmediaplayer_android.cc

Issue 445013002: media: Optimize HW Video to 2D Canvas copy. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: rebase to ToT Created 5 years, 12 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
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 1f794858d303dd65971fde646850b74f020aed8c..fd0f53634963e086c52f249386a6c3614c328791 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,40 @@ void OnReleaseTexture(
gl->DeleteTextures(1, &texture_id);
}
+bool IsSkBitmapProperlySizedTexture(const SkBitmap* bitmap,
+ 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.
+ desc.fConfig = kRGBA_8888_GrPixelConfig;
+ // kRenderTarget_GrTextureFlagBit avoids a copy before readback in skia.
+ desc.fFlags = kRenderTarget_GrTextureFlagBit | kNoStencil_GrTextureFlagBit;
+ 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(
@@ -540,39 +576,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,
@@ -593,9 +596,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>(

Powered by Google App Engine
This is Rietveld 408576698