| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright (C) 2015 Google Inc. All rights reserved. | 2 * Copyright (C) 2015 Google Inc. All rights reserved. |
| 3 * | 3 * |
| 4 * Redistribution and use in source and binary forms, with or without | 4 * Redistribution and use in source and binary forms, with or without |
| 5 * modification, are permitted provided that the following conditions are | 5 * modification, are permitted provided that the following conditions are |
| 6 * met: | 6 * met: |
| 7 * | 7 * |
| 8 * * Redistributions of source code must retain the above copyright | 8 * * 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 * * Redistributions in binary form must reproduce the above | 10 * * Redistributions in binary form must reproduce the above |
| (...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 47 | 47 |
| 48 PassRefPtr<SegmentReader> copyToROBufferSegmentReader(PassRefPtr<SegmentReader>
input) | 48 PassRefPtr<SegmentReader> copyToROBufferSegmentReader(PassRefPtr<SegmentReader>
input) |
| 49 { | 49 { |
| 50 SkRWBuffer rwBuffer; | 50 SkRWBuffer rwBuffer; |
| 51 const char* segment = 0; | 51 const char* segment = 0; |
| 52 size_t position = 0; | 52 size_t position = 0; |
| 53 while (size_t length = input->getSomeData(segment, position)) { | 53 while (size_t length = input->getSomeData(segment, position)) { |
| 54 rwBuffer.append(segment, length); | 54 rwBuffer.append(segment, length); |
| 55 position += length; | 55 position += length; |
| 56 } | 56 } |
| 57 return SegmentReader::createFromSkROBuffer(adoptRef(rwBuffer.newRBufferSnaps
hot())); | 57 return SegmentReader::createFromSkROBuffer(sk_sp<SkROBuffer>(rwBuffer.newRBu
fferSnapshot())); |
| 58 } | 58 } |
| 59 | 59 |
| 60 PassRefPtr<SegmentReader> copyToDataSegmentReader(PassRefPtr<SegmentReader> inpu
t) | 60 PassRefPtr<SegmentReader> copyToDataSegmentReader(PassRefPtr<SegmentReader> inpu
t) |
| 61 { | 61 { |
| 62 return SegmentReader::createFromSkData(input->getAsSkData()); | 62 return SegmentReader::createFromSkData(input->getAsSkData()); |
| 63 } | 63 } |
| 64 | 64 |
| 65 struct SegmentReaders { | 65 struct SegmentReaders { |
| 66 RefPtr<SegmentReader> segmentReaders[3]; | 66 RefPtr<SegmentReader> segmentReaders[3]; |
| 67 | 67 |
| (...skipping 141 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 209 // are not the same size. This test relies on knowledge of the | 209 // are not the same size. This test relies on knowledge of the |
| 210 // internals of SkRWBuffer: it ensures that each segment is at least | 210 // internals of SkRWBuffer: it ensures that each segment is at least |
| 211 // 4096 (though the actual data may be smaller, if it has not been | 211 // 4096 (though the actual data may be smaller, if it has not been |
| 212 // written to yet), but when appending a larger amount it may create a | 212 // written to yet), but when appending a larger amount it may create a |
| 213 // larger segment. | 213 // larger segment. |
| 214 SkRWBuffer rwBuffer; | 214 SkRWBuffer rwBuffer; |
| 215 rwBuffer.append(referenceData, SharedBuffer::kSegmentSize); | 215 rwBuffer.append(referenceData, SharedBuffer::kSegmentSize); |
| 216 rwBuffer.append(referenceData + SharedBuffer::kSegmentSize, 2 * SharedBu
ffer::kSegmentSize); | 216 rwBuffer.append(referenceData + SharedBuffer::kSegmentSize, 2 * SharedBu
ffer::kSegmentSize); |
| 217 rwBuffer.append(referenceData + 3 * SharedBuffer::kSegmentSize, .5 * Sha
redBuffer::kSegmentSize); | 217 rwBuffer.append(referenceData + 3 * SharedBuffer::kSegmentSize, .5 * Sha
redBuffer::kSegmentSize); |
| 218 | 218 |
| 219 segmentReader = SegmentReader::createFromSkROBuffer(adoptRef(rwBuffer.ne
wRBufferSnapshot())); | 219 segmentReader = SegmentReader::createFromSkROBuffer(sk_sp<SkROBuffer>(rw
Buffer.newRBufferSnapshot())); |
| 220 } | 220 } |
| 221 | 221 |
| 222 const char* segment; | 222 const char* segment; |
| 223 size_t position = 0; | 223 size_t position = 0; |
| 224 size_t lastLength = 0; | 224 size_t lastLength = 0; |
| 225 for (size_t length = segmentReader->getSomeData(segment, position); | 225 for (size_t length = segmentReader->getSomeData(segment, position); |
| 226 length; length = segmentReader->getSomeData(segment, position)) { | 226 length; length = segmentReader->getSomeData(segment, position)) { |
| 227 // It is not a bug to have consecutive segments of the same length, but | 227 // It is not a bug to have consecutive segments of the same length, but |
| 228 // it does mean that the following test does not actually test what it | 228 // it does mean that the following test does not actually test what it |
| 229 // is intended to test. | 229 // is intended to test. |
| 230 ASSERT_NE(length, lastLength); | 230 ASSERT_NE(length, lastLength); |
| 231 lastLength = length; | 231 lastLength = length; |
| 232 | 232 |
| 233 ASSERT_FALSE(memcmp(segment, referenceData + position, length)); | 233 ASSERT_FALSE(memcmp(segment, referenceData + position, length)); |
| 234 position += length; | 234 position += length; |
| 235 } | 235 } |
| 236 EXPECT_EQ(position, dataSize); | 236 EXPECT_EQ(position, dataSize); |
| 237 } | 237 } |
| 238 | 238 |
| 239 } // namespace blink | 239 } // namespace blink |
| OLD | NEW |