のねのBlog

パソコンの問題や、ソフトウェアの開発で起きた問題など書いていきます。よろしくお願いします^^。

openStream

openStreamの流れ

     99 void SkTypeface::serialize(SkWStream* wstream) const {
    100     bool isLocal = false;
    101     SkFontDescriptor desc(this->style());
    102     this->onGetFontDescriptor(&desc, &isLocal);
    103 
    104     desc.serialize(wstream);
    105     if (isLocal) {
    106         int ttcIndex;   // TODO: write this to the stream?
    107         SkAutoTUnref<SkStream> rstream(this->openStream(&ttcIndex)); <=====ここ
    108         if (rstream.get()) {
    109             size_t length = rstream->getLength();
    110             wstream->writePackedUInt(length);
    111             wstream->writeStream(rstream, length);
    112         } else {
    113             wstream->writePackedUInt(0);
    114         }
    115     } else {
    116         wstream->writePackedUInt(0);
    117     }
    118 }
    165 SkStream* SkTypeface::openStream(int* ttcIndex) const {
    166     int ttcIndexStorage;
    167     if (NULL == ttcIndex) {
    168         // So our subclasses don't need to check for null param
    169         ttcIndex = &ttcIndexStorage;
    170     }
    171     return this->onOpenStream(ttcIndex); <=====ここ
    172 }
    168 SkStream* FontConfigTypeface::onOpenStream(int* ttcIndex) const {
    169     SkStream* stream = this->getLocalStream();
    170     if (stream) {
    171         // should have been provided by CreateFromStream()
    172         *ttcIndex = 0;
    173 
    174         SkAutoTUnref<SkStream> dupStream(stream->duplicate());
    175         if (dupStream) {
    176             return dupStream.detach();
    177         }
    178 
    179         // TODO: update interface use, remove the following code in this block.
    180         size_t length = stream->getLength();
    181 
    182         const void* memory = stream->getMemoryBase();
    183         if (NULL != memory) {
    184             return new SkMemoryStream(memory, length, true);
    185         }
    186 
    187         SkAutoTMalloc<uint8_t> allocMemory(length);
    188         stream->rewind();
    189         if (length == stream->read(allocMemory.get(), length)) {
    190             SkAutoTUnref<SkMemoryStream> copyStream(new SkMemoryStream());
    191             copyStream->setMemoryOwned(allocMemory.detach(), length);
    192             return copyStream.detach();
    193         }
    194 
    195         stream->rewind();
    196         stream->ref();
    197     } else {
    198         SkAutoTUnref<SkFontConfigInterface> fci(RefFCI());
    199         if (NULL == fci.get()) {
    200             return NULL;
    201         }
    202         stream = fci->openStream(this->getIdentity());<=====ここ
    203         *ttcIndex = this->getIdentity().fTTCIndex;
    204     }
    205     return stream;
    206 }
    446 SkStream* SkFontConfigInterfaceAndroid::openStream(const FontIdentity& identity) {
    447     return SkStream::NewFromFile(identity.fString.c_str());
    448 }