diff options
author | 2013-05-17 19:05:03 +0000 | |
---|---|---|
committer | 2013-05-17 19:05:03 +0000 | |
commit | 20f7f173e05b60f541910d0c1da9850ac73e2958 (patch) | |
tree | 6d06f639a90e18a85b6188eed1a15854b96888fd /src/gpu | |
parent | d7c37425805d5909ed5601bf2fbf14d5c8b4c86b (diff) |
One SkTSearch to rule them all. Allow key to be of different type than the array.
R=bungeman@google.com
Review URL: https://codereview.chromium.org/15070011
git-svn-id: http://skia.googlecode.com/svn/trunk@9182 2bbb7eff-a529-9590-31e7-b0007b416f81
Diffstat (limited to 'src/gpu')
-rw-r--r-- | src/gpu/effects/GrTextureStripAtlas.cpp | 11 | ||||
-rw-r--r-- | src/gpu/effects/GrTextureStripAtlas.h | 4 | ||||
-rw-r--r-- | src/gpu/gl/GrGLCaps.cpp | 39 | ||||
-rw-r--r-- | src/gpu/gl/GrGLExtensions.cpp | 6 |
4 files changed, 30 insertions, 30 deletions
diff --git a/src/gpu/effects/GrTextureStripAtlas.cpp b/src/gpu/effects/GrTextureStripAtlas.cpp index f726b25cf9..8e9e1556c7 100644 --- a/src/gpu/effects/GrTextureStripAtlas.cpp +++ b/src/gpu/effects/GrTextureStripAtlas.cpp @@ -273,11 +273,12 @@ void GrTextureStripAtlas::removeFromLRU(AtlasRow* row) { int GrTextureStripAtlas::searchByKey(uint32_t key) { AtlasRow target; target.fKey = key; - return SkTSearch<AtlasRow, GrTextureStripAtlas::compareKeys>((const AtlasRow**)fKeyTable.begin(), - fKeyTable.count(), - &target, - sizeof(AtlasRow*)); -} + return SkTSearch<const AtlasRow, + GrTextureStripAtlas::KeyLess>((const AtlasRow**)fKeyTable.begin(), + fKeyTable.count(), + &target, + sizeof(AtlasRow*)); +} #ifdef SK_DEBUG void GrTextureStripAtlas::validate() { diff --git a/src/gpu/effects/GrTextureStripAtlas.h b/src/gpu/effects/GrTextureStripAtlas.h index 9ac356b4cc..0148665a4c 100644 --- a/src/gpu/effects/GrTextureStripAtlas.h +++ b/src/gpu/effects/GrTextureStripAtlas.h @@ -120,8 +120,8 @@ private: /** * Compare two atlas rows by key, so we can sort/search by key */ - static int compareKeys(const AtlasRow* lhs, const AtlasRow* rhs) { - return lhs->fKey - rhs->fKey; + static bool KeyLess(const AtlasRow& lhs, const AtlasRow& rhs) { + return lhs.fKey < rhs.fKey; } #ifdef SK_DEBUG diff --git a/src/gpu/gl/GrGLCaps.cpp b/src/gpu/gl/GrGLCaps.cpp index 5568c48123..8b296e360b 100644 --- a/src/gpu/gl/GrGLCaps.cpp +++ b/src/gpu/gl/GrGLCaps.cpp @@ -9,6 +9,7 @@ #include "GrGLCaps.h" #include "GrGLContext.h" #include "SkTSearch.h" +#include "SkTSort.h" SK_DEFINE_INST_COUNT(GrGLCaps) @@ -335,18 +336,16 @@ bool GrGLCaps::readPixelsSupported(const GrGLInterface* intf, } namespace { -int coverage_mode_compare(const GrGLCaps::MSAACoverageMode* left, - const GrGLCaps::MSAACoverageMode* right) { - if (left->fCoverageSampleCnt < right->fCoverageSampleCnt) { - return -1; - } else if (right->fCoverageSampleCnt < left->fCoverageSampleCnt) { - return 1; - } else if (left->fColorSampleCnt < right->fColorSampleCnt) { - return -1; - } else if (right->fColorSampleCnt < left->fColorSampleCnt) { - return 1; +bool cov_mode_less(const GrGLCaps::MSAACoverageMode& left, + const GrGLCaps::MSAACoverageMode& right) { + if (left.fCoverageSampleCnt < right.fCoverageSampleCnt) { + return true; + } else if (right.fCoverageSampleCnt < left.fCoverageSampleCnt) { + return false; + } else if (left.fColorSampleCnt < right.fColorSampleCnt) { + return true; } - return 0; + return false; } } @@ -389,10 +388,11 @@ void GrGLCaps::initFSAASupport(const GrGLContextInfo& ctxInfo, const GrGLInterfa (int*)&fMSAACoverageModes[0]); // The NV driver seems to return the modes already sorted but the // spec doesn't require this. So we sort. - qsort(&fMSAACoverageModes[0], - count, - sizeof(MSAACoverageMode), - SkCastForQSort(coverage_mode_compare)); + typedef SkTLessFunctionToFunctorAdaptor<MSAACoverageMode, cov_mode_less> SortFunctor; + SortFunctor sortFunctor; + SkTQSort<MSAACoverageMode, SortFunctor>(fMSAACoverageModes.begin(), + fMSAACoverageModes.end() - 1, + sortFunctor); } } } @@ -406,11 +406,10 @@ const GrGLCaps::MSAACoverageMode& GrGLCaps::getMSAACoverageMode(int desiredSampl int max = (fMSAACoverageModes.end() - 1)->fCoverageSampleCnt; desiredSampleCount = GrMin(desiredSampleCount, max); MSAACoverageMode desiredMode = {desiredSampleCount, 0}; - int idx = SkTSearch<MSAACoverageMode>(&fMSAACoverageModes[0], - fMSAACoverageModes.count(), - desiredMode, - sizeof(MSAACoverageMode), - &coverage_mode_compare); + int idx = SkTSearch<const MSAACoverageMode, cov_mode_less>(&fMSAACoverageModes[0], + fMSAACoverageModes.count(), + desiredMode, + sizeof(MSAACoverageMode)); if (idx < 0) { idx = ~idx; } diff --git a/src/gpu/gl/GrGLExtensions.cpp b/src/gpu/gl/GrGLExtensions.cpp index a071923527..633796ded8 100644 --- a/src/gpu/gl/GrGLExtensions.cpp +++ b/src/gpu/gl/GrGLExtensions.cpp @@ -13,8 +13,8 @@ #include "SkTSort.h" namespace { -inline int extension_compare(const SkString* a, const SkString* b) { - return strcmp(a->c_str(), b->c_str()); +inline bool extension_compare(const SkString& a, const SkString& b) { + return strcmp(a.c_str(), b.c_str()) < 0; } } @@ -67,7 +67,7 @@ bool GrGLExtensions::init(GrGLBinding binding, } } if (0 != fStrings.count()) { - SkTSearchCompareLTFunctor<SkString, extension_compare> cmp; + SkTLessFunctionToFunctorAdaptor<SkString, extension_compare> cmp; SkTQSort(&fStrings.front(), &fStrings.back(), cmp); } return true; |