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> 27c3ebe66b49cfba035e1fd0e160a13db38eb81b0eRiley Andrews#include <Transform.h> 28875d8e1323536e16dcfc90c9674d7ad32116a69aMathias Agopian 2919e872912af66c53a4350afcc333bbafaf6a2294Jesse Hall#define EGL_NO_CONFIG ((EGLConfig)0) 3019e872912af66c53a4350afcc333bbafaf6a2294Jesse Hall 31875d8e1323536e16dcfc90c9674d7ad32116a69aMathias Agopian// --------------------------------------------------------------------------- 32875d8e1323536e16dcfc90c9674d7ad32116a69aMathias Agopiannamespace android { 33875d8e1323536e16dcfc90c9674d7ad32116a69aMathias Agopian// --------------------------------------------------------------------------- 34875d8e1323536e16dcfc90c9674d7ad32116a69aMathias Agopian 35875d8e1323536e16dcfc90c9674d7ad32116a69aMathias Agopianclass String8; 363f84483382be2d528918cc1a6fbc6a7d68e0b181Mathias Agopianclass Rect; 373f84483382be2d528918cc1a6fbc6a7d68e0b181Mathias Agopianclass Region; 383f84483382be2d528918cc1a6fbc6a7d68e0b181Mathias Agopianclass Mesh; 3949457ac092071a8f964f7f69156093657ccdc3d0Mathias Agopianclass Texture; 40875d8e1323536e16dcfc90c9674d7ad32116a69aMathias Agopian 41875d8e1323536e16dcfc90c9674d7ad32116a69aMathias Agopianclass RenderEngine { 42875d8e1323536e16dcfc90c9674d7ad32116a69aMathias Agopian enum GlesVersion { 43875d8e1323536e16dcfc90c9674d7ad32116a69aMathias Agopian GLES_VERSION_1_0 = 0x10000, 44875d8e1323536e16dcfc90c9674d7ad32116a69aMathias Agopian GLES_VERSION_1_1 = 0x10001, 45875d8e1323536e16dcfc90c9674d7ad32116a69aMathias Agopian GLES_VERSION_2_0 = 0x20000, 46875d8e1323536e16dcfc90c9674d7ad32116a69aMathias Agopian GLES_VERSION_3_0 = 0x30000, 47875d8e1323536e16dcfc90c9674d7ad32116a69aMathias Agopian }; 48875d8e1323536e16dcfc90c9674d7ad32116a69aMathias Agopian static GlesVersion parseGlesVersion(const char* str); 49875d8e1323536e16dcfc90c9674d7ad32116a69aMathias Agopian 5005f8c703d4a050669ff8f406be3a9dc2357935f7Jesse Hall EGLConfig mEGLConfig; 51875d8e1323536e16dcfc90c9674d7ad32116a69aMathias Agopian EGLContext mEGLContext; 5205f8c703d4a050669ff8f406be3a9dc2357935f7Jesse Hall void setEGLHandles(EGLConfig config, EGLContext ctxt); 53875d8e1323536e16dcfc90c9674d7ad32116a69aMathias Agopian 54458197de008be8fe561286b09f4edddb2f5c540aMathias Agopian virtual void bindImageAsFramebuffer(EGLImageKHR image, uint32_t* texName, uint32_t* fbName, uint32_t* status) = 0; 55458197de008be8fe561286b09f4edddb2f5c540aMathias Agopian virtual void unbindFramebuffer(uint32_t texName, uint32_t fbName) = 0; 56458197de008be8fe561286b09f4edddb2f5c540aMathias Agopian 57875d8e1323536e16dcfc90c9674d7ad32116a69aMathias Agopianprotected: 58875d8e1323536e16dcfc90c9674d7ad32116a69aMathias Agopian RenderEngine(); 59875d8e1323536e16dcfc90c9674d7ad32116a69aMathias Agopian virtual ~RenderEngine() = 0; 60875d8e1323536e16dcfc90c9674d7ad32116a69aMathias Agopian 61875d8e1323536e16dcfc90c9674d7ad32116a69aMathias Agopianpublic: 6205f8c703d4a050669ff8f406be3a9dc2357935f7Jesse Hall static RenderEngine* create(EGLDisplay display, int hwcFormat); 6305f8c703d4a050669ff8f406be3a9dc2357935f7Jesse Hall 6405f8c703d4a050669ff8f406be3a9dc2357935f7Jesse Hall static EGLConfig chooseEglConfig(EGLDisplay display, int format); 65875d8e1323536e16dcfc90c9674d7ad32116a69aMathias Agopian 66458197de008be8fe561286b09f4edddb2f5c540aMathias Agopian // dump the extension strings. always call the base class. 67458197de008be8fe561286b09f4edddb2f5c540aMathias Agopian virtual void dump(String8& result); 68458197de008be8fe561286b09f4edddb2f5c540aMathias Agopian 693f84483382be2d528918cc1a6fbc6a7d68e0b181Mathias Agopian // helpers 709707f4df640c3369f873a934bb05ffa5a68a5640Riley Andrews void flush(); 713f84483382be2d528918cc1a6fbc6a7d68e0b181Mathias Agopian void clearWithColor(float red, float green, float blue, float alpha); 723f84483382be2d528918cc1a6fbc6a7d68e0b181Mathias Agopian void fillRegionWithColor(const Region& region, uint32_t height, 733f84483382be2d528918cc1a6fbc6a7d68e0b181Mathias Agopian float red, float green, float blue, float alpha); 743f84483382be2d528918cc1a6fbc6a7d68e0b181Mathias Agopian 753f84483382be2d528918cc1a6fbc6a7d68e0b181Mathias Agopian // common to all GL versions 763f84483382be2d528918cc1a6fbc6a7d68e0b181Mathias Agopian void setScissor(uint32_t left, uint32_t bottom, uint32_t right, uint32_t top); 773f84483382be2d528918cc1a6fbc6a7d68e0b181Mathias Agopian void disableScissor(); 783f84483382be2d528918cc1a6fbc6a7d68e0b181Mathias Agopian void genTextures(size_t count, uint32_t* names); 793f84483382be2d528918cc1a6fbc6a7d68e0b181Mathias Agopian void deleteTextures(size_t count, uint32_t const* names); 80d555684cb36dfb959694db76962e570184f98838Mathias Agopian void readPixels(size_t l, size_t b, size_t w, size_t h, uint32_t* pixels); 813f84483382be2d528918cc1a6fbc6a7d68e0b181Mathias Agopian 823f84483382be2d528918cc1a6fbc6a7d68e0b181Mathias Agopian class BindImageAsFramebuffer { 833f84483382be2d528918cc1a6fbc6a7d68e0b181Mathias Agopian RenderEngine& mEngine; 84458197de008be8fe561286b09f4edddb2f5c540aMathias Agopian uint32_t mTexName, mFbName; 85458197de008be8fe561286b09f4edddb2f5c540aMathias Agopian uint32_t mStatus; 863f84483382be2d528918cc1a6fbc6a7d68e0b181Mathias Agopian public: 873f84483382be2d528918cc1a6fbc6a7d68e0b181Mathias Agopian BindImageAsFramebuffer(RenderEngine& engine, EGLImageKHR image); 883f84483382be2d528918cc1a6fbc6a7d68e0b181Mathias Agopian ~BindImageAsFramebuffer(); 893f84483382be2d528918cc1a6fbc6a7d68e0b181Mathias Agopian int getStatus() const; 903f84483382be2d528918cc1a6fbc6a7d68e0b181Mathias Agopian }; 91875d8e1323536e16dcfc90c9674d7ad32116a69aMathias Agopian 923f84483382be2d528918cc1a6fbc6a7d68e0b181Mathias Agopian // set-up 933f84483382be2d528918cc1a6fbc6a7d68e0b181Mathias Agopian virtual void checkErrors() const; 94c18790018be5d7ea7061ccbc81f3044e74adc823Dan Stoza virtual void setViewportAndProjection(size_t vpw, size_t vph, 95c3ebe66b49cfba035e1fd0e160a13db38eb81b0eRiley Andrews Rect sourceCrop, size_t hwh, bool yswap, Transform::orientation_flags rotation) = 0; 96875d8e1323536e16dcfc90c9674d7ad32116a69aMathias Agopian virtual void setupLayerBlending(bool premultipliedAlpha, bool opaque, int alpha) = 0; 97875d8e1323536e16dcfc90c9674d7ad32116a69aMathias Agopian virtual void setupDimLayerBlending(int alpha) = 0; 9849457ac092071a8f964f7f69156093657ccdc3d0Mathias Agopian virtual void setupLayerTexturing(const Texture& texture) = 0; 99875d8e1323536e16dcfc90c9674d7ad32116a69aMathias Agopian virtual void setupLayerBlackedOut() = 0; 10019733a32799f792125913e746e8644d16f8dc223Mathias Agopian virtual void setupFillWithColor(float r, float g, float b, float a) = 0; 101875d8e1323536e16dcfc90c9674d7ad32116a69aMathias Agopian 102875d8e1323536e16dcfc90c9674d7ad32116a69aMathias Agopian virtual void disableTexturing() = 0; 103875d8e1323536e16dcfc90c9674d7ad32116a69aMathias Agopian virtual void disableBlending() = 0; 104875d8e1323536e16dcfc90c9674d7ad32116a69aMathias Agopian 1053f84483382be2d528918cc1a6fbc6a7d68e0b181Mathias Agopian // drawing 1063f84483382be2d528918cc1a6fbc6a7d68e0b181Mathias Agopian virtual void drawMesh(const Mesh& mesh) = 0; 107875d8e1323536e16dcfc90c9674d7ad32116a69aMathias Agopian 108ff2ed70fa30f04b90dd1a2c06ec2319e157152d7Mathias Agopian // grouping 109ff2ed70fa30f04b90dd1a2c06ec2319e157152d7Mathias Agopian // creates a color-transform group, everything drawn in the group will be 110ff2ed70fa30f04b90dd1a2c06ec2319e157152d7Mathias Agopian // transformed by the given color transform when endGroup() is called. 111ff2ed70fa30f04b90dd1a2c06ec2319e157152d7Mathias Agopian virtual void beginGroup(const mat4& colorTransform) = 0; 112ff2ed70fa30f04b90dd1a2c06ec2319e157152d7Mathias Agopian virtual void endGroup() = 0; 113ff2ed70fa30f04b90dd1a2c06ec2319e157152d7Mathias Agopian 1143f84483382be2d528918cc1a6fbc6a7d68e0b181Mathias Agopian // queries 115875d8e1323536e16dcfc90c9674d7ad32116a69aMathias Agopian virtual size_t getMaxTextureSize() const = 0; 116875d8e1323536e16dcfc90c9674d7ad32116a69aMathias Agopian virtual size_t getMaxViewportDims() const = 0; 117875d8e1323536e16dcfc90c9674d7ad32116a69aMathias Agopian 11805f8c703d4a050669ff8f406be3a9dc2357935f7Jesse Hall EGLConfig getEGLConfig() const; 119875d8e1323536e16dcfc90c9674d7ad32116a69aMathias Agopian EGLContext getEGLContext() const; 120875d8e1323536e16dcfc90c9674d7ad32116a69aMathias Agopian}; 121875d8e1323536e16dcfc90c9674d7ad32116a69aMathias Agopian 122875d8e1323536e16dcfc90c9674d7ad32116a69aMathias Agopian// --------------------------------------------------------------------------- 123875d8e1323536e16dcfc90c9674d7ad32116a69aMathias Agopian}; // namespace android 124875d8e1323536e16dcfc90c9674d7ad32116a69aMathias Agopian// --------------------------------------------------------------------------- 125875d8e1323536e16dcfc90c9674d7ad32116a69aMathias Agopian 126875d8e1323536e16dcfc90c9674d7ad32116a69aMathias Agopian#endif /* SF_RENDERENGINE_H_ */ 127