Merge Chromium + Blink git repositories
[chromium-blink-merge.git] / cc / layers / video_frame_provider_client_impl.h
blobe626b541405a2ea4c0da086d0496afdd261b32de
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; }
18 namespace cc {
19 class VideoLayerImpl;
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
24 // has.
25 class CC_EXPORT VideoFrameProviderClientImpl
26 : public VideoFrameProvider::Client,
27 public VideoFrameController,
28 public base::RefCounted<VideoFrameProviderClientImpl> {
29 public:
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);
38 bool Stopped() const;
39 // Must be called on the impl thread while the main thread is blocked.
40 void Stop();
42 scoped_refptr<media::VideoFrame> AcquireLockAndCurrentFrame();
43 void PutCurrentFrame();
44 void ReleaseLock();
45 bool HasCurrentFrame();
47 const gfx::Transform& StreamTextureMatrix() const;
49 // VideoFrameController implementation.
50 void OnBeginFrame(const BeginFrameArgs& args) override;
51 void DidDrawFrame() override;
53 // VideoFrameProvider::Client implementation.
54 // Called on the main thread.
55 void StopUsingProvider() override;
56 // Called on the impl thread.
57 void StartRendering() override;
58 void StopRendering() override;
59 void DidReceiveFrame() override;
60 void DidUpdateMatrix(const float* matrix) override;
62 const VideoFrameProvider* get_provider_for_testing() const {
63 return provider_;
66 private:
67 friend class base::RefCounted<VideoFrameProviderClientImpl>;
69 VideoFrameProviderClientImpl(VideoFrameProvider* provider,
70 VideoFrameControllerClient* client);
71 ~VideoFrameProviderClientImpl() override;
73 VideoFrameProvider* provider_;
74 VideoFrameControllerClient* client_;
75 VideoLayerImpl* active_video_layer_;
76 bool stopped_;
77 bool rendering_;
78 bool needs_put_current_frame_;
80 // Since the provider lives on another thread, it can be destroyed while the
81 // frame controller are accessing its frame. Before being destroyed the
82 // provider calls StopUsingProvider. provider_lock_ blocks StopUsingProvider
83 // from returning until the frame controller is done using the frame.
84 base::Lock provider_lock_;
85 base::ThreadChecker thread_checker_;
87 gfx::Transform stream_texture_matrix_;
89 DISALLOW_COPY_AND_ASSIGN(VideoFrameProviderClientImpl);
92 } // namespace cc
94 #endif // CC_LAYERS_VIDEO_FRAME_PROVIDER_CLIENT_IMPL_H_