| 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 "GrGLGpu.h" | 9 #include "GrGLGpu.h" |
| 10 #include "GrGLGLSL.h" | 10 #include "GrGLGLSL.h" |
| (...skipping 546 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 557 if (GR_GL_TEXTURE_EXTERNAL == texture->target()) { | 557 if (GR_GL_TEXTURE_EXTERNAL == texture->target()) { |
| 558 // We don't currently support writing pixels to EXTERNAL textures. | 558 // We don't currently support writing pixels to EXTERNAL textures. |
| 559 return false; | 559 return false; |
| 560 } | 560 } |
| 561 } | 561 } |
| 562 | 562 |
| 563 if (GrPixelConfigIsSRGB(dstSurface->config()) != GrPixelConfigIsSRGB(srcConf
ig)) { | 563 if (GrPixelConfigIsSRGB(dstSurface->config()) != GrPixelConfigIsSRGB(srcConf
ig)) { |
| 564 ElevateDrawPreference(drawPreference, kRequireDraw_DrawPreference); | 564 ElevateDrawPreference(drawPreference, kRequireDraw_DrawPreference); |
| 565 } | 565 } |
| 566 | 566 |
| 567 tempDrawInfo->fSwapRAndB = false; | 567 // Start off assuming no swizzling |
| 568 tempDrawInfo->fSwizzle = GrSwizzle::RGBA(); |
| 569 tempDrawInfo->fWriteConfig = srcConfig; |
| 568 | 570 |
| 569 // These settings we will always want if a temp draw is performed. Initially
set the config | 571 // These settings we will always want if a temp draw is performed. Initially
set the config |
| 570 // to srcConfig, though that may be modified if we decide to do a R/G swap. | 572 // to srcConfig, though that may be modified if we decide to do a R/G swap. |
| 571 tempDrawInfo->fTempSurfaceDesc.fFlags = kNone_GrSurfaceFlags; | 573 tempDrawInfo->fTempSurfaceDesc.fFlags = kNone_GrSurfaceFlags; |
| 572 tempDrawInfo->fTempSurfaceDesc.fConfig = srcConfig; | 574 tempDrawInfo->fTempSurfaceDesc.fConfig = srcConfig; |
| 573 tempDrawInfo->fTempSurfaceDesc.fWidth = width; | 575 tempDrawInfo->fTempSurfaceDesc.fWidth = width; |
| 574 tempDrawInfo->fTempSurfaceDesc.fHeight = height; | 576 tempDrawInfo->fTempSurfaceDesc.fHeight = height; |
| 575 tempDrawInfo->fTempSurfaceDesc.fSampleCnt = 0; | 577 tempDrawInfo->fTempSurfaceDesc.fSampleCnt = 0; |
| 576 tempDrawInfo->fTempSurfaceDesc.fOrigin = kTopLeft_GrSurfaceOrigin; // no CPU
y-flip for TL. | 578 tempDrawInfo->fTempSurfaceDesc.fOrigin = kTopLeft_GrSurfaceOrigin; // no CPU
y-flip for TL. |
| 577 | 579 |
| 578 bool configsAreRBSwaps = GrPixelConfigSwapRAndB(srcConfig) == dstSurface->co
nfig(); | 580 bool configsAreRBSwaps = GrPixelConfigSwapRAndB(srcConfig) == dstSurface->co
nfig(); |
| 579 | 581 |
| 580 if (configsAreRBSwaps) { | 582 if (configsAreRBSwaps) { |
| 581 if (!this->caps()->isConfigTexturable(srcConfig)) { | 583 if (!this->caps()->isConfigTexturable(srcConfig)) { |
| 582 ElevateDrawPreference(drawPreference, kRequireDraw_DrawPreference); | 584 ElevateDrawPreference(drawPreference, kRequireDraw_DrawPreference); |
| 583 tempDrawInfo->fTempSurfaceDesc.fConfig = dstSurface->config(); | 585 tempDrawInfo->fTempSurfaceDesc.fConfig = dstSurface->config(); |
| 584 tempDrawInfo->fSwapRAndB = true; | 586 tempDrawInfo->fSwizzle = GrSwizzle::BGRA(); |
| 587 tempDrawInfo->fWriteConfig = dstSurface->config(); |
| 585 } else if (this->glCaps().rgba8888PixelsOpsAreSlow() && | 588 } else if (this->glCaps().rgba8888PixelsOpsAreSlow() && |
| 586 kRGBA_8888_GrPixelConfig == srcConfig) { | 589 kRGBA_8888_GrPixelConfig == srcConfig) { |
| 587 ElevateDrawPreference(drawPreference, kGpuPrefersDraw_DrawPreference
); | 590 ElevateDrawPreference(drawPreference, kGpuPrefersDraw_DrawPreference
); |
| 588 tempDrawInfo->fTempSurfaceDesc.fConfig = dstSurface->config(); | 591 tempDrawInfo->fTempSurfaceDesc.fConfig = dstSurface->config(); |
| 589 tempDrawInfo->fSwapRAndB = true; | 592 tempDrawInfo->fSwizzle = GrSwizzle::BGRA(); |
| 593 tempDrawInfo->fWriteConfig = dstSurface->config(); |
| 590 } else if (kGLES_GrGLStandard == this->glStandard() && | 594 } else if (kGLES_GrGLStandard == this->glStandard() && |
| 591 this->glCaps().bgraIsInternalFormat()) { | 595 this->glCaps().bgraIsInternalFormat()) { |
| 592 // The internal format and external formats must match texture uploa
ds so we can't | 596 // The internal format and external formats must match texture uploa
ds so we can't |
| 593 // swizzle while uploading when BGRA is a distinct internal format. | 597 // swizzle while uploading when BGRA is a distinct internal format. |
| 594 ElevateDrawPreference(drawPreference, kRequireDraw_DrawPreference); | 598 ElevateDrawPreference(drawPreference, kRequireDraw_DrawPreference); |
| 595 tempDrawInfo->fTempSurfaceDesc.fConfig = dstSurface->config(); | 599 tempDrawInfo->fTempSurfaceDesc.fConfig = dstSurface->config(); |
| 596 tempDrawInfo->fSwapRAndB = true; | 600 tempDrawInfo->fSwizzle = GrSwizzle::BGRA(); |
| 601 tempDrawInfo->fWriteConfig = dstSurface->config(); |
| 597 } | 602 } |
| 598 } | 603 } |
| 599 | 604 |
| 600 if (!this->glCaps().unpackFlipYSupport() && | 605 if (!this->glCaps().unpackFlipYSupport() && |
| 601 kBottomLeft_GrSurfaceOrigin == dstSurface->origin()) { | 606 kBottomLeft_GrSurfaceOrigin == dstSurface->origin()) { |
| 602 ElevateDrawPreference(drawPreference, kGpuPrefersDraw_DrawPreference); | 607 ElevateDrawPreference(drawPreference, kGpuPrefersDraw_DrawPreference); |
| 603 } | 608 } |
| 604 | 609 |
| 605 return true; | 610 return true; |
| 606 } | 611 } |
| (...skipping 1357 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1964 // This subclass can only read pixels from a render target. We could use glT
exSubImage2D on | 1969 // This subclass can only read pixels from a render target. We could use glT
exSubImage2D on |
| 1965 // GL versions that support it but we don't today. | 1970 // GL versions that support it but we don't today. |
| 1966 if (!srcSurface->asRenderTarget()) { | 1971 if (!srcSurface->asRenderTarget()) { |
| 1967 ElevateDrawPreference(drawPreference, kRequireDraw_DrawPreference); | 1972 ElevateDrawPreference(drawPreference, kRequireDraw_DrawPreference); |
| 1968 } | 1973 } |
| 1969 | 1974 |
| 1970 if (GrPixelConfigIsSRGB(srcSurface->config()) != GrPixelConfigIsSRGB(readCon
fig)) { | 1975 if (GrPixelConfigIsSRGB(srcSurface->config()) != GrPixelConfigIsSRGB(readCon
fig)) { |
| 1971 ElevateDrawPreference(drawPreference, kRequireDraw_DrawPreference); | 1976 ElevateDrawPreference(drawPreference, kRequireDraw_DrawPreference); |
| 1972 } | 1977 } |
| 1973 | 1978 |
| 1974 tempDrawInfo->fSwapRAndB = false; | 1979 tempDrawInfo->fSwizzle = GrSwizzle::RGBA(); |
| 1980 tempDrawInfo->fReadConfig = readConfig; |
| 1975 | 1981 |
| 1976 // These settings we will always want if a temp draw is performed. The confi
g is set below | 1982 // These settings we will always want if a temp draw is performed. The confi
g is set below |
| 1977 // depending on whether we want to do a R/B swap or not. | 1983 // depending on whether we want to do a R/B swap or not. |
| 1978 tempDrawInfo->fTempSurfaceDesc.fFlags = kRenderTarget_GrSurfaceFlag; | 1984 tempDrawInfo->fTempSurfaceDesc.fFlags = kRenderTarget_GrSurfaceFlag; |
| 1979 tempDrawInfo->fTempSurfaceDesc.fWidth = width; | 1985 tempDrawInfo->fTempSurfaceDesc.fWidth = width; |
| 1980 tempDrawInfo->fTempSurfaceDesc.fHeight = height; | 1986 tempDrawInfo->fTempSurfaceDesc.fHeight = height; |
| 1981 tempDrawInfo->fTempSurfaceDesc.fSampleCnt = 0; | 1987 tempDrawInfo->fTempSurfaceDesc.fSampleCnt = 0; |
| 1982 tempDrawInfo->fTempSurfaceDesc.fOrigin = kTopLeft_GrSurfaceOrigin; // no CPU
y-flip for TL. | 1988 tempDrawInfo->fTempSurfaceDesc.fOrigin = kTopLeft_GrSurfaceOrigin; // no CPU
y-flip for TL. |
| 1983 tempDrawInfo->fUseExactScratch = this->glCaps().partialFBOReadIsSlow(); | 1989 tempDrawInfo->fUseExactScratch = this->glCaps().partialFBOReadIsSlow(); |
| 1984 | 1990 |
| 1985 // Start off assuming that any temp draw should be to the readConfig, then c
heck if that will | 1991 // Start off assuming that any temp draw should be to the readConfig, then c
heck if that will |
| 1986 // be inefficient. | 1992 // be inefficient. |
| 1987 GrPixelConfig srcConfig = srcSurface->config(); | 1993 GrPixelConfig srcConfig = srcSurface->config(); |
| 1988 tempDrawInfo->fTempSurfaceDesc.fConfig = readConfig; | 1994 tempDrawInfo->fTempSurfaceDesc.fConfig = readConfig; |
| 1989 | 1995 |
| 1990 if (this->glCaps().rgba8888PixelsOpsAreSlow() && kRGBA_8888_GrPixelConfig ==
readConfig) { | 1996 if (this->glCaps().rgba8888PixelsOpsAreSlow() && kRGBA_8888_GrPixelConfig ==
readConfig) { |
| 1991 tempDrawInfo->fTempSurfaceDesc.fConfig = kBGRA_8888_GrPixelConfig; | 1997 tempDrawInfo->fTempSurfaceDesc.fConfig = kBGRA_8888_GrPixelConfig; |
| 1992 tempDrawInfo->fSwapRAndB = true; | 1998 tempDrawInfo->fSwizzle = GrSwizzle::BGRA(); |
| 1999 tempDrawInfo->fReadConfig = kBGRA_8888_GrPixelConfig; |
| 1993 ElevateDrawPreference(drawPreference, kGpuPrefersDraw_DrawPreference); | 2000 ElevateDrawPreference(drawPreference, kGpuPrefersDraw_DrawPreference); |
| 1994 } else if (kMesa_GrGLDriver == this->glContext().driver() && | 2001 } else if (kMesa_GrGLDriver == this->glContext().driver() && |
| 1995 GrBytesPerPixel(readConfig) == 4 && | 2002 GrBytesPerPixel(readConfig) == 4 && |
| 1996 GrPixelConfigSwapRAndB(readConfig) == srcConfig) { | 2003 GrPixelConfigSwapRAndB(readConfig) == srcConfig) { |
| 1997 // Mesa 3D takes a slow path on when reading back BGRA from an RGBA sur
face and vice-versa. | 2004 // Mesa 3D takes a slow path on when reading back BGRA from an RGBA surf
ace and vice-versa. |
| 1998 // Better to do a draw with a R/B swap and then read as the original con
fig. | 2005 // Better to do a draw with a R/B swap and then read as the original con
fig. |
| 1999 tempDrawInfo->fTempSurfaceDesc.fConfig = srcConfig; | 2006 tempDrawInfo->fTempSurfaceDesc.fConfig = srcConfig; |
| 2000 tempDrawInfo->fSwapRAndB = true; | 2007 tempDrawInfo->fSwizzle = GrSwizzle::BGRA(); |
| 2008 tempDrawInfo->fReadConfig = srcConfig; |
| 2001 ElevateDrawPreference(drawPreference, kGpuPrefersDraw_DrawPreference); | 2009 ElevateDrawPreference(drawPreference, kGpuPrefersDraw_DrawPreference); |
| 2002 } else if (readConfig == kBGRA_8888_GrPixelConfig && | 2010 } else if (readConfig == kBGRA_8888_GrPixelConfig && |
| 2003 !this->glCaps().readPixelsSupported(this->glInterface(), readConf
ig, srcConfig)) { | 2011 !this->glCaps().readPixelsSupported(this->glInterface(), readConf
ig, srcConfig)) { |
| 2004 tempDrawInfo->fTempSurfaceDesc.fConfig = kRGBA_8888_GrPixelConfig; | 2012 tempDrawInfo->fTempSurfaceDesc.fConfig = kRGBA_8888_GrPixelConfig; |
| 2005 tempDrawInfo->fSwapRAndB = true; | 2013 tempDrawInfo->fSwizzle = GrSwizzle::BGRA(); |
| 2014 tempDrawInfo->fReadConfig = kRGBA_8888_GrPixelConfig; |
| 2006 ElevateDrawPreference(drawPreference, kRequireDraw_DrawPreference); | 2015 ElevateDrawPreference(drawPreference, kRequireDraw_DrawPreference); |
| 2007 } | 2016 } |
| 2008 | 2017 |
| 2009 GrRenderTarget* srcAsRT = srcSurface->asRenderTarget(); | 2018 GrRenderTarget* srcAsRT = srcSurface->asRenderTarget(); |
| 2010 if (!srcAsRT) { | 2019 if (!srcAsRT) { |
| 2011 ElevateDrawPreference(drawPreference, kRequireDraw_DrawPreference); | 2020 ElevateDrawPreference(drawPreference, kRequireDraw_DrawPreference); |
| 2012 } else if (read_pixels_pays_for_y_flip(srcAsRT, this->glCaps(), width, heigh
t, readConfig, | 2021 } else if (read_pixels_pays_for_y_flip(srcAsRT, this->glCaps(), width, heigh
t, readConfig, |
| 2013 rowBytes)) { | 2022 rowBytes)) { |
| 2014 ElevateDrawPreference(drawPreference, kGpuPrefersDraw_DrawPreference); | 2023 ElevateDrawPreference(drawPreference, kGpuPrefersDraw_DrawPreference); |
| 2015 } | 2024 } |
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2047 switch (tgt->getResolveType()) { | 2056 switch (tgt->getResolveType()) { |
| 2048 case GrGLRenderTarget::kCantResolve_ResolveType: | 2057 case GrGLRenderTarget::kCantResolve_ResolveType: |
| 2049 return false; | 2058 return false; |
| 2050 case GrGLRenderTarget::kAutoResolves_ResolveType: | 2059 case GrGLRenderTarget::kAutoResolves_ResolveType: |
| 2051 this->flushRenderTarget(tgt, &SkIRect::EmptyIRect()); | 2060 this->flushRenderTarget(tgt, &SkIRect::EmptyIRect()); |
| 2052 break; | 2061 break; |
| 2053 case GrGLRenderTarget::kCanResolve_ResolveType: | 2062 case GrGLRenderTarget::kCanResolve_ResolveType: |
| 2054 this->onResolveRenderTarget(tgt); | 2063 this->onResolveRenderTarget(tgt); |
| 2055 // we don't track the state of the READ FBO ID. | 2064 // we don't track the state of the READ FBO ID. |
| 2056 fStats.incRenderTargetBinds(); | 2065 fStats.incRenderTargetBinds(); |
| 2057 GL_CALL(BindFramebuffer(GR_GL_READ_FRAMEBUFFER, | 2066 GL_CALL(BindFramebuffer(GR_GL_READ_FRAMEBUFFER, tgt->textureFBOID())
); |
| 2058 tgt->textureFBOID())); | |
| 2059 break; | 2067 break; |
| 2060 default: | 2068 default: |
| 2061 SkFAIL("Unknown resolve type"); | 2069 SkFAIL("Unknown resolve type"); |
| 2062 } | 2070 } |
| 2063 | 2071 |
| 2064 const GrGLIRect& glvp = tgt->getViewport(); | 2072 const GrGLIRect& glvp = tgt->getViewport(); |
| 2065 | 2073 |
| 2066 // the read rect is viewport-relative | 2074 // the read rect is viewport-relative |
| 2067 GrGLIRect readRect; | 2075 GrGLIRect readRect; |
| 2068 readRect.setRelativeTo(glvp, left, top, width, height, tgt->origin()); | 2076 readRect.setRelativeTo(glvp, left, top, width, height, tgt->origin()); |
| (...skipping 1431 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3500 if (GR_GL_TEXTURE_EXTERNAL == glTexture->target() || | 3508 if (GR_GL_TEXTURE_EXTERNAL == glTexture->target() || |
| 3501 GR_GL_TEXTURE_RECTANGLE == glTexture->target()) { | 3509 GR_GL_TEXTURE_RECTANGLE == glTexture->target()) { |
| 3502 copyParams->fFilter = GrTextureParams::kNone_FilterMode; | 3510 copyParams->fFilter = GrTextureParams::kNone_FilterMode; |
| 3503 copyParams->fWidth = texture->width(); | 3511 copyParams->fWidth = texture->width(); |
| 3504 copyParams->fHeight = texture->height(); | 3512 copyParams->fHeight = texture->height(); |
| 3505 return true; | 3513 return true; |
| 3506 } | 3514 } |
| 3507 } | 3515 } |
| 3508 return false; | 3516 return false; |
| 3509 } | 3517 } |
| OLD | NEW |