RenderEngine.h revision 05f8c703d4a050669ff8f406be3a9dc2357935f7
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 4705f8c703d4a050669ff8f406be3a9dc2357935f7Jesse Hall EGLConfig mEGLConfig; 48875d8e1323536e16dcfc90c9674d7ad32116a69aMathias Agopian EGLContext mEGLContext; 4905f8c703d4a050669ff8f406be3a9dc2357935f7Jesse Hall void setEGLHandles(EGLConfig config, EGLContext ctxt); 50875d8e1323536e16dcfc90c9674d7ad32116a69aMathias Agopian 51458197de008be8fe561286b09f4edddb2f5c540aMathias Agopian virtual void bindImageAsFramebuffer(EGLImageKHR image, uint32_t* texName, uint32_t* fbName, uint32_t* status) = 0; 52458197de008be8fe561286b09f4edddb2f5c540aMathias Agopian virtual void unbindFramebuffer(uint32_t texName, uint32_t fbName) = 0; 53458197de008be8fe561286b09f4edddb2f5c540aMathias Agopian 54875d8e1323536e16dcfc90c9674d7ad32116a69aMathias Agopianprotected: 55875d8e1323536e16dcfc90c9674d7ad32116a69aMathias Agopian RenderEngine(); 56875d8e1323536e16dcfc90c9674d7ad32116a69aMathias Agopian virtual ~RenderEngine() = 0; 57875d8e1323536e16dcfc90c9674d7ad32116a69aMathias Agopian 58875d8e1323536e16dcfc90c9674d7ad32116a69aMathias Agopianpublic: 5905f8c703d4a050669ff8f406be3a9dc2357935f7Jesse Hall static RenderEngine* create(EGLDisplay display, int hwcFormat); 6005f8c703d4a050669ff8f406be3a9dc2357935f7Jesse Hall 6105f8c703d4a050669ff8f406be3a9dc2357935f7Jesse Hall static EGLConfig chooseEglConfig(EGLDisplay display, int format); 62875d8e1323536e16dcfc90c9674d7ad32116a69aMathias Agopian 63458197de008be8fe561286b09f4edddb2f5c540aMathias Agopian // dump the extension strings. always call the base class. 64458197de008be8fe561286b09f4edddb2f5c540aMathias Agopian virtual void dump(String8& result); 65458197de008be8fe561286b09f4edddb2f5c540aMathias Agopian 663f84483382be2d528918cc1a6fbc6a7d68e0b181Mathias Agopian // helpers 673f84483382be2d528918cc1a6fbc6a7d68e0b181Mathias Agopian void clearWithColor(float red, float green, float blue, float alpha); 683f84483382be2d528918cc1a6fbc6a7d68e0b181Mathias Agopian void fillRegionWithColor(const Region& region, uint32_t height, 693f84483382be2d528918cc1a6fbc6a7d68e0b181Mathias Agopian float red, float green, float blue, float alpha); 703f84483382be2d528918cc1a6fbc6a7d68e0b181Mathias Agopian 713f84483382be2d528918cc1a6fbc6a7d68e0b181Mathias Agopian // common to all GL versions 723f84483382be2d528918cc1a6fbc6a7d68e0b181Mathias Agopian void setScissor(uint32_t left, uint32_t bottom, uint32_t right, uint32_t top); 733f84483382be2d528918cc1a6fbc6a7d68e0b181Mathias Agopian void disableScissor(); 743f84483382be2d528918cc1a6fbc6a7d68e0b181Mathias Agopian void genTextures(size_t count, uint32_t* names); 753f84483382be2d528918cc1a6fbc6a7d68e0b181Mathias Agopian void deleteTextures(size_t count, uint32_t const* names); 76d555684cb36dfb959694db76962e570184f98838Mathias Agopian void readPixels(size_t l, size_t b, size_t w, size_t h, uint32_t* pixels); 773f84483382be2d528918cc1a6fbc6a7d68e0b181Mathias Agopian 783f84483382be2d528918cc1a6fbc6a7d68e0b181Mathias Agopian class BindImageAsFramebuffer { 793f84483382be2d528918cc1a6fbc6a7d68e0b181Mathias Agopian RenderEngine& mEngine; 80458197de008be8fe561286b09f4edddb2f5c540aMathias Agopian uint32_t mTexName, mFbName; 81458197de008be8fe561286b09f4edddb2f5c540aMathias Agopian uint32_t mStatus; 823f84483382be2d528918cc1a6fbc6a7d68e0b181Mathias Agopian public: 833f84483382be2d528918cc1a6fbc6a7d68e0b181Mathias Agopian BindImageAsFramebuffer(RenderEngine& engine, EGLImageKHR image); 843f84483382be2d528918cc1a6fbc6a7d68e0b181Mathias Agopian ~BindImageAsFramebuffer(); 853f84483382be2d528918cc1a6fbc6a7d68e0b181Mathias Agopian int getStatus() const; 863f84483382be2d528918cc1a6fbc6a7d68e0b181Mathias Agopian }; 87875d8e1323536e16dcfc90c9674d7ad32116a69aMathias Agopian 883f84483382be2d528918cc1a6fbc6a7d68e0b181Mathias Agopian // set-up 893f84483382be2d528918cc1a6fbc6a7d68e0b181Mathias Agopian virtual void checkErrors() const; 903f84483382be2d528918cc1a6fbc6a7d68e0b181Mathias Agopian virtual void setViewportAndProjection(size_t vpw, size_t vph, size_t w, size_t h, bool yswap) = 0; 91875d8e1323536e16dcfc90c9674d7ad32116a69aMathias Agopian virtual void setupLayerBlending(bool premultipliedAlpha, bool opaque, int alpha) = 0; 92875d8e1323536e16dcfc90c9674d7ad32116a69aMathias Agopian virtual void setupDimLayerBlending(int alpha) = 0; 9349457ac092071a8f964f7f69156093657ccdc3d0Mathias Agopian virtual void setupLayerTexturing(const Texture& texture) = 0; 94875d8e1323536e16dcfc90c9674d7ad32116a69aMathias Agopian virtual void setupLayerBlackedOut() = 0; 9519733a32799f792125913e746e8644d16f8dc223Mathias Agopian virtual void setupFillWithColor(float r, float g, float b, float a) = 0; 96875d8e1323536e16dcfc90c9674d7ad32116a69aMathias Agopian 97875d8e1323536e16dcfc90c9674d7ad32116a69aMathias Agopian virtual void disableTexturing() = 0; 98875d8e1323536e16dcfc90c9674d7ad32116a69aMathias Agopian virtual void disableBlending() = 0; 99875d8e1323536e16dcfc90c9674d7ad32116a69aMathias Agopian 1003f84483382be2d528918cc1a6fbc6a7d68e0b181Mathias Agopian // drawing 1013f84483382be2d528918cc1a6fbc6a7d68e0b181Mathias Agopian virtual void drawMesh(const Mesh& mesh) = 0; 102875d8e1323536e16dcfc90c9674d7ad32116a69aMathias Agopian 103ff2ed70fa30f04b90dd1a2c06ec2319e157152d7Mathias Agopian // grouping 104ff2ed70fa30f04b90dd1a2c06ec2319e157152d7Mathias Agopian // creates a color-transform group, everything drawn in the group will be 105ff2ed70fa30f04b90dd1a2c06ec2319e157152d7Mathias Agopian // transformed by the given color transform when endGroup() is called. 106ff2ed70fa30f04b90dd1a2c06ec2319e157152d7Mathias Agopian virtual void beginGroup(const mat4& colorTransform) = 0; 107ff2ed70fa30f04b90dd1a2c06ec2319e157152d7Mathias Agopian virtual void endGroup() = 0; 108ff2ed70fa30f04b90dd1a2c06ec2319e157152d7Mathias Agopian 1093f84483382be2d528918cc1a6fbc6a7d68e0b181Mathias Agopian // queries 110875d8e1323536e16dcfc90c9674d7ad32116a69aMathias Agopian virtual size_t getMaxTextureSize() const = 0; 111875d8e1323536e16dcfc90c9674d7ad32116a69aMathias Agopian virtual size_t getMaxViewportDims() const = 0; 112875d8e1323536e16dcfc90c9674d7ad32116a69aMathias Agopian 11305f8c703d4a050669ff8f406be3a9dc2357935f7Jesse Hall EGLConfig getEGLConfig() const; 114875d8e1323536e16dcfc90c9674d7ad32116a69aMathias Agopian EGLContext getEGLContext() const; 115875d8e1323536e16dcfc90c9674d7ad32116a69aMathias Agopian}; 116875d8e1323536e16dcfc90c9674d7ad32116a69aMathias Agopian 117875d8e1323536e16dcfc90c9674d7ad32116a69aMathias Agopian// --------------------------------------------------------------------------- 118875d8e1323536e16dcfc90c9674d7ad32116a69aMathias Agopian}; // namespace android 119875d8e1323536e16dcfc90c9674d7ad32116a69aMathias Agopian// --------------------------------------------------------------------------- 120875d8e1323536e16dcfc90c9674d7ad32116a69aMathias Agopian 121875d8e1323536e16dcfc90c9674d7ad32116a69aMathias Agopian#endif /* SF_RENDERENGINE_H_ */ 122