Store the native display as an opaque pointer. Bug 18314459 Change-Id: I63e56d626bd1838803d1de71b417b7e40242c5e9 Reviewed-on: https://swiftshader-review.googlesource.com/4390 Reviewed-by: Nicolas Capens <capn@google.com> Tested-by: Nicolas Capens <capn@google.com>
diff --git a/src/Main/FrameBufferAndroid.hpp b/src/Main/FrameBufferAndroid.hpp index 7e7acde..359cea9 100644 --- a/src/Main/FrameBufferAndroid.hpp +++ b/src/Main/FrameBufferAndroid.hpp
@@ -16,10 +16,10 @@ ~FrameBufferAndroid(); - void flip(void *source, Format sourceFormat, size_t sourceStride) override {blit(source, 0, 0, sourceFormat, sourceStride);}; - void blit(void *source, const Rect *sourceRect, const Rect *destRect, Format sourceFormat, size_t sourceStride) override; - - void *lock() override; + void flip(void *source, Format sourceFormat, size_t sourceStride) override {blit(source, 0, 0, sourceFormat, sourceStride);}; + void blit(void *source, const Rect *sourceRect, const Rect *destRect, Format sourceFormat, size_t sourceStride) override; + + void *lock() override; void unlock() override; bool setSwapRectangle(int l, int t, int w, int h);
diff --git a/src/Main/FrameBufferWin.cpp b/src/Main/FrameBufferWin.cpp index 8765171..860a424 100644 --- a/src/Main/FrameBufferWin.cpp +++ b/src/Main/FrameBufferWin.cpp
@@ -69,7 +69,7 @@ return 0; } -sw::FrameBuffer *createFrameBuffer(HDC display, HWND window, int width, int height) +sw::FrameBuffer *createFrameBuffer(void *display, HWND window, int width, int height) { return createFrameBufferWin(window, width, height, false, false); }
diff --git a/src/Main/FrameBufferX11.cpp b/src/Main/FrameBufferX11.cpp index 245805f..e079e8c 100644 --- a/src/Main/FrameBufferX11.cpp +++ b/src/Main/FrameBufferX11.cpp
@@ -1,150 +1,150 @@ -// SwiftShader Software Renderer -// -// Copyright(c) 2005-2012 TransGaming Inc. -// -// All rights reserved. No part of this software may be copied, distributed, transmitted, -// transcribed, stored in a retrieval system, translated into any human or computer -// language by any means, or disclosed to third parties without the explicit written -// agreement of TransGaming Inc. Without such an agreement, no rights or licenses, express -// or implied, including but not limited to any patent rights, are granted to you. -// - -// Surface.cpp: Implements the egl::Surface class, representing a drawing surface -// such as the client area of a window, including any back buffers. -// Implements EGLSurface and related functionality. [EGL 1.4] section 2.2 page 3. - -#include "FrameBufferX11.hpp" - -#include "libX11.hpp" - -#include <sys/ipc.h> -#include <sys/shm.h> -#include <string.h> -#include <assert.h> - -namespace sw -{ - static int (*PreviousXErrorHandler)(Display *display, XErrorEvent *event) = 0; - static bool shmBadAccess = false; - - // Catches BadAcces errors so we can fall back to not using MIT-SHM - static int XShmErrorHandler(Display *display, XErrorEvent *event) - { - if(event->error_code == BadAccess) - { - shmBadAccess = true; - return 0; - } - else - { - return PreviousXErrorHandler(display, event); - } - } - - FrameBufferX11::FrameBufferX11(Display *display, Window window, int width, int height) : FrameBuffer(width, height, false, false), ownX11(!display), x_display(display), x_window(window) - { - if(!x_display) - { - x_display = libX11->XOpenDisplay(0); - } - - int screen = DefaultScreen(x_display); - x_gc = libX11->XDefaultGC(x_display, screen); - int depth = libX11->XDefaultDepth(x_display, screen); - - Status status = libX11->XMatchVisualInfo(x_display, screen, 32, TrueColor, &x_visual); - bool match = (status != 0 && x_visual.blue_mask == 0xFF); // Prefer X8R8G8B8 - Visual *visual = match ? x_visual.visual : libX11->XDefaultVisual(x_display, screen); - - mit_shm = (libX11->XShmQueryExtension && libX11->XShmQueryExtension(x_display) == True); - - if(mit_shm) - { - x_image = libX11->XShmCreateImage(x_display, visual, depth, ZPixmap, 0, &shminfo, width, height); - - shminfo.shmid = shmget(IPC_PRIVATE, x_image->bytes_per_line * x_image->height, IPC_CREAT | SHM_R | SHM_W); - shminfo.shmaddr = x_image->data = buffer = (char*)shmat(shminfo.shmid, 0, 0); - shminfo.readOnly = False; - - PreviousXErrorHandler = libX11->XSetErrorHandler(XShmErrorHandler); - libX11->XShmAttach(x_display, &shminfo); // May produce a BadAccess error - libX11->XSync(x_display, False); - libX11->XSetErrorHandler(PreviousXErrorHandler); - - if(shmBadAccess) - { - mit_shm = false; - - XDestroyImage(x_image); - shmdt(shminfo.shmaddr); - shmctl(shminfo.shmid, IPC_RMID, 0); - - shmBadAccess = false; - } - } - - if(!mit_shm) - { - buffer = new char[width * height * 4]; - x_image = libX11->XCreateImage(x_display, visual, depth, ZPixmap, 0, buffer, width, height, 32, width * 4); - } - } - - FrameBufferX11::~FrameBufferX11() - { - if(!mit_shm) - { - x_image->data = 0; - XDestroyImage(x_image); - - delete[] buffer; - buffer = 0; - } - else - { - libX11->XShmDetach(x_display, &shminfo); - XDestroyImage(x_image); - shmdt(shminfo.shmaddr); - shmctl(shminfo.shmid, IPC_RMID, 0); - } - - if(ownX11) - { - libX11->XCloseDisplay(x_display); - } - } - - void *FrameBufferX11::lock() - { - stride = x_image->bytes_per_line; - locked = buffer; - - return locked; - } - - void FrameBufferX11::unlock() - { - locked = 0; - } - - void FrameBufferX11::blit(void *source, const Rect *sourceRect, const Rect *destRect, Format sourceFormat, size_t sourceStride) - { - copy(source, sourceFormat, sourceStride); - - if(!mit_shm) - { - libX11->XPutImage(x_display, x_window, x_gc, x_image, 0, 0, 0, 0, width, height); - } - else - { - libX11->XShmPutImage(x_display, x_window, x_gc, x_image, 0, 0, 0, 0, width, height, False); - } - - libX11->XSync(x_display, False); - } -} - -sw::FrameBuffer *createFrameBuffer(Display *display, Window window, int width, int height) -{ - return new sw::FrameBufferX11(display, window, width, height); -} +// SwiftShader Software Renderer +// +// Copyright(c) 2005-2012 TransGaming Inc. +// +// All rights reserved. No part of this software may be copied, distributed, transmitted, +// transcribed, stored in a retrieval system, translated into any human or computer +// language by any means, or disclosed to third parties without the explicit written +// agreement of TransGaming Inc. Without such an agreement, no rights or licenses, express +// or implied, including but not limited to any patent rights, are granted to you. +// + +// Surface.cpp: Implements the egl::Surface class, representing a drawing surface +// such as the client area of a window, including any back buffers. +// Implements EGLSurface and related functionality. [EGL 1.4] section 2.2 page 3. + +#include "FrameBufferX11.hpp" + +#include "libX11.hpp" + +#include <sys/ipc.h> +#include <sys/shm.h> +#include <string.h> +#include <assert.h> + +namespace sw +{ + static int (*PreviousXErrorHandler)(Display *display, XErrorEvent *event) = 0; + static bool shmBadAccess = false; + + // Catches BadAcces errors so we can fall back to not using MIT-SHM + static int XShmErrorHandler(Display *display, XErrorEvent *event) + { + if(event->error_code == BadAccess) + { + shmBadAccess = true; + return 0; + } + else + { + return PreviousXErrorHandler(display, event); + } + } + + FrameBufferX11::FrameBufferX11(Display *display, Window window, int width, int height) : FrameBuffer(width, height, false, false), ownX11(!display), x_display(display), x_window(window) + { + if(!x_display) + { + x_display = libX11->XOpenDisplay(0); + } + + int screen = DefaultScreen(x_display); + x_gc = libX11->XDefaultGC(x_display, screen); + int depth = libX11->XDefaultDepth(x_display, screen); + + Status status = libX11->XMatchVisualInfo(x_display, screen, 32, TrueColor, &x_visual); + bool match = (status != 0 && x_visual.blue_mask == 0xFF); // Prefer X8R8G8B8 + Visual *visual = match ? x_visual.visual : libX11->XDefaultVisual(x_display, screen); + + mit_shm = (libX11->XShmQueryExtension && libX11->XShmQueryExtension(x_display) == True); + + if(mit_shm) + { + x_image = libX11->XShmCreateImage(x_display, visual, depth, ZPixmap, 0, &shminfo, width, height); + + shminfo.shmid = shmget(IPC_PRIVATE, x_image->bytes_per_line * x_image->height, IPC_CREAT | SHM_R | SHM_W); + shminfo.shmaddr = x_image->data = buffer = (char*)shmat(shminfo.shmid, 0, 0); + shminfo.readOnly = False; + + PreviousXErrorHandler = libX11->XSetErrorHandler(XShmErrorHandler); + libX11->XShmAttach(x_display, &shminfo); // May produce a BadAccess error + libX11->XSync(x_display, False); + libX11->XSetErrorHandler(PreviousXErrorHandler); + + if(shmBadAccess) + { + mit_shm = false; + + XDestroyImage(x_image); + shmdt(shminfo.shmaddr); + shmctl(shminfo.shmid, IPC_RMID, 0); + + shmBadAccess = false; + } + } + + if(!mit_shm) + { + buffer = new char[width * height * 4]; + x_image = libX11->XCreateImage(x_display, visual, depth, ZPixmap, 0, buffer, width, height, 32, width * 4); + } + } + + FrameBufferX11::~FrameBufferX11() + { + if(!mit_shm) + { + x_image->data = 0; + XDestroyImage(x_image); + + delete[] buffer; + buffer = 0; + } + else + { + libX11->XShmDetach(x_display, &shminfo); + XDestroyImage(x_image); + shmdt(shminfo.shmaddr); + shmctl(shminfo.shmid, IPC_RMID, 0); + } + + if(ownX11) + { + libX11->XCloseDisplay(x_display); + } + } + + void *FrameBufferX11::lock() + { + stride = x_image->bytes_per_line; + locked = buffer; + + return locked; + } + + void FrameBufferX11::unlock() + { + locked = 0; + } + + void FrameBufferX11::blit(void *source, const Rect *sourceRect, const Rect *destRect, Format sourceFormat, size_t sourceStride) + { + copy(source, sourceFormat, sourceStride); + + if(!mit_shm) + { + libX11->XPutImage(x_display, x_window, x_gc, x_image, 0, 0, 0, 0, width, height); + } + else + { + libX11->XShmPutImage(x_display, x_window, x_gc, x_image, 0, 0, 0, 0, width, height, False); + } + + libX11->XSync(x_display, False); + } +} + +sw::FrameBuffer *createFrameBuffer(void *display, Window window, int width, int height) +{ + return new sw::FrameBufferX11((::Display*)display, window, width, height); +}
diff --git a/src/Main/FrameBufferX11.hpp b/src/Main/FrameBufferX11.hpp index c5e8b53..0473553 100644 --- a/src/Main/FrameBufferX11.hpp +++ b/src/Main/FrameBufferX11.hpp
@@ -1,56 +1,56 @@ -// SwiftShader Software Renderer -// -// Copyright(c) 2005-2012 TransGaming Inc. -// -// All rights reserved. No part of this software may be copied, distributed, transmitted, -// transcribed, stored in a retrieval system, translated into any human or computer -// language by any means, or disclosed to third parties without the explicit written -// agreement of TransGaming Inc. Without such an agreement, no rights or licenses, express -// or implied, including but not limited to any patent rights, are granted to you. -// - -// Surface.cpp: Implements the egl::Surface class, representing a drawing surface -// such as the client area of a window, including any back buffers. -// Implements EGLSurface and related functionality. [EGL 1.4] section 2.2 page 3. - -#ifndef sw_FrameBufferX11_hpp -#define sw_FrameBufferX11_hpp - -#include "Main/FrameBuffer.hpp" -#include "Common/Debug.hpp" - -#include <X11/Xlib.h> -#include <X11/Xutil.h> -#include <X11/extensions/XShm.h> - -namespace sw -{ - class FrameBufferX11 : public FrameBuffer - { - public: - FrameBufferX11(Display *display, Window window, int width, int height); - - ~FrameBufferX11(); - - void flip(void *source, Format sourceFormat, size_t sourceStride) override {blit(source, 0, 0, sourceFormat, sourceStride);}; - void blit(void *source, const Rect *sourceRect, const Rect *destRect, Format sourceFormat, size_t sourceStride) override; - - void *lock() override; - void unlock() override; - - private: - bool ownX11; - Display *x_display; - Window x_window; - XImage *x_image; +// SwiftShader Software Renderer +// +// Copyright(c) 2005-2012 TransGaming Inc. +// +// All rights reserved. No part of this software may be copied, distributed, transmitted, +// transcribed, stored in a retrieval system, translated into any human or computer +// language by any means, or disclosed to third parties without the explicit written +// agreement of TransGaming Inc. Without such an agreement, no rights or licenses, express +// or implied, including but not limited to any patent rights, are granted to you. +// + +// Surface.cpp: Implements the egl::Surface class, representing a drawing surface +// such as the client area of a window, including any back buffers. +// Implements EGLSurface and related functionality. [EGL 1.4] section 2.2 page 3. + +#ifndef sw_FrameBufferX11_hpp +#define sw_FrameBufferX11_hpp + +#include "Main/FrameBuffer.hpp" +#include "Common/Debug.hpp" + +#include <X11/Xlib.h> +#include <X11/Xutil.h> +#include <X11/extensions/XShm.h> + +namespace sw +{ + class FrameBufferX11 : public FrameBuffer + { + public: + FrameBufferX11(Display *display, Window window, int width, int height); + + ~FrameBufferX11(); + + void flip(void *source, Format sourceFormat, size_t sourceStride) override {blit(source, 0, 0, sourceFormat, sourceStride);}; + void blit(void *source, const Rect *sourceRect, const Rect *destRect, Format sourceFormat, size_t sourceStride) override; + + void *lock() override; + void unlock() override; + + private: + bool ownX11; + Display *x_display; + Window x_window; + XImage *x_image; GC x_gc; - XVisualInfo x_visual; - - bool mit_shm; - XShmSegmentInfo shminfo; - - char *buffer; - }; -} - -#endif // sw_FrameBufferX11_hpp + XVisualInfo x_visual; + + bool mit_shm; + XShmSegmentInfo shminfo; + + char *buffer; + }; +} + +#endif // sw_FrameBufferX11_hpp
diff --git a/src/OpenGL/libEGL/Display.cpp b/src/OpenGL/libEGL/Display.cpp index 8715d95..4ec679b 100644 --- a/src/OpenGL/libEGL/Display.cpp +++ b/src/OpenGL/libEGL/Display.cpp
@@ -38,23 +38,11 @@ namespace egl { -typedef std::map<EGLNativeDisplayType, Display*> DisplayMap; -// Protects the global displays map. -sw::BackoffLock displays_lock; - -// The order of construction of globals is undefined in C++. -// This function ensures that construction has completed before we attempt -// to access displays. -DisplayMap* getDisplays() { - static DisplayMap displays; - return &displays; -} - -egl::Display *Display::getPlatformDisplay(EGLenum platform, EGLNativeDisplayType displayId) +egl::Display *Display::getPlatformDisplay(EGLenum platform, void *nativeDisplay) { #ifndef __ANDROID__ - if(platform == EGL_UNKNOWN) // Default + if(platform == EGL_UNKNOWN) // Default platform { #if defined(__unix__) if(libX11) @@ -68,14 +56,14 @@ #endif } - if(displayId == EGL_DEFAULT_DISPLAY) + if(!nativeDisplay) // Default display { if(platform == EGL_PLATFORM_X11_EXT) { #if defined(__unix__) if(libX11->XOpenDisplay) { - displayId = libX11->XOpenDisplay(NULL); + nativeDisplay = libX11->XOpenDisplay(NULL); } else { @@ -88,26 +76,29 @@ } else { - // FIXME: Check if displayId is a valid display device context for <platform> + // FIXME: Check if nativeDisplay is a valid display device context for <platform> } #endif - egl::Display *rval; - displays_lock.lock(); - DisplayMap* displays = getDisplays(); - if (displays->find(displayId) != displays->end()) - { - rval = (*displays)[displayId]; - } else { - rval = new egl::Display(platform, displayId); + static std::map<void*, Display*> displays; + static sw::BackoffLock displaysMutex; - (*displays)[displayId] = rval; + displaysMutex.lock(); + + egl::Display *display = displays[nativeDisplay]; + + if(!display) + { + display = new egl::Display(platform, nativeDisplay); + displays[nativeDisplay] = display; } - displays_lock.unlock(); - return rval; + + displaysMutex.unlock(); + + return display; } -Display::Display(EGLenum platform, EGLNativeDisplayType displayId) : platform(platform), displayId(displayId) +Display::Display(EGLenum platform, void *nativeDisplay) : platform(platform), nativeDisplay(nativeDisplay) { mMinSwapInterval = 1; mMaxSwapInterval = 1; @@ -116,10 +107,6 @@ Display::~Display() { terminate(); - - displays_lock.lock(); - getDisplays()->erase(displayId); - displays_lock.unlock(); } static void cpuid(int registers[4], int info) @@ -561,7 +548,7 @@ if(platform == EGL_PLATFORM_X11_EXT) { XWindowAttributes windowAttributes; - Status status = libX11->XGetWindowAttributes(displayId, window, &windowAttributes); + Status status = libX11->XGetWindowAttributes((::Display*)nativeDisplay, window, &windowAttributes); return status == True; } @@ -596,9 +583,9 @@ return mMaxSwapInterval; } -EGLNativeDisplayType Display::getNativeDisplay() const +void *Display::getNativeDisplay() const { - return displayId; + return nativeDisplay; } sw::Format Display::getDisplayFormat() const @@ -680,7 +667,7 @@ #else if(platform == EGL_PLATFORM_X11_EXT) { - Screen *screen = libX11->XDefaultScreenOfDisplay(displayId); + Screen *screen = libX11->XDefaultScreenOfDisplay((::Display*)nativeDisplay); unsigned int bpp = libX11->XPlanesOfScreen(screen); switch(bpp)
diff --git a/src/OpenGL/libEGL/Display.h b/src/OpenGL/libEGL/Display.h index 76e856f..da1b442 100644 --- a/src/OpenGL/libEGL/Display.h +++ b/src/OpenGL/libEGL/Display.h
@@ -28,9 +28,7 @@ class Display { public: - ~Display(); - - static egl::Display *getPlatformDisplay(EGLenum platform, EGLNativeDisplayType displayId); + static egl::Display *getPlatformDisplay(EGLenum platform, void *nativeDisplay); bool initialize(); void terminate(); @@ -55,20 +53,21 @@ EGLint getMinSwapInterval() const; EGLint getMaxSwapInterval() const; - EGLNativeDisplayType getNativeDisplay() const; + void *getNativeDisplay() const; const char *getExtensionString() const; private: - Display(EGLenum platform, EGLNativeDisplayType displayId); + Display(EGLenum platform, void *nativeDisplay); + ~Display(); sw::Format getDisplayFormat() const; const EGLenum platform; - const EGLNativeDisplayType displayId; + void *const nativeDisplay; EGLint mMaxSwapInterval; EGLint mMinSwapInterval; - + typedef std::set<Surface*> SurfaceSet; SurfaceSet mSurfaceSet;
diff --git a/src/OpenGL/libEGL/Surface.cpp b/src/OpenGL/libEGL/Surface.cpp index 3db1db2..538d010 100644 --- a/src/OpenGL/libEGL/Surface.cpp +++ b/src/OpenGL/libEGL/Surface.cpp
@@ -246,7 +246,7 @@ return reset(width, height); #else XWindowAttributes windowAttributes; - libX11->XGetWindowAttributes(display->getNativeDisplay(), window, &windowAttributes); + libX11->XGetWindowAttributes((::Display*)display->getNativeDisplay(), window, &windowAttributes); return reset(windowAttributes.width, windowAttributes.height); #endif @@ -286,7 +286,7 @@ int clientHeight; window->query(window, NATIVE_WINDOW_HEIGHT, &clientHeight); #else XWindowAttributes windowAttributes; - libX11->XGetWindowAttributes(display->getNativeDisplay(), window, &windowAttributes); + libX11->XGetWindowAttributes((::Display*)display->getNativeDisplay(), window, &windowAttributes); int clientWidth = windowAttributes.width; int clientHeight = windowAttributes.height;
diff --git a/src/OpenGL/libEGL/libEGL.cpp b/src/OpenGL/libEGL/libEGL.cpp index 1aff963..21065c4 100644 --- a/src/OpenGL/libEGL/libEGL.cpp +++ b/src/OpenGL/libEGL/libEGL.cpp
@@ -108,7 +108,14 @@ { TRACE("(EGLNativeDisplayType display_id = %p)", display_id); - return egl::Display::getPlatformDisplay(EGL_UNKNOWN, display_id); + if(display_id == EGL_DEFAULT_DISPLAY) + { + return egl::Display::getPlatformDisplay(EGL_UNKNOWN, nullptr); + } + else + { + return egl::Display::getPlatformDisplay(EGL_UNKNOWN, reinterpret_cast<void*>((uintptr_t)display_id)); + } } EGLBoolean Initialize(EGLDisplay dpy, EGLint *major, EGLint *minor) @@ -948,7 +955,7 @@ { TRACE("(EGLenum platform = 0x%X, void *native_display = %p, const EGLint *attrib_list = %p)", platform, native_display, attrib_list); - return egl::Display::getPlatformDisplay(platform, (EGLNativeDisplayType)native_display); + return egl::Display::getPlatformDisplay(platform, native_display); } EGLSurface CreatePlatformWindowSurfaceEXT(EGLDisplay dpy, EGLConfig config, void *native_window, const EGLint *attrib_list)
diff --git a/src/OpenGL/libGL/main.h b/src/OpenGL/libGL/main.h index 28d5802..6b86940 100644 --- a/src/OpenGL/libGL/main.h +++ b/src/OpenGL/libGL/main.h
@@ -1,71 +1,71 @@ -// SwiftShader Software Renderer -// -// Copyright(c) 2005-2012 TransGaming Inc. -// -// All rights reserved. No part of this software may be copied, distributed, transmitted, -// transcribed, stored in a retrieval system, translated into any human or computer -// language by any means, or disclosed to third parties without the explicit written -// agreement of TransGaming Inc. Without such an agreement, no rights or licenses, express -// or implied, including but not limited to any patent rights, are granted to you. -// - -// main.h: Management of thread-local data. - -#ifndef LIBGL_MAIN_H_ -#define LIBGL_MAIN_H_ - -#include "Context.h" -#include "Device.hpp" -#include "common/debug.h" -#include "Display.h" - -#define _GDI32_ -#include <windows.h> -#include <GL/GL.h> -#include <GL/glext.h> - -namespace gl -{ - struct Current - { - Context *context; - Display *display; - Surface *drawSurface; - Surface *readSurface; - }; - - void makeCurrent(Context *context, Display *display, Surface *surface); - - Context *getContext(); - Display *getDisplay(); - Device *getDevice(); - Surface *getCurrentDrawSurface(); - Surface *getCurrentReadSurface(); - - void setCurrentDisplay(Display *dpy); - void setCurrentContext(gl::Context *ctx); - void setCurrentDrawSurface(Surface *surface); - void setCurrentReadSurface(Surface *surface); -} - -void error(GLenum errorCode); - -template<class T> -T &error(GLenum errorCode, T &returnValue) -{ - error(errorCode); - - return returnValue; -} - -template<class T> -const T &error(GLenum errorCode, const T &returnValue) -{ - error(errorCode); - - return returnValue; -} - -extern sw::FrameBuffer *createFrameBuffer(NativeDisplayType display, NativeWindowType window, int width, int height); - -#endif // LIBGL_MAIN_H_ +// SwiftShader Software Renderer +// +// Copyright(c) 2005-2012 TransGaming Inc. +// +// All rights reserved. No part of this software may be copied, distributed, transmitted, +// transcribed, stored in a retrieval system, translated into any human or computer +// language by any means, or disclosed to third parties without the explicit written +// agreement of TransGaming Inc. Without such an agreement, no rights or licenses, express +// or implied, including but not limited to any patent rights, are granted to you. +// + +// main.h: Management of thread-local data. + +#ifndef LIBGL_MAIN_H_ +#define LIBGL_MAIN_H_ + +#include "Context.h" +#include "Device.hpp" +#include "common/debug.h" +#include "Display.h" + +#define _GDI32_ +#include <windows.h> +#include <GL/GL.h> +#include <GL/glext.h> + +namespace gl +{ + struct Current + { + Context *context; + Display *display; + Surface *drawSurface; + Surface *readSurface; + }; + + void makeCurrent(Context *context, Display *display, Surface *surface); + + Context *getContext(); + Display *getDisplay(); + Device *getDevice(); + Surface *getCurrentDrawSurface(); + Surface *getCurrentReadSurface(); + + void setCurrentDisplay(Display *dpy); + void setCurrentContext(gl::Context *ctx); + void setCurrentDrawSurface(Surface *surface); + void setCurrentReadSurface(Surface *surface); +} + +void error(GLenum errorCode); + +template<class T> +T &error(GLenum errorCode, T &returnValue) +{ + error(errorCode); + + return returnValue; +} + +template<class T> +const T &error(GLenum errorCode, const T &returnValue) +{ + error(errorCode); + + return returnValue; +} + +extern sw::FrameBuffer *createFrameBuffer(void *display, NativeWindowType window, int width, int height); + +#endif // LIBGL_MAIN_H_
diff --git a/src/OpenGL/libGLES_CM/libGLES_CM.hpp b/src/OpenGL/libGLES_CM/libGLES_CM.hpp index 864783e..d4b4d75 100644 --- a/src/OpenGL/libGLES_CM/libGLES_CM.hpp +++ b/src/OpenGL/libGLES_CM/libGLES_CM.hpp
@@ -208,7 +208,7 @@ __eglMustCastToProperFunctionPointerType (*es1GetProcAddress)(const char *procname); egl::Image *(*createBackBuffer)(int width, int height, const egl::Config *config); egl::Image *(*createDepthStencil)(unsigned int width, unsigned int height, sw::Format format, int multiSampleDepth, bool discard); - sw::FrameBuffer *(*createFrameBuffer)(EGLNativeDisplayType display, EGLNativeWindowType window, int width, int height); + sw::FrameBuffer *(*createFrameBuffer)(void *display, EGLNativeWindowType window, int width, int height); }; class LibGLES_CM
diff --git a/src/OpenGL/libGLES_CM/main.cpp b/src/OpenGL/libGLES_CM/main.cpp index 38a50aa..2cc06e3 100644 --- a/src/OpenGL/libGLES_CM/main.cpp +++ b/src/OpenGL/libGLES_CM/main.cpp
@@ -337,7 +337,7 @@ extern "C" __eglMustCastToProperFunctionPointerType es1GetProcAddress(const char *procname); egl::Image *createBackBuffer(int width, int height, const egl::Config *config); egl::Image *createDepthStencil(unsigned int width, unsigned int height, sw::Format format, int multiSampleDepth, bool discard); -sw::FrameBuffer *createFrameBuffer(EGLNativeDisplayType display, EGLNativeWindowType window, int width, int height); +sw::FrameBuffer *createFrameBuffer(void *display, EGLNativeWindowType window, int width, int height); extern "C" {
diff --git a/src/OpenGL/libGLESv2/libGLESv2.hpp b/src/OpenGL/libGLESv2/libGLESv2.hpp index bde6c0a..afb7224 100644 --- a/src/OpenGL/libGLESv2/libGLESv2.hpp +++ b/src/OpenGL/libGLESv2/libGLESv2.hpp
@@ -229,7 +229,7 @@ __eglMustCastToProperFunctionPointerType (*es2GetProcAddress)(const char *procname); egl::Image *(*createBackBuffer)(int width, int height, const egl::Config *config); egl::Image *(*createDepthStencil)(unsigned int width, unsigned int height, sw::Format format, int multiSampleDepth, bool discard); - sw::FrameBuffer *(*createFrameBuffer)(EGLNativeDisplayType display, EGLNativeWindowType window, int width, int height); + sw::FrameBuffer *(*createFrameBuffer)(void *display, EGLNativeWindowType window, int width, int height); }; class LibGLESv2
diff --git a/src/OpenGL/libGLESv2/main.cpp b/src/OpenGL/libGLESv2/main.cpp index 1b51f67..6e5f008 100644 --- a/src/OpenGL/libGLESv2/main.cpp +++ b/src/OpenGL/libGLESv2/main.cpp
@@ -1333,7 +1333,7 @@ extern "C" __eglMustCastToProperFunctionPointerType es2GetProcAddress(const char *procname); egl::Image *createBackBuffer(int width, int height, const egl::Config *config); egl::Image *createDepthStencil(unsigned int width, unsigned int height, sw::Format format, int multiSampleDepth, bool discard); -sw::FrameBuffer *createFrameBuffer(EGLNativeDisplayType display, EGLNativeWindowType window, int width, int height); +sw::FrameBuffer *createFrameBuffer(void *display, EGLNativeWindowType window, int width, int height); LibGLESv2exports::LibGLESv2exports() {