summaryrefslogtreecommitdiff
path: root/vcl/inc/skia
diff options
context:
space:
mode:
authorLuboš Luňák <l.lunak@collabora.com>2021-11-19 11:09:51 +0100
committerLuboš Luňák <l.lunak@collabora.com>2021-11-22 13:49:01 +0100
commit53ce0e3af4dcb1c70380016b3824da71548cdc60 (patch)
treeb4077a95525b1b0f0026e2e84957136f396fe6cc /vcl/inc/skia
parent1b327e4a33a2a2c575c247ea90365652d6549852 (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>
Diffstat (limited to 'vcl/inc/skia')
-rw-r--r--vcl/inc/skia/gdiimpl.hxx25
-rw-r--r--vcl/inc/skia/utils.hxx22
2 files changed, 47 insertions, 0 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