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

Side by Side Diff: src/gpu/gl/GrGpuGL.cpp

Issue 13910009: Use blitframebuffer to implement copySurface. (Closed) Base URL: http://skia.googlecode.com/svn/trunk/
Patch Set: Created 7 years, 8 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 | Annotate | Revision Log
« no previous file with comments | « src/gpu/gl/GrGpuGL.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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
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 bool GrGpuGL::onCopySurface(GrSurface* dst,
2231 GrSurface* src,
2232 const SkIRect& srcRect,
2233 const SkIPoint& dstPoint) {
2234 // TODO: Add support for glCopyTexSubImage for cases when src is an FBO and dst is not
2235 // renderable or we don't have glBlitFramebuffer.
2236 bool copied = false;
2237 // Check whether both src and dst could be attached to an FBO and we're on a GL that supports
2238 // glBlitFramebuffer.
2239 if (this->isConfigRenderable(dst->config()) && this->isConfigRenderable(src- >config()) &&
robertphillips 2013/04/11 19:44:10 Does it make sense to wrap this in something like
bsalomon 2013/04/11 20:06:57 Done.
2240 (GrGLCaps::kDesktopEXT_MSFBOType == this->glCaps().msFBOType() ||
2241 GrGLCaps::kDesktopARB_MSFBOType == this->glCaps().msFBOType())) {
2242
2243 SkIRect dstRect = SkIRect::MakeXYWH(dstPoint.fX, dstPoint.fY,
2244 srcRect.width(), srcRect.height());
2245 bool selfOverlap = false;
2246 if (dst->isSameAs(src)) {
2247 selfOverlap = SkIRect::IntersectsNoEmptyCheck(dstRect, srcRect);
2248 }
2249
2250 if (!selfOverlap) {
2251 GrGLuint dstFBO = 0;
2252 GrGLuint srcFBO = 0;
2253 GrGLIRect dstVP;
2254 GrGLIRect srcVP;
2255 GrGLRenderTarget* dstRT = static_cast<GrGLRenderTarget*>(dst->asRend erTarget());
2256 GrGLRenderTarget* srcRT = static_cast<GrGLRenderTarget*>(src->asRend erTarget());
2257 if (NULL == dstRT) {
2258 GrAssert(NULL != dst->asTexture());
2259 GrGLuint texID = static_cast<GrGLTexture*>(dst->asTexture())->te xtureID();
2260 GL_CALL(GenFramebuffers(1, &dstFBO));
2261 GL_CALL(BindFramebuffer(GR_GL_DRAW_FRAMEBUFFER, dstFBO));
2262 GL_CALL(FramebufferTexture2D(GR_GL_DRAW_FRAMEBUFFER,
2263 GR_GL_COLOR_ATTACHMENT0,
2264 GR_GL_TEXTURE_2D,
2265 texID,
2266 0));
2267 dstVP.fLeft = 0;
2268 dstVP.fBottom = 0;
2269 dstVP.fWidth = dst->width();
2270 dstVP.fHeight = dst->height();
2271 } else {
2272 GL_CALL(BindFramebuffer(GR_GL_DRAW_FRAMEBUFFER, dstRT->renderFBO ID()));
2273 dstVP = dstRT->getViewport();
2274 }
2275 if (NULL == srcRT) {
2276 GrAssert(NULL != src->asTexture());
2277 GrGLuint texID = static_cast<GrGLTexture*>(src->asTexture())->te xtureID();
2278 GL_CALL(GenFramebuffers(1, &srcFBO));
2279 GL_CALL(BindFramebuffer(GR_GL_READ_FRAMEBUFFER, srcFBO));
2280 GL_CALL(FramebufferTexture2D(GR_GL_READ_FRAMEBUFFER,
2281 GR_GL_COLOR_ATTACHMENT0,
2282 GR_GL_TEXTURE_2D,
2283 texID,
2284 0));
2285 srcVP.fLeft = 0;
2286 srcVP.fBottom = 0;
2287 srcVP.fWidth = src->width();
2288 srcVP.fHeight = src->height();
2289 } else {
2290 GL_CALL(BindFramebuffer(GR_GL_READ_FRAMEBUFFER, srcRT->renderFBO ID()));
2291 srcVP = srcRT->getViewport();
2292 }
2293
2294 // We modified the bound FB
2295 fHWBoundRenderTarget = NULL;
2296 GrGLIRect srcGLRect;
2297 GrGLIRect dstGLRect;
2298 srcGLRect.setRelativeTo(srcVP,
2299 srcRect.fLeft,
2300 srcRect.fTop,
2301 srcRect.width(),
2302 srcRect.height(),
2303 src->origin());
2304 dstGLRect.setRelativeTo(dstVP,
2305 dstRect.fLeft,
2306 dstRect.fTop,
2307 dstRect.width(),
2308 dstRect.height(),
2309 dst->origin());
2310
2311 GrAutoTRestore<ScissorState> asr;
2312 if (GrGLCaps::kDesktopEXT_MSFBOType == this->glCaps().msFBOType()) {
robertphillips 2013/04/11 19:44:10 In this ...?
bsalomon 2013/04/11 20:06:57 // The EXT version applies the scissor during the
2313 // This EXT version the scissor during the blit, so disable it.
2314 asr.reset(&fScissorState);
2315 fScissorState.fEnabled = false;
2316 this->flushScissor();
2317 }
2318 GrGLint srcY0;
2319 GrGLint srcY1;
2320 // Does the blit need to y-mirror or not?
2321 if (src->origin() == dst->origin()) {
2322 srcY0 = srcGLRect.fBottom;
2323 srcY1 = srcGLRect.fBottom + srcGLRect.fHeight;
2324 } else {
2325 srcY0 = srcGLRect.fBottom + srcGLRect.fHeight;
2326 srcY1 = srcGLRect.fBottom;
2327 }
2328 GL_CALL(BlitFramebuffer(srcGLRect.fLeft,
2329 srcY0,
2330 srcGLRect.fLeft + srcGLRect.fWidth,
2331 srcY1,
2332 dstGLRect.fLeft,
2333 dstGLRect.fBottom,
2334 dstGLRect.fLeft + dstGLRect.fWidth,
2335 dstGLRect.fBottom + dstGLRect.fHeight,
2336 GR_GL_COLOR_BUFFER_BIT, GR_GL_NEAREST));
2337 if (dstFBO) {
2338 GL_CALL(DeleteFramebuffers(1, &dstFBO));
2339 }
2340 if (srcFBO) {
2341 GL_CALL(DeleteFramebuffers(1, &srcFBO));
2342 }
2343 copied = true;
2344 }
2345 }
2346 if (!copied) {
2347 copied = INHERITED::onCopySurface(dst, src, srcRect, dstPoint);
2348 }
2349 return copied;
2350 }
2351
2352 bool GrGpuGL::onCanCopySurface(GrSurface* dst,
2353 GrSurface* src,
2354 const SkIRect& srcRect,
2355 const SkIPoint& dstPoint) {
2356 // This mirrors the logic in onCopySurface.
2357 bool canBlitFramebuffer = false;
2358 if (this->isConfigRenderable(dst->config()) && this->isConfigRenderable(src- >config()) &&
2359 (GrGLCaps::kDesktopEXT_MSFBOType == this->glCaps().msFBOType() ||
2360 GrGLCaps::kDesktopARB_MSFBOType == this->glCaps().msFBOType())) {
2361
2362 SkIRect dstRect = SkIRect::MakeXYWH(dstPoint.fX, dstPoint.fY,
2363 srcRect.width(), srcRect.height());
2364 if (dst->isSameAs(src)) {
2365 canBlitFramebuffer = !SkIRect::IntersectsNoEmptyCheck(dstRect, srcRe ct);
2366 } else {
2367 canBlitFramebuffer = true;
2368 }
2369 }
2370 if (canBlitFramebuffer) {
2371 return true;
2372 } else {
2373 return INHERITED::onCanCopySurface(dst, src, srcRect, dstPoint);
2374 }
2375 }
2376
2377
2230 /////////////////////////////////////////////////////////////////////////////// 2378 ///////////////////////////////////////////////////////////////////////////////
2231 2379
2232 GrGLAttribArrayState* GrGpuGL::HWGeometryState::bindArrayAndBuffersToDraw( 2380 GrGLAttribArrayState* GrGpuGL::HWGeometryState::bindArrayAndBuffersToDraw(
2233 GrGpuGL* gpu, 2381 GrGpuGL* gpu,
2234 const GrGLVertexBuffer* vbuffer, 2382 const GrGLVertexBuffer* vbuffer,
2235 const GrGLIndexBuffer* ibuffer) { 2383 const GrGLIndexBuffer* ibuffer) {
2236 GrAssert(NULL != vbuffer); 2384 GrAssert(NULL != vbuffer);
2237 GrGLAttribArrayState* attribState; 2385 GrGLAttribArrayState* attribState;
2238 2386
2239 // We use a vertex array if we're on a core profile and the verts are in a V BO. 2387 // 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
2253 this->setVertexArrayID(gpu, 0); 2401 this->setVertexArrayID(gpu, 0);
2254 } 2402 }
2255 int attrCount = gpu->glCaps().maxVertexAttributes(); 2403 int attrCount = gpu->glCaps().maxVertexAttributes();
2256 if (fDefaultVertexArrayAttribState.count() != attrCount) { 2404 if (fDefaultVertexArrayAttribState.count() != attrCount) {
2257 fDefaultVertexArrayAttribState.resize(attrCount); 2405 fDefaultVertexArrayAttribState.resize(attrCount);
2258 } 2406 }
2259 attribState = &fDefaultVertexArrayAttribState; 2407 attribState = &fDefaultVertexArrayAttribState;
2260 } 2408 }
2261 return attribState; 2409 return attribState;
2262 } 2410 }
OLDNEW
« no previous file with comments | « src/gpu/gl/GrGpuGL.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698