OLD | NEW |
| (Empty) |
1 /* | |
2 * Copyright (C) 2006 Apple Computer, Inc. All rights reserved. | |
3 * Copyright (C) 2008, 2009 Google, Inc. | |
4 * | |
5 * Redistribution and use in source and binary forms, with or without | |
6 * modification, are permitted provided that the following conditions | |
7 * are met: | |
8 * 1. Redistributions of source code must retain the above copyright | |
9 * notice, this list of conditions and the following disclaimer. | |
10 * 2. Redistributions in binary form must reproduce the above copyright | |
11 * notice, this list of conditions and the following disclaimer in the | |
12 * documentation and/or other materials provided with the distribution. | |
13 * | |
14 * THIS SOFTWARE IS PROVIDED BY APPLE COMPUTER, INC. ``AS IS'' AND ANY | |
15 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | |
16 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR | |
17 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE COMPUTER, INC. OR | |
18 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, | |
19 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, | |
20 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR | |
21 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY | |
22 * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | |
23 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE | |
24 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | |
25 */ | |
26 | |
27 #include "config.h" | |
28 #include "core/platform/image-decoders/ImageDecoder.h" | |
29 | |
30 #include "core/platform/graphics/skia/NativeImageSkia.h" | |
31 #include "wtf/PassRefPtr.h" | |
32 | |
33 namespace WebCore { | |
34 | |
35 ImageFrame::ImageFrame() | |
36 : m_bitmap(NativeImageSkia::create()) | |
37 , m_allocator(0) | |
38 , m_hasAlpha(false) | |
39 , m_status(FrameEmpty) | |
40 , m_duration(0) | |
41 , m_disposalMethod(DisposeNotSpecified) | |
42 , m_alphaBlendSource(BlendAtopPreviousFrame) | |
43 , m_premultiplyAlpha(true) | |
44 , m_pixelsChanged(false) | |
45 , m_requiredPreviousFrameIndex(kNotFound) | |
46 #if !ASSERT_DISABLED | |
47 , m_requiredPreviousFrameIndexValid(false) | |
48 #endif | |
49 { | |
50 } | |
51 | |
52 ImageFrame& ImageFrame::operator=(const ImageFrame& other) | |
53 { | |
54 if (this == &other) | |
55 return *this; | |
56 | |
57 m_bitmap = other.m_bitmap->clone(); | |
58 // Keep the pixels locked since we will be writing directly into the | |
59 // bitmap throughout this object's lifetime. | |
60 m_bitmap->bitmap().lockPixels(); | |
61 // Be sure to assign this before calling setStatus(), since setStatus() may | |
62 // call notifyBitmapIfPixelsChanged(). | |
63 m_pixelsChanged = other.m_pixelsChanged; | |
64 setMemoryAllocator(other.allocator()); | |
65 setOriginalFrameRect(other.originalFrameRect()); | |
66 setStatus(other.status()); | |
67 setDuration(other.duration()); | |
68 setDisposalMethod(other.disposalMethod()); | |
69 setAlphaBlendSource(other.alphaBlendSource()); | |
70 setPremultiplyAlpha(other.premultiplyAlpha()); | |
71 // Be sure that this is called after we've called setStatus(), since we | |
72 // look at our status to know what to do with the alpha value. | |
73 setHasAlpha(other.hasAlpha()); | |
74 // Copy raw fields to avoid ASSERT failure in requiredPreviousFrameIndex(). | |
75 m_requiredPreviousFrameIndex = other.m_requiredPreviousFrameIndex; | |
76 #if !ASSERT_DISABLED | |
77 m_requiredPreviousFrameIndexValid = other.m_requiredPreviousFrameIndexValid; | |
78 #endif | |
79 return *this; | |
80 } | |
81 | |
82 void ImageFrame::clearPixelData() | |
83 { | |
84 m_bitmap->bitmap().reset(); | |
85 m_status = FrameEmpty; | |
86 // NOTE: Do not reset other members here; clearFrameBufferCache() | |
87 // calls this to free the bitmap data, but other functions like | |
88 // initFrameBuffer() and frameComplete() may still need to read | |
89 // other metadata out of this frame later. | |
90 } | |
91 | |
92 void ImageFrame::zeroFillPixelData() | |
93 { | |
94 m_bitmap->bitmap().eraseARGB(0, 0, 0, 0); | |
95 m_hasAlpha = true; | |
96 } | |
97 | |
98 bool ImageFrame::copyBitmapData(const ImageFrame& other) | |
99 { | |
100 if (this == &other) | |
101 return true; | |
102 | |
103 m_hasAlpha = other.m_hasAlpha; | |
104 m_bitmap->bitmap().reset(); | |
105 const NativeImageSkia* otherBitmap = other.m_bitmap.get(); | |
106 return otherBitmap->bitmap().copyTo(&m_bitmap->bitmap(), otherBitmap->bitmap
().config()); | |
107 } | |
108 | |
109 bool ImageFrame::setSize(int newWidth, int newHeight) | |
110 { | |
111 // setSize() should only be called once, it leaks memory otherwise. | |
112 ASSERT(!width() && !height()); | |
113 | |
114 m_bitmap->bitmap().setConfig(SkBitmap::kARGB_8888_Config, newWidth, newHeigh
t); | |
115 if (!m_bitmap->bitmap().allocPixels(m_allocator, 0)) | |
116 return false; | |
117 | |
118 zeroFillPixelData(); | |
119 return true; | |
120 } | |
121 | |
122 PassRefPtr<NativeImageSkia> ImageFrame::asNewNativeImage() const | |
123 { | |
124 return m_bitmap->clone(); | |
125 } | |
126 | |
127 bool ImageFrame::hasAlpha() const | |
128 { | |
129 return m_hasAlpha; | |
130 } | |
131 | |
132 void ImageFrame::setHasAlpha(bool alpha) | |
133 { | |
134 m_hasAlpha = alpha; | |
135 | |
136 // If the frame is not fully loaded, there will be transparent pixels, | |
137 // so we can't tell skia we're opaque, even for image types that logically | |
138 // always are (e.g. jpeg). | |
139 if (m_status != FrameComplete) | |
140 alpha = true; | |
141 m_bitmap->bitmap().setAlphaType(alpha ? kPremul_SkAlphaType : kOpaque_SkAlph
aType); | |
142 } | |
143 | |
144 void ImageFrame::setStatus(Status status) | |
145 { | |
146 m_status = status; | |
147 if (m_status == FrameComplete) { | |
148 m_bitmap->bitmap().setAlphaType(m_hasAlpha ? kPremul_SkAlphaType : kOpaq
ue_SkAlphaType); | |
149 // Send pending pixels changed notifications now, because we can't do th
is after | |
150 // the bitmap was set immutable by setDataComplete(). | |
151 notifyBitmapIfPixelsChanged(); | |
152 m_bitmap->setDataComplete(); // Tell the bitmap it's done. | |
153 } | |
154 } | |
155 | |
156 void ImageFrame::zeroFillFrameRect(const IntRect& rect) | |
157 { | |
158 if (rect.isEmpty()) | |
159 return; | |
160 | |
161 m_bitmap->bitmap().eraseArea(rect, SkColorSetARGB(0, 0, 0, 0)); | |
162 setHasAlpha(true); | |
163 } | |
164 | |
165 } // namespace WebCore | |
OLD | NEW |