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" 10 #include "SkFlattenableBuffers.h" 11 SkDataPixelRef(const SkImageInfo & info,SkData * data)12SkDataPixelRef::SkDataPixelRef(const SkImageInfo& info, SkData* data) 13 : INHERITED(info) 14 , fData(data) 15 { 16 fData->ref(); 17 this->setPreLocked(const_cast<void*>(fData->data()), NULL); 18 } 19 ~SkDataPixelRef()20SkDataPixelRef::~SkDataPixelRef() { 21 fData->unref(); 22 } 23 onLockPixels(SkColorTable ** ct)24void* SkDataPixelRef::onLockPixels(SkColorTable** ct) { 25 *ct = NULL; 26 return const_cast<void*>(fData->data()); 27 } 28 onUnlockPixels()29void SkDataPixelRef::onUnlockPixels() { 30 // nothing to do 31 } 32 getAllocatedSizeInBytes() const33size_t SkDataPixelRef::getAllocatedSizeInBytes() const { 34 return fData ? fData->size() : 0; 35 } 36 flatten(SkFlattenableWriteBuffer & buffer) const37void SkDataPixelRef::flatten(SkFlattenableWriteBuffer& buffer) const { 38 this->INHERITED::flatten(buffer); 39 buffer.writeDataAsByteArray(fData); 40 } 41 SkDataPixelRef(SkFlattenableReadBuffer & buffer)42SkDataPixelRef::SkDataPixelRef(SkFlattenableReadBuffer& buffer) 43 : INHERITED(buffer, NULL) { 44 fData = buffer.readByteArrayAsData(); 45 this->setPreLocked(const_cast<void*>(fData->data()), NULL); 46 } 47