michael@0: /* This Source Code Form is subject to the terms of the Mozilla Public michael@0: * License, v. 2.0. If a copy of the MPL was not distributed with this michael@0: * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ michael@0: michael@0: #ifndef GFX_2D_GLUE_H michael@0: #define GFX_2D_GLUE_H michael@0: michael@0: michael@0: #include "gfxPlatform.h" michael@0: #include "gfxRect.h" michael@0: #include "gfxMatrix.h" michael@0: #include "gfx3DMatrix.h" michael@0: #include "gfxContext.h" michael@0: #include "mozilla/gfx/Matrix.h" michael@0: #include "mozilla/gfx/Rect.h" michael@0: #include "mozilla/gfx/2D.h" michael@0: #include "gfxColor.h" michael@0: michael@0: namespace mozilla { michael@0: namespace gfx { michael@0: class DrawTarget; michael@0: class SourceSurface; michael@0: class ScaledFont; michael@0: } michael@0: } michael@0: michael@0: namespace mozilla { michael@0: namespace gfx { michael@0: michael@0: inline Rect ToRect(const gfxRect &aRect) michael@0: { michael@0: return Rect(Float(aRect.x), Float(aRect.y), michael@0: Float(aRect.width), Float(aRect.height)); michael@0: } michael@0: michael@0: inline Rect ToRect(const nsIntRect &aRect) michael@0: { michael@0: return Rect(aRect.x, aRect.y, aRect.width, aRect.height); michael@0: } michael@0: michael@0: inline IntRect ToIntRect(const nsIntRect &aRect) michael@0: { michael@0: return IntRect(aRect.x, aRect.y, aRect.width, aRect.height); michael@0: } michael@0: michael@0: inline Color ToColor(const gfxRGBA &aRGBA) michael@0: { michael@0: return Color(Float(aRGBA.r), Float(aRGBA.g), michael@0: Float(aRGBA.b), Float(aRGBA.a)); michael@0: } michael@0: michael@0: inline Matrix ToMatrix(const gfxMatrix &aMatrix) michael@0: { michael@0: return Matrix(Float(aMatrix.xx), Float(aMatrix.yx), Float(aMatrix.xy), michael@0: Float(aMatrix.yy), Float(aMatrix.x0), Float(aMatrix.y0)); michael@0: } michael@0: michael@0: inline gfxMatrix ThebesMatrix(const Matrix &aMatrix) michael@0: { michael@0: return gfxMatrix(aMatrix._11, aMatrix._12, aMatrix._21, michael@0: aMatrix._22, aMatrix._31, aMatrix._32); michael@0: } michael@0: michael@0: inline Point ToPoint(const gfxPoint &aPoint) michael@0: { michael@0: return Point(Float(aPoint.x), Float(aPoint.y)); michael@0: } michael@0: michael@0: inline IntPoint ToIntPoint(const nsIntPoint &aPoint) michael@0: { michael@0: return IntPoint(aPoint.x, aPoint.y); michael@0: } michael@0: michael@0: inline Size ToSize(const gfxSize &aSize) michael@0: { michael@0: return Size(Float(aSize.width), Float(aSize.height)); michael@0: } michael@0: michael@0: inline IntSize ToIntSize(const gfxIntSize &aSize) michael@0: { michael@0: return IntSize(aSize.width, aSize.height); michael@0: } michael@0: michael@0: inline Filter ToFilter(GraphicsFilter aFilter) michael@0: { michael@0: switch (aFilter) { michael@0: case GraphicsFilter::FILTER_NEAREST: michael@0: return Filter::POINT; michael@0: case GraphicsFilter::FILTER_GOOD: michael@0: return Filter::GOOD; michael@0: default: michael@0: return Filter::LINEAR; michael@0: } michael@0: } michael@0: michael@0: inline GraphicsFilter ThebesFilter(Filter aFilter) michael@0: { michael@0: switch (aFilter) { michael@0: case Filter::POINT: michael@0: return GraphicsFilter::FILTER_NEAREST; michael@0: default: michael@0: return GraphicsFilter::FILTER_BEST; michael@0: } michael@0: } michael@0: michael@0: inline ExtendMode ToExtendMode(gfxPattern::GraphicsExtend aExtend) michael@0: { michael@0: switch (aExtend) { michael@0: case gfxPattern::EXTEND_REPEAT: michael@0: return ExtendMode::REPEAT; michael@0: case gfxPattern::EXTEND_REFLECT: michael@0: return ExtendMode::REFLECT; michael@0: default: michael@0: return ExtendMode::CLAMP; michael@0: } michael@0: } michael@0: michael@0: inline gfxPattern::GraphicsExtend ThebesExtend(ExtendMode aExtend) michael@0: { michael@0: switch (aExtend) { michael@0: case ExtendMode::REPEAT: michael@0: return gfxPattern::EXTEND_REPEAT; michael@0: case ExtendMode::REFLECT: michael@0: return gfxPattern::EXTEND_REFLECT; michael@0: default: michael@0: return gfxPattern::EXTEND_PAD; michael@0: } michael@0: } michael@0: michael@0: inline gfxPoint ThebesPoint(const Point &aPoint) michael@0: { michael@0: return gfxPoint(aPoint.x, aPoint.y); michael@0: } michael@0: michael@0: inline gfxSize ThebesSize(const Size &aSize) michael@0: { michael@0: return gfxSize(aSize.width, aSize.height); michael@0: } michael@0: michael@0: inline gfxIntSize ThebesIntSize(const IntSize &aSize) michael@0: { michael@0: return gfxIntSize(aSize.width, aSize.height); michael@0: } michael@0: michael@0: inline gfxRect ThebesRect(const Rect &aRect) michael@0: { michael@0: return gfxRect(aRect.x, aRect.y, aRect.width, aRect.height); michael@0: } michael@0: michael@0: inline nsIntRect ThebesIntRect(const IntRect &aRect) michael@0: { michael@0: return nsIntRect(aRect.x, aRect.y, aRect.width, aRect.height); michael@0: } michael@0: michael@0: inline gfxRGBA ThebesRGBA(const Color &aColor) michael@0: { michael@0: return gfxRGBA(aColor.r, aColor.g, aColor.b, aColor.a); michael@0: } michael@0: michael@0: inline gfxContext::GraphicsLineCap ThebesLineCap(CapStyle aStyle) michael@0: { michael@0: switch (aStyle) { michael@0: case CapStyle::BUTT: michael@0: return gfxContext::LINE_CAP_BUTT; michael@0: case CapStyle::ROUND: michael@0: return gfxContext::LINE_CAP_ROUND; michael@0: case CapStyle::SQUARE: michael@0: return gfxContext::LINE_CAP_SQUARE; michael@0: } michael@0: MOZ_CRASH("Incomplete switch"); michael@0: } michael@0: michael@0: inline CapStyle ToCapStyle(gfxContext::GraphicsLineCap aStyle) michael@0: { michael@0: switch (aStyle) { michael@0: case gfxContext::LINE_CAP_BUTT: michael@0: return CapStyle::BUTT; michael@0: case gfxContext::LINE_CAP_ROUND: michael@0: return CapStyle::ROUND; michael@0: case gfxContext::LINE_CAP_SQUARE: michael@0: return CapStyle::SQUARE; michael@0: } michael@0: MOZ_CRASH("Incomplete switch"); michael@0: } michael@0: michael@0: inline gfxContext::GraphicsLineJoin ThebesLineJoin(JoinStyle aStyle) michael@0: { michael@0: switch (aStyle) { michael@0: case JoinStyle::MITER: michael@0: return gfxContext::LINE_JOIN_MITER; michael@0: case JoinStyle::BEVEL: michael@0: return gfxContext::LINE_JOIN_BEVEL; michael@0: case JoinStyle::ROUND: michael@0: return gfxContext::LINE_JOIN_ROUND; michael@0: default: michael@0: return gfxContext::LINE_JOIN_MITER; michael@0: } michael@0: } michael@0: michael@0: inline JoinStyle ToJoinStyle(gfxContext::GraphicsLineJoin aStyle) michael@0: { michael@0: switch (aStyle) { michael@0: case gfxContext::LINE_JOIN_MITER: michael@0: return JoinStyle::MITER; michael@0: case gfxContext::LINE_JOIN_BEVEL: michael@0: return JoinStyle::BEVEL; michael@0: case gfxContext::LINE_JOIN_ROUND: michael@0: return JoinStyle::ROUND; michael@0: } michael@0: MOZ_CRASH("Incomplete switch"); michael@0: } michael@0: michael@0: inline gfxImageFormat SurfaceFormatToImageFormat(SurfaceFormat aFormat) michael@0: { michael@0: switch (aFormat) { michael@0: case SurfaceFormat::B8G8R8A8: michael@0: return gfxImageFormat::ARGB32; michael@0: case SurfaceFormat::B8G8R8X8: michael@0: return gfxImageFormat::RGB24; michael@0: case SurfaceFormat::R5G6B5: michael@0: return gfxImageFormat::RGB16_565; michael@0: case SurfaceFormat::A8: michael@0: return gfxImageFormat::A8; michael@0: default: michael@0: return gfxImageFormat::Unknown; michael@0: } michael@0: } michael@0: michael@0: inline SurfaceFormat ImageFormatToSurfaceFormat(gfxImageFormat aFormat) michael@0: { michael@0: switch (aFormat) { michael@0: case gfxImageFormat::ARGB32: michael@0: return SurfaceFormat::B8G8R8A8; michael@0: case gfxImageFormat::RGB24: michael@0: return SurfaceFormat::B8G8R8X8; michael@0: case gfxImageFormat::RGB16_565: michael@0: return SurfaceFormat::R5G6B5; michael@0: case gfxImageFormat::A8: michael@0: return SurfaceFormat::A8; michael@0: default: michael@0: case gfxImageFormat::Unknown: michael@0: return SurfaceFormat::B8G8R8A8; michael@0: } michael@0: } michael@0: michael@0: inline gfxContentType ContentForFormat(const SurfaceFormat &aFormat) michael@0: { michael@0: switch (aFormat) { michael@0: case SurfaceFormat::R5G6B5: michael@0: case SurfaceFormat::B8G8R8X8: michael@0: case SurfaceFormat::R8G8B8X8: michael@0: return gfxContentType::COLOR; michael@0: case SurfaceFormat::A8: michael@0: return gfxContentType::ALPHA; michael@0: case SurfaceFormat::B8G8R8A8: michael@0: case SurfaceFormat::R8G8B8A8: michael@0: default: michael@0: return gfxContentType::COLOR_ALPHA; michael@0: } michael@0: } michael@0: michael@0: inline CompositionOp CompositionOpForOp(gfxContext::GraphicsOperator aOp) michael@0: { michael@0: switch (aOp) { michael@0: case gfxContext::OPERATOR_ADD: michael@0: return CompositionOp::OP_ADD; michael@0: case gfxContext::OPERATOR_ATOP: michael@0: return CompositionOp::OP_ATOP; michael@0: case gfxContext::OPERATOR_IN: michael@0: return CompositionOp::OP_IN; michael@0: case gfxContext::OPERATOR_OUT: michael@0: return CompositionOp::OP_OUT; michael@0: case gfxContext::OPERATOR_SOURCE: michael@0: return CompositionOp::OP_SOURCE; michael@0: case gfxContext::OPERATOR_DEST_IN: michael@0: return CompositionOp::OP_DEST_IN; michael@0: case gfxContext::OPERATOR_DEST_OUT: michael@0: return CompositionOp::OP_DEST_OUT; michael@0: case gfxContext::OPERATOR_DEST_ATOP: michael@0: return CompositionOp::OP_DEST_ATOP; michael@0: case gfxContext::OPERATOR_XOR: michael@0: return CompositionOp::OP_XOR; michael@0: case gfxContext::OPERATOR_MULTIPLY: michael@0: return CompositionOp::OP_MULTIPLY; michael@0: case gfxContext::OPERATOR_SCREEN: michael@0: return CompositionOp::OP_SCREEN; michael@0: case gfxContext::OPERATOR_OVERLAY: michael@0: return CompositionOp::OP_OVERLAY; michael@0: case gfxContext::OPERATOR_DARKEN: michael@0: return CompositionOp::OP_DARKEN; michael@0: case gfxContext::OPERATOR_LIGHTEN: michael@0: return CompositionOp::OP_LIGHTEN; michael@0: case gfxContext::OPERATOR_COLOR_DODGE: michael@0: return CompositionOp::OP_COLOR_DODGE; michael@0: case gfxContext::OPERATOR_COLOR_BURN: michael@0: return CompositionOp::OP_COLOR_BURN; michael@0: case gfxContext::OPERATOR_HARD_LIGHT: michael@0: return CompositionOp::OP_HARD_LIGHT; michael@0: case gfxContext::OPERATOR_SOFT_LIGHT: michael@0: return CompositionOp::OP_SOFT_LIGHT; michael@0: case gfxContext::OPERATOR_DIFFERENCE: michael@0: return CompositionOp::OP_DIFFERENCE; michael@0: case gfxContext::OPERATOR_EXCLUSION: michael@0: return CompositionOp::OP_EXCLUSION; michael@0: case gfxContext::OPERATOR_HUE: michael@0: return CompositionOp::OP_HUE; michael@0: case gfxContext::OPERATOR_SATURATION: michael@0: return CompositionOp::OP_SATURATION; michael@0: case gfxContext::OPERATOR_COLOR: michael@0: return CompositionOp::OP_COLOR; michael@0: case gfxContext::OPERATOR_LUMINOSITY: michael@0: return CompositionOp::OP_LUMINOSITY; michael@0: default: michael@0: return CompositionOp::OP_OVER; michael@0: } michael@0: } michael@0: michael@0: inline gfxContext::GraphicsOperator ThebesOp(CompositionOp aOp) michael@0: { michael@0: switch (aOp) { michael@0: case CompositionOp::OP_ADD: michael@0: return gfxContext::OPERATOR_ADD; michael@0: case CompositionOp::OP_ATOP: michael@0: return gfxContext::OPERATOR_ATOP; michael@0: case CompositionOp::OP_IN: michael@0: return gfxContext::OPERATOR_IN; michael@0: case CompositionOp::OP_OUT: michael@0: return gfxContext::OPERATOR_OUT; michael@0: case CompositionOp::OP_SOURCE: michael@0: return gfxContext::OPERATOR_SOURCE; michael@0: case CompositionOp::OP_DEST_IN: michael@0: return gfxContext::OPERATOR_DEST_IN; michael@0: case CompositionOp::OP_DEST_OUT: michael@0: return gfxContext::OPERATOR_DEST_OUT; michael@0: case CompositionOp::OP_DEST_ATOP: michael@0: return gfxContext::OPERATOR_DEST_ATOP; michael@0: case CompositionOp::OP_XOR: michael@0: return gfxContext::OPERATOR_XOR; michael@0: case CompositionOp::OP_MULTIPLY: michael@0: return gfxContext::OPERATOR_MULTIPLY; michael@0: case CompositionOp::OP_SCREEN: michael@0: return gfxContext::OPERATOR_SCREEN; michael@0: case CompositionOp::OP_OVERLAY: michael@0: return gfxContext::OPERATOR_OVERLAY; michael@0: case CompositionOp::OP_DARKEN: michael@0: return gfxContext::OPERATOR_DARKEN; michael@0: case CompositionOp::OP_LIGHTEN: michael@0: return gfxContext::OPERATOR_LIGHTEN; michael@0: case CompositionOp::OP_COLOR_DODGE: michael@0: return gfxContext::OPERATOR_COLOR_DODGE; michael@0: case CompositionOp::OP_COLOR_BURN: michael@0: return gfxContext::OPERATOR_COLOR_BURN; michael@0: case CompositionOp::OP_HARD_LIGHT: michael@0: return gfxContext::OPERATOR_HARD_LIGHT; michael@0: case CompositionOp::OP_SOFT_LIGHT: michael@0: return gfxContext::OPERATOR_SOFT_LIGHT; michael@0: case CompositionOp::OP_DIFFERENCE: michael@0: return gfxContext::OPERATOR_DIFFERENCE; michael@0: case CompositionOp::OP_EXCLUSION: michael@0: return gfxContext::OPERATOR_EXCLUSION; michael@0: case CompositionOp::OP_HUE: michael@0: return gfxContext::OPERATOR_HUE; michael@0: case CompositionOp::OP_SATURATION: michael@0: return gfxContext::OPERATOR_SATURATION; michael@0: case CompositionOp::OP_COLOR: michael@0: return gfxContext::OPERATOR_COLOR; michael@0: case CompositionOp::OP_LUMINOSITY: michael@0: return gfxContext::OPERATOR_LUMINOSITY; michael@0: default: michael@0: return gfxContext::OPERATOR_OVER; michael@0: } michael@0: } michael@0: michael@0: inline void michael@0: ToMatrix4x4(const gfx3DMatrix& aIn, Matrix4x4& aOut) michael@0: { michael@0: aOut._11 = aIn._11; michael@0: aOut._12 = aIn._12; michael@0: aOut._13 = aIn._13; michael@0: aOut._14 = aIn._14; michael@0: aOut._21 = aIn._21; michael@0: aOut._22 = aIn._22; michael@0: aOut._23 = aIn._23; michael@0: aOut._24 = aIn._24; michael@0: aOut._31 = aIn._31; michael@0: aOut._32 = aIn._32; michael@0: aOut._33 = aIn._33; michael@0: aOut._34 = aIn._34; michael@0: aOut._41 = aIn._41; michael@0: aOut._42 = aIn._42; michael@0: aOut._43 = aIn._43; michael@0: aOut._44 = aIn._44; michael@0: } michael@0: michael@0: inline void michael@0: To3DMatrix(const Matrix4x4& aIn, gfx3DMatrix& aOut) michael@0: { michael@0: aOut._11 = aIn._11; michael@0: aOut._12 = aIn._12; michael@0: aOut._13 = aIn._13; michael@0: aOut._14 = aIn._14; michael@0: aOut._21 = aIn._21; michael@0: aOut._22 = aIn._22; michael@0: aOut._23 = aIn._23; michael@0: aOut._24 = aIn._24; michael@0: aOut._31 = aIn._31; michael@0: aOut._32 = aIn._32; michael@0: aOut._33 = aIn._33; michael@0: aOut._34 = aIn._34; michael@0: aOut._41 = aIn._41; michael@0: aOut._42 = aIn._42; michael@0: aOut._43 = aIn._43; michael@0: aOut._44 = aIn._44; michael@0: } michael@0: michael@0: } michael@0: } michael@0: michael@0: #endif