Skip to content

Commit

Permalink
Rename localMatrix to uvMatrix for better clarity. (#234)
Browse files Browse the repository at this point in the history
Co-authored-by: ffjiefan <[email protected]>
  • Loading branch information
Fjie and Fjie authored Sep 20, 2024
1 parent da33896 commit 9437205
Show file tree
Hide file tree
Showing 67 changed files with 212 additions and 206 deletions.
8 changes: 5 additions & 3 deletions include/tgfx/core/Image.h
Original file line number Diff line number Diff line change
Expand Up @@ -287,9 +287,11 @@ class Image {
virtual std::shared_ptr<TextureProxy> lockTextureProxy(Context* context,
uint32_t renderFlags = 0) const;

virtual std::unique_ptr<FragmentProcessor> asFragmentProcessor(
const FPArgs& args, TileMode tileModeX, TileMode tileModeY, const SamplingOptions& sampling,
const Matrix* localMatrix) const = 0;
virtual std::unique_ptr<FragmentProcessor> asFragmentProcessor(const FPArgs& args,
TileMode tileModeX,
TileMode tileModeY,
const SamplingOptions& sampling,
const Matrix* uvMatrix) const = 0;

friend class FragmentProcessor;
friend class RuntimeImageFilter;
Expand Down
9 changes: 5 additions & 4 deletions include/tgfx/core/ImageFilter.h
Original file line number Diff line number Diff line change
Expand Up @@ -114,9 +114,10 @@ class ImageFilter {
* Returns a FragmentProcessor that applies this filter to the source image. The returned
* processor is in the coordinate space of the source image.
*/
virtual std::unique_ptr<FragmentProcessor> asFragmentProcessor(
std::shared_ptr<Image> source, const FPArgs& args, const SamplingOptions& sampling,
const Matrix* localMatrix) const = 0;
virtual std::unique_ptr<FragmentProcessor> asFragmentProcessor(std::shared_ptr<Image> source,
const FPArgs& args,
const SamplingOptions& sampling,
const Matrix* uvMatrix) const = 0;

/**
* Returns true if this filter is a ComposeImageFilter.
Expand All @@ -130,7 +131,7 @@ class ImageFilter {
std::unique_ptr<FragmentProcessor> makeFPFromFilteredImage(std::shared_ptr<Image> source,
const FPArgs& args,
const SamplingOptions& sampling,
const Matrix* localMatrix) const;
const Matrix* uvMatrix) const;

friend class DropShadowImageFilter;
friend class ComposeImageFilter;
Expand Down
4 changes: 2 additions & 2 deletions include/tgfx/core/MaskFilter.h
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,8 @@ class MaskFilter {
virtual ~MaskFilter() = default;

private:
virtual std::unique_ptr<FragmentProcessor> asFragmentProcessor(
const FPArgs& args, const Matrix* localMatrix) const = 0;
virtual std::unique_ptr<FragmentProcessor> asFragmentProcessor(const FPArgs& args,
const Matrix* uvMatrix) const = 0;

friend class RenderContext;
};
Expand Down
4 changes: 2 additions & 2 deletions include/tgfx/core/Shader.h
Original file line number Diff line number Diff line change
Expand Up @@ -135,8 +135,8 @@ class Shader {
protected:
std::weak_ptr<Shader> weakThis;

virtual std::unique_ptr<FragmentProcessor> asFragmentProcessor(
const FPArgs& args, const Matrix* localMatrix) const = 0;
virtual std::unique_ptr<FragmentProcessor> asFragmentProcessor(const FPArgs& args,
const Matrix* uvMatrix) const = 0;

friend class FragmentProcessor;
friend class Canvas;
Expand Down
10 changes: 5 additions & 5 deletions src/core/ImageFilter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -70,11 +70,11 @@ bool ImageFilter::applyCropRect(const Rect& srcRect, Rect* dstRect, const Rect*

std::unique_ptr<FragmentProcessor> ImageFilter::makeFPFromFilteredImage(
std::shared_ptr<Image> source, const FPArgs& args, const SamplingOptions& sampling,
const Matrix* localMatrix) const {
const Matrix* uvMatrix) const {
auto inputBounds = Rect::MakeWH(source->width(), source->height());
auto clipBounds = args.drawRect;
if (localMatrix) {
clipBounds = localMatrix->mapRect(clipBounds);
if (uvMatrix) {
clipBounds = uvMatrix->mapRect(clipBounds);
}
Rect dstBounds = Rect::MakeEmpty();
if (!applyCropRect(inputBounds, &dstBounds, &clipBounds)) {
Expand All @@ -86,8 +86,8 @@ std::unique_ptr<FragmentProcessor> ImageFilter::makeFPFromFilteredImage(
return nullptr;
}
auto fpMatrix = Matrix::MakeTrans(-dstBounds.x(), -dstBounds.y());
if (localMatrix != nullptr) {
fpMatrix.preConcat(*localMatrix);
if (uvMatrix != nullptr) {
fpMatrix.preConcat(*uvMatrix);
}
return TextureEffect::Make(std::move(textureProxy), sampling, &fpMatrix);
}
Expand Down
10 changes: 5 additions & 5 deletions src/filters/BlurImageFilter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -88,15 +88,15 @@ void BlurImageFilter::draw(std::shared_ptr<RenderTargetProxy> renderTarget,
const Rect& imageBounds, bool isDown) const {
auto dstWidth = static_cast<float>(renderTarget->width());
auto dstHeight = static_cast<float>(renderTarget->height());
auto localMatrix =
auto uvMatrix =
Matrix::MakeScale(imageBounds.width() / dstWidth, imageBounds.height() / dstHeight);
localMatrix.postTranslate(imageBounds.x(), imageBounds.y());
uvMatrix.postTranslate(imageBounds.x(), imageBounds.y());
auto texelSize = Size::Make(0.5f / imageBounds.width(), 0.5f / imageBounds.height());
auto blurProcessor =
DualBlurFragmentProcessor::Make(isDown ? DualBlurPassMode::Down : DualBlurPassMode::Up,
std::move(imageProcessor), blurOffset, texelSize);
OpContext opContext(std::move(renderTarget), true);
opContext.fillWithFP(std::move(blurProcessor), localMatrix);
opContext.fillWithFP(std::move(blurProcessor), uvMatrix);
}

Rect BlurImageFilter::onFilterBounds(const Rect& srcRect) const {
Expand Down Expand Up @@ -149,7 +149,7 @@ std::shared_ptr<TextureProxy> BlurImageFilter::onFilterImage(Context* context,

std::unique_ptr<FragmentProcessor> BlurImageFilter::asFragmentProcessor(
std::shared_ptr<Image> source, const FPArgs& args, const SamplingOptions& sampling,
const Matrix* localMatrix) const {
return makeFPFromFilteredImage(source, args, sampling, localMatrix);
const Matrix* uvMatrix) const {
return makeFPFromFilteredImage(source, args, sampling, uvMatrix);
}
} // namespace tgfx
2 changes: 1 addition & 1 deletion src/filters/BlurImageFilter.h
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ class BlurImageFilter : public ImageFilter {
std::unique_ptr<FragmentProcessor> asFragmentProcessor(std::shared_ptr<Image> source,
const FPArgs& args,
const SamplingOptions& sampling,
const Matrix* localMatrix) const override;
const Matrix* uvMatrix) const override;

void draw(std::shared_ptr<RenderTargetProxy> renderTarget,
std::unique_ptr<FragmentProcessor> imageProcessor, const Rect& imageBounds,
Expand Down
10 changes: 5 additions & 5 deletions src/filters/ComposeImageFilter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -73,11 +73,11 @@ Rect ComposeImageFilter::onFilterBounds(const Rect& srcRect) const {

std::unique_ptr<FragmentProcessor> ComposeImageFilter::asFragmentProcessor(
std::shared_ptr<Image> source, const FPArgs& args, const SamplingOptions& sampling,
const Matrix* localMatrix) const {
const Matrix* uvMatrix) const {
auto bounds = Rect::MakeWH(source->width(), source->height());
auto drawBounds = args.drawRect;
if (localMatrix) {
drawBounds = localMatrix->mapRect(drawBounds);
if (uvMatrix) {
drawBounds = uvMatrix->mapRect(drawBounds);
}
bool hasMipmaps = source->hasMipmaps() && sampling.mipmapMode != MipmapMode::None;
auto count = filters.size() - 1;
Expand All @@ -98,8 +98,8 @@ std::unique_ptr<FragmentProcessor> ComposeImageFilter::asFragmentProcessor(
lastOffset.offset(bounds.x(), bounds.y());
}
auto matrix = Matrix::MakeTrans(-lastOffset.x, -lastOffset.y);
if (localMatrix) {
matrix.preConcat(*localMatrix);
if (uvMatrix) {
matrix.preConcat(*uvMatrix);
}
return filters.back()->asFragmentProcessor(std::move(lastSource), args, sampling, &matrix);
}
Expand Down
2 changes: 1 addition & 1 deletion src/filters/ComposeImageFilter.h
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ class ComposeImageFilter : public ImageFilter {
std::unique_ptr<FragmentProcessor> asFragmentProcessor(std::shared_ptr<Image> source,
const FPArgs& args,
const SamplingOptions& sampling,
const Matrix* localMatrix) const override;
const Matrix* uvMatrix) const override;

bool isComposeFilter() const override {
return true;
Expand Down
8 changes: 4 additions & 4 deletions src/filters/DropShadowImageFilter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -55,13 +55,13 @@ Rect DropShadowImageFilter::onFilterBounds(const Rect& srcRect) const {

std::unique_ptr<FragmentProcessor> DropShadowImageFilter::asFragmentProcessor(
std::shared_ptr<Image> source, const FPArgs& args, const SamplingOptions& sampling,
const Matrix* localMatrix) const {
const Matrix* uvMatrix) const {
// Request a rasterized image, does nothing if the source is not already rasterized.
source = source->makeRasterized();
std::unique_ptr<FragmentProcessor> shadowProcessor;
auto shadowMatrix = Matrix::MakeTrans(-dx, -dy);
if (localMatrix != nullptr) {
shadowMatrix.preConcat(*localMatrix);
if (uvMatrix != nullptr) {
shadowMatrix.preConcat(*uvMatrix);
}
if (blurFilter != nullptr) {
shadowProcessor = blurFilter->asFragmentProcessor(source, args, sampling, &shadowMatrix);
Expand All @@ -79,7 +79,7 @@ std::unique_ptr<FragmentProcessor> DropShadowImageFilter::asFragmentProcessor(
return colorShadowProcessor;
}
auto imageProcessor = FragmentProcessor::Make(std::move(source), args, TileMode::Decal,
TileMode::Decal, sampling, localMatrix);
TileMode::Decal, sampling, uvMatrix);
return XfermodeFragmentProcessor::MakeFromTwoProcessors(
std::move(imageProcessor), std::move(colorShadowProcessor), BlendMode::SrcOver);
}
Expand Down
2 changes: 1 addition & 1 deletion src/filters/DropShadowImageFilter.h
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,6 @@ class DropShadowImageFilter : public ImageFilter {
std::unique_ptr<FragmentProcessor> asFragmentProcessor(std::shared_ptr<Image> source,
const FPArgs& args,
const SamplingOptions& sampling,
const Matrix* localMatrix) const override;
const Matrix* uvMatrix) const override;
};
} // namespace tgfx
4 changes: 2 additions & 2 deletions src/filters/RuntimeImageFilter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ std::shared_ptr<TextureProxy> RuntimeImageFilter::onFilterImage(Context* context

std::unique_ptr<FragmentProcessor> RuntimeImageFilter::asFragmentProcessor(
std::shared_ptr<Image> source, const FPArgs& args, const SamplingOptions& sampling,
const Matrix* localMatrix) const {
return makeFPFromFilteredImage(source, args, sampling, localMatrix);
const Matrix* uvMatrix) const {
return makeFPFromFilteredImage(source, args, sampling, uvMatrix);
}
} // namespace tgfx
2 changes: 1 addition & 1 deletion src/filters/RuntimeImageFilter.h
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ class RuntimeImageFilter : public ImageFilter {
std::unique_ptr<FragmentProcessor> asFragmentProcessor(std::shared_ptr<Image> source,
const FPArgs& args,
const SamplingOptions& sampling,
const Matrix* localMatrix) const override;
const Matrix* uvMatrix) const override;

private:
std::shared_ptr<RuntimeEffect> effect = nullptr;
Expand Down
4 changes: 2 additions & 2 deletions src/filters/ShaderMaskFilter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,8 @@ std::shared_ptr<MaskFilter> MaskFilter::MakeShader(std::shared_ptr<Shader> shade
}

std::unique_ptr<FragmentProcessor> ShaderMaskFilter::asFragmentProcessor(
const FPArgs& args, const Matrix* localMatrix) const {
auto processor = FragmentProcessor::Make(shader, args, localMatrix);
const FPArgs& args, const Matrix* uvMatrix) const {
auto processor = FragmentProcessor::Make(shader, args, uvMatrix);
return FragmentProcessor::MulInputByChildAlpha(std::move(processor), inverted);
}
} // namespace tgfx
2 changes: 1 addition & 1 deletion src/filters/ShaderMaskFilter.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ class ShaderMaskFilter : public MaskFilter {

protected:
std::unique_ptr<FragmentProcessor> asFragmentProcessor(const FPArgs& args,
const Matrix* localMatrix) const override;
const Matrix* uvMatrix) const override;

private:
std::shared_ptr<Shader> shader;
Expand Down
8 changes: 4 additions & 4 deletions src/gpu/OpContext.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,21 +28,21 @@ OpContext::~OpContext() {
}
}

void OpContext::fillWithFP(std::unique_ptr<FragmentProcessor> fp, const Matrix& localMatrix) {
void OpContext::fillWithFP(std::unique_ptr<FragmentProcessor> fp, const Matrix& uvMatrix) {
fillRectWithFP(Rect::MakeWH(renderTargetProxy->width(), renderTargetProxy->height()),
std::move(fp), localMatrix);
std::move(fp), uvMatrix);
if (autoResolve) {
auto drawingManager = renderTargetProxy->getContext()->drawingManager();
drawingManager->addTextureResolveTask(renderTargetProxy);
}
}

void OpContext::fillRectWithFP(const Rect& dstRect, std::unique_ptr<FragmentProcessor> fp,
const Matrix& localMatrix) {
const Matrix& uvMatrix) {
if (fp == nullptr) {
return;
}
auto op = FillRectOp::Make(std::nullopt, dstRect, Matrix::I(), &localMatrix);
auto op = FillRectOp::Make(std::nullopt, dstRect, Matrix::I(), &uvMatrix);
op->addColorFP(std::move(fp));
op->setBlendMode(BlendMode::Src);
addOp(std::move(op));
Expand Down
4 changes: 2 additions & 2 deletions src/gpu/OpContext.h
Original file line number Diff line number Diff line change
Expand Up @@ -41,10 +41,10 @@ class OpContext {
return renderTargetProxy.get();
}

void fillWithFP(std::unique_ptr<FragmentProcessor> fp, const Matrix& localMatrix);
void fillWithFP(std::unique_ptr<FragmentProcessor> fp, const Matrix& uvMatrix);

void fillRectWithFP(const Rect& dstRect, std::unique_ptr<FragmentProcessor> fp,
const Matrix& localMatrix);
const Matrix& uvMatrix);

void addOp(std::unique_ptr<Op> op);

Expand Down
10 changes: 5 additions & 5 deletions src/gpu/RenderContext.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -184,12 +184,12 @@ void RenderContext::drawPath(const Path& path, const MCState& state, const FillS
}

static std::unique_ptr<FragmentProcessor> CreateMaskFP(std::shared_ptr<TextureProxy> textureProxy,
const Matrix* localMatrix = nullptr) {
const Matrix* uvMatrix = nullptr) {
if (textureProxy == nullptr) {
return nullptr;
}
auto isAlphaOnly = textureProxy->isAlphaOnly();
auto processor = TextureEffect::Make(std::move(textureProxy), {}, localMatrix);
auto processor = TextureEffect::Make(std::move(textureProxy), {}, uvMatrix);
if (processor == nullptr) {
return nullptr;
}
Expand Down Expand Up @@ -449,9 +449,9 @@ std::unique_ptr<FragmentProcessor> RenderContext::getClipMask(const Path& clip,
if (texture == nullptr) {
return nullptr;
}
auto localMatrix = viewMatrix;
localMatrix.postTranslate(-clipBounds.left, -clipBounds.top);
auto maskEffect = TextureEffect::Make(texture, {}, &localMatrix);
auto uvMatrix = viewMatrix;
uvMatrix.postTranslate(-clipBounds.left, -clipBounds.top);
auto maskEffect = TextureEffect::Make(texture, {}, &uvMatrix);
if (!texture->isAlphaOnly()) {
maskEffect = FragmentProcessor::MulInputByChildAlpha(std::move(maskEffect));
}
Expand Down
24 changes: 12 additions & 12 deletions src/gpu/ops/FillRectOp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,15 +28,15 @@ namespace tgfx {
class RectPaint {
public:
RectPaint(std::optional<Color> color, const Rect& rect, const Matrix& viewMatrix,
const Matrix* localMatrix)
const Matrix* uvMatrix)
: color(color.value_or(Color::White())), rect(rect), viewMatrix(viewMatrix),
localMatrix(localMatrix ? *localMatrix : Matrix::I()) {
uvMatrix(uvMatrix ? *uvMatrix : Matrix::I()) {
}

Color color;
Rect rect;
Matrix viewMatrix;
Matrix localMatrix;
Matrix uvMatrix;
};

class RectCoverageVerticesProvider : public DataProvider {
Expand All @@ -53,7 +53,7 @@ class RectCoverageVerticesProvider : public DataProvider {
for (auto& rectPaint : rectPaints) {
auto& viewMatrix = rectPaint->viewMatrix;
auto& rect = rectPaint->rect;
auto& localMatrix = rectPaint->localMatrix;
auto& uvMatrix = rectPaint->uvMatrix;
auto scale = sqrtf(viewMatrix.getScaleX() * viewMatrix.getScaleX() +
viewMatrix.getSkewY() * viewMatrix.getSkewY());
// we want the new edge to be .5px away from the old line.
Expand All @@ -63,8 +63,8 @@ class RectCoverageVerticesProvider : public DataProvider {
auto outsetBounds = rect.makeOutset(padding, padding);
auto outsetQuad = Quad::MakeFromRect(outsetBounds, viewMatrix);

auto normalInsetQuad = Quad::MakeFromRect(insetBounds, localMatrix);
auto normalOutsetQuad = Quad::MakeFromRect(outsetBounds, localMatrix);
auto normalInsetQuad = Quad::MakeFromRect(insetBounds, uvMatrix);
auto normalOutsetQuad = Quad::MakeFromRect(outsetBounds, uvMatrix);

for (int j = 0; j < 2; ++j) {
const auto& quad = j == 0 ? insetQuad : outsetQuad;
Expand Down Expand Up @@ -108,9 +108,9 @@ class RectNonCoverageVerticesProvider : public DataProvider {
for (auto& rectPaint : rectPaints) {
auto& viewMatrix = rectPaint->viewMatrix;
auto& rect = rectPaint->rect;
auto& localMatrix = rectPaint->localMatrix;
auto& uvMatrix = rectPaint->uvMatrix;
auto quad = Quad::MakeFromRect(rect, viewMatrix);
auto localQuad = Quad::MakeFromRect(rect, localMatrix);
auto localQuad = Quad::MakeFromRect(rect, uvMatrix);
for (size_t j = 4; j >= 1; --j) {
vertices[index++] = quad.point(j - 1).x;
vertices[index++] = quad.point(j - 1).y;
Expand All @@ -134,14 +134,14 @@ class RectNonCoverageVerticesProvider : public DataProvider {
};

std::unique_ptr<FillRectOp> FillRectOp::Make(std::optional<Color> color, const Rect& rect,
const Matrix& viewMatrix, const Matrix* localMatrix) {
return std::unique_ptr<FillRectOp>(new FillRectOp(color, rect, viewMatrix, localMatrix));
const Matrix& viewMatrix, const Matrix* uvMatrix) {
return std::unique_ptr<FillRectOp>(new FillRectOp(color, rect, viewMatrix, uvMatrix));
}

FillRectOp::FillRectOp(std::optional<Color> color, const Rect& rect, const Matrix& viewMatrix,
const Matrix* localMatrix)
const Matrix* uvMatrix)
: DrawOp(ClassID()), hasColor(color) {
auto rectPaint = std::make_shared<RectPaint>(color, rect, viewMatrix, localMatrix);
auto rectPaint = std::make_shared<RectPaint>(color, rect, viewMatrix, uvMatrix);
rectPaints.push_back(std::move(rectPaint));
auto bounds = viewMatrix.mapRect(rect);
setBounds(bounds);
Expand Down
4 changes: 2 additions & 2 deletions src/gpu/ops/FillRectOp.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,15 +30,15 @@ class FillRectOp : public DrawOp {

static std::unique_ptr<FillRectOp> Make(std::optional<Color> color, const Rect& rect,
const Matrix& viewMatrix,
const Matrix* localMatrix = nullptr);
const Matrix* uvMatrix = nullptr);

void prepare(Context* context) override;

void execute(RenderPass* renderPass) override;

private:
FillRectOp(std::optional<Color> color, const Rect& rect, const Matrix& viewMatrix,
const Matrix* localMatrix = nullptr);
const Matrix* uvMatrix = nullptr);

bool onCombineIfPossible(Op* op) override;

Expand Down
Loading

0 comments on commit 9437205

Please sign in to comment.