OSDN Git Service

Merge WebKit at r71558: Initial merge by git.
[android-x86/external-webkit.git] / WebCore / platform / image-decoders / qt / RGBA32BufferQt.cpp
1 /*
2  * Copyright (C) 2006 Apple Computer, Inc.  All rights reserved.
3  * Copyright (C) 2008, 2009 Google, Inc.
4  * Copyright (C) 2009 Holger Hans Peter Freyther
5  *
6  * Redistribution and use in source and binary forms, with or without
7  * modification, are permitted provided that the following conditions
8  * are met:
9  * 1. Redistributions of source code must retain the above copyright
10  *    notice, this list of conditions and the following disclaimer.
11  * 2. Redistributions in binary form must reproduce the above copyright
12  *    notice, this list of conditions and the following disclaimer in the
13  *    documentation and/or other materials provided with the distribution.
14  *
15  * THIS SOFTWARE IS PROVIDED BY APPLE COMPUTER, INC. ``AS IS'' AND ANY
16  * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
17  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
18  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL APPLE COMPUTER, INC. OR
19  * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
20  * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
21  * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
22  * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
23  * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
24  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
25  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26  */
27
28 #include "config.h"
29 #include "ImageDecoder.h"
30
31 #include "NotImplemented.h"
32
33 #include <QPixmap>
34 #include <stdio.h>
35
36 namespace WebCore {
37
38 RGBA32Buffer::RGBA32Buffer()
39     : m_hasAlpha(false) 
40     , m_size()
41     , m_status(FrameEmpty)
42     , m_duration(0)
43     , m_disposalMethod(DisposeNotSpecified)
44 {
45 }
46
47 RGBA32Buffer& RGBA32Buffer::operator=(const RGBA32Buffer& other)
48 {
49     if (this == &other)
50         return *this;
51
52     copyBitmapData(other);
53     setRect(other.rect());
54     setStatus(other.status());
55     setDuration(other.duration());
56     setDisposalMethod(other.disposalMethod());
57     return *this;
58 }
59
60 void RGBA32Buffer::clear()
61 {
62     m_pixmap = QPixmap();
63     m_image = QImage();
64     m_status = FrameEmpty;
65     // NOTE: Do not reset other members here; clearFrameBufferCache()
66     // calls this to free the bitmap data, but other functions like
67     // initFrameBuffer() and frameComplete() may still need to read
68     // other metadata out of this frame later.
69 }
70
71 void RGBA32Buffer::zeroFill()
72 {
73     if (m_pixmap.isNull() && !m_image.isNull()) {
74         m_pixmap = QPixmap(m_image.width(), m_image.height());
75         m_image = QImage();
76     }
77     m_pixmap.fill(QColor(0, 0, 0, 0));
78 }
79
80 bool RGBA32Buffer::copyBitmapData(const RGBA32Buffer& other)
81 {
82     if (this == &other)
83         return true;
84
85     m_image = other.m_image;
86     m_pixmap = other.m_pixmap;
87     m_size = other.m_size;
88     m_hasAlpha = other.m_hasAlpha;
89     return true;
90 }
91
92 bool RGBA32Buffer::setSize(int newWidth, int newHeight)
93 {
94     // This function should only be called once, it will leak memory
95     // otherwise.
96     ASSERT(width() == 0 && height() == 0);
97
98     m_size = IntSize(newWidth, newHeight);
99     m_image = QImage();
100     m_pixmap = QPixmap(newWidth, newHeight);
101     if (m_pixmap.isNull())
102         return false;
103
104     // Zero the image.
105     zeroFill();
106
107     return true;
108 }
109
110 QPixmap* RGBA32Buffer::asNewNativeImage() const
111 {
112     if (m_pixmap.isNull() && !m_image.isNull()) {
113         m_pixmap = QPixmap::fromImage(m_image);
114         m_image = QImage();
115     }
116     return new QPixmap(m_pixmap);
117 }
118
119 bool RGBA32Buffer::hasAlpha() const
120 {
121     return m_hasAlpha;
122 }
123
124 void RGBA32Buffer::setHasAlpha(bool alpha)
125 {
126     m_hasAlpha = alpha;
127 }
128
129 void RGBA32Buffer::setColorProfile(const ColorProfile& colorProfile)
130 {
131     notImplemented();
132 }
133
134 void RGBA32Buffer::setStatus(FrameStatus status)
135 {
136     m_status = status;
137 }
138
139 // The image must not have format 8888 pre multiplied...
140 void RGBA32Buffer::setPixmap(const QPixmap& pixmap)
141 {
142     m_pixmap = pixmap;
143     m_image = QImage();
144     m_size = pixmap.size();
145     m_hasAlpha = pixmap.hasAlphaChannel();
146 }
147
148 int RGBA32Buffer::width() const
149 {
150     return m_size.width();
151 }
152
153 int RGBA32Buffer::height() const
154 {
155     return m_size.height();
156 }
157
158 }