Skip to content

Commit

Permalink
Fix a rendering error when applying matrix to a Shape. (#329)
Browse files Browse the repository at this point in the history
  • Loading branch information
domchen authored Nov 13, 2024
1 parent fb9a840 commit 4723271
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 6 deletions.
4 changes: 4 additions & 0 deletions src/core/Canvas.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -234,6 +234,10 @@ void Canvas::drawShape(std::shared_ptr<Shape> shape, const Paint& paint) {
return;
}
shape = Shape::ApplyStroke(std::move(shape), paint.getStroke());
if (shape->isLine()) {
// a line has no fill to draw.
return;
}
auto style = CreateFillStyle(paint);
Rect rect = {};
if (shape->isRect(&rect)) {
Expand Down
2 changes: 2 additions & 0 deletions src/core/ShapeRasterizer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
#include "ShapeRasterizer.h"
#include "core/PathTriangulator.h"
#include "tgfx/core/Mask.h"
#include "utils/Log.h"

namespace tgfx {
ShapeRasterizer::ShapeRasterizer(int width, int height, std::shared_ptr<Shape> shape,
Expand Down Expand Up @@ -59,6 +60,7 @@ std::shared_ptr<ImageBuffer> ShapeRasterizer::makeImageBuffer(const Path& finalP
bool tryHardware) const {
auto mask = Mask::Make(width(), height(), tryHardware);
if (!mask) {
LOGE("ShapeRasterizer::makeImageBuffer() Failed to create the mask!");
return nullptr;
}
mask->setAntiAlias(antiAlias);
Expand Down
12 changes: 7 additions & 5 deletions src/gpu/ops/ShapeDrawOp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -37,9 +37,7 @@ std::unique_ptr<ShapeDrawOp> ShapeDrawOp::Make(Color color, std::shared_ptr<Shap
if (shape->type() == Shape::Type::Matrix) {
// always unwrap the matrix shape.
auto matrixShape = std::static_pointer_cast<MatrixShape>(shape);
if (!matrixShape->matrix.invert(&uvMatrix)) {
return nullptr;
}
uvMatrix = matrixShape->matrix;
totalMatrix.preConcat(matrixShape->matrix);
shape = matrixShape->shape;
}
Expand Down Expand Up @@ -122,7 +120,7 @@ void ShapeDrawOp::execute(RenderPass* renderPass) {
return;
}
auto realUVMatrix = uvMatrix;
realUVMatrix.postConcat(invert);
realUVMatrix.preConcat(invert);
auto realViewMatrix = viewMatrix;
realViewMatrix.preConcat(invert);
auto vertexBuffer = shapeProxy->getTriangles();
Expand All @@ -132,9 +130,13 @@ void ShapeDrawOp::execute(RenderPass* renderPass) {
if (textureProxy == nullptr) {
return;
}
Matrix maskMatrix = Matrix::I();
if (!realUVMatrix.invert(&maskMatrix)) {
return;
}
auto rect = Rect::MakeWH(textureProxy->width(), textureProxy->height());
vertexData = aa == AAType::Coverage ? MakeAAVertexData(rect) : MakeVertexData(rect);
auto maskFP = TextureEffect::Make(std::move(textureProxy), {}, &rasterizeMatrix, true);
auto maskFP = TextureEffect::Make(std::move(textureProxy), {}, &maskMatrix, true);
if (maskFP == nullptr) {
return;
}
Expand Down
2 changes: 1 addition & 1 deletion src/gpu/tasks/ShapeBufferUploadTask.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ bool ShapeBufferUploadTask::execute(Context* context) {
}
auto shapeBuffer = provider->getBuffer();
if (shapeBuffer == nullptr) {
LOGE("ShapeBufferUploadTask::execute() Failed to get the shape buffer!");
// No need to log an error here; the shape might not be a filled path or could be invisible.
return false;
}
if (auto triangles = shapeBuffer->triangles()) {
Expand Down

0 comments on commit 4723271

Please sign in to comment.