SkRecordOpts.cpp revision ad8ce572f69633ffebe2fa486275d82a5e9a71fe
1c4b21e6c03a6cdb03e116b9f510eb10cf8daedb1commit-bot@chromium.org/* 2c4b21e6c03a6cdb03e116b9f510eb10cf8daedb1commit-bot@chromium.org * Copyright 2014 Google Inc. 3c4b21e6c03a6cdb03e116b9f510eb10cf8daedb1commit-bot@chromium.org * 4c4b21e6c03a6cdb03e116b9f510eb10cf8daedb1commit-bot@chromium.org * Use of this source code is governed by a BSD-style license that can be 5c4b21e6c03a6cdb03e116b9f510eb10cf8daedb1commit-bot@chromium.org * found in the LICENSE file. 6c4b21e6c03a6cdb03e116b9f510eb10cf8daedb1commit-bot@chromium.org */ 7c4b21e6c03a6cdb03e116b9f510eb10cf8daedb1commit-bot@chromium.org 8ad8ce572f69633ffebe2fa486275d82a5e9a71fecommit-bot@chromium.org#include "SkRecordOpts.h" 9506db0b7d2905c6bedba9fc5d4aeaf231a9a34eacommit-bot@chromium.org 10506db0b7d2905c6bedba9fc5d4aeaf231a9a34eacommit-bot@chromium.org#include "SkRecords.h" 11506db0b7d2905c6bedba9fc5d4aeaf231a9a34eacommit-bot@chromium.org#include "SkTDArray.h" 12506db0b7d2905c6bedba9fc5d4aeaf231a9a34eacommit-bot@chromium.org 13ad8ce572f69633ffebe2fa486275d82a5e9a71fecommit-bot@chromium.orgvoid SkRecordOptimize(SkRecord* record) { 14ad8ce572f69633ffebe2fa486275d82a5e9a71fecommit-bot@chromium.org SkRecordAnnotateCullingPairs(record); 15ad8ce572f69633ffebe2fa486275d82a5e9a71fecommit-bot@chromium.org} 16ad8ce572f69633ffebe2fa486275d82a5e9a71fecommit-bot@chromium.org 17506db0b7d2905c6bedba9fc5d4aeaf231a9a34eacommit-bot@chromium.orgnamespace { 18506db0b7d2905c6bedba9fc5d4aeaf231a9a34eacommit-bot@chromium.org 19506db0b7d2905c6bedba9fc5d4aeaf231a9a34eacommit-bot@chromium.orgstruct Annotator { 20506db0b7d2905c6bedba9fc5d4aeaf231a9a34eacommit-bot@chromium.org unsigned index; 21506db0b7d2905c6bedba9fc5d4aeaf231a9a34eacommit-bot@chromium.org SkTDArray<SkRecords::PushCull*> pushStack; 22506db0b7d2905c6bedba9fc5d4aeaf231a9a34eacommit-bot@chromium.org 23506db0b7d2905c6bedba9fc5d4aeaf231a9a34eacommit-bot@chromium.org // Do nothing to most record types. 24506db0b7d2905c6bedba9fc5d4aeaf231a9a34eacommit-bot@chromium.org template <typename T> void operator()(T*) {} 25506db0b7d2905c6bedba9fc5d4aeaf231a9a34eacommit-bot@chromium.org}; 26506db0b7d2905c6bedba9fc5d4aeaf231a9a34eacommit-bot@chromium.org 27506db0b7d2905c6bedba9fc5d4aeaf231a9a34eacommit-bot@chromium.orgtemplate <> void Annotator::operator()(SkRecords::PushCull* push) { 28506db0b7d2905c6bedba9fc5d4aeaf231a9a34eacommit-bot@chromium.org // Store the push's index for now. We'll calculate the offset using this in the paired pop. 29506db0b7d2905c6bedba9fc5d4aeaf231a9a34eacommit-bot@chromium.org push->popOffset = index; 30506db0b7d2905c6bedba9fc5d4aeaf231a9a34eacommit-bot@chromium.org pushStack.push(push); 31506db0b7d2905c6bedba9fc5d4aeaf231a9a34eacommit-bot@chromium.org} 32506db0b7d2905c6bedba9fc5d4aeaf231a9a34eacommit-bot@chromium.org 33506db0b7d2905c6bedba9fc5d4aeaf231a9a34eacommit-bot@chromium.orgtemplate <> void Annotator::operator()(SkRecords::PopCull* pop) { 34506db0b7d2905c6bedba9fc5d4aeaf231a9a34eacommit-bot@chromium.org SkRecords::PushCull* push = pushStack.top(); 35506db0b7d2905c6bedba9fc5d4aeaf231a9a34eacommit-bot@chromium.org pushStack.pop(); 36506db0b7d2905c6bedba9fc5d4aeaf231a9a34eacommit-bot@chromium.org 37506db0b7d2905c6bedba9fc5d4aeaf231a9a34eacommit-bot@chromium.org SkASSERT(index > push->popOffset); // push->popOffset holds the index of the push. 38506db0b7d2905c6bedba9fc5d4aeaf231a9a34eacommit-bot@chromium.org push->popOffset = index - push->popOffset; // Now it's the offset between push and pop. 39506db0b7d2905c6bedba9fc5d4aeaf231a9a34eacommit-bot@chromium.org} 40506db0b7d2905c6bedba9fc5d4aeaf231a9a34eacommit-bot@chromium.org 41506db0b7d2905c6bedba9fc5d4aeaf231a9a34eacommit-bot@chromium.org} // namespace 42506db0b7d2905c6bedba9fc5d4aeaf231a9a34eacommit-bot@chromium.org 43506db0b7d2905c6bedba9fc5d4aeaf231a9a34eacommit-bot@chromium.orgvoid SkRecordAnnotateCullingPairs(SkRecord* record) { 44506db0b7d2905c6bedba9fc5d4aeaf231a9a34eacommit-bot@chromium.org Annotator annotator; 45506db0b7d2905c6bedba9fc5d4aeaf231a9a34eacommit-bot@chromium.org 46506db0b7d2905c6bedba9fc5d4aeaf231a9a34eacommit-bot@chromium.org for (annotator.index = 0; annotator.index < record->count(); annotator.index++) { 47506db0b7d2905c6bedba9fc5d4aeaf231a9a34eacommit-bot@chromium.org record->mutate(annotator.index, annotator); 48506db0b7d2905c6bedba9fc5d4aeaf231a9a34eacommit-bot@chromium.org } 49506db0b7d2905c6bedba9fc5d4aeaf231a9a34eacommit-bot@chromium.org} 50