Go to file
Michael Ludwig daa9b8e4d9 Add mapRect function and RectToRect constructor to SkM44
The SkM44::RectToRect function matches the semantics of
SkMatrix::RectToRect(kFill_ScaleToFit). No other ScaleToFit variants are
ported over to SkM44.

skottie uses some instances of kCenter_ScaleToFit so that functionality
may need to be added in the future (in SkM44 or in skottie). There are
no current usages of the kStart and kEnd_ScaleToFit semantics.

The SkM44::mapRect() function is implemented to correspond to the
SkMatrix::mapRect() that returns the mapped rect (instead of modifying a
pointer) and always has ApplyPerspectiveClip::kYes. This was chosen to
keep its behavior simple and because perspective clipping is almost
always the right thing to do. In the new implementation there is no
longer a performance cliff to worry about (see below). For the timebeing
mapRect is hidden behind SkMatrixPriv::MapRect().

Performance:
I added benchmarks for mapRect() on SkM44 and SkMatrix that use the same
matrices to get a fair comparison on their different specializations.
SkMatrix has a very efficient mapRect when it's scale+translate or
simpler, then another impl. for affine matrices, and then falls back to
SkPath clipping when there's perspective. On the other hand, SkM44 only
has 2 modes: affine and perspective.

On my desktop, with a Ryzen 9 3900X, here are the times for 100,000 calls
to mapRect for different types of matrices:
                         SkMatrix    SkM44
scale+translate           0.35 ms    0.42 ms
rotate                    1.70 ms    0.42 ms
perspective              63.90 ms    0.66 ms
clipped-perspective      138.0 ms    0.96 ms

To summarize, the SkM44::mapRect is almost as fast as the s+t specialization
in SkMatrix, but for all non-perspective matrices. For perspective matrices
it's only 2x slower than that specialization when no vertices are clipped,
and still almost 2x faster than the affine specialization when vertices are
clipped (and 100x faster than falling back to SkPath).

Given that, there's the open question of whether or not keeping an affine
specialization is worth it for SkM44's code size.

Bug: skia:11720
Change-Id: I6771956729ed64f3b287a9de503513375c9f42a0
Reviewed-on: https://skia-review.googlesource.com/c/skia/+/402957
Reviewed-by: Mike Reed <reed@google.com>
Commit-Queue: Mike Reed <reed@google.com>
Auto-Submit: Michael Ludwig <michaelludwig@google.com>
2021-05-05 19:57:26 +00:00
animations first cut at a checkbox 2009-10-21 19:41:10 +00:00
bazel bazel baby steps 2020-09-14 15:18:32 +00:00
bench Add mapRect function and RectToRect constructor to SkM44 2021-05-05 19:57:26 +00:00
bin Fix Python3 compatibility 2021-03-25 14:15:35 +00:00
build/fuchsia [fuchsia] Fix fidlc command. 2020-06-10 03:29:24 +00:00
build_overrides Prepare for Dawn using Tint unconditionally. 2021-03-12 15:05:26 +00:00
client_utils/android Replace 'typedef xxxxx INHERITED' with 'using INHERITED = xxxx;'. 2020-09-03 03:41:26 +00:00
demos.skia.org Add some comments 2021-04-27 22:16:02 +00:00
dm Convert dmsaa to an SkSurfaceProp 2021-04-20 16:24:56 +00:00
docker [infra] Fix index.d.ts copy in Wasm Docker build 2021-02-23 15:54:11 +00:00
docs/examples Must pass filtering to picture shader 2021-03-18 22:18:47 +00:00
example Reland "Remove use of legacy display globals." 2020-10-05 19:13:58 +00:00
experimental Add NGA compilation stubs 2021-05-05 16:48:01 +00:00
fuzz Revert "Better first-class shader & color filter support in runtime effects" 2021-05-04 13:36:26 +00:00
gm Revert "Better first-class shader & color filter support in runtime effects" 2021-05-04 13:36:26 +00:00
gn Add NGA compilation stubs 2021-05-05 16:48:01 +00:00
include Add mapRect function and RectToRect constructor to SkM44 2021-05-05 19:57:26 +00:00
infra [infra] Fix asset_utils import 2021-05-05 19:10:25 +00:00
modules [canvaskit] Small example fixes 2021-05-05 17:20:26 +00:00
platform_tools [androidkit] add transformation operations to Matrix 2021-04-30 14:07:18 +00:00
resources Optimize compound constructors containing constant vars. 2021-05-05 16:42:56 +00:00
samplecode Delete mixed samples 2021-04-22 20:11:34 +00:00
site Restore cube demo to canvaskit demo page 2021-04-21 21:55:27 +00:00
specs Fix CanvasKit generated documentation to work with emscripten 1.39.16. 2020-05-27 12:23:32 +00:00
src Add mapRect function and RectToRect constructor to SkM44 2021-05-05 19:57:26 +00:00
tests Add mapRect function and RectToRect constructor to SkM44 2021-05-05 19:57:26 +00:00
third_party Update version of libjpeg-turbo used by Skia's test infra 2021-05-04 21:49:45 +00:00
tools Revert "Better first-class shader & color filter support in runtime effects" 2021-05-04 13:36:26 +00:00
.bazelignore bazel baby steps 2020-09-14 15:18:32 +00:00
.clang-format no more bin packing in .clang-format 2021-03-04 17:22:50 +00:00
.clang-tidy Disable ClangTidy namespace comments for short blocks. 2020-08-24 14:01:22 +00:00
.gitignore [sk] Add DEPS entry for "sk" tool 2021-04-09 14:21:37 +00:00
.gn Pre-emptive fix for upcoming ANGLE change. 2021-01-08 17:23:52 +00:00
AUTHORS Add UWP support 2021-02-10 19:04:42 +00:00
BUILD.bazel bazel baby steps 2020-09-14 15:18:32 +00:00
BUILD.gn Add NGA compilation stubs 2021-05-05 16:48:01 +00:00
codereview.settings Make uploading to Gerrit the default for Skia 2016-11-09 19:07:56 +00:00
CONTRIBUTING Fix references to https://sites.google.com/site/skiadocs/. 2015-02-03 13:12:54 -02:00
CQ_COMMITTERS Moved committer list to chrome-infra-auth and deleted it from the repo 2015-09-02 13:37:54 -07:00
DEPS Roll Chromium from 2dddec205bbd to 565426207196 (492 revisions) 2021-05-05 04:55:55 +00:00
DIR_METADATA Move metadata in OWNERS files to DIR_METADATA files 2021-02-02 23:41:54 +00:00
go.mod [infra] Roll infra dependency 2021-02-25 19:56:00 +00:00
go.sum [infra] Roll infra dependency 2021-02-25 19:56:00 +00:00
LICENSE LICENSE file: clean up 2019-11-22 21:59:03 +00:00
PRESUBMIT.py Revert "Display a Docs-Preview link for each modified MD file" 2021-04-22 13:39:28 +00:00
public.bzl Enable DSL FP tests. 2021-04-22 21:03:43 +00:00
README Fix references to https://sites.google.com/site/skiadocs/. 2015-02-03 13:12:54 -02:00
README.chromium Update README.chromium. 2015-06-11 13:19:24 -07:00
RELEASE_NOTES.txt Add mapRect function and RectToRect constructor to SkM44 2021-05-05 19:57:26 +00:00
whitespace.txt Whitespace change to re-trigger Mac/iOS tests 2020-02-23 20:55:01 +00:00
WORKSPACE.bazel bazel baby steps 2020-09-14 15:18:32 +00:00

Skia is a complete 2D graphic library for drawing Text, Geometries, and Images.

See full details, and build instructions, at https://skia.org.