| 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..35846f90660656fa163a14ff9cc5195291e97694
|
| --- /dev/null
|
| +++ b/content/browser/aura/browser_compositor_output_surface_capturer.h
|
| @@ -0,0 +1,112 @@
|
| +// 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.
|
| +
|
| +#ifndef CONTENT_BROWSER_AURA_BROWSER_COMPOSITOR_OUTPUT_SURFACE_CAPTURER_H_
|
| +#define CONTENT_BROWSER_AURA_BROWSER_COMPOSITOR_OUTPUT_SURFACE_CAPTURER_H_
|
| +
|
| +#include <list>
|
| +
|
| +#include "base/id_map.h"
|
| +#include "base/memory/ref_counted.h"
|
| +#include "base/memory/weak_ptr.h"
|
| +#include "content/browser/aura/browser_compositor_output_surface.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 {
|
| +
|
| +// 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 BrowserCompositorOutputSurface::Observer {
|
| + 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. This interface should be called on
|
| + // |ui_compositor_message_loop_proxy_|.
|
| + 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. This interface should be called on
|
| + // |compositor_impl_message_loop_proxy_|.
|
| + 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);
|
| +
|
| + // BrowserCompositorOutputSurface::Observer implementation. This interface
|
| + // should be called on |compositor_impl_message_loop_proxy_|.
|
| + virtual void OnReshape(const gfx::Size& size) OVERRIDE;
|
| + virtual void OnSwapBuffers() OVERRIDE;
|
| + virtual void OnPostSubBuffer(const gfx::Rect& rect) OVERRIDE;
|
| + virtual void OnDelete() OVERRIDE;
|
| +
|
| + private:
|
| + void DoInitializeOnImplThread(media::VideoFrame::Format format);
|
| + void DoCopyCaptureToVideoFrameOnImplThread(
|
| + const scoped_refptr<media::VideoFrame>& frame);
|
| + void DoDestroyInternalsOnImplThread();
|
| +
|
| + // 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
|
| +
|
| +#endif // CONTENT_BROWSER_AURA_BROWSER_COMPOSITOR_OUTPUT_SURFACE_CAPTURER_H_
|
|
|