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 | |
| 12 | SkDataPixelRef::SkDataPixelRef(SkData* data) : fData(data) { |
| 13 | fData->ref(); |
| 14 | this->setPreLocked(const_cast<void*>(fData->data()), NULL); |
| 15 | } |
| 16 | |
| 17 | SkDataPixelRef::~SkDataPixelRef() { |
| 18 | fData->unref(); |
| 19 | } |
| 20 | |
| 21 | void* SkDataPixelRef::onLockPixels(SkColorTable** ct) { |
| 22 | *ct = NULL; |
| 23 | return const_cast<void*>(fData->data()); |
| 24 | } |
| 25 | |
| 26 | void SkDataPixelRef::onUnlockPixels() { |
| 27 | // nothing to do |
| 28 | } |
| 29 | |
| 30 | void SkDataPixelRef::flatten(SkFlattenableWriteBuffer& buffer) const { |
| 31 | this->INHERITED::flatten(buffer); |
reed@google.com | da30055 | 2013-10-14 14:33:11 +0000 | [diff] [blame] | 32 | buffer.writeDataAsByteArray(fData); |
reed@google.com | f6627b7 | 2012-07-27 18:02:50 +0000 | [diff] [blame] | 33 | } |
| 34 | |
| 35 | SkDataPixelRef::SkDataPixelRef(SkFlattenableReadBuffer& buffer) |
| 36 | : INHERITED(buffer, NULL) { |
reed@google.com | da30055 | 2013-10-14 14:33:11 +0000 | [diff] [blame] | 37 | fData = buffer.readByteArrayAsData(); |
reed@google.com | bd5fa90 | 2012-07-31 15:19:56 +0000 | [diff] [blame] | 38 | this->setPreLocked(const_cast<void*>(fData->data()), NULL); |
reed@google.com | f6627b7 | 2012-07-27 18:02:50 +0000 | [diff] [blame] | 39 | } |