本文整理汇总了C++中SharedBuffer类的典型用法代码示例。如果您正苦于以下问题:C++ SharedBuffer类的具体用法?C++ SharedBuffer怎么用?C++ SharedBuffer使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了SharedBuffer类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: PLATFORM
void ImageDecoder::setData(SharedBuffer& data, bool allDataReceived)
{
m_isAllDataReceived = allDataReceived;
#if PLATFORM(COCOA)
// On Mac the NSData inside the SharedBuffer can be secretly appended to without the SharedBuffer's knowledge.
// We use SharedBuffer's ability to wrap itself inside CFData to get around this, ensuring that ImageIO is
// really looking at the SharedBuffer.
CGImageSourceUpdateData(m_nativeDecoder.get(), data.createCFData().get(), allDataReceived);
#else
// Create a CGDataProvider to wrap the SharedBuffer.
data.ref();
// We use the GetBytesAtPosition callback rather than the GetBytePointer one because SharedBuffer
// does not provide a way to lock down the byte pointer and guarantee that it won't move, which
// is a requirement for using the GetBytePointer callback.
CGDataProviderDirectCallbacks providerCallbacks = { 0, 0, 0, sharedBufferGetBytesAtPosition, sharedBufferRelease };
RetainPtr<CGDataProviderRef> dataProvider = adoptCF(CGDataProviderCreateDirect(&data, data.size(), &providerCallbacks));
CGImageSourceUpdateDataProvider(m_nativeDecoder.get(), dataProvider.get(), allDataReceived);
#endif
}
示例2: size
status_t String16::replaceAll(char16_t replaceThis, char16_t withThis)
{
const size_t N = size();
const char16_t* str = string();
char16_t* edit = NULL;
for (size_t i=0; i<N; i++) {
if (str[i] == replaceThis) {
if (!edit) {
SharedBuffer* buf = SharedBuffer::bufferFromData(mString)->edit();
if (!buf) {
return NO_MEMORY;
}
edit = (char16_t*)buf->data();
mString = str = edit;
}
edit[i] = withThis;
}
}
return NO_ERROR;
}
示例3: size
status_t String16::makeLower()
{
const size_t N = size();
const char16_t* str = string();
char16_t* edit = NULL;
for (size_t i=0; i<N; i++) {
const char16_t v = str[i];
if (v >= 'A' && v <= 'Z') {
if (!edit) {
SharedBuffer* buf = SharedBuffer::bufferFromData(mString)->edit();
if (!buf) {
return NO_MEMORY;
}
edit = (char16_t*)buf->data();
mString = str = edit;
}
edit[i] = tolower((char)v);
}
}
return NO_ERROR;
}
示例4: capacity
ssize_t VectorImpl::setCapacity(size_t new_capacity)
{
// The capacity must always be greater than or equal to the size
// of this vector.
if (new_capacity <= size()) {
return capacity();
}
size_t new_allocation_size = 0;
LOG_ALWAYS_FATAL_IF(!safe_mul(&new_allocation_size, new_capacity, mItemSize));
SharedBuffer* sb = SharedBuffer::alloc(new_allocation_size);
if (sb) {
void* array = sb->data();
_do_copy(array, mStorage, size());
release_storage();
mStorage = const_cast<void*>(array);
} else {
return NO_MEMORY;
}
return new_capacity;
}
示例5: freeBuffer
ENS_API_EXPORT OMX_ERRORTYPE NmfHostMpc_ProcessingComponent::freeBuffer(OMX_U32 nPortIndex,
OMX_U32 nBufferIndex,
OMX_BOOL bBufferAllocated,
void *bufferAllocInfo,
void *portPrivateInfo)
{
OMX_ERRORTYPE error;
SharedBuffer *sharedBuf = static_cast<SharedBuffer *>(portPrivateInfo);
if (bBufferAllocated) {
error = doBufferDeAllocation(nPortIndex, nBufferIndex, bufferAllocInfo);
if(error != OMX_ErrorNone) return error;
} else if (useBufferNeedsMemcpy()){
error = doBufferDeAllocation(nPortIndex, nBufferIndex, (void*)sharedBuf->getBufferAllocInfo());
if(error != OMX_ErrorNone) return error;
}
delete sharedBuf;
return OMX_ErrorNone;
}
示例6: allocFromUTF32
static char* allocFromUTF32(const char32_t* in, size_t len)
{
if (len == 0) {
return getEmptyString();
}
const ssize_t bytes = utf32_to_utf8_length(in, len);
if (bytes < 0) {
return getEmptyString();
}
SharedBuffer* buf = SharedBuffer::alloc(bytes+1);
if (!buf) {
return getEmptyString();
}
char* str = (char*) buf->data();
utf32_to_utf8(in, len, str);
return str;
}
示例7: generateMHTMLPart
void MHTMLArchive::generateMHTMLPart(
const String& boundary,
EncodingPolicy encodingPolicy,
const SerializedResource& resource,
SharedBuffer& outputBuffer)
{
StringBuilder stringBuilder;
stringBuilder.append("--" + boundary + "\r\n");
stringBuilder.appendLiteral("Content-Type: ");
stringBuilder.append(resource.mimeType);
const char* contentEncoding = 0;
if (encodingPolicy == UseBinaryEncoding)
contentEncoding = binary;
else if (MIMETypeRegistry::isSupportedJavaScriptMIMEType(resource.mimeType) || MIMETypeRegistry::isSupportedNonImageMIMEType(resource.mimeType))
contentEncoding = quotedPrintable;
else
contentEncoding = base64;
stringBuilder.appendLiteral("\r\nContent-Transfer-Encoding: ");
stringBuilder.append(contentEncoding);
stringBuilder.appendLiteral("\r\nContent-Location: ");
stringBuilder.append(resource.url);
stringBuilder.appendLiteral("\r\n\r\n");
CString asciiString = stringBuilder.toString().utf8();
outputBuffer.append(asciiString.data(), asciiString.length());
if (!strcmp(contentEncoding, binary)) {
const char* data;
size_t position = 0;
while (size_t length = resource.data->getSomeData(data, position)) {
outputBuffer.append(data, length);
position += length;
}
} else {
// FIXME: ideally we would encode the content as a stream without having to fetch it all.
const char* data = resource.data->data();
size_t dataLength = resource.data->size();
Vector<char> encodedData;
if (!strcmp(contentEncoding, quotedPrintable)) {
quotedPrintableEncode(data, dataLength, encodedData);
outputBuffer.append(encodedData.data(), encodedData.size());
outputBuffer.append("\r\n", 2);
} else {
ASSERT(!strcmp(contentEncoding, base64));
// We are not specifying insertLFs = true below as it would cut the lines with LFs and MHTML requires CRLFs.
base64Encode(data, dataLength, encodedData);
const size_t maximumLineLength = 76;
size_t index = 0;
size_t encodedDataLength = encodedData.size();
do {
size_t lineLength = std::min(encodedDataLength - index, maximumLineLength);
outputBuffer.append(encodedData.data() + index, lineLength);
outputBuffer.append("\r\n", 2);
index += maximumLineLength;
} while (index < encodedDataLength);
}
}
}
示例8: doBufferAllocation
ENS_API_EXPORT OMX_ERRORTYPE NmfMpc_ProcessingComponent::useBuffer(
OMX_U32 nPortIndex,
OMX_U32 nBufferIndex,
OMX_BUFFERHEADERTYPE* pBufferHdr,
void **portPrivateInfo)
{
OMX_ERRORTYPE error;
void *bufferAllocInfo = 0;
OMX_U8 *pBuffer;
if (nPortIndex>=mENSComponent.getPortCount() || mENSComponent.getPort(nPortIndex)==0) {
return OMX_ErrorBadPortIndex;
}
if (useBufferNeedsMemcpy()) {
error = doBufferAllocation(nPortIndex, nBufferIndex, pBufferHdr->nAllocLen, &pBuffer, &bufferAllocInfo);
if (error != OMX_ErrorNone) return error;
} else {
ENS_Port *port = mENSComponent.getPort(nPortIndex);
bufferAllocInfo = port->getSharedChunk();
pBuffer = pBufferHdr->pBuffer;
OMX_ERRORTYPE error = ((MMHwBuffer *)bufferAllocInfo)->AddBufferInfo(nBufferIndex, (OMX_U32)pBufferHdr->pBuffer, pBufferHdr->nAllocLen);
if (error != OMX_ErrorNone)
return error;
}
OMX_U32 bufPhysicalAddr = getBufferPhysicalAddress(bufferAllocInfo, pBuffer, pBufferHdr->nAllocLen);
OMX_U32 bufMpcAddress = getBufferMpcAddress(bufferAllocInfo);
SharedBuffer *sharedBuf = new SharedBuffer(mENSComponent.getNMFDomainHandle(),
pBufferHdr->nAllocLen, pBuffer, bufPhysicalAddr, bufMpcAddress, bufferAllocInfo, error);
if (sharedBuf == 0) return OMX_ErrorInsufficientResources;
if (error != OMX_ErrorNone) return error;
sharedBuf->setOMXHeader(pBufferHdr);
*portPrivateInfo = sharedBuf;
return OMX_ErrorNone;
}
示例9: allocFromUTF32
static char* allocFromUTF32(const char32_t* in, size_t len)
{
if (len == 0) {
return getEmptyString();
}
const ssize_t resultStrLen = utf32_to_utf8_length(in, len) + 1;
if (resultStrLen < 1) {
return getEmptyString();
}
SharedBuffer* buf = SharedBuffer::alloc(resultStrLen);
ALOG_ASSERT(buf, "Unable to allocate shared buffer");
if (!buf) {
return getEmptyString();
}
char* resultStr = (char*) buf->data();
utf32_to_utf8(in, len, resultStr, resultStrLen);
return resultStr;
}
示例10: setData
void DeferredImageDecoder::setData(SharedBuffer& data, bool allDataReceived)
{
if (m_actualDecoder) {
m_data = RefPtr<SharedBuffer>(data);
m_lastDataSize = data.size();
m_allDataReceived = allDataReceived;
m_actualDecoder->setData(&data, allDataReceived);
prepareLazyDecodedFrames();
}
if (m_frameGenerator)
m_frameGenerator->setData(&data, allDataReceived);
}
示例11: copyFromSharedBuffer
static unsigned copyFromSharedBuffer(char* buffer, unsigned bufferLength, const SharedBuffer& sharedBuffer, unsigned offset)
{
unsigned bytesExtracted = 0;
const char* moreData;
while (unsigned moreDataLength = sharedBuffer.getSomeData(moreData, offset)) {
unsigned bytesToCopy = std::min(bufferLength - bytesExtracted, moreDataLength);
memcpy(buffer + bytesExtracted, moreData, bytesToCopy);
bytesExtracted += bytesToCopy;
if (bytesExtracted == bufferLength)
break;
offset += bytesToCopy;
}
return bytesExtracted;
}
示例12: LOG_ALWAYS_FATAL_IF
SharedBuffer* SharedBuffer::editResize(size_t newSize) const
{
if (onlyOwner()) {
SharedBuffer* buf = const_cast<SharedBuffer*>(this);
if (buf->mSize == newSize) return buf;
// Don't overflow if the combined size of the new buffer / header is larger than
// size_max.
LOG_ALWAYS_FATAL_IF((newSize >= (SIZE_MAX - sizeof(SharedBuffer))),
"Invalid buffer size %zu", newSize);
buf = (SharedBuffer*)realloc(buf, sizeof(SharedBuffer) + newSize);
if (buf != NULL) {
buf->mSize = newSize;
return buf;
}
}
SharedBuffer* sb = alloc(newSize);
if (sb) {
const size_t mySize = mSize;
memcpy(sb->data(), data(), newSize < mySize ? newSize : mySize);
release();
}
return sb;
}
示例13:
FontCustomPlatformData::FontCustomPlatformData(FT_Face freeTypeFace, SharedBuffer& buffer)
: m_freeTypeFace(freeTypeFace)
, m_fontFace(cairo_ft_font_face_create_for_ft_face(freeTypeFace, 0))
{
// FIXME Should we be setting some hinting options here?
buffer.ref(); // This is balanced by the buffer->deref() in releaseCustomFontData.
static cairo_user_data_key_t bufferKey;
cairo_font_face_set_user_data(m_fontFace, &bufferKey, &buffer,
static_cast<cairo_destroy_func_t>(releaseCustomFontData));
// Cairo doesn't do FreeType reference counting, so we need to ensure that when
// this cairo_font_face_t is destroyed, it cleans up the FreeType face as well.
static cairo_user_data_key_t freeTypeFaceKey;
cairo_font_face_set_user_data(m_fontFace, &freeTypeFaceKey, freeTypeFace,
reinterpret_cast<cairo_destroy_func_t>(FT_Done_Face));
}
示例14: decode
bool decode(const SharedBuffer& data, bool sizeOnly)
{
m_decodingSizeOnly = sizeOnly;
// We need to do the setjmp here. Otherwise bad things will happen.
if (setjmp(JMPBUF(m_png)))
return m_decoder->setFailed();
const char* segment;
while (unsigned segmentLength = data.getSomeData(segment, m_readOffset)) {
m_readOffset += segmentLength;
m_currentBufferSize = m_readOffset;
png_process_data(m_png, m_info, reinterpret_cast<png_bytep>(const_cast<char*>(segment)), segmentLength);
if (sizeOnly ? m_decoder->isDecodedSizeAvailable() : m_decoder->frameIsCompleteAtIndex(0))
return true;
}
return false;
}
示例15: compressZlib
void compressZlib(SharedBuffer<u8> data, std::ostream &os)
{
z_stream z;
const s32 bufsize = 16384;
char output_buffer[bufsize];
int status = 0;
int ret;
z.zalloc = Z_NULL;
z.zfree = Z_NULL;
z.opaque = Z_NULL;
ret = deflateInit(&z, -1);
if(ret != Z_OK)
throw SerializationError("compressZlib: deflateInit failed");
// Point zlib to our input buffer
z.next_in = (Bytef*)&data[0];
z.avail_in = data.getSize();
// And get all output
for(;;)
{
z.next_out = (Bytef*)output_buffer;
z.avail_out = bufsize;
status = deflate(&z, Z_FINISH);
if(status == Z_NEED_DICT || status == Z_DATA_ERROR
|| status == Z_MEM_ERROR)
{
zerr(status);
throw SerializationError("compressZlib: deflate failed");
}
int count = bufsize - z.avail_out;
if(count)
os.write(output_buffer, count);
// This determines zlib has given all output
if(status == Z_STREAM_END)
break;
}
deflateEnd(&z);
}