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
|
|
|
|
|
|
|
#include "DrawTargetSkia.h"
|
|
|
|
#include "SourceSurfaceSkia.h"
|
2012-01-09 10:54:44 -08:00
|
|
|
#include "ScaledFontBase.h"
|
2013-06-05 10:48:59 -07:00
|
|
|
#include "ScaledFontCairo.h"
|
2011-11-02 12:55:03 -07:00
|
|
|
#include "skia/SkDevice.h"
|
2013-03-13 16:29:47 -07:00
|
|
|
|
|
|
|
#ifdef USE_SKIA_GPU
|
2012-11-30 15:57:38 -08:00
|
|
|
#include "skia/SkGpuDevice.h"
|
2013-06-16 19:07:18 -07:00
|
|
|
#include "skia/GrGLInterface.h"
|
2013-03-13 16:29:47 -07:00
|
|
|
#endif
|
|
|
|
|
2011-11-02 12:55:03 -07:00
|
|
|
#include "skia/SkTypeface.h"
|
|
|
|
#include "skia/SkGradientShader.h"
|
|
|
|
#include "skia/SkBlurDrawLooper.h"
|
|
|
|
#include "skia/SkBlurMaskFilter.h"
|
|
|
|
#include "skia/SkColorFilter.h"
|
|
|
|
#include "skia/SkLayerRasterizer.h"
|
|
|
|
#include "skia/SkLayerDrawLooper.h"
|
|
|
|
#include "skia/SkDashPathEffect.h"
|
|
|
|
#include "Logging.h"
|
|
|
|
#include "HelpersSkia.h"
|
|
|
|
#include "Tools.h"
|
|
|
|
#include <algorithm>
|
|
|
|
|
|
|
|
namespace mozilla {
|
|
|
|
namespace gfx {
|
|
|
|
|
|
|
|
class GradientStopsSkia : public GradientStops
|
|
|
|
{
|
|
|
|
public:
|
2012-01-18 20:48:33 -08:00
|
|
|
GradientStopsSkia(const std::vector<GradientStop>& aStops, uint32_t aNumStops, ExtendMode aExtendMode)
|
2011-11-02 12:55:03 -07:00
|
|
|
: mCount(aNumStops)
|
2012-01-18 20:48:33 -08:00
|
|
|
, mExtendMode(aExtendMode)
|
2011-11-02 12:55:03 -07:00
|
|
|
{
|
|
|
|
if (mCount == 0) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Skia gradients always require a stop at 0.0 and 1.0, insert these if
|
|
|
|
// we don't have them.
|
|
|
|
uint32_t shift = 0;
|
|
|
|
if (aStops[0].offset != 0) {
|
|
|
|
mCount++;
|
|
|
|
shift = 1;
|
|
|
|
}
|
|
|
|
if (aStops[aNumStops-1].offset != 1) {
|
|
|
|
mCount++;
|
|
|
|
}
|
|
|
|
mColors.resize(mCount);
|
|
|
|
mPositions.resize(mCount);
|
|
|
|
if (aStops[0].offset != 0) {
|
|
|
|
mColors[0] = ColorToSkColor(aStops[0].color, 1.0);
|
|
|
|
mPositions[0] = 0;
|
|
|
|
}
|
|
|
|
for (uint32_t i = 0; i < aNumStops; i++) {
|
|
|
|
mColors[i + shift] = ColorToSkColor(aStops[i].color, 1.0);
|
|
|
|
mPositions[i + shift] = SkFloatToScalar(aStops[i].offset);
|
|
|
|
}
|
|
|
|
if (aStops[aNumStops-1].offset != 1) {
|
|
|
|
mColors[mCount-1] = ColorToSkColor(aStops[aNumStops-1].color, 1.0);
|
|
|
|
mPositions[mCount-1] = SK_Scalar1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
BackendType GetBackendType() const { return BACKEND_SKIA; }
|
|
|
|
|
|
|
|
std::vector<SkColor> mColors;
|
|
|
|
std::vector<SkScalar> mPositions;
|
|
|
|
int mCount;
|
2012-01-18 20:48:33 -08:00
|
|
|
ExtendMode mExtendMode;
|
2011-11-02 12:55:03 -07:00
|
|
|
};
|
|
|
|
|
2013-08-28 07:08:10 -07:00
|
|
|
#ifdef USE_SKIA_GPU
|
2013-10-22 12:15:24 -07:00
|
|
|
int DrawTargetSkia::sTextureCacheCount = 256;
|
|
|
|
int DrawTargetSkia::sTextureCacheSizeInBytes = 96*1024*1024;
|
2013-08-28 07:08:10 -07:00
|
|
|
|
|
|
|
static std::vector<DrawTargetSkia*>&
|
|
|
|
GLDrawTargets()
|
|
|
|
{
|
|
|
|
static std::vector<DrawTargetSkia*> targets;
|
|
|
|
return targets;
|
|
|
|
}
|
|
|
|
|
2013-10-22 12:15:24 -07:00
|
|
|
void
|
|
|
|
DrawTargetSkia::RebalanceCacheLimits()
|
2013-08-28 07:08:10 -07:00
|
|
|
{
|
2013-10-22 12:15:24 -07:00
|
|
|
// Divide the global cache limits equally between all currently active GL-backed
|
|
|
|
// Skia DrawTargets.
|
2013-08-28 07:08:10 -07:00
|
|
|
std::vector<DrawTargetSkia*>& targets = GLDrawTargets();
|
2013-10-22 12:15:24 -07:00
|
|
|
uint32_t targetCount = targets.size();
|
|
|
|
if (targetCount == 0)
|
2013-08-28 07:08:10 -07:00
|
|
|
return;
|
|
|
|
|
2013-10-22 12:15:24 -07:00
|
|
|
int individualCacheSize = sTextureCacheSizeInBytes / targetCount;
|
|
|
|
for (uint32_t i = 0; i < targetCount; i++) {
|
|
|
|
targets[i]->SetCacheLimits(sTextureCacheCount, individualCacheSize);
|
2013-08-28 07:08:10 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
AddGLDrawTarget(DrawTargetSkia* target)
|
|
|
|
{
|
|
|
|
GLDrawTargets().push_back(target);
|
2013-10-22 12:15:24 -07:00
|
|
|
DrawTargetSkia::RebalanceCacheLimits();
|
2013-08-28 07:08:10 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
RemoveGLDrawTarget(DrawTargetSkia* target)
|
|
|
|
{
|
|
|
|
std::vector<DrawTargetSkia*>& targets = GLDrawTargets();
|
|
|
|
std::vector<DrawTargetSkia*>::iterator it = std::find(targets.begin(), targets.end(), target);
|
|
|
|
if (it != targets.end()) {
|
|
|
|
targets.erase(it);
|
2013-10-22 12:15:24 -07:00
|
|
|
DrawTargetSkia::RebalanceCacheLimits();
|
2013-08-28 07:08:10 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-10-22 12:15:24 -07:00
|
|
|
void
|
|
|
|
DrawTargetSkia::SetGlobalCacheLimits(int aCount, int aSizeInBytes)
|
|
|
|
{
|
|
|
|
sTextureCacheCount = aCount;
|
|
|
|
sTextureCacheSizeInBytes = aSizeInBytes;
|
|
|
|
|
|
|
|
DrawTargetSkia::RebalanceCacheLimits();
|
|
|
|
}
|
2013-08-28 07:08:10 -07:00
|
|
|
#endif
|
|
|
|
|
2011-11-02 12:55:03 -07:00
|
|
|
DrawTargetSkia::DrawTargetSkia()
|
2013-08-01 18:12:16 -07:00
|
|
|
: mSnapshot(nullptr)
|
2011-11-02 12:55:03 -07:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
DrawTargetSkia::~DrawTargetSkia()
|
|
|
|
{
|
2013-08-28 07:08:10 -07:00
|
|
|
#ifdef USE_SKIA_GPU
|
|
|
|
RemoveGLDrawTarget(this);
|
|
|
|
#endif
|
2011-11-02 12:55:03 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
TemporaryRef<SourceSurface>
|
|
|
|
DrawTargetSkia::Snapshot()
|
|
|
|
{
|
2013-08-01 18:12:16 -07:00
|
|
|
RefPtr<SourceSurfaceSkia> snapshot = mSnapshot;
|
|
|
|
if (!snapshot) {
|
|
|
|
snapshot = new SourceSurfaceSkia();
|
|
|
|
mSnapshot = snapshot;
|
|
|
|
if (!snapshot->InitFromCanvas(mCanvas.get(), mFormat, this))
|
|
|
|
return nullptr;
|
|
|
|
}
|
2013-05-29 09:49:40 -07:00
|
|
|
|
2013-08-01 18:12:16 -07:00
|
|
|
return snapshot;
|
2011-11-02 12:55:03 -07:00
|
|
|
}
|
|
|
|
|
2012-01-18 20:48:33 -08:00
|
|
|
void SetPaintPattern(SkPaint& aPaint, const Pattern& aPattern, Float aAlpha = 1.0)
|
|
|
|
{
|
|
|
|
switch (aPattern.GetType()) {
|
|
|
|
case PATTERN_COLOR: {
|
|
|
|
Color color = static_cast<const ColorPattern&>(aPattern).mColor;
|
|
|
|
aPaint.setColor(ColorToSkColor(color, aAlpha));
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case PATTERN_LINEAR_GRADIENT: {
|
|
|
|
const LinearGradientPattern& pat = static_cast<const LinearGradientPattern&>(aPattern);
|
|
|
|
GradientStopsSkia *stops = static_cast<GradientStopsSkia*>(pat.mStops.get());
|
|
|
|
SkShader::TileMode mode = ExtendModeToTileMode(stops->mExtendMode);
|
|
|
|
|
|
|
|
if (stops->mCount >= 2) {
|
|
|
|
SkPoint points[2];
|
|
|
|
points[0] = SkPoint::Make(SkFloatToScalar(pat.mBegin.x), SkFloatToScalar(pat.mBegin.y));
|
|
|
|
points[1] = SkPoint::Make(SkFloatToScalar(pat.mEnd.x), SkFloatToScalar(pat.mEnd.y));
|
|
|
|
|
|
|
|
SkShader* shader = SkGradientShader::CreateLinear(points,
|
|
|
|
&stops->mColors.front(),
|
|
|
|
&stops->mPositions.front(),
|
|
|
|
stops->mCount,
|
|
|
|
mode);
|
2012-07-25 17:11:17 -07:00
|
|
|
|
|
|
|
if (shader) {
|
|
|
|
SkMatrix mat;
|
|
|
|
GfxMatrixToSkiaMatrix(pat.mMatrix, mat);
|
|
|
|
shader->setLocalMatrix(mat);
|
|
|
|
SkSafeUnref(aPaint.setShader(shader));
|
|
|
|
}
|
|
|
|
|
2012-01-18 20:48:33 -08:00
|
|
|
} else {
|
|
|
|
aPaint.setColor(SkColorSetARGB(0, 0, 0, 0));
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case PATTERN_RADIAL_GRADIENT: {
|
|
|
|
const RadialGradientPattern& pat = static_cast<const RadialGradientPattern&>(aPattern);
|
|
|
|
GradientStopsSkia *stops = static_cast<GradientStopsSkia*>(pat.mStops.get());
|
|
|
|
SkShader::TileMode mode = ExtendModeToTileMode(stops->mExtendMode);
|
|
|
|
|
|
|
|
if (stops->mCount >= 2) {
|
|
|
|
SkPoint points[2];
|
|
|
|
points[0] = SkPoint::Make(SkFloatToScalar(pat.mCenter1.x), SkFloatToScalar(pat.mCenter1.y));
|
|
|
|
points[1] = SkPoint::Make(SkFloatToScalar(pat.mCenter2.x), SkFloatToScalar(pat.mCenter2.y));
|
|
|
|
|
2012-09-12 09:37:34 -07:00
|
|
|
SkShader* shader = SkGradientShader::CreateTwoPointConical(points[0],
|
|
|
|
SkFloatToScalar(pat.mRadius1),
|
|
|
|
points[1],
|
|
|
|
SkFloatToScalar(pat.mRadius2),
|
|
|
|
&stops->mColors.front(),
|
|
|
|
&stops->mPositions.front(),
|
|
|
|
stops->mCount,
|
|
|
|
mode);
|
2012-07-25 17:11:17 -07:00
|
|
|
if (shader) {
|
|
|
|
SkMatrix mat;
|
|
|
|
GfxMatrixToSkiaMatrix(pat.mMatrix, mat);
|
|
|
|
shader->setLocalMatrix(mat);
|
|
|
|
SkSafeUnref(aPaint.setShader(shader));
|
|
|
|
}
|
|
|
|
|
2012-01-18 20:48:33 -08:00
|
|
|
} else {
|
|
|
|
aPaint.setColor(SkColorSetARGB(0, 0, 0, 0));
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case PATTERN_SURFACE: {
|
|
|
|
const SurfacePattern& pat = static_cast<const SurfacePattern&>(aPattern);
|
|
|
|
const SkBitmap& bitmap = static_cast<SourceSurfaceSkia*>(pat.mSurface.get())->GetBitmap();
|
|
|
|
|
|
|
|
SkShader::TileMode mode = ExtendModeToTileMode(pat.mExtendMode);
|
|
|
|
SkShader* shader = SkShader::CreateBitmapShader(bitmap, mode, mode);
|
|
|
|
SkMatrix mat;
|
|
|
|
GfxMatrixToSkiaMatrix(pat.mMatrix, mat);
|
|
|
|
shader->setLocalMatrix(mat);
|
|
|
|
SkSafeUnref(aPaint.setShader(shader));
|
|
|
|
if (pat.mFilter == FILTER_POINT) {
|
|
|
|
aPaint.setFilterBitmap(false);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-11-02 12:55:03 -07:00
|
|
|
struct AutoPaintSetup {
|
|
|
|
AutoPaintSetup(SkCanvas *aCanvas, const DrawOptions& aOptions, const Pattern& aPattern)
|
|
|
|
: mNeedsRestore(false), mAlpha(1.0)
|
|
|
|
{
|
|
|
|
Init(aCanvas, aOptions);
|
2012-01-18 20:48:33 -08:00
|
|
|
SetPaintPattern(mPaint, aPattern, mAlpha);
|
2011-11-02 12:55:03 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
AutoPaintSetup(SkCanvas *aCanvas, const DrawOptions& aOptions)
|
|
|
|
: mNeedsRestore(false), mAlpha(1.0)
|
|
|
|
{
|
|
|
|
Init(aCanvas, aOptions);
|
|
|
|
}
|
|
|
|
|
|
|
|
~AutoPaintSetup()
|
|
|
|
{
|
|
|
|
if (mNeedsRestore) {
|
|
|
|
mCanvas->restore();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void Init(SkCanvas *aCanvas, const DrawOptions& aOptions)
|
|
|
|
{
|
|
|
|
mPaint.setXfermodeMode(GfxOpToSkiaOp(aOptions.mCompositionOp));
|
|
|
|
mCanvas = aCanvas;
|
|
|
|
|
|
|
|
//TODO: Can we set greyscale somehow?
|
|
|
|
if (aOptions.mAntialiasMode != AA_NONE) {
|
|
|
|
mPaint.setAntiAlias(true);
|
|
|
|
} else {
|
|
|
|
mPaint.setAntiAlias(false);
|
|
|
|
}
|
|
|
|
|
2012-03-04 16:12:15 -08:00
|
|
|
MOZ_ASSERT(aOptions.mSnapping == SNAP_NONE, "Pixel snapping not supported yet!");
|
2011-11-02 12:55:03 -07:00
|
|
|
|
|
|
|
// TODO: We could skip the temporary for operator_source and just
|
|
|
|
// clear the clip rect. The other operators would be harder
|
|
|
|
// but could be worth it to skip pushing a group.
|
|
|
|
if (!IsOperatorBoundByMask(aOptions.mCompositionOp)) {
|
|
|
|
mPaint.setXfermodeMode(SkXfermode::kSrcOver_Mode);
|
|
|
|
SkPaint temp;
|
|
|
|
temp.setXfermodeMode(GfxOpToSkiaOp(aOptions.mCompositionOp));
|
2012-09-28 10:21:40 -07:00
|
|
|
temp.setAlpha(U8CPU(aOptions.mAlpha*255));
|
2011-11-02 12:55:03 -07:00
|
|
|
//TODO: Get a rect here
|
2012-08-14 11:06:12 -07:00
|
|
|
mCanvas->saveLayer(nullptr, &temp);
|
2011-11-02 12:55:03 -07:00
|
|
|
mNeedsRestore = true;
|
|
|
|
} else {
|
2012-09-28 10:21:40 -07:00
|
|
|
mPaint.setAlpha(U8CPU(aOptions.mAlpha*255.0));
|
2011-11-02 12:55:03 -07:00
|
|
|
mAlpha = aOptions.mAlpha;
|
|
|
|
}
|
2011-11-17 20:00:38 -08:00
|
|
|
mPaint.setFilterBitmap(true);
|
2011-11-02 12:55:03 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
// TODO: Maybe add an operator overload to access this easier?
|
|
|
|
SkPaint mPaint;
|
|
|
|
bool mNeedsRestore;
|
|
|
|
SkCanvas* mCanvas;
|
|
|
|
Float mAlpha;
|
|
|
|
};
|
|
|
|
|
|
|
|
void
|
|
|
|
DrawTargetSkia::Flush()
|
|
|
|
{
|
2012-11-30 15:57:38 -08:00
|
|
|
mCanvas->flush();
|
2011-11-02 12:55:03 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
DrawTargetSkia::DrawSurface(SourceSurface *aSurface,
|
|
|
|
const Rect &aDest,
|
|
|
|
const Rect &aSource,
|
|
|
|
const DrawSurfaceOptions &aSurfOptions,
|
|
|
|
const DrawOptions &aOptions)
|
|
|
|
{
|
|
|
|
if (aSurface->GetType() != SURFACE_SKIA) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (aSource.IsEmpty()) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2011-11-02 12:55:03 -07:00
|
|
|
MarkChanged();
|
|
|
|
|
2012-11-15 16:57:40 -08:00
|
|
|
IntRect sourceIntRect;
|
|
|
|
bool integerAligned = aSource.ToIntRect(&sourceIntRect);
|
|
|
|
|
2011-11-02 12:55:03 -07:00
|
|
|
SkRect destRect = RectToSkRect(aDest);
|
|
|
|
SkRect sourceRect = RectToSkRect(aSource);
|
|
|
|
|
2012-11-15 16:57:40 -08:00
|
|
|
Rect boundingSource = aSource;
|
|
|
|
boundingSource.RoundOut();
|
|
|
|
|
|
|
|
SkRect sourceBoundingRect = RectToSkRect(boundingSource);
|
|
|
|
SkIRect sourceBoundingIRect = RectToSkIRect(boundingSource);
|
|
|
|
|
2011-11-02 12:55:03 -07:00
|
|
|
const SkBitmap& bitmap = static_cast<SourceSurfaceSkia*>(aSurface)->GetBitmap();
|
|
|
|
|
|
|
|
AutoPaintSetup paint(mCanvas.get(), aOptions);
|
2013-07-31 11:46:25 -07:00
|
|
|
if (aSurfOptions.mFilter == FILTER_POINT) {
|
2011-11-17 20:00:38 -08:00
|
|
|
paint.mPaint.setFilterBitmap(false);
|
|
|
|
}
|
2012-11-15 16:57:40 -08:00
|
|
|
|
|
|
|
if (!integerAligned) {
|
|
|
|
// We need to inflate our destRect by the same amount we inflated sourceRect
|
|
|
|
// by when we rounded up to the nearest integer size to ensure we interpolate
|
|
|
|
// the edge pixels properly, but clip to the true destination rect first so
|
|
|
|
// we don't draw outside our designated area.
|
|
|
|
mCanvas->save();
|
|
|
|
mCanvas->clipRect(destRect);
|
|
|
|
|
|
|
|
SkMatrix rectTransform;
|
|
|
|
rectTransform.setRectToRect(sourceRect, sourceBoundingRect, SkMatrix::kFill_ScaleToFit);
|
|
|
|
rectTransform.mapRect(&destRect);
|
|
|
|
}
|
|
|
|
|
|
|
|
mCanvas->drawBitmapRect(bitmap, &sourceBoundingIRect, destRect, &paint.mPaint);
|
|
|
|
|
|
|
|
if (!integerAligned) {
|
|
|
|
mCanvas->restore();
|
|
|
|
}
|
2011-11-02 12:55:03 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
DrawTargetSkia::DrawSurfaceWithShadow(SourceSurface *aSurface,
|
|
|
|
const Point &aDest,
|
|
|
|
const Color &aColor,
|
|
|
|
const Point &aOffset,
|
|
|
|
Float aSigma,
|
|
|
|
CompositionOp aOperator)
|
|
|
|
{
|
2011-11-02 12:55:03 -07:00
|
|
|
MarkChanged();
|
2011-11-02 12:55:03 -07:00
|
|
|
mCanvas->save(SkCanvas::kMatrix_SaveFlag);
|
|
|
|
mCanvas->resetMatrix();
|
|
|
|
|
|
|
|
uint32_t blurFlags = SkBlurMaskFilter::kHighQuality_BlurFlag |
|
|
|
|
SkBlurMaskFilter::kIgnoreTransform_BlurFlag;
|
|
|
|
const SkBitmap& bitmap = static_cast<SourceSurfaceSkia*>(aSurface)->GetBitmap();
|
|
|
|
SkShader* shader = SkShader::CreateBitmapShader(bitmap, SkShader::kClamp_TileMode, SkShader::kClamp_TileMode);
|
|
|
|
SkMatrix matrix;
|
|
|
|
matrix.reset();
|
|
|
|
matrix.setTranslateX(SkFloatToScalar(aDest.x));
|
|
|
|
matrix.setTranslateY(SkFloatToScalar(aDest.y));
|
|
|
|
shader->setLocalMatrix(matrix);
|
|
|
|
SkLayerDrawLooper* dl = new SkLayerDrawLooper;
|
|
|
|
SkLayerDrawLooper::LayerInfo info;
|
|
|
|
info.fPaintBits |= SkLayerDrawLooper::kShader_Bit;
|
|
|
|
SkPaint *layerPaint = dl->addLayer(info);
|
|
|
|
layerPaint->setShader(shader);
|
|
|
|
|
|
|
|
info.fPaintBits = 0;
|
|
|
|
info.fPaintBits |= SkLayerDrawLooper::kMaskFilter_Bit;
|
|
|
|
info.fPaintBits |= SkLayerDrawLooper::kColorFilter_Bit;
|
|
|
|
info.fColorMode = SkXfermode::kDst_Mode;
|
|
|
|
info.fOffset.set(SkFloatToScalar(aOffset.x), SkFloatToScalar(aOffset.y));
|
|
|
|
info.fPostTranslate = true;
|
|
|
|
|
|
|
|
SkMaskFilter* mf = SkBlurMaskFilter::Create(aSigma, SkBlurMaskFilter::kNormal_BlurStyle, blurFlags);
|
|
|
|
SkColor color = ColorToSkColor(aColor, 1);
|
|
|
|
SkColorFilter* cf = SkColorFilter::CreateModeFilter(color, SkXfermode::kSrcIn_Mode);
|
|
|
|
|
|
|
|
|
|
|
|
layerPaint = dl->addLayer(info);
|
|
|
|
SkSafeUnref(layerPaint->setMaskFilter(mf));
|
|
|
|
SkSafeUnref(layerPaint->setColorFilter(cf));
|
|
|
|
layerPaint->setColor(color);
|
|
|
|
|
|
|
|
// TODO: This is using the rasterizer to calculate an alpha mask
|
|
|
|
// on both the shadow and normal layers. We should fix this
|
|
|
|
// properly so it only happens for the shadow layer
|
|
|
|
SkLayerRasterizer *raster = new SkLayerRasterizer();
|
|
|
|
SkPaint maskPaint;
|
|
|
|
SkSafeUnref(maskPaint.setShader(shader));
|
|
|
|
raster->addLayer(maskPaint, 0, 0);
|
|
|
|
|
|
|
|
SkPaint paint;
|
|
|
|
paint.setAntiAlias(true);
|
|
|
|
SkSafeUnref(paint.setRasterizer(raster));
|
|
|
|
paint.setXfermodeMode(GfxOpToSkiaOp(aOperator));
|
|
|
|
SkSafeUnref(paint.setLooper(dl));
|
|
|
|
|
2012-09-28 10:21:40 -07:00
|
|
|
SkRect rect = RectToSkRect(Rect(Float(aDest.x), Float(aDest.y),
|
|
|
|
Float(bitmap.width()), Float(bitmap.height())));
|
2011-11-02 12:55:03 -07:00
|
|
|
mCanvas->drawRect(rect, paint);
|
|
|
|
mCanvas->restore();
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
DrawTargetSkia::FillRect(const Rect &aRect,
|
|
|
|
const Pattern &aPattern,
|
|
|
|
const DrawOptions &aOptions)
|
|
|
|
{
|
2011-11-02 12:55:03 -07:00
|
|
|
MarkChanged();
|
2011-11-02 12:55:03 -07:00
|
|
|
SkRect rect = RectToSkRect(aRect);
|
|
|
|
AutoPaintSetup paint(mCanvas.get(), aOptions, aPattern);
|
|
|
|
|
|
|
|
mCanvas->drawRect(rect, paint.mPaint);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
DrawTargetSkia::Stroke(const Path *aPath,
|
|
|
|
const Pattern &aPattern,
|
|
|
|
const StrokeOptions &aStrokeOptions,
|
|
|
|
const DrawOptions &aOptions)
|
|
|
|
{
|
2011-11-02 12:55:03 -07:00
|
|
|
MarkChanged();
|
2012-04-25 15:04:35 -07:00
|
|
|
MOZ_ASSERT(aPath, "Null path");
|
2011-11-02 12:55:03 -07:00
|
|
|
if (aPath->GetBackendType() != BACKEND_SKIA) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
const PathSkia *skiaPath = static_cast<const PathSkia*>(aPath);
|
|
|
|
|
|
|
|
|
|
|
|
AutoPaintSetup paint(mCanvas.get(), aOptions, aPattern);
|
2011-11-17 20:00:38 -08:00
|
|
|
if (!StrokeOptionsToPaint(paint.mPaint, aStrokeOptions)) {
|
|
|
|
return;
|
|
|
|
}
|
2011-11-02 12:55:03 -07:00
|
|
|
|
|
|
|
mCanvas->drawPath(skiaPath->GetPath(), paint.mPaint);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
DrawTargetSkia::StrokeRect(const Rect &aRect,
|
|
|
|
const Pattern &aPattern,
|
|
|
|
const StrokeOptions &aStrokeOptions,
|
|
|
|
const DrawOptions &aOptions)
|
|
|
|
{
|
2011-11-02 12:55:03 -07:00
|
|
|
MarkChanged();
|
2011-11-02 12:55:03 -07:00
|
|
|
AutoPaintSetup paint(mCanvas.get(), aOptions, aPattern);
|
2011-11-17 20:00:38 -08:00
|
|
|
if (!StrokeOptionsToPaint(paint.mPaint, aStrokeOptions)) {
|
|
|
|
return;
|
|
|
|
}
|
2011-11-02 12:55:03 -07:00
|
|
|
|
|
|
|
mCanvas->drawRect(RectToSkRect(aRect), paint.mPaint);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
DrawTargetSkia::StrokeLine(const Point &aStart,
|
|
|
|
const Point &aEnd,
|
|
|
|
const Pattern &aPattern,
|
|
|
|
const StrokeOptions &aStrokeOptions,
|
|
|
|
const DrawOptions &aOptions)
|
|
|
|
{
|
2011-11-02 12:55:03 -07:00
|
|
|
MarkChanged();
|
2011-11-02 12:55:03 -07:00
|
|
|
AutoPaintSetup paint(mCanvas.get(), aOptions, aPattern);
|
2011-11-17 20:00:38 -08:00
|
|
|
if (!StrokeOptionsToPaint(paint.mPaint, aStrokeOptions)) {
|
|
|
|
return;
|
|
|
|
}
|
2011-11-02 12:55:03 -07:00
|
|
|
|
|
|
|
mCanvas->drawLine(SkFloatToScalar(aStart.x), SkFloatToScalar(aStart.y),
|
|
|
|
SkFloatToScalar(aEnd.x), SkFloatToScalar(aEnd.y),
|
|
|
|
paint.mPaint);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
DrawTargetSkia::Fill(const Path *aPath,
|
|
|
|
const Pattern &aPattern,
|
|
|
|
const DrawOptions &aOptions)
|
|
|
|
{
|
2011-11-02 12:55:03 -07:00
|
|
|
MarkChanged();
|
2011-11-02 12:55:03 -07:00
|
|
|
if (aPath->GetBackendType() != BACKEND_SKIA) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
const PathSkia *skiaPath = static_cast<const PathSkia*>(aPath);
|
|
|
|
|
|
|
|
AutoPaintSetup paint(mCanvas.get(), aOptions, aPattern);
|
|
|
|
|
|
|
|
mCanvas->drawPath(skiaPath->GetPath(), paint.mPaint);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
DrawTargetSkia::FillGlyphs(ScaledFont *aFont,
|
|
|
|
const GlyphBuffer &aBuffer,
|
|
|
|
const Pattern &aPattern,
|
2012-03-19 12:20:17 -07:00
|
|
|
const DrawOptions &aOptions,
|
2013-06-05 10:48:59 -07:00
|
|
|
const GlyphRenderingOptions *aRenderingOptions)
|
2011-11-02 12:55:03 -07:00
|
|
|
{
|
2012-04-25 15:04:35 -07:00
|
|
|
if (aFont->GetType() != FONT_MAC &&
|
|
|
|
aFont->GetType() != FONT_SKIA &&
|
|
|
|
aFont->GetType() != FONT_GDI) {
|
2011-11-02 12:55:03 -07:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2011-11-02 12:55:03 -07:00
|
|
|
MarkChanged();
|
|
|
|
|
2012-01-09 10:54:44 -08:00
|
|
|
ScaledFontBase* skiaFont = static_cast<ScaledFontBase*>(aFont);
|
2011-11-02 12:55:03 -07:00
|
|
|
|
|
|
|
AutoPaintSetup paint(mCanvas.get(), aOptions, aPattern);
|
2012-01-09 10:54:44 -08:00
|
|
|
paint.mPaint.setTypeface(skiaFont->GetSkTypeface());
|
2011-11-02 12:55:03 -07:00
|
|
|
paint.mPaint.setTextSize(SkFloatToScalar(skiaFont->mSize));
|
|
|
|
paint.mPaint.setTextEncoding(SkPaint::kGlyphID_TextEncoding);
|
2013-06-05 10:48:59 -07:00
|
|
|
|
|
|
|
if (aRenderingOptions && aRenderingOptions->GetType() == FONT_CAIRO) {
|
|
|
|
switch (static_cast<const GlyphRenderingOptionsCairo*>(aRenderingOptions)->GetHinting()) {
|
|
|
|
case FONT_HINTING_NONE:
|
|
|
|
paint.mPaint.setHinting(SkPaint::kNo_Hinting);
|
|
|
|
break;
|
|
|
|
case FONT_HINTING_LIGHT:
|
|
|
|
paint.mPaint.setHinting(SkPaint::kSlight_Hinting);
|
|
|
|
break;
|
|
|
|
case FONT_HINTING_NORMAL:
|
|
|
|
paint.mPaint.setHinting(SkPaint::kNormal_Hinting);
|
|
|
|
break;
|
|
|
|
case FONT_HINTING_FULL:
|
|
|
|
paint.mPaint.setHinting(SkPaint::kFull_Hinting);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (static_cast<const GlyphRenderingOptionsCairo*>(aRenderingOptions)->GetAutoHinting()) {
|
|
|
|
paint.mPaint.setAutohinted(true);
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
paint.mPaint.setHinting(SkPaint::kNormal_Hinting);
|
|
|
|
}
|
|
|
|
|
2011-11-02 12:55:03 -07:00
|
|
|
std::vector<uint16_t> indices;
|
|
|
|
std::vector<SkPoint> offsets;
|
|
|
|
indices.resize(aBuffer.mNumGlyphs);
|
|
|
|
offsets.resize(aBuffer.mNumGlyphs);
|
|
|
|
|
|
|
|
for (unsigned int i = 0; i < aBuffer.mNumGlyphs; i++) {
|
|
|
|
indices[i] = aBuffer.mGlyphs[i].mIndex;
|
|
|
|
offsets[i].fX = SkFloatToScalar(aBuffer.mGlyphs[i].mPosition.x);
|
|
|
|
offsets[i].fY = SkFloatToScalar(aBuffer.mGlyphs[i].mPosition.y);
|
|
|
|
}
|
|
|
|
|
|
|
|
mCanvas->drawPosText(&indices.front(), aBuffer.mNumGlyphs*2, &offsets.front(), paint.mPaint);
|
|
|
|
}
|
|
|
|
|
2012-01-18 20:48:33 -08:00
|
|
|
void
|
|
|
|
DrawTargetSkia::Mask(const Pattern &aSource,
|
|
|
|
const Pattern &aMask,
|
|
|
|
const DrawOptions &aOptions)
|
|
|
|
{
|
|
|
|
MarkChanged();
|
|
|
|
AutoPaintSetup paint(mCanvas.get(), aOptions, aSource);
|
|
|
|
|
|
|
|
SkPaint maskPaint;
|
|
|
|
SetPaintPattern(maskPaint, aMask);
|
|
|
|
|
|
|
|
SkLayerRasterizer *raster = new SkLayerRasterizer();
|
|
|
|
raster->addLayer(maskPaint);
|
|
|
|
SkSafeUnref(paint.mPaint.setRasterizer(raster));
|
|
|
|
|
|
|
|
// Skia only uses the mask rasterizer when we are drawing a path/rect.
|
|
|
|
// Take our destination bounds and convert them into user space to use
|
|
|
|
// as the path to draw.
|
|
|
|
SkPath path;
|
2012-09-28 10:21:40 -07:00
|
|
|
path.addRect(SkRect::MakeWH(SkScalar(mSize.width), SkScalar(mSize.height)));
|
2012-01-18 20:48:33 -08:00
|
|
|
|
|
|
|
Matrix temp = mTransform;
|
|
|
|
temp.Invert();
|
|
|
|
SkMatrix mat;
|
|
|
|
GfxMatrixToSkiaMatrix(temp, mat);
|
|
|
|
path.transform(mat);
|
|
|
|
|
|
|
|
mCanvas->drawPath(path, paint.mPaint);
|
|
|
|
}
|
|
|
|
|
2011-11-02 12:55:03 -07:00
|
|
|
TemporaryRef<SourceSurface>
|
|
|
|
DrawTargetSkia::CreateSourceSurfaceFromData(unsigned char *aData,
|
|
|
|
const IntSize &aSize,
|
|
|
|
int32_t aStride,
|
|
|
|
SurfaceFormat aFormat) const
|
|
|
|
{
|
|
|
|
RefPtr<SourceSurfaceSkia> newSurf = new SourceSurfaceSkia();
|
|
|
|
|
|
|
|
if (!newSurf->InitFromData(aData, aSize, aStride, aFormat)) {
|
|
|
|
gfxDebug() << *this << ": Failure to create source surface from data. Size: " << aSize;
|
2012-08-14 11:06:12 -07:00
|
|
|
return nullptr;
|
2011-11-02 12:55:03 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
return newSurf;
|
|
|
|
}
|
|
|
|
|
|
|
|
TemporaryRef<DrawTarget>
|
|
|
|
DrawTargetSkia::CreateSimilarDrawTarget(const IntSize &aSize, SurfaceFormat aFormat) const
|
|
|
|
{
|
|
|
|
RefPtr<DrawTargetSkia> target = new DrawTargetSkia();
|
|
|
|
if (!target->Init(aSize, aFormat)) {
|
2012-08-14 11:06:12 -07:00
|
|
|
return nullptr;
|
2011-11-02 12:55:03 -07:00
|
|
|
}
|
|
|
|
return target;
|
|
|
|
}
|
|
|
|
|
|
|
|
TemporaryRef<SourceSurface>
|
|
|
|
DrawTargetSkia::OptimizeSourceSurface(SourceSurface *aSurface) const
|
|
|
|
{
|
2012-08-14 11:06:12 -07:00
|
|
|
return nullptr;
|
2011-11-02 12:55:03 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
TemporaryRef<SourceSurface>
|
|
|
|
DrawTargetSkia::CreateSourceSurfaceFromNativeSurface(const NativeSurface &aSurface) const
|
|
|
|
{
|
2012-08-14 11:06:12 -07:00
|
|
|
return nullptr;
|
2011-11-02 12:55:03 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
DrawTargetSkia::CopySurface(SourceSurface *aSurface,
|
|
|
|
const IntRect& aSourceRect,
|
|
|
|
const IntPoint &aDestination)
|
|
|
|
{
|
|
|
|
//TODO: We could just use writePixels() here if the sourceRect is the entire source
|
|
|
|
|
2013-05-29 09:49:40 -07:00
|
|
|
if (aSurface->GetType() != SURFACE_SKIA) {
|
2011-11-02 12:55:03 -07:00
|
|
|
return;
|
|
|
|
}
|
2011-11-02 12:55:03 -07:00
|
|
|
|
|
|
|
MarkChanged();
|
2011-11-02 12:55:03 -07:00
|
|
|
|
|
|
|
const SkBitmap& bitmap = static_cast<SourceSurfaceSkia*>(aSurface)->GetBitmap();
|
|
|
|
|
|
|
|
mCanvas->save();
|
|
|
|
mCanvas->resetMatrix();
|
|
|
|
SkRect dest = IntRectToSkRect(IntRect(aDestination.x, aDestination.y, aSourceRect.width, aSourceRect.height));
|
|
|
|
SkIRect source = IntRectToSkIRect(aSourceRect);
|
|
|
|
mCanvas->clipRect(dest, SkRegion::kReplace_Op);
|
|
|
|
SkPaint paint;
|
2012-05-31 11:56:33 -07:00
|
|
|
|
2013-05-29 09:49:40 -07:00
|
|
|
if (mCanvas->getDevice()->config() == SkBitmap::kRGB_565_Config) {
|
2012-05-31 11:56:33 -07:00
|
|
|
// Set the xfermode to SOURCE_OVER to workaround
|
|
|
|
// http://code.google.com/p/skia/issues/detail?id=628
|
|
|
|
// RGB565 is opaque so they're equivalent anyway
|
|
|
|
paint.setXfermodeMode(SkXfermode::kSrcOver_Mode);
|
|
|
|
} else {
|
|
|
|
paint.setXfermodeMode(SkXfermode::kSrc_Mode);
|
|
|
|
}
|
|
|
|
|
2011-11-02 12:55:03 -07:00
|
|
|
mCanvas->drawBitmapRect(bitmap, &source, dest, &paint);
|
|
|
|
mCanvas->restore();
|
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
|
|
|
DrawTargetSkia::Init(const IntSize &aSize, SurfaceFormat aFormat)
|
|
|
|
{
|
2013-05-29 09:49:40 -07:00
|
|
|
SkAutoTUnref<SkDevice> device(new SkDevice(GfxFormatToSkiaConfig(aFormat), aSize.width, aSize.height));
|
|
|
|
|
|
|
|
SkBitmap bitmap = device->accessBitmap(true);
|
|
|
|
if (!bitmap.allocPixels()) {
|
2011-11-02 12:55:03 -07:00
|
|
|
return false;
|
|
|
|
}
|
2013-05-29 09:49:40 -07:00
|
|
|
|
|
|
|
bitmap.eraseARGB(0, 0, 0, 0);
|
|
|
|
|
2011-11-02 12:55:03 -07:00
|
|
|
SkAutoTUnref<SkCanvas> canvas(new SkCanvas(device.get()));
|
|
|
|
mSize = aSize;
|
|
|
|
|
|
|
|
mCanvas = canvas.get();
|
|
|
|
mFormat = aFormat;
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2013-03-13 16:29:47 -07:00
|
|
|
#ifdef USE_SKIA_GPU
|
2012-11-30 15:57:38 -08:00
|
|
|
void
|
2013-06-16 19:07:18 -07:00
|
|
|
DrawTargetSkia::InitWithGLContextAndGrGLInterface(GenericRefCountedBase* aGLContext,
|
|
|
|
GrGLInterface* aGrGLInterface,
|
|
|
|
const IntSize &aSize,
|
|
|
|
SurfaceFormat aFormat)
|
2012-11-30 15:57:38 -08:00
|
|
|
{
|
2013-06-16 19:07:18 -07:00
|
|
|
mGLContext = aGLContext;
|
|
|
|
mSize = aSize;
|
|
|
|
mFormat = aFormat;
|
2013-06-17 10:45:04 -07:00
|
|
|
|
2013-06-16 19:07:18 -07:00
|
|
|
mGrGLInterface = aGrGLInterface;
|
2013-06-17 10:45:04 -07:00
|
|
|
mGrGLInterface->fCallbackData = reinterpret_cast<GrGLInterfaceCallbackData>(this);
|
|
|
|
|
2013-06-16 19:07:18 -07:00
|
|
|
GrBackendContext backendContext = reinterpret_cast<GrBackendContext>(aGrGLInterface);
|
2013-06-17 10:45:04 -07:00
|
|
|
SkAutoTUnref<GrContext> gr(GrContext::Create(kOpenGL_GrBackend, backendContext));
|
|
|
|
mGrContext = gr.get();
|
2013-06-16 19:07:18 -07:00
|
|
|
|
2013-04-09 12:57:22 -07:00
|
|
|
GrBackendRenderTargetDesc targetDescriptor;
|
2012-11-30 15:57:38 -08:00
|
|
|
|
2013-06-16 19:07:18 -07:00
|
|
|
targetDescriptor.fWidth = mSize.width;
|
|
|
|
targetDescriptor.fHeight = mSize.height;
|
|
|
|
targetDescriptor.fConfig = GfxFormatToGrConfig(mFormat);
|
2013-04-09 12:57:22 -07:00
|
|
|
targetDescriptor.fOrigin = kBottomLeft_GrSurfaceOrigin;
|
2012-11-30 15:57:38 -08:00
|
|
|
targetDescriptor.fSampleCnt = 0;
|
2013-06-16 19:07:18 -07:00
|
|
|
targetDescriptor.fRenderTargetHandle = 0; // GLContext always exposes the right framebuffer as id 0
|
2012-11-30 15:57:38 -08:00
|
|
|
|
2013-06-16 19:07:18 -07:00
|
|
|
SkAutoTUnref<GrRenderTarget> target(mGrContext->wrapBackendRenderTarget(targetDescriptor));
|
2013-05-29 11:04:25 -07:00
|
|
|
SkAutoTUnref<SkDevice> device(new SkGpuDevice(mGrContext.get(), target.get()));
|
2012-11-30 15:57:38 -08:00
|
|
|
SkAutoTUnref<SkCanvas> canvas(new SkCanvas(device.get()));
|
|
|
|
mCanvas = canvas.get();
|
2013-08-28 07:08:10 -07:00
|
|
|
|
|
|
|
AddGLDrawTarget(this);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
DrawTargetSkia::SetCacheLimits(int aCount, int aSizeInBytes)
|
|
|
|
{
|
|
|
|
MOZ_ASSERT(mGrContext, "No GrContext!");
|
|
|
|
mGrContext->setTextureCacheLimits(aCount, aSizeInBytes);
|
2012-11-30 15:57:38 -08:00
|
|
|
}
|
2013-03-13 16:29:47 -07:00
|
|
|
#endif
|
2012-11-30 15:57:38 -08:00
|
|
|
|
2012-01-18 20:48:33 -08:00
|
|
|
void
|
|
|
|
DrawTargetSkia::Init(unsigned char* aData, const IntSize &aSize, int32_t aStride, SurfaceFormat aFormat)
|
|
|
|
{
|
2013-05-29 09:49:40 -07:00
|
|
|
bool isOpaque = false;
|
2012-09-12 16:07:53 -07:00
|
|
|
if (aFormat == FORMAT_B8G8R8X8) {
|
|
|
|
// We have to manually set the A channel to be 255 as Skia doesn't understand BGRX
|
|
|
|
ConvertBGRXToBGRA(aData, aSize, aStride);
|
2013-05-29 09:49:40 -07:00
|
|
|
isOpaque = true;
|
2012-09-12 16:07:53 -07:00
|
|
|
}
|
2012-01-18 20:48:33 -08:00
|
|
|
|
2013-05-29 09:49:40 -07:00
|
|
|
SkAutoTUnref<SkDevice> device(new SkDevice(GfxFormatToSkiaConfig(aFormat), aSize.width, aSize.height, isOpaque));
|
|
|
|
|
|
|
|
SkBitmap bitmap = (SkBitmap)device->accessBitmap(true);
|
|
|
|
bitmap.lockPixels();
|
|
|
|
bitmap.setPixels(aData);
|
|
|
|
bitmap.setConfig(GfxFormatToSkiaConfig(aFormat), aSize.width, aSize.height, aStride);
|
|
|
|
bitmap.unlockPixels();
|
|
|
|
bitmap.notifyPixelsChanged();
|
|
|
|
|
2012-01-18 20:48:33 -08:00
|
|
|
SkAutoTUnref<SkCanvas> canvas(new SkCanvas(device.get()));
|
|
|
|
mSize = aSize;
|
|
|
|
|
|
|
|
mCanvas = canvas.get();
|
|
|
|
mFormat = aFormat;
|
|
|
|
}
|
|
|
|
|
2011-11-02 12:55:03 -07:00
|
|
|
void
|
|
|
|
DrawTargetSkia::SetTransform(const Matrix& aTransform)
|
|
|
|
{
|
|
|
|
SkMatrix mat;
|
|
|
|
GfxMatrixToSkiaMatrix(aTransform, mat);
|
|
|
|
mCanvas->setMatrix(mat);
|
|
|
|
mTransform = aTransform;
|
|
|
|
}
|
|
|
|
|
|
|
|
TemporaryRef<PathBuilder>
|
|
|
|
DrawTargetSkia::CreatePathBuilder(FillRule aFillRule) const
|
|
|
|
{
|
|
|
|
RefPtr<PathBuilderSkia> pb = new PathBuilderSkia(aFillRule);
|
|
|
|
return pb;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
DrawTargetSkia::ClearRect(const Rect &aRect)
|
|
|
|
{
|
2011-11-02 12:55:03 -07:00
|
|
|
MarkChanged();
|
2011-11-02 12:55:03 -07:00
|
|
|
SkPaint paint;
|
|
|
|
mCanvas->save();
|
2013-10-08 12:05:57 -07:00
|
|
|
mCanvas->clipRect(RectToSkRect(aRect), SkRegion::kIntersect_Op, true);
|
2011-11-02 12:55:03 -07:00
|
|
|
paint.setColor(SkColorSetARGB(0, 0, 0, 0));
|
|
|
|
paint.setXfermodeMode(SkXfermode::kSrc_Mode);
|
|
|
|
mCanvas->drawPaint(paint);
|
|
|
|
mCanvas->restore();
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
DrawTargetSkia::PushClip(const Path *aPath)
|
|
|
|
{
|
|
|
|
if (aPath->GetBackendType() != BACKEND_SKIA) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
const PathSkia *skiaPath = static_cast<const PathSkia*>(aPath);
|
|
|
|
mCanvas->save(SkCanvas::kClip_SaveFlag);
|
2013-10-08 12:05:57 -07:00
|
|
|
mCanvas->clipPath(skiaPath->GetPath(), SkRegion::kIntersect_Op, true);
|
2011-11-02 12:55:03 -07:00
|
|
|
}
|
|
|
|
|
2012-01-18 20:48:33 -08:00
|
|
|
void
|
|
|
|
DrawTargetSkia::PushClipRect(const Rect& aRect)
|
|
|
|
{
|
|
|
|
SkRect rect = RectToSkRect(aRect);
|
|
|
|
|
|
|
|
mCanvas->save(SkCanvas::kClip_SaveFlag);
|
2013-10-08 12:05:57 -07:00
|
|
|
mCanvas->clipRect(rect, SkRegion::kIntersect_Op, true);
|
2012-01-18 20:48:33 -08:00
|
|
|
}
|
|
|
|
|
2011-11-02 12:55:03 -07:00
|
|
|
void
|
|
|
|
DrawTargetSkia::PopClip()
|
|
|
|
{
|
|
|
|
mCanvas->restore();
|
|
|
|
}
|
|
|
|
|
|
|
|
TemporaryRef<GradientStops>
|
2011-12-27 21:56:11 -08:00
|
|
|
DrawTargetSkia::CreateGradientStops(GradientStop *aStops, uint32_t aNumStops, ExtendMode aExtendMode) const
|
2011-11-02 12:55:03 -07:00
|
|
|
{
|
|
|
|
std::vector<GradientStop> stops;
|
|
|
|
stops.resize(aNumStops);
|
|
|
|
for (uint32_t i = 0; i < aNumStops; i++) {
|
|
|
|
stops[i] = aStops[i];
|
|
|
|
}
|
|
|
|
std::stable_sort(stops.begin(), stops.end());
|
|
|
|
|
2012-01-18 20:48:33 -08:00
|
|
|
return new GradientStopsSkia(stops, aNumStops, aExtendMode);
|
2011-11-02 12:55:03 -07:00
|
|
|
}
|
|
|
|
|
2011-11-02 12:55:03 -07:00
|
|
|
void
|
2013-08-01 18:12:16 -07:00
|
|
|
DrawTargetSkia::MarkChanged()
|
2013-08-02 20:35:39 -07:00
|
|
|
{
|
2013-08-01 18:12:16 -07:00
|
|
|
if (mSnapshot) {
|
|
|
|
mSnapshot->DrawTargetWillChange();
|
|
|
|
mSnapshot = nullptr;
|
2011-11-02 12:55:03 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2013-08-01 18:12:16 -07:00
|
|
|
DrawTargetSkia::SnapshotDestroyed()
|
2011-11-02 12:55:03 -07:00
|
|
|
{
|
2013-08-01 18:12:16 -07:00
|
|
|
mSnapshot = nullptr;
|
2011-11-02 12:55:03 -07:00
|
|
|
}
|
|
|
|
|
2011-11-02 12:55:03 -07:00
|
|
|
}
|
|
|
|
}
|