2017-10-28 02:10:06 +03:00
|
|
|
/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
|
|
|
/* vim: set ts=8 sts=2 et sw=2 tw=80: */
|
|
|
|
/* This Source Code Form is subject to the terms of the Mozilla Public
|
2012-05-21 15:12:37 +04:00
|
|
|
* 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-11-02 23:55:03 +04:00
|
|
|
|
|
|
|
#ifndef MOZILLA_GFX_HELPERSSKIA_H_
|
|
|
|
#define MOZILLA_GFX_HELPERSSKIA_H_
|
|
|
|
|
|
|
|
#include "2D.h"
|
2015-07-29 23:31:40 +03:00
|
|
|
#include "skia/include/core/SkCanvas.h"
|
|
|
|
#include "skia/include/effects/SkDashPathEffect.h"
|
|
|
|
#include "skia/include/core/SkShader.h"
|
2012-03-27 06:50:08 +04:00
|
|
|
#include "mozilla/Assertions.h"
|
2012-08-23 23:36:04 +04:00
|
|
|
#include <vector>
|
2016-05-17 21:41:38 +03:00
|
|
|
#include "nsDebug.h"
|
2011-11-02 23:55:03 +04:00
|
|
|
|
|
|
|
namespace mozilla {
|
|
|
|
namespace gfx {
|
|
|
|
|
2014-03-20 22:07:36 +04:00
|
|
|
static inline SkColorType
|
|
|
|
GfxFormatToSkiaColorType(SurfaceFormat format)
|
|
|
|
{
|
|
|
|
switch (format)
|
|
|
|
{
|
|
|
|
case SurfaceFormat::B8G8R8A8:
|
|
|
|
return kBGRA_8888_SkColorType;
|
|
|
|
case SurfaceFormat::B8G8R8X8:
|
|
|
|
// We probably need to do something here.
|
|
|
|
return kBGRA_8888_SkColorType;
|
2015-10-23 09:01:31 +03:00
|
|
|
case SurfaceFormat::R5G6B5_UINT16:
|
2014-03-20 22:07:36 +04:00
|
|
|
return kRGB_565_SkColorType;
|
|
|
|
case SurfaceFormat::A8:
|
|
|
|
return kAlpha_8_SkColorType;
|
|
|
|
default:
|
|
|
|
return kRGBA_8888_SkColorType;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-04-09 23:57:22 +04:00
|
|
|
static inline SurfaceFormat
|
2016-02-03 21:49:36 +03:00
|
|
|
SkiaColorTypeToGfxFormat(SkColorType aColorType, SkAlphaType aAlphaType = kPremul_SkAlphaType)
|
2013-04-09 23:57:22 +04:00
|
|
|
{
|
2016-02-03 21:49:36 +03:00
|
|
|
switch (aColorType)
|
2013-04-09 23:57:22 +04:00
|
|
|
{
|
2014-07-28 04:47:43 +04:00
|
|
|
case kBGRA_8888_SkColorType:
|
2016-02-03 21:49:36 +03:00
|
|
|
return aAlphaType == kOpaque_SkAlphaType ?
|
|
|
|
SurfaceFormat::B8G8R8X8 : SurfaceFormat::B8G8R8A8;
|
2014-07-28 04:47:43 +04:00
|
|
|
case kRGB_565_SkColorType:
|
2015-10-23 09:01:31 +03:00
|
|
|
return SurfaceFormat::R5G6B5_UINT16;
|
2014-07-28 04:47:43 +04:00
|
|
|
case kAlpha_8_SkColorType:
|
2014-01-10 23:06:16 +04:00
|
|
|
return SurfaceFormat::A8;
|
2013-04-09 23:57:22 +04:00
|
|
|
default:
|
2014-01-10 23:06:16 +04:00
|
|
|
return SurfaceFormat::B8G8R8A8;
|
2013-04-09 23:57:22 +04:00
|
|
|
}
|
2011-11-02 23:55:03 +04:00
|
|
|
}
|
|
|
|
|
2016-01-21 17:50:43 +03:00
|
|
|
static inline SkAlphaType
|
|
|
|
GfxFormatToSkiaAlphaType(SurfaceFormat format)
|
|
|
|
{
|
|
|
|
switch (format)
|
|
|
|
{
|
|
|
|
case SurfaceFormat::B8G8R8X8:
|
|
|
|
case SurfaceFormat::R5G6B5_UINT16:
|
|
|
|
return kOpaque_SkAlphaType;
|
|
|
|
default:
|
|
|
|
return kPremul_SkAlphaType;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline SkImageInfo
|
|
|
|
MakeSkiaImageInfo(const IntSize& aSize, SurfaceFormat aFormat)
|
|
|
|
{
|
|
|
|
return SkImageInfo::Make(aSize.width, aSize.height,
|
|
|
|
GfxFormatToSkiaColorType(aFormat),
|
|
|
|
GfxFormatToSkiaAlphaType(aFormat));
|
|
|
|
}
|
|
|
|
|
2011-11-02 23:55:03 +04:00
|
|
|
static inline void
|
|
|
|
GfxMatrixToSkiaMatrix(const Matrix& mat, SkMatrix& retval)
|
|
|
|
{
|
|
|
|
retval.setAll(SkFloatToScalar(mat._11), SkFloatToScalar(mat._21), SkFloatToScalar(mat._31),
|
|
|
|
SkFloatToScalar(mat._12), SkFloatToScalar(mat._22), SkFloatToScalar(mat._32),
|
|
|
|
0, 0, SK_Scalar1);
|
|
|
|
}
|
|
|
|
|
2016-03-23 08:03:10 +03:00
|
|
|
static inline void
|
|
|
|
GfxMatrixToSkiaMatrix(const Matrix4x4& aMatrix, SkMatrix& aResult)
|
|
|
|
{
|
|
|
|
aResult.setAll(SkFloatToScalar(aMatrix._11), SkFloatToScalar(aMatrix._21), SkFloatToScalar(aMatrix._41),
|
|
|
|
SkFloatToScalar(aMatrix._12), SkFloatToScalar(aMatrix._22), SkFloatToScalar(aMatrix._42),
|
|
|
|
SkFloatToScalar(aMatrix._14), SkFloatToScalar(aMatrix._24), SkFloatToScalar(aMatrix._44));
|
|
|
|
}
|
|
|
|
|
2011-11-18 08:00:38 +04:00
|
|
|
static inline SkPaint::Cap
|
|
|
|
CapStyleToSkiaCap(CapStyle aCap)
|
|
|
|
{
|
|
|
|
switch (aCap)
|
|
|
|
{
|
2014-01-10 23:06:17 +04:00
|
|
|
case CapStyle::BUTT:
|
2011-11-18 08:00:38 +04:00
|
|
|
return SkPaint::kButt_Cap;
|
2014-01-10 23:06:17 +04:00
|
|
|
case CapStyle::ROUND:
|
2011-11-18 08:00:38 +04:00
|
|
|
return SkPaint::kRound_Cap;
|
2014-01-10 23:06:17 +04:00
|
|
|
case CapStyle::SQUARE:
|
2011-11-18 08:00:38 +04:00
|
|
|
return SkPaint::kSquare_Cap;
|
|
|
|
}
|
|
|
|
return SkPaint::kDefault_Cap;
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline SkPaint::Join
|
|
|
|
JoinStyleToSkiaJoin(JoinStyle aJoin)
|
|
|
|
{
|
|
|
|
switch (aJoin)
|
|
|
|
{
|
2014-01-10 23:06:17 +04:00
|
|
|
case JoinStyle::BEVEL:
|
2011-11-18 08:00:38 +04:00
|
|
|
return SkPaint::kBevel_Join;
|
2014-01-10 23:06:17 +04:00
|
|
|
case JoinStyle::ROUND:
|
2011-11-18 08:00:38 +04:00
|
|
|
return SkPaint::kRound_Join;
|
2014-01-10 23:06:17 +04:00
|
|
|
case JoinStyle::MITER:
|
|
|
|
case JoinStyle::MITER_OR_BEVEL:
|
2011-11-18 08:00:38 +04:00
|
|
|
return SkPaint::kMiter_Join;
|
|
|
|
}
|
|
|
|
return SkPaint::kDefault_Join;
|
|
|
|
}
|
|
|
|
|
2011-11-18 08:00:38 +04:00
|
|
|
static inline bool
|
2011-11-18 08:00:38 +04:00
|
|
|
StrokeOptionsToPaint(SkPaint& aPaint, const StrokeOptions &aOptions)
|
|
|
|
{
|
2012-04-26 02:04:35 +04:00
|
|
|
// Skia renders 0 width strokes with a width of 1 (and in black),
|
2011-11-18 08:00:38 +04:00
|
|
|
// so we should just skip the draw call entirely.
|
2016-02-24 02:09:03 +03:00
|
|
|
// Skia does not handle non-finite line widths.
|
|
|
|
if (!aOptions.mLineWidth || !IsFinite(aOptions.mLineWidth)) {
|
2011-11-18 08:00:38 +04:00
|
|
|
return false;
|
|
|
|
}
|
2011-11-18 08:00:38 +04:00
|
|
|
aPaint.setStrokeWidth(SkFloatToScalar(aOptions.mLineWidth));
|
|
|
|
aPaint.setStrokeMiter(SkFloatToScalar(aOptions.mMiterLimit));
|
|
|
|
aPaint.setStrokeCap(CapStyleToSkiaCap(aOptions.mLineCap));
|
|
|
|
aPaint.setStrokeJoin(JoinStyleToSkiaJoin(aOptions.mLineJoin));
|
2012-03-27 06:50:08 +04:00
|
|
|
|
2012-03-31 01:36:34 +04:00
|
|
|
if (aOptions.mDashLength > 0) {
|
|
|
|
// Skia only supports dash arrays that are multiples of 2.
|
|
|
|
uint32_t dashCount;
|
|
|
|
|
|
|
|
if (aOptions.mDashLength % 2 == 0) {
|
|
|
|
dashCount = aOptions.mDashLength;
|
|
|
|
} else {
|
|
|
|
dashCount = aOptions.mDashLength * 2;
|
|
|
|
}
|
|
|
|
|
2011-11-18 08:00:38 +04:00
|
|
|
std::vector<SkScalar> pattern;
|
2012-03-31 01:36:34 +04:00
|
|
|
pattern.resize(dashCount);
|
|
|
|
|
|
|
|
for (uint32_t i = 0; i < dashCount; i++) {
|
|
|
|
pattern[i] = SkFloatToScalar(aOptions.mDashPattern[i % aOptions.mDashLength]);
|
2011-11-18 08:00:38 +04:00
|
|
|
}
|
2012-03-31 01:36:34 +04:00
|
|
|
|
2016-04-29 05:55:27 +03:00
|
|
|
sk_sp<SkPathEffect> dash = SkDashPathEffect::Make(&pattern.front(),
|
|
|
|
dashCount,
|
|
|
|
SkFloatToScalar(aOptions.mDashOffset));
|
|
|
|
aPaint.setPathEffect(dash);
|
2011-11-18 08:00:38 +04:00
|
|
|
}
|
2012-03-31 01:36:34 +04:00
|
|
|
|
2011-11-18 08:00:38 +04:00
|
|
|
aPaint.setStyle(SkPaint::kStroke_Style);
|
2011-11-18 08:00:38 +04:00
|
|
|
return true;
|
2011-11-18 08:00:38 +04:00
|
|
|
}
|
|
|
|
|
2016-10-25 05:40:59 +03:00
|
|
|
static inline SkBlendMode
|
2012-10-17 01:16:45 +04:00
|
|
|
GfxOpToSkiaOp(CompositionOp op)
|
|
|
|
{
|
|
|
|
switch (op)
|
|
|
|
{
|
2014-01-10 23:06:17 +04:00
|
|
|
case CompositionOp::OP_OVER:
|
2016-10-25 05:40:59 +03:00
|
|
|
return SkBlendMode::kSrcOver;
|
2014-01-10 23:06:17 +04:00
|
|
|
case CompositionOp::OP_ADD:
|
2016-10-25 05:40:59 +03:00
|
|
|
return SkBlendMode::kPlus;
|
2014-01-10 23:06:17 +04:00
|
|
|
case CompositionOp::OP_ATOP:
|
2016-10-25 05:40:59 +03:00
|
|
|
return SkBlendMode::kSrcATop;
|
2014-01-10 23:06:17 +04:00
|
|
|
case CompositionOp::OP_OUT:
|
2016-10-25 05:40:59 +03:00
|
|
|
return SkBlendMode::kSrcOut;
|
2014-01-10 23:06:17 +04:00
|
|
|
case CompositionOp::OP_IN:
|
2016-10-25 05:40:59 +03:00
|
|
|
return SkBlendMode::kSrcIn;
|
2014-01-10 23:06:17 +04:00
|
|
|
case CompositionOp::OP_SOURCE:
|
2016-10-25 05:40:59 +03:00
|
|
|
return SkBlendMode::kSrc;
|
2014-01-10 23:06:17 +04:00
|
|
|
case CompositionOp::OP_DEST_IN:
|
2016-10-25 05:40:59 +03:00
|
|
|
return SkBlendMode::kDstIn;
|
2014-01-10 23:06:17 +04:00
|
|
|
case CompositionOp::OP_DEST_OUT:
|
2016-10-25 05:40:59 +03:00
|
|
|
return SkBlendMode::kDstOut;
|
2014-01-10 23:06:17 +04:00
|
|
|
case CompositionOp::OP_DEST_OVER:
|
2016-10-25 05:40:59 +03:00
|
|
|
return SkBlendMode::kDstOver;
|
2014-01-10 23:06:17 +04:00
|
|
|
case CompositionOp::OP_DEST_ATOP:
|
2016-10-25 05:40:59 +03:00
|
|
|
return SkBlendMode::kDstATop;
|
2014-01-10 23:06:17 +04:00
|
|
|
case CompositionOp::OP_XOR:
|
2016-10-25 05:40:59 +03:00
|
|
|
return SkBlendMode::kXor;
|
2014-01-10 23:06:17 +04:00
|
|
|
case CompositionOp::OP_MULTIPLY:
|
2016-10-25 05:40:59 +03:00
|
|
|
return SkBlendMode::kMultiply;
|
2014-01-10 23:06:17 +04:00
|
|
|
case CompositionOp::OP_SCREEN:
|
2016-10-25 05:40:59 +03:00
|
|
|
return SkBlendMode::kScreen;
|
2014-01-10 23:06:17 +04:00
|
|
|
case CompositionOp::OP_OVERLAY:
|
2016-10-25 05:40:59 +03:00
|
|
|
return SkBlendMode::kOverlay;
|
2014-01-10 23:06:17 +04:00
|
|
|
case CompositionOp::OP_DARKEN:
|
2016-10-25 05:40:59 +03:00
|
|
|
return SkBlendMode::kDarken;
|
2014-01-10 23:06:17 +04:00
|
|
|
case CompositionOp::OP_LIGHTEN:
|
2016-10-25 05:40:59 +03:00
|
|
|
return SkBlendMode::kLighten;
|
2014-01-10 23:06:17 +04:00
|
|
|
case CompositionOp::OP_COLOR_DODGE:
|
2016-10-25 05:40:59 +03:00
|
|
|
return SkBlendMode::kColorDodge;
|
2014-01-10 23:06:17 +04:00
|
|
|
case CompositionOp::OP_COLOR_BURN:
|
2016-10-25 05:40:59 +03:00
|
|
|
return SkBlendMode::kColorBurn;
|
2014-01-10 23:06:17 +04:00
|
|
|
case CompositionOp::OP_HARD_LIGHT:
|
2016-10-25 05:40:59 +03:00
|
|
|
return SkBlendMode::kHardLight;
|
2014-01-10 23:06:17 +04:00
|
|
|
case CompositionOp::OP_SOFT_LIGHT:
|
2016-10-25 05:40:59 +03:00
|
|
|
return SkBlendMode::kSoftLight;
|
2014-01-10 23:06:17 +04:00
|
|
|
case CompositionOp::OP_DIFFERENCE:
|
2016-10-25 05:40:59 +03:00
|
|
|
return SkBlendMode::kDifference;
|
2014-01-10 23:06:17 +04:00
|
|
|
case CompositionOp::OP_EXCLUSION:
|
2016-10-25 05:40:59 +03:00
|
|
|
return SkBlendMode::kExclusion;
|
2014-01-10 23:06:17 +04:00
|
|
|
case CompositionOp::OP_HUE:
|
2016-10-25 05:40:59 +03:00
|
|
|
return SkBlendMode::kHue;
|
2014-01-10 23:06:17 +04:00
|
|
|
case CompositionOp::OP_SATURATION:
|
2016-10-25 05:40:59 +03:00
|
|
|
return SkBlendMode::kSaturation;
|
2014-01-10 23:06:17 +04:00
|
|
|
case CompositionOp::OP_COLOR:
|
2016-10-25 05:40:59 +03:00
|
|
|
return SkBlendMode::kColor;
|
2014-01-10 23:06:17 +04:00
|
|
|
case CompositionOp::OP_LUMINOSITY:
|
2016-10-25 05:40:59 +03:00
|
|
|
return SkBlendMode::kLuminosity;
|
2013-02-08 01:54:59 +04:00
|
|
|
default:
|
2016-10-25 05:40:59 +03:00
|
|
|
return SkBlendMode::kSrcOver;
|
2012-10-17 01:16:45 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-06-18 18:16:30 +04:00
|
|
|
/* There's quite a bit of inconsistency about
|
|
|
|
* whether float colors should be rounded with .5f.
|
|
|
|
* We choose to do it to match cairo which also
|
|
|
|
* happens to match the Direct3D specs */
|
|
|
|
static inline U8CPU ColorFloatToByte(Float color)
|
2012-10-17 01:16:45 +04:00
|
|
|
{
|
|
|
|
//XXX: do a better job converting to int
|
2014-06-18 18:16:30 +04:00
|
|
|
return U8CPU(color*255.f + .5f);
|
|
|
|
};
|
|
|
|
|
|
|
|
static inline SkColor ColorToSkColor(const Color &color, Float aAlpha)
|
|
|
|
{
|
|
|
|
return SkColorSetARGB(ColorFloatToByte(color.a*aAlpha), ColorFloatToByte(color.r),
|
|
|
|
ColorFloatToByte(color.g), ColorFloatToByte(color.b));
|
2012-10-17 01:16:45 +04:00
|
|
|
}
|
|
|
|
|
2015-08-27 22:44:26 +03:00
|
|
|
static inline SkPoint
|
|
|
|
PointToSkPoint(const Point &aPoint)
|
|
|
|
{
|
|
|
|
return SkPoint::Make(SkFloatToScalar(aPoint.x), SkFloatToScalar(aPoint.y));
|
|
|
|
}
|
|
|
|
|
2012-10-17 01:16:45 +04:00
|
|
|
static inline SkRect
|
|
|
|
RectToSkRect(const Rect& aRect)
|
|
|
|
{
|
2017-12-19 23:48:39 +03:00
|
|
|
return SkRect::MakeXYWH(SkFloatToScalar(aRect.X()), SkFloatToScalar(aRect.Y()),
|
2017-08-14 15:28:11 +03:00
|
|
|
SkFloatToScalar(aRect.Width()), SkFloatToScalar(aRect.Height()));
|
2012-10-17 01:16:45 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
static inline SkRect
|
|
|
|
IntRectToSkRect(const IntRect& aRect)
|
|
|
|
{
|
2017-12-19 23:48:39 +03:00
|
|
|
return SkRect::MakeXYWH(SkIntToScalar(aRect.X()), SkIntToScalar(aRect.Y()),
|
2017-08-14 15:28:11 +03:00
|
|
|
SkIntToScalar(aRect.Width()), SkIntToScalar(aRect.Height()));
|
2012-10-17 01:16:45 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
static inline SkIRect
|
|
|
|
RectToSkIRect(const Rect& aRect)
|
|
|
|
{
|
2017-12-19 23:48:39 +03:00
|
|
|
return SkIRect::MakeXYWH(int32_t(aRect.X()), int32_t(aRect.Y()),
|
2017-08-14 15:28:11 +03:00
|
|
|
int32_t(aRect.Width()), int32_t(aRect.Height()));
|
2012-10-17 01:16:45 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
static inline SkIRect
|
|
|
|
IntRectToSkIRect(const IntRect& aRect)
|
|
|
|
{
|
2017-12-19 23:48:39 +03:00
|
|
|
return SkIRect::MakeXYWH(aRect.X(), aRect.Y(), aRect.Width(), aRect.Height());
|
2012-10-17 01:16:45 +04:00
|
|
|
}
|
|
|
|
|
2017-02-28 23:47:46 +03:00
|
|
|
static inline IntRect
|
|
|
|
SkIRectToIntRect(const SkIRect& aRect)
|
|
|
|
{
|
|
|
|
return IntRect(aRect.x(), aRect.y(), aRect.width(), aRect.height());
|
|
|
|
}
|
|
|
|
|
2013-11-07 13:11:48 +04:00
|
|
|
static inline Point
|
|
|
|
SkPointToPoint(const SkPoint &aPoint)
|
|
|
|
{
|
|
|
|
return Point(SkScalarToFloat(aPoint.x()), SkScalarToFloat(aPoint.y()));
|
|
|
|
}
|
|
|
|
|
2014-04-01 12:59:20 +04:00
|
|
|
static inline Rect
|
|
|
|
SkRectToRect(const SkRect &aRect)
|
|
|
|
{
|
|
|
|
return Rect(SkScalarToFloat(aRect.x()), SkScalarToFloat(aRect.y()),
|
|
|
|
SkScalarToFloat(aRect.width()), SkScalarToFloat(aRect.height()));
|
|
|
|
}
|
|
|
|
|
2012-10-17 01:16:45 +04:00
|
|
|
static inline SkShader::TileMode
|
2015-11-23 19:17:35 +03:00
|
|
|
ExtendModeToTileMode(ExtendMode aMode, Axis aAxis)
|
2012-10-17 01:16:45 +04:00
|
|
|
{
|
|
|
|
switch (aMode)
|
|
|
|
{
|
2014-01-10 23:06:17 +04:00
|
|
|
case ExtendMode::CLAMP:
|
2012-10-17 01:16:45 +04:00
|
|
|
return SkShader::kClamp_TileMode;
|
2014-01-10 23:06:17 +04:00
|
|
|
case ExtendMode::REPEAT:
|
2012-10-17 01:16:45 +04:00
|
|
|
return SkShader::kRepeat_TileMode;
|
2014-01-10 23:06:17 +04:00
|
|
|
case ExtendMode::REFLECT:
|
2012-10-17 01:16:45 +04:00
|
|
|
return SkShader::kMirror_TileMode;
|
2015-11-23 19:17:35 +03:00
|
|
|
case ExtendMode::REPEAT_X:
|
|
|
|
{
|
|
|
|
return aAxis == Axis::X_AXIS
|
|
|
|
? SkShader::kRepeat_TileMode
|
|
|
|
: SkShader::kClamp_TileMode;
|
|
|
|
}
|
|
|
|
case ExtendMode::REPEAT_Y:
|
|
|
|
{
|
|
|
|
return aAxis == Axis::Y_AXIS
|
|
|
|
? SkShader::kRepeat_TileMode
|
|
|
|
: SkShader::kClamp_TileMode;
|
|
|
|
}
|
2012-10-17 01:16:45 +04:00
|
|
|
}
|
|
|
|
return SkShader::kClamp_TileMode;
|
|
|
|
}
|
|
|
|
|
2015-09-02 21:12:32 +03:00
|
|
|
static inline SkPaint::Hinting
|
|
|
|
GfxHintingToSkiaHinting(FontHinting aHinting)
|
|
|
|
{
|
|
|
|
switch (aHinting) {
|
|
|
|
case FontHinting::NONE:
|
|
|
|
return SkPaint::kNo_Hinting;
|
|
|
|
case FontHinting::LIGHT:
|
|
|
|
return SkPaint::kSlight_Hinting;
|
|
|
|
case FontHinting::NORMAL:
|
|
|
|
return SkPaint::kNormal_Hinting;
|
|
|
|
case FontHinting::FULL:
|
|
|
|
return SkPaint::kFull_Hinting;
|
|
|
|
}
|
|
|
|
return SkPaint::kNormal_Hinting;
|
|
|
|
}
|
|
|
|
|
2016-05-17 21:41:38 +03:00
|
|
|
static inline FillRule GetFillRule(SkPath::FillType aFillType)
|
|
|
|
{
|
|
|
|
switch (aFillType)
|
|
|
|
{
|
|
|
|
case SkPath::kWinding_FillType:
|
|
|
|
return FillRule::FILL_WINDING;
|
|
|
|
case SkPath::kEvenOdd_FillType:
|
|
|
|
return FillRule::FILL_EVEN_ODD;
|
|
|
|
case SkPath::kInverseWinding_FillType:
|
|
|
|
case SkPath::kInverseEvenOdd_FillType:
|
|
|
|
default:
|
|
|
|
NS_WARNING("Unsupported fill type\n");
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
return FillRule::FILL_EVEN_ODD;
|
|
|
|
}
|
|
|
|
|
2016-12-22 04:35:22 +03:00
|
|
|
/**
|
|
|
|
* Returns true if the canvas is backed by pixels. Returns false if the canvas
|
|
|
|
* wraps an SkPDFDocument, for example.
|
|
|
|
*
|
|
|
|
* Note: It is not clear whether the test used to implement this function may
|
|
|
|
* result in it returning false in some circumstances even when the canvas
|
|
|
|
* _is_ pixel backed. In other words maybe it is possible for such a canvas to
|
|
|
|
* have kUnknown_SkPixelGeometry?
|
|
|
|
*/
|
|
|
|
static inline bool IsBackedByPixels(const SkCanvas* aCanvas)
|
|
|
|
{
|
|
|
|
SkSurfaceProps props(0, kUnknown_SkPixelGeometry);
|
|
|
|
if (!aCanvas->getProps(&props) ||
|
|
|
|
props.pixelGeometry() == kUnknown_SkPixelGeometry) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2015-07-13 18:25:42 +03:00
|
|
|
} // namespace gfx
|
|
|
|
} // namespace mozilla
|
2011-11-02 23:55:03 +04:00
|
|
|
|
|
|
|
#endif /* MOZILLA_GFX_HELPERSSKIA_H_ */
|