• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 // Copyright (C) 2021 The Android Open Source Project
2 //
3 // Licensed under the Apache License, Version 2.0 (the "License");
4 // you may not use this file except in compliance with the License.
5 // You may obtain a copy of the License at
6 //
7 // http://www.apache.org/licenses/LICENSE-2.0
8 //
9 // Unless required by applicable law or agreed to in writing, software
10 // distributed under the License is distributed on an "AS IS" BASIS,
11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 // See the License for the specific language governing permissions and
13 // limitations under the License.
14 #include "../apigen-codec-common/X11Support.h"
15 #include <stdio.h>
16 
17 struct X11State {
X11StateX11State18     X11State() :
19         threadsInitResult(XInitThreads()),
20         display(XOpenDisplay(NULL)),
21         window(DefaultRootWindow(display)) {
22         fprintf(stderr, "%s: Are we testing x11? Just initialized x11 "
23                 "with threads init status %u display %p window %p\n",
24                 __func__, threadsInitResult, display, (void*)window);
25     }
26     Status threadsInitResult;
27     Display* display;
28     Window window;
29 };
30 
31 // static X11State sX11State;
x11()32 static X11State* x11() {
33     static X11State* res = new X11State;
34     return res;
35 }
36 
createNativePixmap(int width,int height,int bytesPerPixel)37 void* createNativePixmap(int width, int height, int bytesPerPixel) {
38     auto x = x11();
39 
40     auto res = XCreatePixmap(x->display, x->window, width, height, bytesPerPixel * 8);
41     if (!res) {
42         fprintf(stderr, "%s: Failed to create pixmap.\n", __func__);
43     }
44 
45     XFlush(x->display);
46     return (void*)res;
47 }
48 
freeNativePixmap(void * pixmap)49 void freeNativePixmap(void* pixmap) { XFreePixmap(x11()->display, (Pixmap)pixmap); }
50