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