• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 
40 namespace WebCore {
41 
42 // A Layer that contains a Video element.
43 class VideoLayerChromium : public LayerChromium {
44 public:
45     struct Texture {
46         unsigned id;
47         IntSize size;
48         IntSize visibleSize;
49         bool ownedByLayerRenderer;
50         bool isEmpty;
51     };
52 
53     static PassRefPtr<VideoLayerChromium> create(GraphicsLayerChromium* owner = 0,
54                                                  VideoFrameProvider* = 0);
55     virtual ~VideoLayerChromium();
56 
57     virtual PassRefPtr<CCLayerImpl> createCCLayerImpl();
58 
59     virtual void updateCompositorResources();
drawsContent()60     virtual bool drawsContent() const { return true; }
61 
62     // This function is called by VideoFrameProvider. When this method is called
63     // putCurrentFrame() must be called to return the frame currently held.
64     void releaseCurrentFrame();
65 
66     virtual void pushPropertiesTo(CCLayerImpl*);
67 
68 protected:
69     virtual void cleanupResources();
layerTypeAsString()70     virtual const char* layerTypeAsString() const { return "VideoLayer"; }
71 
72 private:
73     VideoLayerChromium(GraphicsLayerChromium* owner, VideoFrameProvider*);
74 
75     static unsigned determineTextureFormat(const VideoFrameChromium*);
76     static IntSize computeVisibleSize(const VideoFrameChromium*, unsigned plane);
77     void deleteTexturesInUse();
78 
79     bool allocateTexturesIfNeeded(GraphicsContext3D*, const VideoFrameChromium*, unsigned textureFormat);
80     void allocateTexture(GraphicsContext3D*, unsigned textureId, const IntSize& dimensions, unsigned textureFormat) const;
81 
82     void updateTexture(GraphicsContext3D*, unsigned textureId, const IntSize& dimensions, unsigned textureFormat, const void* data) const;
83 
84     void resetFrameParameters();
85     void saveCurrentFrame(VideoFrameChromium*);
86 
87     bool m_skipsDraw;
88     VideoFrameChromium::Format m_frameFormat;
89     VideoFrameProvider* m_provider;
90 
91     Texture m_textures[3];
92 
93     // This will be null for the entire duration of video playback if hardware
94     // decoding is not being used.
95     VideoFrameChromium* m_currentFrame;
96 };
97 
98 }
99 #endif // USE(ACCELERATED_COMPOSITING)
100 
101 #endif
102