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

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

Issue 2080623002: Revert "Remove OwnPtr from Blink." (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 6 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. 2 * Copyright (C) 2006 Apple Computer, Inc.
3 * Copyright (C) Research In Motion Limited 2009-2010. All rights reserved. 3 * Copyright (C) Research In Motion Limited 2009-2010. All rights reserved.
4 * 4 *
5 * Portions are Copyright (C) 2001 mozilla.org 5 * Portions are Copyright (C) 2001 mozilla.org
6 * 6 *
7 * Other contributors: 7 * Other contributors:
8 * Stuart Parmenter <stuart@mozilla.com> 8 * Stuart Parmenter <stuart@mozilla.com>
9 * 9 *
10 * This library is free software; you can redistribute it and/or 10 * This library is free software; you can redistribute it and/or
(...skipping 21 matching lines...) Expand all
32 * version of this file under the LGPL, indicate your decision by 32 * version of this file under the LGPL, indicate your decision by
33 * deletingthe provisions above and replace them with the notice and 33 * deletingthe provisions above and replace them with the notice and
34 * other provisions required by the MPL or the GPL, as the case may be. 34 * other provisions required by the MPL or the GPL, as the case may be.
35 * If you do not delete the provisions above, a recipient may use your 35 * If you do not delete the provisions above, a recipient may use your
36 * version of this file under any of the LGPL, the MPL or the GPL. 36 * version of this file under any of the LGPL, the MPL or the GPL.
37 */ 37 */
38 38
39 #include "platform/image-decoders/png/PNGImageDecoder.h" 39 #include "platform/image-decoders/png/PNGImageDecoder.h"
40 40
41 #include "png.h" 41 #include "png.h"
42 #include "wtf/PtrUtil.h"
43 #include <memory>
44 42
45 #if !defined(PNG_LIBPNG_VER_MAJOR) || !defined(PNG_LIBPNG_VER_MINOR) 43 #if !defined(PNG_LIBPNG_VER_MAJOR) || !defined(PNG_LIBPNG_VER_MINOR)
46 #error version error: compile against a versioned libpng. 44 #error version error: compile against a versioned libpng.
47 #endif 45 #endif
48 #if USE(QCMSLIB) 46 #if USE(QCMSLIB)
49 #include "qcms.h" 47 #include "qcms.h"
50 #endif 48 #endif
51 49
52 #if PNG_LIBPNG_VER_MAJOR > 1 || (PNG_LIBPNG_VER_MAJOR == 1 && PNG_LIBPNG_VER_MIN OR >= 4) 50 #if PNG_LIBPNG_VER_MAJOR > 1 || (PNG_LIBPNG_VER_MAJOR == 1 && PNG_LIBPNG_VER_MIN OR >= 4)
53 #define JMPBUF(png_ptr) png_jmpbuf(png_ptr) 51 #define JMPBUF(png_ptr) png_jmpbuf(png_ptr)
(...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after
137 png_infop infoPtr() const { return m_info; } 135 png_infop infoPtr() const { return m_info; }
138 136
139 size_t getReadOffset() const { return m_readOffset; } 137 size_t getReadOffset() const { return m_readOffset; }
140 void setReadOffset(size_t offset) { m_readOffset = offset; } 138 void setReadOffset(size_t offset) { m_readOffset = offset; }
141 size_t currentBufferSize() const { return m_currentBufferSize; } 139 size_t currentBufferSize() const { return m_currentBufferSize; }
142 bool decodingSizeOnly() const { return m_decodingSizeOnly; } 140 bool decodingSizeOnly() const { return m_decodingSizeOnly; }
143 void setHasAlpha(bool hasAlpha) { m_hasAlpha = hasAlpha; } 141 void setHasAlpha(bool hasAlpha) { m_hasAlpha = hasAlpha; }
144 bool hasAlpha() const { return m_hasAlpha; } 142 bool hasAlpha() const { return m_hasAlpha; }
145 143
146 png_bytep interlaceBuffer() const { return m_interlaceBuffer.get(); } 144 png_bytep interlaceBuffer() const { return m_interlaceBuffer.get(); }
147 void createInterlaceBuffer(int size) { m_interlaceBuffer = wrapArrayUnique(n ew png_byte[size]); } 145 void createInterlaceBuffer(int size) { m_interlaceBuffer = adoptArrayPtr(new png_byte[size]); }
148 #if USE(QCMSLIB) 146 #if USE(QCMSLIB)
149 png_bytep rowBuffer() const { return m_rowBuffer.get(); } 147 png_bytep rowBuffer() const { return m_rowBuffer.get(); }
150 void createRowBuffer(int size) { m_rowBuffer = wrapArrayUnique(new png_byte[ size]); } 148 void createRowBuffer(int size) { m_rowBuffer = adoptArrayPtr(new png_byte[si ze]); }
151 #endif 149 #endif
152 150
153 private: 151 private:
154 png_structp m_png; 152 png_structp m_png;
155 png_infop m_info; 153 png_infop m_info;
156 PNGImageDecoder* m_decoder; 154 PNGImageDecoder* m_decoder;
157 size_t m_readOffset; 155 size_t m_readOffset;
158 size_t m_currentBufferSize; 156 size_t m_currentBufferSize;
159 bool m_decodingSizeOnly; 157 bool m_decodingSizeOnly;
160 bool m_hasAlpha; 158 bool m_hasAlpha;
161 std::unique_ptr<png_byte[]> m_interlaceBuffer; 159 OwnPtr<png_byte[]> m_interlaceBuffer;
162 #if USE(QCMSLIB) 160 #if USE(QCMSLIB)
163 std::unique_ptr<png_byte[]> m_rowBuffer; 161 OwnPtr<png_byte[]> m_rowBuffer;
164 #endif 162 #endif
165 }; 163 };
166 164
167 PNGImageDecoder::PNGImageDecoder(AlphaOption alphaOption, GammaAndColorProfileOp tion colorOptions, size_t maxDecodedBytes, size_t offset) 165 PNGImageDecoder::PNGImageDecoder(AlphaOption alphaOption, GammaAndColorProfileOp tion colorOptions, size_t maxDecodedBytes, size_t offset)
168 : ImageDecoder(alphaOption, colorOptions, maxDecodedBytes) 166 : ImageDecoder(alphaOption, colorOptions, maxDecodedBytes)
169 , m_offset(offset) 167 , m_offset(offset)
170 { 168 {
171 } 169 }
172 170
173 PNGImageDecoder::~PNGImageDecoder() 171 PNGImageDecoder::~PNGImageDecoder()
(...skipping 249 matching lines...) Expand 10 before | Expand all | Expand 10 after
423 { 421 {
424 return decoder->frameIsCompleteAtIndex(0); 422 return decoder->frameIsCompleteAtIndex(0);
425 } 423 }
426 424
427 void PNGImageDecoder::decode(bool onlySize) 425 void PNGImageDecoder::decode(bool onlySize)
428 { 426 {
429 if (failed()) 427 if (failed())
430 return; 428 return;
431 429
432 if (!m_reader) 430 if (!m_reader)
433 m_reader = wrapUnique(new PNGImageReader(this, m_offset)); 431 m_reader = adoptPtr(new PNGImageReader(this, m_offset));
434 432
435 // If we couldn't decode the image but have received all the data, decoding 433 // If we couldn't decode the image but have received all the data, decoding
436 // has failed. 434 // has failed.
437 if (!m_reader->decode(*m_data, onlySize) && isAllDataReceived()) 435 if (!m_reader->decode(*m_data, onlySize) && isAllDataReceived())
438 setFailed(); 436 setFailed();
439 437
440 // If decoding is done or failed, we don't need the PNGImageReader anymore. 438 // If decoding is done or failed, we don't need the PNGImageReader anymore.
441 if (isComplete(this) || failed()) 439 if (isComplete(this) || failed())
442 m_reader.reset(); 440 m_reader.reset();
443 } 441 }
444 442
445 } // namespace blink 443 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698