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

Side by Side 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 unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « src/sfnt/SkOTTable_name.cpp ('k') | tests/FlatDataTest.cpp » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 1
2 /* 2 /*
3 * Copyright 2011 Google Inc. 3 * Copyright 2011 Google Inc.
4 * 4 *
5 * Use of this source code is governed by a BSD-style license that can be 5 * Use of this source code is governed by a BSD-style license that can be
6 * found in the LICENSE file. 6 * found in the LICENSE file.
7 */ 7 */
8 8
9 #include "SkWGL.h" 9 #include "SkWGL.h"
10 10
11 #include "SkTDArray.h" 11 #include "SkTDArray.h"
12 #include "SkTSearch.h" 12 #include "SkTSearch.h"
13 #include "SkTSort.h"
13 14
14 bool SkWGLExtensions::hasExtension(HDC dc, const char* ext) const { 15 bool SkWGLExtensions::hasExtension(HDC dc, const char* ext) const {
15 if (NULL == this->fGetExtensionsString) { 16 if (NULL == this->fGetExtensionsString) {
16 return false; 17 return false;
17 } 18 }
18 if (!strcmp("WGL_ARB_extensions_string", ext)) { 19 if (!strcmp("WGL_ARB_extensions_string", ext)) {
19 return true; 20 return true;
20 } 21 }
21 const char* extensionString = this->getExtensionsString(dc); 22 const char* extensionString = this->getExtensionsString(dc);
22 int extLength = strlen(ext); 23 int extLength = strlen(ext);
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after
76 77
77 namespace { 78 namespace {
78 79
79 struct PixelFormat { 80 struct PixelFormat {
80 int fFormat; 81 int fFormat;
81 int fCoverageSamples; 82 int fCoverageSamples;
82 int fColorSamples; 83 int fColorSamples;
83 int fChoosePixelFormatRank; 84 int fChoosePixelFormatRank;
84 }; 85 };
85 86
86 int compare_pf(const PixelFormat* a, const PixelFormat* b) { 87 bool pf_less(const PixelFormat& a, const PixelFormat& b) {
87 if (a->fCoverageSamples < b->fCoverageSamples) { 88 if (a.fCoverageSamples < b.fCoverageSamples) {
88 return -1; 89 return true;
89 } else if (b->fCoverageSamples < a->fCoverageSamples) { 90 } else if (b.fCoverageSamples < a.fCoverageSamples) {
90 return 1; 91 return false;
91 } else if (a->fColorSamples < b->fColorSamples) { 92 } else if (a.fColorSamples < b.fColorSamples) {
92 return -1; 93 return true;
93 } else if (b->fColorSamples < a->fColorSamples) { 94 } else if (b.fColorSamples < a.fColorSamples) {
94 return 1; 95 return false;
95 } else if (a->fChoosePixelFormatRank < b->fChoosePixelFormatRank) { 96 } else if (a.fChoosePixelFormatRank < b.fChoosePixelFormatRank) {
96 return -1; 97 return true;
97 } else if (b->fChoosePixelFormatRank < a->fChoosePixelFormatRank) {
98 return 1;
99 } 98 }
100 return 0; 99 return false;
101 } 100 }
102 } 101 }
103 102
104 int SkWGLExtensions::selectFormat(const int formats[], 103 int SkWGLExtensions::selectFormat(const int formats[],
105 int formatCount, 104 int formatCount,
106 HDC dc, 105 HDC dc,
107 int desiredSampleCount) { 106 int desiredSampleCount) {
108 PixelFormat desiredFormat = { 107 PixelFormat desiredFormat = {
109 0, 108 0,
110 desiredSampleCount, 109 desiredSampleCount,
(...skipping 18 matching lines...) Expand all
129 formats[i], 128 formats[i],
130 0, 129 0,
131 queryAttrCnt, 130 queryAttrCnt,
132 queryAttrs, 131 queryAttrs,
133 answers); 132 answers);
134 rankedFormats[i].fFormat = formats[i]; 133 rankedFormats[i].fFormat = formats[i];
135 rankedFormats[i].fCoverageSamples = answers[0]; 134 rankedFormats[i].fCoverageSamples = answers[0];
136 rankedFormats[i].fColorSamples = answers[supportsCoverage ? 1 : 0]; 135 rankedFormats[i].fColorSamples = answers[supportsCoverage ? 1 : 0];
137 rankedFormats[i].fChoosePixelFormatRank = i; 136 rankedFormats[i].fChoosePixelFormatRank = i;
138 } 137 }
139 qsort(rankedFormats.begin(), 138 SkTQSort(rankedFormats.begin(),
140 rankedFormats.count(), 139 rankedFormats.begin() + rankedFormats.count() - 1,
141 sizeof(PixelFormat), 140 SkTLessFunctionToFunctorAdaptor<PixelFormat, pf_less>());
142 SkCastForQSort(compare_pf)); 141 int idx = SkTSearch<PixelFormat, pf_less>(rankedFormats.begin(),
143 int idx = SkTSearch<PixelFormat>(rankedFormats.begin(), 142 rankedFormats.count(),
144 rankedFormats.count(), 143 desiredFormat,
145 desiredFormat, 144 sizeof(PixelFormat));
146 sizeof(PixelFormat),
147 compare_pf);
148 if (idx < 0) { 145 if (idx < 0) {
149 idx = ~idx; 146 idx = ~idx;
150 } 147 }
151 return rankedFormats[idx].fFormat; 148 return rankedFormats[idx].fFormat;
152 } 149 }
153 150
154 151
155 namespace { 152 namespace {
156 153
157 #if defined(UNICODE) 154 #if defined(UNICODE)
(...skipping 204 matching lines...) Expand 10 before | Expand all | Expand 10 after
362 } 359 }
363 360
364 if (NULL == glrc) { 361 if (NULL == glrc) {
365 glrc = wglCreateContext(dc); 362 glrc = wglCreateContext(dc);
366 } 363 }
367 SkASSERT(glrc); 364 SkASSERT(glrc);
368 365
369 wglMakeCurrent(prevDC, prevGLRC); 366 wglMakeCurrent(prevDC, prevGLRC);
370 return glrc; 367 return glrc;
371 } 368 }
OLDNEW
« 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