2017-10-28 02:10:06 +03:00
|
|
|
/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
|
|
|
/* vim: set ts=8 sts=2 et sw=2 tw=80: */
|
|
|
|
/* This Source Code Form is subject to the terms of the Mozilla Public
|
2012-05-21 15:12:37 +04:00
|
|
|
* 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/. */
|
2011-06-24 21:41:16 +04:00
|
|
|
|
|
|
|
#ifndef MOZILLA_GFX_TYPES_H_
|
|
|
|
#define MOZILLA_GFX_TYPES_H_
|
|
|
|
|
2020-03-02 13:20:57 +03:00
|
|
|
#include "mozilla/DefineEnum.h" // for MOZ_DEFINE_ENUM_CLASS_WITH_BASE
|
2016-05-22 23:31:11 +03:00
|
|
|
#include "mozilla/EndianUtils.h"
|
2020-02-04 06:28:27 +03:00
|
|
|
#include "mozilla/EnumeratedRange.h"
|
2016-11-18 10:25:33 +03:00
|
|
|
#include "mozilla/MacroArgs.h" // for MOZ_CONCAT
|
2019-10-08 00:01:53 +03:00
|
|
|
#include "mozilla/TypedEnumBits.h"
|
2015-10-19 07:53:40 +03:00
|
|
|
|
2020-09-25 11:57:24 +03:00
|
|
|
#include <iosfwd> // for ostream
|
2011-06-24 21:41:16 +04:00
|
|
|
#include <stddef.h>
|
2013-07-30 18:25:31 +04:00
|
|
|
#include <stdint.h>
|
2011-06-24 21:41:16 +04:00
|
|
|
|
|
|
|
namespace mozilla {
|
|
|
|
namespace gfx {
|
|
|
|
|
|
|
|
typedef float Float;
|
2017-05-23 06:53:04 +03:00
|
|
|
typedef double Double;
|
2011-06-24 21:41:16 +04:00
|
|
|
|
2015-01-26 01:22:07 +03:00
|
|
|
enum class SurfaceType : int8_t {
|
2014-01-10 22:55:24 +04:00
|
|
|
DATA, /* Data surface - bitmap in memory */
|
|
|
|
D2D1_BITMAP, /* Surface wrapping a ID2D1Bitmap */
|
|
|
|
D2D1_DRAWTARGET, /* Surface made from a D2D draw target */
|
|
|
|
CAIRO, /* Surface wrapping a cairo surface */
|
|
|
|
CAIRO_IMAGE, /* Data surface wrapping a cairo image surface */
|
|
|
|
COREGRAPHICS_IMAGE, /* Surface wrapping a CoreGraphics Image */
|
|
|
|
COREGRAPHICS_CGCONTEXT, /* Surface wrapping a CG context */
|
|
|
|
SKIA, /* Surface wrapping a Skia bitmap */
|
|
|
|
DUAL_DT, /* Snapshot of a dual drawtarget */
|
|
|
|
D2D1_1_IMAGE, /* A D2D 1.1 ID2D1Image SourceSurface */
|
2014-06-11 23:53:02 +04:00
|
|
|
RECORDING, /* Surface used for recording */
|
2020-01-23 00:21:08 +03:00
|
|
|
WRAP_AND_RECORD, /* Surface used for wrap and record */
|
2017-01-18 18:12:32 +03:00
|
|
|
TILED, /* Surface from a tiled DrawTarget */
|
|
|
|
DATA_SHARED, /* Data surface using shared memory */
|
2018-10-01 21:47:17 +03:00
|
|
|
CAPTURE, /* Data from a DrawTargetCapture */
|
2019-01-26 02:06:24 +03:00
|
|
|
DATA_RECYCLING_SHARED, /* Data surface using shared memory */
|
|
|
|
OFFSET, /* Offset */
|
2019-12-26 00:27:46 +03:00
|
|
|
DATA_ALIGNED, /* Data surface using aligned heap memory */
|
2021-03-30 01:43:26 +03:00
|
|
|
DATA_SHARED_WRAPPER, /* Shared memory mapped in from another process */
|
2021-05-13 19:24:06 +03:00
|
|
|
BLOB_IMAGE, /* Recorded blob image */
|
2021-05-20 15:31:27 +03:00
|
|
|
DATA_MAPPED, /* Data surface wrapping a ScopedMap */
|
2015-01-26 01:22:07 +03:00
|
|
|
};
|
2011-06-24 21:41:16 +04:00
|
|
|
|
2015-01-26 01:22:07 +03:00
|
|
|
enum class SurfaceFormat : int8_t {
|
2015-10-23 09:04:40 +03:00
|
|
|
// The following values are named to reflect layout of colors in memory, from
|
|
|
|
// lowest byte to highest byte. The 32-bit value layout depends on machine
|
|
|
|
// endianness.
|
|
|
|
// in-memory 32-bit LE value 32-bit BE value
|
|
|
|
B8G8R8A8, // [BB, GG, RR, AA] 0xAARRGGBB 0xBBGGRRAA
|
|
|
|
B8G8R8X8, // [BB, GG, RR, 00] 0x00RRGGBB 0xBBGGRR00
|
|
|
|
R8G8B8A8, // [RR, GG, BB, AA] 0xAABBGGRR 0xRRGGBBAA
|
|
|
|
R8G8B8X8, // [RR, GG, BB, 00] 0x00BBGGRR 0xRRGGBB00
|
2015-10-19 07:53:40 +03:00
|
|
|
A8R8G8B8, // [AA, RR, GG, BB] 0xBBGGRRAA 0xAARRGGBB
|
|
|
|
X8R8G8B8, // [00, RR, GG, BB] 0xBBGGRR00 0x00RRGGBB
|
2015-10-23 09:04:40 +03:00
|
|
|
|
2016-03-18 13:25:38 +03:00
|
|
|
R8G8B8,
|
|
|
|
B8G8R8,
|
|
|
|
|
2015-10-23 09:04:40 +03:00
|
|
|
// The _UINT16 suffix here indicates that the name reflects the layout when
|
|
|
|
// viewed as a uint16_t value. In memory these values are stored using native
|
|
|
|
// endianness.
|
|
|
|
R5G6B5_UINT16, // 0bRRRRRGGGGGGBBBBB
|
|
|
|
|
|
|
|
// This one is a single-byte, so endianness isn't an issue.
|
2014-01-10 23:06:16 +04:00
|
|
|
A8,
|
2017-09-29 17:37:56 +03:00
|
|
|
A16,
|
2015-10-23 09:04:40 +03:00
|
|
|
|
2017-05-18 17:59:06 +03:00
|
|
|
R8G8,
|
2019-04-11 15:37:23 +03:00
|
|
|
R16G16,
|
2017-05-18 17:59:06 +03:00
|
|
|
|
2015-10-23 09:04:40 +03:00
|
|
|
// These ones are their own special cases.
|
2014-01-10 23:06:16 +04:00
|
|
|
YUV,
|
2020-08-07 00:27:46 +03:00
|
|
|
NV12, // YUV 4:2:0 image with a plane of 8 bit Y samples followed by
|
|
|
|
// an interleaved U/V plane containing 8 bit 2x2 subsampled
|
|
|
|
// colour difference samples.
|
|
|
|
P016, // Similar to NV12, but with 16 bits plane values
|
|
|
|
P010, // Identical to P016 but the 6 least significant bits are 0.
|
|
|
|
// With DXGI in theory entirely compatible, however practice has
|
|
|
|
// shown that it's not the case.
|
|
|
|
YUV422, // Single plane YUV 4:2:2 interleaved as Y`0 Cb Y`1 Cr.
|
2016-03-18 13:25:38 +03:00
|
|
|
HSV,
|
|
|
|
Lab,
|
|
|
|
Depth,
|
2015-10-23 09:04:40 +03:00
|
|
|
|
|
|
|
// This represents the unknown format.
|
2015-10-19 07:53:40 +03:00
|
|
|
UNKNOWN,
|
|
|
|
|
|
|
|
// The following values are endian-independent synonyms. The _UINT32 suffix
|
|
|
|
// indicates that the name reflects the layout when viewed as a uint32_t
|
|
|
|
// value.
|
2019-12-13 23:51:04 +03:00
|
|
|
#if MOZ_LITTLE_ENDIAN()
|
2015-10-19 07:53:40 +03:00
|
|
|
A8R8G8B8_UINT32 = B8G8R8A8, // 0xAARRGGBB
|
2019-11-06 19:37:53 +03:00
|
|
|
X8R8G8B8_UINT32 = B8G8R8X8, // 0x00RRGGBB
|
2019-12-13 23:51:04 +03:00
|
|
|
#elif MOZ_BIG_ENDIAN()
|
2015-10-19 07:53:40 +03:00
|
|
|
A8R8G8B8_UINT32 = A8R8G8B8, // 0xAARRGGBB
|
2019-11-06 19:37:53 +03:00
|
|
|
X8R8G8B8_UINT32 = X8R8G8B8, // 0x00RRGGBB
|
2015-10-19 07:53:40 +03:00
|
|
|
#else
|
|
|
|
# error "bad endianness"
|
|
|
|
#endif
|
2019-11-06 19:37:53 +03:00
|
|
|
|
|
|
|
// The following values are OS and endian-independent synonyms.
|
|
|
|
//
|
|
|
|
// TODO(aosmond): When everything blocking bug 1581828 has been resolved, we
|
|
|
|
// can make this use R8B8G8A8 and R8B8G8X8 for non-Windows platforms.
|
|
|
|
OS_RGBA = A8R8G8B8_UINT32,
|
|
|
|
OS_RGBX = X8R8G8B8_UINT32
|
2015-01-26 01:22:07 +03:00
|
|
|
};
|
2011-06-24 21:41:16 +04:00
|
|
|
|
2020-10-12 02:22:28 +03:00
|
|
|
std::ostream& operator<<(std::ostream& aOut, const SurfaceFormat& aFormat);
|
|
|
|
|
2019-11-06 19:37:53 +03:00
|
|
|
// Represents the bit-shifts required to access color channels when the layout
|
|
|
|
// is viewed as a uint32_t value.
|
|
|
|
enum class SurfaceFormatBit : uint32_t {
|
2019-12-13 23:51:04 +03:00
|
|
|
#if MOZ_LITTLE_ENDIAN()
|
2019-11-06 19:37:53 +03:00
|
|
|
R8G8B8A8_R = 0,
|
|
|
|
R8G8B8A8_G = 8,
|
|
|
|
R8G8B8A8_B = 16,
|
|
|
|
R8G8B8A8_A = 24,
|
2019-12-13 23:51:04 +03:00
|
|
|
#elif MOZ_BIG_ENDIAN()
|
2019-11-06 19:37:53 +03:00
|
|
|
R8G8B8A8_A = 0,
|
|
|
|
R8G8B8A8_B = 8,
|
|
|
|
R8G8B8A8_G = 16,
|
|
|
|
R8G8B8A8_R = 24,
|
|
|
|
#else
|
|
|
|
# error "bad endianness"
|
|
|
|
#endif
|
|
|
|
|
|
|
|
// The following values are endian-independent for A8R8G8B8_UINT32.
|
|
|
|
A8R8G8B8_UINT32_B = 0,
|
|
|
|
A8R8G8B8_UINT32_G = 8,
|
|
|
|
A8R8G8B8_UINT32_R = 16,
|
|
|
|
A8R8G8B8_UINT32_A = 24,
|
|
|
|
|
|
|
|
// The following values are OS and endian-independent.
|
|
|
|
//
|
|
|
|
// TODO(aosmond): When everything blocking bug 1581828 has been resolved, we
|
|
|
|
// can make this use R8G8B8A8_X for non-Windows platforms.
|
|
|
|
OS_R = A8R8G8B8_UINT32_R,
|
|
|
|
OS_G = A8R8G8B8_UINT32_G,
|
|
|
|
OS_B = A8R8G8B8_UINT32_B,
|
|
|
|
OS_A = A8R8G8B8_UINT32_A,
|
|
|
|
};
|
|
|
|
|
|
|
|
inline uint32_t operator<<(uint8_t a, SurfaceFormatBit b) {
|
|
|
|
return a << static_cast<uint32_t>(b);
|
|
|
|
}
|
|
|
|
|
|
|
|
inline uint32_t operator>>(uint32_t a, SurfaceFormatBit b) {
|
|
|
|
return a >> static_cast<uint32_t>(b);
|
|
|
|
}
|
|
|
|
|
2018-10-09 15:56:25 +03:00
|
|
|
static inline int BytesPerPixel(SurfaceFormat aFormat) {
|
|
|
|
switch (aFormat) {
|
|
|
|
case SurfaceFormat::A8:
|
|
|
|
return 1;
|
|
|
|
case SurfaceFormat::R5G6B5_UINT16:
|
|
|
|
case SurfaceFormat::A16:
|
|
|
|
return 2;
|
|
|
|
case SurfaceFormat::R8G8B8:
|
|
|
|
case SurfaceFormat::B8G8R8:
|
|
|
|
return 3;
|
|
|
|
case SurfaceFormat::HSV:
|
|
|
|
case SurfaceFormat::Lab:
|
|
|
|
return 3 * sizeof(float);
|
|
|
|
case SurfaceFormat::Depth:
|
|
|
|
return sizeof(uint16_t);
|
|
|
|
default:
|
|
|
|
return 4;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-10-30 05:31:54 +03:00
|
|
|
inline bool IsOpaque(SurfaceFormat aFormat) {
|
|
|
|
switch (aFormat) {
|
|
|
|
case SurfaceFormat::B8G8R8X8:
|
|
|
|
case SurfaceFormat::R8G8B8X8:
|
2018-10-09 16:07:58 +03:00
|
|
|
case SurfaceFormat::X8R8G8B8:
|
2015-10-23 09:01:31 +03:00
|
|
|
case SurfaceFormat::R5G6B5_UINT16:
|
2018-10-09 16:07:58 +03:00
|
|
|
case SurfaceFormat::R8G8B8:
|
|
|
|
case SurfaceFormat::B8G8R8:
|
|
|
|
case SurfaceFormat::R8G8:
|
|
|
|
case SurfaceFormat::HSV:
|
|
|
|
case SurfaceFormat::Lab:
|
|
|
|
case SurfaceFormat::Depth:
|
2014-10-30 05:31:54 +03:00
|
|
|
case SurfaceFormat::YUV:
|
2015-08-04 00:57:19 +03:00
|
|
|
case SurfaceFormat::NV12:
|
2018-10-11 01:21:53 +03:00
|
|
|
case SurfaceFormat::P010:
|
|
|
|
case SurfaceFormat::P016:
|
2016-02-23 05:26:27 +03:00
|
|
|
case SurfaceFormat::YUV422:
|
2014-10-30 05:31:54 +03:00
|
|
|
return true;
|
|
|
|
default:
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-08-11 00:39:03 +03:00
|
|
|
// The matrix coeffiecients used for YUV to RGB conversion.
|
2019-04-11 15:41:33 +03:00
|
|
|
enum class YUVColorSpace : uint8_t {
|
|
|
|
BT601,
|
|
|
|
BT709,
|
|
|
|
BT2020,
|
2021-03-19 03:58:23 +03:00
|
|
|
Identity, // Todo: s/YUVColorSpace/ColorSpace/, s/Identity/SRGB/
|
|
|
|
Default = BT709,
|
|
|
|
_First = BT601,
|
|
|
|
_Last = Identity,
|
2019-04-11 15:41:33 +03:00
|
|
|
};
|
|
|
|
|
2018-09-25 14:18:34 +03:00
|
|
|
enum class ColorDepth : uint8_t {
|
|
|
|
COLOR_8,
|
|
|
|
COLOR_10,
|
|
|
|
COLOR_12,
|
2018-10-04 12:47:57 +03:00
|
|
|
COLOR_16,
|
2021-03-19 03:58:23 +03:00
|
|
|
_First = COLOR_8,
|
|
|
|
_Last = COLOR_16,
|
2018-09-25 14:18:34 +03:00
|
|
|
};
|
|
|
|
|
2021-03-19 03:58:23 +03:00
|
|
|
enum class ColorRange : uint8_t {
|
|
|
|
LIMITED,
|
|
|
|
FULL,
|
|
|
|
_First = LIMITED,
|
|
|
|
_Last = FULL,
|
|
|
|
};
|
2019-07-26 11:45:22 +03:00
|
|
|
|
2021-06-25 22:16:22 +03:00
|
|
|
// Really "YcbcrColorSpace"
|
|
|
|
enum class YUVRangedColorSpace : uint8_t {
|
|
|
|
BT601_Narrow = 0,
|
|
|
|
BT601_Full,
|
|
|
|
BT709_Narrow,
|
|
|
|
BT709_Full,
|
|
|
|
BT2020_Narrow,
|
|
|
|
BT2020_Full,
|
|
|
|
GbrIdentity,
|
|
|
|
|
|
|
|
_First = BT601_Narrow,
|
|
|
|
_Last = GbrIdentity,
|
|
|
|
Default = BT709_Narrow,
|
|
|
|
};
|
|
|
|
|
|
|
|
struct FromYUVRangedColorSpaceT final {
|
|
|
|
const YUVColorSpace space;
|
|
|
|
const ColorRange range;
|
|
|
|
};
|
|
|
|
|
|
|
|
inline FromYUVRangedColorSpaceT FromYUVRangedColorSpace(
|
|
|
|
const YUVRangedColorSpace s) {
|
|
|
|
switch (s) {
|
|
|
|
case YUVRangedColorSpace::BT601_Narrow:
|
|
|
|
return {YUVColorSpace::BT601, ColorRange::LIMITED};
|
|
|
|
case YUVRangedColorSpace::BT601_Full:
|
|
|
|
return {YUVColorSpace::BT601, ColorRange::FULL};
|
|
|
|
|
|
|
|
case YUVRangedColorSpace::BT709_Narrow:
|
|
|
|
return {YUVColorSpace::BT709, ColorRange::LIMITED};
|
|
|
|
case YUVRangedColorSpace::BT709_Full:
|
|
|
|
return {YUVColorSpace::BT709, ColorRange::FULL};
|
|
|
|
|
|
|
|
case YUVRangedColorSpace::BT2020_Narrow:
|
|
|
|
return {YUVColorSpace::BT2020, ColorRange::LIMITED};
|
|
|
|
case YUVRangedColorSpace::BT2020_Full:
|
|
|
|
return {YUVColorSpace::BT2020, ColorRange::FULL};
|
|
|
|
|
|
|
|
case YUVRangedColorSpace::GbrIdentity:
|
|
|
|
return {YUVColorSpace::Identity, ColorRange::FULL};
|
|
|
|
}
|
|
|
|
MOZ_CRASH("bad YUVRangedColorSpace");
|
|
|
|
}
|
|
|
|
|
|
|
|
// Todo: This should go in the CPP.
|
|
|
|
inline YUVRangedColorSpace ToYUVRangedColorSpace(const YUVColorSpace space,
|
|
|
|
const ColorRange range) {
|
|
|
|
bool narrow;
|
|
|
|
switch (range) {
|
|
|
|
case ColorRange::FULL:
|
|
|
|
narrow = false;
|
|
|
|
break;
|
|
|
|
case ColorRange::LIMITED:
|
|
|
|
narrow = true;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
switch (space) {
|
|
|
|
case YUVColorSpace::Identity:
|
|
|
|
MOZ_ASSERT(range == ColorRange::FULL);
|
|
|
|
return YUVRangedColorSpace::GbrIdentity;
|
|
|
|
|
|
|
|
case YUVColorSpace::BT601:
|
|
|
|
return narrow ? YUVRangedColorSpace::BT601_Narrow
|
|
|
|
: YUVRangedColorSpace::BT601_Full;
|
|
|
|
|
|
|
|
case YUVColorSpace::BT709:
|
|
|
|
return narrow ? YUVRangedColorSpace::BT709_Narrow
|
|
|
|
: YUVRangedColorSpace::BT709_Full;
|
|
|
|
|
|
|
|
case YUVColorSpace::BT2020:
|
|
|
|
return narrow ? YUVRangedColorSpace::BT2020_Narrow
|
|
|
|
: YUVRangedColorSpace::BT2020_Full;
|
|
|
|
}
|
|
|
|
MOZ_CRASH("bad YUVColorSpace");
|
|
|
|
}
|
|
|
|
|
|
|
|
template <typename DescriptorT>
|
|
|
|
inline YUVRangedColorSpace GetYUVRangedColorSpace(const DescriptorT& d) {
|
|
|
|
return ToYUVRangedColorSpace(d.yUVColorSpace(), d.colorRange());
|
|
|
|
}
|
|
|
|
|
2018-10-09 15:56:25 +03:00
|
|
|
static inline SurfaceFormat SurfaceFormatForColorDepth(ColorDepth aColorDepth) {
|
|
|
|
SurfaceFormat format = SurfaceFormat::A8;
|
|
|
|
switch (aColorDepth) {
|
|
|
|
case ColorDepth::COLOR_8:
|
|
|
|
break;
|
|
|
|
case ColorDepth::COLOR_10:
|
|
|
|
case ColorDepth::COLOR_12:
|
|
|
|
case ColorDepth::COLOR_16:
|
|
|
|
format = SurfaceFormat::A16;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
return format;
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline uint32_t BitDepthForColorDepth(ColorDepth aColorDepth) {
|
|
|
|
uint32_t depth = 8;
|
|
|
|
switch (aColorDepth) {
|
|
|
|
case ColorDepth::COLOR_8:
|
|
|
|
break;
|
|
|
|
case ColorDepth::COLOR_10:
|
|
|
|
depth = 10;
|
|
|
|
break;
|
|
|
|
case ColorDepth::COLOR_12:
|
|
|
|
depth = 12;
|
|
|
|
break;
|
|
|
|
case ColorDepth::COLOR_16:
|
|
|
|
depth = 16;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
return depth;
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline ColorDepth ColorDepthForBitDepth(uint8_t aBitDepth) {
|
|
|
|
ColorDepth depth = ColorDepth::COLOR_8;
|
|
|
|
switch (aBitDepth) {
|
|
|
|
case 8:
|
|
|
|
break;
|
|
|
|
case 10:
|
|
|
|
depth = ColorDepth::COLOR_10;
|
|
|
|
break;
|
|
|
|
case 12:
|
|
|
|
depth = ColorDepth::COLOR_12;
|
|
|
|
break;
|
|
|
|
case 16:
|
|
|
|
depth = ColorDepth::COLOR_16;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
return depth;
|
|
|
|
}
|
|
|
|
|
|
|
|
// 10 and 12 bits color depth image are using 16 bits integers for storage
|
|
|
|
// As such we need to rescale the value from 10 or 12 bits to 16.
|
|
|
|
static inline uint32_t RescalingFactorForColorDepth(ColorDepth aColorDepth) {
|
|
|
|
uint32_t factor = 1;
|
|
|
|
switch (aColorDepth) {
|
|
|
|
case ColorDepth::COLOR_8:
|
|
|
|
break;
|
|
|
|
case ColorDepth::COLOR_10:
|
|
|
|
factor = 64;
|
|
|
|
break;
|
|
|
|
case ColorDepth::COLOR_12:
|
|
|
|
factor = 16;
|
|
|
|
break;
|
|
|
|
case ColorDepth::COLOR_16:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
return factor;
|
|
|
|
}
|
|
|
|
|
2015-01-26 01:22:07 +03:00
|
|
|
enum class FilterType : int8_t {
|
2014-01-10 23:06:16 +04:00
|
|
|
BLEND = 0,
|
|
|
|
TRANSFORM,
|
|
|
|
MORPHOLOGY,
|
|
|
|
COLOR_MATRIX,
|
|
|
|
FLOOD,
|
|
|
|
TILE,
|
|
|
|
TABLE_TRANSFER,
|
|
|
|
DISCRETE_TRANSFER,
|
|
|
|
LINEAR_TRANSFER,
|
|
|
|
GAMMA_TRANSFER,
|
|
|
|
CONVOLVE_MATRIX,
|
|
|
|
DISPLACEMENT_MAP,
|
|
|
|
TURBULENCE,
|
|
|
|
ARITHMETIC_COMBINE,
|
|
|
|
COMPOSITE,
|
|
|
|
DIRECTIONAL_BLUR,
|
|
|
|
GAUSSIAN_BLUR,
|
|
|
|
POINT_DIFFUSE,
|
|
|
|
POINT_SPECULAR,
|
|
|
|
SPOT_DIFFUSE,
|
|
|
|
SPOT_SPECULAR,
|
|
|
|
DISTANT_DIFFUSE,
|
|
|
|
DISTANT_SPECULAR,
|
|
|
|
CROP,
|
|
|
|
PREMULTIPLY,
|
2018-07-17 22:11:13 +03:00
|
|
|
UNPREMULTIPLY,
|
|
|
|
OPACITY
|
2015-01-26 01:22:07 +03:00
|
|
|
};
|
2013-11-27 15:22:07 +04:00
|
|
|
|
2015-01-26 01:22:07 +03:00
|
|
|
enum class DrawTargetType : int8_t {
|
2014-06-27 13:17:49 +04:00
|
|
|
SOFTWARE_RASTER = 0,
|
|
|
|
HARDWARE_RASTER,
|
|
|
|
VECTOR
|
2015-01-26 01:22:07 +03:00
|
|
|
};
|
2014-06-27 13:17:49 +04:00
|
|
|
|
2015-01-26 01:22:07 +03:00
|
|
|
enum class BackendType : int8_t {
|
2014-01-10 23:06:16 +04:00
|
|
|
NONE = 0,
|
2016-02-13 16:33:28 +03:00
|
|
|
DIRECT2D, // Used for version independent D2D objects.
|
2014-01-10 23:06:16 +04:00
|
|
|
CAIRO,
|
|
|
|
SKIA,
|
|
|
|
RECORDING,
|
2016-08-04 21:33:44 +03:00
|
|
|
DIRECT2D1_1,
|
2017-09-21 22:15:58 +03:00
|
|
|
WEBRENDER_TEXT,
|
2019-01-14 03:16:17 +03:00
|
|
|
CAPTURE, // Used for paths
|
2016-08-04 21:33:44 +03:00
|
|
|
|
|
|
|
// Add new entries above this line.
|
|
|
|
BACKEND_LAST
|
2015-01-26 01:22:07 +03:00
|
|
|
};
|
2011-06-24 21:41:16 +04:00
|
|
|
|
2015-01-26 01:22:07 +03:00
|
|
|
enum class FontType : int8_t {
|
2014-01-10 23:06:16 +04:00
|
|
|
DWRITE,
|
|
|
|
GDI,
|
|
|
|
MAC,
|
2017-04-07 00:41:02 +03:00
|
|
|
FONTCONFIG,
|
2018-06-15 02:42:56 +03:00
|
|
|
FREETYPE,
|
|
|
|
UNKNOWN
|
2015-01-26 01:22:07 +03:00
|
|
|
};
|
2011-06-24 21:41:16 +04:00
|
|
|
|
2015-01-26 01:22:07 +03:00
|
|
|
enum class NativeSurfaceType : int8_t {
|
2014-01-10 23:06:16 +04:00
|
|
|
D3D10_TEXTURE,
|
|
|
|
CAIRO_CONTEXT,
|
|
|
|
CGCONTEXT,
|
2014-03-06 01:49:37 +04:00
|
|
|
CGCONTEXT_ACCELERATED,
|
|
|
|
OPENGL_TEXTURE
|
2015-01-26 01:22:07 +03:00
|
|
|
};
|
2011-06-24 21:41:16 +04:00
|
|
|
|
2015-01-26 01:22:07 +03:00
|
|
|
enum class FontStyle : int8_t { NORMAL, ITALIC, BOLD, BOLD_ITALIC };
|
2012-05-17 02:30:10 +04:00
|
|
|
|
2015-01-26 01:22:07 +03:00
|
|
|
enum class FontHinting : int8_t { NONE, LIGHT, NORMAL, FULL };
|
2013-06-05 21:48:59 +04:00
|
|
|
|
2015-01-26 01:22:07 +03:00
|
|
|
enum class CompositionOp : int8_t {
|
2014-01-10 23:06:17 +04:00
|
|
|
OP_OVER,
|
|
|
|
OP_ADD,
|
|
|
|
OP_ATOP,
|
|
|
|
OP_OUT,
|
|
|
|
OP_IN,
|
|
|
|
OP_SOURCE,
|
|
|
|
OP_DEST_IN,
|
|
|
|
OP_DEST_OUT,
|
|
|
|
OP_DEST_OVER,
|
|
|
|
OP_DEST_ATOP,
|
|
|
|
OP_XOR,
|
|
|
|
OP_MULTIPLY,
|
|
|
|
OP_SCREEN,
|
|
|
|
OP_OVERLAY,
|
|
|
|
OP_DARKEN,
|
|
|
|
OP_LIGHTEN,
|
|
|
|
OP_COLOR_DODGE,
|
|
|
|
OP_COLOR_BURN,
|
|
|
|
OP_HARD_LIGHT,
|
|
|
|
OP_SOFT_LIGHT,
|
|
|
|
OP_DIFFERENCE,
|
|
|
|
OP_EXCLUSION,
|
|
|
|
OP_HUE,
|
|
|
|
OP_SATURATION,
|
|
|
|
OP_COLOR,
|
|
|
|
OP_LUMINOSITY,
|
|
|
|
OP_COUNT
|
2015-01-26 01:22:07 +03:00
|
|
|
};
|
2014-01-10 23:06:17 +04:00
|
|
|
|
2015-11-23 19:17:35 +03:00
|
|
|
enum class Axis : int8_t { X_AXIS, Y_AXIS, BOTH };
|
|
|
|
|
2015-01-26 01:22:07 +03:00
|
|
|
enum class ExtendMode : int8_t {
|
2015-11-23 19:17:35 +03:00
|
|
|
CLAMP, // Do not repeat
|
|
|
|
REPEAT, // Repeat in both axis
|
|
|
|
REPEAT_X, // Only X axis
|
|
|
|
REPEAT_Y, // Only Y axis
|
|
|
|
REFLECT // Mirror the image
|
2015-01-26 01:22:07 +03:00
|
|
|
};
|
2014-01-10 23:06:17 +04:00
|
|
|
|
2015-01-26 01:22:07 +03:00
|
|
|
enum class FillRule : int8_t { FILL_WINDING, FILL_EVEN_ODD };
|
2014-01-10 23:06:17 +04:00
|
|
|
|
2015-01-26 01:22:07 +03:00
|
|
|
enum class AntialiasMode : int8_t { NONE, GRAY, SUBPIXEL, DEFAULT };
|
2014-01-10 23:06:17 +04:00
|
|
|
|
2016-05-25 19:01:18 +03:00
|
|
|
// See https://en.wikipedia.org/wiki/Texture_filtering
|
|
|
|
enum class SamplingFilter : int8_t {
|
2014-01-10 23:06:17 +04:00
|
|
|
GOOD,
|
|
|
|
LINEAR,
|
2015-10-06 03:12:46 +03:00
|
|
|
POINT,
|
|
|
|
SENTINEL // one past the last valid value
|
2015-01-26 01:22:07 +03:00
|
|
|
};
|
2014-01-10 23:06:17 +04:00
|
|
|
|
2020-10-08 15:40:05 +03:00
|
|
|
std::ostream& operator<<(std::ostream& aOut, const SamplingFilter& aFilter);
|
|
|
|
|
2020-03-02 13:20:57 +03:00
|
|
|
// clang-format off
|
|
|
|
MOZ_DEFINE_ENUM_CLASS_WITH_BASE(PatternType, int8_t, (
|
2014-01-10 23:06:17 +04:00
|
|
|
COLOR,
|
|
|
|
SURFACE,
|
|
|
|
LINEAR_GRADIENT,
|
2020-02-21 03:12:47 +03:00
|
|
|
RADIAL_GRADIENT,
|
|
|
|
CONIC_GRADIENT
|
2020-03-02 13:20:57 +03:00
|
|
|
));
|
|
|
|
// clang-format on
|
2014-01-10 23:06:17 +04:00
|
|
|
|
2015-01-26 01:22:07 +03:00
|
|
|
enum class JoinStyle : int8_t {
|
2014-01-10 23:06:17 +04:00
|
|
|
BEVEL,
|
|
|
|
ROUND,
|
2014-12-16 18:40:59 +03:00
|
|
|
MITER, //!< Mitered if within the miter limit, else, if the backed supports
|
|
|
|
//!< it (D2D), the miter is clamped. If the backend does not support
|
|
|
|
//!< miter clamping the behavior is as for MITER_OR_BEVEL.
|
|
|
|
MITER_OR_BEVEL //!< Mitered if within the miter limit, else beveled.
|
2015-01-26 01:22:07 +03:00
|
|
|
};
|
2014-01-10 23:06:17 +04:00
|
|
|
|
2015-01-26 01:22:07 +03:00
|
|
|
enum class CapStyle : int8_t { BUTT, ROUND, SQUARE };
|
2014-01-10 23:06:17 +04:00
|
|
|
|
2015-01-26 01:22:07 +03:00
|
|
|
enum class SamplingBounds : int8_t { UNBOUNDED, BOUNDED };
|
2011-06-24 21:41:16 +04:00
|
|
|
|
2017-06-02 21:13:36 +03:00
|
|
|
// Moz2d version for SVG mask types
|
|
|
|
enum class LuminanceType : int8_t {
|
|
|
|
LUMINANCE,
|
|
|
|
LINEARRGB,
|
|
|
|
};
|
|
|
|
|
2020-03-09 17:16:17 +03:00
|
|
|
/* Color is stored in non-premultiplied form in sRGB color space */
|
|
|
|
struct sRGBColor {
|
2011-06-24 21:41:16 +04:00
|
|
|
public:
|
2020-10-15 07:54:41 +03:00
|
|
|
constexpr sRGBColor() : r(0.0f), g(0.0f), b(0.0f), a(0.0f) {}
|
|
|
|
constexpr sRGBColor(Float aR, Float aG, Float aB, Float aA)
|
2020-03-09 17:16:17 +03:00
|
|
|
: r(aR), g(aG), b(aB), a(aA) {}
|
2020-10-15 07:54:41 +03:00
|
|
|
constexpr sRGBColor(Float aR, Float aG, Float aB)
|
|
|
|
: r(aR), g(aG), b(aB), a(1.0f) {}
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2021-02-10 03:47:38 +03:00
|
|
|
static constexpr sRGBColor White(float aA) {
|
|
|
|
return sRGBColor(1.f, 1.f, 1.f, aA);
|
|
|
|
}
|
2020-03-09 17:16:17 +03:00
|
|
|
|
2021-02-10 03:47:38 +03:00
|
|
|
static constexpr sRGBColor Black(float aA) {
|
|
|
|
return sRGBColor(0.f, 0.f, 0.f, aA);
|
|
|
|
}
|
2020-03-09 17:16:17 +03:00
|
|
|
|
2021-02-10 03:47:38 +03:00
|
|
|
static constexpr sRGBColor OpaqueWhite() { return White(1.f); }
|
2020-03-09 17:16:17 +03:00
|
|
|
|
2021-02-10 03:47:38 +03:00
|
|
|
static constexpr sRGBColor OpaqueBlack() { return Black(1.f); }
|
2020-03-09 17:16:17 +03:00
|
|
|
|
2021-02-10 03:47:38 +03:00
|
|
|
static constexpr sRGBColor FromU8(uint8_t aR, uint8_t aG, uint8_t aB,
|
|
|
|
uint8_t aA) {
|
2020-03-09 17:16:17 +03:00
|
|
|
return sRGBColor(float(aR) / 255.f, float(aG) / 255.f, float(aB) / 255.f,
|
|
|
|
float(aA) / 255.f);
|
|
|
|
}
|
|
|
|
|
2021-02-10 03:47:38 +03:00
|
|
|
static constexpr sRGBColor FromABGR(uint32_t aColor) {
|
|
|
|
return sRGBColor(((aColor >> 0) & 0xff) * (1.0f / 255.0f),
|
|
|
|
((aColor >> 8) & 0xff) * (1.0f / 255.0f),
|
|
|
|
((aColor >> 16) & 0xff) * (1.0f / 255.0f),
|
|
|
|
((aColor >> 24) & 0xff) * (1.0f / 255.0f));
|
2011-06-24 21:41:16 +04:00
|
|
|
}
|
|
|
|
|
2015-09-25 04:16:50 +03:00
|
|
|
// The "Unusual" prefix is to avoid unintentionally using this function when
|
|
|
|
// FromABGR(), which is much more common, is needed.
|
2021-02-10 03:47:38 +03:00
|
|
|
static constexpr sRGBColor UnusualFromARGB(uint32_t aColor) {
|
|
|
|
return sRGBColor(((aColor >> 16) & 0xff) * (1.0f / 255.0f),
|
|
|
|
((aColor >> 8) & 0xff) * (1.0f / 255.0f),
|
|
|
|
((aColor >> 0) & 0xff) * (1.0f / 255.0f),
|
|
|
|
((aColor >> 24) & 0xff) * (1.0f / 255.0f));
|
2014-10-17 15:53:15 +04:00
|
|
|
}
|
|
|
|
|
2021-05-11 16:24:24 +03:00
|
|
|
constexpr uint32_t ToABGR() const {
|
2012-10-27 08:32:52 +04:00
|
|
|
return uint32_t(r * 255.0f) | uint32_t(g * 255.0f) << 8 |
|
|
|
|
uint32_t(b * 255.0f) << 16 | uint32_t(a * 255.0f) << 24;
|
|
|
|
}
|
|
|
|
|
2021-05-11 16:24:24 +03:00
|
|
|
constexpr sRGBColor Premultiplied() const {
|
|
|
|
return sRGBColor(r * a, g * a, b * a, a);
|
|
|
|
}
|
|
|
|
|
|
|
|
constexpr sRGBColor Unpremultiplied() const {
|
|
|
|
return a > 0.f ? sRGBColor(r / a, g / a, b / a, a) : *this;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Returns aFrac*aC2 + (1 - aFrac)*C1. The interpolation is done in
|
|
|
|
// unpremultiplied space, which is what SVG gradients and cairo gradients
|
|
|
|
// expect.
|
|
|
|
constexpr static sRGBColor InterpolatePremultiplied(const sRGBColor& aC1,
|
|
|
|
const sRGBColor& aC2,
|
|
|
|
float aFrac) {
|
|
|
|
double other = 1 - aFrac;
|
|
|
|
return sRGBColor(
|
|
|
|
aC2.r * aFrac + aC1.r * other, aC2.g * aFrac + aC1.g * other,
|
|
|
|
aC2.b * aFrac + aC1.b * other, aC2.a * aFrac + aC1.a * other);
|
|
|
|
}
|
|
|
|
|
|
|
|
constexpr static sRGBColor Interpolate(const sRGBColor& aC1,
|
|
|
|
const sRGBColor& aC2, float aFrac) {
|
|
|
|
return InterpolatePremultiplied(aC1.Premultiplied(), aC2.Premultiplied(),
|
|
|
|
aFrac)
|
|
|
|
.Unpremultiplied();
|
|
|
|
}
|
|
|
|
|
2015-09-25 04:16:50 +03:00
|
|
|
// The "Unusual" prefix is to avoid unintentionally using this function when
|
|
|
|
// ToABGR(), which is much more common, is needed.
|
|
|
|
uint32_t UnusualToARGB() const {
|
2014-10-17 15:53:15 +04:00
|
|
|
return uint32_t(b * 255.0f) | uint32_t(g * 255.0f) << 8 |
|
|
|
|
uint32_t(r * 255.0f) << 16 | uint32_t(a * 255.0f) << 24;
|
|
|
|
}
|
|
|
|
|
2020-03-09 17:16:17 +03:00
|
|
|
bool operator==(const sRGBColor& aColor) const {
|
2015-07-31 21:27:19 +03:00
|
|
|
return r == aColor.r && g == aColor.g && b == aColor.b && a == aColor.a;
|
|
|
|
}
|
|
|
|
|
2020-03-09 17:16:17 +03:00
|
|
|
bool operator!=(const sRGBColor& aColor) const { return !(*this == aColor); }
|
|
|
|
|
|
|
|
Float r, g, b, a;
|
|
|
|
};
|
|
|
|
|
|
|
|
/* Color is stored in non-premultiplied form in device color space */
|
|
|
|
struct DeviceColor {
|
|
|
|
public:
|
|
|
|
DeviceColor() : r(0.0f), g(0.0f), b(0.0f), a(0.0f) {}
|
|
|
|
DeviceColor(Float aR, Float aG, Float aB, Float aA)
|
|
|
|
: r(aR), g(aG), b(aB), a(aA) {}
|
|
|
|
DeviceColor(Float aR, Float aG, Float aB) : r(aR), g(aG), b(aB), a(1.0f) {}
|
|
|
|
|
|
|
|
/* The following Mask* variants are helpers used to make it clear when a
|
|
|
|
* particular color is being used for masking purposes. These masks should
|
|
|
|
* never be colored managed. */
|
|
|
|
static DeviceColor Mask(float aC, float aA) {
|
|
|
|
return DeviceColor(aC, aC, aC, aA);
|
|
|
|
}
|
|
|
|
|
|
|
|
static DeviceColor MaskWhite(float aA) { return Mask(1.f, aA); }
|
|
|
|
|
|
|
|
static DeviceColor MaskBlack(float aA) { return Mask(0.f, aA); }
|
|
|
|
|
|
|
|
static DeviceColor MaskOpaqueWhite() { return MaskWhite(1.f); }
|
|
|
|
|
|
|
|
static DeviceColor MaskOpaqueBlack() { return MaskBlack(1.f); }
|
|
|
|
|
|
|
|
static DeviceColor FromU8(uint8_t aR, uint8_t aG, uint8_t aB, uint8_t aA) {
|
|
|
|
return DeviceColor(float(aR) / 255.f, float(aG) / 255.f, float(aB) / 255.f,
|
|
|
|
float(aA) / 255.f);
|
|
|
|
}
|
|
|
|
|
|
|
|
static DeviceColor FromABGR(uint32_t aColor) {
|
|
|
|
DeviceColor newColor(((aColor >> 0) & 0xff) * (1.0f / 255.0f),
|
|
|
|
((aColor >> 8) & 0xff) * (1.0f / 255.0f),
|
|
|
|
((aColor >> 16) & 0xff) * (1.0f / 255.0f),
|
|
|
|
((aColor >> 24) & 0xff) * (1.0f / 255.0f));
|
|
|
|
|
|
|
|
return newColor;
|
|
|
|
}
|
|
|
|
|
|
|
|
// The "Unusual" prefix is to avoid unintentionally using this function when
|
|
|
|
// FromABGR(), which is much more common, is needed.
|
|
|
|
static DeviceColor UnusualFromARGB(uint32_t aColor) {
|
|
|
|
DeviceColor newColor(((aColor >> 16) & 0xff) * (1.0f / 255.0f),
|
|
|
|
((aColor >> 8) & 0xff) * (1.0f / 255.0f),
|
|
|
|
((aColor >> 0) & 0xff) * (1.0f / 255.0f),
|
|
|
|
((aColor >> 24) & 0xff) * (1.0f / 255.0f));
|
|
|
|
|
|
|
|
return newColor;
|
|
|
|
}
|
|
|
|
|
|
|
|
uint32_t ToABGR() const {
|
|
|
|
return uint32_t(r * 255.0f) | uint32_t(g * 255.0f) << 8 |
|
|
|
|
uint32_t(b * 255.0f) << 16 | uint32_t(a * 255.0f) << 24;
|
|
|
|
}
|
|
|
|
|
|
|
|
// The "Unusual" prefix is to avoid unintentionally using this function when
|
|
|
|
// ToABGR(), which is much more common, is needed.
|
|
|
|
uint32_t UnusualToARGB() const {
|
|
|
|
return uint32_t(b * 255.0f) | uint32_t(g * 255.0f) << 8 |
|
|
|
|
uint32_t(r * 255.0f) << 16 | uint32_t(a * 255.0f) << 24;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool operator==(const DeviceColor& aColor) const {
|
|
|
|
return r == aColor.r && g == aColor.g && b == aColor.b && a == aColor.a;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool operator!=(const DeviceColor& aColor) const {
|
|
|
|
return !(*this == aColor);
|
|
|
|
}
|
2015-07-31 21:27:19 +03:00
|
|
|
|
2020-09-25 11:57:24 +03:00
|
|
|
friend std::ostream& operator<<(std::ostream& aOut,
|
|
|
|
const DeviceColor& aColor);
|
|
|
|
|
2011-06-24 21:41:16 +04:00
|
|
|
Float r, g, b, a;
|
|
|
|
};
|
|
|
|
|
|
|
|
struct GradientStop {
|
2011-11-02 23:55:03 +04:00
|
|
|
bool operator<(const GradientStop& aOther) const {
|
|
|
|
return offset < aOther.offset;
|
|
|
|
}
|
|
|
|
|
2011-06-24 21:41:16 +04:00
|
|
|
Float offset;
|
2020-03-09 17:16:17 +03:00
|
|
|
DeviceColor color;
|
2011-06-24 21:41:16 +04:00
|
|
|
};
|
|
|
|
|
2015-09-28 14:49:43 +03:00
|
|
|
enum class JobStatus { Complete, Wait, Yield, Error };
|
|
|
|
|
2015-07-13 18:25:42 +03:00
|
|
|
} // namespace gfx
|
|
|
|
} // namespace mozilla
|
2011-06-24 21:41:16 +04:00
|
|
|
|
2016-01-08 07:57:38 +03:00
|
|
|
// XXX: temporary
|
|
|
|
typedef mozilla::gfx::SurfaceFormat gfxImageFormat;
|
|
|
|
|
2014-03-04 03:24:04 +04:00
|
|
|
#if defined(XP_WIN) && defined(MOZ_GFX)
|
2012-05-03 23:21:52 +04:00
|
|
|
# ifdef GFX2D_INTERNAL
|
|
|
|
# define GFX2D_API __declspec(dllexport)
|
2019-01-18 12:16:18 +03:00
|
|
|
# else
|
2012-05-03 23:21:52 +04:00
|
|
|
# define GFX2D_API __declspec(dllimport)
|
2019-01-18 12:16:18 +03:00
|
|
|
# endif
|
2012-05-03 23:21:52 +04:00
|
|
|
#else
|
|
|
|
# define GFX2D_API
|
|
|
|
#endif
|
|
|
|
|
2011-06-24 21:41:16 +04:00
|
|
|
namespace mozilla {
|
2014-11-03 13:01:58 +03:00
|
|
|
|
2014-06-28 14:13:13 +04:00
|
|
|
// Side constants for use in various places.
|
2020-02-11 17:11:06 +03:00
|
|
|
enum Side : uint8_t { eSideTop, eSideRight, eSideBottom, eSideLeft };
|
2014-06-28 14:13:13 +04:00
|
|
|
|
2020-02-04 06:28:27 +03:00
|
|
|
constexpr auto AllPhysicalSides() {
|
|
|
|
return mozilla::MakeInclusiveEnumeratedRange(eSideTop, eSideLeft);
|
|
|
|
}
|
|
|
|
|
2019-11-16 23:59:34 +03:00
|
|
|
enum class SideBits {
|
|
|
|
eNone = 0,
|
|
|
|
eTop = 1 << eSideTop,
|
|
|
|
eRight = 1 << eSideRight,
|
|
|
|
eBottom = 1 << eSideBottom,
|
|
|
|
eLeft = 1 << eSideLeft,
|
|
|
|
eTopBottom = SideBits::eTop | SideBits::eBottom,
|
|
|
|
eLeftRight = SideBits::eLeft | SideBits::eRight,
|
|
|
|
eAll = SideBits::eTopBottom | SideBits::eLeftRight
|
2014-06-28 14:13:13 +04:00
|
|
|
};
|
2015-07-13 18:25:42 +03:00
|
|
|
|
2019-10-08 00:01:53 +03:00
|
|
|
MOZ_MAKE_ENUM_CLASS_BITWISE_OPERATORS(SideBits)
|
|
|
|
|
2020-02-11 17:11:06 +03:00
|
|
|
enum Corner : uint8_t {
|
2017-01-04 11:19:20 +03:00
|
|
|
// This order is important!
|
|
|
|
eCornerTopLeft = 0,
|
|
|
|
eCornerTopRight = 1,
|
|
|
|
eCornerBottomRight = 2,
|
2017-01-04 12:41:49 +03:00
|
|
|
eCornerBottomLeft = 3
|
2017-01-04 11:19:20 +03:00
|
|
|
};
|
|
|
|
|
2017-01-05 12:07:07 +03:00
|
|
|
// RectCornerRadii::radii depends on this value. It is not being added to
|
|
|
|
// Corner because we want to lift the responsibility to handle it in the
|
|
|
|
// switch-case.
|
|
|
|
constexpr int eCornerCount = 4;
|
|
|
|
|
2020-02-04 06:28:35 +03:00
|
|
|
constexpr auto AllPhysicalCorners() {
|
|
|
|
return mozilla::MakeInclusiveEnumeratedRange(eCornerTopLeft,
|
|
|
|
eCornerBottomLeft);
|
2017-01-04 11:19:20 +03:00
|
|
|
}
|
|
|
|
|
2017-01-05 06:31:38 +03:00
|
|
|
// Indices into "half corner" arrays (nsStyleCorners e.g.)
|
2019-02-24 21:47:53 +03:00
|
|
|
enum HalfCorner : uint8_t {
|
2017-01-05 06:31:38 +03:00
|
|
|
// This order is important!
|
|
|
|
eCornerTopLeftX = 0,
|
|
|
|
eCornerTopLeftY = 1,
|
|
|
|
eCornerTopRightX = 2,
|
|
|
|
eCornerTopRightY = 3,
|
|
|
|
eCornerBottomRightX = 4,
|
|
|
|
eCornerBottomRightY = 5,
|
|
|
|
eCornerBottomLeftX = 6,
|
|
|
|
eCornerBottomLeftY = 7
|
|
|
|
};
|
|
|
|
|
2020-02-04 06:28:47 +03:00
|
|
|
constexpr auto AllPhysicalHalfCorners() {
|
|
|
|
return mozilla::MakeInclusiveEnumeratedRange(eCornerTopLeftX,
|
|
|
|
eCornerBottomLeftY);
|
2017-01-05 07:03:23 +03:00
|
|
|
}
|
|
|
|
|
2017-01-05 11:23:16 +03:00
|
|
|
// The result of these conversion functions are exhaustively checked in
|
2019-06-28 12:46:26 +03:00
|
|
|
// nsFrame.cpp, which also serves as usage examples.
|
2017-01-05 11:23:16 +03:00
|
|
|
|
2017-01-05 09:30:14 +03:00
|
|
|
constexpr bool HalfCornerIsX(HalfCorner aHalfCorner) {
|
|
|
|
return !(aHalfCorner % 2);
|
|
|
|
}
|
|
|
|
|
2017-01-05 09:39:58 +03:00
|
|
|
constexpr Corner HalfToFullCorner(HalfCorner aHalfCorner) {
|
|
|
|
return Corner(aHalfCorner / 2);
|
|
|
|
}
|
|
|
|
|
2017-01-05 09:59:17 +03:00
|
|
|
constexpr HalfCorner FullToHalfCorner(Corner aCorner, bool aIsVertical) {
|
|
|
|
return HalfCorner(aCorner * 2 + aIsVertical);
|
|
|
|
}
|
|
|
|
|
2020-11-23 19:21:38 +03:00
|
|
|
constexpr bool SideIsVertical(mozilla::Side aSide) { return aSide % 2; }
|
2017-01-05 11:07:02 +03:00
|
|
|
|
2017-01-05 11:13:34 +03:00
|
|
|
// @param aIsSecond when true, return the clockwise second of the two
|
|
|
|
// corners associated with aSide. For example, with aSide = eSideBottom the
|
|
|
|
// result is eCornerBottomRight when aIsSecond is false, and
|
|
|
|
// eCornerBottomLeft when aIsSecond is true.
|
2020-11-23 19:21:38 +03:00
|
|
|
constexpr Corner SideToFullCorner(mozilla::Side aSide, bool aIsSecond) {
|
2017-01-05 11:13:34 +03:00
|
|
|
return Corner((aSide + aIsSecond) % 4);
|
|
|
|
}
|
|
|
|
|
2017-01-05 11:23:16 +03:00
|
|
|
// @param aIsSecond see SideToFullCorner.
|
|
|
|
// @param aIsParallel return the half-corner that is parallel with aSide
|
|
|
|
// when aIsParallel is true. For example with aSide=eSideTop, aIsSecond=true
|
|
|
|
// the result is eCornerTopRightX when aIsParallel is true, and
|
|
|
|
// eCornerTopRightY when aIsParallel is false (because "X" is parallel with
|
|
|
|
// eSideTop/eSideBottom, similarly "Y" is parallel with
|
|
|
|
// eSideLeft/eSideRight)
|
2020-11-23 19:21:38 +03:00
|
|
|
constexpr HalfCorner SideToHalfCorner(mozilla::Side aSide, bool aIsSecond,
|
2017-01-05 11:23:16 +03:00
|
|
|
bool aIsParallel) {
|
|
|
|
return HalfCorner(((aSide + aIsSecond) * 2 + (aSide + !aIsParallel) % 2) % 8);
|
|
|
|
}
|
|
|
|
|
2016-11-18 10:25:33 +03:00
|
|
|
} // namespace mozilla
|
|
|
|
|
2011-06-24 21:41:16 +04:00
|
|
|
#endif /* MOZILLA_GFX_TYPES_H_ */
|