зеркало из https://github.com/mozilla/moz-skia.git
Add coverage AA support for SampleApp root layers (windows only)
Review URL: http://codereview.appspot.com/6043045/ git-svn-id: http://skia.googlecode.com/svn/trunk@3703 2bbb7eff-a529-9590-31e7-b0007b416f81
This commit is contained in:
Родитель
78e17130f3
Коммит
8a189b0632
|
@ -43,6 +43,8 @@
|
|||
#define SK_WGL_FULL_ACCELERATION 0x2027
|
||||
#define SK_WGL_SAMPLE_BUFFERS 0x2041
|
||||
#define SK_WGL_SAMPLES 0x2042
|
||||
#define SK_WGL_COVERAGE_SAMPLES 0x2042 /* same as SAMPLES */
|
||||
#define SK_WGL_COLOR_SAMPLES 0x20B9
|
||||
#define SK_WGL_CONTEXT_MAJOR_VERSION 0x2091
|
||||
#define SK_WGL_CONTEXT_MINOR_VERSION 0x2092
|
||||
#define SK_WGL_CONTEXT_LAYER_PLANE 0x2093
|
||||
|
@ -73,6 +75,23 @@ public:
|
|||
BOOL getPixelFormatAttribfv(HDC hdc, int, int, UINT, const int*, FLOAT*) const;
|
||||
HGLRC createContextAttribs(HDC, HGLRC, const int *) const;
|
||||
|
||||
/**
|
||||
* WGL doesn't have precise rules for the ordering of formats returned
|
||||
* by wglChoosePixelFormat. This function helps choose among the set of
|
||||
* formats returned by wglChoosePixelFormat. The rules in decreasing
|
||||
* priority are:
|
||||
* * Choose formats with the smallest sample count that is >=
|
||||
* desiredSampleCount (or the largest sample count if all formats have
|
||||
* fewer samples than desiredSampleCount.)
|
||||
* * Choose formats with the fewest color samples when coverage sampling
|
||||
* is available.
|
||||
* * If the above rules leave multiple formats, choose the one that
|
||||
* appears first in the formats array parameter.
|
||||
*/
|
||||
int selectFormat(const int formats[],
|
||||
int formatCount,
|
||||
HDC dc,
|
||||
int desiredSampleCount);
|
||||
private:
|
||||
typedef const char* (WINAPI *GetExtensionsStringProc)(HDC hdc);
|
||||
typedef BOOL (WINAPI *ChoosePixelFormatProc)(HDC hdc, const int *, const FLOAT *, UINT, int *, UINT *);
|
||||
|
|
|
@ -8,6 +8,9 @@
|
|||
|
||||
#include "SkWGL.h"
|
||||
|
||||
#include "SkTDArray.h"
|
||||
#include "SkTSearch.h"
|
||||
|
||||
bool SkWGLExtensions::hasExtension(HDC dc, const char* ext) const {
|
||||
if (NULL == this->fGetExtensionsString) {
|
||||
return false;
|
||||
|
@ -71,6 +74,81 @@ HGLRC SkWGLExtensions::createContextAttribs(HDC hDC,
|
|||
return fCreateContextAttribs(hDC, hShareContext, attribList);
|
||||
}
|
||||
|
||||
namespace {
|
||||
|
||||
struct PixelFormat {
|
||||
int fFormat;
|
||||
int fCoverageSamples;
|
||||
int fColorSamples;
|
||||
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;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
int SkWGLExtensions::selectFormat(const int formats[],
|
||||
int formatCount,
|
||||
HDC dc,
|
||||
int desiredSampleCount) {
|
||||
PixelFormat desiredFormat = {
|
||||
0,
|
||||
desiredSampleCount,
|
||||
0,
|
||||
0,
|
||||
};
|
||||
SkTDArray<PixelFormat> rankedFormats;
|
||||
rankedFormats.setCount(formatCount);
|
||||
bool supportsCoverage = this->hasExtension(dc,
|
||||
"WGL_NV_multisample_coverage");
|
||||
for (int i = 0; i < formatCount; ++i) {
|
||||
static const int queryAttrs[] = {
|
||||
SK_WGL_COVERAGE_SAMPLES,
|
||||
SK_WGL_COLOR_SAMPLES,
|
||||
};
|
||||
int answers[2];
|
||||
int queryAttrCnt = supportsCoverage ? 2 : 1;
|
||||
this->getPixelFormatAttribiv(dc,
|
||||
formats[i],
|
||||
0,
|
||||
SK_ARRAY_COUNT(queryAttrs),
|
||||
queryAttrs,
|
||||
answers);
|
||||
rankedFormats[i].fFormat = formats[i];
|
||||
rankedFormats[i].fCoverageSamples = answers[0];
|
||||
rankedFormats[i].fColorSamples = answers[supportsCoverage ? 1 : 0];
|
||||
rankedFormats[i].fChoosePixelFormatRank = i;
|
||||
}
|
||||
SkQSort(rankedFormats.begin(),
|
||||
rankedFormats.count(),
|
||||
sizeof(PixelFormat),
|
||||
(SkQSortCompareProc)compare_pf);
|
||||
int idx = SkTSearch<PixelFormat>(rankedFormats.begin(),
|
||||
rankedFormats.count(),
|
||||
desiredFormat,
|
||||
sizeof(PixelFormat),
|
||||
compare_pf);
|
||||
if (idx < 0) {
|
||||
idx = ~idx;
|
||||
}
|
||||
return rankedFormats[idx].fFormat;
|
||||
}
|
||||
|
||||
|
||||
namespace {
|
||||
|
||||
#if defined(UNICODE)
|
||||
|
|
|
@ -305,9 +305,6 @@ void SkEvent::SignalQueueTimer(SkMSec delay)
|
|||
}
|
||||
}
|
||||
|
||||
|
||||
#define USE_MSAA 0
|
||||
|
||||
HGLRC create_gl(HWND hwnd, int msaaSampleCount) {
|
||||
|
||||
HDC dc = GetDC(hwnd);
|
||||
|
@ -339,7 +336,7 @@ HGLRC create_gl(HWND hwnd, int msaaSampleCount) {
|
|||
if (msaaSampleCount > 0 &&
|
||||
extensions.hasExtension(dc, "WGL_ARB_multisample")) {
|
||||
static const int kIAttrsCount = SK_ARRAY_COUNT(iAttrs);
|
||||
GLint msaaIAttrs[kIAttrsCount + 4];
|
||||
GLint msaaIAttrs[kIAttrsCount + 6];
|
||||
memcpy(msaaIAttrs, iAttrs, sizeof(GLint) * kIAttrsCount);
|
||||
SkASSERT(0 == msaaIAttrs[kIAttrsCount - 2] &&
|
||||
0 == msaaIAttrs[kIAttrsCount - 1]);
|
||||
|
@ -347,18 +344,29 @@ HGLRC create_gl(HWND hwnd, int msaaSampleCount) {
|
|||
msaaIAttrs[kIAttrsCount - 1] = TRUE;
|
||||
msaaIAttrs[kIAttrsCount + 0] = SK_WGL_SAMPLES;
|
||||
msaaIAttrs[kIAttrsCount + 1] = msaaSampleCount;
|
||||
if (extensions.hasExtension(dc, "WGL_NV_multisample_coverage")) {
|
||||
msaaIAttrs[kIAttrsCount + 2] = SK_WGL_COLOR_SAMPLES;
|
||||
// We want the fewest number of color samples possible.
|
||||
// Passing 0 gives only the formats where all samples are color
|
||||
// samples.
|
||||
msaaIAttrs[kIAttrsCount + 3] = 1;
|
||||
msaaIAttrs[kIAttrsCount + 4] = 0;
|
||||
msaaIAttrs[kIAttrsCount + 5] = 0;
|
||||
} else {
|
||||
msaaIAttrs[kIAttrsCount + 2] = 0;
|
||||
msaaIAttrs[kIAttrsCount + 3] = 0;
|
||||
}
|
||||
GLuint num;
|
||||
int formats[64];
|
||||
extensions.choosePixelFormat(dc, msaaIAttrs, fAttrs, 64, formats, &num);
|
||||
num = min(num,64);
|
||||
for (GLuint i = 0; i < num; ++i) {
|
||||
DescribePixelFormat(dc, formats[i], sizeof(pfd), &pfd);
|
||||
if (SetPixelFormat(dc, formats[i], &pfd)) {
|
||||
format = formats[i];
|
||||
break;
|
||||
}
|
||||
int formatToTry = extensions.selectFormat(formats,
|
||||
num,
|
||||
dc,
|
||||
msaaSampleCount);
|
||||
DescribePixelFormat(dc, formatToTry, sizeof(pfd), &pfd);
|
||||
if (SetPixelFormat(dc, formatToTry, &pfd)) {
|
||||
format = formatToTry;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Загрузка…
Ссылка в новой задаче