1/*
2 * Copyright (C) 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 INC. AND ITS CONTRIBUTORS ``AS IS''
14 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
15 * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
16 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS
17 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
18 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
19 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
20 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
21 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
22 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
23 * THE POSSIBILITY OF SUCH DAMAGE.
24 */
25
26#include "config.h"
27#include "WKCAImageQueue.h"
28
29#include <CoreFoundation/CoreFoundation.h>
30#include <WebKitSystemInterface/WebKitSystemInterface.h>
31#include <wtf/PassOwnPtr.h>
32#include <wtf/RetainPtr.h>
33
34namespace WebCore {
35
36class WKCAImageQueuePrivate {
37public:
38    RetainPtr<CAImageQueueRef> m_imageQueue;
39};
40
41static CAImageQueueRef WKCAImageQueueRetain(CAImageQueueRef iq)
42{
43    if (iq)
44        return (CAImageQueueRef)CFRetain(iq);
45    return 0;
46}
47
48static void WKCAImageQueueRelease(CAImageQueueRef iq)
49{
50    if (iq)
51        CFRelease(iq);
52}
53
54WKCAImageQueue::WKCAImageQueue(uint32_t width, uint32_t height, uint32_t capacity)
55    : m_private(adoptPtr(new WKCAImageQueuePrivate()))
56{
57    m_private->m_imageQueue = adoptCF(wkCAImageQueueCreate(width, height, capacity));
58}
59
60WKCAImageQueue::WKCAImageQueue(const WKCAImageQueue& o)
61    : m_private(adoptPtr(new WKCAImageQueuePrivate()))
62{
63    m_private->m_imageQueue = o.m_private->m_imageQueue;
64}
65
66WKCAImageQueue::~WKCAImageQueue(void)
67{
68}
69
70WKCAImageQueue& WKCAImageQueue::operator=(const WKCAImageQueue& o)
71{
72    m_private->m_imageQueue = o.m_private->m_imageQueue;
73    return *this;
74}
75
76size_t WKCAImageQueue::collect()
77{
78    return wkCAImageQueueCollect(m_private->m_imageQueue.get());
79}
80
81bool WKCAImageQueue::insertImage(double t, unsigned int type, uint64_t id, uint32_t flags, ReleaseCallback release, void* info)
82{
83    return wkCAImageQueueInsertImage(m_private->m_imageQueue.get(), t, type, id, flags, release, info);
84}
85
86uint64_t WKCAImageQueue::registerPixelBuffer(void *data, size_t data_size, size_t rowbytes, size_t width, size_t height, uint32_t pixel_format, CFDictionaryRef attachments, uint32_t flags)
87{
88    return wkCAImageQueueRegisterPixelBuffer(m_private->m_imageQueue.get(), data, data_size, rowbytes, width, height, pixel_format, attachments, flags);
89}
90
91void WKCAImageQueue::setFlags(uint32_t mask, uint32_t flags)
92{
93    wkCAImageQueueSetFlags(m_private->m_imageQueue.get(), mask, flags);
94}
95
96CFTypeRef WKCAImageQueue::get()
97{
98    return m_private->m_imageQueue.get();
99}
100
101}
102