1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/gfx/skia/trunk/include/utils/SkWGL.h Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,115 @@ 1.4 + 1.5 +/* 1.6 + * Copyright 2011 Google Inc. 1.7 + * 1.8 + * Use of this source code is governed by a BSD-style license that can be 1.9 + * found in the LICENSE file. 1.10 + */ 1.11 + 1.12 +#include "SkRefCnt.h" 1.13 + 1.14 +#ifndef SkWGL_DEFINED 1.15 +#define SkWGL_DEFINED 1.16 + 1.17 +/** 1.18 + * Working with WGL extensions can be a pain. Among the reasons is that You must 1.19 + * have a GL context to get the proc addresses, but you want to use the procs to 1.20 + * create a context in the first place. So you have to create a dummy GL ctx to 1.21 + * get the proc addresses. 1.22 + * 1.23 + * This file helps by providing SkCreateWGLInterface(). It returns a struct of 1.24 + * function pointers that it initializes. It also has a helper function to query 1.25 + * for WGL extensions. It handles the fact that wglGetExtensionsString is itself 1.26 + * an extension. 1.27 + */ 1.28 + 1.29 +#if !defined(WIN32_LEAN_AND_MEAN) 1.30 + #define WIN32_LEAN_AND_MEAN 1.31 + #define SK_LOCAL_LEAN_AND_MEAN 1.32 +#endif 1.33 +#include <windows.h> 1.34 +#if defined(SK_LOCAL_LEAN_AND_MEAN) 1.35 + #undef WIN32_LEAN_AND_MEAN 1.36 + #undef SK_LOCAL_LEAN_AND_MEAN 1.37 +#endif 1.38 + 1.39 +#define SK_WGL_DRAW_TO_WINDOW 0x2001 1.40 +#define SK_WGL_ACCELERATION 0x2003 1.41 +#define SK_WGL_SUPPORT_OPENGL 0x2010 1.42 +#define SK_WGL_DOUBLE_BUFFER 0x2011 1.43 +#define SK_WGL_COLOR_BITS 0x2014 1.44 +#define SK_WGL_ALPHA_BITS 0x201B 1.45 +#define SK_WGL_STENCIL_BITS 0x2023 1.46 +#define SK_WGL_FULL_ACCELERATION 0x2027 1.47 +#define SK_WGL_SAMPLE_BUFFERS 0x2041 1.48 +#define SK_WGL_SAMPLES 0x2042 1.49 +#define SK_WGL_CONTEXT_MAJOR_VERSION 0x2091 1.50 +#define SK_WGL_CONTEXT_MINOR_VERSION 0x2092 1.51 +#define SK_WGL_CONTEXT_LAYER_PLANE 0x2093 1.52 +#define SK_WGL_CONTEXT_FLAGS 0x2094 1.53 +#define SK_WGL_CONTEXT_PROFILE_MASK 0x9126 1.54 +#define SK_WGL_CONTEXT_DEBUG_BIT 0x0001 1.55 +#define SK_WGL_CONTEXT_FORWARD_COMPATIBLE_BIT 0x0002 1.56 +#define SK_WGL_CONTEXT_CORE_PROFILE_BIT 0x00000001 1.57 +#define SK_WGL_CONTEXT_COMPATIBILITY_PROFILE_BIT 0x00000002 1.58 +#define SK_WGL_CONTEXT_ES2_PROFILE_BIT 0x00000004 1.59 +#define SK_ERROR_INVALID_VERSION 0x2095 1.60 +#define SK_ERROR_INVALID_PROFILE 0x2096 1.61 + 1.62 +class SkWGLExtensions { 1.63 +public: 1.64 + SkWGLExtensions(); 1.65 + /** 1.66 + * Determines if an extensions is available for a given DC. 1.67 + * WGL_extensions_string is considered a prerequisite for all other 1.68 + * extensions. It is necessary to check this before calling other class 1.69 + * functions. 1.70 + */ 1.71 + bool hasExtension(HDC dc, const char* ext) const; 1.72 + 1.73 + const char* getExtensionsString(HDC hdc) const; 1.74 + BOOL choosePixelFormat(HDC hdc, const int*, const FLOAT*, UINT, int*, UINT*) const; 1.75 + BOOL getPixelFormatAttribiv(HDC, int, int, UINT, const int*, int*) const; 1.76 + BOOL getPixelFormatAttribfv(HDC hdc, int, int, UINT, const int*, FLOAT*) const; 1.77 + HGLRC createContextAttribs(HDC, HGLRC, const int *) const; 1.78 + 1.79 + /** 1.80 + * WGL doesn't have precise rules for the ordering of formats returned 1.81 + * by wglChoosePixelFormat. This function helps choose among the set of 1.82 + * formats returned by wglChoosePixelFormat. The rules in decreasing 1.83 + * priority are: 1.84 + * * Choose formats with the smallest sample count that is >= 1.85 + * desiredSampleCount (or the largest sample count if all formats have 1.86 + * fewer samples than desiredSampleCount.) 1.87 + * * Choose formats with the fewest color samples when coverage sampling 1.88 + * is available. 1.89 + * * If the above rules leave multiple formats, choose the one that 1.90 + * appears first in the formats array parameter. 1.91 + */ 1.92 + int selectFormat(const int formats[], 1.93 + int formatCount, 1.94 + HDC dc, 1.95 + int desiredSampleCount); 1.96 +private: 1.97 + typedef const char* (WINAPI *GetExtensionsStringProc)(HDC hdc); 1.98 + typedef BOOL (WINAPI *ChoosePixelFormatProc)(HDC hdc, const int *, const FLOAT *, UINT, int *, UINT *); 1.99 + typedef BOOL (WINAPI *GetPixelFormatAttribivProc)(HDC, int, int, UINT, const int*, int*); 1.100 + typedef BOOL (WINAPI *GetPixelFormatAttribfvProc)(HDC hdc, int, int, UINT, const int*, FLOAT*); 1.101 + typedef HGLRC (WINAPI *CreateContextAttribsProc)(HDC hDC, HGLRC, const int *); 1.102 + 1.103 + GetExtensionsStringProc fGetExtensionsString; 1.104 + ChoosePixelFormatProc fChoosePixelFormat; 1.105 + GetPixelFormatAttribfvProc fGetPixelFormatAttribfv; 1.106 + GetPixelFormatAttribivProc fGetPixelFormatAttribiv; 1.107 + CreateContextAttribsProc fCreateContextAttribs; 1.108 +}; 1.109 + 1.110 +/** 1.111 + * Helper to create an OpenGL context for a DC using WGL. Configs with a sample count >= to 1.112 + * msaaSampleCount are preferred but if none is available then a context with a lower sample count 1.113 + * (including non-MSAA) will be created. If preferCoreProfile is true but a core profile cannot be 1.114 + * created then a compatible profile context will be created. 1.115 + */ 1.116 +HGLRC SkCreateWGLContext(HDC dc, int msaaSampleCount, bool preferCoreProfile); 1.117 + 1.118 +#endif