diff options
author | bsalomon <bsalomon@google.com> | 2014-07-01 07:20:11 -0700 |
---|---|---|
committer | Commit bot <commit-bot@chromium.org> | 2014-07-01 07:20:11 -0700 |
commit | 9245b7ee764b61222ffba409a7d2d7e62fde01a6 (patch) | |
tree | b9c3550a2211a480fb25f65c92d69251e4fc58ba /src/gpu | |
parent | 2fd0d14b9be34a7a945942733c3516d97d07f516 (diff) |
When performing offscreen rendering on windows, attempt to use a pbuffer context.
A pbuffer context is less likely to have a blocking SwapBuffers (due to vsync).
R=robertphillips@google.com
Author: bsalomon@google.com
Review URL: https://codereview.chromium.org/336863009
Diffstat (limited to 'src/gpu')
-rw-r--r-- | src/gpu/gl/win/SkNativeGLContext_win.cpp | 58 |
1 files changed, 49 insertions, 9 deletions
diff --git a/src/gpu/gl/win/SkNativeGLContext_win.cpp b/src/gpu/gl/win/SkNativeGLContext_win.cpp index f085fdc6ee..ab66ba4d55 100644 --- a/src/gpu/gl/win/SkNativeGLContext_win.cpp +++ b/src/gpu/gl/win/SkNativeGLContext_win.cpp @@ -7,7 +7,6 @@ */ #include "gl/SkNativeGLContext.h" -#include "SkWGL.h" #define WIN32_LEAN_AND_MEAN #include <windows.h> @@ -28,7 +27,8 @@ ATOM SkNativeGLContext::gWC = 0; SkNativeGLContext::SkNativeGLContext() : fWindow(NULL) , fDeviceContext(NULL) - , fGlRenderContext(0) { + , fGlRenderContext(0) + , fPbufferContext(NULL) { } SkNativeGLContext::~SkNativeGLContext() { @@ -36,14 +36,18 @@ SkNativeGLContext::~SkNativeGLContext() { } void SkNativeGLContext::destroyGLContext() { + SkSafeSetNull(fPbufferContext); if (fGlRenderContext) { wglDeleteContext(fGlRenderContext); + fGlRenderContext = 0; } if (fWindow && fDeviceContext) { ReleaseDC(fWindow, fDeviceContext); + fDeviceContext = 0; } if (fWindow) { DestroyWindow(fWindow); + fWindow = 0; } } @@ -91,17 +95,35 @@ const GrGLInterface* SkNativeGLContext::createGLContext(GrGLStandard forcedGpuAP kGLES_GrGLStandard == forcedGpuAPI ? kGLES_SkWGLContextRequest : kGLPreferCompatibilityProfile_SkWGLContextRequest; - if (!(fGlRenderContext = SkCreateWGLContext(fDeviceContext, 0, contextType))) { - SkDebugf("Could not create rendering context.\n"); - this->destroyGLContext(); - return NULL; + fPbufferContext = SkWGLPbufferContext::Create(fDeviceContext, 0, contextType); + + HDC dc; + HGLRC glrc; + + if (NULL == fPbufferContext) { + if (!(fGlRenderContext = SkCreateWGLContext(fDeviceContext, 0, contextType))) { + SkDebugf("Could not create rendering context.\n"); + this->destroyGLContext(); + return NULL; + } + dc = fDeviceContext; + glrc = fGlRenderContext; + } else { + ReleaseDC(fWindow, fDeviceContext); + fDeviceContext = 0; + DestroyWindow(fWindow); + fWindow = 0; + + dc = fPbufferContext->getDC(); + glrc = fPbufferContext->getGLRC(); } - if (!(wglMakeCurrent(fDeviceContext, fGlRenderContext))) { + if (!(wglMakeCurrent(dc, glrc))) { SkDebugf("Could not set the context.\n"); this->destroyGLContext(); return NULL; } + const GrGLInterface* interface = GrGLCreateNativeInterface(); if (NULL == interface) { SkDebugf("Could not create GL interface.\n"); @@ -113,13 +135,31 @@ const GrGLInterface* SkNativeGLContext::createGLContext(GrGLStandard forcedGpuAP } void SkNativeGLContext::makeCurrent() const { - if (!wglMakeCurrent(fDeviceContext, fGlRenderContext)) { + HDC dc; + HGLRC glrc; + + if (NULL == fPbufferContext) { + dc = fDeviceContext; + glrc = fGlRenderContext; + } else { + dc = fPbufferContext->getDC(); + glrc = fPbufferContext->getGLRC(); + } + + if (!wglMakeCurrent(dc, glrc)) { SkDebugf("Could not create rendering context.\n"); } } void SkNativeGLContext::swapBuffers() const { - if (!SwapBuffers(fDeviceContext)) { + HDC dc; + + if (NULL == fPbufferContext) { + dc = fDeviceContext; + } else { + dc = fPbufferContext->getDC(); + } + if (!SwapBuffers(dc)) { SkDebugf("Could not complete SwapBuffers.\n"); } } |