本文整理汇总了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);
}
示例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);
}
示例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;
}
示例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;
}
示例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;
}
示例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);
}
示例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;
}
示例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;
}
示例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);
}
示例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);
}
示例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;
}
示例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);
}