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 #include "GrGLGpu.h" | 8 #include "GrGLGpu.h" |
9 #include "GrGLGLSL.h" | 9 #include "GrGLGLSL.h" |
10 #include "GrGLStencilAttachment.h" | 10 #include "GrGLStencilAttachment.h" |
(...skipping 880 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
891 case kAlpha_8_GrPixelConfig: | 891 case kAlpha_8_GrPixelConfig: |
892 return 1; | 892 return 1; |
893 case kRGB_565_GrPixelConfig: | 893 case kRGB_565_GrPixelConfig: |
894 case kRGBA_4444_GrPixelConfig: | 894 case kRGBA_4444_GrPixelConfig: |
895 case kAlpha_half_GrPixelConfig: | 895 case kAlpha_half_GrPixelConfig: |
896 case kRGBA_half_GrPixelConfig: | 896 case kRGBA_half_GrPixelConfig: |
897 return 2; | 897 return 2; |
898 case kRGBA_8888_GrPixelConfig: | 898 case kRGBA_8888_GrPixelConfig: |
899 case kBGRA_8888_GrPixelConfig: | 899 case kBGRA_8888_GrPixelConfig: |
900 case kSRGBA_8888_GrPixelConfig: | 900 case kSRGBA_8888_GrPixelConfig: |
| 901 case kSBGRA_8888_GrPixelConfig: |
901 case kRGBA_float_GrPixelConfig: | 902 case kRGBA_float_GrPixelConfig: |
902 return 4; | 903 return 4; |
903 default: | 904 default: |
904 return 0; | 905 return 0; |
905 } | 906 } |
906 } | 907 } |
907 | 908 |
908 static inline GrGLenum check_alloc_error(const GrSurfaceDesc& desc, | 909 static inline GrGLenum check_alloc_error(const GrSurfaceDesc& desc, |
909 const GrGLInterface* interface) { | 910 const GrGLInterface* interface) { |
910 if (SkToBool(desc.fFlags & kCheckAllocation_GrSurfaceFlag)) { | 911 if (SkToBool(desc.fFlags & kCheckAllocation_GrSurfaceFlag)) { |
(...skipping 1182 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2093 if (blendInfo.fWriteColor) { | 2094 if (blendInfo.fWriteColor) { |
2094 // Swizzle the blend to match what the shader will output. | 2095 // Swizzle the blend to match what the shader will output. |
2095 const GrSwizzle& swizzle = this->glCaps().glslCaps()->configOutputSwizzl
e( | 2096 const GrSwizzle& swizzle = this->glCaps().glslCaps()->configOutputSwizzl
e( |
2096 pipeline.getRenderTarget()->config()); | 2097 pipeline.getRenderTarget()->config()); |
2097 this->flushBlend(blendInfo, swizzle); | 2098 this->flushBlend(blendInfo, swizzle); |
2098 } | 2099 } |
2099 | 2100 |
2100 SkSTArray<8, const GrTextureAccess*> textureAccesses; | 2101 SkSTArray<8, const GrTextureAccess*> textureAccesses; |
2101 program->setData(primProc, pipeline, &textureAccesses); | 2102 program->setData(primProc, pipeline, &textureAccesses); |
2102 | 2103 |
| 2104 GrGLRenderTarget* glRT = static_cast<GrGLRenderTarget*>(pipeline.getRenderTa
rget()); |
| 2105 bool allowSRGB = GrAllowSRGBForDestinationPixelConfig(glRT->config()); |
| 2106 |
2103 int numTextureAccesses = textureAccesses.count(); | 2107 int numTextureAccesses = textureAccesses.count(); |
2104 for (int i = 0; i < numTextureAccesses; i++) { | 2108 for (int i = 0; i < numTextureAccesses; i++) { |
2105 this->bindTexture(i, textureAccesses[i]->getParams(), | 2109 this->bindTexture(i, textureAccesses[i]->getParams(), allowSRGB, |
2106 static_cast<GrGLTexture*>(textureAccesses[i]->getTextu
re())); | 2110 static_cast<GrGLTexture*>(textureAccesses[i]->getTextu
re())); |
2107 } | 2111 } |
2108 | 2112 |
2109 GrGLRenderTarget* glRT = static_cast<GrGLRenderTarget*>(pipeline.getRenderTa
rget()); | |
2110 this->flushStencil(pipeline.getStencil()); | 2113 this->flushStencil(pipeline.getStencil()); |
2111 this->flushScissor(pipeline.getScissorState(), glRT->getViewport(), glRT->or
igin()); | 2114 this->flushScissor(pipeline.getScissorState(), glRT->getViewport(), glRT->or
igin()); |
2112 this->flushHWAAState(glRT, pipeline.isHWAntialiasState(), !pipeline.getStenc
il().isDisabled()); | 2115 this->flushHWAAState(glRT, pipeline.isHWAntialiasState(), !pipeline.getStenc
il().isDisabled()); |
2113 | 2116 |
2114 // This must come after textures are flushed because a texture may need | 2117 // This must come after textures are flushed because a texture may need |
2115 // to be msaa-resolved (which will modify bound FBO state). | 2118 // to be msaa-resolved (which will modify bound FBO state). |
2116 this->flushRenderTarget(glRT, nullptr); | 2119 this->flushRenderTarget(glRT, nullptr); |
2117 | 2120 |
2118 return true; | 2121 return true; |
2119 } | 2122 } |
(...skipping 480 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2600 if (readConfig == kBGRA_8888_GrPixelConfig && | 2603 if (readConfig == kBGRA_8888_GrPixelConfig && |
2601 this->glCaps().isConfigRenderable(kRGBA_8888_GrPixelConfig, false) &
& | 2604 this->glCaps().isConfigRenderable(kRGBA_8888_GrPixelConfig, false) &
& |
2602 this->readPixelsSupported(kRGBA_8888_GrPixelConfig, kRGBA_8888_GrPix
elConfig)) { | 2605 this->readPixelsSupported(kRGBA_8888_GrPixelConfig, kRGBA_8888_GrPix
elConfig)) { |
2603 // We're trying to read BGRA but it's not supported. If RGBA is rend
erable and | 2606 // We're trying to read BGRA but it's not supported. If RGBA is rend
erable and |
2604 // we can read it back, then do a swizzling draw to a RGBA and read
it back (which | 2607 // we can read it back, then do a swizzling draw to a RGBA and read
it back (which |
2605 // will effectively be BGRA). | 2608 // will effectively be BGRA). |
2606 tempDrawInfo->fTempSurfaceDesc.fConfig = kRGBA_8888_GrPixelConfig; | 2609 tempDrawInfo->fTempSurfaceDesc.fConfig = kRGBA_8888_GrPixelConfig; |
2607 tempDrawInfo->fSwizzle = GrSwizzle::BGRA(); | 2610 tempDrawInfo->fSwizzle = GrSwizzle::BGRA(); |
2608 tempDrawInfo->fReadConfig = kRGBA_8888_GrPixelConfig; | 2611 tempDrawInfo->fReadConfig = kRGBA_8888_GrPixelConfig; |
2609 ElevateDrawPreference(drawPreference, kRequireDraw_DrawPreference); | 2612 ElevateDrawPreference(drawPreference, kRequireDraw_DrawPreference); |
| 2613 } else if (readConfig == kSBGRA_8888_GrPixelConfig && |
| 2614 this->glCaps().isConfigRenderable(kSRGBA_8888_GrPixelConfig, false)
&& |
| 2615 this->readPixelsSupported(kSRGBA_8888_GrPixelConfig, kSRGBA_8888_GrP
ixelConfig)) { |
| 2616 // We're trying to read sBGRA but it's not supported. If sRGBA is re
nderable and |
| 2617 // we can read it back, then do a swizzling draw to a sRGBA and read
it back (which |
| 2618 // will effectively be sBGRA). |
| 2619 tempDrawInfo->fTempSurfaceDesc.fConfig = kSRGBA_8888_GrPixelConfig; |
| 2620 tempDrawInfo->fSwizzle = GrSwizzle::BGRA(); |
| 2621 tempDrawInfo->fReadConfig = kSRGBA_8888_GrPixelConfig; |
| 2622 ElevateDrawPreference(drawPreference, kRequireDraw_DrawPreference); |
2610 } else if (readConfig == kAlpha_8_GrPixelConfig) { | 2623 } else if (readConfig == kAlpha_8_GrPixelConfig) { |
2611 // onReadPixels implements a fallback for cases where we are want to
read kAlpha_8, | 2624 // onReadPixels implements a fallback for cases where we are want to
read kAlpha_8, |
2612 // it's unsupported, but 32bit RGBA reads are supported. | 2625 // it's unsupported, but 32bit RGBA reads are supported. |
2613 // Don't attempt to do any srgb conversions since we only care about
alpha. | 2626 // Don't attempt to do any srgb conversions since we only care about
alpha. |
2614 GrPixelConfig cpuTempConfig = kRGBA_8888_GrPixelConfig; | 2627 GrPixelConfig cpuTempConfig = kRGBA_8888_GrPixelConfig; |
2615 if (GrPixelConfigIsSRGB(srcSurface->config())) { | 2628 if (GrPixelConfigIsSRGB(srcSurface->config())) { |
2616 cpuTempConfig = kSRGBA_8888_GrPixelConfig; | 2629 cpuTempConfig = kSRGBA_8888_GrPixelConfig; |
2617 } | 2630 } |
2618 if (!this->readPixelsSupported(srcSurface, cpuTempConfig)) { | 2631 if (!this->readPixelsSupported(srcSurface, cpuTempConfig)) { |
2619 // If we can't read RGBA from the src try to draw to a kRGBA_888
8 (or kSRGBA_8888) | 2632 // If we can't read RGBA from the src try to draw to a kRGBA_888
8 (or kSRGBA_8888) |
(...skipping 684 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3304 the generated shader code. This potentially allows greater reuse of cached sha
ders. */ | 3317 the generated shader code. This potentially allows greater reuse of cached sha
ders. */ |
3305 static void get_tex_param_swizzle(GrPixelConfig config, | 3318 static void get_tex_param_swizzle(GrPixelConfig config, |
3306 const GrGLCaps& caps, | 3319 const GrGLCaps& caps, |
3307 GrGLenum* glSwizzle) { | 3320 GrGLenum* glSwizzle) { |
3308 const GrSwizzle& swizzle = caps.configSwizzle(config); | 3321 const GrSwizzle& swizzle = caps.configSwizzle(config); |
3309 for (int i = 0; i < 4; ++i) { | 3322 for (int i = 0; i < 4; ++i) { |
3310 glSwizzle[i] = get_component_enum_from_char(swizzle.c_str()[i]); | 3323 glSwizzle[i] = get_component_enum_from_char(swizzle.c_str()[i]); |
3311 } | 3324 } |
3312 } | 3325 } |
3313 | 3326 |
3314 void GrGLGpu::bindTexture(int unitIdx, const GrTextureParams& params, GrGLTextur
e* texture) { | 3327 void GrGLGpu::bindTexture(int unitIdx, const GrTextureParams& params, bool dstCo
nfigAllowsSRGB, |
| 3328 GrGLTexture* texture) { |
3315 SkASSERT(texture); | 3329 SkASSERT(texture); |
3316 | 3330 |
3317 #ifdef SK_DEBUG | 3331 #ifdef SK_DEBUG |
3318 if (!this->caps()->npotTextureTileSupport()) { | 3332 if (!this->caps()->npotTextureTileSupport()) { |
3319 const bool tileX = SkShader::kClamp_TileMode != params.getTileModeX(); | 3333 const bool tileX = SkShader::kClamp_TileMode != params.getTileModeX(); |
3320 const bool tileY = SkShader::kClamp_TileMode != params.getTileModeY(); | 3334 const bool tileY = SkShader::kClamp_TileMode != params.getTileModeY(); |
3321 if (tileX || tileY) { | 3335 if (tileX || tileY) { |
3322 const int w = texture->width(); | 3336 const int w = texture->width(); |
3323 const int h = texture->height(); | 3337 const int h = texture->height(); |
3324 SkASSERT(SkIsPow2(w) && SkIsPow2(h)); | 3338 SkASSERT(SkIsPow2(w) && SkIsPow2(h)); |
(...skipping 15 matching lines...) Expand all Loading... |
3340 this->setTextureUnit(unitIdx); | 3354 this->setTextureUnit(unitIdx); |
3341 GL_CALL(BindTexture(target, texture->textureID())); | 3355 GL_CALL(BindTexture(target, texture->textureID())); |
3342 fHWBoundTextureUniqueIDs[unitIdx] = textureID; | 3356 fHWBoundTextureUniqueIDs[unitIdx] = textureID; |
3343 } | 3357 } |
3344 | 3358 |
3345 ResetTimestamp timestamp; | 3359 ResetTimestamp timestamp; |
3346 const GrGLTexture::TexParams& oldTexParams = texture->getCachedTexParams(&ti
mestamp); | 3360 const GrGLTexture::TexParams& oldTexParams = texture->getCachedTexParams(&ti
mestamp); |
3347 bool setAll = timestamp < this->getResetTimestamp(); | 3361 bool setAll = timestamp < this->getResetTimestamp(); |
3348 GrGLTexture::TexParams newTexParams; | 3362 GrGLTexture::TexParams newTexParams; |
3349 | 3363 |
| 3364 if (this->caps()->srgbSupport()) { |
| 3365 // By default, the decision to allow SRGB decode is based on the destina
tion config. |
| 3366 // A texture can override that by specifying a value in GrTextureParams. |
| 3367 newTexParams.fSRGBDecode = |
| 3368 (dstConfigAllowsSRGB || GrTextureParams::kForceAllowSRGB_SRGBMode ==
params.srgbMode()) |
| 3369 ? GR_GL_DECODE_EXT : GR_GL_SKIP_DECODE_EXT; |
| 3370 |
| 3371 if (setAll || newTexParams.fSRGBDecode != oldTexParams.fSRGBDecode) { |
| 3372 this->setTextureUnit(unitIdx); |
| 3373 GL_CALL(TexParameteri(target, GR_GL_TEXTURE_SRGB_DECODE_EXT, newTexP
arams.fSRGBDecode)); |
| 3374 } |
| 3375 } |
| 3376 |
3350 static GrGLenum glMinFilterModes[] = { | 3377 static GrGLenum glMinFilterModes[] = { |
3351 GR_GL_NEAREST, | 3378 GR_GL_NEAREST, |
3352 GR_GL_LINEAR, | 3379 GR_GL_LINEAR, |
3353 GR_GL_LINEAR_MIPMAP_LINEAR | 3380 GR_GL_LINEAR_MIPMAP_LINEAR |
3354 }; | 3381 }; |
3355 static GrGLenum glMagFilterModes[] = { | 3382 static GrGLenum glMagFilterModes[] = { |
3356 GR_GL_NEAREST, | 3383 GR_GL_NEAREST, |
3357 GR_GL_LINEAR, | 3384 GR_GL_LINEAR, |
3358 GR_GL_LINEAR | 3385 GR_GL_LINEAR |
3359 }; | 3386 }; |
(...skipping 647 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
4007 | 4034 |
4008 void GrGLGpu::copySurfaceAsDraw(GrSurface* dst, | 4035 void GrGLGpu::copySurfaceAsDraw(GrSurface* dst, |
4009 GrSurface* src, | 4036 GrSurface* src, |
4010 const SkIRect& srcRect, | 4037 const SkIRect& srcRect, |
4011 const SkIPoint& dstPoint) { | 4038 const SkIPoint& dstPoint) { |
4012 int w = srcRect.width(); | 4039 int w = srcRect.width(); |
4013 int h = srcRect.height(); | 4040 int h = srcRect.height(); |
4014 | 4041 |
4015 GrGLTexture* srcTex = static_cast<GrGLTexture*>(src->asTexture()); | 4042 GrGLTexture* srcTex = static_cast<GrGLTexture*>(src->asTexture()); |
4016 GrTextureParams params(SkShader::kClamp_TileMode, GrTextureParams::kNone_Fil
terMode); | 4043 GrTextureParams params(SkShader::kClamp_TileMode, GrTextureParams::kNone_Fil
terMode); |
4017 this->bindTexture(0, params, srcTex); | 4044 this->bindTexture(0, params, true, srcTex); |
4018 | 4045 |
4019 GrGLIRect dstVP; | 4046 GrGLIRect dstVP; |
4020 this->bindSurfaceFBOForCopy(dst, GR_GL_FRAMEBUFFER, &dstVP, kDst_TempFBOTarg
et); | 4047 this->bindSurfaceFBOForCopy(dst, GR_GL_FRAMEBUFFER, &dstVP, kDst_TempFBOTarg
et); |
4021 this->flushViewport(dstVP); | 4048 this->flushViewport(dstVP); |
4022 fHWBoundRenderTargetUniqueID = SK_InvalidUniqueID; | 4049 fHWBoundRenderTargetUniqueID = SK_InvalidUniqueID; |
4023 | 4050 |
4024 SkIRect dstRect = SkIRect::MakeXYWH(dstPoint.fX, dstPoint.fY, w, h); | 4051 SkIRect dstRect = SkIRect::MakeXYWH(dstPoint.fX, dstPoint.fY, w, h); |
4025 | 4052 |
4026 int progIdx = TextureTargetToCopyProgramIdx(srcTex->target()); | 4053 int progIdx = TextureTargetToCopyProgramIdx(srcTex->target()); |
4027 | 4054 |
(...skipping 362 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
4390 if (GR_GL_TEXTURE_EXTERNAL == glTexture->target() || | 4417 if (GR_GL_TEXTURE_EXTERNAL == glTexture->target() || |
4391 GR_GL_TEXTURE_RECTANGLE == glTexture->target()) { | 4418 GR_GL_TEXTURE_RECTANGLE == glTexture->target()) { |
4392 copyParams->fFilter = GrTextureParams::kNone_FilterMode; | 4419 copyParams->fFilter = GrTextureParams::kNone_FilterMode; |
4393 copyParams->fWidth = texture->width(); | 4420 copyParams->fWidth = texture->width(); |
4394 copyParams->fHeight = texture->height(); | 4421 copyParams->fHeight = texture->height(); |
4395 return true; | 4422 return true; |
4396 } | 4423 } |
4397 } | 4424 } |
4398 return false; | 4425 return false; |
4399 } | 4426 } |
OLD | NEW |