1 // Copyright 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_COMMON_GPU_SURFACE_CAPTURER_H_
6 #define CONTENT_COMMON_GPU_SURFACE_CAPTURER_H_
8 #include "content/common/content_export.h"
9 #include "media/base/video_frame.h"
20 // Surface capturer interface. This interface is implemented by classes
21 // that perform image capturing from the backbuffer.
22 class CONTENT_EXPORT SurfaceCapturer
{
25 // Invalid argument was passed to an API method.
26 kInvalidArgumentError
,
27 // A failure occurred at the GPU process or one of its dependencies.
28 // Examples of such failures include GPU hardware failures, GPU driver
29 // failures, GPU library failures, GPU process programming errors, and so
31 kPlatformFailureError
,
34 class CONTENT_EXPORT Client
{
36 // Callback to notify client of parameters of the backbuffer capture. Every
37 // time the Client receives this callback, subsequent media::VideoFrames
38 // passed to CopyCaptureToVideoFrame() should mind the new parameters.
40 // |buffer_size| is the required logical size (in pixels) of the buffer
41 // to capture to (corresponds to |frame->coded_size()| in
42 // CopyCaptureToVideoFrame().
43 // |visible_rect| is the visible subrect of the actual screen capture
44 // contents in the buffer to capture to (corresponds to
45 // |frame->visible_rect()| in CopyCaptureToVideoFrame().
46 virtual void NotifyCaptureParameters(const gfx::Size
& buffer_size
,
47 const gfx::Rect
& visible_rect
) = 0;
49 // Callback to notify client that CopyCaptureToVideoFrame() has been
50 // completed for |frame|. After this call, the capturer will drop all its
51 // outstanding references to |frame|.
53 // |frame| is the completed copied captured frame.
54 virtual void NotifyCopyCaptureDone(
55 const scoped_refptr
<media::VideoFrame
>& frame
) = 0;
57 // Error notification callback.
59 // |error| is the error to report.
60 virtual void NotifyError(Error error
) = 0;
63 // Clients are not owned by Capturer instances and should not be deleted
64 // through these pointers.
68 // Initialize the capturer to a specific configuration.
70 // |format| is the format to capture to (corresponds to |frame->format()| in
71 // CopyCaptureToVideoFrame()). The NotifyCaptureParameters() callback is
72 // made to the Client on success; on failure, a NotifyError() callback is
74 virtual void Initialize(media::VideoFrame::Format format
) = 0;
76 // Attempt to capture a single frame. This call is advisory to note to the
77 // SurfaceCapturer that capture should be attempted at this time; success is
78 // not guaranteed. The most recent captured frame is cached internally, and
79 // its contents returned every time CopyCaptureToVideoFrame() is called.
80 virtual void TryCapture() = 0;
82 // Copy the most recent captured contents to |frame|.
84 // |frame| is the media::VideoFrame to fill with captured contents.
85 virtual void CopyCaptureToVideoFrame(
86 const scoped_refptr
<media::VideoFrame
>& frame
) = 0;
88 // Destroys the capturer; all pending inputs and outputs are dropped
89 // immediately and the component is freed. This call may asynchronously free
90 // system resources, but its client-visible effects are synchronous. After
91 // this method returns no more callbacks will be made on the client. Deletes
92 // |this| unconditionally, so make sure to drop all pointers to it!
93 virtual void Destroy() = 0;
95 virtual ~SurfaceCapturer();
98 } // namespace content
100 #endif // CONTENT_COMMON_GPU_SURFACE_CAPTURER_H_