Commit e63db96b by Nicolas Capens

Store the native display as an opaque pointer.

Bug 18314459 Change-Id: I63e56d626bd1838803d1de71b417b7e40242c5e9 Reviewed-on: https://swiftshader-review.googlesource.com/4390Reviewed-by: 's avatarNicolas Capens <capn@google.com> Tested-by: 's avatarNicolas Capens <capn@google.com>
parent 5524f05f
...@@ -16,10 +16,10 @@ namespace sw ...@@ -16,10 +16,10 @@ namespace sw
~FrameBufferAndroid(); ~FrameBufferAndroid();
void flip(void *source, Format sourceFormat, size_t sourceStride) override {blit(source, 0, 0, sourceFormat, sourceStride);}; 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 blit(void *source, const Rect *sourceRect, const Rect *destRect, Format sourceFormat, size_t sourceStride) override;
void *lock() override; void *lock() override;
void unlock() override; void unlock() override;
bool setSwapRectangle(int l, int t, int w, int h); bool setSwapRectangle(int l, int t, int w, int h);
......
...@@ -69,7 +69,7 @@ sw::FrameBufferWin *createFrameBufferWin(HWND windowHandle, int width, int heigh ...@@ -69,7 +69,7 @@ sw::FrameBufferWin *createFrameBufferWin(HWND windowHandle, int width, int heigh
return 0; 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); return createFrameBufferWin(window, width, height, false, false);
} }
// SwiftShader Software Renderer // SwiftShader Software Renderer
// //
// Copyright(c) 2005-2012 TransGaming Inc. // Copyright(c) 2005-2012 TransGaming Inc.
// //
// All rights reserved. No part of this software may be copied, distributed, transmitted, // 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 // 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 // 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 // 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. // 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 // Surface.cpp: Implements the egl::Surface class, representing a drawing surface
// such as the client area of a window, including any back buffers. // 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. // Implements EGLSurface and related functionality. [EGL 1.4] section 2.2 page 3.
#include "FrameBufferX11.hpp" #include "FrameBufferX11.hpp"
#include "libX11.hpp" #include "libX11.hpp"
#include <sys/ipc.h> #include <sys/ipc.h>
#include <sys/shm.h> #include <sys/shm.h>
#include <string.h> #include <string.h>
#include <assert.h> #include <assert.h>
namespace sw namespace sw
{ {
static int (*PreviousXErrorHandler)(Display *display, XErrorEvent *event) = 0; static int (*PreviousXErrorHandler)(Display *display, XErrorEvent *event) = 0;
static bool shmBadAccess = false; static bool shmBadAccess = false;
// Catches BadAcces errors so we can fall back to not using MIT-SHM // Catches BadAcces errors so we can fall back to not using MIT-SHM
static int XShmErrorHandler(Display *display, XErrorEvent *event) static int XShmErrorHandler(Display *display, XErrorEvent *event)
{ {
if(event->error_code == BadAccess) if(event->error_code == BadAccess)
{ {
shmBadAccess = true; shmBadAccess = true;
return 0; return 0;
} }
else else
{ {
return PreviousXErrorHandler(display, event); 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) 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) if(!x_display)
{ {
x_display = libX11->XOpenDisplay(0); x_display = libX11->XOpenDisplay(0);
} }
int screen = DefaultScreen(x_display); int screen = DefaultScreen(x_display);
x_gc = libX11->XDefaultGC(x_display, screen); x_gc = libX11->XDefaultGC(x_display, screen);
int depth = libX11->XDefaultDepth(x_display, screen); int depth = libX11->XDefaultDepth(x_display, screen);
Status status = libX11->XMatchVisualInfo(x_display, screen, 32, TrueColor, &x_visual); Status status = libX11->XMatchVisualInfo(x_display, screen, 32, TrueColor, &x_visual);
bool match = (status != 0 && x_visual.blue_mask == 0xFF); // Prefer X8R8G8B8 bool match = (status != 0 && x_visual.blue_mask == 0xFF); // Prefer X8R8G8B8
Visual *visual = match ? x_visual.visual : libX11->XDefaultVisual(x_display, screen); Visual *visual = match ? x_visual.visual : libX11->XDefaultVisual(x_display, screen);
mit_shm = (libX11->XShmQueryExtension && libX11->XShmQueryExtension(x_display) == True); mit_shm = (libX11->XShmQueryExtension && libX11->XShmQueryExtension(x_display) == True);
if(mit_shm) if(mit_shm)
{ {
x_image = libX11->XShmCreateImage(x_display, visual, depth, ZPixmap, 0, &shminfo, width, height); 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.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.shmaddr = x_image->data = buffer = (char*)shmat(shminfo.shmid, 0, 0);
shminfo.readOnly = False; shminfo.readOnly = False;
PreviousXErrorHandler = libX11->XSetErrorHandler(XShmErrorHandler); PreviousXErrorHandler = libX11->XSetErrorHandler(XShmErrorHandler);
libX11->XShmAttach(x_display, &shminfo); // May produce a BadAccess error libX11->XShmAttach(x_display, &shminfo); // May produce a BadAccess error
libX11->XSync(x_display, False); libX11->XSync(x_display, False);
libX11->XSetErrorHandler(PreviousXErrorHandler); libX11->XSetErrorHandler(PreviousXErrorHandler);
if(shmBadAccess) if(shmBadAccess)
{ {
mit_shm = false; mit_shm = false;
XDestroyImage(x_image); XDestroyImage(x_image);
shmdt(shminfo.shmaddr); shmdt(shminfo.shmaddr);
shmctl(shminfo.shmid, IPC_RMID, 0); shmctl(shminfo.shmid, IPC_RMID, 0);
shmBadAccess = false; shmBadAccess = false;
} }
} }
if(!mit_shm) if(!mit_shm)
{ {
buffer = new char[width * height * 4]; buffer = new char[width * height * 4];
x_image = libX11->XCreateImage(x_display, visual, depth, ZPixmap, 0, buffer, width, height, 32, width * 4); x_image = libX11->XCreateImage(x_display, visual, depth, ZPixmap, 0, buffer, width, height, 32, width * 4);
} }
} }
FrameBufferX11::~FrameBufferX11() FrameBufferX11::~FrameBufferX11()
{ {
if(!mit_shm) if(!mit_shm)
{ {
x_image->data = 0; x_image->data = 0;
XDestroyImage(x_image); XDestroyImage(x_image);
delete[] buffer; delete[] buffer;
buffer = 0; buffer = 0;
} }
else else
{ {
libX11->XShmDetach(x_display, &shminfo); libX11->XShmDetach(x_display, &shminfo);
XDestroyImage(x_image); XDestroyImage(x_image);
shmdt(shminfo.shmaddr); shmdt(shminfo.shmaddr);
shmctl(shminfo.shmid, IPC_RMID, 0); shmctl(shminfo.shmid, IPC_RMID, 0);
} }
if(ownX11) if(ownX11)
{ {
libX11->XCloseDisplay(x_display); libX11->XCloseDisplay(x_display);
} }
} }
void *FrameBufferX11::lock() void *FrameBufferX11::lock()
{ {
stride = x_image->bytes_per_line; stride = x_image->bytes_per_line;
locked = buffer; locked = buffer;
return locked; return locked;
} }
void FrameBufferX11::unlock() void FrameBufferX11::unlock()
{ {
locked = 0; locked = 0;
} }
void FrameBufferX11::blit(void *source, const Rect *sourceRect, const Rect *destRect, Format sourceFormat, size_t sourceStride) void FrameBufferX11::blit(void *source, const Rect *sourceRect, const Rect *destRect, Format sourceFormat, size_t sourceStride)
{ {
copy(source, sourceFormat, sourceStride); copy(source, sourceFormat, sourceStride);
if(!mit_shm) if(!mit_shm)
{ {
libX11->XPutImage(x_display, x_window, x_gc, x_image, 0, 0, 0, 0, width, height); libX11->XPutImage(x_display, x_window, x_gc, x_image, 0, 0, 0, 0, width, height);
} }
else else
{ {
libX11->XShmPutImage(x_display, x_window, x_gc, x_image, 0, 0, 0, 0, width, height, False); libX11->XShmPutImage(x_display, x_window, x_gc, x_image, 0, 0, 0, 0, width, height, False);
} }
libX11->XSync(x_display, False); libX11->XSync(x_display, False);
} }
} }
sw::FrameBuffer *createFrameBuffer(Display *display, Window window, int width, int height) sw::FrameBuffer *createFrameBuffer(void *display, Window window, int width, int height)
{ {
return new sw::FrameBufferX11(display, window, width, height); return new sw::FrameBufferX11((::Display*)display, window, width, height);
} }
// SwiftShader Software Renderer // SwiftShader Software Renderer
// //
// Copyright(c) 2005-2012 TransGaming Inc. // Copyright(c) 2005-2012 TransGaming Inc.
// //
// All rights reserved. No part of this software may be copied, distributed, transmitted, // 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 // 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 // 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 // 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. // 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 // Surface.cpp: Implements the egl::Surface class, representing a drawing surface
// such as the client area of a window, including any back buffers. // 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. // Implements EGLSurface and related functionality. [EGL 1.4] section 2.2 page 3.
#ifndef sw_FrameBufferX11_hpp #ifndef sw_FrameBufferX11_hpp
#define sw_FrameBufferX11_hpp #define sw_FrameBufferX11_hpp
#include "Main/FrameBuffer.hpp" #include "Main/FrameBuffer.hpp"
#include "Common/Debug.hpp" #include "Common/Debug.hpp"
#include <X11/Xlib.h> #include <X11/Xlib.h>
#include <X11/Xutil.h> #include <X11/Xutil.h>
#include <X11/extensions/XShm.h> #include <X11/extensions/XShm.h>
namespace sw namespace sw
{ {
class FrameBufferX11 : public FrameBuffer class FrameBufferX11 : public FrameBuffer
{ {
public: public:
FrameBufferX11(Display *display, Window window, int width, int height); FrameBufferX11(Display *display, Window window, int width, int height);
~FrameBufferX11(); ~FrameBufferX11();
void flip(void *source, Format sourceFormat, size_t sourceStride) override {blit(source, 0, 0, sourceFormat, sourceStride);}; 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 blit(void *source, const Rect *sourceRect, const Rect *destRect, Format sourceFormat, size_t sourceStride) override;
void *lock() override; void *lock() override;
void unlock() override; void unlock() override;
private: private:
bool ownX11; bool ownX11;
Display *x_display; Display *x_display;
Window x_window; Window x_window;
XImage *x_image; XImage *x_image;
GC x_gc; GC x_gc;
XVisualInfo x_visual; XVisualInfo x_visual;
bool mit_shm; bool mit_shm;
XShmSegmentInfo shminfo; XShmSegmentInfo shminfo;
char *buffer; char *buffer;
}; };
} }
#endif // sw_FrameBufferX11_hpp #endif // sw_FrameBufferX11_hpp
...@@ -38,23 +38,11 @@ ...@@ -38,23 +38,11 @@
namespace egl namespace egl
{ {
typedef std::map<EGLNativeDisplayType, Display*> DisplayMap;
// Protects the global displays map. egl::Display *Display::getPlatformDisplay(EGLenum platform, void *nativeDisplay)
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)
{ {
#ifndef __ANDROID__ #ifndef __ANDROID__
if(platform == EGL_UNKNOWN) // Default if(platform == EGL_UNKNOWN) // Default platform
{ {
#if defined(__unix__) #if defined(__unix__)
if(libX11) if(libX11)
...@@ -68,14 +56,14 @@ egl::Display *Display::getPlatformDisplay(EGLenum platform, EGLNativeDisplayType ...@@ -68,14 +56,14 @@ egl::Display *Display::getPlatformDisplay(EGLenum platform, EGLNativeDisplayType
#endif #endif
} }
if(displayId == EGL_DEFAULT_DISPLAY) if(!nativeDisplay) // Default display
{ {
if(platform == EGL_PLATFORM_X11_EXT) if(platform == EGL_PLATFORM_X11_EXT)
{ {
#if defined(__unix__) #if defined(__unix__)
if(libX11->XOpenDisplay) if(libX11->XOpenDisplay)
{ {
displayId = libX11->XOpenDisplay(NULL); nativeDisplay = libX11->XOpenDisplay(NULL);
} }
else else
{ {
...@@ -88,26 +76,29 @@ egl::Display *Display::getPlatformDisplay(EGLenum platform, EGLNativeDisplayType ...@@ -88,26 +76,29 @@ egl::Display *Display::getPlatformDisplay(EGLenum platform, EGLNativeDisplayType
} }
else 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 #endif
egl::Display *rval; static std::map<void*, Display*> displays;
displays_lock.lock(); static sw::BackoffLock displaysMutex;
DisplayMap* displays = getDisplays();
if (displays->find(displayId) != displays->end()) displaysMutex.lock();
{
rval = (*displays)[displayId];
} else {
rval = new egl::Display(platform, displayId);
(*displays)[displayId] = rval; 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; mMinSwapInterval = 1;
mMaxSwapInterval = 1; mMaxSwapInterval = 1;
...@@ -116,10 +107,6 @@ Display::Display(EGLenum platform, EGLNativeDisplayType displayId) : platform(pl ...@@ -116,10 +107,6 @@ Display::Display(EGLenum platform, EGLNativeDisplayType displayId) : platform(pl
Display::~Display() Display::~Display()
{ {
terminate(); terminate();
displays_lock.lock();
getDisplays()->erase(displayId);
displays_lock.unlock();
} }
static void cpuid(int registers[4], int info) static void cpuid(int registers[4], int info)
...@@ -561,7 +548,7 @@ bool Display::isValidWindow(EGLNativeWindowType window) ...@@ -561,7 +548,7 @@ bool Display::isValidWindow(EGLNativeWindowType window)
if(platform == EGL_PLATFORM_X11_EXT) if(platform == EGL_PLATFORM_X11_EXT)
{ {
XWindowAttributes windowAttributes; XWindowAttributes windowAttributes;
Status status = libX11->XGetWindowAttributes(displayId, window, &windowAttributes); Status status = libX11->XGetWindowAttributes((::Display*)nativeDisplay, window, &windowAttributes);
return status == True; return status == True;
} }
...@@ -596,9 +583,9 @@ EGLint Display::getMaxSwapInterval() const ...@@ -596,9 +583,9 @@ EGLint Display::getMaxSwapInterval() const
return mMaxSwapInterval; return mMaxSwapInterval;
} }
EGLNativeDisplayType Display::getNativeDisplay() const void *Display::getNativeDisplay() const
{ {
return displayId; return nativeDisplay;
} }
sw::Format Display::getDisplayFormat() const sw::Format Display::getDisplayFormat() const
...@@ -680,7 +667,7 @@ sw::Format Display::getDisplayFormat() const ...@@ -680,7 +667,7 @@ sw::Format Display::getDisplayFormat() const
#else #else
if(platform == EGL_PLATFORM_X11_EXT) if(platform == EGL_PLATFORM_X11_EXT)
{ {
Screen *screen = libX11->XDefaultScreenOfDisplay(displayId); Screen *screen = libX11->XDefaultScreenOfDisplay((::Display*)nativeDisplay);
unsigned int bpp = libX11->XPlanesOfScreen(screen); unsigned int bpp = libX11->XPlanesOfScreen(screen);
switch(bpp) switch(bpp)
......
...@@ -28,9 +28,7 @@ namespace egl ...@@ -28,9 +28,7 @@ namespace egl
class Display class Display
{ {
public: public:
~Display(); static egl::Display *getPlatformDisplay(EGLenum platform, void *nativeDisplay);
static egl::Display *getPlatformDisplay(EGLenum platform, EGLNativeDisplayType displayId);
bool initialize(); bool initialize();
void terminate(); void terminate();
...@@ -55,20 +53,21 @@ namespace egl ...@@ -55,20 +53,21 @@ namespace egl
EGLint getMinSwapInterval() const; EGLint getMinSwapInterval() const;
EGLint getMaxSwapInterval() const; EGLint getMaxSwapInterval() const;
EGLNativeDisplayType getNativeDisplay() const; void *getNativeDisplay() const;
const char *getExtensionString() const; const char *getExtensionString() const;
private: private:
Display(EGLenum platform, EGLNativeDisplayType displayId); Display(EGLenum platform, void *nativeDisplay);
~Display();
sw::Format getDisplayFormat() const; sw::Format getDisplayFormat() const;
const EGLenum platform; const EGLenum platform;
const EGLNativeDisplayType displayId; void *const nativeDisplay;
EGLint mMaxSwapInterval; EGLint mMaxSwapInterval;
EGLint mMinSwapInterval; EGLint mMinSwapInterval;
typedef std::set<Surface*> SurfaceSet; typedef std::set<Surface*> SurfaceSet;
SurfaceSet mSurfaceSet; SurfaceSet mSurfaceSet;
......
...@@ -246,7 +246,7 @@ bool WindowSurface::initialize() ...@@ -246,7 +246,7 @@ bool WindowSurface::initialize()
return reset(width, height); return reset(width, height);
#else #else
XWindowAttributes windowAttributes; XWindowAttributes windowAttributes;
libX11->XGetWindowAttributes(display->getNativeDisplay(), window, &windowAttributes); libX11->XGetWindowAttributes((::Display*)display->getNativeDisplay(), window, &windowAttributes);
return reset(windowAttributes.width, windowAttributes.height); return reset(windowAttributes.width, windowAttributes.height);
#endif #endif
...@@ -286,7 +286,7 @@ bool WindowSurface::checkForResize() ...@@ -286,7 +286,7 @@ bool WindowSurface::checkForResize()
int clientHeight; window->query(window, NATIVE_WINDOW_HEIGHT, &clientHeight); int clientHeight; window->query(window, NATIVE_WINDOW_HEIGHT, &clientHeight);
#else #else
XWindowAttributes windowAttributes; XWindowAttributes windowAttributes;
libX11->XGetWindowAttributes(display->getNativeDisplay(), window, &windowAttributes); libX11->XGetWindowAttributes((::Display*)display->getNativeDisplay(), window, &windowAttributes);
int clientWidth = windowAttributes.width; int clientWidth = windowAttributes.width;
int clientHeight = windowAttributes.height; int clientHeight = windowAttributes.height;
......
...@@ -108,7 +108,14 @@ EGLDisplay GetDisplay(EGLNativeDisplayType display_id) ...@@ -108,7 +108,14 @@ EGLDisplay GetDisplay(EGLNativeDisplayType display_id)
{ {
TRACE("(EGLNativeDisplayType display_id = %p)", display_id); 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) EGLBoolean Initialize(EGLDisplay dpy, EGLint *major, EGLint *minor)
...@@ -948,7 +955,7 @@ EGLDisplay GetPlatformDisplayEXT(EGLenum platform, void *native_display, const E ...@@ -948,7 +955,7 @@ EGLDisplay GetPlatformDisplayEXT(EGLenum platform, void *native_display, const E
{ {
TRACE("(EGLenum platform = 0x%X, void *native_display = %p, const EGLint *attrib_list = %p)", platform, native_display, attrib_list); 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) EGLSurface CreatePlatformWindowSurfaceEXT(EGLDisplay dpy, EGLConfig config, void *native_window, const EGLint *attrib_list)
......
// SwiftShader Software Renderer // SwiftShader Software Renderer
// //
// Copyright(c) 2005-2012 TransGaming Inc. // Copyright(c) 2005-2012 TransGaming Inc.
// //
// All rights reserved. No part of this software may be copied, distributed, transmitted, // 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 // 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 // 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 // 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. // or implied, including but not limited to any patent rights, are granted to you.
// //
// main.h: Management of thread-local data. // main.h: Management of thread-local data.
#ifndef LIBGL_MAIN_H_ #ifndef LIBGL_MAIN_H_
#define LIBGL_MAIN_H_ #define LIBGL_MAIN_H_
#include "Context.h" #include "Context.h"
#include "Device.hpp" #include "Device.hpp"
#include "common/debug.h" #include "common/debug.h"
#include "Display.h" #include "Display.h"
#define _GDI32_ #define _GDI32_
#include <windows.h> #include <windows.h>
#include <GL/GL.h> #include <GL/GL.h>
#include <GL/glext.h> #include <GL/glext.h>
namespace gl namespace gl
{ {
struct Current struct Current
{ {
Context *context; Context *context;
Display *display; Display *display;
Surface *drawSurface; Surface *drawSurface;
Surface *readSurface; Surface *readSurface;
}; };
void makeCurrent(Context *context, Display *display, Surface *surface); void makeCurrent(Context *context, Display *display, Surface *surface);
Context *getContext(); Context *getContext();
Display *getDisplay(); Display *getDisplay();
Device *getDevice(); Device *getDevice();
Surface *getCurrentDrawSurface(); Surface *getCurrentDrawSurface();
Surface *getCurrentReadSurface(); Surface *getCurrentReadSurface();
void setCurrentDisplay(Display *dpy); void setCurrentDisplay(Display *dpy);
void setCurrentContext(gl::Context *ctx); void setCurrentContext(gl::Context *ctx);
void setCurrentDrawSurface(Surface *surface); void setCurrentDrawSurface(Surface *surface);
void setCurrentReadSurface(Surface *surface); void setCurrentReadSurface(Surface *surface);
} }
void error(GLenum errorCode); void error(GLenum errorCode);
template<class T> template<class T>
T &error(GLenum errorCode, T &returnValue) T &error(GLenum errorCode, T &returnValue)
{ {
error(errorCode); error(errorCode);
return returnValue; return returnValue;
} }
template<class T> template<class T>
const T &error(GLenum errorCode, const T &returnValue) const T &error(GLenum errorCode, const T &returnValue)
{ {
error(errorCode); error(errorCode);
return returnValue; return returnValue;
} }
extern sw::FrameBuffer *createFrameBuffer(NativeDisplayType display, NativeWindowType window, int width, int height); extern sw::FrameBuffer *createFrameBuffer(void *display, NativeWindowType window, int width, int height);
#endif // LIBGL_MAIN_H_ #endif // LIBGL_MAIN_H_
...@@ -208,7 +208,7 @@ public: ...@@ -208,7 +208,7 @@ public:
__eglMustCastToProperFunctionPointerType (*es1GetProcAddress)(const char *procname); __eglMustCastToProperFunctionPointerType (*es1GetProcAddress)(const char *procname);
egl::Image *(*createBackBuffer)(int width, int height, const egl::Config *config); 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); 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 class LibGLES_CM
......
...@@ -337,7 +337,7 @@ egl::Context *es1CreateContext(const egl::Config *config, const egl::Context *sh ...@@ -337,7 +337,7 @@ egl::Context *es1CreateContext(const egl::Config *config, const egl::Context *sh
extern "C" __eglMustCastToProperFunctionPointerType es1GetProcAddress(const char *procname); extern "C" __eglMustCastToProperFunctionPointerType es1GetProcAddress(const char *procname);
egl::Image *createBackBuffer(int width, int height, const egl::Config *config); 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); 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" extern "C"
{ {
......
...@@ -229,7 +229,7 @@ public: ...@@ -229,7 +229,7 @@ public:
__eglMustCastToProperFunctionPointerType (*es2GetProcAddress)(const char *procname); __eglMustCastToProperFunctionPointerType (*es2GetProcAddress)(const char *procname);
egl::Image *(*createBackBuffer)(int width, int height, const egl::Config *config); 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); 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 class LibGLESv2
......
...@@ -1333,7 +1333,7 @@ egl::Context *es2CreateContext(const egl::Config *config, const egl::Context *sh ...@@ -1333,7 +1333,7 @@ egl::Context *es2CreateContext(const egl::Config *config, const egl::Context *sh
extern "C" __eglMustCastToProperFunctionPointerType es2GetProcAddress(const char *procname); extern "C" __eglMustCastToProperFunctionPointerType es2GetProcAddress(const char *procname);
egl::Image *createBackBuffer(int width, int height, const egl::Config *config); 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); 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() LibGLESv2exports::LibGLESv2exports()
{ {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment