1 
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 
10 
11 #ifndef GrGLConfig_DEFINED
12 #define GrGLConfig_DEFINED
13 
14 #include "GrTypes.h"
15 
16 /**
17  * Optional GL config file.
18  */
19 #ifdef GR_GL_CUSTOM_SETUP_HEADER
20     #include GR_GL_CUSTOM_SETUP_HEADER
21 #endif
22 
23 #if !defined(GR_GL_FUNCTION_TYPE)
24     #define GR_GL_FUNCTION_TYPE
25 #endif
26 
27 /**
28  * The following are optional defines that can be enabled at the compiler
29  * command line, in a IDE project, in a GrUserConfig.h file, or in a GL custom
30  * file (if one is in use). If a GR_GL_CUSTOM_SETUP_HEADER is used they can
31  * also be placed there.
32  *
33  * GR_GL_LOG_CALLS: if 1 Gr can print every GL call using SkDebugf. Defaults to
34  * 0. Logging can be enabled and disabled at runtime using a debugger via to
35  * global gLogCallsGL. The initial value of gLogCallsGL is controlled by
36  * GR_GL_LOG_CALLS_START.
37  *
38  * GR_GL_LOG_CALLS_START: controls the initial value of gLogCallsGL when
39  * GR_GL_LOG_CALLS is 1. Defaults to 0.
40  *
41  * GR_GL_CHECK_ERROR: if enabled Gr can do a glGetError() after every GL call.
42  * Defaults to 1 if SK_DEBUG is set, otherwise 0. When GR_GL_CHECK_ERROR is 1
43  * this can be toggled in a debugger using the gCheckErrorGL global. The initial
44  * value of gCheckErrorGL is controlled by by GR_GL_CHECK_ERROR_START.
45  *
46  * GR_GL_CHECK_ERROR_START: controls the initial value of gCheckErrorGL
47  * when GR_GL_CHECK_ERROR is 1.  Defaults to 1.
48  *
49  * GR_GL_USE_BUFFER_DATA_NULL_HINT: When specifing new data for a vertex/index
50  * buffer that replaces old data Ganesh can give a hint to the driver that the
51  * previous data will not be used in future draws like this:
52  *  glBufferData(GL_..._BUFFER, size, NULL, usage);       //<--hint, NULL means
53  *  glBufferSubData(GL_..._BUFFER, 0, lessThanSize, data) //   old data can't be
54  *                                                        //   used again.
55  * However, this can be an unoptimization on some platforms, esp. Chrome.
56  * Chrome's cmd buffer will create a new allocation and memset the whole thing
57  * to zero (for security reasons). Defaults to 1 (enabled).
58  *
59  * GR_GL_PER_GL_FUNC_CALLBACK: When set to 1 the GrGLInterface object provides
60  * a function pointer that is called just before every gl function. The ptr must
61  * be valid (i.e. there is no NULL check). However, by default the callback will
62  * be set to a function that does nothing. The signature of the function is:
63  *    void function(const GrGLInterface*)
64  * It is not extern "C".
65  * The GrGLInterface field fCallback specifies the function ptr and there is an
66  * additional field fCallbackData of type intptr_t for client data.
67  *
68  * GR_GL_RGBA_8888_PIXEL_OPS_SLOW: Set this to 1 if it is known that performing
69  * glReadPixels / glTex(Sub)Image with format=GL_RGBA, type=GL_UNISIGNED_BYTE is
70  * significantly slower than format=GL_BGRA, type=GL_UNISIGNED_BYTE.
71  *
72  * GR_GL_FULL_READPIXELS_FASTER_THAN_PARTIAL: Set this to 1 if calling
73  * glReadPixels to read the entire framebuffer is faster than calling it with
74  * the same sized rectangle but with a framebuffer bound that is larger than
75  * the rectangle read.
76  *
77  * GR_GL_CHECK_ALLOC_WITH_GET_ERROR: If set to 1 this will then glTexImage,
78  * glBufferData, glRenderbufferStorage, etc will be checked for errors. This
79  * amounts to ensuring the error is GL_NO_ERROR, calling the allocating
80  * function, and then checking that the error is still GL_NO_ERROR. When the
81  * value is 0 we will assume no error was generated without checking.
82  *
83  * GR_GL_CHECK_FBO_STATUS_ONCE_PER_FORMAT: We will normally check the FBO status
84  * every time we bind a texture or renderbuffer to an FBO. However, in some
85  * environments CheckFrameBufferStatus is very expensive. If this is set we will
86  * check the first time we use a color format or a combination of color /
87  * stencil formats as attachments. If the FBO is complete we will assume
88  * subsequent attachments with the same formats are complete as well.
89  *
90  * GR_GL_MUST_USE_VBO: Indicates that all vertices and indices must be rendered
91  * from VBOs. Chromium's command buffer doesn't allow glVertexAttribArray with
92  * ARARY_BUFFER 0 bound or glDrawElements with ELEMENT_ARRAY_BUFFER 0 bound.
93  *
94  * GR_GL_USE_NEW_SHADER_SOURCE_SIGNATURE is for compatibility with the new version
95  * of the OpenGLES2.0 headers from Khronos.  glShaderSource now takes a const char * const *,
96  * instead of a const char
97  */
98 
99 #if !defined(GR_GL_LOG_CALLS)
100     #ifdef SK_DEBUG
101         #define GR_GL_LOG_CALLS 1
102     #else
103         #define GR_GL_LOG_CALLS 0
104     #endif
105 #endif
106 
107 #if !defined(GR_GL_LOG_CALLS_START)
108     #define GR_GL_LOG_CALLS_START                       0
109 #endif
110 
111 #if !defined(GR_GL_CHECK_ERROR)
112     #ifdef SK_DEBUG
113         #define GR_GL_CHECK_ERROR 1
114     #else
115         #define GR_GL_CHECK_ERROR 0
116     #endif
117 #endif
118 
119 #if !defined(GR_GL_CHECK_ERROR_START)
120     #define GR_GL_CHECK_ERROR_START                     1
121 #endif
122 
123 #if !defined(GR_GL_USE_BUFFER_DATA_NULL_HINT)
124     #define GR_GL_USE_BUFFER_DATA_NULL_HINT             1
125 #endif
126 
127 #if !defined(GR_GL_PER_GL_FUNC_CALLBACK)
128     #define GR_GL_PER_GL_FUNC_CALLBACK                  0
129 #endif
130 
131 #if !defined(GR_GL_RGBA_8888_PIXEL_OPS_SLOW)
132     #define GR_GL_RGBA_8888_PIXEL_OPS_SLOW              0
133 #endif
134 
135 #if !defined(GR_GL_FULL_READPIXELS_FASTER_THAN_PARTIAL)
136     #define GR_GL_FULL_READPIXELS_FASTER_THAN_PARTIAL   0
137 #endif
138 
139 #if !defined(GR_GL_CHECK_ALLOC_WITH_GET_ERROR)
140     #define GR_GL_CHECK_ALLOC_WITH_GET_ERROR            1
141 #endif
142 
143 #if !defined(GR_GL_CHECK_FBO_STATUS_ONCE_PER_FORMAT)
144     #define GR_GL_CHECK_FBO_STATUS_ONCE_PER_FORMAT      0
145 #endif
146 
147 #if !defined(GR_GL_MUST_USE_VBO)
148     #define GR_GL_MUST_USE_VBO                          0
149 #endif
150 
151 #if !defined(GR_GL_USE_NEW_SHADER_SOURCE_SIGNATURE)
152     #define GR_GL_USE_NEW_SHADER_SOURCE_SIGNATURE       0
153 #endif
154 
155 /**
156  * There is a strange bug that occurs on Macs with NVIDIA GPUs. We don't
157  * fully understand it. When (element) array buffers are continually
158  * respecified using glBufferData performance can fall off of a cliff. The
159  * driver winds up performing many DMA mapping / unmappings and chews up ~50% of
160  * the core. However, it has been observed that occaisonally respecifiying the
161  * buffer using glBufferData and then writing data using glBufferSubData
162  * prevents the bad behavior.
163  *
164  * There is a lot of uncertainty around this issue. In Chrome backgrounding
165  * the tab somehow initiates this behavior and we don't know what the connection
166  * is. Another observation is that Chrome's cmd buffer server will actually
167  * create a buffer full of zeros when it sees a NULL data param (for security
168  * reasons). If this is disabled and NULL is actually passed all the way to the
169  * driver then the workaround doesn't help.
170  *
171  * The issue is tracked at:
172  * http://code.google.com/p/chromium/issues/detail?id=114865
173  *
174  * When the workaround is enabled we will use the glBufferData / glBufferSubData
175  * trick every 128 array buffer uploads.
176  *
177  * Hopefully we will understand this better and have a cleaner fix or get a
178  * OS/driver level fix.
179  */
180 #define GR_GL_MAC_BUFFER_OBJECT_PERFOMANCE_WORKAROUND   \
181     (defined(SK_BUILD_FOR_MAC) &&                       \
182      !GR_GL_USE_BUFFER_DATA_NULL_HINT)
183 
184 #endif
185