• 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 
15 #include <stdio.h>
16 
17 #include "../apigen-codec-common/X11Support.h"
18 
19 namespace gfxstream {
20 
21 struct X11State {
X11Stategfxstream::X11State22     X11State() :
23         threadsInitResult(XInitThreads()),
24         display(XOpenDisplay(NULL)),
25         window(DefaultRootWindow(display)) {
26         fprintf(stderr, "%s: Are we testing x11? Just initialized x11 "
27                 "with threads init status %u display %p window %p\n",
28                 __func__, threadsInitResult, display, (void*)window);
29     }
30     Status threadsInitResult;
31     Display* display;
32     Window window;
33 };
34 
35 // static X11State sX11State;
x11()36 static X11State* x11() {
37     static X11State* res = new X11State;
38     return res;
39 }
40 
createNativePixmap(int width,int height,int bytesPerPixel)41 void* createNativePixmap(int width, int height, int bytesPerPixel) {
42     auto x = x11();
43 
44     auto res = XCreatePixmap(x->display, x->window, width, height, bytesPerPixel * 8);
45     if (!res) {
46         fprintf(stderr, "%s: Failed to create pixmap.\n", __func__);
47     }
48 
49     XFlush(x->display);
50     return (void*)res;
51 }
52 
freeNativePixmap(void * pixmap)53 void freeNativePixmap(void* pixmap) { XFreePixmap(x11()->display, (Pixmap)pixmap); }
54 
55 }  // namespace gfxstream