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 15// Surface.hpp: Defines the egl::Surface class, representing a rendering surface 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 19#ifndef INCLUDE_EGL_SURFACE_H_ 20#define INCLUDE_EGL_SURFACE_H_ 21 22#include "common/Object.hpp" 23#include "common/Surface.hpp" 24 25#include "Main/FrameBuffer.hpp" 26 27#include <EGL/egl.h> 28 29namespace egl 30{ 31class Display; 32class Config; 33 34class Surface : public gl::Surface, public gl::Object 35{ 36public: 37 virtual bool initialize(); 38 virtual void swap() = 0; 39 40 egl::Image *getRenderTarget() override; 41 egl::Image *getDepthStencil() override; 42 43 void setSwapBehavior(EGLenum swapBehavior); 44 void setSwapInterval(EGLint interval); 45 46 virtual EGLint getConfigID() const; 47 virtual EGLenum getSurfaceType() const; 48 sw::Format getInternalFormat() const override; 49 50 EGLint getWidth() const override; 51 EGLint getHeight() const override; 52 virtual EGLint getPixelAspectRatio() const; 53 virtual EGLenum getRenderBuffer() const; 54 virtual EGLenum getSwapBehavior() const; 55 virtual EGLenum getTextureFormat() const; 56 virtual EGLenum getTextureTarget() const; 57 virtual EGLBoolean getLargestPBuffer() const; 58 virtual EGLNativeWindowType getWindowHandle() const = 0; 59 60 void setBoundTexture(egl::Texture *texture) override; 61 virtual egl::Texture *getBoundTexture() const; 62 63 virtual bool isWindowSurface() const { return false; } 64 virtual bool isPBufferSurface() const { return false; } 65 66protected: 67 Surface(const Display *display, const Config *config); 68 69 ~Surface() override; 70 71 virtual void deleteResources(); 72 73 const Display *const display; 74 Image *depthStencil; 75 Image *backBuffer; 76 Texture *texture; 77 78 bool reset(int backbufferWidth, int backbufferHeight); 79 80 const Config *const config; // EGL config surface was created with 81 EGLint height; // Height of surface 82 EGLint width; // Width of surface 83// EGLint horizontalResolution; // Horizontal dot pitch 84// EGLint verticalResolution; // Vertical dot pitch 85 EGLBoolean largestPBuffer; // If true, create largest pbuffer possible 86// EGLBoolean mipmapTexture; // True if texture has mipmaps 87// EGLint mipmapLevel; // Mipmap level to render to 88// EGLenum multisampleResolve; // Multisample resolve behavior 89 EGLint pixelAspectRatio; // Display aspect ratio 90 EGLenum renderBuffer; // Render buffer 91 EGLenum swapBehavior; // Buffer swap behavior 92 EGLenum textureFormat; // Format of texture: RGB, RGBA, or no texture 93 EGLenum textureTarget; // Type of texture: 2D or no texture 94// EGLenum vgAlphaFormat; // Alpha format for OpenVG 95// EGLenum vgColorSpace; // Color space for OpenVG 96 EGLint swapInterval; 97}; 98 99class WindowSurface : public Surface 100{ 101public: 102 WindowSurface(Display *display, const egl::Config *config, EGLNativeWindowType window); 103 ~WindowSurface() override; 104 105 bool initialize() override; 106 107 bool isWindowSurface() const override { return true; } 108 void swap() override; 109 110 EGLNativeWindowType getWindowHandle() const override; 111 112private: 113 void deleteResources() override; 114 bool checkForResize(); 115 bool reset(int backBufferWidth, int backBufferHeight); 116 117 const EGLNativeWindowType window; 118 sw::FrameBuffer *frameBuffer; 119}; 120 121class PBufferSurface : public Surface 122{ 123public: 124 PBufferSurface(Display *display, const egl::Config *config, EGLint width, EGLint height, EGLenum textureFormat, EGLenum textureTarget, EGLBoolean largestPBuffer); 125 ~PBufferSurface() override; 126 127 bool isPBufferSurface() const override { return true; } 128 void swap() override; 129 130 EGLNativeWindowType getWindowHandle() const override; 131 132private: 133 void deleteResources() override; 134}; 135} 136 137#endif // INCLUDE_EGL_SURFACE_H_ 138