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

Side by Side Diff: src/core/SkStream.cpp

Issue 185263012: DM: read image files without an extra copy (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: three-lnies Created 6 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
« include/core/SkStream.h ('K') | « include/core/SkStream.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 1
2 /* 2 /*
3 * Copyright 2006 The Android Open Source Project 3 * Copyright 2006 The Android Open Source Project
4 * 4 *
5 * Use of this source code is governed by a BSD-style license that can be 5 * Use of this source code is governed by a BSD-style license that can be
6 * found in the LICENSE file. 6 * found in the LICENSE file.
7 */ 7 */
8 8
9 9
10 #include "SkStream.h" 10 #include "SkStream.h"
(...skipping 415 matching lines...) Expand 10 before | Expand all | Expand 10 after
426 //////////////////////////////////////////////////////////////////////////////// ///////////////////////// 426 //////////////////////////////////////////////////////////////////////////////// /////////////////////////
427 //////////////////////////////////////////////////////////////////////////////// ///////////////////////// 427 //////////////////////////////////////////////////////////////////////////////// /////////////////////////
428 428
429 SkFILEWStream::SkFILEWStream(const char path[]) 429 SkFILEWStream::SkFILEWStream(const char path[])
430 { 430 {
431 fFILE = sk_fopen(path, kWrite_SkFILE_Flag); 431 fFILE = sk_fopen(path, kWrite_SkFILE_Flag);
432 } 432 }
433 433
434 SkFILEWStream::~SkFILEWStream() 434 SkFILEWStream::~SkFILEWStream()
435 { 435 {
436 if (fFILE) 436 if (fFILE) {
437 sk_fclose(fFILE); 437 sk_fclose(fFILE);
438 }
439 }
440
441 size_t SkFILEWStream::bytesWritten() const {
442 return sk_ftell(fFILE);
438 } 443 }
439 444
440 bool SkFILEWStream::write(const void* buffer, size_t size) 445 bool SkFILEWStream::write(const void* buffer, size_t size)
441 { 446 {
442 if (fFILE == NULL) 447 if (fFILE == NULL) {
443 return false; 448 return false;
449 }
444 450
445 if (sk_fwrite(buffer, size, fFILE) != size) 451 if (sk_fwrite(buffer, size, fFILE) != size)
446 { 452 {
447 SkDEBUGCODE(SkDebugf("SkFILEWStream failed writing %d bytes\n", size);) 453 SkDEBUGCODE(SkDebugf("SkFILEWStream failed writing %d bytes\n", size);)
448 sk_fclose(fFILE); 454 sk_fclose(fFILE);
449 fFILE = NULL; 455 fFILE = NULL;
450 return false; 456 return false;
451 } 457 }
452 return true; 458 return true;
453 } 459 }
454 460
455 void SkFILEWStream::flush() 461 void SkFILEWStream::flush()
456 { 462 {
457 if (fFILE) 463 if (fFILE) {
458 sk_fflush(fFILE); 464 sk_fflush(fFILE);
465 }
459 } 466 }
460 467
461 //////////////////////////////////////////////////////////////////////// 468 ////////////////////////////////////////////////////////////////////////
462 469
463 SkMemoryWStream::SkMemoryWStream(void* buffer, size_t size) 470 SkMemoryWStream::SkMemoryWStream(void* buffer, size_t size)
464 : fBuffer((char*)buffer), fMaxLength(size), fBytesWritten(0) 471 : fBuffer((char*)buffer), fMaxLength(size), fBytesWritten(0)
465 { 472 {
466 } 473 }
467 474
468 bool SkMemoryWStream::write(const void* buffer, size_t size) 475 bool SkMemoryWStream::write(const void* buffer, size_t size)
(...skipping 360 matching lines...) Expand 10 before | Expand all | Expand 10 after
829 836
830 // If we get here, then our attempt at using mmap failed, so try normal 837 // If we get here, then our attempt at using mmap failed, so try normal
831 // file access. 838 // file access.
832 SkFILEStream* stream = SkNEW_ARGS(SkFILEStream, (path)); 839 SkFILEStream* stream = SkNEW_ARGS(SkFILEStream, (path));
833 if (!stream->isValid()) { 840 if (!stream->isValid()) {
834 stream->unref(); 841 stream->unref();
835 stream = NULL; 842 stream = NULL;
836 } 843 }
837 return stream; 844 return stream;
838 } 845 }
OLDNEW
« include/core/SkStream.h ('K') | « include/core/SkStream.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698