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

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

Issue 1581203005: Revert of Make A8 readback work in more cases and improve testing. (Closed) Base URL: https://skia.googlesource.com/skia.git@outputswiz
Patch Set: 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/GrGLCaps.cpp ('k') | tests/ReadWriteAlphaTest.cpp » ('j') | 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 1933 matching lines...) Expand 10 before | Expand all | Expand 10 after
1944 // Note that we're assuming that 0 rowBytes has already been handled and tha t the width has been 1944 // Note that we're assuming that 0 rowBytes has already been handled and tha t the width has been
1945 // clipped. 1945 // clipped.
1946 return caps.packRowLengthSupport() || GrBytesPerPixel(config) * width == row Bytes; 1946 return caps.packRowLengthSupport() || GrBytesPerPixel(config) * width == row Bytes;
1947 } 1947 }
1948 1948
1949 bool GrGLGpu::onGetReadPixelsInfo(GrSurface* srcSurface, int width, int height, size_t rowBytes, 1949 bool GrGLGpu::onGetReadPixelsInfo(GrSurface* srcSurface, int width, int height, size_t rowBytes,
1950 GrPixelConfig readConfig, DrawPreference* draw Preference, 1950 GrPixelConfig readConfig, DrawPreference* draw Preference,
1951 ReadPixelTempDrawInfo* tempDrawInfo) { 1951 ReadPixelTempDrawInfo* tempDrawInfo) {
1952 // This subclass can only read pixels from a render target. We could use glT exSubImage2D on 1952 // This subclass can only read pixels from a render target. We could use glT exSubImage2D on
1953 // GL versions that support it but we don't today. 1953 // GL versions that support it but we don't today.
1954 GrRenderTarget* srcAsRT = srcSurface->asRenderTarget(); 1954 if (!srcSurface->asRenderTarget()) {
1955 if (!srcAsRT) {
1956 ElevateDrawPreference(drawPreference, kRequireDraw_DrawPreference); 1955 ElevateDrawPreference(drawPreference, kRequireDraw_DrawPreference);
1957 } 1956 }
1958 1957
1959 if (GrPixelConfigIsSRGB(srcSurface->config()) != GrPixelConfigIsSRGB(readCon fig)) { 1958 if (GrPixelConfigIsSRGB(srcSurface->config()) != GrPixelConfigIsSRGB(readCon fig)) {
1960 ElevateDrawPreference(drawPreference, kRequireDraw_DrawPreference); 1959 ElevateDrawPreference(drawPreference, kRequireDraw_DrawPreference);
1961 } 1960 }
1962 1961
1963 tempDrawInfo->fSwapRAndB = false; 1962 tempDrawInfo->fSwapRAndB = false;
1964 1963
1965 // These settings we will always want if a temp draw is performed. The confi g is set below 1964 // These settings we will always want if a temp draw is performed. The confi g is set below
(...skipping 20 matching lines...) Expand all
1986 // Mesa 3D takes a slow path on when reading back BGRA from an RGBA sur face and vice-versa. 1985 // Mesa 3D takes a slow path on when reading back BGRA from an RGBA sur face and vice-versa.
1987 // Better to do a draw with a R/B swap and then read as the original con fig. 1986 // Better to do a draw with a R/B swap and then read as the original con fig.
1988 tempDrawInfo->fTempSurfaceDesc.fConfig = srcConfig; 1987 tempDrawInfo->fTempSurfaceDesc.fConfig = srcConfig;
1989 tempDrawInfo->fSwapRAndB = true; 1988 tempDrawInfo->fSwapRAndB = true;
1990 ElevateDrawPreference(drawPreference, kGpuPrefersDraw_DrawPreference); 1989 ElevateDrawPreference(drawPreference, kGpuPrefersDraw_DrawPreference);
1991 } else if (readConfig == kBGRA_8888_GrPixelConfig && 1990 } else if (readConfig == kBGRA_8888_GrPixelConfig &&
1992 !this->glCaps().readPixelsSupported(this->glInterface(), readConf ig, srcConfig)) { 1991 !this->glCaps().readPixelsSupported(this->glInterface(), readConf ig, srcConfig)) {
1993 tempDrawInfo->fTempSurfaceDesc.fConfig = kRGBA_8888_GrPixelConfig; 1992 tempDrawInfo->fTempSurfaceDesc.fConfig = kRGBA_8888_GrPixelConfig;
1994 tempDrawInfo->fSwapRAndB = true; 1993 tempDrawInfo->fSwapRAndB = true;
1995 ElevateDrawPreference(drawPreference, kRequireDraw_DrawPreference); 1994 ElevateDrawPreference(drawPreference, kRequireDraw_DrawPreference);
1996 } else if (kRequireDraw_DrawPreference == *drawPreference &&
1997 readConfig == kAlpha_8_GrPixelConfig &&
1998 !this->caps()->isConfigRenderable(kAlpha_8_GrPixelConfig, false)) {
1999 // On some GLs there is no renderable single channel format. In that cas e we fall back
2000 // to rendering to a RGBA and then will extract the alpha from that.
2001 if (this->caps()->isConfigRenderable(kRGBA_8888_GrPixelConfig, false)) {
2002 tempDrawInfo->fTempSurfaceDesc.fConfig = kRGBA_8888_GrPixelConfig;
2003 } else {
2004 return false;
2005 }
2006 } 1995 }
2007 1996
2008 if (srcAsRT && read_pixels_pays_for_y_flip(srcAsRT, this->glCaps(), width, h eight, readConfig, 1997 GrRenderTarget* srcAsRT = srcSurface->asRenderTarget();
2009 rowBytes)) { 1998 if (!srcAsRT) {
1999 ElevateDrawPreference(drawPreference, kRequireDraw_DrawPreference);
2000 } else if (read_pixels_pays_for_y_flip(srcAsRT, this->glCaps(), width, heigh t, readConfig,
2001 rowBytes)) {
2010 ElevateDrawPreference(drawPreference, kGpuPrefersDraw_DrawPreference); 2002 ElevateDrawPreference(drawPreference, kGpuPrefersDraw_DrawPreference);
2011 } 2003 }
2012 2004
2013 return true; 2005 return true;
2014 } 2006 }
2015 2007
2016 bool GrGLGpu::onReadPixels(GrSurface* surface, 2008 bool GrGLGpu::onReadPixels(GrSurface* surface,
2017 int left, int top, 2009 int left, int top,
2018 int width, int height, 2010 int width, int height,
2019 GrPixelConfig config, 2011 GrPixelConfig config,
(...skipping 30 matching lines...) Expand all
2050 this->onResolveRenderTarget(tgt); 2042 this->onResolveRenderTarget(tgt);
2051 // we don't track the state of the READ FBO ID. 2043 // we don't track the state of the READ FBO ID.
2052 fStats.incRenderTargetBinds(); 2044 fStats.incRenderTargetBinds();
2053 GL_CALL(BindFramebuffer(GR_GL_READ_FRAMEBUFFER, 2045 GL_CALL(BindFramebuffer(GR_GL_READ_FRAMEBUFFER,
2054 tgt->textureFBOID())); 2046 tgt->textureFBOID()));
2055 break; 2047 break;
2056 default: 2048 default:
2057 SkFAIL("Unknown resolve type"); 2049 SkFAIL("Unknown resolve type");
2058 } 2050 }
2059 2051
2060 // We have a special case fallback for reading alpha from a RGBA/BGRA surfac e. We will read
2061 // back all the channels as RGBA and then extract A.
2062 // This must be called after the RT is bound as the FBO above.
2063 if (!this->glCaps().readPixelsSupported(this->glInterface(), config, tgt->co nfig())) {
2064 if ((tgt->config() == kRGBA_8888_GrPixelConfig ||
2065 tgt->config() == kBGRA_8888_GrPixelConfig) &&
2066 kAlpha_8_GrPixelConfig == config) {
2067 SkAutoTDeleteArray<uint32_t> temp(new uint32_t[width * height * 4]);
2068 if (this->onReadPixels(surface, left, top, width, height, kRGBA_8888 _GrPixelConfig,
2069 temp.get(), width*4)) {
2070 uint8_t* dst = reinterpret_cast<uint8_t*>(buffer);
2071 for (int j = 0; j < height; ++j) {
2072 for (int i = 0; i < width; ++i) {
2073 dst[j*rowBytes + i] = (0xFF000000U & temp[j*width+i]) >> 24;
2074 }
2075 }
2076 return true;
2077 }
2078 }
2079 return false;
2080 }
2081
2082 const GrGLIRect& glvp = tgt->getViewport(); 2052 const GrGLIRect& glvp = tgt->getViewport();
2083 2053
2084 // the read rect is viewport-relative 2054 // the read rect is viewport-relative
2085 GrGLIRect readRect; 2055 GrGLIRect readRect;
2086 readRect.setRelativeTo(glvp, left, top, width, height, tgt->origin()); 2056 readRect.setRelativeTo(glvp, left, top, width, height, tgt->origin());
2087 2057
2088 size_t tightRowBytes = GrBytesPerPixel(config) * width; 2058 size_t tightRowBytes = GrBytesPerPixel(config) * width;
2089 2059
2090 size_t readDstRowBytes = tightRowBytes; 2060 size_t readDstRowBytes = tightRowBytes;
2091 void* readDst = buffer; 2061 void* readDst = buffer;
(...skipping 1395 matching lines...) Expand 10 before | Expand all | Expand 10 after
3487 this->setVertexArrayID(gpu, 0); 3457 this->setVertexArrayID(gpu, 0);
3488 } 3458 }
3489 int attrCount = gpu->glCaps().maxVertexAttributes(); 3459 int attrCount = gpu->glCaps().maxVertexAttributes();
3490 if (fDefaultVertexArrayAttribState.count() != attrCount) { 3460 if (fDefaultVertexArrayAttribState.count() != attrCount) {
3491 fDefaultVertexArrayAttribState.resize(attrCount); 3461 fDefaultVertexArrayAttribState.resize(attrCount);
3492 } 3462 }
3493 attribState = &fDefaultVertexArrayAttribState; 3463 attribState = &fDefaultVertexArrayAttribState;
3494 } 3464 }
3495 return attribState; 3465 return attribState;
3496 } 3466 }
OLDNEW
« no previous file with comments | « src/gpu/gl/GrGLCaps.cpp ('k') | tests/ReadWriteAlphaTest.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698