initial import
[vuplus_webkit] / Source / WebKit / chromium / src / VideoFrameChromiumImpl.cpp
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 #include "config.h"
32 #include "VideoFrameChromiumImpl.h"
33
34 #include "VideoFrameChromium.h"
35 #include "WebVideoFrame.h"
36
37 using namespace WebCore;
38
39 namespace WebKit {
40
41 WebVideoFrame* VideoFrameChromiumImpl::toWebVideoFrame(VideoFrameChromium* videoFrame)
42 {
43     VideoFrameChromiumImpl* wrappedFrame = static_cast<VideoFrameChromiumImpl*>(videoFrame);
44     if (wrappedFrame)
45         return wrappedFrame->m_webVideoFrame;
46     return 0;
47 }
48
49 VideoFrameChromiumImpl::VideoFrameChromiumImpl(WebVideoFrame* webVideoFrame)
50     : m_webVideoFrame(webVideoFrame)
51 {
52 }
53
54 VideoFrameChromium::Format VideoFrameChromiumImpl::format() const
55 {
56     if (m_webVideoFrame)
57         return static_cast<VideoFrameChromium::Format>(m_webVideoFrame->format());
58     return Invalid;
59 }
60
61 unsigned VideoFrameChromiumImpl::width() const
62 {
63     if (m_webVideoFrame)
64         return m_webVideoFrame->width();
65     return 0;
66 }
67
68 unsigned VideoFrameChromiumImpl::width(unsigned plane) const
69 {
70     unsigned planeWidth = width();
71     if (format() == YV12 && plane != static_cast<unsigned>(yPlane))
72         planeWidth /= 2;
73     return planeWidth;
74 }
75
76 unsigned VideoFrameChromiumImpl::height() const
77 {
78     if (m_webVideoFrame)
79         return m_webVideoFrame->height();
80     return 0;
81 }
82
83 unsigned VideoFrameChromiumImpl::height(unsigned plane) const
84 {
85     unsigned planeHeight = height();
86     if (format() == YV12 && plane != static_cast<unsigned>(yPlane))
87         planeHeight /= 2;
88     return planeHeight;
89 }
90
91 unsigned VideoFrameChromiumImpl::planes() const
92 {
93     if (m_webVideoFrame)
94         return m_webVideoFrame->planes();
95     return 0;
96 }
97
98 int VideoFrameChromiumImpl::stride(unsigned plane) const
99 {
100     if (m_webVideoFrame)
101         return m_webVideoFrame->stride(plane);
102     return 0;
103 }
104
105 const void* VideoFrameChromiumImpl::data(unsigned plane) const
106 {
107     if (m_webVideoFrame)
108         return m_webVideoFrame->data(plane);
109     return 0;
110 }
111
112 const IntSize VideoFrameChromiumImpl::requiredTextureSize(unsigned plane) const
113 {
114     return IntSize(stride(plane), height(plane));
115 }
116
117 bool VideoFrameChromiumImpl::hasPaddingBytes(unsigned plane) const
118 {
119     if (m_webVideoFrame)
120         return stride(plane) - width(plane) > 0;
121     return false;
122 }
123
124 } // namespace WebKit