1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/gfx/skia/trunk/src/utils/ios/SkStream_NSData.mm Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,44 @@ 1.4 +/* 1.5 + * Copyright 2010 Google Inc. 1.6 + * 1.7 + * Use of this source code is governed by a BSD-style license that can be 1.8 + * found in the LICENSE file. 1.9 + */ 1.10 + 1.11 +#include "SkStream_NSData.h" 1.12 + 1.13 +NSData* NSData_dataWithStream(SkStream* stream) { 1.14 + size_t length = stream->getLength(); 1.15 + void* src = malloc(length); 1.16 + size_t bytes = stream->read(src, length); 1.17 + SkASSERT(bytes == length); 1.18 + return [NSData dataWithBytesNoCopy:src length:length freeWhenDone:YES]; 1.19 +} 1.20 + 1.21 +NSData* NSData_dataFromResource(const char cname[], const char csuffix[]) { 1.22 + NSBundle* bundle = [NSBundle mainBundle]; 1.23 + NSString* name = [NSString stringWithUTF8String:cname]; 1.24 + NSString* suffix = [NSString stringWithUTF8String:csuffix]; 1.25 + NSString* path = [bundle pathForResource:name ofType:suffix]; 1.26 + return [NSData dataWithContentsOfMappedFile:path]; 1.27 +} 1.28 + 1.29 +/////////////////////////////////////////////////////////////////////////////// 1.30 + 1.31 +SkStream_NSData::SkStream_NSData(NSData* data) { 1.32 + fNSData = data; 1.33 + [fNSData retain]; 1.34 + 1.35 + this->setMemory([fNSData bytes], [fNSData length], false); 1.36 +} 1.37 + 1.38 +SkStream_NSData::~SkStream_NSData() { 1.39 + [fNSData release]; 1.40 +} 1.41 + 1.42 +SkStream_NSData* SkStream_NSData::CreateFromResource(const char name[], 1.43 + const char suffix[]) { 1.44 + NSData* data = NSData_dataFromResource(name, suffix); 1.45 + return SkNEW_ARGS(SkStream_NSData, (data)); 1.46 +} 1.47 +