blob: e1961316e49dbb8c87e15df2725f3161d69be8f5 [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*);
Yuqian Li6e3d9952017-09-27 13:25:36 -040029 SkOSWindow(void*, int width, int height);
Brian Salomond3b65972017-03-22 12:05:03 -040030 ~SkOSWindow() override;
reed@android.com8a1c16f2008-12-17 15:59:43 +000031
scroggob7e9aee2011-03-15 15:15:15 +000032 void* getHWND() const { return (void*)fUnixWindow.fWin; }
33 void* getDisplay() const { return (void*)fUnixWindow.fDisplay; }
34 void* getUnixWindow() const { return (void*)&fUnixWindow; }
Scroggo9df214e2011-04-15 14:48:08 +000035 void loop();
robertphillips@google.comb442a6d2012-04-02 19:24:21 +000036
37 enum SkBackEndTypes {
38 kNone_BackEndType,
39 kNativeGL_BackEndType,
hendrikw6f0fdac2015-09-23 11:35:55 -070040#if SK_ANGLE
41 kANGLE_BackEndType,
42#endif // SK_ANGLE
robertphillips@google.comb442a6d2012-04-02 19:24:21 +000043 };
44
brianosman2d1ee792016-05-05 12:24:31 -070045 bool attach(SkBackEndTypes attachType, int msaaSampleCount, bool deepColor, AttachmentInfo*);
mtklein18300a32016-03-16 13:53:35 -070046 void release();
robertphillips@google.comb442a6d2012-04-02 19:24:21 +000047 void present();
reed@android.com8a1c16f2008-12-17 15:59:43 +000048
bsalomon@google.com11959252012-04-06 20:13:38 +000049 int getMSAASampleCount() const { return fMSAASampleCount; }
50
scroggob7e9aee2011-03-15 15:15:15 +000051 //static bool PostEvent(SkEvent* evt, SkEventSinkID, SkMSec delay);
reed@android.com8a1c16f2008-12-17 15:59:43 +000052
bsalomon85ab5512015-06-16 12:47:25 -070053 bool makeFullscreen();
54 void setVsync(bool);
55 void closeWindow();
joshualittda7b8432015-05-27 09:19:03 -070056
reed@android.com8a1c16f2008-12-17 15:59:43 +000057protected:
tomhudson@google.com178b8e02012-03-05 18:29:23 +000058 // Overridden from from SkWindow:
mtklein36352bf2015-03-25 18:17:31 -070059 void onSetTitle(const char title[]) override;
reed@android.com8a1c16f2008-12-17 15:59:43 +000060
61private:
reed@google.comacb3d882013-06-17 13:42:43 +000062 enum NextXEventResult {
63 kContinue_NextXEventResult,
64 kQuitRequest_NextXEventResult,
65 kPaintRequest_NextXEventResult
66 };
67
68 NextXEventResult nextXEvent();
tomhudson@google.com178b8e02012-03-05 18:29:23 +000069 void doPaint();
70 void mapWindowAndWait();
71
joshualitt7fe8ee42015-06-01 10:03:54 -070072 // Forcefully closes the window. If a graceful shutdown is desired then call the public
73 // closeWindow method
74 void internalCloseWindow();
Yuqian Li6e3d9952017-09-27 13:25:36 -040075 void initWindow(int newMSAASampleCount, AttachmentInfo* info, int w, int h);
76 void init(int w, int h);
bsalomon@google.com11959252012-04-06 20:13:38 +000077
tomhudson@google.com178b8e02012-03-05 18:29:23 +000078 SkUnixWindow fUnixWindow;
Scroggo9df214e2011-04-15 14:48:08 +000079
80 // Needed for GL
81 XVisualInfo* fVi;
bsalomon@google.com11959252012-04-06 20:13:38 +000082 // we recreate the underlying xwindow if this changes
83 int fMSAASampleCount;
reed@android.com8a1c16f2008-12-17 15:59:43 +000084
reed@android.com8a1c16f2008-12-17 15:59:43 +000085 typedef SkWindow INHERITED;
86};
87
88#endif