From e6d64e95eeac250b092366b95c5dc3bbfcf717b5 Mon Sep 17 00:00:00 2001 From: Mikko Rasa Date: Sun, 12 Oct 2014 17:18:57 +0300 Subject: [PATCH] Drop the DrawContext class I've never actually used it, and 2D graphics are all but dead. I don't have any real interest of implementing it on other platforms either. --- source/graphics/drawcontext.h | 32 -------- source/graphics/windows/drawcontext.cpp | 34 --------- source/graphics/x11/drawcontext.cpp | 99 ------------------------- 3 files changed, 165 deletions(-) delete mode 100644 source/graphics/drawcontext.h delete mode 100644 source/graphics/windows/drawcontext.cpp delete mode 100644 source/graphics/x11/drawcontext.cpp diff --git a/source/graphics/drawcontext.h b/source/graphics/drawcontext.h deleted file mode 100644 index 957e153..0000000 --- a/source/graphics/drawcontext.h +++ /dev/null @@ -1,32 +0,0 @@ -#ifndef MSP_GRAPHICS_DRAWCONTEXT_H_ -#define MSP_GRAPHICS_DRAWCONTEXT_H_ - -namespace Msp { -namespace Graphics { - -class Display; -class Window; - -class DrawContext -{ -private: - struct Private; - - Display &display; - Window &window; - Private *priv; - -public: - DrawContext(Window &); - ~DrawContext(); - - Window &get_window() const { return window; } - unsigned get_depth() const; - unsigned char *get_data(); - void update(); -}; - -} // namespace Graphics -} // namespace Msp - -#endif diff --git a/source/graphics/windows/drawcontext.cpp b/source/graphics/windows/drawcontext.cpp deleted file mode 100644 index b887615..0000000 --- a/source/graphics/windows/drawcontext.cpp +++ /dev/null @@ -1,34 +0,0 @@ -#include -#include "drawcontext.h" -#include "window.h" - -using namespace std; - -namespace Msp { -namespace Graphics { - -DrawContext::DrawContext(Window &w): - display(w.get_display()), - window(w) -{ - throw runtime_error("no DrawContext support on windows"); -} - -DrawContext::~DrawContext() -{ } - -unsigned DrawContext::get_depth() const -{ - return 0; -} - -unsigned char *DrawContext::get_data() -{ - return 0; -} - -void DrawContext::update() -{ } - -} // namespace Graphics -} // namespace Msp diff --git a/source/graphics/x11/drawcontext.cpp b/source/graphics/x11/drawcontext.cpp deleted file mode 100644 index e40390f..0000000 --- a/source/graphics/x11/drawcontext.cpp +++ /dev/null @@ -1,99 +0,0 @@ -#include -#include -#include -#include -#include -#include -#include "display_private.h" -#include "drawcontext.h" -#include "window_private.h" - -using namespace std; - -namespace Msp { -namespace Graphics { - -struct DrawContext::Private -{ - XImage *image; - bool use_shm; - XShmSegmentInfo shminfo; -}; - -DrawContext::DrawContext(Window &w): - display(w.get_display()), - window(w), - priv(new Private) -{ - DisplayHandle dpy = display.get_private().display; - - priv->use_shm = XShmQueryExtension(dpy); - - XWindowAttributes wa; - XGetWindowAttributes(dpy, window.get_private().window, &wa); - - if(priv->use_shm) - { - priv->image = XShmCreateImage(dpy, wa.visual, wa.depth, ZPixmap, 0, &priv->shminfo, wa.width, wa.height); - if(!priv->image) - throw runtime_error("XShmCreateImage"); - - priv->shminfo.shmid = shmget(IPC_PRIVATE, priv->image->bytes_per_line*priv->image->height, IPC_CREAT|0666); - priv->shminfo.shmaddr=priv->image->data = reinterpret_cast(shmat(priv->shminfo.shmid, 0, 0)); - priv->shminfo.readOnly = false; - - XShmAttach(dpy, &priv->shminfo); - - XSync(dpy, false); - display.check_error(); - } - else - { - priv->image = XCreateImage(dpy, wa.visual, wa.depth, ZPixmap, 0, 0, wa.width, wa.height, 8, 0); - if(!priv->image) - throw runtime_error("XCreateImage"); - priv->image->data = new char[priv->image->bytes_per_line*priv->image->height]; - } -} - -DrawContext::~DrawContext() -{ - if(priv->use_shm) - { - XShmDetach(display.get_private().display, &priv->shminfo); - shmdt(priv->shminfo.shmaddr); - shmctl(priv->shminfo.shmid, IPC_RMID, 0); - } - - XDestroyImage(priv->image); - - delete priv; -} - -unsigned DrawContext::get_depth() const -{ - return priv->image->bits_per_pixel; -} - -unsigned char *DrawContext::get_data() -{ - return reinterpret_cast(priv->image->data); -} - -void DrawContext::update() -{ - DisplayHandle dpy = display.get_private().display; - WindowHandle wnd = window.get_private().window; - - GC gc = XCreateGC(dpy, wnd, 0, 0); - - if(priv->use_shm) - XShmPutImage(dpy, wnd, gc, priv->image, 0, 0, 0, 0, priv->image->width, priv->image->height, false); - else - XPutImage(dpy, wnd, gc, priv->image, 0, 0, 0, 0, priv->image->width, priv->image->height); - - XFreeGC(dpy, gc); -} - -} // namespace Graphics -} // namespace Msp -- 2.43.0