blob: 8a55ef455ef1f98892345a4d11efba03718a8b74 [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();
robertphillips@google.comb442a6d2012-04-02 19:24:21 +000035
36 enum SkBackEndTypes {
37 kNone_BackEndType,
38 kNativeGL_BackEndType,
39 };
40
bsalomon@google.com64cc8102013-03-05 20:06:05 +000041 struct AttachmentInfo {
42 int fSampleCount;
43 int fStencilBits;
44 };
45
46 bool attach(SkBackEndTypes attachType, int msaaSampleCount, AttachmentInfo*);
robertphillips@google.comb442a6d2012-04-02 19:24:21 +000047 void detach();
48 void present();
reed@android.com8a1c16f2008-12-17 15:59:43 +000049
bsalomon@google.com11959252012-04-06 20:13:38 +000050 int getMSAASampleCount() const { return fMSAASampleCount; }
51
scroggob7e9aee2011-03-15 15:15:15 +000052 //static bool PostEvent(SkEvent* evt, SkEventSinkID, SkMSec delay);
reed@android.com8a1c16f2008-12-17 15:59:43 +000053
reed@android.com8a1c16f2008-12-17 15:59:43 +000054protected:
tomhudson@google.com178b8e02012-03-05 18:29:23 +000055 // Overridden from from SkWindow:
tomhudson@google.com178b8e02012-03-05 18:29:23 +000056 virtual void onSetTitle(const char title[]) SK_OVERRIDE;
reed@android.com8a1c16f2008-12-17 15:59:43 +000057
58private:
reed@google.comacb3d882013-06-17 13:42:43 +000059 enum NextXEventResult {
60 kContinue_NextXEventResult,
61 kQuitRequest_NextXEventResult,
62 kPaintRequest_NextXEventResult
63 };
64
65 NextXEventResult nextXEvent();
tomhudson@google.com178b8e02012-03-05 18:29:23 +000066 void doPaint();
67 void mapWindowAndWait();
68
bsalomon@google.com11959252012-04-06 20:13:38 +000069 void closeWindow();
bsalomon@google.com64cc8102013-03-05 20:06:05 +000070 void initWindow(int newMSAASampleCount, AttachmentInfo* info);
bsalomon@google.com11959252012-04-06 20:13:38 +000071
tomhudson@google.com178b8e02012-03-05 18:29:23 +000072 SkUnixWindow fUnixWindow;
Scroggo9df214e2011-04-15 14:48:08 +000073
74 // Needed for GL
75 XVisualInfo* fVi;
bsalomon@google.com11959252012-04-06 20:13:38 +000076 // we recreate the underlying xwindow if this changes
77 int fMSAASampleCount;
reed@android.com8a1c16f2008-12-17 15:59:43 +000078
reed@android.com8a1c16f2008-12-17 15:59:43 +000079 typedef SkWindow INHERITED;
80};
81
82#endif