Created
January 31, 2011 08:06
-
-
Save natduca/803761 to your computer and use it in GitHub Desktop.
Commit flow for LayerRendererChromium
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class LayerChromium { | |
public: | |
LayerChromium() { | |
m_needsCommit = 0; | |
m_parent = NULL; | |
} | |
~LayerChromium() { | |
m_compositorLayer = NULL; // will not cause a delete --- the parent compositorLayer should hold a reference, too | |
} | |
void addChild(LayerChromium* child) { | |
m_children.push_back(child); | |
child->m_parent = this; | |
setNeedsCommit(COMMIT_CHILDREN_VECTOR); | |
if(child->m_needsCommit) | |
setNeedsCommit(COMMIT_CHILDREN); | |
} | |
void insertChildBefore(int position, LayerChromium* child) { | |
LayerChromium* oldParent = child->m_parent; | |
m_children.insertAt(position, child); | |
if(oldParent) { | |
oldParent->remove(child); | |
} | |
child->m_parent = this; | |
setNeedsCommit(COMMIT_CHILDREN_VECTOR); | |
if(child->m_needsCommit) | |
setNeedsCommit(COMMIT_CHILDREN); | |
} | |
void removeChild(LayerChromium* child) { | |
child->m_parent = NULL; | |
m_children.remove(child); | |
setNeedsCommit(COMMIT_CHILDREN_VECTOR); | |
} | |
void setNeedsCommit(CommitMask mask) { | |
CommitMask oldMask = m_needsCommit; | |
assert(mask != 0); | |
m_needsCommit |= mask; | |
if(m_parent && !oldMask) | |
m_parent->setNeedsCommit(COMMIT_CHILDREN); | |
} | |
CompositorLayerChromium* getOrCreateCompositorLayer() { | |
assert(ChildThread::current()->type() == ChildThread::COMPOSITOR); | |
if(m_compositorLayer == NULL) | |
m_compositorLayer = new CompositorLayerChromium(); | |
return m_compositorLayer; | |
} | |
void commit() { | |
assert(m_compositorLayer); | |
CompositorLayerChromium* cLayer = m_compositorLayer; | |
commitData(cLayer); | |
// commit children vector... | |
if(m_childrenNeedsCommit) { | |
if(m_children.size() > cLayer.m_children.size()) { | |
// grow, then copy | |
while(cLayer->m_children.size() < m_children.size()) | |
cLayer->m_children.push_back(NULL); | |
for(size_t i = 0; i < m_children.size(); ++i) { | |
cLayer->m_children[i] = m_children[i]->getOrCreateCompositorLayer(); | |
cLayer->m_children[i]->m_parent = cLayer; | |
} | |
} else if(m_children.size() < cLayer->m_children.size()) { | |
// copy then shrink | |
for(size_t i = 0; i < m_children.size(); ++i) { | |
cLayer->m_children[i] = m_children[i]->getOrCreateCompositorLayer(); | |
cLayer->m_children[i]->m_parent = cLayer; | |
} | |
while(cLayer->m_children.size() > m_children.size()) | |
cLayer->m_children.pop_back(); | |
} else { | |
// copynn | |
for(size_t i = 0; i < m_children.size(); ++i) { | |
cLayer->m_children[i] = m_children[i]->getOrCreateCompositorLayer(); | |
cLayer->m_children[i]->m_parent = cLayer; | |
} | |
} | |
m_childrenNeedsCommit = false; | |
} | |
// commit children | |
if(m_needsCommit & COMMIT_CHILDREN) { | |
for(size_t i = 0; i < m_children.size(); ++i) { | |
m_children[i].commit(); | |
} | |
} | |
// clear flag | |
m_needsCommit = 0; | |
} | |
void commitData() { | |
// commit any data fields | |
} | |
protected: | |
enum CommitMask { | |
COMMIT_CHILDREN = 0x1, | |
COMMIT_CHILDREN_VECTOR = 0x2, | |
}; | |
CommitMask m_needsCommit; | |
RefPtr<CompositorLayerChromium> m_compositorLayer; | |
bool m_childrenNeedsCommit; | |
std::vector<RefPtr<LayerChromium> > m_children;; | |
} | |
class CompositorLayerChromium { | |
public: | |
CompositorLayerChromium() { | |
assert(ChildThread::current()->type() == ChildThread::COMPOSITOR); | |
} | |
~CompositorLayerChromium() { | |
assert(ChildThread::current()->type() == ChildThread::COMPOSITOR); | |
} | |
protected: | |
CompositorLayerChromium* m_parent; | |
std::vector<RefPtr<CompositorLayerChromium> > m_children; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment