aboutsummaryrefslogtreecommitdiffhomepage
path: root/tools/viewer/sk_app
diff options
context:
space:
mode:
authorGravatar bsalomon <bsalomon@google.com>2016-07-26 12:56:32 -0700
committerGravatar Commit bot <commit-bot@chromium.org>2016-07-26 12:56:32 -0700
commit6c471f75b28ba8c7127875277ae27799f57a3ddc (patch)
tree839b48bdb09ee9c25bed9c03e736cb9721e5b434 /tools/viewer/sk_app
parent1b51e0ec466026794f96e2c476f0c7f9db0f13dc (diff)
Add sw support to viewer on Linux.
This doesn't yet do anything with srgb/colorspace. Replaces the --vulkan flag with --backend which takes 'gl', 'vk', or 'sw'. GOLD_TRYBOT_URL= https://gold.skia.org/search?issue=2165813002 Review-Url: https://codereview.chromium.org/2165813002
Diffstat (limited to 'tools/viewer/sk_app')
-rw-r--r--tools/viewer/sk_app/unix/RasterWindowContext_unix.cpp100
-rw-r--r--tools/viewer/sk_app/unix/WindowContextFactory_unix.h2
-rw-r--r--tools/viewer/sk_app/unix/Window_unix.cpp18
3 files changed, 112 insertions, 8 deletions
diff --git a/tools/viewer/sk_app/unix/RasterWindowContext_unix.cpp b/tools/viewer/sk_app/unix/RasterWindowContext_unix.cpp
new file mode 100644
index 0000000000..aaf1712be0
--- /dev/null
+++ b/tools/viewer/sk_app/unix/RasterWindowContext_unix.cpp
@@ -0,0 +1,100 @@
+/*
+ * Copyright 2016 Google Inc.
+ *
+ * Use of this source code is governed by a BSD-style license that can be
+ * found in the LICENSE file.
+ */
+
+#include "WindowContextFactory_unix.h"
+#include "../RasterWindowContext.h"
+#include "SkSurface.h"
+
+using sk_app::RasterWindowContext;
+using sk_app::DisplayParams;
+
+namespace {
+
+class RasterWindowContext_xlib : public RasterWindowContext {
+public:
+ RasterWindowContext_xlib(Display*, XWindow, const DisplayParams&);
+
+ sk_sp<SkSurface> getBackbufferSurface() override;
+ void swapBuffers() override;
+ bool isValid() override { return SkToBool(fWindow); }
+ void resize(uint32_t w, uint32_t h) override;
+ void setDisplayParams(const DisplayParams& params) override;
+
+protected:
+ sk_sp<SkSurface> fBackbufferSurface;
+ Display* fDisplay;
+ XWindow fWindow;
+ GC fGC;
+};
+
+RasterWindowContext_xlib::RasterWindowContext_xlib(Display* display, XWindow window,
+ const DisplayParams& params)
+ : fDisplay(display)
+ , fWindow(window) {
+ fDisplayParams = params;
+ XWindowAttributes attrs;
+ XGetWindowAttributes(fDisplay, fWindow, &attrs);
+ fGC = XCreateGC(fDisplay, fWindow, 0, nullptr);
+ this->resize(attrs.width, attrs.height);
+}
+
+void RasterWindowContext_xlib::setDisplayParams(const DisplayParams& params) {
+ fDisplayParams = params;
+ XWindowAttributes attrs;
+ XGetWindowAttributes(fDisplay, fWindow, &attrs);
+ this->resize(attrs.width, attrs.height);
+}
+
+void RasterWindowContext_xlib::resize(uint32_t w, uint32_t h) {
+ SkImageInfo info = SkImageInfo::Make(w, h, fDisplayParams.fColorType, kPremul_SkAlphaType,
+ fDisplayParams.fColorSpace);
+ fBackbufferSurface = SkSurface::MakeRaster(info);
+
+}
+
+sk_sp<SkSurface> RasterWindowContext_xlib::getBackbufferSurface() { return fBackbufferSurface; }
+
+void RasterWindowContext_xlib::swapBuffers() {
+ SkPixmap pm;
+ if (!fBackbufferSurface->peekPixels(&pm)) {
+ return;
+ }
+ int bitsPerPixel = pm.info().bytesPerPixel() * 8;
+ XImage 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)) {
+ return;
+ }
+ XPutImage(fDisplay, fWindow, fGC, &image, 0, 0, 0, 0, pm.width(), pm.height());
+}
+
+} // anonymous namespace
+
+namespace sk_app {
+namespace window_context_factory {
+
+WindowContext* NewRasterForXlib(const XlibWindowInfo& info, const DisplayParams& params) {
+ WindowContext* ctx = new RasterWindowContext_xlib(info.fDisplay, info.fWindow, params);
+ if (!ctx->isValid()) {
+ delete ctx;
+ ctx = nullptr;
+ }
+ return ctx;
+}
+
+} // namespace window_context_factory
+} // namespace sk_app
diff --git a/tools/viewer/sk_app/unix/WindowContextFactory_unix.h b/tools/viewer/sk_app/unix/WindowContextFactory_unix.h
index fb1568902d..b1e21ac67a 100644
--- a/tools/viewer/sk_app/unix/WindowContextFactory_unix.h
+++ b/tools/viewer/sk_app/unix/WindowContextFactory_unix.h
@@ -30,6 +30,8 @@ WindowContext* NewVulkanForXlib(const XlibWindowInfo&, const DisplayParams&);
WindowContext* NewGLForXlib(const XlibWindowInfo&, const DisplayParams&);
+WindowContext* NewRasterForXlib(const XlibWindowInfo&, const DisplayParams&);
+
} // namespace window_context_factory
} // namespace sk_app
diff --git a/tools/viewer/sk_app/unix/Window_unix.cpp b/tools/viewer/sk_app/unix/Window_unix.cpp
index e6edfd9ef9..3520257b5f 100644
--- a/tools/viewer/sk_app/unix/Window_unix.cpp
+++ b/tools/viewer/sk_app/unix/Window_unix.cpp
@@ -47,7 +47,7 @@ bool Window_unix::initWindow(Display* display, const DisplayParams* params) {
// we already have a window
if (fDisplay) {
return true;
- }
+ }
fDisplay = display;
fWidth = 1280;
@@ -272,19 +272,21 @@ void Window_unix::show() {
bool Window_unix::attach(BackendType attachType, const DisplayParams& params) {
this->initWindow(fDisplay, &params);
- window_context_factory::XlibWindowInfo xwinInfo;
- xwinInfo.fDisplay = fDisplay;
- xwinInfo.fWindow = fWindow;
- xwinInfo.fVisualInfo = fVisualInfo;
+ window_context_factory::XlibWindowInfo winInfo;
+ winInfo.fDisplay = fDisplay;
+ winInfo.fWindow = fWindow;
+ winInfo.fVisualInfo = fVisualInfo;
switch (attachType) {
#ifdef SK_VULKAN
case kVulkan_BackendType:
- fWindowContext = window_context_factory::NewVulkanForXlib(xwinInfo, params);
+ fWindowContext = window_context_factory::NewVulkanForXlib(winInfo, params);
break;
#endif
case kNativeGL_BackendType:
- default:
- fWindowContext = window_context_factory::NewGLForXlib(xwinInfo, params);
+ fWindowContext = window_context_factory::NewGLForXlib(winInfo, params);
+ break;
+ case kRaster_BackendType:
+ fWindowContext = window_context_factory::NewRasterForXlib(winInfo, params);
break;
}