gfx/angle/src/libGLESv2/renderer/IndexRangeCache.cpp

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/gfx/angle/src/libGLESv2/renderer/IndexRangeCache.cpp	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,97 @@
     1.4 +#include "precompiled.h"
     1.5 +//
     1.6 +// Copyright (c) 2013 The ANGLE Project Authors. All rights reserved.
     1.7 +// Use of this source code is governed by a BSD-style license that can be
     1.8 +// found in the LICENSE file.
     1.9 +//
    1.10 +
    1.11 +// IndexRangeCache.cpp: Defines the rx::IndexRangeCache class which stores information about
    1.12 +// ranges of indices.
    1.13 +
    1.14 +#include "libGLESv2/renderer/IndexRangeCache.h"
    1.15 +#include "common/debug.h"
    1.16 +#include "libGLESv2/utilities.h"
    1.17 +#include <tuple>
    1.18 +
    1.19 +namespace rx
    1.20 +{
    1.21 +
    1.22 +void IndexRangeCache::addRange(GLenum type, intptr_t offset, GLsizei count, unsigned int minIdx, unsigned int maxIdx, 
    1.23 +                               unsigned int streamOffset)
    1.24 +{
    1.25 +    mIndexRangeCache[IndexRange(type, offset, count)] = IndexBounds(minIdx, maxIdx, streamOffset);
    1.26 +}
    1.27 +
    1.28 +void IndexRangeCache::invalidateRange(unsigned int offset, unsigned int size)
    1.29 +{
    1.30 +    unsigned int invalidateStart = offset;
    1.31 +    unsigned int invalidateEnd = offset + size;
    1.32 +
    1.33 +    IndexRangeMap::iterator i = mIndexRangeCache.begin();
    1.34 +    while (i != mIndexRangeCache.end())
    1.35 +    {
    1.36 +        unsigned int rangeStart = i->second.streamOffset;
    1.37 +        unsigned int rangeEnd = i->second.streamOffset + (gl::ComputeTypeSize(i->first.type) * i->first.count);
    1.38 +
    1.39 +        if (invalidateEnd < rangeStart || invalidateStart > rangeEnd)
    1.40 +        {
    1.41 +            ++i;
    1.42 +        }
    1.43 +        else
    1.44 +        {
    1.45 +            i = mIndexRangeCache.erase(i);
    1.46 +        }
    1.47 +    }
    1.48 +}
    1.49 +
    1.50 +bool IndexRangeCache::findRange(GLenum type, intptr_t offset, GLsizei count, unsigned int *outMinIndex,
    1.51 +                                unsigned int *outMaxIndex, unsigned int *outStreamOffset) const
    1.52 +{
    1.53 +    IndexRangeMap::const_iterator i = mIndexRangeCache.find(IndexRange(type, offset, count));
    1.54 +    if (i != mIndexRangeCache.end())
    1.55 +    {
    1.56 +        if (outMinIndex)     *outMinIndex = i->second.minIndex;
    1.57 +        if (outMaxIndex)     *outMaxIndex = i->second.maxIndex;
    1.58 +        if (outStreamOffset) *outStreamOffset = i->second.streamOffset;
    1.59 +        return true;
    1.60 +    }
    1.61 +    else
    1.62 +    {
    1.63 +        if (outMinIndex)     *outMinIndex = 0;
    1.64 +        if (outMaxIndex)     *outMaxIndex = 0;
    1.65 +        if (outStreamOffset) *outStreamOffset = 0;
    1.66 +        return false;
    1.67 +    }
    1.68 +}
    1.69 +
    1.70 +void IndexRangeCache::clear()
    1.71 +{
    1.72 +    mIndexRangeCache.clear();
    1.73 +}
    1.74 +
    1.75 +IndexRangeCache::IndexRange::IndexRange()
    1.76 +    : type(GL_NONE), offset(0), count(0)
    1.77 +{
    1.78 +}
    1.79 +
    1.80 +IndexRangeCache::IndexRange::IndexRange(GLenum typ, intptr_t off, GLsizei c)
    1.81 +    : type(typ), offset(off), count(c)
    1.82 +{
    1.83 +}
    1.84 +
    1.85 +bool IndexRangeCache::IndexRange::operator<(const IndexRange& rhs) const
    1.86 +{
    1.87 +    return std::make_tuple(type, offset, count) < std::make_tuple(rhs.type, rhs.offset, rhs.count);
    1.88 +}
    1.89 +
    1.90 +IndexRangeCache::IndexBounds::IndexBounds()
    1.91 +    : minIndex(0), maxIndex(0), streamOffset(0)
    1.92 +{
    1.93 +}
    1.94 +
    1.95 +IndexRangeCache::IndexBounds::IndexBounds(unsigned int minIdx, unsigned int maxIdx, unsigned int offset)
    1.96 +    : minIndex(minIdx), maxIndex(maxIdx), streamOffset(offset)
    1.97 +{
    1.98 +}
    1.99 +
   1.100 +}

mercurial