Changeset 139142 in webkit


Ignore:
Timestamp:
Jan 8, 2013 6:21:57 PM (11 years ago)
Author:
commit-queue@webkit.org
Message:

Make WebGLRenderingContext inherit from ActiveDOMObject
https://bugs.webkit.org/show_bug.cgi?id=104733

Patch by Brandon Jones <bajones@chromium.org> on 2013-01-08
Reviewed by Adam Barth.

Source/WebCore:

When ActiveDOMObject::stop is called on the WebGLRenderingContext the
DrawingBuffer and GraphicsContext3D instances are forcibly released in
order to keep GPU memory utilization to a minimum.

Incorporated new layout test based on one just added to the WebGL
conformance suite. Also tested manually by reloading and
navigating between many WebGL apps.

Test: fast/canvas/webgl/context-release-upon-reload.html

  • bindings/v8/custom/V8HTMLCanvasElementCustom.cpp:

(WebCore::V8HTMLCanvasElement::getContextCallback):

Removed garbage collection hack added in Bug 76255.

  • html/canvas/WebGLRenderingContext.cpp:

(WebCore):
(WebCore::WebGLRenderingContext::create):

Call suspendIfNeeded per ActiveDOMObject contract.

(WebCore::WebGLRenderingContext::WebGLRenderingContext):

Call ActiveDOMObject constructor.

(WebCore::WebGLRenderingContext::~WebGLRenderingContext):

Call destroyGraphicsContext3D.

(WebCore::WebGLRenderingContext::destroyGraphicsContext3D):

Drop DrawingBuffer backing store and delete GraphicsContext3D.

(WebCore::WebGLRenderingContext::hasPendingActivity):

Always return false.

(WebCore::WebGLRenderingContext::stop):

Force lost context upon page reload or navigation.

  • html/canvas/WebGLRenderingContext.h:

(WebGLRenderingContext):

Inherit from ActiveDOMObject and override notifications.

  • platform/graphics/blackberry/DrawingBufferBlackBerry.cpp:

(WebCore):
(WebCore::DrawingBuffer::clearPlatformLayer):

Add currently no-op implementation.

  • platform/graphics/cairo/DrawingBufferCairo.cpp:

(WebCore):
(WebCore::DrawingBuffer::clearPlatformLayer):

Add currently no-op implementation.

  • platform/graphics/chromium/DrawingBufferChromium.cpp:

(WebCore::DrawingBufferPrivate::clearTextureId):

Clear texture ID from compositor's layer.

(DrawingBufferPrivate):
(WebCore::DrawingBuffer::framebuffer):

Moved around to reduce number of #ifdefs.

(WebCore):
(WebCore::DrawingBuffer::platformLayer):
(WebCore::DrawingBuffer::clearPlatformLayer):

Tell compositor to stop referencing DrawingBuffer's texture.

  • platform/graphics/clutter/DrawingBufferClutter.cpp:

(WebCore):
(WebCore::DrawingBuffer::clearPlatformLayer):

Add currently no-op implementation.

  • platform/graphics/gpu/DrawingBuffer.cpp:

(WebCore::DrawingBuffer::clear):

Call clearPlatformLayer before deleting OpenGL resources.

  • platform/graphics/gpu/DrawingBuffer.h:

(DrawingBuffer):

Add clearPlatformLayer.

  • platform/graphics/gpu/mac/DrawingBufferMac.mm:

(WebCore):
(WebCore::DrawingBuffer::clearPlatformLayer):

Add currently no-op implementation.

  • platform/graphics/gpu/qt/DrawingBufferQt.cpp:

(WebCore):
(WebCore::DrawingBuffer::clearPlatformLayer):

Add currently no-op implementation.

LayoutTests:

  • fast/canvas/webgl/context-release-upon-reload-expected.txt: Added.
  • fast/canvas/webgl/context-release-upon-reload.html: Added.
  • fast/canvas/webgl/resources/context-release-upon-reload-child.html: Added.
Location:
trunk
Files:
3 added
13 edited

Legend:

Unmodified
Added
Removed
  • trunk/LayoutTests/ChangeLog

    r139140 r139142  
     12013-01-08  Brandon Jones  <bajones@chromium.org>
     2
     3        Make WebGLRenderingContext inherit from ActiveDOMObject
     4        https://bugs.webkit.org/show_bug.cgi?id=104733
     5
     6        Reviewed by Adam Barth.
     7
     8        * fast/canvas/webgl/context-release-upon-reload-expected.txt: Added.
     9        * fast/canvas/webgl/context-release-upon-reload.html: Added.
     10        * fast/canvas/webgl/resources/context-release-upon-reload-child.html: Added.
     11
    1122013-01-08  Martin Robinson  <mrobinson@igalia.com>
    213
  • trunk/Source/WebCore/ChangeLog

    r139141 r139142  
     12013-01-08  Brandon Jones  <bajones@chromium.org>
     2
     3        Make WebGLRenderingContext inherit from ActiveDOMObject
     4        https://bugs.webkit.org/show_bug.cgi?id=104733
     5
     6        Reviewed by Adam Barth.
     7
     8        When ActiveDOMObject::stop is called on the WebGLRenderingContext the
     9        DrawingBuffer and GraphicsContext3D instances are forcibly released in
     10        order to keep GPU memory utilization to a minimum.
     11
     12        Incorporated new layout test based on one just added to the WebGL
     13        conformance suite. Also tested manually by reloading and
     14        navigating between many WebGL apps.
     15
     16        Test: fast/canvas/webgl/context-release-upon-reload.html
     17
     18        * bindings/v8/custom/V8HTMLCanvasElementCustom.cpp:
     19        (WebCore::V8HTMLCanvasElement::getContextCallback):
     20            Removed garbage collection hack added in Bug 76255.
     21        * html/canvas/WebGLRenderingContext.cpp:
     22        (WebCore):
     23        (WebCore::WebGLRenderingContext::create):
     24            Call suspendIfNeeded per ActiveDOMObject contract.
     25        (WebCore::WebGLRenderingContext::WebGLRenderingContext):
     26            Call ActiveDOMObject constructor.
     27        (WebCore::WebGLRenderingContext::~WebGLRenderingContext):
     28            Call destroyGraphicsContext3D.
     29        (WebCore::WebGLRenderingContext::destroyGraphicsContext3D):
     30            Drop DrawingBuffer backing store and delete GraphicsContext3D.
     31        (WebCore::WebGLRenderingContext::hasPendingActivity):
     32            Always return false.
     33        (WebCore::WebGLRenderingContext::stop):
     34            Force lost context upon page reload or navigation.
     35        * html/canvas/WebGLRenderingContext.h:
     36        (WebGLRenderingContext):
     37            Inherit from ActiveDOMObject and override notifications.
     38        * platform/graphics/blackberry/DrawingBufferBlackBerry.cpp:
     39        (WebCore):
     40        (WebCore::DrawingBuffer::clearPlatformLayer):
     41            Add currently no-op implementation.
     42        * platform/graphics/cairo/DrawingBufferCairo.cpp:
     43        (WebCore):
     44        (WebCore::DrawingBuffer::clearPlatformLayer):
     45            Add currently no-op implementation.
     46        * platform/graphics/chromium/DrawingBufferChromium.cpp:
     47        (WebCore::DrawingBufferPrivate::clearTextureId):
     48            Clear texture ID from compositor's layer.
     49        (DrawingBufferPrivate):
     50        (WebCore::DrawingBuffer::framebuffer):
     51            Moved around to reduce number of #ifdefs.
     52        (WebCore):
     53        (WebCore::DrawingBuffer::platformLayer):
     54        (WebCore::DrawingBuffer::clearPlatformLayer):
     55            Tell compositor to stop referencing DrawingBuffer's texture.
     56        * platform/graphics/clutter/DrawingBufferClutter.cpp:
     57        (WebCore):
     58        (WebCore::DrawingBuffer::clearPlatformLayer):
     59            Add currently no-op implementation.
     60        * platform/graphics/gpu/DrawingBuffer.cpp:
     61        (WebCore::DrawingBuffer::clear):
     62            Call clearPlatformLayer before deleting OpenGL resources.
     63        * platform/graphics/gpu/DrawingBuffer.h:
     64        (DrawingBuffer):
     65            Add clearPlatformLayer.
     66        * platform/graphics/gpu/mac/DrawingBufferMac.mm:
     67        (WebCore):
     68        (WebCore::DrawingBuffer::clearPlatformLayer):
     69            Add currently no-op implementation.
     70        * platform/graphics/gpu/qt/DrawingBufferQt.cpp:
     71        (WebCore):
     72        (WebCore::DrawingBuffer::clearPlatformLayer):
     73            Add currently no-op implementation.
     74
    1752013-01-08  Tony Gentilcore  <tonyg@chromium.org>
    276
  • trunk/Source/WebCore/bindings/v8/custom/V8HTMLCanvasElementCustom.cpp

    r138665 r139142  
    9898#if ENABLE(WEBGL)
    9999    else if (result->is3d()) {
    100         // 3D canvas contexts can hold on to lots of GPU resources, and we want to take an
    101         // opportunity to get rid of them as soon as possible when we navigate away from pages using
    102         // them.
    103         V8PerIsolateData* perIsolateData = V8PerIsolateData::from(args.GetIsolate());
    104         perIsolateData->setShouldCollectGarbageSoon();
    105 
    106100        v8::Handle<v8::Value> v8Result = toV8(static_cast<WebGLRenderingContext*>(result), args.Holder(), args.GetIsolate());
    107101        if (InspectorInstrumentation::canvasAgentEnabled(imp->document())) {
  • trunk/Source/WebCore/html/canvas/WebGLRenderingContext.cpp

    r138542 r139142  
    440440
    441441    OwnPtr<WebGLRenderingContext> renderingContext = adoptPtr(new WebGLRenderingContext(canvas, context, attributes));
     442    renderingContext->suspendIfNeeded();
    442443
    443444#if PLATFORM(CHROMIUM)
     
    454455                                             GraphicsContext3D::Attributes attributes)
    455456    : CanvasRenderingContext(passedCanvas)
     457    , ActiveDOMObject(passedCanvas->document(), this)
    456458    , m_context(context)
    457459    , m_drawingBuffer(0)
     
    616618
    617619    detachAndRemoveAllObjects();
    618     m_context->setContextLostCallback(nullptr);
    619     m_context->setErrorMessageCallback(nullptr);
     620    destroyGraphicsContext3D();
    620621    m_contextGroup->removeContext(this);
     622}
     623
     624void WebGLRenderingContext::destroyGraphicsContext3D()
     625{
     626    // The drawing buffer holds a context reference. It must also be destroyed
     627    // in order for the context to be released.
     628    if (m_drawingBuffer)
     629        m_drawingBuffer.clear();
     630
     631    if (m_context) {
     632        m_context->setContextLostCallback(nullptr);
     633        m_context->setErrorMessageCallback(nullptr);
     634        m_context.clear();
     635    }
    621636}
    622637
     
    45854600}
    45864601
     4602bool WebGLRenderingContext::hasPendingActivity() const
     4603{
     4604    return false;
     4605}
     4606
     4607void WebGLRenderingContext::stop()
     4608{
     4609    if (!isContextLost()) {
     4610        forceLostContext(SyntheticLostContext);
     4611        destroyGraphicsContext3D();
     4612    }
     4613}
     4614
    45874615WebGLGetInfo WebGLRenderingContext::getBooleanParameter(GC3Denum pname)
    45884616{
  • trunk/Source/WebCore/html/canvas/WebGLRenderingContext.h

    r137397 r139142  
    2727#define WebGLRenderingContext_h
    2828
     29#include "ActiveDOMObject.h"
    2930#include "CanvasRenderingContext.h"
    3031#include "DrawingBuffer.h"
     
    7677typedef int ExceptionCode;
    7778
    78 class WebGLRenderingContext : public CanvasRenderingContext {
     79class WebGLRenderingContext : public CanvasRenderingContext, public ActiveDOMObject {
    7980public:
    8081    static PassOwnPtr<WebGLRenderingContext> create(HTMLCanvasElement*, WebGLContextAttributes*);
     
    318319    unsigned getMaxVertexAttribs() const { return m_maxVertexAttribs; }
    319320
     321    // ActiveDOMObject notifications
     322    virtual bool hasPendingActivity() const;
     323    virtual void stop();
     324
    320325  private:
    321326    friend class WebGLFramebuffer;
     
    335340    void detachAndRemoveAllObjects();
    336341
     342    void destroyGraphicsContext3D();
    337343    void markContextChanged();
    338344    void cleanupAfterGraphicsCall(bool changed)
  • trunk/Source/WebCore/platform/graphics/blackberry/DrawingBufferBlackBerry.cpp

    r113493 r139142  
    123123    return colorBuffer();
    124124}
     125
     126void DrawingBuffer::clearPlatformLayer()
     127{
     128}
    125129#endif
    126130
  • trunk/Source/WebCore/platform/graphics/cairo/DrawingBufferCairo.cpp

    r122175 r139142  
    102102{
    103103}
     104
     105void DrawingBuffer::clearPlatformLayer()
     106{
     107}
    104108#endif
    105109
  • trunk/Source/WebCore/platform/graphics/chromium/DrawingBufferChromium.cpp

    r128785 r139142  
    204204    }
    205205
     206    void clearTextureId()
     207    {
     208        m_layer->setTextureId(0);
     209    }
     210
    206211    WebKit::WebLayer* layer() { return m_layer->layer(); }
    207212
     
    211216};
    212217
     218Platform3DObject DrawingBuffer::framebuffer() const
     219{
     220    return m_fbo;
     221}
     222
    213223#if USE(ACCELERATED_COMPOSITING)
    214224PlatformLayer* DrawingBuffer::platformLayer()
     
    219229    return m_private->layer();
    220230}
    221 #endif
    222 
    223 Platform3DObject DrawingBuffer::framebuffer() const
    224 {
    225     return m_fbo;
    226 }
    227 
    228 #if USE(ACCELERATED_COMPOSITING)
     231
    229232void DrawingBuffer::paintCompositedResultsToCanvas(ImageBuffer* imageBuffer)
    230233{
     
    250253    m_context->bindFramebuffer(GraphicsContext3D::FRAMEBUFFER, previousFramebuffer);
    251254}
     255
     256void DrawingBuffer::clearPlatformLayer()
     257{
     258    if (m_private)
     259        m_private->clearTextureId();
     260
     261    m_context->flush();
     262}
    252263#endif
    253264
  • trunk/Source/WebCore/platform/graphics/clutter/DrawingBufferClutter.cpp

    r122175 r139142  
    7575{
    7676}
     77
     78void DrawingBuffer::clearPlatformLayer()
     79{
     80}
    7781#endif
    7882
  • trunk/Source/WebCore/platform/graphics/gpu/DrawingBuffer.cpp

    r130235 r139142  
    7777
    7878    m_context->makeContextCurrent();
     79
     80#if USE(ACCELERATED_COMPOSITING)
     81    clearPlatformLayer();
     82#endif
     83
    7984    if (!m_size.isEmpty()) {
    8085        s_currentResourceUsePixels -= m_size.width() * m_size.height();
  • trunk/Source/WebCore/platform/graphics/gpu/DrawingBuffer.h

    r131502 r139142  
    130130    unsigned frontColorBuffer() const;
    131131    void paintCompositedResultsToCanvas(ImageBuffer*);
     132    void clearPlatformLayer();
    132133#endif
    133134
  • trunk/Source/WebCore/platform/graphics/gpu/mac/DrawingBufferMac.mm

    r122175 r139142  
    114114    return colorBuffer();
    115115}
     116
     117void DrawingBuffer::clearPlatformLayer()
     118{
     119    // Don't need to do anything on this platform.
     120}
    116121#endif
    117122
  • trunk/Source/WebCore/platform/graphics/gpu/qt/DrawingBufferQt.cpp

    r122175 r139142  
    105105{
    106106}
     107
     108void DrawingBuffer::clearPlatformLayer()
     109{
     110}
    107111#endif
    108112
Note: See TracChangeset for help on using the changeset viewer.