Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(240)

Unified Diff: tools/viewer/sk_app/unix/RasterWindowContext_unix.cpp

Issue 2165813002: Add sw support to viewer on Linux. (Closed) Base URL: https://chromium.googlesource.com/skia.git@master
Patch Set: minor Created 4 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: tools/viewer/sk_app/unix/RasterWindowContext_unix.cpp
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 0000000000000000000000000000000000000000..6674615c78a744714475d1563f51bf5581399b04
--- /dev/null
+++ b/tools/viewer/sk_app/unix/RasterWindowContext_unix.cpp
@@ -0,0 +1,78 @@
+/*
+ * 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 "RasterWindowContext_unix.h"
+
+#include "SkSurface.h"
+#include "SkTypes.h"
+
+using ::Window;
+
+namespace sk_app {
+
+RasterWindowContext* RasterWindowContext_unix::Create(Display* display, Window window,
+ const DisplayParams& params) {
+ RasterWindowContext* ctx = new RasterWindowContext_unix(display, window, params);
+ if (!ctx->isValid()) {
+ delete ctx;
+ ctx = nullptr;
+ }
+ return ctx;
+}
+
+RasterWindowContext_unix::RasterWindowContext_unix(Display* display, Window 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_unix::setDisplayParams(const DisplayParams& params) {
+ fDisplayParams = params;
+ XWindowAttributes attrs;
+ XGetWindowAttributes(fDisplay, fWindow, &attrs);
+ this->resize(attrs.width, attrs.height);
+}
+
+void RasterWindowContext_unix::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_unix::getBackbufferSurface() { return fBackbufferSurface; }
+
+void RasterWindowContext_unix::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());
+}
+
+} // namespace sk_app

Powered by Google App Engine
This is Rietveld 408576698