Bug 1686855 [wpt PR 27197] - PlzDedicatedWorker: WPT for clients.matchAll() with...
[gecko.git] / gfx / 2d / Types.h
blob3bd0b8e1d70a0661c0537d6227e7106f8fe73224
1 /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2 /* vim: set ts=8 sts=2 et sw=2 tw=80: */
3 /* This Source Code Form is subject to the terms of the Mozilla Public
4 * License, v. 2.0. If a copy of the MPL was not distributed with this
5 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
7 #ifndef MOZILLA_GFX_TYPES_H_
8 #define MOZILLA_GFX_TYPES_H_
10 #include "mozilla/DefineEnum.h" // for MOZ_DEFINE_ENUM_CLASS_WITH_BASE
11 #include "mozilla/EndianUtils.h"
12 #include "mozilla/EnumeratedRange.h"
13 #include "mozilla/MacroArgs.h" // for MOZ_CONCAT
14 #include "mozilla/TypedEnumBits.h"
16 #include <iosfwd> // for ostream
17 #include <stddef.h>
18 #include <stdint.h>
20 namespace mozilla {
21 namespace gfx {
23 typedef float Float;
24 typedef double Double;
26 enum class SurfaceType : int8_t {
27 DATA, /* Data surface - bitmap in memory */
28 D2D1_BITMAP, /* Surface wrapping a ID2D1Bitmap */
29 D2D1_DRAWTARGET, /* Surface made from a D2D draw target */
30 CAIRO, /* Surface wrapping a cairo surface */
31 CAIRO_IMAGE, /* Data surface wrapping a cairo image surface */
32 COREGRAPHICS_IMAGE, /* Surface wrapping a CoreGraphics Image */
33 COREGRAPHICS_CGCONTEXT, /* Surface wrapping a CG context */
34 SKIA, /* Surface wrapping a Skia bitmap */
35 DUAL_DT, /* Snapshot of a dual drawtarget */
36 D2D1_1_IMAGE, /* A D2D 1.1 ID2D1Image SourceSurface */
37 RECORDING, /* Surface used for recording */
38 WRAP_AND_RECORD, /* Surface used for wrap and record */
39 TILED, /* Surface from a tiled DrawTarget */
40 DATA_SHARED, /* Data surface using shared memory */
41 CAPTURE, /* Data from a DrawTargetCapture */
42 DATA_RECYCLING_SHARED, /* Data surface using shared memory */
43 OFFSET, /* Offset */
44 DATA_ALIGNED, /* Data surface using aligned heap memory */
47 enum class SurfaceFormat : int8_t {
48 // The following values are named to reflect layout of colors in memory, from
49 // lowest byte to highest byte. The 32-bit value layout depends on machine
50 // endianness.
51 // in-memory 32-bit LE value 32-bit BE value
52 B8G8R8A8, // [BB, GG, RR, AA] 0xAARRGGBB 0xBBGGRRAA
53 B8G8R8X8, // [BB, GG, RR, 00] 0x00RRGGBB 0xBBGGRR00
54 R8G8B8A8, // [RR, GG, BB, AA] 0xAABBGGRR 0xRRGGBBAA
55 R8G8B8X8, // [RR, GG, BB, 00] 0x00BBGGRR 0xRRGGBB00
56 A8R8G8B8, // [AA, RR, GG, BB] 0xBBGGRRAA 0xAARRGGBB
57 X8R8G8B8, // [00, RR, GG, BB] 0xBBGGRR00 0x00RRGGBB
59 R8G8B8,
60 B8G8R8,
62 // The _UINT16 suffix here indicates that the name reflects the layout when
63 // viewed as a uint16_t value. In memory these values are stored using native
64 // endianness.
65 R5G6B5_UINT16, // 0bRRRRRGGGGGGBBBBB
67 // This one is a single-byte, so endianness isn't an issue.
68 A8,
69 A16,
71 R8G8,
72 R16G16,
74 // These ones are their own special cases.
75 YUV,
76 NV12, // YUV 4:2:0 image with a plane of 8 bit Y samples followed by
77 // an interleaved U/V plane containing 8 bit 2x2 subsampled
78 // colour difference samples.
79 P016, // Similar to NV12, but with 16 bits plane values
80 P010, // Identical to P016 but the 6 least significant bits are 0.
81 // With DXGI in theory entirely compatible, however practice has
82 // shown that it's not the case.
83 YUV422, // Single plane YUV 4:2:2 interleaved as Y`0 Cb Y`1 Cr.
84 HSV,
85 Lab,
86 Depth,
88 // This represents the unknown format.
89 UNKNOWN,
91 // The following values are endian-independent synonyms. The _UINT32 suffix
92 // indicates that the name reflects the layout when viewed as a uint32_t
93 // value.
94 #if MOZ_LITTLE_ENDIAN()
95 A8R8G8B8_UINT32 = B8G8R8A8, // 0xAARRGGBB
96 X8R8G8B8_UINT32 = B8G8R8X8, // 0x00RRGGBB
97 #elif MOZ_BIG_ENDIAN()
98 A8R8G8B8_UINT32 = A8R8G8B8, // 0xAARRGGBB
99 X8R8G8B8_UINT32 = X8R8G8B8, // 0x00RRGGBB
100 #else
101 # error "bad endianness"
102 #endif
104 // The following values are OS and endian-independent synonyms.
106 // TODO(aosmond): When everything blocking bug 1581828 has been resolved, we
107 // can make this use R8B8G8A8 and R8B8G8X8 for non-Windows platforms.
108 OS_RGBA = A8R8G8B8_UINT32,
109 OS_RGBX = X8R8G8B8_UINT32
112 std::ostream& operator<<(std::ostream& aOut, const SurfaceFormat& aFormat);
114 // Represents the bit-shifts required to access color channels when the layout
115 // is viewed as a uint32_t value.
116 enum class SurfaceFormatBit : uint32_t {
117 #if MOZ_LITTLE_ENDIAN()
118 R8G8B8A8_R = 0,
119 R8G8B8A8_G = 8,
120 R8G8B8A8_B = 16,
121 R8G8B8A8_A = 24,
122 #elif MOZ_BIG_ENDIAN()
123 R8G8B8A8_A = 0,
124 R8G8B8A8_B = 8,
125 R8G8B8A8_G = 16,
126 R8G8B8A8_R = 24,
127 #else
128 # error "bad endianness"
129 #endif
131 // The following values are endian-independent for A8R8G8B8_UINT32.
132 A8R8G8B8_UINT32_B = 0,
133 A8R8G8B8_UINT32_G = 8,
134 A8R8G8B8_UINT32_R = 16,
135 A8R8G8B8_UINT32_A = 24,
137 // The following values are OS and endian-independent.
139 // TODO(aosmond): When everything blocking bug 1581828 has been resolved, we
140 // can make this use R8G8B8A8_X for non-Windows platforms.
141 OS_R = A8R8G8B8_UINT32_R,
142 OS_G = A8R8G8B8_UINT32_G,
143 OS_B = A8R8G8B8_UINT32_B,
144 OS_A = A8R8G8B8_UINT32_A,
147 inline uint32_t operator<<(uint8_t a, SurfaceFormatBit b) {
148 return a << static_cast<uint32_t>(b);
151 inline uint32_t operator>>(uint32_t a, SurfaceFormatBit b) {
152 return a >> static_cast<uint32_t>(b);
155 static inline int BytesPerPixel(SurfaceFormat aFormat) {
156 switch (aFormat) {
157 case SurfaceFormat::A8:
158 return 1;
159 case SurfaceFormat::R5G6B5_UINT16:
160 case SurfaceFormat::A16:
161 return 2;
162 case SurfaceFormat::R8G8B8:
163 case SurfaceFormat::B8G8R8:
164 return 3;
165 case SurfaceFormat::HSV:
166 case SurfaceFormat::Lab:
167 return 3 * sizeof(float);
168 case SurfaceFormat::Depth:
169 return sizeof(uint16_t);
170 default:
171 return 4;
175 inline bool IsOpaque(SurfaceFormat aFormat) {
176 switch (aFormat) {
177 case SurfaceFormat::B8G8R8X8:
178 case SurfaceFormat::R8G8B8X8:
179 case SurfaceFormat::X8R8G8B8:
180 case SurfaceFormat::R5G6B5_UINT16:
181 case SurfaceFormat::R8G8B8:
182 case SurfaceFormat::B8G8R8:
183 case SurfaceFormat::R8G8:
184 case SurfaceFormat::HSV:
185 case SurfaceFormat::Lab:
186 case SurfaceFormat::Depth:
187 case SurfaceFormat::YUV:
188 case SurfaceFormat::NV12:
189 case SurfaceFormat::P010:
190 case SurfaceFormat::P016:
191 case SurfaceFormat::YUV422:
192 return true;
193 default:
194 return false;
198 // The matrix coeffiecients used for YUV to RGB conversion.
199 enum class YUVColorSpace : uint8_t {
200 BT601,
201 BT709,
202 BT2020,
203 Identity, // aka RGB
204 // This represents the unknown format and is a valid value.
205 UNKNOWN,
206 _NUM_COLORSPACE
209 enum class ColorDepth : uint8_t {
210 COLOR_8,
211 COLOR_10,
212 COLOR_12,
213 COLOR_16,
214 UNKNOWN
217 enum class ColorRange : uint8_t { LIMITED, FULL, UNKNOWN };
219 static inline SurfaceFormat SurfaceFormatForColorDepth(ColorDepth aColorDepth) {
220 SurfaceFormat format = SurfaceFormat::A8;
221 switch (aColorDepth) {
222 case ColorDepth::COLOR_8:
223 break;
224 case ColorDepth::COLOR_10:
225 case ColorDepth::COLOR_12:
226 case ColorDepth::COLOR_16:
227 format = SurfaceFormat::A16;
228 break;
229 case ColorDepth::UNKNOWN:
230 MOZ_ASSERT_UNREACHABLE("invalid color depth value");
232 return format;
235 static inline uint32_t BitDepthForColorDepth(ColorDepth aColorDepth) {
236 uint32_t depth = 8;
237 switch (aColorDepth) {
238 case ColorDepth::COLOR_8:
239 break;
240 case ColorDepth::COLOR_10:
241 depth = 10;
242 break;
243 case ColorDepth::COLOR_12:
244 depth = 12;
245 break;
246 case ColorDepth::COLOR_16:
247 depth = 16;
248 break;
249 case ColorDepth::UNKNOWN:
250 MOZ_ASSERT_UNREACHABLE("invalid color depth value");
252 return depth;
255 static inline ColorDepth ColorDepthForBitDepth(uint8_t aBitDepth) {
256 ColorDepth depth = ColorDepth::COLOR_8;
257 switch (aBitDepth) {
258 case 8:
259 break;
260 case 10:
261 depth = ColorDepth::COLOR_10;
262 break;
263 case 12:
264 depth = ColorDepth::COLOR_12;
265 break;
266 case 16:
267 depth = ColorDepth::COLOR_16;
268 break;
269 default:
270 MOZ_ASSERT_UNREACHABLE("invalid color depth value");
272 return depth;
275 // 10 and 12 bits color depth image are using 16 bits integers for storage
276 // As such we need to rescale the value from 10 or 12 bits to 16.
277 static inline uint32_t RescalingFactorForColorDepth(ColorDepth aColorDepth) {
278 uint32_t factor = 1;
279 switch (aColorDepth) {
280 case ColorDepth::COLOR_8:
281 break;
282 case ColorDepth::COLOR_10:
283 factor = 64;
284 break;
285 case ColorDepth::COLOR_12:
286 factor = 16;
287 break;
288 case ColorDepth::COLOR_16:
289 break;
290 case ColorDepth::UNKNOWN:
291 MOZ_ASSERT_UNREACHABLE("invalid color depth value");
293 return factor;
296 enum class FilterType : int8_t {
297 BLEND = 0,
298 TRANSFORM,
299 MORPHOLOGY,
300 COLOR_MATRIX,
301 FLOOD,
302 TILE,
303 TABLE_TRANSFER,
304 DISCRETE_TRANSFER,
305 LINEAR_TRANSFER,
306 GAMMA_TRANSFER,
307 CONVOLVE_MATRIX,
308 DISPLACEMENT_MAP,
309 TURBULENCE,
310 ARITHMETIC_COMBINE,
311 COMPOSITE,
312 DIRECTIONAL_BLUR,
313 GAUSSIAN_BLUR,
314 POINT_DIFFUSE,
315 POINT_SPECULAR,
316 SPOT_DIFFUSE,
317 SPOT_SPECULAR,
318 DISTANT_DIFFUSE,
319 DISTANT_SPECULAR,
320 CROP,
321 PREMULTIPLY,
322 UNPREMULTIPLY,
323 OPACITY
326 enum class DrawTargetType : int8_t {
327 SOFTWARE_RASTER = 0,
328 HARDWARE_RASTER,
329 VECTOR
332 enum class BackendType : int8_t {
333 NONE = 0,
334 DIRECT2D, // Used for version independent D2D objects.
335 CAIRO,
336 SKIA,
337 RECORDING,
338 DIRECT2D1_1,
339 WEBRENDER_TEXT,
340 CAPTURE, // Used for paths
342 // Add new entries above this line.
343 BACKEND_LAST
346 enum class FontType : int8_t {
347 DWRITE,
348 GDI,
349 MAC,
350 FONTCONFIG,
351 FREETYPE,
352 UNKNOWN
355 enum class NativeSurfaceType : int8_t {
356 D3D10_TEXTURE,
357 CAIRO_CONTEXT,
358 CGCONTEXT,
359 CGCONTEXT_ACCELERATED,
360 OPENGL_TEXTURE
363 enum class FontStyle : int8_t { NORMAL, ITALIC, BOLD, BOLD_ITALIC };
365 enum class FontHinting : int8_t { NONE, LIGHT, NORMAL, FULL };
367 enum class CompositionOp : int8_t {
368 OP_OVER,
369 OP_ADD,
370 OP_ATOP,
371 OP_OUT,
372 OP_IN,
373 OP_SOURCE,
374 OP_DEST_IN,
375 OP_DEST_OUT,
376 OP_DEST_OVER,
377 OP_DEST_ATOP,
378 OP_XOR,
379 OP_MULTIPLY,
380 OP_SCREEN,
381 OP_OVERLAY,
382 OP_DARKEN,
383 OP_LIGHTEN,
384 OP_COLOR_DODGE,
385 OP_COLOR_BURN,
386 OP_HARD_LIGHT,
387 OP_SOFT_LIGHT,
388 OP_DIFFERENCE,
389 OP_EXCLUSION,
390 OP_HUE,
391 OP_SATURATION,
392 OP_COLOR,
393 OP_LUMINOSITY,
394 OP_COUNT
397 enum class Axis : int8_t { X_AXIS, Y_AXIS, BOTH };
399 enum class ExtendMode : int8_t {
400 CLAMP, // Do not repeat
401 REPEAT, // Repeat in both axis
402 REPEAT_X, // Only X axis
403 REPEAT_Y, // Only Y axis
404 REFLECT // Mirror the image
407 enum class FillRule : int8_t { FILL_WINDING, FILL_EVEN_ODD };
409 enum class AntialiasMode : int8_t { NONE, GRAY, SUBPIXEL, DEFAULT };
411 // See https://en.wikipedia.org/wiki/Texture_filtering
412 enum class SamplingFilter : int8_t {
413 GOOD,
414 LINEAR,
415 POINT,
416 SENTINEL // one past the last valid value
419 std::ostream& operator<<(std::ostream& aOut, const SamplingFilter& aFilter);
421 // clang-format off
422 MOZ_DEFINE_ENUM_CLASS_WITH_BASE(PatternType, int8_t, (
423 COLOR,
424 SURFACE,
425 LINEAR_GRADIENT,
426 RADIAL_GRADIENT,
427 CONIC_GRADIENT
429 // clang-format on
431 enum class JoinStyle : int8_t {
432 BEVEL,
433 ROUND,
434 MITER, //!< Mitered if within the miter limit, else, if the backed supports
435 //!< it (D2D), the miter is clamped. If the backend does not support
436 //!< miter clamping the behavior is as for MITER_OR_BEVEL.
437 MITER_OR_BEVEL //!< Mitered if within the miter limit, else beveled.
440 enum class CapStyle : int8_t { BUTT, ROUND, SQUARE };
442 enum class SamplingBounds : int8_t { UNBOUNDED, BOUNDED };
444 // Moz2d version for SVG mask types
445 enum class LuminanceType : int8_t {
446 LUMINANCE,
447 LINEARRGB,
450 /* Color is stored in non-premultiplied form in sRGB color space */
451 struct sRGBColor {
452 public:
453 constexpr sRGBColor() : r(0.0f), g(0.0f), b(0.0f), a(0.0f) {}
454 constexpr sRGBColor(Float aR, Float aG, Float aB, Float aA)
455 : r(aR), g(aG), b(aB), a(aA) {}
456 constexpr sRGBColor(Float aR, Float aG, Float aB)
457 : r(aR), g(aG), b(aB), a(1.0f) {}
459 static sRGBColor White(float aA) { return sRGBColor(1.f, 1.f, 1.f, aA); }
461 static sRGBColor Black(float aA) { return sRGBColor(0.f, 0.f, 0.f, aA); }
463 static sRGBColor OpaqueWhite() { return White(1.f); }
465 static sRGBColor OpaqueBlack() { return Black(1.f); }
467 static sRGBColor FromU8(uint8_t aR, uint8_t aG, uint8_t aB, uint8_t aA) {
468 return sRGBColor(float(aR) / 255.f, float(aG) / 255.f, float(aB) / 255.f,
469 float(aA) / 255.f);
472 static sRGBColor FromABGR(uint32_t aColor) {
473 sRGBColor newColor(((aColor >> 0) & 0xff) * (1.0f / 255.0f),
474 ((aColor >> 8) & 0xff) * (1.0f / 255.0f),
475 ((aColor >> 16) & 0xff) * (1.0f / 255.0f),
476 ((aColor >> 24) & 0xff) * (1.0f / 255.0f));
478 return newColor;
481 // The "Unusual" prefix is to avoid unintentionally using this function when
482 // FromABGR(), which is much more common, is needed.
483 static sRGBColor UnusualFromARGB(uint32_t aColor) {
484 sRGBColor newColor(((aColor >> 16) & 0xff) * (1.0f / 255.0f),
485 ((aColor >> 8) & 0xff) * (1.0f / 255.0f),
486 ((aColor >> 0) & 0xff) * (1.0f / 255.0f),
487 ((aColor >> 24) & 0xff) * (1.0f / 255.0f));
489 return newColor;
492 uint32_t ToABGR() const {
493 return uint32_t(r * 255.0f) | uint32_t(g * 255.0f) << 8 |
494 uint32_t(b * 255.0f) << 16 | uint32_t(a * 255.0f) << 24;
497 // The "Unusual" prefix is to avoid unintentionally using this function when
498 // ToABGR(), which is much more common, is needed.
499 uint32_t UnusualToARGB() const {
500 return uint32_t(b * 255.0f) | uint32_t(g * 255.0f) << 8 |
501 uint32_t(r * 255.0f) << 16 | uint32_t(a * 255.0f) << 24;
504 bool operator==(const sRGBColor& aColor) const {
505 return r == aColor.r && g == aColor.g && b == aColor.b && a == aColor.a;
508 bool operator!=(const sRGBColor& aColor) const { return !(*this == aColor); }
510 Float r, g, b, a;
513 /* Color is stored in non-premultiplied form in device color space */
514 struct DeviceColor {
515 public:
516 DeviceColor() : r(0.0f), g(0.0f), b(0.0f), a(0.0f) {}
517 DeviceColor(Float aR, Float aG, Float aB, Float aA)
518 : r(aR), g(aG), b(aB), a(aA) {}
519 DeviceColor(Float aR, Float aG, Float aB) : r(aR), g(aG), b(aB), a(1.0f) {}
521 /* The following Mask* variants are helpers used to make it clear when a
522 * particular color is being used for masking purposes. These masks should
523 * never be colored managed. */
524 static DeviceColor Mask(float aC, float aA) {
525 return DeviceColor(aC, aC, aC, aA);
528 static DeviceColor MaskWhite(float aA) { return Mask(1.f, aA); }
530 static DeviceColor MaskBlack(float aA) { return Mask(0.f, aA); }
532 static DeviceColor MaskOpaqueWhite() { return MaskWhite(1.f); }
534 static DeviceColor MaskOpaqueBlack() { return MaskBlack(1.f); }
536 static DeviceColor FromU8(uint8_t aR, uint8_t aG, uint8_t aB, uint8_t aA) {
537 return DeviceColor(float(aR) / 255.f, float(aG) / 255.f, float(aB) / 255.f,
538 float(aA) / 255.f);
541 static DeviceColor FromABGR(uint32_t aColor) {
542 DeviceColor newColor(((aColor >> 0) & 0xff) * (1.0f / 255.0f),
543 ((aColor >> 8) & 0xff) * (1.0f / 255.0f),
544 ((aColor >> 16) & 0xff) * (1.0f / 255.0f),
545 ((aColor >> 24) & 0xff) * (1.0f / 255.0f));
547 return newColor;
550 // The "Unusual" prefix is to avoid unintentionally using this function when
551 // FromABGR(), which is much more common, is needed.
552 static DeviceColor UnusualFromARGB(uint32_t aColor) {
553 DeviceColor newColor(((aColor >> 16) & 0xff) * (1.0f / 255.0f),
554 ((aColor >> 8) & 0xff) * (1.0f / 255.0f),
555 ((aColor >> 0) & 0xff) * (1.0f / 255.0f),
556 ((aColor >> 24) & 0xff) * (1.0f / 255.0f));
558 return newColor;
561 uint32_t ToABGR() const {
562 return uint32_t(r * 255.0f) | uint32_t(g * 255.0f) << 8 |
563 uint32_t(b * 255.0f) << 16 | uint32_t(a * 255.0f) << 24;
566 // The "Unusual" prefix is to avoid unintentionally using this function when
567 // ToABGR(), which is much more common, is needed.
568 uint32_t UnusualToARGB() const {
569 return uint32_t(b * 255.0f) | uint32_t(g * 255.0f) << 8 |
570 uint32_t(r * 255.0f) << 16 | uint32_t(a * 255.0f) << 24;
573 bool operator==(const DeviceColor& aColor) const {
574 return r == aColor.r && g == aColor.g && b == aColor.b && a == aColor.a;
577 bool operator!=(const DeviceColor& aColor) const {
578 return !(*this == aColor);
581 friend std::ostream& operator<<(std::ostream& aOut,
582 const DeviceColor& aColor);
584 Float r, g, b, a;
587 struct GradientStop {
588 bool operator<(const GradientStop& aOther) const {
589 return offset < aOther.offset;
592 Float offset;
593 DeviceColor color;
596 enum class JobStatus { Complete, Wait, Yield, Error };
598 } // namespace gfx
599 } // namespace mozilla
601 // XXX: temporary
602 typedef mozilla::gfx::SurfaceFormat gfxImageFormat;
604 #if defined(XP_WIN) && defined(MOZ_GFX)
605 # ifdef GFX2D_INTERNAL
606 # define GFX2D_API __declspec(dllexport)
607 # else
608 # define GFX2D_API __declspec(dllimport)
609 # endif
610 #else
611 # define GFX2D_API
612 #endif
614 namespace mozilla {
616 // Side constants for use in various places.
617 enum Side : uint8_t { eSideTop, eSideRight, eSideBottom, eSideLeft };
619 constexpr auto AllPhysicalSides() {
620 return mozilla::MakeInclusiveEnumeratedRange(eSideTop, eSideLeft);
623 enum class SideBits {
624 eNone = 0,
625 eTop = 1 << eSideTop,
626 eRight = 1 << eSideRight,
627 eBottom = 1 << eSideBottom,
628 eLeft = 1 << eSideLeft,
629 eTopBottom = SideBits::eTop | SideBits::eBottom,
630 eLeftRight = SideBits::eLeft | SideBits::eRight,
631 eAll = SideBits::eTopBottom | SideBits::eLeftRight
634 MOZ_MAKE_ENUM_CLASS_BITWISE_OPERATORS(SideBits)
636 enum Corner : uint8_t {
637 // This order is important!
638 eCornerTopLeft = 0,
639 eCornerTopRight = 1,
640 eCornerBottomRight = 2,
641 eCornerBottomLeft = 3
644 // RectCornerRadii::radii depends on this value. It is not being added to
645 // Corner because we want to lift the responsibility to handle it in the
646 // switch-case.
647 constexpr int eCornerCount = 4;
649 constexpr auto AllPhysicalCorners() {
650 return mozilla::MakeInclusiveEnumeratedRange(eCornerTopLeft,
651 eCornerBottomLeft);
654 // Indices into "half corner" arrays (nsStyleCorners e.g.)
655 enum HalfCorner : uint8_t {
656 // This order is important!
657 eCornerTopLeftX = 0,
658 eCornerTopLeftY = 1,
659 eCornerTopRightX = 2,
660 eCornerTopRightY = 3,
661 eCornerBottomRightX = 4,
662 eCornerBottomRightY = 5,
663 eCornerBottomLeftX = 6,
664 eCornerBottomLeftY = 7
667 constexpr auto AllPhysicalHalfCorners() {
668 return mozilla::MakeInclusiveEnumeratedRange(eCornerTopLeftX,
669 eCornerBottomLeftY);
672 // The result of these conversion functions are exhaustively checked in
673 // nsFrame.cpp, which also serves as usage examples.
675 constexpr bool HalfCornerIsX(HalfCorner aHalfCorner) {
676 return !(aHalfCorner % 2);
679 constexpr Corner HalfToFullCorner(HalfCorner aHalfCorner) {
680 return Corner(aHalfCorner / 2);
683 constexpr HalfCorner FullToHalfCorner(Corner aCorner, bool aIsVertical) {
684 return HalfCorner(aCorner * 2 + aIsVertical);
687 constexpr bool SideIsVertical(mozilla::Side aSide) { return aSide % 2; }
689 // @param aIsSecond when true, return the clockwise second of the two
690 // corners associated with aSide. For example, with aSide = eSideBottom the
691 // result is eCornerBottomRight when aIsSecond is false, and
692 // eCornerBottomLeft when aIsSecond is true.
693 constexpr Corner SideToFullCorner(mozilla::Side aSide, bool aIsSecond) {
694 return Corner((aSide + aIsSecond) % 4);
697 // @param aIsSecond see SideToFullCorner.
698 // @param aIsParallel return the half-corner that is parallel with aSide
699 // when aIsParallel is true. For example with aSide=eSideTop, aIsSecond=true
700 // the result is eCornerTopRightX when aIsParallel is true, and
701 // eCornerTopRightY when aIsParallel is false (because "X" is parallel with
702 // eSideTop/eSideBottom, similarly "Y" is parallel with
703 // eSideLeft/eSideRight)
704 constexpr HalfCorner SideToHalfCorner(mozilla::Side aSide, bool aIsSecond,
705 bool aIsParallel) {
706 return HalfCorner(((aSide + aIsSecond) * 2 + (aSide + !aIsParallel) % 2) % 8);
709 } // namespace mozilla
711 #endif /* MOZILLA_GFX_TYPES_H_ */