blob: d9675799d2387a8e543fb325eefb6e33165b7811 [file] [log] [blame]
reed@android.com8a1c16f2008-12-17 15:59:43 +00001/*
epoger@google.comec3ed6a2011-07-28 14:26:00 +00002 * Copyright 2006 The Android Open Source Project
reed@android.com8a1c16f2008-12-17 15:59:43 +00003 *
epoger@google.comec3ed6a2011-07-28 14:26:00 +00004 * Use of this source code is governed by a BSD-style license that can be
5 * found in the LICENSE file.
reed@android.com8a1c16f2008-12-17 15:59:43 +00006 */
7
8#ifndef SkOSWindow_Unix_DEFINED
9#define SkOSWindow_Unix_DEFINED
10
Scroggo9df214e2011-04-15 14:48:08 +000011#include <GL/glx.h>
tomhudson@google.com178b8e02012-03-05 18:29:23 +000012#include <X11/Xlib.h>
reed@android.com8a1c16f2008-12-17 15:59:43 +000013
tomhudson@google.com178b8e02012-03-05 18:29:23 +000014#include "SkWindow.h"
15
scroggob7e9aee2011-03-15 15:15:15 +000016class SkEvent;
17
reed@android.com8a1c16f2008-12-17 15:59:43 +000018struct SkUnixWindow {
19 Display* fDisplay;
20 Window fWin;
21 size_t fOSWin;
scroggob7e9aee2011-03-15 15:15:15 +000022 GC fGc;
Scroggo9df214e2011-04-15 14:48:08 +000023 GLXContext fGLContext;
reed@android.com8a1c16f2008-12-17 15:59:43 +000024};
25
26class SkOSWindow : public SkWindow {
27public:
scroggob7e9aee2011-03-15 15:15:15 +000028 SkOSWindow(void*);
29 ~SkOSWindow();
reed@android.com8a1c16f2008-12-17 15:59:43 +000030
scroggob7e9aee2011-03-15 15:15:15 +000031 void* getHWND() const { return (void*)fUnixWindow.fWin; }
32 void* getDisplay() const { return (void*)fUnixWindow.fDisplay; }
33 void* getUnixWindow() const { return (void*)&fUnixWindow; }
Scroggo9df214e2011-04-15 14:48:08 +000034 void loop();
35 void post_linuxevent();
robertphillips@google.comb442a6d2012-04-02 19:24:21 +000036
37 enum SkBackEndTypes {
38 kNone_BackEndType,
39 kNativeGL_BackEndType,
40 };
41
bsalomon@google.com11959252012-04-06 20:13:38 +000042 bool attach(SkBackEndTypes attachType, int msaaSampleCount);
robertphillips@google.comb442a6d2012-04-02 19:24:21 +000043 void detach();
44 void present();
reed@android.com8a1c16f2008-12-17 15:59:43 +000045
bsalomon@google.com11959252012-04-06 20:13:38 +000046 int getMSAASampleCount() const { return fMSAASampleCount; }
47
scroggob7e9aee2011-03-15 15:15:15 +000048 //static bool PostEvent(SkEvent* evt, SkEventSinkID, SkMSec delay);
reed@android.com8a1c16f2008-12-17 15:59:43 +000049
scroggob7e9aee2011-03-15 15:15:15 +000050 //static bool WndProc(SkUnixWindow* w, XEvent &e);
reed@android.com8a1c16f2008-12-17 15:59:43 +000051
52protected:
tomhudson@google.com178b8e02012-03-05 18:29:23 +000053 // Overridden from from SkWindow:
54 virtual bool onEvent(const SkEvent&) SK_OVERRIDE;
55 virtual void onHandleInval(const SkIRect&) SK_OVERRIDE;
56 virtual bool onHandleChar(SkUnichar) SK_OVERRIDE;
57 virtual bool onHandleKey(SkKey) SK_OVERRIDE;
58 virtual bool onHandleKeyUp(SkKey) SK_OVERRIDE;
59 virtual void onSetTitle(const char title[]) SK_OVERRIDE;
reed@android.com8a1c16f2008-12-17 15:59:43 +000060
61private:
tomhudson@google.com178b8e02012-03-05 18:29:23 +000062 void doPaint();
63 void mapWindowAndWait();
64
bsalomon@google.com11959252012-04-06 20:13:38 +000065 void closeWindow();
66 void initWindow(int newMSAASampleCount);
67
tomhudson@google.com178b8e02012-03-05 18:29:23 +000068 SkUnixWindow fUnixWindow;
Scroggo9df214e2011-04-15 14:48:08 +000069
70 // Needed for GL
71 XVisualInfo* fVi;
bsalomon@google.com11959252012-04-06 20:13:38 +000072 // we recreate the underlying xwindow if this changes
73 int fMSAASampleCount;
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