OLD | NEW |
1 /* | 1 /* |
2 * Copyright 2016 Google Inc. | 2 * Copyright 2016 Google Inc. |
3 * | 3 * |
4 * Use of this source code is governed by a BSD-style license that can be | 4 * Use of this source code is governed by a BSD-style license that can be |
5 * found in the LICENSE file. | 5 * found in the LICENSE file. |
6 */ | 6 */ |
7 | 7 |
8 #include "WindowContextFactory_unix.h" | 8 #include "WindowContextFactory_unix.h" |
9 #include "../RasterWindowContext.h" | 9 #include "../RasterWindowContext.h" |
10 #include "SkSurface.h" | 10 #include "SkSurface.h" |
11 | 11 |
12 using sk_app::RasterWindowContext; | 12 using sk_app::RasterWindowContext; |
13 using sk_app::DisplayParams; | 13 using sk_app::DisplayParams; |
14 | 14 |
15 namespace { | 15 namespace { |
16 | 16 |
17 class RasterWindowContext_xlib : public RasterWindowContext { | 17 class RasterWindowContext_xlib : public RasterWindowContext { |
18 public: | 18 public: |
19 RasterWindowContext_xlib(Display*, XWindow, const DisplayParams&); | 19 RasterWindowContext_xlib(Display*, XWindow, const DisplayParams&); |
20 | 20 |
21 sk_sp<SkSurface> getBackbufferSurface() override; | 21 sk_sp<SkSurface> getBackbufferSurface() override; |
22 void swapBuffers() override; | 22 void swapBuffers() override; |
23 bool isValid() override { return SkToBool(fWindow); } | 23 bool isValid() override { return SkToBool(fWindow); } |
24 void resize(uint32_t w, uint32_t h) override; | 24 void resize(int w, int h) override; |
25 void setDisplayParams(const DisplayParams& params) override; | 25 void setDisplayParams(const DisplayParams& params) override; |
26 | 26 |
27 protected: | 27 protected: |
28 sk_sp<SkSurface> fBackbufferSurface; | 28 sk_sp<SkSurface> fBackbufferSurface; |
29 Display* fDisplay; | 29 Display* fDisplay; |
30 XWindow fWindow; | 30 XWindow fWindow; |
31 GC fGC; | 31 GC fGC; |
32 }; | 32 }; |
33 | 33 |
34 RasterWindowContext_xlib::RasterWindowContext_xlib(Display* display, XWindow win
dow, | 34 RasterWindowContext_xlib::RasterWindowContext_xlib(Display* display, XWindow win
dow, |
35 const DisplayParams& params) | 35 const DisplayParams& params) |
36 : fDisplay(display) | 36 : fDisplay(display) |
37 , fWindow(window) { | 37 , fWindow(window) { |
38 fDisplayParams = params; | 38 fDisplayParams = params; |
39 XWindowAttributes attrs; | 39 XWindowAttributes attrs; |
40 XGetWindowAttributes(fDisplay, fWindow, &attrs); | 40 XGetWindowAttributes(fDisplay, fWindow, &attrs); |
41 fGC = XCreateGC(fDisplay, fWindow, 0, nullptr); | 41 fGC = XCreateGC(fDisplay, fWindow, 0, nullptr); |
42 this->resize(attrs.width, attrs.height); | 42 this->resize(attrs.width, attrs.height); |
43 } | 43 } |
44 | 44 |
45 void RasterWindowContext_xlib::setDisplayParams(const DisplayParams& params) { | 45 void RasterWindowContext_xlib::setDisplayParams(const DisplayParams& params) { |
46 fDisplayParams = params; | 46 fDisplayParams = params; |
47 XWindowAttributes attrs; | 47 XWindowAttributes attrs; |
48 XGetWindowAttributes(fDisplay, fWindow, &attrs); | 48 XGetWindowAttributes(fDisplay, fWindow, &attrs); |
49 this->resize(attrs.width, attrs.height); | 49 this->resize(attrs.width, attrs.height); |
50 } | 50 } |
51 | 51 |
52 void RasterWindowContext_xlib::resize(uint32_t w, uint32_t h) { | 52 void RasterWindowContext_xlib::resize(int w, int h) { |
53 SkImageInfo info = SkImageInfo::Make(w, h, fDisplayParams.fColorType, kPremu
l_SkAlphaType, | 53 SkImageInfo info = SkImageInfo::Make(w, h, fDisplayParams.fColorType, kPremu
l_SkAlphaType, |
54 fDisplayParams.fColorSpace); | 54 fDisplayParams.fColorSpace); |
55 fBackbufferSurface = SkSurface::MakeRaster(info); | 55 fBackbufferSurface = SkSurface::MakeRaster(info); |
56 | 56 |
57 } | 57 } |
58 | 58 |
59 sk_sp<SkSurface> RasterWindowContext_xlib::getBackbufferSurface() { return fBack
bufferSurface; } | 59 sk_sp<SkSurface> RasterWindowContext_xlib::getBackbufferSurface() { return fBack
bufferSurface; } |
60 | 60 |
61 void RasterWindowContext_xlib::swapBuffers() { | 61 void RasterWindowContext_xlib::swapBuffers() { |
62 SkPixmap pm; | 62 SkPixmap pm; |
(...skipping 28 matching lines...) Expand all Loading... |
91 WindowContext* ctx = new RasterWindowContext_xlib(info.fDisplay, info.fWindo
w, params); | 91 WindowContext* ctx = new RasterWindowContext_xlib(info.fDisplay, info.fWindo
w, params); |
92 if (!ctx->isValid()) { | 92 if (!ctx->isValid()) { |
93 delete ctx; | 93 delete ctx; |
94 ctx = nullptr; | 94 ctx = nullptr; |
95 } | 95 } |
96 return ctx; | 96 return ctx; |
97 } | 97 } |
98 | 98 |
99 } // namespace window_context_factory | 99 } // namespace window_context_factory |
100 } // namespace sk_app | 100 } // namespace sk_app |
OLD | NEW |