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

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

Issue 1812273003: Eliminate copies of encoded image data (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Rebase Created 4 years, 8 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 * 3 *
4 * Portions are Copyright (C) 2001-6 mozilla.org 4 * Portions are Copyright (C) 2001-6 mozilla.org
5 * 5 *
6 * Other contributors: 6 * Other contributors:
7 * Stuart Parmenter <stuart@mozilla.com> 7 * Stuart Parmenter <stuart@mozilla.com>
8 * 8 *
9 * This library is free software; you can redistribute it and/or 9 * This library is free software; you can redistribute it and/or
10 * modify it under the terms of the GNU Lesser General Public 10 * modify it under the terms of the GNU Lesser General Public
(...skipping 343 matching lines...) Expand 10 before | Expand all | Expand 10 after
354 } 354 }
355 355
356 m_nextReadPosition += bytes; 356 m_nextReadPosition += bytes;
357 m_info.src->bytes_in_buffer = bytes; 357 m_info.src->bytes_in_buffer = bytes;
358 const JOCTET* nextByte = reinterpret_cast_ptr<const JOCTET*>(segment); 358 const JOCTET* nextByte = reinterpret_cast_ptr<const JOCTET*>(segment);
359 m_info.src->next_input_byte = nextByte; 359 m_info.src->next_input_byte = nextByte;
360 m_lastSetByte = nextByte; 360 m_lastSetByte = nextByte;
361 return true; 361 return true;
362 } 362 }
363 363
364 void setData(SharedBuffer* data) 364 void setData(SegmentReader* data)
365 { 365 {
366 if (m_data.get() == data) 366 if (m_data.get() == data)
367 return; 367 return;
368 368
369 m_data = data; 369 m_data = data;
370 370
371 // If a restart is needed, the next call to fillBuffer will read from th e new SharedBuffer. 371 // If a restart is needed, the next call to fillBuffer will read from th e new SegmentReader.
372 if (m_needsRestart) 372 if (m_needsRestart)
373 return; 373 return;
374 374
375 // Otherwise, empty the buffer, and leave the position the same, so fill Buffer continues 375 // Otherwise, empty the buffer, and leave the position the same, so fill Buffer continues
376 // reading from the same position in the new SharedBuffer. 376 // reading from the same position in the new SegmentReader.
377 m_nextReadPosition -= m_info.src->bytes_in_buffer; 377 m_nextReadPosition -= m_info.src->bytes_in_buffer;
378 clearBuffer(); 378 clearBuffer();
379 } 379 }
380 380
381 bool decode(bool onlySize) 381 bool decode(bool onlySize)
382 { 382 {
383 // We need to do the setjmp here. Otherwise bad things will happen 383 // We need to do the setjmp here. Otherwise bad things will happen
384 if (setjmp(m_err.setjmp_buffer)) 384 if (setjmp(m_err.setjmp_buffer))
385 return m_decoder->setFailed(); 385 return m_decoder->setFailed();
386 386
(...skipping 243 matching lines...) Expand 10 before | Expand all | Expand 10 after
630 } 630 }
631 631
632 void clearBuffer() 632 void clearBuffer()
633 { 633 {
634 // Let libjpeg know that the buffer needs to be refilled. 634 // Let libjpeg know that the buffer needs to be refilled.
635 m_info.src->bytes_in_buffer = 0; 635 m_info.src->bytes_in_buffer = 0;
636 m_info.src->next_input_byte = nullptr; 636 m_info.src->next_input_byte = nullptr;
637 m_lastSetByte = nullptr; 637 m_lastSetByte = nullptr;
638 } 638 }
639 639
640 RefPtr<SharedBuffer> m_data; 640 RefPtr<SegmentReader> m_data;
641 JPEGImageDecoder* m_decoder; 641 JPEGImageDecoder* m_decoder;
642 642
643 // Input reading: True if we need to back up to m_restartPosition. 643 // Input reading: True if we need to back up to m_restartPosition.
644 bool m_needsRestart; 644 bool m_needsRestart;
645 // If libjpeg needed to restart, this is the position to restart from. 645 // If libjpeg needed to restart, this is the position to restart from.
646 size_t m_restartPosition; 646 size_t m_restartPosition;
647 // This is the position where we will read from, unless there is a restart. 647 // This is the position where we will read from, unless there is a restart.
648 size_t m_nextReadPosition; 648 size_t m_nextReadPosition;
649 // This is how we know to update the restart position. It is the last value 649 // This is how we know to update the restart position. It is the last value
650 // we set to next_input_byte. libjpeg will update next_input_byte when it 650 // we set to next_input_byte. libjpeg will update next_input_byte when it
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after
716 if (!ImageDecoder::setSize(width, height)) 716 if (!ImageDecoder::setSize(width, height))
717 return false; 717 return false;
718 718
719 if (!desiredScaleNumerator()) 719 if (!desiredScaleNumerator())
720 return setFailed(); 720 return setFailed();
721 721
722 setDecodedSize(width, height); 722 setDecodedSize(width, height);
723 return true; 723 return true;
724 } 724 }
725 725
726 void JPEGImageDecoder::onSetData(SharedBuffer* data) 726 void JPEGImageDecoder::onSetData(SegmentReader* data)
727 { 727 {
728 if (m_reader) 728 if (m_reader)
729 m_reader->setData(data); 729 m_reader->setData(data);
730 } 730 }
731 731
732 void JPEGImageDecoder::setDecodedSize(unsigned width, unsigned height) 732 void JPEGImageDecoder::setDecodedSize(unsigned width, unsigned height)
733 { 733 {
734 m_decodedSize = IntSize(width, height); 734 m_decodedSize = IntSize(width, height);
735 } 735 }
736 736
(...skipping 251 matching lines...) Expand 10 before | Expand all | Expand 10 after
988 // has failed. 988 // has failed.
989 if (!m_reader->decode(onlySize) && isAllDataReceived()) 989 if (!m_reader->decode(onlySize) && isAllDataReceived())
990 setFailed(); 990 setFailed();
991 991
992 // If decoding is done or failed, we don't need the JPEGImageReader anymore. 992 // If decoding is done or failed, we don't need the JPEGImageReader anymore.
993 if (isComplete(this, onlySize) || failed()) 993 if (isComplete(this, onlySize) || failed())
994 m_reader.clear(); 994 m_reader.clear();
995 } 995 }
996 996
997 } // namespace blink 997 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698