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

Side by Side Diff: content/browser/aura/browser_compositor_output_surface_capturer.h

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

Powered by Google App Engine
This is Rietveld 408576698