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

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: Remove unecessary color check in ImageBitmap. Thanks dcheng@. 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_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;
Ken Russell (switch to Gerrit) 2016/09/29 00:40:04 What about all of the other fields of this ImageFr
aleksandar.stojiljkovic 2016/09/29 08:03:53 For both clients, GIF and WebP right after this ca
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()) { 117 if (RuntimeEnabledFeatures::colorCorrectRenderingEnabled()) {
106 if (newIccProfile.isEmpty()) 118 if (newIccProfile.isEmpty())
107 colorSpace = SkColorSpace::NewNamed(SkColorSpace::kSRGB_Named); 119 colorSpace = SkColorSpace::NewNamed(SkColorSpace::kSRGB_Named);
108 else 120 else
109 colorSpace = SkColorSpace::NewICC(newIccProfile.data(), newIccProfil e.size()); 121 colorSpace = SkColorSpace::NewICC(newIccProfile.data(), newIccProfil e.size());
110 DCHECK(colorSpace); 122 DCHECK(colorSpace);
111 } 123 }
112 124
113 m_bitmap.setInfo(SkImageInfo::MakeN32(newWidth, newHeight, 125 m_bitmap.setInfo(SkImageInfo::MakeN32(newWidth, newHeight,
114 m_premultiplyAlpha ? kPremul_SkAlphaType : kUnpremul_SkAlphaType, colorS pace)); 126 m_premultiplyAlpha ? kPremul_SkAlphaType : kUnpremul_SkAlphaType, colorS pace));
115 if (!m_bitmap.tryAllocPixels(m_allocator, 0)) 127 if (!m_bitmap.tryAllocPixels(m_allocator, 0))
116 return false; 128 return false;
117 129
118 zeroFillPixelData(); 130 zeroFillPixelData();
119 return true; 131 return true;
120 } 132 }
121 133
122 bool ImageFrame::hasAlpha() const 134 bool ImageFrame::hasAlpha() const
123 { 135 {
124 return m_hasAlpha; 136 return m_hasAlpha;
125 } 137 }
126 138
139 sk_sp<SkImage> ImageFrame::finalizePixelsAndGetImage()
140 {
141 DCHECK_EQ(FrameComplete, m_status);
142 m_bitmap.setImmutable();
143 return SkImage::MakeFromBitmap(m_bitmap);
144 }
145
127 void ImageFrame::setHasAlpha(bool alpha) 146 void ImageFrame::setHasAlpha(bool alpha)
128 { 147 {
129 m_hasAlpha = alpha; 148 m_hasAlpha = alpha;
130 149
131 m_bitmap.setAlphaType(computeAlphaType()); 150 m_bitmap.setAlphaType(computeAlphaType());
132 } 151 }
133 152
134 void ImageFrame::setStatus(Status status) 153 void ImageFrame::setStatus(Status status)
135 { 154 {
136 m_status = status; 155 m_status = status;
137 if (m_status == FrameComplete) { 156 if (m_status == FrameComplete) {
138 m_bitmap.setAlphaType(computeAlphaType()); 157 m_bitmap.setAlphaType(computeAlphaType());
139 // 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
140 // the bitmap has been marked immutable. 159 // this after the bitmap has been marked immutable. We don't set the
160 // bitmap immutable here because it would defeat
161 // takeBitmapDataIfWritable(). Instead we let the bitmap stay mutable
162 // until someone calls finalizePixelsAndGetImage() to actually get the
163 // SkImage.
141 notifyBitmapIfPixelsChanged(); 164 notifyBitmapIfPixelsChanged();
142 m_bitmap.setImmutable(); // Tell the bitmap it's done.
143 } 165 }
144 } 166 }
145 167
146 void ImageFrame::zeroFillFrameRect(const IntRect& rect) 168 void ImageFrame::zeroFillFrameRect(const IntRect& rect)
147 { 169 {
148 if (rect.isEmpty()) 170 if (rect.isEmpty())
149 return; 171 return;
150 172
151 m_bitmap.eraseArea(rect, SkColorSetARGB(0, 0, 0, 0)); 173 m_bitmap.eraseArea(rect, SkColorSetARGB(0, 0, 0, 0));
152 setHasAlpha(true); 174 setHasAlpha(true);
153 } 175 }
154 176
155 SkAlphaType ImageFrame::computeAlphaType() const 177 SkAlphaType ImageFrame::computeAlphaType() const
156 { 178 {
157 // If the frame is not fully loaded, there will be transparent pixels, 179 // 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 180 // so we can't tell skia we're opaque, even for image types that logically
159 // always are (e.g. jpeg). 181 // always are (e.g. jpeg).
160 if (!m_hasAlpha && m_status == FrameComplete) 182 if (!m_hasAlpha && m_status == FrameComplete)
161 return kOpaque_SkAlphaType; 183 return kOpaque_SkAlphaType;
162 184
163 return m_premultiplyAlpha ? kPremul_SkAlphaType : kUnpremul_SkAlphaType; 185 return m_premultiplyAlpha ? kPremul_SkAlphaType : kUnpremul_SkAlphaType;
164 } 186 }
165 187
166 } // namespace blink 188 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698