1 // Copyright 2013 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 #ifndef CONTENT_RENDERER_MEDIA_RENDERER_GPU_VIDEO_ACCELERATOR_FACTORIES_H_
6 #define CONTENT_RENDERER_MEDIA_RENDERER_GPU_VIDEO_ACCELERATOR_FACTORIES_H_
10 #include "base/basictypes.h"
11 #include "base/memory/ref_counted.h"
12 #include "base/memory/weak_ptr.h"
13 #include "base/synchronization/waitable_event.h"
14 #include "content/child/thread_safe_sender.h"
15 #include "content/common/content_export.h"
16 #include "media/renderers/gpu_video_accelerator_factories.h"
17 #include "ui/gfx/geometry/size.h"
24 class GpuMemoryBufferManager
;
28 class ContextProviderCommandBuffer
;
31 class WebGraphicsContext3DCommandBufferImpl
;
33 // Glue code to expose functionality needed by media::GpuVideoAccelerator to
34 // RenderViewImpl. This class is entirely an implementation detail of
35 // RenderViewImpl and only has its own header to allow extraction of its
36 // implementation from render_view_impl.cc which is already far too large.
38 // The RendererGpuVideoAcceleratorFactories can be constructed on any thread,
39 // but subsequent calls to all public methods of the class must be called from
40 // the |task_runner_|, as provided during construction.
41 class CONTENT_EXPORT RendererGpuVideoAcceleratorFactories
42 : public media::GpuVideoAcceleratorFactories
{
44 // Takes a ref on |gpu_channel_host| and tests |context| for loss before each
45 // use. Safe to call from any thread.
46 static scoped_refptr
<RendererGpuVideoAcceleratorFactories
> Create(
47 GpuChannelHost
* gpu_channel_host
,
48 const scoped_refptr
<base::SingleThreadTaskRunner
>& task_runner
,
49 const scoped_refptr
<ContextProviderCommandBuffer
>& context_provider
,
50 bool enable_gpu_memory_buffer_video_frames
,
51 unsigned image_texture_target
,
52 bool enable_video_accelerator
);
54 bool IsGpuVideoAcceleratorEnabled() override
;
55 // media::GpuVideoAcceleratorFactories implementation.
56 scoped_ptr
<media::VideoDecodeAccelerator
> CreateVideoDecodeAccelerator()
58 scoped_ptr
<media::VideoEncodeAccelerator
> CreateVideoEncodeAccelerator()
60 // Creates textures and produces them into mailboxes. Returns true on success
61 // or false on failure.
62 bool CreateTextures(int32 count
,
63 const gfx::Size
& size
,
64 std::vector
<uint32
>* texture_ids
,
65 std::vector
<gpu::Mailbox
>* texture_mailboxes
,
66 uint32 texture_target
) override
;
67 void DeleteTexture(uint32 texture_id
) override
;
68 void WaitSyncPoint(uint32 sync_point
) override
;
70 scoped_ptr
<gfx::GpuMemoryBuffer
> AllocateGpuMemoryBuffer(
71 const gfx::Size
& size
,
72 gfx::BufferFormat format
,
73 gfx::BufferUsage usage
) override
;
75 bool ShouldUseGpuMemoryBuffersForVideoFrames() const override
;
76 unsigned ImageTextureTarget() override
;
77 media::VideoPixelFormat
VideoFrameOutputFormat() override
;
78 gpu::gles2::GLES2Interface
* GetGLES2Interface() override
;
79 scoped_ptr
<base::SharedMemory
> CreateSharedMemory(size_t size
) override
;
80 scoped_refptr
<base::SingleThreadTaskRunner
> GetTaskRunner() override
;
82 std::vector
<media::VideoDecodeAccelerator::SupportedProfile
>
83 GetVideoDecodeAcceleratorSupportedProfiles() override
;
84 std::vector
<media::VideoEncodeAccelerator::SupportedProfile
>
85 GetVideoEncodeAcceleratorSupportedProfiles() override
;
88 friend class base::RefCountedThreadSafe
<RendererGpuVideoAcceleratorFactories
>;
89 RendererGpuVideoAcceleratorFactories(
90 GpuChannelHost
* gpu_channel_host
,
91 const scoped_refptr
<base::SingleThreadTaskRunner
>& task_runner
,
92 const scoped_refptr
<ContextProviderCommandBuffer
>& context_provider
,
93 bool enable_gpu_memory_buffer_video_frames
,
94 unsigned image_texture_target
,
95 bool enable_video_accelerator
);
97 ~RendererGpuVideoAcceleratorFactories() override
;
99 // Helper to bind |context_provider| to the |task_runner_| thread after
103 // Helper to get a pointer to the WebGraphicsContext3DCommandBufferImpl,
104 // if it has not been lost yet.
105 WebGraphicsContext3DCommandBufferImpl
* GetContext3d();
106 GLHelper
* GetGLHelper();
108 scoped_refptr
<base::SingleThreadTaskRunner
> task_runner_
;
109 scoped_refptr
<GpuChannelHost
> gpu_channel_host_
;
110 scoped_refptr
<ContextProviderCommandBuffer
> context_provider_
;
112 // Whether gpu memory buffers should be used to hold video frames data.
113 bool enable_gpu_memory_buffer_video_frames_
;
114 const unsigned image_texture_target_
;
115 // Whether video acceleration encoding/decoding should be enabled.
116 const bool video_accelerator_enabled_
;
118 scoped_ptr
<GLHelper
> gl_helper_
;
119 gpu::GpuMemoryBufferManager
* const gpu_memory_buffer_manager_
;
121 // For sending requests to allocate shared memory in the Browser process.
122 scoped_refptr
<ThreadSafeSender
> thread_safe_sender_
;
124 DISALLOW_COPY_AND_ASSIGN(RendererGpuVideoAcceleratorFactories
);
127 } // namespace content
129 #endif // CONTENT_RENDERER_MEDIA_RENDERER_GPU_VIDEO_ACCELERATOR_FACTORIES_H_