blob: 4a73d227ba8eb3f2a95dede72194b358a41be890 [file] [log] [blame]
Lingfeng Yang8e2b6e02016-10-14 11:20:45 -07001/*
2* Copyright (C) 2016 The Android Open Source Project
3*
4* Licensed under the Apache License, Version 2.0 (the "License");
5* you may not use this file except in compliance with the License.
6* You may obtain a copy of the License at
7*
8* http://www.apache.org/licenses/LICENSE-2.0
9*
10* Unless required by applicable law or agreed to in writing, software
11* distributed under the License is distributed on an "AS IS" BASIS,
12* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13* See the License for the specific language governing permissions and
14* limitations under the License.
15*/
16
17#include "IndexRangeCache.h"
18
19// This is almost literally
20// external/angle/src/libANGLE/IndexRangeCache.cpp
21
22void IndexRangeCache::addRange(GLenum type,
23 size_t offset,
24 size_t count,
25 bool primitiveRestartEnabled,
26 int start,
27 int end) {
28 IndexRange r;
29 r.start = start;
30 r.end = end;
31 mIndexRangeCache[IndexRangeKey(type, offset, count, primitiveRestartEnabled)] = r;
32}
33
34bool IndexRangeCache::findRange(GLenum type,
35 size_t offset,
36 size_t count,
37 bool primitiveRestartEnabled,
38 int* start_out,
39 int* end_out) const {
40 IndexRangeMap::const_iterator it =
41 mIndexRangeCache.find(
42 IndexRangeKey(type, offset, count, primitiveRestartEnabled));
43
44 if (it != mIndexRangeCache.end()) {
45 if (start_out) *start_out = it->second.start;
46 if (end_out) *end_out = it->second.end;
47 return true;
48 } else {
49 if (start_out) *start_out = 0;
50 if (end_out) *end_out = 0;
51 return false;
52 }
53}
54
55
56void IndexRangeCache::invalidateRange(size_t offset, size_t size) {
57 size_t invalidateStart = offset;
58 size_t invalidateEnd = offset + size;
59
Yahan Zhou0f3971d2018-11-28 12:00:13 -080060 IndexRangeMap::iterator it = mIndexRangeCache.begin();
Lingfeng Yang8e2b6e02016-10-14 11:20:45 -070061
62 while (it != mIndexRangeCache.end()) {
63 size_t rangeStart = it->first.offset;
64 size_t rangeEnd =
65 it->first.offset +
66 it->first.count * glSizeof(it->first.type);
67
68 if (invalidateEnd < rangeStart ||
69 invalidateStart > rangeEnd) {
70 ++it;
71 } else {
72 mIndexRangeCache.erase(it++);
73 }
74 }
75}
76
77void IndexRangeCache::clear() {
78 mIndexRangeCache.clear();
79}