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 273 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
284 class SK_API SkMemoryStream : public SkStreamMemory { | 284 class SK_API SkMemoryStream : public SkStreamMemory { |
285 public: | 285 public: |
286 SkMemoryStream(); | 286 SkMemoryStream(); |
287 | 287 |
288 /** We allocate (and free) the memory. Write to it via getMemoryBase() */ | 288 /** We allocate (and free) the memory. Write to it via getMemoryBase() */ |
289 SkMemoryStream(size_t length); | 289 SkMemoryStream(size_t length); |
290 | 290 |
291 /** If copyData is true, the stream makes a private copy of the data. */ | 291 /** If copyData is true, the stream makes a private copy of the data. */ |
292 SkMemoryStream(const void* data, size_t length, bool copyData = false); | 292 SkMemoryStream(const void* data, size_t length, bool copyData = false); |
293 | 293 |
| 294 #ifdef SK_SUPPORT_LEGACY_STREAM_DATA |
294 /** Use the specified data as the memory for this stream. | 295 /** Use the specified data as the memory for this stream. |
295 * The stream will call ref() on the data (assuming it is not NULL). | 296 * The stream will call ref() on the data (assuming it is not NULL). |
296 * DEPRECATED | 297 * DEPRECATED |
297 */ | 298 */ |
298 SkMemoryStream(SkData*); | 299 SkMemoryStream(SkData*); |
| 300 #endif |
299 | 301 |
300 /** Creates the stream to read from the specified data */ | 302 /** Creates the stream to read from the specified data */ |
301 SkMemoryStream(sk_sp<SkData>); | 303 SkMemoryStream(sk_sp<SkData>); |
302 | 304 |
303 /** Resets the stream to the specified data and length, | 305 /** Resets the stream to the specified data and length, |
304 just like the constructor. | 306 just like the constructor. |
305 if copyData is true, the stream makes a private copy of the data | 307 if copyData is true, the stream makes a private copy of the data |
306 */ | 308 */ |
307 virtual void setMemory(const void* data, size_t length, | 309 virtual void setMemory(const void* data, size_t length, |
308 bool copyData = false); | 310 bool copyData = false); |
309 /** Replace any memory buffer with the specified buffer. The caller | 311 /** Replace any memory buffer with the specified buffer. The caller |
310 must have allocated data with sk_malloc or sk_realloc, since it | 312 must have allocated data with sk_malloc or sk_realloc, since it |
311 will be freed with sk_free. | 313 will be freed with sk_free. |
312 */ | 314 */ |
313 void setMemoryOwned(const void* data, size_t length); | 315 void setMemoryOwned(const void* data, size_t length); |
314 | 316 |
| 317 sk_sp<SkData> asData() const { return fData; } |
| 318 void setData(sk_sp<SkData>); |
| 319 #ifdef SK_SUPPORT_LEGACY_STREAM_DATA |
315 /** Return the stream's data in a SkData. | 320 /** Return the stream's data in a SkData. |
316 * The caller must call unref() when it is finished using the data. | 321 * The caller must call unref() when it is finished using the data. |
317 */ | 322 */ |
318 SkData* copyToData() const; | 323 SkData* copyToData() const { return asData().release(); } |
319 | 324 |
320 /** | 325 /** |
321 * Use the specified data as the memory for this stream. | 326 * Use the specified data as the memory for this stream. |
322 * The stream will call ref() on the data (assuming it is not NULL). | 327 * The stream will call ref() on the data (assuming it is not NULL). |
323 * The function returns the data parameter as a convenience. | 328 * The function returns the data parameter as a convenience. |
324 */ | 329 */ |
325 SkData* setData(SkData*); | 330 SkData* setData(SkData* data) { |
| 331 this->setData(sk_ref_sp(data)); |
| 332 return data; |
| 333 } |
| 334 #endif |
326 | 335 |
327 void skipToAlign4(); | 336 void skipToAlign4(); |
328 const void* getAtPos(); | 337 const void* getAtPos(); |
329 | 338 |
330 size_t read(void* buffer, size_t size) override; | 339 size_t read(void* buffer, size_t size) override; |
331 bool isAtEnd() const override; | 340 bool isAtEnd() const override; |
332 | 341 |
333 size_t peek(void* buffer, size_t size) const override; | 342 size_t peek(void* buffer, size_t size) const override; |
334 | 343 |
335 bool rewind() override; | 344 bool rewind() override; |
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
397 // random access write | 406 // random access write |
398 // modifies stream and returns true if offset + size is less than or equal t
o getOffset() | 407 // modifies stream and returns true if offset + size is less than or equal t
o getOffset() |
399 bool write(const void* buffer, size_t offset, size_t size); | 408 bool write(const void* buffer, size_t offset, size_t size); |
400 bool read(void* buffer, size_t offset, size_t size); | 409 bool read(void* buffer, size_t offset, size_t size); |
401 size_t getOffset() const { return fBytesWritten; } | 410 size_t getOffset() const { return fBytesWritten; } |
402 | 411 |
403 // copy what has been written to the stream into dst | 412 // copy what has been written to the stream into dst |
404 void copyTo(void* dst) const; | 413 void copyTo(void* dst) const; |
405 void writeToStream(SkWStream* dst) const; | 414 void writeToStream(SkWStream* dst) const; |
406 | 415 |
| 416 sk_sp<SkData> snapshotAsData() const; |
| 417 // Return the contents as SkData, and then reset the stream. |
| 418 sk_sp<SkData> detachAsData(); |
| 419 #ifdef SK_SUPPORT_LEGACY_STREAM_DATA |
407 /** | 420 /** |
408 * Return a copy of the data written so far. This call is responsible for | 421 * Return a copy of the data written so far. This call is responsible for |
409 * calling unref() when they are finished with the data. | 422 * calling unref() when they are finished with the data. |
410 */ | 423 */ |
411 SkData* copyToData() const; | 424 SkData* copyToData() const { |
| 425 return snapshotAsData().release(); |
| 426 } |
| 427 #endif |
412 | 428 |
413 /** Reset, returning a reader stream with the current content. */ | 429 /** Reset, returning a reader stream with the current content. */ |
414 SkStreamAsset* detachAsStream(); | 430 SkStreamAsset* detachAsStream(); |
415 | 431 |
416 /** Reset the stream to its original, empty, state. */ | 432 /** Reset the stream to its original, empty, state. */ |
417 void reset(); | 433 void reset(); |
418 void padToAlign4(); | 434 void padToAlign4(); |
419 private: | 435 private: |
420 struct Block; | 436 struct Block; |
421 Block* fHead; | 437 Block* fHead; |
(...skipping 22 matching lines...) Expand all Loading... |
444 | 460 |
445 private: | 461 private: |
446 size_t fBytesWritten; | 462 size_t fBytesWritten; |
447 typedef SkWStream INHERITED; | 463 typedef SkWStream INHERITED; |
448 }; | 464 }; |
449 | 465 |
450 // for now | 466 // for now |
451 typedef SkFILEStream SkURLStream; | 467 typedef SkFILEStream SkURLStream; |
452 | 468 |
453 #endif | 469 #endif |
OLD | NEW |