blob: 22905f82af0b9ed806b86ba546f7463e2d507a23 [file] [log] [blame]
Lingfeng Yang9872c792021-07-23 12:39:29 -07001// 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.
Jason Macnaked0c9e62023-03-30 15:58:24 -070014
Andrew Woloszynd37d7c82023-03-30 18:08:32 +000015#include <stdio.h>
Jason Macnak5f93e1a2023-03-30 09:16:54 -070016
Jason Macnaked0c9e62023-03-30 15:58:24 -070017#include "../apigen-codec-common/X11Support.h"
18
19namespace gfxstream {
20
Lingfeng Yang9872c792021-07-23 12:39:29 -070021struct X11State {
22 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;
36static X11State* x11() {
37 static X11State* res = new X11State;
38 return res;
39}
40
41void* 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
53void freeNativePixmap(void* pixmap) { XFreePixmap(x11()->display, (Pixmap)pixmap); }
Jason Macnaked0c9e62023-03-30 15:58:24 -070054
55} // namespace gfxstream