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