OLD | NEW |
1 /* | 1 /* |
2 * Copyright (C) 2006 Apple Computer, Inc. All rights reserved. | 2 * Copyright (C) 2006 Apple Computer, Inc. All rights reserved. |
3 * Copyright (C) 2008, 2009 Google, Inc. | 3 * Copyright (C) 2008, 2009 Google, Inc. |
4 * | 4 * |
5 * Redistribution and use in source and binary forms, with or without | 5 * Redistribution and use in source and binary forms, with or without |
6 * modification, are permitted provided that the following conditions | 6 * modification, are permitted provided that the following conditions |
7 * are met: | 7 * are met: |
8 * 1. Redistributions of source code must retain the above copyright | 8 * 1. Redistributions of source code must retain the above copyright |
9 * notice, this list of conditions and the following disclaimer. | 9 * notice, this list of conditions and the following disclaimer. |
10 * 2. Redistributions in binary form must reproduce the above copyright | 10 * 2. Redistributions in binary form must reproduce the above copyright |
(...skipping 11 matching lines...) Expand all Loading... |
22 * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | 22 * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
23 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE | 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. | 24 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
25 */ | 25 */ |
26 | 26 |
27 #include "platform/image-decoders/ImageDecoder.h" | 27 #include "platform/image-decoders/ImageDecoder.h" |
28 | 28 |
29 namespace blink { | 29 namespace blink { |
30 | 30 |
31 ImageFrame::ImageFrame() | 31 ImageFrame::ImageFrame() |
32 : m_allocator(0) | 32 : m_hasAlpha(true) |
33 , m_hasAlpha(true) | |
34 , m_status(FrameEmpty) | 33 , m_status(FrameEmpty) |
35 , m_duration(0) | 34 , m_duration(0) |
36 , m_disposalMethod(DisposeNotSpecified) | 35 , m_disposalMethod(DisposeNotSpecified) |
37 , m_alphaBlendSource(BlendAtopPreviousFrame) | 36 , m_alphaBlendSource(BlendAtopPreviousFrame) |
38 , m_premultiplyAlpha(true) | 37 , m_premultiplyAlpha(true) |
39 , m_pixelsChanged(false) | 38 , m_pixelsChanged(false) |
40 , m_requiredPreviousFrameIndex(kNotFound) | 39 , m_requiredPreviousFrameIndex(kNotFound) |
41 { | 40 { |
42 } | 41 } |
43 | 42 |
44 ImageFrame& ImageFrame::operator=(const ImageFrame& other) | 43 ImageFrame& ImageFrame::operator=(const ImageFrame& other) |
45 { | 44 { |
46 if (this == &other) | 45 if (this == &other) |
47 return *this; | 46 return *this; |
48 | 47 |
49 m_bitmap = other.m_bitmap; | 48 m_bitmap = other.m_bitmap; |
50 // Keep the pixels locked since we will be writing directly into the | 49 // Keep the pixels locked since we will be writing directly into the |
51 // bitmap throughout this object's lifetime. | 50 // bitmap throughout this object's lifetime. |
52 m_bitmap.lockPixels(); | 51 m_bitmap.lockPixels(); |
53 // Be sure to assign this before calling setStatus(), since setStatus() may | 52 // Be sure to assign this before calling setStatus(), since setStatus() may |
54 // call notifyBitmapIfPixelsChanged(). | 53 // call notifyBitmapIfPixelsChanged(). |
55 m_pixelsChanged = other.m_pixelsChanged; | 54 m_pixelsChanged = other.m_pixelsChanged; |
56 setMemoryAllocator(other.allocator()); | 55 m_allocator = other.m_allocator; |
57 setOriginalFrameRect(other.originalFrameRect()); | 56 setOriginalFrameRect(other.originalFrameRect()); |
58 setStatus(other.getStatus()); | 57 setStatus(other.getStatus()); |
59 setDuration(other.duration()); | 58 setDuration(other.duration()); |
60 setDisposalMethod(other.getDisposalMethod()); | 59 setDisposalMethod(other.getDisposalMethod()); |
61 setAlphaBlendSource(other.getAlphaBlendSource()); | 60 setAlphaBlendSource(other.getAlphaBlendSource()); |
62 setPremultiplyAlpha(other.premultiplyAlpha()); | 61 setPremultiplyAlpha(other.premultiplyAlpha()); |
63 // Be sure that this is called after we've called setStatus(), since we | 62 // Be sure that this is called after we've called setStatus(), since we |
64 // look at our status to know what to do with the alpha value. | 63 // look at our status to know what to do with the alpha value. |
65 setHasAlpha(other.hasAlpha()); | 64 setHasAlpha(other.hasAlpha()); |
66 setRequiredPreviousFrameIndex(other.requiredPreviousFrameIndex()); | 65 setRequiredPreviousFrameIndex(other.requiredPreviousFrameIndex()); |
(...skipping 26 matching lines...) Expand all Loading... |
93 return other.m_bitmap.copyTo(&m_bitmap, other.m_bitmap.colorType()); | 92 return other.m_bitmap.copyTo(&m_bitmap, other.m_bitmap.colorType()); |
94 } | 93 } |
95 | 94 |
96 bool ImageFrame::setSize(int newWidth, int newHeight) | 95 bool ImageFrame::setSize(int newWidth, int newHeight) |
97 { | 96 { |
98 // setSize() should only be called once, it leaks memory otherwise. | 97 // setSize() should only be called once, it leaks memory otherwise. |
99 ASSERT(!width() && !height()); | 98 ASSERT(!width() && !height()); |
100 | 99 |
101 m_bitmap.setInfo(SkImageInfo::MakeN32(newWidth, newHeight, | 100 m_bitmap.setInfo(SkImageInfo::MakeN32(newWidth, newHeight, |
102 m_premultiplyAlpha ? kPremul_SkAlphaType : kUnpremul_SkAlphaType)); | 101 m_premultiplyAlpha ? kPremul_SkAlphaType : kUnpremul_SkAlphaType)); |
103 if (!m_bitmap.tryAllocPixels(m_allocator, 0)) | 102 if (!m_bitmap.tryAllocPixels(m_allocator.get(), 0)) |
104 return false; | 103 return false; |
105 | 104 |
106 zeroFillPixelData(); | 105 zeroFillPixelData(); |
107 return true; | 106 return true; |
108 } | 107 } |
109 | 108 |
110 bool ImageFrame::hasAlpha() const | 109 bool ImageFrame::hasAlpha() const |
111 { | 110 { |
112 return m_hasAlpha; | 111 return m_hasAlpha; |
113 } | 112 } |
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
145 // If the frame is not fully loaded, there will be transparent pixels, | 144 // If the frame is not fully loaded, there will be transparent pixels, |
146 // so we can't tell skia we're opaque, even for image types that logically | 145 // so we can't tell skia we're opaque, even for image types that logically |
147 // always are (e.g. jpeg). | 146 // always are (e.g. jpeg). |
148 if (!m_hasAlpha && m_status == FrameComplete) | 147 if (!m_hasAlpha && m_status == FrameComplete) |
149 return kOpaque_SkAlphaType; | 148 return kOpaque_SkAlphaType; |
150 | 149 |
151 return m_premultiplyAlpha ? kPremul_SkAlphaType : kUnpremul_SkAlphaType; | 150 return m_premultiplyAlpha ? kPremul_SkAlphaType : kUnpremul_SkAlphaType; |
152 } | 151 } |
153 | 152 |
154 } // namespace blink | 153 } // namespace blink |
OLD | NEW |