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 | 8 |
9 #include "GrGLGpu.h" | 9 #include "GrGLGpu.h" |
10 #include "GrGLGLSL.h" | 10 #include "GrGLGLSL.h" |
(...skipping 724 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
735 | 735 |
736 // in case we need a temporary, trimmed copy of the src pixels | 736 // in case we need a temporary, trimmed copy of the src pixels |
737 #if defined(GOOGLE3) | 737 #if defined(GOOGLE3) |
738 // Stack frame size is limited in GOOGLE3. | 738 // Stack frame size is limited in GOOGLE3. |
739 SkAutoSMalloc<64 * 128> tempStorage; | 739 SkAutoSMalloc<64 * 128> tempStorage; |
740 #else | 740 #else |
741 SkAutoSMalloc<128 * 128> tempStorage; | 741 SkAutoSMalloc<128 * 128> tempStorage; |
742 #endif | 742 #endif |
743 | 743 |
744 // Internal format comes from the texture desc. | 744 // Internal format comes from the texture desc. |
745 GrGLenum internalFormat = | 745 GrGLenum internalFormat; |
746 this->glCaps().configGLFormats(desc.fConfig).fInternalFormatTexImage; | |
747 | |
748 // External format and type come from the upload data. | 746 // External format and type come from the upload data. |
749 GrGLenum externalFormat = | 747 GrGLenum externalFormat; |
750 this->glCaps().configGLFormats(dataConfig).fExternalFormatForTexImage; | 748 GrGLenum externalType; |
751 GrGLenum externalType = this->glCaps().configGLFormats(dataConfig).fExternal
Type; | 749 if (!this->glCaps().getTexImageFormats(desc.fConfig, dataConfig, &internalFo
rmat, |
752 | 750 &externalFormat, &externalType)) { |
| 751 return false; |
| 752 } |
753 /* | 753 /* |
754 * Check whether to allocate a temporary buffer for flipping y or | 754 * Check whether to allocate a temporary buffer for flipping y or |
755 * because our srcData has extra bytes past each row. If so, we need | 755 * because our srcData has extra bytes past each row. If so, we need |
756 * to trim those off here, since GL ES may not let us specify | 756 * to trim those off here, since GL ES may not let us specify |
757 * GL_UNPACK_ROW_LENGTH. | 757 * GL_UNPACK_ROW_LENGTH. |
758 */ | 758 */ |
759 bool restoreGLRowLength = false; | 759 bool restoreGLRowLength = false; |
760 bool swFlipY = false; | 760 bool swFlipY = false; |
761 bool glFlipY = false; | 761 bool glFlipY = false; |
762 if (dataOrOffset) { | 762 if (dataOrOffset) { |
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
804 GL_CALL(PixelStorei(GR_GL_UNPACK_ALIGNMENT, config_alignment(dataConfig)
)); | 804 GL_CALL(PixelStorei(GR_GL_UNPACK_ALIGNMENT, config_alignment(dataConfig)
)); |
805 } | 805 } |
806 bool succeeded = true; | 806 bool succeeded = true; |
807 if (kNewTexture_UploadType == uploadType) { | 807 if (kNewTexture_UploadType == uploadType) { |
808 if (dataOrOffset && | 808 if (dataOrOffset && |
809 !(0 == left && 0 == top && desc.fWidth == width && desc.fHeight == h
eight)) { | 809 !(0 == left && 0 == top && desc.fWidth == width && desc.fHeight == h
eight)) { |
810 succeeded = false; | 810 succeeded = false; |
811 } else { | 811 } else { |
812 CLEAR_ERROR_BEFORE_ALLOC(this->glInterface()); | 812 CLEAR_ERROR_BEFORE_ALLOC(this->glInterface()); |
813 GL_ALLOC_CALL(this->glInterface(), TexImage2D(target, 0, internalFor
mat, desc.fWidth, | 813 GL_ALLOC_CALL(this->glInterface(), TexImage2D(target, 0, internalFor
mat, desc.fWidth, |
814 desc.fHeight, 0, exte
rnalFormat, | 814 desc.fHeight, 0, exter
nalFormat, |
815 externalType, dataOrOf
fset)); | 815 externalType, dataOrOf
fset)); |
816 GrGLenum error = check_alloc_error(desc, this->glInterface()); | 816 GrGLenum error = check_alloc_error(desc, this->glInterface()); |
817 if (error != GR_GL_NO_ERROR) { | 817 if (error != GR_GL_NO_ERROR) { |
818 succeeded = false; | 818 succeeded = false; |
819 } | 819 } |
820 } | 820 } |
821 } else { | 821 } else { |
822 if (swFlipY || glFlipY) { | 822 if (swFlipY || glFlipY) { |
823 top = desc.fHeight - (top + height); | 823 top = desc.fHeight - (top + height); |
824 } | 824 } |
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
871 #ifdef SK_DEBUG | 871 #ifdef SK_DEBUG |
872 else { | 872 else { |
873 SkASSERT(height <= desc.fHeight); | 873 SkASSERT(height <= desc.fHeight); |
874 } | 874 } |
875 #endif | 875 #endif |
876 | 876 |
877 // Make sure that the width and height that we pass to OpenGL | 877 // Make sure that the width and height that we pass to OpenGL |
878 // is a multiple of the block size. | 878 // is a multiple of the block size. |
879 size_t dataSize = GrCompressedFormatDataSize(desc.fConfig, width, height); | 879 size_t dataSize = GrCompressedFormatDataSize(desc.fConfig, width, height); |
880 | 880 |
881 // We only need the internal format for compressed 2D textures. There is on | 881 // We only need the internal format for compressed 2D textures. |
882 // sized vs base internal format distinction for compressed textures. | 882 GrGLenum internalFormat; |
883 GrGLenum internalFormat =this->glCaps().configGLFormats(desc.fConfig).fSized
InternalFormat; | 883 if (!this->glCaps().getCompressedTexImageFormats(desc.fConfig, &internalForm
at)) { |
| 884 return false; |
| 885 } |
884 | 886 |
885 if (kNewTexture_UploadType == uploadType) { | 887 if (kNewTexture_UploadType == uploadType) { |
886 CLEAR_ERROR_BEFORE_ALLOC(this->glInterface()); | 888 CLEAR_ERROR_BEFORE_ALLOC(this->glInterface()); |
887 GL_ALLOC_CALL(this->glInterface(), | 889 GL_ALLOC_CALL(this->glInterface(), |
888 CompressedTexImage2D(target, | 890 CompressedTexImage2D(target, |
889 0, // level | 891 0, // level |
890 internalFormat, | 892 internalFormat, |
891 width, height, | 893 width, height, |
892 0, // border | 894 0, // border |
893 SkToInt(dataSize), | 895 SkToInt(dataSize), |
(...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
981 // the texture bound to the other. The exception is the IMG multisample exte
nsion. With this | 983 // the texture bound to the other. The exception is the IMG multisample exte
nsion. With this |
982 // extension the texture is multisampled when rendered to and then auto-reso
lves it when it is | 984 // extension the texture is multisampled when rendered to and then auto-reso
lves it when it is |
983 // rendered from. | 985 // rendered from. |
984 if (desc.fSampleCnt > 0 && this->glCaps().usesMSAARenderBuffers()) { | 986 if (desc.fSampleCnt > 0 && this->glCaps().usesMSAARenderBuffers()) { |
985 GL_CALL(GenFramebuffers(1, &idDesc->fRTFBOID)); | 987 GL_CALL(GenFramebuffers(1, &idDesc->fRTFBOID)); |
986 GL_CALL(GenRenderbuffers(1, &idDesc->fMSColorRenderbufferID)); | 988 GL_CALL(GenRenderbuffers(1, &idDesc->fMSColorRenderbufferID)); |
987 if (!idDesc->fRTFBOID || | 989 if (!idDesc->fRTFBOID || |
988 !idDesc->fMSColorRenderbufferID) { | 990 !idDesc->fMSColorRenderbufferID) { |
989 goto FAILED; | 991 goto FAILED; |
990 } | 992 } |
991 // All ES versions (thus far) require sized internal formats for render
buffers. | 993 if (!this->glCaps().getRenderbufferFormat(desc.fConfig, &colorRenderbuff
erFormat)) { |
992 // TODO: Always use sized internal format? | 994 return false; |
993 // If this rule gets more complicated, add a field to ConfigEntry rather
than logic here. | 995 } |
994 colorRenderbufferFormat = kGLES_GrGLStandard == this->glStandard() ? | |
995 this->glCaps().configGLFormats(desc.fConfig).fSizedI
nternalFormat : | |
996 this->glCaps().configGLFormats(desc.fConfig).fBaseIn
ternalFormat; | |
997 } else { | 996 } else { |
998 idDesc->fRTFBOID = idDesc->fTexFBOID; | 997 idDesc->fRTFBOID = idDesc->fTexFBOID; |
999 } | 998 } |
1000 | 999 |
1001 // below here we may bind the FBO | 1000 // below here we may bind the FBO |
1002 fHWBoundRenderTargetUniqueID = SK_InvalidUniqueID; | 1001 fHWBoundRenderTargetUniqueID = SK_InvalidUniqueID; |
1003 if (idDesc->fRTFBOID != idDesc->fTexFBOID) { | 1002 if (idDesc->fRTFBOID != idDesc->fTexFBOID) { |
1004 SkASSERT(desc.fSampleCnt > 0); | 1003 SkASSERT(desc.fSampleCnt > 0); |
1005 GL_CALL(BindRenderbuffer(GR_GL_RENDERBUFFER, idDesc->fMSColorRenderbuffe
rID)); | 1004 GL_CALL(BindRenderbuffer(GR_GL_RENDERBUFFER, idDesc->fMSColorRenderbuffe
rID)); |
1006 if (!renderbuffer_storage_msaa(*fGLContext, | 1005 if (!renderbuffer_storage_msaa(*fGLContext, |
(...skipping 253 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1260 GL_CALL(TexParameteri(GR_GL_TEXTURE_2D, | 1259 GL_CALL(TexParameteri(GR_GL_TEXTURE_2D, |
1261 GR_GL_TEXTURE_MIN_FILTER, | 1260 GR_GL_TEXTURE_MIN_FILTER, |
1262 GR_GL_NEAREST)); | 1261 GR_GL_NEAREST)); |
1263 GL_CALL(TexParameteri(GR_GL_TEXTURE_2D, | 1262 GL_CALL(TexParameteri(GR_GL_TEXTURE_2D, |
1264 GR_GL_TEXTURE_WRAP_S, | 1263 GR_GL_TEXTURE_WRAP_S, |
1265 GR_GL_CLAMP_TO_EDGE)); | 1264 GR_GL_CLAMP_TO_EDGE)); |
1266 GL_CALL(TexParameteri(GR_GL_TEXTURE_2D, | 1265 GL_CALL(TexParameteri(GR_GL_TEXTURE_2D, |
1267 GR_GL_TEXTURE_WRAP_T, | 1266 GR_GL_TEXTURE_WRAP_T, |
1268 GR_GL_CLAMP_TO_EDGE)); | 1267 GR_GL_CLAMP_TO_EDGE)); |
1269 | 1268 |
1270 const GrGLCaps::ConfigFormats colorFormats = this->glCaps().configGLForm
ats(config); | 1269 GrGLenum internalFormat; |
1271 | 1270 GrGLenum externalFormat; |
| 1271 GrGLenum externalType; |
| 1272 if (!this->glCaps().getTexImageFormats(config, config, &internalFormat,
&externalFormat, |
| 1273 &externalType)) { |
| 1274 return false; |
| 1275 } |
1272 CLEAR_ERROR_BEFORE_ALLOC(this->glInterface()); | 1276 CLEAR_ERROR_BEFORE_ALLOC(this->glInterface()); |
1273 GL_ALLOC_CALL(this->glInterface(), TexImage2D(GR_GL_TEXTURE_2D, | 1277 GL_ALLOC_CALL(this->glInterface(), TexImage2D(GR_GL_TEXTURE_2D, |
1274 0, | 1278 0, |
1275 colorFormats.fInternalForm
atTexImage, | 1279 internalFormat, |
1276 kSize, | 1280 kSize, |
1277 kSize, | 1281 kSize, |
1278 0, | 1282 0, |
1279 colorFormats.fExternalForm
atForTexImage, | 1283 externalFormat, |
1280 colorFormats.fExternalType
, | 1284 externalType, |
1281 NULL)); | 1285 NULL)); |
1282 if (GR_GL_NO_ERROR != CHECK_ALLOC_ERROR(this->glInterface())) { | 1286 if (GR_GL_NO_ERROR != CHECK_ALLOC_ERROR(this->glInterface())) { |
1283 GL_CALL(DeleteTextures(1, &colorID)); | 1287 GL_CALL(DeleteTextures(1, &colorID)); |
1284 return -1; | 1288 return -1; |
1285 } | 1289 } |
1286 | 1290 |
1287 // unbind the texture from the texture unit before binding it to the fra
me buffer | 1291 // unbind the texture from the texture unit before binding it to the fra
me buffer |
1288 GL_CALL(BindTexture(GR_GL_TEXTURE_2D, 0)); | 1292 GL_CALL(BindTexture(GR_GL_TEXTURE_2D, 0)); |
1289 | 1293 |
1290 // Create Framebuffer | 1294 // Create Framebuffer |
(...skipping 268 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1559 return false; | 1563 return false; |
1560 } | 1564 } |
1561 | 1565 |
1562 GrGLuint programID = program->programID(); | 1566 GrGLuint programID = program->programID(); |
1563 if (fHWProgramID != programID) { | 1567 if (fHWProgramID != programID) { |
1564 GL_CALL(UseProgram(programID)); | 1568 GL_CALL(UseProgram(programID)); |
1565 fHWProgramID = programID; | 1569 fHWProgramID = programID; |
1566 } | 1570 } |
1567 | 1571 |
1568 if (blendInfo.fWriteColor) { | 1572 if (blendInfo.fWriteColor) { |
1569 this->flushBlend(blendInfo); | 1573 const GrSwizzle& swizzle = |
| 1574 this->glCaps().configSwizzle(args.fPipeline->getRenderTarget()->conf
ig()); |
| 1575 this->flushBlend(blendInfo, swizzle); |
1570 } | 1576 } |
1571 | 1577 |
1572 SkSTArray<8, const GrTextureAccess*> textureAccesses; | 1578 SkSTArray<8, const GrTextureAccess*> textureAccesses; |
1573 program->setData(*args.fPrimitiveProcessor, pipeline, &textureAccesses); | 1579 program->setData(*args.fPrimitiveProcessor, pipeline, &textureAccesses); |
1574 | 1580 |
1575 int numTextureAccesses = textureAccesses.count(); | 1581 int numTextureAccesses = textureAccesses.count(); |
1576 for (int i = 0; i < numTextureAccesses; i++) { | 1582 for (int i = 0; i < numTextureAccesses; i++) { |
1577 this->bindTexture(i, textureAccesses[i]->getParams(), | 1583 this->bindTexture(i, textureAccesses[i]->getParams(), |
1578 static_cast<GrGLTexture*>(textureAccesses[i]->getTextu
re())); | 1584 static_cast<GrGLTexture*>(textureAccesses[i]->getTextu
re())); |
1579 } | 1585 } |
(...skipping 429 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2009 GrGLRenderTarget* tgt = static_cast<GrGLRenderTarget*>(surface->asRenderTarg
et()); | 2015 GrGLRenderTarget* tgt = static_cast<GrGLRenderTarget*>(surface->asRenderTarg
et()); |
2010 if (!tgt) { | 2016 if (!tgt) { |
2011 return false; | 2017 return false; |
2012 } | 2018 } |
2013 | 2019 |
2014 // OpenGL doesn't do sRGB <-> linear conversions when reading and writing pi
xels. | 2020 // OpenGL doesn't do sRGB <-> linear conversions when reading and writing pi
xels. |
2015 if (GrPixelConfigIsSRGB(surface->config()) != GrPixelConfigIsSRGB(config)) { | 2021 if (GrPixelConfigIsSRGB(surface->config()) != GrPixelConfigIsSRGB(config)) { |
2016 return false; | 2022 return false; |
2017 } | 2023 } |
2018 | 2024 |
2019 GrGLenum format = this->glCaps().configGLFormats(config).fExternalFormat; | 2025 GrGLenum externalFormat; |
2020 GrGLenum type = this->glCaps().configGLFormats(config).fExternalType; | 2026 GrGLenum externalType; |
| 2027 if (!this->glCaps().getReadPixelsFormat(surface->config(), config, &external
Format, |
| 2028 &externalType)) { |
| 2029 return false; |
| 2030 } |
2021 bool flipY = kBottomLeft_GrSurfaceOrigin == surface->origin(); | 2031 bool flipY = kBottomLeft_GrSurfaceOrigin == surface->origin(); |
2022 | 2032 |
2023 // resolve the render target if necessary | 2033 // resolve the render target if necessary |
2024 switch (tgt->getResolveType()) { | 2034 switch (tgt->getResolveType()) { |
2025 case GrGLRenderTarget::kCantResolve_ResolveType: | 2035 case GrGLRenderTarget::kCantResolve_ResolveType: |
2026 return false; | 2036 return false; |
2027 case GrGLRenderTarget::kAutoResolves_ResolveType: | 2037 case GrGLRenderTarget::kAutoResolves_ResolveType: |
2028 this->flushRenderTarget(tgt, &SkIRect::EmptyIRect()); | 2038 this->flushRenderTarget(tgt, &SkIRect::EmptyIRect()); |
2029 break; | 2039 break; |
2030 case GrGLRenderTarget::kCanResolve_ResolveType: | 2040 case GrGLRenderTarget::kCanResolve_ResolveType: |
2031 this->onResolveRenderTarget(tgt); | 2041 this->onResolveRenderTarget(tgt); |
2032 // we don't track the state of the READ FBO ID. | 2042 // we don't track the state of the READ FBO ID. |
2033 fStats.incRenderTargetBinds(); | 2043 fStats.incRenderTargetBinds(); |
2034 GL_CALL(BindFramebuffer(GR_GL_READ_FRAMEBUFFER, | 2044 GL_CALL(BindFramebuffer(GR_GL_READ_FRAMEBUFFER, |
2035 tgt->textureFBOID())); | 2045 tgt->textureFBOID())); |
2036 break; | 2046 break; |
2037 default: | 2047 default: |
2038 SkFAIL("Unknown resolve type"); | 2048 SkFAIL("Unknown resolve type"); |
2039 } | 2049 } |
2040 | 2050 |
| 2051 // This must be called after the RT is bound as the FBO above. |
| 2052 if (!this->glCaps().readPixelsSupported(this->glInterface(), config, tgt->co
nfig())) { |
| 2053 if ((tgt->config() == kRGBA_8888_GrPixelConfig || |
| 2054 tgt->config() == kBGRA_8888_GrPixelConfig) && |
| 2055 kAlpha_8_GrPixelConfig == config) { |
| 2056 SkAutoTDeleteArray<uint32_t> temp(new uint32_t[width * height * 4]); |
| 2057 if (this->onReadPixels(surface, left, top, width, height, kRGBA_8888
_GrPixelConfig, |
| 2058 temp.get(), width*4)) { |
| 2059 uint8_t* dst = reinterpret_cast<uint8_t*>(buffer); |
| 2060 for (int j = 0; j < height; ++j) { |
| 2061 for (int i = 0; i < width; ++i) { |
| 2062 dst[j*rowBytes + i] = (0xFF000000U & temp[j*width+i]) >>
24; |
| 2063 } |
| 2064 } |
| 2065 return true; |
| 2066 } |
| 2067 } |
| 2068 return false; |
| 2069 } |
| 2070 |
2041 const GrGLIRect& glvp = tgt->getViewport(); | 2071 const GrGLIRect& glvp = tgt->getViewport(); |
2042 | 2072 |
2043 // the read rect is viewport-relative | 2073 // the read rect is viewport-relative |
2044 GrGLIRect readRect; | 2074 GrGLIRect readRect; |
2045 readRect.setRelativeTo(glvp, left, top, width, height, tgt->origin()); | 2075 readRect.setRelativeTo(glvp, left, top, width, height, tgt->origin()); |
2046 | 2076 |
2047 size_t tightRowBytes = GrBytesPerPixel(config) * width; | 2077 size_t tightRowBytes = GrBytesPerPixel(config) * width; |
2048 | 2078 |
2049 size_t readDstRowBytes = tightRowBytes; | 2079 size_t readDstRowBytes = tightRowBytes; |
2050 void* readDst = buffer; | 2080 void* readDst = buffer; |
(...skipping 12 matching lines...) Expand all Loading... |
2063 readDst = scratch.get(); | 2093 readDst = scratch.get(); |
2064 } | 2094 } |
2065 } | 2095 } |
2066 if (flipY && this->glCaps().packFlipYSupport()) { | 2096 if (flipY && this->glCaps().packFlipYSupport()) { |
2067 GL_CALL(PixelStorei(GR_GL_PACK_REVERSE_ROW_ORDER, 1)); | 2097 GL_CALL(PixelStorei(GR_GL_PACK_REVERSE_ROW_ORDER, 1)); |
2068 } | 2098 } |
2069 GL_CALL(PixelStorei(GR_GL_PACK_ALIGNMENT, config_alignment(config))); | 2099 GL_CALL(PixelStorei(GR_GL_PACK_ALIGNMENT, config_alignment(config))); |
2070 | 2100 |
2071 GL_CALL(ReadPixels(readRect.fLeft, readRect.fBottom, | 2101 GL_CALL(ReadPixels(readRect.fLeft, readRect.fBottom, |
2072 readRect.fWidth, readRect.fHeight, | 2102 readRect.fWidth, readRect.fHeight, |
2073 format, type, readDst)); | 2103 externalFormat, externalType, readDst)); |
2074 if (readDstRowBytes != tightRowBytes) { | 2104 if (readDstRowBytes != tightRowBytes) { |
2075 SkASSERT(this->glCaps().packRowLengthSupport()); | 2105 SkASSERT(this->glCaps().packRowLengthSupport()); |
2076 GL_CALL(PixelStorei(GR_GL_PACK_ROW_LENGTH, 0)); | 2106 GL_CALL(PixelStorei(GR_GL_PACK_ROW_LENGTH, 0)); |
2077 } | 2107 } |
2078 if (flipY && this->glCaps().packFlipYSupport()) { | 2108 if (flipY && this->glCaps().packFlipYSupport()) { |
2079 GL_CALL(PixelStorei(GR_GL_PACK_REVERSE_ROW_ORDER, 0)); | 2109 GL_CALL(PixelStorei(GR_GL_PACK_REVERSE_ROW_ORDER, 0)); |
2080 flipY = false; | 2110 flipY = false; |
2081 } | 2111 } |
2082 | 2112 |
2083 // now reverse the order of the rows, since GL's are bottom-to-top, but our | 2113 // now reverse the order of the rows, since GL's are bottom-to-top, but our |
(...skipping 296 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2380 } | 2410 } |
2381 } else { | 2411 } else { |
2382 if (kNo_TriState != fMSAAEnabled) { | 2412 if (kNo_TriState != fMSAAEnabled) { |
2383 GL_CALL(Disable(GR_GL_MULTISAMPLE)); | 2413 GL_CALL(Disable(GR_GL_MULTISAMPLE)); |
2384 fMSAAEnabled = kNo_TriState; | 2414 fMSAAEnabled = kNo_TriState; |
2385 } | 2415 } |
2386 } | 2416 } |
2387 } | 2417 } |
2388 } | 2418 } |
2389 | 2419 |
2390 void GrGLGpu::flushBlend(const GrXferProcessor::BlendInfo& blendInfo) { | 2420 void GrGLGpu::flushBlend(const GrXferProcessor::BlendInfo& blendInfo, const GrSw
izzle& swizzle) { |
2391 // Any optimization to disable blending should have already been applied and | 2421 // Any optimization to disable blending should have already been applied and |
2392 // tweaked the equation to "add" or "subtract", and the coeffs to (1, 0). | 2422 // tweaked the equation to "add" or "subtract", and the coeffs to (1, 0). |
2393 | 2423 |
2394 GrBlendEquation equation = blendInfo.fEquation; | 2424 GrBlendEquation equation = blendInfo.fEquation; |
2395 GrBlendCoeff srcCoeff = blendInfo.fSrcBlend; | 2425 GrBlendCoeff srcCoeff = blendInfo.fSrcBlend; |
2396 GrBlendCoeff dstCoeff = blendInfo.fDstBlend; | 2426 GrBlendCoeff dstCoeff = blendInfo.fDstBlend; |
2397 bool blendOff = (kAdd_GrBlendEquation == equation || kSubtract_GrBlendEquati
on == equation) && | 2427 bool blendOff = (kAdd_GrBlendEquation == equation || kSubtract_GrBlendEquati
on == equation) && |
2398 kOne_GrBlendCoeff == srcCoeff && kZero_GrBlendCoeff == dstCo
eff; | 2428 kOne_GrBlendCoeff == srcCoeff && kZero_GrBlendCoeff == dstCo
eff; |
2399 if (blendOff) { | 2429 if (blendOff) { |
2400 if (kNo_TriState != fHWBlendState.fEnabled) { | 2430 if (kNo_TriState != fHWBlendState.fEnabled) { |
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2433 } | 2463 } |
2434 | 2464 |
2435 if (fHWBlendState.fSrcCoeff != srcCoeff || | 2465 if (fHWBlendState.fSrcCoeff != srcCoeff || |
2436 fHWBlendState.fDstCoeff != dstCoeff) { | 2466 fHWBlendState.fDstCoeff != dstCoeff) { |
2437 GL_CALL(BlendFunc(gXfermodeCoeff2Blend[srcCoeff], | 2467 GL_CALL(BlendFunc(gXfermodeCoeff2Blend[srcCoeff], |
2438 gXfermodeCoeff2Blend[dstCoeff])); | 2468 gXfermodeCoeff2Blend[dstCoeff])); |
2439 fHWBlendState.fSrcCoeff = srcCoeff; | 2469 fHWBlendState.fSrcCoeff = srcCoeff; |
2440 fHWBlendState.fDstCoeff = dstCoeff; | 2470 fHWBlendState.fDstCoeff = dstCoeff; |
2441 } | 2471 } |
2442 | 2472 |
2443 GrColor blendConst = blendInfo.fBlendConstant; | 2473 if ((BlendCoeffReferencesConstant(srcCoeff) || BlendCoeffReferencesConstant(
dstCoeff))) { |
2444 if ((BlendCoeffReferencesConstant(srcCoeff) || | 2474 GrColor blendConst = blendInfo.fBlendConstant; |
2445 BlendCoeffReferencesConstant(dstCoeff)) && | 2475 swizzle.applyTo(blendConst); |
2446 (!fHWBlendState.fConstColorValid || | 2476 if (!fHWBlendState.fConstColorValid || fHWBlendState.fConstColor != blen
dConst) { |
2447 fHWBlendState.fConstColor != blendConst)) { | 2477 GrGLfloat c[4]; |
2448 GrGLfloat c[4]; | 2478 GrColorToRGBAFloat(blendConst, c); |
2449 GrColorToRGBAFloat(blendConst, c); | 2479 GL_CALL(BlendColor(c[0], c[1], c[2], c[3])); |
2450 GL_CALL(BlendColor(c[0], c[1], c[2], c[3])); | 2480 fHWBlendState.fConstColor = blendConst; |
2451 fHWBlendState.fConstColor = blendConst; | 2481 fHWBlendState.fConstColorValid = true; |
2452 fHWBlendState.fConstColorValid = true; | 2482 } |
2453 } | 2483 } |
2454 } | 2484 } |
2455 | 2485 |
2456 static inline GrGLenum tile_to_gl_wrap(SkShader::TileMode tm) { | 2486 static inline GrGLenum tile_to_gl_wrap(SkShader::TileMode tm) { |
2457 static const GrGLenum gWrapModes[] = { | 2487 static const GrGLenum gWrapModes[] = { |
2458 GR_GL_CLAMP_TO_EDGE, | 2488 GR_GL_CLAMP_TO_EDGE, |
2459 GR_GL_REPEAT, | 2489 GR_GL_REPEAT, |
2460 GR_GL_MIRRORED_REPEAT | 2490 GR_GL_MIRRORED_REPEAT |
2461 }; | 2491 }; |
2462 GR_STATIC_ASSERT(SkShader::kTileModeCount == SK_ARRAY_COUNT(gWrapModes)); | 2492 GR_STATIC_ASSERT(SkShader::kTileModeCount == SK_ARRAY_COUNT(gWrapModes)); |
(...skipping 637 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3100 GrGLAttribArrayState* attribs = | 3130 GrGLAttribArrayState* attribs = |
3101 fHWGeometryState.bindArrayAndBufferToDraw(this, fWireRectArrayBuffer); | 3131 fHWGeometryState.bindArrayAndBufferToDraw(this, fWireRectArrayBuffer); |
3102 attribs->set(this, 0, fWireRectArrayBuffer, 2, GR_GL_FLOAT, false, 2 * sizeo
f(GrGLfloat), 0); | 3132 attribs->set(this, 0, fWireRectArrayBuffer, 2, GR_GL_FLOAT, false, 2 * sizeo
f(GrGLfloat), 0); |
3103 attribs->disableUnusedArrays(this, 0x1); | 3133 attribs->disableUnusedArrays(this, 0x1); |
3104 | 3134 |
3105 GL_CALL(Uniform4fv(fWireRectProgram.fRectUniform, 1, edges)); | 3135 GL_CALL(Uniform4fv(fWireRectProgram.fRectUniform, 1, edges)); |
3106 GL_CALL(Uniform4fv(fWireRectProgram.fColorUniform, 1, channels)); | 3136 GL_CALL(Uniform4fv(fWireRectProgram.fColorUniform, 1, channels)); |
3107 | 3137 |
3108 GrXferProcessor::BlendInfo blendInfo; | 3138 GrXferProcessor::BlendInfo blendInfo; |
3109 blendInfo.reset(); | 3139 blendInfo.reset(); |
3110 this->flushBlend(blendInfo); | 3140 this->flushBlend(blendInfo, GrSwizzle::RGBA()); |
3111 this->flushColorWrite(true); | 3141 this->flushColorWrite(true); |
3112 this->flushDrawFace(GrPipelineBuilder::kBoth_DrawFace); | 3142 this->flushDrawFace(GrPipelineBuilder::kBoth_DrawFace); |
3113 this->flushHWAAState(glRT, false); | 3143 this->flushHWAAState(glRT, false); |
3114 this->disableScissor(); | 3144 this->disableScissor(); |
3115 GrStencilSettings stencil; | 3145 GrStencilSettings stencil; |
3116 stencil.setDisabled(); | 3146 stencil.setDisabled(); |
3117 this->flushStencil(stencil); | 3147 this->flushStencil(stencil); |
3118 | 3148 |
3119 GL_CALL(DrawArrays(GR_GL_LINE_LOOP, 0, 4)); | 3149 GL_CALL(DrawArrays(GR_GL_LINE_LOOP, 0, 4)); |
3120 } | 3150 } |
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3171 sy1 = 1.f - sy1; | 3201 sy1 = 1.f - sy1; |
3172 } | 3202 } |
3173 | 3203 |
3174 GL_CALL(Uniform4f(fCopyPrograms[progIdx].fPosXformUniform, dx1 - dx0, dy1 -
dy0, dx0, dy0)); | 3204 GL_CALL(Uniform4f(fCopyPrograms[progIdx].fPosXformUniform, dx1 - dx0, dy1 -
dy0, dx0, dy0)); |
3175 GL_CALL(Uniform4f(fCopyPrograms[progIdx].fTexCoordXformUniform, | 3205 GL_CALL(Uniform4f(fCopyPrograms[progIdx].fTexCoordXformUniform, |
3176 sx1 - sx0, sy1 - sy0, sx0, sy0)); | 3206 sx1 - sx0, sy1 - sy0, sx0, sy0)); |
3177 GL_CALL(Uniform1i(fCopyPrograms[progIdx].fTextureUniform, 0)); | 3207 GL_CALL(Uniform1i(fCopyPrograms[progIdx].fTextureUniform, 0)); |
3178 | 3208 |
3179 GrXferProcessor::BlendInfo blendInfo; | 3209 GrXferProcessor::BlendInfo blendInfo; |
3180 blendInfo.reset(); | 3210 blendInfo.reset(); |
3181 this->flushBlend(blendInfo); | 3211 this->flushBlend(blendInfo, GrSwizzle::RGBA()); |
3182 this->flushColorWrite(true); | 3212 this->flushColorWrite(true); |
3183 this->flushDrawFace(GrPipelineBuilder::kBoth_DrawFace); | 3213 this->flushDrawFace(GrPipelineBuilder::kBoth_DrawFace); |
3184 this->flushHWAAState(dstRT, false); | 3214 this->flushHWAAState(dstRT, false); |
3185 this->disableScissor(); | 3215 this->disableScissor(); |
3186 GrStencilSettings stencil; | 3216 GrStencilSettings stencil; |
3187 stencil.setDisabled(); | 3217 stencil.setDisabled(); |
3188 this->flushStencil(stencil); | 3218 this->flushStencil(stencil); |
3189 | 3219 |
3190 GL_CALL(DrawArrays(GR_GL_TRIANGLE_STRIP, 0, 4)); | 3220 GL_CALL(DrawArrays(GR_GL_TRIANGLE_STRIP, 0, 4)); |
3191 } | 3221 } |
(...skipping 127 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3319 info->fID = 0; | 3349 info->fID = 0; |
3320 GL_CALL(GenTextures(1, &info->fID)); | 3350 GL_CALL(GenTextures(1, &info->fID)); |
3321 GL_CALL(ActiveTexture(GR_GL_TEXTURE0)); | 3351 GL_CALL(ActiveTexture(GR_GL_TEXTURE0)); |
3322 GL_CALL(PixelStorei(GR_GL_UNPACK_ALIGNMENT, 1)); | 3352 GL_CALL(PixelStorei(GR_GL_UNPACK_ALIGNMENT, 1)); |
3323 GL_CALL(BindTexture(info->fTarget, info->fID)); | 3353 GL_CALL(BindTexture(info->fTarget, info->fID)); |
3324 GL_CALL(TexParameteri(info->fTarget, GR_GL_TEXTURE_MAG_FILTER, GR_GL_NEAREST
)); | 3354 GL_CALL(TexParameteri(info->fTarget, GR_GL_TEXTURE_MAG_FILTER, GR_GL_NEAREST
)); |
3325 GL_CALL(TexParameteri(info->fTarget, GR_GL_TEXTURE_MIN_FILTER, GR_GL_NEAREST
)); | 3355 GL_CALL(TexParameteri(info->fTarget, GR_GL_TEXTURE_MIN_FILTER, GR_GL_NEAREST
)); |
3326 GL_CALL(TexParameteri(info->fTarget, GR_GL_TEXTURE_WRAP_S, GR_GL_CLAMP_TO_ED
GE)); | 3356 GL_CALL(TexParameteri(info->fTarget, GR_GL_TEXTURE_WRAP_S, GR_GL_CLAMP_TO_ED
GE)); |
3327 GL_CALL(TexParameteri(info->fTarget, GR_GL_TEXTURE_WRAP_T, GR_GL_CLAMP_TO_ED
GE)); | 3357 GL_CALL(TexParameteri(info->fTarget, GR_GL_TEXTURE_WRAP_T, GR_GL_CLAMP_TO_ED
GE)); |
3328 | 3358 |
3329 GrGLenum internalFormat = this->glCaps().configGLFormats(config).fInternalFo
rmatTexImage; | 3359 GrGLenum internalFormat; |
3330 GrGLenum externalFormat = this->glCaps().configGLFormats(config).fExternalFo
rmatForTexImage; | 3360 GrGLenum externalFormat; |
3331 GrGLenum externalType = this->glCaps().configGLFormats(config).fExternalType
; | 3361 GrGLenum externalType; |
| 3362 |
| 3363 if (!this->glCaps().getTexImageFormats(config, config, &internalFormat, &ext
ernalFormat, |
| 3364 &externalType)) { |
| 3365 delete info; |
| 3366 #ifdef SK_IGNORE_GL_TEXTURE_TARGET |
| 3367 return 0; |
| 3368 #else |
| 3369 return reinterpret_cast<GrBackendObject>(nullptr); |
| 3370 #endif |
| 3371 } |
3332 | 3372 |
3333 GL_CALL(TexImage2D(info->fTarget, 0, internalFormat, w, h, 0, externalFormat
, | 3373 GL_CALL(TexImage2D(info->fTarget, 0, internalFormat, w, h, 0, externalFormat
, |
3334 externalType, pixels)); | 3374 externalType, pixels)); |
3335 | 3375 |
3336 #ifdef SK_IGNORE_GL_TEXTURE_TARGET | 3376 #ifdef SK_IGNORE_GL_TEXTURE_TARGET |
3337 GrGLuint id = info->fID; | 3377 GrGLuint id = info->fID; |
3338 delete info; | 3378 delete info; |
3339 return id; | 3379 return id; |
3340 #else | 3380 #else |
3341 return reinterpret_cast<GrBackendObject>(info); | 3381 return reinterpret_cast<GrBackendObject>(info); |
(...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3427 this->setVertexArrayID(gpu, 0); | 3467 this->setVertexArrayID(gpu, 0); |
3428 } | 3468 } |
3429 int attrCount = gpu->glCaps().maxVertexAttributes(); | 3469 int attrCount = gpu->glCaps().maxVertexAttributes(); |
3430 if (fDefaultVertexArrayAttribState.count() != attrCount) { | 3470 if (fDefaultVertexArrayAttribState.count() != attrCount) { |
3431 fDefaultVertexArrayAttribState.resize(attrCount); | 3471 fDefaultVertexArrayAttribState.resize(attrCount); |
3432 } | 3472 } |
3433 attribState = &fDefaultVertexArrayAttribState; | 3473 attribState = &fDefaultVertexArrayAttribState; |
3434 } | 3474 } |
3435 return attribState; | 3475 return attribState; |
3436 } | 3476 } |
OLD | NEW |