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 182 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
193 size_t segment = SegmentIndex(position); | 193 size_t segment = SegmentIndex(position); |
194 if (segment < segments) { | 194 if (segment < segments) { |
195 size_t bytes_left = total_size - consecutive_size; | 195 size_t bytes_left = total_size - consecutive_size; |
196 size_t segmented_size = std::min(max_segmented_size, bytes_left); | 196 size_t segmented_size = std::min(max_segmented_size, bytes_left); |
197 | 197 |
198 size_t position_in_segment = OffsetInSegment(position); | 198 size_t position_in_segment = OffsetInSegment(position); |
199 some_data = segments_[segment] + position_in_segment; | 199 some_data = segments_[segment] + position_in_segment; |
200 return segment == segments - 1 ? segmented_size - position | 200 return segment == segments - 1 ? segmented_size - position |
201 : kSegmentSize - position_in_segment; | 201 : kSegmentSize - position_in_segment; |
202 } | 202 } |
203 ASSERT_NOT_REACHED(); | 203 NOTREACHED(); |
204 return 0; | 204 return 0; |
205 } | 205 } |
206 | 206 |
207 bool SharedBuffer::GetAsBytesInternal(void* dest, | 207 bool SharedBuffer::GetAsBytesInternal(void* dest, |
208 size_t load_position, | 208 size_t load_position, |
209 size_t byte_length) const { | 209 size_t byte_length) const { |
210 if (!dest) | 210 if (!dest) |
211 return false; | 211 return false; |
212 | 212 |
213 const char* segment = nullptr; | 213 const char* segment = nullptr; |
(...skipping 19 matching lines...) Expand all Loading... |
233 sk_sp<SkData> data = SkData::MakeUninitialized(buffer_length); | 233 sk_sp<SkData> data = SkData::MakeUninitialized(buffer_length); |
234 char* buffer = static_cast<char*>(data->writable_data()); | 234 char* buffer = static_cast<char*>(data->writable_data()); |
235 const char* segment = 0; | 235 const char* segment = 0; |
236 size_t position = 0; | 236 size_t position = 0; |
237 while (size_t segment_size = GetSomeDataInternal(segment, position)) { | 237 while (size_t segment_size = GetSomeDataInternal(segment, position)) { |
238 memcpy(buffer + position, segment, segment_size); | 238 memcpy(buffer + position, segment, segment_size); |
239 position += segment_size; | 239 position += segment_size; |
240 } | 240 } |
241 | 241 |
242 if (position != buffer_length) { | 242 if (position != buffer_length) { |
243 ASSERT_NOT_REACHED(); | 243 NOTREACHED(); |
244 // Don't return the incomplete SkData. | 244 // Don't return the incomplete SkData. |
245 return nullptr; | 245 return nullptr; |
246 } | 246 } |
247 return data; | 247 return data; |
248 } | 248 } |
249 | 249 |
250 void SharedBuffer::OnMemoryDump(const String& dump_prefix, | 250 void SharedBuffer::OnMemoryDump(const String& dump_prefix, |
251 WebProcessMemoryDump* memory_dump) const { | 251 WebProcessMemoryDump* memory_dump) const { |
252 if (buffer_.size()) { | 252 if (buffer_.size()) { |
253 WebMemoryAllocatorDump* dump = | 253 WebMemoryAllocatorDump* dump = |
254 memory_dump->CreateMemoryAllocatorDump(dump_prefix + "/shared_buffer"); | 254 memory_dump->CreateMemoryAllocatorDump(dump_prefix + "/shared_buffer"); |
255 dump->AddScalar("size", "bytes", buffer_.size()); | 255 dump->AddScalar("size", "bytes", buffer_.size()); |
256 memory_dump->AddSuballocation( | 256 memory_dump->AddSuballocation( |
257 dump->Guid(), String(WTF::Partitions::kAllocatedObjectPoolName)); | 257 dump->Guid(), String(WTF::Partitions::kAllocatedObjectPoolName)); |
258 } else { | 258 } else { |
259 // If there is data in the segments, then it should have been allocated | 259 // If there is data in the segments, then it should have been allocated |
260 // using fastMalloc. | 260 // using fastMalloc. |
261 const String data_dump_name = dump_prefix + "/segments"; | 261 const String data_dump_name = dump_prefix + "/segments"; |
262 auto dump = memory_dump->CreateMemoryAllocatorDump(data_dump_name); | 262 auto dump = memory_dump->CreateMemoryAllocatorDump(data_dump_name); |
263 dump->AddScalar("size", "bytes", size_); | 263 dump->AddScalar("size", "bytes", size_); |
264 memory_dump->AddSuballocation( | 264 memory_dump->AddSuballocation( |
265 dump->Guid(), String(WTF::Partitions::kAllocatedObjectPoolName)); | 265 dump->Guid(), String(WTF::Partitions::kAllocatedObjectPoolName)); |
266 } | 266 } |
267 } | 267 } |
268 | 268 |
269 } // namespace blink | 269 } // namespace blink |
OLD | NEW |