1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/gfx/thebes/gfx2DGlue.h Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,419 @@ 1.4 +/* This Source Code Form is subject to the terms of the Mozilla Public 1.5 + * License, v. 2.0. If a copy of the MPL was not distributed with this 1.6 + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ 1.7 + 1.8 +#ifndef GFX_2D_GLUE_H 1.9 +#define GFX_2D_GLUE_H 1.10 + 1.11 + 1.12 +#include "gfxPlatform.h" 1.13 +#include "gfxRect.h" 1.14 +#include "gfxMatrix.h" 1.15 +#include "gfx3DMatrix.h" 1.16 +#include "gfxContext.h" 1.17 +#include "mozilla/gfx/Matrix.h" 1.18 +#include "mozilla/gfx/Rect.h" 1.19 +#include "mozilla/gfx/2D.h" 1.20 +#include "gfxColor.h" 1.21 + 1.22 +namespace mozilla { 1.23 +namespace gfx { 1.24 +class DrawTarget; 1.25 +class SourceSurface; 1.26 +class ScaledFont; 1.27 +} 1.28 +} 1.29 + 1.30 +namespace mozilla { 1.31 +namespace gfx { 1.32 + 1.33 +inline Rect ToRect(const gfxRect &aRect) 1.34 +{ 1.35 + return Rect(Float(aRect.x), Float(aRect.y), 1.36 + Float(aRect.width), Float(aRect.height)); 1.37 +} 1.38 + 1.39 +inline Rect ToRect(const nsIntRect &aRect) 1.40 +{ 1.41 + return Rect(aRect.x, aRect.y, aRect.width, aRect.height); 1.42 +} 1.43 + 1.44 +inline IntRect ToIntRect(const nsIntRect &aRect) 1.45 +{ 1.46 + return IntRect(aRect.x, aRect.y, aRect.width, aRect.height); 1.47 +} 1.48 + 1.49 +inline Color ToColor(const gfxRGBA &aRGBA) 1.50 +{ 1.51 + return Color(Float(aRGBA.r), Float(aRGBA.g), 1.52 + Float(aRGBA.b), Float(aRGBA.a)); 1.53 +} 1.54 + 1.55 +inline Matrix ToMatrix(const gfxMatrix &aMatrix) 1.56 +{ 1.57 + return Matrix(Float(aMatrix.xx), Float(aMatrix.yx), Float(aMatrix.xy), 1.58 + Float(aMatrix.yy), Float(aMatrix.x0), Float(aMatrix.y0)); 1.59 +} 1.60 + 1.61 +inline gfxMatrix ThebesMatrix(const Matrix &aMatrix) 1.62 +{ 1.63 + return gfxMatrix(aMatrix._11, aMatrix._12, aMatrix._21, 1.64 + aMatrix._22, aMatrix._31, aMatrix._32); 1.65 +} 1.66 + 1.67 +inline Point ToPoint(const gfxPoint &aPoint) 1.68 +{ 1.69 + return Point(Float(aPoint.x), Float(aPoint.y)); 1.70 +} 1.71 + 1.72 +inline IntPoint ToIntPoint(const nsIntPoint &aPoint) 1.73 +{ 1.74 + return IntPoint(aPoint.x, aPoint.y); 1.75 +} 1.76 + 1.77 +inline Size ToSize(const gfxSize &aSize) 1.78 +{ 1.79 + return Size(Float(aSize.width), Float(aSize.height)); 1.80 +} 1.81 + 1.82 +inline IntSize ToIntSize(const gfxIntSize &aSize) 1.83 +{ 1.84 + return IntSize(aSize.width, aSize.height); 1.85 +} 1.86 + 1.87 +inline Filter ToFilter(GraphicsFilter aFilter) 1.88 +{ 1.89 + switch (aFilter) { 1.90 + case GraphicsFilter::FILTER_NEAREST: 1.91 + return Filter::POINT; 1.92 + case GraphicsFilter::FILTER_GOOD: 1.93 + return Filter::GOOD; 1.94 + default: 1.95 + return Filter::LINEAR; 1.96 + } 1.97 +} 1.98 + 1.99 +inline GraphicsFilter ThebesFilter(Filter aFilter) 1.100 +{ 1.101 + switch (aFilter) { 1.102 + case Filter::POINT: 1.103 + return GraphicsFilter::FILTER_NEAREST; 1.104 + default: 1.105 + return GraphicsFilter::FILTER_BEST; 1.106 + } 1.107 +} 1.108 + 1.109 +inline ExtendMode ToExtendMode(gfxPattern::GraphicsExtend aExtend) 1.110 +{ 1.111 + switch (aExtend) { 1.112 + case gfxPattern::EXTEND_REPEAT: 1.113 + return ExtendMode::REPEAT; 1.114 + case gfxPattern::EXTEND_REFLECT: 1.115 + return ExtendMode::REFLECT; 1.116 + default: 1.117 + return ExtendMode::CLAMP; 1.118 + } 1.119 +} 1.120 + 1.121 +inline gfxPattern::GraphicsExtend ThebesExtend(ExtendMode aExtend) 1.122 +{ 1.123 + switch (aExtend) { 1.124 + case ExtendMode::REPEAT: 1.125 + return gfxPattern::EXTEND_REPEAT; 1.126 + case ExtendMode::REFLECT: 1.127 + return gfxPattern::EXTEND_REFLECT; 1.128 + default: 1.129 + return gfxPattern::EXTEND_PAD; 1.130 + } 1.131 +} 1.132 + 1.133 +inline gfxPoint ThebesPoint(const Point &aPoint) 1.134 +{ 1.135 + return gfxPoint(aPoint.x, aPoint.y); 1.136 +} 1.137 + 1.138 +inline gfxSize ThebesSize(const Size &aSize) 1.139 +{ 1.140 + return gfxSize(aSize.width, aSize.height); 1.141 +} 1.142 + 1.143 +inline gfxIntSize ThebesIntSize(const IntSize &aSize) 1.144 +{ 1.145 + return gfxIntSize(aSize.width, aSize.height); 1.146 +} 1.147 + 1.148 +inline gfxRect ThebesRect(const Rect &aRect) 1.149 +{ 1.150 + return gfxRect(aRect.x, aRect.y, aRect.width, aRect.height); 1.151 +} 1.152 + 1.153 +inline nsIntRect ThebesIntRect(const IntRect &aRect) 1.154 +{ 1.155 + return nsIntRect(aRect.x, aRect.y, aRect.width, aRect.height); 1.156 +} 1.157 + 1.158 +inline gfxRGBA ThebesRGBA(const Color &aColor) 1.159 +{ 1.160 + return gfxRGBA(aColor.r, aColor.g, aColor.b, aColor.a); 1.161 +} 1.162 + 1.163 +inline gfxContext::GraphicsLineCap ThebesLineCap(CapStyle aStyle) 1.164 +{ 1.165 + switch (aStyle) { 1.166 + case CapStyle::BUTT: 1.167 + return gfxContext::LINE_CAP_BUTT; 1.168 + case CapStyle::ROUND: 1.169 + return gfxContext::LINE_CAP_ROUND; 1.170 + case CapStyle::SQUARE: 1.171 + return gfxContext::LINE_CAP_SQUARE; 1.172 + } 1.173 + MOZ_CRASH("Incomplete switch"); 1.174 +} 1.175 + 1.176 +inline CapStyle ToCapStyle(gfxContext::GraphicsLineCap aStyle) 1.177 +{ 1.178 + switch (aStyle) { 1.179 + case gfxContext::LINE_CAP_BUTT: 1.180 + return CapStyle::BUTT; 1.181 + case gfxContext::LINE_CAP_ROUND: 1.182 + return CapStyle::ROUND; 1.183 + case gfxContext::LINE_CAP_SQUARE: 1.184 + return CapStyle::SQUARE; 1.185 + } 1.186 + MOZ_CRASH("Incomplete switch"); 1.187 +} 1.188 + 1.189 +inline gfxContext::GraphicsLineJoin ThebesLineJoin(JoinStyle aStyle) 1.190 +{ 1.191 + switch (aStyle) { 1.192 + case JoinStyle::MITER: 1.193 + return gfxContext::LINE_JOIN_MITER; 1.194 + case JoinStyle::BEVEL: 1.195 + return gfxContext::LINE_JOIN_BEVEL; 1.196 + case JoinStyle::ROUND: 1.197 + return gfxContext::LINE_JOIN_ROUND; 1.198 + default: 1.199 + return gfxContext::LINE_JOIN_MITER; 1.200 + } 1.201 +} 1.202 + 1.203 +inline JoinStyle ToJoinStyle(gfxContext::GraphicsLineJoin aStyle) 1.204 +{ 1.205 + switch (aStyle) { 1.206 + case gfxContext::LINE_JOIN_MITER: 1.207 + return JoinStyle::MITER; 1.208 + case gfxContext::LINE_JOIN_BEVEL: 1.209 + return JoinStyle::BEVEL; 1.210 + case gfxContext::LINE_JOIN_ROUND: 1.211 + return JoinStyle::ROUND; 1.212 + } 1.213 + MOZ_CRASH("Incomplete switch"); 1.214 +} 1.215 + 1.216 +inline gfxImageFormat SurfaceFormatToImageFormat(SurfaceFormat aFormat) 1.217 +{ 1.218 + switch (aFormat) { 1.219 + case SurfaceFormat::B8G8R8A8: 1.220 + return gfxImageFormat::ARGB32; 1.221 + case SurfaceFormat::B8G8R8X8: 1.222 + return gfxImageFormat::RGB24; 1.223 + case SurfaceFormat::R5G6B5: 1.224 + return gfxImageFormat::RGB16_565; 1.225 + case SurfaceFormat::A8: 1.226 + return gfxImageFormat::A8; 1.227 + default: 1.228 + return gfxImageFormat::Unknown; 1.229 + } 1.230 +} 1.231 + 1.232 +inline SurfaceFormat ImageFormatToSurfaceFormat(gfxImageFormat aFormat) 1.233 +{ 1.234 + switch (aFormat) { 1.235 + case gfxImageFormat::ARGB32: 1.236 + return SurfaceFormat::B8G8R8A8; 1.237 + case gfxImageFormat::RGB24: 1.238 + return SurfaceFormat::B8G8R8X8; 1.239 + case gfxImageFormat::RGB16_565: 1.240 + return SurfaceFormat::R5G6B5; 1.241 + case gfxImageFormat::A8: 1.242 + return SurfaceFormat::A8; 1.243 + default: 1.244 + case gfxImageFormat::Unknown: 1.245 + return SurfaceFormat::B8G8R8A8; 1.246 + } 1.247 +} 1.248 + 1.249 +inline gfxContentType ContentForFormat(const SurfaceFormat &aFormat) 1.250 +{ 1.251 + switch (aFormat) { 1.252 + case SurfaceFormat::R5G6B5: 1.253 + case SurfaceFormat::B8G8R8X8: 1.254 + case SurfaceFormat::R8G8B8X8: 1.255 + return gfxContentType::COLOR; 1.256 + case SurfaceFormat::A8: 1.257 + return gfxContentType::ALPHA; 1.258 + case SurfaceFormat::B8G8R8A8: 1.259 + case SurfaceFormat::R8G8B8A8: 1.260 + default: 1.261 + return gfxContentType::COLOR_ALPHA; 1.262 + } 1.263 +} 1.264 + 1.265 +inline CompositionOp CompositionOpForOp(gfxContext::GraphicsOperator aOp) 1.266 +{ 1.267 + switch (aOp) { 1.268 + case gfxContext::OPERATOR_ADD: 1.269 + return CompositionOp::OP_ADD; 1.270 + case gfxContext::OPERATOR_ATOP: 1.271 + return CompositionOp::OP_ATOP; 1.272 + case gfxContext::OPERATOR_IN: 1.273 + return CompositionOp::OP_IN; 1.274 + case gfxContext::OPERATOR_OUT: 1.275 + return CompositionOp::OP_OUT; 1.276 + case gfxContext::OPERATOR_SOURCE: 1.277 + return CompositionOp::OP_SOURCE; 1.278 + case gfxContext::OPERATOR_DEST_IN: 1.279 + return CompositionOp::OP_DEST_IN; 1.280 + case gfxContext::OPERATOR_DEST_OUT: 1.281 + return CompositionOp::OP_DEST_OUT; 1.282 + case gfxContext::OPERATOR_DEST_ATOP: 1.283 + return CompositionOp::OP_DEST_ATOP; 1.284 + case gfxContext::OPERATOR_XOR: 1.285 + return CompositionOp::OP_XOR; 1.286 + case gfxContext::OPERATOR_MULTIPLY: 1.287 + return CompositionOp::OP_MULTIPLY; 1.288 + case gfxContext::OPERATOR_SCREEN: 1.289 + return CompositionOp::OP_SCREEN; 1.290 + case gfxContext::OPERATOR_OVERLAY: 1.291 + return CompositionOp::OP_OVERLAY; 1.292 + case gfxContext::OPERATOR_DARKEN: 1.293 + return CompositionOp::OP_DARKEN; 1.294 + case gfxContext::OPERATOR_LIGHTEN: 1.295 + return CompositionOp::OP_LIGHTEN; 1.296 + case gfxContext::OPERATOR_COLOR_DODGE: 1.297 + return CompositionOp::OP_COLOR_DODGE; 1.298 + case gfxContext::OPERATOR_COLOR_BURN: 1.299 + return CompositionOp::OP_COLOR_BURN; 1.300 + case gfxContext::OPERATOR_HARD_LIGHT: 1.301 + return CompositionOp::OP_HARD_LIGHT; 1.302 + case gfxContext::OPERATOR_SOFT_LIGHT: 1.303 + return CompositionOp::OP_SOFT_LIGHT; 1.304 + case gfxContext::OPERATOR_DIFFERENCE: 1.305 + return CompositionOp::OP_DIFFERENCE; 1.306 + case gfxContext::OPERATOR_EXCLUSION: 1.307 + return CompositionOp::OP_EXCLUSION; 1.308 + case gfxContext::OPERATOR_HUE: 1.309 + return CompositionOp::OP_HUE; 1.310 + case gfxContext::OPERATOR_SATURATION: 1.311 + return CompositionOp::OP_SATURATION; 1.312 + case gfxContext::OPERATOR_COLOR: 1.313 + return CompositionOp::OP_COLOR; 1.314 + case gfxContext::OPERATOR_LUMINOSITY: 1.315 + return CompositionOp::OP_LUMINOSITY; 1.316 + default: 1.317 + return CompositionOp::OP_OVER; 1.318 + } 1.319 +} 1.320 + 1.321 +inline gfxContext::GraphicsOperator ThebesOp(CompositionOp aOp) 1.322 +{ 1.323 + switch (aOp) { 1.324 + case CompositionOp::OP_ADD: 1.325 + return gfxContext::OPERATOR_ADD; 1.326 + case CompositionOp::OP_ATOP: 1.327 + return gfxContext::OPERATOR_ATOP; 1.328 + case CompositionOp::OP_IN: 1.329 + return gfxContext::OPERATOR_IN; 1.330 + case CompositionOp::OP_OUT: 1.331 + return gfxContext::OPERATOR_OUT; 1.332 + case CompositionOp::OP_SOURCE: 1.333 + return gfxContext::OPERATOR_SOURCE; 1.334 + case CompositionOp::OP_DEST_IN: 1.335 + return gfxContext::OPERATOR_DEST_IN; 1.336 + case CompositionOp::OP_DEST_OUT: 1.337 + return gfxContext::OPERATOR_DEST_OUT; 1.338 + case CompositionOp::OP_DEST_ATOP: 1.339 + return gfxContext::OPERATOR_DEST_ATOP; 1.340 + case CompositionOp::OP_XOR: 1.341 + return gfxContext::OPERATOR_XOR; 1.342 + case CompositionOp::OP_MULTIPLY: 1.343 + return gfxContext::OPERATOR_MULTIPLY; 1.344 + case CompositionOp::OP_SCREEN: 1.345 + return gfxContext::OPERATOR_SCREEN; 1.346 + case CompositionOp::OP_OVERLAY: 1.347 + return gfxContext::OPERATOR_OVERLAY; 1.348 + case CompositionOp::OP_DARKEN: 1.349 + return gfxContext::OPERATOR_DARKEN; 1.350 + case CompositionOp::OP_LIGHTEN: 1.351 + return gfxContext::OPERATOR_LIGHTEN; 1.352 + case CompositionOp::OP_COLOR_DODGE: 1.353 + return gfxContext::OPERATOR_COLOR_DODGE; 1.354 + case CompositionOp::OP_COLOR_BURN: 1.355 + return gfxContext::OPERATOR_COLOR_BURN; 1.356 + case CompositionOp::OP_HARD_LIGHT: 1.357 + return gfxContext::OPERATOR_HARD_LIGHT; 1.358 + case CompositionOp::OP_SOFT_LIGHT: 1.359 + return gfxContext::OPERATOR_SOFT_LIGHT; 1.360 + case CompositionOp::OP_DIFFERENCE: 1.361 + return gfxContext::OPERATOR_DIFFERENCE; 1.362 + case CompositionOp::OP_EXCLUSION: 1.363 + return gfxContext::OPERATOR_EXCLUSION; 1.364 + case CompositionOp::OP_HUE: 1.365 + return gfxContext::OPERATOR_HUE; 1.366 + case CompositionOp::OP_SATURATION: 1.367 + return gfxContext::OPERATOR_SATURATION; 1.368 + case CompositionOp::OP_COLOR: 1.369 + return gfxContext::OPERATOR_COLOR; 1.370 + case CompositionOp::OP_LUMINOSITY: 1.371 + return gfxContext::OPERATOR_LUMINOSITY; 1.372 + default: 1.373 + return gfxContext::OPERATOR_OVER; 1.374 + } 1.375 +} 1.376 + 1.377 +inline void 1.378 +ToMatrix4x4(const gfx3DMatrix& aIn, Matrix4x4& aOut) 1.379 +{ 1.380 + aOut._11 = aIn._11; 1.381 + aOut._12 = aIn._12; 1.382 + aOut._13 = aIn._13; 1.383 + aOut._14 = aIn._14; 1.384 + aOut._21 = aIn._21; 1.385 + aOut._22 = aIn._22; 1.386 + aOut._23 = aIn._23; 1.387 + aOut._24 = aIn._24; 1.388 + aOut._31 = aIn._31; 1.389 + aOut._32 = aIn._32; 1.390 + aOut._33 = aIn._33; 1.391 + aOut._34 = aIn._34; 1.392 + aOut._41 = aIn._41; 1.393 + aOut._42 = aIn._42; 1.394 + aOut._43 = aIn._43; 1.395 + aOut._44 = aIn._44; 1.396 +} 1.397 + 1.398 +inline void 1.399 +To3DMatrix(const Matrix4x4& aIn, gfx3DMatrix& aOut) 1.400 +{ 1.401 + aOut._11 = aIn._11; 1.402 + aOut._12 = aIn._12; 1.403 + aOut._13 = aIn._13; 1.404 + aOut._14 = aIn._14; 1.405 + aOut._21 = aIn._21; 1.406 + aOut._22 = aIn._22; 1.407 + aOut._23 = aIn._23; 1.408 + aOut._24 = aIn._24; 1.409 + aOut._31 = aIn._31; 1.410 + aOut._32 = aIn._32; 1.411 + aOut._33 = aIn._33; 1.412 + aOut._34 = aIn._34; 1.413 + aOut._41 = aIn._41; 1.414 + aOut._42 = aIn._42; 1.415 + aOut._43 = aIn._43; 1.416 + aOut._44 = aIn._44; 1.417 +} 1.418 + 1.419 +} 1.420 +} 1.421 + 1.422 +#endif