GrTextureDomain.cpp revision e0e7cfe44bb9d66d76120a79e5275c294bacaa22
12f68e7684bb2ecdf0c03a513c31d0626d2caf752tomhudson@google.com/* 22f68e7684bb2ecdf0c03a513c31d0626d2caf752tomhudson@google.com * Copyright 2012 Google Inc. 32f68e7684bb2ecdf0c03a513c31d0626d2caf752tomhudson@google.com * 42f68e7684bb2ecdf0c03a513c31d0626d2caf752tomhudson@google.com * Use of this source code is governed by a BSD-style license that can be 52f68e7684bb2ecdf0c03a513c31d0626d2caf752tomhudson@google.com * found in the LICENSE file. 62f68e7684bb2ecdf0c03a513c31d0626d2caf752tomhudson@google.com */ 72f68e7684bb2ecdf0c03a513c31d0626d2caf752tomhudson@google.com 82f68e7684bb2ecdf0c03a513c31d0626d2caf752tomhudson@google.com#include "GrTextureDomainEffect.h" 968b58c95384dd6c2fd389a5b4bbf8fc468819454bsalomon@google.com#include "GrSimpleTextureEffect.h" 102eaaefd7e6a58339b3f93333f1e9cc92252cc303bsalomon@google.com#include "GrTBackendEffectFactory.h" 11d698f77c13d97c61109b861eac4d25b14a5de935bsalomon@google.com#include "gl/GrGLEffect.h" 1292b6a94ac103ea3f37a8f9f02072ef884cc17a7cbsalomon@google.com#include "gl/GrGLEffectMatrix.h" 1392b6a94ac103ea3f37a8f9f02072ef884cc17a7cbsalomon@google.com#include "SkFloatingPoint.h" 142f68e7684bb2ecdf0c03a513c31d0626d2caf752tomhudson@google.com 1522a800a2578564a8b66bd4d9903ef4186c37f35cbsalomon@google.comclass GrGLTextureDomainEffect : public GrGLEffect { 162f68e7684bb2ecdf0c03a513c31d0626d2caf752tomhudson@google.compublic: 17c78188896e28a4ae49e406a7422b345ae177dafebsalomon@google.com GrGLTextureDomainEffect(const GrBackendEffectFactory&, const GrDrawEffect&); 182f68e7684bb2ecdf0c03a513c31d0626d2caf752tomhudson@google.com 1922a800a2578564a8b66bd4d9903ef4186c37f35cbsalomon@google.com virtual void emitCode(GrGLShaderBuilder*, 20c78188896e28a4ae49e406a7422b345ae177dafebsalomon@google.com const GrDrawEffect&, 2122a800a2578564a8b66bd4d9903ef4186c37f35cbsalomon@google.com EffectKey, 2222a800a2578564a8b66bd4d9903ef4186c37f35cbsalomon@google.com const char* outputColor, 2322a800a2578564a8b66bd4d9903ef4186c37f35cbsalomon@google.com const char* inputColor, 2422a800a2578564a8b66bd4d9903ef4186c37f35cbsalomon@google.com const TextureSamplerArray&) SK_OVERRIDE; 252f68e7684bb2ecdf0c03a513c31d0626d2caf752tomhudson@google.com 26c78188896e28a4ae49e406a7422b345ae177dafebsalomon@google.com virtual void setData(const GrGLUniformManager&, const GrDrawEffect&) SK_OVERRIDE; 272f68e7684bb2ecdf0c03a513c31d0626d2caf752tomhudson@google.com 28c78188896e28a4ae49e406a7422b345ae177dafebsalomon@google.com static inline EffectKey GenKey(const GrDrawEffect&, const GrGLCaps&); 292f68e7684bb2ecdf0c03a513c31d0626d2caf752tomhudson@google.com 302f68e7684bb2ecdf0c03a513c31d0626d2caf752tomhudson@google.comprivate: 31dbbc4e2da93cef5c0cfb0b3c92ff6c2c80f6e67absalomon@google.com GrGLUniformManager::UniformHandle fNameUni; 3292b6a94ac103ea3f37a8f9f02072ef884cc17a7cbsalomon@google.com GrGLEffectMatrix fEffectMatrix; 3392b6a94ac103ea3f37a8f9f02072ef884cc17a7cbsalomon@google.com GrGLfloat fPrevDomain[4]; 342f68e7684bb2ecdf0c03a513c31d0626d2caf752tomhudson@google.com 3522a800a2578564a8b66bd4d9903ef4186c37f35cbsalomon@google.com typedef GrGLEffect INHERITED; 362f68e7684bb2ecdf0c03a513c31d0626d2caf752tomhudson@google.com}; 372f68e7684bb2ecdf0c03a513c31d0626d2caf752tomhudson@google.com 38396e61fe440590744345e0c56970b26ab464591dbsalomon@google.comGrGLTextureDomainEffect::GrGLTextureDomainEffect(const GrBackendEffectFactory& factory, 39c78188896e28a4ae49e406a7422b345ae177dafebsalomon@google.com const GrDrawEffect& drawEffect) 40374e75956e7a56bbbd2da5509f9c4117512515d2bsalomon@google.com : INHERITED(factory) 41c78188896e28a4ae49e406a7422b345ae177dafebsalomon@google.com , fEffectMatrix(drawEffect.castEffect<GrTextureDomainEffect>().coordsType()) { 4292b6a94ac103ea3f37a8f9f02072ef884cc17a7cbsalomon@google.com fPrevDomain[0] = SK_FloatNaN; 432f68e7684bb2ecdf0c03a513c31d0626d2caf752tomhudson@google.com} 442f68e7684bb2ecdf0c03a513c31d0626d2caf752tomhudson@google.com 4522a800a2578564a8b66bd4d9903ef4186c37f35cbsalomon@google.comvoid GrGLTextureDomainEffect::emitCode(GrGLShaderBuilder* builder, 46c78188896e28a4ae49e406a7422b345ae177dafebsalomon@google.com const GrDrawEffect& drawEffect, 4792b6a94ac103ea3f37a8f9f02072ef884cc17a7cbsalomon@google.com EffectKey key, 4822a800a2578564a8b66bd4d9903ef4186c37f35cbsalomon@google.com const char* outputColor, 4922a800a2578564a8b66bd4d9903ef4186c37f35cbsalomon@google.com const char* inputColor, 5022a800a2578564a8b66bd4d9903ef4186c37f35cbsalomon@google.com const TextureSamplerArray& samplers) { 51c78188896e28a4ae49e406a7422b345ae177dafebsalomon@google.com const GrTextureDomainEffect& texDom = drawEffect.castEffect<GrTextureDomainEffect>(); 527b7cdd147f5528865238e5ed98c79e6d319fde9bbsalomon@google.com 537ab7ca4199e97126de01d507d34f60a07843937fcommit-bot@chromium.org SkString coords; 54c78188896e28a4ae49e406a7422b345ae177dafebsalomon@google.com fEffectMatrix.emitCodeMakeFSCoords2D(builder, key, &coords); 557b7cdd147f5528865238e5ed98c79e6d319fde9bbsalomon@google.com const char* domain; 5674a3a2135ca82ab9324b7e499caa3280348a4fdacommit-bot@chromium.org fNameUni = builder->addUniform(GrGLShaderBuilder::kFragment_Visibility, 577b7cdd147f5528865238e5ed98c79e6d319fde9bbsalomon@google.com kVec4f_GrSLType, "TexDom", &domain); 58c78188896e28a4ae49e406a7422b345ae177dafebsalomon@google.com if (GrTextureDomainEffect::kClamp_WrapMode == texDom.wrapMode()) { 597b7cdd147f5528865238e5ed98c79e6d319fde9bbsalomon@google.com 60f910d3b23bcf590ee937628dbab8e39a98ee5860bsalomon@google.com builder->fsCodeAppendf("\tvec2 clampCoord = clamp(%s, %s.xy, %s.zw);\n", 617ab7ca4199e97126de01d507d34f60a07843937fcommit-bot@chromium.org coords.c_str(), domain, domain); 627b7cdd147f5528865238e5ed98c79e6d319fde9bbsalomon@google.com 63f910d3b23bcf590ee937628dbab8e39a98ee5860bsalomon@google.com builder->fsCodeAppendf("\t%s = ", outputColor); 6474a3a2135ca82ab9324b7e499caa3280348a4fdacommit-bot@chromium.org builder->fsAppendTextureLookupAndModulate(inputColor, samplers[0], "clampCoord"); 65f910d3b23bcf590ee937628dbab8e39a98ee5860bsalomon@google.com builder->fsCodeAppend(";\n"); 667b7cdd147f5528865238e5ed98c79e6d319fde9bbsalomon@google.com } else { 67f6de475e5cbd143f348ff7738919e397b7fe7f57tfarina@chromium.org SkASSERT(GrTextureDomainEffect::kDecal_WrapMode == texDom.wrapMode()); 6813f181f28f4336adcc93b7297b6d16503f4c323crobertphillips@google.com 6913f181f28f4336adcc93b7297b6d16503f4c323crobertphillips@google.com if (kImagination_GrGLVendor == builder->ctxInfo().vendor()) { 700c23faf222c24529781139495a5f4f4ab61f7cb2skia.committer@gmail.com // On the NexusS and GalaxyNexus, the other path (with the 'any' 710c23faf222c24529781139495a5f4f4ab61f7cb2skia.committer@gmail.com // call) causes the compilation error "Calls to any function that 720c23faf222c24529781139495a5f4f4ab61f7cb2skia.committer@gmail.com // may require a gradient calculation inside a conditional block 7313f181f28f4336adcc93b7297b6d16503f4c323crobertphillips@google.com // may return undefined results". This appears to be an issue with 7413f181f28f4336adcc93b7297b6d16503f4c323crobertphillips@google.com // the 'any' call since even the simple "result=black; if (any()) 7513f181f28f4336adcc93b7297b6d16503f4c323crobertphillips@google.com // result=white;" code fails to compile. 76f910d3b23bcf590ee937628dbab8e39a98ee5860bsalomon@google.com builder->fsCodeAppend("\tvec4 outside = vec4(0.0, 0.0, 0.0, 0.0);\n"); 77f910d3b23bcf590ee937628dbab8e39a98ee5860bsalomon@google.com builder->fsCodeAppend("\tvec4 inside = "); 7874a3a2135ca82ab9324b7e499caa3280348a4fdacommit-bot@chromium.org builder->fsAppendTextureLookupAndModulate(inputColor, samplers[0], coords.c_str()); 79f910d3b23bcf590ee937628dbab8e39a98ee5860bsalomon@google.com builder->fsCodeAppend(";\n"); 80f910d3b23bcf590ee937628dbab8e39a98ee5860bsalomon@google.com 81f910d3b23bcf590ee937628dbab8e39a98ee5860bsalomon@google.com builder->fsCodeAppendf("\tfloat x = abs(2.0*(%s.x - %s.x)/(%s.z - %s.x) - 1.0);\n", 827ab7ca4199e97126de01d507d34f60a07843937fcommit-bot@chromium.org coords.c_str(), domain, domain, domain); 83f910d3b23bcf590ee937628dbab8e39a98ee5860bsalomon@google.com builder->fsCodeAppendf("\tfloat y = abs(2.0*(%s.y - %s.y)/(%s.w - %s.y) - 1.0);\n", 847ab7ca4199e97126de01d507d34f60a07843937fcommit-bot@chromium.org coords.c_str(), domain, domain, domain); 85f910d3b23bcf590ee937628dbab8e39a98ee5860bsalomon@google.com builder->fsCodeAppend("\tfloat blend = step(1.0, max(x, y));\n"); 86f910d3b23bcf590ee937628dbab8e39a98ee5860bsalomon@google.com builder->fsCodeAppendf("\t%s = mix(inside, outside, blend);\n", outputColor); 8713f181f28f4336adcc93b7297b6d16503f4c323crobertphillips@google.com } else { 88f910d3b23bcf590ee937628dbab8e39a98ee5860bsalomon@google.com builder->fsCodeAppend("\tbvec4 outside;\n"); 897ab7ca4199e97126de01d507d34f60a07843937fcommit-bot@chromium.org builder->fsCodeAppendf("\toutside.xy = lessThan(%s, %s.xy);\n", coords.c_str(), domain); 907ab7ca4199e97126de01d507d34f60a07843937fcommit-bot@chromium.org builder->fsCodeAppendf("\toutside.zw = greaterThan(%s, %s.zw);\n", coords.c_str(), domain); 91f910d3b23bcf590ee937628dbab8e39a98ee5860bsalomon@google.com builder->fsCodeAppendf("\t%s = any(outside) ? vec4(0.0, 0.0, 0.0, 0.0) : ", outputColor); 9274a3a2135ca82ab9324b7e499caa3280348a4fdacommit-bot@chromium.org builder->fsAppendTextureLookupAndModulate(inputColor, samplers[0], coords.c_str()); 93f910d3b23bcf590ee937628dbab8e39a98ee5860bsalomon@google.com builder->fsCodeAppend(";\n"); 9413f181f28f4336adcc93b7297b6d16503f4c323crobertphillips@google.com } 957b7cdd147f5528865238e5ed98c79e6d319fde9bbsalomon@google.com } 962f68e7684bb2ecdf0c03a513c31d0626d2caf752tomhudson@google.com} 972f68e7684bb2ecdf0c03a513c31d0626d2caf752tomhudson@google.com 98c78188896e28a4ae49e406a7422b345ae177dafebsalomon@google.comvoid GrGLTextureDomainEffect::setData(const GrGLUniformManager& uman, 99c78188896e28a4ae49e406a7422b345ae177dafebsalomon@google.com const GrDrawEffect& drawEffect) { 100c78188896e28a4ae49e406a7422b345ae177dafebsalomon@google.com const GrTextureDomainEffect& texDom = drawEffect.castEffect<GrTextureDomainEffect>(); 101fd03d4a829efe2d77a712fd991927c55f59a2ffecommit-bot@chromium.org const SkRect& domain = texDom.domain(); 1022f68e7684bb2ecdf0c03a513c31d0626d2caf752tomhudson@google.com 1032f68e7684bb2ecdf0c03a513c31d0626d2caf752tomhudson@google.com float values[4] = { 10481712883419f76e25d2ffec38a9438284a45a48dbsalomon@google.com SkScalarToFloat(domain.left()), 10581712883419f76e25d2ffec38a9438284a45a48dbsalomon@google.com SkScalarToFloat(domain.top()), 10681712883419f76e25d2ffec38a9438284a45a48dbsalomon@google.com SkScalarToFloat(domain.right()), 10781712883419f76e25d2ffec38a9438284a45a48dbsalomon@google.com SkScalarToFloat(domain.bottom()) 1082f68e7684bb2ecdf0c03a513c31d0626d2caf752tomhudson@google.com }; 1092f68e7684bb2ecdf0c03a513c31d0626d2caf752tomhudson@google.com // vertical flip if necessary 110c78188896e28a4ae49e406a7422b345ae177dafebsalomon@google.com if (kBottomLeft_GrSurfaceOrigin == texDom.texture(0)->origin()) { 1112f68e7684bb2ecdf0c03a513c31d0626d2caf752tomhudson@google.com values[1] = 1.0f - values[1]; 1122f68e7684bb2ecdf0c03a513c31d0626d2caf752tomhudson@google.com values[3] = 1.0f - values[3]; 1132f68e7684bb2ecdf0c03a513c31d0626d2caf752tomhudson@google.com // The top and bottom were just flipped, so correct the ordering 1142f68e7684bb2ecdf0c03a513c31d0626d2caf752tomhudson@google.com // of elements so that values = (l, t, r, b). 1152f68e7684bb2ecdf0c03a513c31d0626d2caf752tomhudson@google.com SkTSwap(values[1], values[3]); 1162f68e7684bb2ecdf0c03a513c31d0626d2caf752tomhudson@google.com } 11792b6a94ac103ea3f37a8f9f02072ef884cc17a7cbsalomon@google.com if (0 != memcmp(values, fPrevDomain, 4 * sizeof(GrGLfloat))) { 11892b6a94ac103ea3f37a8f9f02072ef884cc17a7cbsalomon@google.com uman.set4fv(fNameUni, 0, 1, values); 1196b96d368f0dbd09bdec2e209a08fa6306c4a3603robertphillips@google.com memcpy(fPrevDomain, values, 4 * sizeof(GrGLfloat)); 12092b6a94ac103ea3f37a8f9f02072ef884cc17a7cbsalomon@google.com } 12192b6a94ac103ea3f37a8f9f02072ef884cc17a7cbsalomon@google.com fEffectMatrix.setData(uman, 122c78188896e28a4ae49e406a7422b345ae177dafebsalomon@google.com texDom.getMatrix(), 123c78188896e28a4ae49e406a7422b345ae177dafebsalomon@google.com drawEffect, 124c78188896e28a4ae49e406a7422b345ae177dafebsalomon@google.com texDom.texture(0)); 1251aa90cf11e136a722bce71dd77f4bb03cc2b56f8skia.committer@gmail.com} 12692b6a94ac103ea3f37a8f9f02072ef884cc17a7cbsalomon@google.com 127c78188896e28a4ae49e406a7422b345ae177dafebsalomon@google.comGrGLEffect::EffectKey GrGLTextureDomainEffect::GenKey(const GrDrawEffect& drawEffect, 128c78188896e28a4ae49e406a7422b345ae177dafebsalomon@google.com const GrGLCaps&) { 129c78188896e28a4ae49e406a7422b345ae177dafebsalomon@google.com const GrTextureDomainEffect& texDom = drawEffect.castEffect<GrTextureDomainEffect>(); 130c78188896e28a4ae49e406a7422b345ae177dafebsalomon@google.com EffectKey key = texDom.wrapMode(); 1317b7cdd147f5528865238e5ed98c79e6d319fde9bbsalomon@google.com key <<= GrGLEffectMatrix::kKeyBits; 132c78188896e28a4ae49e406a7422b345ae177dafebsalomon@google.com EffectKey matrixKey = GrGLEffectMatrix::GenKey(texDom.getMatrix(), 133c78188896e28a4ae49e406a7422b345ae177dafebsalomon@google.com drawEffect, 134c78188896e28a4ae49e406a7422b345ae177dafebsalomon@google.com texDom.coordsType(), 135c78188896e28a4ae49e406a7422b345ae177dafebsalomon@google.com texDom.texture(0)); 1367b7cdd147f5528865238e5ed98c79e6d319fde9bbsalomon@google.com return key | matrixKey; 1372f68e7684bb2ecdf0c03a513c31d0626d2caf752tomhudson@google.com} 1382f68e7684bb2ecdf0c03a513c31d0626d2caf752tomhudson@google.com 1392f68e7684bb2ecdf0c03a513c31d0626d2caf752tomhudson@google.com 1402f68e7684bb2ecdf0c03a513c31d0626d2caf752tomhudson@google.com/////////////////////////////////////////////////////////////////////////////// 1412f68e7684bb2ecdf0c03a513c31d0626d2caf752tomhudson@google.com 1420ac6af49975c54c2debf41e9200af416ecd2d973bsalomon@google.comGrEffectRef* GrTextureDomainEffect::Create(GrTexture* texture, 1430ac6af49975c54c2debf41e9200af416ecd2d973bsalomon@google.com const SkMatrix& matrix, 144fd03d4a829efe2d77a712fd991927c55f59a2ffecommit-bot@chromium.org const SkRect& domain, 1450ac6af49975c54c2debf41e9200af416ecd2d973bsalomon@google.com WrapMode wrapMode, 146b86add1ad37776818e1f730359ec587c9fdbff5fhumper@google.com GrTextureParams::FilterMode filterMode, 147c78188896e28a4ae49e406a7422b345ae177dafebsalomon@google.com CoordsType coordsType) { 1487b7cdd147f5528865238e5ed98c79e6d319fde9bbsalomon@google.com static const SkRect kFullRect = {0, 0, SK_Scalar1, SK_Scalar1}; 1497b7cdd147f5528865238e5ed98c79e6d319fde9bbsalomon@google.com if (kClamp_WrapMode == wrapMode && domain.contains(kFullRect)) { 150b86add1ad37776818e1f730359ec587c9fdbff5fhumper@google.com return GrSimpleTextureEffect::Create(texture, matrix, filterMode); 1517b7cdd147f5528865238e5ed98c79e6d319fde9bbsalomon@google.com } else { 1527b7cdd147f5528865238e5ed98c79e6d319fde9bbsalomon@google.com SkRect clippedDomain; 1537b7cdd147f5528865238e5ed98c79e6d319fde9bbsalomon@google.com // We don't currently handle domains that are empty or don't intersect the texture. 154fe4e4916b37346ee7b4ca7a13d2eaee1fb3fc416bsalomon@google.com // It is OK if the domain rect is a line or point, but it should not be inverted. We do not 155fe4e4916b37346ee7b4ca7a13d2eaee1fb3fc416bsalomon@google.com // handle rects that do not intersect the [0..1]x[0..1] rect. 156f6de475e5cbd143f348ff7738919e397b7fe7f57tfarina@chromium.org SkASSERT(domain.fLeft <= domain.fRight); 157f6de475e5cbd143f348ff7738919e397b7fe7f57tfarina@chromium.org SkASSERT(domain.fTop <= domain.fBottom); 158fe4e4916b37346ee7b4ca7a13d2eaee1fb3fc416bsalomon@google.com clippedDomain.fLeft = SkMaxScalar(domain.fLeft, kFullRect.fLeft); 159fe4e4916b37346ee7b4ca7a13d2eaee1fb3fc416bsalomon@google.com clippedDomain.fRight = SkMinScalar(domain.fRight, kFullRect.fRight); 160fe4e4916b37346ee7b4ca7a13d2eaee1fb3fc416bsalomon@google.com clippedDomain.fTop = SkMaxScalar(domain.fTop, kFullRect.fTop); 161fe4e4916b37346ee7b4ca7a13d2eaee1fb3fc416bsalomon@google.com clippedDomain.fBottom = SkMinScalar(domain.fBottom, kFullRect.fBottom); 162f6de475e5cbd143f348ff7738919e397b7fe7f57tfarina@chromium.org SkASSERT(clippedDomain.fLeft <= clippedDomain.fRight); 163f6de475e5cbd143f348ff7738919e397b7fe7f57tfarina@chromium.org SkASSERT(clippedDomain.fTop <= clippedDomain.fBottom); 1640ac6af49975c54c2debf41e9200af416ecd2d973bsalomon@google.com 1656340a41108633ac1ce5941e5cd30538630c4c55bbsalomon@google.com AutoEffectUnref effect(SkNEW_ARGS(GrTextureDomainEffect, (texture, 1666340a41108633ac1ce5941e5cd30538630c4c55bbsalomon@google.com matrix, 1676340a41108633ac1ce5941e5cd30538630c4c55bbsalomon@google.com clippedDomain, 1686340a41108633ac1ce5941e5cd30538630c4c55bbsalomon@google.com wrapMode, 169b86add1ad37776818e1f730359ec587c9fdbff5fhumper@google.com filterMode, 170c78188896e28a4ae49e406a7422b345ae177dafebsalomon@google.com coordsType))); 171a1ebbe447d5eab098111eb83580e55f2f5f6facabsalomon@google.com return CreateEffectRef(effect); 1720ac6af49975c54c2debf41e9200af416ecd2d973bsalomon@google.com 1737b7cdd147f5528865238e5ed98c79e6d319fde9bbsalomon@google.com } 1742f68e7684bb2ecdf0c03a513c31d0626d2caf752tomhudson@google.com} 1752f68e7684bb2ecdf0c03a513c31d0626d2caf752tomhudson@google.com 1761ce49fc91714ce8974d11246d29ebe7b97b5fe98bsalomon@google.comGrTextureDomainEffect::GrTextureDomainEffect(GrTexture* texture, 1777b7cdd147f5528865238e5ed98c79e6d319fde9bbsalomon@google.com const SkMatrix& matrix, 178fd03d4a829efe2d77a712fd991927c55f59a2ffecommit-bot@chromium.org const SkRect& domain, 1797b7cdd147f5528865238e5ed98c79e6d319fde9bbsalomon@google.com WrapMode wrapMode, 180b86add1ad37776818e1f730359ec587c9fdbff5fhumper@google.com GrTextureParams::FilterMode filterMode, 181c78188896e28a4ae49e406a7422b345ae177dafebsalomon@google.com CoordsType coordsType) 182b86add1ad37776818e1f730359ec587c9fdbff5fhumper@google.com : GrSingleTextureEffect(texture, matrix, filterMode, coordsType) 1837b7cdd147f5528865238e5ed98c79e6d319fde9bbsalomon@google.com , fWrapMode(wrapMode) 1841ce49fc91714ce8974d11246d29ebe7b97b5fe98bsalomon@google.com , fTextureDomain(domain) { 1851ce49fc91714ce8974d11246d29ebe7b97b5fe98bsalomon@google.com} 1861ce49fc91714ce8974d11246d29ebe7b97b5fe98bsalomon@google.com 1872f68e7684bb2ecdf0c03a513c31d0626d2caf752tomhudson@google.comGrTextureDomainEffect::~GrTextureDomainEffect() { 1882f68e7684bb2ecdf0c03a513c31d0626d2caf752tomhudson@google.com 1892f68e7684bb2ecdf0c03a513c31d0626d2caf752tomhudson@google.com} 1902f68e7684bb2ecdf0c03a513c31d0626d2caf752tomhudson@google.com 191396e61fe440590744345e0c56970b26ab464591dbsalomon@google.comconst GrBackendEffectFactory& GrTextureDomainEffect::getFactory() const { 192396e61fe440590744345e0c56970b26ab464591dbsalomon@google.com return GrTBackendEffectFactory<GrTextureDomainEffect>::getInstance(); 1932f68e7684bb2ecdf0c03a513c31d0626d2caf752tomhudson@google.com} 1942f68e7684bb2ecdf0c03a513c31d0626d2caf752tomhudson@google.com 1958a252f79629b189a03de22cd8ff0312c5bccedd1bsalomon@google.combool GrTextureDomainEffect::onIsEqual(const GrEffect& sBase) const { 1966340a41108633ac1ce5941e5cd30538630c4c55bbsalomon@google.com const GrTextureDomainEffect& s = CastEffect<GrTextureDomainEffect>(sBase); 197c78188896e28a4ae49e406a7422b345ae177dafebsalomon@google.com return this->hasSameTextureParamsMatrixAndCoordsType(s) && 198c78188896e28a4ae49e406a7422b345ae177dafebsalomon@google.com this->fTextureDomain == s.fTextureDomain; 19968b58c95384dd6c2fd389a5b4bbf8fc468819454bsalomon@google.com} 20068b58c95384dd6c2fd389a5b4bbf8fc468819454bsalomon@google.com 20168b58c95384dd6c2fd389a5b4bbf8fc468819454bsalomon@google.comvoid GrTextureDomainEffect::getConstantColorComponents(GrColor* color, uint32_t* validFlags) const { 20268b58c95384dd6c2fd389a5b4bbf8fc468819454bsalomon@google.com if (kDecal_WrapMode == fWrapMode) { 20368b58c95384dd6c2fd389a5b4bbf8fc468819454bsalomon@google.com *validFlags = 0; 20468b58c95384dd6c2fd389a5b4bbf8fc468819454bsalomon@google.com } else { 20568b58c95384dd6c2fd389a5b4bbf8fc468819454bsalomon@google.com this->updateConstantColorComponentsForModulation(color, validFlags); 20668b58c95384dd6c2fd389a5b4bbf8fc468819454bsalomon@google.com } 2072f68e7684bb2ecdf0c03a513c31d0626d2caf752tomhudson@google.com} 2080a7672f85ef7655b343679609d02018f83fcfc23bsalomon@google.com 2090a7672f85ef7655b343679609d02018f83fcfc23bsalomon@google.com/////////////////////////////////////////////////////////////////////////////// 2100a7672f85ef7655b343679609d02018f83fcfc23bsalomon@google.com 211f271cc7183fe48ac64d2d9a454eb013c91b42d53bsalomon@google.comGR_DEFINE_EFFECT_TEST(GrTextureDomainEffect); 2120a7672f85ef7655b343679609d02018f83fcfc23bsalomon@google.com 213e0e7cfe44bb9d66d76120a79e5275c294bacaa22commit-bot@chromium.orgGrEffectRef* GrTextureDomainEffect::TestCreate(SkRandom* random, 214e0e385c1d4171e065348ba17c546b3463a0bd651sugoi@google.com GrContext*, 215c26d94fd7dc0b00cd6d0e42d28285f4a38aff021bsalomon@google.com const GrDrawTargetCaps&, 2160ac6af49975c54c2debf41e9200af416ecd2d973bsalomon@google.com GrTexture* textures[]) { 2176f261bed0252e3f3caa595798364e0bf12a2573absalomon@google.com int texIdx = random->nextBool() ? GrEffectUnitTest::kSkiaPMTextureIdx : 2186f261bed0252e3f3caa595798364e0bf12a2573absalomon@google.com GrEffectUnitTest::kAlphaTextureIdx; 219fd03d4a829efe2d77a712fd991927c55f59a2ffecommit-bot@chromium.org SkRect domain; 2200a7672f85ef7655b343679609d02018f83fcfc23bsalomon@google.com domain.fLeft = random->nextUScalar1(); 2210a7672f85ef7655b343679609d02018f83fcfc23bsalomon@google.com domain.fRight = random->nextRangeScalar(domain.fLeft, SK_Scalar1); 2220a7672f85ef7655b343679609d02018f83fcfc23bsalomon@google.com domain.fTop = random->nextUScalar1(); 2230a7672f85ef7655b343679609d02018f83fcfc23bsalomon@google.com domain.fBottom = random->nextRangeScalar(domain.fTop, SK_Scalar1); 2247b7cdd147f5528865238e5ed98c79e6d319fde9bbsalomon@google.com WrapMode wrapMode = random->nextBool() ? kClamp_WrapMode : kDecal_WrapMode; 2257b7cdd147f5528865238e5ed98c79e6d319fde9bbsalomon@google.com const SkMatrix& matrix = GrEffectUnitTest::TestMatrix(random); 226c78188896e28a4ae49e406a7422b345ae177dafebsalomon@google.com bool bilerp = random->nextBool(); 227c78188896e28a4ae49e406a7422b345ae177dafebsalomon@google.com CoordsType coords = random->nextBool() ? kLocal_CoordsType : kPosition_CoordsType; 228c78188896e28a4ae49e406a7422b345ae177dafebsalomon@google.com return GrTextureDomainEffect::Create(textures[texIdx], 229c78188896e28a4ae49e406a7422b345ae177dafebsalomon@google.com matrix, 230c78188896e28a4ae49e406a7422b345ae177dafebsalomon@google.com domain, 231c78188896e28a4ae49e406a7422b345ae177dafebsalomon@google.com wrapMode, 232b86add1ad37776818e1f730359ec587c9fdbff5fhumper@google.com bilerp ? GrTextureParams::kBilerp_FilterMode : GrTextureParams::kNone_FilterMode, 233c78188896e28a4ae49e406a7422b345ae177dafebsalomon@google.com coords); 2340a7672f85ef7655b343679609d02018f83fcfc23bsalomon@google.com} 235