Chromium Code Reviews| Index: content/renderer/render_view_impl.cc |
| diff --git a/content/renderer/render_view_impl.cc b/content/renderer/render_view_impl.cc |
| index aedf3d9a3612779893e504545255a7614cca5f37..ada5fcd11e0e8a1b32a76e5f4fa1ebdb91cb3c27 100644 |
| --- a/content/renderer/render_view_impl.cc |
| +++ b/content/renderer/render_view_impl.cc |
| @@ -52,6 +52,8 @@ |
| #include "content/renderer/devtools_agent.h" |
| #include "content/renderer/external_popup_menu.h" |
| #include "content/renderer/geolocation_dispatcher.h" |
| +#include "content/renderer/gpu/command_buffer_proxy.h" |
| +#include "content/renderer/gpu/gpu_channel_host.h" |
| #include "content/renderer/gpu/webgraphicscontext3d_command_buffer_impl.h" |
| #include "content/renderer/idle_user_detector.h" |
| #include "content/renderer/intents_dispatcher.h" |
| @@ -77,9 +79,11 @@ |
| #include "content/renderer/web_ui_bindings.h" |
| #include "content/renderer/webplugin_delegate_proxy.h" |
| #include "content/renderer/websharedworker_proxy.h" |
| +#include "gpu/command_buffer/client/gles2_implementation.h" |
| #include "media/base/filter_collection.h" |
| #include "media/base/media_switches.h" |
| #include "media/base/message_loop_factory_impl.h" |
| +#include "media/filters/gpu_video_decoder.h" |
| #include "net/base/escape.h" |
| #include "net/base/net_errors.h" |
| #include "net/http/http_util.h" |
| @@ -147,7 +151,6 @@ |
| #include "webkit/glue/webkit_constants.h" |
| #include "webkit/glue/webkit_glue.h" |
| #include "webkit/glue/weburlloader_impl.h" |
| -#include "webkit/media/video_renderer_impl.h" |
| #include "webkit/media/webmediaplayer_impl.h" |
| #include "webkit/plugins/npapi/plugin_list.h" |
| #include "webkit/plugins/npapi/webplugin_delegate.h" |
| @@ -1927,6 +1930,67 @@ WebSharedWorker* RenderViewImpl::createSharedWorker( |
| } |
| } |
| +// Glue code to expose functionality needed by media::GpuVideoDecoder. |
| +class GpuVideoDecoderFactories : public media::GpuVideoDecoder::Factories { |
|
scherkus (not reviewing)
2011/12/09 00:26:20
render_view_impl.cc is approaching 5000 lines
can
Ami GONE FROM CHROMIUM
2011/12/09 22:55:50
Done.
|
| + public: |
| + virtual ~GpuVideoDecoderFactories() {} |
| + // Takes a ref on |gpu_channel_host| and tests |context| for NULL before each |
| + // use. |
| + GpuVideoDecoderFactories(GpuChannelHost* gpu_channel_host, |
| + base::WeakPtr<RendererGLContext> context) |
| + : gpu_channel_host_(gpu_channel_host), context_(context) { |
| + } |
| + |
| + media::VideoDecodeAccelerator* CreateVideoDecodeAccelerator( |
| + media::VideoDecodeAccelerator::Profile profile, |
| + media::VideoDecodeAccelerator::Client* client) OVERRIDE { |
| + if (!context_) |
| + return NULL; |
| + return gpu_channel_host_->CreateVideoDecoder( |
| + context_->GetCommandBufferProxy()->route_id(), profile, client); |
| + } |
| + |
| + virtual bool CreateTextures(int32 count, const gfx::Size& size, |
| + std::vector<uint32>* texture_ids) OVERRIDE { |
| + if (!context_) |
| + return false; |
| + gpu::gles2::GLES2Implementation* gles2 = context_->GetImplementation(); |
| + texture_ids->resize(count); |
| + gles2->GenTextures(count, &texture_ids->at(0)); |
| + for (int i = 0; i < count; ++i) { |
| + gles2->ActiveTexture(GL_TEXTURE0); |
| + uint32 texture_id = texture_ids->at(i); |
| + gles2->BindTexture(GL_TEXTURE_2D, texture_id); |
| + gles2->TexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); |
| + gles2->TexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); |
| + gles2->TexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE); |
| + gles2->TexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE); |
| + gles2->TexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, size.width(), size.height(), |
| + 0, GL_RGBA, GL_UNSIGNED_BYTE, NULL); |
| + } |
| + DCHECK_EQ(gles2->GetError(), static_cast<GLenum>(GL_NO_ERROR)); |
| + return true; |
| + } |
| + |
| + virtual bool DeleteTexture(uint32 texture_id) OVERRIDE { |
| + if (!context_) |
| + return false; |
| + gpu::gles2::GLES2Implementation* gles2 = context_->GetImplementation(); |
| + gles2->DeleteTextures(1, &texture_id); |
| + DCHECK_EQ(gles2->GetError(), static_cast<GLenum>(GL_NO_ERROR)); |
| + return true; |
| + } |
| + |
| + virtual base::SharedMemory* CreateSharedMemory(size_t size) OVERRIDE { |
| + return ChildThread::current()->AllocateSharedMemory(size); |
| + } |
| + |
| + private: |
| + scoped_refptr<GpuChannelHost> gpu_channel_host_; |
| + base::WeakPtr<RendererGLContext> context_; |
| + DISALLOW_IMPLICIT_CONSTRUCTORS(GpuVideoDecoderFactories); |
| +}; |
| + |
| WebMediaPlayer* RenderViewImpl::createMediaPlayer( |
| WebFrame* frame, WebMediaPlayerClient* client) { |
| FOR_EACH_OBSERVER( |
| @@ -1944,6 +2008,25 @@ WebMediaPlayer* RenderViewImpl::createMediaPlayer( |
| collection->AddAudioRenderer(new AudioRendererImpl()); |
| } |
| +#if defined(OS_CHROMEOS) && defined(ARCH_CPU_ARMEL) |
| + // Currently only cros/arm has any HW video decode support in |
| + // GpuVideoDecodeAccelerator so we don't even try to use it on other |
| + // platforms. This is a startup-time optimization. When new VDA |
| + // implementations are added, relax the #if above. |
| + WebKit::WebGraphicsContext3D* wk_context3d = webview()->graphicsContext3D(); |
| + if (wk_context3d) { |
| + WebGraphicsContext3DCommandBufferImpl* context3d = |
| + static_cast<WebGraphicsContext3DCommandBufferImpl*>(wk_context3d); |
| + GpuChannelHost* gpu_channel_host = |
| + RenderThreadImpl::current()->EstablishGpuChannelSync( |
| + content::CAUSE_FOR_GPU_LAUNCH_VIDEODECODEACCELERATOR_INITIALIZE); |
| + collection->AddVideoDecoder(new media::GpuVideoDecoder( |
| + MessageLoop::current(), |
| + new GpuVideoDecoderFactories(gpu_channel_host, |
| + context3d->context()->AsWeakPtr()))); |
| + } |
| +#endif |
| + |
| scoped_ptr<webkit_media::WebMediaPlayerImpl> result( |
| new webkit_media::WebMediaPlayerImpl(client, |
| AsWeakPtr(), |