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

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

Issue 2749703002: Refactor ImageFrame::setSizeAndColorSpace() (Closed)
Patch Set: Fix alloc returned value flipped Created 3 years, 9 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
(...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after
101 m_bitmap.swap(other->m_bitmap); 101 m_bitmap.swap(other->m_bitmap);
102 other->m_status = FrameEmpty; 102 other->m_status = FrameEmpty;
103 return true; 103 return true;
104 } 104 }
105 105
106 bool ImageFrame::setSizeAndColorSpace(int newWidth, 106 bool ImageFrame::setSizeAndColorSpace(int newWidth,
107 int newHeight, 107 int newHeight,
108 sk_sp<SkColorSpace> colorSpace) { 108 sk_sp<SkColorSpace> colorSpace) {
109 // setSizeAndColorSpace() should only be called once, it leaks memory 109 // setSizeAndColorSpace() should only be called once, it leaks memory
110 // otherwise. 110 // otherwise.
111 DCHECK(!width() && !height()); 111 DCHECK(!width() && !height());
Noel Gordon 2017/03/14 06:30:41 Yeah, this DCHECK looks entirely bogus to me now.
cblume 2017/03/14 07:59:51 I was talking to scroggo@ about the don't-leak-mem
f(malita) 2017/03/14 13:18:05 +1 to name change. Since this is supposed to be o
Noel Gordon 2017/03/14 14:26:26 Agree with the one-time initialization part. Howev
scroggo_chromium 2017/03/14 14:28:59 I think you're confused - this is ImageFrame, not
scroggo_chromium 2017/03/14 14:28:59 The ExternalMemoryAllocator supplies an SkPixelRef
Noel Gordon 2017/03/14 14:49:10 Ah yes, I was using ImageDecoder thinking, not Ima
cblume 2017/03/14 17:30:50 Name updated. Removed the comment.
112 112
113 m_bitmap.setInfo(SkImageInfo::MakeN32( 113 m_bitmap.setInfo(SkImageInfo::MakeN32(
114 newWidth, newHeight, 114 newWidth, newHeight,
115 m_premultiplyAlpha ? kPremul_SkAlphaType : kUnpremul_SkAlphaType, 115 m_premultiplyAlpha ? kPremul_SkAlphaType : kUnpremul_SkAlphaType,
116 std::move(colorSpace))); 116 std::move(colorSpace)));
117 if (!m_bitmap.tryAllocPixels(m_allocator, 0)) 117 return m_bitmap.tryAllocPixels(m_allocator, 0);
118 return false;
119
120 zeroFillPixelData();
121 return true;
122 } 118 }
123 119
124 bool ImageFrame::hasAlpha() const { 120 bool ImageFrame::hasAlpha() const {
125 return m_hasAlpha; 121 return m_hasAlpha;
126 } 122 }
127 123
128 sk_sp<SkImage> ImageFrame::finalizePixelsAndGetImage() { 124 sk_sp<SkImage> ImageFrame::finalizePixelsAndGetImage() {
129 DCHECK_EQ(FrameComplete, m_status); 125 DCHECK_EQ(FrameComplete, m_status);
130 m_bitmap.setImmutable(); 126 m_bitmap.setImmutable();
131 return SkImage::MakeFromBitmap(m_bitmap); 127 return SkImage::MakeFromBitmap(m_bitmap);
(...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after
207 // If the frame is not fully loaded, there will be transparent pixels, 203 // If the frame is not fully loaded, there will be transparent pixels,
208 // so we can't tell skia we're opaque, even for image types that logically 204 // so we can't tell skia we're opaque, even for image types that logically
209 // always are (e.g. jpeg). 205 // always are (e.g. jpeg).
210 if (!m_hasAlpha && m_status == FrameComplete) 206 if (!m_hasAlpha && m_status == FrameComplete)
211 return kOpaque_SkAlphaType; 207 return kOpaque_SkAlphaType;
212 208
213 return m_premultiplyAlpha ? kPremul_SkAlphaType : kUnpremul_SkAlphaType; 209 return m_premultiplyAlpha ? kPremul_SkAlphaType : kUnpremul_SkAlphaType;
214 } 210 }
215 211
216 } // namespace blink 212 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698