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

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

Issue 2930513004: [WIP] Move ImageDecoders to SkCodec
Patch Set: Adding check for decoder creation Created 3 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
(Empty)
1 /*
2 * Copyright (C) 2015 Google Inc. All rights reserved.
3 *
4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions are
6 * met:
7 *
8 * * Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer.
10 * * Redistributions in binary form must reproduce the above
11 * copyright notice, this list of conditions and the following disclaimer
12 * in the documentation and/or other materials provided with the
13 * distribution.
14 * * Neither the name of Google Inc. nor the names of its
15 * contributors may be used to endorse or promote products derived from
16 * this software without specific prior written permission.
17 *
18 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
19 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
20 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
21 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
22 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
23 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
24 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
25 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
26 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
27 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
28 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29 */
30
31 #include "platform/image-decoders/FastSharedBufferReader.h"
32
33 namespace blink {
34
35 FastSharedBufferReader::FastSharedBufferReader(PassRefPtr<SegmentReader> data)
36 : data_(std::move(data)),
37 segment_(0),
38 segment_length_(0),
39 data_position_(0) {}
40
41 void FastSharedBufferReader::SetData(PassRefPtr<SegmentReader> data) {
42 if (data == data_)
43 return;
44 data_ = std::move(data);
45 ClearCache();
46 }
47
48 void FastSharedBufferReader::ClearCache() {
49 segment_ = 0;
50 segment_length_ = 0;
51 data_position_ = 0;
52 }
53
54 const char* FastSharedBufferReader::GetConsecutiveData(size_t data_position,
55 size_t length,
56 char* buffer) const {
57 CHECK_LE(data_position + length, data_->size());
58
59 // Use the cached segment if it can serve the request.
60 if (data_position >= data_position_ &&
61 data_position + length <= data_position_ + segment_length_)
62 return segment_ + data_position - data_position_;
63
64 // Return a pointer into |data_| if the request doesn't span segments.
65 GetSomeDataInternal(data_position);
66 if (length <= segment_length_)
67 return segment_;
68
69 for (char* dest = buffer;;) {
70 size_t copy = std::min(length, segment_length_);
71 memcpy(dest, segment_, copy);
72 length -= copy;
73 if (!length)
74 return buffer;
75
76 // Continue reading the next segment.
77 dest += copy;
78 GetSomeDataInternal(data_position_ + copy);
79 }
80 }
81
82 size_t FastSharedBufferReader::GetSomeData(const char*& some_data,
83 size_t data_position) const {
84 GetSomeDataInternal(data_position);
85 some_data = segment_;
86 return segment_length_;
87 }
88
89 void FastSharedBufferReader::GetSomeDataInternal(size_t data_position) const {
90 data_position_ = data_position;
91 segment_length_ = data_->GetSomeData(segment_, data_position);
92 DCHECK(segment_length_);
93 }
94
95 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698