summaryrefslogtreecommitdiffstats
path: root/cc/video_layer_impl.h
blob: 73d854a4282ae02f13489e2a1518882d71828e31 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
// Copyright 2012 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#ifndef CC_VIDEO_LAYER_IMPL_H_
#define CC_VIDEO_LAYER_IMPL_H_

#include "base/callback.h"
#include "base/synchronization/lock.h"
#include "cc/cc_export.h"
#include "cc/layer_impl.h"
#include "cc/video_frame_provider.h"
#include "media/base/video_frame.h"
#include "third_party/khronos/GLES2/gl2.h"
#include "ui/gfx/size.h"
#include "ui/gfx/transform.h"

namespace media {
class SkCanvasVideoRenderer;
}

namespace cc {
class LayerTreeHostImpl;
class VideoFrameProviderClientImpl;

class CC_EXPORT VideoLayerImpl : public LayerImpl {
public:
    static scoped_ptr<VideoLayerImpl> create(LayerTreeImpl* treeImpl, int id, VideoFrameProvider* provider);
    virtual ~VideoLayerImpl();

    // LayerImpl implementation.
    virtual scoped_ptr<LayerImpl> createLayerImpl(LayerTreeImpl*) OVERRIDE;
    virtual void pushPropertiesTo(LayerImpl*) OVERRIDE;
    virtual void willDraw(ResourceProvider*) OVERRIDE;
    virtual void appendQuads(QuadSink&, AppendQuadsData&) OVERRIDE;
    virtual void didDraw(ResourceProvider*) OVERRIDE;
    virtual void didBecomeActive() OVERRIDE;
    virtual void didLoseOutputSurface() OVERRIDE;

    void setNeedsRedraw();

    void setProviderClientImpl(scoped_refptr<VideoFrameProviderClientImpl>);

    struct FramePlane {
        ResourceProvider::ResourceId resourceId;
        gfx::Size size;
        GLenum format;

        FramePlane() : resourceId(0) { }

        bool allocateData(ResourceProvider*);
        void freeData(ResourceProvider*);
    };

private:
    VideoLayerImpl(LayerTreeImpl*, int);

    virtual const char* layerTypeAsString() const OVERRIDE;

    void willDrawInternal(ResourceProvider*);
    bool allocatePlaneData(ResourceProvider*);
    bool copyPlaneData(ResourceProvider*);
    void freePlaneData(ResourceProvider*);
    void freeUnusedPlaneData(ResourceProvider*);
    size_t numPlanes() const;

    scoped_refptr<VideoFrameProviderClientImpl> m_providerClientImpl;

    media::VideoFrame* m_frame;
    GLenum m_format;
    bool m_convertYUV;
    ResourceProvider::ResourceId m_externalTextureResource;
    scoped_ptr<media::SkCanvasVideoRenderer> m_videoRenderer;

    // Each index in this array corresponds to a plane in media::VideoFrame.
    FramePlane m_framePlanes[media::VideoFrame::kMaxPlanes];
};

}  // namespace cc

#endif  // CC_VIDEO_LAYER_IMPL_H_