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_CLIENT_GL_SURFACE_CAPTURER_HOST_H_
6 #define CONTENT_COMMON_GPU_CLIENT_GL_SURFACE_CAPTURER_HOST_H_
8 #include "base/containers/small_map.h"
9 #include "base/memory/ref_counted.h"
10 #include "base/memory/weak_ptr.h"
11 #include "base/threading/thread_checker.h"
12 #include "content/common/gpu/client/command_buffer_proxy_impl.h"
13 #include "content/common/gpu/surface_capturer.h"
14 #include "ipc/ipc_listener.h"
33 // This class is the browser-side host for the SurfaceCapturer in the GPU
34 // process, coordinated over IPC.
35 class GLSurfaceCapturerHost
: public IPC::Listener
,
36 public SurfaceCapturer
,
37 public CommandBufferProxyImpl::DeletionObserver
{
39 // |client| is expected to outlive this object. We are registered as a
40 // DeletionObserver with |impl|, so it will notify us when it is about to
42 GLSurfaceCapturerHost(int32 capturer_route_id
,
43 SurfaceCapturer::Client
* client
,
44 CommandBufferProxyImpl
* impl
);
46 // IPC::Listener implementation.
47 virtual void OnChannelError() OVERRIDE
;
48 virtual bool OnMessageReceived(const IPC::Message
& message
) OVERRIDE
;
50 // SurfaceCapturer implementation.
51 virtual void Initialize(media::VideoFrame::Format format
) OVERRIDE
;
52 virtual void TryCapture() OVERRIDE
;
53 virtual void CopyCaptureToVideoFrame(
54 const scoped_refptr
<media::VideoFrame
>& frame
) OVERRIDE
;
55 virtual void Destroy() OVERRIDE
;
57 // CommandBufferProxyImpl::DeletionObserver implementation.
58 virtual void OnWillDeleteImpl() OVERRIDE
;
61 virtual ~GLSurfaceCapturerHost();
63 // Notify |client_| when an error has occured. Used when notifying from
64 // within a media::VideoEncodeAccelerator entry point, to avoid re-entrancy.
65 void NotifyError(Error error
);
67 // IPC handlers, proxying SurfaceCapturer::Client for the GPU process.
68 void OnNotifyCaptureParameters(const gfx::Size
& buffer_size
,
69 const gfx::Rect
& visible_rect
);
70 void OnNotifyCopyCaptureDone(int32 frame_id
);
71 void OnNotifyError(Error error
);
73 void Send(IPC::Message
* message
);
75 const base::ThreadChecker thread_checker_
;
77 // Route ID for corresponding GLSurfaceCapturer in the GPU process.
78 const int32 capturer_route_id_
;
80 // Weak pointer for registering as a listener for |channel_|.
81 base::WeakPtrFactory
<GLSurfaceCapturerHost
> weak_this_factory_
;
83 // SurfaceEncoder::Client callbacks received over IPC are forwarded to
85 SurfaceCapturer::Client
* client_
;
87 // Unowned reference to the CommandBufferProxyImpl that created us.
88 CommandBufferProxyImpl
* impl_
;
90 // GPU process channel to send messages on.
91 GpuChannelHost
* channel_
;
93 // media::VideoFrames sent to the capturer.
94 // base::IDMap not used here, since that takes pointers, not scoped_refptr.
95 typedef base::SmallMap
<std::map
<int32
, scoped_refptr
<media::VideoFrame
> > >
99 // ID serial number for next frame to send to the GPU process.
100 int32 next_frame_id_
;
102 DISALLOW_COPY_AND_ASSIGN(GLSurfaceCapturerHost
);
105 } // namespace content
107 #endif // CONTENT_COMMON_GPU_CLIENT_GL_SURFACE_CAPTURER_HOST_H_