gfx/skia/trunk/src/gpu/gl/win/SkNativeGLContext_win.cpp

Wed, 31 Dec 2014 06:09:35 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Wed, 31 Dec 2014 06:09:35 +0100
changeset 0
6474c204b198
permissions
-rw-r--r--

Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.

michael@0 1
michael@0 2 /*
michael@0 3 * Copyright 2011 Google Inc.
michael@0 4 *
michael@0 5 * Use of this source code is governed by a BSD-style license that can be
michael@0 6 * found in the LICENSE file.
michael@0 7 */
michael@0 8
michael@0 9 #include "gl/SkNativeGLContext.h"
michael@0 10 #include "SkWGL.h"
michael@0 11
michael@0 12 #define WIN32_LEAN_AND_MEAN
michael@0 13 #include <windows.h>
michael@0 14
michael@0 15 SkNativeGLContext::AutoContextRestore::AutoContextRestore() {
michael@0 16 fOldHGLRC = wglGetCurrentContext();
michael@0 17 fOldHDC = wglGetCurrentDC();
michael@0 18 }
michael@0 19
michael@0 20 SkNativeGLContext::AutoContextRestore::~AutoContextRestore() {
michael@0 21 wglMakeCurrent(fOldHDC, fOldHGLRC);
michael@0 22 }
michael@0 23
michael@0 24 ///////////////////////////////////////////////////////////////////////////////
michael@0 25
michael@0 26 ATOM SkNativeGLContext::gWC = 0;
michael@0 27
michael@0 28 SkNativeGLContext::SkNativeGLContext()
michael@0 29 : fWindow(NULL)
michael@0 30 , fDeviceContext(NULL)
michael@0 31 , fGlRenderContext(0) {
michael@0 32 }
michael@0 33
michael@0 34 SkNativeGLContext::~SkNativeGLContext() {
michael@0 35 this->destroyGLContext();
michael@0 36 }
michael@0 37
michael@0 38 void SkNativeGLContext::destroyGLContext() {
michael@0 39 if (fGlRenderContext) {
michael@0 40 wglDeleteContext(fGlRenderContext);
michael@0 41 }
michael@0 42 if (fWindow && fDeviceContext) {
michael@0 43 ReleaseDC(fWindow, fDeviceContext);
michael@0 44 }
michael@0 45 if (fWindow) {
michael@0 46 DestroyWindow(fWindow);
michael@0 47 }
michael@0 48 }
michael@0 49
michael@0 50 const GrGLInterface* SkNativeGLContext::createGLContext() {
michael@0 51 HINSTANCE hInstance = (HINSTANCE)GetModuleHandle(NULL);
michael@0 52
michael@0 53 if (!gWC) {
michael@0 54 WNDCLASS wc;
michael@0 55 wc.cbClsExtra = 0;
michael@0 56 wc.cbWndExtra = 0;
michael@0 57 wc.hbrBackground = NULL;
michael@0 58 wc.hCursor = LoadCursor(NULL, IDC_ARROW);
michael@0 59 wc.hIcon = LoadIcon(NULL, IDI_APPLICATION);
michael@0 60 wc.hInstance = hInstance;
michael@0 61 wc.lpfnWndProc = (WNDPROC) DefWindowProc;
michael@0 62 wc.lpszClassName = TEXT("Griffin");
michael@0 63 wc.lpszMenuName = NULL;
michael@0 64 wc.style = CS_HREDRAW | CS_VREDRAW | CS_OWNDC;
michael@0 65
michael@0 66 gWC = RegisterClass(&wc);
michael@0 67 if (!gWC) {
michael@0 68 SkDebugf("Could not register window class.\n");
michael@0 69 return NULL;
michael@0 70 }
michael@0 71 }
michael@0 72
michael@0 73 if (!(fWindow = CreateWindow(TEXT("Griffin"),
michael@0 74 TEXT("The Invisible Man"),
michael@0 75 WS_OVERLAPPEDWINDOW,
michael@0 76 0, 0, 1, 1,
michael@0 77 NULL, NULL,
michael@0 78 hInstance, NULL))) {
michael@0 79 SkDebugf("Could not create window.\n");
michael@0 80 return NULL;
michael@0 81 }
michael@0 82
michael@0 83 if (!(fDeviceContext = GetDC(fWindow))) {
michael@0 84 SkDebugf("Could not get device context.\n");
michael@0 85 this->destroyGLContext();
michael@0 86 return NULL;
michael@0 87 }
michael@0 88
michael@0 89 // Requesting a Core profile would bar us from using NVPR. So we pass false.
michael@0 90 if (!(fGlRenderContext = SkCreateWGLContext(fDeviceContext, 0, false))) {
michael@0 91 SkDebugf("Could not create rendering context.\n");
michael@0 92 this->destroyGLContext();
michael@0 93 return NULL;
michael@0 94 }
michael@0 95
michael@0 96 if (!(wglMakeCurrent(fDeviceContext, fGlRenderContext))) {
michael@0 97 SkDebugf("Could not set the context.\n");
michael@0 98 this->destroyGLContext();
michael@0 99 return NULL;
michael@0 100 }
michael@0 101 const GrGLInterface* interface = GrGLCreateNativeInterface();
michael@0 102 if (NULL == interface) {
michael@0 103 SkDebugf("Could not create GL interface.\n");
michael@0 104 this->destroyGLContext();
michael@0 105 return NULL;
michael@0 106 }
michael@0 107
michael@0 108 return interface;
michael@0 109 }
michael@0 110
michael@0 111 void SkNativeGLContext::makeCurrent() const {
michael@0 112 if (!wglMakeCurrent(fDeviceContext, fGlRenderContext)) {
michael@0 113 SkDebugf("Could not create rendering context.\n");
michael@0 114 }
michael@0 115 }
michael@0 116
michael@0 117 void SkNativeGLContext::swapBuffers() const {
michael@0 118 if (!SwapBuffers(fDeviceContext)) {
michael@0 119 SkDebugf("Could not complete SwapBuffers.\n");
michael@0 120 }
michael@0 121 }

mercurial