reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 1 | /* |
| 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> |
Scroggo | 9df214e | 2011-04-15 14:48:08 +0000 | [diff] [blame^] | 22 | #include <GL/glx.h> |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 23 | |
scroggo | b7e9aee | 2011-03-15 15:15:15 +0000 | [diff] [blame] | 24 | class SkBitmap; |
| 25 | class SkEvent; |
| 26 | |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 27 | struct SkUnixWindow { |
| 28 | Display* fDisplay; |
| 29 | Window fWin; |
| 30 | size_t fOSWin; |
scroggo | b7e9aee | 2011-03-15 15:15:15 +0000 | [diff] [blame] | 31 | GC fGc; |
Scroggo | 9df214e | 2011-04-15 14:48:08 +0000 | [diff] [blame^] | 32 | GLXContext fGLContext; |
| 33 | bool fGLCreated; |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 34 | }; |
| 35 | |
| 36 | class SkOSWindow : public SkWindow { |
| 37 | public: |
scroggo | b7e9aee | 2011-03-15 15:15:15 +0000 | [diff] [blame] | 38 | SkOSWindow(void*); |
| 39 | ~SkOSWindow(); |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 40 | |
scroggo | b7e9aee | 2011-03-15 15:15:15 +0000 | [diff] [blame] | 41 | void* getHWND() const { return (void*)fUnixWindow.fWin; } |
| 42 | void* getDisplay() const { return (void*)fUnixWindow.fDisplay; } |
| 43 | void* getUnixWindow() const { return (void*)&fUnixWindow; } |
Scroggo | 9df214e | 2011-04-15 14:48:08 +0000 | [diff] [blame^] | 44 | void loop(); |
| 45 | void post_linuxevent(); |
bsalomon@google.com | c8ad63e | 2011-03-18 14:29:44 +0000 | [diff] [blame] | 46 | bool attachGL(); |
scroggo | b7e9aee | 2011-03-15 15:15:15 +0000 | [diff] [blame] | 47 | void detachGL(); |
| 48 | void presentGL(); |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 49 | |
scroggo | b7e9aee | 2011-03-15 15:15:15 +0000 | [diff] [blame] | 50 | //static bool PostEvent(SkEvent* evt, SkEventSinkID, SkMSec delay); |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 51 | |
scroggo | b7e9aee | 2011-03-15 15:15:15 +0000 | [diff] [blame] | 52 | //static bool WndProc(SkUnixWindow* w, XEvent &e); |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 53 | |
| 54 | protected: |
| 55 | // overrides from SkWindow |
scroggo | b7e9aee | 2011-03-15 15:15:15 +0000 | [diff] [blame] | 56 | virtual bool onEvent(const SkEvent&); |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 57 | virtual void onHandleInval(const SkIRect&); |
scroggo | b7e9aee | 2011-03-15 15:15:15 +0000 | [diff] [blame] | 58 | virtual bool onHandleChar(SkUnichar); |
| 59 | virtual bool onHandleKey(SkKey); |
| 60 | virtual bool onHandleKeyUp(SkKey); |
| 61 | virtual void onSetTitle(const char title[]); |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 62 | |
| 63 | private: |
| 64 | SkUnixWindow fUnixWindow; |
Scroggo | 9df214e | 2011-04-15 14:48:08 +0000 | [diff] [blame^] | 65 | bool fGLAttached; |
| 66 | bool fRestart; |
| 67 | |
| 68 | // Needed for GL |
| 69 | XVisualInfo* fVi; |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 70 | |
| 71 | void doPaint(); |
Scroggo | 9df214e | 2011-04-15 14:48:08 +0000 | [diff] [blame^] | 72 | void restartLoop(); |
| 73 | void mapWindowAndWait(); |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 74 | |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 75 | typedef SkWindow INHERITED; |
| 76 | }; |
| 77 | |
| 78 | #endif |
| 79 | |