Nicolas Capens | 0bac285 | 2016-05-07 06:09:58 -0400 | [diff] [blame] | 1 | // Copyright 2016 The SwiftShader Authors. All Rights Reserved. |
| 2 | // |
| 3 | // Licensed under the Apache License, Version 2.0 (the "License"); |
| 4 | // you may not use this file except in compliance with the License. |
| 5 | // You may obtain a copy of the License at |
| 6 | // |
| 7 | // http://www.apache.org/licenses/LICENSE-2.0 |
| 8 | // |
| 9 | // Unless required by applicable law or agreed to in writing, software |
| 10 | // distributed under the License is distributed on an "AS IS" BASIS, |
| 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 12 | // See the License for the specific language governing permissions and |
| 13 | // limitations under the License. |
| 14 | |
Nicolas Capens | 31c07a3 | 2017-06-13 23:44:13 -0400 | [diff] [blame] | 15 | // Surface.hpp: Defines the egl::Surface class, representing a rendering surface |
Nicolas Capens | 0bac285 | 2016-05-07 06:09:58 -0400 | [diff] [blame] | 16 | // such as the client area of a window, including any back buffers. |
| 17 | // Implements EGLSurface and related functionality. [EGL 1.4] section 2.2 page 3. |
| 18 | |
Nicolas Capens | 31c07a3 | 2017-06-13 23:44:13 -0400 | [diff] [blame] | 19 | #ifndef INCLUDE_EGL_SURFACE_H_ |
| 20 | #define INCLUDE_EGL_SURFACE_H_ |
| 21 | |
| 22 | #include "common/Object.hpp" |
| 23 | #include "common/Surface.hpp" |
Nicolas Capens | 0bac285 | 2016-05-07 06:09:58 -0400 | [diff] [blame] | 24 | |
| 25 | #include "Main/FrameBuffer.hpp" |
Nicolas Capens | 0bac285 | 2016-05-07 06:09:58 -0400 | [diff] [blame] | 26 | |
| 27 | #include <EGL/egl.h> |
| 28 | |
| 29 | namespace egl |
| 30 | { |
| 31 | class Display; |
| 32 | class Config; |
Nicolas Capens | 0bac285 | 2016-05-07 06:09:58 -0400 | [diff] [blame] | 33 | |
Nicolas Capens | 31c07a3 | 2017-06-13 23:44:13 -0400 | [diff] [blame] | 34 | class Surface : public gl::Surface, public gl::Object |
Nicolas Capens | 0bac285 | 2016-05-07 06:09:58 -0400 | [diff] [blame] | 35 | { |
| 36 | public: |
| 37 | virtual bool initialize(); |
| 38 | virtual void swap() = 0; |
| 39 | |
Nicolas Capens | 31c07a3 | 2017-06-13 23:44:13 -0400 | [diff] [blame] | 40 | egl::Image *getRenderTarget() override; |
| 41 | egl::Image *getDepthStencil() override; |
Nicolas Capens | 0bac285 | 2016-05-07 06:09:58 -0400 | [diff] [blame] | 42 | |
Nicolas Capens | c8eedeb | 2018-04-12 12:50:21 -0400 | [diff] [blame] | 43 | void setMipmapLevel(EGLint mipmapLevel); |
| 44 | void setMultisampleResolve(EGLenum multisampleResolve); |
Nicolas Capens | 0bac285 | 2016-05-07 06:09:58 -0400 | [diff] [blame] | 45 | void setSwapBehavior(EGLenum swapBehavior); |
| 46 | void setSwapInterval(EGLint interval); |
| 47 | |
| 48 | virtual EGLint getConfigID() const; |
| 49 | virtual EGLenum getSurfaceType() const; |
Nicolas Capens | 0bac285 | 2016-05-07 06:09:58 -0400 | [diff] [blame] | 50 | |
Nicolas Capens | 31c07a3 | 2017-06-13 23:44:13 -0400 | [diff] [blame] | 51 | EGLint getWidth() const override; |
| 52 | EGLint getHeight() const override; |
Alexis Hetu | c80eada | 2018-02-13 15:02:40 -0500 | [diff] [blame] | 53 | EGLenum getTextureTarget() const override; |
Nicolas Capens | c8eedeb | 2018-04-12 12:50:21 -0400 | [diff] [blame] | 54 | virtual EGLint getMipmapLevel() const; |
| 55 | virtual EGLenum getMultisampleResolve() const; |
Nicolas Capens | 0bac285 | 2016-05-07 06:09:58 -0400 | [diff] [blame] | 56 | virtual EGLint getPixelAspectRatio() const; |
| 57 | virtual EGLenum getRenderBuffer() const; |
| 58 | virtual EGLenum getSwapBehavior() const; |
| 59 | virtual EGLenum getTextureFormat() const; |
Nicolas Capens | 0bac285 | 2016-05-07 06:09:58 -0400 | [diff] [blame] | 60 | virtual EGLBoolean getLargestPBuffer() const; |
| 61 | virtual EGLNativeWindowType getWindowHandle() const = 0; |
| 62 | |
Nicolas Capens | 31c07a3 | 2017-06-13 23:44:13 -0400 | [diff] [blame] | 63 | void setBoundTexture(egl::Texture *texture) override; |
Nicolas Capens | 0bac285 | 2016-05-07 06:09:58 -0400 | [diff] [blame] | 64 | virtual egl::Texture *getBoundTexture() const; |
| 65 | |
| 66 | virtual bool isWindowSurface() const { return false; } |
| 67 | virtual bool isPBufferSurface() const { return false; } |
Alexis Hetu | c80eada | 2018-02-13 15:02:40 -0500 | [diff] [blame] | 68 | bool hasClientBuffer() const { return clientBuffer != nullptr; } |
Nicolas Capens | 0bac285 | 2016-05-07 06:09:58 -0400 | [diff] [blame] | 69 | |
| 70 | protected: |
| 71 | Surface(const Display *display, const Config *config); |
| 72 | |
Nicolas Capens | 31c07a3 | 2017-06-13 23:44:13 -0400 | [diff] [blame] | 73 | ~Surface() override; |
Nicolas Capens | 0bac285 | 2016-05-07 06:09:58 -0400 | [diff] [blame] | 74 | |
| 75 | virtual void deleteResources(); |
| 76 | |
Alexis Hetu | c80eada | 2018-02-13 15:02:40 -0500 | [diff] [blame] | 77 | sw::Format getClientBufferFormat() const; |
| 78 | |
Nicolas Capens | 0bac285 | 2016-05-07 06:09:58 -0400 | [diff] [blame] | 79 | const Display *const display; |
Nicolas Capens | c8eedeb | 2018-04-12 12:50:21 -0400 | [diff] [blame] | 80 | const Config *const config; |
| 81 | |
| 82 | Image *depthStencil = nullptr; |
| 83 | Image *backBuffer = nullptr; |
| 84 | Texture *texture = nullptr; |
Nicolas Capens | 0bac285 | 2016-05-07 06:09:58 -0400 | [diff] [blame] | 85 | |
| 86 | bool reset(int backbufferWidth, int backbufferHeight); |
| 87 | |
Nicolas Capens | c8eedeb | 2018-04-12 12:50:21 -0400 | [diff] [blame] | 88 | // Surface attributes: |
| 89 | EGLint width = 0; // Width of surface |
| 90 | EGLint height= 0; // Height of surface |
| 91 | // EGLint horizontalResolution = EGL_UNKNOWN; // Horizontal dot pitch |
| 92 | // EGLint verticalResolution = EGL_UNKNOWN; // Vertical dot pitch |
| 93 | EGLBoolean largestPBuffer = EGL_FALSE; // If true, create largest pbuffer possible |
| 94 | // EGLBoolean mipmapTexture = EGL_FALSE; // True if texture has mipmaps |
| 95 | EGLint mipmapLevel = 0; // Mipmap level to render to |
| 96 | EGLenum multisampleResolve = EGL_MULTISAMPLE_RESOLVE_DEFAULT; // Multisample resolve behavior |
| 97 | EGLint pixelAspectRatio = EGL_UNKNOWN; // Display aspect ratio |
| 98 | EGLenum renderBuffer = EGL_BACK_BUFFER; // Render buffer |
| 99 | EGLenum swapBehavior = EGL_BUFFER_PRESERVED; // Buffer swap behavior (initial value chosen by implementation) |
| 100 | EGLenum textureFormat = EGL_NO_TEXTURE; // Format of texture: RGB, RGBA, or no texture |
| 101 | EGLenum textureTarget = EGL_NO_TEXTURE; // Type of texture: 2D or no texture |
| 102 | // EGLenum vgAlphaFormat = EGL_VG_ALPHA_FORMAT_NONPRE; // Alpha format for OpenVG |
| 103 | // EGLenum vgColorSpace = EGL_VG_COLORSPACE_sRGB; // Color space for OpenVG |
| 104 | |
| 105 | EGLint swapInterval = 1; |
| 106 | |
| 107 | // EGL_ANGLE_iosurface_client_buffer attributes: |
| 108 | EGLClientBuffer clientBuffer = nullptr; |
| 109 | EGLint clientBufferPlane; |
Alexis Hetu | c80eada | 2018-02-13 15:02:40 -0500 | [diff] [blame] | 110 | EGLenum clientBufferFormat; // Format of the client buffer |
| 111 | EGLenum clientBufferType; // Type of the client buffer |
Nicolas Capens | 0bac285 | 2016-05-07 06:09:58 -0400 | [diff] [blame] | 112 | }; |
| 113 | |
| 114 | class WindowSurface : public Surface |
| 115 | { |
| 116 | public: |
| 117 | WindowSurface(Display *display, const egl::Config *config, EGLNativeWindowType window); |
| 118 | ~WindowSurface() override; |
| 119 | |
| 120 | bool initialize() override; |
| 121 | |
| 122 | bool isWindowSurface() const override { return true; } |
| 123 | void swap() override; |
| 124 | |
| 125 | EGLNativeWindowType getWindowHandle() const override; |
| 126 | |
| 127 | private: |
| 128 | void deleteResources() override; |
| 129 | bool checkForResize(); |
| 130 | bool reset(int backBufferWidth, int backBufferHeight); |
| 131 | |
| 132 | const EGLNativeWindowType window; |
Nicolas Capens | c8eedeb | 2018-04-12 12:50:21 -0400 | [diff] [blame] | 133 | sw::FrameBuffer *frameBuffer = nullptr; |
Nicolas Capens | 0bac285 | 2016-05-07 06:09:58 -0400 | [diff] [blame] | 134 | }; |
| 135 | |
| 136 | class PBufferSurface : public Surface |
| 137 | { |
| 138 | public: |
Alexis Hetu | c80eada | 2018-02-13 15:02:40 -0500 | [diff] [blame] | 139 | PBufferSurface(Display *display, const egl::Config *config, EGLint width, EGLint height, |
| 140 | EGLenum textureFormat, EGLenum textureTarget, EGLenum internalFormat, |
| 141 | EGLenum textureType, EGLBoolean largestPBuffer, EGLClientBuffer clientBuffer, |
| 142 | EGLint clientBufferPlane); |
Nicolas Capens | 0bac285 | 2016-05-07 06:09:58 -0400 | [diff] [blame] | 143 | ~PBufferSurface() override; |
| 144 | |
| 145 | bool isPBufferSurface() const override { return true; } |
| 146 | void swap() override; |
| 147 | |
| 148 | EGLNativeWindowType getWindowHandle() const override; |
| 149 | |
| 150 | private: |
| 151 | void deleteResources() override; |
| 152 | }; |
| 153 | } |
| 154 | |
Nicolas Capens | 31c07a3 | 2017-06-13 23:44:13 -0400 | [diff] [blame] | 155 | #endif // INCLUDE_EGL_SURFACE_H_ |