summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLuboš Luňák <l.lunak@collabora.com>2021-08-30 21:02:29 +0200
committerLuboš Luňák <l.lunak@collabora.com>2021-08-31 11:37:53 +0200
commit234ed4bcd5c4b5b41467890b82c6efa08dec559d (patch)
treea481116f3ce3efcfc26b49676337c5fe5a151623
parent4a65109b7ab3cafddad113900754260af2dbb4ea (diff)
reduce code duplication
Change-Id: I31ee84be7ebee7f1644d7fd43bbc951abd2842d6 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/121328 Tested-by: Jenkins Reviewed-by: Luboš Luňák <l.lunak@collabora.com>
-rw-r--r--vcl/inc/skia/gdiimpl.hxx4
-rw-r--r--vcl/inc/skia/osx/gdiimpl.hxx4
-rw-r--r--vcl/inc/skia/win/gdiimpl.hxx1
-rw-r--r--vcl/inc/skia/x11/gdiimpl.hxx1
-rw-r--r--vcl/skia/gdiimpl.cxx16
-rw-r--r--vcl/skia/osx/gdiimpl.cxx41
-rw-r--r--vcl/skia/win/gdiimpl.cxx12
-rw-r--r--vcl/skia/x11/gdiimpl.cxx13
8 files changed, 35 insertions, 57 deletions
diff --git a/vcl/inc/skia/gdiimpl.hxx b/vcl/inc/skia/gdiimpl.hxx
index c914c26752cc..03a4d5cf0413 100644
--- a/vcl/inc/skia/gdiimpl.hxx
+++ b/vcl/inc/skia/gdiimpl.hxx
@@ -235,7 +235,7 @@ protected:
void createWindowSurface(bool forceRaster = false);
virtual void createWindowSurfaceInternal(bool forceRaster = false) = 0;
void createOffscreenSurface();
- void flushSurfaceToWindowContext(const SkIRect& rect);
+ virtual void flushSurfaceToWindowContext();
void privateDrawAlphaRect(tools::Long nX, tools::Long nY, tools::Long nWidth,
tools::Long nHeight, double nTransparency, bool blockAA = false);
@@ -248,7 +248,7 @@ protected:
void invert(basegfx::B2DPolygon const& rPoly, SalInvert eFlags);
// Called by SkiaFlushIdle.
- virtual void performFlush() = 0;
+ void performFlush();
void scheduleFlush();
friend class SkiaFlushIdle;
diff --git a/vcl/inc/skia/osx/gdiimpl.hxx b/vcl/inc/skia/osx/gdiimpl.hxx
index 4ffac5985edb..c4892ab45b43 100644
--- a/vcl/inc/skia/osx/gdiimpl.hxx
+++ b/vcl/inc/skia/osx/gdiimpl.hxx
@@ -45,8 +45,8 @@ public:
private:
virtual void createWindowSurfaceInternal(bool forceRaster = false) override;
- virtual void performFlush() override;
- void flushSurfaceToScreenCG(const SkIRect& rect);
+ virtual void flushSurfaceToWindowContext() override;
+ void flushSurfaceToScreenCG();
static inline sk_sp<SkFontMgr> fontManager;
};
diff --git a/vcl/inc/skia/win/gdiimpl.hxx b/vcl/inc/skia/win/gdiimpl.hxx
index 7e3f37ce435c..58043e5f6a83 100644
--- a/vcl/inc/skia/win/gdiimpl.hxx
+++ b/vcl/inc/skia/win/gdiimpl.hxx
@@ -60,7 +60,6 @@ public:
protected:
virtual void createWindowSurfaceInternal(bool forceRaster = false) override;
- virtual void performFlush() override;
static sk_sp<SkTypeface> createDirectWriteTypeface(HDC hdc, HFONT hfont);
static void initFontInfo();
inline static sal::systools::COMReference<IDWriteFactory> dwriteFactory;
diff --git a/vcl/inc/skia/x11/gdiimpl.hxx b/vcl/inc/skia/x11/gdiimpl.hxx
index d85c7dc0e5c7..b7e9fe2615e0 100644
--- a/vcl/inc/skia/x11/gdiimpl.hxx
+++ b/vcl/inc/skia/x11/gdiimpl.hxx
@@ -33,7 +33,6 @@ public:
private:
virtual void createWindowSurfaceInternal(bool forceRaster = false) override;
- virtual void performFlush() override;
virtual bool avoidRecreateByResize() const override;
static std::unique_ptr<sk_app::WindowContext>
createWindowContext(Display* display, Drawable drawable, const XVisualInfo* visual, int width,
diff --git a/vcl/skia/gdiimpl.cxx b/vcl/skia/gdiimpl.cxx
index 97a34bb3f66f..433663eadd55 100644
--- a/vcl/skia/gdiimpl.cxx
+++ b/vcl/skia/gdiimpl.cxx
@@ -391,7 +391,19 @@ void SkiaSalGraphicsImpl::destroySurface()
mIsGPU = false;
}
-void SkiaSalGraphicsImpl::flushSurfaceToWindowContext(const SkIRect& rect)
+void SkiaSalGraphicsImpl::performFlush()
+{
+ SkiaZone zone;
+ flushDrawing();
+ if (mWindowContext)
+ {
+ if (mDirtyRect.intersect(SkIRect::MakeWH(GetWidth(), GetHeight())))
+ flushSurfaceToWindowContext();
+ mDirtyRect.setEmpty();
+ }
+}
+
+void SkiaSalGraphicsImpl::flushSurfaceToWindowContext()
{
sk_sp<SkSurface> screenSurface = mWindowContext->getBackbufferSurface();
if (screenSurface != mSurface)
@@ -415,7 +427,7 @@ void SkiaSalGraphicsImpl::flushSurfaceToWindowContext(const SkIRect& rect)
// getBackbufferSurface() repeatedly. Using our own surface would duplicate
// memory and cost time copying pixels around.
assert(!isGPU());
- mWindowContext->swapBuffers(&rect);
+ mWindowContext->swapBuffers(&mDirtyRect);
}
}
diff --git a/vcl/skia/osx/gdiimpl.cxx b/vcl/skia/osx/gdiimpl.cxx
index 1be661629741..43fe07d5391a 100644
--- a/vcl/skia/osx/gdiimpl.cxx
+++ b/vcl/skia/osx/gdiimpl.cxx
@@ -84,21 +84,12 @@ void AquaSkiaSalGraphicsImpl::Flush() { performFlush(); }
void AquaSkiaSalGraphicsImpl::Flush(const tools::Rectangle&) { performFlush(); }
-void AquaSkiaSalGraphicsImpl::performFlush()
+void AquaSkiaSalGraphicsImpl::flushSurfaceToWindowContext()
{
- SkiaZone zone;
- flushDrawing();
- if (mSurface)
- {
- if (mDirtyRect.intersect(SkIRect::MakeWH(GetWidth(), GetHeight())))
- {
- if (!isGPU())
- flushSurfaceToScreenCG(mDirtyRect);
- else
- flushSurfaceToWindowContext(mDirtyRect);
- }
- mDirtyRect.setEmpty();
- }
+ if (!isGPU())
+ flushSurfaceToScreenCG();
+ else
+ SkiaSalGraphicsImpl::flushSurfaceToWindowContext();
}
constexpr static uint32_t toCGBitmapType(SkColorType color, SkAlphaType alpha)
@@ -120,7 +111,7 @@ constexpr static uint32_t toCGBitmapType(SkColorType color, SkAlphaType alpha)
}
// For Raster we use our own screen blitting (see above).
-void AquaSkiaSalGraphicsImpl::flushSurfaceToScreenCG(const SkIRect& rect)
+void AquaSkiaSalGraphicsImpl::flushSurfaceToScreenCG()
{
// Based on AquaGraphicsBackend::drawBitmap().
if (!mrShared.checkContext())
@@ -133,19 +124,20 @@ void AquaSkiaSalGraphicsImpl::flushSurfaceToScreenCG(const SkIRect& rect)
if (!image->peekPixels(&pixmap))
abort();
// This creates the bitmap context from the cropped part, writable_addr32() will get
- // the first pixel of rect.topLeft(), and using pixmap.rowBytes() ensures the following
+ // the first pixel of mDirtyRect.topLeft(), and using pixmap.rowBytes() ensures the following
// pixel lines will be read from correct positions.
- CGContextRef context
- = CGBitmapContextCreate(pixmap.writable_addr32(rect.x(), rect.y()), rect.width(),
- rect.height(), 8, pixmap.rowBytes(), GetSalData()->mxRGBSpace,
- toCGBitmapType(image->colorType(), image->alphaType()));
+ CGContextRef context = CGBitmapContextCreate(
+ pixmap.writable_addr32(mDirtyRect.x(), mDirtyRect.y()), mDirtyRect.width(),
+ mDirtyRect.height(), 8, pixmap.rowBytes(), GetSalData()->mxRGBSpace,
+ toCGBitmapType(image->colorType(), image->alphaType()));
assert(context); // TODO
CGImageRef screenImage = CGBitmapContextCreateImage(context);
assert(screenImage); // TODO
if (mrShared.isFlipped())
{
- const CGRect screenRect = CGRectMake(rect.x(), GetHeight() - rect.y() - rect.height(),
- rect.width(), rect.height());
+ const CGRect screenRect
+ = CGRectMake(mDirtyRect.x(), GetHeight() - mDirtyRect.y() - mDirtyRect.height(),
+ mDirtyRect.width(), mDirtyRect.height());
mrShared.maContextHolder.saveState();
CGContextTranslateCTM(mrShared.maContextHolder.get(), 0, pixmap.height());
CGContextScaleCTM(mrShared.maContextHolder.get(), 1, -1);
@@ -154,13 +146,14 @@ void AquaSkiaSalGraphicsImpl::flushSurfaceToScreenCG(const SkIRect& rect)
}
else
{
- const CGRect screenRect = CGRectMake(rect.x(), rect.y(), rect.width(), rect.height());
+ const CGRect screenRect
+ = CGRectMake(mDirtyRect.x(), mDirtyRect.y(), mDirtyRect.width(), mDirtyRect.height());
CGContextDrawImage(mrShared.maContextHolder.get(), screenRect, screenImage);
}
CGImageRelease(screenImage);
CGContextRelease(context);
- mrShared.refreshRect(rect.x(), rect.y(), rect.width(), rect.height());
+ mrShared.refreshRect(mDirtyRect.x(), mDirtyRect.y(), mDirtyRect.width(), mDirtyRect.height());
}
bool AquaSkiaSalGraphicsImpl::drawNativeControl(ControlType nType, ControlPart nPart,
diff --git a/vcl/skia/win/gdiimpl.cxx b/vcl/skia/win/gdiimpl.cxx
index 914e7dbc2159..1dacc71bdf3d 100644
--- a/vcl/skia/win/gdiimpl.cxx
+++ b/vcl/skia/win/gdiimpl.cxx
@@ -69,18 +69,6 @@ void WinSkiaSalGraphicsImpl::freeResources() {}
void WinSkiaSalGraphicsImpl::Flush() { performFlush(); }
-void WinSkiaSalGraphicsImpl::performFlush()
-{
- SkiaZone zone;
- flushDrawing();
- if (mWindowContext)
- {
- if (mDirtyRect.intersect(SkIRect::MakeWH(GetWidth(), GetHeight())))
- flushSurfaceToWindowContext(mDirtyRect);
- mDirtyRect.setEmpty();
- }
-}
-
bool WinSkiaSalGraphicsImpl::TryRenderCachedNativeControl(ControlCacheKey const& rControlCacheKey,
int nX, int nY)
{
diff --git a/vcl/skia/x11/gdiimpl.cxx b/vcl/skia/x11/gdiimpl.cxx
index b667dbe4c2b7..03211d8050dd 100644
--- a/vcl/skia/x11/gdiimpl.cxx
+++ b/vcl/skia/x11/gdiimpl.cxx
@@ -143,19 +143,6 @@ void X11SkiaSalGraphicsImpl::freeResources() {}
void X11SkiaSalGraphicsImpl::Flush() { performFlush(); }
-void X11SkiaSalGraphicsImpl::performFlush()
-{
- SkiaZone zone;
- flushDrawing();
- // TODO XPutImage() is somewhat inefficient, XShmPutImage() should be preferred.
- if (mWindowContext)
- {
- if (mDirtyRect.intersect(SkIRect::MakeWH(GetWidth(), GetHeight())))
- flushSurfaceToWindowContext(mDirtyRect);
- mDirtyRect.setEmpty();
- }
-}
-
std::unique_ptr<sk_app::WindowContext> createVulkanWindowContext(bool temporary)
{
SalDisplay* salDisplay = vcl_sal::getSalDisplay(GetGenericUnixSalData());