blob: 650ced28b0d7ed3ce5813a73b05152bc3f125e02 [file] [log] [blame]
scroggob7e9aee2011-03-15 15:15:15 +00001#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
12SkOSWindow::SkOSWindow(void* unused)
13{
14 fUnixWindow.fDisplay = NULL;
15}
16
17SkOSWindow::~SkOSWindow()
18{
19}
20
21void 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.comc8ad63e2011-03-18 14:29:44 +000029bool SkOSWindow::attachGL()
scroggob7e9aee2011-03-15 15:15:15 +000030{
31 return false;
32}
33
34void SkOSWindow::detachGL()
35{
36
37}
38
39void SkOSWindow::presentGL()
40{
41
42}
43
44void 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
55void SkOSWindow::onHandleInval(const SkIRect&)
56{
57 SkEvent* evt = new SkEvent("inval-imageview");
58 evt->post(getSinkID());
59}
60
61bool 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
71void SkOSWindow::doPaint() {
72 if (!fUnixWindow.fDisplay) return;
73 // Draw the bitmap to the screen.
74 const SkBitmap& bitmap = getBitmap();
scroggob66365f2011-03-18 21:43:03 +000075
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());
scroggob7e9aee2011-03-15 15:15:15 +000093}
94
95bool SkOSWindow::onHandleChar(SkUnichar)
96{
97 return false;
98}
99
100bool SkOSWindow::onHandleKey(SkKey key)
101{
102 return false;
103}
104
105bool SkOSWindow::onHandleKeyUp(SkKey key)
106{
107 return false;
108}