Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 /* | 1 /* |
| 2 * Copyright (C) 2012 Google Inc. All rights reserved. | 2 * Copyright (C) 2012 Google Inc. All rights reserved. |
| 3 * | 3 * |
| 4 * Redistribution and use in source and binary forms, with or without | 4 * Redistribution and use in source and binary forms, with or without |
| 5 * modification, are permitted provided that the following conditions | 5 * modification, are permitted provided that the following conditions |
| 6 * are met: | 6 * are met: |
| 7 * | 7 * |
| 8 * 1. Redistributions of source code must retain the above copyright | 8 * 1. Redistributions of source code must retain the above copyright |
| 9 * notice, this list of conditions and the following disclaimer. | 9 * notice, this list of conditions and the following disclaimer. |
| 10 * 2. Redistributions in binary form must reproduce the above copyright | 10 * 2. Redistributions in binary form must reproduce the above copyright |
| (...skipping 25 matching lines...) Expand all Loading... | |
| 36 #include "wtf/DoublyLinkedList.h" | 36 #include "wtf/DoublyLinkedList.h" |
| 37 #include "wtf/PassOwnPtr.h" | 37 #include "wtf/PassOwnPtr.h" |
| 38 #include "wtf/RefPtr.h" | 38 #include "wtf/RefPtr.h" |
| 39 | 39 |
| 40 namespace WebKit { | 40 namespace WebKit { |
| 41 class WebGraphicsContext3D; | 41 class WebGraphicsContext3D; |
| 42 } | 42 } |
| 43 | 43 |
| 44 namespace WebCore { | 44 namespace WebCore { |
| 45 | 45 |
| 46 class Canvas2DLayerBridge; | |
| 47 | |
| 48 // Pointer class, for Canva2DLayerBridge. Similar to OwnPtr, with special | |
|
Stephen White
2013/08/20 17:32:18
Nit: Canva -> Canvas.
| |
| 49 // asynchronous destruction mechanism | |
| 50 class Canvas2DLayerBridgePtr { | |
| 51 public: | |
| 52 Canvas2DLayerBridgePtr() { } | |
| 53 explicit Canvas2DLayerBridgePtr(Canvas2DLayerBridge* ptr) { m_ownPtr = adopt Ptr(ptr); } | |
| 54 Canvas2DLayerBridgePtr(Canvas2DLayerBridgePtr& other) : m_ownPtr(other.m_own Ptr.release()) { } | |
| 55 Canvas2DLayerBridgePtr& operator=(Canvas2DLayerBridgePtr& other) | |
| 56 { | |
| 57 clear(); | |
| 58 m_ownPtr = other.m_ownPtr.release(); | |
| 59 return *this; | |
| 60 } | |
| 61 ~Canvas2DLayerBridgePtr() { clear(); } | |
| 62 void clear(); | |
| 63 Canvas2DLayerBridge* get() const { return m_ownPtr.get(); } | |
| 64 Canvas2DLayerBridge* operator->() const { ASSERT(m_ownPtr); return m_ownPtr. get(); } | |
| 65 private: | |
| 66 OwnPtr<Canvas2DLayerBridge> m_ownPtr; | |
| 67 }; | |
| 68 | |
| 46 class Canvas2DLayerBridge : public WebKit::WebExternalTextureLayerClient, public SkDeferredCanvas::NotificationClient, public DoublyLinkedListNode<Canvas2DLayer Bridge> { | 69 class Canvas2DLayerBridge : public WebKit::WebExternalTextureLayerClient, public SkDeferredCanvas::NotificationClient, public DoublyLinkedListNode<Canvas2DLayer Bridge> { |
| 47 WTF_MAKE_NONCOPYABLE(Canvas2DLayerBridge); | 70 WTF_MAKE_NONCOPYABLE(Canvas2DLayerBridge); |
| 48 public: | 71 public: |
| 49 enum OpacityMode { | 72 enum OpacityMode { |
| 50 Opaque, | 73 Opaque, |
| 51 NonOpaque | 74 NonOpaque |
| 52 }; | 75 }; |
| 53 | 76 |
| 54 static PassOwnPtr<Canvas2DLayerBridge> create(PassRefPtr<GraphicsContext3D>, const IntSize&, OpacityMode); | 77 static Canvas2DLayerBridgePtr create(PassRefPtr<GraphicsContext3D>, const In tSize&, OpacityMode); |
| 55 | 78 |
| 56 virtual ~Canvas2DLayerBridge(); | 79 virtual ~Canvas2DLayerBridge(); // should not be called directly |
| 57 | 80 |
| 58 // WebKit::WebExternalTextureLayerClient implementation. | 81 // WebKit::WebExternalTextureLayerClient implementation. |
| 59 virtual WebKit::WebGraphicsContext3D* context() OVERRIDE; | 82 virtual WebKit::WebGraphicsContext3D* context() OVERRIDE; |
| 60 virtual bool prepareMailbox(WebKit::WebExternalTextureMailbox*, WebKit::WebE xternalBitmap*) OVERRIDE; | 83 virtual bool prepareMailbox(WebKit::WebExternalTextureMailbox*, WebKit::WebE xternalBitmap*) OVERRIDE; |
| 61 virtual void mailboxReleased(const WebKit::WebExternalTextureMailbox&) OVERR IDE; | 84 virtual void mailboxReleased(const WebKit::WebExternalTextureMailbox&) OVERR IDE; |
| 62 | 85 |
| 63 // SkDeferredCanvas::NotificationClient implementation | 86 // SkDeferredCanvas::NotificationClient implementation |
| 64 virtual void prepareForDraw() OVERRIDE; | 87 virtual void prepareForDraw() OVERRIDE; |
| 65 virtual void storageAllocatedForRecordingChanged(size_t) OVERRIDE; | 88 virtual void storageAllocatedForRecordingChanged(size_t) OVERRIDE; |
| 66 virtual void flushedDrawCommands() OVERRIDE; | 89 virtual void flushedDrawCommands() OVERRIDE; |
| (...skipping 10 matching lines...) Expand all Loading... | |
| 77 void contextAcquired(); | 100 void contextAcquired(); |
| 78 SkCanvas* getCanvas() { return m_canvas; } | 101 SkCanvas* getCanvas() { return m_canvas; } |
| 79 | 102 |
| 80 unsigned backBufferTexture(); | 103 unsigned backBufferTexture(); |
| 81 | 104 |
| 82 bool isValid(); | 105 bool isValid(); |
| 83 | 106 |
| 84 protected: | 107 protected: |
| 85 Canvas2DLayerBridge(PassRefPtr<GraphicsContext3D>, SkDeferredCanvas*, Opacit yMode); | 108 Canvas2DLayerBridge(PassRefPtr<GraphicsContext3D>, SkDeferredCanvas*, Opacit yMode); |
| 86 void setRateLimitingEnabled(bool); | 109 void setRateLimitingEnabled(bool); |
| 110 void destroy(); | |
| 111 void deleteIfPossible(); | |
| 112 friend class Canvas2DLayerBridgePtr; | |
| 87 | 113 |
| 88 SkDeferredCanvas* m_canvas; | 114 SkDeferredCanvas* m_canvas; |
| 89 OwnPtr<WebKit::WebExternalTextureLayer> m_layer; | 115 OwnPtr<WebKit::WebExternalTextureLayer> m_layer; |
| 90 RefPtr<GraphicsContext3D> m_context; | 116 RefPtr<GraphicsContext3D> m_context; |
| 91 size_t m_bytesAllocated; | 117 size_t m_bytesAllocated; |
| 92 bool m_didRecordDrawCommand; | 118 bool m_didRecordDrawCommand; |
| 93 bool m_surfaceIsValid; | 119 bool m_surfaceIsValid; |
| 94 int m_framesPending; | 120 int m_framesPending; |
| 95 bool m_rateLimitingEnabled; | 121 bool m_rateLimitingEnabled; |
| 122 bool m_destructionInProgress; | |
| 96 | 123 |
| 97 friend class WTF::DoublyLinkedListNode<Canvas2DLayerBridge>; | 124 friend class WTF::DoublyLinkedListNode<Canvas2DLayerBridge>; |
| 98 Canvas2DLayerBridge* m_next; | 125 Canvas2DLayerBridge* m_next; |
| 99 Canvas2DLayerBridge* m_prev; | 126 Canvas2DLayerBridge* m_prev; |
| 100 | 127 |
| 101 enum MailboxStatus { | 128 enum MailboxStatus { |
| 102 MailboxInUse, | 129 MailboxInUse, |
| 103 MailboxReleased, | 130 MailboxReleased, |
| 104 MailboxAvailable, | 131 MailboxAvailable, |
| 105 }; | 132 }; |
| 106 | 133 |
| 107 struct MailboxInfo { | 134 struct MailboxInfo { |
| 108 WebKit::WebExternalTextureMailbox m_mailbox; | 135 WebKit::WebExternalTextureMailbox m_mailbox; |
| 109 SkAutoTUnref<SkImage> m_image; | 136 SkAutoTUnref<SkImage> m_image; |
| 110 MailboxStatus m_status; | 137 MailboxStatus m_status; |
| 111 | 138 |
| 112 MailboxInfo(const MailboxInfo&); | 139 MailboxInfo(const MailboxInfo&); |
| 113 MailboxInfo() {} | 140 MailboxInfo() {} |
| 114 }; | 141 }; |
| 115 MailboxInfo* createMailboxInfo(); | 142 MailboxInfo* createMailboxInfo(); |
| 116 | 143 |
| 117 uint32_t m_lastImageId; | 144 uint32_t m_lastImageId; |
| 118 Vector<MailboxInfo> m_mailboxes; | 145 Vector<MailboxInfo> m_mailboxes; |
| 119 }; | 146 }; |
| 120 | 147 |
| 148 inline void Canvas2DLayerBridgePtr::clear() | |
| 149 { | |
| 150 if (m_ownPtr) | |
| 151 m_ownPtr.leakPtr()->destroy(); | |
|
Stephen White
2013/08/20 17:32:18
This looks kind of error-prone to me.
| |
| 152 } | |
| 153 | |
| 121 } | 154 } |
| 122 | 155 |
| 123 #endif | 156 #endif |
| OLD | NEW |