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
3 // found in the LICENSE file.
5 #ifndef CC_VIDEO_LAYER_IMPL_H_
6 #define CC_VIDEO_LAYER_IMPL_H_
8 #include "base/callback.h"
9 #include "base/synchronization/lock.h"
10 #include "cc/cc_export.h"
11 #include "cc/layer_impl.h"
12 #include "cc/video_frame_provider.h"
13 #include "media/base/video_frame.h"
14 #include "third_party/khronos/GLES2/gl2.h"
15 #include "ui/gfx/size.h"
16 #include "ui/gfx/transform.h"
19 class SkCanvasVideoRenderer
;
23 class LayerTreeHostImpl
;
25 class CC_EXPORT VideoLayerImpl
: public LayerImpl
26 , public VideoFrameProvider::Client
{
28 static scoped_ptr
<VideoLayerImpl
> create(LayerTreeImpl
* treeImpl
, int id
, VideoFrameProvider
* provider
)
30 return make_scoped_ptr(new VideoLayerImpl(treeImpl
, id
, provider
));
32 virtual ~VideoLayerImpl();
34 virtual void willDraw(ResourceProvider
*) OVERRIDE
;
35 virtual void appendQuads(QuadSink
&, AppendQuadsData
&) OVERRIDE
;
36 virtual void didDraw(ResourceProvider
*) 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 thread.
43 virtual void didLoseOutputSurface() OVERRIDE
;
45 void setNeedsRedraw();
48 ResourceProvider::ResourceId resourceId
;
52 FramePlane() : resourceId(0) { }
54 bool allocateData(ResourceProvider
*);
55 void freeData(ResourceProvider
*);
59 VideoLayerImpl(LayerTreeImpl
*, int, VideoFrameProvider
*);
61 virtual const char* layerTypeAsString() const OVERRIDE
;
63 void willDrawInternal(ResourceProvider
*);
64 bool allocatePlaneData(ResourceProvider
*);
65 bool copyPlaneData(ResourceProvider
*);
66 void freePlaneData(ResourceProvider
*);
67 void freeUnusedPlaneData(ResourceProvider
*);
68 size_t numPlanes() const;
70 // Guards the destruction of m_provider and the frame that it provides
71 base::Lock m_providerLock
;
72 VideoFrameProvider
* m_provider
;
74 gfx::Transform m_streamTextureMatrix
;
76 media::VideoFrame
* m_frame
;
79 ResourceProvider::ResourceId m_externalTextureResource
;
80 scoped_ptr
<media::SkCanvasVideoRenderer
> m_videoRenderer
;
82 // Each index in this array corresponds to a plane in media::VideoFrame.
83 FramePlane m_framePlanes
[media::VideoFrame::kMaxPlanes
];
88 #endif // CC_VIDEO_LAYER_IMPL_H_