// Return the context associated with the next logical typeface, or NULL if // there are no more entries in the fallback chain. SkScalerContext* SkScalerContext::allocNextContext() const { #ifdef SK_BUILD_FOR_ANDROID SkTypeface* newFace = SkAndroidNextLogicalTypeface(fRec.fFontID, fRec.fOrigFontID, fPaintOptionsAndroid); if (0 == newFace) { return NULL; } SkAutoTUnref<SkTypeface> aur(newFace); uint32_t newFontID = newFace->uniqueID(); SkWriteBuffer androidBuffer; fPaintOptionsAndroid.flatten(androidBuffer); SkAutoDescriptor ad(sizeof(fRec) + androidBuffer.bytesWritten() + SkDescriptor::ComputeOverhead(2)); SkDescriptor* desc = ad.getDesc(); desc->init(); SkScalerContext::Rec* newRec = (SkScalerContext::Rec*)desc->addEntry(kRec_SkDescriptorTag, sizeof(fRec), &fRec); androidBuffer.writeToMemory(desc->addEntry(kAndroidOpts_SkDescriptorTag, androidBuffer.bytesWritten(), NULL)); newRec->fFontID = newFontID; desc->computeChecksum(); return newFace->createScalerContext(desc); #else return NULL; #endif }
SkData* SkValidatingSerializeFlattenable(SkFlattenable* flattenable) { SkWriteBuffer writer; writer.writeFlattenable(flattenable); size_t size = writer.bytesWritten(); auto data = SkData::MakeUninitialized(size); writer.writeToMemory(data->writable_data()); return data.release(); }
static sk_sp<SkColorFilter> reincarnate_colorfilter(SkFlattenable* obj) { SkWriteBuffer wb; wb.writeFlattenable(obj); size_t size = wb.bytesWritten(); SkAutoSMalloc<1024> storage(size); // make a copy into storage wb.writeToMemory(storage.get()); SkReadBuffer rb(storage.get(), size); return rb.readColorFilter(); }
bool SkGPipeCanvas::shuttleBitmap(const SkBitmap& bm, int32_t slot) { SkASSERT(shouldFlattenBitmaps(fFlags)); SkWriteBuffer buffer; buffer.setNamedFactoryRecorder(fFactorySet); buffer.writeBitmap(bm); this->flattenFactoryNames(); size_t size = buffer.bytesWritten(); if (this->needOpBytes(size)) { this->writeOp(kDef_Bitmap_DrawOp, 0, slot); void* dst = static_cast<void*>(fWriter.reserve(size)); buffer.writeToMemory(dst); return true; } return false; }
static void flatten(const SkFlattenable* flattenable, Json::Value* target, bool sendBinaries) { if (sendBinaries) { SkWriteBuffer buffer; flattenable->flatten(buffer); void* data = sk_malloc_throw(buffer.bytesWritten()); buffer.writeToMemory(data); Json::Value bytes; encode_data(data, buffer.bytesWritten(), &bytes); Json::Value jsonFlattenable; jsonFlattenable[SKJSONCANVAS_ATTRIBUTE_NAME] = Json::Value(flattenable->getTypeName()); jsonFlattenable[SKJSONCANVAS_ATTRIBUTE_BYTES] = bytes; (*target) = jsonFlattenable; free(data); } else { (*target)[SKJSONCANVAS_ATTRIBUTE_DESCRIPTION] = Json::Value(flattenable->getTypeName()); } }