Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(140)

Unified Diff: src/ports/SkFontHost_fontconfig.cpp

Issue 15298009: Change SkStream. (Closed) Base URL: http://skia.googlecode.com/svn/trunk/
Patch Set: Clean up, address comments. Created 7 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « src/core/SkStream.cpp ('k') | src/ports/SkOSFile_none.cpp » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: src/ports/SkFontHost_fontconfig.cpp
===================================================================
--- src/ports/SkFontHost_fontconfig.cpp (revision 9222)
+++ src/ports/SkFontHost_fontconfig.cpp (working copy)
@@ -136,16 +136,30 @@
SkStream* FontConfigTypeface::onOpenStream(int* ttcIndex) const {
SkStream* stream = this->getLocalStream();
if (stream) {
- // TODO: fix issue 1176.
- // As of now open_stream will return a stream and unwind it, but the
- // SkStream is not thread safe, and if two threads use the stream they
- // may collide and print preview for example could still fail,
- // or there could be some failures in rendering if this stream is used
- // there.
+ // should have been provided by CreateFromStream()
+ *ttcIndex = 0;
+
+ SkAutoTUnref<SkStream> dupStream(stream->duplicate());
+ if (dupStream) {
+ return dupStream.detach();
+ }
+
+ // TODO: update interface use, remove the following code in this block.
+ size_t length = stream->getLength();
+
+ const void* memory = stream->getMemoryBase();
+ if (NULL != memory) {
+ return new SkMemoryStream(memory, length);
+ }
+
+ SkAutoTMalloc<uint8_t> allocMemory(length);
stream->rewind();
+ if (length == stream->read(allocMemory.get(), length)) {
+ return new SkMemoryStream(allocMemory.detach(), length);
+ }
+
+ stream->rewind();
stream->ref();
- // should have been provided by CreateFromStream()
- *ttcIndex = 0;
} else {
SkAutoTUnref<SkFontConfigInterface> fci(RefFCI());
if (NULL == fci.get()) {
« no previous file with comments | « src/core/SkStream.cpp ('k') | src/ports/SkOSFile_none.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698