gfx/skia/trunk/include/utils/SkWGL.h

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 "SkRefCnt.h"
michael@0 10
michael@0 11 #ifndef SkWGL_DEFINED
michael@0 12 #define SkWGL_DEFINED
michael@0 13
michael@0 14 /**
michael@0 15 * Working with WGL extensions can be a pain. Among the reasons is that You must
michael@0 16 * have a GL context to get the proc addresses, but you want to use the procs to
michael@0 17 * create a context in the first place. So you have to create a dummy GL ctx to
michael@0 18 * get the proc addresses.
michael@0 19 *
michael@0 20 * This file helps by providing SkCreateWGLInterface(). It returns a struct of
michael@0 21 * function pointers that it initializes. It also has a helper function to query
michael@0 22 * for WGL extensions. It handles the fact that wglGetExtensionsString is itself
michael@0 23 * an extension.
michael@0 24 */
michael@0 25
michael@0 26 #if !defined(WIN32_LEAN_AND_MEAN)
michael@0 27 #define WIN32_LEAN_AND_MEAN
michael@0 28 #define SK_LOCAL_LEAN_AND_MEAN
michael@0 29 #endif
michael@0 30 #include <windows.h>
michael@0 31 #if defined(SK_LOCAL_LEAN_AND_MEAN)
michael@0 32 #undef WIN32_LEAN_AND_MEAN
michael@0 33 #undef SK_LOCAL_LEAN_AND_MEAN
michael@0 34 #endif
michael@0 35
michael@0 36 #define SK_WGL_DRAW_TO_WINDOW 0x2001
michael@0 37 #define SK_WGL_ACCELERATION 0x2003
michael@0 38 #define SK_WGL_SUPPORT_OPENGL 0x2010
michael@0 39 #define SK_WGL_DOUBLE_BUFFER 0x2011
michael@0 40 #define SK_WGL_COLOR_BITS 0x2014
michael@0 41 #define SK_WGL_ALPHA_BITS 0x201B
michael@0 42 #define SK_WGL_STENCIL_BITS 0x2023
michael@0 43 #define SK_WGL_FULL_ACCELERATION 0x2027
michael@0 44 #define SK_WGL_SAMPLE_BUFFERS 0x2041
michael@0 45 #define SK_WGL_SAMPLES 0x2042
michael@0 46 #define SK_WGL_CONTEXT_MAJOR_VERSION 0x2091
michael@0 47 #define SK_WGL_CONTEXT_MINOR_VERSION 0x2092
michael@0 48 #define SK_WGL_CONTEXT_LAYER_PLANE 0x2093
michael@0 49 #define SK_WGL_CONTEXT_FLAGS 0x2094
michael@0 50 #define SK_WGL_CONTEXT_PROFILE_MASK 0x9126
michael@0 51 #define SK_WGL_CONTEXT_DEBUG_BIT 0x0001
michael@0 52 #define SK_WGL_CONTEXT_FORWARD_COMPATIBLE_BIT 0x0002
michael@0 53 #define SK_WGL_CONTEXT_CORE_PROFILE_BIT 0x00000001
michael@0 54 #define SK_WGL_CONTEXT_COMPATIBILITY_PROFILE_BIT 0x00000002
michael@0 55 #define SK_WGL_CONTEXT_ES2_PROFILE_BIT 0x00000004
michael@0 56 #define SK_ERROR_INVALID_VERSION 0x2095
michael@0 57 #define SK_ERROR_INVALID_PROFILE 0x2096
michael@0 58
michael@0 59 class SkWGLExtensions {
michael@0 60 public:
michael@0 61 SkWGLExtensions();
michael@0 62 /**
michael@0 63 * Determines if an extensions is available for a given DC.
michael@0 64 * WGL_extensions_string is considered a prerequisite for all other
michael@0 65 * extensions. It is necessary to check this before calling other class
michael@0 66 * functions.
michael@0 67 */
michael@0 68 bool hasExtension(HDC dc, const char* ext) const;
michael@0 69
michael@0 70 const char* getExtensionsString(HDC hdc) const;
michael@0 71 BOOL choosePixelFormat(HDC hdc, const int*, const FLOAT*, UINT, int*, UINT*) const;
michael@0 72 BOOL getPixelFormatAttribiv(HDC, int, int, UINT, const int*, int*) const;
michael@0 73 BOOL getPixelFormatAttribfv(HDC hdc, int, int, UINT, const int*, FLOAT*) const;
michael@0 74 HGLRC createContextAttribs(HDC, HGLRC, const int *) const;
michael@0 75
michael@0 76 /**
michael@0 77 * WGL doesn't have precise rules for the ordering of formats returned
michael@0 78 * by wglChoosePixelFormat. This function helps choose among the set of
michael@0 79 * formats returned by wglChoosePixelFormat. The rules in decreasing
michael@0 80 * priority are:
michael@0 81 * * Choose formats with the smallest sample count that is >=
michael@0 82 * desiredSampleCount (or the largest sample count if all formats have
michael@0 83 * fewer samples than desiredSampleCount.)
michael@0 84 * * Choose formats with the fewest color samples when coverage sampling
michael@0 85 * is available.
michael@0 86 * * If the above rules leave multiple formats, choose the one that
michael@0 87 * appears first in the formats array parameter.
michael@0 88 */
michael@0 89 int selectFormat(const int formats[],
michael@0 90 int formatCount,
michael@0 91 HDC dc,
michael@0 92 int desiredSampleCount);
michael@0 93 private:
michael@0 94 typedef const char* (WINAPI *GetExtensionsStringProc)(HDC hdc);
michael@0 95 typedef BOOL (WINAPI *ChoosePixelFormatProc)(HDC hdc, const int *, const FLOAT *, UINT, int *, UINT *);
michael@0 96 typedef BOOL (WINAPI *GetPixelFormatAttribivProc)(HDC, int, int, UINT, const int*, int*);
michael@0 97 typedef BOOL (WINAPI *GetPixelFormatAttribfvProc)(HDC hdc, int, int, UINT, const int*, FLOAT*);
michael@0 98 typedef HGLRC (WINAPI *CreateContextAttribsProc)(HDC hDC, HGLRC, const int *);
michael@0 99
michael@0 100 GetExtensionsStringProc fGetExtensionsString;
michael@0 101 ChoosePixelFormatProc fChoosePixelFormat;
michael@0 102 GetPixelFormatAttribfvProc fGetPixelFormatAttribfv;
michael@0 103 GetPixelFormatAttribivProc fGetPixelFormatAttribiv;
michael@0 104 CreateContextAttribsProc fCreateContextAttribs;
michael@0 105 };
michael@0 106
michael@0 107 /**
michael@0 108 * Helper to create an OpenGL context for a DC using WGL. Configs with a sample count >= to
michael@0 109 * msaaSampleCount are preferred but if none is available then a context with a lower sample count
michael@0 110 * (including non-MSAA) will be created. If preferCoreProfile is true but a core profile cannot be
michael@0 111 * created then a compatible profile context will be created.
michael@0 112 */
michael@0 113 HGLRC SkCreateWGLContext(HDC dc, int msaaSampleCount, bool preferCoreProfile);
michael@0 114
michael@0 115 #endif

mercurial