OLD | NEW |
1 // Copyright 2012 The Chromium Authors. All rights reserved. | 1 // Copyright 2012 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #ifndef CC_VIDEO_LAYER_IMPL_H_ | 5 #ifndef CC_VIDEO_LAYER_IMPL_H_ |
6 #define CC_VIDEO_LAYER_IMPL_H_ | 6 #define CC_VIDEO_LAYER_IMPL_H_ |
7 | 7 |
8 #include "base/callback.h" | 8 #include "base/callback.h" |
9 #include "base/synchronization/lock.h" | 9 #include "base/synchronization/lock.h" |
10 #include "cc/cc_export.h" | 10 #include "cc/cc_export.h" |
11 #include "cc/layer_impl.h" | 11 #include "cc/layer_impl.h" |
12 #include "cc/video_frame_provider.h" | 12 #include "cc/video_frame_provider.h" |
13 #include "media/base/video_frame.h" | 13 #include "media/base/video_frame.h" |
14 #include "third_party/khronos/GLES2/gl2.h" | 14 #include "third_party/khronos/GLES2/gl2.h" |
15 #include "ui/gfx/size.h" | 15 #include "ui/gfx/size.h" |
16 #include "ui/gfx/transform.h" | 16 #include "ui/gfx/transform.h" |
17 | 17 |
18 namespace media { | 18 namespace media { |
19 class SkCanvasVideoRenderer; | 19 class SkCanvasVideoRenderer; |
20 } | 20 } |
21 | 21 |
22 namespace cc { | 22 namespace cc { |
23 class LayerTreeHostImpl; | 23 class LayerTreeHostImpl; |
| 24 class VideoFrameProviderClientImpl; |
24 | 25 |
25 class CC_EXPORT VideoLayerImpl : public LayerImpl | 26 class CC_EXPORT VideoLayerImpl : public LayerImpl { |
26 , public VideoFrameProvider::Client { | |
27 public: | 27 public: |
28 static scoped_ptr<VideoLayerImpl> create(LayerTreeImpl* treeImpl, int id, Vi
deoFrameProvider* provider) | 28 static scoped_ptr<VideoLayerImpl> create(LayerTreeImpl* treeImpl, int id, Vi
deoFrameProvider* provider); |
29 { | |
30 return make_scoped_ptr(new VideoLayerImpl(treeImpl, id, provider)); | |
31 } | |
32 virtual ~VideoLayerImpl(); | 29 virtual ~VideoLayerImpl(); |
33 | 30 |
| 31 // LayerImpl implementation. |
| 32 virtual scoped_ptr<LayerImpl> createLayerImpl(LayerTreeImpl*) OVERRIDE; |
| 33 virtual void pushPropertiesTo(LayerImpl*) OVERRIDE; |
34 virtual void willDraw(ResourceProvider*) OVERRIDE; | 34 virtual void willDraw(ResourceProvider*) OVERRIDE; |
35 virtual void appendQuads(QuadSink&, AppendQuadsData&) OVERRIDE; | 35 virtual void appendQuads(QuadSink&, AppendQuadsData&) OVERRIDE; |
36 virtual void didDraw(ResourceProvider*) OVERRIDE; | 36 virtual void didDraw(ResourceProvider*) OVERRIDE; |
37 | 37 virtual void didBecomeActive() OVERRIDE; |
38 // VideoFrameProvider::Client implementation. | |
39 virtual void StopUsingProvider() OVERRIDE; // Callable on any thread. | |
40 virtual void DidReceiveFrame() OVERRIDE; // Callable on impl thread. | |
41 virtual void DidUpdateMatrix(const float*) OVERRIDE; // Callable on impl thr
ead. | |
42 | |
43 virtual void didLoseOutputSurface() OVERRIDE; | 38 virtual void didLoseOutputSurface() OVERRIDE; |
44 | 39 |
45 void setNeedsRedraw(); | 40 void setNeedsRedraw(); |
46 | 41 |
| 42 void setProviderClientImpl(scoped_refptr<VideoFrameProviderClientImpl>); |
| 43 |
47 struct FramePlane { | 44 struct FramePlane { |
48 ResourceProvider::ResourceId resourceId; | 45 ResourceProvider::ResourceId resourceId; |
49 gfx::Size size; | 46 gfx::Size size; |
50 GLenum format; | 47 GLenum format; |
51 | 48 |
52 FramePlane() : resourceId(0) { } | 49 FramePlane() : resourceId(0) { } |
53 | 50 |
54 bool allocateData(ResourceProvider*); | 51 bool allocateData(ResourceProvider*); |
55 void freeData(ResourceProvider*); | 52 void freeData(ResourceProvider*); |
56 }; | 53 }; |
57 | 54 |
58 private: | 55 private: |
59 VideoLayerImpl(LayerTreeImpl*, int, VideoFrameProvider*); | 56 VideoLayerImpl(LayerTreeImpl*, int); |
60 | 57 |
61 virtual const char* layerTypeAsString() const OVERRIDE; | 58 virtual const char* layerTypeAsString() const OVERRIDE; |
62 | 59 |
63 void willDrawInternal(ResourceProvider*); | 60 void willDrawInternal(ResourceProvider*); |
64 bool allocatePlaneData(ResourceProvider*); | 61 bool allocatePlaneData(ResourceProvider*); |
65 bool copyPlaneData(ResourceProvider*); | 62 bool copyPlaneData(ResourceProvider*); |
66 void freePlaneData(ResourceProvider*); | 63 void freePlaneData(ResourceProvider*); |
67 void freeUnusedPlaneData(ResourceProvider*); | 64 void freeUnusedPlaneData(ResourceProvider*); |
68 size_t numPlanes() const; | 65 size_t numPlanes() const; |
69 | 66 |
70 // Guards the destruction of m_provider and the frame that it provides | 67 scoped_refptr<VideoFrameProviderClientImpl> m_providerClientImpl; |
71 base::Lock m_providerLock; | |
72 VideoFrameProvider* m_provider; | |
73 | |
74 gfx::Transform m_streamTextureMatrix; | |
75 | 68 |
76 media::VideoFrame* m_frame; | 69 media::VideoFrame* m_frame; |
77 GLenum m_format; | 70 GLenum m_format; |
78 bool m_convertYUV; | 71 bool m_convertYUV; |
79 ResourceProvider::ResourceId m_externalTextureResource; | 72 ResourceProvider::ResourceId m_externalTextureResource; |
80 scoped_ptr<media::SkCanvasVideoRenderer> m_videoRenderer; | 73 scoped_ptr<media::SkCanvasVideoRenderer> m_videoRenderer; |
81 | 74 |
82 // Each index in this array corresponds to a plane in media::VideoFrame. | 75 // Each index in this array corresponds to a plane in media::VideoFrame. |
83 FramePlane m_framePlanes[media::VideoFrame::kMaxPlanes]; | 76 FramePlane m_framePlanes[media::VideoFrame::kMaxPlanes]; |
84 }; | 77 }; |
85 | 78 |
86 } // namespace cc | 79 } // namespace cc |
87 | 80 |
88 #endif // CC_VIDEO_LAYER_IMPL_H_ | 81 #endif // CC_VIDEO_LAYER_IMPL_H_ |
OLD | NEW |