ImageDirView() { SkImageRef_GlobalPool::SetRAMBudget(320 * 1024); #ifdef SPECIFIC_IMAGE fBitmaps = new SkBitmap[3]; fStrings = new SkString[3]; fBitmapCount = 3; const SkBitmap::Config configs[] = { SkBitmap::kARGB_8888_Config, SkBitmap::kRGB_565_Config, SkBitmap::kARGB_4444_Config }; for (int i = 0; i < fBitmapCount; i++) { #if 1 SkStream* stream = new SkFILEStream(SPECIFIC_IMAGE); SetImageRef(&fBitmaps[i], stream, configs[i], SPECIFIC_IMAGE); stream->unref(); #else SkImageDecoder::DecodeFile(SPECIFIC_IMAGE, &fBitmaps[i]); #endif } #else int i, N = 0; SkOSFile::Iter iter(IMAGE_DIR, IMAGE_SUFFIX); SkString name; while (iter.next(&name)) { N += 1; } fBitmaps = new SkBitmap[N]; fStrings = new SkString[N]; iter.reset(IMAGE_DIR, IMAGE_SUFFIX); for (i = 0; i < N; i++) { iter.next(&name); SkString path(IMAGE_DIR); path.append(name); SkStream* stream = new SkFILEStream(path.c_str()); SetImageRef(&fBitmaps[i], stream, SkBitmap::kNo_Config, name.c_str()); stream->unref(); fStrings[i] = name; } fBitmapCount = N; #endif fCurrIndex = 0; fDX = fDY = 0; fSaturation = SK_Scalar1; fAngle = 0; fScale = SK_Scalar1; }
void SkFontHost::Serialize(const SkTypeface* face, SkWStream* stream) { SkFontDescriptor descriptor; { SkAutoMutexAcquire ac(gFamilyHeadAndNameListMutex); descriptor.setFamilyName(find_family_name(face)); descriptor.setStyle(face->style()); descriptor.setFontFileName(((FamilyTypeface*)face)->getUniqueString()); } descriptor.serialize(stream); const bool isCustomFont = !((FamilyTypeface*)face)->isSysFont(); if (isCustomFont) { // store the entire font in the fontData SkStream* fontStream = ((FamilyTypeface*)face)->openStream(); const uint32_t length = fontStream->getLength(); stream->writePackedUInt(length); stream->writeStream(fontStream, length); fontStream->unref(); } else { stream->writePackedUInt(0); } }
ECode Movie::NativeDecodeStream( /* [in] */ IInputStream* istream, /* [out] */IMovie** movie) { VALIDATE_NOT_NULL(movie); // NPE_CHECK_RETURN_ZERO(env, istream); if (istream == NULL) { *movie = NULL; return NOERROR; } AutoPtr<ArrayOf<Byte> > byteArray = ArrayOf<Byte>::Alloc(16*1024); // ScopedLocalRef<jbyteArray> scoper(env, byteArray); SkStream* strm = CreateInputStreamAdaptor(istream, byteArray); if (NULL == strm) { *movie = NULL; return NOERROR; } // Need to buffer enough input to be able to rewind as much as might be read by a decoder // trying to determine the stream's format. The only decoder for movies is GIF, which // will only read 6. // FIXME: Get this number from SkImageDecoder SkAutoTUnref<SkStreamRewindable> bufferedStream(SkFrontBufferedStream::Create(strm, 6)); SkASSERT(bufferedStream.get() != NULL); SkMovie* moov = SkMovie::DecodeStream(bufferedStream); strm->unref(); return CreateMovie(moov, movie); }
Boolean FontFamily::NativeAddFontFromAsset( /* [in] */ Int64 familyPtr, /* [in] */ IAssetManager* assetMgr, /* [in] */ const String& path) { if (assetMgr == NULL || path.IsNull()) { return FALSE; } android::AssetManager* mgr = (android::AssetManager*)((CAssetManager*)assetMgr)->Ni(); if (NULL == mgr) { return FALSE; } android::Asset* asset = mgr->open(path.string(), android::Asset::ACCESS_BUFFER); if (NULL == asset) { return FALSE; } SkStream* stream = new AssetStreamAdaptor(asset, AssetStreamAdaptor::kYes_OwnAsset, AssetStreamAdaptor::kYes_HasMemoryBase); SkTypeface* face = SkTypeface::CreateFromStream(stream); // Note: SkTypeface::CreateFromStream holds its own reference to the stream stream->unref(); if (face == NULL) { Logger::E(String("FontFamily"), String("addFontFromAsset failed to create font %s"), path.string()); return FALSE; } android::FontFamily* fontFamily = reinterpret_cast<android::FontFamily*>(familyPtr); return addSkTypeface(fontFamily, face); }
static SkTypeface* Typeface_createFromAsset(JNIEnv* env, jobject, jobject jassetMgr, jstring jpath) { NPE_CHECK_RETURN_ZERO(env, jassetMgr); NPE_CHECK_RETURN_ZERO(env, jpath); AssetManager* mgr = assetManagerForJavaObject(env, jassetMgr); if (NULL == mgr) { return NULL; } AutoJavaStringToUTF8 str(env, jpath); Asset* asset = mgr->open(str.c_str(), Asset::ACCESS_BUFFER); if (NULL == asset) { return NULL; } SkStream* stream = new AssetStreamAdaptor(asset, AssetStreamAdaptor::kYes_OwnAsset, AssetStreamAdaptor::kYes_HasMemoryBase); SkTypeface* face = SkTypeface::CreateFromStream(stream); // SkTypeFace::CreateFromStream calls ref() on the stream, so we // need to unref it here or it won't be freed later on stream->unref(); return face; }
// CAPPFIX_WEB_WOFF FontCustomPlatformData* createFontCustomPlatformData(SharedBuffer* buffer, bool woffEnabled) { RefPtr<SharedBuffer> sfntBuffer; if (woffEnabled && isWOFF(buffer)) { Vector<char> sfnt; if (!convertWOFFToSfnt(buffer, sfnt)) return 0; sfntBuffer = SharedBuffer::adoptVector(sfnt); buffer = sfntBuffer.get(); } // pass true until we know how we can share the data, and not have to // make a copy of it. SkStream* stream = new SkMemoryStream(buffer->data(), buffer->size(), true); SkTypeface* face = SkTypeface::CreateFromStream(stream); // Release the stream. stream->unref(); if (0 == face) { SkDebugf("--------- SkTypeface::CreateFromBuffer failed %d\n", buffer->size()); return NULL; } SkAutoUnref aur(face); return new FontCustomPlatformData(face); }
SkTypeface* SkFontHost::CreateTypefaceFromFile(const char path[]) { SkStream* stream = SkNEW_ARGS(SkMMAPStream, (path)); SkTypeface* face = SkFontHost::CreateTypefaceFromStream(stream); // since we created the stream, we let go of our ref() here stream->unref(); return face; }
SkStream* SkFontHost::OpenStream(uint32_t fontID) { FamilyTypeface* tf = (FamilyTypeface*)find_from_uniqueID(fontID); SkStream* stream = tf ? tf->openStream() : NULL; if (stream && stream->getLength() == 0) { stream->unref(); stream = NULL; } return stream; }
SkStream* SkFontHost::OpenStream(uint32_t fontID) { SkAutoMutexAcquire ac(gFamilyHeadAndNameListMutex); FamilyTypeface* tf = (FamilyTypeface*)find_from_uniqueID(fontID); SkStream* stream = tf ? tf->openStream() : NULL; if (stream && stream->getLength() == 0) { stream->unref(); stream = NULL; } return stream; }
static jobject nativeDecodeStreamScaled(JNIEnv* env, jobject clazz, jobject is, jbyteArray storage, jobject padding, jobject options, jboolean applyScale, jfloat scale) { jobject bitmap = NULL; SkStream* stream = CreateJavaInputStreamAdaptor(env, is, storage, 0); if (stream) { // for now we don't allow purgeable with java inputstreams bitmap = doDecode(env, stream, padding, options, false, false, applyScale, scale); stream->unref(); } return bitmap; }
static jobject movie_decodeStream(JNIEnv* env, jobject clazz, jobject istream) { NPE_CHECK_RETURN_ZERO(env, istream); // what is the lifetime of the array? Can the skstream hold onto it? jbyteArray byteArray = env->NewByteArray(16*1024); SkStream* strm = CreateJavaInputStreamAdaptor(env, istream, byteArray); if (NULL == strm) { return 0; } SkMovie* moov = SkMovie::DecodeStream(strm); strm->unref(); return create_jmovie(env, moov); }
static jobject nativeNewInstanceFromStream(JNIEnv* env, jobject clazz, jobject is, // InputStream jbyteArray storage, // byte[] jboolean isShareable) { jobject largeBitmap = NULL; SkStream* stream = CreateJavaInputStreamAdaptor(env, is, storage, 1024); if (stream) { // for now we don't allow shareable with java inputstreams SkMemoryStream *mStream = buildSkMemoryStream(stream); largeBitmap = doBuildTileIndex(env, mStream); stream->unref(); } return largeBitmap; }
static jobject nativeDecodeStream(JNIEnv* env, jobject clazz, jobject is, // InputStream jbyteArray storage, // byte[] jobject padding, jobject options) { // BitmapFactory$Options jobject bitmap = NULL; SkStream* stream = CreateJavaInputStreamAdaptor(env, is, storage, 0); if (stream) { // for now we don't allow purgeable with java inputstreams bitmap = doDecode(env, stream, padding, options, false); stream->unref(); } return bitmap; }
FontCustomPlatformData* createFontCustomPlatformData(SharedBuffer* buffer) { // pass true until we know how we can share the data, and not have to // make a copy of it. SkStream* stream = new SkMemoryStream(buffer->data(), buffer->size(), true); SkTypeface* face = SkTypeface::CreateFromStream(stream); // Release the stream. stream->unref(); if (0 == face) { SkDebugf("--------- SkTypeface::CreateFromBuffer failed %d\n", buffer->size()); return NULL; } SkAutoUnref aur(face); return new FontCustomPlatformData(face); }
void SkFontHost::Serialize(const SkTypeface* face, SkWStream* stream) { SkStream* fontStream = ((FamilyTypeface*)face)->openStream(); // store the length of the custom font uint32_t len = fontStream->getLength(); stream->write32(len); // store the entire font in the serialized stream void* fontData = malloc(len); fontStream->read(fontData, len); stream->write(fontData, len); fontStream->unref(); free(fontData); // sk_throw(); }
static jobject movie_decodeStream(JNIEnv* env, jobject clazz, jobject istream) { NPE_CHECK_RETURN_ZERO(env, istream); jbyteArray byteArray = env->NewByteArray(16*1024); ScopedLocalRef<jbyteArray> scoper(env, byteArray); SkStream* strm = CreateJavaInputStreamAdaptor(env, istream, byteArray); if (NULL == strm) { return 0; } // Need to buffer enough input to be able to rewind as much as might be read by a decoder // trying to determine the stream's format. The only decoder for movies is GIF, which // will only read 6. // FIXME: Get this number from SkImageDecoder SkAutoTUnref<SkStreamRewindable> bufferedStream(SkFrontBufferedStream::Create(strm, 6)); SkASSERT(bufferedStream.get() != NULL); SkMovie* moov = SkMovie::DecodeStream(bufferedStream); strm->unref(); return create_jmovie(env, moov); }
void SkFontHost::Serialize(const SkTypeface* face, SkWStream* stream) { // lookup and record if the font is custom (i.e. not a system font) bool isCustomFont = !((FamilyTypeface*)face)->isSysFont(); stream->writeBool(isCustomFont); if (isCustomFont) { SkStream* fontStream = ((FamilyTypeface*)face)->openStream(); // store the length of the custom font uint32_t len = fontStream->getLength(); stream->write32(len); // store the entire font in the serialized stream void* fontData = malloc(len); fontStream->read(fontData, len); stream->write(fontData, len); fontStream->unref(); free(fontData); // SkDebugf("--- fonthost custom serialize %d %d\n", face->style(), len); } else { const char* name = ((FamilyTypeface*)face)->getFilePath(); // const char* name = ((FamilyTypeface*)face)->getUniqueString(); stream->write8((uint8_t)face->style()); if (NULL == name || 0 == *name) { stream->writePackedUInt(0); // SkDebugf("--- fonthost serialize null\n"); } else { uint32_t len = strlen(name); stream->writePackedUInt(len); stream->write(name, len); // SkDebugf("--- fonthost serialize <%s> %d\n", name, face->style()); } } }
~SkFaceRec() { fSkStream->unref(); }