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

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. Address nits Created 6 years, 2 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 e2b9e7e9c53f62be1264f3b97f4534222d6dfc22..7f38f298d34e429bb9b68133e2f962b9505a4221 100644
--- a/content/renderer/media/android/webmediaplayer_android.cc
+++ b/content/renderer/media/android/webmediaplayer_android.cc
@@ -43,9 +43,8 @@
#include "media/blink/webmediaplayer_delegate.h"
#include "media/blink/webmediaplayer_util.h"
#include "net/base/mime_util.h"
-#include "third_party/WebKit/public/platform/Platform.h"
#include "third_party/WebKit/public/platform/WebContentDecryptionModuleResult.h"
-#include "third_party/WebKit/public/platform/WebGraphicsContext3DProvider.h"
+#include "third_party/WebKit/public/platform/WebGraphicsContext3D.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"
@@ -54,10 +53,12 @@
#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"
#include "ui/gfx/image/image.h"
+#include "webkit/common/gpu/context_provider_web_context.h"
+#include "webkit/common/gpu/webgraphicscontext3d_impl.h"
static const uint32 kGLTextureExternalOES = 0x8D65;
static const int kSDKVersionToSupportSecurityOriginCheck = 20;
@@ -84,23 +85,6 @@ void OnReleaseTexture(
gl->DeleteTextures(1, &texture_id);
}
-class SyncPointClientImpl : public media::VideoFrame::SyncPointClient {
- public:
- explicit SyncPointClientImpl(
- blink::WebGraphicsContext3D* web_graphics_context)
- : web_graphics_context_(web_graphics_context) {}
- virtual ~SyncPointClientImpl() {}
- virtual uint32 InsertSyncPoint() override {
- return web_graphics_context_->insertSyncPoint();
- }
- virtual void WaitSyncPoint(uint32 sync_point) override {
- web_graphics_context_->waitSyncPoint(sync_point);
- }
-
- private:
- blink::WebGraphicsContext3D* web_graphics_context_;
-};
-
// Used for calls to decryptor_ready_cb_ where the result can be ignored.
void DoNothing(bool) {
}
@@ -541,39 +525,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) {
@@ -585,45 +536,28 @@ void WebMediaPlayerAndroid::paint(blink::WebCanvas* canvas,
unsigned char alpha,
SkXfermode::Mode mode) {
DCHECK(main_thread_checker_.CalledOnValidThread());
- scoped_ptr<blink::WebGraphicsContext3DProvider> provider =
- scoped_ptr<blink::WebGraphicsContext3DProvider>(blink::Platform::current(
- )->createSharedOffscreenGraphicsContext3DProvider());
- if (!provider)
- return;
- blink::WebGraphicsContext3D* context3D = provider->context3d();
- if (!context3D)
- 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(), bitmap_,
- naturalSize(), kTopLeft_GrSurfaceOrigin, kSkia8888_GrPixelConfig)) {
+ // Don't allow clients to copy an encrypted video frame.
+ if (needs_external_surface_)
return;
- }
- unsigned textureId = static_cast<unsigned>(
- (bitmap_.getTexture())->getTextureHandle());
- if (!copyVideoTextureToPlatformTexture(context3D, textureId, 0,
- GL_RGBA, GL_UNSIGNED_BYTE, true, false)) {
- return;
+ scoped_refptr<VideoFrame> video_frame;
+ {
+ base::AutoLock auto_lock(current_frame_lock_);
+ video_frame = current_frame_;
}
- // 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);
- paint.setXfermodeMode(mode);
- // 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(bitmap_, 0, dest, &paint);
+ gfx::Rect gfx_rect(rect);
+ scoped_refptr<cc::ContextProvider> context_provider =
+ RenderThreadImpl::current()->SharedMainThreadContextProvider();
+ media::SkCanvasVideoRenderer::Context3DProvider provider{
+ context_provider->ContextGL(), context_provider->GrContext()};
+ skcanvas_video_renderer_.Paint(video_frame.get(),
+ canvas,
+ gfx_rect,
+ alpha,
+ mode,
+ media::VIDEO_ROTATION_0,
+ &provider);
}
bool WebMediaPlayerAndroid::copyVideoTextureToPlatformTexture(
@@ -648,40 +582,27 @@ bool WebMediaPlayerAndroid::copyVideoTextureToPlatformTexture(
if (!video_frame.get() ||
video_frame->format() != media::VideoFrame::NATIVE_TEXTURE)
return false;
+
+#if DCHECK_IS_ON
const gpu::MailboxHolder* mailbox_holder = video_frame->mailbox_holder();
DCHECK((!is_remote_ &&
mailbox_holder->texture_target == GL_TEXTURE_EXTERNAL_OES) ||
(is_remote_ && mailbox_holder->texture_target == GL_TEXTURE_2D));
+#endif
- web_graphics_context->waitSyncPoint(mailbox_holder->sync_point);
-
- // Ensure the target of texture is set before copyTextureCHROMIUM, otherwise
- // an invalid texture target may be used for copy texture.
- uint32 src_texture = web_graphics_context->createAndConsumeTextureCHROMIUM(
- mailbox_holder->texture_target, mailbox_holder->mailbox.name);
-
- // The video is stored in an unmultiplied format, so premultiply if
- // necessary.
- web_graphics_context->pixelStorei(GL_UNPACK_PREMULTIPLY_ALPHA_CHROMIUM,
- premultiply_alpha);
-
- // Application itself needs to take care of setting the right flip_y
- // value down to get the expected result.
- // flip_y==true means to reverse the video orientation while
- // flip_y==false means to keep the intrinsic orientation.
- web_graphics_context->pixelStorei(GL_UNPACK_FLIP_Y_CHROMIUM, flip_y);
- web_graphics_context->copyTextureCHROMIUM(GL_TEXTURE_2D, src_texture,
- texture, level, internal_format,
- type);
- web_graphics_context->pixelStorei(GL_UNPACK_FLIP_Y_CHROMIUM, false);
- web_graphics_context->pixelStorei(GL_UNPACK_PREMULTIPLY_ALPHA_CHROMIUM,
- false);
-
- web_graphics_context->deleteTexture(src_texture);
- web_graphics_context->flush();
-
- SyncPointClientImpl client(web_graphics_context);
- video_frame->UpdateReleaseSyncPoint(&client);
+ // TODO(dshwang): need more elegant way to convert WebGraphicsContext3D to
+ // GLES2Interface.
+ gpu::gles2::GLES2Interface* gl =
+ static_cast<webkit::gpu::WebGraphicsContext3DImpl*>(web_graphics_context)
+ ->GetGLInterface();
+ skcanvas_video_renderer_.CopyVideoFrameToTexture(gl,
scherkus (not reviewing) 2014/10/15 17:10:23 use SkCanvasVideoRenderer:: instead of the object
+ video_frame.get(),
+ texture,
+ level,
+ internal_format,
+ type,
+ premultiply_alpha,
+ flip_y);
return true;
}

Powered by Google App Engine
This is Rietveld 408576698