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

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

Issue 1584563002: Make A8 readback work in more cases and improve testing. (Closed) Base URL: https://skia.googlesource.com/skia.git@outputswiz
Patch Set: fix test for ios 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
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 if (!srcSurface->asRenderTarget()) { 1954 GrRenderTarget* srcAsRT = srcSurface->asRenderTarget();
1955 if (!srcAsRT) {
1955 ElevateDrawPreference(drawPreference, kRequireDraw_DrawPreference); 1956 ElevateDrawPreference(drawPreference, kRequireDraw_DrawPreference);
1956 } 1957 }
1957 1958
1958 if (GrPixelConfigIsSRGB(srcSurface->config()) != GrPixelConfigIsSRGB(readCon fig)) { 1959 if (GrPixelConfigIsSRGB(srcSurface->config()) != GrPixelConfigIsSRGB(readCon fig)) {
1959 ElevateDrawPreference(drawPreference, kRequireDraw_DrawPreference); 1960 ElevateDrawPreference(drawPreference, kRequireDraw_DrawPreference);
1960 } 1961 }
1961 1962
1962 tempDrawInfo->fSwapRAndB = false; 1963 tempDrawInfo->fSwapRAndB = false;
1963 1964
1964 // These settings we will always want if a temp draw is performed. The confi g is set below 1965 // These settings we will always want if a temp draw is performed. The confi g is set below
(...skipping 20 matching lines...) Expand all
1985 // Mesa 3D takes a slow path on when reading back BGRA from an RGBA sur face and vice-versa. 1986 // Mesa 3D takes a slow path on when reading back BGRA from an RGBA sur face and vice-versa.
1986 // Better to do a draw with a R/B swap and then read as the original con fig. 1987 // Better to do a draw with a R/B swap and then read as the original con fig.
1987 tempDrawInfo->fTempSurfaceDesc.fConfig = srcConfig; 1988 tempDrawInfo->fTempSurfaceDesc.fConfig = srcConfig;
1988 tempDrawInfo->fSwapRAndB = true; 1989 tempDrawInfo->fSwapRAndB = true;
1989 ElevateDrawPreference(drawPreference, kGpuPrefersDraw_DrawPreference); 1990 ElevateDrawPreference(drawPreference, kGpuPrefersDraw_DrawPreference);
1990 } else if (readConfig == kBGRA_8888_GrPixelConfig && 1991 } else if (readConfig == kBGRA_8888_GrPixelConfig &&
1991 !this->glCaps().readPixelsSupported(this->glInterface(), readConf ig, srcConfig)) { 1992 !this->glCaps().readPixelsSupported(this->glInterface(), readConf ig, srcConfig)) {
1992 tempDrawInfo->fTempSurfaceDesc.fConfig = kRGBA_8888_GrPixelConfig; 1993 tempDrawInfo->fTempSurfaceDesc.fConfig = kRGBA_8888_GrPixelConfig;
1993 tempDrawInfo->fSwapRAndB = true; 1994 tempDrawInfo->fSwapRAndB = true;
1994 ElevateDrawPreference(drawPreference, kRequireDraw_DrawPreference); 1995 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 }
1995 } 2006 }
1996 2007
1997 GrRenderTarget* srcAsRT = srcSurface->asRenderTarget(); 2008 if (srcAsRT && read_pixels_pays_for_y_flip(srcAsRT, this->glCaps(), width, h eight, readConfig,
1998 if (!srcAsRT) { 2009 rowBytes)) {
1999 ElevateDrawPreference(drawPreference, kRequireDraw_DrawPreference);
2000 } else if (read_pixels_pays_for_y_flip(srcAsRT, this->glCaps(), width, heigh t, readConfig,
2001 rowBytes)) {
2002 ElevateDrawPreference(drawPreference, kGpuPrefersDraw_DrawPreference); 2010 ElevateDrawPreference(drawPreference, kGpuPrefersDraw_DrawPreference);
2003 } 2011 }
2004 2012
2005 return true; 2013 return true;
2006 } 2014 }
2007 2015
2008 bool GrGLGpu::onReadPixels(GrSurface* surface, 2016 bool GrGLGpu::onReadPixels(GrSurface* surface,
2009 int left, int top, 2017 int left, int top,
2010 int width, int height, 2018 int width, int height,
2011 GrPixelConfig config, 2019 GrPixelConfig config,
(...skipping 30 matching lines...) Expand all
2042 this->onResolveRenderTarget(tgt); 2050 this->onResolveRenderTarget(tgt);
2043 // we don't track the state of the READ FBO ID. 2051 // we don't track the state of the READ FBO ID.
2044 fStats.incRenderTargetBinds(); 2052 fStats.incRenderTargetBinds();
2045 GL_CALL(BindFramebuffer(GR_GL_READ_FRAMEBUFFER, 2053 GL_CALL(BindFramebuffer(GR_GL_READ_FRAMEBUFFER,
2046 tgt->textureFBOID())); 2054 tgt->textureFBOID()));
2047 break; 2055 break;
2048 default: 2056 default:
2049 SkFAIL("Unknown resolve type"); 2057 SkFAIL("Unknown resolve type");
2050 } 2058 }
2051 2059
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
2052 const GrGLIRect& glvp = tgt->getViewport(); 2082 const GrGLIRect& glvp = tgt->getViewport();
2053 2083
2054 // the read rect is viewport-relative 2084 // the read rect is viewport-relative
2055 GrGLIRect readRect; 2085 GrGLIRect readRect;
2056 readRect.setRelativeTo(glvp, left, top, width, height, tgt->origin()); 2086 readRect.setRelativeTo(glvp, left, top, width, height, tgt->origin());
2057 2087
2058 size_t tightRowBytes = GrBytesPerPixel(config) * width; 2088 size_t tightRowBytes = GrBytesPerPixel(config) * width;
2059 2089
2060 size_t readDstRowBytes = tightRowBytes; 2090 size_t readDstRowBytes = tightRowBytes;
2061 void* readDst = buffer; 2091 void* readDst = buffer;
(...skipping 1395 matching lines...) Expand 10 before | Expand all | Expand 10 after
3457 this->setVertexArrayID(gpu, 0); 3487 this->setVertexArrayID(gpu, 0);
3458 } 3488 }
3459 int attrCount = gpu->glCaps().maxVertexAttributes(); 3489 int attrCount = gpu->glCaps().maxVertexAttributes();
3460 if (fDefaultVertexArrayAttribState.count() != attrCount) { 3490 if (fDefaultVertexArrayAttribState.count() != attrCount) {
3461 fDefaultVertexArrayAttribState.resize(attrCount); 3491 fDefaultVertexArrayAttribState.resize(attrCount);
3462 } 3492 }
3463 attribState = &fDefaultVertexArrayAttribState; 3493 attribState = &fDefaultVertexArrayAttribState;
3464 } 3494 }
3465 return attribState; 3495 return attribState;
3466 } 3496 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698