Upstream version 5.34.104.0
[platform/framework/web/crosswalk.git] / src / content / renderer / media / renderer_gpu_video_accelerator_factories.h
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.
4
5 #ifndef CONTENT_RENDERER_MEDIA_RENDERER_GPU_VIDEO_ACCELERATOR_FACTORIES_H_
6 #define CONTENT_RENDERER_MEDIA_RENDERER_GPU_VIDEO_ACCELERATOR_FACTORIES_H_
7
8 #include <vector>
9
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/filters/gpu_video_accelerator_factories.h"
17 #include "ui/gfx/size.h"
18
19 namespace base {
20 class WaitableEvent;
21 }
22
23 namespace content {
24 class ContextProviderCommandBuffer;
25 class GpuChannelHost;
26 class WebGraphicsContext3DCommandBufferImpl;
27
28 // Glue code to expose functionality needed by media::GpuVideoAccelerator to
29 // RenderViewImpl.  This class is entirely an implementation detail of
30 // RenderViewImpl and only has its own header to allow extraction of its
31 // implementation from render_view_impl.cc which is already far too large.
32 //
33 // The RendererGpuVideoAcceleratorFactories can be constructed on any thread,
34 // but subsequent calls to all public methods of the class must be called from
35 // the |message_loop_proxy_|, as provided during construction.
36 class CONTENT_EXPORT RendererGpuVideoAcceleratorFactories
37     : public media::GpuVideoAcceleratorFactories {
38  public:
39   // Takes a ref on |gpu_channel_host| and tests |context| for loss before each
40   // use.  Safe to call from any thread.
41   RendererGpuVideoAcceleratorFactories(
42       GpuChannelHost* gpu_channel_host,
43       const scoped_refptr<base::MessageLoopProxy>& message_loop_proxy,
44       const scoped_refptr<ContextProviderCommandBuffer>& context_provider);
45
46   // media::GpuVideoAcceleratorFactories implementation.
47   virtual scoped_ptr<media::VideoDecodeAccelerator>
48       CreateVideoDecodeAccelerator(
49           media::VideoCodecProfile profile,
50           media::VideoDecodeAccelerator::Client* client) OVERRIDE;
51   virtual scoped_ptr<media::VideoEncodeAccelerator>
52       CreateVideoEncodeAccelerator(
53           media::VideoEncodeAccelerator::Client* client) OVERRIDE;
54   // Creates textures and produces them into mailboxes. Returns a sync point to
55   // wait on before using the mailboxes, or 0 on failure.
56   virtual uint32 CreateTextures(int32 count,
57                                 const gfx::Size& size,
58                                 std::vector<uint32>* texture_ids,
59                                 std::vector<gpu::Mailbox>* texture_mailboxes,
60                                 uint32 texture_target) OVERRIDE;
61   virtual void DeleteTexture(uint32 texture_id) OVERRIDE;
62   virtual void WaitSyncPoint(uint32 sync_point) OVERRIDE;
63   virtual void ReadPixels(uint32 texture_id,
64                           const gfx::Rect& visible_rect,
65                           const SkBitmap& pixels) OVERRIDE;
66   virtual base::SharedMemory* CreateSharedMemory(size_t size) OVERRIDE;
67   virtual scoped_refptr<base::SingleThreadTaskRunner> GetTaskRunner() OVERRIDE;
68
69  protected:
70   friend class base::RefCountedThreadSafe<RendererGpuVideoAcceleratorFactories>;
71   virtual ~RendererGpuVideoAcceleratorFactories();
72
73  private:
74   // Helper to get a pointer to the WebGraphicsContext3DCommandBufferImpl,
75   // if it has not been lost yet.
76   WebGraphicsContext3DCommandBufferImpl* GetContext3d();
77
78   scoped_refptr<base::SingleThreadTaskRunner> task_runner_;
79   scoped_refptr<GpuChannelHost> gpu_channel_host_;
80   scoped_refptr<ContextProviderCommandBuffer> context_provider_;
81
82   // For sending requests to allocate shared memory in the Browser process.
83   scoped_refptr<ThreadSafeSender> thread_safe_sender_;
84
85   DISALLOW_COPY_AND_ASSIGN(RendererGpuVideoAcceleratorFactories);
86 };
87
88 }  // namespace content
89
90 #endif  // CONTENT_RENDERER_MEDIA_RENDERER_GPU_VIDEO_ACCELERATOR_FACTORIES_H_