2011-11-02 12:55:03 -07:00
|
|
|
/* -*- Mode: C++; tab-width: 20; indent-tabs-mode: nil; c-basic-offset: 2 -*-
|
2012-05-21 04:12:37 -07:00
|
|
|
* 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/. */
|
2011-11-02 12:55:03 -07:00
|
|
|
|
|
|
|
#ifndef MOZILLA_GFX_HELPERSSKIA_H_
|
|
|
|
#define MOZILLA_GFX_HELPERSSKIA_H_
|
|
|
|
|
|
|
|
#include "2D.h"
|
|
|
|
#include "skia/SkCanvas.h"
|
2011-11-17 20:00:38 -08:00
|
|
|
#include "skia/SkDashPathEffect.h"
|
2012-10-16 14:16:45 -07:00
|
|
|
#include "skia/SkShader.h"
|
2013-03-26 14:13:12 -07:00
|
|
|
#ifdef USE_SKIA_GPU
|
2012-11-30 15:57:38 -08:00
|
|
|
#include "skia/GrTypes.h"
|
2013-03-26 14:13:12 -07:00
|
|
|
#endif
|
2012-03-26 19:50:08 -07:00
|
|
|
#include "mozilla/Assertions.h"
|
2012-08-23 12:36:04 -07:00
|
|
|
#include <vector>
|
2011-11-02 12:55:03 -07:00
|
|
|
|
|
|
|
namespace mozilla {
|
|
|
|
namespace gfx {
|
|
|
|
|
2014-03-20 11:07:36 -07: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;
|
|
|
|
case SurfaceFormat::R5G6B5:
|
|
|
|
return kRGB_565_SkColorType;
|
|
|
|
case SurfaceFormat::A8:
|
|
|
|
return kAlpha_8_SkColorType;
|
|
|
|
default:
|
|
|
|
return kRGBA_8888_SkColorType;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-04-09 12:57:22 -07:00
|
|
|
static inline SurfaceFormat
|
2014-07-27 17:47:43 -07:00
|
|
|
SkiaColorTypeToGfxFormat(SkColorType type)
|
2013-04-09 12:57:22 -07:00
|
|
|
{
|
2014-07-27 17:47:43 -07:00
|
|
|
switch (type)
|
2013-04-09 12:57:22 -07:00
|
|
|
{
|
2014-07-27 17:47:43 -07:00
|
|
|
case kBGRA_8888_SkColorType:
|
2014-01-10 11:06:16 -08:00
|
|
|
return SurfaceFormat::B8G8R8A8;
|
2014-07-27 17:47:43 -07:00
|
|
|
case kRGB_565_SkColorType:
|
2014-01-10 11:06:16 -08:00
|
|
|
return SurfaceFormat::R5G6B5;
|
2014-07-27 17:47:43 -07:00
|
|
|
case kAlpha_8_SkColorType:
|
2014-01-10 11:06:16 -08:00
|
|
|
return SurfaceFormat::A8;
|
2013-04-09 12:57:22 -07:00
|
|
|
default:
|
2014-01-10 11:06:16 -08:00
|
|
|
return SurfaceFormat::B8G8R8A8;
|
2013-04-09 12:57:22 -07:00
|
|
|
}
|
2011-11-02 12:55:03 -07:00
|
|
|
}
|
|
|
|
|
2013-03-26 14:13:12 -07:00
|
|
|
#ifdef USE_SKIA_GPU
|
2012-11-30 15:57:38 -08:00
|
|
|
static inline GrPixelConfig
|
|
|
|
GfxFormatToGrConfig(SurfaceFormat format)
|
|
|
|
{
|
|
|
|
switch (format)
|
|
|
|
{
|
2014-01-10 11:06:16 -08:00
|
|
|
case SurfaceFormat::B8G8R8A8:
|
2012-11-30 15:57:38 -08:00
|
|
|
return kBGRA_8888_GrPixelConfig;
|
2014-01-10 11:06:16 -08:00
|
|
|
case SurfaceFormat::B8G8R8X8:
|
2012-11-30 15:57:38 -08:00
|
|
|
// We probably need to do something here.
|
|
|
|
return kBGRA_8888_GrPixelConfig;
|
2014-01-10 11:06:16 -08:00
|
|
|
case SurfaceFormat::R5G6B5:
|
2012-11-30 15:57:38 -08:00
|
|
|
return kRGB_565_GrPixelConfig;
|
2014-01-10 11:06:16 -08:00
|
|
|
case SurfaceFormat::A8:
|
2012-11-30 15:57:38 -08:00
|
|
|
return kAlpha_8_GrPixelConfig;
|
|
|
|
default:
|
|
|
|
return kRGBA_8888_GrPixelConfig;
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
2013-03-26 14:13:12 -07:00
|
|
|
#endif
|
2011-11-02 12:55:03 -07: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);
|
|
|
|
}
|
|
|
|
|
2011-11-17 20:00:38 -08:00
|
|
|
static inline SkPaint::Cap
|
|
|
|
CapStyleToSkiaCap(CapStyle aCap)
|
|
|
|
{
|
|
|
|
switch (aCap)
|
|
|
|
{
|
2014-01-10 11:06:17 -08:00
|
|
|
case CapStyle::BUTT:
|
2011-11-17 20:00:38 -08:00
|
|
|
return SkPaint::kButt_Cap;
|
2014-01-10 11:06:17 -08:00
|
|
|
case CapStyle::ROUND:
|
2011-11-17 20:00:38 -08:00
|
|
|
return SkPaint::kRound_Cap;
|
2014-01-10 11:06:17 -08:00
|
|
|
case CapStyle::SQUARE:
|
2011-11-17 20:00:38 -08:00
|
|
|
return SkPaint::kSquare_Cap;
|
|
|
|
}
|
|
|
|
return SkPaint::kDefault_Cap;
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline SkPaint::Join
|
|
|
|
JoinStyleToSkiaJoin(JoinStyle aJoin)
|
|
|
|
{
|
|
|
|
switch (aJoin)
|
|
|
|
{
|
2014-01-10 11:06:17 -08:00
|
|
|
case JoinStyle::BEVEL:
|
2011-11-17 20:00:38 -08:00
|
|
|
return SkPaint::kBevel_Join;
|
2014-01-10 11:06:17 -08:00
|
|
|
case JoinStyle::ROUND:
|
2011-11-17 20:00:38 -08:00
|
|
|
return SkPaint::kRound_Join;
|
2014-01-10 11:06:17 -08:00
|
|
|
case JoinStyle::MITER:
|
|
|
|
case JoinStyle::MITER_OR_BEVEL:
|
2011-11-17 20:00:38 -08:00
|
|
|
return SkPaint::kMiter_Join;
|
|
|
|
}
|
|
|
|
return SkPaint::kDefault_Join;
|
|
|
|
}
|
|
|
|
|
2011-11-17 20:00:38 -08:00
|
|
|
static inline bool
|
2011-11-17 20:00:38 -08:00
|
|
|
StrokeOptionsToPaint(SkPaint& aPaint, const StrokeOptions &aOptions)
|
|
|
|
{
|
2012-04-25 15:04:35 -07:00
|
|
|
// Skia renders 0 width strokes with a width of 1 (and in black),
|
2011-11-17 20:00:38 -08:00
|
|
|
// so we should just skip the draw call entirely.
|
|
|
|
if (!aOptions.mLineWidth) {
|
|
|
|
return false;
|
|
|
|
}
|
2011-11-17 20:00:38 -08:00
|
|
|
aPaint.setStrokeWidth(SkFloatToScalar(aOptions.mLineWidth));
|
|
|
|
aPaint.setStrokeMiter(SkFloatToScalar(aOptions.mMiterLimit));
|
|
|
|
aPaint.setStrokeCap(CapStyleToSkiaCap(aOptions.mLineCap));
|
|
|
|
aPaint.setStrokeJoin(JoinStyleToSkiaJoin(aOptions.mLineJoin));
|
2012-03-26 19:50:08 -07:00
|
|
|
|
2012-03-30 14:36:34 -07: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-17 20:00:38 -08:00
|
|
|
std::vector<SkScalar> pattern;
|
2012-03-30 14:36:34 -07:00
|
|
|
pattern.resize(dashCount);
|
|
|
|
|
|
|
|
for (uint32_t i = 0; i < dashCount; i++) {
|
|
|
|
pattern[i] = SkFloatToScalar(aOptions.mDashPattern[i % aOptions.mDashLength]);
|
2011-11-17 20:00:38 -08:00
|
|
|
}
|
2012-03-30 14:36:34 -07:00
|
|
|
|
2014-03-20 11:07:36 -07:00
|
|
|
SkDashPathEffect* dash = SkDashPathEffect::Create(&pattern.front(),
|
|
|
|
dashCount,
|
|
|
|
SkFloatToScalar(aOptions.mDashOffset));
|
2011-11-17 20:00:38 -08:00
|
|
|
SkSafeUnref(aPaint.setPathEffect(dash));
|
|
|
|
}
|
2012-03-30 14:36:34 -07:00
|
|
|
|
2011-11-17 20:00:38 -08:00
|
|
|
aPaint.setStyle(SkPaint::kStroke_Style);
|
2011-11-17 20:00:38 -08:00
|
|
|
return true;
|
2011-11-17 20:00:38 -08:00
|
|
|
}
|
|
|
|
|
2012-10-16 14:16:45 -07:00
|
|
|
static inline SkXfermode::Mode
|
|
|
|
GfxOpToSkiaOp(CompositionOp op)
|
|
|
|
{
|
|
|
|
switch (op)
|
|
|
|
{
|
2014-01-10 11:06:17 -08:00
|
|
|
case CompositionOp::OP_OVER:
|
2012-10-16 14:16:45 -07:00
|
|
|
return SkXfermode::kSrcOver_Mode;
|
2014-01-10 11:06:17 -08:00
|
|
|
case CompositionOp::OP_ADD:
|
2012-10-16 14:16:45 -07:00
|
|
|
return SkXfermode::kPlus_Mode;
|
2014-01-10 11:06:17 -08:00
|
|
|
case CompositionOp::OP_ATOP:
|
2012-10-16 14:16:45 -07:00
|
|
|
return SkXfermode::kSrcATop_Mode;
|
2014-01-10 11:06:17 -08:00
|
|
|
case CompositionOp::OP_OUT:
|
2012-10-16 14:16:45 -07:00
|
|
|
return SkXfermode::kSrcOut_Mode;
|
2014-01-10 11:06:17 -08:00
|
|
|
case CompositionOp::OP_IN:
|
2012-10-16 14:16:45 -07:00
|
|
|
return SkXfermode::kSrcIn_Mode;
|
2014-01-10 11:06:17 -08:00
|
|
|
case CompositionOp::OP_SOURCE:
|
2012-10-16 14:16:45 -07:00
|
|
|
return SkXfermode::kSrc_Mode;
|
2014-01-10 11:06:17 -08:00
|
|
|
case CompositionOp::OP_DEST_IN:
|
2012-10-16 14:16:45 -07:00
|
|
|
return SkXfermode::kDstIn_Mode;
|
2014-01-10 11:06:17 -08:00
|
|
|
case CompositionOp::OP_DEST_OUT:
|
2012-10-16 14:16:45 -07:00
|
|
|
return SkXfermode::kDstOut_Mode;
|
2014-01-10 11:06:17 -08:00
|
|
|
case CompositionOp::OP_DEST_OVER:
|
2012-10-16 14:16:45 -07:00
|
|
|
return SkXfermode::kDstOver_Mode;
|
2014-01-10 11:06:17 -08:00
|
|
|
case CompositionOp::OP_DEST_ATOP:
|
2012-10-16 14:16:45 -07:00
|
|
|
return SkXfermode::kDstATop_Mode;
|
2014-01-10 11:06:17 -08:00
|
|
|
case CompositionOp::OP_XOR:
|
2012-10-16 14:16:45 -07:00
|
|
|
return SkXfermode::kXor_Mode;
|
2014-01-10 11:06:17 -08:00
|
|
|
case CompositionOp::OP_MULTIPLY:
|
2013-02-07 13:54:59 -08:00
|
|
|
return SkXfermode::kMultiply_Mode;
|
2014-01-10 11:06:17 -08:00
|
|
|
case CompositionOp::OP_SCREEN:
|
2013-02-07 13:54:59 -08:00
|
|
|
return SkXfermode::kScreen_Mode;
|
2014-01-10 11:06:17 -08:00
|
|
|
case CompositionOp::OP_OVERLAY:
|
2013-02-07 13:54:59 -08:00
|
|
|
return SkXfermode::kOverlay_Mode;
|
2014-01-10 11:06:17 -08:00
|
|
|
case CompositionOp::OP_DARKEN:
|
2013-02-07 13:54:59 -08:00
|
|
|
return SkXfermode::kDarken_Mode;
|
2014-01-10 11:06:17 -08:00
|
|
|
case CompositionOp::OP_LIGHTEN:
|
2013-02-07 13:54:59 -08:00
|
|
|
return SkXfermode::kLighten_Mode;
|
2014-01-10 11:06:17 -08:00
|
|
|
case CompositionOp::OP_COLOR_DODGE:
|
2013-02-07 13:54:59 -08:00
|
|
|
return SkXfermode::kColorDodge_Mode;
|
2014-01-10 11:06:17 -08:00
|
|
|
case CompositionOp::OP_COLOR_BURN:
|
2013-02-07 13:54:59 -08:00
|
|
|
return SkXfermode::kColorBurn_Mode;
|
2014-01-10 11:06:17 -08:00
|
|
|
case CompositionOp::OP_HARD_LIGHT:
|
2013-02-07 13:54:59 -08:00
|
|
|
return SkXfermode::kHardLight_Mode;
|
2014-01-10 11:06:17 -08:00
|
|
|
case CompositionOp::OP_SOFT_LIGHT:
|
2013-02-07 13:54:59 -08:00
|
|
|
return SkXfermode::kSoftLight_Mode;
|
2014-01-10 11:06:17 -08:00
|
|
|
case CompositionOp::OP_DIFFERENCE:
|
2013-02-07 13:54:59 -08:00
|
|
|
return SkXfermode::kDifference_Mode;
|
2014-01-10 11:06:17 -08:00
|
|
|
case CompositionOp::OP_EXCLUSION:
|
2013-02-07 13:54:59 -08:00
|
|
|
return SkXfermode::kExclusion_Mode;
|
2014-01-10 11:06:17 -08:00
|
|
|
case CompositionOp::OP_HUE:
|
2013-02-07 13:54:59 -08:00
|
|
|
return SkXfermode::kHue_Mode;
|
2014-01-10 11:06:17 -08:00
|
|
|
case CompositionOp::OP_SATURATION:
|
2013-02-07 13:54:59 -08:00
|
|
|
return SkXfermode::kSaturation_Mode;
|
2014-01-10 11:06:17 -08:00
|
|
|
case CompositionOp::OP_COLOR:
|
2013-02-07 13:54:59 -08:00
|
|
|
return SkXfermode::kColor_Mode;
|
2014-01-10 11:06:17 -08:00
|
|
|
case CompositionOp::OP_LUMINOSITY:
|
2013-02-07 13:54:59 -08:00
|
|
|
return SkXfermode::kLuminosity_Mode;
|
|
|
|
default:
|
2012-10-16 14:16:45 -07:00
|
|
|
return SkXfermode::kSrcOver_Mode;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-06-18 07:16:30 -07: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-16 14:16:45 -07:00
|
|
|
{
|
|
|
|
//XXX: do a better job converting to int
|
2014-06-18 07:16:30 -07: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-16 14:16:45 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
static inline SkRect
|
|
|
|
RectToSkRect(const Rect& aRect)
|
|
|
|
{
|
|
|
|
return SkRect::MakeXYWH(SkFloatToScalar(aRect.x), SkFloatToScalar(aRect.y),
|
|
|
|
SkFloatToScalar(aRect.width), SkFloatToScalar(aRect.height));
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline SkRect
|
|
|
|
IntRectToSkRect(const IntRect& aRect)
|
|
|
|
{
|
|
|
|
return SkRect::MakeXYWH(SkIntToScalar(aRect.x), SkIntToScalar(aRect.y),
|
|
|
|
SkIntToScalar(aRect.width), SkIntToScalar(aRect.height));
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline SkIRect
|
|
|
|
RectToSkIRect(const Rect& aRect)
|
|
|
|
{
|
|
|
|
return SkIRect::MakeXYWH(int32_t(aRect.x), int32_t(aRect.y),
|
|
|
|
int32_t(aRect.width), int32_t(aRect.height));
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline SkIRect
|
|
|
|
IntRectToSkIRect(const IntRect& aRect)
|
|
|
|
{
|
|
|
|
return SkIRect::MakeXYWH(aRect.x, aRect.y, aRect.width, aRect.height);
|
|
|
|
}
|
|
|
|
|
2013-11-07 01:11:48 -08:00
|
|
|
static inline Point
|
|
|
|
SkPointToPoint(const SkPoint &aPoint)
|
|
|
|
{
|
|
|
|
return Point(SkScalarToFloat(aPoint.x()), SkScalarToFloat(aPoint.y()));
|
|
|
|
}
|
|
|
|
|
2014-04-01 01:59:20 -07:00
|
|
|
static inline Rect
|
|
|
|
SkRectToRect(const SkRect &aRect)
|
|
|
|
{
|
|
|
|
return Rect(SkScalarToFloat(aRect.x()), SkScalarToFloat(aRect.y()),
|
|
|
|
SkScalarToFloat(aRect.width()), SkScalarToFloat(aRect.height()));
|
|
|
|
}
|
|
|
|
|
2012-10-16 14:16:45 -07:00
|
|
|
static inline SkShader::TileMode
|
|
|
|
ExtendModeToTileMode(ExtendMode aMode)
|
|
|
|
{
|
|
|
|
switch (aMode)
|
|
|
|
{
|
2014-01-10 11:06:17 -08:00
|
|
|
case ExtendMode::CLAMP:
|
2012-10-16 14:16:45 -07:00
|
|
|
return SkShader::kClamp_TileMode;
|
2014-01-10 11:06:17 -08:00
|
|
|
case ExtendMode::REPEAT:
|
2012-10-16 14:16:45 -07:00
|
|
|
return SkShader::kRepeat_TileMode;
|
2014-01-10 11:06:17 -08:00
|
|
|
case ExtendMode::REFLECT:
|
2012-10-16 14:16:45 -07:00
|
|
|
return SkShader::kMirror_TileMode;
|
|
|
|
}
|
|
|
|
return SkShader::kClamp_TileMode;
|
|
|
|
}
|
|
|
|
|
2014-07-28 11:48:29 -07:00
|
|
|
// The following class was imported from Skia, which is under the
|
|
|
|
// following licence:
|
|
|
|
//
|
|
|
|
// Copyright (c) 2011 Google Inc. All rights reserved.
|
|
|
|
//
|
|
|
|
// Redistribution and use in source and binary forms, with or without
|
|
|
|
// modification, are permitted provided that the following conditions are
|
|
|
|
// met:
|
|
|
|
//
|
|
|
|
// * Redistributions of source code must retain the above copyright
|
|
|
|
// notice, this list of conditions and the following disclaimer.
|
|
|
|
// * Redistributions in binary form must reproduce the above
|
|
|
|
// copyright notice, this list of conditions and the following disclaimer
|
|
|
|
// in the documentation and/or other materials provided with the
|
|
|
|
// distribution.
|
|
|
|
// * Neither the name of Google Inc. nor the names of its
|
|
|
|
// contributors may be used to endorse or promote products derived from
|
|
|
|
// this software without specific prior written permission.
|
|
|
|
//
|
|
|
|
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
|
|
|
// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
|
|
|
// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
|
|
|
// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
|
|
|
// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
|
|
|
// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
|
|
|
// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
|
|
|
// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
|
|
|
// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
|
|
|
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
|
|
|
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|
|
|
|
|
|
|
template <typename T> class RefPtrSkia {
|
|
|
|
public:
|
|
|
|
RefPtrSkia() : fObj(NULL) {}
|
2014-08-31 20:31:20 -07:00
|
|
|
explicit RefPtrSkia(T* obj) : fObj(obj) { SkSafeRef(fObj); }
|
2014-07-28 11:48:29 -07:00
|
|
|
RefPtrSkia(const RefPtrSkia& o) : fObj(o.fObj) { SkSafeRef(fObj); }
|
|
|
|
~RefPtrSkia() { SkSafeUnref(fObj); }
|
|
|
|
|
|
|
|
RefPtrSkia& operator=(const RefPtrSkia& rp) {
|
|
|
|
SkRefCnt_SafeAssign(fObj, rp.fObj);
|
|
|
|
return *this;
|
|
|
|
}
|
|
|
|
RefPtrSkia& operator=(T* obj) {
|
|
|
|
SkRefCnt_SafeAssign(fObj, obj);
|
|
|
|
return *this;
|
|
|
|
}
|
|
|
|
|
|
|
|
T* get() const { return fObj; }
|
|
|
|
T& operator*() const { return *fObj; }
|
|
|
|
T* operator->() const { return fObj; }
|
|
|
|
|
|
|
|
RefPtrSkia& adopt(T* obj) {
|
|
|
|
SkSafeUnref(fObj);
|
|
|
|
fObj = obj;
|
|
|
|
return *this;
|
|
|
|
}
|
|
|
|
|
|
|
|
typedef T* RefPtrSkia::*unspecified_bool_type;
|
|
|
|
operator unspecified_bool_type() const {
|
|
|
|
return fObj ? &RefPtrSkia::fObj : NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
|
|
|
T* fObj;
|
|
|
|
};
|
|
|
|
|
|
|
|
// End of code imported from Skia.
|
|
|
|
|
2011-11-02 12:55:03 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
#endif /* MOZILLA_GFX_HELPERSSKIA_H_ */
|