Files
palemoon27/gfx/2d/PathHelpers.cpp
T
roytam1 9855d648fe import changes from `dev' branch of rmottola/Arctic-Fox:
- Bug 1144107 - Part 4: Prevent assert when hitting EOS. r=kentuckyfriedtakahe (4e66e9d148)
- Bug 1226842: Error rather than asserting when encountering error in sample table. r=gerald (4bbe6cd7f2)
- Bug 1189992: Don't assume the last chunk always contains the sample we're looking for. r=gerald (4cf3a3f63a)
- Bug 1225703 - Update in-tree libcubeb. r=padenot (49ce53e3c8)
- Bug 1203449 - Remove OutputStreamListener from DecodedStream.cpp. r=roc. (24421a02e1)
- Bug 1207915 - Apply the fix of bug 1052206 to DecodedStream. r=roc. (c73a3aecc6)
- Bug 1218311 - Port the fix of bug 1193614 to VideoSink. r=cpearce. (cbbe3dc1ab)
- Bug 1230338 - Record video frames dropped by the compositor, or while flushing during skip-to-keyframe. r=jya (edf53548d3)
- Bug 1230882. Part 1 - destroy DecodedStreamData properly when dispatch fails. r=roc. (adb3c05671)
- Bug 1230004. Part 1 - cache data in MDSM so it won't need to ask MediaDecoder. r=cpearce. (728c6b3e82)
- Bug 1219163. Part 1 - Remove unused functions from AbstractMediaDecoder. r=jya. (f1dba3d50c)
- Bug 1219163. Part 2 - Move some functions that are never called from the interface of AbstractMediaDecoder down the class hierarchy. r=jya. (c0fc72790f)
- Bug 1226569. Part 1 - Use MediaEventSource to publish MetadataLoaded and FirstFrameLoaded events. r=jya. (76195567a5)
- Bug 1226569. Part 2 - assert functions that should never be called after shutdown. r=jya. (672df604e5)
- Bug 1227797 - Use MediaEventSource to publish playback events for MDSM. r=jya. (4a3fda2f34)
- Bug 1228923 - Merge some MediaEventSource for MDSM. r=jya. (31929f5777)
- Bug 1228939 - 1. add mSeekable to MediaInfo. 2. use MediaEventSource to notify the decoder when the media is not seekable. 3. remove unused code. r=jya. (38fb6d1099)
- Bug 1230004. Part 2 - have MDSM::BeginShutdown return a promise and remove MDSM::mDecoder. r=cpearce. (0f45558e15)
- add some disabled EME stuff (c4fa7e65be)
- Bug 873438 - Implement IAccessible2_2::accessibleWithCaret, r=yzen (9fb71ce7f3)
- Bug 1159872 - Make IAccessible2::Get_States once again return S_OK when it detects a defunct accessible. r=surkov (91ad6d1798)
- bug 606080 - on windows give accessibles a unique 32 bit id r=surkov (848c16f16c)
- Bug 1220897 - fix IAccessible2::get_accessibleWithCaret, r=tbsaunde (492790b4e1)
- Bug 1225298 - Use GCHashMap for UniqueIdMap, r=terrence (ee896fb807)
- Bug 1227567 - Optimise module namespace imports in Ion where we have type information r=shu (19fdf97bc3)
- Bug 1230337 - Fix TypedArrayObject::isNeutered to stop calling typed arrays using inline storage neutered. (r=Waldo) (2838830319)
- Bug 1055472 - Part 1: Factor out GetPrototypeFromConstructor and use it in existing object creation paths. (r=Waldo) (a26c188064)
- Bug 1055472 - Part 2: Make the Function constructor properly subclassable. (r=Waldo) (e2ff4b48d4)
- Bug 1055472 - Part 2b: Make Function.prototype.bind play nicely with subclassed functions. (r=Waldo, shoutouts for good flyby by evilpie) (59b347ced4)
- Bug 1055472 - Part 3: Make the Object constructor properly subclassable. (r=Waldo) (aa23b6c005)
- Bug 1055472 - Part 4: Make the Boolean constructor properly subclassable. (r=Waldo) (6ff68c5198)
- Bug 1055472 - Part 5: Make the various Error constructors properly subclassable. (r=Waldo) (7e36f26bcd)
- Bug 1055472 - Part 6: Make the Number constructor properly subclassable. (r=Waldo) (5b081bb54c)
- Bug 1055472 - Part 7: Make the Date constructor properly subclassable. (r=Waldo) (a841523521)
- Bug 1055472 - Part 8 prelim: Rename InitializeRegExp to RegExpObject::initFromAtom for readability. (r=Waldo) (053ce20768)
- Bug 1055472 - Part 8: Make the RegExp constructor properly subclassable. (r=Waldo) (a522ecca25)
- Bug 1055472 - Part 9: Make the Map constructor properly subclassable. (r=Waldo) (a29bb1408a)
- Bug 1055472 - Part 10: Make the Set constructor properly subclassable. (r=Waldo) (82befdc508)
- Bug 1055472 - Part 11: Make the WeakMap constructor properly subclassable. (r=Waldo) (0ea50757d4)
- Bug 1055472 - Part 12: Mae the WeakSet constructor properly subclassable. (r=Waldo) (6ba67d4fe6)
- Bug 1055472 - Part 13: Make the ArrayBuffer constructor properly subclassable. (r=Waldo) (7811dadf92)
- Bug 1055472 - Part 14: Make the various TypedArray constructors properly subclassable. (r=Waldo, r=bhackett) (6bc10f8ec1)
- Bug 1055472 - Part 15: Make the DataView constructor properly subclassable. (r=jorendorff, r=bhackett) (b2b6aef1f6)
- Bug 1055472 - Part 16: Make the String constructor properly subclassable. (r=Waldo) (6bed2e45bc)
- Bug 1055472 - Part 17: Make the Array constructor properly subclassable. (r=jorendorff, r=bhackett, r=terrence) (d301fe9814)
- Bug 1055472 - Part 18: Incorportate arai's test into the subclassing suite. (r=me) (cfbc97738a)
- Bug 1226416 - Expose a method to get a node's set of immediately dominated nodes in the dominator tree; r=bz,sfink (8226985fb6)
- Bug 1199422 - Stop pattern matching class-constructors in String#replace and Array#sort. r=efaust (58b56ad143)
- Bug 1206308 - include nsprpub and zlib for Windows, plus minor enhancements to make-source-package.sh, r=sstangl (e933f3a27a)
- Bug 1229729 - Make make-source-package.sh work on OS X. r=sfink (d55f9bc552)
- Bug 1221747 - Make JS_vsnprintf() return a value that indicates failure if we reach the buffer limit r=nbp (1bc82ccafd)
- Bug 1227385 - Properly propagate $DIST from top-level after bug 1224490. r=mshal (ee4fc81981)
- Bug 1200304 - Move stumbling code from gonkgps to MozStumbler.cpp. r=jdm (89aea7211c)
- Bug 1207266 - turn off b2g stumbler if no RIL. r=jdm (ae42aeb5a2)
- Bug 1228947 - Replace mfbt/Constants.h with math.h. r=roc (d56e2bbe2f)
- Bug 1176261 - Discard gps with impossibly tiny accuracy. r=jaliu (93a4114ac7)
- Bug 772750 - Get mobile connection technology from MobileConnectionService. r=garvank,echen (742d68becb)
- Bug 1168068 - GonkGPSGeolocationProvider should use mRilDataServiceId in SetReferenceLocation. r=garvank (b07ee26cc4)
- Bug 1227385 - Avoid make variable references in VISIBILITY_FLAGS and STL_FLAGS. r=mshal (e3e7fc9d99)
- Bug 1225298 - Use GCHashSet for atoms table, r=terrence (4bce42238c)
- Bug 1225298 - Use GCHashSet for InnerViewTable, r=terrence (e8da10443c)
- Bug 1203297 - Fix one last bit of unified bustage; r=bbouvier (7395aca8da)
- Bug 1228340: Rename JitOptions into DefaultJitOptions and get rid of the js_ prefix for the instance; r=h4writer (19777f9a49)
- Bug 1227190 part 1. change PrepareScriptEnvironmentAndInvoke to return void, not bool, to make it clearer that it reports exceptions for you. r=jorendorff (7525efb3ad)
- Bug 1227190 part 2. Change PrepareScriptEnvironmentAndInvoke to take a JSContext*, not a JSRuntime*. r=jorendorff (01b69ccab1)
- Bug 1227190 part 3. Make debugger error reporting play nice with the embedding taking ownership of error reporting. r=jorendorff (008195b9a3)
- Bug 1221600 - Tweak comments about standard internal methods in jsobj.h, jsfriendapi.h. r=efaust. (c1a4b0e2bf)
- Bug 1223372 - Handle ToWindowProxyIfWindow returning a dead wrapper in PrepareForWrapping. r=bholley (0b3dd8084b)
- Bug 1197095 - ensure that ForOfIterator does not pass arguments to next calls; r=evilpie (29acf9b12d)
- Bug 1197094 - ForOfIterator calls ToObject on iterable; r=evilpie (533dd11111)
- Bug 1216379 - Throw less cryptic error message when using a non-iterable in a for...of loop. r=jorendorff (ae7d4c3734)
- Bug 1230010 - OdinMonkey: MIPS: Make immediate patching shared. r=luke (97b5650d3a)
- Bug 1131759 - Atomicize SharedScriptData::marked. (r=terrence) (bafe64c080)
- Bug 1229579 - Make class members properly XDR-able. (r=billm) (d95743694f)
- Bug 1227642: Make data a ScopedJSFreePtr in js::detail::CopyScript to ensure it doesn't leak; r=jonco (db8bcafc09)
- Bug 1227287 - Fix minor bug with f.arguments and lazy arguments. r=luke (9c1cc5aaad)
- Bug 1228947 - mingw fixup. (3216b8df21)
- Bug 1231163 - Don't assume the RNG's been initialized by a prior call to Math.random, when a call to Math.random is being inlined. (A method can be inlined once its identity has been guarded against, but mere identity can be established without the method having been called.) r=jwalden (d7e2235e63)
- crash stuff (12dfaea226)
- Bug 1218027 - "--with-system-icu fails: js/src/jsapi.cpp:69: error: visibility does not match previous declaration". r=mh+mozilla (5929f4280c)
- Bug 1229740 - add <array> to the list of wrapped system headers; r=glandium (990a0a22ab)
- Bug 1192312 - Use MediaCodecSource for camera recording since gonkL r=aosmond (f68121e622)
- Bug 1210293 - Remove legacy check from the XPIDL HTMLInputElement::SetUserInput. r=bz (f70fbfd8ea)
- Bug 1220323 - Enable FasterMake backend by default for all apps. r=gps (7421f68979)
- Fixup for b2g bustage from bug 1164921. r=me (6207a28039)
- Bug 1209391 - Remove build/unix/uniq.py. r=mshal (d757f44938)
- Bug 1192233 - delete check for sys/cdefs.h from configure; r=mshal (ca2709a478)
- Bug 1191816 - don't check for sys/int_types.h in configure; r=mshal (3f77884338)
- Bug 1182565 - Disable sandboxing on Linux Thread Sanitizer builds. r=kang (5dcd521ca1)
- missing bits of Bug 1157768 - Build files and config headers for libav fft (5ab19c5158)
- Bug 1149279 - Remove unused build config variable NSS_NO_LIBPKIX. r=gps (0abbcd89c3)
- Bug 1161238 - Remove --disable-logging. r=gps (b896b8f77d)
- Bug 1167201 - Make absence of gconf developer packages a fatal error rather than disabling gconf automatically in the build system. This is necessary because if gconf is disabled, many tests don't work because they use gconf to detect linux. r=glandium (4def45dc4f)
- bug 1220037 pack and unpack Nyquist for MOZ_LIBAV_FFT r=padenot (23e4e277ff)
- bug 1220041 remove unnecessary temp buffer and copy with libav FFT r=padenot (20df464d7b)
- bug 1220041 scale when copying for inverse FFT to avoid iterating twice r=padenot (d9c11db7e2)
- bug 1223520 avoid leaking NaNs to and from the otherwise unused imaginary frequency components r=padenot (0ff120a534)
- bug 1188704 remove now unused PerformInverseFFT() variation r=rillian (b82b4d459a)
- bug 1188704 add accessor functions for setting frequency components for inverse FFT r=rillian (c8357b6268)
- style (3b9fc23a34)
- Bug 1173016 - Properly refcount the inner PeriodicWave object. r=karlt (634e09bb79)
- bug 1187785 reverse tableInterpolationFactor to make it consistent with documentation r=rillian (928fa29f6c)
- bug 1188704 redefine halfSize as fftSize / 2 r=rillian (1cf36a13e3)
- bug 1188704 trim unnecessary extra basic waveform coeffient r=rillian (c33983684a)
- bug 1188704 simplify culling of partials r=rillian (484932e54e)
- bug 1188704 combine scaling with copying r=rillian (7e5d3f9c7d)
- bug 1188704 limit number of Fourier coefficients used to halfSize earlier r=rillian (abba4f31bb)
- bug 1188704 use existing FFTBlock arrays instead of allocating and copying and scaling r=rillian (74b58f3bc3)
- warnings (cf6c0840e8)
- Bug 1171436 - support at least 8192 elements for PeriodicWave r=padenot (7ddeb3ec3f)
- bug 1221831 remove unused Reverb::reset() r=padenot (913849471f)
- bug 1221831 remove unused Reverb::latencyFrames() r=padenot (767744e87c)
- bug 1221830 use WEBAUDIO_BLOCK_SIZE constant in Reverb methods r=padenot (38dc6b0a92)
- bug 1221831 use initial input buffer offset to control when convolver stages perform their FFT r=padenot (4f594ded7a)
- bug 1221831 remove now-unnecessary m_preDelayBuffer r=padenot (af5b36efdc)
- bug 1221830 use WEBAUDIO_BLOCK_SIZE slice size for background convolver thread r=padenot (0d6dbe1daa)
- bug 1221830 double maximum realtime convolver stage size to 2048 r=padenot (1cf7698f2d)
- bug 1221830 use WEBAUDIO_BLOCK_SIZE constant in FFTConvolver r=padenot (955e902db8)
- bug 1221833 reduce FFTConvolver latency by one block r=padenot (024b13396a)
- bug 1221833 replace initial direct convolution stage with fft r=padenot (70319e951b)
- bug 1221833 remove first two half-block-size convolver stages r=padenot (2709910848)
- bug 1221833 remove now-unused direct convolver r=padenot (d0cfb712af)
- bug 1221836 return output pointer from FFTConvolver::process() to save a buffer copy r=padenot (4bf6c5e6c8)
- Bug 1196608 - Link liblgpllibs against mozglue. r=mshal (3212491e68)
- missing bit of 1157768 (3d6844b56e)
- bug 1224102 reduce the size of the final FFT convolution stage if possible r=padenot (f1fbd7f04d)
- Bug 1192587 - Build media/libav in unified mode. r=qDot (77dd2810e3)
- Bug 1228230 - Rely more on top-level configure auto-detection. r=qdot (8add5f4014)
- Bug 1261414 - Don't build libav with sysctl on Unix (it's not used anyway). r=glandium (195c3ddba4)
- Bug 1222405 - (part 1) Store PeriodicWave components for later use r=padenot (a993b3303d)
- Bug 1222405 - (part 2) Build band limited tables after fundamental frequency is known r=padenot (d350f2e201)
- Bug 1222405 - (part 3) Build band limited tables lazily r=padenot (0dc6f013fc)
2023-05-09 11:34:56 +08:00

278 lines
9.6 KiB
C++

/* -*- Mode: C++; tab-width: 20; indent-tabs-mode: nil; c-basic-offset: 2 -*-
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
#include "PathHelpers.h"
namespace mozilla {
namespace gfx {
UserDataKey sDisablePixelSnapping;
void
AppendRectToPath(PathBuilder* aPathBuilder,
const Rect& aRect,
bool aDrawClockwise)
{
if (aDrawClockwise) {
aPathBuilder->MoveTo(aRect.TopLeft());
aPathBuilder->LineTo(aRect.TopRight());
aPathBuilder->LineTo(aRect.BottomRight());
aPathBuilder->LineTo(aRect.BottomLeft());
} else {
aPathBuilder->MoveTo(aRect.TopRight());
aPathBuilder->LineTo(aRect.TopLeft());
aPathBuilder->LineTo(aRect.BottomLeft());
aPathBuilder->LineTo(aRect.BottomRight());
}
aPathBuilder->Close();
}
void
AppendRoundedRectToPath(PathBuilder* aPathBuilder,
const Rect& aRect,
const RectCornerRadii& aRadii,
bool aDrawClockwise)
{
// For CW drawing, this looks like:
//
// ...******0** 1 C
// ****
// *** 2
// **
// *
// *
// 3
// *
// *
//
// Where 0, 1, 2, 3 are the control points of the Bezier curve for
// the corner, and C is the actual corner point.
//
// At the start of the loop, the current point is assumed to be
// the point adjacent to the top left corner on the top
// horizontal. Note that corner indices start at the top left and
// continue clockwise, whereas in our loop i = 0 refers to the top
// right corner.
//
// When going CCW, the control points are swapped, and the first
// corner that's drawn is the top left (along with the top segment).
//
// There is considerable latitude in how one chooses the four
// control points for a Bezier curve approximation to an ellipse.
// For the overall path to be continuous and show no corner at the
// endpoints of the arc, points 0 and 3 must be at the ends of the
// straight segments of the rectangle; points 0, 1, and C must be
// collinear; and points 3, 2, and C must also be collinear. This
// leaves only two free parameters: the ratio of the line segments
// 01 and 0C, and the ratio of the line segments 32 and 3C. See
// the following papers for extensive discussion of how to choose
// these ratios:
//
// Dokken, Tor, et al. "Good approximation of circles by
// curvature-continuous Bezier curves." Computer-Aided
// Geometric Design 7(1990) 33--41.
// Goldapp, Michael. "Approximation of circular arcs by cubic
// polynomials." Computer-Aided Geometric Design 8(1991) 227--238.
// Maisonobe, Luc. "Drawing an elliptical arc using polylines,
// quadratic, or cubic Bezier curves."
// http://www.spaceroots.org/documents/ellipse/elliptical-arc.pdf
//
// We follow the approach in section 2 of Goldapp (least-error,
// Hermite-type approximation) and make both ratios equal to
//
// 2 2 + n - sqrt(2n + 28)
// alpha = - * ---------------------
// 3 n - 4
//
// where n = 3( cbrt(sqrt(2)+1) - cbrt(sqrt(2)-1) ).
//
// This is the result of Goldapp's equation (10b) when the angle
// swept out by the arc is pi/2, and the parameter "a-bar" is the
// expression given immediately below equation (21).
//
// Using this value, the maximum radial error for a circle, as a
// fraction of the radius, is on the order of 0.2 x 10^-3.
// Neither Dokken nor Goldapp discusses error for a general
// ellipse; Maisonobe does, but his choice of control points
// follows different constraints, and Goldapp's expression for
// 'alpha' gives much smaller radial error, even for very flat
// ellipses, than Maisonobe's equivalent.
//
// For the various corners and for each axis, the sign of this
// constant changes, or it might be 0 -- it's multiplied by the
// appropriate multiplier from the list before using.
const Float alpha = Float(0.55191497064665766025);
typedef struct { Float a, b; } twoFloats;
twoFloats cwCornerMults[4] = { { -1, 0 }, // cc == clockwise
{ 0, -1 },
{ +1, 0 },
{ 0, +1 } };
twoFloats ccwCornerMults[4] = { { +1, 0 }, // ccw == counter-clockwise
{ 0, -1 },
{ -1, 0 },
{ 0, +1 } };
twoFloats *cornerMults = aDrawClockwise ? cwCornerMults : ccwCornerMults;
Point cornerCoords[] = { aRect.TopLeft(), aRect.TopRight(),
aRect.BottomRight(), aRect.BottomLeft() };
Point pc, p0, p1, p2, p3;
if (aDrawClockwise) {
aPathBuilder->MoveTo(Point(aRect.X() + aRadii[RectCorner::TopLeft].width,
aRect.Y()));
} else {
aPathBuilder->MoveTo(Point(aRect.X() + aRect.Width() - aRadii[RectCorner::TopRight].width,
aRect.Y()));
}
for (int i = 0; i < 4; ++i) {
// the corner index -- either 1 2 3 0 (cw) or 0 3 2 1 (ccw)
int c = aDrawClockwise ? ((i+1) % 4) : ((4-i) % 4);
// i+2 and i+3 respectively. These are used to index into the corner
// multiplier table, and were deduced by calculating out the long form
// of each corner and finding a pattern in the signs and values.
int i2 = (i+2) % 4;
int i3 = (i+3) % 4;
pc = cornerCoords[c];
if (aRadii[c].width > 0.0 && aRadii[c].height > 0.0) {
p0.x = pc.x + cornerMults[i].a * aRadii[c].width;
p0.y = pc.y + cornerMults[i].b * aRadii[c].height;
p3.x = pc.x + cornerMults[i3].a * aRadii[c].width;
p3.y = pc.y + cornerMults[i3].b * aRadii[c].height;
p1.x = p0.x + alpha * cornerMults[i2].a * aRadii[c].width;
p1.y = p0.y + alpha * cornerMults[i2].b * aRadii[c].height;
p2.x = p3.x - alpha * cornerMults[i3].a * aRadii[c].width;
p2.y = p3.y - alpha * cornerMults[i3].b * aRadii[c].height;
aPathBuilder->LineTo(p0);
aPathBuilder->BezierTo(p1, p2, p3);
} else {
aPathBuilder->LineTo(pc);
}
}
aPathBuilder->Close();
}
void
AppendEllipseToPath(PathBuilder* aPathBuilder,
const Point& aCenter,
const Size& aDimensions)
{
Size halfDim = aDimensions / 2.f;
Rect rect(aCenter - Point(halfDim.width, halfDim.height), aDimensions);
RectCornerRadii radii(halfDim.width, halfDim.height);
AppendRoundedRectToPath(aPathBuilder, rect, radii);
}
bool
SnapLineToDevicePixelsForStroking(Point& aP1, Point& aP2,
const DrawTarget& aDrawTarget,
Float aLineWidth)
{
Matrix mat = aDrawTarget.GetTransform();
if (mat.HasNonTranslation()) {
return false;
}
if (aP1.x != aP2.x && aP1.y != aP2.y) {
return false; // not a horizontal or vertical line
}
Point p1 = aP1 + mat.GetTranslation(); // into device space
Point p2 = aP2 + mat.GetTranslation();
p1.Round();
p2.Round();
p1 -= mat.GetTranslation(); // back into user space
p2 -= mat.GetTranslation();
aP1 = p1;
aP2 = p2;
bool lineWidthIsOdd = (int(aLineWidth) % 2) == 1;
if (lineWidthIsOdd) {
if (aP1.x == aP2.x) {
// snap vertical line, adding 0.5 to align it to be mid-pixel:
aP1 += Point(0.5, 0);
aP2 += Point(0.5, 0);
} else {
// snap horizontal line, adding 0.5 to align it to be mid-pixel:
aP1 += Point(0, 0.5);
aP2 += Point(0, 0.5);
}
}
return true;
}
void
StrokeSnappedEdgesOfRect(const Rect& aRect, DrawTarget& aDrawTarget,
const ColorPattern& aColor,
const StrokeOptions& aStrokeOptions)
{
if (aRect.IsEmpty()) {
return;
}
Point p1 = aRect.TopLeft();
Point p2 = aRect.BottomLeft();
SnapLineToDevicePixelsForStroking(p1, p2, aDrawTarget,
aStrokeOptions.mLineWidth);
aDrawTarget.StrokeLine(p1, p2, aColor, aStrokeOptions);
p1 = aRect.BottomLeft();
p2 = aRect.BottomRight();
SnapLineToDevicePixelsForStroking(p1, p2, aDrawTarget,
aStrokeOptions.mLineWidth);
aDrawTarget.StrokeLine(p1, p2, aColor, aStrokeOptions);
p1 = aRect.TopLeft();
p2 = aRect.TopRight();
SnapLineToDevicePixelsForStroking(p1, p2, aDrawTarget,
aStrokeOptions.mLineWidth);
aDrawTarget.StrokeLine(p1, p2, aColor, aStrokeOptions);
p1 = aRect.TopRight();
p2 = aRect.BottomRight();
SnapLineToDevicePixelsForStroking(p1, p2, aDrawTarget,
aStrokeOptions.mLineWidth);
aDrawTarget.StrokeLine(p1, p2, aColor, aStrokeOptions);
}
// The logic for this comes from _cairo_stroke_style_max_distance_from_path
Margin
MaxStrokeExtents(const StrokeOptions& aStrokeOptions,
const Matrix& aTransform)
{
double styleExpansionFactor = 0.5f;
if (aStrokeOptions.mLineCap == CapStyle::SQUARE) {
styleExpansionFactor = M_SQRT1_2;
}
if (aStrokeOptions.mLineJoin == JoinStyle::MITER &&
styleExpansionFactor < M_SQRT2 * aStrokeOptions.mMiterLimit) {
styleExpansionFactor = M_SQRT2 * aStrokeOptions.mMiterLimit;
}
styleExpansionFactor *= aStrokeOptions.mLineWidth;
double dx = styleExpansionFactor * hypot(aTransform._11, aTransform._21);
double dy = styleExpansionFactor * hypot(aTransform._22, aTransform._12);
return Margin(dy, dx, dy, dx);
}
} // namespace gfx
} // namespace mozilla