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

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

Issue 1789663002: sRGB support in Ganesh. Several pieces: (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: Ensure sBGRA is unsupported on ES 2.0. Fix CreateRenderTarget. Created 4 years, 9 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 #include "GrGLGpu.h" 8 #include "GrGLGpu.h"
9 #include "GrGLGLSL.h" 9 #include "GrGLGLSL.h"
10 #include "GrGLStencilAttachment.h" 10 #include "GrGLStencilAttachment.h"
(...skipping 877 matching lines...) Expand 10 before | Expand all | Expand 10 after
888 case kAlpha_8_GrPixelConfig: 888 case kAlpha_8_GrPixelConfig:
889 return 1; 889 return 1;
890 case kRGB_565_GrPixelConfig: 890 case kRGB_565_GrPixelConfig:
891 case kRGBA_4444_GrPixelConfig: 891 case kRGBA_4444_GrPixelConfig:
892 case kAlpha_half_GrPixelConfig: 892 case kAlpha_half_GrPixelConfig:
893 case kRGBA_half_GrPixelConfig: 893 case kRGBA_half_GrPixelConfig:
894 return 2; 894 return 2;
895 case kRGBA_8888_GrPixelConfig: 895 case kRGBA_8888_GrPixelConfig:
896 case kBGRA_8888_GrPixelConfig: 896 case kBGRA_8888_GrPixelConfig:
897 case kSRGBA_8888_GrPixelConfig: 897 case kSRGBA_8888_GrPixelConfig:
898 case kSBGRA_8888_GrPixelConfig:
898 case kRGBA_float_GrPixelConfig: 899 case kRGBA_float_GrPixelConfig:
899 return 4; 900 return 4;
900 default: 901 default:
901 return 0; 902 return 0;
902 } 903 }
903 } 904 }
904 905
905 static inline GrGLenum check_alloc_error(const GrSurfaceDesc& desc, 906 static inline GrGLenum check_alloc_error(const GrSurfaceDesc& desc,
906 const GrGLInterface* interface) { 907 const GrGLInterface* interface) {
907 if (SkToBool(desc.fFlags & kCheckAllocation_GrSurfaceFlag)) { 908 if (SkToBool(desc.fFlags & kCheckAllocation_GrSurfaceFlag)) {
(...skipping 1183 matching lines...) Expand 10 before | Expand all | Expand 10 after
2091 if (blendInfo.fWriteColor) { 2092 if (blendInfo.fWriteColor) {
2092 // Swizzle the blend to match what the shader will output. 2093 // Swizzle the blend to match what the shader will output.
2093 const GrSwizzle& swizzle = this->glCaps().glslCaps()->configOutputSwizzl e( 2094 const GrSwizzle& swizzle = this->glCaps().glslCaps()->configOutputSwizzl e(
2094 args.fPipeline->getRenderTarget()->config()); 2095 args.fPipeline->getRenderTarget()->config());
2095 this->flushBlend(blendInfo, swizzle); 2096 this->flushBlend(blendInfo, swizzle);
2096 } 2097 }
2097 2098
2098 SkSTArray<8, const GrTextureAccess*> textureAccesses; 2099 SkSTArray<8, const GrTextureAccess*> textureAccesses;
2099 program->setData(*args.fPrimitiveProcessor, pipeline, &textureAccesses); 2100 program->setData(*args.fPrimitiveProcessor, pipeline, &textureAccesses);
2100 2101
2102 GrGLRenderTarget* glRT = static_cast<GrGLRenderTarget*>(pipeline.getRenderTa rget());
2103 GrSRGBPolicy srgbPolicy = GrPixelConfigSRGBPolicy(glRT->config());
2104
2101 int numTextureAccesses = textureAccesses.count(); 2105 int numTextureAccesses = textureAccesses.count();
2102 for (int i = 0; i < numTextureAccesses; i++) { 2106 for (int i = 0; i < numTextureAccesses; i++) {
2103 this->bindTexture(i, textureAccesses[i]->getParams(), 2107 this->bindTexture(i, textureAccesses[i]->getParams(), srgbPolicy,
2104 static_cast<GrGLTexture*>(textureAccesses[i]->getTextu re())); 2108 static_cast<GrGLTexture*>(textureAccesses[i]->getTextu re()));
2105 } 2109 }
2106 2110
2107 GrGLRenderTarget* glRT = static_cast<GrGLRenderTarget*>(pipeline.getRenderTa rget());
2108 this->flushStencil(pipeline.getStencil()); 2111 this->flushStencil(pipeline.getStencil());
2109 this->flushScissor(pipeline.getScissorState(), glRT->getViewport(), glRT->or igin()); 2112 this->flushScissor(pipeline.getScissorState(), glRT->getViewport(), glRT->or igin());
2110 this->flushHWAAState(glRT, pipeline.isHWAntialiasState(), !pipeline.getStenc il().isDisabled()); 2113 this->flushHWAAState(glRT, pipeline.isHWAntialiasState(), !pipeline.getStenc il().isDisabled());
2111 2114
2112 // This must come after textures are flushed because a texture may need 2115 // This must come after textures are flushed because a texture may need
2113 // to be msaa-resolved (which will modify bound FBO state). 2116 // to be msaa-resolved (which will modify bound FBO state).
2114 this->flushRenderTarget(glRT, nullptr); 2117 this->flushRenderTarget(glRT, nullptr);
2115 2118
2116 return true; 2119 return true;
2117 } 2120 }
(...skipping 456 matching lines...) Expand 10 before | Expand all | Expand 10 after
2574 if (readConfig == kBGRA_8888_GrPixelConfig && 2577 if (readConfig == kBGRA_8888_GrPixelConfig &&
2575 this->glCaps().isConfigRenderable(kRGBA_8888_GrPixelConfig, false) & & 2578 this->glCaps().isConfigRenderable(kRGBA_8888_GrPixelConfig, false) & &
2576 this->readPixelsSupported(kRGBA_8888_GrPixelConfig, kRGBA_8888_GrPix elConfig)) { 2579 this->readPixelsSupported(kRGBA_8888_GrPixelConfig, kRGBA_8888_GrPix elConfig)) {
2577 // We're trying to read BGRA but it's not supported. If RGBA is rend erable and 2580 // We're trying to read BGRA but it's not supported. If RGBA is rend erable and
2578 // we can read it back, then do a swizzling draw to a RGBA and read it back (which 2581 // we can read it back, then do a swizzling draw to a RGBA and read it back (which
2579 // will effectively be BGRA). 2582 // will effectively be BGRA).
2580 tempDrawInfo->fTempSurfaceDesc.fConfig = kRGBA_8888_GrPixelConfig; 2583 tempDrawInfo->fTempSurfaceDesc.fConfig = kRGBA_8888_GrPixelConfig;
2581 tempDrawInfo->fSwizzle = GrSwizzle::BGRA(); 2584 tempDrawInfo->fSwizzle = GrSwizzle::BGRA();
2582 tempDrawInfo->fReadConfig = kRGBA_8888_GrPixelConfig; 2585 tempDrawInfo->fReadConfig = kRGBA_8888_GrPixelConfig;
2583 ElevateDrawPreference(drawPreference, kRequireDraw_DrawPreference); 2586 ElevateDrawPreference(drawPreference, kRequireDraw_DrawPreference);
2587 } else if (readConfig == kSBGRA_8888_GrPixelConfig &&
2588 this->glCaps().isConfigRenderable(kSRGBA_8888_GrPixelConfig, false) &&
2589 this->readPixelsSupported(kSRGBA_8888_GrPixelConfig, kSRGBA_8888_GrP ixelConfig)) {
2590 // We're trying to read sBGRA but it's not supported. If sRGBA is re nderable and
2591 // we can read it back, then do a swizzling draw to a sRGBA and read it back (which
2592 // will effectively be sBGRA).
2593 tempDrawInfo->fTempSurfaceDesc.fConfig = kSRGBA_8888_GrPixelConfig;
2594 tempDrawInfo->fSwizzle = GrSwizzle::BGRA();
2595 tempDrawInfo->fReadConfig = kSRGBA_8888_GrPixelConfig;
2596 ElevateDrawPreference(drawPreference, kRequireDraw_DrawPreference);
Brian Osman 2016/03/11 17:15:24 This block of code may make no sense, given how sB
2584 } else if (readConfig == kAlpha_8_GrPixelConfig) { 2597 } else if (readConfig == kAlpha_8_GrPixelConfig) {
2585 // onReadPixels implements a fallback for cases where we are want to read kAlpha_8, 2598 // onReadPixels implements a fallback for cases where we are want to read kAlpha_8,
2586 // it's unsupported, but 32bit RGBA reads are supported. 2599 // it's unsupported, but 32bit RGBA reads are supported.
2587 // Don't attempt to do any srgb conversions since we only care about alpha. 2600 // Don't attempt to do any srgb conversions since we only care about alpha.
2588 GrPixelConfig cpuTempConfig = kRGBA_8888_GrPixelConfig; 2601 GrPixelConfig cpuTempConfig = kRGBA_8888_GrPixelConfig;
2589 if (GrPixelConfigIsSRGB(srcSurface->config())) { 2602 if (GrPixelConfigIsSRGB(srcSurface->config())) {
2590 cpuTempConfig = kSRGBA_8888_GrPixelConfig; 2603 cpuTempConfig = kSRGBA_8888_GrPixelConfig;
2591 } 2604 }
2592 if (!this->readPixelsSupported(srcSurface, cpuTempConfig)) { 2605 if (!this->readPixelsSupported(srcSurface, cpuTempConfig)) {
2593 // If we can't read RGBA from the src try to draw to a kRGBA_888 8 (or kSRGBA_8888) 2606 // If we can't read RGBA from the src try to draw to a kRGBA_888 8 (or kSRGBA_8888)
(...skipping 672 matching lines...) Expand 10 before | Expand all | Expand 10 after
3266 the generated shader code. This potentially allows greater reuse of cached sha ders. */ 3279 the generated shader code. This potentially allows greater reuse of cached sha ders. */
3267 static void get_tex_param_swizzle(GrPixelConfig config, 3280 static void get_tex_param_swizzle(GrPixelConfig config,
3268 const GrGLCaps& caps, 3281 const GrGLCaps& caps,
3269 GrGLenum* glSwizzle) { 3282 GrGLenum* glSwizzle) {
3270 const GrSwizzle& swizzle = caps.configSwizzle(config); 3283 const GrSwizzle& swizzle = caps.configSwizzle(config);
3271 for (int i = 0; i < 4; ++i) { 3284 for (int i = 0; i < 4; ++i) {
3272 glSwizzle[i] = get_component_enum_from_char(swizzle.c_str()[i]); 3285 glSwizzle[i] = get_component_enum_from_char(swizzle.c_str()[i]);
3273 } 3286 }
3274 } 3287 }
3275 3288
3276 void GrGLGpu::bindTexture(int unitIdx, const GrTextureParams& params, GrGLTextur e* texture) { 3289 void GrGLGpu::bindTexture(int unitIdx, const GrTextureParams& params, GrSRGBPoli cy srgbPolicy,
3290 GrGLTexture* texture) {
3277 SkASSERT(texture); 3291 SkASSERT(texture);
3278 3292
3279 #ifdef SK_DEBUG 3293 #ifdef SK_DEBUG
3280 if (!this->caps()->npotTextureTileSupport()) { 3294 if (!this->caps()->npotTextureTileSupport()) {
3281 const bool tileX = SkShader::kClamp_TileMode != params.getTileModeX(); 3295 const bool tileX = SkShader::kClamp_TileMode != params.getTileModeX();
3282 const bool tileY = SkShader::kClamp_TileMode != params.getTileModeY(); 3296 const bool tileY = SkShader::kClamp_TileMode != params.getTileModeY();
3283 if (tileX || tileY) { 3297 if (tileX || tileY) {
3284 const int w = texture->width(); 3298 const int w = texture->width();
3285 const int h = texture->height(); 3299 const int h = texture->height();
3286 SkASSERT(SkIsPow2(w) && SkIsPow2(h)); 3300 SkASSERT(SkIsPow2(w) && SkIsPow2(h));
(...skipping 15 matching lines...) Expand all
3302 this->setTextureUnit(unitIdx); 3316 this->setTextureUnit(unitIdx);
3303 GL_CALL(BindTexture(target, texture->textureID())); 3317 GL_CALL(BindTexture(target, texture->textureID()));
3304 fHWBoundTextureUniqueIDs[unitIdx] = textureID; 3318 fHWBoundTextureUniqueIDs[unitIdx] = textureID;
3305 } 3319 }
3306 3320
3307 ResetTimestamp timestamp; 3321 ResetTimestamp timestamp;
3308 const GrGLTexture::TexParams& oldTexParams = texture->getCachedTexParams(&ti mestamp); 3322 const GrGLTexture::TexParams& oldTexParams = texture->getCachedTexParams(&ti mestamp);
3309 bool setAll = timestamp < this->getResetTimestamp(); 3323 bool setAll = timestamp < this->getResetTimestamp();
3310 GrGLTexture::TexParams newTexParams; 3324 GrGLTexture::TexParams newTexParams;
3311 3325
3326 if (this->caps()->srgbSupport()) {
3327 static GrGLenum glSRGBDecodeModes[] = {
3328 GR_GL_DECODE_EXT, // kUnknown_GrSRGBPolicy
3329 GR_GL_DECODE_EXT, // kAllowSRGB_GrSRGBPolicy
3330 GR_GL_SKIP_DECODE_EXT // kSuppressSRGB_GrSRGBPolicy
3331 };
3332
3333 // By default, the decision to allow SRGB decode is based on the destina tion config.
3334 // A texture can override that by specifying a value in GrTextureParams.
3335 if (kUnknown_GrSRGBPolicy != params.srgbPolicy()) {
3336 srgbPolicy = params.srgbPolicy();
3337 }
3338
3339 SkASSERT(srgbPolicy >= kAllowSRGB_GrSRGBPolicy && srgbPolicy <= kSuppres sSRGB_GrSRGBPolicy);
3340 newTexParams.fSRGBDecode = glSRGBDecodeModes[srgbPolicy];
3341 if (setAll || newTexParams.fSRGBDecode != oldTexParams.fSRGBDecode) {
3342 this->setTextureUnit(unitIdx);
3343 GL_CALL(TexParameteri(target, GR_GL_TEXTURE_SRGB_DECODE_EXT, newTexP arams.fSRGBDecode));
3344 }
3345 }
3346
3312 static GrGLenum glMinFilterModes[] = { 3347 static GrGLenum glMinFilterModes[] = {
3313 GR_GL_NEAREST, 3348 GR_GL_NEAREST,
3314 GR_GL_LINEAR, 3349 GR_GL_LINEAR,
3315 GR_GL_LINEAR_MIPMAP_LINEAR 3350 GR_GL_LINEAR_MIPMAP_LINEAR
3316 }; 3351 };
3317 static GrGLenum glMagFilterModes[] = { 3352 static GrGLenum glMagFilterModes[] = {
3318 GR_GL_NEAREST, 3353 GR_GL_NEAREST,
3319 GR_GL_LINEAR, 3354 GR_GL_LINEAR,
3320 GR_GL_LINEAR 3355 GR_GL_LINEAR
3321 }; 3356 };
(...skipping 647 matching lines...) Expand 10 before | Expand all | Expand 10 after
3969 4004
3970 void GrGLGpu::copySurfaceAsDraw(GrSurface* dst, 4005 void GrGLGpu::copySurfaceAsDraw(GrSurface* dst,
3971 GrSurface* src, 4006 GrSurface* src,
3972 const SkIRect& srcRect, 4007 const SkIRect& srcRect,
3973 const SkIPoint& dstPoint) { 4008 const SkIPoint& dstPoint) {
3974 int w = srcRect.width(); 4009 int w = srcRect.width();
3975 int h = srcRect.height(); 4010 int h = srcRect.height();
3976 4011
3977 GrGLTexture* srcTex = static_cast<GrGLTexture*>(src->asTexture()); 4012 GrGLTexture* srcTex = static_cast<GrGLTexture*>(src->asTexture());
3978 GrTextureParams params(SkShader::kClamp_TileMode, GrTextureParams::kNone_Fil terMode); 4013 GrTextureParams params(SkShader::kClamp_TileMode, GrTextureParams::kNone_Fil terMode);
3979 this->bindTexture(0, params, srcTex); 4014 this->bindTexture(0, params, kAllowSRGB_GrSRGBPolicy, srcTex);
3980 4015
3981 GrGLIRect dstVP; 4016 GrGLIRect dstVP;
3982 this->bindSurfaceFBOForCopy(dst, GR_GL_FRAMEBUFFER, &dstVP, kDst_TempFBOTarg et); 4017 this->bindSurfaceFBOForCopy(dst, GR_GL_FRAMEBUFFER, &dstVP, kDst_TempFBOTarg et);
3983 this->flushViewport(dstVP); 4018 this->flushViewport(dstVP);
3984 fHWBoundRenderTargetUniqueID = SK_InvalidUniqueID; 4019 fHWBoundRenderTargetUniqueID = SK_InvalidUniqueID;
3985 4020
3986 SkIRect dstRect = SkIRect::MakeXYWH(dstPoint.fX, dstPoint.fY, w, h); 4021 SkIRect dstRect = SkIRect::MakeXYWH(dstPoint.fX, dstPoint.fY, w, h);
3987 4022
3988 int progIdx = TextureTargetToCopyProgramIdx(srcTex->target()); 4023 int progIdx = TextureTargetToCopyProgramIdx(srcTex->target());
3989 4024
(...skipping 362 matching lines...) Expand 10 before | Expand all | Expand 10 after
4352 if (GR_GL_TEXTURE_EXTERNAL == glTexture->target() || 4387 if (GR_GL_TEXTURE_EXTERNAL == glTexture->target() ||
4353 GR_GL_TEXTURE_RECTANGLE == glTexture->target()) { 4388 GR_GL_TEXTURE_RECTANGLE == glTexture->target()) {
4354 copyParams->fFilter = GrTextureParams::kNone_FilterMode; 4389 copyParams->fFilter = GrTextureParams::kNone_FilterMode;
4355 copyParams->fWidth = texture->width(); 4390 copyParams->fWidth = texture->width();
4356 copyParams->fHeight = texture->height(); 4391 copyParams->fHeight = texture->height();
4357 return true; 4392 return true;
4358 } 4393 }
4359 } 4394 }
4360 return false; 4395 return false;
4361 } 4396 }
OLDNEW
« src/gpu/gl/GrGLCaps.cpp ('K') | « src/gpu/gl/GrGLGpu.h ('k') | src/gpu/gl/GrGLTexture.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698