diff options
-rw-r--r-- | src/utils/win/SkWGL.h | 4 | ||||
-rw-r--r-- | src/utils/win/SkWGL_win.cpp | 54 | ||||
-rw-r--r-- | tools/gpu/gl/win/CreatePlatformGLTestContext_win.cpp | 2 |
3 files changed, 40 insertions, 20 deletions
diff --git a/src/utils/win/SkWGL.h b/src/utils/win/SkWGL.h index 315be24cd9..c6c9479abe 100644 --- a/src/utils/win/SkWGL.h +++ b/src/utils/win/SkWGL.h @@ -143,8 +143,8 @@ HGLRC SkCreateWGLContext(HDC dc, int msaaSampleCount, bool deepColor, SkWGLConte */ class SkWGLPbufferContext : public SkRefCnt { public: - static SkWGLPbufferContext* Create(HDC parentDC, int msaaSampleCount, - SkWGLContextRequest contextType, HGLRC shareContext); + static SkWGLPbufferContext* Create(HDC parentDC, SkWGLContextRequest contextType, + HGLRC shareContext); virtual ~SkWGLPbufferContext(); diff --git a/src/utils/win/SkWGL_win.cpp b/src/utils/win/SkWGL_win.cpp index cc95f4988d..016b61b2bf 100644 --- a/src/utils/win/SkWGL_win.cpp +++ b/src/utils/win/SkWGL_win.cpp @@ -438,8 +438,7 @@ HGLRC SkCreateWGLContext(HDC dc, int msaaSampleCount, bool deepColor, return create_gl_context(dc, extensions, contextType, shareContext); } -SkWGLPbufferContext* SkWGLPbufferContext::Create(HDC parentDC, int msaaSampleCount, - SkWGLContextRequest contextType, +SkWGLPbufferContext* SkWGLPbufferContext::Create(HDC parentDC, SkWGLContextRequest contextType, HGLRC shareContext) { SkWGLExtensions extensions; if (!extensions.hasExtension(parentDC, "WGL_ARB_pixel_format") || @@ -447,24 +446,45 @@ SkWGLPbufferContext* SkWGLPbufferContext::Create(HDC parentDC, int msaaSampleCou return nullptr; } + // We cache the pixel formats once, and then reuse them. That's possibly incorrect if + // there are multiple GPUs, but this function is always called with a freshly made, + // identically constructed HDC (see WinGLTestContext). + // + // We only store two potential pixel formats, one for single buffer, one for double buffer. + // We never ask for MSAA, so we don't need the second pixel format for each buffering state. + static int gPixelFormats[2] = { -1, -1 }; + static SkOnce once; + once([=] { + { + // Single buffer + int pixelFormatsToTry[2] = { -1, -1 }; + get_pixel_formats_to_try(parentDC, extensions, false, 0, false, pixelFormatsToTry); + gPixelFormats[0] = pixelFormatsToTry[0]; + } + { + // Double buffer + int pixelFormatsToTry[2] = { -1, -1 }; + get_pixel_formats_to_try(parentDC, extensions, true, 0, false, pixelFormatsToTry); + gPixelFormats[1] = pixelFormatsToTry[0]; + } + }); + // try for single buffer first - for (int dblBuffer = 0; dblBuffer < 2; ++dblBuffer) { - int pixelFormatsToTry[] = { -1, -1 }; - get_pixel_formats_to_try(parentDC, extensions, (0 != dblBuffer), msaaSampleCount, - 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) { - HDC dc = extensions.getPbufferDC(pbuf); - if (dc) { - HGLRC glrc = create_gl_context(dc, extensions, contextType, shareContext); - if (glrc) { - return new SkWGLPbufferContext(pbuf, dc, glrc); - } - extensions.releasePbufferDC(pbuf, dc); + for (int pixelFormat : gPixelFormats) { + if (-1 == pixelFormat) { + continue; + } + HPBUFFER pbuf = extensions.createPbuffer(parentDC, pixelFormat, 1, 1, nullptr); + if (0 != pbuf) { + HDC dc = extensions.getPbufferDC(pbuf); + if (dc) { + HGLRC glrc = create_gl_context(dc, extensions, contextType, shareContext); + if (glrc) { + return new SkWGLPbufferContext(pbuf, dc, glrc); } - extensions.destroyPbuffer(pbuf); + extensions.releasePbufferDC(pbuf, dc); } + extensions.destroyPbuffer(pbuf); } } return nullptr; diff --git a/tools/gpu/gl/win/CreatePlatformGLTestContext_win.cpp b/tools/gpu/gl/win/CreatePlatformGLTestContext_win.cpp index 49d774315b..0e97153794 100644 --- a/tools/gpu/gl/win/CreatePlatformGLTestContext_win.cpp +++ b/tools/gpu/gl/win/CreatePlatformGLTestContext_win.cpp @@ -90,7 +90,7 @@ WinGLTestContext::WinGLTestContext(GrGLStandard forcedGpuAPI, WinGLTestContext* winShareContext = shareContext->fPbufferContext ? shareContext->fPbufferContext->getGLRC() : shareContext->fGlRenderContext; } - fPbufferContext = SkWGLPbufferContext::Create(fDeviceContext, 0, contextType, winShareContext); + fPbufferContext = SkWGLPbufferContext::Create(fDeviceContext, contextType, winShareContext); HDC dc; HGLRC glrc; |