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 |
11 * notice, this list of conditions and the following disclaimer in the | 11 * notice, this list of conditions and the following disclaimer in the |
12 * documentation and/or other materials provided with the distribution. | 12 * documentation and/or other materials provided with the distribution. |
13 * | 13 * |
14 * THIS SOFTWARE IS PROVIDED BY APPLE COMPUTER, INC. ``AS IS'' AND ANY | 14 * THIS SOFTWARE IS PROVIDED BY APPLE COMPUTER, INC. ``AS IS'' AND ANY |
15 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | 15 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE |
16 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR | 16 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR |
17 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE COMPUTER, INC. OR | 17 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE COMPUTER, INC. OR |
18 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, | 18 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, |
19 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, | 19 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, |
20 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR | 20 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR |
21 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY | 21 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY |
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/ImageFrame.h" | 27 #include "platform/image-decoders/ImageFrame.h" |
28 | 28 |
29 #include "platform/RuntimeEnabledFeatures.h" | 29 #include "platform/RuntimeEnabledFeatures.h" |
30 #include "platform/graphics/skia/SkiaUtils.h" | |
30 #include "platform/image-decoders/ImageDecoder.h" | 31 #include "platform/image-decoders/ImageDecoder.h" |
31 | 32 |
32 namespace blink { | 33 namespace blink { |
33 | 34 |
34 ImageFrame::ImageFrame() | 35 ImageFrame::ImageFrame() |
35 : m_allocator(0) | 36 : m_allocator(0) |
36 , m_hasAlpha(true) | 37 , m_hasAlpha(true) |
37 , m_status(FrameEmpty) | 38 , m_status(FrameEmpty) |
38 , m_duration(0) | 39 , m_duration(0) |
39 , m_disposalMethod(DisposeNotSpecified) | 40 , m_disposalMethod(DisposeNotSpecified) |
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
81 } | 82 } |
82 | 83 |
83 void ImageFrame::zeroFillPixelData() | 84 void ImageFrame::zeroFillPixelData() |
84 { | 85 { |
85 m_bitmap.eraseARGB(0, 0, 0, 0); | 86 m_bitmap.eraseARGB(0, 0, 0, 0); |
86 m_hasAlpha = true; | 87 m_hasAlpha = true; |
87 } | 88 } |
88 | 89 |
89 bool ImageFrame::copyBitmapData(const ImageFrame& other) | 90 bool ImageFrame::copyBitmapData(const ImageFrame& other) |
90 { | 91 { |
91 if (this == &other) | 92 DCHECK_NE(this, &other); |
92 return true; | |
93 | |
94 m_hasAlpha = other.m_hasAlpha; | 93 m_hasAlpha = other.m_hasAlpha; |
95 m_bitmap.reset(); | 94 m_bitmap.reset(); |
96 return other.m_bitmap.copyTo(&m_bitmap, other.m_bitmap.colorType()); | 95 return other.m_bitmap.copyTo(&m_bitmap, other.m_bitmap.colorType()); |
97 } | 96 } |
98 | 97 |
98 bool ImageFrame::takeBitmapDataIfWritable(ImageFrame* other) | |
99 { | |
100 DCHECK(other); | |
101 DCHECK_NE(this, other); | |
102 if (other->m_bitmap.isImmutable()) | |
103 return false; | |
104 m_hasAlpha = other->m_hasAlpha; | |
105 m_bitmap.reset(); | |
106 m_bitmap.swap(other->m_bitmap); | |
107 other->m_status = FrameEmpty; | |
108 return true; | |
109 } | |
110 | |
99 bool ImageFrame::setSizeAndColorProfile(int newWidth, int newHeight, const ICCPr ofile& newIccProfile) | 111 bool ImageFrame::setSizeAndColorProfile(int newWidth, int newHeight, const ICCPr ofile& newIccProfile) |
100 { | 112 { |
101 // setSizeAndColorProfile() should only be called once, it leaks memory othe rwise. | 113 // setSizeAndColorProfile() should only be called once, it leaks memory othe rwise. |
102 ASSERT(!width() && !height()); | 114 ASSERT(!width() && !height()); |
103 | 115 |
104 sk_sp<SkColorSpace> colorSpace; | 116 sk_sp<SkColorSpace> colorSpace; |
105 if (RuntimeEnabledFeatures::colorCorrectRenderingEnabled() && !newIccProfile .isEmpty()) | 117 if (RuntimeEnabledFeatures::colorCorrectRenderingEnabled() && !newIccProfile .isEmpty()) |
106 colorSpace = SkColorSpace::NewICC(newIccProfile.data(), newIccProfile.si ze()); | 118 colorSpace = SkColorSpace::NewICC(newIccProfile.data(), newIccProfile.si ze()); |
107 | 119 |
108 m_bitmap.setInfo(SkImageInfo::MakeN32(newWidth, newHeight, | 120 m_bitmap.setInfo(SkImageInfo::MakeN32(newWidth, newHeight, |
109 m_premultiplyAlpha ? kPremul_SkAlphaType : kUnpremul_SkAlphaType, colorS pace)); | 121 m_premultiplyAlpha ? kPremul_SkAlphaType : kUnpremul_SkAlphaType, colorS pace)); |
110 if (!m_bitmap.tryAllocPixels(m_allocator, 0)) | 122 if (!m_bitmap.tryAllocPixels(m_allocator, 0)) |
111 return false; | 123 return false; |
112 | 124 |
113 zeroFillPixelData(); | 125 zeroFillPixelData(); |
114 return true; | 126 return true; |
115 } | 127 } |
116 | 128 |
117 bool ImageFrame::hasAlpha() const | 129 bool ImageFrame::hasAlpha() const |
118 { | 130 { |
119 return m_hasAlpha; | 131 return m_hasAlpha; |
120 } | 132 } |
121 | 133 |
134 sk_sp<SkImage> ImageFrame::finalizePixelsAndGetImage() | |
135 { | |
136 DCHECK(m_status == FrameComplete); | |
Peter Kasting
2016/09/22 21:44:08
Nit: DCHECK_EQ(FrameComplete, m_status)
aleksandar.stojiljkovic
2016/09/27 18:08:28
Done.
| |
137 | |
138 // We don't set the status to immutable until there is a request to get | |
139 // SkImage and decoding is done. We set the bitmap to immutable here to | |
140 // avoid copying in SkImage::MakeFromBitmap. | |
Peter Kasting
2016/09/22 21:44:08
Nit: Second sentence is already in the header and
aleksandar.stojiljkovic
2016/09/27 18:08:28
Done. Rephrased it, removed the note about copy as
| |
141 if (!m_bitmap.isImmutable()) | |
Peter Kasting
2016/09/22 21:44:08
Nit: Conditional check unnecessary
aleksandar.stojiljkovic
2016/09/27 18:08:28
Done.
| |
142 m_bitmap.setImmutable(); | |
143 return SkImage::MakeFromBitmap(m_bitmap); | |
144 } | |
145 | |
122 void ImageFrame::setHasAlpha(bool alpha) | 146 void ImageFrame::setHasAlpha(bool alpha) |
123 { | 147 { |
124 m_hasAlpha = alpha; | 148 m_hasAlpha = alpha; |
125 | 149 |
126 m_bitmap.setAlphaType(computeAlphaType()); | 150 m_bitmap.setAlphaType(computeAlphaType()); |
127 } | 151 } |
128 | 152 |
129 void ImageFrame::setStatus(Status status) | 153 void ImageFrame::setStatus(Status status) |
130 { | 154 { |
131 m_status = status; | 155 m_status = status; |
132 if (m_status == FrameComplete) { | 156 if (m_status == FrameComplete) { |
133 m_bitmap.setAlphaType(computeAlphaType()); | 157 m_bitmap.setAlphaType(computeAlphaType()); |
134 // Send pending pixels changed notifications now, because we can't do th is after | 158 // Send pending pixels changed notifications now, because we can't do th is after |
135 // the bitmap has been marked immutable. | 159 // the bitmap has been marked immutable. |
136 notifyBitmapIfPixelsChanged(); | 160 notifyBitmapIfPixelsChanged(); |
137 m_bitmap.setImmutable(); // Tell the bitmap it's done. | |
138 } | 161 } |
139 } | 162 } |
140 | 163 |
141 void ImageFrame::zeroFillFrameRect(const IntRect& rect) | 164 void ImageFrame::zeroFillFrameRect(const IntRect& rect) |
142 { | 165 { |
143 if (rect.isEmpty()) | 166 if (rect.isEmpty()) |
144 return; | 167 return; |
145 | 168 |
146 m_bitmap.eraseArea(rect, SkColorSetARGB(0, 0, 0, 0)); | 169 m_bitmap.eraseArea(rect, SkColorSetARGB(0, 0, 0, 0)); |
147 setHasAlpha(true); | 170 setHasAlpha(true); |
148 } | 171 } |
149 | 172 |
150 SkAlphaType ImageFrame::computeAlphaType() const | 173 SkAlphaType ImageFrame::computeAlphaType() const |
151 { | 174 { |
152 // If the frame is not fully loaded, there will be transparent pixels, | 175 // If the frame is not fully loaded, there will be transparent pixels, |
153 // so we can't tell skia we're opaque, even for image types that logically | 176 // so we can't tell skia we're opaque, even for image types that logically |
154 // always are (e.g. jpeg). | 177 // always are (e.g. jpeg). |
155 if (!m_hasAlpha && m_status == FrameComplete) | 178 if (!m_hasAlpha && m_status == FrameComplete) |
156 return kOpaque_SkAlphaType; | 179 return kOpaque_SkAlphaType; |
157 | 180 |
158 return m_premultiplyAlpha ? kPremul_SkAlphaType : kUnpremul_SkAlphaType; | 181 return m_premultiplyAlpha ? kPremul_SkAlphaType : kUnpremul_SkAlphaType; |
159 } | 182 } |
160 | 183 |
161 } // namespace blink | 184 } // namespace blink |
OLD | NEW |