本文整理汇总了C++中sk_malloc_throw函数的典型用法代码示例。如果您正苦于以下问题:C++ sk_malloc_throw函数的具体用法?C++ sk_malloc_throw怎么用?C++ sk_malloc_throw使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了sk_malloc_throw函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: write_png
static void write_png(const png_bytep rgba, png_uint_32 width, png_uint_32 height, SkWStream& out) {
png_structp png = png_create_write_struct(PNG_LIBPNG_VER_STRING, NULL, NULL, NULL);
SkASSERT(png != nullptr);
png_infop info_ptr = png_create_info_struct(png);
SkASSERT(info_ptr != nullptr);
if (setjmp(png_jmpbuf(png))) {
SkFAIL("png encode error");
}
png_set_IHDR(png, info_ptr, width, height, 8, PNG_COLOR_TYPE_RGB, PNG_INTERLACE_NONE,
PNG_COMPRESSION_TYPE_DEFAULT, PNG_FILTER_TYPE_DEFAULT);
png_set_compression_level(png, 1);
png_bytepp rows = (png_bytepp) sk_malloc_throw(height * sizeof(png_byte*));
png_bytep pixels = (png_bytep) sk_malloc_throw(width * height * 3);
for (png_size_t y = 0; y < height; ++y) {
const png_bytep src = rgba + y * width * 4;
rows[y] = pixels + y * width * 3;
// convert from RGBA to RGB
for (png_size_t x = 0; x < width; ++x) {
rows[y][x * 3] = src[x * 4];
rows[y][x * 3 + 1] = src[x * 4 + 1];
rows[y][x * 3 + 2] = src[x * 4 + 2];
}
}
png_set_filter(png, 0, PNG_NO_FILTERS);
png_set_rows(png, info_ptr, &rows[0]);
png_set_write_fn(png, &out, write_png_callback, NULL);
png_write_png(png, info_ptr, PNG_TRANSFORM_IDENTITY, NULL);
png_destroy_write_struct(&png, NULL);
sk_free(rows);
}
示例2: SkScalerContext
SkScalerContext_Ascender::SkScalerContext_Ascender(const SkDescriptor* desc)
: SkScalerContext(desc)
{
int size = aca_Get_FontHandleRec_Size();
fHandle = (aca_FontHandle)sk_malloc_throw(size);
// get the pointer to the font
fFontStream = new SkMMAPStream("/UcsGB2312-Hei-H.FDL");
fHintStream = new SkMMAPStream("/genv6-23.bin");
void* hints = sk_malloc_throw(fHintStream->getLength());
memcpy(hints, fHintStream->getMemoryBase(), fHintStream->getLength());
aca_Create_Font_Handle(fHandle,
(void*)fFontStream->getMemoryBase(), fFontStream->getLength(),
"fred",
hints, fHintStream->getLength());
// compute our factors from the record
SkMatrix m;
fRec.getSingleMatrix(&m);
// now compute our scale factors
SkScalar sx = m.getScaleX();
SkScalar sy = m.getScaleY();
int ppemX = SkScalarRound(sx);
int ppemY = SkScalarRound(sy);
size = aca_Find_Font_Memory_Required(fHandle, ppemX, ppemY);
size *= 8; // Jeff suggests this :)
fWorkspace = sk_malloc_throw(size);
aca_Set_Font_Memory(fHandle, (uint8_t*)fWorkspace, size);
aca_GlyphAttribsRec rec;
memset(&rec, 0, sizeof(rec));
rec.xSize = ppemX;
rec.ySize = ppemY;
rec.doAdjust = true;
rec.doExceptions = true;
rec.doGlyphHints = true;
rec.doInterpolate = true;
rec.grayMode = 2;
aca_Set_Font_Attributes(fHandle, &rec, &size);
fGlyphWorkspace = sk_malloc_throw(size);
aca_Set_Glyph_Memory(fHandle, fGlyphWorkspace);
}
示例3: strlen
char* SkOrderedReadBuffer::readString() {
const char* string = fReader.readString();
const int32_t length = strlen(string);
char* value = (char*)sk_malloc_throw(length + 1);
strcpy(value, string);
return value;
}
示例4: INHERITED
SkDashPathEffect::SkDashPathEffect(SkReadBuffer& buffer) : INHERITED(buffer) {
bool useOldPic = buffer.isVersionLT(SkReadBuffer::kDashWritesPhaseIntervals_Version);
if (useOldPic) {
fInitialDashIndex = buffer.readInt();
fInitialDashLength = buffer.readScalar();
fIntervalLength = buffer.readScalar();
buffer.readBool(); // Dummy for old ScalarToFit field
} else {
fPhase = buffer.readScalar();
}
fCount = buffer.getArrayCount();
size_t allocSize = sizeof(SkScalar) * fCount;
if (buffer.validateAvailable(allocSize)) {
fIntervals = (SkScalar*)sk_malloc_throw(allocSize);
buffer.readScalarArray(fIntervals, fCount);
} else {
fIntervals = NULL;
}
if (useOldPic) {
fPhase = 0;
if (fInitialDashLength != -1) { // Signal for bad dash interval
for (int i = 0; i < fInitialDashIndex; ++i) {
fPhase += fIntervals[i];
}
fPhase += fIntervals[fInitialDashIndex] - fInitialDashLength;
}
} else {
this->setInternalMembers(fPhase);
}
}
示例5: SkSafeUnref
const GrIndexBuffer* GrGpu::getQuadIndexBuffer() const {
if (NULL == fQuadIndexBuffer || fQuadIndexBuffer->wasDestroyed()) {
SkSafeUnref(fQuadIndexBuffer);
static const int SIZE = sizeof(uint16_t) * 6 * MAX_QUADS;
GrGpu* me = const_cast<GrGpu*>(this);
fQuadIndexBuffer = me->createIndexBuffer(SIZE, false);
if (fQuadIndexBuffer) {
uint16_t* indices = (uint16_t*)fQuadIndexBuffer->map();
if (indices) {
fill_indices(indices, MAX_QUADS);
fQuadIndexBuffer->unmap();
} else {
indices = (uint16_t*)sk_malloc_throw(SIZE);
fill_indices(indices, MAX_QUADS);
if (!fQuadIndexBuffer->updateData(indices, SIZE)) {
fQuadIndexBuffer->unref();
fQuadIndexBuffer = NULL;
SkFAIL("Can't get indices into buffer!");
}
sk_free(indices);
}
}
}
return fQuadIndexBuffer;
}
示例6: fCanvasTransform
SkPDFShader::State::State(const SkShader& shader,
const SkMatrix& canvasTransform, const SkIRect& bbox)
: fCanvasTransform(canvasTransform),
fBBox(bbox),
fPixelGeneration(0) {
fInfo.fColorCount = 0;
fInfo.fColors = NULL;
fInfo.fColorOffsets = NULL;
shader.getLocalMatrix(&fShaderTransform);
fImageTileModes[0] = fImageTileModes[1] = SkShader::kClamp_TileMode;
fType = shader.asAGradient(&fInfo);
if (fType == SkShader::kNone_GradientType) {
SkShader::BitmapType bitmapType;
SkMatrix matrix;
bitmapType = shader.asABitmap(&fImage, &matrix, fImageTileModes, NULL);
if (bitmapType != SkShader::kDefault_BitmapType) {
fImage.reset();
return;
}
SkASSERT(matrix.isIdentity());
fPixelGeneration = fImage.getGenerationID();
} else {
fColorData.set(sk_malloc_throw(
fInfo.fColorCount * (sizeof(SkColor) + sizeof(SkScalar))));
fInfo.fColors = reinterpret_cast<SkColor*>(fColorData.get());
fInfo.fColorOffsets =
reinterpret_cast<SkScalar*>(fInfo.fColors + fInfo.fColorCount);
shader.asAGradient(&fInfo);
}
}
示例7: FindOrAdd
int FindOrAdd(IDWriteFontFileLoader* fontFileLoader,
const void* refKey, UINT32 refKeySize) const
{
SkTScopedComPtr<IUnknown> fontFileLoaderId;
HR_GENERAL(fontFileLoader->QueryInterface(&fontFileLoaderId),
"Failed to re-convert to IDWriteFontFileLoader.",
SkFontIdentity::kInvalidDataId);
SkAutoMutexAcquire ama(fDataIdCacheMutex);
int count = fDataIdCache.count();
int i;
for (i = 0; i < count; ++i) {
const DataId& current = fDataIdCache[i];
if (fontFileLoaderId.get() == current.fLoader &&
refKeySize == current.fKeySize &&
0 == memcmp(refKey, current.fKey, refKeySize))
{
return i;
}
}
DataId& added = fDataIdCache.push_back();
added.fLoader = fontFileLoaderId.release(); // Ref is passed.
added.fKey = sk_malloc_throw(refKeySize);
memcpy(added.fKey, refKey, refKeySize);
added.fKeySize = refKeySize;
return i;
}
示例8: sizeof
void SkPDFShader::State::AllocateGradientInfoStorage() {
fColorData.set(sk_malloc_throw(
fInfo.fColorCount * (sizeof(SkColor) + sizeof(SkScalar))));
fInfo.fColors = reinterpret_cast<SkColor*>(fColorData.get());
fInfo.fColorOffsets =
reinterpret_cast<SkScalar*>(fInfo.fColors + fInfo.fColorCount);
}
示例9: INHERITED
SkGradientShaderBase::SkGradientShaderBase(SkFlattenableReadBuffer& buffer) :
INHERITED(buffer) {
fCacheAlpha = 256;
fMapper = buffer.readFlattenableT<SkUnitMapper>();
fCache16 = fCache16Storage = NULL;
fCache32 = NULL;
fCache32PixelRef = NULL;
int colorCount = fColorCount = buffer.getArrayCount();
if (colorCount > kColorStorageCount) {
size_t size = sizeof(SkColor) + sizeof(SkPMColor) + sizeof(Rec);
fOrigColors = (SkColor*)sk_malloc_throw(size * colorCount);
} else {
fOrigColors = fStorage;
}
buffer.readColorArray(fOrigColors);
fTileMode = (TileMode)buffer.readUInt();
fTileProc = gTileProcs[fTileMode];
fRecs = (Rec*)(fOrigColors + colorCount);
if (colorCount > 2) {
Rec* recs = fRecs;
recs[0].fPos = 0;
for (int i = 1; i < colorCount; i++) {
recs[i].fPos = buffer.readInt();
recs[i].fScale = buffer.readUInt();
}
}
buffer.readMatrix(&fPtsToUnit);
this->initCommon();
}
示例10: flatten
static bool SK_WARN_UNUSED_RESULT flatten(const SkImage& image, Json::Value* target,
bool sendBinaries) {
if (sendBinaries) {
SkData* encoded = image.encode(SkImageEncoder::kPNG_Type, 100);
if (encoded == nullptr) {
// PNG encode doesn't necessarily support all color formats, convert to a different
// format
size_t rowBytes = 4 * image.width();
void* buffer = sk_malloc_throw(rowBytes * image.height());
SkImageInfo dstInfo = SkImageInfo::Make(image.width(), image.height(),
kN32_SkColorType, kPremul_SkAlphaType);
if (!image.readPixels(dstInfo, buffer, rowBytes, 0, 0)) {
SkDebugf("readPixels failed\n");
return false;
}
SkImage* converted = SkImage::NewRasterCopy(dstInfo, buffer, rowBytes);
encoded = converted->encode(SkImageEncoder::kPNG_Type, 100);
if (encoded == nullptr) {
SkDebugf("image encode failed\n");
return false;
}
free(converted);
free(buffer);
}
Json::Value bytes;
encode_data(encoded->data(), encoded->size(), &bytes);
(*target)[SKJSONCANVAS_ATTRIBUTE_BYTES] = bytes;
encoded->unref();
}
else {
SkString description = SkStringPrintf("%dx%d pixel image", image.width(), image.height());
(*target)[SKJSONCANVAS_ATTRIBUTE_DESCRIPTION] = Json::Value(description.c_str());
}
return true;
}
示例11: INHERITED
SkARGB32_Shader_Blitter::SkARGB32_Shader_Blitter(const SkBitmap& device,
const SkPaint& paint)
: INHERITED(device, paint) {
fBuffer = (SkPMColor*)sk_malloc_throw(device.width() * (sizeof(SkPMColor)));
(fXfermode = paint.getXfermode())->safeRef();
}
示例12: sizeof
const GrIndexBuffer* GrGpu::getQuadIndexBuffer() const {
if (NULL == fQuadIndexBuffer) {
static const int SIZE = sizeof(uint16_t) * 6 * MAX_QUADS;
GrGpu* me = const_cast<GrGpu*>(this);
fQuadIndexBuffer = me->createIndexBuffer(SIZE, false);
if (NULL != fQuadIndexBuffer) {
uint16_t* indices = (uint16_t*)fQuadIndexBuffer->lock();
if (NULL != indices) {
fill_indices(indices, MAX_QUADS);
fQuadIndexBuffer->unlock();
} else {
indices = (uint16_t*)sk_malloc_throw(SIZE);
fill_indices(indices, MAX_QUADS);
if (!fQuadIndexBuffer->updateData(indices, SIZE)) {
fQuadIndexBuffer->unref();
fQuadIndexBuffer = NULL;
GrCrash("Can't get indices into buffer!");
}
sk_free(indices);
}
}
}
return fQuadIndexBuffer;
}
示例13: sizeof
sk_sp<SkDataTable> SkDataTable::MakeCopyArrays(const void * const * ptrs,
const size_t sizes[], int count) {
if (count <= 0) {
return SkDataTable::MakeEmpty();
}
size_t dataSize = 0;
for (int i = 0; i < count; ++i) {
dataSize += sizes[i];
}
size_t bufferSize = count * sizeof(Dir) + dataSize;
void* buffer = sk_malloc_throw(bufferSize);
Dir* dir = (Dir*)buffer;
char* elem = (char*)(dir + count);
for (int i = 0; i < count; ++i) {
dir[i].fPtr = elem;
dir[i].fSize = sizes[i];
memcpy(elem, ptrs[i], sizes[i]);
elem += sizes[i];
}
return sk_sp<SkDataTable>(new SkDataTable(dir, count, malloc_freeproc, buffer));
}
示例14: SkRef
SkData* SkWriter32::snapshotAsData() const {
// get a non const version of this, we are only conceptually const
SkWriter32& mutable_this = *const_cast<SkWriter32*>(this);
// we use size change detection to invalidate the cached data
if ((fSnapshot.get() != NULL) && (fSnapshot->size() != fUsed)) {
mutable_this.fSnapshot.reset(NULL);
}
if (fSnapshot.get() == NULL) {
uint8_t* buffer = NULL;
if ((fExternal != NULL) && (fData == fExternal)) {
// We need to copy to an allocated buffer before returning.
buffer = (uint8_t*)sk_malloc_throw(fUsed);
memcpy(buffer, fData, fUsed);
} else {
buffer = mutable_this.fInternal.detach();
// prepare us to do copy on write, by pretending the data buffer
// is external and size limited
mutable_this.fData = buffer;
mutable_this.fCapacity = fUsed;
mutable_this.fExternal = buffer;
}
mutable_this.fSnapshot.reset(SkData::NewFromMalloc(buffer, fUsed));
}
return SkRef(fSnapshot.get()); // Take an extra ref for the caller.
}
示例15: setup_MC_state
static void setup_MC_state(SkMCState* state, const SkMatrix& matrix, const SkRegion& clip) {
// initialize the struct
state->clipRectCount = 0;
// capture the matrix
for (int i = 0; i < 9; i++) {
state->matrix[i] = matrix.get(i);
}
/*
* capture the clip
*
* storage is allocated on the stack for the first 4 rects. This value was
* chosen somewhat arbitrarily, but does allow us to represent simple clips
* and some more common complex clips (e.g. a clipRect with a sub-rect
* clipped out of its interior) without needing to malloc any additional memory.
*/
SkSWriter32<4*sizeof(ClipRect)> clipWriter;
if (!clip.isEmpty()) {
// only returns the b/w clip so aa clips fail
SkRegion::Iterator clip_iterator(clip);
for (; !clip_iterator.done(); clip_iterator.next()) {
// this assumes the SkIRect is stored in l,t,r,b ordering which
// matches the ordering of our ClipRect struct
clipWriter.writeIRect(clip_iterator.rect());
state->clipRectCount++;
}
}
// allocate memory for the clip then and copy them to the struct
state->clipRects = (ClipRect*) sk_malloc_throw(clipWriter.bytesWritten());
clipWriter.flatten(state->clipRects);
}