当前位置: 首页>>代码示例>>C++>>正文


C++ SkMemoryStream类代码示例

本文整理汇总了C++中SkMemoryStream的典型用法代码示例。如果您正苦于以下问题:C++ SkMemoryStream类的具体用法?C++ SkMemoryStream怎么用?C++ SkMemoryStream使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


在下文中一共展示了SkMemoryStream类的12个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: ac

SkTypeface* SkFontHost::Deserialize(SkStream* stream) {
    {
        SkAutoMutexAcquire  ac(gFamilyMutex);
        load_system_fonts();
    }

    SkFontDescriptor descriptor(stream);
    const char* familyName = descriptor.getFamilyName();
    const char* typefaceName = descriptor.getFontFileName();
    const SkTypeface::Style style = descriptor.getStyle();

    const uint32_t customFontDataLength = stream->readPackedUInt();
    if (customFontDataLength > 0) {

        // generate a new stream to store the custom typeface
        SkMemoryStream* fontStream = new SkMemoryStream(customFontDataLength - 1);
        stream->read((void*)fontStream->getMemoryBase(), customFontDataLength - 1);

        SkTypeface* face = CreateTypefaceFromStream(fontStream);

        fontStream->unref();
        return face;
    }

    return SkFontHost::CreateTypeface(NULL, familyName, style);
}
开发者ID:jamorton,项目名称:blix,代码行数:26,代码来源:SkFontHost_linux.cpp

示例2: test_initial_offset

// Test using a stream with an initial offset.
static void test_initial_offset(skiatest::Reporter* reporter, size_t bufferSize) {
    SkMemoryStream* memStream = new SkMemoryStream(gAbcs, strlen(gAbcs), false);

    // Skip a few characters into the memStream, so that bufferedStream represents an offset into
    // the stream it wraps.
    const size_t arbitraryOffset = 17;
    memStream->skip(arbitraryOffset);
    std::unique_ptr<SkStream> bufferedStream(SkFrontBufferedStream::Create(memStream, bufferSize));

    // Since SkMemoryStream has a length, bufferedStream must also.
    REPORTER_ASSERT(reporter, bufferedStream->hasLength());

    const size_t amountToRead = 10;
    const size_t bufferedLength = bufferedStream->getLength();
    size_t currentPosition = 0;

    // Read the stream in chunks. After each read, the position must match currentPosition,
    // which sums the amount attempted to read, unless the end of the stream has been reached.
    // Importantly, the end should not have been reached until currentPosition == bufferedLength.
    while (currentPosition < bufferedLength) {
        REPORTER_ASSERT(reporter, !bufferedStream->isAtEnd());
        test_read(reporter, bufferedStream.get(), gAbcs + arbitraryOffset + currentPosition,
                  amountToRead);
        currentPosition = SkTMin(currentPosition + amountToRead, bufferedLength);
        REPORTER_ASSERT(reporter, memStream->getPosition() - arbitraryOffset == currentPosition);
    }
    REPORTER_ASSERT(reporter, bufferedStream->isAtEnd());
    REPORTER_ASSERT(reporter, bufferedLength == currentPosition);
}
开发者ID:MIPS,项目名称:external-skia,代码行数:30,代码来源:FrontBufferedStreamTest.cpp

示例3: SkASSERT

size_t SkMemoryStream::peek(void* buffer, size_t size) const {
    SkASSERT(buffer != nullptr);

    const size_t currentOffset = fOffset;
    SkMemoryStream* nonConstThis = const_cast<SkMemoryStream*>(this);
    const size_t bytesRead = nonConstThis->read(buffer, size);
    nonConstThis->fOffset = currentOffset;
    return bytesRead;
}
开发者ID:alphan102,项目名称:gecko-dev,代码行数:9,代码来源:SkStream.cpp

示例4: content

SkStream* SkPDFDevice::content() const {
    size_t offset = fContent.getOffset();
    char* data = (char*)sk_malloc_throw(offset + fGraphicStackIndex * 2);
    fContent.copyTo(data);
    for (int i = 0; i < fGraphicStackIndex; i++) {
        data[offset++] = 'Q';
        data[offset++] = '\n';
    }
    SkMemoryStream* result = new SkMemoryStream;
    result->setMemoryOwned(data, offset);
    return result;
}
开发者ID:xuchiheng,项目名称:ucore-arm-skia,代码行数:12,代码来源:SkPDFDevice.cpp

示例5: SkASSERT

bool SkMemoryStream::peek(void* buffer, size_t size) const {
    SkASSERT(buffer != nullptr);
    const size_t position = fOffset;
    if (size > fData->size() - position) {
        // The stream is not large enough to satisfy this request.
        return false;
    }
    SkMemoryStream* nonConstThis = const_cast<SkMemoryStream*>(this);
    SkDEBUGCODE(const size_t bytesRead =) nonConstThis->read(buffer, size);
    SkASSERT(bytesRead == size);
    nonConstThis->fOffset = position;
    return true;
}
开发者ID:Just-D,项目名称:skia,代码行数:13,代码来源:SkStream.cpp

示例6: test_perfectly_sized_buffer

static void test_perfectly_sized_buffer(skiatest::Reporter* reporter, size_t bufferSize) {
    SkMemoryStream* memStream = new SkMemoryStream(gAbcs, strlen(gAbcs), false);
    std::unique_ptr<SkStream> bufferedStream(SkFrontBufferedStream::Create(memStream, bufferSize));
    test_hasLength(reporter, *bufferedStream, *memStream);

    // Read exactly the amount that fits in the buffer.
    test_read(reporter, bufferedStream.get(), gAbcs, bufferSize);

    // Rewinding should succeed.
    test_rewind(reporter, bufferedStream.get(), true);

    // Once again reading buffered info should succeed
    test_read(reporter, bufferedStream.get(), gAbcs, bufferSize);

    // Read past the size of the buffer. At this point, we cannot return.
    test_read(reporter, bufferedStream.get(), gAbcs + memStream->getPosition(), 1);
    test_rewind(reporter, bufferedStream.get(), false);
}
开发者ID:MIPS,项目名称:external-skia,代码行数:18,代码来源:FrontBufferedStreamTest.cpp

示例7: load_system_fonts

SkTypeface* SkFontHost::Deserialize(SkStream* stream) {
    load_system_fonts();

    // read the length of the custom font from the stream
    uint32_t len = stream->readU32();

    // generate a new stream to store the custom typeface
    SkMemoryStream* fontStream = new SkMemoryStream(len);
    stream->read((void*)fontStream->getMemoryBase(), len);

    SkTypeface* face = CreateTypefaceFromStream(fontStream);

    fontStream->unref();

    return face;

//    sk_throw();
//    return NULL;
}
开发者ID:Carbon2011,项目名称:android_external_skia,代码行数:19,代码来源:SkFontHost_linux.cpp

示例8: buildSkMemoryStream

static SkMemoryStream* buildSkMemoryStream(SkStream *stream) {
    size_t bufferSize = 4096;
    size_t streamLen = 0;
    size_t len;
    char* data = (char*)sk_malloc_throw(bufferSize);

    while ((len = stream->read(data + streamLen,
                    bufferSize - streamLen)) != 0) {
        streamLen += len;
        if (streamLen == bufferSize) {
            bufferSize *= 2;
            data = (char*)sk_realloc_throw(data, bufferSize);
        }
    }
    data = (char*)sk_realloc_throw(data, streamLen);

    SkMemoryStream* streamMem = new SkMemoryStream();
    streamMem->setMemoryOwned(data, streamLen);
    return streamMem;
}
开发者ID:AwaisKing,项目名称:mt6577_aosp_source,代码行数:20,代码来源:BitmapRegionDecoder.cpp

示例9: ac

SkTypeface* SkFontHost::Deserialize(SkStream* stream) {
    {
        SkAutoMutexAcquire  ac(gFamilyHeadAndNameListMutex);
        load_system_fonts();
    }

    SkFontDescriptor descriptor(stream);
    const char* familyName = descriptor.getFamilyName();
    const char* fontFileName = descriptor.getFontFileName();
    const SkTypeface::Style style = descriptor.getStyle();

    const uint32_t customFontDataLength = stream->readPackedUInt();
    if (customFontDataLength > 0) {

        // generate a new stream to store the custom typeface
        SkMemoryStream* fontStream = new SkMemoryStream(customFontDataLength - 1);
        stream->read((void*)fontStream->getMemoryBase(), customFontDataLength - 1);

        SkTypeface* face = CreateTypefaceFromStream(fontStream);

        fontStream->unref();
        return face;
    }

    if (NULL != fontFileName && 0 != *fontFileName) {
        const FontInitRec* rec = gSystemFonts;
        for (size_t i = 0; i < gNumSystemFonts; i++) {
            if (strcmp(rec[i].fFileName, fontFileName) == 0) {
                // backup until we hit the fNames
                for (int j = i; j >= 0; --j) {
                    if (rec[j].fNames != NULL) {
                        return SkFontHost::CreateTypeface(NULL,
                                    rec[j].fNames[0], style);
                    }
                }
            }
        }
    }

    return SkFontHost::CreateTypeface(NULL, familyName, style);
}
开发者ID:bunhere,项目名称:skia,代码行数:41,代码来源:SkFontHost_android.cpp

示例10: test_skipping

static void test_skipping(skiatest::Reporter* reporter, size_t bufferSize) {
    SkMemoryStream* memStream = new SkMemoryStream(gAbcs, strlen(gAbcs), false);
    std::unique_ptr<SkStream> bufferedStream(SkFrontBufferedStream::Create(memStream, bufferSize));
    test_hasLength(reporter, *bufferedStream, *memStream);

    // Skip half the buffer.
    bufferedStream->skip(bufferSize / 2);

    // Rewind, then read part of the buffer, which should have been read.
    test_rewind(reporter, bufferedStream.get(), true);
    test_read(reporter, bufferedStream.get(), gAbcs, bufferSize / 4);

    // Now skip beyond the buffered piece, but still within the total buffer.
    bufferedStream->skip(bufferSize / 2);

    // Test that reading will still work.
    test_read(reporter, bufferedStream.get(), gAbcs + memStream->getPosition(), bufferSize / 4);

    test_rewind(reporter, bufferedStream.get(), true);
    test_read(reporter, bufferedStream.get(), gAbcs, bufferSize);
}
开发者ID:MIPS,项目名称:external-skia,代码行数:21,代码来源:FrontBufferedStreamTest.cpp

示例11: ac

SkStream* SkFontHost::OpenStream(SkFontID uniqueID) {
    SkAutoMutexAcquire ac(gFTMutex);
    LogFontTypeface* rec = LogFontTypeface::FindById(uniqueID);

    HDC hdc = ::CreateCompatibleDC(NULL);
    HFONT font = CreateFontIndirect(&rec->logFont());
    HFONT savefont = (HFONT)SelectObject(hdc, font);

    size_t bufferSize = GetFontData(hdc, 0, 0, NULL, 0);
    SkMemoryStream* stream = new SkMemoryStream(bufferSize);
    if (!GetFontData(hdc, 0, 0, (void*)stream->getMemoryBase(), bufferSize)) {
        delete stream;
        stream = NULL;
    }

    SelectObject(hdc, savefont);
    DeleteObject(font);
    DeleteDC(hdc);

    return stream;
}
开发者ID:bluecover,项目名称:chromium_base,代码行数:21,代码来源:SkFontHost_win.cpp

示例12: test_dataset

static void test_dataset(skiatest::Reporter* reporter, const SkDataSet& ds,
                         int count) {
    REPORTER_ASSERT(reporter, ds.count() == count);

    SkDataSet::Iter iter(ds);
    int index = 0;
    for (; !iter.done(); iter.next()) {
//        const char* name = iter.key();
//        SkData* data = iter.value();
//        SkDebugf("[%d] %s:%s\n", index, name, (const char*)data->bytes());
        index += 1;
    }
    REPORTER_ASSERT(reporter, index == count);

    SkDynamicMemoryWStream ostream;
    ds.writeToStream(&ostream);
    SkMemoryStream istream;
    istream.setData(ostream.copyToData())->unref();
    SkDataSet copy(&istream);

    test_datasets_equal(reporter, ds, copy);
}
开发者ID:Cue,项目名称:skia,代码行数:22,代码来源:DataRefTest.cpp


注:本文中的SkMemoryStream类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。