Upstream version 10.39.225.0
[platform/framework/web/crosswalk.git] / src / third_party / angle / src / libGLESv2 / renderer / IndexRangeCache.cpp
index 4fdb0ca..d472e14 100644 (file)
@@ -1,4 +1,3 @@
-#include "precompiled.h"
 //
 // Copyright (c) 2013 The ANGLE Project Authors. All rights reserved.
 // Use of this source code is governed by a BSD-style license that can be
 
 #include "libGLESv2/renderer/IndexRangeCache.h"
 #include "libGLESv2/formatutils.h"
+
 #include "common/debug.h"
+
 #include <tuple>
 
 namespace rx
 {
 
-void IndexRangeCache::addRange(GLenum type, unsigned int offset, GLsizei count, unsigned int minIdx, unsigned int maxIdx,
+template <class IndexType>
+static RangeUI ComputeTypedRange(const IndexType *indices, GLsizei count)
+{
+    unsigned int minIndex = indices[0];
+    unsigned int maxIndex = indices[0];
+
+    for (GLsizei i = 1; i < count; i++)
+    {
+        if (minIndex > indices[i]) minIndex = indices[i];
+        if (maxIndex < indices[i]) maxIndex = indices[i];
+    }
+
+    return RangeUI(minIndex, maxIndex);
+}
+
+RangeUI IndexRangeCache::ComputeRange(GLenum type, const GLvoid *indices, GLsizei count)
+{
+    switch (type)
+    {
+      case GL_UNSIGNED_BYTE:
+        return ComputeTypedRange(static_cast<const GLubyte*>(indices), count);
+      case GL_UNSIGNED_INT:
+        return ComputeTypedRange(static_cast<const GLuint*>(indices), count);
+      case GL_UNSIGNED_SHORT:
+        return ComputeTypedRange(static_cast<const GLushort*>(indices), count);
+      default:
+        UNREACHABLE();
+        return RangeUI();
+    }
+}
+
+void IndexRangeCache::addRange(GLenum type, unsigned int offset, GLsizei count, const RangeUI &range,
                                unsigned int streamOffset)
 {
-    mIndexRangeCache[IndexRange(type, offset, count)] = IndexBounds(minIdx, maxIdx, streamOffset);
+    mIndexRangeCache[IndexRange(type, offset, count)] = IndexBounds(range, streamOffset);
 }
 
 void IndexRangeCache::invalidateRange(unsigned int offset, unsigned int size)
@@ -44,21 +76,19 @@ void IndexRangeCache::invalidateRange(unsigned int offset, unsigned int size)
     }
 }
 
-bool IndexRangeCache::findRange(GLenum type, unsigned int offset, GLsizei count, unsigned int *outMinIndex,
-                                unsigned int *outMaxIndex, unsigned int *outStreamOffset) const
+bool IndexRangeCache::findRange(GLenum type, unsigned int offset, GLsizei count,
+                                RangeUI *outRange, unsigned int *outStreamOffset) const
 {
     IndexRangeMap::const_iterator i = mIndexRangeCache.find(IndexRange(type, offset, count));
     if (i != mIndexRangeCache.end())
     {
-        if (outMinIndex)     *outMinIndex = i->second.minIndex;
-        if (outMaxIndex)     *outMaxIndex = i->second.maxIndex;
+        if (outRange)        *outRange = i->second.range;
         if (outStreamOffset) *outStreamOffset = i->second.streamOffset;
         return true;
     }
     else
     {
-        if (outMinIndex)     *outMinIndex = 0;
-        if (outMaxIndex)     *outMaxIndex = 0;
+        if (outRange)        *outRange = RangeUI(0, 0);
         if (outStreamOffset) *outStreamOffset = 0;
         return false;
     }
@@ -85,12 +115,13 @@ bool IndexRangeCache::IndexRange::operator<(const IndexRange& rhs) const
 }
 
 IndexRangeCache::IndexBounds::IndexBounds()
-    : minIndex(0), maxIndex(0), streamOffset(0)
+    : range(0, 0),
+      streamOffset(0)
 {
 }
 
-IndexRangeCache::IndexBounds::IndexBounds(unsigned int minIdx, unsigned int maxIdx, unsigned int offset)
-    : minIndex(minIdx), maxIndex(maxIdx), streamOffset(offset)
+IndexRangeCache::IndexBounds::IndexBounds(const RangeUI &rangeIn, unsigned int offset)
+    : range(rangeIn), streamOffset(offset)
 {
 }