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 CC_LAYERS_VIDEO_FRAME_PROVIDER_CLIENT_IMPL_H_
6 #define CC_LAYERS_VIDEO_FRAME_PROVIDER_CLIENT_IMPL_H_
8 #include "base/memory/ref_counted.h"
9 #include "base/synchronization/lock.h"
10 #include "base/threading/thread_checker.h"
11 #include "cc/base/cc_export.h"
12 #include "cc/layers/video_frame_provider.h"
13 #include "cc/scheduler/video_frame_controller.h"
14 #include "ui/gfx/transform.h"
16 namespace media
{ class VideoFrame
; }
21 // VideoFrameProviderClientImpl liasons with the VideoFrameProvider and the
22 // VideoLayer. It receives updates from the provider and updates the layer as a
23 // result. It also allows the layer to access the video frame that the provider
25 class CC_EXPORT VideoFrameProviderClientImpl
26 : public VideoFrameProvider::Client
,
27 public VideoFrameController
,
28 public base::RefCounted
<VideoFrameProviderClientImpl
> {
30 // Must be created on the impl thread while the main thread is blocked.
31 static scoped_refptr
<VideoFrameProviderClientImpl
> Create(
32 VideoFrameProvider
* provider
,
33 VideoFrameControllerClient
* client
);
35 VideoLayerImpl
* ActiveVideoLayer() const;
36 void SetActiveVideoLayer(VideoLayerImpl
* video_layer
);
39 // Must be called on the impl thread while the main thread is blocked.
42 scoped_refptr
<media::VideoFrame
> AcquireLockAndCurrentFrame();
43 void PutCurrentFrame();
46 const gfx::Transform
& StreamTextureMatrix() const;
48 // VideoFrameController implementation.
49 void OnBeginFrame(const BeginFrameArgs
& args
) override
;
51 // VideoFrameProvider::Client implementation.
52 // Called on the main thread.
53 void StopUsingProvider() override
;
54 // Called on the impl thread.
55 void StartRendering() override
;
56 void StopRendering() override
;
57 void DidReceiveFrame() override
;
58 void DidUpdateMatrix(const float* matrix
) override
;
61 friend class base::RefCounted
<VideoFrameProviderClientImpl
>;
63 VideoFrameProviderClientImpl(VideoFrameProvider
* provider
,
64 VideoFrameControllerClient
* client
);
65 ~VideoFrameProviderClientImpl() override
;
67 VideoFrameProvider
* provider_
;
68 VideoFrameControllerClient
* client_
;
69 VideoLayerImpl
* active_video_layer_
;
73 // Since the provider lives on another thread, it can be destroyed while the
74 // frame controller are accessing its frame. Before being destroyed the
75 // provider calls StopUsingProvider. provider_lock_ blocks StopUsingProvider
76 // from returning until the frame controller is done using the frame.
77 base::Lock provider_lock_
;
78 base::ThreadChecker thread_checker_
;
80 gfx::Transform stream_texture_matrix_
;
82 DISALLOW_COPY_AND_ASSIGN(VideoFrameProviderClientImpl
);
87 #endif // CC_LAYERS_VIDEO_FRAME_PROVIDER_CLIENT_IMPL_H_