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>
261d77b719d51a01cbd6954a048fb64e79d50a950eMathias Agopian#include <math/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
664e63777f75e9756c74352e62e79dfa8a994de2b3Dan Stoza    void primeCache() const;
674e63777f75e9756c74352e62e79dfa8a994de2b3Dan Stoza
68458197de008be8fe561286b09f4edddb2f5c540aMathias Agopian    // dump the extension strings. always call the base class.
69458197de008be8fe561286b09f4edddb2f5c540aMathias Agopian    virtual void dump(String8& result);
70458197de008be8fe561286b09f4edddb2f5c540aMathias Agopian
713f84483382be2d528918cc1a6fbc6a7d68e0b181Mathias Agopian    // helpers
729707f4df640c3369f873a934bb05ffa5a68a5640Riley Andrews    void flush();
733f84483382be2d528918cc1a6fbc6a7d68e0b181Mathias Agopian    void clearWithColor(float red, float green, float blue, float alpha);
743f84483382be2d528918cc1a6fbc6a7d68e0b181Mathias Agopian    void fillRegionWithColor(const Region& region, uint32_t height,
753f84483382be2d528918cc1a6fbc6a7d68e0b181Mathias Agopian            float red, float green, float blue, float alpha);
763f84483382be2d528918cc1a6fbc6a7d68e0b181Mathias Agopian
773f84483382be2d528918cc1a6fbc6a7d68e0b181Mathias Agopian    // common to all GL versions
783f84483382be2d528918cc1a6fbc6a7d68e0b181Mathias Agopian    void setScissor(uint32_t left, uint32_t bottom, uint32_t right, uint32_t top);
793f84483382be2d528918cc1a6fbc6a7d68e0b181Mathias Agopian    void disableScissor();
803f84483382be2d528918cc1a6fbc6a7d68e0b181Mathias Agopian    void genTextures(size_t count, uint32_t* names);
813f84483382be2d528918cc1a6fbc6a7d68e0b181Mathias Agopian    void deleteTextures(size_t count, uint32_t const* names);
82d555684cb36dfb959694db76962e570184f98838Mathias Agopian    void readPixels(size_t l, size_t b, size_t w, size_t h, uint32_t* pixels);
833f84483382be2d528918cc1a6fbc6a7d68e0b181Mathias Agopian
843f84483382be2d528918cc1a6fbc6a7d68e0b181Mathias Agopian    class BindImageAsFramebuffer {
853f84483382be2d528918cc1a6fbc6a7d68e0b181Mathias Agopian        RenderEngine& mEngine;
86458197de008be8fe561286b09f4edddb2f5c540aMathias Agopian        uint32_t mTexName, mFbName;
87458197de008be8fe561286b09f4edddb2f5c540aMathias Agopian        uint32_t mStatus;
883f84483382be2d528918cc1a6fbc6a7d68e0b181Mathias Agopian    public:
893f84483382be2d528918cc1a6fbc6a7d68e0b181Mathias Agopian        BindImageAsFramebuffer(RenderEngine& engine, EGLImageKHR image);
903f84483382be2d528918cc1a6fbc6a7d68e0b181Mathias Agopian        ~BindImageAsFramebuffer();
913f84483382be2d528918cc1a6fbc6a7d68e0b181Mathias Agopian        int getStatus() const;
923f84483382be2d528918cc1a6fbc6a7d68e0b181Mathias Agopian    };
93875d8e1323536e16dcfc90c9674d7ad32116a69aMathias Agopian
943f84483382be2d528918cc1a6fbc6a7d68e0b181Mathias Agopian    // set-up
953f84483382be2d528918cc1a6fbc6a7d68e0b181Mathias Agopian    virtual void checkErrors() const;
96c18790018be5d7ea7061ccbc81f3044e74adc823Dan Stoza    virtual void setViewportAndProjection(size_t vpw, size_t vph,
97c3ebe66b49cfba035e1fd0e160a13db38eb81b0eRiley Andrews            Rect sourceCrop, size_t hwh, bool yswap, Transform::orientation_flags rotation) = 0;
989d96de49673cb6c916bfb797aad4f4e024ea73caFabien Sanglard#ifdef USE_HWC2
999e56aa0fdb5f7121b9b975c6c16db103ea4d2fe9Dan Stoza    virtual void setupLayerBlending(bool premultipliedAlpha, bool opaque, float alpha) = 0;
1009e56aa0fdb5f7121b9b975c6c16db103ea4d2fe9Dan Stoza    virtual void setupDimLayerBlending(float alpha) = 0;
1015d94389241cc651e6bd327ab80eba3ad476f3724Courtney Goeltzenleuchter    virtual void setColorMode(android_color_mode mode) = 0;
1025d94389241cc651e6bd327ab80eba3ad476f3724Courtney Goeltzenleuchter    virtual void setSourceDataSpace(android_dataspace source) = 0;
1035d94389241cc651e6bd327ab80eba3ad476f3724Courtney Goeltzenleuchter    virtual void setWideColor(bool hasWideColor) = 0;
1045d94389241cc651e6bd327ab80eba3ad476f3724Courtney Goeltzenleuchter    virtual bool usesWideColor() = 0;
1059d96de49673cb6c916bfb797aad4f4e024ea73caFabien Sanglard#else
1069d96de49673cb6c916bfb797aad4f4e024ea73caFabien Sanglard    virtual void setupLayerBlending(bool premultipliedAlpha, bool opaque, int alpha) = 0;
1079d96de49673cb6c916bfb797aad4f4e024ea73caFabien Sanglard    virtual void setupDimLayerBlending(int alpha) = 0;
1089d96de49673cb6c916bfb797aad4f4e024ea73caFabien Sanglard#endif
10949457ac092071a8f964f7f69156093657ccdc3d0Mathias Agopian    virtual void setupLayerTexturing(const Texture& texture) = 0;
110875d8e1323536e16dcfc90c9674d7ad32116a69aMathias Agopian    virtual void setupLayerBlackedOut() = 0;
11119733a32799f792125913e746e8644d16f8dc223Mathias Agopian    virtual void setupFillWithColor(float r, float g, float b, float a) = 0;
112875d8e1323536e16dcfc90c9674d7ad32116a69aMathias Agopian
113f008799d3753e52c10849824ff8146985ea66284Dan Stoza    virtual mat4 setupColorTransform(const mat4& /* colorTransform */) {
114f008799d3753e52c10849824ff8146985ea66284Dan Stoza        return mat4();
115f008799d3753e52c10849824ff8146985ea66284Dan Stoza    }
116f008799d3753e52c10849824ff8146985ea66284Dan Stoza
117875d8e1323536e16dcfc90c9674d7ad32116a69aMathias Agopian    virtual void disableTexturing() = 0;
118875d8e1323536e16dcfc90c9674d7ad32116a69aMathias Agopian    virtual void disableBlending() = 0;
119875d8e1323536e16dcfc90c9674d7ad32116a69aMathias Agopian
1203f84483382be2d528918cc1a6fbc6a7d68e0b181Mathias Agopian    // drawing
1213f84483382be2d528918cc1a6fbc6a7d68e0b181Mathias Agopian    virtual void drawMesh(const Mesh& mesh) = 0;
122875d8e1323536e16dcfc90c9674d7ad32116a69aMathias Agopian
1233f84483382be2d528918cc1a6fbc6a7d68e0b181Mathias Agopian    // queries
124875d8e1323536e16dcfc90c9674d7ad32116a69aMathias Agopian    virtual size_t getMaxTextureSize() const = 0;
125875d8e1323536e16dcfc90c9674d7ad32116a69aMathias Agopian    virtual size_t getMaxViewportDims() const = 0;
126875d8e1323536e16dcfc90c9674d7ad32116a69aMathias Agopian
12705f8c703d4a050669ff8f406be3a9dc2357935f7Jesse Hall    EGLConfig getEGLConfig() const;
128875d8e1323536e16dcfc90c9674d7ad32116a69aMathias Agopian    EGLContext getEGLContext() const;
129875d8e1323536e16dcfc90c9674d7ad32116a69aMathias Agopian};
130875d8e1323536e16dcfc90c9674d7ad32116a69aMathias Agopian
131875d8e1323536e16dcfc90c9674d7ad32116a69aMathias Agopian// ---------------------------------------------------------------------------
132875d8e1323536e16dcfc90c9674d7ad32116a69aMathias Agopian}; // namespace android
133875d8e1323536e16dcfc90c9674d7ad32116a69aMathias Agopian// ---------------------------------------------------------------------------
134875d8e1323536e16dcfc90c9674d7ad32116a69aMathias Agopian
135875d8e1323536e16dcfc90c9674d7ad32116a69aMathias Agopian#endif /* SF_RENDERENGINE_H_ */
136