Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(365)

Side by Side Diff: third_party/WebKit/Source/platform/image-decoders/ImageFrame.cpp

Issue 2155973002: Save a bitmap copy when advancing to dependent GIF and WebP animation frames (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: DCHECK m_status in ImageFrame. Shortened commit message. Thanks kbr@. Created 4 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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
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_EQ(FrameComplete, other->m_status);
102 DCHECK_EQ(FrameEmpty, m_status);
103 DCHECK_NE(this, other);
104 if (other->m_bitmap.isImmutable())
105 return false;
106 m_hasAlpha = other->m_hasAlpha;
107 m_bitmap.reset();
108 m_bitmap.swap(other->m_bitmap);
109 other->m_status = FrameEmpty;
110 return true;
111 }
112
99 bool ImageFrame::setSizeAndColorProfile(int newWidth, int newHeight, const ICCPr ofile& newIccProfile) 113 bool ImageFrame::setSizeAndColorProfile(int newWidth, int newHeight, const ICCPr ofile& newIccProfile)
100 { 114 {
101 // setSizeAndColorProfile() should only be called once, it leaks memory othe rwise. 115 // setSizeAndColorProfile() should only be called once, it leaks memory othe rwise.
102 ASSERT(!width() && !height()); 116 ASSERT(!width() && !height());
103 117
104 sk_sp<SkColorSpace> colorSpace; 118 sk_sp<SkColorSpace> colorSpace;
105 if (RuntimeEnabledFeatures::colorCorrectRenderingEnabled()) { 119 if (RuntimeEnabledFeatures::colorCorrectRenderingEnabled()) {
106 if (newIccProfile.isEmpty()) 120 if (newIccProfile.isEmpty())
107 colorSpace = SkColorSpace::NewNamed(SkColorSpace::kSRGB_Named); 121 colorSpace = SkColorSpace::NewNamed(SkColorSpace::kSRGB_Named);
108 else 122 else
109 colorSpace = SkColorSpace::NewICC(newIccProfile.data(), newIccProfil e.size()); 123 colorSpace = SkColorSpace::NewICC(newIccProfile.data(), newIccProfil e.size());
110 DCHECK(colorSpace); 124 DCHECK(colorSpace);
111 } 125 }
112 126
113 m_bitmap.setInfo(SkImageInfo::MakeN32(newWidth, newHeight, 127 m_bitmap.setInfo(SkImageInfo::MakeN32(newWidth, newHeight,
114 m_premultiplyAlpha ? kPremul_SkAlphaType : kUnpremul_SkAlphaType, colorS pace)); 128 m_premultiplyAlpha ? kPremul_SkAlphaType : kUnpremul_SkAlphaType, colorS pace));
115 if (!m_bitmap.tryAllocPixels(m_allocator, 0)) 129 if (!m_bitmap.tryAllocPixels(m_allocator, 0))
116 return false; 130 return false;
117 131
118 zeroFillPixelData(); 132 zeroFillPixelData();
119 return true; 133 return true;
120 } 134 }
121 135
122 bool ImageFrame::hasAlpha() const 136 bool ImageFrame::hasAlpha() const
123 { 137 {
124 return m_hasAlpha; 138 return m_hasAlpha;
125 } 139 }
126 140
141 sk_sp<SkImage> ImageFrame::finalizePixelsAndGetImage()
142 {
143 DCHECK_EQ(FrameComplete, m_status);
144 m_bitmap.setImmutable();
145 return SkImage::MakeFromBitmap(m_bitmap);
146 }
147
127 void ImageFrame::setHasAlpha(bool alpha) 148 void ImageFrame::setHasAlpha(bool alpha)
128 { 149 {
129 m_hasAlpha = alpha; 150 m_hasAlpha = alpha;
130 151
131 m_bitmap.setAlphaType(computeAlphaType()); 152 m_bitmap.setAlphaType(computeAlphaType());
132 } 153 }
133 154
134 void ImageFrame::setStatus(Status status) 155 void ImageFrame::setStatus(Status status)
135 { 156 {
136 m_status = status; 157 m_status = status;
137 if (m_status == FrameComplete) { 158 if (m_status == FrameComplete) {
138 m_bitmap.setAlphaType(computeAlphaType()); 159 m_bitmap.setAlphaType(computeAlphaType());
139 // Send pending pixels changed notifications now, because we can't do th is after 160 // Send pending pixels changed notifications now, because we can't do
140 // the bitmap has been marked immutable. 161 // this after the bitmap has been marked immutable. We don't set the
162 // bitmap immutable here because it would defeat
163 // takeBitmapDataIfWritable(). Instead we let the bitmap stay mutable
164 // until someone calls finalizePixelsAndGetImage() to actually get the
165 // SkImage.
141 notifyBitmapIfPixelsChanged(); 166 notifyBitmapIfPixelsChanged();
142 m_bitmap.setImmutable(); // Tell the bitmap it's done.
143 } 167 }
144 } 168 }
145 169
146 void ImageFrame::zeroFillFrameRect(const IntRect& rect) 170 void ImageFrame::zeroFillFrameRect(const IntRect& rect)
147 { 171 {
148 if (rect.isEmpty()) 172 if (rect.isEmpty())
149 return; 173 return;
150 174
151 m_bitmap.eraseArea(rect, SkColorSetARGB(0, 0, 0, 0)); 175 m_bitmap.eraseArea(rect, SkColorSetARGB(0, 0, 0, 0));
152 setHasAlpha(true); 176 setHasAlpha(true);
153 } 177 }
154 178
155 SkAlphaType ImageFrame::computeAlphaType() const 179 SkAlphaType ImageFrame::computeAlphaType() const
156 { 180 {
157 // If the frame is not fully loaded, there will be transparent pixels, 181 // If the frame is not fully loaded, there will be transparent pixels,
158 // so we can't tell skia we're opaque, even for image types that logically 182 // so we can't tell skia we're opaque, even for image types that logically
159 // always are (e.g. jpeg). 183 // always are (e.g. jpeg).
160 if (!m_hasAlpha && m_status == FrameComplete) 184 if (!m_hasAlpha && m_status == FrameComplete)
161 return kOpaque_SkAlphaType; 185 return kOpaque_SkAlphaType;
162 186
163 return m_premultiplyAlpha ? kPremul_SkAlphaType : kUnpremul_SkAlphaType; 187 return m_premultiplyAlpha ? kPremul_SkAlphaType : kUnpremul_SkAlphaType;
164 } 188 }
165 189
166 } // namespace blink 190 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698