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

Side by Side Diff: tools/viewer/sk_app/unix/GLWindowContext_unix.cpp

Issue 2169543002: Use Windowing system-specific WindowContext factories. (Closed) Base URL: https://chromium.googlesource.com/skia.git@master
Patch Set: more xlib 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
OLDNEW
1 1
2 /* 2 /*
3 * Copyright 2016 Google Inc. 3 * Copyright 2016 Google Inc.
4 * 4 *
5 * Use of this source code is governed by a BSD-style license that can be 5 * Use of this source code is governed by a BSD-style license that can be
6 * found in the LICENSE file. 6 * found in the LICENSE file.
7 */ 7 */
8 8
9 #include "GLWindowContext_unix.h" 9 #include "../GLWindowContext.h"
10 #include "WindowContextFactory_unix.h"
10 11
11 #include <GL/gl.h> 12 #include <GL/gl.h>
12 13
13 #include "Window_unix.h" 14 using sk_app::window_context_factory::XlibWindowInfo;
15 using sk_app::DisplayParams;
16 using sk_app::GLWindowContext;
14 17
15 namespace sk_app { 18 namespace {
16 19
17 // platform-dependent create 20 class GLWindowContext_xlib : public GLWindowContext {
18 GLWindowContext* GLWindowContext::Create(void* platformData, const DisplayParams & params) { 21 public:
19 GLWindowContext_unix* ctx = new GLWindowContext_unix(platformData, params); 22 GLWindowContext_xlib(const XlibWindowInfo&, const DisplayParams&);
20 if (!ctx->isValid()) { 23 ~GLWindowContext_xlib() override;
21 delete ctx; 24
22 return nullptr; 25 void onSwapBuffers() override;
23 } 26
24 return ctx; 27 void onDestroyContext() override;
28
29 protected:
30 void onInitializeContext() override;
31
32 private:
33 GLWindowContext_xlib(void*, const DisplayParams&);
34
35 Display* fDisplay;
36 XWindow fWindow;
37 XVisualInfo* fVisualInfo;
38 GLXContext fGLContext;
39 };
40
41 GLWindowContext_xlib::GLWindowContext_xlib(const XlibWindowInfo& winInfo, const DisplayParams& params)
42 : GLWindowContext(params)
43 , fDisplay(winInfo.fDisplay)
44 , fWindow(winInfo.fWindow)
45 , fVisualInfo(winInfo.fVisualInfo)
46 , fGLContext() {
47 this->initializeContext();
25 } 48 }
26 49
27 GLWindowContext_unix::GLWindowContext_unix(void* platformData, const DisplayPara ms& params) 50 void GLWindowContext_xlib::onInitializeContext() {
28 : GLWindowContext(platformData, params)
29 , fDisplay(nullptr)
30 , fWindow(0)
31 , fGLContext(0) {
32
33 // any config code here (particularly for msaa)? 51 // any config code here (particularly for msaa)?
34
35 this->initializeContext(platformData, params);
36 }
37
38 GLWindowContext_unix::~GLWindowContext_unix() {
39 this->destroyContext();
40 }
41
42 void GLWindowContext_unix::onInitializeContext(void* platformData, const Display Params& params) {
43 ContextPlatformData_unix* unixPlatformData =
44 reinterpret_cast<ContextPlatformData_unix*>(platformData);
45
46 if (unixPlatformData) {
47 fDisplay = unixPlatformData->fDisplay;
48 fWindow = unixPlatformData->fWindow;
49 fVisualInfo = unixPlatformData->fVisualInfo;
50 }
51 SkASSERT(fDisplay); 52 SkASSERT(fDisplay);
52
53 fGLContext = glXCreateContext(fDisplay, fVisualInfo, nullptr, GL_TRUE); 53 fGLContext = glXCreateContext(fDisplay, fVisualInfo, nullptr, GL_TRUE);
54 if (!fGLContext) { 54 if (!fGLContext) {
55 return; 55 return;
56 } 56 }
57 57
58 if (glXMakeCurrent(fDisplay, fWindow, fGLContext)) { 58 if (glXMakeCurrent(fDisplay, fWindow, fGLContext)) {
59 glClearStencil(0); 59 glClearStencil(0);
60 glClearColor(0, 0, 0, 0); 60 glClearColor(0, 0, 0, 0);
61 glStencilMask(0xffffffff); 61 glStencilMask(0xffffffff);
62 glClear(GL_STENCIL_BUFFER_BIT | GL_COLOR_BUFFER_BIT); 62 glClear(GL_STENCIL_BUFFER_BIT | GL_COLOR_BUFFER_BIT);
63 63
64 int redBits, greenBits, blueBits; 64 int redBits, greenBits, blueBits;
65 glXGetConfig(fDisplay, fVisualInfo, GLX_RED_SIZE, &redBits); 65 glXGetConfig(fDisplay, fVisualInfo, GLX_RED_SIZE, &redBits);
66 glXGetConfig(fDisplay, fVisualInfo, GLX_GREEN_SIZE, &greenBits); 66 glXGetConfig(fDisplay, fVisualInfo, GLX_GREEN_SIZE, &greenBits);
67 glXGetConfig(fDisplay, fVisualInfo, GLX_BLUE_SIZE, &blueBits); 67 glXGetConfig(fDisplay, fVisualInfo, GLX_BLUE_SIZE, &blueBits);
68 fColorBits = redBits + greenBits + blueBits; 68 fColorBits = redBits + greenBits + blueBits;
69 glXGetConfig(fDisplay, fVisualInfo, GLX_STENCIL_SIZE, &fStencilBits); 69 glXGetConfig(fDisplay, fVisualInfo, GLX_STENCIL_SIZE, &fStencilBits);
70 glXGetConfig(fDisplay, fVisualInfo, GLX_SAMPLES_ARB, &fSampleCount); 70 glXGetConfig(fDisplay, fVisualInfo, GLX_SAMPLES_ARB, &fSampleCount);
71 71
72 XWindow root; 72 XWindow root;
73 int x, y; 73 int x, y;
74 unsigned int border_width, depth; 74 unsigned int border_width, depth;
75 XGetGeometry(fDisplay, fWindow, &root, &x, &y, 75 XGetGeometry(fDisplay, fWindow, &root, &x, &y,
76 (unsigned int*)&fWidth, (unsigned int*)&fHeight, &border_wi dth, &depth); 76 (unsigned int*)&fWidth, (unsigned int*)&fHeight, &border_wi dth, &depth);
77 glViewport(0, 0, fWidth, fHeight); 77 glViewport(0, 0, fWidth, fHeight);
78 } 78 }
79 } 79 }
80 80
81 void GLWindowContext_unix::onDestroyContext() { 81 GLWindowContext_xlib::~GLWindowContext_xlib() {
82 this->destroyContext();
83 }
84
85 void GLWindowContext_xlib::onDestroyContext() {
82 if (!fDisplay || !fGLContext) { 86 if (!fDisplay || !fGLContext) {
83 return; 87 return;
84 } 88 }
85 glXMakeCurrent(fDisplay, None, nullptr); 89 glXMakeCurrent(fDisplay, None, nullptr);
86 glXDestroyContext(fDisplay, fGLContext); 90 glXDestroyContext(fDisplay, fGLContext);
87 fGLContext = nullptr; 91 fGLContext = nullptr;
88 } 92 }
89 93
90 94 void GLWindowContext_xlib::onSwapBuffers() {
91 void GLWindowContext_unix::onSwapBuffers() {
92 if (fDisplay && fGLContext) { 95 if (fDisplay && fGLContext) {
93 glXSwapBuffers(fDisplay, fWindow); 96 glXSwapBuffers(fDisplay, fWindow);
94 } 97 }
95 } 98 }
96 99
100 } // anonymous namespace
97 101
98 } //namespace sk_app 102 namespace sk_app {
103
104 namespace window_context_factory {
105
106 WindowContext* NewGLForXlib(const XlibWindowInfo& winInfo, const DisplayParams& params) {
107 WindowContext* ctx = new GLWindowContext_xlib(winInfo, params);
108 if (!ctx->isValid()) {
109 delete ctx;
110 return nullptr;
111 }
112 return ctx;
113 }
114
115 } // namespace window_context_factory
116
117 } // namespace sk_app
OLDNEW
« no previous file with comments | « tools/viewer/sk_app/unix/GLWindowContext_unix.h ('k') | tools/viewer/sk_app/unix/VulkanWindowContext_unix.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698