| 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 1946 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1957 } | 1957 } |
| 1958 | 1958 |
| 1959 // If we have to do memcpy to handle non-trim rowBytes then we | 1959 // If we have to do memcpy to handle non-trim rowBytes then we |
| 1960 // get the flip for free. Otherwise it costs. | 1960 // get the flip for free. Otherwise it costs. |
| 1961 // Note that we're assuming that 0 rowBytes has already been handled and tha
t the width has been | 1961 // Note that we're assuming that 0 rowBytes has already been handled and tha
t the width has been |
| 1962 // clipped. | 1962 // clipped. |
| 1963 return caps.packRowLengthSupport() || GrBytesPerPixel(config) * width == row
Bytes; | 1963 return caps.packRowLengthSupport() || GrBytesPerPixel(config) * width == row
Bytes; |
| 1964 } | 1964 } |
| 1965 | 1965 |
| 1966 bool GrGLGpu::readPixelsSupported(GrRenderTarget* target, GrPixelConfig readConf
ig) { | 1966 bool GrGLGpu::readPixelsSupported(GrRenderTarget* target, GrPixelConfig readConf
ig) { |
| 1967 auto bindRenderTarget = [this](GrGLRenderTarget* target) { | 1967 auto bindRenderTarget = [this, target]() -> bool { |
| 1968 this->flushRenderTarget(target, &SkIRect::EmptyIRect()); | 1968 this->flushRenderTarget(static_cast<GrGLRenderTarget*>(target), &SkIRect
::EmptyIRect()); |
| 1969 return true; |
| 1969 }; | 1970 }; |
| 1970 auto getIntegerv = [this](GrGLenum query, GrGLint* value) { | 1971 auto getIntegerv = [this](GrGLenum query, GrGLint* value) { |
| 1971 GR_GL_GetIntegerv(this->glInterface(), query, value); | 1972 GR_GL_GetIntegerv(this->glInterface(), query, value); |
| 1972 }; | 1973 }; |
| 1973 GrGLRenderTarget* glTarget = static_cast<GrGLRenderTarget*>(target); | 1974 GrPixelConfig rtConfig = target->config(); |
| 1974 return this->glCaps().readPixelsSupported(glTarget, readConfig, getIntegerv,
bindRenderTarget); | 1975 return this->glCaps().readPixelsSupported(rtConfig, readConfig, getIntegerv,
bindRenderTarget); |
| 1976 } |
| 1977 |
| 1978 bool GrGLGpu::readPixelsSupported(GrPixelConfig rtConfig, GrPixelConfig readConf
ig) { |
| 1979 auto bindRenderTarget = [this, rtConfig]() -> bool { |
| 1980 GrTextureDesc desc; |
| 1981 desc.fConfig = rtConfig; |
| 1982 desc.fWidth = desc.fHeight = 16; |
| 1983 desc.fFlags = kRenderTarget_GrSurfaceFlag; |
| 1984 SkAutoTUnref<GrTexture> temp(this->createTexture(desc, false, nullptr, 0
)); |
| 1985 if (!temp) { |
| 1986 return false; |
| 1987 } |
| 1988 GrGLRenderTarget* glrt = static_cast<GrGLRenderTarget*>(temp->asRenderTa
rget()); |
| 1989 this->flushRenderTarget(glrt, &SkIRect::EmptyIRect()); |
| 1990 return true; |
| 1991 }; |
| 1992 auto getIntegerv = [this](GrGLenum query, GrGLint* value) { |
| 1993 GR_GL_GetIntegerv(this->glInterface(), query, value); |
| 1994 }; |
| 1995 return this->glCaps().readPixelsSupported(rtConfig, readConfig, getIntegerv,
bindRenderTarget); |
| 1996 } |
| 1997 |
| 1998 bool GrGLGpu::readPixelsSupported(GrSurface* surfaceForConfig, GrPixelConfig rea
dConfig) { |
| 1999 if (GrRenderTarget* rt = surfaceForConfig->asRenderTarget()) { |
| 2000 return this->readPixelsSupported(rt, readConfig); |
| 2001 } else { |
| 2002 GrPixelConfig config = surfaceForConfig->config(); |
| 2003 return this->readPixelsSupported(config, readConfig); |
| 2004 } |
| 1975 } | 2005 } |
| 1976 | 2006 |
| 1977 bool GrGLGpu::onGetReadPixelsInfo(GrSurface* srcSurface, int width, int height,
size_t rowBytes, | 2007 bool GrGLGpu::onGetReadPixelsInfo(GrSurface* srcSurface, int width, int height,
size_t rowBytes, |
| 1978 GrPixelConfig readConfig, DrawPreference* draw
Preference, | 2008 GrPixelConfig readConfig, DrawPreference* draw
Preference, |
| 1979 ReadPixelTempDrawInfo* tempDrawInfo) { | 2009 ReadPixelTempDrawInfo* tempDrawInfo) { |
| 1980 GrRenderTarget* srcAsRT = srcSurface->asRenderTarget(); | 2010 GrRenderTarget* srcAsRT = srcSurface->asRenderTarget(); |
| 1981 | 2011 |
| 1982 // This subclass can only read pixels from a render target. We could use glT
exSubImage2D on | 2012 // This subclass can only read pixels from a render target. We could use glT
exSubImage2D on |
| 1983 // GL versions that support it but we don't today. | 2013 // GL versions that support it but we don't today. |
| 1984 if (!srcAsRT) { | 2014 if (!srcAsRT) { |
| (...skipping 14 matching lines...) Expand all Loading... |
| 1999 tempDrawInfo->fTempSurfaceDesc.fHeight = height; | 2029 tempDrawInfo->fTempSurfaceDesc.fHeight = height; |
| 2000 tempDrawInfo->fTempSurfaceDesc.fSampleCnt = 0; | 2030 tempDrawInfo->fTempSurfaceDesc.fSampleCnt = 0; |
| 2001 tempDrawInfo->fTempSurfaceDesc.fOrigin = kTopLeft_GrSurfaceOrigin; // no CPU
y-flip for TL. | 2031 tempDrawInfo->fTempSurfaceDesc.fOrigin = kTopLeft_GrSurfaceOrigin; // no CPU
y-flip for TL. |
| 2002 tempDrawInfo->fUseExactScratch = this->glCaps().partialFBOReadIsSlow(); | 2032 tempDrawInfo->fUseExactScratch = this->glCaps().partialFBOReadIsSlow(); |
| 2003 | 2033 |
| 2004 // Start off assuming that any temp draw should be to the readConfig, then c
heck if that will | 2034 // Start off assuming that any temp draw should be to the readConfig, then c
heck if that will |
| 2005 // be inefficient. | 2035 // be inefficient. |
| 2006 GrPixelConfig srcConfig = srcSurface->config(); | 2036 GrPixelConfig srcConfig = srcSurface->config(); |
| 2007 tempDrawInfo->fTempSurfaceDesc.fConfig = readConfig; | 2037 tempDrawInfo->fTempSurfaceDesc.fConfig = readConfig; |
| 2008 | 2038 |
| 2009 if (this->glCaps().rgba8888PixelsOpsAreSlow() && kRGBA_8888_GrPixelConfig ==
readConfig) { | 2039 if (this->glCaps().rgba8888PixelsOpsAreSlow() && kRGBA_8888_GrPixelConfig ==
readConfig && |
| 2040 this->readPixelsSupported(kBGRA_8888_GrPixelConfig, kBGRA_8888_GrPixelCo
nfig)) { |
| 2010 tempDrawInfo->fTempSurfaceDesc.fConfig = kBGRA_8888_GrPixelConfig; | 2041 tempDrawInfo->fTempSurfaceDesc.fConfig = kBGRA_8888_GrPixelConfig; |
| 2011 tempDrawInfo->fSwizzle = GrSwizzle::BGRA(); | 2042 tempDrawInfo->fSwizzle = GrSwizzle::BGRA(); |
| 2012 tempDrawInfo->fReadConfig = kBGRA_8888_GrPixelConfig; | 2043 tempDrawInfo->fReadConfig = kBGRA_8888_GrPixelConfig; |
| 2013 ElevateDrawPreference(drawPreference, kGpuPrefersDraw_DrawPreference); | 2044 ElevateDrawPreference(drawPreference, kGpuPrefersDraw_DrawPreference); |
| 2014 } else if (kMesa_GrGLDriver == this->glContext().driver() && | 2045 } else if (kMesa_GrGLDriver == this->glContext().driver() && |
| 2015 GrBytesPerPixel(readConfig) == 4 && | 2046 GrBytesPerPixel(readConfig) == 4 && |
| 2016 GrPixelConfigSwapRAndB(readConfig) == srcConfig) { | 2047 GrPixelConfigSwapRAndB(readConfig) == srcConfig && |
| 2048 this->readPixelsSupported(srcSurface, srcConfig)) { |
| 2017 // Mesa 3D takes a slow path on when reading back BGRA from an RGBA surf
ace and vice-versa. | 2049 // Mesa 3D takes a slow path on when reading back BGRA from an RGBA surf
ace and vice-versa. |
| 2018 // Better to do a draw with a R/B swap and then read as the original con
fig. | 2050 // Better to do a draw with a R/B swap and then read as the original con
fig. |
| 2019 tempDrawInfo->fTempSurfaceDesc.fConfig = srcConfig; | 2051 tempDrawInfo->fTempSurfaceDesc.fConfig = srcConfig; |
| 2020 tempDrawInfo->fSwizzle = GrSwizzle::BGRA(); | 2052 tempDrawInfo->fSwizzle = GrSwizzle::BGRA(); |
| 2021 tempDrawInfo->fReadConfig = srcConfig; | 2053 tempDrawInfo->fReadConfig = srcConfig; |
| 2022 ElevateDrawPreference(drawPreference, kGpuPrefersDraw_DrawPreference); | 2054 ElevateDrawPreference(drawPreference, kGpuPrefersDraw_DrawPreference); |
| 2023 } else if (readConfig == kBGRA_8888_GrPixelConfig && | 2055 } else if (!this->readPixelsSupported(srcSurface, readConfig)) { |
| 2024 !this->readPixelsSupported(srcAsRT, readConfig)) { | 2056 if (readConfig == kBGRA_8888_GrPixelConfig && |
| 2025 tempDrawInfo->fTempSurfaceDesc.fConfig = kRGBA_8888_GrPixelConfig; | 2057 this->glCaps().isConfigRenderable(kRGBA_8888_GrPixelConfig, false) &
& |
| 2026 tempDrawInfo->fSwizzle = GrSwizzle::BGRA(); | 2058 this->readPixelsSupported(kRGBA_8888_GrPixelConfig, kRGBA_8888_GrPix
elConfig)) { |
| 2027 tempDrawInfo->fReadConfig = kRGBA_8888_GrPixelConfig; | 2059 |
| 2028 ElevateDrawPreference(drawPreference, kRequireDraw_DrawPreference); | 2060 tempDrawInfo->fTempSurfaceDesc.fConfig = kRGBA_8888_GrPixelConfig; |
| 2061 tempDrawInfo->fSwizzle = GrSwizzle::BGRA(); |
| 2062 tempDrawInfo->fReadConfig = kRGBA_8888_GrPixelConfig; |
| 2063 ElevateDrawPreference(drawPreference, kRequireDraw_DrawPreference); |
| 2064 } else { |
| 2065 return false; |
| 2066 } |
| 2029 } | 2067 } |
| 2030 | 2068 |
| 2031 if (srcAsRT && | 2069 if (srcAsRT && |
| 2032 read_pixels_pays_for_y_flip(srcAsRT, this->glCaps(), width, height, read
Config, rowBytes)) { | 2070 read_pixels_pays_for_y_flip(srcAsRT, this->glCaps(), width, height, read
Config, rowBytes)) { |
| 2033 ElevateDrawPreference(drawPreference, kGpuPrefersDraw_DrawPreference); | 2071 ElevateDrawPreference(drawPreference, kGpuPrefersDraw_DrawPreference); |
| 2034 } | 2072 } |
| 2035 | 2073 |
| 2036 return true; | 2074 return true; |
| 2037 } | 2075 } |
| 2038 | 2076 |
| (...skipping 1478 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3517 if (GR_GL_TEXTURE_EXTERNAL == glTexture->target() || | 3555 if (GR_GL_TEXTURE_EXTERNAL == glTexture->target() || |
| 3518 GR_GL_TEXTURE_RECTANGLE == glTexture->target()) { | 3556 GR_GL_TEXTURE_RECTANGLE == glTexture->target()) { |
| 3519 copyParams->fFilter = GrTextureParams::kNone_FilterMode; | 3557 copyParams->fFilter = GrTextureParams::kNone_FilterMode; |
| 3520 copyParams->fWidth = texture->width(); | 3558 copyParams->fWidth = texture->width(); |
| 3521 copyParams->fHeight = texture->height(); | 3559 copyParams->fHeight = texture->height(); |
| 3522 return true; | 3560 return true; |
| 3523 } | 3561 } |
| 3524 } | 3562 } |
| 3525 return false; | 3563 return false; |
| 3526 } | 3564 } |
| OLD | NEW |