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

Unified 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, 4 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 side-by-side diff with in-line comments
Download patch
Index: content/browser/aura/browser_compositor_output_surface_capturer.h
diff --git a/content/browser/aura/browser_compositor_output_surface_capturer.h b/content/browser/aura/browser_compositor_output_surface_capturer.h
new file mode 100644
index 0000000000000000000000000000000000000000..d92ecb572ad1b19e6326211f2c71b2e43bcee349
--- /dev/null
+++ b/content/browser/aura/browser_compositor_output_surface_capturer.h
@@ -0,0 +1,99 @@
+// Copyright (c) 2013 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include <list>
+
+#include "base/id_map.h"
+#include "base/memory/ref_counted.h"
+#include "base/memory/weak_ptr.h"
+#include "content/common/gpu/surface_capturer.h"
+#include "ui/gfx/rect.h"
+#include "ui/gfx/size.h"
+
+namespace base {
+
+class MessageLoopProxy;
+class SharedMemory;
+
+} // namespace base
+
+namespace content {
+
+class BrowserCompositorOutputSurface;
+
+// This class implements the SurfaceCapturer interface for capturing from a
+// BrowserCompositorOutputSurface. It essentially proxies the SurfaceCapturer
+// between the compositor's impl thread (which BrowserCompositorOutputSurface
+// runs on), stored in |compositor_impl_message_loop_proxy_|, and the
+// compositor's own main thread (presently the UI thread), stored in
+// |ui_compositor_message_loop_proxy_|.
+// BrowserCompositorOutputSurfaceCapturer should be instantiated, and all
+// SurfaceCapturer entry points called, on the compositor main thread.
+// Internally, to synchronize with the compositor, operations are trampolined
+// to |compositor_impl_message_loop_proxy_|, and callbacks are posted back to
+// the compositor main thread.
+class BrowserCompositorOutputSurfaceCapturer : public SurfaceCapturer,
+ public SurfaceCapturer::Client {
+ public:
+ // |output_surface_map| is owned and operated on
+ // |compositor_impl_message_loop_proxy_|. We just copy a pointer to it in the
+ // constructor.
+ BrowserCompositorOutputSurfaceCapturer(
+ IDMap<BrowserCompositorOutputSurface>* output_surface_map,
+ int output_surface_id,
+ SurfaceCapturer::Client* client);
+ virtual ~BrowserCompositorOutputSurfaceCapturer();
+
+ // SurfaceCapturer implementation.
+ virtual void Initialize(media::VideoFrame::Format format) OVERRIDE;
+ virtual void TryCapture() OVERRIDE;
+ virtual void CopyCaptureToVideoFrame(
+ const scoped_refptr<media::VideoFrame>& frame) OVERRIDE;
+ virtual void Destroy() OVERRIDE;
+
+ // SurfaceCapturer::Client implementation.
+ virtual void NotifyCaptureParameters(const gfx::Size& buffer_size,
+ const gfx::Rect& visible_rect) OVERRIDE;
+ virtual void NotifyCopyCaptureDone(
+ const scoped_refptr<media::VideoFrame>& frame) OVERRIDE;
+ virtual void NotifyError(Error error);
+
+ void NotifySwapBuffersOnImplThread();
+ void DoDestroyOnImplThread();
+
+ private:
+ void DoInitializeOnImplThread(media::VideoFrame::Format format);
+ void DoCopyCaptureToVideoFrameOnImplThread(
+ const scoped_refptr<media::VideoFrame>& frame);
+
+ // Create a media::VideoFrame from a buffer using our cached format and sizes.
+ scoped_refptr<media::VideoFrame> CreateCaptureVideoFrame(
+ scoped_ptr<base::SharedMemory> buffer);
+ void ReturnCaptureVideoFrame(scoped_ptr<base::SharedMemory> buffer);
+
+ // Map to look up BrowserCompositorOutputSurfaces from their surface IDs.
+ // Must outlive |this|. Should only be accessed on
+ // |compositor_impl_message_loop_proxy_|.
+ const IDMap<BrowserCompositorOutputSurface>* output_surface_map_;
+
+ // The ID of the surface we will be capturing from.
+ const int output_surface_id_;
+
+ // Factory for weak pointers back to the SurfaceCapturer::Client, for
+ // callbacks posted back to |ui_compositor_message_loop_proxy_|.
+ base::WeakPtrFactory<SurfaceCapturer::Client> client_ptr_factory_;
+ base::WeakPtr<SurfaceCapturer::Client> client_;
+
+ // The main thread of the ui::Compositor. Presently the Browser process UI
+ // thread.
+ scoped_refptr<base::MessageLoopProxy> ui_compositor_message_loop_proxy_;
+
+ // The impl thread of the ui::Compositor.
+ scoped_refptr<base::MessageLoopProxy> compositor_impl_message_loop_proxy_;
+
+ // The underlying capturer we capture from.
+ scoped_ptr<SurfaceCapturer> capturer_;
+};
+
+} // namespace content

Powered by Google App Engine
This is Rietveld 408576698