webkit引擎源码
CanvasRenderingContext2D* HTMLCanvasElement::createContext2d(const String& type)
{
ASSERT_UNUSED(HTMLCanvasElement::is2dType(type), type);
ASSERT(!m_context);
bool usesDashboardCompatibilityMode = false;
#if ENABLE(DASHBOARD_SUPPORT)
usesDashboardCompatibilityMode = document().settings().usesDashboardBackwardCompatibilityMode();
#endif
// Make sure we don't use more pixel memory than the system can support.
size_t requestedPixelMemory = 4 * width() * height();//计算占用内存
if (activePixelMemory + requestedPixelMemory > maxActivePixelMemory()) {
StringBuilder stringBuilder;
stringBuilder.appendLiteral("Total canvas memory use exceeds the maximum limit (");
stringBuilder.appendNumber(maxActivePixelMemory() / 1024 / 1024);
stringBuilder.appendLiteral(" MB).");
document().addConsoleMessage(MessageSource::JS, MessageLevel::Warning, stringBuilder.toString());
return nullptr;
}
m_context = CanvasRenderingContext2D::create(*this, document().inQuirksMode(), usesDashboardCompatibilityMode);
downcast<CanvasRenderingContext2D>(*m_context).setUsesDisplayListDrawing(m_usesDisplayListDrawing);
downcast<CanvasRenderingContext2D>(*m_context).setTracksDisplayListReplay(m_tracksDisplayListReplay);
#if USE(IOSURFACE_CANVAS_BACKING_STORE) || ENABLE(ACCELERATED_2D_CANVAS)
// Need to make sure a RenderLayer and compositing layer get created for the Canvas.
invalidateStyleAndLayerComposition();
#endif
return static_cast<CanvasRenderingContext2D*>(m_context.get());
}
100 * 100 canvas 占的内存是 100 * 100 * 4 bytes = 40,000 bytes
https://github.com/WebKit/webkit/blob/master/Source/WebCore/html/HTMLCanvasElement.cpp#L365
100*100的 canvas 占多少内存
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。
推荐阅读更多精彩内容
- 直接看代码吧. 我们不考虑 MonthEnum 和 MonthConst 他们对于 dex 大小的影响,这个没什么...
- 虽然自己画的不咋样,但还是有小伙伴会问怎么才能学会画画,我这半桶水都没有人的也晃不起来,所以今天分享一个不需要画画...