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 2209 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2220 } | 2220 } |
2221 } | 2221 } |
2222 | 2222 |
2223 void GrGpuGL::setSpareTextureUnit() { | 2223 void GrGpuGL::setSpareTextureUnit() { |
2224 if (fHWActiveTextureUnitIdx != (GR_GL_TEXTURE0 + SPARE_TEX_UNIT)) { | 2224 if (fHWActiveTextureUnitIdx != (GR_GL_TEXTURE0 + SPARE_TEX_UNIT)) { |
2225 GL_CALL(ActiveTexture(GR_GL_TEXTURE0 + SPARE_TEX_UNIT)); | 2225 GL_CALL(ActiveTexture(GR_GL_TEXTURE0 + SPARE_TEX_UNIT)); |
2226 fHWActiveTextureUnitIdx = SPARE_TEX_UNIT; | 2226 fHWActiveTextureUnitIdx = SPARE_TEX_UNIT; |
2227 } | 2227 } |
2228 } | 2228 } |
2229 | 2229 |
| 2230 namespace { |
| 2231 // Determines whether glBlitFramebuffer could be used between src and dst. |
| 2232 inline bool can_blit_framebuffer(const GrSurface* dst, const GrSurface* src, con
st GrGpuGL* gpu) { |
| 2233 return gpu->isConfigRenderable(dst->config()) && gpu->isConfigRenderable(src
->config()) && |
| 2234 (GrGLCaps::kDesktopEXT_MSFBOType == gpu->glCaps().msFBOType() || |
| 2235 GrGLCaps::kDesktopARB_MSFBOType == gpu->glCaps().msFBOType()); |
| 2236 } |
| 2237 } |
| 2238 |
| 2239 bool GrGpuGL::onCopySurface(GrSurface* dst, |
| 2240 GrSurface* src, |
| 2241 const SkIRect& srcRect, |
| 2242 const SkIPoint& dstPoint) { |
| 2243 // TODO: Add support for glCopyTexSubImage for cases when src is an FBO and
dst is not |
| 2244 // renderable or we don't have glBlitFramebuffer. |
| 2245 bool copied = false; |
| 2246 // Check whether both src and dst could be attached to an FBO and we're on a
GL that supports |
| 2247 // glBlitFramebuffer. |
| 2248 if (can_blit_framebuffer(dst, src, this)) { |
| 2249 SkIRect dstRect = SkIRect::MakeXYWH(dstPoint.fX, dstPoint.fY, |
| 2250 srcRect.width(), srcRect.height()); |
| 2251 bool selfOverlap = false; |
| 2252 if (dst->isSameAs(src)) { |
| 2253 selfOverlap = SkIRect::IntersectsNoEmptyCheck(dstRect, srcRect); |
| 2254 } |
| 2255 |
| 2256 if (!selfOverlap) { |
| 2257 GrGLuint dstFBO = 0; |
| 2258 GrGLuint srcFBO = 0; |
| 2259 GrGLIRect dstVP; |
| 2260 GrGLIRect srcVP; |
| 2261 GrGLRenderTarget* dstRT = static_cast<GrGLRenderTarget*>(dst->asRend
erTarget()); |
| 2262 GrGLRenderTarget* srcRT = static_cast<GrGLRenderTarget*>(src->asRend
erTarget()); |
| 2263 if (NULL == dstRT) { |
| 2264 GrAssert(NULL != dst->asTexture()); |
| 2265 GrGLuint texID = static_cast<GrGLTexture*>(dst->asTexture())->te
xtureID(); |
| 2266 GL_CALL(GenFramebuffers(1, &dstFBO)); |
| 2267 GL_CALL(BindFramebuffer(GR_GL_DRAW_FRAMEBUFFER, dstFBO)); |
| 2268 GL_CALL(FramebufferTexture2D(GR_GL_DRAW_FRAMEBUFFER, |
| 2269 GR_GL_COLOR_ATTACHMENT0, |
| 2270 GR_GL_TEXTURE_2D, |
| 2271 texID, |
| 2272 0)); |
| 2273 dstVP.fLeft = 0; |
| 2274 dstVP.fBottom = 0; |
| 2275 dstVP.fWidth = dst->width(); |
| 2276 dstVP.fHeight = dst->height(); |
| 2277 } else { |
| 2278 GL_CALL(BindFramebuffer(GR_GL_DRAW_FRAMEBUFFER, dstRT->renderFBO
ID())); |
| 2279 dstVP = dstRT->getViewport(); |
| 2280 } |
| 2281 if (NULL == srcRT) { |
| 2282 GrAssert(NULL != src->asTexture()); |
| 2283 GrGLuint texID = static_cast<GrGLTexture*>(src->asTexture())->te
xtureID(); |
| 2284 GL_CALL(GenFramebuffers(1, &srcFBO)); |
| 2285 GL_CALL(BindFramebuffer(GR_GL_READ_FRAMEBUFFER, srcFBO)); |
| 2286 GL_CALL(FramebufferTexture2D(GR_GL_READ_FRAMEBUFFER, |
| 2287 GR_GL_COLOR_ATTACHMENT0, |
| 2288 GR_GL_TEXTURE_2D, |
| 2289 texID, |
| 2290 0)); |
| 2291 srcVP.fLeft = 0; |
| 2292 srcVP.fBottom = 0; |
| 2293 srcVP.fWidth = src->width(); |
| 2294 srcVP.fHeight = src->height(); |
| 2295 } else { |
| 2296 GL_CALL(BindFramebuffer(GR_GL_READ_FRAMEBUFFER, srcRT->renderFBO
ID())); |
| 2297 srcVP = srcRT->getViewport(); |
| 2298 } |
| 2299 |
| 2300 // We modified the bound FB |
| 2301 fHWBoundRenderTarget = NULL; |
| 2302 GrGLIRect srcGLRect; |
| 2303 GrGLIRect dstGLRect; |
| 2304 srcGLRect.setRelativeTo(srcVP, |
| 2305 srcRect.fLeft, |
| 2306 srcRect.fTop, |
| 2307 srcRect.width(), |
| 2308 srcRect.height(), |
| 2309 src->origin()); |
| 2310 dstGLRect.setRelativeTo(dstVP, |
| 2311 dstRect.fLeft, |
| 2312 dstRect.fTop, |
| 2313 dstRect.width(), |
| 2314 dstRect.height(), |
| 2315 dst->origin()); |
| 2316 |
| 2317 GrAutoTRestore<ScissorState> asr; |
| 2318 if (GrGLCaps::kDesktopEXT_MSFBOType == this->glCaps().msFBOType()) { |
| 2319 // The EXT version applies the scissor during the blit, so disab
le it. |
| 2320 asr.reset(&fScissorState); |
| 2321 fScissorState.fEnabled = false; |
| 2322 this->flushScissor(); |
| 2323 } |
| 2324 GrGLint srcY0; |
| 2325 GrGLint srcY1; |
| 2326 // Does the blit need to y-mirror or not? |
| 2327 if (src->origin() == dst->origin()) { |
| 2328 srcY0 = srcGLRect.fBottom; |
| 2329 srcY1 = srcGLRect.fBottom + srcGLRect.fHeight; |
| 2330 } else { |
| 2331 srcY0 = srcGLRect.fBottom + srcGLRect.fHeight; |
| 2332 srcY1 = srcGLRect.fBottom; |
| 2333 } |
| 2334 GL_CALL(BlitFramebuffer(srcGLRect.fLeft, |
| 2335 srcY0, |
| 2336 srcGLRect.fLeft + srcGLRect.fWidth, |
| 2337 srcY1, |
| 2338 dstGLRect.fLeft, |
| 2339 dstGLRect.fBottom, |
| 2340 dstGLRect.fLeft + dstGLRect.fWidth, |
| 2341 dstGLRect.fBottom + dstGLRect.fHeight, |
| 2342 GR_GL_COLOR_BUFFER_BIT, GR_GL_NEAREST)); |
| 2343 if (dstFBO) { |
| 2344 GL_CALL(DeleteFramebuffers(1, &dstFBO)); |
| 2345 } |
| 2346 if (srcFBO) { |
| 2347 GL_CALL(DeleteFramebuffers(1, &srcFBO)); |
| 2348 } |
| 2349 copied = true; |
| 2350 } |
| 2351 } |
| 2352 if (!copied) { |
| 2353 copied = INHERITED::onCopySurface(dst, src, srcRect, dstPoint); |
| 2354 } |
| 2355 return copied; |
| 2356 } |
| 2357 |
| 2358 bool GrGpuGL::onCanCopySurface(GrSurface* dst, |
| 2359 GrSurface* src, |
| 2360 const SkIRect& srcRect, |
| 2361 const SkIPoint& dstPoint) { |
| 2362 // This mirrors the logic in onCopySurface. |
| 2363 bool canBlitFramebuffer = false; |
| 2364 if (can_blit_framebuffer(dst, src, this)) { |
| 2365 SkIRect dstRect = SkIRect::MakeXYWH(dstPoint.fX, dstPoint.fY, |
| 2366 srcRect.width(), srcRect.height()); |
| 2367 if (dst->isSameAs(src)) { |
| 2368 canBlitFramebuffer = !SkIRect::IntersectsNoEmptyCheck(dstRect, srcRe
ct); |
| 2369 } else { |
| 2370 canBlitFramebuffer = true; |
| 2371 } |
| 2372 } |
| 2373 if (canBlitFramebuffer) { |
| 2374 return true; |
| 2375 } else { |
| 2376 return INHERITED::onCanCopySurface(dst, src, srcRect, dstPoint); |
| 2377 } |
| 2378 } |
| 2379 |
| 2380 |
2230 /////////////////////////////////////////////////////////////////////////////// | 2381 /////////////////////////////////////////////////////////////////////////////// |
2231 | 2382 |
2232 GrGLAttribArrayState* GrGpuGL::HWGeometryState::bindArrayAndBuffersToDraw( | 2383 GrGLAttribArrayState* GrGpuGL::HWGeometryState::bindArrayAndBuffersToDraw( |
2233 GrGpuGL* gpu, | 2384 GrGpuGL* gpu, |
2234 const GrGLVertexBuffer* vbuffer, | 2385 const GrGLVertexBuffer* vbuffer, |
2235 const GrGLIndexBuffer* ibuffer)
{ | 2386 const GrGLIndexBuffer* ibuffer)
{ |
2236 GrAssert(NULL != vbuffer); | 2387 GrAssert(NULL != vbuffer); |
2237 GrGLAttribArrayState* attribState; | 2388 GrGLAttribArrayState* attribState; |
2238 | 2389 |
2239 // We use a vertex array if we're on a core profile and the verts are in a V
BO. | 2390 // We use a vertex array if we're on a core profile and the verts are in a V
BO. |
(...skipping 13 matching lines...) Expand all Loading... |
2253 this->setVertexArrayID(gpu, 0); | 2404 this->setVertexArrayID(gpu, 0); |
2254 } | 2405 } |
2255 int attrCount = gpu->glCaps().maxVertexAttributes(); | 2406 int attrCount = gpu->glCaps().maxVertexAttributes(); |
2256 if (fDefaultVertexArrayAttribState.count() != attrCount) { | 2407 if (fDefaultVertexArrayAttribState.count() != attrCount) { |
2257 fDefaultVertexArrayAttribState.resize(attrCount); | 2408 fDefaultVertexArrayAttribState.resize(attrCount); |
2258 } | 2409 } |
2259 attribState = &fDefaultVertexArrayAttribState; | 2410 attribState = &fDefaultVertexArrayAttribState; |
2260 } | 2411 } |
2261 return attribState; | 2412 return attribState; |
2262 } | 2413 } |
OLD | NEW |