Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(129)

Side by Side Diff: include/core/SkStream.h

Issue 1779263003: Make sp variants for SkData (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: fix dynamicmemorywstream Created 4 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 "SkRefCnt.h" 11 #include "SkData.h"
bungeman-skia 2016/03/11 14:53:13 Please don't remove this. You are directly using s
bungeman-skia 2016/03/11 14:53:13 Was there a compiler that required this? It should
reed1 2016/03/11 19:23:34 Needed for destructor
12 #include "SkScalar.h" 12 #include "SkScalar.h"
13 13
14 class SkData;
15
16 class SkStream; 14 class SkStream;
17 class SkStreamRewindable; 15 class SkStreamRewindable;
18 class SkStreamSeekable; 16 class SkStreamSeekable;
19 class SkStreamAsset; 17 class SkStreamAsset;
20 class SkStreamMemory; 18 class SkStreamMemory;
21 19
22 /** 20 /**
23 * SkStream -- abstraction for a source of bytes. Subclasses can be backed by 21 * SkStream -- abstraction for a source of bytes. Subclasses can be backed by
24 * memory, or a file, or something else. 22 * memory, or a file, or something else.
25 * 23 *
(...skipping 237 matching lines...) Expand 10 before | Expand all | Expand 10 after
263 size_t getPosition() const override; 261 size_t getPosition() const override;
264 bool seek(size_t position) override; 262 bool seek(size_t position) override;
265 bool move(long offset) override; 263 bool move(long offset) override;
266 SkStreamAsset* fork() const override; 264 SkStreamAsset* fork() const override;
267 265
268 size_t getLength() const override; 266 size_t getLength() const override;
269 267
270 const void* getMemoryBase() override; 268 const void* getMemoryBase() override;
271 269
272 private: 270 private:
273 FILE* fFILE; 271 FILE* fFILE;
274 SkString fName; 272 SkString fName;
275 Ownership fOwnership; 273 Ownership fOwnership;
276 // fData is lazilly initialized when needed. 274 // fData is lazilly initialized when needed.
277 mutable SkAutoTUnref<SkData> fData; 275 mutable sk_sp<SkData> fData;
278 276
279 typedef SkStreamAsset INHERITED; 277 typedef SkStreamAsset INHERITED;
280 }; 278 };
281 279
282 class SK_API SkMemoryStream : public SkStreamMemory { 280 class SK_API SkMemoryStream : public SkStreamMemory {
283 public: 281 public:
284 SkMemoryStream(); 282 SkMemoryStream();
285 283
286 /** We allocate (and free) the memory. Write to it via getMemoryBase() */ 284 /** We allocate (and free) the memory. Write to it via getMemoryBase() */
287 SkMemoryStream(size_t length); 285 SkMemoryStream(size_t length);
288 286
289 /** If copyData is true, the stream makes a private copy of the data. */ 287 /** If copyData is true, the stream makes a private copy of the data. */
290 SkMemoryStream(const void* data, size_t length, bool copyData = false); 288 SkMemoryStream(const void* data, size_t length, bool copyData = false);
291 289
292 /** Use the specified data as the memory for this stream. 290 /** Use the specified data as the memory for this stream.
293 * The stream will call ref() on the data (assuming it is not NULL). 291 * The stream will call ref() on the data (assuming it is not NULL).
scroggo 2016/03/11 15:28:35 IIUC, this is not necessarily true for the sk_sp v
reed1 2016/03/11 19:23:34 Done.
294 */ 292 */
295 SkMemoryStream(SkData*); 293 SkMemoryStream(SkData*);
296 294 SkMemoryStream(sk_sp<SkData>);
297 virtual ~SkMemoryStream();
298 295
299 /** Resets the stream to the specified data and length, 296 /** Resets the stream to the specified data and length,
300 just like the constructor. 297 just like the constructor.
301 if copyData is true, the stream makes a private copy of the data 298 if copyData is true, the stream makes a private copy of the data
302 */ 299 */
303 virtual void setMemory(const void* data, size_t length, 300 virtual void setMemory(const void* data, size_t length,
304 bool copyData = false); 301 bool copyData = false);
305 /** Replace any memory buffer with the specified buffer. The caller 302 /** Replace any memory buffer with the specified buffer. The caller
306 must have allocated data with sk_malloc or sk_realloc, since it 303 must have allocated data with sk_malloc or sk_realloc, since it
307 will be freed with sk_free. 304 will be freed with sk_free.
(...skipping 26 matching lines...) Expand all
334 size_t getPosition() const override; 331 size_t getPosition() const override;
335 bool seek(size_t position) override; 332 bool seek(size_t position) override;
336 bool move(long offset) override; 333 bool move(long offset) override;
337 SkMemoryStream* fork() const override; 334 SkMemoryStream* fork() const override;
338 335
339 size_t getLength() const override; 336 size_t getLength() const override;
340 337
341 const void* getMemoryBase() override; 338 const void* getMemoryBase() override;
342 339
343 private: 340 private:
344 SkData* fData; 341 sk_sp<SkData> fData;
345 size_t fOffset; 342 size_t fOffset;
346 343
347 typedef SkStreamMemory INHERITED; 344 typedef SkStreamMemory INHERITED;
348 }; 345 };
349 346
350 //////////////////////////////////////////////////////////////////////////////// ///////////// 347 //////////////////////////////////////////////////////////////////////////////// /////////////
351 348
352 class SK_API SkFILEWStream : public SkWStream { 349 class SK_API SkFILEWStream : public SkWStream {
353 public: 350 public:
354 SkFILEWStream(const char path[]); 351 SkFILEWStream(const char path[]);
355 virtual ~SkFILEWStream(); 352 virtual ~SkFILEWStream();
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after
410 SkStreamAsset* detachAsStream(); 407 SkStreamAsset* detachAsStream();
411 408
412 /** Reset the stream to its original, empty, state. */ 409 /** Reset the stream to its original, empty, state. */
413 void reset(); 410 void reset();
414 void padToAlign4(); 411 void padToAlign4();
415 private: 412 private:
416 struct Block; 413 struct Block;
417 Block* fHead; 414 Block* fHead;
418 Block* fTail; 415 Block* fTail;
419 size_t fBytesWritten; 416 size_t fBytesWritten;
420 mutable SkData* fCopy; // is invalidated if we write after it is created 417 mutable sk_sp<SkData> fCopy; // is invalidated if we write after it is crea ted
421 418
422 void invalidateCopy(); 419 void invalidateCopy();
423 420
424 // For access to the Block type. 421 // For access to the Block type.
425 friend class SkBlockMemoryStream; 422 friend class SkBlockMemoryStream;
426 friend class SkBlockMemoryRefCnt; 423 friend class SkBlockMemoryRefCnt;
427 424
428 typedef SkWStream INHERITED; 425 typedef SkWStream INHERITED;
429 }; 426 };
430 427
431 428
432 class SK_API SkDebugWStream : public SkWStream { 429 class SK_API SkDebugWStream : public SkWStream {
433 public: 430 public:
434 SkDebugWStream() : fBytesWritten(0) {} 431 SkDebugWStream() : fBytesWritten(0) {}
435 432
436 // overrides 433 // overrides
437 bool write(const void* buffer, size_t size) override; 434 bool write(const void* buffer, size_t size) override;
438 void newline() override; 435 void newline() override;
439 size_t bytesWritten() const override { return fBytesWritten; } 436 size_t bytesWritten() const override { return fBytesWritten; }
440 437
441 private: 438 private:
442 size_t fBytesWritten; 439 size_t fBytesWritten;
443 typedef SkWStream INHERITED; 440 typedef SkWStream INHERITED;
444 }; 441 };
445 442
446 // for now 443 // for now
447 typedef SkFILEStream SkURLStream; 444 typedef SkFILEStream SkURLStream;
448 445
449 #endif 446 #endif
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698