美文网首页
100*100的 canvas 占多少内存

100*100的 canvas 占多少内存

作者: 铲事官 | 来源:发表于2019-01-19 15:53 被阅读0次
    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 占多少内存

          本文链接:https://www.haomeiwen.com/subject/jklzdqtx.html