OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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_BROWSER_COMPOSITOR_REFLECTOR_IMPL_H_ | 5 #ifndef CONTENT_BROWSER_COMPOSITOR_REFLECTOR_IMPL_H_ |
6 #define CONTENT_BROWSER_COMPOSITOR_REFLECTOR_IMPL_H_ | 6 #define CONTENT_BROWSER_COMPOSITOR_REFLECTOR_IMPL_H_ |
7 | 7 |
8 #include "base/id_map.h" | 8 #include "base/id_map.h" |
9 #include "base/memory/scoped_ptr.h" | 9 #include "base/memory/scoped_ptr.h" |
10 #include "base/memory/weak_ptr.h" | 10 #include "base/memory/weak_ptr.h" |
11 #include "base/synchronization/lock.h" | 11 #include "base/synchronization/lock.h" |
12 #include "content/browser/compositor/image_transport_factory.h" | 12 #include "content/browser/compositor/image_transport_factory.h" |
| 13 #include "content/common/content_export.h" |
13 #include "gpu/command_buffer/common/mailbox_holder.h" | 14 #include "gpu/command_buffer/common/mailbox_holder.h" |
14 #include "ui/compositor/reflector.h" | 15 #include "ui/compositor/reflector.h" |
15 #include "ui/gfx/geometry/size.h" | 16 #include "ui/gfx/geometry/size.h" |
16 | 17 |
17 namespace base { class MessageLoopProxy; } | 18 namespace base { class MessageLoopProxy; } |
18 | 19 |
19 namespace gfx { class Rect; } | 20 namespace gfx { class Rect; } |
20 | 21 |
21 namespace ui { | 22 namespace ui { |
22 class Compositor; | 23 class Compositor; |
23 class Layer; | 24 class Layer; |
24 } | 25 } |
25 | 26 |
26 namespace content { | 27 namespace content { |
27 | 28 |
28 class OwnedMailbox; | 29 class OwnedMailbox; |
29 class BrowserCompositorOutputSurface; | 30 class BrowserCompositorOutputSurface; |
30 | 31 |
31 // A reflector implementation that copies the framebuffer content | 32 // A reflector implementation that copies the framebuffer content |
32 // to the texture, then draw it onto the mirroring compositor. | 33 // to the texture, then draw it onto the mirroring compositor. |
33 class ReflectorImpl : public base::SupportsWeakPtr<ReflectorImpl>, | 34 class CONTENT_EXPORT ReflectorImpl |
34 public ui::Reflector { | 35 : public base::SupportsWeakPtr<ReflectorImpl>, |
| 36 public ui::Reflector { |
35 public: | 37 public: |
36 ReflectorImpl( | 38 ReflectorImpl( |
37 ui::Compositor* mirrored_compositor, | 39 ui::Compositor* mirrored_compositor, |
38 ui::Layer* mirroring_layer, | 40 ui::Layer* mirroring_layer, |
39 IDMap<BrowserCompositorOutputSurface>* output_surface_map, | 41 IDMap<BrowserCompositorOutputSurface>* output_surface_map, |
40 base::MessageLoopProxy* compositor_thread_loop, | 42 base::MessageLoopProxy* compositor_thread_loop, |
41 int surface_id); | 43 int surface_id); |
42 | 44 |
43 ui::Compositor* mirrored_compositor() { | 45 ui::Compositor* mirrored_compositor() { |
44 return GetMain().mirrored_compositor; | 46 return GetMain().mirrored_compositor; |
(...skipping 26 matching lines...) Expand all Loading... |
71 // impl thread. | 73 // impl thread. |
72 void CreateSharedTextureOnMainThread(gfx::Size size); | 74 void CreateSharedTextureOnMainThread(gfx::Size size); |
73 | 75 |
74 // Called when the source surface is bound and available. This must | 76 // Called when the source surface is bound and available. This must |
75 // be called on ImplThread. | 77 // be called on ImplThread. |
76 void OnSourceSurfaceReady(BrowserCompositorOutputSurface* surface); | 78 void OnSourceSurfaceReady(BrowserCompositorOutputSurface* surface); |
77 | 79 |
78 void DetachFromOutputSurface(); | 80 void DetachFromOutputSurface(); |
79 | 81 |
80 private: | 82 private: |
| 83 friend class ReflectorImplTest; |
| 84 |
81 struct MainThreadData { | 85 struct MainThreadData { |
82 MainThreadData(ui::Compositor* mirrored_compositor, | 86 MainThreadData(ui::Compositor* mirrored_compositor, |
83 ui::Layer* mirroring_layer); | 87 ui::Layer* mirroring_layer); |
84 ~MainThreadData(); | 88 ~MainThreadData(); |
85 scoped_refptr<OwnedMailbox> mailbox; | 89 scoped_refptr<OwnedMailbox> mailbox; |
86 bool needs_set_mailbox; | 90 bool needs_set_mailbox; |
87 ui::Compositor* mirrored_compositor; | 91 ui::Compositor* mirrored_compositor; |
88 ui::Layer* mirroring_layer; | 92 ui::Layer* mirroring_layer; |
| 93 bool flip_texture; |
89 }; | 94 }; |
90 | 95 |
91 struct ImplThreadData { | 96 struct ImplThreadData { |
92 explicit ImplThreadData( | 97 explicit ImplThreadData( |
93 IDMap<BrowserCompositorOutputSurface>* output_surface_map); | 98 IDMap<BrowserCompositorOutputSurface>* output_surface_map); |
94 ~ImplThreadData(); | 99 ~ImplThreadData(); |
95 IDMap<BrowserCompositorOutputSurface>* output_surface_map; | 100 IDMap<BrowserCompositorOutputSurface>* output_surface_map; |
96 BrowserCompositorOutputSurface* output_surface; | 101 BrowserCompositorOutputSurface* output_surface; |
97 scoped_ptr<GLHelper> gl_helper; | 102 scoped_ptr<GLHelper> gl_helper; |
98 unsigned texture_id; | 103 unsigned texture_id; |
99 gpu::MailboxHolder mailbox_holder; | 104 gpu::MailboxHolder mailbox_holder; |
100 }; | 105 }; |
101 | 106 |
102 ~ReflectorImpl() override; | 107 ~ReflectorImpl() override; |
103 | 108 |
104 void AttachToOutputSurfaceOnImplThread( | 109 void AttachToOutputSurfaceOnImplThread( |
105 const gpu::MailboxHolder& mailbox_holder, | 110 const gpu::MailboxHolder& mailbox_holder, |
106 BrowserCompositorOutputSurface* surface); | 111 BrowserCompositorOutputSurface* surface); |
107 | 112 |
108 void UpdateTextureSizeOnMainThread(gfx::Size size); | 113 void UpdateTextureSizeOnMainThread(gfx::Size size); |
109 | 114 |
110 // Request full redraw on mirroring compositor. | 115 // Request full redraw on mirroring compositor. |
111 void FullRedrawOnMainThread(gfx::Size size); | 116 void FullRedrawOnMainThread(gfx::Size size); |
112 | 117 |
113 void UpdateSubBufferOnMainThread(gfx::Size size, gfx::Rect rect); | 118 void UpdateSubBufferOnMainThread(const gfx::Size& size, |
| 119 const gfx::Rect& rect); |
114 | 120 |
115 // Request full redraw on mirrored compositor so that | 121 // Request full redraw on mirrored compositor so that |
116 // the full content will be copied to mirroring compositor. | 122 // the full content will be copied to mirroring compositor. |
117 void FullRedrawContentOnMainThread(); | 123 void FullRedrawContentOnMainThread(bool flip_texture); |
118 | 124 |
119 // This exists just to hold a reference to a ReflectorImpl in a post task, | 125 // This exists just to hold a reference to a ReflectorImpl in a post task, |
120 // so the ReflectorImpl gets deleted when the function returns. | 126 // so the ReflectorImpl gets deleted when the function returns. |
121 static void DeleteOnMainThread(scoped_refptr<ReflectorImpl> reflector) {} | 127 static void DeleteOnMainThread(scoped_refptr<ReflectorImpl> reflector) {} |
122 | 128 |
123 MainThreadData& GetMain(); | 129 MainThreadData& GetMain(); |
124 ImplThreadData& GetImpl(); | 130 ImplThreadData& GetImpl(); |
125 | 131 |
126 // Must be accessed only on ImplThread, through GetImpl(). | 132 // Must be accessed only on ImplThread, through GetImpl(). |
127 ImplThreadData impl_unsafe_; | 133 ImplThreadData impl_unsafe_; |
128 | 134 |
129 // Must be accessed only on MainThread, through GetMain(). | 135 // Must be accessed only on MainThread, through GetMain(). |
130 MainThreadData main_unsafe_; | 136 MainThreadData main_unsafe_; |
131 | 137 |
132 // Can be accessed on both. | 138 // Can be accessed on both. |
133 scoped_refptr<base::MessageLoopProxy> impl_message_loop_; | 139 scoped_refptr<base::MessageLoopProxy> impl_message_loop_; |
134 scoped_refptr<base::MessageLoopProxy> main_message_loop_; | 140 scoped_refptr<base::MessageLoopProxy> main_message_loop_; |
135 int surface_id_; | 141 int surface_id_; |
136 }; | 142 }; |
137 | 143 |
138 } // namespace content | 144 } // namespace content |
139 | 145 |
140 #endif // CONTENT_BROWSER_COMPOSITOR_REFLECTOR_IMPL_H_ | 146 #endif // CONTENT_BROWSER_COMPOSITOR_REFLECTOR_IMPL_H_ |
OLD | NEW |