~ubuntu-branches/ubuntu/raring/qtwebkit-source/raring-proposed

« back to all changes in this revision

Viewing changes to Source/WebCore/platform/graphics/win/QTMovieVisualContext.cpp

  • Committer: Package Import Robot
  • Author(s): Jonathan Riddell
  • Date: 2013-02-18 14:24:18 UTC
  • Revision ID: package-import@ubuntu.com-20130218142418-eon0jmjg3nj438uy
Tags: upstream-2.3
ImportĀ upstreamĀ versionĀ 2.3

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
 * Copyright (C) 2007, 2008, 2009, 2010 Apple, 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
 
6
 * are met:
 
7
 * 1. Redistributions of source code must retain the above copyright
 
8
 *    notice, this list of conditions and the following disclaimer.
 
9
 * 2. Redistributions in binary form must reproduce the above copyright
 
10
 *    notice, this list of conditions and the following disclaimer in the
 
11
 *    documentation and/or other materials provided with the distribution.
 
12
 *
 
13
 * THIS SOFTWARE IS PROVIDED BY APPLE COMPUTER, INC. ``AS IS'' AND ANY
 
14
 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
 
15
 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
 
16
 * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL APPLE COMPUTER, INC. OR
 
17
 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
 
18
 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
 
19
 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
 
20
 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
 
21
 * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
 
22
 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
 
23
 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 
 
24
 */
 
25
#include "config.h"
 
26
 
 
27
#include "QTMovieVisualContext.h"
 
28
 
 
29
#include "QTMovieTask.h"
 
30
#include <CVBase.h>
 
31
#include <CVHostTime.h>
 
32
#include <ImageCompression.h>
 
33
#include <Movies.h>
 
34
#include <windows.h>
 
35
#include <wtf/PassOwnPtr.h>
 
36
 
 
37
struct QTCVTimeStamp {
 
38
    CVTimeStamp t;
 
39
};
 
40
 
 
41
class QTMovieVisualContextPriv {
 
42
public:
 
43
    QTMovieVisualContextPriv(QTMovieVisualContext* parent, QTMovieVisualContextClient* client, QTPixelBuffer::Type contextType);
 
44
    ~QTMovieVisualContextPriv();
 
45
 
 
46
    bool isImageAvailableForTime(const QTCVTimeStamp*) const;
 
47
    QTPixelBuffer imageForTime(const QTCVTimeStamp*);
 
48
    void task();
 
49
 
 
50
    QTVisualContextRef visualContextRef();
 
51
 
 
52
    void setMovie(PassRefPtr<QTMovie>);
 
53
    QTMovie* movie() const;
 
54
    
 
55
    static void imageAvailableCallback(QTVisualContextRef visualContext, const CVTimeStamp *timeStamp, void *refCon);
 
56
 
 
57
private:
 
58
    QTMovieVisualContext* m_parent;
 
59
    QTMovieVisualContextClient* m_client;
 
60
    QTVisualContextRef m_visualContext;
 
61
    RefPtr<QTMovie> m_movie;
 
62
 
 
63
};
 
64
 
 
65
static CFDictionaryRef createPixelBufferOptionsDictionary(QTPixelBuffer::Type contextType)
 
66
{
 
67
    const void* key = kQTVisualContextPixelBufferAttributesKey;
 
68
    const void* value = QTPixelBuffer::createPixelBufferAttributesDictionary(contextType);
 
69
    CFDictionaryRef pixelBufferOptions = CFDictionaryCreate(kCFAllocatorDefault, &key, &value, 1, &kCFTypeDictionaryKeyCallBacks, &kCFTypeDictionaryValueCallBacks);
 
70
    CFRelease(value);
 
71
    return pixelBufferOptions;
 
72
}
 
73
 
 
74
static CFDictionaryRef pixelBufferCreationOptions(QTPixelBuffer::Type contextType)
 
75
{
 
76
    if (contextType == QTPixelBuffer::ConfigureForCAImageQueue) {
 
77
        static CFDictionaryRef imageQueueOptions = createPixelBufferOptionsDictionary(contextType);
 
78
        return imageQueueOptions;
 
79
    } 
 
80
 
 
81
    ASSERT(contextType == QTPixelBuffer::ConfigureForCGImage);
 
82
    static CFDictionaryRef cgImageOptions = createPixelBufferOptionsDictionary(contextType);
 
83
    return cgImageOptions;
 
84
}
 
85
 
 
86
QTMovieVisualContextPriv::QTMovieVisualContextPriv(QTMovieVisualContext* parent, QTMovieVisualContextClient* client, QTPixelBuffer::Type contextType) 
 
87
        : m_parent(parent)
 
88
        , m_client(client)
 
89
        , m_visualContext(0)
 
90
{
 
91
    typedef OSStatus ( __cdecl *pfnQTPixelBufferContextCreate)(CFAllocatorRef, CFDictionaryRef, QTVisualContextRef*);
 
92
    static pfnQTPixelBufferContextCreate pPixelBufferContextCreate = 0;
 
93
    if (!pPixelBufferContextCreate) {
 
94
        HMODULE qtmlDLL = ::LoadLibraryW(L"QTMLClient.dll");
 
95
        if (!qtmlDLL)
 
96
            return;
 
97
        pPixelBufferContextCreate = reinterpret_cast<pfnQTPixelBufferContextCreate>(GetProcAddress(qtmlDLL, "QTPixelBufferContextCreate"));
 
98
        if (!pPixelBufferContextCreate) 
 
99
            return;
 
100
    }
 
101
 
 
102
    OSStatus status = pPixelBufferContextCreate(kCFAllocatorDefault, pixelBufferCreationOptions(contextType), &m_visualContext);
 
103
    if (status == noErr && m_visualContext)
 
104
        QTVisualContextSetImageAvailableCallback(m_visualContext, &QTMovieVisualContextPriv::imageAvailableCallback, static_cast<void*>(this));
 
105
}
 
106
 
 
107
QTMovieVisualContextPriv::~QTMovieVisualContextPriv()
 
108
{
 
109
    if (m_visualContext)
 
110
        QTVisualContextSetImageAvailableCallback(m_visualContext, 0, 0);
 
111
}
 
112
 
 
113
bool QTMovieVisualContextPriv::isImageAvailableForTime(const QTCVTimeStamp* timeStamp) const
 
114
{
 
115
    if (!m_visualContext)
 
116
        return false;
 
117
 
 
118
    return QTVisualContextIsNewImageAvailable(m_visualContext, reinterpret_cast<const CVTimeStamp*>(timeStamp)); 
 
119
}
 
120
 
 
121
QTPixelBuffer QTMovieVisualContextPriv::imageForTime(const QTCVTimeStamp* timeStamp)
 
122
{
 
123
    QTPixelBuffer pixelBuffer;
 
124
    if (m_visualContext) {
 
125
        CVImageBufferRef newImage = 0;
 
126
        OSStatus status = QTVisualContextCopyImageForTime(m_visualContext, kCFAllocatorDefault, reinterpret_cast<const CVTimeStamp*>(timeStamp), &newImage);
 
127
        if (status == noErr)
 
128
            pixelBuffer.adopt(newImage);
 
129
    }
 
130
    return pixelBuffer;
 
131
}
 
132
 
 
133
void QTMovieVisualContextPriv::task()
 
134
{
 
135
    if (m_visualContext)
 
136
        QTVisualContextTask(m_visualContext);
 
137
}
 
138
 
 
139
QTVisualContextRef QTMovieVisualContextPriv::visualContextRef() 
 
140
{
 
141
    return m_visualContext;
 
142
}
 
143
 
 
144
void QTMovieVisualContextPriv::setMovie(PassRefPtr<QTMovie> movie)
 
145
{
 
146
    if (movie == m_movie)
 
147
        return;
 
148
 
 
149
    if (m_movie) {
 
150
        SetMovieVisualContext(m_movie->getMovieHandle(), 0);
 
151
        m_movie = 0;
 
152
    }
 
153
 
 
154
    if (movie)
 
155
        OSStatus status = SetMovieVisualContext(movie->getMovieHandle(), m_visualContext);
 
156
    
 
157
    m_movie = movie;
 
158
}
 
159
 
 
160
QTMovie* QTMovieVisualContextPriv::movie() const
 
161
{
 
162
    return m_movie.get();
 
163
}
 
164
 
 
165
void QTMovieVisualContextPriv::imageAvailableCallback(QTVisualContextRef visualContext, const CVTimeStamp *timeStamp, void *refCon) 
 
166
{
 
167
    if (!refCon)
 
168
        return;
 
169
 
 
170
    QTMovieVisualContextPriv* vc = static_cast<QTMovieVisualContextPriv*>(refCon);
 
171
    if (!vc->m_client)
 
172
        return;
 
173
 
 
174
    vc->m_client->imageAvailableForTime(reinterpret_cast<const QTCVTimeStamp*>(timeStamp));
 
175
}
 
176
 
 
177
PassRefPtr<QTMovieVisualContext> QTMovieVisualContext::create(QTMovieVisualContextClient* client, QTPixelBuffer::Type contextType)
 
178
{
 
179
    return adoptRef(new QTMovieVisualContext(client, contextType));
 
180
}
 
181
 
 
182
QTMovieVisualContext::QTMovieVisualContext(QTMovieVisualContextClient* client, QTPixelBuffer::Type contextType) 
 
183
    : m_private(adoptPtr(new QTMovieVisualContextPriv(this, client, contextType)))
 
184
{
 
185
}
 
186
 
 
187
QTMovieVisualContext::~QTMovieVisualContext()
 
188
{
 
189
}
 
190
 
 
191
bool QTMovieVisualContext::isImageAvailableForTime(const QTCVTimeStamp* timeStamp) const
 
192
{
 
193
    return m_private->isImageAvailableForTime(timeStamp);
 
194
}
 
195
 
 
196
QTPixelBuffer QTMovieVisualContext::imageForTime(const QTCVTimeStamp* timeStamp)
 
197
{
 
198
    return m_private->imageForTime(timeStamp);
 
199
}
 
200
 
 
201
void QTMovieVisualContext::task()
 
202
{
 
203
    m_private->task();
 
204
}
 
205
 
 
206
QTVisualContextRef QTMovieVisualContext::visualContextRef() 
 
207
{
 
208
    return m_private->visualContextRef();
 
209
}
 
210
 
 
211
void QTMovieVisualContext::setMovie(PassRefPtr<QTMovie> movie)
 
212
{
 
213
    m_private->setMovie(movie);
 
214
}
 
215
 
 
216
QTMovie* QTMovieVisualContext::movie() const
 
217
{
 
218
    return m_private->movie();
 
219
}
 
220
 
 
221
double QTMovieVisualContext::currentHostTime()
 
222
{
 
223
    return CVGetCurrentHostTime() / CVGetHostClockFrequency();
 
224
}