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

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: rebase Created 4 years, 4 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
« no previous file with comments | « tools/viewer/Viewer.cpp ('k') | tools/viewer/sk_app/unix/WindowContextFactory_unix.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 "WindowContextFactory_unix.h"
9 #include "../RasterWindowContext.h"
10 #include "SkSurface.h"
11
12 using sk_app::RasterWindowContext;
13 using sk_app::DisplayParams;
14
15 namespace {
16
17 class RasterWindowContext_xlib : public RasterWindowContext {
18 public:
19 RasterWindowContext_xlib(Display*, XWindow, const DisplayParams&);
20
21 sk_sp<SkSurface> getBackbufferSurface() override;
22 void swapBuffers() override;
23 bool isValid() override { return SkToBool(fWindow); }
24 void resize(uint32_t w, uint32_t h) override;
25 void setDisplayParams(const DisplayParams& params) override;
26
27 protected:
28 sk_sp<SkSurface> fBackbufferSurface;
29 Display* fDisplay;
30 XWindow fWindow;
31 GC fGC;
32 };
33
34 RasterWindowContext_xlib::RasterWindowContext_xlib(Display* display, XWindow win dow,
35 const DisplayParams& params)
36 : fDisplay(display)
37 , fWindow(window) {
38 fDisplayParams = params;
39 XWindowAttributes attrs;
40 XGetWindowAttributes(fDisplay, fWindow, &attrs);
41 fGC = XCreateGC(fDisplay, fWindow, 0, nullptr);
42 this->resize(attrs.width, attrs.height);
43 }
44
45 void RasterWindowContext_xlib::setDisplayParams(const DisplayParams& params) {
46 fDisplayParams = params;
47 XWindowAttributes attrs;
48 XGetWindowAttributes(fDisplay, fWindow, &attrs);
49 this->resize(attrs.width, attrs.height);
50 }
51
52 void RasterWindowContext_xlib::resize(uint32_t w, uint32_t h) {
53 SkImageInfo info = SkImageInfo::Make(w, h, fDisplayParams.fColorType, kPremu l_SkAlphaType,
54 fDisplayParams.fColorSpace);
55 fBackbufferSurface = SkSurface::MakeRaster(info);
56
57 }
58
59 sk_sp<SkSurface> RasterWindowContext_xlib::getBackbufferSurface() { return fBack bufferSurface; }
60
61 void RasterWindowContext_xlib::swapBuffers() {
62 SkPixmap pm;
63 if (!fBackbufferSurface->peekPixels(&pm)) {
64 return;
65 }
66 int bitsPerPixel = pm.info().bytesPerPixel() * 8;
67 XImage image;
68 image.width = pm.width();
69 image.height = pm.height();
70 image.format = ZPixmap;
71 image.data = (char*) pm.addr();
72 image.byte_order = LSBFirst;
73 image.bitmap_unit = bitsPerPixel;
74 image.bitmap_bit_order = LSBFirst;
75 image.bitmap_pad = bitsPerPixel;
76 image.depth = 24;
77 image.bytes_per_line = pm.rowBytes() - pm.width() * pm.info().bytesPerPixel( );
78 image.bits_per_pixel = bitsPerPixel;
79 if (!XInitImage(&image)) {
80 return;
81 }
82 XPutImage(fDisplay, fWindow, fGC, &image, 0, 0, 0, 0, pm.width(), pm.height( ));
83 }
84
85 } // anonymous namespace
86
87 namespace sk_app {
88 namespace window_context_factory {
89
90 WindowContext* NewRasterForXlib(const XlibWindowInfo& info, const DisplayParams& params) {
91 WindowContext* ctx = new RasterWindowContext_xlib(info.fDisplay, info.fWindo w, params);
92 if (!ctx->isValid()) {
93 delete ctx;
94 ctx = nullptr;
95 }
96 return ctx;
97 }
98
99 } // namespace window_context_factory
100 } // namespace sk_app
OLDNEW
« no previous file with comments | « tools/viewer/Viewer.cpp ('k') | tools/viewer/sk_app/unix/WindowContextFactory_unix.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698