void Init(SkCanvas *aCanvas, const DrawOptions& aOptions) { mPaint.setXfermodeMode(GfxOpToSkiaOp(aOptions.mCompositionOp)); mCanvas = aCanvas; //TODO: Can we set greyscale somehow? if (aOptions.mAntialiasMode != AntialiasMode::NONE) { mPaint.setAntiAlias(true); } else { mPaint.setAntiAlias(false); } // 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)); temp.setAlpha(U8CPU(aOptions.mAlpha*255)); //TODO: Get a rect here mCanvas->saveLayer(nullptr, &temp); mNeedsRestore = true; } else { mPaint.setAlpha(U8CPU(aOptions.mAlpha*255.0)); mAlpha = aOptions.mAlpha; } mPaint.setFilterBitmap(true); }
void Init(SkCanvas *aCanvas, const DrawOptions& aOptions, const Rect* aMaskBounds) { mPaint.setXfermodeMode(GfxOpToSkiaOp(aOptions.mCompositionOp)); mCanvas = aCanvas; //TODO: Can we set greyscale somehow? if (aOptions.mAntialiasMode != AntialiasMode::NONE) { mPaint.setAntiAlias(true); } else { mPaint.setAntiAlias(false); } Rect clipBounds = GetClipBounds(aCanvas); bool needsGroup = !IsOperatorBoundByMask(aOptions.mCompositionOp) && (!aMaskBounds || !aMaskBounds->Contains(clipBounds)); // 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 (needsGroup) { mPaint.setXfermodeMode(SkXfermode::kSrcOver_Mode); SkPaint temp; temp.setXfermodeMode(GfxOpToSkiaOp(aOptions.mCompositionOp)); temp.setAlpha(U8CPU(aOptions.mAlpha*255+0.5)); //TODO: Get a rect here mCanvas->saveLayer(nullptr, &temp); mNeedsRestore = true; } else { mPaint.setAlpha(U8CPU(aOptions.mAlpha*255.0+0.5)); mAlpha = aOptions.mAlpha; } mPaint.setFilterLevel(SkPaint::kLow_FilterLevel); }
SkColor ColorToSkColor(const Color &color, Float aAlpha) { //XXX: do a better job converting to int return SkColorSetARGB(U8CPU(color.a*aAlpha*255.0), U8CPU(color.r*255.0), U8CPU(color.g*255.0), U8CPU(color.b*255.0)); }