• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 GrPrintf. 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 GR_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_NO_CONSTANT_ATTRIBUTES: if this evaluates to true then the GL backend
50  * will use uniforms instead of attributes in all cases when there is not
51  * per-vertex data. This is important when the underlying GL implementation
52  * doesn't actually support immediate style attribute values (e.g. when
53  * the GL stream is converted to DX as in ANGLE on Chrome). Defaults to 0.
54  *
55  * GR_GL_USE_BUFFER_DATA_NULL_HINT: When specifing new data for a vertex/index
56  * buffer that replaces old data Ganesh can give a hint to the driver that the
57  * previous data will not be used in future draws like this:
58  *  glBufferData(GL_..._BUFFER, size, NULL, usage);       //<--hint, NULL means
59  *  glBufferSubData(GL_..._BUFFER, 0, lessThanSize, data) //   old data can't be
60  *                                                        //   used again.
61  * However, this can be an unoptimization on some platforms, esp. Chrome.
62  * Chrome's cmd buffer will create a new allocation and memset the whole thing
63  * to zero (for security reasons). Defaults to 1 (enabled).
64  *
65  * GR_GL_PER_GL_FUNC_CALLBACK: When set to 1 the GrGLInterface object provides
66  * a function pointer that is called just before every gl function. The ptr must
67  * be valid (i.e. there is no NULL check). However, by default the callback will
68  * be set to a function that does nothing. The signature of the function is:
69  *    void function(const GrGLInterface*)
70  * It is not extern "C".
71  * The GrGLInterface field fCallback specifies the function ptr and there is an
72  * additional field fCallbackData of type intptr_t for client data.
73  *
74  * GR_GL_RGBA_8888_PIXEL_OPS_SLOW: Set this to 1 if it is known that performing
75  * glReadPixels / glTex(Sub)Image with format=GL_RGBA, type=GL_UNISIGNED_BYTE is
76  * significantly slower than format=GL_BGRA, type=GL_UNISIGNED_BYTE.
77  *
78  * GR_GL_FULL_READPIXELS_FASTER_THAN_PARTIAL: Set this to 1 if calling
79  * glReadPixels to read the entire framebuffer is faster than calling it with
80  * the same sized rectangle but with a framebuffer bound that is larger than
81  * the rectangle read.
82  *
83  * GR_GL_CHECK_ALLOC_WITH_GET_ERROR: If set to 1 this will then glTexImage,
84  * glBufferData, glRenderbufferStorage, etc will be checked for errors. This
85  * amounts to ensuring the error is GL_NO_ERROR, calling the allocating
86  * function, and then checking that the error is still GL_NO_ERROR. When the
87  * value is 0 we will assume no error was generated without checking.
88  *
89  * GR_GL_CHECK_FBO_STATUS_ONCE_PER_FORMAT: We will normally check the FBO status
90  * every time we bind a texture or renderbuffer to an FBO. However, in some
91  * environments CheckFrameBufferStatus is very expensive. If this is set we will
92  * check the first time we use a color format or a combination of color /
93  * stencil formats as attachments. If the FBO is complete we will assume
94  * subsequent attachments with the same formats are complete as well.
95  *
96  * GR_GL_USE_NV_PATH_RENDERING: Enable experimental support for
97  * GL_NV_path_rendering. There are known issues with clipping, non-AA paths, and
98  * perspective.
99  */
100 
101 #if !defined(GR_GL_LOG_CALLS)
102     #define GR_GL_LOG_CALLS                             GR_DEBUG
103 #endif
104 
105 #if !defined(GR_GL_LOG_CALLS_START)
106     #define GR_GL_LOG_CALLS_START                       0
107 #endif
108 
109 #if !defined(GR_GL_CHECK_ERROR)
110     #define GR_GL_CHECK_ERROR                           GR_DEBUG
111 #endif
112 
113 #if !defined(GR_GL_CHECK_ERROR_START)
114     #define GR_GL_CHECK_ERROR_START                     1
115 #endif
116 
117 #if !defined(GR_GL_NO_CONSTANT_ATTRIBUTES)
118     #define GR_GL_NO_CONSTANT_ATTRIBUTES                0
119 #endif
120 
121 #if !defined(GR_GL_USE_BUFFER_DATA_NULL_HINT)
122     #define GR_GL_USE_BUFFER_DATA_NULL_HINT             1
123 #endif
124 
125 #if !defined(GR_GL_PER_GL_FUNC_CALLBACK)
126     #define GR_GL_PER_GL_FUNC_CALLBACK                  0
127 #endif
128 
129 #if !defined(GR_GL_RGBA_8888_PIXEL_OPS_SLOW)
130     #define GR_GL_RGBA_8888_PIXEL_OPS_SLOW              0
131 #endif
132 
133 #if !defined(GR_GL_FULL_READPIXELS_FASTER_THAN_PARTIAL)
134     #define GR_GL_FULL_READPIXELS_FASTER_THAN_PARTIAL   0
135 #endif
136 
137 #if !defined(GR_GL_CHECK_ALLOC_WITH_GET_ERROR)
138     #define GR_GL_CHECK_ALLOC_WITH_GET_ERROR            1
139 #endif
140 
141 #if !defined(GR_GL_CHECK_FBO_STATUS_ONCE_PER_FORMAT)
142     #define GR_GL_CHECK_FBO_STATUS_ONCE_PER_FORMAT      0
143 #endif
144 
145 #if !defined(GR_GL_USE_NV_PATH_RENDERING)
146     #define GR_GL_USE_NV_PATH_RENDERING                 0
147 #endif
148 
149 /**
150  * There is a strange bug that occurs on Macs with NVIDIA GPUs. We don't
151  * fully understand it. When (element) array buffers are continually
152  * respecified using glBufferData performance can fall off of a cliff. The
153  * driver winds up performing many DMA mapping / unmappings and chews up ~50% of
154  * the core. However, it has been observed that occaisonally respecifiying the
155  * buffer using glBufferData and then writing data using glBufferSubData
156  * prevents the bad behavior.
157  *
158  * There is a lot of uncertainty around this issue. In Chrome backgrounding
159  * the tab somehow initiates this behavior and we don't know what the connection
160  * is. Another observation is that Chrome's cmd buffer server will actually
161  * create a buffer full of zeros when it sees a NULL data param (for security
162  * reasons). If this is disabled and NULL is actually passed all the way to the
163  * driver then the workaround doesn't help.
164  *
165  * The issue is tracked at:
166  * http://code.google.com/p/chromium/issues/detail?id=114865
167  *
168  * When the workaround is enabled we will use the glBufferData / glBufferSubData
169  * trick every 128 array buffer uploads.
170  *
171  * Hopefully we will understand this better and have a cleaner fix or get a
172  * OS/driver level fix.
173  */
174 #define GR_GL_MAC_BUFFER_OBJECT_PERFOMANCE_WORKAROUND   \
175     (GR_MAC_BUILD &&                                    \
176      !GR_GL_USE_BUFFER_DATA_NULL_HINT)
177 
178 #endif
179