skia image lib

1.SkImage decoded procedure
SkImageDecoder.DecodeMemory/SkImageDecoder.DecodeFile
SkImageDecoder.DecodeStream
SkImageDecoder.decode
SkImageDecoder.onDecode
SkJPEGImageDecoder.onDecode(SkImageDecoder_libjpeg.cpp)
SkImageDecoder.return_flase(error)


2.factory mode
a.client use abs product in it's code.
client set the product to a specific one before use it.
b.client use the factory to get a specific product.
the key point is how we can get a specific product from the factory.
there are two imporant points here. first we should pass a parameter in;
second, how we can get different factory from the parameter.


3.SkImageDecoder's factory
in SkImageDecoder::DecodeStream, call
SkImageDecoder* codec = SkImageDecoder::Factory(stream);
to get a concrete ImageDecoder.
a. in SkImageDecoder_Factory.cpp
    const DecodeReg* curr = DecodeReg::Head();
    while (curr) {
        codec = curr->factory()(stream);
        // we rewind here, because we promise later when we call "decode", that
        // the stream will be at its beginning.
        stream->rewind();
        if (codec) {
            return codec;
        }
        curr = curr->next();
    }

Factory use DecodeReg class, traversal a DecodeReg list
use "codec = curr->factory()(stream);" to find the decoder that match the stream.


b.how does curr->factory()(stream) works?
1)SkTRegistry defined in SkTRegistry.h
typedef SkTRegistry<SkImageDecoder*, SkStream*> DecodeReg;
//template class with two class parameters, first is SkImageDecoder, second is SKStream.
Factory factory() const { return fFact; }
Factory      fFact;
template <typename T, typename P> class SkTRegistry :{
typedef T (*Factory)(P);...}
so curr->factory() will call a function pointer, input the SKStream and return SkImaageDecoer.
2)how is the pointer assigned?
SkTRegistry(Factory fact) {fFact = fact;...}
in the constructor function.
3)when is it called?
in every concrete factory we define the factory.
static SkTRegistry<SkImageDecoder*, SkStream*> gReg(Factory);
static SkTRegistry<SkImageDecoder*, SkStream*> gReg(Factory);
static SkTRegistry<SkImageDecoder*, SkStream*> gReg(Factory);
static SkTRegistry<SkImageDecoder*, SkStream*> gDReg(DFactory);
static SkTRegistry<SkImageEncoder*, SkImageEncoder::Type> gEReg(EFactory);
static SkTRegistry<SkImageEncoder*, SkImageEncoder::Type> gEReg(sk_libpng_efactory);
static SkTRegistry<SkImageDecoder*, SkStream*> gDReg(sk_libpng_dfactory);
static SkTRegistry<SkImageDecoder*, SkStream*> gDReg(DFactory);
static SkTRegistry<SkImageDecoder*, SkStream*> gReg(Factory);
so we will call every decoder's Factory() when traversal the list and return the factory we want.
4)how is the coder above added in called when we just call curr->factory?
in SkImageDecoder_empty.cpp
SkImageDecoder* SkImageDecoder::Factory(SkStream* stream) {
    for (size_t i = 0; i < SK_ARRAY_COUNT(gPairs); i++) {
        SkImageDecoder* codec = gPairs[i].fProc(stream);
        stream->rewind();
        if (NULL != codec) {
            return codec;
        }
    }
    return NULL;
}


add every in and call it.
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值