blob: 619b8e0ff1842510da5f9ae656a38d3a7a91945e [file] [log] [blame]
bsalomon@google.combd7c6412011-12-01 16:34:28 +00001
2/*
3 * Copyright 2011 Google Inc.
4 *
5 * Use of this source code is governed by a BSD-style license that can be
6 * found in the LICENSE file.
7 */
8
9#include "SkRefCnt.h"
10
11#ifndef SkWGL_DEFINED
12#define SkWGL_DEFINED
13
14/**
15 * Working with WGL extensions can be a pain. Among the reasons is that You must
16 * have a GL context to get the proc addresses, but you want to use the procs to
17 * create a context in the first place. So you have to create a dummy GL ctx to
18 * get the proc addresses.
19 *
20 * This file helps by providing SkCreateWGLInterface(). It returns a struct of
21 * function pointers that it initializes. It also has a helper function to query
22 * for WGL extensions. It handles the fact that wglGetExtensionsString is itself
23 * an extension.
24 */
25
26#if !defined(WIN32_LEAN_AND_MEAN)
27 #define WIN32_LEAN_AND_MEAN
28 #define SK_LOCAL_LEAN_AND_MEAN
29#endif
30#include <Windows.h>
31#if defined(SK_LOCAL_LEAN_AND_MEAN)
32 #undef WIN32_LEAN_AND_MEAN
33 #undef SK_LOCAL_LEAN_AND_MEAN
34#endif
35
bsalomon@google.com8a189b02012-04-17 12:43:00 +000036#define SK_WGL_DRAW_TO_WINDOW 0x2001
37#define SK_WGL_ACCELERATION 0x2003
38#define SK_WGL_SUPPORT_OPENGL 0x2010
39#define SK_WGL_DOUBLE_BUFFER 0x2011
40#define SK_WGL_COLOR_BITS 0x2014
41#define SK_WGL_ALPHA_BITS 0x201B
42#define SK_WGL_STENCIL_BITS 0x2023
43#define SK_WGL_FULL_ACCELERATION 0x2027
44#define SK_WGL_SAMPLE_BUFFERS 0x2041
45#define SK_WGL_SAMPLES 0x2042
46#define SK_WGL_COVERAGE_SAMPLES 0x2042 /* same as SAMPLES */
47#define SK_WGL_COLOR_SAMPLES 0x20B9
48#define SK_WGL_CONTEXT_MAJOR_VERSION 0x2091
49#define SK_WGL_CONTEXT_MINOR_VERSION 0x2092
50#define SK_WGL_CONTEXT_LAYER_PLANE 0x2093
51#define SK_WGL_CONTEXT_FLAGS 0x2094
52#define SK_WGL_CONTEXT_PROFILE_MASK 0x9126
53#define SK_WGL_CONTEXT_DEBUG_BIT 0x0001
54#define SK_WGL_CONTEXT_FORWARD_COMPATIBLE_BIT 0x0002
55#define SK_WGL_CONTEXT_CORE_PROFILE_BIT 0x00000001
56#define SK_WGL_CONTEXT_COMPATIBILITY_PROFILE_BIT 0x00000002
57#define SK_WGL_CONTEXT_ES2_PROFILE_BIT 0x00000004
58#define SK_ERROR_INVALID_VERSION 0x2095
59#define SK_ERROR_INVALID_PROFILE 0x2096
bsalomon@google.combd7c6412011-12-01 16:34:28 +000060
61class SkWGLExtensions {
62public:
63 SkWGLExtensions();
64 /**
65 * Determines if an extensions is available for a given DC.
bsalomon@google.comeedef252011-12-01 16:50:24 +000066 * WGL_extensions_string is considered a prerequisite for all other
bsalomon@google.combd7c6412011-12-01 16:34:28 +000067 * extensions. It is necessary to check this before calling other class
68 * functions.
69 */
70 bool hasExtension(HDC dc, const char* ext) const;
71
72 const char* getExtensionsString(HDC hdc) const;
73 BOOL choosePixelFormat(HDC hdc, const int*, const FLOAT*, UINT, int*, UINT*) const;
74 BOOL getPixelFormatAttribiv(HDC, int, int, UINT, const int*, int*) const;
75 BOOL getPixelFormatAttribfv(HDC hdc, int, int, UINT, const int*, FLOAT*) const;
76 HGLRC createContextAttribs(HDC, HGLRC, const int *) const;
77
bsalomon@google.com8a189b02012-04-17 12:43:00 +000078 /**
79 * WGL doesn't have precise rules for the ordering of formats returned
80 * by wglChoosePixelFormat. This function helps choose among the set of
81 * formats returned by wglChoosePixelFormat. The rules in decreasing
82 * priority are:
83 * * Choose formats with the smallest sample count that is >=
84 * desiredSampleCount (or the largest sample count if all formats have
85 * fewer samples than desiredSampleCount.)
86 * * Choose formats with the fewest color samples when coverage sampling
87 * is available.
88 * * If the above rules leave multiple formats, choose the one that
89 * appears first in the formats array parameter.
90 */
91 int selectFormat(const int formats[],
92 int formatCount,
93 HDC dc,
94 int desiredSampleCount);
bsalomon@google.combd7c6412011-12-01 16:34:28 +000095private:
96 typedef const char* (WINAPI *GetExtensionsStringProc)(HDC hdc);
97 typedef BOOL (WINAPI *ChoosePixelFormatProc)(HDC hdc, const int *, const FLOAT *, UINT, int *, UINT *);
98 typedef BOOL (WINAPI *GetPixelFormatAttribivProc)(HDC, int, int, UINT, const int*, int*);
99 typedef BOOL (WINAPI *GetPixelFormatAttribfvProc)(HDC hdc, int, int, UINT, const int*, FLOAT*);
100 typedef HGLRC (WINAPI *CreateContextAttribsProc)(HDC hDC, HGLRC, const int *);
101
102 GetExtensionsStringProc fGetExtensionsString;
103 ChoosePixelFormatProc fChoosePixelFormat;
104 GetPixelFormatAttribfvProc fGetPixelFormatAttribfv;
105 GetPixelFormatAttribivProc fGetPixelFormatAttribiv;
106 CreateContextAttribsProc fCreateContextAttribs;
107};
108
109#endif