1 //
2 // Copyright 2015 The ANGLE Project Authors. All rights reserved.
3 // Use of this source code is governed by a BSD-style license that can be
4 // found in the LICENSE file.
5 //
6
7 // X11Pixmap.cpp: Implementation of OSPixmap for X11
8
9 #include "util/x11/X11Pixmap.h"
10
X11Pixmap()11 X11Pixmap::X11Pixmap() : mPixmap(0), mDisplay(nullptr) {}
12
~X11Pixmap()13 X11Pixmap::~X11Pixmap()
14 {
15 if (mPixmap)
16 {
17 XFreePixmap(mDisplay, mPixmap);
18 }
19 }
20
initialize(EGLNativeDisplayType display,size_t width,size_t height,int nativeVisual)21 bool X11Pixmap::initialize(EGLNativeDisplayType display,
22 size_t width,
23 size_t height,
24 int nativeVisual)
25 {
26 mDisplay = reinterpret_cast<Display *>(display);
27
28 int screen = DefaultScreen(mDisplay);
29 Window root = RootWindow(mDisplay, screen);
30 int depth = 0;
31
32 XVisualInfo visualTemplate;
33 visualTemplate.visualid = nativeVisual;
34
35 int numVisuals = 0;
36 XVisualInfo *info = XGetVisualInfo(mDisplay, VisualIDMask, &visualTemplate, &numVisuals);
37 if (numVisuals == 1)
38 {
39 depth = info->depth;
40 }
41 XFree(info);
42
43 mPixmap = XCreatePixmap(mDisplay, root, static_cast<unsigned int>(width),
44 static_cast<unsigned int>(height), depth);
45
46 return mPixmap != 0;
47 }
48
getNativePixmap() const49 EGLNativePixmapType X11Pixmap::getNativePixmap() const
50 {
51 return mPixmap;
52 }
53
CreateOSPixmap()54 OSPixmap *CreateOSPixmap()
55 {
56 return new X11Pixmap();
57 }
58