OLD | NEW |
| (Empty) |
1 // Copyright (c) 2012 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_DECODER_FACTORIES_H_ | |
6 #define CONTENT_RENDERER_MEDIA_RENDERER_GPU_VIDEO_DECODER_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_decoder_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::GpuVideoDecoder 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 RendererGpuVideoDecoderFactories | |
38 : public media::GpuVideoDecoderFactories { | |
39 public: | |
40 // Takes a ref on |gpu_channel_host| and tests |context| for loss before each | |
41 // use. | |
42 RendererGpuVideoDecoderFactories( | |
43 GpuChannelHost* gpu_channel_host, | |
44 const scoped_refptr<base::MessageLoopProxy>& message_loop, | |
45 WebGraphicsContext3DCommandBufferImpl* wgc3dcbi); | |
46 | |
47 // media::GpuVideoDecoderFactories implementation. | |
48 virtual media::VideoDecodeAccelerator* CreateVideoDecodeAccelerator( | |
49 media::VideoCodecProfile profile, | |
50 media::VideoDecodeAccelerator::Client* client) OVERRIDE; | |
51 // Creates textures and produces them into mailboxes. Returns a sync point to | |
52 // wait on before using the mailboxes, or 0 on failure. | |
53 virtual uint32 CreateTextures( | |
54 int32 count, const gfx::Size& size, | |
55 std::vector<uint32>* texture_ids, | |
56 std::vector<gpu::Mailbox>* texture_mailboxes, | |
57 uint32 texture_target) OVERRIDE; | |
58 virtual void DeleteTexture(uint32 texture_id) OVERRIDE; | |
59 virtual void WaitSyncPoint(uint32 sync_point) OVERRIDE; | |
60 virtual void ReadPixels(uint32 texture_id, | |
61 uint32 texture_target, | |
62 const gfx::Size& size, | |
63 const SkBitmap& pixels) OVERRIDE; | |
64 virtual base::SharedMemory* CreateSharedMemory(size_t size) OVERRIDE; | |
65 virtual scoped_refptr<base::MessageLoopProxy> GetMessageLoop() OVERRIDE; | |
66 virtual void Abort() OVERRIDE; | |
67 virtual bool IsAborted() OVERRIDE; | |
68 | |
69 // Makes a copy of |this|. | |
70 scoped_refptr<media::GpuVideoDecoderFactories> Clone(); | |
71 | |
72 protected: | |
73 friend class base::RefCountedThreadSafe<RendererGpuVideoDecoderFactories>; | |
74 virtual ~RendererGpuVideoDecoderFactories(); | |
75 | |
76 private: | |
77 RendererGpuVideoDecoderFactories(); | |
78 | |
79 // Helper for the constructor to acquire the ContentGLContext on | |
80 // |message_loop_|. | |
81 void AsyncGetContext(WebGraphicsContext3DCommandBufferImpl* context); | |
82 | |
83 // Async versions of the public methods. They use output parameters instead | |
84 // of return values and each takes a WaitableEvent* param to signal completion | |
85 // (except for DeleteTexture, which is fire-and-forget). | |
86 // AsyncCreateSharedMemory runs on the renderer thread and the rest run on | |
87 // |message_loop_|. | |
88 // The AsyncCreateVideoDecodeAccelerator returns its output in the vda_ | |
89 // member. | |
90 void AsyncCreateVideoDecodeAccelerator( | |
91 media::VideoCodecProfile profile, | |
92 media::VideoDecodeAccelerator::Client* client); | |
93 void AsyncCreateTextures(int32 count, const gfx::Size& size, | |
94 uint32 texture_target, uint32* sync_point); | |
95 void AsyncDeleteTexture(uint32 texture_id); | |
96 void AsyncWaitSyncPoint(uint32 sync_point); | |
97 void AsyncReadPixels(uint32 texture_id, uint32 texture_target, | |
98 const gfx::Size& size); | |
99 void AsyncCreateSharedMemory(size_t size); | |
100 void AsyncDestroyVideoDecodeAccelerator(); | |
101 | |
102 scoped_refptr<base::MessageLoopProxy> message_loop_; | |
103 scoped_refptr<base::MessageLoopProxy> main_message_loop_; | |
104 scoped_refptr<GpuChannelHost> gpu_channel_host_; | |
105 base::WeakPtr<WebGraphicsContext3DCommandBufferImpl> context_; | |
106 | |
107 // This event is signaled if we have been asked to Abort(). | |
108 base::WaitableEvent aborted_waiter_; | |
109 | |
110 // This event is signaled by asynchronous tasks posted to |message_loop_| to | |
111 // indicate their completion. | |
112 // e.g. AsyncCreateVideoDecodeAccelerator()/AsyncCreateTextures() etc. | |
113 base::WaitableEvent message_loop_async_waiter_; | |
114 | |
115 // This event is signaled by asynchronous tasks posted to the renderer thread | |
116 // message loop to indicate their completion. e.g. AsyncCreateSharedMemory. | |
117 base::WaitableEvent render_thread_async_waiter_; | |
118 | |
119 // The vda returned by the CreateVideoAcclelerator function. | |
120 scoped_ptr<media::VideoDecodeAccelerator> vda_; | |
121 | |
122 // Shared memory segment which is returned by the CreateSharedMemory() | |
123 // function. | |
124 scoped_ptr<base::SharedMemory> shared_memory_segment_; | |
125 | |
126 // Bitmap returned by ReadPixels(). | |
127 SkBitmap read_pixels_bitmap_; | |
128 | |
129 // Textures returned by the CreateTexture() function. | |
130 std::vector<uint32> created_textures_; | |
131 std::vector<gpu::Mailbox> created_texture_mailboxes_; | |
132 | |
133 DISALLOW_COPY_AND_ASSIGN(RendererGpuVideoDecoderFactories); | |
134 }; | |
135 | |
136 } // namespace content | |
137 | |
138 #endif // CONTENT_RENDERER_MEDIA_RENDERER_GPU_VIDEO_DECODER_FACTORIES_H_ | |
OLD | NEW |