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_MEDIA_GL_SURFACE_CAPTURER_H_
6 #define CONTENT_COMMON_GPU_MEDIA_GL_SURFACE_CAPTURER_H_
8 #include "base/callback.h"
9 #include "base/containers/small_map.h"
10 #include "base/memory/scoped_ptr.h"
11 #include "base/threading/thread_checker.h"
12 #include "content/common/gpu/gpu_command_buffer_stub.h"
13 #include "content/common/gpu/surface_capturer.h"
14 #include "ipc/ipc_listener.h"
15 #include "ipc/ipc_sender.h"
28 // This class implements the GPU process side of a SurfaceCapturer,
29 // communicating over IPC with a GLSurfaceCapturerHost on the browser process.
30 class GLSurfaceCapturer
: public IPC::Listener
,
31 public SurfaceCapturer::Client
,
32 public GpuCommandBufferStub::DestructionObserver
{
34 GLSurfaceCapturer(int32 route_id
, GpuCommandBufferStub
* stub
);
35 virtual ~GLSurfaceCapturer();
37 // IPC::Listener implementation.
38 virtual bool OnMessageReceived(const IPC::Message
& message
) OVERRIDE
;
40 // SurfaceCapturer::Client implementation.
41 virtual void NotifyCaptureParameters(const gfx::Size
& buffer_size
,
42 const gfx::Rect
& visible_rect
) OVERRIDE
;
43 virtual void NotifyCopyCaptureDone(
44 const scoped_refptr
<media::VideoFrame
>& frame
) OVERRIDE
;
45 virtual void NotifyError(SurfaceCapturer::Error error
) OVERRIDE
;
47 // GpuCommandBufferStub::DestructionObserver implementation.
48 virtual void OnWillDestroyStub() OVERRIDE
;
51 // Handlers for IPC messages.
52 void OnInitialize(media::VideoFrame::Format format
);
53 void OnCopyCaptureToVideoFrame(int32 frame_id
,
54 base::SharedMemoryHandle buffer_shm
,
59 void Send(IPC::Message
* message
);
61 const base::ThreadChecker thread_checker_
;
63 // Route ID assigned by the GpuCommandBufferStub.
64 const int32 route_id_
;
66 // The GpuCommandBufferStub this instance belongs to, as an unowned pointer
67 // since |stub_| will own (and outlive) this.
68 GpuCommandBufferStub
* const stub_
;
70 // media::VideoFrames received from the host side.
71 typedef base::SmallMap
<std::map
<scoped_refptr
<media::VideoFrame
>, int32
> >
73 FrameIdMap frame_id_map_
;
75 // The underlying capturer we delegate to.
76 scoped_ptr
<SurfaceCapturer
> surface_capturer_
;
78 // The capture output parameters that the capturer informs us of.
79 media::VideoFrame::Format output_format_
;
80 gfx::Size output_buffer_size_
;
81 gfx::Rect output_visible_rect_
;
83 DISALLOW_COPY_AND_ASSIGN(GLSurfaceCapturer
);
86 } // namespace content
88 #endif // CONTENT_COMMON_GPU_MEDIA_GL_SURFACE_CAPTURER_H_