| 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 12 matching lines...) Expand all Loading... |
| 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 "config.h" | 27 #include "config.h" |
| 28 #include "platform/image-decoders/ImageDecoder.h" | 28 #include "platform/image-decoders/ImageDecoder.h" |
| 29 | 29 |
| 30 namespace WebCore { | 30 namespace WebCore { |
| 31 | 31 |
| 32 ImageFrame::ImageFrame() | 32 ImageFrame::ImageFrame() |
| 33 : m_bitmap(NativeImageSkia::create()) | 33 : m_allocator(0) |
| 34 , m_allocator(0) | |
| 35 , m_hasAlpha(false) | 34 , m_hasAlpha(false) |
| 36 , m_status(FrameEmpty) | 35 , m_status(FrameEmpty) |
| 37 , m_duration(0) | 36 , m_duration(0) |
| 38 , m_disposalMethod(DisposeNotSpecified) | 37 , m_disposalMethod(DisposeNotSpecified) |
| 39 , m_alphaBlendSource(BlendAtopPreviousFrame) | 38 , m_alphaBlendSource(BlendAtopPreviousFrame) |
| 40 , m_premultiplyAlpha(true) | 39 , m_premultiplyAlpha(true) |
| 41 , m_pixelsChanged(false) | 40 , m_pixelsChanged(false) |
| 42 , m_requiredPreviousFrameIndex(kNotFound) | 41 , m_requiredPreviousFrameIndex(kNotFound) |
| 43 #if !ASSERT_DISABLED | 42 #if !ASSERT_DISABLED |
| 44 , m_requiredPreviousFrameIndexValid(false) | 43 , m_requiredPreviousFrameIndexValid(false) |
| 45 #endif | 44 #endif |
| 46 { | 45 { |
| 47 } | 46 } |
| 48 | 47 |
| 49 ImageFrame& ImageFrame::operator=(const ImageFrame& other) | 48 ImageFrame& ImageFrame::operator=(const ImageFrame& other) |
| 50 { | 49 { |
| 51 if (this == &other) | 50 if (this == &other) |
| 52 return *this; | 51 return *this; |
| 53 | 52 |
| 54 m_bitmap = other.m_bitmap->clone(); | 53 m_bitmap = other.m_bitmap; |
| 55 // Keep the pixels locked since we will be writing directly into the | 54 // Keep the pixels locked since we will be writing directly into the |
| 56 // bitmap throughout this object's lifetime. | 55 // bitmap throughout this object's lifetime. |
| 57 m_bitmap->bitmap().lockPixels(); | 56 m_bitmap.lockPixels(); |
| 58 // Be sure to assign this before calling setStatus(), since setStatus() may | 57 // Be sure to assign this before calling setStatus(), since setStatus() may |
| 59 // call notifyBitmapIfPixelsChanged(). | 58 // call notifyBitmapIfPixelsChanged(). |
| 60 m_pixelsChanged = other.m_pixelsChanged; | 59 m_pixelsChanged = other.m_pixelsChanged; |
| 61 setMemoryAllocator(other.allocator()); | 60 setMemoryAllocator(other.allocator()); |
| 62 setOriginalFrameRect(other.originalFrameRect()); | 61 setOriginalFrameRect(other.originalFrameRect()); |
| 63 setStatus(other.status()); | 62 setStatus(other.status()); |
| 64 setDuration(other.duration()); | 63 setDuration(other.duration()); |
| 65 setDisposalMethod(other.disposalMethod()); | 64 setDisposalMethod(other.disposalMethod()); |
| 66 setAlphaBlendSource(other.alphaBlendSource()); | 65 setAlphaBlendSource(other.alphaBlendSource()); |
| 67 setPremultiplyAlpha(other.premultiplyAlpha()); | 66 setPremultiplyAlpha(other.premultiplyAlpha()); |
| 68 // Be sure that this is called after we've called setStatus(), since we | 67 // Be sure that this is called after we've called setStatus(), since we |
| 69 // look at our status to know what to do with the alpha value. | 68 // look at our status to know what to do with the alpha value. |
| 70 setHasAlpha(other.hasAlpha()); | 69 setHasAlpha(other.hasAlpha()); |
| 71 // Copy raw fields to avoid ASSERT failure in requiredPreviousFrameIndex(). | 70 // Copy raw fields to avoid ASSERT failure in requiredPreviousFrameIndex(). |
| 72 m_requiredPreviousFrameIndex = other.m_requiredPreviousFrameIndex; | 71 m_requiredPreviousFrameIndex = other.m_requiredPreviousFrameIndex; |
| 73 #if !ASSERT_DISABLED | 72 #if !ASSERT_DISABLED |
| 74 m_requiredPreviousFrameIndexValid = other.m_requiredPreviousFrameIndexValid; | 73 m_requiredPreviousFrameIndexValid = other.m_requiredPreviousFrameIndexValid; |
| 75 #endif | 74 #endif |
| 76 return *this; | 75 return *this; |
| 77 } | 76 } |
| 78 | 77 |
| 79 void ImageFrame::clearPixelData() | 78 void ImageFrame::clearPixelData() |
| 80 { | 79 { |
| 81 m_bitmap->bitmap().reset(); | 80 m_bitmap.reset(); |
| 82 m_status = FrameEmpty; | 81 m_status = FrameEmpty; |
| 83 // NOTE: Do not reset other members here; clearFrameBufferCache() | 82 // NOTE: Do not reset other members here; clearFrameBufferCache() |
| 84 // calls this to free the bitmap data, but other functions like | 83 // calls this to free the bitmap data, but other functions like |
| 85 // initFrameBuffer() and frameComplete() may still need to read | 84 // initFrameBuffer() and frameComplete() may still need to read |
| 86 // other metadata out of this frame later. | 85 // other metadata out of this frame later. |
| 87 } | 86 } |
| 88 | 87 |
| 89 void ImageFrame::zeroFillPixelData() | 88 void ImageFrame::zeroFillPixelData() |
| 90 { | 89 { |
| 91 m_bitmap->bitmap().eraseARGB(0, 0, 0, 0); | 90 m_bitmap.eraseARGB(0, 0, 0, 0); |
| 92 m_hasAlpha = true; | 91 m_hasAlpha = true; |
| 93 } | 92 } |
| 94 | 93 |
| 95 bool ImageFrame::copyBitmapData(const ImageFrame& other) | 94 bool ImageFrame::copyBitmapData(const ImageFrame& other) |
| 96 { | 95 { |
| 97 if (this == &other) | 96 if (this == &other) |
| 98 return true; | 97 return true; |
| 99 | 98 |
| 100 m_hasAlpha = other.m_hasAlpha; | 99 m_hasAlpha = other.m_hasAlpha; |
| 101 m_bitmap->bitmap().reset(); | 100 m_bitmap.reset(); |
| 102 const NativeImageSkia* otherBitmap = other.m_bitmap.get(); | 101 return other.m_bitmap.copyTo(&m_bitmap, other.m_bitmap.colorType()); |
| 103 return otherBitmap->bitmap().copyTo(&m_bitmap->bitmap(), otherBitmap->bitmap
().colorType()); | |
| 104 } | 102 } |
| 105 | 103 |
| 106 bool ImageFrame::setSize(int newWidth, int newHeight) | 104 bool ImageFrame::setSize(int newWidth, int newHeight) |
| 107 { | 105 { |
| 108 // setSize() should only be called once, it leaks memory otherwise. | 106 // setSize() should only be called once, it leaks memory otherwise. |
| 109 ASSERT(!width() && !height()); | 107 ASSERT(!width() && !height()); |
| 110 | 108 |
| 111 m_bitmap->bitmap().setConfig(SkImageInfo::MakeN32Premul(newWidth, newHeight)
); | 109 m_bitmap.setConfig(SkImageInfo::MakeN32Premul(newWidth, newHeight)); |
| 112 if (!m_bitmap->bitmap().allocPixels(m_allocator, 0)) | 110 if (!m_bitmap.allocPixels(m_allocator, 0)) |
| 113 return false; | 111 return false; |
| 114 | 112 |
| 115 zeroFillPixelData(); | 113 zeroFillPixelData(); |
| 116 return true; | 114 return true; |
| 117 } | 115 } |
| 118 | 116 |
| 119 PassRefPtr<NativeImageSkia> ImageFrame::asNewNativeImage() const | 117 PassRefPtr<NativeImageSkia> ImageFrame::asNewNativeImage() const |
| 120 { | 118 { |
| 121 return m_bitmap->clone(); | 119 return NativeImageSkia::create(m_bitmap); |
| 122 } | 120 } |
| 123 | 121 |
| 124 bool ImageFrame::hasAlpha() const | 122 bool ImageFrame::hasAlpha() const |
| 125 { | 123 { |
| 126 return m_hasAlpha; | 124 return m_hasAlpha; |
| 127 } | 125 } |
| 128 | 126 |
| 129 void ImageFrame::setHasAlpha(bool alpha) | 127 void ImageFrame::setHasAlpha(bool alpha) |
| 130 { | 128 { |
| 131 m_hasAlpha = alpha; | 129 m_hasAlpha = alpha; |
| 132 | 130 |
| 133 // If the frame is not fully loaded, there will be transparent pixels, | 131 // If the frame is not fully loaded, there will be transparent pixels, |
| 134 // so we can't tell skia we're opaque, even for image types that logically | 132 // so we can't tell skia we're opaque, even for image types that logically |
| 135 // always are (e.g. jpeg). | 133 // always are (e.g. jpeg). |
| 136 if (m_status != FrameComplete) | 134 if (m_status != FrameComplete) |
| 137 alpha = true; | 135 alpha = true; |
| 138 m_bitmap->bitmap().setAlphaType(alpha ? kPremul_SkAlphaType : kOpaque_SkAlph
aType); | 136 m_bitmap.setAlphaType(alpha ? kPremul_SkAlphaType : kOpaque_SkAlphaType); |
| 139 } | 137 } |
| 140 | 138 |
| 141 void ImageFrame::setStatus(Status status) | 139 void ImageFrame::setStatus(Status status) |
| 142 { | 140 { |
| 143 m_status = status; | 141 m_status = status; |
| 144 if (m_status == FrameComplete) { | 142 if (m_status == FrameComplete) { |
| 145 m_bitmap->bitmap().setAlphaType(m_hasAlpha ? kPremul_SkAlphaType : kOpaq
ue_SkAlphaType); | 143 m_bitmap.setAlphaType(m_hasAlpha ? kPremul_SkAlphaType : kOpaque_SkAlpha
Type); |
| 146 // Send pending pixels changed notifications now, because we can't do th
is after | 144 // Send pending pixels changed notifications now, because we can't do th
is after |
| 147 // the bitmap was set immutable by setDataComplete(). | 145 // the bitmap has been marked immutable. |
| 148 notifyBitmapIfPixelsChanged(); | 146 notifyBitmapIfPixelsChanged(); |
| 149 m_bitmap->setDataComplete(); // Tell the bitmap it's done. | 147 m_bitmap.setImmutable(); // Tell the bitmap it's done. |
| 150 } | 148 } |
| 151 } | 149 } |
| 152 | 150 |
| 153 void ImageFrame::zeroFillFrameRect(const IntRect& rect) | 151 void ImageFrame::zeroFillFrameRect(const IntRect& rect) |
| 154 { | 152 { |
| 155 if (rect.isEmpty()) | 153 if (rect.isEmpty()) |
| 156 return; | 154 return; |
| 157 | 155 |
| 158 m_bitmap->bitmap().eraseArea(rect, SkColorSetARGB(0, 0, 0, 0)); | 156 m_bitmap.eraseArea(rect, SkColorSetARGB(0, 0, 0, 0)); |
| 159 setHasAlpha(true); | 157 setHasAlpha(true); |
| 160 } | 158 } |
| 161 | 159 |
| 162 } // namespace WebCore | 160 } // namespace WebCore |
| OLD | NEW |