reed@google.com | f6627b7 | 2012-07-27 18:02:50 +0000 | [diff] [blame] | 1 | /* |
| 2 | * Copyright 2012 Google Inc. |
| 3 | * |
| 4 | * Use of this source code is governed by a BSD-style license that can be |
| 5 | * found in the LICENSE file. |
| 6 | */ |
| 7 | |
| 8 | #include "SkDataPixelRef.h" |
| 9 | #include "SkData.h" |
reed@google.com | 9ddef9b | 2012-08-07 16:10:42 +0000 | [diff] [blame] | 10 | #include "SkFlattenableBuffers.h" |
reed@google.com | f6627b7 | 2012-07-27 18:02:50 +0000 | [diff] [blame] | 11 | |
reed@google.com | 398337b | 2013-12-11 21:22:39 +0000 | [diff] [blame^] | 12 | SkDataPixelRef::SkDataPixelRef(SkData* data) : fData(data) { |
reed@google.com | f6627b7 | 2012-07-27 18:02:50 +0000 | [diff] [blame] | 13 | fData->ref(); |
reed@google.com | 398337b | 2013-12-11 21:22:39 +0000 | [diff] [blame^] | 14 | this->setPreLocked(const_cast<void*>(fData->data()), NULL); |
reed@google.com | f6627b7 | 2012-07-27 18:02:50 +0000 | [diff] [blame] | 15 | } |
| 16 | |
| 17 | SkDataPixelRef::~SkDataPixelRef() { |
| 18 | fData->unref(); |
| 19 | } |
| 20 | |
reed@google.com | 398337b | 2013-12-11 21:22:39 +0000 | [diff] [blame^] | 21 | void* SkDataPixelRef::onLockPixels(SkColorTable** ct) { |
| 22 | *ct = NULL; |
| 23 | return const_cast<void*>(fData->data()); |
reed@google.com | f6627b7 | 2012-07-27 18:02:50 +0000 | [diff] [blame] | 24 | } |
| 25 | |
| 26 | void SkDataPixelRef::onUnlockPixels() { |
| 27 | // nothing to do |
| 28 | } |
| 29 | |
commit-bot@chromium.org | cd3b15c | 2013-12-04 17:06:49 +0000 | [diff] [blame] | 30 | size_t SkDataPixelRef::getAllocatedSizeInBytes() const { |
| 31 | return fData ? fData->size() : 0; |
| 32 | } |
| 33 | |
reed@google.com | f6627b7 | 2012-07-27 18:02:50 +0000 | [diff] [blame] | 34 | void SkDataPixelRef::flatten(SkFlattenableWriteBuffer& buffer) const { |
| 35 | this->INHERITED::flatten(buffer); |
reed@google.com | da30055 | 2013-10-14 14:33:11 +0000 | [diff] [blame] | 36 | buffer.writeDataAsByteArray(fData); |
reed@google.com | f6627b7 | 2012-07-27 18:02:50 +0000 | [diff] [blame] | 37 | } |
| 38 | |
| 39 | SkDataPixelRef::SkDataPixelRef(SkFlattenableReadBuffer& buffer) |
reed@google.com | 398337b | 2013-12-11 21:22:39 +0000 | [diff] [blame^] | 40 | : INHERITED(buffer, NULL) { |
reed@google.com | da30055 | 2013-10-14 14:33:11 +0000 | [diff] [blame] | 41 | fData = buffer.readByteArrayAsData(); |
reed@google.com | 398337b | 2013-12-11 21:22:39 +0000 | [diff] [blame^] | 42 | this->setPreLocked(const_cast<void*>(fData->data()), NULL); |
reed@google.com | f6627b7 | 2012-07-27 18:02:50 +0000 | [diff] [blame] | 43 | } |