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