RenderEngine.h revision ff2ed70fa30f04b90dd1a2c06ec2319e157152d7
1875d8e1323536e16dcfc90c9674d7ad32116a69aMathias Agopian/* 2875d8e1323536e16dcfc90c9674d7ad32116a69aMathias Agopian * Copyright 2013 The Android Open Source Project 3875d8e1323536e16dcfc90c9674d7ad32116a69aMathias Agopian * 4875d8e1323536e16dcfc90c9674d7ad32116a69aMathias Agopian * Licensed under the Apache License, Version 2.0 (the "License"); 5875d8e1323536e16dcfc90c9674d7ad32116a69aMathias Agopian * you may not use this file except in compliance with the License. 6875d8e1323536e16dcfc90c9674d7ad32116a69aMathias Agopian * You may obtain a copy of the License at 7875d8e1323536e16dcfc90c9674d7ad32116a69aMathias Agopian * 8875d8e1323536e16dcfc90c9674d7ad32116a69aMathias Agopian * http://www.apache.org/licenses/LICENSE-2.0 9875d8e1323536e16dcfc90c9674d7ad32116a69aMathias Agopian * 10875d8e1323536e16dcfc90c9674d7ad32116a69aMathias Agopian * Unless required by applicable law or agreed to in writing, software 11875d8e1323536e16dcfc90c9674d7ad32116a69aMathias Agopian * distributed under the License is distributed on an "AS IS" BASIS, 12875d8e1323536e16dcfc90c9674d7ad32116a69aMathias Agopian * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13875d8e1323536e16dcfc90c9674d7ad32116a69aMathias Agopian * See the License for the specific language governing permissions and 14875d8e1323536e16dcfc90c9674d7ad32116a69aMathias Agopian * limitations under the License. 15875d8e1323536e16dcfc90c9674d7ad32116a69aMathias Agopian */ 16875d8e1323536e16dcfc90c9674d7ad32116a69aMathias Agopian 17875d8e1323536e16dcfc90c9674d7ad32116a69aMathias Agopian 18875d8e1323536e16dcfc90c9674d7ad32116a69aMathias Agopian#ifndef SF_RENDERENGINE_H_ 19875d8e1323536e16dcfc90c9674d7ad32116a69aMathias Agopian#define SF_RENDERENGINE_H_ 20875d8e1323536e16dcfc90c9674d7ad32116a69aMathias Agopian 21875d8e1323536e16dcfc90c9674d7ad32116a69aMathias Agopian#include <stdint.h> 22875d8e1323536e16dcfc90c9674d7ad32116a69aMathias Agopian#include <sys/types.h> 23875d8e1323536e16dcfc90c9674d7ad32116a69aMathias Agopian 24875d8e1323536e16dcfc90c9674d7ad32116a69aMathias Agopian#include <EGL/egl.h> 253f84483382be2d528918cc1a6fbc6a7d68e0b181Mathias Agopian#include <EGL/eglext.h> 26ff2ed70fa30f04b90dd1a2c06ec2319e157152d7Mathias Agopian#include <ui/mat4.h> 27875d8e1323536e16dcfc90c9674d7ad32116a69aMathias Agopian 28875d8e1323536e16dcfc90c9674d7ad32116a69aMathias Agopian// --------------------------------------------------------------------------- 29875d8e1323536e16dcfc90c9674d7ad32116a69aMathias Agopiannamespace android { 30875d8e1323536e16dcfc90c9674d7ad32116a69aMathias Agopian// --------------------------------------------------------------------------- 31875d8e1323536e16dcfc90c9674d7ad32116a69aMathias Agopian 32875d8e1323536e16dcfc90c9674d7ad32116a69aMathias Agopianclass String8; 333f84483382be2d528918cc1a6fbc6a7d68e0b181Mathias Agopianclass Rect; 343f84483382be2d528918cc1a6fbc6a7d68e0b181Mathias Agopianclass Region; 353f84483382be2d528918cc1a6fbc6a7d68e0b181Mathias Agopianclass Mesh; 3649457ac092071a8f964f7f69156093657ccdc3d0Mathias Agopianclass Texture; 37875d8e1323536e16dcfc90c9674d7ad32116a69aMathias Agopian 38875d8e1323536e16dcfc90c9674d7ad32116a69aMathias Agopianclass RenderEngine { 39875d8e1323536e16dcfc90c9674d7ad32116a69aMathias Agopian enum GlesVersion { 40875d8e1323536e16dcfc90c9674d7ad32116a69aMathias Agopian GLES_VERSION_1_0 = 0x10000, 41875d8e1323536e16dcfc90c9674d7ad32116a69aMathias Agopian GLES_VERSION_1_1 = 0x10001, 42875d8e1323536e16dcfc90c9674d7ad32116a69aMathias Agopian GLES_VERSION_2_0 = 0x20000, 43875d8e1323536e16dcfc90c9674d7ad32116a69aMathias Agopian GLES_VERSION_3_0 = 0x30000, 44875d8e1323536e16dcfc90c9674d7ad32116a69aMathias Agopian }; 45875d8e1323536e16dcfc90c9674d7ad32116a69aMathias Agopian static GlesVersion parseGlesVersion(const char* str); 46875d8e1323536e16dcfc90c9674d7ad32116a69aMathias Agopian 47875d8e1323536e16dcfc90c9674d7ad32116a69aMathias Agopian EGLContext mEGLContext; 48875d8e1323536e16dcfc90c9674d7ad32116a69aMathias Agopian void setEGLContext(EGLContext ctxt); 49875d8e1323536e16dcfc90c9674d7ad32116a69aMathias Agopian 50458197de008be8fe561286b09f4edddb2f5c540aMathias Agopian virtual void bindImageAsFramebuffer(EGLImageKHR image, uint32_t* texName, uint32_t* fbName, uint32_t* status) = 0; 51458197de008be8fe561286b09f4edddb2f5c540aMathias Agopian virtual void unbindFramebuffer(uint32_t texName, uint32_t fbName) = 0; 52458197de008be8fe561286b09f4edddb2f5c540aMathias Agopian 53875d8e1323536e16dcfc90c9674d7ad32116a69aMathias Agopianprotected: 54875d8e1323536e16dcfc90c9674d7ad32116a69aMathias Agopian RenderEngine(); 55875d8e1323536e16dcfc90c9674d7ad32116a69aMathias Agopian virtual ~RenderEngine() = 0; 56875d8e1323536e16dcfc90c9674d7ad32116a69aMathias Agopian 57875d8e1323536e16dcfc90c9674d7ad32116a69aMathias Agopianpublic: 58875d8e1323536e16dcfc90c9674d7ad32116a69aMathias Agopian static RenderEngine* create(EGLDisplay display, EGLConfig config); 59875d8e1323536e16dcfc90c9674d7ad32116a69aMathias Agopian 60458197de008be8fe561286b09f4edddb2f5c540aMathias Agopian // dump the extension strings. always call the base class. 61458197de008be8fe561286b09f4edddb2f5c540aMathias Agopian virtual void dump(String8& result); 62458197de008be8fe561286b09f4edddb2f5c540aMathias Agopian 633f84483382be2d528918cc1a6fbc6a7d68e0b181Mathias Agopian // helpers 643f84483382be2d528918cc1a6fbc6a7d68e0b181Mathias Agopian void clearWithColor(float red, float green, float blue, float alpha); 653f84483382be2d528918cc1a6fbc6a7d68e0b181Mathias Agopian void fillRegionWithColor(const Region& region, uint32_t height, 663f84483382be2d528918cc1a6fbc6a7d68e0b181Mathias Agopian float red, float green, float blue, float alpha); 673f84483382be2d528918cc1a6fbc6a7d68e0b181Mathias Agopian 683f84483382be2d528918cc1a6fbc6a7d68e0b181Mathias Agopian // common to all GL versions 693f84483382be2d528918cc1a6fbc6a7d68e0b181Mathias Agopian void setScissor(uint32_t left, uint32_t bottom, uint32_t right, uint32_t top); 703f84483382be2d528918cc1a6fbc6a7d68e0b181Mathias Agopian void disableScissor(); 713f84483382be2d528918cc1a6fbc6a7d68e0b181Mathias Agopian void genTextures(size_t count, uint32_t* names); 723f84483382be2d528918cc1a6fbc6a7d68e0b181Mathias Agopian void deleteTextures(size_t count, uint32_t const* names); 733f84483382be2d528918cc1a6fbc6a7d68e0b181Mathias Agopian 743f84483382be2d528918cc1a6fbc6a7d68e0b181Mathias Agopian class BindImageAsFramebuffer { 753f84483382be2d528918cc1a6fbc6a7d68e0b181Mathias Agopian RenderEngine& mEngine; 76458197de008be8fe561286b09f4edddb2f5c540aMathias Agopian uint32_t mTexName, mFbName; 77458197de008be8fe561286b09f4edddb2f5c540aMathias Agopian uint32_t mStatus; 783f84483382be2d528918cc1a6fbc6a7d68e0b181Mathias Agopian public: 793f84483382be2d528918cc1a6fbc6a7d68e0b181Mathias Agopian BindImageAsFramebuffer(RenderEngine& engine, EGLImageKHR image); 803f84483382be2d528918cc1a6fbc6a7d68e0b181Mathias Agopian ~BindImageAsFramebuffer(); 813f84483382be2d528918cc1a6fbc6a7d68e0b181Mathias Agopian int getStatus() const; 823f84483382be2d528918cc1a6fbc6a7d68e0b181Mathias Agopian }; 83875d8e1323536e16dcfc90c9674d7ad32116a69aMathias Agopian 843f84483382be2d528918cc1a6fbc6a7d68e0b181Mathias Agopian // set-up 853f84483382be2d528918cc1a6fbc6a7d68e0b181Mathias Agopian virtual void checkErrors() const; 863f84483382be2d528918cc1a6fbc6a7d68e0b181Mathias Agopian virtual void setViewportAndProjection(size_t vpw, size_t vph, size_t w, size_t h, bool yswap) = 0; 87875d8e1323536e16dcfc90c9674d7ad32116a69aMathias Agopian virtual void setupLayerBlending(bool premultipliedAlpha, bool opaque, int alpha) = 0; 88875d8e1323536e16dcfc90c9674d7ad32116a69aMathias Agopian virtual void setupDimLayerBlending(int alpha) = 0; 8949457ac092071a8f964f7f69156093657ccdc3d0Mathias Agopian virtual void setupLayerTexturing(const Texture& texture) = 0; 90875d8e1323536e16dcfc90c9674d7ad32116a69aMathias Agopian virtual void setupLayerBlackedOut() = 0; 9119733a32799f792125913e746e8644d16f8dc223Mathias Agopian virtual void setupFillWithColor(float r, float g, float b, float a) = 0; 92875d8e1323536e16dcfc90c9674d7ad32116a69aMathias Agopian 93875d8e1323536e16dcfc90c9674d7ad32116a69aMathias Agopian virtual void disableTexturing() = 0; 94875d8e1323536e16dcfc90c9674d7ad32116a69aMathias Agopian virtual void disableBlending() = 0; 95875d8e1323536e16dcfc90c9674d7ad32116a69aMathias Agopian 963f84483382be2d528918cc1a6fbc6a7d68e0b181Mathias Agopian // drawing 973f84483382be2d528918cc1a6fbc6a7d68e0b181Mathias Agopian virtual void drawMesh(const Mesh& mesh) = 0; 98875d8e1323536e16dcfc90c9674d7ad32116a69aMathias Agopian 99ff2ed70fa30f04b90dd1a2c06ec2319e157152d7Mathias Agopian // grouping 100ff2ed70fa30f04b90dd1a2c06ec2319e157152d7Mathias Agopian // creates a color-transform group, everything drawn in the group will be 101ff2ed70fa30f04b90dd1a2c06ec2319e157152d7Mathias Agopian // transformed by the given color transform when endGroup() is called. 102ff2ed70fa30f04b90dd1a2c06ec2319e157152d7Mathias Agopian virtual void beginGroup(const mat4& colorTransform) = 0; 103ff2ed70fa30f04b90dd1a2c06ec2319e157152d7Mathias Agopian virtual void endGroup() = 0; 104ff2ed70fa30f04b90dd1a2c06ec2319e157152d7Mathias Agopian 1053f84483382be2d528918cc1a6fbc6a7d68e0b181Mathias Agopian // queries 106875d8e1323536e16dcfc90c9674d7ad32116a69aMathias Agopian virtual size_t getMaxTextureSize() const = 0; 107875d8e1323536e16dcfc90c9674d7ad32116a69aMathias Agopian virtual size_t getMaxViewportDims() const = 0; 108875d8e1323536e16dcfc90c9674d7ad32116a69aMathias Agopian 1093f84483382be2d528918cc1a6fbc6a7d68e0b181Mathias Agopian 1103f84483382be2d528918cc1a6fbc6a7d68e0b181Mathias Agopian 111875d8e1323536e16dcfc90c9674d7ad32116a69aMathias Agopian EGLContext getEGLContext() const; 112875d8e1323536e16dcfc90c9674d7ad32116a69aMathias Agopian}; 113875d8e1323536e16dcfc90c9674d7ad32116a69aMathias Agopian 114875d8e1323536e16dcfc90c9674d7ad32116a69aMathias Agopian// --------------------------------------------------------------------------- 115875d8e1323536e16dcfc90c9674d7ad32116a69aMathias Agopian}; // namespace android 116875d8e1323536e16dcfc90c9674d7ad32116a69aMathias Agopian// --------------------------------------------------------------------------- 117875d8e1323536e16dcfc90c9674d7ad32116a69aMathias Agopian 118875d8e1323536e16dcfc90c9674d7ad32116a69aMathias Agopian#endif /* SF_RENDERENGINE_H_ */ 119