From 1a6880597e88ecb81e19df26fed8fb63f42cb627 Mon Sep 17 00:00:00 2001 From: "reed@google.com" Date: Mon, 25 Feb 2013 18:17:12 +0000 Subject: move SkFDStream out of images into core git-svn-id: http://skia.googlecode.com/svn/trunk@7846 2bbb7eff-a529-9590-31e7-b0007b416f81 --- gyp/core.gypi | 1 + gyp/images.gyp | 1 - src/core/SkFDStream.cpp | 91 +++++++++++++++++++++++++++++++++++++++++++++++ src/images/SkFDStream.cpp | 91 ----------------------------------------------- 4 files changed, 92 insertions(+), 92 deletions(-) create mode 100644 src/core/SkFDStream.cpp delete mode 100644 src/images/SkFDStream.cpp diff --git a/gyp/core.gypi b/gyp/core.gypi index 9831bbb168..590cac205e 100644 --- a/gyp/core.gypi +++ b/gyp/core.gypi @@ -76,6 +76,7 @@ '<(skia_src_path)/core/SkEdgeClipper.cpp', '<(skia_src_path)/core/SkEdge.cpp', '<(skia_src_path)/core/SkEdge.h', + '<(skia_src_path)/core/SkFDStream.cpp', '<(skia_src_path)/core/SkFP.h', '<(skia_src_path)/core/SkFilterProc.cpp', '<(skia_src_path)/core/SkFilterProc.h', diff --git a/gyp/images.gyp b/gyp/images.gyp index 2f007ff68a..4560980a1a 100644 --- a/gyp/images.gyp +++ b/gyp/images.gyp @@ -31,7 +31,6 @@ '../src/images/bmpdecoderhelper.cpp', '../src/images/bmpdecoderhelper.h', - '../src/images/SkFDStream.cpp', '../src/images/SkImageDecoder.cpp', '../src/images/SkImageDecoder_Factory.cpp', '../src/images/SkImageDecoder_libjpeg.cpp', diff --git a/src/core/SkFDStream.cpp b/src/core/SkFDStream.cpp new file mode 100644 index 0000000000..d38813c54d --- /dev/null +++ b/src/core/SkFDStream.cpp @@ -0,0 +1,91 @@ + +/* + * Copyright 2011 Google Inc. + * + * Use of this source code is governed by a BSD-style license that can be + * found in the LICENSE file. + */ +#include "SkStream.h" +#include + +//#define TRACE_FDSTREAM + +SkFDStream::SkFDStream(int fileDesc, bool closeWhenDone) + : fFD(fileDesc), fCloseWhenDone(closeWhenDone) { +} + +SkFDStream::~SkFDStream() { + if (fFD >= 0 && fCloseWhenDone) { + ::close(fFD); + } +} + +bool SkFDStream::rewind() { + if (fFD >= 0) { + off_t value = ::lseek(fFD, 0, SEEK_SET); +#ifdef TRACE_FDSTREAM + if (value) { + SkDebugf("xxxxxxxxxxxxxx rewind failed %d\n", value); + } +#endif + return value == 0; + } + return false; +} + +size_t SkFDStream::read(void* buffer, size_t size) { + if (fFD >= 0) { + if (buffer == NULL && size == 0) { // request total size + off_t curr = ::lseek(fFD, 0, SEEK_CUR); + if (curr < 0) { +#ifdef TRACE_FDSTREAM + SkDebugf("xxxxxxxxxxxxx lseek failed 0 CURR\n"); +#endif + return 0; // error + } + off_t size = ::lseek(fFD, 0, SEEK_END); + if (size < 0) { +#ifdef TRACE_FDSTREAM + SkDebugf("xxxxxxxxxxxxx lseek failed 0 END\n"); +#endif + size = 0; // error + } + if (::lseek(fFD, curr, SEEK_SET) != curr) { + // can't restore, error +#ifdef TRACE_FDSTREAM + SkDebugf("xxxxxxxxxxxxx lseek failed %d SET\n", curr); +#endif + return 0; + } + return (size_t) size; + } else if (NULL == buffer) { // skip + off_t oldCurr = ::lseek(fFD, 0, SEEK_CUR); + if (oldCurr < 0) { +#ifdef TRACE_FDSTREAM + SkDebugf("xxxxxxxxxxxxx lseek1 failed %d CUR\n", oldCurr); +#endif + return 0; // error; + } + off_t newCurr = ::lseek(fFD, size, SEEK_CUR); + if (newCurr < 0) { +#ifdef TRACE_FDSTREAM + SkDebugf("xxxxxxxxxxxxx lseek2 failed %d CUR\n", newCurr); +#endif + return 0; // error; + } + // return the actual amount we skipped + return (size_t) (newCurr - oldCurr); + } else { // read + ssize_t actual = ::read(fFD, buffer, size); + // our API can't return an error, so we return 0 + if (actual < 0) { +#ifdef TRACE_FDSTREAM + SkDebugf("xxxxxxxxxxxxx read failed %d actual %d\n", size, actual); +#endif + actual = 0; + } + return actual; + } + } + return 0; +} diff --git a/src/images/SkFDStream.cpp b/src/images/SkFDStream.cpp deleted file mode 100644 index d38813c54d..0000000000 --- a/src/images/SkFDStream.cpp +++ /dev/null @@ -1,91 +0,0 @@ - -/* - * Copyright 2011 Google Inc. - * - * Use of this source code is governed by a BSD-style license that can be - * found in the LICENSE file. - */ -#include "SkStream.h" -#include - -//#define TRACE_FDSTREAM - -SkFDStream::SkFDStream(int fileDesc, bool closeWhenDone) - : fFD(fileDesc), fCloseWhenDone(closeWhenDone) { -} - -SkFDStream::~SkFDStream() { - if (fFD >= 0 && fCloseWhenDone) { - ::close(fFD); - } -} - -bool SkFDStream::rewind() { - if (fFD >= 0) { - off_t value = ::lseek(fFD, 0, SEEK_SET); -#ifdef TRACE_FDSTREAM - if (value) { - SkDebugf("xxxxxxxxxxxxxx rewind failed %d\n", value); - } -#endif - return value == 0; - } - return false; -} - -size_t SkFDStream::read(void* buffer, size_t size) { - if (fFD >= 0) { - if (buffer == NULL && size == 0) { // request total size - off_t curr = ::lseek(fFD, 0, SEEK_CUR); - if (curr < 0) { -#ifdef TRACE_FDSTREAM - SkDebugf("xxxxxxxxxxxxx lseek failed 0 CURR\n"); -#endif - return 0; // error - } - off_t size = ::lseek(fFD, 0, SEEK_END); - if (size < 0) { -#ifdef TRACE_FDSTREAM - SkDebugf("xxxxxxxxxxxxx lseek failed 0 END\n"); -#endif - size = 0; // error - } - if (::lseek(fFD, curr, SEEK_SET) != curr) { - // can't restore, error -#ifdef TRACE_FDSTREAM - SkDebugf("xxxxxxxxxxxxx lseek failed %d SET\n", curr); -#endif - return 0; - } - return (size_t) size; - } else if (NULL == buffer) { // skip - off_t oldCurr = ::lseek(fFD, 0, SEEK_CUR); - if (oldCurr < 0) { -#ifdef TRACE_FDSTREAM - SkDebugf("xxxxxxxxxxxxx lseek1 failed %d CUR\n", oldCurr); -#endif - return 0; // error; - } - off_t newCurr = ::lseek(fFD, size, SEEK_CUR); - if (newCurr < 0) { -#ifdef TRACE_FDSTREAM - SkDebugf("xxxxxxxxxxxxx lseek2 failed %d CUR\n", newCurr); -#endif - return 0; // error; - } - // return the actual amount we skipped - return (size_t) (newCurr - oldCurr); - } else { // read - ssize_t actual = ::read(fFD, buffer, size); - // our API can't return an error, so we return 0 - if (actual < 0) { -#ifdef TRACE_FDSTREAM - SkDebugf("xxxxxxxxxxxxx read failed %d actual %d\n", size, actual); -#endif - actual = 0; - } - return actual; - } - } - return 0; -} -- cgit v1.2.3