OLD | NEW |
(Empty) | |
| 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. |
| 4 |
| 5 #ifndef CONTENT_BROWSER_AURA_BROWSER_COMPOSITOR_OUTPUT_SURFACE_CAPTURER_H_ |
| 6 #define CONTENT_BROWSER_AURA_BROWSER_COMPOSITOR_OUTPUT_SURFACE_CAPTURER_H_ |
| 7 |
| 8 #include <list> |
| 9 |
| 10 #include "base/id_map.h" |
| 11 #include "base/memory/ref_counted.h" |
| 12 #include "base/memory/weak_ptr.h" |
| 13 #include "content/browser/aura/browser_compositor_output_surface.h" |
| 14 #include "content/common/gpu/surface_capturer.h" |
| 15 #include "ui/gfx/rect.h" |
| 16 #include "ui/gfx/size.h" |
| 17 |
| 18 namespace base { |
| 19 |
| 20 class MessageLoopProxy; |
| 21 class SharedMemory; |
| 22 |
| 23 } // namespace base |
| 24 |
| 25 namespace content { |
| 26 |
| 27 // This class implements the SurfaceCapturer interface for capturing from a |
| 28 // BrowserCompositorOutputSurface. It essentially proxies the SurfaceCapturer |
| 29 // between the compositor's impl thread (which BrowserCompositorOutputSurface |
| 30 // runs on), stored in |compositor_impl_message_loop_proxy_|, and the |
| 31 // compositor's own main thread (presently the UI thread), stored in |
| 32 // |ui_compositor_message_loop_proxy_|. |
| 33 // BrowserCompositorOutputSurfaceCapturer should be instantiated, and all |
| 34 // SurfaceCapturer entry points called, on the compositor main thread. |
| 35 // Internally, to synchronize with the compositor, operations are trampolined |
| 36 // to |compositor_impl_message_loop_proxy_|, and callbacks are posted back to |
| 37 // the compositor main thread. |
| 38 class BrowserCompositorOutputSurfaceCapturer |
| 39 : public SurfaceCapturer, |
| 40 public SurfaceCapturer::Client, |
| 41 public BrowserCompositorOutputSurface::Observer { |
| 42 public: |
| 43 // |output_surface_map| is owned and operated on |
| 44 // |compositor_impl_message_loop_proxy_|. We just copy a pointer to it in the |
| 45 // constructor. |
| 46 BrowserCompositorOutputSurfaceCapturer( |
| 47 IDMap<BrowserCompositorOutputSurface>* output_surface_map, |
| 48 int output_surface_id, |
| 49 SurfaceCapturer::Client* client); |
| 50 virtual ~BrowserCompositorOutputSurfaceCapturer(); |
| 51 |
| 52 // SurfaceCapturer implementation. This interface should be called on |
| 53 // |ui_compositor_message_loop_proxy_|. |
| 54 virtual void Initialize(media::VideoFrame::Format format) OVERRIDE; |
| 55 virtual void TryCapture() OVERRIDE; |
| 56 virtual void CopyCaptureToVideoFrame( |
| 57 const scoped_refptr<media::VideoFrame>& frame) OVERRIDE; |
| 58 virtual void Destroy() OVERRIDE; |
| 59 |
| 60 // SurfaceCapturer::Client implementation. This interface should be called on |
| 61 // |compositor_impl_message_loop_proxy_|. |
| 62 virtual void NotifyCaptureParameters(const gfx::Size& buffer_size, |
| 63 const gfx::Rect& visible_rect) OVERRIDE; |
| 64 virtual void NotifyCopyCaptureDone( |
| 65 const scoped_refptr<media::VideoFrame>& frame) OVERRIDE; |
| 66 virtual void NotifyError(Error error); |
| 67 |
| 68 // BrowserCompositorOutputSurface::Observer implementation. This interface |
| 69 // should be called on |compositor_impl_message_loop_proxy_|. |
| 70 virtual void OnReshape(const gfx::Size& size) OVERRIDE; |
| 71 virtual void OnSwapBuffers() OVERRIDE; |
| 72 virtual void OnPostSubBuffer(const gfx::Rect& rect) OVERRIDE; |
| 73 virtual void OnDelete() OVERRIDE; |
| 74 |
| 75 private: |
| 76 void DoInitializeOnImplThread(media::VideoFrame::Format format); |
| 77 void DoCopyCaptureToVideoFrameOnImplThread( |
| 78 const scoped_refptr<media::VideoFrame>& frame); |
| 79 void DoDestroyInternalsOnImplThread(); |
| 80 |
| 81 // Create a media::VideoFrame from a buffer using our cached format and sizes. |
| 82 scoped_refptr<media::VideoFrame> CreateCaptureVideoFrame( |
| 83 scoped_ptr<base::SharedMemory> buffer); |
| 84 void ReturnCaptureVideoFrame(scoped_ptr<base::SharedMemory> buffer); |
| 85 |
| 86 // Map to look up BrowserCompositorOutputSurfaces from their surface IDs. |
| 87 // Must outlive |this|. Should only be accessed on |
| 88 // |compositor_impl_message_loop_proxy_|. |
| 89 const IDMap<BrowserCompositorOutputSurface>* output_surface_map_; |
| 90 |
| 91 // The ID of the surface we will be capturing from. |
| 92 const int output_surface_id_; |
| 93 |
| 94 // Factory for weak pointers back to the SurfaceCapturer::Client, for |
| 95 // callbacks posted back to |ui_compositor_message_loop_proxy_|. |
| 96 base::WeakPtrFactory<SurfaceCapturer::Client> client_ptr_factory_; |
| 97 base::WeakPtr<SurfaceCapturer::Client> client_; |
| 98 |
| 99 // The main thread of the ui::Compositor. Presently the Browser process UI |
| 100 // thread. |
| 101 scoped_refptr<base::MessageLoopProxy> ui_compositor_message_loop_proxy_; |
| 102 |
| 103 // The impl thread of the ui::Compositor. |
| 104 scoped_refptr<base::MessageLoopProxy> compositor_impl_message_loop_proxy_; |
| 105 |
| 106 // The underlying capturer we capture from. |
| 107 scoped_ptr<SurfaceCapturer> capturer_; |
| 108 }; |
| 109 |
| 110 } // namespace content |
| 111 |
| 112 #endif // CONTENT_BROWSER_AURA_BROWSER_COMPOSITOR_OUTPUT_SURFACE_CAPTURER_H_ |
OLD | NEW |