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 8907fbd53c5e5dd4cbde7b72f9242b51febd7ef95commit-bot@chromium.org#include "GrTextureDomain.h" 968b58c95384dd6c2fd389a5b4bbf8fc468819454bsalomon@google.com#include "GrSimpleTextureEffect.h" 102eaaefd7e6a58339b3f93333f1e9cc92252cc303bsalomon@google.com#include "GrTBackendEffectFactory.h" 11d698f77c13d97c61109b861eac4d25b14a5de935bsalomon@google.com#include "gl/GrGLEffect.h" 1292b6a94ac103ea3f37a8f9f02072ef884cc17a7cbsalomon@google.com#include "SkFloatingPoint.h" 132f68e7684bb2ecdf0c03a513c31d0626d2caf752tomhudson@google.com 14907fbd53c5e5dd4cbde7b72f9242b51febd7ef95commit-bot@chromium.org 15907fbd53c5e5dd4cbde7b72f9242b51febd7ef95commit-bot@chromium.orgGrTextureDomain::GrTextureDomain(const SkRect& domain, Mode mode, int index) 16907fbd53c5e5dd4cbde7b72f9242b51febd7ef95commit-bot@chromium.org : fIndex(index) { 17907fbd53c5e5dd4cbde7b72f9242b51febd7ef95commit-bot@chromium.org 18907fbd53c5e5dd4cbde7b72f9242b51febd7ef95commit-bot@chromium.org static const SkRect kFullRect = {0, 0, SK_Scalar1, SK_Scalar1}; 1926632630fdf17f5a11d9aed6d8766e22842fec14commit-bot@chromium.org if (domain.contains(kFullRect) && kClamp_Mode == mode) { 20907fbd53c5e5dd4cbde7b72f9242b51febd7ef95commit-bot@chromium.org fMode = kIgnore_Mode; 21907fbd53c5e5dd4cbde7b72f9242b51febd7ef95commit-bot@chromium.org } else { 22907fbd53c5e5dd4cbde7b72f9242b51febd7ef95commit-bot@chromium.org fMode = mode; 23907fbd53c5e5dd4cbde7b72f9242b51febd7ef95commit-bot@chromium.org } 24907fbd53c5e5dd4cbde7b72f9242b51febd7ef95commit-bot@chromium.org 25907fbd53c5e5dd4cbde7b72f9242b51febd7ef95commit-bot@chromium.org if (fMode != kIgnore_Mode) { 26907fbd53c5e5dd4cbde7b72f9242b51febd7ef95commit-bot@chromium.org // We don't currently handle domains that are empty or don't intersect the texture. 27907fbd53c5e5dd4cbde7b72f9242b51febd7ef95commit-bot@chromium.org // It is OK if the domain rect is a line or point, but it should not be inverted. We do not 28907fbd53c5e5dd4cbde7b72f9242b51febd7ef95commit-bot@chromium.org // handle rects that do not intersect the [0..1]x[0..1] rect. 29907fbd53c5e5dd4cbde7b72f9242b51febd7ef95commit-bot@chromium.org SkASSERT(domain.fLeft <= domain.fRight); 30907fbd53c5e5dd4cbde7b72f9242b51febd7ef95commit-bot@chromium.org SkASSERT(domain.fTop <= domain.fBottom); 31907fbd53c5e5dd4cbde7b72f9242b51febd7ef95commit-bot@chromium.org fDomain.fLeft = SkMaxScalar(domain.fLeft, kFullRect.fLeft); 32907fbd53c5e5dd4cbde7b72f9242b51febd7ef95commit-bot@chromium.org fDomain.fRight = SkMinScalar(domain.fRight, kFullRect.fRight); 33907fbd53c5e5dd4cbde7b72f9242b51febd7ef95commit-bot@chromium.org fDomain.fTop = SkMaxScalar(domain.fTop, kFullRect.fTop); 34907fbd53c5e5dd4cbde7b72f9242b51febd7ef95commit-bot@chromium.org fDomain.fBottom = SkMinScalar(domain.fBottom, kFullRect.fBottom); 35907fbd53c5e5dd4cbde7b72f9242b51febd7ef95commit-bot@chromium.org SkASSERT(fDomain.fLeft <= fDomain.fRight); 36907fbd53c5e5dd4cbde7b72f9242b51febd7ef95commit-bot@chromium.org SkASSERT(fDomain.fTop <= fDomain.fBottom); 37907fbd53c5e5dd4cbde7b72f9242b51febd7ef95commit-bot@chromium.org } 38907fbd53c5e5dd4cbde7b72f9242b51febd7ef95commit-bot@chromium.org} 39907fbd53c5e5dd4cbde7b72f9242b51febd7ef95commit-bot@chromium.org 40907fbd53c5e5dd4cbde7b72f9242b51febd7ef95commit-bot@chromium.org////////////////////////////////////////////////////////////////////////////// 41907fbd53c5e5dd4cbde7b72f9242b51febd7ef95commit-bot@chromium.org 42907fbd53c5e5dd4cbde7b72f9242b51febd7ef95commit-bot@chromium.orgvoid GrTextureDomain::GLDomain::sampleTexture(GrGLShaderBuilder* builder, 43907fbd53c5e5dd4cbde7b72f9242b51febd7ef95commit-bot@chromium.org const GrTextureDomain& textureDomain, 44907fbd53c5e5dd4cbde7b72f9242b51febd7ef95commit-bot@chromium.org const char* outColor, 45907fbd53c5e5dd4cbde7b72f9242b51febd7ef95commit-bot@chromium.org const SkString& inCoords, 46907fbd53c5e5dd4cbde7b72f9242b51febd7ef95commit-bot@chromium.org const GrGLEffect::TextureSampler sampler, 47907fbd53c5e5dd4cbde7b72f9242b51febd7ef95commit-bot@chromium.org const char* inModulateColor) { 48d7b1af68deefe6e4ca5fa635625154c1e4f2eae6reed@google.com SkASSERT((Mode)-1 == fMode || textureDomain.mode() == fMode); 49907fbd53c5e5dd4cbde7b72f9242b51febd7ef95commit-bot@chromium.org SkDEBUGCODE(fMode = textureDomain.mode();) 50907fbd53c5e5dd4cbde7b72f9242b51febd7ef95commit-bot@chromium.org 51907fbd53c5e5dd4cbde7b72f9242b51febd7ef95commit-bot@chromium.org if (kIgnore_Mode == textureDomain.mode()) { 52907fbd53c5e5dd4cbde7b72f9242b51febd7ef95commit-bot@chromium.org builder->fsCodeAppendf("\t%s = ", outColor); 53907fbd53c5e5dd4cbde7b72f9242b51febd7ef95commit-bot@chromium.org builder->fsAppendTextureLookupAndModulate(inModulateColor, sampler, 54907fbd53c5e5dd4cbde7b72f9242b51febd7ef95commit-bot@chromium.org inCoords.c_str()); 55907fbd53c5e5dd4cbde7b72f9242b51febd7ef95commit-bot@chromium.org builder->fsCodeAppend(";\n"); 56907fbd53c5e5dd4cbde7b72f9242b51febd7ef95commit-bot@chromium.org return; 57907fbd53c5e5dd4cbde7b72f9242b51febd7ef95commit-bot@chromium.org } 58907fbd53c5e5dd4cbde7b72f9242b51febd7ef95commit-bot@chromium.org 59907fbd53c5e5dd4cbde7b72f9242b51febd7ef95commit-bot@chromium.org if (!fDomainUni.isValid()) { 60907fbd53c5e5dd4cbde7b72f9242b51febd7ef95commit-bot@chromium.org const char* name; 61907fbd53c5e5dd4cbde7b72f9242b51febd7ef95commit-bot@chromium.org SkString uniName("TexDom"); 62907fbd53c5e5dd4cbde7b72f9242b51febd7ef95commit-bot@chromium.org if (textureDomain.fIndex >= 0) { 63907fbd53c5e5dd4cbde7b72f9242b51febd7ef95commit-bot@chromium.org uniName.appendS32(textureDomain.fIndex); 64907fbd53c5e5dd4cbde7b72f9242b51febd7ef95commit-bot@chromium.org } 65907fbd53c5e5dd4cbde7b72f9242b51febd7ef95commit-bot@chromium.org fDomainUni = builder->addUniform(GrGLShaderBuilder::kFragment_Visibility, 66907fbd53c5e5dd4cbde7b72f9242b51febd7ef95commit-bot@chromium.org kVec4f_GrSLType, uniName.c_str(), &name); 67907fbd53c5e5dd4cbde7b72f9242b51febd7ef95commit-bot@chromium.org fDomainName = name; 68907fbd53c5e5dd4cbde7b72f9242b51febd7ef95commit-bot@chromium.org } 69907fbd53c5e5dd4cbde7b72f9242b51febd7ef95commit-bot@chromium.org if (kClamp_Mode == textureDomain.mode()) { 70907fbd53c5e5dd4cbde7b72f9242b51febd7ef95commit-bot@chromium.org SkString clampedCoords; 71907fbd53c5e5dd4cbde7b72f9242b51febd7ef95commit-bot@chromium.org clampedCoords.appendf("\tclamp(%s, %s.xy, %s.zw)", 72907fbd53c5e5dd4cbde7b72f9242b51febd7ef95commit-bot@chromium.org inCoords.c_str(), fDomainName.c_str(), fDomainName.c_str()); 73907fbd53c5e5dd4cbde7b72f9242b51febd7ef95commit-bot@chromium.org 74907fbd53c5e5dd4cbde7b72f9242b51febd7ef95commit-bot@chromium.org builder->fsCodeAppendf("\t%s = ", outColor); 75907fbd53c5e5dd4cbde7b72f9242b51febd7ef95commit-bot@chromium.org builder->fsAppendTextureLookupAndModulate(inModulateColor, sampler, clampedCoords.c_str()); 76907fbd53c5e5dd4cbde7b72f9242b51febd7ef95commit-bot@chromium.org builder->fsCodeAppend(";\n"); 77907fbd53c5e5dd4cbde7b72f9242b51febd7ef95commit-bot@chromium.org } else { 78907fbd53c5e5dd4cbde7b72f9242b51febd7ef95commit-bot@chromium.org SkASSERT(GrTextureDomain::kDecal_Mode == textureDomain.mode()); 79907fbd53c5e5dd4cbde7b72f9242b51febd7ef95commit-bot@chromium.org // Add a block since we're going to declare variables. 80907fbd53c5e5dd4cbde7b72f9242b51febd7ef95commit-bot@chromium.org GrGLShaderBuilder::FSBlock block(builder); 81907fbd53c5e5dd4cbde7b72f9242b51febd7ef95commit-bot@chromium.org 82907fbd53c5e5dd4cbde7b72f9242b51febd7ef95commit-bot@chromium.org const char* domain = fDomainName.c_str(); 83907fbd53c5e5dd4cbde7b72f9242b51febd7ef95commit-bot@chromium.org if (kImagination_GrGLVendor == builder->ctxInfo().vendor()) { 84907fbd53c5e5dd4cbde7b72f9242b51febd7ef95commit-bot@chromium.org // On the NexusS and GalaxyNexus, the other path (with the 'any' 85907fbd53c5e5dd4cbde7b72f9242b51febd7ef95commit-bot@chromium.org // call) causes the compilation error "Calls to any function that 86907fbd53c5e5dd4cbde7b72f9242b51febd7ef95commit-bot@chromium.org // may require a gradient calculation inside a conditional block 87907fbd53c5e5dd4cbde7b72f9242b51febd7ef95commit-bot@chromium.org // may return undefined results". This appears to be an issue with 88907fbd53c5e5dd4cbde7b72f9242b51febd7ef95commit-bot@chromium.org // the 'any' call since even the simple "result=black; if (any()) 89907fbd53c5e5dd4cbde7b72f9242b51febd7ef95commit-bot@chromium.org // result=white;" code fails to compile. 90907fbd53c5e5dd4cbde7b72f9242b51febd7ef95commit-bot@chromium.org builder->fsCodeAppend("\tvec4 outside = vec4(0.0, 0.0, 0.0, 0.0);\n"); 91907fbd53c5e5dd4cbde7b72f9242b51febd7ef95commit-bot@chromium.org builder->fsCodeAppend("\tvec4 inside = "); 92907fbd53c5e5dd4cbde7b72f9242b51febd7ef95commit-bot@chromium.org builder->fsAppendTextureLookupAndModulate(inModulateColor, sampler, inCoords.c_str()); 93907fbd53c5e5dd4cbde7b72f9242b51febd7ef95commit-bot@chromium.org builder->fsCodeAppend(";\n"); 94907fbd53c5e5dd4cbde7b72f9242b51febd7ef95commit-bot@chromium.org 95907fbd53c5e5dd4cbde7b72f9242b51febd7ef95commit-bot@chromium.org builder->fsCodeAppendf("\tfloat x = abs(2.0*(%s.x - %s.x)/(%s.z - %s.x) - 1.0);\n", 96907fbd53c5e5dd4cbde7b72f9242b51febd7ef95commit-bot@chromium.org inCoords.c_str(), domain, domain, domain); 97907fbd53c5e5dd4cbde7b72f9242b51febd7ef95commit-bot@chromium.org builder->fsCodeAppendf("\tfloat y = abs(2.0*(%s.y - %s.y)/(%s.w - %s.y) - 1.0);\n", 98907fbd53c5e5dd4cbde7b72f9242b51febd7ef95commit-bot@chromium.org inCoords.c_str(), domain, domain, domain); 99907fbd53c5e5dd4cbde7b72f9242b51febd7ef95commit-bot@chromium.org builder->fsCodeAppend("\tfloat blend = step(1.0, max(x, y));\n"); 100907fbd53c5e5dd4cbde7b72f9242b51febd7ef95commit-bot@chromium.org builder->fsCodeAppendf("\t%s = mix(inside, outside, blend);\n", outColor); 101907fbd53c5e5dd4cbde7b72f9242b51febd7ef95commit-bot@chromium.org } else { 102907fbd53c5e5dd4cbde7b72f9242b51febd7ef95commit-bot@chromium.org builder->fsCodeAppend("\tbvec4 outside;\n"); 103907fbd53c5e5dd4cbde7b72f9242b51febd7ef95commit-bot@chromium.org builder->fsCodeAppendf("\toutside.xy = lessThan(%s, %s.xy);\n", inCoords.c_str(), 104907fbd53c5e5dd4cbde7b72f9242b51febd7ef95commit-bot@chromium.org domain); 105907fbd53c5e5dd4cbde7b72f9242b51febd7ef95commit-bot@chromium.org builder->fsCodeAppendf("\toutside.zw = greaterThan(%s, %s.zw);\n", inCoords.c_str(), 106907fbd53c5e5dd4cbde7b72f9242b51febd7ef95commit-bot@chromium.org domain); 107907fbd53c5e5dd4cbde7b72f9242b51febd7ef95commit-bot@chromium.org builder->fsCodeAppendf("\t%s = any(outside) ? vec4(0.0, 0.0, 0.0, 0.0) : ", outColor); 108907fbd53c5e5dd4cbde7b72f9242b51febd7ef95commit-bot@chromium.org builder->fsAppendTextureLookupAndModulate(inModulateColor, sampler, inCoords.c_str()); 109907fbd53c5e5dd4cbde7b72f9242b51febd7ef95commit-bot@chromium.org builder->fsCodeAppend(";\n"); 110907fbd53c5e5dd4cbde7b72f9242b51febd7ef95commit-bot@chromium.org } 111907fbd53c5e5dd4cbde7b72f9242b51febd7ef95commit-bot@chromium.org } 112907fbd53c5e5dd4cbde7b72f9242b51febd7ef95commit-bot@chromium.org} 113907fbd53c5e5dd4cbde7b72f9242b51febd7ef95commit-bot@chromium.org 114907fbd53c5e5dd4cbde7b72f9242b51febd7ef95commit-bot@chromium.orgvoid GrTextureDomain::GLDomain::setData(const GrGLUniformManager& uman, 115907fbd53c5e5dd4cbde7b72f9242b51febd7ef95commit-bot@chromium.org const GrTextureDomain& textureDomain, 116907fbd53c5e5dd4cbde7b72f9242b51febd7ef95commit-bot@chromium.org GrSurfaceOrigin textureOrigin) { 117907fbd53c5e5dd4cbde7b72f9242b51febd7ef95commit-bot@chromium.org SkASSERT(textureDomain.mode() == fMode); 118907fbd53c5e5dd4cbde7b72f9242b51febd7ef95commit-bot@chromium.org if (kIgnore_Mode != textureDomain.mode()) { 119907fbd53c5e5dd4cbde7b72f9242b51febd7ef95commit-bot@chromium.org GrGLfloat values[4] = { 120907fbd53c5e5dd4cbde7b72f9242b51febd7ef95commit-bot@chromium.org SkScalarToFloat(textureDomain.domain().left()), 121907fbd53c5e5dd4cbde7b72f9242b51febd7ef95commit-bot@chromium.org SkScalarToFloat(textureDomain.domain().top()), 122907fbd53c5e5dd4cbde7b72f9242b51febd7ef95commit-bot@chromium.org SkScalarToFloat(textureDomain.domain().right()), 123907fbd53c5e5dd4cbde7b72f9242b51febd7ef95commit-bot@chromium.org SkScalarToFloat(textureDomain.domain().bottom()) 124907fbd53c5e5dd4cbde7b72f9242b51febd7ef95commit-bot@chromium.org }; 125907fbd53c5e5dd4cbde7b72f9242b51febd7ef95commit-bot@chromium.org // vertical flip if necessary 126907fbd53c5e5dd4cbde7b72f9242b51febd7ef95commit-bot@chromium.org if (kBottomLeft_GrSurfaceOrigin == textureOrigin) { 127907fbd53c5e5dd4cbde7b72f9242b51febd7ef95commit-bot@chromium.org values[1] = 1.0f - values[1]; 128907fbd53c5e5dd4cbde7b72f9242b51febd7ef95commit-bot@chromium.org values[3] = 1.0f - values[3]; 129907fbd53c5e5dd4cbde7b72f9242b51febd7ef95commit-bot@chromium.org // The top and bottom were just flipped, so correct the ordering 130907fbd53c5e5dd4cbde7b72f9242b51febd7ef95commit-bot@chromium.org // of elements so that values = (l, t, r, b). 131907fbd53c5e5dd4cbde7b72f9242b51febd7ef95commit-bot@chromium.org SkTSwap(values[1], values[3]); 132907fbd53c5e5dd4cbde7b72f9242b51febd7ef95commit-bot@chromium.org } 133907fbd53c5e5dd4cbde7b72f9242b51febd7ef95commit-bot@chromium.org if (0 != memcmp(values, fPrevDomain, 4 * sizeof(GrGLfloat))) { 134907fbd53c5e5dd4cbde7b72f9242b51febd7ef95commit-bot@chromium.org uman.set4fv(fDomainUni, 1, values); 135907fbd53c5e5dd4cbde7b72f9242b51febd7ef95commit-bot@chromium.org memcpy(fPrevDomain, values, 4 * sizeof(GrGLfloat)); 136907fbd53c5e5dd4cbde7b72f9242b51febd7ef95commit-bot@chromium.org } 137907fbd53c5e5dd4cbde7b72f9242b51febd7ef95commit-bot@chromium.org } 138907fbd53c5e5dd4cbde7b72f9242b51febd7ef95commit-bot@chromium.org} 139907fbd53c5e5dd4cbde7b72f9242b51febd7ef95commit-bot@chromium.org 140907fbd53c5e5dd4cbde7b72f9242b51febd7ef95commit-bot@chromium.org 141907fbd53c5e5dd4cbde7b72f9242b51febd7ef95commit-bot@chromium.org////////////////////////////////////////////////////////////////////////////// 142907fbd53c5e5dd4cbde7b72f9242b51febd7ef95commit-bot@chromium.org 14322a800a2578564a8b66bd4d9903ef4186c37f35cbsalomon@google.comclass GrGLTextureDomainEffect : public GrGLEffect { 1442f68e7684bb2ecdf0c03a513c31d0626d2caf752tomhudson@google.compublic: 145c78188896e28a4ae49e406a7422b345ae177dafebsalomon@google.com GrGLTextureDomainEffect(const GrBackendEffectFactory&, const GrDrawEffect&); 1462f68e7684bb2ecdf0c03a513c31d0626d2caf752tomhudson@google.com 14722a800a2578564a8b66bd4d9903ef4186c37f35cbsalomon@google.com virtual void emitCode(GrGLShaderBuilder*, 148c78188896e28a4ae49e406a7422b345ae177dafebsalomon@google.com const GrDrawEffect&, 14922a800a2578564a8b66bd4d9903ef4186c37f35cbsalomon@google.com EffectKey, 15022a800a2578564a8b66bd4d9903ef4186c37f35cbsalomon@google.com const char* outputColor, 15122a800a2578564a8b66bd4d9903ef4186c37f35cbsalomon@google.com const char* inputColor, 15277af6805e5faea1e2a5c0220098aec9082f3a6e5bsalomon@google.com const TransformedCoordsArray&, 15322a800a2578564a8b66bd4d9903ef4186c37f35cbsalomon@google.com const TextureSamplerArray&) SK_OVERRIDE; 1542f68e7684bb2ecdf0c03a513c31d0626d2caf752tomhudson@google.com 155c78188896e28a4ae49e406a7422b345ae177dafebsalomon@google.com virtual void setData(const GrGLUniformManager&, const GrDrawEffect&) SK_OVERRIDE; 1562f68e7684bb2ecdf0c03a513c31d0626d2caf752tomhudson@google.com 157c78188896e28a4ae49e406a7422b345ae177dafebsalomon@google.com static inline EffectKey GenKey(const GrDrawEffect&, const GrGLCaps&); 1582f68e7684bb2ecdf0c03a513c31d0626d2caf752tomhudson@google.com 1592f68e7684bb2ecdf0c03a513c31d0626d2caf752tomhudson@google.comprivate: 160907fbd53c5e5dd4cbde7b72f9242b51febd7ef95commit-bot@chromium.org GrTextureDomain::GLDomain fGLDomain; 16122a800a2578564a8b66bd4d9903ef4186c37f35cbsalomon@google.com typedef GrGLEffect INHERITED; 1622f68e7684bb2ecdf0c03a513c31d0626d2caf752tomhudson@google.com}; 1632f68e7684bb2ecdf0c03a513c31d0626d2caf752tomhudson@google.com 164396e61fe440590744345e0c56970b26ab464591dbsalomon@google.comGrGLTextureDomainEffect::GrGLTextureDomainEffect(const GrBackendEffectFactory& factory, 16577af6805e5faea1e2a5c0220098aec9082f3a6e5bsalomon@google.com const GrDrawEffect&) 16677af6805e5faea1e2a5c0220098aec9082f3a6e5bsalomon@google.com : INHERITED(factory) { 1672f68e7684bb2ecdf0c03a513c31d0626d2caf752tomhudson@google.com} 1682f68e7684bb2ecdf0c03a513c31d0626d2caf752tomhudson@google.com 16922a800a2578564a8b66bd4d9903ef4186c37f35cbsalomon@google.comvoid GrGLTextureDomainEffect::emitCode(GrGLShaderBuilder* builder, 170c78188896e28a4ae49e406a7422b345ae177dafebsalomon@google.com const GrDrawEffect& drawEffect, 17192b6a94ac103ea3f37a8f9f02072ef884cc17a7cbsalomon@google.com EffectKey key, 17222a800a2578564a8b66bd4d9903ef4186c37f35cbsalomon@google.com const char* outputColor, 17322a800a2578564a8b66bd4d9903ef4186c37f35cbsalomon@google.com const char* inputColor, 17477af6805e5faea1e2a5c0220098aec9082f3a6e5bsalomon@google.com const TransformedCoordsArray& coords, 17522a800a2578564a8b66bd4d9903ef4186c37f35cbsalomon@google.com const TextureSamplerArray& samplers) { 176907fbd53c5e5dd4cbde7b72f9242b51febd7ef95commit-bot@chromium.org const GrTextureDomainEffect& effect = drawEffect.castEffect<GrTextureDomainEffect>(); 177907fbd53c5e5dd4cbde7b72f9242b51febd7ef95commit-bot@chromium.org const GrTextureDomain& domain = effect.textureDomain(); 1787b7cdd147f5528865238e5ed98c79e6d319fde9bbsalomon@google.com 17977af6805e5faea1e2a5c0220098aec9082f3a6e5bsalomon@google.com SkString coords2D = builder->ensureFSCoords2D(coords, 0); 180907fbd53c5e5dd4cbde7b72f9242b51febd7ef95commit-bot@chromium.org fGLDomain.sampleTexture(builder, domain, outputColor, coords2D, samplers[0], inputColor); 1812f68e7684bb2ecdf0c03a513c31d0626d2caf752tomhudson@google.com} 1822f68e7684bb2ecdf0c03a513c31d0626d2caf752tomhudson@google.com 183c78188896e28a4ae49e406a7422b345ae177dafebsalomon@google.comvoid GrGLTextureDomainEffect::setData(const GrGLUniformManager& uman, 184c78188896e28a4ae49e406a7422b345ae177dafebsalomon@google.com const GrDrawEffect& drawEffect) { 185907fbd53c5e5dd4cbde7b72f9242b51febd7ef95commit-bot@chromium.org const GrTextureDomainEffect& effect = drawEffect.castEffect<GrTextureDomainEffect>(); 186907fbd53c5e5dd4cbde7b72f9242b51febd7ef95commit-bot@chromium.org const GrTextureDomain& domain = effect.textureDomain(); 187907fbd53c5e5dd4cbde7b72f9242b51febd7ef95commit-bot@chromium.org fGLDomain.setData(uman, domain, effect.texture(0)->origin()); 1881aa90cf11e136a722bce71dd77f4bb03cc2b56f8skia.committer@gmail.com} 18992b6a94ac103ea3f37a8f9f02072ef884cc17a7cbsalomon@google.com 190c78188896e28a4ae49e406a7422b345ae177dafebsalomon@google.comGrGLEffect::EffectKey GrGLTextureDomainEffect::GenKey(const GrDrawEffect& drawEffect, 191c78188896e28a4ae49e406a7422b345ae177dafebsalomon@google.com const GrGLCaps&) { 192907fbd53c5e5dd4cbde7b72f9242b51febd7ef95commit-bot@chromium.org const GrTextureDomain& domain = drawEffect.castEffect<GrTextureDomainEffect>().textureDomain(); 193907fbd53c5e5dd4cbde7b72f9242b51febd7ef95commit-bot@chromium.org return GrTextureDomain::GLDomain::DomainKey(domain); 1942f68e7684bb2ecdf0c03a513c31d0626d2caf752tomhudson@google.com} 1952f68e7684bb2ecdf0c03a513c31d0626d2caf752tomhudson@google.com 1962f68e7684bb2ecdf0c03a513c31d0626d2caf752tomhudson@google.com 1972f68e7684bb2ecdf0c03a513c31d0626d2caf752tomhudson@google.com/////////////////////////////////////////////////////////////////////////////// 1982f68e7684bb2ecdf0c03a513c31d0626d2caf752tomhudson@google.com 1990ac6af49975c54c2debf41e9200af416ecd2d973bsalomon@google.comGrEffectRef* GrTextureDomainEffect::Create(GrTexture* texture, 2000ac6af49975c54c2debf41e9200af416ecd2d973bsalomon@google.com const SkMatrix& matrix, 201fd03d4a829efe2d77a712fd991927c55f59a2ffecommit-bot@chromium.org const SkRect& domain, 202907fbd53c5e5dd4cbde7b72f9242b51febd7ef95commit-bot@chromium.org GrTextureDomain::Mode mode, 203b86add1ad37776818e1f730359ec587c9fdbff5fhumper@google.com GrTextureParams::FilterMode filterMode, 20477af6805e5faea1e2a5c0220098aec9082f3a6e5bsalomon@google.com GrCoordSet coordSet) { 2057b7cdd147f5528865238e5ed98c79e6d319fde9bbsalomon@google.com static const SkRect kFullRect = {0, 0, SK_Scalar1, SK_Scalar1}; 206907fbd53c5e5dd4cbde7b72f9242b51febd7ef95commit-bot@chromium.org if (GrTextureDomain::kIgnore_Mode == mode || 207907fbd53c5e5dd4cbde7b72f9242b51febd7ef95commit-bot@chromium.org (GrTextureDomain::kClamp_Mode == mode && domain.contains(kFullRect))) { 208b86add1ad37776818e1f730359ec587c9fdbff5fhumper@google.com return GrSimpleTextureEffect::Create(texture, matrix, filterMode); 2097b7cdd147f5528865238e5ed98c79e6d319fde9bbsalomon@google.com } else { 2100ac6af49975c54c2debf41e9200af416ecd2d973bsalomon@google.com 2116340a41108633ac1ce5941e5cd30538630c4c55bbsalomon@google.com AutoEffectUnref effect(SkNEW_ARGS(GrTextureDomainEffect, (texture, 2126340a41108633ac1ce5941e5cd30538630c4c55bbsalomon@google.com matrix, 213907fbd53c5e5dd4cbde7b72f9242b51febd7ef95commit-bot@chromium.org domain, 214907fbd53c5e5dd4cbde7b72f9242b51febd7ef95commit-bot@chromium.org mode, 215b86add1ad37776818e1f730359ec587c9fdbff5fhumper@google.com filterMode, 21677af6805e5faea1e2a5c0220098aec9082f3a6e5bsalomon@google.com coordSet))); 217a1ebbe447d5eab098111eb83580e55f2f5f6facabsalomon@google.com return CreateEffectRef(effect); 2180ac6af49975c54c2debf41e9200af416ecd2d973bsalomon@google.com 2197b7cdd147f5528865238e5ed98c79e6d319fde9bbsalomon@google.com } 2202f68e7684bb2ecdf0c03a513c31d0626d2caf752tomhudson@google.com} 2212f68e7684bb2ecdf0c03a513c31d0626d2caf752tomhudson@google.com 2221ce49fc91714ce8974d11246d29ebe7b97b5fe98bsalomon@google.comGrTextureDomainEffect::GrTextureDomainEffect(GrTexture* texture, 2237b7cdd147f5528865238e5ed98c79e6d319fde9bbsalomon@google.com const SkMatrix& matrix, 224fd03d4a829efe2d77a712fd991927c55f59a2ffecommit-bot@chromium.org const SkRect& domain, 225907fbd53c5e5dd4cbde7b72f9242b51febd7ef95commit-bot@chromium.org GrTextureDomain::Mode mode, 226b86add1ad37776818e1f730359ec587c9fdbff5fhumper@google.com GrTextureParams::FilterMode filterMode, 22777af6805e5faea1e2a5c0220098aec9082f3a6e5bsalomon@google.com GrCoordSet coordSet) 22877af6805e5faea1e2a5c0220098aec9082f3a6e5bsalomon@google.com : GrSingleTextureEffect(texture, matrix, filterMode, coordSet) 229907fbd53c5e5dd4cbde7b72f9242b51febd7ef95commit-bot@chromium.org , fTextureDomain(domain, mode) { 2301ce49fc91714ce8974d11246d29ebe7b97b5fe98bsalomon@google.com} 2311ce49fc91714ce8974d11246d29ebe7b97b5fe98bsalomon@google.com 2322f68e7684bb2ecdf0c03a513c31d0626d2caf752tomhudson@google.comGrTextureDomainEffect::~GrTextureDomainEffect() { 2332f68e7684bb2ecdf0c03a513c31d0626d2caf752tomhudson@google.com 2342f68e7684bb2ecdf0c03a513c31d0626d2caf752tomhudson@google.com} 2352f68e7684bb2ecdf0c03a513c31d0626d2caf752tomhudson@google.com 236396e61fe440590744345e0c56970b26ab464591dbsalomon@google.comconst GrBackendEffectFactory& GrTextureDomainEffect::getFactory() const { 237396e61fe440590744345e0c56970b26ab464591dbsalomon@google.com return GrTBackendEffectFactory<GrTextureDomainEffect>::getInstance(); 2382f68e7684bb2ecdf0c03a513c31d0626d2caf752tomhudson@google.com} 2392f68e7684bb2ecdf0c03a513c31d0626d2caf752tomhudson@google.com 2408a252f79629b189a03de22cd8ff0312c5bccedd1bsalomon@google.combool GrTextureDomainEffect::onIsEqual(const GrEffect& sBase) const { 2416340a41108633ac1ce5941e5cd30538630c4c55bbsalomon@google.com const GrTextureDomainEffect& s = CastEffect<GrTextureDomainEffect>(sBase); 24277af6805e5faea1e2a5c0220098aec9082f3a6e5bsalomon@google.com return this->hasSameTextureParamsMatrixAndSourceCoords(s) && 243c78188896e28a4ae49e406a7422b345ae177dafebsalomon@google.com this->fTextureDomain == s.fTextureDomain; 24468b58c95384dd6c2fd389a5b4bbf8fc468819454bsalomon@google.com} 24568b58c95384dd6c2fd389a5b4bbf8fc468819454bsalomon@google.com 24668b58c95384dd6c2fd389a5b4bbf8fc468819454bsalomon@google.comvoid GrTextureDomainEffect::getConstantColorComponents(GrColor* color, uint32_t* validFlags) const { 247907fbd53c5e5dd4cbde7b72f9242b51febd7ef95commit-bot@chromium.org if (GrTextureDomain::kDecal_Mode == fTextureDomain.mode()) { // TODO: helper 24868b58c95384dd6c2fd389a5b4bbf8fc468819454bsalomon@google.com *validFlags = 0; 24968b58c95384dd6c2fd389a5b4bbf8fc468819454bsalomon@google.com } else { 25068b58c95384dd6c2fd389a5b4bbf8fc468819454bsalomon@google.com this->updateConstantColorComponentsForModulation(color, validFlags); 25168b58c95384dd6c2fd389a5b4bbf8fc468819454bsalomon@google.com } 2522f68e7684bb2ecdf0c03a513c31d0626d2caf752tomhudson@google.com} 2530a7672f85ef7655b343679609d02018f83fcfc23bsalomon@google.com 2540a7672f85ef7655b343679609d02018f83fcfc23bsalomon@google.com/////////////////////////////////////////////////////////////////////////////// 2550a7672f85ef7655b343679609d02018f83fcfc23bsalomon@google.com 256f271cc7183fe48ac64d2d9a454eb013c91b42d53bsalomon@google.comGR_DEFINE_EFFECT_TEST(GrTextureDomainEffect); 2570a7672f85ef7655b343679609d02018f83fcfc23bsalomon@google.com 258e0e7cfe44bb9d66d76120a79e5275c294bacaa22commit-bot@chromium.orgGrEffectRef* GrTextureDomainEffect::TestCreate(SkRandom* random, 259e0e385c1d4171e065348ba17c546b3463a0bd651sugoi@google.com GrContext*, 260c26d94fd7dc0b00cd6d0e42d28285f4a38aff021bsalomon@google.com const GrDrawTargetCaps&, 2610ac6af49975c54c2debf41e9200af416ecd2d973bsalomon@google.com GrTexture* textures[]) { 2626f261bed0252e3f3caa595798364e0bf12a2573absalomon@google.com int texIdx = random->nextBool() ? GrEffectUnitTest::kSkiaPMTextureIdx : 2636f261bed0252e3f3caa595798364e0bf12a2573absalomon@google.com GrEffectUnitTest::kAlphaTextureIdx; 264fd03d4a829efe2d77a712fd991927c55f59a2ffecommit-bot@chromium.org SkRect domain; 2650a7672f85ef7655b343679609d02018f83fcfc23bsalomon@google.com domain.fLeft = random->nextUScalar1(); 2660a7672f85ef7655b343679609d02018f83fcfc23bsalomon@google.com domain.fRight = random->nextRangeScalar(domain.fLeft, SK_Scalar1); 2670a7672f85ef7655b343679609d02018f83fcfc23bsalomon@google.com domain.fTop = random->nextUScalar1(); 2680a7672f85ef7655b343679609d02018f83fcfc23bsalomon@google.com domain.fBottom = random->nextRangeScalar(domain.fTop, SK_Scalar1); 269907fbd53c5e5dd4cbde7b72f9242b51febd7ef95commit-bot@chromium.org GrTextureDomain::Mode mode = 270907fbd53c5e5dd4cbde7b72f9242b51febd7ef95commit-bot@chromium.org (GrTextureDomain::Mode) random->nextULessThan(GrTextureDomain::kModeCount); 2717b7cdd147f5528865238e5ed98c79e6d319fde9bbsalomon@google.com const SkMatrix& matrix = GrEffectUnitTest::TestMatrix(random); 272c78188896e28a4ae49e406a7422b345ae177dafebsalomon@google.com bool bilerp = random->nextBool(); 27377af6805e5faea1e2a5c0220098aec9082f3a6e5bsalomon@google.com GrCoordSet coords = random->nextBool() ? kLocal_GrCoordSet : kPosition_GrCoordSet; 274c78188896e28a4ae49e406a7422b345ae177dafebsalomon@google.com return GrTextureDomainEffect::Create(textures[texIdx], 275c78188896e28a4ae49e406a7422b345ae177dafebsalomon@google.com matrix, 276c78188896e28a4ae49e406a7422b345ae177dafebsalomon@google.com domain, 277907fbd53c5e5dd4cbde7b72f9242b51febd7ef95commit-bot@chromium.org mode, 278b86add1ad37776818e1f730359ec587c9fdbff5fhumper@google.com bilerp ? GrTextureParams::kBilerp_FilterMode : GrTextureParams::kNone_FilterMode, 279c78188896e28a4ae49e406a7422b345ae177dafebsalomon@google.com coords); 2800a7672f85ef7655b343679609d02018f83fcfc23bsalomon@google.com} 281