OLD | NEW |
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 |
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
72 HGLRC SkWGLExtensions::createContextAttribs(HDC hDC, | 72 HGLRC SkWGLExtensions::createContextAttribs(HDC hDC, |
73 HGLRC hShareContext, | 73 HGLRC hShareContext, |
74 const int *attribList) const { | 74 const int *attribList) const { |
75 return fCreateContextAttribs(hDC, hShareContext, attribList); | 75 return fCreateContextAttribs(hDC, hShareContext, attribList); |
76 } | 76 } |
77 | 77 |
78 namespace { | 78 namespace { |
79 | 79 |
80 struct PixelFormat { | 80 struct PixelFormat { |
81 int fFormat; | 81 int fFormat; |
82 int fCoverageSamples; | 82 int fSampleCnt; |
83 int fColorSamples; | |
84 int fChoosePixelFormatRank; | 83 int fChoosePixelFormatRank; |
85 }; | 84 }; |
86 | 85 |
87 bool pf_less(const PixelFormat& a, const PixelFormat& b) { | 86 bool pf_less(const PixelFormat& a, const PixelFormat& b) { |
88 if (a.fCoverageSamples < b.fCoverageSamples) { | 87 if (a.fSampleCnt < b.fSampleCnt) { |
89 return true; | 88 return true; |
90 } else if (b.fCoverageSamples < a.fCoverageSamples) { | 89 } else if (b.fSampleCnt < a.fSampleCnt) { |
91 return false; | |
92 } else if (a.fColorSamples < b.fColorSamples) { | |
93 return true; | |
94 } else if (b.fColorSamples < a.fColorSamples) { | |
95 return false; | 90 return false; |
96 } else if (a.fChoosePixelFormatRank < b.fChoosePixelFormatRank) { | 91 } else if (a.fChoosePixelFormatRank < b.fChoosePixelFormatRank) { |
97 return true; | 92 return true; |
98 } | 93 } |
99 return false; | 94 return false; |
100 } | 95 } |
101 } | 96 } |
102 | 97 |
103 int SkWGLExtensions::selectFormat(const int formats[], | 98 int SkWGLExtensions::selectFormat(const int formats[], |
104 int formatCount, | 99 int formatCount, |
105 HDC dc, | 100 HDC dc, |
106 int desiredSampleCount) { | 101 int desiredSampleCount) { |
107 PixelFormat desiredFormat = { | 102 PixelFormat desiredFormat = { |
108 0, | 103 0, |
109 desiredSampleCount, | 104 desiredSampleCount, |
110 0, | 105 0, |
111 0, | |
112 }; | 106 }; |
113 SkTDArray<PixelFormat> rankedFormats; | 107 SkTDArray<PixelFormat> rankedFormats; |
114 rankedFormats.setCount(formatCount); | 108 rankedFormats.setCount(formatCount); |
115 bool supportsCoverage = this->hasExtension(dc, | |
116 "WGL_NV_multisample_coverage"); | |
117 for (int i = 0; i < formatCount; ++i) { | 109 for (int i = 0; i < formatCount; ++i) { |
118 static const int queryAttrs[] = { | 110 static const int kQueryAttr = SK_WGL_SAMPLES; |
119 SK_WGL_COVERAGE_SAMPLES, | 111 int numSamples; |
120 // Keep COLOR_SAMPLES at the end so it can be skipped | |
121 SK_WGL_COLOR_SAMPLES, | |
122 }; | |
123 int answers[2]; | |
124 int queryAttrCnt = supportsCoverage ? | |
125 SK_ARRAY_COUNT(queryAttrs) : | |
126 SK_ARRAY_COUNT(queryAttrs) - 1; | |
127 this->getPixelFormatAttribiv(dc, | 112 this->getPixelFormatAttribiv(dc, |
128 formats[i], | 113 formats[i], |
129 0, | 114 0, |
130 queryAttrCnt, | 115 1, |
131 queryAttrs, | 116 &kQueryAttr, |
132 answers); | 117 &numSamples); |
133 rankedFormats[i].fFormat = formats[i]; | 118 rankedFormats[i].fFormat = formats[i]; |
134 rankedFormats[i].fCoverageSamples = answers[0]; | 119 rankedFormats[i].fSampleCnt = numSamples; |
135 rankedFormats[i].fColorSamples = answers[supportsCoverage ? 1 : 0]; | |
136 rankedFormats[i].fChoosePixelFormatRank = i; | 120 rankedFormats[i].fChoosePixelFormatRank = i; |
137 } | 121 } |
138 SkTQSort(rankedFormats.begin(), | 122 SkTQSort(rankedFormats.begin(), |
139 rankedFormats.begin() + rankedFormats.count() - 1, | 123 rankedFormats.begin() + rankedFormats.count() - 1, |
140 SkTLessFunctionToFunctorAdaptor<PixelFormat, pf_less>()); | 124 SkTLessFunctionToFunctorAdaptor<PixelFormat, pf_less>()); |
141 int idx = SkTSearch<PixelFormat, pf_less>(rankedFormats.begin(), | 125 int idx = SkTSearch<PixelFormat, pf_less>(rankedFormats.begin(), |
142 rankedFormats.count(), | 126 rankedFormats.count(), |
143 desiredFormat, | 127 desiredFormat, |
144 sizeof(PixelFormat)); | 128 sizeof(PixelFormat)); |
145 if (idx < 0) { | 129 if (idx < 0) { |
(...skipping 136 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
282 SK_WGL_ALPHA_BITS, 8, | 266 SK_WGL_ALPHA_BITS, 8, |
283 SK_WGL_STENCIL_BITS, 8, | 267 SK_WGL_STENCIL_BITS, 8, |
284 0, 0 | 268 0, 0 |
285 }; | 269 }; |
286 | 270 |
287 float fAttrs[] = {0, 0}; | 271 float fAttrs[] = {0, 0}; |
288 | 272 |
289 if (msaaSampleCount > 0 && | 273 if (msaaSampleCount > 0 && |
290 extensions.hasExtension(dc, "WGL_ARB_multisample")) { | 274 extensions.hasExtension(dc, "WGL_ARB_multisample")) { |
291 static const int kIAttrsCount = SK_ARRAY_COUNT(iAttrs); | 275 static const int kIAttrsCount = SK_ARRAY_COUNT(iAttrs); |
292 int msaaIAttrs[kIAttrsCount + 6]; | 276 int msaaIAttrs[kIAttrsCount + 4]; |
293 memcpy(msaaIAttrs, iAttrs, sizeof(int) * kIAttrsCount); | 277 memcpy(msaaIAttrs, iAttrs, sizeof(int) * kIAttrsCount); |
294 SkASSERT(0 == msaaIAttrs[kIAttrsCount - 2] && | 278 SkASSERT(0 == msaaIAttrs[kIAttrsCount - 2] && |
295 0 == msaaIAttrs[kIAttrsCount - 1]); | 279 0 == msaaIAttrs[kIAttrsCount - 1]); |
296 msaaIAttrs[kIAttrsCount - 2] = SK_WGL_SAMPLE_BUFFERS; | 280 msaaIAttrs[kIAttrsCount - 2] = SK_WGL_SAMPLE_BUFFERS; |
297 msaaIAttrs[kIAttrsCount - 1] = TRUE; | 281 msaaIAttrs[kIAttrsCount - 1] = TRUE; |
298 msaaIAttrs[kIAttrsCount + 0] = SK_WGL_SAMPLES; | 282 msaaIAttrs[kIAttrsCount + 0] = SK_WGL_SAMPLES; |
299 msaaIAttrs[kIAttrsCount + 1] = msaaSampleCount; | 283 msaaIAttrs[kIAttrsCount + 1] = msaaSampleCount; |
300 if (extensions.hasExtension(dc, "WGL_NV_multisample_coverage")) { | 284 msaaIAttrs[kIAttrsCount + 2] = 0; |
301 msaaIAttrs[kIAttrsCount + 2] = SK_WGL_COLOR_SAMPLES; | 285 msaaIAttrs[kIAttrsCount + 3] = 0; |
302 // We want the fewest number of color samples possible. | |
303 // Passing 0 gives only the formats where all samples are color | |
304 // samples. | |
305 msaaIAttrs[kIAttrsCount + 3] = 1; | |
306 msaaIAttrs[kIAttrsCount + 4] = 0; | |
307 msaaIAttrs[kIAttrsCount + 5] = 0; | |
308 } else { | |
309 msaaIAttrs[kIAttrsCount + 2] = 0; | |
310 msaaIAttrs[kIAttrsCount + 3] = 0; | |
311 } | |
312 unsigned int num; | 286 unsigned int num; |
313 int formats[64]; | 287 int formats[64]; |
314 extensions.choosePixelFormat(dc, msaaIAttrs, fAttrs, 64, formats, &num); | 288 extensions.choosePixelFormat(dc, msaaIAttrs, fAttrs, 64, formats, &num); |
315 num = SkTMin(num, 64U); | 289 num = SkTMin(num, 64U); |
316 int formatToTry = extensions.selectFormat(formats, | 290 int formatToTry = extensions.selectFormat(formats, |
317 num, | 291 num, |
318 dc, | 292 dc, |
319 msaaSampleCount); | 293 msaaSampleCount); |
320 DescribePixelFormat(dc, formatToTry, sizeof(pfd), &pfd); | 294 DescribePixelFormat(dc, formatToTry, sizeof(pfd), &pfd); |
321 if (SetPixelFormat(dc, formatToTry, &pfd)) { | 295 if (SetPixelFormat(dc, formatToTry, &pfd)) { |
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
359 } | 333 } |
360 | 334 |
361 if (NULL == glrc) { | 335 if (NULL == glrc) { |
362 glrc = wglCreateContext(dc); | 336 glrc = wglCreateContext(dc); |
363 } | 337 } |
364 SkASSERT(glrc); | 338 SkASSERT(glrc); |
365 | 339 |
366 wglMakeCurrent(prevDC, prevGLRC); | 340 wglMakeCurrent(prevDC, prevGLRC); |
367 return glrc; | 341 return glrc; |
368 } | 342 } |
OLD | NEW |