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

Unified Diff: media/blink/webmediaplayer_impl.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: media/blink/webmediaplayer_impl.cc
diff --git a/media/blink/webmediaplayer_impl.cc b/media/blink/webmediaplayer_impl.cc
index ce5dc2d6dffd5142675967cab4ebb2daa350adb4..97821eaf3d3f534e32bb9f1a643c7b19a832a271 100644
--- a/media/blink/webmediaplayer_impl.cc
+++ b/media/blink/webmediaplayer_impl.cc
@@ -22,8 +22,6 @@
#include "base/synchronization/waitable_event.h"
#include "cc/blink/web_layer_impl.h"
#include "cc/layers/video_layer.h"
-#include "gpu/GLES2/gl2extchromium.h"
-#include "gpu/command_buffer/common/mailbox_holder.h"
#include "media/audio/null_audio_sink.h"
#include "media/base/audio_hardware_config.h"
#include "media/base/bind_to_current_loop.h"
@@ -38,7 +36,6 @@
#include "media/blink/webaudiosourceprovider_impl.h"
#include "media/blink/webinbandtexttrack_impl.h"
#include "media/blink/webmediaplayer_delegate.h"
-#include "media/blink/webmediaplayer_params.h"
#include "media/blink/webmediaplayer_util.h"
#include "media/blink/webmediasource_impl.h"
#include "media/filters/audio_renderer_impl.h"
@@ -60,6 +57,7 @@
#include "third_party/WebKit/public/web/WebLocalFrame.h"
#include "third_party/WebKit/public/web/WebSecurityOrigin.h"
#include "third_party/WebKit/public/web/WebView.h"
+#include "webkit/common/gpu/webgraphicscontext3d_impl.h"
using blink::WebCanvas;
using blink::WebMediaPlayer;
@@ -88,23 +86,6 @@ namespace {
const double kMinRate = 0.0625;
const double kMaxRate = 16.0;
-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_;
-};
-
} // namespace
namespace media {
@@ -158,6 +139,8 @@ WebMediaPlayerImpl::WebMediaPlayerImpl(
client_(client),
delegate_(delegate),
defer_load_cb_(params.defer_load_cb()),
+ shared_main_thread_context_provider_cb_(
+ params.shared_main_thread_context_provider_cb()),
gpu_factories_(params.gpu_factories()),
supports_save_(true),
chunk_demuxer_(NULL),
@@ -529,13 +512,22 @@ void WebMediaPlayerImpl::paint(blink::WebCanvas* canvas,
GetCurrentFrameFromCompositor();
gfx::Rect gfx_rect(rect);
-
- skcanvas_video_renderer_.Paint(video_frame,
+ media::SkCanvasVideoRenderer::Context3DProvider provider{NULL, NULL};
+ if (!shared_main_thread_context_provider_cb_.is_null()) {
+ cc::ContextProvider* context_provider =
+ shared_main_thread_context_provider_cb_.Run();
scherkus (not reviewing) 2014/10/13 17:48:41 is the context guaranteed to not change throughout
+ if (context_provider) {
+ provider.gl = context_provider->ContextGL();
+ provider.gr_context = context_provider->GrContext();
+ }
+ }
+ skcanvas_video_renderer_.Paint(video_frame.get(),
canvas,
gfx_rect,
alpha,
mode,
- pipeline_metadata_.video_rotation);
+ pipeline_metadata_.video_rotation,
+ &provider);
}
bool WebMediaPlayerImpl::hasSingleSecurityOrigin() const {
@@ -595,43 +587,24 @@ bool WebMediaPlayerImpl::copyVideoTextureToPlatformTexture(
scoped_refptr<VideoFrame> video_frame =
GetCurrentFrameFromCompositor();
- if (!video_frame.get())
- return false;
- if (video_frame->format() != VideoFrame::NATIVE_TEXTURE)
- return false;
-
- const gpu::MailboxHolder* mailbox_holder = video_frame->mailbox_holder();
- if (mailbox_holder->texture_target != GL_TEXTURE_2D)
+ if (!video_frame.get() ||
+ video_frame->format() != media::VideoFrame::NATIVE_TEXTURE) {
return false;
+ }
- web_graphics_context->waitSyncPoint(mailbox_holder->sync_point);
- uint32 source_texture = web_graphics_context->createAndConsumeTextureCHROMIUM(
- GL_TEXTURE_2D, mailbox_holder->mailbox.name);
-
- // The video is stored in a 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,
- source_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(source_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