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

Side by Side 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 unified diff | Download patch
OLDNEW
(Empty)
1 /*
2 * Copyright 2016 Google Inc.
3 *
4 * Use of this source code is governed by a BSD-style license that can be
5 * found in the LICENSE file.
6 */
7
8 #include "RasterWindowContext_unix.h"
9
10 #include "SkSurface.h"
11 #include "SkTypes.h"
12
13 using ::Window;
14
15 namespace sk_app {
16
17 RasterWindowContext* RasterWindowContext_unix::Create(Display* display, Window w indow,
18 const DisplayParams& param s) {
19 RasterWindowContext* ctx = new RasterWindowContext_unix(display, window, par ams);
20 if (!ctx->isValid()) {
21 delete ctx;
22 ctx = nullptr;
23 }
24 return ctx;
25 }
26
27 RasterWindowContext_unix::RasterWindowContext_unix(Display* display, Window wind ow,
28 const DisplayParams& params)
29 : fDisplay(display)
30 , fWindow(window) {
31 fDisplayParams = params;
32 XWindowAttributes attrs;
33 XGetWindowAttributes(fDisplay, fWindow, &attrs);
34 fGC = XCreateGC(fDisplay, fWindow, 0, nullptr);
35 this->resize(attrs.width, attrs.height);
36 }
37
38 void RasterWindowContext_unix::setDisplayParams(const DisplayParams& params) {
39 fDisplayParams = params;
40 XWindowAttributes attrs;
41 XGetWindowAttributes(fDisplay, fWindow, &attrs);
42 this->resize(attrs.width, attrs.height);
43 }
44
45 void RasterWindowContext_unix::resize(uint32_t w, uint32_t h) {
46 SkImageInfo info = SkImageInfo::Make(w, h, fDisplayParams.fColorType, kPremu l_SkAlphaType,
47 fDisplayParams.fColorSpace);
48 fBackbufferSurface = SkSurface::MakeRaster(info);
49
50 }
51
52 sk_sp<SkSurface> RasterWindowContext_unix::getBackbufferSurface() { return fBack bufferSurface; }
53
54 void RasterWindowContext_unix::swapBuffers() {
55 SkPixmap pm;
56 if (!fBackbufferSurface->peekPixels(&pm)) {
57 return;
58 }
59 int bitsPerPixel = pm.info().bytesPerPixel() * 8;
60 XImage image;
61 image.width = pm.width();
62 image.height = pm.height();
63 image.format = ZPixmap;
64 image.data = (char*) pm.addr();
65 image.byte_order = LSBFirst;
66 image.bitmap_unit = bitsPerPixel;
67 image.bitmap_bit_order = LSBFirst;
68 image.bitmap_pad = bitsPerPixel;
69 image.depth = 24;
70 image.bytes_per_line = pm.rowBytes() - pm.width() * pm.info().bytesPerPixel( );
71 image.bits_per_pixel = bitsPerPixel;
72 if (!XInitImage(&image)) {
73 return;
74 }
75 XPutImage(fDisplay, fWindow, fGC, &image, 0, 0, 0, 0, pm.width(), pm.height( ));
76 }
77
78 } // namespace sk_app
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698