30 auto glrc = wglGetCurrentContext();
31 auto dc = wglGetCurrentDC();
32 return [glrc, dc] { wglMakeCurrent(dc, glrc); };
37 WinGLTestContext(
GrGLStandard forcedGpuAPI, WinGLTestContext* shareContext);
38 ~WinGLTestContext()
override;
41 void destroyGLContext();
43 void onPlatformMakeNotCurrent()
const override;
44 void onPlatformMakeCurrent()
const override;
45 std::function<void()> onPlatformGetAutoContextRestore()
const override;
50 HGLRC fGlRenderContext;
55ATOM WinGLTestContext::gWC = 0;
57WinGLTestContext::WinGLTestContext(
GrGLStandard forcedGpuAPI, WinGLTestContext* shareContext)
59 , fDeviceContext(nullptr)
60 , fGlRenderContext(nullptr)
61 , fPbufferContext(nullptr) {
62 HINSTANCE hInstance = (HINSTANCE)GetModuleHandle(
nullptr);
68 wc.hbrBackground =
nullptr;
69 wc.hCursor = LoadCursor(
nullptr, IDC_ARROW);
70 wc.hIcon =
LoadIcon(
nullptr, IDI_APPLICATION);
71 wc.hInstance = hInstance;
72 wc.lpfnWndProc = (WNDPROC) DefWindowProc;
73 wc.lpszClassName = TEXT(
"Griffin");
74 wc.lpszMenuName =
nullptr;
75 wc.style = CS_HREDRAW | CS_VREDRAW | CS_OWNDC;
77 gWC = RegisterClass(&wc);
79 SkDebugf(
"Could not register window class.\n");
84 if (!(fWindow = CreateWindow(TEXT(
"Griffin"),
85 TEXT(
"The Invisible Man"),
89 hInstance,
nullptr))) {
90 SkDebugf(
"Could not create window.\n");
94 if (!(fDeviceContext = GetDC(fWindow))) {
95 SkDebugf(
"Could not get device context.\n");
96 this->destroyGLContext();
106 HGLRC winShareContext =
nullptr;
108 winShareContext = shareContext->fPbufferContext ? shareContext->fPbufferContext->getGLRC()
109 : shareContext->fGlRenderContext;
115 if (
nullptr == fPbufferContext) {
118 SkDebugf(
"Could not create rendering context.\n");
119 this->destroyGLContext();
123 glrc = fGlRenderContext;
125 ReleaseDC(fWindow, fDeviceContext);
126 fDeviceContext =
nullptr;
127 DestroyWindow(fWindow);
130 dc = fPbufferContext->getDC();
131 glrc = fPbufferContext->getGLRC();
135 if (!(wglMakeCurrent(dc, glrc))) {
136 SkDebugf(
"Could not set the context.\n");
137 this->destroyGLContext();
144 SkDebugf(
"Could not create GL interface.\n");
145 this->destroyGLContext();
148 if (!
gl->validate()) {
149 SkDebugf(
"Could not validate GL interface.\n");
150 this->destroyGLContext();
154 this->
init(std::move(
gl));
163WinGLTestContext::~WinGLTestContext() {
165 this->destroyGLContext();
168void WinGLTestContext::destroyGLContext() {
169 fPbufferContext =
nullptr;
170 if (fGlRenderContext) {
172 wglDeleteContext(fGlRenderContext);
173 fGlRenderContext =
nullptr;
175 if (fWindow && fDeviceContext) {
176 ReleaseDC(fWindow, fDeviceContext);
177 fDeviceContext =
nullptr;
180 DestroyWindow(fWindow);
185void WinGLTestContext::onPlatformMakeNotCurrent()
const {
186 if (!wglMakeCurrent(
nullptr,
nullptr)) {
187 SkDebugf(
"Could not null out the rendering context.\n");
191void WinGLTestContext::onPlatformMakeCurrent()
const {
195 if (
nullptr == fPbufferContext) {
197 glrc = fGlRenderContext;
199 dc = fPbufferContext->getDC();
200 glrc = fPbufferContext->getGLRC();
203 if (!wglMakeCurrent(dc, glrc)) {
204 SkDebugf(
"Could not make current.\n");
208std::function<void()> WinGLTestContext::onPlatformGetAutoContextRestore()
const {
209 if (wglGetCurrentContext() == fGlRenderContext) {
212 return context_restorer();
215GrGLFuncPtr WinGLTestContext::onPlatformGetProcAddress(
const char*
name)
const {
223 GLTestContext *shareContext) {
224 WinGLTestContext* winShareContext =
reinterpret_cast<WinGLTestContext*
>(shareContext);
225 WinGLTestContext *ctx =
new WinGLTestContext(forcedGpuAPI, winShareContext);
226 if (!ctx->isValid()) {
SK_API sk_sp< const GrGLInterface > GrGLMakeNativeInterface()
void SK_SPI SkDebugf(const char format[],...) SK_PRINTF_LIKE(1
HGLRC SkCreateWGLContext(HDC dc, int msaaSampleCount, bool deepColor, SkWGLContextRequest context, HGLRC shareContext=nullptr)
@ kGLES_SkWGLContextRequest
@ kGLPreferCompatibilityProfile_SkWGLContextRequest
static sk_sp< SkWGLPbufferContext > Create(HDC parentDC, SkWGLContextRequest contextType, HGLRC shareContext)
Dart_NativeFunction function
DEF_SWITCHES_START aot vmservice shared library name
GLTestContext * CreatePlatformGLTestContext(GrGLStandard forcedGpuAPI, GLTestContext *shareContext)