xref: /aosp_15_r20/external/angle/util/OSWindow.h (revision 8975f5c5ed3d1c378011245431ada316dfb6f244)
1 //
2 // Copyright 2014 The ANGLE Project Authors. All rights reserved.
3 // Use of this source code is governed by a BSD-style license that can be
4 // found in the LICENSE file.
5 //
6 // OSWindow:
7 //   Operating system window integration base class.
8 
9 #ifndef UTIL_OSWINDOW_H_
10 #define UTIL_OSWINDOW_H_
11 
12 #include <stdint.h>
13 #include <list>
14 #include <string>
15 
16 #include <EGL/egl.h>
17 #include <EGL/eglext.h>
18 
19 #include "util/Event.h"
20 #include "util/util_export.h"
21 
22 class ANGLE_UTIL_EXPORT OSWindow
23 {
24   public:
25     static OSWindow *New();
26     static void Delete(OSWindow **osWindow);
27 
28     bool initialize(const std::string &name, int width, int height);
29     virtual void destroy()                   = 0;
30     virtual void disableErrorMessageDialog() = 0;
31 
32     int getX() const;
33     int getY() const;
34     int getWidth() const;
35     int getHeight() const;
36 
37     // Takes a screenshot of the window, returning the result as a mWidth * mHeight * 4
38     // normalized unsigned byte BGRA array. Note that it will be used to test the window
39     // manager's behavior so it needs to take an actual screenshot of the screen and not
40     // just grab the pixels of the window. Returns if it was successful.
41     virtual bool takeScreenshot(uint8_t *pixelData);
42 
43     // Re-initializes the native window. This is used on platforms which do not
44     // have a reusable EGLNativeWindowType in order to recreate it, and is
45     // needed by the test suite because it re-uses the same OSWindow for
46     // multiple EGLSurfaces.
47     virtual void resetNativeWindow() = 0;
48 
49     virtual EGLNativeWindowType getNativeWindow() const = 0;
50 
51     // Returns a native pointer that can be used for eglCreatePlatformWindowSurfaceEXT().
52     virtual void *getPlatformExtension();
53 
setNativeDisplay(EGLNativeDisplayType display)54     virtual void setNativeDisplay(EGLNativeDisplayType display) {}
55     virtual EGLNativeDisplayType getNativeDisplay() const = 0;
56 
57     virtual void messageLoop() = 0;
58 
59     bool popEvent(Event *event);
60     virtual void pushEvent(Event event);
61 
62     virtual void setMousePosition(int x, int y)        = 0;
63     virtual bool setOrientation(int width, int height) = 0;
64     virtual bool setPosition(int x, int y)             = 0;
65     virtual bool resize(int width, int height)         = 0;
66     virtual void setVisible(bool isVisible)            = 0;
67 
68     virtual void signalTestEvent() = 0;
69 
70     // Pops events look for the test event
71     bool didTestEventFire();
72 
73     // Whether window has been successfully initialized.
valid()74     bool valid() const { return mValid; }
75 
ignoreSizeEvents()76     void ignoreSizeEvents() { mIgnoreSizeEvents = true; }
77 
78   protected:
79     OSWindow();
80     virtual ~OSWindow();
81 
82     virtual bool initializeImpl(const std::string &name, int width, int height) = 0;
83 
84     int mX;
85     int mY;
86     int mWidth;
87     int mHeight;
88 
89     std::list<Event> mEvents;
90 
91     bool mValid;
92     bool mIgnoreSizeEvents;
93 };
94 
95 namespace angle
96 {
97 // Find a test data file or directory.
98 ANGLE_UTIL_EXPORT bool FindTestDataPath(const char *searchPath,
99                                         char *dataPathOut,
100                                         size_t maxDataPathOutLen);
101 }  // namespace angle
102 
103 #endif  // UTIL_OSWINDOW_H_
104