gfx/skia/trunk/src/images/SkStreamHelpers.cpp

Wed, 31 Dec 2014 06:09:35 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Wed, 31 Dec 2014 06:09:35 +0100
changeset 0
6474c204b198
permissions
-rw-r--r--

Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.

     1 /*
     2  * Copyright 2013 Google Inc.
     3  *
     4  * Use of this source code is governed by a BSD-style license that can be
     5  * found in the LICENSE file.
     6  */
     8 #include "SkStream.h"
     9 #include "SkStreamHelpers.h"
    10 #include "SkTypes.h"
    12 size_t CopyStreamToStorage(SkAutoMalloc* storage, SkStream* stream) {
    13     SkASSERT(storage != NULL);
    14     SkASSERT(stream != NULL);
    16     if (stream->hasLength()) {
    17         const size_t length = stream->getLength();
    18         void* dst = storage->reset(length);
    19         if (stream->read(dst, length) != length) {
    20             return 0;
    21         }
    22         return length;
    23     }
    25     SkDynamicMemoryWStream tempStream;
    26     // Arbitrary buffer size.
    27     const size_t bufferSize = 256 * 1024; // 256KB
    28     char buffer[bufferSize];
    29     SkDEBUGCODE(size_t debugLength = 0;)
    30     do {
    31         size_t bytesRead = stream->read(buffer, bufferSize);
    32         tempStream.write(buffer, bytesRead);
    33         SkDEBUGCODE(debugLength += bytesRead);
    34         SkASSERT(tempStream.bytesWritten() == debugLength);
    35     } while (!stream->isAtEnd());
    36     const size_t length = tempStream.bytesWritten();
    37     void* dst = storage->reset(length);
    38     tempStream.copyTo(dst);
    39     return length;
    40 }

mercurial