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();
45 bool HasCurrentFrame();
47 const gfx::Transform
& StreamTextureMatrix() const;
49 // VideoFrameController implementation.
50 void OnBeginFrame(const BeginFrameArgs
& args
) override
;
52 // VideoFrameProvider::Client implementation.
53 // Called on the main thread.
54 void StopUsingProvider() override
;
55 // Called on the impl thread.
56 void StartRendering() override
;
57 void StopRendering() override
;
58 void DidReceiveFrame() override
;
59 void DidUpdateMatrix(const float* matrix
) override
;
62 friend class base::RefCounted
<VideoFrameProviderClientImpl
>;
64 VideoFrameProviderClientImpl(VideoFrameProvider
* provider
,
65 VideoFrameControllerClient
* client
);
66 ~VideoFrameProviderClientImpl() override
;
68 VideoFrameProvider
* provider_
;
69 VideoFrameControllerClient
* client_
;
70 VideoLayerImpl
* active_video_layer_
;
74 // Since the provider lives on another thread, it can be destroyed while the
75 // frame controller are accessing its frame. Before being destroyed the
76 // provider calls StopUsingProvider. provider_lock_ blocks StopUsingProvider
77 // from returning until the frame controller is done using the frame.
78 base::Lock provider_lock_
;
79 base::ThreadChecker thread_checker_
;
81 gfx::Transform stream_texture_matrix_
;
83 DISALLOW_COPY_AND_ASSIGN(VideoFrameProviderClientImpl
);
88 #endif // CC_LAYERS_VIDEO_FRAME_PROVIDER_CLIENT_IMPL_H_