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

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: Resolve comments, rebase to ToT 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 869bab6d0665d9fb960cc26f90a00cd2b5320684..6af79afb7c87a7a62f44f7c4600c326d97e7471e 100644
--- a/content/renderer/media/android/webmediaplayer_android.cc
+++ b/content/renderer/media/android/webmediaplayer_android.cc
@@ -42,9 +42,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,9 +53,10 @@
#include "third_party/WebKit/public/web/WebSecurityOrigin.h"
#include "third_party/WebKit/public/web/WebView.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;
@@ -83,23 +83,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) {
}
@@ -540,83 +523,40 @@ 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,
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)
+ // Don't allow clients to copy an encrypted video frame.
+ if (needs_external_surface_)
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)) {
- return;
+ scoped_refptr<VideoFrame> video_frame;
+ {
+ base::AutoLock auto_lock(current_frame_lock_);
+ video_frame = current_frame_;
}
- unsigned textureId = static_cast<unsigned>(
- (bitmap_.getTexture())->getTextureHandle());
- if (!copyVideoTextureToPlatformTexture(context3D, textureId, 0,
- GL_RGBA, GL_UNSIGNED_BYTE, true, false)) {
- return;
+ gfx::Rect gfx_rect(rect);
+ media::Context3DProvider provider{nullptr, nullptr};
+ if (canvas->getGrContext() ||
+ (video_frame.get() &&
scherkus (not reviewing) 2014/10/30 20:40:11 nit: is the .get() needed?
danakj 2014/10/30 21:02:52 It is for scoped_refptr for now, which this is. Bu
dshwang 2014/10/31 09:29:16 danakj, thank you for answering. scoped_refptr::op
+ video_frame->format() == media::VideoFrame::NATIVE_TEXTURE)) {
+ scoped_refptr<cc::ContextProvider> context_provider =
+ RenderThreadImpl::current()->SharedMainThreadContextProvider();
+ // GPU Process crashed.
+ if (!context_provider.get())
+ return;
+ provider = {context_provider->ContextGL(), context_provider->GrContext()};
}
-
- // 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);
+ skcanvas_video_renderer_.Paint(video_frame.get(),
+ canvas,
+ gfx_rect,
+ alpha,
+ mode,
+ media::VIDEO_ROTATION_0,
+ provider);
}
bool WebMediaPlayerAndroid::copyVideoTextureToPlatformTexture(
@@ -641,40 +581,28 @@ 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();
+ media::SkCanvasVideoRenderer::CopyVideoFrameTextureToGLTexture(
+ gl,
+ video_frame.get(),
scherkus (not reviewing) 2014/10/30 20:40:11 nit: is .get() needed?
dshwang 2014/10/31 09:29:16 not needed. done.
+ texture,
+ level,
+ internal_format,
+ type,
+ premultiply_alpha,
+ flip_y);
return true;
}

Powered by Google App Engine
This is Rietveld 408576698