OLD | NEW |
(Empty) | |
| 1 |
| 2 /* |
| 3 * Copyright 2016 Google Inc. |
| 4 * |
| 5 * Use of this source code is governed by a BSD-style license that can be |
| 6 * found in the LICENSE file. |
| 7 */ |
| 8 |
| 9 #include "GLWindowContext_unix.h" |
| 10 |
| 11 #include <GL/gl.h> |
| 12 |
| 13 #include "Window_unix.h" |
| 14 |
| 15 namespace sk_app { |
| 16 |
| 17 // platform-dependent create |
| 18 GLWindowContext* GLWindowContext::Create(void* platformData, const DisplayParams
& params) { |
| 19 GLWindowContext_unix* ctx = new GLWindowContext_unix(platformData, params); |
| 20 if (!ctx->isValid()) { |
| 21 delete ctx; |
| 22 return nullptr; |
| 23 } |
| 24 return ctx; |
| 25 } |
| 26 |
| 27 GLWindowContext_unix::GLWindowContext_unix(void* platformData, const DisplayPara
ms& params) |
| 28 : GLWindowContext(platformData, params) |
| 29 , fDisplay(nullptr) |
| 30 , fWindow(0) |
| 31 , fGLContext(0) { |
| 32 |
| 33 // 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 |
| 53 fGLContext = glXCreateContext(fDisplay, fVisualInfo, nullptr, GL_TRUE); |
| 54 if (!fGLContext) { |
| 55 return; |
| 56 } |
| 57 |
| 58 if (glXMakeCurrent(fDisplay, fWindow, fGLContext)) { |
| 59 glClearStencil(0); |
| 60 glClearColor(0, 0, 0, 0); |
| 61 glStencilMask(0xffffffff); |
| 62 glClear(GL_STENCIL_BUFFER_BIT | GL_COLOR_BUFFER_BIT); |
| 63 |
| 64 int redBits, greenBits, blueBits; |
| 65 glXGetConfig(fDisplay, fVisualInfo, GLX_RED_SIZE, &redBits); |
| 66 glXGetConfig(fDisplay, fVisualInfo, GLX_GREEN_SIZE, &greenBits); |
| 67 glXGetConfig(fDisplay, fVisualInfo, GLX_BLUE_SIZE, &blueBits); |
| 68 fColorBits = redBits + greenBits + blueBits; |
| 69 glXGetConfig(fDisplay, fVisualInfo, GLX_STENCIL_SIZE, &fStencilBits); |
| 70 glXGetConfig(fDisplay, fVisualInfo, GLX_SAMPLES_ARB, &fSampleCount); |
| 71 |
| 72 XWindow root; |
| 73 int x, y; |
| 74 unsigned int border_width, depth; |
| 75 XGetGeometry(fDisplay, fWindow, &root, &x, &y, |
| 76 (unsigned int*)&fWidth, (unsigned int*)&fHeight, &border_wi
dth, &depth); |
| 77 glViewport(0, 0, fWidth, fHeight); |
| 78 } |
| 79 } |
| 80 |
| 81 void GLWindowContext_unix::onDestroyContext() { |
| 82 if (!fDisplay || !fGLContext) { |
| 83 return; |
| 84 } |
| 85 glXMakeCurrent(fDisplay, None, nullptr); |
| 86 glXDestroyContext(fDisplay, fGLContext); |
| 87 fGLContext = nullptr; |
| 88 } |
| 89 |
| 90 |
| 91 void GLWindowContext_unix::onSwapBuffers() { |
| 92 if (fDisplay && fGLContext) { |
| 93 printf("swapping\n"); |
| 94 glXSwapBuffers(fDisplay, fWindow); |
| 95 } |
| 96 } |
| 97 |
| 98 |
| 99 } //namespace sk_app |
OLD | NEW |