Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(84)

Side by Side Diff: include/utils/SkWGL.h

Issue 336863009: When performing offscreen rendering on windows, attempt to use a pbuffer context. (Closed) Base URL: https://skia.googlesource.com/skia.git@klein
Patch Set: Address initial comments Created 6 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 1
2 /* 2 /*
3 * Copyright 2011 Google Inc. 3 * Copyright 2011 Google Inc.
4 * 4 *
5 * Use of this source code is governed by a BSD-style license that can be 5 * Use of this source code is governed by a BSD-style license that can be
6 * found in the LICENSE file. 6 * found in the LICENSE file.
7 */ 7 */
8 8
9 #include "SkRefCnt.h" 9 #include "SkRefCnt.h"
10 10
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
49 #define SK_WGL_CONTEXT_FLAGS 0x2094 49 #define SK_WGL_CONTEXT_FLAGS 0x2094
50 #define SK_WGL_CONTEXT_PROFILE_MASK 0x9126 50 #define SK_WGL_CONTEXT_PROFILE_MASK 0x9126
51 #define SK_WGL_CONTEXT_DEBUG_BIT 0x0001 51 #define SK_WGL_CONTEXT_DEBUG_BIT 0x0001
52 #define SK_WGL_CONTEXT_FORWARD_COMPATIBLE_BIT 0x0002 52 #define SK_WGL_CONTEXT_FORWARD_COMPATIBLE_BIT 0x0002
53 #define SK_WGL_CONTEXT_CORE_PROFILE_BIT 0x00000001 53 #define SK_WGL_CONTEXT_CORE_PROFILE_BIT 0x00000001
54 #define SK_WGL_CONTEXT_COMPATIBILITY_PROFILE_BIT 0x00000002 54 #define SK_WGL_CONTEXT_COMPATIBILITY_PROFILE_BIT 0x00000002
55 #define SK_WGL_CONTEXT_ES2_PROFILE_BIT 0x00000004 55 #define SK_WGL_CONTEXT_ES2_PROFILE_BIT 0x00000004
56 #define SK_ERROR_INVALID_VERSION 0x2095 56 #define SK_ERROR_INVALID_VERSION 0x2095
57 #define SK_ERROR_INVALID_PROFILE 0x2096 57 #define SK_ERROR_INVALID_PROFILE 0x2096
58 58
59 DECLARE_HANDLE(HPBUFFER);
60
59 class SkWGLExtensions { 61 class SkWGLExtensions {
60 public: 62 public:
61 SkWGLExtensions(); 63 SkWGLExtensions();
62 /** 64 /**
63 * Determines if an extensions is available for a given DC. 65 * Determines if an extensions is available for a given DC.
64 * WGL_extensions_string is considered a prerequisite for all other 66 * WGL_extensions_string is considered a prerequisite for all other
65 * extensions. It is necessary to check this before calling other class 67 * extensions. It is necessary to check this before calling other class
66 * functions. 68 * functions.
67 */ 69 */
68 bool hasExtension(HDC dc, const char* ext) const; 70 bool hasExtension(HDC dc, const char* ext) const;
69 71
70 const char* getExtensionsString(HDC hdc) const; 72 const char* getExtensionsString(HDC hdc) const;
71 BOOL choosePixelFormat(HDC hdc, const int*, const FLOAT*, UINT, int*, UINT*) const; 73 BOOL choosePixelFormat(HDC hdc, const int*, const FLOAT*, UINT, int*, UINT*) const;
72 BOOL getPixelFormatAttribiv(HDC, int, int, UINT, const int*, int*) const; 74 BOOL getPixelFormatAttribiv(HDC, int, int, UINT, const int*, int*) const;
73 BOOL getPixelFormatAttribfv(HDC hdc, int, int, UINT, const int*, FLOAT*) con st; 75 BOOL getPixelFormatAttribfv(HDC hdc, int, int, UINT, const int*, FLOAT*) con st;
74 HGLRC createContextAttribs(HDC, HGLRC, const int *) const; 76 HGLRC createContextAttribs(HDC, HGLRC, const int *) const;
75 77
78 BOOL swapInterval(int interval) const;
79
80 HPBUFFER createPbuffer(HDC, int , int, int, const int*) const;
81 HDC getPbufferDC(HPBUFFER) const;
82 int releasePbufferDC(HPBUFFER, HDC) const;
83 BOOL destroyPbuffer(HPBUFFER) const;
84
76 /** 85 /**
77 * WGL doesn't have precise rules for the ordering of formats returned 86 * WGL doesn't have precise rules for the ordering of formats returned
78 * by wglChoosePixelFormat. This function helps choose among the set of 87 * by wglChoosePixelFormat. This function helps choose among the set of
79 * formats returned by wglChoosePixelFormat. The rules in decreasing 88 * formats returned by wglChoosePixelFormat. The rules in decreasing
80 * priority are: 89 * priority are:
81 * * Choose formats with the smallest sample count that is >= 90 * * Choose formats with the smallest sample count that is >=
82 * desiredSampleCount (or the largest sample count if all formats have 91 * desiredSampleCount (or the largest sample count if all formats have
83 * fewer samples than desiredSampleCount.) 92 * fewer samples than desiredSampleCount.)
84 * * Choose formats with the fewest color samples when coverage sampling 93 * * Choose formats with the fewest color samples when coverage sampling
85 * is available. 94 * is available.
86 * * If the above rules leave multiple formats, choose the one that 95 * * If the above rules leave multiple formats, choose the one that
87 * appears first in the formats array parameter. 96 * appears first in the formats array parameter.
88 */ 97 */
89 int selectFormat(const int formats[], 98 int selectFormat(const int formats[],
90 int formatCount, 99 int formatCount,
91 HDC dc, 100 HDC dc,
92 int desiredSampleCount); 101 int desiredSampleCount) const;
93 private: 102 private:
94 typedef const char* (WINAPI *GetExtensionsStringProc)(HDC hdc); 103 typedef const char* (WINAPI *GetExtensionsStringProc)(HDC);
95 typedef BOOL (WINAPI *ChoosePixelFormatProc)(HDC hdc, const int *, const FLO AT *, UINT, int *, UINT *); 104 typedef BOOL (WINAPI *ChoosePixelFormatProc)(HDC, const int *, const FLOAT * , UINT, int *, UINT *);
96 typedef BOOL (WINAPI *GetPixelFormatAttribivProc)(HDC, int, int, UINT, const int*, int*); 105 typedef BOOL (WINAPI *GetPixelFormatAttribivProc)(HDC, int, int, UINT, const int*, int*);
97 typedef BOOL (WINAPI *GetPixelFormatAttribfvProc)(HDC hdc, int, int, UINT, c onst int*, FLOAT*); 106 typedef BOOL (WINAPI *GetPixelFormatAttribfvProc)(HDC, int, int, UINT, const int*, FLOAT*);
98 typedef HGLRC (WINAPI *CreateContextAttribsProc)(HDC hDC, HGLRC, const int * ); 107 typedef HGLRC (WINAPI *CreateContextAttribsProc)(HDC, HGLRC, const int *);
108 typedef BOOL (WINAPI* SwapIntervalProc)(int);
109 typedef HPBUFFER (WINAPI* CreatePbufferProc)(HDC, int , int, int, const int* );
110 typedef HDC (WINAPI* GetPbufferDCProc)(HPBUFFER);
111 typedef int (WINAPI* ReleasePbufferDCProc)(HPBUFFER, HDC);
112 typedef BOOL (WINAPI* DestroyPbufferProc)(HPBUFFER);
99 113
100 GetExtensionsStringProc fGetExtensionsString; 114 GetExtensionsStringProc fGetExtensionsString;
101 ChoosePixelFormatProc fChoosePixelFormat; 115 ChoosePixelFormatProc fChoosePixelFormat;
102 GetPixelFormatAttribfvProc fGetPixelFormatAttribfv; 116 GetPixelFormatAttribfvProc fGetPixelFormatAttribfv;
103 GetPixelFormatAttribivProc fGetPixelFormatAttribiv; 117 GetPixelFormatAttribivProc fGetPixelFormatAttribiv;
104 CreateContextAttribsProc fCreateContextAttribs; 118 CreateContextAttribsProc fCreateContextAttribs;
119 SwapIntervalProc fSwapInterval;
120 CreatePbufferProc fCreatePbuffer;
121 GetPbufferDCProc fGetPbufferDC;
122 ReleasePbufferDCProc fReleasePbufferDC;
123 DestroyPbufferProc fDestroyPbuffer;
105 }; 124 };
106 125
107 enum SkWGLContextRequest { 126 enum SkWGLContextRequest {
108 /** Requests to create core profile context if possible, otherwise 127 /** Requests to create core profile context if possible, otherwise
109 compatibility profile. */ 128 compatibility profile. */
110 kGLPreferCoreProfile_SkWGLContextRequest, 129 kGLPreferCoreProfile_SkWGLContextRequest,
111 /** Requests to create compatibility profile context if possible, otherwise 130 /** Requests to create compatibility profile context if possible, otherwise
112 core profile. */ 131 core profile. */
113 kGLPreferCompatibilityProfile_SkWGLContextRequest, 132 kGLPreferCompatibilityProfile_SkWGLContextRequest,
114 /** Requests to create GL ES profile context. */ 133 /** Requests to create GL ES profile context. */
115 kGLES_SkWGLContextRequest 134 kGLES_SkWGLContextRequest
116 }; 135 };
117 /** 136 /**
118 * Helper to create an OpenGL context for a DC using WGL. Configs with a sample count >= to 137 * Helper to create an OpenGL context for a DC using WGL. Configs with a sample count >= to
119 * msaaSampleCount are preferred but if none is available then a context with a lower sample count 138 * msaaSampleCount are preferred but if none is available then a context with a lower sample count
120 * (including non-MSAA) will be created. If preferCoreProfile is true but a core profile cannot be 139 * (including non-MSAA) will be created. If preferCoreProfile is true but a core profile cannot be
121 * created then a compatible profile context will be created. 140 * created then a compatible profile context will be created.
122 */ 141 */
123 HGLRC SkCreateWGLContext(HDC dc, int msaaSampleCount, SkWGLContextRequest contex t); 142 HGLRC SkCreateWGLContext(HDC dc, int msaaSampleCount, SkWGLContextRequest contex t);
124 143
144 /**
145 * Helper class for creating a pbuffer context and deleting all the handles when finished. This
146 * requires that a device context has been created. However, the pbuffer gets it s own device
147 * context. The original device context can be released once the pbuffer context is created.
148 */
149 class SkWGLPbufferContext : public SkRefCnt {
150 public:
151 static SkWGLPbufferContext* Create(HDC parentDC, int msaaSampleCount,
152 SkWGLContextRequest contextType);
153
154 virtual ~SkWGLPbufferContext();
155
156 HDC getDC() const { return fDC; }
157 HGLRC getGLRC() const { return fGLRC; }
158
159 private:
160 SkWGLPbufferContext(HPBUFFER pbuffer, HDC dc, HGLRC glrc);
161
162 HPBUFFER fPbuffer;
163 HDC fDC;
164 HGLRC fGLRC;
165 SkWGLExtensions fExtensions;
166 };
167
125 #endif 168 #endif
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698