blob: 803ca1303d2c90dcc9fb3cc912a5e0238dee5f9e [file] [log] [blame]
reed@android.com8a1c16f2008-12-17 15:59:43 +00001/*
2 * Copyright (C) 2006 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17#ifndef SkOSWindow_Unix_DEFINED
18#define SkOSWindow_Unix_DEFINED
19
20#include "SkWindow.h"
21#include <X11/Xlib.h>
Scroggo9df214e2011-04-15 14:48:08 +000022#include <GL/glx.h>
reed@android.com8a1c16f2008-12-17 15:59:43 +000023
scroggob7e9aee2011-03-15 15:15:15 +000024class SkBitmap;
25class SkEvent;
26
reed@android.com8a1c16f2008-12-17 15:59:43 +000027struct SkUnixWindow {
28 Display* fDisplay;
29 Window fWin;
30 size_t fOSWin;
scroggob7e9aee2011-03-15 15:15:15 +000031 GC fGc;
Scroggo9df214e2011-04-15 14:48:08 +000032 GLXContext fGLContext;
33 bool fGLCreated;
reed@android.com8a1c16f2008-12-17 15:59:43 +000034};
35
36class SkOSWindow : public SkWindow {
37public:
scroggob7e9aee2011-03-15 15:15:15 +000038 SkOSWindow(void*);
39 ~SkOSWindow();
reed@android.com8a1c16f2008-12-17 15:59:43 +000040
scroggob7e9aee2011-03-15 15:15:15 +000041 void* getHWND() const { return (void*)fUnixWindow.fWin; }
42 void* getDisplay() const { return (void*)fUnixWindow.fDisplay; }
43 void* getUnixWindow() const { return (void*)&fUnixWindow; }
Scroggo9df214e2011-04-15 14:48:08 +000044 void loop();
45 void post_linuxevent();
bsalomon@google.comc8ad63e2011-03-18 14:29:44 +000046 bool attachGL();
scroggob7e9aee2011-03-15 15:15:15 +000047 void detachGL();
48 void presentGL();
reed@android.com8a1c16f2008-12-17 15:59:43 +000049
scroggob7e9aee2011-03-15 15:15:15 +000050 //static bool PostEvent(SkEvent* evt, SkEventSinkID, SkMSec delay);
reed@android.com8a1c16f2008-12-17 15:59:43 +000051
scroggob7e9aee2011-03-15 15:15:15 +000052 //static bool WndProc(SkUnixWindow* w, XEvent &e);
reed@android.com8a1c16f2008-12-17 15:59:43 +000053
54protected:
55 // overrides from SkWindow
scroggob7e9aee2011-03-15 15:15:15 +000056 virtual bool onEvent(const SkEvent&);
reed@android.com8a1c16f2008-12-17 15:59:43 +000057 virtual void onHandleInval(const SkIRect&);
scroggob7e9aee2011-03-15 15:15:15 +000058 virtual bool onHandleChar(SkUnichar);
59 virtual bool onHandleKey(SkKey);
60 virtual bool onHandleKeyUp(SkKey);
61 virtual void onSetTitle(const char title[]);
reed@android.com8a1c16f2008-12-17 15:59:43 +000062
63private:
64 SkUnixWindow fUnixWindow;
Scroggo9df214e2011-04-15 14:48:08 +000065 bool fGLAttached;
66 bool fRestart;
67
68 // Needed for GL
69 XVisualInfo* fVi;
reed@android.com8a1c16f2008-12-17 15:59:43 +000070
71 void doPaint();
Scroggo9df214e2011-04-15 14:48:08 +000072 void restartLoop();
73 void mapWindowAndWait();
reed@android.com8a1c16f2008-12-17 15:59:43 +000074
reed@android.com8a1c16f2008-12-17 15:59:43 +000075 typedef SkWindow INHERITED;
76};
77
78#endif
79