本文整理汇总了C++中SharedBuffer::size方法的典型用法代码示例。如果您正苦于以下问题:C++ SharedBuffer::size方法的具体用法?C++ SharedBuffer::size怎么用?C++ SharedBuffer::size使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类SharedBuffer
的用法示例。
在下文中一共展示了SharedBuffer::size方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: substituteResourceDeliveryTimerFired
void DocumentLoader::substituteResourceDeliveryTimerFired(Timer<DocumentLoader>*)
{
if (m_pendingSubstituteResources.isEmpty())
return;
ASSERT(m_frame && m_frame->page());
if (m_frame->page()->defersLoading())
return;
SubstituteResourceMap copy;
copy.swap(m_pendingSubstituteResources);
SubstituteResourceMap::const_iterator end = copy.end();
for (SubstituteResourceMap::const_iterator it = copy.begin(); it != end; ++it) {
RefPtr<ResourceLoader> loader = it->first;
SubstituteResource* resource = it->second.get();
if (resource) {
SharedBuffer* data = resource->data();
loader->didReceiveResponse(resource->response());
loader->didReceiveData(data->data(), data->size(), data->size(), true);
loader->didFinishLoading();
} else {
// A null resource means that we should fail the load.
// FIXME: Maybe we should use another error here - something like "not in cache".
loader->didFail(loader->cannotShowURLError());
}
}
}
示例2: getBytesWithOffset
size_t getBytesWithOffset(void *info, void* buffer, size_t offset, size_t count)
{
SharedBuffer* sharedBuffer = static_cast<SharedBuffer*>(info);
size_t availBytes = count;
if (offset + count > sharedBuffer->size())
availBytes -= (offset + count) - sharedBuffer->size();
memcpy(buffer, sharedBuffer->data() + offset, availBytes);
return availBytes;
}
示例3: canHandleImage
static bool canHandleImage(const SharedBuffer& _data)
{
// We need at least 4 bytes to figure out what kind of image we're dealing with.
if (_data.size() < 4)
return false;
QByteArray data = QByteArray::fromRawData(_data.data(), _data.size());
QBuffer buffer(&data);
if (!buffer.open(QBuffer::ReadOnly))
return false;
return !QImageReader::imageFormat(&buffer).isEmpty();
}
示例4: refEncodedData
SkData* ImageFrameGenerator::refEncodedData()
{
// SkData is returned only when full image (encoded) data is received. This is important
// since DeferredImageDecoder::setData is called only once with allDataReceived set to true,
// and after that m_data->m_readBuffer.data() is not changed. See also RELEASE_ASSERT used in
// ThreadSafeDataTransport::data().
SharedBuffer* buffer = 0;
bool allDataReceived = false;
m_data->data(&buffer, &allDataReceived);
if (!allDataReceived)
return nullptr;
{
// Prevents concurrent access to m_encodedData creation.
MutexLocker lock(m_decodeMutex);
if (m_encodedData) {
m_encodedData->ref();
return m_encodedData;
}
// m_encodedData is created with initial reference count == 1. ImageFrameGenerator always holds one
// reference to m_encodedData, as it prevents write access in SkData::writable_data.
m_encodedData = SkData::NewWithProc(buffer->data(), buffer->size(), sharedSkDataReleaseCallback, m_data.get());
// While m_encodedData is referenced, prevent disposing m_data and its content.
// it is dereferenced in sharedSkDataReleaseCallback, called when m_encodedData gets dereferenced.
m_data->ref();
}
// Increase the reference, caller must decrease it. One reference is always kept by ImageFrameGenerator and released
// in destructor.
m_encodedData->ref();
return m_encodedData;
}
示例5: writeImageToDataObject
static void writeImageToDataObject(
DataObjectJava* dataObject,
Element* element,
const KURL& url)
{
// Shove image data into a DataObject for use as a file
CachedImage* cachedImage = getCachedImage(element);
if (!cachedImage || !cachedImage->image() || !cachedImage->isLoaded())
return;
SharedBuffer* imageBuffer = cachedImage->image()->data();
if (!imageBuffer || !imageBuffer->size())
return;
dataObject->fileContent = imageBuffer;
// Determine the filename for the file contents of the image. We try to
// use the alt tag if one exists, otherwise we fall back on the suggested
// filename in the http header, and finally we resort to using the filename
// in the URL.
//String title = element->getAttribute(altAttr);
//if (title.isEmpty())
// title = cachedImage->response().suggestedFilename();
//TODO: do we need it?
dataObject->fileContentFilename = cachedImage->response().suggestedFilename();
}
示例6: ensureCapacity
static void* ensureCapacity(void* data, size_t nmemb, size_t size)
{
SharedBuffer* buf;
size_t currentSize;
if (data != NULL) {
buf = SharedBuffer::bufferFromData(data);
currentSize = buf->size();
} else {
buf = NULL;
currentSize = 0;
}
size_t minSize = nmemb * size;
if (minSize > currentSize) {
unsigned int requestSize = roundUpPower2(minSize);
if (buf == NULL) {
buf = SharedBuffer::alloc(requestSize);
} else {
buf = buf->editResize(requestSize);
}
memset((unsigned char*)buf->data()+currentSize, 0, requestSize - currentSize);
}
return buf->data();
}
示例7: setData
void DeferredImageDecoder::setData(SharedBuffer& data, bool allDataReceived)
{
if (m_actualDecoder) {
const bool firstData = !m_data;
const bool moreData = data.size() > m_lastDataSize;
m_dataChanged = firstData || moreData;
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);
}
示例8: checkCacheObjectStatus
void DocLoader::checkCacheObjectStatus(CachedResource* resource)
{
// Return from the function for objects that we didn't load from the cache.
if (!resource)
return;
switch (resource->status()) {
case CachedResource::Cached:
break;
case CachedResource::NotCached:
case CachedResource::Unknown:
case CachedResource::New:
case CachedResource::Pending:
return;
}
// Notify the caller that we "loaded".
if (!m_frame || m_frame->loader()->haveToldBridgeAboutLoad(resource->url()))
return;
ResourceRequest request(resource->url());
const ResourceResponse& response = resource->response();
SharedBuffer* data = resource->data();
if (resource->sendResourceLoadCallbacks()) {
// FIXME: If the WebKit client changes or cancels the request, WebCore does not respect this and continues the load.
m_frame->loader()->loadedResourceFromMemoryCache(request, response, data ? data->size() : 0);
}
m_frame->loader()->didTellBridgeAboutLoad(resource->url());
}
示例9: read
size_t EOTStream::read(void* buffer, size_t count)
{
size_t bytesToRead = count;
if (m_inHeader) {
size_t bytesFromHeader = min(m_eotHeader.size() - m_offset, count);
memcpy(buffer, m_eotHeader.data() + m_offset, bytesFromHeader);
m_offset += bytesFromHeader;
bytesToRead -= bytesFromHeader;
if (m_offset == m_eotHeader.size()) {
m_inHeader = false;
m_offset = 0;
}
}
if (bytesToRead && !m_inHeader) {
size_t bytesFromData = min(m_fontData->size() - m_offset, bytesToRead);
memcpy(buffer, m_fontData->data() + m_offset, bytesFromData);
if (m_offset < m_overlayDst + m_overlayLength && m_offset + bytesFromData >= m_overlayDst) {
size_t dstOffset = max<int>(m_overlayDst - m_offset, 0);
size_t srcOffset = max<int>(0, m_offset - m_overlayDst);
size_t bytesToCopy = min(bytesFromData - dstOffset, m_overlayLength - srcOffset);
memcpy(reinterpret_cast<char*>(buffer) + dstOffset, m_fontData->data() + m_overlaySrc + srcOffset, bytesToCopy);
}
m_offset += bytesFromData;
bytesToRead -= bytesFromData;
}
return count - bytesToRead;
}
示例10: writeImageToDataObject
static void writeImageToDataObject(ChromiumDataObject* dataObject, Element* element,
const KURL& url)
{
// Shove image data into a DataObject for use as a file
CachedImage* cachedImage = getCachedImage(element);
if (!cachedImage || !cachedImage->image() || !cachedImage->isLoaded())
return;
SharedBuffer* imageBuffer = cachedImage->image()->data();
if (!imageBuffer || !imageBuffer->size())
return;
dataObject->fileContent = imageBuffer;
// Determine the filename for the file contents of the image. We try to
// use the alt tag if one exists, otherwise we fall back on the suggested
// filename in the http header, and finally we resort to using the filename
// in the URL.
String extension(".");
extension += MIMETypeRegistry::getPreferredExtensionForMIMEType(
cachedImage->response().mimeType());
String title = element->getAttribute(altAttr);
if (title.isEmpty()) {
title = cachedImage->response().suggestedFilename();
// FIXME: If title is empty, get the filename from the URL.
}
dataObject->fileContentFilename = title + extension;
}
示例11: writeImageToDataObject
static void writeImageToDataObject(IDataObject* dataObject, Element* element, const KURL& url)
{
// Shove image data into a DataObject for use as a file
CachedImage* cachedImage = getCachedImage(element);
if (!cachedImage || !cachedImage->image() || !cachedImage->isLoaded())
return;
SharedBuffer* imageBuffer = cachedImage->image()->data();
if (!imageBuffer || !imageBuffer->size())
return;
HGLOBAL imageFileDescriptor = createGlobalImageFileDescriptor(url.string(), element->getAttribute(altAttr), cachedImage);
if (!imageFileDescriptor)
return;
HGLOBAL imageFileContent = createGlobalImageFileContent(imageBuffer);
if (!imageFileContent) {
GlobalFree(imageFileDescriptor);
return;
}
String fileName = cachedImage->response().suggestedFilename();
HGLOBAL hDropContent = createGlobalHDropContent(url, fileName, imageBuffer);
if (!hDropContent) {
GlobalFree(hDropContent);
return;
}
writeFileToDataObject(dataObject, imageFileDescriptor, imageFileContent, hDropContent);
}
示例12: writeImageToDataObject
static void writeImageToDataObject(DataObject* dataObject, Element* element,
const KURL& url)
{
// Shove image data into a DataObject for use as a file
CachedImage* cachedImage = getCachedImage(element);
if (!cachedImage || !cachedImage->image() || !cachedImage->isLoaded())
return;
SharedBuffer* imageBuffer = cachedImage->image()->data();
if (!imageBuffer || !imageBuffer->size())
return;
dataObject->fileContent = imageBuffer;
// Determine the filename for the file contents of the image. We try to
// use the alt tag if one exists, otherwise we fall back on the suggested
// filename in the http header, and finally we resort to using the filename
// in the URL.
/*String extension = MIMETypeRegistry::getPreferredExtensionForMIMEType(
cachedImage->response().mimeType());*/
String extension = "png";
dataObject->fileExtension = extension.isEmpty() ? "" : "." + extension;
String title = element->getAttribute(altAttr);
if (title.isEmpty())
title = cachedImage->response().suggestedFilename();
//title = ClipboardBal::validateFileName(title, dataObject);
dataObject->fileContentFilename = title + dataObject->fileExtension;
}
示例13: sendDelayedReply
void SynchronousNetworkLoaderClient::sendDelayedReply(NetworkResourceLoader& loader)
{
ASSERT(m_delayedReply);
if (m_response.isNull()) {
ASSERT(!m_error.isNull());
//platformSynthesizeErrorResponse();
}
Vector<char> responseData;
SharedBuffer* buffer = loader.bufferedData();
if (buffer && buffer->size())
responseData.append(buffer->data(), buffer->size());
m_delayedReply->send(m_error, m_response, responseData);
m_delayedReply = nullptr;
}
示例14: sharedBufferGetBytesAtPosition
size_t sharedBufferGetBytesAtPosition(void* info, void* buffer, off_t position, size_t count)
{
SharedBuffer* sharedBuffer = static_cast<SharedBuffer*>(info);
size_t sourceSize = sharedBuffer->size();
if (position >= sourceSize)
return 0;
const char* source = sharedBuffer->data() + position;
size_t amount = min<size_t>(count, sourceSize - position);
memcpy(buffer, source, amount);
return amount;
}
示例15: clearEntriesByType
static void clearEntriesByType(uint32_t** entriesByType)
{
SharedBuffer* buf = SharedBuffer::bufferFromData(entriesByType);
const size_t N = buf->size() / sizeof(entriesByType[0]);
for (size_t i = 0; i < N; i++) {
uint32_t* entries = entriesByType[i];
if (entries != NULL) {
SharedBuffer::bufferFromData(entries)->release();
}
}
buf->release();
}