DXR is a code search and navigation tool aimed at making sense of large projects. It supports full-text and regex searches as well as structural queries.

Mercurial (5b81998bb7ab)

VCS Links

Line Code
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285
/* 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/. */

#ifndef GFX_2D_GLUE_H
#define GFX_2D_GLUE_H


#include "gfxPlatform.h"
#include "gfxRect.h"
#include "gfxMatrix.h"
#include "gfxContext.h"
#include "mozilla/gfx/Rect.h"
#include "mozilla/gfx/2D.h"

namespace mozilla {
namespace gfx {
class DrawTarget;
class SourceSurface;
class ScaledFont;
}
}

namespace mozilla {
namespace gfx {

inline Rect ToRect(const gfxRect &aRect)
{
  return Rect(Float(aRect.x), Float(aRect.y),
              Float(aRect.width), Float(aRect.height));
}

inline Color ToColor(const gfxRGBA &aRGBA)
{
  return Color(Float(aRGBA.r), Float(aRGBA.g),
               Float(aRGBA.b), Float(aRGBA.a));
}

inline Matrix ToMatrix(const gfxMatrix &aMatrix)
{
  return Matrix(Float(aMatrix.xx), Float(aMatrix.yx), Float(aMatrix.xy),
                Float(aMatrix.yy), Float(aMatrix.x0), Float(aMatrix.y0));
}

inline Point ToPoint(const gfxPoint &aPoint)
{
  return Point(Float(aPoint.x), Float(aPoint.y));
}

inline Size ToSize(const gfxSize &aSize)
{
  return Size(Float(aSize.width), Float(aSize.height));
}

inline Filter ToFilter(gfxPattern::GraphicsFilter aFilter)
{
  switch (aFilter) {
  case gfxPattern::FILTER_NEAREST:
    return FILTER_POINT;
  default:
    return FILTER_LINEAR;
  }
}

inline gfxPattern::GraphicsFilter ThebesFilter(Filter aFilter)
{
  switch (aFilter) {
  case FILTER_POINT:
    return gfxPattern::FILTER_NEAREST;
  default:
    return gfxPattern::FILTER_BEST;
  }
}

inline ExtendMode ToExtendMode(gfxPattern::GraphicsExtend aExtend)
{
  switch (aExtend) {
  case gfxPattern::EXTEND_REPEAT:
    return EXTEND_REPEAT;
  case gfxPattern::EXTEND_REFLECT:
    return EXTEND_REFLECT;
  default:
    return EXTEND_CLAMP;
  }
}

inline gfxPattern::GraphicsExtend ThebesExtend(ExtendMode aExtend)
{
  switch (aExtend) {
  case EXTEND_REPEAT:
    return gfxPattern::EXTEND_REPEAT;
  case EXTEND_REFLECT:
    return gfxPattern::EXTEND_REFLECT;
  default:
    return gfxPattern::EXTEND_PAD;
  }
}

inline gfxPoint ThebesPoint(const Point &aPoint)
{
  return gfxPoint(aPoint.x, aPoint.y);
}

inline gfxSize ThebesSize(const Size &aSize)
{
  return gfxSize(aSize.width, aSize.height);
}

inline gfxIntSize ThebesIntSize(const IntSize &aSize)
{
  return gfxIntSize(aSize.width, aSize.height);
}

inline gfxRect ThebesRect(const Rect &aRect)
{
  return gfxRect(aRect.x, aRect.y, aRect.width, aRect.height);
}

inline gfxRGBA ThebesRGBA(const Color &aColor)
{
  return gfxRGBA(aColor.r, aColor.g, aColor.b, aColor.a);
}

inline gfxContext::GraphicsLineCap ThebesLineCap(CapStyle aStyle)
{
  switch (aStyle) {
  case CAP_BUTT:
    return gfxContext::LINE_CAP_BUTT;
  case CAP_ROUND:
    return gfxContext::LINE_CAP_ROUND;
  case CAP_SQUARE:
    return gfxContext::LINE_CAP_SQUARE;
  }
  MOZ_NOT_REACHED("Incomplete switch");
}

inline CapStyle ToCapStyle(gfxContext::GraphicsLineCap aStyle)
{
  switch (aStyle) {
  case gfxContext::LINE_CAP_BUTT:
    return CAP_BUTT;
  case gfxContext::LINE_CAP_ROUND:
    return CAP_ROUND;
  case gfxContext::LINE_CAP_SQUARE:
    return CAP_SQUARE;
  }
  MOZ_NOT_REACHED("Incomplete switch");
}

inline gfxContext::GraphicsLineJoin ThebesLineJoin(JoinStyle aStyle)
{
  switch (aStyle) {
  case JOIN_MITER:
    return gfxContext::LINE_JOIN_MITER;
  case JOIN_BEVEL:
    return gfxContext::LINE_JOIN_BEVEL;
  case JOIN_ROUND:
    return gfxContext::LINE_JOIN_ROUND;
  default:
    return gfxContext::LINE_JOIN_MITER;
  }
}

inline JoinStyle ToJoinStyle(gfxContext::GraphicsLineJoin aStyle)
{
  switch (aStyle) {
  case gfxContext::LINE_JOIN_MITER:
    return JOIN_MITER;
  case gfxContext::LINE_JOIN_BEVEL:
    return JOIN_BEVEL;
  case gfxContext::LINE_JOIN_ROUND:
    return JOIN_ROUND;
  }
  MOZ_NOT_REACHED("Incomplete switch");
}

inline gfxMatrix ThebesMatrix(const Matrix &aMatrix)
{
  return gfxMatrix(aMatrix._11, aMatrix._12, aMatrix._21,
                   aMatrix._22, aMatrix._31, aMatrix._32);
}

inline gfxASurface::gfxImageFormat SurfaceFormatToImageFormat(SurfaceFormat aFormat)
{
  switch (aFormat) {
  case FORMAT_B8G8R8A8:
    return gfxASurface::ImageFormatARGB32;
  case FORMAT_B8G8R8X8:
    return gfxASurface::ImageFormatRGB24;
  case FORMAT_R5G6B5:
    return gfxASurface::ImageFormatRGB16_565;
  case FORMAT_A8:
    return gfxASurface::ImageFormatA8;
  default:
    return gfxASurface::ImageFormatUnknown;
  }
}

inline SurfaceFormat ImageFormatToSurfaceFormat(gfxASurface::gfxImageFormat aFormat)
{
  switch (aFormat) {
  case gfxASurface::ImageFormatARGB32:
    return FORMAT_B8G8R8A8;
  case gfxASurface::ImageFormatRGB24:
    return FORMAT_B8G8R8X8;
  case gfxASurface::ImageFormatRGB16_565:
    return FORMAT_R5G6B5;
  case gfxASurface::ImageFormatA8:
    return FORMAT_A8;
  default:
  case gfxASurface::ImageFormatUnknown:
    return FORMAT_B8G8R8A8;
  }
}

inline gfxASurface::gfxContentType ContentForFormat(const SurfaceFormat &aFormat)
{
  switch (aFormat) {
  case FORMAT_R5G6B5:
  case FORMAT_B8G8R8X8:
    return gfxASurface::CONTENT_COLOR;
  case FORMAT_A8:
    return gfxASurface::CONTENT_ALPHA;
  case FORMAT_B8G8R8A8:
  default:
    return gfxASurface::CONTENT_COLOR_ALPHA;
  }
}

inline CompositionOp CompositionOpForOp(gfxContext::GraphicsOperator aOp)
{
  switch (aOp) {
  case gfxContext::OPERATOR_ADD:
    return OP_ADD;
  case gfxContext::OPERATOR_ATOP:
    return OP_ATOP;
  case gfxContext::OPERATOR_IN:
    return OP_IN;
  case gfxContext::OPERATOR_OUT:
    return OP_OUT;
  case gfxContext::OPERATOR_SOURCE:
    return OP_SOURCE;
  case gfxContext::OPERATOR_DEST_IN:
    return OP_DEST_IN;
  case gfxContext::OPERATOR_DEST_OUT:
    return OP_DEST_OUT;
  case gfxContext::OPERATOR_DEST_ATOP:
    return OP_DEST_ATOP;
  case gfxContext::OPERATOR_XOR:
    return OP_XOR;
  default:
    return OP_OVER;
  }
}

inline gfxContext::GraphicsOperator ThebesOp(CompositionOp aOp)
{
  switch (aOp) {
  case OP_ADD:
    return gfxContext::OPERATOR_ADD;
  case OP_ATOP:
    return gfxContext::OPERATOR_ATOP;
  case OP_IN:
    return gfxContext::OPERATOR_IN;
  case OP_OUT:
    return gfxContext::OPERATOR_OUT;
  case OP_SOURCE:
    return gfxContext::OPERATOR_SOURCE;
  case OP_DEST_IN:
    return gfxContext::OPERATOR_DEST_IN;
  case OP_DEST_OUT:
    return gfxContext::OPERATOR_DEST_OUT;
  case OP_DEST_ATOP:
    return gfxContext::OPERATOR_DEST_ATOP;
  case OP_XOR:
    return gfxContext::OPERATOR_XOR;
  default:
    return gfxContext::OPERATOR_OVER;
  }
}

}
}

#endif