Add @VisibleForTesting to fix ChromePublic release build.
[chromium-blink-merge.git] / cc / layers / video_frame_provider_client_impl.h
blobd49e51d7b7f23f7ad3e675f03b5988e6e9696f8a
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;
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;
61 private:
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_;
71 bool stopped_;
72 bool rendering_;
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);
86 } // namespace cc
88 #endif // CC_LAYERS_VIDEO_FRAME_PROVIDER_CLIENT_IMPL_H_