diff options
author | Luboš Luňák <l.lunak@collabora.com> | 2021-11-19 11:09:51 +0100 |
---|---|---|
committer | Luboš Luňák <l.lunak@collabora.com> | 2021-11-22 13:49:01 +0100 |
commit | 53ce0e3af4dcb1c70380016b3824da71548cdc60 (patch) | |
tree | b4077a95525b1b0f0026e2e84957136f396fe6cc | |
parent | 1b327e4a33a2a2c575c247ea90365652d6549852 (diff) |
move code to helper functions
I'll want some common extra functionality there later.
Change-Id: I249f9ca4662fc8e8d52c58b1bd33293f363464d8
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/125643
Tested-by: Jenkins
Reviewed-by: Luboš Luňák <l.lunak@collabora.com>
-rw-r--r-- | vcl/inc/skia/gdiimpl.hxx | 25 | ||||
-rw-r--r-- | vcl/inc/skia/utils.hxx | 22 | ||||
-rw-r--r-- | vcl/skia/gdiimpl.cxx | 50 | ||||
-rw-r--r-- | vcl/skia/salbmp.cxx | 5 |
4 files changed, 57 insertions, 45 deletions
diff --git a/vcl/inc/skia/gdiimpl.hxx b/vcl/inc/skia/gdiimpl.hxx index 9cf14f176185..aeaef186ca44 100644 --- a/vcl/inc/skia/gdiimpl.hxx +++ b/vcl/inc/skia/gdiimpl.hxx @@ -27,6 +27,8 @@ #include <skia/utils.hxx> +#include <SkPaint.h> + class SkiaFlushIdle; class GenericSalLayout; class SkFont; @@ -306,6 +308,29 @@ protected: void performDrawPolyPolygon(const basegfx::B2DPolyPolygon& polygon, double transparency, bool useAA); + // Create SkPaint set up for drawing lines (using mLineColor etc.). + SkPaint makeLinePaint(double transparency = 0) const + { + assert(mLineColor != SALCOLOR_NONE); + SkPaint paint; + paint.setColor(transparency == 0 + ? SkiaHelper::toSkColor(mLineColor) + : SkiaHelper::toSkColorWithTransparency(mLineColor, transparency)); + paint.setStyle(SkPaint::kStroke_Style); + return paint; + } + // Create SkPaint set up for filling (using mFillColor etc.). + SkPaint makeFillPaint(double transparency = 0) const + { + assert(mFillColor != SALCOLOR_NONE); + SkPaint paint; + paint.setColor(transparency == 0 + ? SkiaHelper::toSkColor(mFillColor) + : SkiaHelper::toSkColorWithTransparency(mFillColor, transparency)); + paint.setStyle(SkPaint::kFill_Style); + return paint; + } + template <typename charT, typename traits> friend inline std::basic_ostream<charT, traits>& operator<<(std::basic_ostream<charT, traits>& stream, const SkiaSalGraphicsImpl* graphics) diff --git a/vcl/inc/skia/utils.hxx b/vcl/inc/skia/utils.hxx index 92df0325c870..0583e9ceb624 100644 --- a/vcl/inc/skia/utils.hxx +++ b/vcl/inc/skia/utils.hxx @@ -73,6 +73,28 @@ VCL_DLLPUBLIC sk_sp<SkImage> makeCheckedImageSnapshot(sk_sp<SkSurface> surface, inline Size imageSize(const sk_sp<SkImage>& image) { return Size(image->width(), image->height()); } +inline SkColor toSkColor(Color color) +{ + return SkColorSetARGB(color.GetAlpha(), color.GetRed(), color.GetGreen(), color.GetBlue()); +} + +inline SkColor toSkColorWithTransparency(Color aColor, double fTransparency) +{ + return SkColorSetA(toSkColor(aColor), 255 * (1.0 - fTransparency)); +} + +inline SkColor toSkColorWithIntensity(Color color, int intensity) +{ + return SkColorSetARGB(color.GetAlpha(), color.GetRed() * intensity / 100, + color.GetGreen() * intensity / 100, color.GetBlue() * intensity / 100); +} + +inline Color fromSkColor(SkColor color) +{ + return Color(ColorAlpha, SkColorGetA(color), SkColorGetR(color), SkColorGetG(color), + SkColorGetB(color)); +} + // Whether to use GetSkImage() that checks for delayed scaling or whether to access // the stored image directly without checks. enum DirectImage diff --git a/vcl/skia/gdiimpl.cxx b/vcl/skia/gdiimpl.cxx index ae07357cb0c1..6f326d6c5aa8 100644 --- a/vcl/skia/gdiimpl.cxx +++ b/vcl/skia/gdiimpl.cxx @@ -207,28 +207,6 @@ bool polygonContainsLine(const basegfx::B2DPolyPolygon& rPolyPolygon) return false; // no straight line found } -SkColor toSkColor(Color color) -{ - return SkColorSetARGB(color.GetAlpha(), color.GetRed(), color.GetGreen(), color.GetBlue()); -} - -SkColor toSkColorWithTransparency(Color aColor, double fTransparency) -{ - return SkColorSetA(toSkColor(aColor), 255 * (1.0 - fTransparency)); -} - -SkColor toSkColorWithIntensity(Color color, int intensity) -{ - return SkColorSetARGB(color.GetAlpha(), color.GetRed() * intensity / 100, - color.GetGreen() * intensity / 100, color.GetBlue() * intensity / 100); -} - -Color fromSkColor(SkColor color) -{ - return Color(ColorAlpha, SkColorGetA(color), SkColorGetR(color), SkColorGetG(color), - SkColorGetB(color)); -} - // returns true if the source or destination rectangles are invalid bool checkInvalidSourceOrDestination(SalTwoRect const& rPosAry) { @@ -842,8 +820,7 @@ void SkiaSalGraphicsImpl::drawLine(tools::Long nX1, tools::Long nY1, tools::Long SAL_INFO("vcl.skia.trace", "drawline(" << this << "): " << Point(nX1, nY1) << "->" << Point(nX2, nY2) << ":" << mLineColor); addUpdateRegion(SkRect::MakeLTRB(nX1, nY1, nX2, nY2).makeSorted()); - SkPaint paint; - paint.setColor(toSkColor(mLineColor)); + SkPaint paint = makeLinePaint(); paint.setAntiAlias(mParent.getAntiAlias()); if (mScaling != 1 && isUnitTestRunning()) { @@ -866,12 +843,10 @@ void SkiaSalGraphicsImpl::privateDrawAlphaRect(tools::Long nX, tools::Long nY, t << ":" << mLineColor << ":" << mFillColor << ":" << fTransparency); addUpdateRegion(SkRect::MakeXYWH(nX, nY, nWidth, nHeight)); SkCanvas* canvas = getDrawCanvas(); - SkPaint paint; - paint.setAntiAlias(!blockAA && mParent.getAntiAlias()); if (mFillColor != SALCOLOR_NONE) { - paint.setColor(toSkColorWithTransparency(mFillColor, fTransparency)); - paint.setStyle(SkPaint::kFill_Style); + SkPaint paint = makeFillPaint(fTransparency); + paint.setAntiAlias(!blockAA && mParent.getAntiAlias()); // HACK: If the polygon is just a line, it still should be drawn. But when filling // Skia doesn't draw empty polygons, so in that case ensure the line is drawn. if (mLineColor == SALCOLOR_NONE && SkSize::Make(nWidth, nHeight).isEmpty()) @@ -880,8 +855,8 @@ void SkiaSalGraphicsImpl::privateDrawAlphaRect(tools::Long nX, tools::Long nY, t } if (mLineColor != SALCOLOR_NONE) { - paint.setColor(toSkColorWithTransparency(mLineColor, fTransparency)); - paint.setStyle(SkPaint::kStroke_Style); + SkPaint paint = makeLinePaint(fTransparency); + paint.setAntiAlias(!blockAA && mParent.getAntiAlias()); if (mScaling != 1 && isUnitTestRunning()) { // On HiDPI displays, do not draw just a hairline but instead a full-width "pixel" when running unittests, @@ -989,9 +964,6 @@ void SkiaSalGraphicsImpl::performDrawPolyPolygon(const basegfx::B2DPolyPolygon& polygonPath.setFillType(SkPathFillType::kEvenOdd); addUpdateRegion(polygonPath.getBounds()); - SkPaint aPaint; - aPaint.setAntiAlias(useAA); - // For lines we use toSkX()/toSkY() in order to pass centers of pixels to Skia, // as that leads to better results with floating-point coordinates // (e.g. https://bugs.chromium.org/p/skia/issues/detail?id=9611). @@ -1012,8 +984,8 @@ void SkiaSalGraphicsImpl::performDrawPolyPolygon(const basegfx::B2DPolyPolygon& } if (mFillColor != SALCOLOR_NONE) { - aPaint.setColor(toSkColorWithTransparency(mFillColor, fTransparency)); - aPaint.setStyle(SkPaint::kFill_Style); + SkPaint aPaint = makeFillPaint(fTransparency); + aPaint.setAntiAlias(useAA); // HACK: If the polygon is just a line, it still should be drawn. But when filling // Skia doesn't draw empty polygons, so in that case ensure the line is drawn. if (mLineColor == SALCOLOR_NONE && polygonPath.getBounds().isEmpty()) @@ -1022,8 +994,8 @@ void SkiaSalGraphicsImpl::performDrawPolyPolygon(const basegfx::B2DPolyPolygon& } if (mLineColor != SALCOLOR_NONE) { - aPaint.setColor(toSkColorWithTransparency(mLineColor, fTransparency)); - aPaint.setStyle(SkPaint::kStroke_Style); + SkPaint aPaint = makeLinePaint(fTransparency); + aPaint.setAntiAlias(useAA); getDrawCanvas()->drawPath(polygonPath, aPaint); } postDraw(); @@ -1222,11 +1194,9 @@ bool SkiaSalGraphicsImpl::drawPolyLine(const basegfx::B2DHomMatrix& rObjectToDev break; } - SkPaint aPaint; - aPaint.setStyle(SkPaint::kStroke_Style); + SkPaint aPaint = makeLinePaint(fTransparency); aPaint.setStrokeCap(eSkLineCap); aPaint.setStrokeJoin(eSkLineJoin); - aPaint.setColor(toSkColorWithTransparency(mLineColor, fTransparency)); aPaint.setStrokeMiter(fMiterLimit); aPaint.setStrokeWidth(fLineWidth); aPaint.setAntiAlias(mParent.getAntiAlias()); diff --git a/vcl/skia/salbmp.cxx b/vcl/skia/salbmp.cxx index 8e1938d15c50..32545963db1b 100644 --- a/vcl/skia/salbmp.cxx +++ b/vcl/skia/salbmp.cxx @@ -698,11 +698,6 @@ SkBitmap SkiaSalBitmap::GetAsSkBitmap() const return bitmap; } -static SkColor toSkColor(Color color) -{ - return SkColorSetARGB(color.GetAlpha(), color.GetRed(), color.GetGreen(), color.GetBlue()); -} - // If mEraseColor is set, this is the color to use when the bitmap is used as alpha bitmap. // E.g. COL_BLACK actually means fully opaque and COL_WHITE means fully transparent. // This is because the alpha value is set as the color itself, not the alpha of the color. |