WebKit Roll 139512:139548
[chromium-blink-merge.git] / cc / video_layer_impl.h
blob0ea274da1e19d398251a212ecb30c3549355f86d
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"
18 namespace media {
19 class SkCanvasVideoRenderer;
22 namespace cc {
23 class LayerTreeHostImpl;
25 class CC_EXPORT VideoLayerImpl : public LayerImpl
26 , public VideoFrameProvider::Client {
27 public:
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();
47 struct FramePlane {
48 ResourceProvider::ResourceId resourceId;
49 gfx::Size size;
50 GLenum format;
52 FramePlane() : resourceId(0) { }
54 bool allocateData(ResourceProvider*);
55 void freeData(ResourceProvider*);
58 private:
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;
77 GLenum m_format;
78 bool m_convertYUV;
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];
86 } // namespace cc
88 #endif // CC_VIDEO_LAYER_IMPL_H_