From: José Fonseca Date: Fri, 6 May 2011 19:43:48 +0000 (+0100) Subject: Take drawable geometry on creation. X-Git-Tag: 2.0_alpha^2~948 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=7497c130f98f33f41437678835f4b2eb2abce750;p=tools%2Fapitrace.git Take drawable geometry on creation. --- diff --git a/glws.hpp b/glws.hpp index 7f4b52d..23de839 100644 --- a/glws.hpp +++ b/glws.hpp @@ -51,17 +51,19 @@ class Drawable { public: const Visual *visual; - unsigned width; - unsigned height; + int width; + int height; - Drawable(const Visual *vis) : - visual(vis) + Drawable(const Visual *vis, int w, int h) : + visual(vis), + width(w), + height(h) {} virtual ~Drawable() {} virtual void - resize(unsigned w, unsigned h) { + resize(int w, int h) { width = w; height = h; } @@ -92,7 +94,7 @@ public: createVisual(bool doubleBuffer = false) = 0; virtual Drawable * - createDrawable(const Visual *visual) = 0; + createDrawable(const Visual *visual, int width = 256, int height = 256) = 0; virtual Context * createContext(const Visual *visual) = 0; diff --git a/glws_glx.cpp b/glws_glx.cpp index 64f8ce1..39e0c46 100644 --- a/glws_glx.cpp +++ b/glws_glx.cpp @@ -33,6 +33,9 @@ namespace glws { +static Display *display = NULL; +static int screen = 0; + class GlxVisual : public Visual { public: @@ -51,21 +54,59 @@ public: class GlxDrawable : public Drawable { public: - Display *display; Window window; - GlxDrawable(const Visual *vis, Display *dpy, Window win) : - Drawable(vis), - display(dpy), - window(win) - {} + GlxDrawable(const Visual *vis, int w, int h) : + Drawable(vis, w, h) + { + XVisualInfo *visinfo = dynamic_cast(visual)->visinfo; + + Window root = RootWindow(display, screen); + + /* window attributes */ + XSetWindowAttributes attr; + attr.background_pixel = 0; + attr.border_pixel = 0; + attr.colormap = XCreateColormap(display, root, visinfo->visual, AllocNone); + attr.event_mask = StructureNotifyMask | ExposureMask | KeyPressMask; + + unsigned long mask; + mask = CWBackPixel | CWBorderPixel | CWColormap | CWEventMask; + + int x = 0, y = 0; + + window = XCreateWindow( + display, root, + x, y, width, height, + 0, + visinfo->depth, + InputOutput, + visinfo->visual, + mask, + &attr); + + XSizeHints sizehints; + sizehints.x = x; + sizehints.y = y; + sizehints.width = width; + sizehints.height = height; + sizehints.flags = USSize | USPosition; + XSetNormalHints(display, window, &sizehints); + + const char *name = "glretrace"; + XSetStandardProperties( + display, window, name, name, + None, (char **)NULL, 0, &sizehints); + + XMapWindow(display, window); + } ~GlxDrawable() { XDestroyWindow(display, window); } - + void - resize(unsigned w, unsigned h) { + resize(int w, int h) { glXWaitGL(); Drawable::resize(w, h); XResizeWindow(display, window, w, h); @@ -81,12 +122,10 @@ public: class GlxContext : public Context { public: - Display *display; GLXContext context; - - GlxContext(const Visual *vis, Display *dpy, GLXContext ctx) : + + GlxContext(const Visual *vis, GLXContext ctx) : Context(vis), - display(dpy), context(ctx) {} @@ -98,18 +137,16 @@ public: class GlxWindowSystem : public WindowSystem { -private: - Display *display; - int screen; - public: GlxWindowSystem() { - display = XOpenDisplay(NULL); - if (!display) { - std::cerr << "error: unable to open display " << XDisplayName(NULL) << "\n"; - exit(1); + if (!display) { + display = XOpenDisplay(NULL); + if (!display) { + std::cerr << "error: unable to open display " << XDisplayName(NULL) << "\n"; + exit(1); + } + screen = DefaultScreen(display); } - screen = DefaultScreen(display); } ~GlxWindowSystem() { @@ -140,57 +177,16 @@ public: }; XVisualInfo *visinfo; - + visinfo = glXChooseVisual(display, screen, doubleBuffer ? double_attribs : single_attribs); return new GlxVisual(visinfo); } - + Drawable * - createDrawable(const Visual *visual) + createDrawable(const Visual *visual, int width, int height) { - XVisualInfo *visinfo = dynamic_cast(visual)->visinfo; - - Window root = RootWindow(display, screen); - - /* window attributes */ - XSetWindowAttributes attr; - attr.background_pixel = 0; - attr.border_pixel = 0; - attr.colormap = XCreateColormap(display, root, visinfo->visual, AllocNone); - attr.event_mask = StructureNotifyMask | ExposureMask | KeyPressMask; - - unsigned long mask; - mask = CWBackPixel | CWBorderPixel | CWColormap | CWEventMask; - - int x = 0, y = 0, width = 256, height = 256; - - Window window = XCreateWindow( - display, root, - x, y, width, height, - 0, - visinfo->depth, - InputOutput, - visinfo->visual, - mask, - &attr); - - XSizeHints sizehints; - sizehints.x = x; - sizehints.y = y; - sizehints.width = width; - sizehints.height = height; - sizehints.flags = USSize | USPosition; - XSetNormalHints(display, window, &sizehints); - - const char *name = "glretrace"; - XSetStandardProperties( - display, window, name, name, - None, (char **)NULL, 0, &sizehints); - - XMapWindow(display, window); - - return new GlxDrawable(visual, display, window); + return new GlxDrawable(visual, width, height); } Context * @@ -198,7 +194,7 @@ public: { XVisualInfo *visinfo = dynamic_cast(visual)->visinfo; GLXContext context = glXCreateContext(display, visinfo, NULL, True); - return new GlxContext(visual, display, context); + return new GlxContext(visual, context); } bool diff --git a/glws_wgl.cpp b/glws_wgl.cpp index bc4dd27..b1e274b 100644 --- a/glws_wgl.cpp +++ b/glws_wgl.cpp @@ -61,8 +61,8 @@ public: PIXELFORMATDESCRIPTOR pfd; int iPixelFormat; - WglDrawable(const Visual *vis) : - Drawable(vis) + WglDrawable(const Visual *vis, int width, int height) : + Drawable(vis, width, height) { static bool first = TRUE; RECT rect; @@ -83,7 +83,7 @@ public: dwExStyle = 0; dwStyle = WS_CLIPSIBLINGS | WS_CLIPCHILDREN | WS_VISIBLE | WS_OVERLAPPEDWINDOW; - int x = 0, y = 0, width = 256, height = 256; + int x = 0, y = 0; rect.left = x; rect.top = y; @@ -134,7 +134,7 @@ public: } void - resize(unsigned w, unsigned h) { + resize(int w, int h) { Drawable::resize(w, h); RECT rClient, rWindow; GetClientRect(hWnd, &rClient); @@ -181,9 +181,9 @@ public: } Drawable * - createDrawable(const Visual *visual) + createDrawable(const Visual *visual, int width, int height) { - return new WglDrawable(visual); + return new WglDrawable(visual, width, height); } Context *