use SkStream::NewFromFile()

git-svn-id: http://skia.googlecode.com/svn/trunk@8210 2bbb7eff-a529-9590-31e7-b0007b416f81
This commit is contained in:
mike@reedtribe.org 2013-03-19 02:18:33 +00:00
parent 54d5f83c33
commit f381162e56
9 changed files with 36 additions and 65 deletions

View File

@ -99,13 +99,15 @@ bool SkAnimateMaker::decodeURI(const char uri[]) {
// SkDebugf("animator decode %s\n", uri);
// SkStream* stream = SkStream::GetURIStream(fPrefix.c_str(), uri);
SkStream* stream = new SkFILEStream(uri);
SkAutoTDelete<SkStream> autoDel(stream);
bool success = decodeStream(stream);
if (hasError() && fError.hasNoun() == false)
fError.setNoun(uri);
return success;
SkAutoTUnref<SkStream> stream(SkStream::NewFromFile(uri));
if (stream.get()) {
bool success = decodeStream(stream);
if (hasError() && fError.hasNoun() == false)
fError.setNoun(uri);
return success;
} else {
return false;
}
}
#if defined SK_DEBUG && 0

View File

@ -84,11 +84,13 @@ bool SkAnimator::decodeURI(const char uri[]) {
// SkDebugf("animator decode %s\n", uri);
// SkStream* stream = SkStream::GetURIStream(fMaker->fPrefix.c_str(), uri);
SkStream* stream = new SkFILEStream(uri);
SkAutoTDelete<SkStream> autoDel(stream);
setURIBase(uri);
return decodeStream(stream);
SkAutoTUnref<SkStream> stream(SkStream::NewFromFile(uri));
if (stream.get()) {
this->setURIBase(uri);
return decodeStream(stream);
} else {
return false;
}
}
bool SkAnimator::doCharEvent(SkUnichar code) {

View File

@ -190,9 +190,9 @@ void SkImageBaseBitmap::resolve() {
fBitmap.reset();
//SkStream* stream = SkStream::GetURIStream(fUriBase, src.c_str());
SkStream* stream = new SkFILEStream(src.c_str());
SkAutoTDelete<SkStream> autoDel(stream);
SkImageDecoder::DecodeStream(stream, &fBitmap);
SkAutoTUnref<SkStream> stream(SkStream::NewFromFile(src.c_str()));
if (stream.get()) {
SkImageDecoder::DecodeStream(stream, &fBitmap);
}
}
}

View File

@ -225,9 +225,9 @@ bool SkImageDecoder::DecodeFile(const char file[], SkBitmap* bm,
SkASSERT(file);
SkASSERT(bm);
SkFILEStream stream(file);
if (stream.isValid()) {
if (SkImageDecoder::DecodeStream(&stream, bm, pref, mode, format)) {
SkAutoTUnref<SkStream> stream(SkStream::NewFromFile(file));
if (stream.get()) {
if (SkImageDecoder::DecodeStream(stream, bm, pref, mode, format)) {
bm->pixelRef()->setURI(file);
return true;
}

View File

@ -91,19 +91,7 @@ SkMovie* SkMovie::DecodeMemory(const void* data, size_t length) {
return SkMovie::DecodeStream(&stream);
}
SkMovie* SkMovie::DecodeFile(const char path[])
{
SkMovie* movie = NULL;
SkFILEStream stream(path);
if (stream.isValid()) {
movie = SkMovie::DecodeStream(&stream);
}
#ifdef SK_DEBUG
else {
SkDebugf("Movie file not found <%s>\n", path);
}
#endif
return movie;
SkMovie* SkMovie::DecodeFile(const char path[]) {
SkAutoTUnref<SkStream> stream(SkStream::NewFromFile(path));
return stream.get() ? SkMovie::DecodeStream(stream) : NULL;
}

View File

@ -167,14 +167,8 @@ SkTypeface* SkFontHost::CreateTypefaceFromStream(SkStream* stream) {
}
SkTypeface* SkFontHost::CreateTypefaceFromFile(const char path[]) {
SkTypeface* face = NULL;
SkFILEStream* stream = SkNEW_ARGS(SkFILEStream, (path));
if (stream->isValid()) {
face = CreateTypefaceFromStream(stream);
}
stream->unref();
return face;
SkAutoTUnref<SkStream> stream(SkStream::NewFromFile(path));
return stream.get() ? CreateTypefaceFromStream(stream) : NULL;
}
///////////////////////////////////////////////////////////////////////////////

View File

@ -567,12 +567,6 @@ SkTypeface* SkFontHost::CreateTypefaceFromStream(SkStream* stream) {
}
SkTypeface* SkFontHost::CreateTypefaceFromFile(const char path[]) {
SkTypeface* face = NULL;
SkFILEStream* stream = SkNEW_ARGS(SkFILEStream, (path));
if (stream->isValid()) {
face = CreateTypefaceFromStream(stream);
}
stream->unref();
return face;
SkAutoTUnref<SkStream> stream(SkStream::NewFromFile(path));
return stream.get() ? CreateTypefaceFromStream(stream) : NULL;
}

View File

@ -1638,13 +1638,8 @@ SkTypeface* SkFontHost::CreateTypeface(const SkTypeface* familyFace,
}
SkTypeface* SkFontHost::CreateTypefaceFromFile(const char path[]) {
SkTypeface* face = NULL;
SkAutoTUnref<SkFILEStream> stream(SkNEW_ARGS(SkFILEStream, (path)));
if (stream->isValid()) {
face = CreateTypefaceFromStream(stream);
}
return face;
SkAutoTUnref<SkStream> stream(SkStream::NewFromFile(path));
return stream.get() ? CreateTypefaceFromStream(stream) : NULL;
}
void SkFontHost::FilterRec(SkScalerContext::Rec* rec, SkTypeface* typeface) {

View File

@ -41,20 +41,16 @@ const char* get_skin_enum_path(SkinEnum se)
return gSkinPaths[se];
}
void init_skin_anim(const char path[], SkAnimator* anim)
{
void init_skin_anim(const char path[], SkAnimator* anim) {
SkASSERT(path && anim);
SkFILEStream stream(path);
if (!stream.isValid())
{
SkAutoTUnref<SkStream> stream(SkStream::NewFromFile(path));
if (!stream.get()) {
SkDEBUGF(("init_skin_anim: loading skin failed <%s>\n", path));
sk_throw();
}
if (!anim->decodeStream(&stream))
{
if (!anim->decodeStream(stream)) {
SkDEBUGF(("init_skin_anim: decoding skin failed <%s>\n", path));
sk_throw();
}