OLD | NEW |
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #ifndef CONTENT_RENDERER_MEDIA_RENDERER_GPU_VIDEO_ACCELERATOR_FACTORIES_H_ | 5 #ifndef CONTENT_RENDERER_MEDIA_RENDERER_GPU_VIDEO_ACCELERATOR_FACTORIES_H_ |
6 #define CONTENT_RENDERER_MEDIA_RENDERER_GPU_VIDEO_ACCELERATOR_FACTORIES_H_ | 6 #define CONTENT_RENDERER_MEDIA_RENDERER_GPU_VIDEO_ACCELERATOR_FACTORIES_H_ |
7 | 7 |
8 #include <vector> | 8 #include <vector> |
9 | 9 |
10 #include "base/basictypes.h" | 10 #include "base/basictypes.h" |
11 #include "base/memory/ref_counted.h" | 11 #include "base/memory/ref_counted.h" |
12 #include "base/memory/weak_ptr.h" | 12 #include "base/memory/weak_ptr.h" |
13 #include "base/synchronization/waitable_event.h" | 13 #include "base/synchronization/waitable_event.h" |
14 #include "content/child/thread_safe_sender.h" | 14 #include "content/child/thread_safe_sender.h" |
15 #include "content/common/content_export.h" | 15 #include "content/common/content_export.h" |
16 #include "media/filters/gpu_video_accelerator_factories.h" | 16 #include "media/filters/gpu_video_accelerator_factories.h" |
| 17 #include "third_party/skia/include/core/SkBitmap.h" |
17 #include "ui/gfx/size.h" | 18 #include "ui/gfx/size.h" |
18 | 19 |
19 namespace base { | 20 namespace base { |
20 class WaitableEvent; | 21 class WaitableEvent; |
21 } | 22 } |
22 | 23 |
23 namespace content { | 24 namespace content { |
24 class ContextProviderCommandBuffer; | 25 class ContextProviderCommandBuffer; |
25 class GpuChannelHost; | 26 class GpuChannelHost; |
26 class WebGraphicsContext3DCommandBufferImpl; | 27 class WebGraphicsContext3DCommandBufferImpl; |
27 | 28 |
28 // Glue code to expose functionality needed by media::GpuVideoAccelerator to | 29 // Glue code to expose functionality needed by media::GpuVideoAccelerator to |
29 // RenderViewImpl. This class is entirely an implementation detail of | 30 // RenderViewImpl. This class is entirely an implementation detail of |
30 // RenderViewImpl and only has its own header to allow extraction of its | 31 // 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 // implementation from render_view_impl.cc which is already far too large. |
32 // | 33 // |
33 // The RendererGpuVideoAcceleratorFactories can be constructed on any thread, | 34 // The RendererGpuVideoAcceleratorFactories can be constructed on any thread. |
34 // but subsequent calls to all public methods of the class must be called from | 35 // Most public methods of the class must be called from the media thread. The |
35 // the |message_loop_proxy_|, as provided during construction. | 36 // exceptions (which can be called from any thread, as they are internally |
| 37 // trampolined) are: |
| 38 // * CreateVideoDecodeAccelerator() |
| 39 // * ReadPixels() |
36 class CONTENT_EXPORT RendererGpuVideoAcceleratorFactories | 40 class CONTENT_EXPORT RendererGpuVideoAcceleratorFactories |
37 : public media::GpuVideoAcceleratorFactories { | 41 : public media::GpuVideoAcceleratorFactories { |
38 public: | 42 public: |
39 // Takes a ref on |gpu_channel_host| and tests |context| for loss before each | 43 // Takes a ref on |gpu_channel_host| and tests |context| for loss before each |
40 // use. Safe to call from any thread. | 44 // use. Safe to call from any thread. |
41 RendererGpuVideoAcceleratorFactories( | 45 RendererGpuVideoAcceleratorFactories( |
42 GpuChannelHost* gpu_channel_host, | 46 GpuChannelHost* gpu_channel_host, |
43 const scoped_refptr<base::MessageLoopProxy>& message_loop_proxy, | |
44 const scoped_refptr<ContextProviderCommandBuffer>& context_provider); | 47 const scoped_refptr<ContextProviderCommandBuffer>& context_provider); |
45 | 48 |
46 // media::GpuVideoAcceleratorFactories implementation. | 49 // media::GpuVideoAcceleratorFactories implementation. |
| 50 // CreateVideoDecodeAccelerator() is safe to call from any thread. |
47 virtual scoped_ptr<media::VideoDecodeAccelerator> | 51 virtual scoped_ptr<media::VideoDecodeAccelerator> |
48 CreateVideoDecodeAccelerator( | 52 CreateVideoDecodeAccelerator( |
49 media::VideoCodecProfile profile, | 53 media::VideoCodecProfile profile, |
50 media::VideoDecodeAccelerator::Client* client) OVERRIDE; | 54 media::VideoDecodeAccelerator::Client* client) OVERRIDE; |
51 virtual scoped_ptr<media::VideoEncodeAccelerator> | 55 virtual scoped_ptr<media::VideoEncodeAccelerator> |
52 CreateVideoEncodeAccelerator( | 56 CreateVideoEncodeAccelerator( |
53 media::VideoEncodeAccelerator::Client* client) OVERRIDE; | 57 media::VideoEncodeAccelerator::Client* client) OVERRIDE; |
54 // Creates textures and produces them into mailboxes. Returns a sync point to | 58 // Creates textures and produces them into mailboxes. Returns a sync point to |
55 // wait on before using the mailboxes, or 0 on failure. | 59 // wait on before using the mailboxes, or 0 on failure. |
56 virtual uint32 CreateTextures(int32 count, | 60 virtual uint32 CreateTextures(int32 count, |
57 const gfx::Size& size, | 61 const gfx::Size& size, |
58 std::vector<uint32>* texture_ids, | 62 std::vector<uint32>* texture_ids, |
59 std::vector<gpu::Mailbox>* texture_mailboxes, | 63 std::vector<gpu::Mailbox>* texture_mailboxes, |
60 uint32 texture_target) OVERRIDE; | 64 uint32 texture_target) OVERRIDE; |
61 virtual void DeleteTexture(uint32 texture_id) OVERRIDE; | 65 virtual void DeleteTexture(uint32 texture_id) OVERRIDE; |
62 virtual void WaitSyncPoint(uint32 sync_point) OVERRIDE; | 66 virtual void WaitSyncPoint(uint32 sync_point) OVERRIDE; |
| 67 // ReadPixels() is safe to call from any thread. |
63 virtual void ReadPixels(uint32 texture_id, | 68 virtual void ReadPixels(uint32 texture_id, |
64 const gfx::Rect& visible_rect, | 69 const gfx::Size& size, |
65 const SkBitmap& pixels) OVERRIDE; | 70 const SkBitmap& pixels) OVERRIDE; |
66 virtual base::SharedMemory* CreateSharedMemory(size_t size) OVERRIDE; | 71 virtual base::SharedMemory* CreateSharedMemory(size_t size) OVERRIDE; |
67 virtual scoped_refptr<base::SingleThreadTaskRunner> GetTaskRunner() OVERRIDE; | 72 virtual scoped_refptr<base::SingleThreadTaskRunner> GetTaskRunner() OVERRIDE; |
| 73 virtual void Abort() OVERRIDE; |
| 74 virtual bool IsAborted() OVERRIDE; |
| 75 scoped_refptr<RendererGpuVideoAcceleratorFactories> Clone(); |
68 | 76 |
69 protected: | 77 protected: |
70 friend class base::RefCountedThreadSafe<RendererGpuVideoAcceleratorFactories>; | 78 friend class base::RefCountedThreadSafe<RendererGpuVideoAcceleratorFactories>; |
71 virtual ~RendererGpuVideoAcceleratorFactories(); | 79 virtual ~RendererGpuVideoAcceleratorFactories(); |
72 | 80 |
73 private: | 81 private: |
| 82 RendererGpuVideoAcceleratorFactories(); |
| 83 |
74 // Helper to get a pointer to the WebGraphicsContext3DCommandBufferImpl, | 84 // Helper to get a pointer to the WebGraphicsContext3DCommandBufferImpl, |
75 // if it has not been lost yet. | 85 // if it has not been lost yet. |
76 WebGraphicsContext3DCommandBufferImpl* GetContext3d(); | 86 WebGraphicsContext3DCommandBufferImpl* GetContext3d(); |
77 | 87 |
| 88 // Helper for the constructor to acquire the ContentGLContext on |
| 89 // |task_runner_|. |
| 90 void AsyncBindContext(); |
| 91 |
| 92 // Async versions of the public methods, run on |task_runner_|. |
| 93 // They use output parameters instead of return values and each takes |
| 94 // a WaitableEvent* param to signal completion (except for DeleteTexture, |
| 95 // which is fire-and-forget). |
| 96 // AsyncCreateVideoDecodeAccelerator returns its output in the |vda_| member. |
| 97 void AsyncCreateVideoDecodeAccelerator( |
| 98 media::VideoCodecProfile profile, |
| 99 media::VideoDecodeAccelerator::Client* client); |
| 100 void AsyncReadPixels(uint32 texture_id, const gfx::Size& size); |
| 101 void AsyncDestroyVideoDecodeAccelerator(); |
| 102 |
78 scoped_refptr<base::SingleThreadTaskRunner> task_runner_; | 103 scoped_refptr<base::SingleThreadTaskRunner> task_runner_; |
79 scoped_refptr<GpuChannelHost> gpu_channel_host_; | 104 scoped_refptr<GpuChannelHost> gpu_channel_host_; |
80 scoped_refptr<ContextProviderCommandBuffer> context_provider_; | 105 scoped_refptr<ContextProviderCommandBuffer> context_provider_; |
81 | 106 |
82 // For sending requests to allocate shared memory in the Browser process. | 107 // For sending requests to allocate shared memory in the Browser process. |
83 scoped_refptr<ThreadSafeSender> thread_safe_sender_; | 108 scoped_refptr<ThreadSafeSender> thread_safe_sender_; |
84 | 109 |
| 110 // This event is signaled if we have been asked to Abort(). |
| 111 base::WaitableEvent aborted_waiter_; |
| 112 |
| 113 // This event is signaled by asynchronous tasks posted to |task_runner_| to |
| 114 // indicate their completion. |
| 115 // e.g. AsyncCreateVideoDecodeAccelerator()/AsyncCreateTextures() etc. |
| 116 base::WaitableEvent task_runner_async_waiter_; |
| 117 |
| 118 // The vda returned by the CreateVideoDecodeAccelerator function. |
| 119 scoped_ptr<media::VideoDecodeAccelerator> vda_; |
| 120 |
| 121 // Bitmap returned by ReadPixels(). |
| 122 SkBitmap read_pixels_bitmap_; |
| 123 |
85 DISALLOW_COPY_AND_ASSIGN(RendererGpuVideoAcceleratorFactories); | 124 DISALLOW_COPY_AND_ASSIGN(RendererGpuVideoAcceleratorFactories); |
86 }; | 125 }; |
87 | 126 |
88 } // namespace content | 127 } // namespace content |
89 | 128 |
90 #endif // CONTENT_RENDERER_MEDIA_RENDERER_GPU_VIDEO_ACCELERATOR_FACTORIES_H_ | 129 #endif // CONTENT_RENDERER_MEDIA_RENDERER_GPU_VIDEO_ACCELERATOR_FACTORIES_H_ |
OLD | NEW |