OLD | NEW |
1 /* | 1 /* |
2 * Copyright 2011 Google Inc. | 2 * Copyright 2011 Google Inc. |
3 * | 3 * |
4 * Use of this source code is governed by a BSD-style license that can be | 4 * Use of this source code is governed by a BSD-style license that can be |
5 * found in the LICENSE file. | 5 * found in the LICENSE file. |
6 */ | 6 */ |
7 | 7 |
8 | 8 |
9 #include "GrGpuGL.h" | 9 #include "GrGpuGL.h" |
10 #include "GrGLStencilBuffer.h" | 10 #include "GrGLStencilBuffer.h" |
(...skipping 109 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
120 : GrGpu(context) | 120 : GrGpu(context) |
121 , fGLContext(ctx) { | 121 , fGLContext(ctx) { |
122 | 122 |
123 SkASSERT(ctx.isInitialized()); | 123 SkASSERT(ctx.isInitialized()); |
124 | 124 |
125 fCaps.reset(SkRef(ctx.info().caps())); | 125 fCaps.reset(SkRef(ctx.info().caps())); |
126 | 126 |
127 fHWBoundTextures.reset(ctx.info().caps()->maxFragmentTextureUnits()); | 127 fHWBoundTextures.reset(ctx.info().caps()->maxFragmentTextureUnits()); |
128 fHWTexGenSettings.reset(ctx.info().caps()->maxFixedFunctionTextureCoords()); | 128 fHWTexGenSettings.reset(ctx.info().caps()->maxFixedFunctionTextureCoords()); |
129 | 129 |
130 fillInConfigRenderableTable(); | |
131 | |
132 | |
133 GrGLClearErr(fGLContext.interface()); | 130 GrGLClearErr(fGLContext.interface()); |
134 | 131 |
135 if (gPrintStartupSpew) { | 132 if (gPrintStartupSpew) { |
136 const GrGLubyte* vendor; | 133 const GrGLubyte* vendor; |
137 const GrGLubyte* renderer; | 134 const GrGLubyte* renderer; |
138 const GrGLubyte* version; | 135 const GrGLubyte* version; |
139 GL_CALL_RET(vendor, GetString(GR_GL_VENDOR)); | 136 GL_CALL_RET(vendor, GetString(GR_GL_VENDOR)); |
140 GL_CALL_RET(renderer, GetString(GR_GL_RENDERER)); | 137 GL_CALL_RET(renderer, GetString(GR_GL_RENDERER)); |
141 GL_CALL_RET(version, GetString(GR_GL_VERSION)); | 138 GL_CALL_RET(version, GetString(GR_GL_VERSION)); |
142 GrPrintf("------------------------- create GrGpuGL %p --------------\n", | 139 GrPrintf("------------------------- create GrGpuGL %p --------------\n", |
(...skipping 27 matching lines...) Expand all Loading... |
170 | 167 |
171 // This must be called by before the GrDrawTarget destructor | 168 // This must be called by before the GrDrawTarget destructor |
172 this->releaseGeometry(); | 169 this->releaseGeometry(); |
173 // This subclass must do this before the base class destructor runs | 170 // This subclass must do this before the base class destructor runs |
174 // since we will unref the GrGLInterface. | 171 // since we will unref the GrGLInterface. |
175 this->releaseResources(); | 172 this->releaseResources(); |
176 } | 173 } |
177 | 174 |
178 /////////////////////////////////////////////////////////////////////////////// | 175 /////////////////////////////////////////////////////////////////////////////// |
179 | 176 |
180 void GrGpuGL::fillInConfigRenderableTable() { | |
181 | |
182 // OpenGL < 3.0 | |
183 // no support for render targets unless the GL_ARB_framebuffer_object | |
184 // extension is supported (in which case we get ALPHA, RED, RG, RGB, | |
185 // RGBA (ALPHA8, RGBA4, RGBA8) for OpenGL > 1.1). Note that we | |
186 // probably don't get R8 in this case. | |
187 | |
188 // OpenGL 3.0 | |
189 // base color renderable: ALPHA, RED, RG, RGB, and RGBA | |
190 // sized derivatives: ALPHA8, R8, RGBA4, RGBA8 | |
191 | |
192 // >= OpenGL 3.1 | |
193 // base color renderable: RED, RG, RGB, and RGBA | |
194 // sized derivatives: R8, RGBA4, RGBA8 | |
195 // if the GL_ARB_compatibility extension is supported then we get back | |
196 // support for GL_ALPHA and ALPHA8 | |
197 | |
198 // GL_EXT_bgra adds BGRA render targets to any version | |
199 | |
200 // ES 2.0 | |
201 // color renderable: RGBA4, RGB5_A1, RGB565 | |
202 // GL_EXT_texture_rg adds support for R8 as a color render target | |
203 // GL_OES_rgb8_rgba8 and/or GL_ARM_rgba8 adds support for RGBA8 | |
204 // GL_EXT_texture_format_BGRA8888 and/or GL_APPLE_texture_format_BGRA8888 a
dded BGRA support | |
205 | |
206 // ES 3.0 | |
207 // Same as ES 2.0 except R8 and RGBA8 are supported without extensions (the
functions called | |
208 // below already account for this). | |
209 | |
210 if (kDesktop_GrGLBinding == this->glBinding()) { | |
211 // Post 3.0 we will get R8 | |
212 // Prior to 3.0 we will get ALPHA8 (with GL_ARB_framebuffer_object) | |
213 if (this->glVersion() >= GR_GL_VER(3,0) || | |
214 this->hasExtension("GL_ARB_framebuffer_object")) { | |
215 fConfigRenderSupport[kAlpha_8_GrPixelConfig] = true; | |
216 } | |
217 } else { | |
218 // On ES we can only hope for R8 | |
219 fConfigRenderSupport[kAlpha_8_GrPixelConfig] = | |
220 this->glCaps().textureRedSupport(); | |
221 } | |
222 | |
223 if (kDesktop_GrGLBinding != this->glBinding()) { | |
224 // only available in ES | |
225 fConfigRenderSupport[kRGB_565_GrPixelConfig] = true; | |
226 } | |
227 | |
228 // we no longer support 444 as a render target | |
229 fConfigRenderSupport[kRGBA_4444_GrPixelConfig] = false; | |
230 | |
231 if (this->glCaps().rgba8RenderbufferSupport()) { | |
232 fConfigRenderSupport[kRGBA_8888_GrPixelConfig] = true; | |
233 } | |
234 | |
235 if (this->glCaps().bgraFormatSupport()) { | |
236 fConfigRenderSupport[kBGRA_8888_GrPixelConfig] = true; | |
237 } | |
238 } | |
239 | 177 |
240 GrPixelConfig GrGpuGL::preferredReadPixelsConfig(GrPixelConfig readConfig, | 178 GrPixelConfig GrGpuGL::preferredReadPixelsConfig(GrPixelConfig readConfig, |
241 GrPixelConfig surfaceConfig) co
nst { | 179 GrPixelConfig surfaceConfig) co
nst { |
242 if (GR_GL_RGBA_8888_PIXEL_OPS_SLOW && kRGBA_8888_GrPixelConfig == readConfig
) { | 180 if (GR_GL_RGBA_8888_PIXEL_OPS_SLOW && kRGBA_8888_GrPixelConfig == readConfig
) { |
243 return kBGRA_8888_GrPixelConfig; | 181 return kBGRA_8888_GrPixelConfig; |
244 } else if (fGLContext.info().isMesa() && | 182 } else if (fGLContext.info().isMesa() && |
245 GrBytesPerPixel(readConfig) == 4 && | 183 GrBytesPerPixel(readConfig) == 4 && |
246 GrPixelConfigSwapRAndB(readConfig) == surfaceConfig) { | 184 GrPixelConfigSwapRAndB(readConfig) == surfaceConfig) { |
247 // Mesa 3D takes a slow path on when reading back BGRA from an RGBA sur
face and vice-versa. | 185 // Mesa 3D takes a slow path on when reading back BGRA from an RGBA sur
face and vice-versa. |
248 // Perhaps this should be guarded by some compiletime or runtime check. | 186 // Perhaps this should be guarded by some compiletime or runtime check. |
(...skipping 2204 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2453 // texture. | 2391 // texture. |
2454 fHWBoundTextures[lastUnitIdx] = NULL; | 2392 fHWBoundTextures[lastUnitIdx] = NULL; |
2455 } | 2393 } |
2456 | 2394 |
2457 namespace { | 2395 namespace { |
2458 // Determines whether glBlitFramebuffer could be used between src and dst. | 2396 // Determines whether glBlitFramebuffer could be used between src and dst. |
2459 inline bool can_blit_framebuffer(const GrSurface* dst, | 2397 inline bool can_blit_framebuffer(const GrSurface* dst, |
2460 const GrSurface* src, | 2398 const GrSurface* src, |
2461 const GrGpuGL* gpu, | 2399 const GrGpuGL* gpu, |
2462 bool* wouldNeedTempFBO = NULL) { | 2400 bool* wouldNeedTempFBO = NULL) { |
2463 if (gpu->isConfigRenderable(dst->config()) && | 2401 if (gpu->glCaps().isConfigRenderable(dst->config()) && |
2464 gpu->isConfigRenderable(src->config()) && | 2402 gpu->glCaps().isConfigRenderable(src->config()) && |
2465 gpu->glCaps().usesMSAARenderBuffers()) { | 2403 gpu->glCaps().usesMSAARenderBuffers()) { |
2466 // ES3 doesn't allow framebuffer blits when the src has MSAA and the con
figs don't match | 2404 // ES3 doesn't allow framebuffer blits when the src has MSAA and the con
figs don't match |
2467 // or the rects are not the same (not just the same size but have the sa
me edges). | 2405 // or the rects are not the same (not just the same size but have the sa
me edges). |
2468 if (GrGLCaps::kES_3_0_MSFBOType == gpu->glCaps().msFBOType() && | 2406 if (GrGLCaps::kES_3_0_MSFBOType == gpu->glCaps().msFBOType() && |
2469 (src->desc().fSampleCnt > 0 || src->config() != dst->config())) { | 2407 (src->desc().fSampleCnt > 0 || src->config() != dst->config())) { |
2470 return false; | 2408 return false; |
2471 } | 2409 } |
2472 if (NULL != wouldNeedTempFBO) { | 2410 if (NULL != wouldNeedTempFBO) { |
2473 *wouldNeedTempFBO = NULL == dst->asRenderTarget() || NULL == src->as
RenderTarget(); | 2411 *wouldNeedTempFBO = NULL == dst->asRenderTarget() || NULL == src->as
RenderTarget(); |
2474 } | 2412 } |
(...skipping 19 matching lines...) Expand all Loading... |
2494 // then we don't want to copy to the texture but to the MSAA buffer. | 2432 // then we don't want to copy to the texture but to the MSAA buffer. |
2495 if (NULL != dstRT && dstRT->renderFBOID() != dstRT->textureFBOID()) { | 2433 if (NULL != dstRT && dstRT->renderFBOID() != dstRT->textureFBOID()) { |
2496 return false; | 2434 return false; |
2497 } | 2435 } |
2498 const GrGLRenderTarget* srcRT = static_cast<const GrGLRenderTarget*>(src->as
RenderTarget()); | 2436 const GrGLRenderTarget* srcRT = static_cast<const GrGLRenderTarget*>(src->as
RenderTarget()); |
2499 // If the src is multisampled (and uses an extension where there is a separa
te MSAA | 2437 // If the src is multisampled (and uses an extension where there is a separa
te MSAA |
2500 // renderbuffer) then it is an invalid operation to call CopyTexSubImage | 2438 // renderbuffer) then it is an invalid operation to call CopyTexSubImage |
2501 if (NULL != srcRT && srcRT->renderFBOID() != srcRT->textureFBOID()) { | 2439 if (NULL != srcRT && srcRT->renderFBOID() != srcRT->textureFBOID()) { |
2502 return false; | 2440 return false; |
2503 } | 2441 } |
2504 if (gpu->isConfigRenderable(src->config()) && NULL != dst->asTexture() && | 2442 if (gpu->glCaps().isConfigRenderable(src->config()) && NULL != dst->asTextur
e() && |
2505 dst->origin() == src->origin() && kIndex_8_GrPixelConfig != src->config(
)) { | 2443 dst->origin() == src->origin() && kIndex_8_GrPixelConfig != src->config(
)) { |
2506 if (NULL != wouldNeedTempFBO) { | 2444 if (NULL != wouldNeedTempFBO) { |
2507 *wouldNeedTempFBO = NULL == src->asRenderTarget(); | 2445 *wouldNeedTempFBO = NULL == src->asRenderTarget(); |
2508 } | 2446 } |
2509 return true; | 2447 return true; |
2510 } else { | 2448 } else { |
2511 return false; | 2449 return false; |
2512 } | 2450 } |
2513 } | 2451 } |
2514 | 2452 |
(...skipping 219 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2734 this->setVertexArrayID(gpu, 0); | 2672 this->setVertexArrayID(gpu, 0); |
2735 } | 2673 } |
2736 int attrCount = gpu->glCaps().maxVertexAttributes(); | 2674 int attrCount = gpu->glCaps().maxVertexAttributes(); |
2737 if (fDefaultVertexArrayAttribState.count() != attrCount) { | 2675 if (fDefaultVertexArrayAttribState.count() != attrCount) { |
2738 fDefaultVertexArrayAttribState.resize(attrCount); | 2676 fDefaultVertexArrayAttribState.resize(attrCount); |
2739 } | 2677 } |
2740 attribState = &fDefaultVertexArrayAttribState; | 2678 attribState = &fDefaultVertexArrayAttribState; |
2741 } | 2679 } |
2742 return attribState; | 2680 return attribState; |
2743 } | 2681 } |
OLD | NEW |