Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 1 // Copyright (c) 2017 The Chromium Authors. All rights reserved. | |
| 2 // Use of this source code is governed by a BSD-style license that can be | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 #include "platform/image-decoders/SegmentStream.h" | |
| 6 #include <utility> | |
| 7 #include "platform/image-decoders/SegmentReader.h" | |
| 8 | |
| 9 namespace blink { | |
| 10 | |
| 11 SegmentStream::SegmentStream() = default; | |
| 12 | |
| 13 SegmentStream::SegmentStream(SegmentStream&& rhs) | |
| 14 : reader_(std::move(rhs.reader_)), position_(rhs.position_) {} | |
|
scroggo_chromium
2017/08/15 19:57:31
Can this just be = default?
cblume
2017/08/16 07:49:16
Yes. The C++11 standard [1] says in §12.8/15
"The
| |
| 15 | |
| 16 SegmentStream::~SegmentStream() = default; | |
| 17 | |
| 18 SegmentStream& SegmentStream::operator=(SegmentStream&& rhs) { | |
|
scroggo_chromium
2017/08/15 19:57:31
Same question here.
| |
| 19 reader_ = std::move(rhs.reader_); | |
| 20 position_ = rhs.position_; | |
| 21 | |
| 22 return *this; | |
| 23 } | |
| 24 | |
| 25 void SegmentStream::SetReader(WTF::RefPtr<SegmentReader> reader) { | |
| 26 reader_ = std::move(reader); | |
| 27 } | |
| 28 | |
| 29 bool SegmentStream::IsCleared() const { | |
| 30 return !reader_ || position_ > reader_->size(); | |
| 31 } | |
| 32 | |
| 33 size_t SegmentStream::read(void* buffer, size_t size) { | |
| 34 if (IsCleared()) | |
|
scroggo_chromium
2017/08/15 19:57:31
Oh yeah, I forgot that you used |is_cleared_| inte
cblume
2017/08/16 07:49:16
Hrmmm we can.
The GIF decoder has a bunch of check
scroggo_chromium
2017/08/16 13:46:40
Other than this I think you've addressed my concer
cblume
2017/08/16 17:02:02
Oops. Sorry. Not sure why that didn't get uploaded
| |
| 35 return 0; | |
| 36 | |
| 37 size = std::min(size, reader_->size() - position_); | |
| 38 | |
| 39 size_t bytes_advanced = 0; | |
| 40 if (!buffer) { // skipping, not reading | |
| 41 bytes_advanced = size; | |
| 42 } else { | |
| 43 bytes_advanced = peek(buffer, size); | |
| 44 } | |
| 45 | |
| 46 position_ += bytes_advanced; | |
| 47 | |
| 48 return bytes_advanced; | |
| 49 } | |
| 50 | |
| 51 size_t SegmentStream::peek(void* buffer, size_t size) const { | |
| 52 if (IsCleared()) | |
| 53 return 0; | |
| 54 | |
| 55 size = std::min(size, reader_->size() - position_); | |
| 56 | |
| 57 size_t total_bytes_peeked = 0; | |
| 58 char* buffer_as_char_ptr = reinterpret_cast<char*>(buffer); | |
| 59 while (size) { | |
| 60 const char* segment = nullptr; | |
| 61 size_t bytes_peeked = | |
| 62 reader_->GetSomeData(segment, position_ + total_bytes_peeked); | |
| 63 if (!bytes_peeked) | |
| 64 break; | |
| 65 if (bytes_peeked > size) | |
| 66 bytes_peeked = size; | |
| 67 | |
| 68 memcpy(buffer_as_char_ptr, segment, bytes_peeked); | |
| 69 buffer_as_char_ptr += bytes_peeked; | |
| 70 size -= bytes_peeked; | |
| 71 total_bytes_peeked += bytes_peeked; | |
| 72 } | |
| 73 | |
| 74 return total_bytes_peeked; | |
| 75 } | |
| 76 | |
| 77 bool SegmentStream::isAtEnd() const { | |
| 78 return !reader_ || position_ >= reader_->size(); | |
| 79 } | |
| 80 | |
| 81 bool SegmentStream::rewind() { | |
| 82 position_ = 0; | |
| 83 return true; | |
| 84 } | |
| 85 | |
| 86 bool SegmentStream::seek(size_t position) { | |
| 87 position_ = position; | |
| 88 return true; | |
| 89 } | |
| 90 | |
| 91 bool SegmentStream::move(long offset) { | |
| 92 DCHECK_GT(offset, 0); | |
| 93 position_ += offset; | |
| 94 return true; | |
| 95 } | |
| 96 | |
| 97 size_t SegmentStream::getLength() const { | |
| 98 if (reader_) | |
| 99 return reader_->size(); | |
| 100 | |
| 101 return 0; | |
| 102 } | |
| 103 | |
| 104 } // namespace blink | |
| OLD | NEW |