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

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

Issue 1615023003: Add ability to query read pixels support without a render target. (Closed) Base URL: https://skia.googlesource.com/skia.git@fixsupp
Patch Set: squash with prev cl in series Created 4 years, 11 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
« no previous file with comments | « src/gpu/gl/GrGLGpu.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 "GrGLGpu.h" 9 #include "GrGLGpu.h"
10 #include "GrGLGLSL.h" 10 #include "GrGLGLSL.h"
(...skipping 2051 matching lines...) Expand 10 before | Expand all | Expand 10 after
2062 return false; 2062 return false;
2063 } 2063 }
2064 2064
2065 // If we have to do memcpy to handle non-trim rowBytes then we 2065 // If we have to do memcpy to handle non-trim rowBytes then we
2066 // get the flip for free. Otherwise it costs. 2066 // get the flip for free. Otherwise it costs.
2067 // Note that we're assuming that 0 rowBytes has already been handled and tha t the width has been 2067 // Note that we're assuming that 0 rowBytes has already been handled and tha t the width has been
2068 // clipped. 2068 // clipped.
2069 return caps.packRowLengthSupport() || GrBytesPerPixel(config) * width == row Bytes; 2069 return caps.packRowLengthSupport() || GrBytesPerPixel(config) * width == row Bytes;
2070 } 2070 }
2071 2071
2072 bool GrGLGpu::readPixelsSupported(GrRenderTarget* target, GrPixelConfig readConf ig) {
2073 auto bindRenderTarget = [this, target]() -> bool {
2074 this->flushRenderTarget(static_cast<GrGLRenderTarget*>(target), &SkIRect ::EmptyIRect());
2075 return true;
2076 };
2077 auto getIntegerv = [this](GrGLenum query, GrGLint* value) {
2078 GR_GL_GetIntegerv(this->glInterface(), query, value);
2079 };
2080 GrPixelConfig rtConfig = target->config();
2081 return this->glCaps().readPixelsSupported(rtConfig, readConfig, getIntegerv, bindRenderTarget);
2082 }
2083
2084 bool GrGLGpu::readPixelsSupported(GrPixelConfig rtConfig, GrPixelConfig readConf ig) {
2085 auto bindRenderTarget = [this, rtConfig]() -> bool {
2086 GrTextureDesc desc;
2087 desc.fConfig = rtConfig;
2088 desc.fWidth = desc.fHeight = 16;
2089 desc.fFlags = kRenderTarget_GrSurfaceFlag;
2090 SkAutoTUnref<GrTexture> temp(this->createTexture(desc, false, nullptr, 0 ));
2091 if (!temp) {
2092 return false;
2093 }
2094 GrGLRenderTarget* glrt = static_cast<GrGLRenderTarget*>(temp->asRenderTa rget());
2095 this->flushRenderTarget(glrt, &SkIRect::EmptyIRect());
2096 return true;
2097 };
2098 auto getIntegerv = [this](GrGLenum query, GrGLint* value) {
2099 GR_GL_GetIntegerv(this->glInterface(), query, value);
2100 };
2101 return this->glCaps().readPixelsSupported(rtConfig, readConfig, getIntegerv, bindRenderTarget);
2102 }
2103
2104 bool GrGLGpu::readPixelsSupported(GrSurface* surfaceForConfig, GrPixelConfig rea dConfig) {
2105 if (GrRenderTarget* rt = surfaceForConfig->asRenderTarget()) {
2106 return this->readPixelsSupported(rt, readConfig);
2107 } else {
2108 GrPixelConfig config = surfaceForConfig->config();
2109 return this->readPixelsSupported(config, readConfig);
2110 }
2111 }
2112
2072 bool GrGLGpu::onGetReadPixelsInfo(GrSurface* srcSurface, int width, int height, size_t rowBytes, 2113 bool GrGLGpu::onGetReadPixelsInfo(GrSurface* srcSurface, int width, int height, size_t rowBytes,
2073 GrPixelConfig readConfig, DrawPreference* draw Preference, 2114 GrPixelConfig readConfig, DrawPreference* draw Preference,
2074 ReadPixelTempDrawInfo* tempDrawInfo) { 2115 ReadPixelTempDrawInfo* tempDrawInfo) {
2116 GrRenderTarget* srcAsRT = srcSurface->asRenderTarget();
2117
2075 // This subclass can only read pixels from a render target. We could use glT exSubImage2D on 2118 // This subclass can only read pixels from a render target. We could use glT exSubImage2D on
2076 // GL versions that support it but we don't today. 2119 // GL versions that support it but we don't today.
2077 if (!srcSurface->asRenderTarget()) { 2120 if (!srcAsRT) {
2078 ElevateDrawPreference(drawPreference, kRequireDraw_DrawPreference); 2121 ElevateDrawPreference(drawPreference, kRequireDraw_DrawPreference);
2079 } 2122 }
2080 2123
2081 if (GrPixelConfigIsSRGB(srcSurface->config()) != GrPixelConfigIsSRGB(readCon fig)) { 2124 if (GrPixelConfigIsSRGB(srcSurface->config()) != GrPixelConfigIsSRGB(readCon fig)) {
2082 ElevateDrawPreference(drawPreference, kRequireDraw_DrawPreference); 2125 ElevateDrawPreference(drawPreference, kRequireDraw_DrawPreference);
2083 } 2126 }
2084 2127
2085 tempDrawInfo->fSwizzle = GrSwizzle::RGBA(); 2128 tempDrawInfo->fSwizzle = GrSwizzle::RGBA();
2086 tempDrawInfo->fReadConfig = readConfig; 2129 tempDrawInfo->fReadConfig = readConfig;
2087 2130
2088 // These settings we will always want if a temp draw is performed. The confi g is set below 2131 // These settings we will always want if a temp draw is performed. The confi g is set below
2089 // depending on whether we want to do a R/B swap or not. 2132 // depending on whether we want to do a R/B swap or not.
2090 tempDrawInfo->fTempSurfaceDesc.fFlags = kRenderTarget_GrSurfaceFlag; 2133 tempDrawInfo->fTempSurfaceDesc.fFlags = kRenderTarget_GrSurfaceFlag;
2091 tempDrawInfo->fTempSurfaceDesc.fWidth = width; 2134 tempDrawInfo->fTempSurfaceDesc.fWidth = width;
2092 tempDrawInfo->fTempSurfaceDesc.fHeight = height; 2135 tempDrawInfo->fTempSurfaceDesc.fHeight = height;
2093 tempDrawInfo->fTempSurfaceDesc.fSampleCnt = 0; 2136 tempDrawInfo->fTempSurfaceDesc.fSampleCnt = 0;
2094 tempDrawInfo->fTempSurfaceDesc.fOrigin = kTopLeft_GrSurfaceOrigin; // no CPU y-flip for TL. 2137 tempDrawInfo->fTempSurfaceDesc.fOrigin = kTopLeft_GrSurfaceOrigin; // no CPU y-flip for TL.
2095 tempDrawInfo->fUseExactScratch = this->glCaps().partialFBOReadIsSlow(); 2138 tempDrawInfo->fUseExactScratch = this->glCaps().partialFBOReadIsSlow();
2096 2139
2097 // Start off assuming that any temp draw should be to the readConfig, then c heck if that will 2140 // Start off assuming that any temp draw should be to the readConfig, then c heck if that will
2098 // be inefficient. 2141 // be inefficient.
2099 GrPixelConfig srcConfig = srcSurface->config(); 2142 GrPixelConfig srcConfig = srcSurface->config();
2100 tempDrawInfo->fTempSurfaceDesc.fConfig = readConfig; 2143 tempDrawInfo->fTempSurfaceDesc.fConfig = readConfig;
2101 2144
2102 if (this->glCaps().rgba8888PixelsOpsAreSlow() && kRGBA_8888_GrPixelConfig == readConfig) { 2145 if (this->glCaps().rgba8888PixelsOpsAreSlow() && kRGBA_8888_GrPixelConfig == readConfig &&
2146 this->readPixelsSupported(kBGRA_8888_GrPixelConfig, kBGRA_8888_GrPixelCo nfig)) {
2103 tempDrawInfo->fTempSurfaceDesc.fConfig = kBGRA_8888_GrPixelConfig; 2147 tempDrawInfo->fTempSurfaceDesc.fConfig = kBGRA_8888_GrPixelConfig;
2104 tempDrawInfo->fSwizzle = GrSwizzle::BGRA(); 2148 tempDrawInfo->fSwizzle = GrSwizzle::BGRA();
2105 tempDrawInfo->fReadConfig = kBGRA_8888_GrPixelConfig; 2149 tempDrawInfo->fReadConfig = kBGRA_8888_GrPixelConfig;
2106 ElevateDrawPreference(drawPreference, kGpuPrefersDraw_DrawPreference); 2150 ElevateDrawPreference(drawPreference, kGpuPrefersDraw_DrawPreference);
2107 } else if (kMesa_GrGLDriver == this->glContext().driver() && 2151 } else if (kMesa_GrGLDriver == this->glContext().driver() &&
2108 GrBytesPerPixel(readConfig) == 4 && 2152 GrBytesPerPixel(readConfig) == 4 &&
2109 GrPixelConfigSwapRAndB(readConfig) == srcConfig) { 2153 GrPixelConfigSwapRAndB(readConfig) == srcConfig &&
2154 this->readPixelsSupported(srcSurface, srcConfig)) {
2110 // Mesa 3D takes a slow path on when reading back BGRA from an RGBA surf ace and vice-versa. 2155 // Mesa 3D takes a slow path on when reading back BGRA from an RGBA surf ace and vice-versa.
2111 // Better to do a draw with a R/B swap and then read as the original con fig. 2156 // Better to do a draw with a R/B swap and then read as the original con fig.
2112 tempDrawInfo->fTempSurfaceDesc.fConfig = srcConfig; 2157 tempDrawInfo->fTempSurfaceDesc.fConfig = srcConfig;
2113 tempDrawInfo->fSwizzle = GrSwizzle::BGRA(); 2158 tempDrawInfo->fSwizzle = GrSwizzle::BGRA();
2114 tempDrawInfo->fReadConfig = srcConfig; 2159 tempDrawInfo->fReadConfig = srcConfig;
2115 ElevateDrawPreference(drawPreference, kGpuPrefersDraw_DrawPreference); 2160 ElevateDrawPreference(drawPreference, kGpuPrefersDraw_DrawPreference);
2116 } else if (readConfig == kBGRA_8888_GrPixelConfig && 2161 } else if (!this->readPixelsSupported(srcSurface, readConfig)) {
2117 !this->glCaps().readPixelsSupported(this->glInterface(), readConf ig, srcConfig)) { 2162 if (readConfig == kBGRA_8888_GrPixelConfig &&
2118 tempDrawInfo->fTempSurfaceDesc.fConfig = kRGBA_8888_GrPixelConfig; 2163 this->glCaps().isConfigRenderable(kRGBA_8888_GrPixelConfig, false) & &
2119 tempDrawInfo->fSwizzle = GrSwizzle::BGRA(); 2164 this->readPixelsSupported(kRGBA_8888_GrPixelConfig, kRGBA_8888_GrPix elConfig)) {
2120 tempDrawInfo->fReadConfig = kRGBA_8888_GrPixelConfig; 2165
2121 ElevateDrawPreference(drawPreference, kRequireDraw_DrawPreference); 2166 tempDrawInfo->fTempSurfaceDesc.fConfig = kRGBA_8888_GrPixelConfig;
2167 tempDrawInfo->fSwizzle = GrSwizzle::BGRA();
2168 tempDrawInfo->fReadConfig = kRGBA_8888_GrPixelConfig;
2169 ElevateDrawPreference(drawPreference, kRequireDraw_DrawPreference);
2170 } else {
2171 return false;
2172 }
2122 } 2173 }
2123 2174
2124 GrRenderTarget* srcAsRT = srcSurface->asRenderTarget(); 2175 if (srcAsRT &&
2125 if (!srcAsRT) { 2176 read_pixels_pays_for_y_flip(srcAsRT, this->glCaps(), width, height, read Config, rowBytes)) {
2126 ElevateDrawPreference(drawPreference, kRequireDraw_DrawPreference);
2127 } else if (read_pixels_pays_for_y_flip(srcAsRT, this->glCaps(), width, heigh t, readConfig,
2128 rowBytes)) {
2129 ElevateDrawPreference(drawPreference, kGpuPrefersDraw_DrawPreference); 2177 ElevateDrawPreference(drawPreference, kGpuPrefersDraw_DrawPreference);
2130 } 2178 }
2131 2179
2132 return true; 2180 return true;
2133 } 2181 }
2134 2182
2135 bool GrGLGpu::onReadPixels(GrSurface* surface, 2183 bool GrGLGpu::onReadPixels(GrSurface* surface,
2136 int left, int top, 2184 int left, int top,
2137 int width, int height, 2185 int width, int height,
2138 GrPixelConfig config, 2186 GrPixelConfig config,
(...skipping 1569 matching lines...) Expand 10 before | Expand all | Expand 10 after
3708 if (GR_GL_TEXTURE_EXTERNAL == glTexture->target() || 3756 if (GR_GL_TEXTURE_EXTERNAL == glTexture->target() ||
3709 GR_GL_TEXTURE_RECTANGLE == glTexture->target()) { 3757 GR_GL_TEXTURE_RECTANGLE == glTexture->target()) {
3710 copyParams->fFilter = GrTextureParams::kNone_FilterMode; 3758 copyParams->fFilter = GrTextureParams::kNone_FilterMode;
3711 copyParams->fWidth = texture->width(); 3759 copyParams->fWidth = texture->width();
3712 copyParams->fHeight = texture->height(); 3760 copyParams->fHeight = texture->height();
3713 return true; 3761 return true;
3714 } 3762 }
3715 } 3763 }
3716 return false; 3764 return false;
3717 } 3765 }
OLDNEW
« no previous file with comments | « src/gpu/gl/GrGLGpu.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698