• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
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 
addRange(GLenum type,size_t offset,size_t count,bool primitiveRestartEnabled,int start,int end)22 void 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 
findRange(GLenum type,size_t offset,size_t count,bool primitiveRestartEnabled,int * start_out,int * end_out) const34 bool 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 
invalidateRange(size_t offset,size_t size)56 void IndexRangeCache::invalidateRange(size_t offset, size_t size) {
57     size_t invalidateStart = offset;
58     size_t invalidateEnd = offset + size;
59 
60     IndexRangeMap::iterator it = mIndexRangeCache.begin();
61 
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 
clear()77 void IndexRangeCache::clear() {
78     mIndexRangeCache.clear();
79 }
80