Skip to content

Commit 3faf1be

Browse files
committed
Ensure that skia clipping and transforms are always applied correctly
1 parent f0dd7a7 commit 3faf1be

File tree

2 files changed

+17
-7
lines changed

2 files changed

+17
-7
lines changed

IGraphics/Drawing/IGraphicsSkia.cpp

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -363,7 +363,10 @@ void IGraphicsSkia::DrawResize()
363363
#endif
364364
#endif
365365
if (mSurface)
366+
{
366367
mCanvas = mSurface->getCanvas();
368+
mCanvas->save();
369+
}
367370
}
368371

369372
void IGraphicsSkia::BeginFrame()
@@ -769,7 +772,6 @@ void IGraphicsSkia::RenderPath(SkPaint& paint)
769772

770773
void IGraphicsSkia::PathTransformSetMatrix(const IMatrix& m)
771774
{
772-
double scale = GetScreenScale() * GetDrawScale();
773775
double xTranslate = 0.0;
774776
double yTranslate = 0.0;
775777

@@ -785,18 +787,22 @@ void IGraphicsSkia::PathTransformSetMatrix(const IMatrix& m)
785787
}
786788

787789
mMatrix = SkMatrix::MakeAll(m.mXX, m.mXY, m.mTX, m.mYX, m.mYY, m.mTY, 0, 0, 1);
788-
SkMatrix globalMatrix = SkMatrix::MakeScale(scale);
789-
SkMatrix skMatrix = mMatrix;
790+
SkMatrix globalMatrix = SkMatrix::MakeScale(GetTotalScale());
791+
mClipMatrix = SkMatrix();
792+
mFinalMatrix = mMatrix;
790793
globalMatrix.preTranslate(xTranslate, yTranslate);
791-
skMatrix.postConcat(globalMatrix);
792-
mCanvas->setMatrix(skMatrix);
794+
mClipMatrix.postConcat(globalMatrix);
795+
mFinalMatrix.postConcat(globalMatrix);
796+
mCanvas->setMatrix(mFinalMatrix);
793797
}
794798

795799
void IGraphicsSkia::SetClipRegion(const IRECT& r)
796800
{
797-
mCanvas->restore();
801+
mCanvas->restoreToCount(0);
798802
mCanvas->save();
803+
mCanvas->setMatrix(mClipMatrix);
799804
mCanvas->clipRect(SkiaRect(r));
805+
mCanvas->setMatrix(mFinalMatrix);
800806
}
801807

802808
APIBitmap* IGraphicsSkia::CreateAPIBitmap(int width, int height, int scale, double drawScale, bool cacheable)
@@ -816,7 +822,9 @@ APIBitmap* IGraphicsSkia::CreateAPIBitmap(int width, int height, int scale, doub
816822
#else
817823
surface = SkSurface::MakeRasterN32Premul(width, height);
818824
#endif
819-
825+
826+
surface->getCanvas()->save();
827+
820828
return new Bitmap(std::move(surface), width, height, scale, drawScale);
821829
}
822830

IGraphics/Drawing/IGraphicsSkia.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -138,6 +138,8 @@ class IGraphicsSkia : public IGraphicsPathBase
138138
SkCanvas* mCanvas = nullptr;
139139
SkPath mMainPath;
140140
SkMatrix mMatrix;
141+
SkMatrix mClipMatrix;
142+
SkMatrix mFinalMatrix;
141143

142144
#if defined OS_WIN && defined IGRAPHICS_CPU
143145
WDL_TypedBuf<uint8_t> mSurfaceMemory;

0 commit comments

Comments
 (0)