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 30 matching lines...) Expand all Loading... |
41 #include "wtf/RefPtr.h" | 41 #include "wtf/RefPtr.h" |
42 | 42 |
43 namespace blink { | 43 namespace blink { |
44 class WebGraphicsContext3D; | 44 class WebGraphicsContext3D; |
45 } | 45 } |
46 | 46 |
47 class Canvas2DLayerBridgeTest; | 47 class Canvas2DLayerBridgeTest; |
48 | 48 |
49 namespace WebCore { | 49 namespace WebCore { |
50 | 50 |
| 51 class Canvas2DLayerBridgeClient { |
| 52 public: |
| 53 virtual bool hidden() const = 0; |
| 54 virtual ~Canvas2DLayerBridgeClient() { } |
| 55 }; |
| 56 |
51 class PLATFORM_EXPORT Canvas2DLayerBridge : public blink::WebExternalTextureLaye
rClient, public SkDeferredCanvas::NotificationClient, public DoublyLinkedListNod
e<Canvas2DLayerBridge>, public RefCounted<Canvas2DLayerBridge> { | 57 class PLATFORM_EXPORT Canvas2DLayerBridge : public blink::WebExternalTextureLaye
rClient, public SkDeferredCanvas::NotificationClient, public DoublyLinkedListNod
e<Canvas2DLayerBridge>, public RefCounted<Canvas2DLayerBridge> { |
52 WTF_MAKE_NONCOPYABLE(Canvas2DLayerBridge); | 58 WTF_MAKE_NONCOPYABLE(Canvas2DLayerBridge); |
53 public: | 59 public: |
54 static PassRefPtr<Canvas2DLayerBridge> create(const IntSize&, OpacityMode, i
nt msaaSampleCount); | 60 static PassRefPtr<Canvas2DLayerBridge> create(Canvas2DLayerBridgeClient*, co
nst IntSize&, OpacityMode, int msaaSampleCount); |
| 61 |
55 virtual ~Canvas2DLayerBridge(); | 62 virtual ~Canvas2DLayerBridge(); |
56 | 63 |
57 // blink::WebExternalTextureLayerClient implementation. | 64 // blink::WebExternalTextureLayerClient implementation. |
58 virtual blink::WebGraphicsContext3D* context() OVERRIDE; | 65 virtual blink::WebGraphicsContext3D* context() OVERRIDE; |
59 virtual bool prepareMailbox(blink::WebExternalTextureMailbox*, blink::WebExt
ernalBitmap*) OVERRIDE; | 66 virtual bool prepareMailbox(blink::WebExternalTextureMailbox*, blink::WebExt
ernalBitmap*) OVERRIDE; |
60 virtual void mailboxReleased(const blink::WebExternalTextureMailbox&) OVERRI
DE; | 67 virtual void mailboxReleased(const blink::WebExternalTextureMailbox&) OVERRI
DE; |
61 | 68 |
62 // SkDeferredCanvas::NotificationClient implementation | 69 // SkDeferredCanvas::NotificationClient implementation |
63 virtual void prepareForDraw() OVERRIDE; | 70 virtual void prepareForDraw() OVERRIDE; |
64 virtual void storageAllocatedForRecordingChanged(size_t) OVERRIDE; | 71 virtual void storageAllocatedForRecordingChanged(size_t) OVERRIDE; |
65 virtual void flushedDrawCommands() OVERRIDE; | 72 virtual void flushedDrawCommands() OVERRIDE; |
66 virtual void skippedPendingDrawCommands() OVERRIDE; | 73 virtual void skippedPendingDrawCommands() OVERRIDE; |
67 | 74 |
68 // ImageBufferSurface implementation | 75 // ImageBufferSurface implementation |
69 void willUse(); | 76 void willUse(); |
70 SkCanvas* canvas() const { return m_canvas.get(); } | 77 SkCanvas* canvas() const { return m_canvas.get(); } |
71 bool isValid(); | 78 bool isValid(); |
72 blink::WebLayer* layer() const; | 79 blink::WebLayer* layer() const; |
73 Platform3DObject getBackingTexture(); | 80 Platform3DObject getBackingTexture(); |
74 bool isAccelerated() const { return true; } | 81 bool isAccelerated() const { return true; } |
75 | 82 |
76 // Methods used by Canvas2DLayerManager | 83 // Methods used by Canvas2DLayerManager |
77 virtual size_t freeMemoryIfPossible(size_t); // virtual for mocking | 84 virtual size_t freeMemoryIfPossible(size_t); // virtual for mocking |
78 virtual void flush(); // virtual for mocking | 85 virtual void flush(); // virtual for mocking |
79 virtual size_t storageAllocatedForRecording(); // virtual for faking | 86 virtual size_t storageAllocatedForRecording(); // virtual for faking |
80 size_t bytesAllocated() const {return m_bytesAllocated;} | 87 size_t bytesAllocated() const { return m_bytesAllocated; } |
81 void limitPendingFrames(); | 88 void limitPendingFrames(); |
| 89 void freeReleasedMailbox(); |
| 90 bool hasReleasedMailbox() const { return m_releasedMailboxInfo; }; |
| 91 void freeTransientResources(); |
| 92 bool hasTransientResources() const; |
| 93 bool hidden() const; |
82 | 94 |
83 void beginDestruction(); | 95 void beginDestruction(); |
84 | 96 |
85 protected: | 97 protected: |
86 Canvas2DLayerBridge(PassRefPtr<GraphicsContext3D>, PassOwnPtr<SkDeferredCanv
as>, int, OpacityMode); | 98 Canvas2DLayerBridge(Canvas2DLayerBridgeClient*, PassRefPtr<GraphicsContext3D
>, PassOwnPtr<SkDeferredCanvas>, int, OpacityMode); |
87 void setRateLimitingEnabled(bool); | 99 void setRateLimitingEnabled(bool); |
88 | 100 |
| 101 Canvas2DLayerBridgeClient* m_client; |
89 OwnPtr<SkDeferredCanvas> m_canvas; | 102 OwnPtr<SkDeferredCanvas> m_canvas; |
90 OwnPtr<blink::WebExternalTextureLayer> m_layer; | 103 OwnPtr<blink::WebExternalTextureLayer> m_layer; |
91 RefPtr<GraphicsContext3D> m_context; | 104 RefPtr<GraphicsContext3D> m_context; |
92 int m_msaaSampleCount; | 105 int m_msaaSampleCount; |
93 size_t m_bytesAllocated; | 106 size_t m_bytesAllocated; |
94 bool m_didRecordDrawCommand; | 107 bool m_didRecordDrawCommand; |
95 bool m_surfaceIsValid; | 108 bool m_surfaceIsValid; |
96 int m_framesPending; | 109 int m_framesPending; |
| 110 int m_framesSinceMailboxRelease; |
97 bool m_destructionInProgress; | 111 bool m_destructionInProgress; |
98 bool m_rateLimitingEnabled; | 112 bool m_rateLimitingEnabled; |
99 | 113 |
100 friend class WTF::DoublyLinkedListNode<Canvas2DLayerBridge>; | 114 friend class WTF::DoublyLinkedListNode<Canvas2DLayerBridge>; |
101 friend class ::Canvas2DLayerBridgeTest; | 115 friend class ::Canvas2DLayerBridgeTest; |
102 Canvas2DLayerBridge* m_next; | 116 Canvas2DLayerBridge* m_next; |
103 Canvas2DLayerBridge* m_prev; | 117 Canvas2DLayerBridge* m_prev; |
104 | 118 |
105 enum MailboxStatus { | 119 enum MailboxStatus { |
106 MailboxInUse, | 120 MailboxInUse, |
107 MailboxReleased, | 121 MailboxReleased, |
108 MailboxAvailable, | 122 MailboxAvailable, |
109 }; | 123 }; |
110 | 124 |
111 struct MailboxInfo { | 125 struct MailboxInfo { |
112 blink::WebExternalTextureMailbox m_mailbox; | 126 blink::WebExternalTextureMailbox m_mailbox; |
113 SkAutoTUnref<SkImage> m_image; | 127 RefPtr<SkImage> m_image; |
114 MailboxStatus m_status; | 128 MailboxStatus m_status; |
115 RefPtr<Canvas2DLayerBridge> m_parentLayerBridge; | 129 RefPtr<Canvas2DLayerBridge> m_parentLayerBridge; |
116 | 130 |
117 MailboxInfo(const MailboxInfo&); | 131 MailboxInfo(const MailboxInfo&); |
118 MailboxInfo() {} | 132 MailboxInfo() {} |
119 }; | 133 }; |
120 MailboxInfo* createMailboxInfo(); | 134 MailboxInfo* createMailboxInfo(); |
121 | 135 |
122 uint32_t m_lastImageId; | 136 uint32_t m_lastImageId; |
123 Vector<MailboxInfo> m_mailboxes; | 137 Vector<MailboxInfo> m_mailboxes; |
| 138 MailboxInfo* m_releasedMailboxInfo; |
124 }; | 139 }; |
125 } | 140 } |
126 #endif | 141 #endif |
OLD | NEW |