| 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 25 matching lines...) Expand all Loading... |
| 36 }; | 36 }; |
| 37 | 37 |
| 38 } // unnamed namespace | 38 } // unnamed namespace |
| 39 | 39 |
| 40 namespace blink { | 40 namespace blink { |
| 41 | 41 |
| 42 Canvas2DLayerManager::Canvas2DLayerManager() | 42 Canvas2DLayerManager::Canvas2DLayerManager() |
| 43 : m_bytesAllocated(0) | 43 : m_bytesAllocated(0) |
| 44 , m_maxBytesAllocated(DefaultMaxBytesAllocated) | 44 , m_maxBytesAllocated(DefaultMaxBytesAllocated) |
| 45 , m_targetBytesAllocated(DefaultTargetBytesAllocated) | 45 , m_targetBytesAllocated(DefaultTargetBytesAllocated) |
| 46 , m_taskObserverActive(false) | 46 , m_limitPendingFramesTimer(this, &Canvas2DLayerManager::limitPendingFramesT
imerFired) |
| 47 { | 47 { |
| 48 } | 48 } |
| 49 | 49 |
| 50 Canvas2DLayerManager::~Canvas2DLayerManager() | 50 Canvas2DLayerManager::~Canvas2DLayerManager() |
| 51 { | 51 { |
| 52 ASSERT(!m_bytesAllocated); | 52 ASSERT(!m_bytesAllocated); |
| 53 ASSERT(!m_layerList.head()); | 53 ASSERT(!m_layerList.head()); |
| 54 ASSERT(!m_taskObserverActive); | |
| 55 } | 54 } |
| 56 | 55 |
| 57 void Canvas2DLayerManager::init(size_t maxBytesAllocated, size_t targetBytesAllo
cated) | 56 void Canvas2DLayerManager::init(size_t maxBytesAllocated, size_t targetBytesAllo
cated) |
| 58 { | 57 { |
| 59 ASSERT(maxBytesAllocated >= targetBytesAllocated); | 58 ASSERT(maxBytesAllocated >= targetBytesAllocated); |
| 60 m_maxBytesAllocated = maxBytesAllocated; | 59 m_maxBytesAllocated = maxBytesAllocated; |
| 61 m_targetBytesAllocated = targetBytesAllocated; | 60 m_targetBytesAllocated = targetBytesAllocated; |
| 62 if (m_taskObserverActive) { | 61 if (m_limitPendingFramesTimer.isActive()) |
| 63 Platform::current()->currentThread()->removeTaskObserver(this); | 62 m_limitPendingFramesTimer.stop(); |
| 64 m_taskObserverActive = false; | |
| 65 } | |
| 66 } | 63 } |
| 67 | 64 |
| 68 Canvas2DLayerManager& Canvas2DLayerManager::get() | 65 Canvas2DLayerManager& Canvas2DLayerManager::get() |
| 69 { | 66 { |
| 70 DEFINE_STATIC_LOCAL(Canvas2DLayerManager, manager, ()); | 67 DEFINE_STATIC_LOCAL(Canvas2DLayerManager, manager, ()); |
| 71 return manager; | 68 return manager; |
| 72 } | 69 } |
| 73 | 70 |
| 74 void Canvas2DLayerManager::willProcessTask() | 71 void Canvas2DLayerManager::limitPendingFramesTimerFired(Timer<Canvas2DLayerManag
er>*) |
| 75 { | 72 { |
| 76 } | |
| 77 | |
| 78 void Canvas2DLayerManager::didProcessTask() | |
| 79 { | |
| 80 // Called after the script action for the current frame has been processed. | |
| 81 ASSERT(m_taskObserverActive); | |
| 82 Platform::current()->currentThread()->removeTaskObserver(this); | |
| 83 m_taskObserverActive = false; | |
| 84 Canvas2DLayerBridge* layer = m_layerList.head(); | 73 Canvas2DLayerBridge* layer = m_layerList.head(); |
| 85 while (layer) { | 74 while (layer) { |
| 86 Canvas2DLayerBridge* currentLayer = layer; | 75 Canvas2DLayerBridge* currentLayer = layer; |
| 87 // must increment iterator before calling limitPendingFrames, which | 76 // must increment iterator before calling limitPendingFrames, which |
| 88 // may result in the layer being removed from the list. | 77 // may result in the layer being removed from the list. |
| 89 layer = layer->next(); | 78 layer = layer->next(); |
| 90 currentLayer->limitPendingFrames(); | 79 currentLayer->limitPendingFrames(); |
| 91 } | 80 } |
| 92 } | 81 } |
| 93 | 82 |
| 94 void Canvas2DLayerManager::layerDidDraw(Canvas2DLayerBridge* layer) | 83 void Canvas2DLayerManager::layerDidDraw(Canvas2DLayerBridge* layer) |
| 95 { | 84 { |
| 96 if (isInList(layer)) { | 85 if (isInList(layer)) { |
| 97 if (layer != m_layerList.head()) { | 86 if (layer != m_layerList.head()) { |
| 98 m_layerList.remove(layer); | 87 m_layerList.remove(layer); |
| 99 m_layerList.push(layer); // Set as MRU | 88 m_layerList.push(layer); // Set as MRU |
| 100 } | 89 } |
| 101 } | 90 } |
| 102 | 91 |
| 103 if (!m_taskObserverActive) { | 92 if (!m_limitPendingFramesTimer.isActive()) |
| 104 m_taskObserverActive = true; | 93 m_limitPendingFramesTimer.startOneShot(0, FROM_HERE); |
| 105 // Schedule a call to didProcessTask() after completion of the current s
cript task. | |
| 106 Platform::current()->currentThread()->addTaskObserver(this); | |
| 107 } | |
| 108 } | 94 } |
| 109 | 95 |
| 110 void Canvas2DLayerManager::layerTransientResourceAllocationChanged(Canvas2DLayer
Bridge* layer, intptr_t deltaBytes) | 96 void Canvas2DLayerManager::layerTransientResourceAllocationChanged(Canvas2DLayer
Bridge* layer, intptr_t deltaBytes) |
| 111 { | 97 { |
| 112 ASSERT((intptr_t)m_bytesAllocated + deltaBytes >= 0); | 98 ASSERT((intptr_t)m_bytesAllocated + deltaBytes >= 0); |
| 113 m_bytesAllocated = (intptr_t)m_bytesAllocated + deltaBytes; | 99 m_bytesAllocated = (intptr_t)m_bytesAllocated + deltaBytes; |
| 114 if (!isInList(layer) && layer->hasTransientResources()) { | 100 if (!isInList(layer) && layer->hasTransientResources()) { |
| 115 m_layerList.push(layer); | 101 m_layerList.push(layer); |
| 116 } else if (isInList(layer) && !layer->hasTransientResources()) { | 102 } else if (isInList(layer) && !layer->hasTransientResources()) { |
| 117 m_layerList.remove(layer); | 103 m_layerList.remove(layer); |
| (...skipping 29 matching lines...) Expand all Loading... |
| 147 } | 133 } |
| 148 } | 134 } |
| 149 | 135 |
| 150 bool Canvas2DLayerManager::isInList(Canvas2DLayerBridge* layer) const | 136 bool Canvas2DLayerManager::isInList(Canvas2DLayerBridge* layer) const |
| 151 { | 137 { |
| 152 return layer->prev() || m_layerList.head() == layer; | 138 return layer->prev() || m_layerList.head() == layer; |
| 153 } | 139 } |
| 154 | 140 |
| 155 } // namespace blink | 141 } // namespace blink |
| 156 | 142 |
| OLD | NEW |