From 10273c1d5fe18f41a62c5ff4faf8bbdb5d5656cc Mon Sep 17 00:00:00 2001 From: Brian Salomon Date: Tue, 4 Dec 2018 12:34:41 -0500 Subject: [PATCH] Use unnormalized coords all the way through with GL_TEXTURE_RECTANGLE textures. We used to unnormalize them in the shader via SkSL. This allows us to support GL_TEXTURE_RECTANGLE without having textureSize() available in GLSL. Change-Id: Ibe63a302228811933ef000251db4cad9aaf4f2ea Reviewed-on: https://skia-review.googlesource.com/c/174068 Reviewed-by: Brian Osman Commit-Queue: Brian Salomon --- gm/rectangletexture.cpp | 127 +++++++++++++--------- include/private/GrTypesPriv.h | 1 + src/gpu/GrCoordTransform.h | 31 ++---- src/gpu/effects/GrTextureDomain.cpp | 31 ++++-- src/gpu/effects/GrYUVtoRGBEffect.h | 3 +- src/gpu/gl/GrGLCaps.cpp | 6 +- src/gpu/gl/GrGLGpu.cpp | 12 +- src/gpu/glsl/GrGLSLPrimitiveProcessor.cpp | 28 +++-- src/gpu/ops/GrTextureOp.cpp | 36 ++++-- src/shaders/SkPerlinNoiseShader.cpp | 4 +- src/sksl/SkSLIRGenerator.cpp | 35 ------ src/sksl/SkSLIRGenerator.h | 1 - tests/SkSLGLSLTest.cpp | 4 +- 13 files changed, 168 insertions(+), 151 deletions(-) diff --git a/gm/rectangletexture.cpp b/gm/rectangletexture.cpp index 325e29ac09..4d4e1df4c6 100644 --- a/gm/rectangletexture.cpp +++ b/gm/rectangletexture.cpp @@ -30,9 +30,7 @@ protected: return SkString("rectangle_texture"); } - SkISize onISize() override { - return SkISize::Make(1035, 240); - } + SkISize onISize() override { return SkISize::Make(1200, 500); } void fillPixels(int width, int height, void *pixels) { SkBitmap bmp; @@ -46,7 +44,7 @@ protected: SkShader::kClamp_TileMode)); canvas.drawPaint(paint); - SkColor colors1[] = { 0xFFA07010 , 0xFFA02080 }; + SkColor colors1[] = {0xFFA07010, 0xFFA02080}; paint.setAntiAlias(true); paint.setShader(SkGradientShader::MakeLinear(pts, colors1, nullptr, 2, SkShader::kClamp_TileMode)); @@ -54,8 +52,8 @@ protected: SkIntToScalar(width + height) / 5, paint); } - sk_sp createRectangleTextureImg(GrContext* context, int width, int height, - void* pixels) { + sk_sp createRectangleTextureImg(GrContext* context, GrSurfaceOrigin origin, int width, + int height, const uint32_t* pixels) { if (!context) { return nullptr; } @@ -88,34 +86,36 @@ protected: } const GrGLInterface* gl = glCtx->interface(); -// Useful for debugging whether errors result from use of RECTANGLE -// #define TARGET GR_GL_TEXTURE_2D -#define TARGET GR_GL_TEXTURE_RECTANGLE + // Useful for debugging whether errors result from use of RECTANGLE + // static constexpr GrGLenum kTarget = GR_GL_TEXTURE_2D; + static constexpr GrGLenum kTarget = GR_GL_TEXTURE_RECTANGLE; GrGLuint id = 0; GR_GL_CALL(gl, GenTextures(1, &id)); - GR_GL_CALL(gl, BindTexture(TARGET, id)); - GR_GL_CALL(gl, TexParameteri(TARGET, GR_GL_TEXTURE_MAG_FILTER, - GR_GL_NEAREST)); - GR_GL_CALL(gl, TexParameteri(TARGET, GR_GL_TEXTURE_MIN_FILTER, - GR_GL_NEAREST)); - GR_GL_CALL(gl, TexParameteri(TARGET, GR_GL_TEXTURE_WRAP_S, - GR_GL_CLAMP_TO_EDGE)); - GR_GL_CALL(gl, TexParameteri(TARGET, GR_GL_TEXTURE_WRAP_T, - GR_GL_CLAMP_TO_EDGE)); - GR_GL_CALL(gl, TexImage2D(TARGET, 0, GR_GL_RGBA, width, height, 0, - format, GR_GL_UNSIGNED_BYTE, pixels)); - + GR_GL_CALL(gl, BindTexture(kTarget, id)); + GR_GL_CALL(gl, TexParameteri(kTarget, GR_GL_TEXTURE_MAG_FILTER, GR_GL_NEAREST)); + GR_GL_CALL(gl, TexParameteri(kTarget, GR_GL_TEXTURE_MIN_FILTER, GR_GL_NEAREST)); + GR_GL_CALL(gl, TexParameteri(kTarget, GR_GL_TEXTURE_WRAP_S, GR_GL_CLAMP_TO_EDGE)); + GR_GL_CALL(gl, TexParameteri(kTarget, GR_GL_TEXTURE_WRAP_T, GR_GL_CLAMP_TO_EDGE)); + std::unique_ptr tempPixels; + if (origin == kBottomLeft_GrSurfaceOrigin) { + tempPixels.reset(new uint32_t[width * height]); + for (int y = 0; y < height; ++y) { + std::copy_n(pixels + width * (height - y - 1), width, tempPixels.get() + width * y); + } + pixels = tempPixels.get(); + } + GR_GL_CALL(gl, TexImage2D(kTarget, 0, GR_GL_RGBA, width, height, 0, format, + GR_GL_UNSIGNED_BYTE, pixels)); context->resetContext(); GrGLTextureInfo info; info.fID = id; - info.fTarget = TARGET; + info.fTarget = kTarget; info.fFormat = GR_GL_RGBA8; GrBackendTexture rectangleTex(width, height, GrMipMapped::kNo, info); - if (sk_sp image = SkImage::MakeFromAdoptedTexture(context, rectangleTex, - kTopLeft_GrSurfaceOrigin, + if (sk_sp image = SkImage::MakeFromAdoptedTexture(context, rectangleTex, origin, kRGBA_8888_SkColorType)) { return image; } @@ -136,9 +136,15 @@ protected: SkPMColor pixels[kWidth * kHeight]; this->fillPixels(kWidth, kHeight, pixels); - sk_sp rectImg(this->createRectangleTextureImg(context, kWidth, kHeight, pixels)); - if (!rectImg) { + sk_sp rectImgs[] = { + this->createRectangleTextureImg(context, kTopLeft_GrSurfaceOrigin, kWidth, kHeight, + pixels), + this->createRectangleTextureImg(context, kBottomLeft_GrSurfaceOrigin, kWidth, + kHeight, pixels), + }; + SkASSERT(SkToBool(rectImgs[0]) == SkToBool(rectImgs[1])); + if (!rectImgs[0]) { SkPaint paint; paint.setAntiAlias(true); const char* kMsg = "Could not create rectangle texture image."; @@ -147,39 +153,56 @@ protected: } constexpr SkFilterQuality kQualities[] = { - kNone_SkFilterQuality, - kLow_SkFilterQuality, - kMedium_SkFilterQuality, - kHigh_SkFilterQuality, + kNone_SkFilterQuality, + kLow_SkFilterQuality, + kMedium_SkFilterQuality, + kHigh_SkFilterQuality, }; - constexpr SkScalar kScales[] = { 1.0f, 1.2f, 0.75f }; + constexpr SkScalar kScales[] = {1.0f, 1.2f, 0.75f}; canvas->translate(kPad, kPad); - for (auto s : kScales) { - canvas->save(); - canvas->scale(s, s); - for (auto q : kQualities) { - SkPaint plainPaint; - plainPaint.setFilterQuality(q); - canvas->drawImage(rectImg.get(), 0, 0, &plainPaint); - canvas->translate(kWidth + kPad, 0); + for (size_t i = 0; i < SK_ARRAY_COUNT(rectImgs); ++i) { + for (auto s : kScales) { + canvas->save(); + canvas->scale(s, s); + for (auto q : kQualities) { + // drawImage + SkPaint plainPaint; + plainPaint.setFilterQuality(q); + canvas->drawImage(rectImgs[i], 0, 0, &plainPaint); + canvas->translate(kWidth + kPad, 0); - SkPaint clampPaint; - clampPaint.setFilterQuality(q); - clampPaint.setShader(rectImg->makeShader()); - canvas->drawRect(SkRect::MakeWH(1.5f * kWidth, 1.5f * kHeight), clampPaint); - canvas->translate(kWidth * 1.5f + kPad, 0); + // clamp/clamp shader + SkPaint clampPaint; + clampPaint.setFilterQuality(q); + clampPaint.setShader(rectImgs[i]->makeShader()); + canvas->drawRect(SkRect::MakeWH(1.5f * kWidth, 1.5f * kHeight), clampPaint); + canvas->translate(kWidth * 1.5f + kPad, 0); - SkPaint repeatPaint; - repeatPaint.setFilterQuality(q); - repeatPaint.setShader(rectImg->makeShader(SkShader::kRepeat_TileMode, - SkShader::kMirror_TileMode)); - canvas->drawRect(SkRect::MakeWH(1.5f * kWidth, 1.5f * kHeight), repeatPaint); - canvas->translate(1.5f * kWidth + kPad, 0); + // repeat/mirror shader + SkPaint repeatPaint; + repeatPaint.setFilterQuality(q); + repeatPaint.setShader(rectImgs[i]->makeShader(SkShader::kRepeat_TileMode, + SkShader::kMirror_TileMode)); + canvas->drawRect(SkRect::MakeWH(1.5f * kWidth, 1.5f * kHeight), repeatPaint); + canvas->translate(1.5f * kWidth + kPad, 0); + + // drawImageRect with kStrict + auto srcRect = SkRect::MakeXYWH(.25f * rectImgs[i]->width(), + .25f * rectImgs[i]->height(), + .50f * rectImgs[i]->width(), + .50f * rectImgs[i]->height()); + auto dstRect = SkRect::MakeXYWH(0, 0, + .50f * rectImgs[i]->width(), + .50f * rectImgs[i]->height()); + canvas->drawImageRect(rectImgs[i], srcRect, dstRect, &plainPaint, + SkCanvas::kStrict_SrcRectConstraint); + canvas->translate(kWidth * .5f + kPad, 0); + } + canvas->restore(); + canvas->translate(0, kPad + 1.5f * kHeight * s); } - canvas->restore(); - canvas->translate(0, kPad + 1.5f * kHeight * s); } } diff --git a/include/private/GrTypesPriv.h b/include/private/GrTypesPriv.h index 86cde4d27f..e9fd0a332d 100644 --- a/include/private/GrTypesPriv.h +++ b/include/private/GrTypesPriv.h @@ -358,6 +358,7 @@ enum GrSLType { */ enum class GrTextureType { k2D, + /* Rectangle uses unnormalized texture coordinates. */ kRectangle, kExternal }; diff --git a/src/gpu/GrCoordTransform.h b/src/gpu/GrCoordTransform.h index 43405f2c46..aee2253ea4 100644 --- a/src/gpu/GrCoordTransform.h +++ b/src/gpu/GrCoordTransform.h @@ -36,7 +36,7 @@ public: GrCoordTransform(GrTextureProxy* proxy) { SkASSERT(proxy); SkDEBUGCODE(fInProcessor = false); - this->reset(SkMatrix::I(), proxy, true); + this->reset(SkMatrix::I(), proxy); } /** @@ -46,7 +46,7 @@ public: GrCoordTransform(const SkMatrix& m, GrTextureProxy* proxy) { SkASSERT(proxy); SkDEBUGCODE(fInProcessor = false); - this->reset(m, proxy, true); + this->reset(m, proxy); } /** @@ -57,24 +57,6 @@ public: this->reset(m); } - void reset(const SkMatrix& m, GrTextureProxy* proxy, bool normalize) { - SkASSERT(proxy); - SkASSERT(!fInProcessor); - - fMatrix = m; - fProxy = proxy; - fNormalize = normalize; - fReverseY = kBottomLeft_GrSurfaceOrigin == proxy->origin(); - } - - void reset(const SkMatrix& m) { - SkASSERT(!fInProcessor); - fMatrix = m; - fProxy = nullptr; - fNormalize = false; - fReverseY = false; - } - GrCoordTransform& operator= (const GrCoordTransform& that) { SkASSERT(!fInProcessor); fMatrix = that.fMatrix; @@ -119,6 +101,15 @@ public: GrTexture* peekTexture() const { return fProxy->peekTexture(); } private: + void reset(const SkMatrix& m, GrTextureProxy* proxy = nullptr) { + SkASSERT(!fInProcessor); + + fMatrix = m; + fProxy = proxy; + fNormalize = proxy && proxy->textureType() != GrTextureType::kRectangle; + fReverseY = proxy && kBottomLeft_GrSurfaceOrigin == proxy->origin(); + } + // The textures' effect is to optionally normalize the final matrix, so a blind // equality check could be misleading bool operator==(const GrCoordTransform& that) const; diff --git a/src/gpu/effects/GrTextureDomain.cpp b/src/gpu/effects/GrTextureDomain.cpp index d8df5acb1a..28a47cd45e 100644 --- a/src/gpu/effects/GrTextureDomain.cpp +++ b/src/gpu/effects/GrTextureDomain.cpp @@ -165,8 +165,15 @@ void GrTextureDomain::GLDomain::setData(const GrGLSLProgramDataManager& pdman, GrTexture* tex = proxy->peekTexture(); SkASSERT(fHasMode && textureDomain.mode() == fMode); if (kIgnore_Mode != textureDomain.mode()) { - SkScalar wInv = SK_Scalar1 / tex->width(); - SkScalar hInv = SK_Scalar1 / tex->height(); + SkScalar wInv, hInv, h; + if (proxy->textureType() == GrTextureType::kRectangle) { + wInv = hInv = 1.f; + h = tex->height(); + } else { + wInv = SK_Scalar1 / tex->width(); + hInv = SK_Scalar1 / tex->height(); + h = 1.f; + } float values[kPrevDomainCount] = { SkScalarToFloat(textureDomain.domain().fLeft * wInv), @@ -175,15 +182,23 @@ void GrTextureDomain::GLDomain::setData(const GrGLSLProgramDataManager& pdman, SkScalarToFloat(textureDomain.domain().fBottom * hInv) }; - SkASSERT(values[0] >= 0.0f && values[0] <= 1.0f); - SkASSERT(values[1] >= 0.0f && values[1] <= 1.0f); - SkASSERT(values[2] >= 0.0f && values[2] <= 1.0f); - SkASSERT(values[3] >= 0.0f && values[3] <= 1.0f); + if (proxy->textureType() == GrTextureType::kRectangle) { + SkASSERT(values[0] >= 0.0f && values[0] <= proxy->height()); + SkASSERT(values[1] >= 0.0f && values[1] <= proxy->height()); + SkASSERT(values[2] >= 0.0f && values[2] <= proxy->height()); + SkASSERT(values[3] >= 0.0f && values[3] <= proxy->height()); + } else { + SkASSERT(values[0] >= 0.0f && values[0] <= 1.0f); + SkASSERT(values[1] >= 0.0f && values[1] <= 1.0f); + SkASSERT(values[2] >= 0.0f && values[2] <= 1.0f); + SkASSERT(values[3] >= 0.0f && values[3] <= 1.0f); + } // vertical flip if necessary if (kBottomLeft_GrSurfaceOrigin == proxy->origin()) { - values[1] = 1.0f - values[1]; - values[3] = 1.0f - values[3]; + values[1] = h - values[1]; + values[3] = h - values[3]; + // The top and bottom were just flipped, so correct the ordering // of elements so that values = (l, t, r, b). using std::swap; diff --git a/src/gpu/effects/GrYUVtoRGBEffect.h b/src/gpu/effects/GrYUVtoRGBEffect.h index 6cdcce9572..3d94402ad3 100644 --- a/src/gpu/effects/GrYUVtoRGBEffect.h +++ b/src/gpu/effects/GrYUVtoRGBEffect.h @@ -42,7 +42,8 @@ private: fSamplers[i].reset(std::move(proxies[i]), GrSamplerState(GrSamplerState::WrapMode::kClamp, filterModes[i])); fSamplerTransforms[i] = SkMatrix::MakeScale(scales[i].width(), scales[i].height()); - fSamplerCoordTransforms[i].reset(fSamplerTransforms[i], fSamplers[i].proxy(), true); + fSamplerCoordTransforms[i] = + GrCoordTransform(fSamplerTransforms[i], fSamplers[i].proxy()); } this->setTextureSamplerCnt(numPlanes); diff --git a/src/gpu/gl/GrGLCaps.cpp b/src/gpu/gl/GrGLCaps.cpp index 73e1f9dc25..9f26a7c06d 100644 --- a/src/gpu/gl/GrGLCaps.cpp +++ b/src/gpu/gl/GrGLCaps.cpp @@ -227,11 +227,7 @@ void GrGLCaps::init(const GrContextOptions& contextOptions, if (kGL_GrGLStandard == standard) { if (version >= GR_GL_VER(3, 1) || ctxInfo.hasExtension("GL_ARB_texture_rectangle") || ctxInfo.hasExtension("GL_ANGLE_texture_rectangle")) { - // We also require textureSize() support for rectangle 2D samplers which was added in - // GLSL 1.40. - if (ctxInfo.glslGeneration() >= k140_GrGLSLGeneration) { - fRectangleTextureSupport = true; - } + fRectangleTextureSupport = true; } } else { // Command buffer exposes this in GL ES context for Chromium reasons, diff --git a/src/gpu/gl/GrGLGpu.cpp b/src/gpu/gl/GrGLGpu.cpp index df10ffdf7b..63bf0322df 100644 --- a/src/gpu/gl/GrGLGpu.cpp +++ b/src/gpu/gl/GrGLGpu.cpp @@ -3739,11 +3739,13 @@ bool GrGLGpu::copySurfaceAsDraw(GrSurface* dst, GrSurfaceOrigin dstOrigin, sy0 = sh - sy0; sy1 = sh - sy1; } - // src rect edges in normalized texture space (0 to 1) - sx0 /= sw; - sx1 /= sw; - sy0 /= sh; - sy1 /= sh; + if (srcTex->texturePriv().textureType() != GrTextureType::kRectangle) { + // src rect edges in normalized texture space (0 to 1) + sx0 /= sw; + sx1 /= sw; + sy0 /= sh; + sy1 /= sh; + } GL_CALL(Uniform4f(fCopyPrograms[progIdx].fPosXformUniform, dx1 - dx0, dy1 - dy0, dx0, dy0)); GL_CALL(Uniform4f(fCopyPrograms[progIdx].fTexCoordXformUniform, diff --git a/src/gpu/glsl/GrGLSLPrimitiveProcessor.cpp b/src/gpu/glsl/GrGLSLPrimitiveProcessor.cpp index fb6e7f28d1..8e6099e87d 100644 --- a/src/gpu/glsl/GrGLSLPrimitiveProcessor.cpp +++ b/src/gpu/glsl/GrGLSLPrimitiveProcessor.cpp @@ -24,14 +24,26 @@ SkMatrix GrGLSLPrimitiveProcessor::GetTransformMatrix(const SkMatrix& localMatri } if (coordTransform.reverseY()) { - // combined.postScale(1,-1); - // combined.postTranslate(0,1); - combined.set(SkMatrix::kMSkewY, - combined[SkMatrix::kMPersp0] - combined[SkMatrix::kMSkewY]); - combined.set(SkMatrix::kMScaleY, - combined[SkMatrix::kMPersp1] - combined[SkMatrix::kMScaleY]); - combined.set(SkMatrix::kMTransY, - combined[SkMatrix::kMPersp2] - combined[SkMatrix::kMTransY]); + if (coordTransform.normalize()) { + // combined.postScale(1,-1); + // combined.postTranslate(0,1); + combined.set(SkMatrix::kMSkewY, + combined[SkMatrix::kMPersp0] - combined[SkMatrix::kMSkewY]); + combined.set(SkMatrix::kMScaleY, + combined[SkMatrix::kMPersp1] - combined[SkMatrix::kMScaleY]); + combined.set(SkMatrix::kMTransY, + combined[SkMatrix::kMPersp2] - combined[SkMatrix::kMTransY]); + } else { + // combined.postScale(1, -1); + // combined.postTranslate(0,1); + SkScalar h = coordTransform.peekTexture()->height(); + combined.set(SkMatrix::kMSkewY, + h * combined[SkMatrix::kMPersp0] - combined[SkMatrix::kMSkewY]); + combined.set(SkMatrix::kMScaleY, + h * combined[SkMatrix::kMPersp1] - combined[SkMatrix::kMScaleY]); + combined.set(SkMatrix::kMTransY, + h * combined[SkMatrix::kMPersp2] - combined[SkMatrix::kMTransY]); + } } return combined; } diff --git a/src/gpu/ops/GrTextureOp.cpp b/src/gpu/ops/GrTextureOp.cpp index 255f937fe9..7ef5896bb5 100644 --- a/src/gpu/ops/GrTextureOp.cpp +++ b/src/gpu/ops/GrTextureOp.cpp @@ -54,9 +54,11 @@ static bool filter_has_effect_for_rect_stays_rect(const GrPerspQuad& quad, const SkScalarFraction(qt) != SkScalarFraction(srcRect.fTop); } -static SkRect compute_domain(Domain domain, GrSamplerState::Filter filter, - GrSurfaceOrigin origin, const SkRect& srcRect, float iw, float ih) { - static constexpr SkRect kLargeRect = {-2, -2, 2, 2}; +// if normalizing the domain then pass 1/width, 1/height, 1 for iw, ih, h. Otherwise pass +// 1, 1, and height. +static SkRect compute_domain(Domain domain, GrSamplerState::Filter filter, GrSurfaceOrigin origin, + const SkRect& srcRect, float iw, float ih, float h) { + static constexpr SkRect kLargeRect = {-100000, -100000, 1000000, 1000000}; if (domain == Domain::kNo) { // Either the quad has no domain constraint and is batched with a domain constrained op // (in which case we want a domain that doesn't restrict normalized tex coords), or the @@ -75,7 +77,7 @@ static SkRect compute_domain(Domain domain, GrSamplerState::Filter filter, ltrb *= Sk4f(iw, ih, iw, ih); if (origin == kBottomLeft_GrSurfaceOrigin) { static const Sk4f kMul = {1.f, -1.f, 1.f, -1.f}; - static const Sk4f kAdd = {0.f, 1.f, 0.f, 1.f}; + static const Sk4f kAdd = {0.f, h, 0.f, h}; ltrb = SkNx_shuffle<0, 3, 2, 1>(kMul * ltrb + kAdd); } @@ -84,8 +86,10 @@ static SkRect compute_domain(Domain domain, GrSamplerState::Filter filter, return domainRect; } -static GrPerspQuad compute_src_quad(GrSurfaceOrigin origin, const SkRect& srcRect, - float iw, float ih) { +// If normalizing the src quad then pass 1/width, 1/height, 1 for iw, ih, h. Otherwise pass +// 1, 1, and height. +static GrPerspQuad compute_src_quad(GrSurfaceOrigin origin, const SkRect& srcRect, float iw, + float ih, float h) { // Convert the pixel-space src rectangle into normalized texture coordinates SkRect texRect = { iw * srcRect.fLeft, @@ -94,8 +98,8 @@ static GrPerspQuad compute_src_quad(GrSurfaceOrigin origin, const SkRect& srcRec ih * srcRect.fBottom }; if (origin == kBottomLeft_GrSurfaceOrigin) { - texRect.fTop = 1.f - texRect.fTop; - texRect.fBottom = 1.f - texRect.fBottom; + texRect.fTop = h - texRect.fTop; + texRect.fBottom = h - texRect.fBottom; } return GrPerspQuad(texRect, SkMatrix::I()); } @@ -305,13 +309,21 @@ private: TRACE_EVENT0("skia", TRACE_FUNC); auto origin = proxy->origin(); const auto* texture = proxy->peekTexture(); - float iw = 1.f / texture->width(); - float ih = 1.f / texture->height(); + float iw, ih, h; + if (proxy->textureType() == GrTextureType::kRectangle) { + iw = ih = 1.f; + h = texture->height(); + } else { + iw = 1.f / texture->width(); + ih = 1.f / texture->height(); + h = 1.f; + } for (int i = start; i < start + cnt; ++i) { const auto q = fQuads[i]; - GrPerspQuad srcQuad = compute_src_quad(origin, q.srcRect(), iw, ih); - SkRect domain = compute_domain(q.domain(), this->filter(), origin, q.srcRect(), iw, ih); + GrPerspQuad srcQuad = compute_src_quad(origin, q.srcRect(), iw, ih, h); + SkRect domain = + compute_domain(q.domain(), this->filter(), origin, q.srcRect(), iw, ih, h); v = GrQuadPerEdgeAA::Tessellate(v, spec, q.quad(), q.color(), srcQuad, domain, q.aaFlags()); } diff --git a/src/shaders/SkPerlinNoiseShader.cpp b/src/shaders/SkPerlinNoiseShader.cpp index b0e3b580f2..b0d464b0cc 100644 --- a/src/shaders/SkPerlinNoiseShader.cpp +++ b/src/shaders/SkPerlinNoiseShader.cpp @@ -768,7 +768,7 @@ private: , fNoiseSampler(std::move(noiseProxy)) , fPaintingData(std::move(paintingData)) { this->setTextureSamplerCnt(2); - fCoordTransform.reset(matrix); + fCoordTransform = GrCoordTransform(matrix); this->addCoordTransform(&fCoordTransform); } @@ -1191,7 +1191,7 @@ private: , fGradientSampler(std::move(gradientProxy)) , fPaintingData(std::move(paintingData)) { this->setTextureSamplerCnt(2); - fCoordTransform.reset(matrix); + fCoordTransform = GrCoordTransform(matrix); this->addCoordTransform(&fCoordTransform); } diff --git a/src/sksl/SkSLIRGenerator.cpp b/src/sksl/SkSLIRGenerator.cpp index 3374630cbc..6f9fcd95fb 100644 --- a/src/sksl/SkSLIRGenerator.cpp +++ b/src/sksl/SkSLIRGenerator.cpp @@ -1549,37 +1549,6 @@ std::unique_ptr IRGenerator::convertTernaryExpression( std::move(ifFalse))); } -// scales the texture coordinates by the texture size for sampling rectangle textures. -// For float2coordinates, implements the transformation: -// texture(sampler, coord) -> texture(sampler, textureSize(sampler) * coord) -// For float3coordinates, implements the transformation: -// texture(sampler, coord) -> texture(sampler, float3textureSize(sampler), 1.0) * coord)) -void IRGenerator::fixRectSampling(std::vector>& arguments) { - SkASSERT(arguments.size() == 2); - SkASSERT(arguments[0]->fType == *fContext.fSampler2DRect_Type); - SkASSERT(arguments[0]->fKind == Expression::kVariableReference_Kind); - const Variable& sampler = ((VariableReference&) *arguments[0]).fVariable; - const Symbol* textureSizeSymbol = (*fSymbolTable)["textureSize"]; - SkASSERT(textureSizeSymbol->fKind == Symbol::kFunctionDeclaration_Kind); - const FunctionDeclaration& textureSize = (FunctionDeclaration&) *textureSizeSymbol; - std::vector> sizeArguments; - sizeArguments.emplace_back(new VariableReference(-1, sampler)); - std::unique_ptr float2ize = call(-1, textureSize, std::move(sizeArguments)); - const Type& type = arguments[1]->fType; - std::unique_ptr scale; - if (type == *fContext.fFloat2_Type) { - scale = std::move(float2ize); - } else { - SkASSERT(type == *fContext.fFloat3_Type); - std::vector> float3rguments; - float3rguments.push_back(std::move(float2ize)); - float3rguments.emplace_back(new FloatLiteral(fContext, -1, 1.0)); - scale.reset(new Constructor(-1, *fContext.fFloat3_Type, std::move(float3rguments))); - } - arguments[1].reset(new BinaryExpression(-1, std::move(scale), Token::STAR, - std::move(arguments[1]), type)); -} - std::unique_ptr IRGenerator::call(int offset, const FunctionDeclaration& function, std::vector> arguments) { @@ -1620,10 +1589,6 @@ std::unique_ptr IRGenerator::call(int offset, VariableReference::kPointer_RefKind); } } - if (function.fBuiltin && function.fName == "texture" && - arguments[0]->fType == *fContext.fSampler2DRect_Type) { - this->fixRectSampling(arguments); - } return std::unique_ptr(new FunctionCall(offset, *returnType, function, std::move(arguments))); } diff --git a/src/sksl/SkSLIRGenerator.h b/src/sksl/SkSLIRGenerator.h index f456915877..0effeb4fa9 100644 --- a/src/sksl/SkSLIRGenerator.h +++ b/src/sksl/SkSLIRGenerator.h @@ -167,7 +167,6 @@ private: // returns a statement which converts sk_Position from device to normalized coordinates std::unique_ptr getNormalizeSkPositionCode(); - void fixRectSampling(std::vector>& arguments); void checkValid(const Expression& expr); void setRefKind(const Expression& expr, VariableReference::RefKind kind); void getConstantInt(const Expression& value, int64_t* out); diff --git a/tests/SkSLGLSLTest.cpp b/tests/SkSLGLSLTest.cpp index 8d12dcc433..64e14062b4 100644 --- a/tests/SkSLGLSLTest.cpp +++ b/tests/SkSLGLSLTest.cpp @@ -1562,7 +1562,7 @@ DEF_TEST(SkSLRectangleTexture, r) { "out vec4 sk_FragColor;\n" "uniform sampler2DRect test;\n" "void main() {\n" - " sk_FragColor = texture(test, textureSize(test) * vec2(0.5));\n" + " sk_FragColor = texture(test, vec2(0.5));\n" "}\n"); test(r, "uniform sampler2DRect test;" @@ -1574,7 +1574,7 @@ DEF_TEST(SkSLRectangleTexture, r) { "out vec4 sk_FragColor;\n" "uniform sampler2DRect test;\n" "void main() {\n" - " sk_FragColor = texture(test, vec3(textureSize(test), 1.0) * vec3(0.5));\n" + " sk_FragColor = texture(test, vec3(0.5));\n" "}\n"); }