OLD | NEW |
1 /* | 1 /* |
2 * Copyright 2006 The Android Open Source Project | 2 * Copyright 2006 The Android Open Source Project |
3 * | 3 * |
4 * Use of this source code is governed by a BSD-style license that can be | 4 * Use of this source code is governed by a BSD-style license that can be |
5 * found in the LICENSE file. | 5 * found in the LICENSE file. |
6 */ | 6 */ |
7 | 7 |
8 #ifndef SkStream_DEFINED | 8 #ifndef SkStream_DEFINED |
9 #define SkStream_DEFINED | 9 #define SkStream_DEFINED |
10 | 10 |
| 11 #include "SkData.h" |
11 #include "SkRefCnt.h" | 12 #include "SkRefCnt.h" |
12 #include "SkScalar.h" | 13 #include "SkScalar.h" |
13 | 14 |
14 class SkData; | |
15 | |
16 class SkStream; | 15 class SkStream; |
17 class SkStreamRewindable; | 16 class SkStreamRewindable; |
18 class SkStreamSeekable; | 17 class SkStreamSeekable; |
19 class SkStreamAsset; | 18 class SkStreamAsset; |
20 class SkStreamMemory; | 19 class SkStreamMemory; |
21 | 20 |
22 /** | 21 /** |
23 * SkStream -- abstraction for a source of bytes. Subclasses can be backed by | 22 * SkStream -- abstraction for a source of bytes. Subclasses can be backed by |
24 * memory, or a file, or something else. | 23 * memory, or a file, or something else. |
25 * | 24 * |
(...skipping 237 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
263 size_t getPosition() const override; | 262 size_t getPosition() const override; |
264 bool seek(size_t position) override; | 263 bool seek(size_t position) override; |
265 bool move(long offset) override; | 264 bool move(long offset) override; |
266 SkStreamAsset* fork() const override; | 265 SkStreamAsset* fork() const override; |
267 | 266 |
268 size_t getLength() const override; | 267 size_t getLength() const override; |
269 | 268 |
270 const void* getMemoryBase() override; | 269 const void* getMemoryBase() override; |
271 | 270 |
272 private: | 271 private: |
273 FILE* fFILE; | 272 FILE* fFILE; |
274 SkString fName; | 273 SkString fName; |
275 Ownership fOwnership; | 274 Ownership fOwnership; |
276 // fData is lazilly initialized when needed. | 275 // fData is lazilly initialized when needed. |
277 mutable SkAutoTUnref<SkData> fData; | 276 mutable sk_sp<SkData> fData; |
278 | 277 |
279 typedef SkStreamAsset INHERITED; | 278 typedef SkStreamAsset INHERITED; |
280 }; | 279 }; |
281 | 280 |
282 class SK_API SkMemoryStream : public SkStreamMemory { | 281 class SK_API SkMemoryStream : public SkStreamMemory { |
283 public: | 282 public: |
284 SkMemoryStream(); | 283 SkMemoryStream(); |
285 | 284 |
286 /** We allocate (and free) the memory. Write to it via getMemoryBase() */ | 285 /** We allocate (and free) the memory. Write to it via getMemoryBase() */ |
287 SkMemoryStream(size_t length); | 286 SkMemoryStream(size_t length); |
288 | 287 |
289 /** If copyData is true, the stream makes a private copy of the data. */ | 288 /** If copyData is true, the stream makes a private copy of the data. */ |
290 SkMemoryStream(const void* data, size_t length, bool copyData = false); | 289 SkMemoryStream(const void* data, size_t length, bool copyData = false); |
291 | 290 |
292 /** Use the specified data as the memory for this stream. | 291 /** Use the specified data as the memory for this stream. |
293 * The stream will call ref() on the data (assuming it is not NULL). | 292 * The stream will call ref() on the data (assuming it is not NULL). |
| 293 * DEPRECATED |
294 */ | 294 */ |
295 SkMemoryStream(SkData*); | 295 SkMemoryStream(SkData*); |
296 | 296 |
297 virtual ~SkMemoryStream(); | 297 /** Creates the stream to read from the specified data */ |
| 298 SkMemoryStream(sk_sp<SkData>); |
298 | 299 |
299 /** Resets the stream to the specified data and length, | 300 /** Resets the stream to the specified data and length, |
300 just like the constructor. | 301 just like the constructor. |
301 if copyData is true, the stream makes a private copy of the data | 302 if copyData is true, the stream makes a private copy of the data |
302 */ | 303 */ |
303 virtual void setMemory(const void* data, size_t length, | 304 virtual void setMemory(const void* data, size_t length, |
304 bool copyData = false); | 305 bool copyData = false); |
305 /** Replace any memory buffer with the specified buffer. The caller | 306 /** Replace any memory buffer with the specified buffer. The caller |
306 must have allocated data with sk_malloc or sk_realloc, since it | 307 must have allocated data with sk_malloc or sk_realloc, since it |
307 will be freed with sk_free. | 308 will be freed with sk_free. |
(...skipping 26 matching lines...) Expand all Loading... |
334 size_t getPosition() const override; | 335 size_t getPosition() const override; |
335 bool seek(size_t position) override; | 336 bool seek(size_t position) override; |
336 bool move(long offset) override; | 337 bool move(long offset) override; |
337 SkMemoryStream* fork() const override; | 338 SkMemoryStream* fork() const override; |
338 | 339 |
339 size_t getLength() const override; | 340 size_t getLength() const override; |
340 | 341 |
341 const void* getMemoryBase() override; | 342 const void* getMemoryBase() override; |
342 | 343 |
343 private: | 344 private: |
344 SkData* fData; | 345 sk_sp<SkData> fData; |
345 size_t fOffset; | 346 size_t fOffset; |
346 | 347 |
347 typedef SkStreamMemory INHERITED; | 348 typedef SkStreamMemory INHERITED; |
348 }; | 349 }; |
349 | 350 |
350 ////////////////////////////////////////////////////////////////////////////////
///////////// | 351 ////////////////////////////////////////////////////////////////////////////////
///////////// |
351 | 352 |
352 class SK_API SkFILEWStream : public SkWStream { | 353 class SK_API SkFILEWStream : public SkWStream { |
353 public: | 354 public: |
354 SkFILEWStream(const char path[]); | 355 SkFILEWStream(const char path[]); |
355 virtual ~SkFILEWStream(); | 356 virtual ~SkFILEWStream(); |
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
410 SkStreamAsset* detachAsStream(); | 411 SkStreamAsset* detachAsStream(); |
411 | 412 |
412 /** Reset the stream to its original, empty, state. */ | 413 /** Reset the stream to its original, empty, state. */ |
413 void reset(); | 414 void reset(); |
414 void padToAlign4(); | 415 void padToAlign4(); |
415 private: | 416 private: |
416 struct Block; | 417 struct Block; |
417 Block* fHead; | 418 Block* fHead; |
418 Block* fTail; | 419 Block* fTail; |
419 size_t fBytesWritten; | 420 size_t fBytesWritten; |
420 mutable SkData* fCopy; // is invalidated if we write after it is created | 421 mutable sk_sp<SkData> fCopy; // is invalidated if we write after it is crea
ted |
421 | 422 |
422 void invalidateCopy(); | 423 void invalidateCopy(); |
423 | 424 |
424 // For access to the Block type. | 425 // For access to the Block type. |
425 friend class SkBlockMemoryStream; | 426 friend class SkBlockMemoryStream; |
426 friend class SkBlockMemoryRefCnt; | 427 friend class SkBlockMemoryRefCnt; |
427 | 428 |
428 typedef SkWStream INHERITED; | 429 typedef SkWStream INHERITED; |
429 }; | 430 }; |
430 | 431 |
431 | 432 |
432 class SK_API SkDebugWStream : public SkWStream { | 433 class SK_API SkDebugWStream : public SkWStream { |
433 public: | 434 public: |
434 SkDebugWStream() : fBytesWritten(0) {} | 435 SkDebugWStream() : fBytesWritten(0) {} |
435 | 436 |
436 // overrides | 437 // overrides |
437 bool write(const void* buffer, size_t size) override; | 438 bool write(const void* buffer, size_t size) override; |
438 void newline() override; | 439 void newline() override; |
439 size_t bytesWritten() const override { return fBytesWritten; } | 440 size_t bytesWritten() const override { return fBytesWritten; } |
440 | 441 |
441 private: | 442 private: |
442 size_t fBytesWritten; | 443 size_t fBytesWritten; |
443 typedef SkWStream INHERITED; | 444 typedef SkWStream INHERITED; |
444 }; | 445 }; |
445 | 446 |
446 // for now | 447 // for now |
447 typedef SkFILEStream SkURLStream; | 448 typedef SkFILEStream SkURLStream; |
448 | 449 |
449 #endif | 450 #endif |
OLD | NEW |