2011-06-24 21:41:16 +04:00
|
|
|
/* -*- Mode: C++; tab-width: 20; indent-tabs-mode: nil; c-basic-offset: 2 -*-
|
2012-05-21 15:12:37 +04:00
|
|
|
* 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/. */
|
2011-06-24 21:41:16 +04:00
|
|
|
|
|
|
|
#ifndef MOZILLA_GFX_TYPES_H_
|
|
|
|
#define MOZILLA_GFX_TYPES_H_
|
|
|
|
|
2016-05-22 23:31:11 +03:00
|
|
|
#include "mozilla/EndianUtils.h"
|
2016-11-18 10:25:33 +03:00
|
|
|
#include "mozilla/MacroArgs.h" // for MOZ_CONCAT
|
2015-10-19 07:53:40 +03:00
|
|
|
|
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 */
|
2017-01-18 18:12:32 +03:00
|
|
|
TILED, /* Surface from a tiled DrawTarget */
|
|
|
|
DATA_SHARED, /* Data surface using shared memory */
|
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,
|
2015-10-23 09:04:40 +03:00
|
|
|
|
2017-05-18 17:59:06 +03:00
|
|
|
R8G8,
|
|
|
|
|
2015-10-23 09:04:40 +03:00
|
|
|
// These ones are their own special cases.
|
2014-01-10 23:06:16 +04:00
|
|
|
YUV,
|
2015-08-04 00:57:19 +03:00
|
|
|
NV12,
|
2016-02-23 05:26:27 +03:00
|
|
|
YUV422,
|
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.
|
|
|
|
#if MOZ_LITTLE_ENDIAN
|
|
|
|
A8R8G8B8_UINT32 = B8G8R8A8, // 0xAARRGGBB
|
|
|
|
X8R8G8B8_UINT32 = B8G8R8X8 // 0x00RRGGBB
|
|
|
|
#elif MOZ_BIG_ENDIAN
|
|
|
|
A8R8G8B8_UINT32 = A8R8G8B8, // 0xAARRGGBB
|
|
|
|
X8R8G8B8_UINT32 = X8R8G8B8 // 0x00RRGGBB
|
|
|
|
#else
|
|
|
|
# error "bad endianness"
|
|
|
|
#endif
|
2015-01-26 01:22:07 +03:00
|
|
|
};
|
2011-06-24 21:41:16 +04:00
|
|
|
|
2014-10-30 05:31:54 +03:00
|
|
|
inline bool IsOpaque(SurfaceFormat aFormat)
|
|
|
|
{
|
|
|
|
switch (aFormat) {
|
|
|
|
case SurfaceFormat::B8G8R8X8:
|
|
|
|
case SurfaceFormat::R8G8B8X8:
|
2015-10-23 09:01:31 +03:00
|
|
|
case SurfaceFormat::R5G6B5_UINT16:
|
2014-10-30 05:31:54 +03:00
|
|
|
case SurfaceFormat::YUV:
|
2015-08-04 00:57:19 +03:00
|
|
|
case SurfaceFormat::NV12:
|
2016-02-23 05:26:27 +03:00
|
|
|
case SurfaceFormat::YUV422:
|
2014-10-30 05:31:54 +03:00
|
|
|
return true;
|
|
|
|
default:
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
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,
|
|
|
|
UNPREMULTIPLY
|
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,
|
|
|
|
|
|
|
|
// 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,
|
|
|
|
SKIA,
|
|
|
|
CAIRO,
|
2016-07-20 22:07:11 +03:00
|
|
|
COREGRAPHICS,
|
2017-04-07 00:41:02 +03:00
|
|
|
FONTCONFIG,
|
|
|
|
FREETYPE
|
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 NativeFontType : int8_t {
|
2014-01-10 23:06:16 +04:00
|
|
|
DWRITE_FONT_FACE,
|
|
|
|
GDI_FONT_FACE,
|
|
|
|
MAC_FONT_FACE,
|
|
|
|
SKIA_FONT_FACE,
|
|
|
|
CAIRO_FONT_FACE
|
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 {
|
2014-01-10 23:06:16 +04:00
|
|
|
NORMAL,
|
|
|
|
ITALIC,
|
|
|
|
BOLD,
|
|
|
|
BOLD_ITALIC
|
2015-01-26 01:22:07 +03:00
|
|
|
};
|
2012-05-17 02:30:10 +04:00
|
|
|
|
2015-01-26 01:22:07 +03:00
|
|
|
enum class FontHinting : int8_t {
|
2014-01-10 23:06:16 +04:00
|
|
|
NONE,
|
|
|
|
LIGHT,
|
|
|
|
NORMAL,
|
|
|
|
FULL
|
2015-01-26 01:22:07 +03:00
|
|
|
};
|
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 {
|
2014-01-10 23:06:17 +04:00
|
|
|
FILL_WINDING,
|
|
|
|
FILL_EVEN_ODD
|
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 AntialiasMode : int8_t {
|
2014-01-10 23:06:17 +04:00
|
|
|
NONE,
|
|
|
|
GRAY,
|
|
|
|
SUBPIXEL,
|
|
|
|
DEFAULT
|
2015-01-26 01:22:07 +03:00
|
|
|
};
|
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
|
|
|
|
2015-01-26 01:22:07 +03:00
|
|
|
enum class PatternType : int8_t {
|
2014-01-10 23:06:17 +04:00
|
|
|
COLOR,
|
|
|
|
SURFACE,
|
|
|
|
LINEAR_GRADIENT,
|
|
|
|
RADIAL_GRADIENT
|
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 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 {
|
2014-01-10 23:06:17 +04:00
|
|
|
BUTT,
|
|
|
|
ROUND,
|
|
|
|
SQUARE
|
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 SamplingBounds : int8_t {
|
2014-01-10 23:06:17 +04:00
|
|
|
UNBOUNDED,
|
|
|
|
BOUNDED
|
2015-01-26 01:22:07 +03:00
|
|
|
};
|
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,
|
|
|
|
};
|
|
|
|
|
2011-09-24 19:51:29 +04:00
|
|
|
/* Color is stored in non-premultiplied form */
|
2011-06-24 21:41:16 +04:00
|
|
|
struct Color
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
Color()
|
|
|
|
: r(0.0f), g(0.0f), b(0.0f), a(0.0f)
|
|
|
|
{}
|
|
|
|
Color(Float aR, Float aG, Float aB, Float aA)
|
|
|
|
: r(aR), g(aG), b(aB), a(aA)
|
|
|
|
{}
|
|
|
|
Color(Float aR, Float aG, Float aB)
|
|
|
|
: r(aR), g(aG), b(aB), a(1.0f)
|
|
|
|
{}
|
|
|
|
|
|
|
|
static Color FromABGR(uint32_t aColor)
|
|
|
|
{
|
|
|
|
Color 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;
|
|
|
|
}
|
|
|
|
|
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.
|
|
|
|
static Color UnusualFromARGB(uint32_t aColor)
|
2014-10-17 15:53:15 +04:00
|
|
|
{
|
|
|
|
Color 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;
|
|
|
|
}
|
|
|
|
|
2012-10-27 08:32:52 +04:00
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
2015-07-31 21:27:19 +03:00
|
|
|
bool operator==(const Color& aColor) const {
|
|
|
|
return r == aColor.r && g == aColor.g && b == aColor.b && a == aColor.a;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool operator!=(const Color& aColor) const {
|
|
|
|
return !(*this == 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;
|
|
|
|
Color color;
|
|
|
|
};
|
|
|
|
|
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)
|
|
|
|
#else
|
|
|
|
#define GFX2D_API __declspec(dllimport)
|
|
|
|
#endif
|
|
|
|
#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.
|
|
|
|
enum Side { eSideTop, eSideRight, eSideBottom, eSideLeft };
|
|
|
|
|
|
|
|
enum SideBits {
|
|
|
|
eSideBitsNone = 0,
|
|
|
|
eSideBitsTop = 1 << eSideTop,
|
|
|
|
eSideBitsRight = 1 << eSideRight,
|
|
|
|
eSideBitsBottom = 1 << eSideBottom,
|
|
|
|
eSideBitsLeft = 1 << eSideLeft,
|
|
|
|
eSideBitsTopBottom = eSideBitsTop | eSideBitsBottom,
|
|
|
|
eSideBitsLeftRight = eSideBitsLeft | eSideBitsRight,
|
|
|
|
eSideBitsAll = eSideBitsTopBottom | eSideBitsLeftRight
|
|
|
|
};
|
2015-07-13 18:25:42 +03:00
|
|
|
|
2016-11-18 11:28:38 +03:00
|
|
|
// Creates a for loop that walks over the four mozilla::Side values.
|
2016-11-18 10:25:33 +03:00
|
|
|
// We use an int32_t helper variable (instead of a Side) for our loop counter,
|
|
|
|
// to avoid triggering undefined behavior just before we exit the loop (at
|
|
|
|
// which point the counter is incremented beyond the largest valid Side value).
|
|
|
|
#define NS_FOR_CSS_SIDES(var_) \
|
2016-11-18 13:12:25 +03:00
|
|
|
int32_t MOZ_CONCAT(var_,__LINE__) = mozilla::eSideTop; \
|
2016-11-18 11:28:38 +03:00
|
|
|
for (mozilla::Side var_; \
|
2016-11-18 13:12:25 +03:00
|
|
|
MOZ_CONCAT(var_,__LINE__) <= mozilla::eSideLeft && \
|
2017-08-03 21:18:50 +03:00
|
|
|
(static_cast<void>(var_ = mozilla::Side(MOZ_CONCAT(var_,__LINE__))), true); \
|
2016-11-23 11:55:04 +03:00
|
|
|
++MOZ_CONCAT(var_,__LINE__))
|
2016-11-18 10:25:33 +03:00
|
|
|
|
2016-11-23 11:55:04 +03:00
|
|
|
static inline Side& operator++(Side& side) {
|
2016-11-18 13:12:25 +03:00
|
|
|
MOZ_ASSERT(side >= eSideTop && side <= eSideLeft,
|
|
|
|
"Out of range side");
|
|
|
|
side = Side(side + 1);
|
|
|
|
return side;
|
2016-11-18 10:25:33 +03:00
|
|
|
}
|
|
|
|
|
2017-01-04 11:19:20 +03:00
|
|
|
enum Corner {
|
|
|
|
// 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;
|
|
|
|
|
2017-01-04 12:41:49 +03:00
|
|
|
// Creates a for loop that walks over the four mozilla::Corner values. This
|
|
|
|
// implementation uses the same technique as NS_FOR_CSS_SIDES.
|
2017-01-04 12:52:43 +03:00
|
|
|
#define NS_FOR_CSS_FULL_CORNERS(var_) \
|
2017-01-04 12:41:49 +03:00
|
|
|
int32_t MOZ_CONCAT(var_,__LINE__) = mozilla::eCornerTopLeft; \
|
|
|
|
for (mozilla::Corner var_; \
|
|
|
|
MOZ_CONCAT(var_,__LINE__) <= mozilla::eCornerBottomLeft && \
|
2017-08-03 21:18:50 +03:00
|
|
|
(static_cast<void>(var_ = mozilla::Corner(MOZ_CONCAT(var_,__LINE__))), true); \
|
2017-01-04 12:41:49 +03:00
|
|
|
++MOZ_CONCAT(var_,__LINE__))
|
|
|
|
|
|
|
|
static inline Corner operator++(Corner& aCorner) {
|
|
|
|
MOZ_ASSERT(aCorner >= eCornerTopLeft && aCorner <= eCornerBottomLeft,
|
|
|
|
"Out of range corner!");
|
|
|
|
aCorner = Corner(aCorner + 1);
|
|
|
|
return aCorner;
|
2017-01-04 11:19:20 +03:00
|
|
|
}
|
|
|
|
|
2017-01-05 06:31:38 +03:00
|
|
|
// Indices into "half corner" arrays (nsStyleCorners e.g.)
|
|
|
|
enum HalfCorner {
|
|
|
|
// This order is important!
|
|
|
|
eCornerTopLeftX = 0,
|
|
|
|
eCornerTopLeftY = 1,
|
|
|
|
eCornerTopRightX = 2,
|
|
|
|
eCornerTopRightY = 3,
|
|
|
|
eCornerBottomRightX = 4,
|
|
|
|
eCornerBottomRightY = 5,
|
|
|
|
eCornerBottomLeftX = 6,
|
|
|
|
eCornerBottomLeftY = 7
|
|
|
|
};
|
|
|
|
|
2017-01-05 07:03:23 +03:00
|
|
|
// Creates a for loop that walks over the eight mozilla::HalfCorner values.
|
|
|
|
// This implementation uses the same technique as NS_FOR_CSS_SIDES.
|
|
|
|
#define NS_FOR_CSS_HALF_CORNERS(var_) \
|
|
|
|
int32_t MOZ_CONCAT(var_,__LINE__) = mozilla::eCornerTopLeftX; \
|
|
|
|
for (mozilla::HalfCorner var_; \
|
|
|
|
MOZ_CONCAT(var_,__LINE__) <= mozilla::eCornerBottomLeftY && \
|
2017-08-03 21:18:50 +03:00
|
|
|
(static_cast<void>(var_ = mozilla::HalfCorner(MOZ_CONCAT(var_,__LINE__))), true); \
|
2017-01-05 07:03:23 +03:00
|
|
|
++MOZ_CONCAT(var_,__LINE__))
|
|
|
|
|
|
|
|
static inline HalfCorner operator++(HalfCorner& aHalfCorner) {
|
|
|
|
MOZ_ASSERT(aHalfCorner >= eCornerTopLeftX && aHalfCorner <= eCornerBottomLeftY,
|
|
|
|
"Out of range half corner!");
|
|
|
|
aHalfCorner = HalfCorner(aHalfCorner + 1);
|
|
|
|
return aHalfCorner;
|
|
|
|
}
|
|
|
|
|
2017-01-05 11:23:16 +03:00
|
|
|
// The result of these conversion functions are exhaustively checked in
|
|
|
|
// nsStyleCoord.cpp, which also serves as usage examples.
|
|
|
|
|
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);
|
|
|
|
}
|
|
|
|
|
2017-01-05 11:07:02 +03:00
|
|
|
constexpr bool SideIsVertical(Side aSide)
|
|
|
|
{
|
|
|
|
return aSide % 2;
|
|
|
|
}
|
|
|
|
|
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.
|
|
|
|
constexpr Corner SideToFullCorner(Side aSide, bool aIsSecond)
|
|
|
|
{
|
|
|
|
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)
|
|
|
|
constexpr HalfCorner SideToHalfCorner(Side aSide, bool aIsSecond,
|
|
|
|
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_ */
|