 Chromium Code Reviews
 Chromium Code Reviews Issue 22929012:
  Change Canvas2DLayerBridge to stay alive until last mailbox is returned.  (Closed) 
  Base URL: svn://svn.chromium.org/blink/trunk
    
  
    Issue 22929012:
  Change Canvas2DLayerBridge to stay alive until last mailbox is returned.  (Closed) 
  Base URL: svn://svn.chromium.org/blink/trunk| Index: Source/core/platform/graphics/chromium/Canvas2DLayerBridge.h | 
| diff --git a/Source/core/platform/graphics/chromium/Canvas2DLayerBridge.h b/Source/core/platform/graphics/chromium/Canvas2DLayerBridge.h | 
| index 12f87fa0f0dd9af0e2c5a6eb8c314d46ec4bd97f..d40988c36f0a177245219310fccdf30d46b6fde6 100644 | 
| --- a/Source/core/platform/graphics/chromium/Canvas2DLayerBridge.h | 
| +++ b/Source/core/platform/graphics/chromium/Canvas2DLayerBridge.h | 
| @@ -43,6 +43,29 @@ class WebGraphicsContext3D; | 
| namespace WebCore { | 
| +class Canvas2DLayerBridge; | 
| + | 
| +// Pointer class, for Canva2DLayerBridge. Similar to OwnPtr, with special | 
| 
Stephen White
2013/08/20 17:32:18
Nit: Canva -> Canvas.
 | 
| +// asynchronous destruction mechanism | 
| +class Canvas2DLayerBridgePtr { | 
| +public: | 
| + Canvas2DLayerBridgePtr() { } | 
| + explicit Canvas2DLayerBridgePtr(Canvas2DLayerBridge* ptr) { m_ownPtr = adoptPtr(ptr); } | 
| + Canvas2DLayerBridgePtr(Canvas2DLayerBridgePtr& other) : m_ownPtr(other.m_ownPtr.release()) { } | 
| + Canvas2DLayerBridgePtr& operator=(Canvas2DLayerBridgePtr& other) | 
| + { | 
| + clear(); | 
| + m_ownPtr = other.m_ownPtr.release(); | 
| + return *this; | 
| + } | 
| + ~Canvas2DLayerBridgePtr() { clear(); } | 
| + void clear(); | 
| + Canvas2DLayerBridge* get() const { return m_ownPtr.get(); } | 
| + Canvas2DLayerBridge* operator->() const { ASSERT(m_ownPtr); return m_ownPtr.get(); } | 
| +private: | 
| + OwnPtr<Canvas2DLayerBridge> m_ownPtr; | 
| +}; | 
| + | 
| class Canvas2DLayerBridge : public WebKit::WebExternalTextureLayerClient, public SkDeferredCanvas::NotificationClient, public DoublyLinkedListNode<Canvas2DLayerBridge> { | 
| WTF_MAKE_NONCOPYABLE(Canvas2DLayerBridge); | 
| public: | 
| @@ -51,9 +74,9 @@ public: | 
| NonOpaque | 
| }; | 
| - static PassOwnPtr<Canvas2DLayerBridge> create(PassRefPtr<GraphicsContext3D>, const IntSize&, OpacityMode); | 
| + static Canvas2DLayerBridgePtr create(PassRefPtr<GraphicsContext3D>, const IntSize&, OpacityMode); | 
| - virtual ~Canvas2DLayerBridge(); | 
| + virtual ~Canvas2DLayerBridge(); // should not be called directly | 
| // WebKit::WebExternalTextureLayerClient implementation. | 
| virtual WebKit::WebGraphicsContext3D* context() OVERRIDE; | 
| @@ -84,6 +107,9 @@ public: | 
| protected: | 
| Canvas2DLayerBridge(PassRefPtr<GraphicsContext3D>, SkDeferredCanvas*, OpacityMode); | 
| void setRateLimitingEnabled(bool); | 
| + void destroy(); | 
| + void deleteIfPossible(); | 
| + friend class Canvas2DLayerBridgePtr; | 
| SkDeferredCanvas* m_canvas; | 
| OwnPtr<WebKit::WebExternalTextureLayer> m_layer; | 
| @@ -93,6 +119,7 @@ protected: | 
| bool m_surfaceIsValid; | 
| int m_framesPending; | 
| bool m_rateLimitingEnabled; | 
| + bool m_destructionInProgress; | 
| friend class WTF::DoublyLinkedListNode<Canvas2DLayerBridge>; | 
| Canvas2DLayerBridge* m_next; | 
| @@ -118,6 +145,12 @@ protected: | 
| Vector<MailboxInfo> m_mailboxes; | 
| }; | 
| +inline void Canvas2DLayerBridgePtr::clear() | 
| +{ | 
| + if (m_ownPtr) | 
| + m_ownPtr.leakPtr()->destroy(); | 
| 
Stephen White
2013/08/20 17:32:18
This looks kind of error-prone to me.
 | 
| +} | 
| + | 
| } | 
| #endif |