| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright (c) 2013 The WebRTC project authors. All Rights Reserved. | 2 * Copyright (c) 2013 The WebRTC project authors. All Rights Reserved. |
| 3 * | 3 * |
| 4 * Use of this source code is governed by a BSD-style license | 4 * Use of this source code is governed by a BSD-style license |
| 5 * that can be found in the LICENSE file in the root of the source | 5 * that can be found in the LICENSE file in the root of the source |
| 6 * tree. An additional intellectual property rights grant can be found | 6 * tree. An additional intellectual property rights grant can be found |
| 7 * in the file PATENTS. All contributing project authors may | 7 * in the file PATENTS. All contributing project authors may |
| 8 * be found in the AUTHORS file in the root of the source tree. | 8 * be found in the AUTHORS file in the root of the source tree. |
| 9 */ | 9 */ |
| 10 | 10 |
| 11 #include "webrtc/test/linux/glx_renderer.h" | 11 #include "webrtc/test/linux/glx_renderer.h" |
| 12 | 12 |
| 13 #include <assert.h> | 13 #include <assert.h> |
| 14 #include <stdlib.h> | 14 #include <stdlib.h> |
| 15 | 15 |
| 16 #include <X11/Xatom.h> | 16 #include <X11/Xatom.h> |
| 17 #include <X11/Xlib.h> | 17 #include <X11/Xlib.h> |
| 18 | 18 |
| 19 #include "webrtc/common_video/libyuv/include/webrtc_libyuv.h" | 19 #include "webrtc/common_video/libyuv/include/webrtc_libyuv.h" |
| 20 | 20 |
| 21 namespace webrtc { | 21 namespace webrtc { |
| 22 namespace test { | 22 namespace test { |
| 23 | 23 |
| 24 GlxRenderer::GlxRenderer(size_t width, size_t height) | 24 GlxRenderer::GlxRenderer(size_t width, size_t height) |
| 25 : width_(width), | 25 : width_(width), height_(height), display_(nullptr), context_(nullptr) { |
| 26 height_(height), | |
| 27 display_(NULL), | |
| 28 context_(NULL) { | |
| 29 assert(width > 0); | 26 assert(width > 0); |
| 30 assert(height > 0); | 27 assert(height > 0); |
| 31 } | 28 } |
| 32 | 29 |
| 33 GlxRenderer::~GlxRenderer() { Destroy(); } | 30 GlxRenderer::~GlxRenderer() { Destroy(); } |
| 34 | 31 |
| 35 bool GlxRenderer::Init(const char* window_title) { | 32 bool GlxRenderer::Init(const char* window_title) { |
| 36 if ((display_ = XOpenDisplay(NULL)) == NULL) { | 33 if ((display_ = XOpenDisplay(nullptr)) == nullptr) { |
| 37 Destroy(); | 34 Destroy(); |
| 38 return false; | 35 return false; |
| 39 } | 36 } |
| 40 | 37 |
| 41 int screen = DefaultScreen(display_); | 38 int screen = DefaultScreen(display_); |
| 42 | 39 |
| 43 XVisualInfo* vi; | 40 XVisualInfo* vi; |
| 44 int attr_list[] = { GLX_DOUBLEBUFFER, GLX_RGBA, GLX_RED_SIZE, 4, | 41 int attr_list[] = { GLX_DOUBLEBUFFER, GLX_RGBA, GLX_RED_SIZE, 4, |
| 45 GLX_GREEN_SIZE, 4, GLX_BLUE_SIZE, 4, GLX_DEPTH_SIZE, 16, | 42 GLX_GREEN_SIZE, 4, GLX_BLUE_SIZE, 4, GLX_DEPTH_SIZE, 16, |
| 46 None, }; | 43 None, }; |
| 47 | 44 |
| 48 if ((vi = glXChooseVisual(display_, screen, attr_list)) == NULL) { | 45 if ((vi = glXChooseVisual(display_, screen, attr_list)) == nullptr) { |
| 49 Destroy(); | 46 Destroy(); |
| 50 return false; | 47 return false; |
| 51 } | 48 } |
| 52 | 49 |
| 53 context_ = glXCreateContext(display_, vi, 0, true); | 50 context_ = glXCreateContext(display_, vi, 0, true); |
| 54 if (context_ == NULL) { | 51 if (context_ == nullptr) { |
| 55 Destroy(); | 52 Destroy(); |
| 56 return false; | 53 return false; |
| 57 } | 54 } |
| 58 | 55 |
| 59 XSetWindowAttributes window_attributes; | 56 XSetWindowAttributes window_attributes; |
| 60 window_attributes.colormap = XCreateColormap( | 57 window_attributes.colormap = XCreateColormap( |
| 61 display_, RootWindow(display_, vi->screen), vi->visual, AllocNone); | 58 display_, RootWindow(display_, vi->screen), vi->visual, AllocNone); |
| 62 window_attributes.border_pixel = 0; | 59 window_attributes.border_pixel = 0; |
| 63 window_attributes.event_mask = StructureNotifyMask | ExposureMask; | 60 window_attributes.event_mask = StructureNotifyMask | ExposureMask; |
| 64 window_ = XCreateWindow(display_, RootWindow(display_, vi->screen), 0, 0, | 61 window_ = XCreateWindow(display_, RootWindow(display_, vi->screen), 0, 0, |
| 65 width_, height_, 0, vi->depth, InputOutput, | 62 width_, height_, 0, vi->depth, InputOutput, |
| 66 vi->visual, CWBorderPixel | CWColormap | CWEventMask, | 63 vi->visual, CWBorderPixel | CWColormap | CWEventMask, |
| 67 &window_attributes); | 64 &window_attributes); |
| 68 XFree(vi); | 65 XFree(vi); |
| 69 | 66 |
| 70 XSetStandardProperties(display_, window_, window_title, window_title, None, | 67 XSetStandardProperties(display_, window_, window_title, window_title, None, |
| 71 NULL, 0, NULL); | 68 nullptr, 0, nullptr); |
| 72 | 69 |
| 73 Atom wm_delete = XInternAtom(display_, "WM_DELETE_WINDOW", True); | 70 Atom wm_delete = XInternAtom(display_, "WM_DELETE_WINDOW", True); |
| 74 if (wm_delete != None) { | 71 if (wm_delete != None) { |
| 75 XSetWMProtocols(display_, window_, &wm_delete, 1); | 72 XSetWMProtocols(display_, window_, &wm_delete, 1); |
| 76 } | 73 } |
| 77 | 74 |
| 78 XMapRaised(display_, window_); | 75 XMapRaised(display_, window_); |
| 79 | 76 |
| 80 if (!glXMakeCurrent(display_, window_, context_)) { | 77 if (!glXMakeCurrent(display_, window_, context_)) { |
| 81 Destroy(); | 78 Destroy(); |
| 82 return false; | 79 return false; |
| 83 } | 80 } |
| 84 GlRenderer::Init(); | 81 GlRenderer::Init(); |
| 85 if (!glXMakeCurrent(display_, None, NULL)) { | 82 if (!glXMakeCurrent(display_, None, nullptr)) { |
| 86 Destroy(); | 83 Destroy(); |
| 87 return false; | 84 return false; |
| 88 } | 85 } |
| 89 | 86 |
| 90 Resize(width_, height_); | 87 Resize(width_, height_); |
| 91 return true; | 88 return true; |
| 92 } | 89 } |
| 93 | 90 |
| 94 void GlxRenderer::Destroy() { | 91 void GlxRenderer::Destroy() { |
| 95 if (context_ != NULL) { | 92 if (context_ != nullptr) { |
| 96 glXMakeCurrent(display_, window_, context_); | 93 glXMakeCurrent(display_, window_, context_); |
| 97 GlRenderer::Destroy(); | 94 GlRenderer::Destroy(); |
| 98 glXMakeCurrent(display_, None, NULL); | 95 glXMakeCurrent(display_, None, nullptr); |
| 99 glXDestroyContext(display_, context_); | 96 glXDestroyContext(display_, context_); |
| 100 context_ = NULL; | 97 context_ = nullptr; |
| 101 } | 98 } |
| 102 | 99 |
| 103 if (display_ != NULL) { | 100 if (display_ != nullptr) { |
| 104 XCloseDisplay(display_); | 101 XCloseDisplay(display_); |
| 105 display_ = NULL; | 102 display_ = nullptr; |
| 106 } | 103 } |
| 107 } | 104 } |
| 108 | 105 |
| 109 GlxRenderer* GlxRenderer::Create(const char* window_title, size_t width, | 106 GlxRenderer* GlxRenderer::Create(const char* window_title, size_t width, |
| 110 size_t height) { | 107 size_t height) { |
| 111 GlxRenderer* glx_renderer = new GlxRenderer(width, height); | 108 GlxRenderer* glx_renderer = new GlxRenderer(width, height); |
| 112 if (!glx_renderer->Init(window_title)) { | 109 if (!glx_renderer->Init(window_title)) { |
| 113 // TODO(pbos): Add GLX-failed warning here? | 110 // TODO(pbos): Add GLX-failed warning here? |
| 114 delete glx_renderer; | 111 delete glx_renderer; |
| 115 return NULL; | 112 return nullptr; |
| 116 } | 113 } |
| 117 return glx_renderer; | 114 return glx_renderer; |
| 118 } | 115 } |
| 119 | 116 |
| 120 void GlxRenderer::Resize(size_t width, size_t height) { | 117 void GlxRenderer::Resize(size_t width, size_t height) { |
| 121 width_ = width; | 118 width_ = width; |
| 122 height_ = height; | 119 height_ = height; |
| 123 if (!glXMakeCurrent(display_, window_, context_)) { | 120 if (!glXMakeCurrent(display_, window_, context_)) { |
| 124 abort(); | 121 abort(); |
| 125 } | 122 } |
| 126 GlRenderer::ResizeViewport(width_, height_); | 123 GlRenderer::ResizeViewport(width_, height_); |
| 127 if (!glXMakeCurrent(display_, None, NULL)) { | 124 if (!glXMakeCurrent(display_, None, nullptr)) { |
| 128 abort(); | 125 abort(); |
| 129 } | 126 } |
| 130 | 127 |
| 131 XSizeHints* size_hints = XAllocSizeHints(); | 128 XSizeHints* size_hints = XAllocSizeHints(); |
| 132 if (size_hints == NULL) { | 129 if (size_hints == nullptr) { |
| 133 abort(); | 130 abort(); |
| 134 } | 131 } |
| 135 size_hints->flags = PAspect; | 132 size_hints->flags = PAspect; |
| 136 size_hints->min_aspect.x = size_hints->max_aspect.x = width_; | 133 size_hints->min_aspect.x = size_hints->max_aspect.x = width_; |
| 137 size_hints->min_aspect.y = size_hints->max_aspect.y = height_; | 134 size_hints->min_aspect.y = size_hints->max_aspect.y = height_; |
| 138 XSetWMNormalHints(display_, window_, size_hints); | 135 XSetWMNormalHints(display_, window_, size_hints); |
| 139 XFree(size_hints); | 136 XFree(size_hints); |
| 140 | 137 |
| 141 XWindowChanges wc; | 138 XWindowChanges wc; |
| 142 wc.width = static_cast<int>(width); | 139 wc.width = static_cast<int>(width); |
| (...skipping 20 matching lines...) Expand all Loading... |
| 163 event.xconfigure.height); | 160 event.xconfigure.height); |
| 164 break; | 161 break; |
| 165 default: | 162 default: |
| 166 break; | 163 break; |
| 167 } | 164 } |
| 168 } | 165 } |
| 169 | 166 |
| 170 GlRenderer::OnFrame(frame); | 167 GlRenderer::OnFrame(frame); |
| 171 glXSwapBuffers(display_, window_); | 168 glXSwapBuffers(display_, window_); |
| 172 | 169 |
| 173 if (!glXMakeCurrent(display_, None, NULL)) { | 170 if (!glXMakeCurrent(display_, None, nullptr)) { |
| 174 abort(); | 171 abort(); |
| 175 } | 172 } |
| 176 } | 173 } |
| 177 } // test | 174 } // test |
| 178 } // webrtc | 175 } // webrtc |
| OLD | NEW |