gfx/thebes/gfx2DGlue.h

Tue, 06 Jan 2015 21:39:09 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Tue, 06 Jan 2015 21:39:09 +0100
branch
TOR_BUG_9701
changeset 8
97036ab72558
permissions
-rw-r--r--

Conditionally force memory storage according to privacy.thirdparty.isolate;
This solves Tor bug #9701, complying with disk avoidance documented in
https://www.torproject.org/projects/torbrowser/design/#disk-avoidance.

michael@0 1 /* This Source Code Form is subject to the terms of the Mozilla Public
michael@0 2 * License, v. 2.0. If a copy of the MPL was not distributed with this
michael@0 3 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
michael@0 4
michael@0 5 #ifndef GFX_2D_GLUE_H
michael@0 6 #define GFX_2D_GLUE_H
michael@0 7
michael@0 8
michael@0 9 #include "gfxPlatform.h"
michael@0 10 #include "gfxRect.h"
michael@0 11 #include "gfxMatrix.h"
michael@0 12 #include "gfx3DMatrix.h"
michael@0 13 #include "gfxContext.h"
michael@0 14 #include "mozilla/gfx/Matrix.h"
michael@0 15 #include "mozilla/gfx/Rect.h"
michael@0 16 #include "mozilla/gfx/2D.h"
michael@0 17 #include "gfxColor.h"
michael@0 18
michael@0 19 namespace mozilla {
michael@0 20 namespace gfx {
michael@0 21 class DrawTarget;
michael@0 22 class SourceSurface;
michael@0 23 class ScaledFont;
michael@0 24 }
michael@0 25 }
michael@0 26
michael@0 27 namespace mozilla {
michael@0 28 namespace gfx {
michael@0 29
michael@0 30 inline Rect ToRect(const gfxRect &aRect)
michael@0 31 {
michael@0 32 return Rect(Float(aRect.x), Float(aRect.y),
michael@0 33 Float(aRect.width), Float(aRect.height));
michael@0 34 }
michael@0 35
michael@0 36 inline Rect ToRect(const nsIntRect &aRect)
michael@0 37 {
michael@0 38 return Rect(aRect.x, aRect.y, aRect.width, aRect.height);
michael@0 39 }
michael@0 40
michael@0 41 inline IntRect ToIntRect(const nsIntRect &aRect)
michael@0 42 {
michael@0 43 return IntRect(aRect.x, aRect.y, aRect.width, aRect.height);
michael@0 44 }
michael@0 45
michael@0 46 inline Color ToColor(const gfxRGBA &aRGBA)
michael@0 47 {
michael@0 48 return Color(Float(aRGBA.r), Float(aRGBA.g),
michael@0 49 Float(aRGBA.b), Float(aRGBA.a));
michael@0 50 }
michael@0 51
michael@0 52 inline Matrix ToMatrix(const gfxMatrix &aMatrix)
michael@0 53 {
michael@0 54 return Matrix(Float(aMatrix.xx), Float(aMatrix.yx), Float(aMatrix.xy),
michael@0 55 Float(aMatrix.yy), Float(aMatrix.x0), Float(aMatrix.y0));
michael@0 56 }
michael@0 57
michael@0 58 inline gfxMatrix ThebesMatrix(const Matrix &aMatrix)
michael@0 59 {
michael@0 60 return gfxMatrix(aMatrix._11, aMatrix._12, aMatrix._21,
michael@0 61 aMatrix._22, aMatrix._31, aMatrix._32);
michael@0 62 }
michael@0 63
michael@0 64 inline Point ToPoint(const gfxPoint &aPoint)
michael@0 65 {
michael@0 66 return Point(Float(aPoint.x), Float(aPoint.y));
michael@0 67 }
michael@0 68
michael@0 69 inline IntPoint ToIntPoint(const nsIntPoint &aPoint)
michael@0 70 {
michael@0 71 return IntPoint(aPoint.x, aPoint.y);
michael@0 72 }
michael@0 73
michael@0 74 inline Size ToSize(const gfxSize &aSize)
michael@0 75 {
michael@0 76 return Size(Float(aSize.width), Float(aSize.height));
michael@0 77 }
michael@0 78
michael@0 79 inline IntSize ToIntSize(const gfxIntSize &aSize)
michael@0 80 {
michael@0 81 return IntSize(aSize.width, aSize.height);
michael@0 82 }
michael@0 83
michael@0 84 inline Filter ToFilter(GraphicsFilter aFilter)
michael@0 85 {
michael@0 86 switch (aFilter) {
michael@0 87 case GraphicsFilter::FILTER_NEAREST:
michael@0 88 return Filter::POINT;
michael@0 89 case GraphicsFilter::FILTER_GOOD:
michael@0 90 return Filter::GOOD;
michael@0 91 default:
michael@0 92 return Filter::LINEAR;
michael@0 93 }
michael@0 94 }
michael@0 95
michael@0 96 inline GraphicsFilter ThebesFilter(Filter aFilter)
michael@0 97 {
michael@0 98 switch (aFilter) {
michael@0 99 case Filter::POINT:
michael@0 100 return GraphicsFilter::FILTER_NEAREST;
michael@0 101 default:
michael@0 102 return GraphicsFilter::FILTER_BEST;
michael@0 103 }
michael@0 104 }
michael@0 105
michael@0 106 inline ExtendMode ToExtendMode(gfxPattern::GraphicsExtend aExtend)
michael@0 107 {
michael@0 108 switch (aExtend) {
michael@0 109 case gfxPattern::EXTEND_REPEAT:
michael@0 110 return ExtendMode::REPEAT;
michael@0 111 case gfxPattern::EXTEND_REFLECT:
michael@0 112 return ExtendMode::REFLECT;
michael@0 113 default:
michael@0 114 return ExtendMode::CLAMP;
michael@0 115 }
michael@0 116 }
michael@0 117
michael@0 118 inline gfxPattern::GraphicsExtend ThebesExtend(ExtendMode aExtend)
michael@0 119 {
michael@0 120 switch (aExtend) {
michael@0 121 case ExtendMode::REPEAT:
michael@0 122 return gfxPattern::EXTEND_REPEAT;
michael@0 123 case ExtendMode::REFLECT:
michael@0 124 return gfxPattern::EXTEND_REFLECT;
michael@0 125 default:
michael@0 126 return gfxPattern::EXTEND_PAD;
michael@0 127 }
michael@0 128 }
michael@0 129
michael@0 130 inline gfxPoint ThebesPoint(const Point &aPoint)
michael@0 131 {
michael@0 132 return gfxPoint(aPoint.x, aPoint.y);
michael@0 133 }
michael@0 134
michael@0 135 inline gfxSize ThebesSize(const Size &aSize)
michael@0 136 {
michael@0 137 return gfxSize(aSize.width, aSize.height);
michael@0 138 }
michael@0 139
michael@0 140 inline gfxIntSize ThebesIntSize(const IntSize &aSize)
michael@0 141 {
michael@0 142 return gfxIntSize(aSize.width, aSize.height);
michael@0 143 }
michael@0 144
michael@0 145 inline gfxRect ThebesRect(const Rect &aRect)
michael@0 146 {
michael@0 147 return gfxRect(aRect.x, aRect.y, aRect.width, aRect.height);
michael@0 148 }
michael@0 149
michael@0 150 inline nsIntRect ThebesIntRect(const IntRect &aRect)
michael@0 151 {
michael@0 152 return nsIntRect(aRect.x, aRect.y, aRect.width, aRect.height);
michael@0 153 }
michael@0 154
michael@0 155 inline gfxRGBA ThebesRGBA(const Color &aColor)
michael@0 156 {
michael@0 157 return gfxRGBA(aColor.r, aColor.g, aColor.b, aColor.a);
michael@0 158 }
michael@0 159
michael@0 160 inline gfxContext::GraphicsLineCap ThebesLineCap(CapStyle aStyle)
michael@0 161 {
michael@0 162 switch (aStyle) {
michael@0 163 case CapStyle::BUTT:
michael@0 164 return gfxContext::LINE_CAP_BUTT;
michael@0 165 case CapStyle::ROUND:
michael@0 166 return gfxContext::LINE_CAP_ROUND;
michael@0 167 case CapStyle::SQUARE:
michael@0 168 return gfxContext::LINE_CAP_SQUARE;
michael@0 169 }
michael@0 170 MOZ_CRASH("Incomplete switch");
michael@0 171 }
michael@0 172
michael@0 173 inline CapStyle ToCapStyle(gfxContext::GraphicsLineCap aStyle)
michael@0 174 {
michael@0 175 switch (aStyle) {
michael@0 176 case gfxContext::LINE_CAP_BUTT:
michael@0 177 return CapStyle::BUTT;
michael@0 178 case gfxContext::LINE_CAP_ROUND:
michael@0 179 return CapStyle::ROUND;
michael@0 180 case gfxContext::LINE_CAP_SQUARE:
michael@0 181 return CapStyle::SQUARE;
michael@0 182 }
michael@0 183 MOZ_CRASH("Incomplete switch");
michael@0 184 }
michael@0 185
michael@0 186 inline gfxContext::GraphicsLineJoin ThebesLineJoin(JoinStyle aStyle)
michael@0 187 {
michael@0 188 switch (aStyle) {
michael@0 189 case JoinStyle::MITER:
michael@0 190 return gfxContext::LINE_JOIN_MITER;
michael@0 191 case JoinStyle::BEVEL:
michael@0 192 return gfxContext::LINE_JOIN_BEVEL;
michael@0 193 case JoinStyle::ROUND:
michael@0 194 return gfxContext::LINE_JOIN_ROUND;
michael@0 195 default:
michael@0 196 return gfxContext::LINE_JOIN_MITER;
michael@0 197 }
michael@0 198 }
michael@0 199
michael@0 200 inline JoinStyle ToJoinStyle(gfxContext::GraphicsLineJoin aStyle)
michael@0 201 {
michael@0 202 switch (aStyle) {
michael@0 203 case gfxContext::LINE_JOIN_MITER:
michael@0 204 return JoinStyle::MITER;
michael@0 205 case gfxContext::LINE_JOIN_BEVEL:
michael@0 206 return JoinStyle::BEVEL;
michael@0 207 case gfxContext::LINE_JOIN_ROUND:
michael@0 208 return JoinStyle::ROUND;
michael@0 209 }
michael@0 210 MOZ_CRASH("Incomplete switch");
michael@0 211 }
michael@0 212
michael@0 213 inline gfxImageFormat SurfaceFormatToImageFormat(SurfaceFormat aFormat)
michael@0 214 {
michael@0 215 switch (aFormat) {
michael@0 216 case SurfaceFormat::B8G8R8A8:
michael@0 217 return gfxImageFormat::ARGB32;
michael@0 218 case SurfaceFormat::B8G8R8X8:
michael@0 219 return gfxImageFormat::RGB24;
michael@0 220 case SurfaceFormat::R5G6B5:
michael@0 221 return gfxImageFormat::RGB16_565;
michael@0 222 case SurfaceFormat::A8:
michael@0 223 return gfxImageFormat::A8;
michael@0 224 default:
michael@0 225 return gfxImageFormat::Unknown;
michael@0 226 }
michael@0 227 }
michael@0 228
michael@0 229 inline SurfaceFormat ImageFormatToSurfaceFormat(gfxImageFormat aFormat)
michael@0 230 {
michael@0 231 switch (aFormat) {
michael@0 232 case gfxImageFormat::ARGB32:
michael@0 233 return SurfaceFormat::B8G8R8A8;
michael@0 234 case gfxImageFormat::RGB24:
michael@0 235 return SurfaceFormat::B8G8R8X8;
michael@0 236 case gfxImageFormat::RGB16_565:
michael@0 237 return SurfaceFormat::R5G6B5;
michael@0 238 case gfxImageFormat::A8:
michael@0 239 return SurfaceFormat::A8;
michael@0 240 default:
michael@0 241 case gfxImageFormat::Unknown:
michael@0 242 return SurfaceFormat::B8G8R8A8;
michael@0 243 }
michael@0 244 }
michael@0 245
michael@0 246 inline gfxContentType ContentForFormat(const SurfaceFormat &aFormat)
michael@0 247 {
michael@0 248 switch (aFormat) {
michael@0 249 case SurfaceFormat::R5G6B5:
michael@0 250 case SurfaceFormat::B8G8R8X8:
michael@0 251 case SurfaceFormat::R8G8B8X8:
michael@0 252 return gfxContentType::COLOR;
michael@0 253 case SurfaceFormat::A8:
michael@0 254 return gfxContentType::ALPHA;
michael@0 255 case SurfaceFormat::B8G8R8A8:
michael@0 256 case SurfaceFormat::R8G8B8A8:
michael@0 257 default:
michael@0 258 return gfxContentType::COLOR_ALPHA;
michael@0 259 }
michael@0 260 }
michael@0 261
michael@0 262 inline CompositionOp CompositionOpForOp(gfxContext::GraphicsOperator aOp)
michael@0 263 {
michael@0 264 switch (aOp) {
michael@0 265 case gfxContext::OPERATOR_ADD:
michael@0 266 return CompositionOp::OP_ADD;
michael@0 267 case gfxContext::OPERATOR_ATOP:
michael@0 268 return CompositionOp::OP_ATOP;
michael@0 269 case gfxContext::OPERATOR_IN:
michael@0 270 return CompositionOp::OP_IN;
michael@0 271 case gfxContext::OPERATOR_OUT:
michael@0 272 return CompositionOp::OP_OUT;
michael@0 273 case gfxContext::OPERATOR_SOURCE:
michael@0 274 return CompositionOp::OP_SOURCE;
michael@0 275 case gfxContext::OPERATOR_DEST_IN:
michael@0 276 return CompositionOp::OP_DEST_IN;
michael@0 277 case gfxContext::OPERATOR_DEST_OUT:
michael@0 278 return CompositionOp::OP_DEST_OUT;
michael@0 279 case gfxContext::OPERATOR_DEST_ATOP:
michael@0 280 return CompositionOp::OP_DEST_ATOP;
michael@0 281 case gfxContext::OPERATOR_XOR:
michael@0 282 return CompositionOp::OP_XOR;
michael@0 283 case gfxContext::OPERATOR_MULTIPLY:
michael@0 284 return CompositionOp::OP_MULTIPLY;
michael@0 285 case gfxContext::OPERATOR_SCREEN:
michael@0 286 return CompositionOp::OP_SCREEN;
michael@0 287 case gfxContext::OPERATOR_OVERLAY:
michael@0 288 return CompositionOp::OP_OVERLAY;
michael@0 289 case gfxContext::OPERATOR_DARKEN:
michael@0 290 return CompositionOp::OP_DARKEN;
michael@0 291 case gfxContext::OPERATOR_LIGHTEN:
michael@0 292 return CompositionOp::OP_LIGHTEN;
michael@0 293 case gfxContext::OPERATOR_COLOR_DODGE:
michael@0 294 return CompositionOp::OP_COLOR_DODGE;
michael@0 295 case gfxContext::OPERATOR_COLOR_BURN:
michael@0 296 return CompositionOp::OP_COLOR_BURN;
michael@0 297 case gfxContext::OPERATOR_HARD_LIGHT:
michael@0 298 return CompositionOp::OP_HARD_LIGHT;
michael@0 299 case gfxContext::OPERATOR_SOFT_LIGHT:
michael@0 300 return CompositionOp::OP_SOFT_LIGHT;
michael@0 301 case gfxContext::OPERATOR_DIFFERENCE:
michael@0 302 return CompositionOp::OP_DIFFERENCE;
michael@0 303 case gfxContext::OPERATOR_EXCLUSION:
michael@0 304 return CompositionOp::OP_EXCLUSION;
michael@0 305 case gfxContext::OPERATOR_HUE:
michael@0 306 return CompositionOp::OP_HUE;
michael@0 307 case gfxContext::OPERATOR_SATURATION:
michael@0 308 return CompositionOp::OP_SATURATION;
michael@0 309 case gfxContext::OPERATOR_COLOR:
michael@0 310 return CompositionOp::OP_COLOR;
michael@0 311 case gfxContext::OPERATOR_LUMINOSITY:
michael@0 312 return CompositionOp::OP_LUMINOSITY;
michael@0 313 default:
michael@0 314 return CompositionOp::OP_OVER;
michael@0 315 }
michael@0 316 }
michael@0 317
michael@0 318 inline gfxContext::GraphicsOperator ThebesOp(CompositionOp aOp)
michael@0 319 {
michael@0 320 switch (aOp) {
michael@0 321 case CompositionOp::OP_ADD:
michael@0 322 return gfxContext::OPERATOR_ADD;
michael@0 323 case CompositionOp::OP_ATOP:
michael@0 324 return gfxContext::OPERATOR_ATOP;
michael@0 325 case CompositionOp::OP_IN:
michael@0 326 return gfxContext::OPERATOR_IN;
michael@0 327 case CompositionOp::OP_OUT:
michael@0 328 return gfxContext::OPERATOR_OUT;
michael@0 329 case CompositionOp::OP_SOURCE:
michael@0 330 return gfxContext::OPERATOR_SOURCE;
michael@0 331 case CompositionOp::OP_DEST_IN:
michael@0 332 return gfxContext::OPERATOR_DEST_IN;
michael@0 333 case CompositionOp::OP_DEST_OUT:
michael@0 334 return gfxContext::OPERATOR_DEST_OUT;
michael@0 335 case CompositionOp::OP_DEST_ATOP:
michael@0 336 return gfxContext::OPERATOR_DEST_ATOP;
michael@0 337 case CompositionOp::OP_XOR:
michael@0 338 return gfxContext::OPERATOR_XOR;
michael@0 339 case CompositionOp::OP_MULTIPLY:
michael@0 340 return gfxContext::OPERATOR_MULTIPLY;
michael@0 341 case CompositionOp::OP_SCREEN:
michael@0 342 return gfxContext::OPERATOR_SCREEN;
michael@0 343 case CompositionOp::OP_OVERLAY:
michael@0 344 return gfxContext::OPERATOR_OVERLAY;
michael@0 345 case CompositionOp::OP_DARKEN:
michael@0 346 return gfxContext::OPERATOR_DARKEN;
michael@0 347 case CompositionOp::OP_LIGHTEN:
michael@0 348 return gfxContext::OPERATOR_LIGHTEN;
michael@0 349 case CompositionOp::OP_COLOR_DODGE:
michael@0 350 return gfxContext::OPERATOR_COLOR_DODGE;
michael@0 351 case CompositionOp::OP_COLOR_BURN:
michael@0 352 return gfxContext::OPERATOR_COLOR_BURN;
michael@0 353 case CompositionOp::OP_HARD_LIGHT:
michael@0 354 return gfxContext::OPERATOR_HARD_LIGHT;
michael@0 355 case CompositionOp::OP_SOFT_LIGHT:
michael@0 356 return gfxContext::OPERATOR_SOFT_LIGHT;
michael@0 357 case CompositionOp::OP_DIFFERENCE:
michael@0 358 return gfxContext::OPERATOR_DIFFERENCE;
michael@0 359 case CompositionOp::OP_EXCLUSION:
michael@0 360 return gfxContext::OPERATOR_EXCLUSION;
michael@0 361 case CompositionOp::OP_HUE:
michael@0 362 return gfxContext::OPERATOR_HUE;
michael@0 363 case CompositionOp::OP_SATURATION:
michael@0 364 return gfxContext::OPERATOR_SATURATION;
michael@0 365 case CompositionOp::OP_COLOR:
michael@0 366 return gfxContext::OPERATOR_COLOR;
michael@0 367 case CompositionOp::OP_LUMINOSITY:
michael@0 368 return gfxContext::OPERATOR_LUMINOSITY;
michael@0 369 default:
michael@0 370 return gfxContext::OPERATOR_OVER;
michael@0 371 }
michael@0 372 }
michael@0 373
michael@0 374 inline void
michael@0 375 ToMatrix4x4(const gfx3DMatrix& aIn, Matrix4x4& aOut)
michael@0 376 {
michael@0 377 aOut._11 = aIn._11;
michael@0 378 aOut._12 = aIn._12;
michael@0 379 aOut._13 = aIn._13;
michael@0 380 aOut._14 = aIn._14;
michael@0 381 aOut._21 = aIn._21;
michael@0 382 aOut._22 = aIn._22;
michael@0 383 aOut._23 = aIn._23;
michael@0 384 aOut._24 = aIn._24;
michael@0 385 aOut._31 = aIn._31;
michael@0 386 aOut._32 = aIn._32;
michael@0 387 aOut._33 = aIn._33;
michael@0 388 aOut._34 = aIn._34;
michael@0 389 aOut._41 = aIn._41;
michael@0 390 aOut._42 = aIn._42;
michael@0 391 aOut._43 = aIn._43;
michael@0 392 aOut._44 = aIn._44;
michael@0 393 }
michael@0 394
michael@0 395 inline void
michael@0 396 To3DMatrix(const Matrix4x4& aIn, gfx3DMatrix& aOut)
michael@0 397 {
michael@0 398 aOut._11 = aIn._11;
michael@0 399 aOut._12 = aIn._12;
michael@0 400 aOut._13 = aIn._13;
michael@0 401 aOut._14 = aIn._14;
michael@0 402 aOut._21 = aIn._21;
michael@0 403 aOut._22 = aIn._22;
michael@0 404 aOut._23 = aIn._23;
michael@0 405 aOut._24 = aIn._24;
michael@0 406 aOut._31 = aIn._31;
michael@0 407 aOut._32 = aIn._32;
michael@0 408 aOut._33 = aIn._33;
michael@0 409 aOut._34 = aIn._34;
michael@0 410 aOut._41 = aIn._41;
michael@0 411 aOut._42 = aIn._42;
michael@0 412 aOut._43 = aIn._43;
michael@0 413 aOut._44 = aIn._44;
michael@0 414 }
michael@0 415
michael@0 416 }
michael@0 417 }
michael@0 418
michael@0 419 #endif

mercurial