Hi,
In order to implement a smooth scrolling, I wonder what is the fastest way with Skia to move a rectangle by an (x, y) offset?
The following code works:
auto image = _surface->makeImageSnapshot();
auto canvas = _surface->getCanvas();
auto src = SkRect::MakeIWH(width, height);
auto dst = SkRect::MakeIWH(width, height);
if (deltaX < 0)
src.offset(SkPoint::Make(-deltaX, 0));
if (deltaY < 0)
src.offset(SkPoint::Make(0, -deltaY));
if (deltaX > 0)
dst.offset(deltaX, 0);
if (deltaY > 0)
dst.offset(0, deltaY);
canvas->drawImageRect(
image, src, dst, SkSamplingOptions {}, nullptr, SkCanvas::kStrict_SrcRectConstraint);
While this one results in artifacts when the delta is positive:
/* doesn't work at all */
auto canvas = _surface->getCanvas();
_surface->draw(canvas, deltaX, deltaY);
Thanks,
Alex