aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/record/SkRecordCulling.cpp
blob: f147ee668353497dac00811bdf5d70a870a3c2e7 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
/*
 * Copyright 2014 Google Inc.
 *
 * Use of this source code is governed by a BSD-style license that can be
 * found in the LICENSE file.
 */

#include "SkRecordCulling.h"

#include "SkRecords.h"
#include "SkTDArray.h"

namespace {

struct Annotator {
    unsigned index;
    SkTDArray<SkRecords::PushCull*> pushStack;

    // Do nothing to most record types.
    template <typename T> void operator()(T*) {}
};

template <> void Annotator::operator()(SkRecords::PushCull* push) {
    // Store the push's index for now.  We'll calculate the offset using this in the paired pop.
    push->popOffset = index;
    pushStack.push(push);
}

template <> void Annotator::operator()(SkRecords::PopCull* pop) {
    SkRecords::PushCull* push = pushStack.top();
    pushStack.pop();

    SkASSERT(index > push->popOffset);          // push->popOffset holds the index of the push.
    push->popOffset = index - push->popOffset;  // Now it's the offset between push and pop.
}

}  // namespace

void SkRecordAnnotateCullingPairs(SkRecord* record) {
    Annotator annotator;

    for (annotator.index = 0; annotator.index < record->count(); annotator.index++) {
        record->mutate(annotator.index, annotator);
    }
}