1 | /* |
2 | * Copyright 2020 Google Inc. |
3 | * |
4 | * Use of this source code is governed by a BSD-style license that can be |
5 | * found in the LICENSE file. |
6 | */ |
7 | |
8 | #include "src/core/SkMarkerStack.h" |
9 | |
10 | void SkMarkerStack::setMarker(uint32_t id, const SkM44& mx, void* boundary) { |
11 | // We compute and cache the inverse here. Most clients are only interested in that, and we'll |
12 | // be fetching matrices from this far more often than we insert them. |
13 | SkM44 inv; |
14 | SkAssertResult(mx.invert(&inv)); |
15 | |
16 | // Look if we've already seen id in this save-frame. |
17 | // If so, replace, else append |
18 | for (auto it = fStack.rbegin(); it != fStack.rend(); ++it) { |
19 | if (it->fBoundary != boundary) { // we've gone past the save-frame |
20 | break; // fall out so we append |
21 | } |
22 | if (it->fID == id) { // in current frame, so replace |
23 | it->fMatrix = mx; |
24 | it->fMatrixInverse = inv; |
25 | return; |
26 | } |
27 | } |
28 | // if we get here, we should append a new marker |
29 | fStack.push_back({boundary, mx, inv, id}); |
30 | } |
31 | |
32 | bool SkMarkerStack::findMarker(uint32_t id, SkM44* mx) const { |
33 | // search from top to bottom, so we find the most recent id |
34 | for (auto it = fStack.rbegin(); it != fStack.rend(); ++it) { |
35 | if (it->fID == id) { |
36 | if (mx) { |
37 | *mx = it->fMatrix; |
38 | } |
39 | return true; |
40 | } |
41 | } |
42 | return false; |
43 | } |
44 | |
45 | bool SkMarkerStack::findMarkerInverse(uint32_t id, SkM44* mx) const { |
46 | // search from top to bottom, so we find the most recent id |
47 | for (auto it = fStack.rbegin(); it != fStack.rend(); ++it) { |
48 | if (it->fID == id) { |
49 | if (mx) { |
50 | *mx = it->fMatrixInverse; |
51 | } |
52 | return true; |
53 | } |
54 | } |
55 | return false; |
56 | } |
57 | |
58 | void SkMarkerStack::restore(void* boundary) { |
59 | while (!fStack.empty() && fStack.back().fBoundary == boundary) { |
60 | fStack.pop_back(); |
61 | } |
62 | } |
63 | |