Path: blob/21.2-virgl/src/glx/apple/apple_xgl_api_read.c
4560 views
/*1Copyright (c) 2008-2011 Apple Inc.23Permission is hereby granted, free of charge, to any person4obtaining a copy of this software and associated documentation files5(the "Software"), to deal in the Software without restriction,6including without limitation the rights to use, copy, modify, merge,7publish, distribute, sublicense, and/or sell copies of the Software,8and to permit persons to whom the Software is furnished to do so,9subject to the following conditions:1011The above copyright notice and this permission notice shall be12included in all copies or substantial portions of the Software.1314THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,15EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF16MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND17NONINFRINGEMENT. IN NO EVENT SHALL THE ABOVE LISTED COPYRIGHT18HOLDER(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,19WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,20OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER21DEALINGS IN THE SOFTWARE.2223Except as contained in this notice, the name(s) of the above24copyright holders shall not be used in advertising or otherwise to25promote the sale, use or other dealings in this Software without26prior written authorization.27*/2829/*30* This file works with the glXMakeContextCurrent readable drawable.31*32* The way it works is by swapping the currentDrawable for the currentReadable33* drawable if they are different.34*/35#include <stdbool.h>36#include "glxclient.h"37#include "apple_glx_context.h"38#include "apple_xgl_api.h"39#include "main/glheader.h"40#include "glapitable.h"4142extern struct _glapi_table * __ogl_framework_api;4344struct apple_xgl_saved_state45{46bool swapped;47};4849static void50SetRead(struct apple_xgl_saved_state *saved)51{52struct glx_context *gc = __glXGetCurrentContext();5354/*55* By default indicate that the state was not swapped, so that UnsetRead56* functions correctly.57*/58saved->swapped = false;5960/*61* If the readable drawable isn't the same as the drawable then62* the user has requested a readable drawable with glXMakeContextCurrent().63* We emulate this behavior by switching the current drawable.64*/65if (None != gc->currentReadable66&& gc->currentReadable != gc->currentDrawable) {67Display *dpy = glXGetCurrentDisplay();6869saved->swapped = true;7071if (apple_glx_make_current_context(dpy, gc->driContext, gc->driContext,72gc->currentReadable)) {73/* An error occurred, so try to restore the old context state. */74(void) apple_glx_make_current_context(dpy, gc->driContext, gc->driContext,75gc->currentDrawable);76saved->swapped = false;77}78}79}8081static void82UnsetRead(struct apple_xgl_saved_state *saved)83{84if (saved->swapped) {85struct glx_context *gc = __glXGetCurrentContext();86Display *dpy = glXGetCurrentDisplay();8788if (apple_glx_make_current_context(dpy, gc->driContext, gc->driContext,89gc->currentDrawable)) {90/*91* An error occurred restoring the drawable.92* It's unclear what to do about that.93*/94}95}96}9798void99__applegl_glReadPixels(GLint x, GLint y, GLsizei width, GLsizei height,100GLenum format, GLenum type, void *pixels)101{102struct apple_xgl_saved_state saved;103104SetRead(&saved);105106__ogl_framework_api->ReadPixels(x, y, width, height, format, type, pixels);107108UnsetRead(&saved);109}110111void112__applegl_glCopyPixels(GLint x, GLint y, GLsizei width, GLsizei height, GLenum type)113{114struct apple_xgl_saved_state saved;115116SetRead(&saved);117118__ogl_framework_api->CopyPixels(x, y, width, height, type);119120UnsetRead(&saved);121}122123void124__applegl_glCopyColorTable(GLenum target, GLenum internalformat, GLint x, GLint y,125GLsizei width)126{127struct apple_xgl_saved_state saved;128129SetRead(&saved);130131__ogl_framework_api->CopyColorTable(target, internalformat, x, y, width);132133UnsetRead(&saved);134}135136137