diff options
author | brettw@google.com <brettw@google.com@0039d316-1c4b-4281-b951-d872f2087c98> | 2008-12-12 21:01:41 +0000 |
---|---|---|
committer | brettw@google.com <brettw@google.com@0039d316-1c4b-4281-b951-d872f2087c98> | 2008-12-12 21:01:41 +0000 |
commit | 52e935d04c59135739c3a68fb6e19d313dc6d5ad (patch) | |
tree | 95f7ab178b045bef4456cbf92c6aa7e476becd99 /skia/include/SkStream.h | |
parent | 30fab79877b4bb067944b74d98346ac9bb6bfc7e (diff) | |
download | chromium_src-52e935d04c59135739c3a68fb6e19d313dc6d5ad.zip chromium_src-52e935d04c59135739c3a68fb6e19d313dc6d5ad.tar.gz chromium_src-52e935d04c59135739c3a68fb6e19d313dc6d5ad.tar.bz2 |
New drop of Skia. This is up to CL 121320.
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@6925 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'skia/include/SkStream.h')
-rw-r--r-- | skia/include/SkStream.h | 79 |
1 files changed, 56 insertions, 23 deletions
diff --git a/skia/include/SkStream.h b/skia/include/SkStream.h index 4612abb..26ef43f 100644 --- a/skia/include/SkStream.h +++ b/skia/include/SkStream.h @@ -1,19 +1,18 @@ -/* include/graphics/SkStream.h -** -** Copyright 2006, Google Inc. -** -** Licensed under the Apache License, Version 2.0 (the "License"); -** you may not use this file except in compliance with the License. -** You may obtain a copy of the License at -** -** http://www.apache.org/licenses/LICENSE-2.0 -** -** Unless required by applicable law or agreed to in writing, software -** distributed under the License is distributed on an "AS IS" BASIS, -** WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -** See the License for the specific language governing permissions and -** limitations under the License. -*/ +/* + * Copyright (C) 2006 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ #ifndef SkStream_DEFINED #define SkStream_DEFINED @@ -69,6 +68,8 @@ public: bool readBool() { return this->readU8() != 0; } SkScalar readScalar(); size_t readPackedUInt(); + + static void UnitTest(); }; class SkWStream : SkNoncopyable { @@ -101,7 +102,7 @@ public: bool writeStream(SkStream* input, size_t length); - SkDEBUGCODE(static void UnitTest();) + static void UnitTest(); }; //////////////////////////////////////////////////////////////////////////////////////// @@ -110,9 +111,15 @@ public: struct SkFILE; +/** A stream that reads from a FILE*, which is opened in the constructor and + closed in the destructor + */ class SkFILEStream : public SkStream { public: - SkFILEStream(const char path[] = NULL); + /** Initialize the stream by calling fopen on the specified path. Will be + closed in the destructor. + */ + explicit SkFILEStream(const char path[] = NULL); virtual ~SkFILEStream(); /** Returns true if the current path could be opened. @@ -122,8 +129,6 @@ public: path. If path is NULL, just close the current file. */ void setPath(const char path[]); - - SkFILE* getSkFILE() const { return fFILE; } virtual bool rewind(); virtual size_t read(void* buffer, size_t size); @@ -134,6 +139,30 @@ private: SkString fName; }; +/** A stream that reads from a file descriptor + */ +class SkFDStream : public SkStream { +public: + /** Initialize the stream with a dup() of the specified file descriptor. + If closeWhenDone is true, then the descriptor will be closed in the + destructor. + */ + SkFDStream(int fileDesc, bool closeWhenDone); + virtual ~SkFDStream(); + + /** Returns true if the current path could be opened. + */ + bool isValid() const { return fFD >= 0; } + + virtual bool rewind(); + virtual size_t read(void* buffer, size_t size); + virtual const char* getFileName() { return NULL; } + +private: + int fFD; + bool fCloseWhenDone; +}; + class SkMemoryStream : public SkStream { public: SkMemoryStream(); @@ -175,14 +204,18 @@ public: /** Provide the stream to be buffered (proxy), and the size of the buffer that should be used. This will be allocated and freed automatically. If bufferSize is 0, a default buffer size will be used. + The proxy stream is referenced, and will be unreferenced in when the + bufferstream is destroyed. */ - SkBufferStream(SkStream& proxy, size_t bufferSize = 0); + SkBufferStream(SkStream* proxy, size_t bufferSize = 0); /** Provide the stream to be buffered (proxy), and a buffer and size to be used. This buffer is owned by the caller, and must be at least bufferSize bytes big. Passing NULL for buffer will cause the buffer to be allocated/freed automatically. If buffer is not NULL, it is an error for bufferSize to be 0. + The proxy stream is referenced, and will be unreferenced in when the + bufferstream is destroyed. */ - SkBufferStream(SkStream& proxy, void* buffer, size_t bufferSize); + SkBufferStream(SkStream* proxy, void* buffer, size_t bufferSize); virtual ~SkBufferStream(); virtual bool rewind(); @@ -198,7 +231,7 @@ private: SkBufferStream(const SkBufferStream&); SkBufferStream& operator=(const SkBufferStream&); - SkStream& fProxy; + SkStream* fProxy; char* fBuffer; size_t fOrigBufferSize, fBufferSize, fBufferOffset; bool fWeOwnTheBuffer; |