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 大小的影响,这个没什么...
- 虽然自己画的不咋样,但还是有小伙伴会问怎么才能学会画画,我这半桶水都没有人的也晃不起来,所以今天分享一个不需要画画...