Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(20)

Side by Side Diff: content/renderer/media/renderer_gpu_video_accelerator_factories.h

Issue 27420004: Remove threading from RendererGpuVideoAcceleratorFactories (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@dthread
Patch Set: d731420c Comment update, 'git cl format', rebase Created 7 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 all public methods of the class must be called from
37 // exceptions (which can be called from any thread, as they are internally 36 // the |message_loop_proxy_|, as provided during construction.
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,
44 const scoped_refptr<base::MessageLoopProxy>& message_loop_proxy,
48 const scoped_refptr<ContextProviderCommandBuffer>& context_provider); 45 const scoped_refptr<ContextProviderCommandBuffer>& context_provider);
49 46
50 // media::GpuVideoAcceleratorFactories implementation. 47 // media::GpuVideoAcceleratorFactories implementation.
51 // CreateVideoDecodeAccelerator() is safe to call from any thread.
52 virtual scoped_ptr<media::VideoDecodeAccelerator> 48 virtual scoped_ptr<media::VideoDecodeAccelerator>
53 CreateVideoDecodeAccelerator( 49 CreateVideoDecodeAccelerator(
54 media::VideoCodecProfile profile, 50 media::VideoCodecProfile profile,
55 media::VideoDecodeAccelerator::Client* client) OVERRIDE; 51 media::VideoDecodeAccelerator::Client* client) OVERRIDE;
56 virtual scoped_ptr<media::VideoEncodeAccelerator> 52 virtual scoped_ptr<media::VideoEncodeAccelerator>
57 CreateVideoEncodeAccelerator( 53 CreateVideoEncodeAccelerator(
58 media::VideoEncodeAccelerator::Client* client) OVERRIDE; 54 media::VideoEncodeAccelerator::Client* client) OVERRIDE;
59 // Creates textures and produces them into mailboxes. Returns a sync point to 55 // Creates textures and produces them into mailboxes. Returns a sync point to
60 // wait on before using the mailboxes, or 0 on failure. 56 // wait on before using the mailboxes, or 0 on failure.
61 virtual uint32 CreateTextures(int32 count, 57 virtual uint32 CreateTextures(int32 count,
62 const gfx::Size& size, 58 const gfx::Size& size,
63 std::vector<uint32>* texture_ids, 59 std::vector<uint32>* texture_ids,
64 std::vector<gpu::Mailbox>* texture_mailboxes, 60 std::vector<gpu::Mailbox>* texture_mailboxes,
65 uint32 texture_target) OVERRIDE; 61 uint32 texture_target) OVERRIDE;
66 virtual void DeleteTexture(uint32 texture_id) OVERRIDE; 62 virtual void DeleteTexture(uint32 texture_id) OVERRIDE;
67 virtual void WaitSyncPoint(uint32 sync_point) OVERRIDE; 63 virtual void WaitSyncPoint(uint32 sync_point) OVERRIDE;
68 // ReadPixels() is safe to call from any thread.
69 virtual void ReadPixels(uint32 texture_id, 64 virtual void ReadPixels(uint32 texture_id,
70 const gfx::Size& size, 65 const gfx::Size& size,
71 const SkBitmap& pixels) OVERRIDE; 66 const SkBitmap& pixels) OVERRIDE;
72 virtual base::SharedMemory* CreateSharedMemory(size_t size) OVERRIDE; 67 virtual base::SharedMemory* CreateSharedMemory(size_t size) OVERRIDE;
73 virtual scoped_refptr<base::MessageLoopProxy> GetMessageLoop() OVERRIDE; 68 virtual scoped_refptr<base::MessageLoopProxy> GetMessageLoop() OVERRIDE;
74 virtual void Abort() OVERRIDE;
75 virtual bool IsAborted() OVERRIDE;
76 scoped_refptr<RendererGpuVideoAcceleratorFactories> Clone();
77 69
78 protected: 70 protected:
79 friend class base::RefCountedThreadSafe<RendererGpuVideoAcceleratorFactories>; 71 friend class base::RefCountedThreadSafe<RendererGpuVideoAcceleratorFactories>;
80 virtual ~RendererGpuVideoAcceleratorFactories(); 72 virtual ~RendererGpuVideoAcceleratorFactories();
81 73
82 private: 74 private:
83 RendererGpuVideoAcceleratorFactories();
84
85 // Helper to get a pointer to the WebGraphicsContext3DCommandBufferImpl, 75 // Helper to get a pointer to the WebGraphicsContext3DCommandBufferImpl,
86 // if it has not been lost yet. 76 // if it has not been lost yet.
87 WebGraphicsContext3DCommandBufferImpl* GetContext3d(); 77 WebGraphicsContext3DCommandBufferImpl* GetContext3d();
88 78
89 // Helper for the constructor to acquire the ContentGLContext on 79 scoped_refptr<base::MessageLoopProxy> message_loop_proxy_;
90 // |message_loop_|.
91 void AsyncBindContext();
92
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_;
105 scoped_refptr<GpuChannelHost> gpu_channel_host_; 80 scoped_refptr<GpuChannelHost> gpu_channel_host_;
106 scoped_refptr<ContextProviderCommandBuffer> context_provider_; 81 scoped_refptr<ContextProviderCommandBuffer> context_provider_;
107 82
108 // For sending requests to allocate shared memory in the Browser process. 83 // For sending requests to allocate shared memory in the Browser process.
109 scoped_refptr<ThreadSafeSender> thread_safe_sender_; 84 scoped_refptr<ThreadSafeSender> thread_safe_sender_;
110 85
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); 86 DISALLOW_COPY_AND_ASSIGN(RendererGpuVideoAcceleratorFactories);
126 }; 87 };
127 88
128 } // namespace content 89 } // namespace content
129 90
130 #endif // CONTENT_RENDERER_MEDIA_RENDERER_GPU_VIDEO_ACCELERATOR_FACTORIES_H_ 91 #endif // CONTENT_RENDERER_MEDIA_RENDERER_GPU_VIDEO_ACCELERATOR_FACTORIES_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698