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 1. Redistributions of source code must retain the above copyright | 7 1. Redistributions of source code must retain the above copyright |
8 notice, this list of conditions and the following disclaimer. | 8 notice, this list of conditions and the following disclaimer. |
9 2. Redistributions in binary form must reproduce the above copyright | 9 2. Redistributions in binary form must reproduce the above copyright |
10 notice, this list of conditions and the following disclaimer in the | 10 notice, this list of conditions and the following disclaimer in the |
(...skipping 10 matching lines...) Expand all Loading... |
21 (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS | 21 (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS |
22 SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | 22 SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
23 */ | 23 */ |
24 #include "config.h" | 24 #include "config.h" |
25 | 25 |
26 #include "platform/graphics/Canvas2DLayerManager.h" | 26 #include "platform/graphics/Canvas2DLayerManager.h" |
27 | 27 |
28 #include "public/platform/Platform.h" | 28 #include "public/platform/Platform.h" |
29 #include "wtf/StdLibExtras.h" | 29 #include "wtf/StdLibExtras.h" |
30 | 30 |
31 using blink::WebThread; | |
32 | |
33 namespace { | 31 namespace { |
34 | 32 |
35 enum { | 33 enum { |
36 DefaultMaxBytesAllocated = 64*1024*1024, | 34 DefaultMaxBytesAllocated = 64*1024*1024, |
37 DefaultTargetBytesAllocated = 16*1024*1024, | 35 DefaultTargetBytesAllocated = 16*1024*1024, |
38 }; | 36 }; |
39 | 37 |
40 } // unnamed namespace | 38 } // unnamed namespace |
41 | 39 |
42 namespace blink { | 40 namespace blink { |
(...skipping 12 matching lines...) Expand all Loading... |
55 ASSERT(!m_layerList.head()); | 53 ASSERT(!m_layerList.head()); |
56 ASSERT(!m_taskObserverActive); | 54 ASSERT(!m_taskObserverActive); |
57 } | 55 } |
58 | 56 |
59 void Canvas2DLayerManager::init(size_t maxBytesAllocated, size_t targetBytesAllo
cated) | 57 void Canvas2DLayerManager::init(size_t maxBytesAllocated, size_t targetBytesAllo
cated) |
60 { | 58 { |
61 ASSERT(maxBytesAllocated >= targetBytesAllocated); | 59 ASSERT(maxBytesAllocated >= targetBytesAllocated); |
62 m_maxBytesAllocated = maxBytesAllocated; | 60 m_maxBytesAllocated = maxBytesAllocated; |
63 m_targetBytesAllocated = targetBytesAllocated; | 61 m_targetBytesAllocated = targetBytesAllocated; |
64 if (m_taskObserverActive) { | 62 if (m_taskObserverActive) { |
65 blink::Platform::current()->currentThread()->removeTaskObserver(this); | 63 Platform::current()->currentThread()->removeTaskObserver(this); |
66 m_taskObserverActive = false; | 64 m_taskObserverActive = false; |
67 } | 65 } |
68 } | 66 } |
69 | 67 |
70 Canvas2DLayerManager& Canvas2DLayerManager::get() | 68 Canvas2DLayerManager& Canvas2DLayerManager::get() |
71 { | 69 { |
72 DEFINE_STATIC_LOCAL(Canvas2DLayerManager, manager, ()); | 70 DEFINE_STATIC_LOCAL(Canvas2DLayerManager, manager, ()); |
73 return manager; | 71 return manager; |
74 } | 72 } |
75 | 73 |
76 void Canvas2DLayerManager::willProcessTask() | 74 void Canvas2DLayerManager::willProcessTask() |
77 { | 75 { |
78 } | 76 } |
79 | 77 |
80 void Canvas2DLayerManager::didProcessTask() | 78 void Canvas2DLayerManager::didProcessTask() |
81 { | 79 { |
82 // Called after the script action for the current frame has been processed. | 80 // Called after the script action for the current frame has been processed. |
83 ASSERT(m_taskObserverActive); | 81 ASSERT(m_taskObserverActive); |
84 blink::Platform::current()->currentThread()->removeTaskObserver(this); | 82 Platform::current()->currentThread()->removeTaskObserver(this); |
85 m_taskObserverActive = false; | 83 m_taskObserverActive = false; |
86 Canvas2DLayerBridge* layer = m_layerList.head(); | 84 Canvas2DLayerBridge* layer = m_layerList.head(); |
87 while (layer) { | 85 while (layer) { |
88 Canvas2DLayerBridge* currentLayer = layer; | 86 Canvas2DLayerBridge* currentLayer = layer; |
89 // must increment iterator before calling limitPendingFrames, which | 87 // must increment iterator before calling limitPendingFrames, which |
90 // may result in the layer being removed from the list. | 88 // may result in the layer being removed from the list. |
91 layer = layer->next(); | 89 layer = layer->next(); |
92 currentLayer->limitPendingFrames(); | 90 currentLayer->limitPendingFrames(); |
93 } | 91 } |
94 } | 92 } |
95 | 93 |
96 void Canvas2DLayerManager::layerDidDraw(Canvas2DLayerBridge* layer) | 94 void Canvas2DLayerManager::layerDidDraw(Canvas2DLayerBridge* layer) |
97 { | 95 { |
98 if (isInList(layer)) { | 96 if (isInList(layer)) { |
99 if (layer != m_layerList.head()) { | 97 if (layer != m_layerList.head()) { |
100 m_layerList.remove(layer); | 98 m_layerList.remove(layer); |
101 m_layerList.push(layer); // Set as MRU | 99 m_layerList.push(layer); // Set as MRU |
102 } | 100 } |
103 } | 101 } |
104 | 102 |
105 if (!m_taskObserverActive) { | 103 if (!m_taskObserverActive) { |
106 m_taskObserverActive = true; | 104 m_taskObserverActive = true; |
107 // Schedule a call to didProcessTask() after completion of the current s
cript task. | 105 // Schedule a call to didProcessTask() after completion of the current s
cript task. |
108 blink::Platform::current()->currentThread()->addTaskObserver(this); | 106 Platform::current()->currentThread()->addTaskObserver(this); |
109 } | 107 } |
110 } | 108 } |
111 | 109 |
112 void Canvas2DLayerManager::layerTransientResourceAllocationChanged(Canvas2DLayer
Bridge* layer, intptr_t deltaBytes) | 110 void Canvas2DLayerManager::layerTransientResourceAllocationChanged(Canvas2DLayer
Bridge* layer, intptr_t deltaBytes) |
113 { | 111 { |
114 ASSERT((intptr_t)m_bytesAllocated + deltaBytes >= 0); | 112 ASSERT((intptr_t)m_bytesAllocated + deltaBytes >= 0); |
115 m_bytesAllocated = (intptr_t)m_bytesAllocated + deltaBytes; | 113 m_bytesAllocated = (intptr_t)m_bytesAllocated + deltaBytes; |
116 if (!isInList(layer) && layer->hasTransientResources()) { | 114 if (!isInList(layer) && layer->hasTransientResources()) { |
117 m_layerList.push(layer); | 115 m_layerList.push(layer); |
118 } else if (isInList(layer) && !layer->hasTransientResources()) { | 116 } else if (isInList(layer) && !layer->hasTransientResources()) { |
(...skipping 28 matching lines...) Expand all Loading... |
147 ASSERT(isInList(currentLayer) == currentLayer->hasTransientResources
()); | 145 ASSERT(isInList(currentLayer) == currentLayer->hasTransientResources
()); |
148 } | 146 } |
149 } | 147 } |
150 } | 148 } |
151 | 149 |
152 bool Canvas2DLayerManager::isInList(Canvas2DLayerBridge* layer) const | 150 bool Canvas2DLayerManager::isInList(Canvas2DLayerBridge* layer) const |
153 { | 151 { |
154 return layer->prev() || m_layerList.head() == layer; | 152 return layer->prev() || m_layerList.head() == layer; |
155 } | 153 } |
156 | 154 |
157 } | 155 } // namespace blink |
158 | 156 |
OLD | NEW |