SkVector4 as ctype for half4

Use in GrColorMatrixFragmentProcessor.

Also make GrColorMatrixFragmentProcessor::Make() call
SkMatrix44::set4x4().


9bf803677ea133368178e1eb23e120dd823da151

Bug: skia:8962
Change-Id: I2476f4af03b4e43cc843e6eda28673d1c2454acc
Reviewed-on: https://skia-review.googlesource.com/c/skia/+/217496
Commit-Queue: Brian Osman <brianosman@google.com>
Auto-Submit: Brian Salomon <bsalomon@google.com>
Reviewed-by: Brian Osman <brianosman@google.com>
This commit is contained in:
Brian Salomon 2019-06-01 11:18:15 -04:00 committed by Skia Commit-Bot
parent 3c0ad02bc5
commit eca66b32fd
9 changed files with 47 additions and 33 deletions

View File

@ -111,13 +111,11 @@ struct SkVector4 {
return *this;
}
bool operator==(const SkVector4& v) {
bool operator==(const SkVector4& v) const {
return fData[0] == v.fData[0] && fData[1] == v.fData[1] &&
fData[2] == v.fData[2] && fData[3] == v.fData[3];
}
bool operator!=(const SkVector4& v) {
return !(*this == v);
}
bool operator!=(const SkVector4& v) const { return !(*this == v); }
bool equals(SkScalar x, SkScalar y, SkScalar z, SkScalar w = SK_Scalar1) {
return fData[0] == x && fData[1] == y &&
fData[2] == z && fData[3] == w;

View File

@ -6,7 +6,7 @@
*/
layout(ctype=SkMatrix44, tracked) in uniform half4x4 m;
layout(ctype=SkRect, tracked) in uniform half4 v;
layout(ctype=SkVector4, tracked) in uniform half4 v;
layout(key) in bool unpremulInput;
layout(key) in bool clampRGBOutput;
layout(key) in bool premulOutput;
@ -46,10 +46,10 @@ void main() {
color.fA = input.fA;
}
m.mapScalars(color.vec());
color.fR += v.fLeft;
color.fG += v.fTop;
color.fB += v.fRight;
color.fA += v.fBottom;
color.fR += v.fData[0];
color.fG += v.fData[1];
color.fB += v.fData[2];
color.fA += v.fData[3];
color.fA = SkTPin(color.fA, 0.f, 1.f);
if (clampRGBOutput) {
color.fR = SkTPin(color.fR, 0.f, 1.f);
@ -66,15 +66,14 @@ void main() {
@make {
static std::unique_ptr<GrFragmentProcessor> Make(const float matrix[20], bool unpremulInput, bool clampRGBOutput, bool premulOutput) {
const float m[] {
matrix[0], matrix[1], matrix[2], matrix[3],
matrix[5], matrix[6], matrix[7], matrix[8],
matrix[10], matrix[11], matrix[12], matrix[13],
matrix[15], matrix[16], matrix[17], matrix[18]
};
SkMatrix44 m44;
m44.setRowMajorf(m);
SkRect v4 = SkRect::MakeLTRB(matrix[4], matrix[9], matrix[14], matrix[19]);
m44.set4x4(
matrix[0], matrix[5], matrix[10], matrix[15],
matrix[1], matrix[6], matrix[11], matrix[16],
matrix[2], matrix[7], matrix[12], matrix[17],
matrix[3], matrix[8], matrix[13], matrix[18]
);
auto v4 = SkVector4(matrix[4], matrix[9], matrix[14], matrix[19]);
return std::unique_ptr<GrFragmentProcessor>(new GrColorMatrixFragmentProcessor(m44, v4, unpremulInput, clampRGBOutput, premulOutput));
}
}

View File

@ -60,15 +60,15 @@ private:
mPrev = mValue;
pdman.setSkMatrix44(mVar, mValue);
}
const SkRect& vValue = _outer.v;
if (vPrev.isEmpty() || vPrev != vValue) {
const SkVector4& vValue = _outer.v;
if (vPrev != (vValue)) {
vPrev = vValue;
pdman.set4fv(vVar, 1, reinterpret_cast<const float*>(&vValue));
pdman.set4fv(vVar, 1, vValue.fData);
}
}
}
SkMatrix44 mPrev = SkMatrix44(SkMatrix44::kNaN_Constructor);
SkRect vPrev = SkRect::MakeEmpty();
SkVector4 vPrev = SkVector4(SK_MScalarNaN, SK_MScalarNaN, SK_MScalarNaN, SK_MScalarNaN);
UniformHandle mVar;
UniformHandle vVar;
};

View File

@ -27,10 +27,10 @@ public:
color.fA = input.fA;
}
m.mapScalars(color.vec());
color.fR += v.fLeft;
color.fG += v.fTop;
color.fB += v.fRight;
color.fA += v.fBottom;
color.fR += v.fData[0];
color.fG += v.fData[1];
color.fB += v.fData[2];
color.fA += v.fData[3];
color.fA = SkTPin(color.fA, 0.f, 1.f);
if (clampRGBOutput) {
color.fR = SkTPin(color.fR, 0.f, 1.f);
@ -46,12 +46,11 @@ public:
static std::unique_ptr<GrFragmentProcessor> Make(const float matrix[20], bool unpremulInput,
bool clampRGBOutput, bool premulOutput) {
const float m[]{matrix[0], matrix[1], matrix[2], matrix[3], matrix[5], matrix[6],
matrix[7], matrix[8], matrix[10], matrix[11], matrix[12], matrix[13],
matrix[15], matrix[16], matrix[17], matrix[18]};
SkMatrix44 m44;
m44.setRowMajorf(m);
SkRect v4 = SkRect::MakeLTRB(matrix[4], matrix[9], matrix[14], matrix[19]);
m44.set4x4(matrix[0], matrix[5], matrix[10], matrix[15], matrix[1], matrix[6], matrix[11],
matrix[16], matrix[2], matrix[7], matrix[12], matrix[17], matrix[3], matrix[8],
matrix[13], matrix[18]);
auto v4 = SkVector4(matrix[4], matrix[9], matrix[14], matrix[19]);
return std::unique_ptr<GrFragmentProcessor>(new GrColorMatrixFragmentProcessor(
m44, v4, unpremulInput, clampRGBOutput, premulOutput));
}
@ -59,14 +58,14 @@ public:
std::unique_ptr<GrFragmentProcessor> clone() const override;
const char* name() const override { return "ColorMatrixFragmentProcessor"; }
SkMatrix44 m;
SkRect v;
SkVector4 v;
bool unpremulInput;
bool clampRGBOutput;
bool premulOutput;
private:
GrColorMatrixFragmentProcessor(SkMatrix44 m, SkRect v, bool unpremulInput, bool clampRGBOutput,
bool premulOutput)
GrColorMatrixFragmentProcessor(SkMatrix44 m, SkVector4 v, bool unpremulInput,
bool clampRGBOutput, bool premulOutput)
: INHERITED(kGrColorMatrixFragmentProcessor_ClassID,
(OptimizationFlags)kConstantOutputForConstantInput_OptimizationFlag)
, m(m)

View File

@ -207,6 +207,12 @@ void CPPCodeGenerator::writeRuntimeValue(const Type& type, const Layout& layout,
fFormatArgs.push_back(cppCode + ".fB");
fFormatArgs.push_back(cppCode + ".fA");
break;
case Layout::CType::kSkVector4:
fFormatArgs.push_back(cppCode + ".fData[0]");
fFormatArgs.push_back(cppCode + ".fData[1]");
fFormatArgs.push_back(cppCode + ".fData[2]");
fFormatArgs.push_back(cppCode + ".fData[3]");
break;
case Layout::CType::kSkRect: // fall through
case Layout::CType::kDefault:
fFormatArgs.push_back(cppCode + ".left()");

View File

@ -161,6 +161,11 @@ static const std::vector<UniformCTypeMapper>& get_mappers() {
"${pdman}.set4fv(${uniform}, 1, ${var}.vec())", // to gpu
"{SK_FloatNaN, SK_FloatNaN, SK_FloatNaN, SK_FloatNaN}"), // default value
REGISTER(Layout::CType::kSkVector4, { "half4", "float4", "double4" },
"${pdman}.set4fv(${uniform}, 1, ${var}.fData)", // to gpu
"SkVector4(SK_MScalarNaN, SK_MScalarNaN, SK_MScalarNaN, SK_MScalarNaN)", // default value
"${oldVar} != (${newVar})"), // dirty check
REGISTER(Layout::CType::kSkPoint, { "half2", "float2", "double2" } ,
"${pdman}.set2f(${uniform}, ${var}.fX, ${var}.fY)", // to gpu
"SkPoint::Make(SK_FloatNaN, SK_FloatNaN)"), // default value

View File

@ -123,6 +123,7 @@ void Parser::InitLayoutMap() {
TOKEN(TRACKED, "tracked");
TOKEN(CTYPE, "ctype");
TOKEN(SKPMCOLOR4F, "SkPMColor4f");
TOKEN(SKVECTOR4, "SkVector4");
TOKEN(SKRECT, "SkRect");
TOKEN(SKIRECT, "SkIRect");
TOKEN(SKPMCOLOR, "SkPMColor");
@ -738,6 +739,8 @@ Layout::CType Parser::layoutCType() {
switch (found->second) {
case LayoutToken::SKPMCOLOR4F:
return Layout::CType::kSkPMColor4f;
case LayoutToken::SKVECTOR4:
return Layout::CType::kSkVector4;
case LayoutToken::SKRECT:
return Layout::CType::kSkRect;
case LayoutToken::SKIRECT:

View File

@ -92,6 +92,7 @@ public:
TRACKED,
CTYPE,
SKPMCOLOR4F,
SKVECTOR4,
SKRECT,
SKIRECT,
SKPMCOLOR,

View File

@ -86,6 +86,7 @@ struct Layout {
kSkIRect,
kSkPMColor4f,
kSkPMColor,
kSkVector4,
kSkPoint,
kSkIPoint,
kSkMatrix,
@ -158,6 +159,8 @@ struct Layout {
return "SkPMColor4f";
case CType::kSkPMColor:
return "SkPMColor";
case CType::kSkVector4:
return "SkVector4";
case CType::kSkPoint:
return "SkPoint";
case CType::kSkIPoint: