| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright (C) 2006, 2008 Apple Inc. All rights reserved. | 2 * Copyright (C) 2006, 2008 Apple Inc. All rights reserved. |
| 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 * Redistribution and use in source and binary forms, with or without | 5 * Redistribution and use in source and binary forms, with or without |
| 6 * modification, are permitted provided that the following conditions | 6 * modification, are permitted provided that the following conditions |
| 7 * are met: | 7 * are met: |
| 8 * 1. Redistributions of source code must retain the above copyright | 8 * 1. 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 * 2. Redistributions in binary form must reproduce the above copyright | 10 * 2. Redistributions in binary form must reproduce the above copyright |
| (...skipping 222 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 233 size_t segmentedSize = std::min(maxSegmentedSize, bytesLeft); | 233 size_t segmentedSize = std::min(maxSegmentedSize, bytesLeft); |
| 234 | 234 |
| 235 size_t positionInSegment = offsetInSegment(position); | 235 size_t positionInSegment = offsetInSegment(position); |
| 236 someData = m_segments[segment] + positionInSegment; | 236 someData = m_segments[segment] + positionInSegment; |
| 237 return segment == segments - 1 ? segmentedSize - position : kSegmentSize
- positionInSegment; | 237 return segment == segments - 1 ? segmentedSize - position : kSegmentSize
- positionInSegment; |
| 238 } | 238 } |
| 239 ASSERT_NOT_REACHED(); | 239 ASSERT_NOT_REACHED(); |
| 240 return 0; | 240 return 0; |
| 241 } | 241 } |
| 242 | 242 |
| 243 bool SharedBuffer::getAsBytesInternal(void* dest, size_t byteLength) const | 243 bool SharedBuffer::getAsBytesInternal(void* dest, size_t loadPosition, size_t by
teLength) const |
| 244 { | 244 { |
| 245 if (!dest || byteLength != size()) | 245 if (!dest) |
| 246 return false; | 246 return false; |
| 247 | 247 |
| 248 const char* segment = 0; | 248 const char* segment = nullptr; |
| 249 size_t position = 0; | 249 size_t writePosition = 0; |
| 250 while (size_t segmentSize = getSomeDataInternal(segment, position)) { | 250 while (byteLength > 0) { |
| 251 memcpy(static_cast<char*>(dest) + position, segment, segmentSize); | 251 size_t loadSize = getSomeDataInternal(segment, loadPosition); |
| 252 position += segmentSize; | 252 if (loadSize == 0) |
| 253 break; |
| 254 |
| 255 if (byteLength < loadSize) |
| 256 loadSize = byteLength; |
| 257 memcpy(static_cast<char*>(dest) + writePosition, segment, loadSize); |
| 258 loadPosition += loadSize; |
| 259 writePosition += loadSize; |
| 260 byteLength -= loadSize; |
| 253 } | 261 } |
| 254 | 262 |
| 255 if (position != byteLength) { | 263 return byteLength == 0; |
| 256 ASSERT_NOT_REACHED(); | |
| 257 // Don't return the incomplete data. | |
| 258 return false; | |
| 259 } | |
| 260 | |
| 261 return true; | |
| 262 } | 264 } |
| 263 | 265 |
| 264 sk_sp<SkData> SharedBuffer::getAsSkData() const | 266 sk_sp<SkData> SharedBuffer::getAsSkData() const |
| 265 { | 267 { |
| 266 size_t bufferLength = size(); | 268 size_t bufferLength = size(); |
| 267 sk_sp<SkData> data = SkData::MakeUninitialized(bufferLength); | 269 sk_sp<SkData> data = SkData::MakeUninitialized(bufferLength); |
| 268 char* buffer = static_cast<char*>(data->writable_data()); | 270 char* buffer = static_cast<char*>(data->writable_data()); |
| 269 const char* segment = 0; | 271 const char* segment = 0; |
| 270 size_t position = 0; | 272 size_t position = 0; |
| 271 while (size_t segmentSize = getSomeDataInternal(segment, position)) { | 273 while (size_t segmentSize = getSomeDataInternal(segment, position)) { |
| (...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 305 // If there is data in the segments, then it should have been allocated | 307 // If there is data in the segments, then it should have been allocated |
| 306 // using fastMalloc. | 308 // using fastMalloc. |
| 307 const String dataDumpName = dumpPrefix + "/segments"; | 309 const String dataDumpName = dumpPrefix + "/segments"; |
| 308 auto dump = memoryDump->createMemoryAllocatorDump(dataDumpName); | 310 auto dump = memoryDump->createMemoryAllocatorDump(dataDumpName); |
| 309 dump->addScalar("size", "bytes", m_size); | 311 dump->addScalar("size", "bytes", m_size); |
| 310 memoryDump->addSuballocation(dump->guid(), String(WTF::Partitions::kAllo
catedObjectPoolName)); | 312 memoryDump->addSuballocation(dump->guid(), String(WTF::Partitions::kAllo
catedObjectPoolName)); |
| 311 } | 313 } |
| 312 } | 314 } |
| 313 | 315 |
| 314 } // namespace blink | 316 } // namespace blink |
| OLD | NEW |