summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLuboš Luňák <l.lunak@collabora.com>2019-10-07 12:40:02 +0200
committerLuboš Luňák <l.lunak@collabora.com>2019-10-10 11:14:08 +0200
commit3d1b9405ad3507d788f7321d3aaddf40febf35d8 (patch)
tree185a38c4fa41827f58a01b0127402c68280785f3
parentf15162033e8716d469052d0e1ebcde395baf30c0 (diff)
make X11/Skia render to screen using Skia code
Change-Id: I3056afe2ba0a15e0798d209ab9bd833c773948be
-rw-r--r--vcl/inc/skia/gdiimpl.hxx2
-rw-r--r--vcl/inc/skia/x11/gdiimpl.hxx10
-rw-r--r--vcl/skia/gdiimpl.cxx9
-rw-r--r--vcl/skia/x11/gdiimpl.cxx74
4 files changed, 51 insertions, 44 deletions
diff --git a/vcl/inc/skia/gdiimpl.hxx b/vcl/inc/skia/gdiimpl.hxx
index 28f088179611..91e3db4be5f8 100644
--- a/vcl/inc/skia/gdiimpl.hxx
+++ b/vcl/inc/skia/gdiimpl.hxx
@@ -197,6 +197,8 @@ public:
#endif
protected:
+ virtual void createSurface();
+
void setProvider(SalGeometryProvider* provider) { mProvider = provider; }
bool isOffscreen() const { return mProvider == nullptr || mProvider->IsOffScreen(); }
diff --git a/vcl/inc/skia/x11/gdiimpl.hxx b/vcl/inc/skia/x11/gdiimpl.hxx
index fcc0ecb116d8..c3ffb1221cd9 100644
--- a/vcl/inc/skia/x11/gdiimpl.hxx
+++ b/vcl/inc/skia/x11/gdiimpl.hxx
@@ -16,6 +16,11 @@
#include <unx/x11/x11gdiimpl.h>
#include <skia/gdiimpl.hxx>
+namespace sk_app
+{
+class WindowContext;
+}
+
class VCL_PLUGIN_PUBLIC X11SkiaSalGraphicsImpl : public SkiaSalGraphicsImpl, public X11GraphicsImpl
{
private:
@@ -26,6 +31,7 @@ public:
virtual ~X11SkiaSalGraphicsImpl() override;
virtual void Init() override;
+ virtual void DeInit() override;
virtual void freeResources() override;
// implementation of X11GraphicsImpl
@@ -36,11 +42,11 @@ public:
bool TryRenderCachedNativeControl(ControlCacheKey& rControlCacheKey, int nX, int nY) override;
protected:
+ virtual void createSurface() override;
virtual void performFlush() override;
private:
- GC getGC();
- GC mCopyGc;
+ std::unique_ptr<sk_app::WindowContext> mWindowContext;
};
#endif // INCLUDED_VCL_INC_SKIA_X11_GDIIMPL_HXX
diff --git a/vcl/skia/gdiimpl.cxx b/vcl/skia/gdiimpl.cxx
index 07937c6b9cb0..c9936d675d66 100644
--- a/vcl/skia/gdiimpl.cxx
+++ b/vcl/skia/gdiimpl.cxx
@@ -67,8 +67,7 @@ SkiaSalGraphicsImpl::~SkiaSalGraphicsImpl() {}
void SkiaSalGraphicsImpl::Init()
{
- // TODO
- mSurface = SkSurface::MakeRasterN32Premul(GetWidth(), GetHeight());
+ createSurface();
mSurface->getCanvas()->save(); // see SetClipRegion()
mClipRegion = vcl::Region(tools::Rectangle(0, 0, GetWidth(), GetHeight()));
@@ -76,6 +75,12 @@ void SkiaSalGraphicsImpl::Init()
mFlush->SetPriority(TaskPriority::POST_PAINT);
}
+void SkiaSalGraphicsImpl::createSurface()
+{
+ // TODO
+ mSurface = SkSurface::MakeRasterN32Premul(GetWidth(), GetHeight());
+}
+
void SkiaSalGraphicsImpl::DeInit() { mSurface.reset(); }
static SkIRect toSkIRect(const tools::Rectangle& rectangle)
diff --git a/vcl/skia/x11/gdiimpl.cxx b/vcl/skia/x11/gdiimpl.cxx
index 3891de5b059e..5c4408eff7c2 100644
--- a/vcl/skia/x11/gdiimpl.cxx
+++ b/vcl/skia/x11/gdiimpl.cxx
@@ -18,10 +18,16 @@
#include <skia/x11/gdiimpl.hxx>
+// TODO
+#define SK_ASSUME_GL 1
+#define SK_ASSUME_GL_ES 0
+
+#include <tools/sk_app/unix/WindowContextFactory_unix.h>
+#include <tools/sk_app/WindowContext.h>
+
X11SkiaSalGraphicsImpl::X11SkiaSalGraphicsImpl(X11SalGraphics& rParent)
: SkiaSalGraphicsImpl(rParent, rParent.GetGeometryProvider())
, mParent(rParent)
- , mCopyGc(None)
{
}
@@ -34,54 +40,42 @@ void X11SkiaSalGraphicsImpl::Init()
SkiaSalGraphicsImpl::Init();
}
-GC X11SkiaSalGraphicsImpl::getGC()
+void X11SkiaSalGraphicsImpl::createSurface()
{
- if (mCopyGc == None)
- {
- XGCValues values;
- values.graphics_exposures = False;
- values.subwindow_mode = ClipByChildren;
- mCopyGc = XCreateGC(mParent.GetXDisplay(), mParent.GetDrawable(),
- GCGraphicsExposures | GCSubwindowMode, &values);
- }
- return mCopyGc;
+ if (isOffscreen())
+ return SkiaSalGraphicsImpl::createSurface();
+ sk_app::DisplayParams displayParams;
+ // TODO The Skia Xlib code actually requires the non-native color type to work properly.
+ // Use a macro to hide an unreachable code warning.
+#define GET_FORMAT \
+ kN32_SkColorType == kBGRA_8888_SkColorType ? kRGBA_8888_SkColorType : kBGRA_8888_SkColorType
+ displayParams.fColorType = GET_FORMAT;
+#undef GET_FORMAT
+ sk_app::window_context_factory::XlibWindowInfo winInfo;
+ winInfo.fDisplay = mParent.GetXDisplay();
+ winInfo.fWindow = mParent.GetDrawable();
+ assert(winInfo.fDisplay && winInfo.fWindow != None);
+ winInfo.fFBConfig = nullptr; // not used
+ winInfo.fVisualInfo = const_cast<SalVisual*>(&mParent.GetVisual());
+ winInfo.fWidth = GetWidth();
+ winInfo.fHeight = GetHeight();
+ mWindowContext.reset(sk_app::window_context_factory::NewRasterForXlib(winInfo, displayParams));
+ assert(SkToBool(mWindowContext)); // TODO
+ mSurface = mWindowContext->getBackbufferSurface();
}
-void X11SkiaSalGraphicsImpl::freeResources()
+void X11SkiaSalGraphicsImpl::DeInit()
{
- if (mCopyGc != None)
- {
- XFreeGC(mParent.GetXDisplay(), mCopyGc);
- mCopyGc = None;
- }
+ mWindowContext.reset();
+ SkiaSalGraphicsImpl::DeInit();
}
+void X11SkiaSalGraphicsImpl::freeResources() {}
+
void X11SkiaSalGraphicsImpl::performFlush()
{
- Display* dpy = mParent.GetXDisplay();
- Drawable drawable = mParent.GetDrawable();
- GC gc = getGC();
- SkPixmap pm;
- if (!mSurface->peekPixels(&pm))
- abort();
- int bitsPerPixel = pm.info().bytesPerPixel() * 8;
- XImage image;
- memset(&image, 0, sizeof(image));
- image.width = pm.width();
- image.height = pm.height();
- image.format = ZPixmap;
- image.data = (char*)pm.addr();
- image.byte_order = LSBFirst;
- image.bitmap_unit = bitsPerPixel;
- image.bitmap_bit_order = LSBFirst;
- image.bitmap_pad = bitsPerPixel;
- image.depth = 24;
- image.bytes_per_line = pm.rowBytes() - pm.width() * pm.info().bytesPerPixel();
- image.bits_per_pixel = bitsPerPixel;
- if (!XInitImage(&image))
- abort();
// TODO XPutImage() is somewhat inefficient, XShmPutImage() should be preferred.
- XPutImage(dpy, drawable, gc, &image, 0, 0, 0, 0, pm.width(), pm.height());
+ mWindowContext->swapBuffers();
}
void X11SkiaSalGraphicsImpl::FillPixmapFromScreen(X11Pixmap* pPixmap, int nX, int nY)