| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright 2012 Google Inc. | 2 * Copyright 2012 Google Inc. |
| 3 * | 3 * |
| 4 * Use of this source code is governed by a BSD-style license that can be | 4 * Use of this source code is governed by a BSD-style license that can be |
| 5 * found in the LICENSE file. | 5 * found in the LICENSE file. |
| 6 */ | 6 */ |
| 7 | 7 |
| 8 #include "SkDataPixelRef.h" | 8 #include "SkDataPixelRef.h" |
| 9 #include "SkData.h" | 9 #include "SkData.h" |
| 10 #include "SkFlattenableBuffers.h" | 10 #include "SkFlattenableBuffers.h" |
| 11 | 11 |
| 12 SkDataPixelRef::SkDataPixelRef(SkData* data) : fData(data) { | 12 SkDataPixelRef::SkDataPixelRef(const SkImageInfo& info, |
| 13 SkData* data, size_t rowBytes) |
| 14 : fInfo(info) |
| 15 , fData(data) |
| 16 , fRB(rowBytes) |
| 17 { |
| 13 fData->ref(); | 18 fData->ref(); |
| 14 this->setPreLocked(const_cast<void*>(fData->data()), NULL); | 19 this->setPreLocked(info, const_cast<void*>(fData->data()), rowBytes, NULL); |
| 15 } | 20 } |
| 16 | 21 |
| 17 SkDataPixelRef::~SkDataPixelRef() { | 22 SkDataPixelRef::~SkDataPixelRef() { |
| 18 fData->unref(); | 23 fData->unref(); |
| 19 } | 24 } |
| 20 | 25 |
| 21 void* SkDataPixelRef::onLockPixels(SkColorTable** ct) { | 26 bool SkDataPixelRef::onGetInfo(SkImageInfo* info) { |
| 22 *ct = NULL; | 27 *info = fInfo; |
| 23 return const_cast<void*>(fData->data()); | 28 return true; |
| 29 } |
| 30 |
| 31 bool SkDataPixelRef::onNewLockPixels(LockRec* rec) { |
| 32 rec->fPixels = const_cast<void*>(fData->data()); |
| 33 rec->fColorTable = NULL; |
| 34 rec->fRowBytes = fRB; |
| 35 return true; |
| 24 } | 36 } |
| 25 | 37 |
| 26 void SkDataPixelRef::onUnlockPixels() { | 38 void SkDataPixelRef::onUnlockPixels() { |
| 27 // nothing to do | 39 // nothing to do |
| 28 } | 40 } |
| 29 | 41 |
| 30 void SkDataPixelRef::flatten(SkFlattenableWriteBuffer& buffer) const { | 42 void SkDataPixelRef::flatten(SkFlattenableWriteBuffer& buffer) const { |
| 31 this->INHERITED::flatten(buffer); | 43 this->INHERITED::flatten(buffer); |
| 44 |
| 45 fInfo.flatten(buffer); |
| 32 buffer.writeDataAsByteArray(fData); | 46 buffer.writeDataAsByteArray(fData); |
| 47 buffer.write32(fRB); |
| 33 } | 48 } |
| 34 | 49 |
| 35 SkDataPixelRef::SkDataPixelRef(SkFlattenableReadBuffer& buffer) | 50 SkDataPixelRef::SkDataPixelRef(SkFlattenableReadBuffer& buffer) |
| 36 : INHERITED(buffer, NULL) { | 51 : INHERITED(buffer, NULL) |
| 52 { |
| 53 fInfo.unflatten(buffer); |
| 37 fData = buffer.readByteArrayAsData(); | 54 fData = buffer.readByteArrayAsData(); |
| 38 this->setPreLocked(const_cast<void*>(fData->data()), NULL); | 55 fRB = buffer.read32(); |
| 56 this->setPreLocked(fInfo, const_cast<void*>(fData->data()), fRB, NULL); |
| 39 } | 57 } |
| OLD | NEW |