scroggo | b7e9aee | 2011-03-15 15:15:15 +0000 | [diff] [blame] | 1 | #include <X11/Xlib.h> |
| 2 | #include <X11/Xatom.h> |
| 3 | #include <X11/keysym.h> |
| 4 | #include <GL/glx.h> |
| 5 | |
| 6 | #include "SkWindow.h" |
| 7 | |
| 8 | #include "SkBitmap.h" |
scroggo | 08526c0 | 2011-03-22 14:03:21 +0000 | [diff] [blame] | 9 | #include "SkCanvas.h" |
scroggo | b7e9aee | 2011-03-15 15:15:15 +0000 | [diff] [blame] | 10 | #include "SkColor.h" |
| 11 | #include "SkEvent.h" |
| 12 | |
| 13 | SkOSWindow::SkOSWindow(void* unused) |
| 14 | { |
| 15 | fUnixWindow.fDisplay = NULL; |
| 16 | } |
| 17 | |
| 18 | SkOSWindow::~SkOSWindow() |
| 19 | { |
| 20 | } |
| 21 | |
| 22 | void SkOSWindow::setUnixWindow(Display* dsp, Window win, size_t screenNumber, GC gc) |
| 23 | { |
| 24 | fUnixWindow.fDisplay = dsp; |
| 25 | fUnixWindow.fWin = win; |
| 26 | fUnixWindow.fOSWin = screenNumber; |
| 27 | fUnixWindow.fGc = gc; |
| 28 | } |
| 29 | |
bsalomon@google.com | c8ad63e | 2011-03-18 14:29:44 +0000 | [diff] [blame] | 30 | bool SkOSWindow::attachGL() |
scroggo | b7e9aee | 2011-03-15 15:15:15 +0000 | [diff] [blame] | 31 | { |
| 32 | return false; |
| 33 | } |
| 34 | |
| 35 | void SkOSWindow::detachGL() |
| 36 | { |
| 37 | |
| 38 | } |
| 39 | |
| 40 | void SkOSWindow::presentGL() |
| 41 | { |
| 42 | |
| 43 | } |
| 44 | |
| 45 | void SkOSWindow::onSetTitle(const char title[]) |
| 46 | { |
| 47 | if (!fUnixWindow.fDisplay) return; |
| 48 | XTextProperty textProp; |
| 49 | textProp.value = (unsigned char*)title; |
| 50 | textProp.format = 8; |
| 51 | textProp.nitems = strlen((char*)textProp.value); |
| 52 | textProp.encoding = XA_STRING; |
| 53 | XSetWMName(fUnixWindow.fDisplay, fUnixWindow.fWin, &textProp); |
| 54 | } |
| 55 | |
| 56 | void SkOSWindow::onHandleInval(const SkIRect&) |
| 57 | { |
| 58 | SkEvent* evt = new SkEvent("inval-imageview"); |
| 59 | evt->post(getSinkID()); |
| 60 | } |
| 61 | |
| 62 | bool SkOSWindow::onEvent(const SkEvent& evt) |
| 63 | { |
| 64 | if (evt.isType("inval-imageview")) { |
| 65 | update(NULL); |
| 66 | doPaint(); |
| 67 | return true; |
| 68 | } |
| 69 | return INHERITED::onEvent(evt); |
| 70 | } |
| 71 | |
scroggo | 08526c0 | 2011-03-22 14:03:21 +0000 | [diff] [blame] | 72 | static bool convertBitmapToXImage(XImage& image, const SkBitmap& bitmap) |
| 73 | { |
scroggo | b66365f | 2011-03-18 21:43:03 +0000 | [diff] [blame] | 74 | sk_bzero(&image, sizeof(image)); |
| 75 | |
| 76 | int bitsPerPixel = bitmap.bytesPerPixel() * 8; |
| 77 | image.width = bitmap.width(); |
| 78 | image.height = bitmap.height(); |
| 79 | image.format = ZPixmap; |
| 80 | image.data = (char*) bitmap.getPixels(); |
| 81 | image.byte_order = LSBFirst; |
| 82 | image.bitmap_unit = bitsPerPixel; |
| 83 | image.bitmap_bit_order = LSBFirst; |
| 84 | image.bitmap_pad = bitsPerPixel; |
| 85 | image.depth = 24; |
| 86 | image.bytes_per_line = bitmap.rowBytes() - bitmap.width() * bitmap.bytesPerPixel(); |
| 87 | image.bits_per_pixel = bitsPerPixel; |
scroggo | 08526c0 | 2011-03-22 14:03:21 +0000 | [diff] [blame] | 88 | return XInitImage(&image); |
| 89 | } |
| 90 | |
scroggo | 08526c0 | 2011-03-22 14:03:21 +0000 | [diff] [blame] | 91 | void SkOSWindow::doPaint() { |
| 92 | if (!fUnixWindow.fDisplay) return; |
| 93 | // Draw the bitmap to the screen. |
| 94 | const SkBitmap& bitmap = getBitmap(); |
| 95 | int width = bitmap.width(); |
| 96 | int height = bitmap.height(); |
| 97 | |
Scroggo | 0f185c2 | 2011-03-24 18:35:50 +0000 | [diff] [blame^] | 98 | XImage image; |
| 99 | if (!convertBitmapToXImage(image, bitmap)) return; |
scroggo | 08526c0 | 2011-03-22 14:03:21 +0000 | [diff] [blame] | 100 | |
Scroggo | 0f185c2 | 2011-03-24 18:35:50 +0000 | [diff] [blame^] | 101 | XPutImage(fUnixWindow.fDisplay, fUnixWindow.fWin, fUnixWindow.fGc, &image, 0, 0, 0, 0, width, height); |
scroggo | b7e9aee | 2011-03-15 15:15:15 +0000 | [diff] [blame] | 102 | } |
| 103 | |
| 104 | bool SkOSWindow::onHandleChar(SkUnichar) |
| 105 | { |
| 106 | return false; |
| 107 | } |
| 108 | |
| 109 | bool SkOSWindow::onHandleKey(SkKey key) |
| 110 | { |
| 111 | return false; |
| 112 | } |
| 113 | |
| 114 | bool SkOSWindow::onHandleKeyUp(SkKey key) |
| 115 | { |
| 116 | return false; |
| 117 | } |