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 <brianosman@google.com>
Commit-Queue: Brian Salomon <bsalomon@google.com>
diff --git a/gm/rectangletexture.cpp b/gm/rectangletexture.cpp
index 325e29a..4d4e1df 100644
--- a/gm/rectangletexture.cpp
+++ b/gm/rectangletexture.cpp
@@ -30,9 +30,7 @@
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 @@
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 @@
SkIntToScalar(width + height) / 5, paint);
}
- sk_sp<SkImage> createRectangleTextureImg(GrContext* context, int width, int height,
- void* pixels) {
+ sk_sp<SkImage> createRectangleTextureImg(GrContext* context, GrSurfaceOrigin origin, int width,
+ int height, const uint32_t* pixels) {
if (!context) {
return nullptr;
}
@@ -88,34 +86,36 @@
}
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<uint32_t[]> 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<SkImage> image = SkImage::MakeFromAdoptedTexture(context, rectangleTex,
- kTopLeft_GrSurfaceOrigin,
+ if (sk_sp<SkImage> image = SkImage::MakeFromAdoptedTexture(context, rectangleTex, origin,
kRGBA_8888_SkColorType)) {
return image;
}
@@ -136,9 +136,15 @@
SkPMColor pixels[kWidth * kHeight];
this->fillPixels(kWidth, kHeight, pixels);
- sk_sp<SkImage> rectImg(this->createRectangleTextureImg(context, kWidth, kHeight, pixels));
- if (!rectImg) {
+ sk_sp<SkImage> 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 @@
}
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 86cde4d..e9fd0a3 100644
--- a/include/private/GrTypesPriv.h
+++ b/include/private/GrTypesPriv.h
@@ -358,6 +358,7 @@
*/
enum class GrTextureType {
k2D,
+ /* Rectangle uses unnormalized texture coordinates. */
kRectangle,
kExternal
};
diff --git a/src/gpu/GrCoordTransform.h b/src/gpu/GrCoordTransform.h
index 43405f2..aee2253 100644
--- a/src/gpu/GrCoordTransform.h
+++ b/src/gpu/GrCoordTransform.h
@@ -36,7 +36,7 @@
GrCoordTransform(GrTextureProxy* proxy) {
SkASSERT(proxy);
SkDEBUGCODE(fInProcessor = false);
- this->reset(SkMatrix::I(), proxy, true);
+ this->reset(SkMatrix::I(), proxy);
}
/**
@@ -46,7 +46,7 @@
GrCoordTransform(const SkMatrix& m, GrTextureProxy* proxy) {
SkASSERT(proxy);
SkDEBUGCODE(fInProcessor = false);
- this->reset(m, proxy, true);
+ this->reset(m, proxy);
}
/**
@@ -57,24 +57,6 @@
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 @@
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 d8df5ac..28a47cd 100644
--- a/src/gpu/effects/GrTextureDomain.cpp
+++ b/src/gpu/effects/GrTextureDomain.cpp
@@ -165,8 +165,15 @@
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 @@
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 6cdcce9..3d94402 100644
--- a/src/gpu/effects/GrYUVtoRGBEffect.h
+++ b/src/gpu/effects/GrYUVtoRGBEffect.h
@@ -42,7 +42,8 @@
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 73e1f9d..9f26a7c 100644
--- a/src/gpu/gl/GrGLCaps.cpp
+++ b/src/gpu/gl/GrGLCaps.cpp
@@ -227,11 +227,7 @@
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 df10ffd..63bf032 100644
--- a/src/gpu/gl/GrGLGpu.cpp
+++ b/src/gpu/gl/GrGLGpu.cpp
@@ -3739,11 +3739,13 @@
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 fb6e7f2..8e6099e 100644
--- a/src/gpu/glsl/GrGLSLPrimitiveProcessor.cpp
+++ b/src/gpu/glsl/GrGLSLPrimitiveProcessor.cpp
@@ -24,14 +24,26 @@
}
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 255f937..7ef5896 100644
--- a/src/gpu/ops/GrTextureOp.cpp
+++ b/src/gpu/ops/GrTextureOp.cpp
@@ -54,9 +54,11 @@
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 @@
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 @@
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 @@
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 @@
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 b0e3b58..b0d464b 100644
--- a/src/shaders/SkPerlinNoiseShader.cpp
+++ b/src/shaders/SkPerlinNoiseShader.cpp
@@ -768,7 +768,7 @@
, fNoiseSampler(std::move(noiseProxy))
, fPaintingData(std::move(paintingData)) {
this->setTextureSamplerCnt(2);
- fCoordTransform.reset(matrix);
+ fCoordTransform = GrCoordTransform(matrix);
this->addCoordTransform(&fCoordTransform);
}
@@ -1191,7 +1191,7 @@
, 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 3374630..6f9fcd9 100644
--- a/src/sksl/SkSLIRGenerator.cpp
+++ b/src/sksl/SkSLIRGenerator.cpp
@@ -1549,37 +1549,6 @@
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<std::unique_ptr<Expression>>& 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<std::unique_ptr<Expression>> sizeArguments;
- sizeArguments.emplace_back(new VariableReference(-1, sampler));
- std::unique_ptr<Expression> float2ize = call(-1, textureSize, std::move(sizeArguments));
- const Type& type = arguments[1]->fType;
- std::unique_ptr<Expression> scale;
- if (type == *fContext.fFloat2_Type) {
- scale = std::move(float2ize);
- } else {
- SkASSERT(type == *fContext.fFloat3_Type);
- std::vector<std::unique_ptr<Expression>> 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<Expression> IRGenerator::call(int offset,
const FunctionDeclaration& function,
std::vector<std::unique_ptr<Expression>> arguments) {
@@ -1620,10 +1589,6 @@
VariableReference::kPointer_RefKind);
}
}
- if (function.fBuiltin && function.fName == "texture" &&
- arguments[0]->fType == *fContext.fSampler2DRect_Type) {
- this->fixRectSampling(arguments);
- }
return std::unique_ptr<FunctionCall>(new FunctionCall(offset, *returnType, function,
std::move(arguments)));
}
diff --git a/src/sksl/SkSLIRGenerator.h b/src/sksl/SkSLIRGenerator.h
index f456915..0effeb4 100644
--- a/src/sksl/SkSLIRGenerator.h
+++ b/src/sksl/SkSLIRGenerator.h
@@ -167,7 +167,6 @@
// returns a statement which converts sk_Position from device to normalized coordinates
std::unique_ptr<Statement> getNormalizeSkPositionCode();
- void fixRectSampling(std::vector<std::unique_ptr<Expression>>& 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 8d12dcc..64e1406 100644
--- a/tests/SkSLGLSLTest.cpp
+++ b/tests/SkSLGLSLTest.cpp
@@ -1562,7 +1562,7 @@
"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 @@
"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");
}