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

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: rebase 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 GetMain().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:
80 struct MainThreadData {
81 MainThreadData(ui::Compositor* mirrored_compositor,
82 ui::Layer* mirroring_layer);
83 ~MainThreadData();
84 scoped_refptr<OwnedMailbox> mailbox;
85 bool needs_set_mailbox;
86 ui::Compositor* mirrored_compositor;
87 ui::Layer* mirroring_layer;
88 };
89
90 struct ImplThreadData {
91 explicit ImplThreadData(
92 IDMap<BrowserCompositorOutputSurface>* output_surface_map);
93 ~ImplThreadData();
94 IDMap<BrowserCompositorOutputSurface>* output_surface_map;
95 BrowserCompositorOutputSurface* output_surface;
96 scoped_ptr<GLHelper> gl_helper;
97 unsigned texture_id;
98 gpu::MailboxHolder mailbox_holder;
99 };
100
84 virtual ~ReflectorImpl(); 101 virtual ~ReflectorImpl();
85 102
86 void AttachToOutputSurfaceOnImplThread( 103 void AttachToOutputSurfaceOnImplThread(
104 const gpu::MailboxHolder& mailbox_holder,
87 BrowserCompositorOutputSurface* surface); 105 BrowserCompositorOutputSurface* surface);
88 106
89 void UpdateTextureSizeOnMainThread(gfx::Size size); 107 void UpdateTextureSizeOnMainThread(gfx::Size size);
90 108
91 // Request full redraw on mirroring compositor. 109 // Request full redraw on mirroring compositor.
92 void FullRedrawOnMainThread(gfx::Size size); 110 void FullRedrawOnMainThread(gfx::Size size);
93 111
94 void UpdateSubBufferOnMainThread(gfx::Size size, gfx::Rect rect); 112 void UpdateSubBufferOnMainThread(gfx::Size size, gfx::Rect rect);
95 113
96 // Request full redraw on mirrored compositor so that 114 // Request full redraw on mirrored compositor so that
97 // the full content will be copied to mirroring compositor. 115 // the full content will be copied to mirroring compositor.
98 void FullRedrawContentOnMainThread(); 116 void FullRedrawContentOnMainThread();
99 117
100 // This exists just to hold a reference to a ReflectorImpl in a post task, 118 // This exists just to hold a reference to a ReflectorImpl in a post task,
101 // so the ReflectorImpl gets deleted when the function returns. 119 // so the ReflectorImpl gets deleted when the function returns.
102 static void DeleteOnMainThread(scoped_refptr<ReflectorImpl> reflector) {} 120 static void DeleteOnMainThread(scoped_refptr<ReflectorImpl> reflector) {}
103 121
104 // These variables are initialized on MainThread before 122 MainThreadData& GetMain();
105 // the reflector is attached to the output surface. Once 123 ImplThreadData& GetImpl();
106 // attached, they must be accessed only on ImplThraed unless
107 // the context is lost. When the context is lost, these
108 // will be re-ininitiailzed when the new output-surface
109 // is created on MainThread.
110 int texture_id_;
111 base::Lock texture_lock_;
112 gfx::Size texture_size_;
113 124
114 // Must be accessed only on ImplThread. 125 // Must be accessed only on ImplThread, through GetImpl().
115 IDMap<BrowserCompositorOutputSurface>* output_surface_map_; 126 ImplThreadData impl_unsafe_;
116 scoped_ptr<GLHelper> gl_helper_;
117 127
118 // Must be accessed only on MainThread. 128 // Must be accessed only on MainThread, through GetMain().
119 ui::Compositor* mirrored_compositor_; 129 MainThreadData main_unsafe_;
120 ui::Compositor* mirroring_compositor_; 130
121 ui::Layer* mirroring_layer_; 131 // Can be accessed on both.
122 scoped_refptr<ui::Texture> shared_texture_;
123 scoped_refptr<base::MessageLoopProxy> impl_message_loop_; 132 scoped_refptr<base::MessageLoopProxy> impl_message_loop_;
124 scoped_refptr<base::MessageLoopProxy> main_message_loop_; 133 scoped_refptr<base::MessageLoopProxy> main_message_loop_;
125 int surface_id_; 134 int surface_id_;
126 }; 135 };
127 136
128 } // namespace content 137 } // namespace content
129 138
130 #endif // CONTENT_BROWSER_COMPOSITOR_REFLECTOR_IMPL_H_ 139 #endif // CONTENT_BROWSER_COMPOSITOR_REFLECTOR_IMPL_H_
OLDNEW
« no previous file with comments | « content/browser/compositor/owned_mailbox.h ('k') | content/browser/compositor/reflector_impl.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698