OLD | NEW |
| (Empty) |
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/common/content_export.h" | |
15 #include "media/filters/gpu_video_accelerator_factories.h" | |
16 #include "third_party/skia/include/core/SkBitmap.h" | |
17 #include "ui/gfx/size.h" | |
18 | |
19 namespace base { | |
20 class MessageLoopProxy; | |
21 class WaitableEvent; | |
22 } | |
23 | |
24 namespace content { | |
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 public methods of the class can be called from any thread, and are | |
34 // internally trampolined to the appropriate thread. GPU/GL-related calls go to | |
35 // the constructor-argument loop (the media thread), and shmem-related calls go | |
36 // to the render thread. | |
37 class CONTENT_EXPORT RendererGpuVideoAcceleratorFactories | |
38 : public media::GpuVideoAcceleratorFactories { | |
39 public: | |
40 // Takes a ref on |gpu_channel_host| and tests |context| for loss before each | |
41 // use. | |
42 RendererGpuVideoAcceleratorFactories( | |
43 GpuChannelHost* gpu_channel_host, | |
44 const scoped_refptr<base::MessageLoopProxy>& message_loop, | |
45 WebGraphicsContext3DCommandBufferImpl* wgc3dcbi); | |
46 | |
47 // media::GpuVideoAcceleratorFactories implementation. | |
48 virtual scoped_ptr<media::VideoDecodeAccelerator> | |
49 CreateVideoDecodeAccelerator( | |
50 media::VideoCodecProfile profile, | |
51 media::VideoDecodeAccelerator::Client* client) OVERRIDE; | |
52 virtual scoped_ptr<media::VideoEncodeAccelerator> | |
53 CreateVideoEncodeAccelerator( | |
54 media::VideoEncodeAccelerator::Client* client) OVERRIDE; | |
55 // Creates textures and produces them into mailboxes. Returns a sync point to | |
56 // wait on before using the mailboxes, or 0 on failure. | |
57 virtual uint32 CreateTextures(int32 count, | |
58 const gfx::Size& size, | |
59 std::vector<uint32>* texture_ids, | |
60 std::vector<gpu::Mailbox>* texture_mailboxes, | |
61 uint32 texture_target) OVERRIDE; | |
62 virtual void DeleteTexture(uint32 texture_id) OVERRIDE; | |
63 virtual void WaitSyncPoint(uint32 sync_point) OVERRIDE; | |
64 virtual void ReadPixels(uint32 texture_id, | |
65 uint32 texture_target, | |
66 const gfx::Size& size, | |
67 const SkBitmap& pixels) OVERRIDE; | |
68 virtual base::SharedMemory* CreateSharedMemory(size_t size) OVERRIDE; | |
69 virtual scoped_refptr<base::MessageLoopProxy> GetMessageLoop() OVERRIDE; | |
70 virtual void Abort() OVERRIDE; | |
71 virtual bool IsAborted() OVERRIDE; | |
72 scoped_refptr<RendererGpuVideoAcceleratorFactories> Clone(); | |
73 | |
74 protected: | |
75 friend class base::RefCountedThreadSafe<RendererGpuVideoAcceleratorFactories>; | |
76 virtual ~RendererGpuVideoAcceleratorFactories(); | |
77 | |
78 private: | |
79 RendererGpuVideoAcceleratorFactories(); | |
80 | |
81 // Helper for the constructor to acquire the ContentGLContext on | |
82 // |message_loop_|. | |
83 void AsyncGetContext(WebGraphicsContext3DCommandBufferImpl* context); | |
84 | |
85 // Async versions of the public methods. They use output parameters instead | |
86 // of return values and each takes a WaitableEvent* param to signal completion | |
87 // (except for DeleteTexture, which is fire-and-forget). | |
88 // AsyncCreateSharedMemory runs on the renderer thread and the rest run on | |
89 // |message_loop_|. | |
90 // AsyncCreateVideoDecodeAccelerator returns its output in the |vda_| member. | |
91 // AsyncCreateVideoEncodeAccelerator returns its output in the |vea_| member. | |
92 void AsyncCreateVideoDecodeAccelerator( | |
93 media::VideoCodecProfile profile, | |
94 media::VideoDecodeAccelerator::Client* client); | |
95 void AsyncCreateVideoEncodeAccelerator( | |
96 media::VideoEncodeAccelerator::Client* client); | |
97 void AsyncCreateTextures(int32 count, | |
98 const gfx::Size& size, | |
99 uint32 texture_target, | |
100 uint32* sync_point); | |
101 void AsyncDeleteTexture(uint32 texture_id); | |
102 void AsyncWaitSyncPoint(uint32 sync_point); | |
103 void AsyncReadPixels(uint32 texture_id, | |
104 uint32 texture_target, | |
105 const gfx::Size& size); | |
106 void AsyncCreateSharedMemory(size_t size); | |
107 void AsyncDestroyVideoDecodeAccelerator(); | |
108 void AsyncDestroyVideoEncodeAccelerator(); | |
109 | |
110 scoped_refptr<base::MessageLoopProxy> message_loop_; | |
111 scoped_refptr<base::MessageLoopProxy> main_message_loop_; | |
112 scoped_refptr<GpuChannelHost> gpu_channel_host_; | |
113 base::WeakPtr<WebGraphicsContext3DCommandBufferImpl> context_; | |
114 | |
115 // This event is signaled if we have been asked to Abort(). | |
116 base::WaitableEvent aborted_waiter_; | |
117 | |
118 // This event is signaled by asynchronous tasks posted to |message_loop_| to | |
119 // indicate their completion. | |
120 // e.g. AsyncCreateVideoDecodeAccelerator()/AsyncCreateTextures() etc. | |
121 base::WaitableEvent message_loop_async_waiter_; | |
122 | |
123 // This event is signaled by asynchronous tasks posted to the renderer thread | |
124 // message loop to indicate their completion. e.g. AsyncCreateSharedMemory. | |
125 base::WaitableEvent render_thread_async_waiter_; | |
126 | |
127 // The vda returned by the CreateVideoDecodeAccelerator function. | |
128 scoped_ptr<media::VideoDecodeAccelerator> vda_; | |
129 | |
130 // The vea returned by the CreateVideoEncodeAccelerator function. | |
131 scoped_ptr<media::VideoEncodeAccelerator> vea_; | |
132 | |
133 // Shared memory segment which is returned by the CreateSharedMemory() | |
134 // function. | |
135 scoped_ptr<base::SharedMemory> shared_memory_segment_; | |
136 | |
137 // Bitmap returned by ReadPixels(). | |
138 SkBitmap read_pixels_bitmap_; | |
139 | |
140 // Textures returned by the CreateTexture() function. | |
141 std::vector<uint32> created_textures_; | |
142 std::vector<gpu::Mailbox> created_texture_mailboxes_; | |
143 | |
144 DISALLOW_COPY_AND_ASSIGN(RendererGpuVideoAcceleratorFactories); | |
145 }; | |
146 | |
147 } // namespace content | |
148 | |
149 #endif // CONTENT_RENDERER_MEDIA_RENDERER_GPU_VIDEO_ACCELERATOR_FACTORIES_H_ | |
OLD | NEW |