Lingfeng Yang | 9872c79 | 2021-07-23 12:39:29 -0700 | [diff] [blame] | 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. |
Jason Macnak | ed0c9e6 | 2023-03-30 15:58:24 -0700 | [diff] [blame] | 14 | |
Andrew Woloszyn | d37d7c8 | 2023-03-30 18:08:32 +0000 | [diff] [blame] | 15 | #include <stdio.h> |
Jason Macnak | 5f93e1a | 2023-03-30 09:16:54 -0700 | [diff] [blame] | 16 | |
Jason Macnak | ed0c9e6 | 2023-03-30 15:58:24 -0700 | [diff] [blame] | 17 | #include "../apigen-codec-common/X11Support.h" |
| 18 | |
| 19 | namespace gfxstream { |
| 20 | |
Lingfeng Yang | 9872c79 | 2021-07-23 12:39:29 -0700 | [diff] [blame] | 21 | struct 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; |
| 36 | static X11State* x11() { |
| 37 | static X11State* res = new X11State; |
| 38 | return res; |
| 39 | } |
| 40 | |
| 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 | |
| 53 | void freeNativePixmap(void* pixmap) { XFreePixmap(x11()->display, (Pixmap)pixmap); } |
Jason Macnak | ed0c9e6 | 2023-03-30 15:58:24 -0700 | [diff] [blame] | 54 | |
| 55 | } // namespace gfxstream |