Home | History | Annotate | Download | only in libEGL
      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 
     29 namespace egl
     30 {
     31 class Display;
     32 class Config;
     33 
     34 class Surface : public gl::Surface, public gl::Object
     35 {
     36 public:
     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 
     49 	EGLint getWidth() const override;
     50 	EGLint getHeight() const override;
     51 	EGLenum getTextureTarget() const override;
     52 	virtual EGLint getPixelAspectRatio() const;
     53 	virtual EGLenum getRenderBuffer() const;
     54 	virtual EGLenum getSwapBehavior() const;
     55 	virtual EGLenum getTextureFormat() const;
     56 	virtual EGLBoolean getLargestPBuffer() const;
     57 	virtual EGLNativeWindowType getWindowHandle() const = 0;
     58 
     59 	void setBoundTexture(egl::Texture *texture) override;
     60 	virtual egl::Texture *getBoundTexture() const;
     61 
     62 	virtual bool isWindowSurface() const { return false; }
     63 	virtual bool isPBufferSurface() const { return false; }
     64 	bool hasClientBuffer() const { return clientBuffer != nullptr; }
     65 
     66 protected:
     67 	Surface(const Display *display, const Config *config);
     68 
     69 	~Surface() override;
     70 
     71 	virtual void deleteResources();
     72 
     73 	sw::Format getClientBufferFormat() const;
     74 
     75 	const Display *const display;
     76 	Image *depthStencil;
     77 	Image *backBuffer;
     78 	Texture *texture;
     79 
     80 	bool reset(int backbufferWidth, int backbufferHeight);
     81 
     82 	const Config *const config;    // EGL config surface was created with
     83 	EGLint width;                  // Width of surface
     84 	EGLint height;                 // Height of surface
     85 //  EGLint horizontalResolution;   // Horizontal dot pitch
     86 //  EGLint verticalResolution;     // Vertical dot pitch
     87 	EGLBoolean largestPBuffer;     // If true, create largest pbuffer possible
     88 //  EGLBoolean mipmapTexture;      // True if texture has mipmaps
     89 //  EGLint mipmapLevel;            // Mipmap level to render to
     90 //  EGLenum multisampleResolve;    // Multisample resolve behavior
     91 	EGLint pixelAspectRatio;       // Display aspect ratio
     92 	EGLenum renderBuffer;          // Render buffer
     93 	EGLenum swapBehavior;          // Buffer swap behavior
     94 	EGLenum textureFormat;         // Format of texture: RGB, RGBA, or no texture
     95 	EGLenum textureTarget;         // Type of texture: 2D or no texture
     96 	EGLenum clientBufferFormat;    // Format of the client buffer
     97 	EGLenum clientBufferType;      // Type of the client buffer
     98 //  EGLenum vgAlphaFormat;         // Alpha format for OpenVG
     99 //  EGLenum vgColorSpace;          // Color space for OpenVG
    100 	EGLint swapInterval;
    101 	EGLClientBuffer clientBuffer;
    102 	EGLint clientBufferPlane;
    103 };
    104 
    105 class WindowSurface : public Surface
    106 {
    107 public:
    108 	WindowSurface(Display *display, const egl::Config *config, EGLNativeWindowType window);
    109 	~WindowSurface() override;
    110 
    111 	bool initialize() override;
    112 
    113 	bool isWindowSurface() const override { return true; }
    114 	void swap() override;
    115 
    116 	EGLNativeWindowType getWindowHandle() const override;
    117 
    118 private:
    119 	void deleteResources() override;
    120 	bool checkForResize();
    121 	bool reset(int backBufferWidth, int backBufferHeight);
    122 
    123 	const EGLNativeWindowType window;
    124 	sw::FrameBuffer *frameBuffer;
    125 };
    126 
    127 class PBufferSurface : public Surface
    128 {
    129 public:
    130 	PBufferSurface(Display *display, const egl::Config *config, EGLint width, EGLint height,
    131 	               EGLenum textureFormat, EGLenum textureTarget, EGLenum internalFormat,
    132 	               EGLenum textureType, EGLBoolean largestPBuffer, EGLClientBuffer clientBuffer,
    133 	               EGLint clientBufferPlane);
    134 	~PBufferSurface() override;
    135 
    136 	bool isPBufferSurface() const override { return true; }
    137 	void swap() override;
    138 
    139 	EGLNativeWindowType getWindowHandle() const override;
    140 
    141 private:
    142 	void deleteResources() override;
    143 };
    144 }
    145 
    146 #endif   // INCLUDE_EGL_SURFACE_H_
    147