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 85 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
96 DCHECK_NE(this, other); | 96 DCHECK_NE(this, other); |
97 if (other->m_bitmap.isImmutable()) | 97 if (other->m_bitmap.isImmutable()) |
98 return false; | 98 return false; |
99 m_hasAlpha = other->m_hasAlpha; | 99 m_hasAlpha = other->m_hasAlpha; |
100 m_bitmap.reset(); | 100 m_bitmap.reset(); |
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::setSizeAndColorSpaceWithoutZeroFilling( |
107 int newHeight, | 107 int newWidth, |
108 sk_sp<SkColorSpace> colorSpace) { | 108 int newHeight, |
109 // setSizeAndColorSpace() should only be called once, it leaks memory | 109 sk_sp<SkColorSpace> colorSpace) { |
scroggo_chromium
2017/03/13 20:36:40
Why not add a boolean (or an enum) for zeroFill?
cblume
2017/03/13 21:53:12
I am happy to make it 1 function with a parameter
cblume
2017/03/16 11:03:30
I made a separate pull request that I think refact
| |
110 // otherwise. | 110 // Either setSizeAndColorSpaceWithoutZeroFilling() or setSizeAndcolorSpace() |
111 // should only be called once. It leaks memory otherwise. | |
scroggo_chromium
2017/03/13 20:36:40
This is a modified version of an existing comment,
cblume
2017/03/13 21:53:12
Okay. If it is safe then I think this comment shou
scroggo_chromium
2017/03/14 16:08:48
The idea of the ExternalMemoryAllocator is that so
| |
111 DCHECK(!width() && !height()); | 112 DCHECK(!width() && !height()); |
112 | 113 |
113 m_bitmap.setInfo(SkImageInfo::MakeN32( | 114 m_bitmap.setInfo(SkImageInfo::MakeN32( |
114 newWidth, newHeight, | 115 newWidth, newHeight, |
115 m_premultiplyAlpha ? kPremul_SkAlphaType : kUnpremul_SkAlphaType, | 116 m_premultiplyAlpha ? kPremul_SkAlphaType : kUnpremul_SkAlphaType, |
116 std::move(colorSpace))); | 117 std::move(colorSpace))); |
117 if (!m_bitmap.tryAllocPixels(m_allocator, 0)) | 118 if (!m_bitmap.tryAllocPixels(m_allocator, 0)) |
118 return false; | 119 return false; |
scroggo_chromium
2017/03/13 20:36:40
I don't like having two separate methods for this,
cblume
2017/03/13 21:53:12
Done.
| |
119 | 120 |
121 return true; | |
122 } | |
123 | |
124 bool ImageFrame::setSizeAndColorSpace(int newWidth, | |
125 int newHeight, | |
126 sk_sp<SkColorSpace> colorSpace) { | |
127 // Either setSizeAndColorSpaceWithoutZeroFilling() or setSizeAndcolorSpace() | |
128 // should only be called once. It leaks memory otherwise. | |
129 if (!setSizeAndColorSpaceWithoutZeroFilling(newWidth, newHeight, colorSpace)) | |
130 return false; | |
131 | |
120 zeroFillPixelData(); | 132 zeroFillPixelData(); |
121 return true; | 133 return true; |
122 } | 134 } |
123 | 135 |
124 bool ImageFrame::hasAlpha() const { | 136 bool ImageFrame::hasAlpha() const { |
125 return m_hasAlpha; | 137 return m_hasAlpha; |
126 } | 138 } |
127 | 139 |
128 sk_sp<SkImage> ImageFrame::finalizePixelsAndGetImage() { | 140 sk_sp<SkImage> ImageFrame::finalizePixelsAndGetImage() { |
129 DCHECK_EQ(FrameComplete, m_status); | 141 DCHECK_EQ(FrameComplete, m_status); |
(...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
207 // If the frame is not fully loaded, there will be transparent pixels, | 219 // 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 | 220 // so we can't tell skia we're opaque, even for image types that logically |
209 // always are (e.g. jpeg). | 221 // always are (e.g. jpeg). |
210 if (!m_hasAlpha && m_status == FrameComplete) | 222 if (!m_hasAlpha && m_status == FrameComplete) |
211 return kOpaque_SkAlphaType; | 223 return kOpaque_SkAlphaType; |
212 | 224 |
213 return m_premultiplyAlpha ? kPremul_SkAlphaType : kUnpremul_SkAlphaType; | 225 return m_premultiplyAlpha ? kPremul_SkAlphaType : kUnpremul_SkAlphaType; |
214 } | 226 } |
215 | 227 |
216 } // namespace blink | 228 } // namespace blink |
OLD | NEW |