android webkit 图片解码

本文解析了WebCore中图像缓存的具体实现流程,包括BitmapImage如何利用ImageSource进行图像解码与缓存,以及缓存如何在绘制过程中被复用。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

 从之前的文章中我们知道,image是一种派生资源,它下载之后会有memory cache机制进行缓存,而image对应的缓存类为CacheImage。CacheImage有一个成员SharedBuffer存储的是图片元数据,也就是没解码前的数据(由loader传递而来)。还有一个Image对象(实际是个BitmapImage),该对象在GraphicsContext绘制时使用。看如下堆栈:

#4  WebCore::BitmapImage::frameDurationAtIndex (this=0x4daf1a78, index=0) at common/external/webkit/Source/WebCore/platform/graphics/BitmapImage.cpp:264
#5  WebCore::BitmapImage::startAnimation 
#6  WebCore::BitmapImage::startAnimation 
#7  WebCore::BitmapImage::draw       ImageAndroid.cpp:180
#8  WebCore::Image::drawTiled 
#9  WebCore::GraphicsContext::drawTiledImage 

  BitmapImage在绘制时会去找,这个图片是不是已在m_frames对象中被缓存,如果被缓存则直接使用,如果没有则创建缓存。那么缓存是怎么创建的呢?

 #1  0x5ae11e2a in WebCore::ImageSource::createFrameAtIndex   ImageSourceAndroid.cpp:389
#2  0x5ae01912 in WebCore::BitmapImage::cacheFrame 

  可见在ImageSource中被创建,注意android的实现在ImageSourceAndroid.cpp中。可见解码后的数据应该存在ImageSource中。实际上ImageSource有一个NativeImageSourcePtr对象,该对象中又有一个PrivateAndroidImageSoureRec对象存储着解码后的SkBitmap。其中解码过程如下:

#0  WebCore::ImageSource::setData   ImageSourceAndroid.cpp:243
#1  WebCore::BitmapImage::dataChanged 
#2  WebCore::Image::setData
#3  WebCore::CachedImage::data 
#4  WebCore::CachedImage::data 
#5  WebCore::CachedResourceRequest::didFinishLoading 

  这个setData的过程就是将前述的SharedBuffer元数据传递的过程,最终在ImageSource::setData(android实现在ImageSourceAndroid.cpp中)中调用Skia库相应的解码类来进行解码。

  这个过程有一点乱,我们以一个类图来梳理一下:

转自:

http://blog.youkuaiyun.com/qq295445028/article/details/20131325#comments



评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值