Chromium Code Reviews| Index: src/views/win/SkOSWindow_win.cpp |
| diff --git a/src/views/win/SkOSWindow_win.cpp b/src/views/win/SkOSWindow_win.cpp |
| index b0bb76ca19cc05071a108a6902cce64b5e4fee2e..ddc6985d5314439d3632ee03b4db9ec38f981a82 100644 |
| --- a/src/views/win/SkOSWindow_win.cpp |
| +++ b/src/views/win/SkOSWindow_win.cpp |
| @@ -30,7 +30,17 @@ |
| (IFACE)->fFunctions.f##X; \ |
| } while (false) |
| -#endif |
| +#endif // SK_ANGLE |
| + |
| +#if SK_COMMAND_BUFFER |
| +#include "gl/command_buffer/SkCommandBufferGLContext.h" |
| + |
| +#define COMMAND_BUFFER_GL_CALL(IFACE, X) \ |
| + do { \ |
| + (IFACE)->fFunctions.f##X; \ |
| + } while (false) |
| + |
| +#endif // SK_COMMAND_BUFFER |
| #define WM_EVENT_CALLBACK (WM_USER+0) |
| @@ -48,7 +58,7 @@ SkOSWindow::SkOSWindow(const void* winInit) { |
| CW_USEDEFAULT, 0, CW_USEDEFAULT, 0, NULL, NULL, fWinInit.fInstance, NULL); |
| gHwndToOSWindowMap.set(fHWND, this); |
| #if SK_SUPPORT_GPU |
| -#if SK_ANGLE |
| +#if SK_ANGLE || SK_COMMAND_BUFFER |
| fDisplay = EGL_NO_DISPLAY; |
| fContext = EGL_NO_CONTEXT; |
| fSurface = EGL_NO_SURFACE; |
| @@ -64,7 +74,7 @@ SkOSWindow::~SkOSWindow() { |
| if (fHGLRC) { |
| wglDeleteContext((HGLRC)fHGLRC); |
| } |
| -#if SK_ANGLE |
| +#if SK_ANGLE || SK_COMMAND_BUFFER |
| if (EGL_NO_CONTEXT != fContext) { |
| eglDestroyContext(fDisplay, fContext); |
| fContext = EGL_NO_CONTEXT; |
| @@ -79,7 +89,7 @@ SkOSWindow::~SkOSWindow() { |
| eglTerminate(fDisplay); |
| fDisplay = EGL_NO_DISPLAY; |
| } |
| -#endif // SK_ANGLE |
| +#endif // SK_ANGLE || SK_COMMAND_BUFFER |
| #endif // SK_SUPPORT_GPU |
| this->closeWindow(); |
| } |
| @@ -530,6 +540,163 @@ void SkOSWindow::presentANGLE() { |
| eglSwapBuffers(fDisplay, fSurface); |
| } |
| #endif // SK_ANGLE |
| + |
| +#if SK_COMMAND_BUFFER |
| + |
| +bool create_CommandBuffer(EGLNativeWindowType hWnd, |
|
bsalomon
2015/08/26 18:19:55
Can a lot of this be shared with the ANGLE functio
hendrikw
2015/08/27 01:28:35
All this code is bogus, I'm replacing it with the
|
| + int msaaSampleCount, |
| + EGLDisplay* eglDisplay, |
| + EGLContext* eglContext, |
| + EGLSurface* eglSurface, |
| + EGLConfig* eglConfig) { |
| + static const EGLint contextAttribs[] = { |
| + EGL_CONTEXT_CLIENT_VERSION, 2, |
| + EGL_NONE, EGL_NONE |
| + }; |
| + static const EGLint configAttribList[] = { |
| + EGL_RED_SIZE, 8, |
| + EGL_GREEN_SIZE, 8, |
| + EGL_BLUE_SIZE, 8, |
| + EGL_ALPHA_SIZE, 8, |
| + EGL_DEPTH_SIZE, 8, |
| + EGL_STENCIL_SIZE, 8, |
| + EGL_NONE |
| + }; |
| + static const EGLint surfaceAttribList[] = { |
| + EGL_NONE, EGL_NONE |
| + }; |
| + |
| + EGLDisplay display = SkANGLEGLContext::GetD3DEGLDisplay(GetDC(hWnd)); |
|
bsalomon
2015/08/26 18:19:55
Seems a bit weird to use angle here to get the dis
hendrikw
2015/08/27 01:28:35
All of this code is gone, yay.
|
| + |
| + if (EGL_NO_DISPLAY == display) { |
| + SkDebugf("Could not create Command Buffer egl display!\n"); |
| + return false; |
| + } |
| + |
| + // Initialize EGL |
| + EGLint majorVersion, minorVersion; |
| + if (!eglInitialize(display, &majorVersion, &minorVersion)) { |
| + return false; |
| + } |
| + |
| + EGLint numConfigs; |
| + if (!eglGetConfigs(display, NULL, 0, &numConfigs)) { |
| + return false; |
| + } |
| + |
| + // Choose config |
| + bool foundConfig = false; |
| + if (msaaSampleCount) { |
| + static const int kConfigAttribListCnt = |
| + SK_ARRAY_COUNT(configAttribList); |
| + EGLint msaaConfigAttribList[kConfigAttribListCnt + 4]; |
| + memcpy(msaaConfigAttribList, |
| + configAttribList, |
| + sizeof(configAttribList)); |
| + SkASSERT(EGL_NONE == msaaConfigAttribList[kConfigAttribListCnt - 1]); |
| + msaaConfigAttribList[kConfigAttribListCnt - 1] = EGL_SAMPLE_BUFFERS; |
| + msaaConfigAttribList[kConfigAttribListCnt + 0] = 1; |
| + msaaConfigAttribList[kConfigAttribListCnt + 1] = EGL_SAMPLES; |
| + msaaConfigAttribList[kConfigAttribListCnt + 2] = msaaSampleCount; |
| + msaaConfigAttribList[kConfigAttribListCnt + 3] = EGL_NONE; |
| + if (eglChooseConfig(display, configAttribList, eglConfig, 1, &numConfigs)) { |
| + SkASSERT(numConfigs > 0); |
| + foundConfig = true; |
| + } |
| + } |
| + if (!foundConfig) { |
| + if (!eglChooseConfig(display, configAttribList, eglConfig, 1, &numConfigs)) { |
| + return false; |
| + } |
| + } |
| + |
| + // Create a surface |
| + EGLSurface surface = eglCreateWindowSurface(display, *eglConfig, |
| + (EGLNativeWindowType)hWnd, |
| + surfaceAttribList); |
| + if (surface == EGL_NO_SURFACE) { |
| + return false; |
| + } |
| + |
| + // Create a GL context |
| + EGLContext context = eglCreateContext(display, *eglConfig, |
| + EGL_NO_CONTEXT, |
| + contextAttribs ); |
| + if (context == EGL_NO_CONTEXT ) { |
| + return false; |
| + } |
| + |
| + // Make the context current |
| + if (!eglMakeCurrent(display, surface, surface, context)) { |
| + return false; |
| + } |
| + |
| + *eglDisplay = display; |
| + *eglContext = context; |
| + *eglSurface = surface; |
| + return true; |
| +} |
| + |
| +bool SkOSWindow::attachCommandBuffer(int msaaSampleCount, AttachmentInfo* info) { |
| + if (EGL_NO_DISPLAY == fDisplay) { |
| + bool bResult = create_CommandBuffer((HWND)fHWND, |
| + msaaSampleCount, |
| + &fDisplay, |
| + &fContext, |
| + &fSurface, |
| + &fConfig); |
| + if (false == bResult) { |
| + return false; |
| + } |
| + SkAutoTUnref<const GrGLInterface> intf(GrGLCreateANGLEInterface()); |
| + |
| + if (intf) { |
| + COMMAND_BUFFER_GL_CALL(intf, ClearStencil(0)); |
| + COMMAND_BUFFER_GL_CALL(intf, ClearColor(0, 0, 0, 0)); |
| + COMMAND_BUFFER_GL_CALL(intf, StencilMask(0xffffffff)); |
| + COMMAND_BUFFER_GL_CALL(intf, Clear(GL_STENCIL_BUFFER_BIT |GL_COLOR_BUFFER_BIT)); |
| + } |
| + } |
| + if (eglMakeCurrent(fDisplay, fSurface, fSurface, fContext)) { |
| + eglGetConfigAttrib(fDisplay, fConfig, EGL_STENCIL_SIZE, &info->fStencilBits); |
| + eglGetConfigAttrib(fDisplay, fConfig, EGL_SAMPLES, &info->fSampleCount); |
| + |
| + SkAutoTUnref<const GrGLInterface> intf(GrGLCreateANGLEInterface()); |
| + |
| + if (intf ) { |
| + COMMAND_BUFFER_GL_CALL(intf, Viewport(0, 0, |
| + SkScalarRoundToInt(this->width()), |
| + SkScalarRoundToInt(this->height()))); |
| + } |
| + return true; |
| + } |
| + return false; |
| +} |
| + |
| +void SkOSWindow::detachCommandBuffer() { |
| + eglMakeCurrent(fDisplay, EGL_NO_SURFACE , EGL_NO_SURFACE , EGL_NO_CONTEXT); |
| + |
| + eglDestroyContext(fDisplay, fContext); |
| + fContext = EGL_NO_CONTEXT; |
| + |
| + eglDestroySurface(fDisplay, fSurface); |
| + fSurface = EGL_NO_SURFACE; |
| + |
| + eglTerminate(fDisplay); |
| + fDisplay = EGL_NO_DISPLAY; |
| +} |
| + |
| +void SkOSWindow::presentCommandBuffer() { |
| + SkAutoTUnref<const GrGLInterface> intf(GrGLCreateANGLEInterface()); |
| + |
| + if (intf) { |
| + COMMAND_BUFFER_GL_CALL(intf, Flush()); |
| + } |
| + |
| + eglSwapBuffers(fDisplay, fSurface); |
| +} |
| +#endif // SK_COMMAND_BUFFER |
| + |
| #endif // SK_SUPPORT_GPU |
| // return true on success |
| @@ -554,6 +721,11 @@ bool SkOSWindow::attach(SkBackEndTypes attachType, int msaaSampleCount, Attachme |
| result = attachANGLE(msaaSampleCount, info); |
| break; |
| #endif // SK_ANGLE |
| +#if SK_COMMAND_BUFFER |
| + case kCommandBuffer_BackEndType: |
| + result = attachCommandBuffer(msaaSampleCount, info); |
| + break; |
| +#endif // SK_COMMAND_BUFFER |
| #endif // SK_SUPPORT_GPU |
| default: |
| SkASSERT(false); |
| @@ -582,6 +754,11 @@ void SkOSWindow::detach() { |
| detachANGLE(); |
| break; |
| #endif // SK_ANGLE |
| +#if SK_COMMAND_BUFFER |
| + case kCommandBuffer_BackEndType: |
| + detachCommandBuffer(); |
| + break; |
| +#endif // SK_COMMAND_BUFFER |
| #endif // SK_SUPPORT_GPU |
| default: |
| SkASSERT(false); |
| @@ -604,6 +781,11 @@ void SkOSWindow::present() { |
| presentANGLE(); |
| break; |
| #endif // SK_ANGLE |
| +#if SK_COMMAND_BUFFER |
| + case kCommandBuffer_BackEndType: |
| + presentCommandBuffer(); |
| + break; |
| +#endif // SK_COMMAND_BUFFER |
| #endif // SK_SUPPORT_GPU |
| default: |
| SkASSERT(false); |