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 |
(...skipping 171 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
182 | 182 |
183 /** Called to write bytes to a SkWStream. Returns true on success | 183 /** Called to write bytes to a SkWStream. Returns true on success |
184 @param buffer the address of at least size bytes to be written to the st
ream | 184 @param buffer the address of at least size bytes to be written to the st
ream |
185 @param size The number of bytes in buffer to write to the stream | 185 @param size The number of bytes in buffer to write to the stream |
186 @return true on success | 186 @return true on success |
187 */ | 187 */ |
188 virtual bool write(const void* buffer, size_t size) = 0; | 188 virtual bool write(const void* buffer, size_t size) = 0; |
189 virtual void newline(); | 189 virtual void newline(); |
190 virtual void flush(); | 190 virtual void flush(); |
191 | 191 |
| 192 virtual size_t bytesWritten() const = 0; |
| 193 |
192 // helpers | 194 // helpers |
193 | 195 |
194 bool write8(U8CPU); | 196 bool write8(U8CPU); |
195 bool write16(U16CPU); | 197 bool write16(U16CPU); |
196 bool write32(uint32_t); | 198 bool write32(uint32_t); |
197 | 199 |
198 bool writeText(const char text[]); | 200 bool writeText(const char text[]); |
199 bool writeDecAsText(int32_t); | 201 bool writeDecAsText(int32_t); |
200 bool writeBigDecAsText(int64_t, int minDigits = 0); | 202 bool writeBigDecAsText(int64_t, int minDigits = 0); |
201 bool writeHexAsText(uint32_t, int minDigits = 0); | 203 bool writeHexAsText(uint32_t, int minDigits = 0); |
(...skipping 160 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
362 public: | 364 public: |
363 SK_DECLARE_INST_COUNT(SkFILEWStream) | 365 SK_DECLARE_INST_COUNT(SkFILEWStream) |
364 | 366 |
365 SkFILEWStream(const char path[]); | 367 SkFILEWStream(const char path[]); |
366 virtual ~SkFILEWStream(); | 368 virtual ~SkFILEWStream(); |
367 | 369 |
368 /** Returns true if the current path could be opened. | 370 /** Returns true if the current path could be opened. |
369 */ | 371 */ |
370 bool isValid() const { return fFILE != NULL; } | 372 bool isValid() const { return fFILE != NULL; } |
371 | 373 |
372 size_t bytesWritten() const; | |
373 virtual bool write(const void* buffer, size_t size) SK_OVERRIDE; | 374 virtual bool write(const void* buffer, size_t size) SK_OVERRIDE; |
374 virtual void flush() SK_OVERRIDE; | 375 virtual void flush() SK_OVERRIDE; |
| 376 virtual size_t bytesWritten() const SK_OVERRIDE; |
375 | 377 |
376 private: | 378 private: |
377 SkFILE* fFILE; | 379 SkFILE* fFILE; |
378 | 380 |
379 typedef SkWStream INHERITED; | 381 typedef SkWStream INHERITED; |
380 }; | 382 }; |
381 | 383 |
382 class SkMemoryWStream : public SkWStream { | 384 class SkMemoryWStream : public SkWStream { |
383 public: | 385 public: |
384 SK_DECLARE_INST_COUNT(SkMemoryWStream) | 386 SK_DECLARE_INST_COUNT(SkMemoryWStream) |
385 | 387 |
386 SkMemoryWStream(void* buffer, size_t size); | 388 SkMemoryWStream(void* buffer, size_t size); |
387 virtual bool write(const void* buffer, size_t size) SK_OVERRIDE; | 389 virtual bool write(const void* buffer, size_t size) SK_OVERRIDE; |
388 size_t bytesWritten() const { return fBytesWritten; } | 390 virtual size_t bytesWritten() const SK_OVERRIDE { return fBytesWritten; } |
389 | 391 |
390 private: | 392 private: |
391 char* fBuffer; | 393 char* fBuffer; |
392 size_t fMaxLength; | 394 size_t fMaxLength; |
393 size_t fBytesWritten; | 395 size_t fBytesWritten; |
394 | 396 |
395 typedef SkWStream INHERITED; | 397 typedef SkWStream INHERITED; |
396 }; | 398 }; |
397 | 399 |
398 class SK_API SkDynamicMemoryWStream : public SkWStream { | 400 class SK_API SkDynamicMemoryWStream : public SkWStream { |
399 public: | 401 public: |
400 SK_DECLARE_INST_COUNT(SkDynamicMemoryWStream) | 402 SK_DECLARE_INST_COUNT(SkDynamicMemoryWStream) |
401 | 403 |
402 SkDynamicMemoryWStream(); | 404 SkDynamicMemoryWStream(); |
403 virtual ~SkDynamicMemoryWStream(); | 405 virtual ~SkDynamicMemoryWStream(); |
404 | 406 |
405 virtual bool write(const void* buffer, size_t size) SK_OVERRIDE; | 407 virtual bool write(const void* buffer, size_t size) SK_OVERRIDE; |
| 408 virtual size_t bytesWritten() const SK_OVERRIDE { return fBytesWritten; } |
406 // random access write | 409 // random access write |
407 // modifies stream and returns true if offset + size is less than or equal t
o getOffset() | 410 // modifies stream and returns true if offset + size is less than or equal t
o getOffset() |
408 bool write(const void* buffer, size_t offset, size_t size); | 411 bool write(const void* buffer, size_t offset, size_t size); |
409 bool read(void* buffer, size_t offset, size_t size); | 412 bool read(void* buffer, size_t offset, size_t size); |
410 size_t getOffset() const { return fBytesWritten; } | 413 size_t getOffset() const { return fBytesWritten; } |
411 size_t bytesWritten() const { return fBytesWritten; } | |
412 | 414 |
413 // copy what has been written to the stream into dst | 415 // copy what has been written to the stream into dst |
414 void copyTo(void* dst) const; | 416 void copyTo(void* dst) const; |
415 | 417 |
416 /** | 418 /** |
417 * Return a copy of the data written so far. This call is responsible for | 419 * Return a copy of the data written so far. This call is responsible for |
418 * calling unref() when they are finished with the data. | 420 * calling unref() when they are finished with the data. |
419 */ | 421 */ |
420 SkData* copyToData() const; | 422 SkData* copyToData() const; |
421 | 423 |
(...skipping 15 matching lines...) Expand all Loading... |
437 // For access to the Block type. | 439 // For access to the Block type. |
438 friend class SkBlockMemoryStream; | 440 friend class SkBlockMemoryStream; |
439 friend class SkBlockMemoryRefCnt; | 441 friend class SkBlockMemoryRefCnt; |
440 | 442 |
441 typedef SkWStream INHERITED; | 443 typedef SkWStream INHERITED; |
442 }; | 444 }; |
443 | 445 |
444 | 446 |
445 class SK_API SkDebugWStream : public SkWStream { | 447 class SK_API SkDebugWStream : public SkWStream { |
446 public: | 448 public: |
| 449 SkDebugWStream() : fBytesWritten(0) {} |
447 SK_DECLARE_INST_COUNT(SkDebugWStream) | 450 SK_DECLARE_INST_COUNT(SkDebugWStream) |
448 | 451 |
449 // overrides | 452 // overrides |
450 virtual bool write(const void* buffer, size_t size) SK_OVERRIDE; | 453 virtual bool write(const void* buffer, size_t size) SK_OVERRIDE; |
451 virtual void newline() SK_OVERRIDE; | 454 virtual void newline() SK_OVERRIDE; |
| 455 virtual size_t bytesWritten() const SK_OVERRIDE { return fBytesWritten; } |
452 | 456 |
453 private: | 457 private: |
| 458 size_t fBytesWritten; |
454 typedef SkWStream INHERITED; | 459 typedef SkWStream INHERITED; |
455 }; | 460 }; |
456 | 461 |
457 // for now | 462 // for now |
458 typedef SkFILEStream SkURLStream; | 463 typedef SkFILEStream SkURLStream; |
459 | 464 |
460 #endif | 465 #endif |
OLD | NEW |