| 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 368 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 379 // Don't return the incomplete ArrayBuffer. | 379 // Don't return the incomplete ArrayBuffer. |
| 380 return nullptr; | 380 return nullptr; |
| 381 } | 381 } |
| 382 | 382 |
| 383 return arrayBuffer; | 383 return arrayBuffer; |
| 384 } | 384 } |
| 385 | 385 |
| 386 PassRefPtr<SkData> SharedBuffer::getAsSkData() const | 386 PassRefPtr<SkData> SharedBuffer::getAsSkData() const |
| 387 { | 387 { |
| 388 unsigned bufferLength = size(); | 388 unsigned bufferLength = size(); |
| 389 char* buffer = static_cast<char*>(sk_malloc_throw(bufferLength)); | 389 SkData* data = SkData::NewUninitialized(bufferLength); |
| 390 char* buffer = static_cast<char*>(data->writable_data()); |
| 390 const char* segment = 0; | 391 const char* segment = 0; |
| 391 unsigned position = 0; | 392 unsigned position = 0; |
| 392 while (unsigned segmentSize = getSomeData(segment, position)) { | 393 while (unsigned segmentSize = getSomeData(segment, position)) { |
| 393 memcpy(buffer + position, segment, segmentSize); | 394 memcpy(buffer + position, segment, segmentSize); |
| 394 position += segmentSize; | 395 position += segmentSize; |
| 395 } | 396 } |
| 396 | 397 |
| 397 if (position != bufferLength) { | 398 if (position != bufferLength) { |
| 398 ASSERT_NOT_REACHED(); | 399 ASSERT_NOT_REACHED(); |
| 399 // Don't return the incomplete SkData. | 400 // Don't return the incomplete SkData. |
| 400 return nullptr; | 401 return nullptr; |
| 401 } | 402 } |
| 402 return adoptRef(SkData::NewFromMalloc(buffer, bufferLength)); | 403 return adoptRef(data); |
| 403 } | 404 } |
| 404 | 405 |
| 405 bool SharedBuffer::lock() | 406 bool SharedBuffer::lock() |
| 406 { | 407 { |
| 407 return m_buffer.lock(); | 408 return m_buffer.lock(); |
| 408 } | 409 } |
| 409 | 410 |
| 410 void SharedBuffer::unlock() | 411 void SharedBuffer::unlock() |
| 411 { | 412 { |
| 412 mergeSegmentsIntoBuffer(); | 413 mergeSegmentsIntoBuffer(); |
| 413 m_buffer.unlock(); | 414 m_buffer.unlock(); |
| 414 } | 415 } |
| 415 | 416 |
| 416 bool SharedBuffer::isLocked() const | 417 bool SharedBuffer::isLocked() const |
| 417 { | 418 { |
| 418 return m_buffer.isLocked(); | 419 return m_buffer.isLocked(); |
| 419 } | 420 } |
| 420 | 421 |
| 421 } // namespace blink | 422 } // namespace blink |
| OLD | NEW |