Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(505)

Unified Diff: src/utils/win/SkWGL_win.cpp

Issue 15070011: One SkTSearch to rule them all. Allow key to be of different type than the array. (Closed) Base URL: https://skia.googlecode.com/svn/trunk
Patch Set: fixes to compile on gcc Created 7 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « src/sfnt/SkOTTable_name.cpp ('k') | tests/FlatDataTest.cpp » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: src/utils/win/SkWGL_win.cpp
diff --git a/src/utils/win/SkWGL_win.cpp b/src/utils/win/SkWGL_win.cpp
index dabe13637336f53f5b2c7ff59a2237ef75b651b2..f20262b81840eba6b7416872eca6c44194bd3cf2 100644
--- a/src/utils/win/SkWGL_win.cpp
+++ b/src/utils/win/SkWGL_win.cpp
@@ -10,6 +10,7 @@
#include "SkTDArray.h"
#include "SkTSearch.h"
+#include "SkTSort.h"
bool SkWGLExtensions::hasExtension(HDC dc, const char* ext) const {
if (NULL == this->fGetExtensionsString) {
@@ -83,21 +84,19 @@ struct PixelFormat {
int fChoosePixelFormatRank;
};
-int compare_pf(const PixelFormat* a, const PixelFormat* b) {
- if (a->fCoverageSamples < b->fCoverageSamples) {
- return -1;
- } else if (b->fCoverageSamples < a->fCoverageSamples) {
- return 1;
- } else if (a->fColorSamples < b->fColorSamples) {
- return -1;
- } else if (b->fColorSamples < a->fColorSamples) {
- return 1;
- } else if (a->fChoosePixelFormatRank < b->fChoosePixelFormatRank) {
- return -1;
- } else if (b->fChoosePixelFormatRank < a->fChoosePixelFormatRank) {
- return 1;
+bool pf_less(const PixelFormat& a, const PixelFormat& b) {
+ if (a.fCoverageSamples < b.fCoverageSamples) {
+ return true;
+ } else if (b.fCoverageSamples < a.fCoverageSamples) {
+ return false;
+ } else if (a.fColorSamples < b.fColorSamples) {
+ return true;
+ } else if (b.fColorSamples < a.fColorSamples) {
+ return false;
+ } else if (a.fChoosePixelFormatRank < b.fChoosePixelFormatRank) {
+ return true;
}
- return 0;
+ return false;
}
}
@@ -136,15 +135,13 @@ int SkWGLExtensions::selectFormat(const int formats[],
rankedFormats[i].fColorSamples = answers[supportsCoverage ? 1 : 0];
rankedFormats[i].fChoosePixelFormatRank = i;
}
- qsort(rankedFormats.begin(),
- rankedFormats.count(),
- sizeof(PixelFormat),
- SkCastForQSort(compare_pf));
- int idx = SkTSearch<PixelFormat>(rankedFormats.begin(),
- rankedFormats.count(),
- desiredFormat,
- sizeof(PixelFormat),
- compare_pf);
+ SkTQSort(rankedFormats.begin(),
+ rankedFormats.begin() + rankedFormats.count() - 1,
+ SkTLessFunctionToFunctorAdaptor<PixelFormat, pf_less>());
+ int idx = SkTSearch<PixelFormat, pf_less>(rankedFormats.begin(),
+ rankedFormats.count(),
+ desiredFormat,
+ sizeof(PixelFormat));
if (idx < 0) {
idx = ~idx;
}
« no previous file with comments | « src/sfnt/SkOTTable_name.cpp ('k') | tests/FlatDataTest.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698