aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/utils/win
diff options
context:
space:
mode:
Diffstat (limited to 'src/utils/win')
-rw-r--r--src/utils/win/SkWGL.h5
-rw-r--r--src/utils/win/SkWGL_win.cpp57
2 files changed, 35 insertions, 27 deletions
diff --git a/src/utils/win/SkWGL.h b/src/utils/win/SkWGL.h
index 5322d916b5..ebd95e7a83 100644
--- a/src/utils/win/SkWGL.h
+++ b/src/utils/win/SkWGL.h
@@ -37,6 +37,9 @@
#define SK_WGL_SUPPORT_OPENGL 0x2010
#define SK_WGL_DOUBLE_BUFFER 0x2011
#define SK_WGL_COLOR_BITS 0x2014
+#define SK_WGL_RED_BITS 0x2015
+#define SK_WGL_GREEN_BITS 0x2017
+#define SK_WGL_BLUE_BITS 0x2019
#define SK_WGL_ALPHA_BITS 0x201B
#define SK_WGL_STENCIL_BITS 0x2023
#define SK_WGL_FULL_ACCELERATION 0x2027
@@ -138,7 +141,7 @@ enum SkWGLContextRequest {
* (including non-MSAA) will be created. If preferCoreProfile is true but a core profile cannot be
* created then a compatible profile context will be created.
*/
-HGLRC SkCreateWGLContext(HDC dc, int msaaSampleCount, SkWGLContextRequest context);
+HGLRC SkCreateWGLContext(HDC dc, int msaaSampleCount, bool deepColor, SkWGLContextRequest context);
/**
* Helper class for creating a pbuffer context and deleting all the handles when finished. This
diff --git a/src/utils/win/SkWGL_win.cpp b/src/utils/win/SkWGL_win.cpp
index 65ffaf1ecf..dc1b4caf1a 100644
--- a/src/utils/win/SkWGL_win.cpp
+++ b/src/utils/win/SkWGL_win.cpp
@@ -288,38 +288,41 @@ SkWGLExtensions::SkWGLExtensions()
///////////////////////////////////////////////////////////////////////////////
static void get_pixel_formats_to_try(HDC dc, const SkWGLExtensions& extensions,
- bool doubleBuffered, int msaaSampleCount,
+ bool doubleBuffered, int msaaSampleCount, bool deepColor,
int formatsToTry[2]) {
- int iAttrs[] = {
- SK_WGL_DRAW_TO_WINDOW, TRUE,
- SK_WGL_DOUBLE_BUFFER, (doubleBuffered ? TRUE : FALSE),
- SK_WGL_ACCELERATION, SK_WGL_FULL_ACCELERATION,
- SK_WGL_SUPPORT_OPENGL, TRUE,
- SK_WGL_COLOR_BITS, 24,
- SK_WGL_ALPHA_BITS, 8,
- SK_WGL_STENCIL_BITS, 8,
- 0, 0
+ auto appendAttr = [](SkTDArray<int>& attrs, int attr, int value) {
+ attrs.push(attr);
+ attrs.push(value);
};
+ SkTDArray<int> iAttrs;
+ appendAttr(iAttrs, SK_WGL_DRAW_TO_WINDOW, TRUE);
+ appendAttr(iAttrs, SK_WGL_DOUBLE_BUFFER, (doubleBuffered ? TRUE : FALSE));
+ appendAttr(iAttrs, SK_WGL_ACCELERATION, SK_WGL_FULL_ACCELERATION);
+ appendAttr(iAttrs, SK_WGL_SUPPORT_OPENGL, TRUE);
+ if (deepColor) {
+ appendAttr(iAttrs, SK_WGL_RED_BITS, 10);
+ appendAttr(iAttrs, SK_WGL_GREEN_BITS, 10);
+ appendAttr(iAttrs, SK_WGL_BLUE_BITS, 10);
+ appendAttr(iAttrs, SK_WGL_ALPHA_BITS, 2);
+ } else {
+ appendAttr(iAttrs, SK_WGL_COLOR_BITS, 24);
+ appendAttr(iAttrs, SK_WGL_ALPHA_BITS, 8);
+ }
+ appendAttr(iAttrs, SK_WGL_STENCIL_BITS, 8);
+
float fAttrs[] = {0, 0};
// Get a MSAA format if requested and possible.
if (msaaSampleCount > 0 &&
extensions.hasExtension(dc, "WGL_ARB_multisample")) {
- static const int kIAttrsCount = SK_ARRAY_COUNT(iAttrs);
- int msaaIAttrs[kIAttrsCount + 4];
- memcpy(msaaIAttrs, iAttrs, sizeof(int) * kIAttrsCount);
- SkASSERT(0 == msaaIAttrs[kIAttrsCount - 2] &&
- 0 == msaaIAttrs[kIAttrsCount - 1]);
- msaaIAttrs[kIAttrsCount - 2] = SK_WGL_SAMPLE_BUFFERS;
- msaaIAttrs[kIAttrsCount - 1] = TRUE;
- msaaIAttrs[kIAttrsCount + 0] = SK_WGL_SAMPLES;
- msaaIAttrs[kIAttrsCount + 1] = msaaSampleCount;
- msaaIAttrs[kIAttrsCount + 2] = 0;
- msaaIAttrs[kIAttrsCount + 3] = 0;
+ SkTDArray<int> msaaIAttrs = iAttrs;
+ appendAttr(msaaIAttrs, SK_WGL_SAMPLE_BUFFERS, TRUE);
+ appendAttr(msaaIAttrs, SK_WGL_SAMPLES, msaaSampleCount);
+ appendAttr(msaaIAttrs, 0, 0);
unsigned int num;
int formats[64];
- extensions.choosePixelFormat(dc, msaaIAttrs, fAttrs, 64, formats, &num);
+ extensions.choosePixelFormat(dc, msaaIAttrs.begin(), fAttrs, 64, formats, &num);
num = SkTMin(num, 64U);
formatsToTry[0] = extensions.selectFormat(formats, num, dc, msaaSampleCount);
}
@@ -327,7 +330,8 @@ static void get_pixel_formats_to_try(HDC dc, const SkWGLExtensions& extensions,
// Get a non-MSAA format
int* format = -1 == formatsToTry[0] ? &formatsToTry[0] : &formatsToTry[1];
unsigned int num;
- extensions.choosePixelFormat(dc, iAttrs, fAttrs, 1, format, &num);
+ appendAttr(iAttrs, 0, 0);
+ extensions.choosePixelFormat(dc, iAttrs.begin(), fAttrs, 1, format, &num);
}
static HGLRC create_gl_context(HDC dc, SkWGLExtensions extensions, SkWGLContextRequest contextType) {
@@ -393,7 +397,8 @@ static HGLRC create_gl_context(HDC dc, SkWGLExtensions extensions, SkWGLContextR
return glrc;
}
-HGLRC SkCreateWGLContext(HDC dc, int msaaSampleCount, SkWGLContextRequest contextType) {
+HGLRC SkCreateWGLContext(HDC dc, int msaaSampleCount, bool deepColor,
+ SkWGLContextRequest contextType) {
SkWGLExtensions extensions;
if (!extensions.hasExtension(dc, "WGL_ARB_pixel_format")) {
return nullptr;
@@ -402,7 +407,7 @@ HGLRC SkCreateWGLContext(HDC dc, int msaaSampleCount, SkWGLContextRequest contex
BOOL set = FALSE;
int pixelFormatsToTry[] = { -1, -1 };
- get_pixel_formats_to_try(dc, extensions, true, msaaSampleCount, pixelFormatsToTry);
+ get_pixel_formats_to_try(dc, extensions, true, msaaSampleCount, deepColor, pixelFormatsToTry);
for (int f = 0;
!set && -1 != pixelFormatsToTry[f] && f < SK_ARRAY_COUNT(pixelFormatsToTry);
++f) {
@@ -429,7 +434,7 @@ SkWGLPbufferContext* SkWGLPbufferContext::Create(HDC parentDC, int msaaSampleCou
for (int dblBuffer = 0; dblBuffer < 2; ++dblBuffer) {
int pixelFormatsToTry[] = { -1, -1 };
get_pixel_formats_to_try(parentDC, extensions, (0 != dblBuffer), msaaSampleCount,
- pixelFormatsToTry);
+ false, pixelFormatsToTry);
for (int f = 0; -1 != pixelFormatsToTry[f] && f < SK_ARRAY_COUNT(pixelFormatsToTry); ++f) {
HPBUFFER pbuf = extensions.createPbuffer(parentDC, pixelFormatsToTry[f], 1, 1, nullptr);
if (0 != pbuf) {