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 ContextProviderCommandBuffer
;
27 class WebGraphicsContext3DCommandBufferImpl
;
29 // Glue code to expose functionality needed by media::GpuVideoAccelerator to
30 // RenderViewImpl. This class is entirely an implementation detail of
31 // RenderViewImpl and only has its own header to allow extraction of its
32 // implementation from render_view_impl.cc which is already far too large.
34 // The RendererGpuVideoAcceleratorFactories can be constructed on any thread,
35 // but subsequent calls to all public methods of the class must be called from
36 // the |task_runner_|, as provided during construction.
37 class CONTENT_EXPORT RendererGpuVideoAcceleratorFactories
38 : public media::GpuVideoAcceleratorFactories
{
40 // Takes a ref on |gpu_channel_host| and tests |context| for loss before each
41 // use. Safe to call from any thread.
42 static scoped_refptr
<RendererGpuVideoAcceleratorFactories
> Create(
43 GpuChannelHost
* gpu_channel_host
,
44 const scoped_refptr
<base::SingleThreadTaskRunner
>& task_runner
,
45 const scoped_refptr
<ContextProviderCommandBuffer
>& context_provider
);
47 // media::GpuVideoAcceleratorFactories implementation.
48 scoped_ptr
<media::VideoDecodeAccelerator
> CreateVideoDecodeAccelerator()
50 scoped_ptr
<media::VideoEncodeAccelerator
> CreateVideoEncodeAccelerator()
52 // Creates textures and produces them into mailboxes. Returns true on success
53 // or false on failure.
54 bool CreateTextures(int32 count
,
55 const gfx::Size
& size
,
56 std::vector
<uint32
>* texture_ids
,
57 std::vector
<gpu::Mailbox
>* texture_mailboxes
,
58 uint32 texture_target
) override
;
59 void DeleteTexture(uint32 texture_id
) override
;
60 void WaitSyncPoint(uint32 sync_point
) override
;
61 scoped_ptr
<base::SharedMemory
> CreateSharedMemory(size_t size
) override
;
62 scoped_refptr
<base::SingleThreadTaskRunner
> GetTaskRunner() override
;
63 std::vector
<media::VideoEncodeAccelerator::SupportedProfile
>
64 GetVideoEncodeAcceleratorSupportedProfiles() override
;
67 friend class base::RefCountedThreadSafe
<RendererGpuVideoAcceleratorFactories
>;
68 RendererGpuVideoAcceleratorFactories(
69 GpuChannelHost
* gpu_channel_host
,
70 const scoped_refptr
<base::SingleThreadTaskRunner
>& task_runner
,
71 const scoped_refptr
<ContextProviderCommandBuffer
>& context_provider
);
72 ~RendererGpuVideoAcceleratorFactories() override
;
74 // Helper to bind |context_provider| to the |task_runner_| thread after
78 // Helper to get a pointer to the WebGraphicsContext3DCommandBufferImpl,
79 // if it has not been lost yet.
80 WebGraphicsContext3DCommandBufferImpl
* GetContext3d();
81 GLHelper
* GetGLHelper();
83 scoped_refptr
<base::SingleThreadTaskRunner
> task_runner_
;
84 scoped_refptr
<GpuChannelHost
> gpu_channel_host_
;
85 scoped_refptr
<ContextProviderCommandBuffer
> context_provider_
;
86 scoped_ptr
<GLHelper
> gl_helper_
;
88 // For sending requests to allocate shared memory in the Browser process.
89 scoped_refptr
<ThreadSafeSender
> thread_safe_sender_
;
91 DISALLOW_COPY_AND_ASSIGN(RendererGpuVideoAcceleratorFactories
);
94 } // namespace content
96 #endif // CONTENT_RENDERER_MEDIA_RENDERER_GPU_VIDEO_ACCELERATOR_FACTORIES_H_