VideoLayerChromium.h revision 81bc750723a18f21cd17d1b173cd2a4dda9cea6e
1/*
2 * Copyright (C) 2010 Google Inc. All rights reserved.
3 *
4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions are
6 * met:
7 *
8 *     * Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer.
10 *     * Redistributions in binary form must reproduce the above
11 * copyright notice, this list of conditions and the following disclaimer
12 * in the documentation and/or other materials provided with the
13 * distribution.
14 *     * Neither the name of Google Inc. nor the names of its
15 * contributors may be used to endorse or promote products derived from
16 * this software without specific prior written permission.
17 *
18 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
19 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
20 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
21 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
22 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
23 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
24 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
25 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
26 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
27 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
28 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29 */
30
31
32#ifndef VideoLayerChromium_h
33#define VideoLayerChromium_h
34
35#if USE(ACCELERATED_COMPOSITING)
36
37#include "LayerChromium.h"
38#include "VideoFrameProvider.h"
39
40namespace WebCore {
41
42// A Layer that contains a Video element.
43class VideoLayerChromium : public LayerChromium {
44public:
45    static PassRefPtr<VideoLayerChromium> create(GraphicsLayerChromium* owner = 0,
46                                                 VideoFrameProvider* = 0);
47    virtual ~VideoLayerChromium();
48    virtual void updateContentsIfDirty();
49    virtual bool drawsContent() const { return true; }
50    virtual void draw();
51
52    // This function is called by VideoFrameProvider. When this method is called
53    // putCurrentFrame() must be called to return the frame currently held.
54    void releaseCurrentFrame();
55
56    typedef ProgramBinding<VertexShaderPosTexTransform, FragmentShaderRGBATexFlipAlpha> RGBAProgram;
57    typedef ProgramBinding<VertexShaderPosTexYUVStretch, FragmentShaderYUVVideo> YUVProgram;
58
59protected:
60    virtual void cleanupResources();
61    virtual const char* layerTypeAsString() const { return "VideoLayer"; }
62
63private:
64    VideoLayerChromium(GraphicsLayerChromium* owner, VideoFrameProvider*);
65
66    static unsigned determineTextureFormat(VideoFrameChromium*);
67    bool allocateTexturesIfNeeded(GraphicsContext3D*, VideoFrameChromium*, unsigned textureFormat);
68    void updateYUVContents(GraphicsContext3D*, const VideoFrameChromium*);
69    void updateRGBAContents(GraphicsContext3D*, const VideoFrameChromium*);
70    void allocateTexture(GraphicsContext3D*, unsigned textureId, const IntSize& dimensions, unsigned textureFormat);
71    void updateTexture(GraphicsContext3D*, unsigned textureId, const IntSize& dimensions, unsigned textureFormat, const void* data);
72    void drawYUV(const YUVProgram*);
73    void drawRGBA(const RGBAProgram*);
74    void resetFrameParameters();
75    void saveCurrentFrame(VideoFrameChromium*);
76
77    static const float yuv2RGB[9];
78
79    bool m_skipsDraw;
80    VideoFrameChromium::Format m_frameFormat;
81    VideoFrameProvider* m_provider;
82    VideoFrameChromium* m_currentFrame;
83
84    unsigned m_textures[3];
85    IntSize m_textureSizes[3];
86    IntSize m_frameSizes[3];
87};
88
89}
90#endif // USE(ACCELERATED_COMPOSITING)
91
92#endif
93