1f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org/* 2f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org * Copyright © 2011 Intel Corporation 3f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org * 4f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org * Permission is hereby granted, free of charge, to any person obtaining a 5f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org * copy of this software and associated documentation files (the "Software"), 6f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org * to deal in the Software without restriction, including without limitation 7f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org * the rights to use, copy, modify, merge, publish, distribute, sublicense, 8f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org * and/or sell copies of the Software, and to permit persons to whom the 9f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org * Software is furnished to do so, subject to the following conditions: 10f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org * 11f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org * The above copyright notice and this permission notice (including the next 12f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org * paragraph) shall be included in all copies or substantial portions of the 13f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org * Software. 14f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org * 15f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL 18f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 20f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER 21f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org * DEALINGS IN THE SOFTWARE. 22f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org */ 23f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.orgextern "C" { 24f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org#include "glxclient.h" 25f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org}; 26f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org 27f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.orgclass fake_glx_screen : public glx_screen { 28f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.orgpublic: 29f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org fake_glx_screen(struct glx_display *glx_dpy, int num, const char *ext) 30f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org { 31f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org this->vtable = &fake_glx_screen::vt; 32f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org this->serverGLXexts = 0; 33f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org this->effectiveGLXexts = 0; 34f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org this->display = 0; 35f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org this->dpy = 0; 36f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org this->scr = num; 37f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org this->visuals = 0; 38f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org this->configs = 0; 39f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org 40f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org this->display = glx_dpy; 41f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org this->dpy = (glx_dpy != NULL) ? glx_dpy->dpy : NULL; 42f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org 43f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org this->serverGLXexts = new char[strlen(ext) + 1]; 44f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org strcpy((char *) this->serverGLXexts, ext); 45f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org } 46f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org 47f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org ~fake_glx_screen() 48f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org { 49f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org delete [] this->serverGLXexts; 50f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org } 51f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org 52f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.orgprivate: 53f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org static struct glx_screen_vtable vt; 54f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org}; 55f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org 56f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.orgclass fake_glx_screen_direct : public fake_glx_screen { 57f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.orgpublic: 58f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org fake_glx_screen_direct(struct glx_display *glx_dpy, int num, 59f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org const char *ext) 60f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org : fake_glx_screen(glx_dpy, num, ext) 61f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org { 62f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org this->vtable = &fake_glx_screen_direct::vt; 63f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org } 64f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org 65f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.orgprivate: 66f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org static struct glx_screen_vtable vt; 67f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org}; 68f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org 69f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.orgclass fake_glx_context : public glx_context { 70f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.orgpublic: 71f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org fake_glx_context(struct glx_screen *psc, struct glx_config *mode) 72f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org { 73f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org contexts_allocated++; 74f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org 75f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org this->vtable = &fake_glx_context::vt; 76f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org this->majorOpcode = 123; 77f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org this->screen = psc->scr; 78f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org this->psc = psc; 79f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org this->config = mode; 80f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org this->isDirect = false; 81f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org this->currentContextTag = -1; 82f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org 83f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org this->client_state_private = (struct __GLXattributeRec *) 0xcafebabe; 84f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org } 85f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org 86f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org ~fake_glx_context() 87f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org { 88f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org contexts_allocated--; 89f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org } 90f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org 91f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org static glx_context *create_attribs(struct glx_screen *psc, 92f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org struct glx_config *mode, 93f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org struct glx_context *shareList, 94f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org unsigned num_attribs, 95f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org const uint32_t *attribs, 96f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org unsigned *error) 97f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org { 98f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org (void) shareList; 99f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org (void) num_attribs; 100f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org (void) attribs; 101f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org 102f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org *error = 0; 103f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org return new fake_glx_context(psc, mode); 104f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org } 105f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org 106f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org /** Number of context that are allocated (and not freed). */ 107f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org static int contexts_allocated; 108f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org 109f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.orgprivate: 110f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org static const struct glx_context_vtable vt; 111f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org 112f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org static void destroy(struct glx_context *gc) 113f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org { 114f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org delete gc; 115f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org } 116f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org}; 117f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org 118f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.orgclass fake_glx_context_direct : public fake_glx_context { 119f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.orgpublic: 120f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org fake_glx_context_direct(struct glx_screen *psc, struct glx_config *mode) 121f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org : fake_glx_context(psc, mode) 122f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org { 123f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org this->isDirect = True; 124f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org } 125f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org 126f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org static glx_context *create(struct glx_screen *psc, struct glx_config *mode, 127f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org struct glx_context *shareList, int renderType) 128f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org { 129f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org (void) shareList; 130f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org (void) renderType; 131f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org 132f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org return new fake_glx_context_direct(psc, mode); 133f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org } 134f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org 135f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org static glx_context *create_attribs(struct glx_screen *psc, 136f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org struct glx_config *mode, 137f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org struct glx_context *shareList, 138f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org unsigned num_attribs, 139f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org const uint32_t *attribs, 140f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org unsigned *error) 141f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org { 142f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org (void) shareList; 143f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org (void) num_attribs; 144f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org (void) attribs; 145f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org 146f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org *error = 0; 147f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org return new fake_glx_context_direct(psc, mode); 148f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org } 149f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org}; 150