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