OSWindow.h 2.98 KB
Newer Older
Geoff Lang's avatar
Geoff Lang committed
1
//
2
// Copyright 2014 The ANGLE Project Authors. All rights reserved.
Geoff Lang's avatar
Geoff Lang committed
3
4
5
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
//
6
7
// OSWindow:
//   Operating system window integration base class.
Geoff Lang's avatar
Geoff Lang committed
8

9
10
#ifndef UTIL_OSWINDOW_H_
#define UTIL_OSWINDOW_H_
Geoff Lang's avatar
Geoff Lang committed
11

12
#include <stdint.h>
13
#include <list>
14
#include <string>
Geoff Lang's avatar
Geoff Lang committed
15

16
17
#include <EGL/egl.h>
#include <EGL/eglext.h>
18

19
20
#include "util/Event.h"
#include "util/util_export.h"
Geoff Lang's avatar
Geoff Lang committed
21

22
class ANGLE_UTIL_EXPORT OSWindow
Geoff Lang's avatar
Geoff Lang committed
23
24
{
  public:
25
26
    static OSWindow *New();
    static void Delete(OSWindow **osWindow);
Geoff Lang's avatar
Geoff Lang committed
27

28
29
30
    bool initialize(const std::string &name, int width, int height);
    virtual void destroy()                   = 0;
    virtual void disableErrorMessageDialog() = 0;
Geoff Lang's avatar
Geoff Lang committed
31

32
33
    int getX() const;
    int getY() const;
Geoff Lang's avatar
Geoff Lang committed
34
35
36
    int getWidth() const;
    int getHeight() const;

37
38
39
40
    // Takes a screenshot of the window, returning the result as a mWidth * mHeight * 4
    // normalized unsigned byte BGRA array. Note that it will be used to test the window
    // manager's behavior so it needs to take an actual screenshot of the screen and not
    // just grab the pixels of the window. Returns if it was successful.
Jamie Madill's avatar
Jamie Madill committed
41
    virtual bool takeScreenshot(uint8_t *pixelData);
42

43
44
45
46
47
48
    // Re-initializes the native window. This is used on platforms which do not
    // have a reusable EGLNativeWindowType in order to recreate it, and is
    // needed by the test suite because it re-uses the same OSWindow for
    // multiple EGLSurfaces.
    virtual void resetNativeWindow() = 0;

49
50
51
52
53
    virtual EGLNativeWindowType getNativeWindow() const = 0;

    // Returns a native pointer that can be used for eglCreatePlatformWindowSurfaceEXT().
    virtual void *getPlatformExtension();

Geoff Lang's avatar
Geoff Lang committed
54
55
56
57
58
    virtual EGLNativeDisplayType getNativeDisplay() const = 0;

    virtual void messageLoop() = 0;

    bool popEvent(Event *event);
59
    virtual void pushEvent(Event event);
Geoff Lang's avatar
Geoff Lang committed
60

61
62
63
64
65
    virtual void setMousePosition(int x, int y)        = 0;
    virtual bool setOrientation(int width, int height) = 0;
    virtual bool setPosition(int x, int y)             = 0;
    virtual bool resize(int width, int height)         = 0;
    virtual void setVisible(bool isVisible)            = 0;
66

67
68
69
70
71
    virtual void signalTestEvent() = 0;

    // Pops events look for the test event
    bool didTestEventFire();

72
73
74
    // Whether window has been successfully initialized.
    bool valid() const { return mValid; }

Jamie Madill's avatar
Jamie Madill committed
75
76
    void ignoreSizeEvents() { mIgnoreSizeEvents = true; }

77
  protected:
78
79
80
    OSWindow();
    virtual ~OSWindow();

81
82
    virtual bool initializeImpl(const std::string &name, int width, int height) = 0;

83
84
    int mX;
    int mY;
Geoff Lang's avatar
Geoff Lang committed
85
86
87
88
    int mWidth;
    int mHeight;

    std::list<Event> mEvents;
89
90

    bool mValid;
Jamie Madill's avatar
Jamie Madill committed
91
    bool mIgnoreSizeEvents;
Geoff Lang's avatar
Geoff Lang committed
92
93
};

94
95
96
97
98
99
100
101
namespace angle
{
// Find a test data file or directory.
ANGLE_UTIL_EXPORT bool FindTestDataPath(const char *searchPath,
                                        char *dataPathOut,
                                        size_t maxDataPathOutLen);
}  // namespace angle

102
#endif  // UTIL_OSWINDOW_H_