1 // Copyright (c) 2013 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.
5 #ifndef CONTENT_BROWSER_AURA_REFLECTOR_IMPL_H_
6 #define CONTENT_BROWSER_AURA_REFLECTOR_IMPL_H_
8 #include "base/id_map.h"
9 #include "base/memory/scoped_ptr.h"
10 #include "base/memory/weak_ptr.h"
11 #include "content/browser/aura/image_transport_factory.h"
12 #include "ui/compositor/reflector.h"
13 #include "ui/gfx/size.h"
15 namespace base
{ class MessageLoopProxy
; }
17 namespace gfx
{ class Rect
; }
26 class BrowserCompositorOutputSurface
;
28 // A reflector implementation that copies the framebuffer content
29 // to the texture, then draw it onto the mirroring compositor.
30 class ReflectorImpl
: public ImageTransportFactoryObserver
,
31 public base::SupportsWeakPtr
<ReflectorImpl
>,
32 public ui::Reflector
{
35 ui::Compositor
* mirrored_compositor
,
36 ui::Layer
* mirroring_layer
,
37 IDMap
<BrowserCompositorOutputSurface
>* output_surface_map
,
40 ui::Compositor
* mirrored_compositor() {
41 return mirrored_compositor_
;
44 void InitOnImplThread();
46 void ShutdownOnImplThread();
48 // This must be called on ImplThread, or before the surface is passed to
50 void AttachToOutputSurface(BrowserCompositorOutputSurface
* surface
);
52 // ui::Reflector implementation.
53 virtual void OnMirroringCompositorResized() OVERRIDE
;
55 // ImageTransportFactoryObsever implementation.
56 virtual void OnLostResources() OVERRIDE
;
58 // Called when the output surface's size has changed.
59 // This must be called on ImplThread.
60 void OnReshape(gfx::Size size
);
62 // Called in |BrowserCompositorOutputSurface::SwapBuffers| to copy
63 // the full screen image to the |texture_id_|. This must be called
67 // Called in |BrowserCompositorOutputSurface::PostSubBuffer| copy
68 // the sub image given by |rect| to the texture.This must be called
70 void OnPostSubBuffer(gfx::Rect rect
);
72 // Create a shared texture that will be used to copy the content of
73 // mirrored compositor to the mirroring compositor. This must be
74 // called before the reflector is attached to OutputSurface to avoid
75 // race with ImplThread accessing |texture_id_|.
76 void CreateSharedTexture();
78 // Called when the source surface is bound and available. This must
79 // be called on ImplThread.
80 void OnSourceSurfaceReady(int surface_id
);
83 virtual ~ReflectorImpl();
85 void UpdateTextureSizeOnMainThread(gfx::Size size
);
87 // Request full redraw on mirroring compositor.
88 void FullRedrawOnMainThread(gfx::Size size
);
90 void UpdateSubBufferOnMainThread(gfx::Size size
, gfx::Rect rect
);
92 // Request full redraw on mirrored compositor so that
93 // the full content will be copied to mirroring compositor.
94 void FullRedrawContentOnMainThread();
96 // This exists just to hold a reference to a ReflectorImpl in a post task,
97 // so the ReflectorImpl gets deleted when the function returns.
98 static void DeleteOnMainThread(scoped_refptr
<ReflectorImpl
> reflector
) {}
100 // These variables are initialized on MainThread before
101 // the reflector is attached to the output surface. Once
102 // attached, they must be accessed only on ImplThraed unless
103 // the context is lost. When the context is lost, these
104 // will be re-ininitiailzed when the new output-surface
105 // is created on MainThread.
107 gfx::Size texture_size_
;
109 // Must be accessed only on ImplThread.
110 IDMap
<BrowserCompositorOutputSurface
>* output_surface_map_
;
111 scoped_ptr
<GLHelper
> gl_helper_
;
113 // Must be accessed only on MainThread.
114 ui::Compositor
* mirrored_compositor_
;
115 ui::Compositor
* mirroring_compositor_
;
116 ui::Layer
* mirroring_layer_
;
117 scoped_refptr
<ui::Texture
> shared_texture_
;
118 scoped_refptr
<base::MessageLoopProxy
> impl_message_loop_
;
119 scoped_refptr
<base::MessageLoopProxy
> main_message_loop_
;
123 } // namespace content
125 #endif // CONTENT_BROWSER_AURA_REFLECTOR_IMPL_H_