RenderEngine.h revision 19733a32799f792125913e746e8644d16f8dc223
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> 26875d8e1323536e16dcfc90c9674d7ad32116a69aMathias Agopian 27875d8e1323536e16dcfc90c9674d7ad32116a69aMathias Agopian// --------------------------------------------------------------------------- 28875d8e1323536e16dcfc90c9674d7ad32116a69aMathias Agopiannamespace android { 29875d8e1323536e16dcfc90c9674d7ad32116a69aMathias Agopian// --------------------------------------------------------------------------- 30875d8e1323536e16dcfc90c9674d7ad32116a69aMathias Agopian 31875d8e1323536e16dcfc90c9674d7ad32116a69aMathias Agopianclass String8; 323f84483382be2d528918cc1a6fbc6a7d68e0b181Mathias Agopianclass Rect; 333f84483382be2d528918cc1a6fbc6a7d68e0b181Mathias Agopianclass Region; 343f84483382be2d528918cc1a6fbc6a7d68e0b181Mathias Agopianclass Mesh; 3549457ac092071a8f964f7f69156093657ccdc3d0Mathias Agopianclass Texture; 36875d8e1323536e16dcfc90c9674d7ad32116a69aMathias Agopian 37875d8e1323536e16dcfc90c9674d7ad32116a69aMathias Agopianclass RenderEngine { 38875d8e1323536e16dcfc90c9674d7ad32116a69aMathias Agopian enum GlesVersion { 39875d8e1323536e16dcfc90c9674d7ad32116a69aMathias Agopian GLES_VERSION_1_0 = 0x10000, 40875d8e1323536e16dcfc90c9674d7ad32116a69aMathias Agopian GLES_VERSION_1_1 = 0x10001, 41875d8e1323536e16dcfc90c9674d7ad32116a69aMathias Agopian GLES_VERSION_2_0 = 0x20000, 42875d8e1323536e16dcfc90c9674d7ad32116a69aMathias Agopian GLES_VERSION_3_0 = 0x30000, 43875d8e1323536e16dcfc90c9674d7ad32116a69aMathias Agopian }; 44875d8e1323536e16dcfc90c9674d7ad32116a69aMathias Agopian static GlesVersion parseGlesVersion(const char* str); 45875d8e1323536e16dcfc90c9674d7ad32116a69aMathias Agopian 46875d8e1323536e16dcfc90c9674d7ad32116a69aMathias Agopian EGLContext mEGLContext; 47875d8e1323536e16dcfc90c9674d7ad32116a69aMathias Agopian void setEGLContext(EGLContext ctxt); 48875d8e1323536e16dcfc90c9674d7ad32116a69aMathias Agopian 49458197de008be8fe561286b09f4edddb2f5c540aMathias Agopian virtual void bindImageAsFramebuffer(EGLImageKHR image, uint32_t* texName, uint32_t* fbName, uint32_t* status) = 0; 50458197de008be8fe561286b09f4edddb2f5c540aMathias Agopian virtual void unbindFramebuffer(uint32_t texName, uint32_t fbName) = 0; 51458197de008be8fe561286b09f4edddb2f5c540aMathias Agopian 52875d8e1323536e16dcfc90c9674d7ad32116a69aMathias Agopianprotected: 53875d8e1323536e16dcfc90c9674d7ad32116a69aMathias Agopian RenderEngine(); 54875d8e1323536e16dcfc90c9674d7ad32116a69aMathias Agopian virtual ~RenderEngine() = 0; 55875d8e1323536e16dcfc90c9674d7ad32116a69aMathias Agopian 56875d8e1323536e16dcfc90c9674d7ad32116a69aMathias Agopianpublic: 57875d8e1323536e16dcfc90c9674d7ad32116a69aMathias Agopian static RenderEngine* create(EGLDisplay display, EGLConfig config); 58875d8e1323536e16dcfc90c9674d7ad32116a69aMathias Agopian 59458197de008be8fe561286b09f4edddb2f5c540aMathias Agopian // dump the extension strings. always call the base class. 60458197de008be8fe561286b09f4edddb2f5c540aMathias Agopian virtual void dump(String8& result); 61458197de008be8fe561286b09f4edddb2f5c540aMathias Agopian 623f84483382be2d528918cc1a6fbc6a7d68e0b181Mathias Agopian // helpers 633f84483382be2d528918cc1a6fbc6a7d68e0b181Mathias Agopian void clearWithColor(float red, float green, float blue, float alpha); 643f84483382be2d528918cc1a6fbc6a7d68e0b181Mathias Agopian void fillRegionWithColor(const Region& region, uint32_t height, 653f84483382be2d528918cc1a6fbc6a7d68e0b181Mathias Agopian float red, float green, float blue, float alpha); 663f84483382be2d528918cc1a6fbc6a7d68e0b181Mathias Agopian 673f84483382be2d528918cc1a6fbc6a7d68e0b181Mathias Agopian // common to all GL versions 683f84483382be2d528918cc1a6fbc6a7d68e0b181Mathias Agopian void setScissor(uint32_t left, uint32_t bottom, uint32_t right, uint32_t top); 693f84483382be2d528918cc1a6fbc6a7d68e0b181Mathias Agopian void disableScissor(); 703f84483382be2d528918cc1a6fbc6a7d68e0b181Mathias Agopian void genTextures(size_t count, uint32_t* names); 713f84483382be2d528918cc1a6fbc6a7d68e0b181Mathias Agopian void deleteTextures(size_t count, uint32_t const* names); 723f84483382be2d528918cc1a6fbc6a7d68e0b181Mathias Agopian 733f84483382be2d528918cc1a6fbc6a7d68e0b181Mathias Agopian class BindImageAsFramebuffer { 743f84483382be2d528918cc1a6fbc6a7d68e0b181Mathias Agopian RenderEngine& mEngine; 75458197de008be8fe561286b09f4edddb2f5c540aMathias Agopian uint32_t mTexName, mFbName; 76458197de008be8fe561286b09f4edddb2f5c540aMathias Agopian uint32_t mStatus; 773f84483382be2d528918cc1a6fbc6a7d68e0b181Mathias Agopian public: 783f84483382be2d528918cc1a6fbc6a7d68e0b181Mathias Agopian BindImageAsFramebuffer(RenderEngine& engine, EGLImageKHR image); 793f84483382be2d528918cc1a6fbc6a7d68e0b181Mathias Agopian ~BindImageAsFramebuffer(); 803f84483382be2d528918cc1a6fbc6a7d68e0b181Mathias Agopian int getStatus() const; 813f84483382be2d528918cc1a6fbc6a7d68e0b181Mathias Agopian }; 82875d8e1323536e16dcfc90c9674d7ad32116a69aMathias Agopian 833f84483382be2d528918cc1a6fbc6a7d68e0b181Mathias Agopian // set-up 843f84483382be2d528918cc1a6fbc6a7d68e0b181Mathias Agopian virtual void checkErrors() const; 853f84483382be2d528918cc1a6fbc6a7d68e0b181Mathias Agopian virtual void setViewportAndProjection(size_t vpw, size_t vph, size_t w, size_t h, bool yswap) = 0; 86875d8e1323536e16dcfc90c9674d7ad32116a69aMathias Agopian virtual void setupLayerBlending(bool premultipliedAlpha, bool opaque, int alpha) = 0; 87875d8e1323536e16dcfc90c9674d7ad32116a69aMathias Agopian virtual void setupDimLayerBlending(int alpha) = 0; 8849457ac092071a8f964f7f69156093657ccdc3d0Mathias Agopian virtual void setupLayerTexturing(const Texture& texture) = 0; 89875d8e1323536e16dcfc90c9674d7ad32116a69aMathias Agopian virtual void setupLayerBlackedOut() = 0; 9019733a32799f792125913e746e8644d16f8dc223Mathias Agopian virtual void setupFillWithColor(float r, float g, float b, float a) = 0; 91875d8e1323536e16dcfc90c9674d7ad32116a69aMathias Agopian 92875d8e1323536e16dcfc90c9674d7ad32116a69aMathias Agopian virtual void disableTexturing() = 0; 93875d8e1323536e16dcfc90c9674d7ad32116a69aMathias Agopian virtual void disableBlending() = 0; 94875d8e1323536e16dcfc90c9674d7ad32116a69aMathias Agopian 953f84483382be2d528918cc1a6fbc6a7d68e0b181Mathias Agopian // drawing 963f84483382be2d528918cc1a6fbc6a7d68e0b181Mathias Agopian virtual void drawMesh(const Mesh& mesh) = 0; 97875d8e1323536e16dcfc90c9674d7ad32116a69aMathias Agopian 983f84483382be2d528918cc1a6fbc6a7d68e0b181Mathias Agopian // queries 99875d8e1323536e16dcfc90c9674d7ad32116a69aMathias Agopian virtual size_t getMaxTextureSize() const = 0; 100875d8e1323536e16dcfc90c9674d7ad32116a69aMathias Agopian virtual size_t getMaxViewportDims() const = 0; 101875d8e1323536e16dcfc90c9674d7ad32116a69aMathias Agopian 1023f84483382be2d528918cc1a6fbc6a7d68e0b181Mathias Agopian 1033f84483382be2d528918cc1a6fbc6a7d68e0b181Mathias Agopian 104875d8e1323536e16dcfc90c9674d7ad32116a69aMathias Agopian EGLContext getEGLContext() const; 105875d8e1323536e16dcfc90c9674d7ad32116a69aMathias Agopian}; 106875d8e1323536e16dcfc90c9674d7ad32116a69aMathias Agopian 107875d8e1323536e16dcfc90c9674d7ad32116a69aMathias Agopian// --------------------------------------------------------------------------- 108875d8e1323536e16dcfc90c9674d7ad32116a69aMathias Agopian}; // namespace android 109875d8e1323536e16dcfc90c9674d7ad32116a69aMathias Agopian// --------------------------------------------------------------------------- 110875d8e1323536e16dcfc90c9674d7ad32116a69aMathias Agopian 111875d8e1323536e16dcfc90c9674d7ad32116a69aMathias Agopian#endif /* SF_RENDERENGINE_H_ */ 112