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

Side by Side Diff: content/browser/compositor/reflector_impl.h

Issue 228083002: Make ReflectorImpl use mailboxes (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 6 years, 8 months 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 | Annotate | Revision Log
OLDNEW
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 "gpu/command_buffer/common/mailbox_holder.h"
13 #include "ui/compositor/reflector.h" 14 #include "ui/compositor/reflector.h"
14 #include "ui/gfx/size.h" 15 #include "ui/gfx/size.h"
15 16
16 namespace base { class MessageLoopProxy; } 17 namespace base { class MessageLoopProxy; }
17 18
18 namespace gfx { class Rect; } 19 namespace gfx { class Rect; }
19 20
20 namespace ui { 21 namespace ui {
21 class Compositor; 22 class Compositor;
22 class Layer; 23 class Layer;
23 } 24 }
24 25
25 namespace content { 26 namespace content {
26 27
28 class OwnedMailbox;
27 class BrowserCompositorOutputSurface; 29 class BrowserCompositorOutputSurface;
28 30
29 // A reflector implementation that copies the framebuffer content 31 // A reflector implementation that copies the framebuffer content
30 // to the texture, then draw it onto the mirroring compositor. 32 // to the texture, then draw it onto the mirroring compositor.
31 class ReflectorImpl : public ImageTransportFactoryObserver, 33 class ReflectorImpl : public base::SupportsWeakPtr<ReflectorImpl>,
32 public base::SupportsWeakPtr<ReflectorImpl>,
33 public ui::Reflector { 34 public ui::Reflector {
34 public: 35 public:
35 ReflectorImpl( 36 ReflectorImpl(
36 ui::Compositor* mirrored_compositor, 37 ui::Compositor* mirrored_compositor,
37 ui::Layer* mirroring_layer, 38 ui::Layer* mirroring_layer,
38 IDMap<BrowserCompositorOutputSurface>* output_surface_map, 39 IDMap<BrowserCompositorOutputSurface>* output_surface_map,
39 int surface_id); 40 int surface_id);
40 41
41 ui::Compositor* mirrored_compositor() { 42 ui::Compositor* mirrored_compositor() {
42 return mirrored_compositor_; 43 return mirrored_compositor_;
43 } 44 }
44 45
45 void InitOnImplThread(); 46 void InitOnImplThread(const gpu::MailboxHolder& mailbox_holder);
46 void Shutdown(); 47 void Shutdown();
47 void ShutdownOnImplThread(); 48 void ShutdownOnImplThread();
48 49
49 // Post a task to attach the reflector to the output surface onto ImplThread. 50 // Post a task to attach the reflector to the output surface onto ImplThread.
50 void ReattachToOutputSurfaceFromMainThread( 51 void ReattachToOutputSurfaceFromMainThread(
51 BrowserCompositorOutputSurface* surface); 52 BrowserCompositorOutputSurface* surface);
52 53
53 // ui::Reflector implementation. 54 // ui::Reflector implementation.
54 virtual void OnMirroringCompositorResized() OVERRIDE; 55 virtual void OnMirroringCompositorResized() OVERRIDE;
55 56
56 // ImageTransportFactoryObsever implementation.
57 virtual void OnLostResources() OVERRIDE;
58
59 // Called when the output surface's size has changed.
60 // This must be called on ImplThread.
61 void OnReshape(gfx::Size size);
62
63 // Called in |BrowserCompositorOutputSurface::SwapBuffers| to copy 57 // Called in |BrowserCompositorOutputSurface::SwapBuffers| to copy
64 // the full screen image to the |texture_id_|. This must be called 58 // the full screen image to the |texture_id_|. This must be called
65 // on ImplThread. 59 // on ImplThread.
66 void OnSwapBuffers(); 60 void OnSwapBuffers();
67 61
68 // Called in |BrowserCompositorOutputSurface::PostSubBuffer| copy 62 // Called in |BrowserCompositorOutputSurface::PostSubBuffer| copy
69 // the sub image given by |rect| to the texture.This must be called 63 // the sub image given by |rect| to the texture.This must be called
70 // on ImplThread. 64 // on ImplThread.
71 void OnPostSubBuffer(gfx::Rect rect); 65 void OnPostSubBuffer(gfx::Rect rect);
72 66
73 // Create a shared texture that will be used to copy the content of 67 // Create a shared texture that will be used to copy the content of
74 // mirrored compositor to the mirroring compositor. This should 68 // mirrored compositor to the mirroring compositor. This should
75 // be posted to the main thread when the output is attached in 69 // be posted to the main thread when the output is attached in
76 // impl thread. 70 // impl thread.
77 void CreateSharedTextureOnMainThread(gfx::Size size); 71 void CreateSharedTextureOnMainThread(gfx::Size size);
78 72
79 // Called when the source surface is bound and available. This must 73 // Called when the source surface is bound and available. This must
80 // be called on ImplThread. 74 // be called on ImplThread.
81 void OnSourceSurfaceReady(int surface_id); 75 void OnSourceSurfaceReady(BrowserCompositorOutputSurface* surface);
76
77 void DetachFromOutputSurface();
82 78
83 private: 79 private:
84 virtual ~ReflectorImpl(); 80 virtual ~ReflectorImpl();
85 81
86 void AttachToOutputSurfaceOnImplThread( 82 void AttachToOutputSurfaceOnImplThread(
83 const gpu::MailboxHolder& mailbox_holder,
87 BrowserCompositorOutputSurface* surface); 84 BrowserCompositorOutputSurface* surface);
88 85
89 void UpdateTextureSizeOnMainThread(gfx::Size size); 86 void UpdateTextureSizeOnMainThread(gfx::Size size);
90 87
91 // Request full redraw on mirroring compositor. 88 // Request full redraw on mirroring compositor.
92 void FullRedrawOnMainThread(gfx::Size size); 89 void FullRedrawOnMainThread(gfx::Size size);
93 90
94 void UpdateSubBufferOnMainThread(gfx::Size size, gfx::Rect rect); 91 void UpdateSubBufferOnMainThread(gfx::Size size, gfx::Rect rect);
95 92
96 // Request full redraw on mirrored compositor so that 93 // Request full redraw on mirrored compositor so that
97 // the full content will be copied to mirroring compositor. 94 // the full content will be copied to mirroring compositor.
98 void FullRedrawContentOnMainThread(); 95 void FullRedrawContentOnMainThread();
99 96
100 // This exists just to hold a reference to a ReflectorImpl in a post task, 97 // This exists just to hold a reference to a ReflectorImpl in a post task,
101 // so the ReflectorImpl gets deleted when the function returns. 98 // so the ReflectorImpl gets deleted when the function returns.
102 static void DeleteOnMainThread(scoped_refptr<ReflectorImpl> reflector) {} 99 static void DeleteOnMainThread(scoped_refptr<ReflectorImpl> reflector) {}
103 100
104 // These variables are initialized on MainThread before 101 // Must be accessed only on ImplThread.
danakj 2014/04/08 16:08:01 This starts to remind me of cc::ThreadProxy. Consi
piman 2014/04/08 23:17:46 Done.
105 // the reflector is attached to the output surface. Once 102 IDMap<BrowserCompositorOutputSurface>* output_surface_map_;
106 // attached, they must be accessed only on ImplThraed unless 103 BrowserCompositorOutputSurface* output_surface_;
107 // the context is lost. When the context is lost, these 104 scoped_ptr<GLHelper> gl_helper_;
108 // will be re-ininitiailzed when the new output-surface 105 unsigned impl_thread_texture_id_;
109 // is created on MainThread. 106 gpu::MailboxHolder impl_thread_mailbox_holder_;
110 int texture_id_;
111 base::Lock texture_lock_;
112 gfx::Size texture_size_; 107 gfx::Size texture_size_;
113 108
114 // Must be accessed only on ImplThread.
115 IDMap<BrowserCompositorOutputSurface>* output_surface_map_;
116 scoped_ptr<GLHelper> gl_helper_;
117
118 // Must be accessed only on MainThread. 109 // Must be accessed only on MainThread.
110 scoped_refptr<OwnedMailbox> main_thread_mailbox_;
111 bool needs_set_mailbox_;
119 ui::Compositor* mirrored_compositor_; 112 ui::Compositor* mirrored_compositor_;
120 ui::Compositor* mirroring_compositor_;
121 ui::Layer* mirroring_layer_; 113 ui::Layer* mirroring_layer_;
122 scoped_refptr<ui::Texture> shared_texture_;
123 scoped_refptr<base::MessageLoopProxy> impl_message_loop_; 114 scoped_refptr<base::MessageLoopProxy> impl_message_loop_;
124 scoped_refptr<base::MessageLoopProxy> main_message_loop_; 115 scoped_refptr<base::MessageLoopProxy> main_message_loop_;
danakj 2014/04/08 16:08:01 Can this only be accessed on MainThread also? Mayb
piman 2014/04/08 23:17:46 Done.
125 int surface_id_; 116 int surface_id_;
126 }; 117 };
127 118
128 } // namespace content 119 } // namespace content
129 120
130 #endif // CONTENT_BROWSER_COMPOSITOR_REFLECTOR_IMPL_H_ 121 #endif // CONTENT_BROWSER_COMPOSITOR_REFLECTOR_IMPL_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698