RenderEngine.h revision 19e872912af66c53a4350afcc333bbafaf6a2294
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
2819e872912af66c53a4350afcc333bbafaf6a2294Jesse Hall#define EGL_NO_CONFIG ((EGLConfig)0)
2919e872912af66c53a4350afcc333bbafaf6a2294Jesse Hall
30875d8e1323536e16dcfc90c9674d7ad32116a69aMathias Agopian// ---------------------------------------------------------------------------
31875d8e1323536e16dcfc90c9674d7ad32116a69aMathias Agopiannamespace android {
32875d8e1323536e16dcfc90c9674d7ad32116a69aMathias Agopian// ---------------------------------------------------------------------------
33875d8e1323536e16dcfc90c9674d7ad32116a69aMathias Agopian
34875d8e1323536e16dcfc90c9674d7ad32116a69aMathias Agopianclass String8;
353f84483382be2d528918cc1a6fbc6a7d68e0b181Mathias Agopianclass Rect;
363f84483382be2d528918cc1a6fbc6a7d68e0b181Mathias Agopianclass Region;
373f84483382be2d528918cc1a6fbc6a7d68e0b181Mathias Agopianclass Mesh;
3849457ac092071a8f964f7f69156093657ccdc3d0Mathias Agopianclass Texture;
39875d8e1323536e16dcfc90c9674d7ad32116a69aMathias Agopian
40875d8e1323536e16dcfc90c9674d7ad32116a69aMathias Agopianclass RenderEngine {
41875d8e1323536e16dcfc90c9674d7ad32116a69aMathias Agopian    enum GlesVersion {
42875d8e1323536e16dcfc90c9674d7ad32116a69aMathias Agopian        GLES_VERSION_1_0    = 0x10000,
43875d8e1323536e16dcfc90c9674d7ad32116a69aMathias Agopian        GLES_VERSION_1_1    = 0x10001,
44875d8e1323536e16dcfc90c9674d7ad32116a69aMathias Agopian        GLES_VERSION_2_0    = 0x20000,
45875d8e1323536e16dcfc90c9674d7ad32116a69aMathias Agopian        GLES_VERSION_3_0    = 0x30000,
46875d8e1323536e16dcfc90c9674d7ad32116a69aMathias Agopian    };
47875d8e1323536e16dcfc90c9674d7ad32116a69aMathias Agopian    static GlesVersion parseGlesVersion(const char* str);
48875d8e1323536e16dcfc90c9674d7ad32116a69aMathias Agopian
4905f8c703d4a050669ff8f406be3a9dc2357935f7Jesse Hall    EGLConfig mEGLConfig;
50875d8e1323536e16dcfc90c9674d7ad32116a69aMathias Agopian    EGLContext mEGLContext;
5105f8c703d4a050669ff8f406be3a9dc2357935f7Jesse Hall    void setEGLHandles(EGLConfig config, EGLContext ctxt);
52875d8e1323536e16dcfc90c9674d7ad32116a69aMathias Agopian
53458197de008be8fe561286b09f4edddb2f5c540aMathias Agopian    virtual void bindImageAsFramebuffer(EGLImageKHR image, uint32_t* texName, uint32_t* fbName, uint32_t* status) = 0;
54458197de008be8fe561286b09f4edddb2f5c540aMathias Agopian    virtual void unbindFramebuffer(uint32_t texName, uint32_t fbName) = 0;
55458197de008be8fe561286b09f4edddb2f5c540aMathias Agopian
56875d8e1323536e16dcfc90c9674d7ad32116a69aMathias Agopianprotected:
57875d8e1323536e16dcfc90c9674d7ad32116a69aMathias Agopian    RenderEngine();
58875d8e1323536e16dcfc90c9674d7ad32116a69aMathias Agopian    virtual ~RenderEngine() = 0;
59875d8e1323536e16dcfc90c9674d7ad32116a69aMathias Agopian
60875d8e1323536e16dcfc90c9674d7ad32116a69aMathias Agopianpublic:
6105f8c703d4a050669ff8f406be3a9dc2357935f7Jesse Hall    static RenderEngine* create(EGLDisplay display, int hwcFormat);
6205f8c703d4a050669ff8f406be3a9dc2357935f7Jesse Hall
6305f8c703d4a050669ff8f406be3a9dc2357935f7Jesse Hall    static EGLConfig chooseEglConfig(EGLDisplay display, int format);
64875d8e1323536e16dcfc90c9674d7ad32116a69aMathias Agopian
65458197de008be8fe561286b09f4edddb2f5c540aMathias Agopian    // dump the extension strings. always call the base class.
66458197de008be8fe561286b09f4edddb2f5c540aMathias Agopian    virtual void dump(String8& result);
67458197de008be8fe561286b09f4edddb2f5c540aMathias Agopian
683f84483382be2d528918cc1a6fbc6a7d68e0b181Mathias Agopian    // helpers
693f84483382be2d528918cc1a6fbc6a7d68e0b181Mathias Agopian    void clearWithColor(float red, float green, float blue, float alpha);
703f84483382be2d528918cc1a6fbc6a7d68e0b181Mathias Agopian    void fillRegionWithColor(const Region& region, uint32_t height,
713f84483382be2d528918cc1a6fbc6a7d68e0b181Mathias Agopian            float red, float green, float blue, float alpha);
723f84483382be2d528918cc1a6fbc6a7d68e0b181Mathias Agopian
733f84483382be2d528918cc1a6fbc6a7d68e0b181Mathias Agopian    // common to all GL versions
743f84483382be2d528918cc1a6fbc6a7d68e0b181Mathias Agopian    void setScissor(uint32_t left, uint32_t bottom, uint32_t right, uint32_t top);
753f84483382be2d528918cc1a6fbc6a7d68e0b181Mathias Agopian    void disableScissor();
763f84483382be2d528918cc1a6fbc6a7d68e0b181Mathias Agopian    void genTextures(size_t count, uint32_t* names);
773f84483382be2d528918cc1a6fbc6a7d68e0b181Mathias Agopian    void deleteTextures(size_t count, uint32_t const* names);
78d555684cb36dfb959694db76962e570184f98838Mathias Agopian    void readPixels(size_t l, size_t b, size_t w, size_t h, uint32_t* pixels);
793f84483382be2d528918cc1a6fbc6a7d68e0b181Mathias Agopian
803f84483382be2d528918cc1a6fbc6a7d68e0b181Mathias Agopian    class BindImageAsFramebuffer {
813f84483382be2d528918cc1a6fbc6a7d68e0b181Mathias Agopian        RenderEngine& mEngine;
82458197de008be8fe561286b09f4edddb2f5c540aMathias Agopian        uint32_t mTexName, mFbName;
83458197de008be8fe561286b09f4edddb2f5c540aMathias Agopian        uint32_t mStatus;
843f84483382be2d528918cc1a6fbc6a7d68e0b181Mathias Agopian    public:
853f84483382be2d528918cc1a6fbc6a7d68e0b181Mathias Agopian        BindImageAsFramebuffer(RenderEngine& engine, EGLImageKHR image);
863f84483382be2d528918cc1a6fbc6a7d68e0b181Mathias Agopian        ~BindImageAsFramebuffer();
873f84483382be2d528918cc1a6fbc6a7d68e0b181Mathias Agopian        int getStatus() const;
883f84483382be2d528918cc1a6fbc6a7d68e0b181Mathias Agopian    };
89875d8e1323536e16dcfc90c9674d7ad32116a69aMathias Agopian
903f84483382be2d528918cc1a6fbc6a7d68e0b181Mathias Agopian    // set-up
913f84483382be2d528918cc1a6fbc6a7d68e0b181Mathias Agopian    virtual void checkErrors() const;
923f84483382be2d528918cc1a6fbc6a7d68e0b181Mathias Agopian    virtual void setViewportAndProjection(size_t vpw, size_t vph, size_t w, size_t h, bool yswap) = 0;
93875d8e1323536e16dcfc90c9674d7ad32116a69aMathias Agopian    virtual void setupLayerBlending(bool premultipliedAlpha, bool opaque, int alpha) = 0;
94875d8e1323536e16dcfc90c9674d7ad32116a69aMathias Agopian    virtual void setupDimLayerBlending(int alpha) = 0;
9549457ac092071a8f964f7f69156093657ccdc3d0Mathias Agopian    virtual void setupLayerTexturing(const Texture& texture) = 0;
96875d8e1323536e16dcfc90c9674d7ad32116a69aMathias Agopian    virtual void setupLayerBlackedOut() = 0;
9719733a32799f792125913e746e8644d16f8dc223Mathias Agopian    virtual void setupFillWithColor(float r, float g, float b, float a) = 0;
98875d8e1323536e16dcfc90c9674d7ad32116a69aMathias Agopian
99875d8e1323536e16dcfc90c9674d7ad32116a69aMathias Agopian    virtual void disableTexturing() = 0;
100875d8e1323536e16dcfc90c9674d7ad32116a69aMathias Agopian    virtual void disableBlending() = 0;
101875d8e1323536e16dcfc90c9674d7ad32116a69aMathias Agopian
1023f84483382be2d528918cc1a6fbc6a7d68e0b181Mathias Agopian    // drawing
1033f84483382be2d528918cc1a6fbc6a7d68e0b181Mathias Agopian    virtual void drawMesh(const Mesh& mesh) = 0;
104875d8e1323536e16dcfc90c9674d7ad32116a69aMathias Agopian
105ff2ed70fa30f04b90dd1a2c06ec2319e157152d7Mathias Agopian    // grouping
106ff2ed70fa30f04b90dd1a2c06ec2319e157152d7Mathias Agopian    // creates a color-transform group, everything drawn in the group will be
107ff2ed70fa30f04b90dd1a2c06ec2319e157152d7Mathias Agopian    // transformed by the given color transform when endGroup() is called.
108ff2ed70fa30f04b90dd1a2c06ec2319e157152d7Mathias Agopian    virtual void beginGroup(const mat4& colorTransform) = 0;
109ff2ed70fa30f04b90dd1a2c06ec2319e157152d7Mathias Agopian    virtual void endGroup() = 0;
110ff2ed70fa30f04b90dd1a2c06ec2319e157152d7Mathias Agopian
1113f84483382be2d528918cc1a6fbc6a7d68e0b181Mathias Agopian    // queries
112875d8e1323536e16dcfc90c9674d7ad32116a69aMathias Agopian    virtual size_t getMaxTextureSize() const = 0;
113875d8e1323536e16dcfc90c9674d7ad32116a69aMathias Agopian    virtual size_t getMaxViewportDims() const = 0;
114875d8e1323536e16dcfc90c9674d7ad32116a69aMathias Agopian
11505f8c703d4a050669ff8f406be3a9dc2357935f7Jesse Hall    EGLConfig getEGLConfig() const;
116875d8e1323536e16dcfc90c9674d7ad32116a69aMathias Agopian    EGLContext getEGLContext() const;
117875d8e1323536e16dcfc90c9674d7ad32116a69aMathias Agopian};
118875d8e1323536e16dcfc90c9674d7ad32116a69aMathias Agopian
119875d8e1323536e16dcfc90c9674d7ad32116a69aMathias Agopian// ---------------------------------------------------------------------------
120875d8e1323536e16dcfc90c9674d7ad32116a69aMathias Agopian}; // namespace android
121875d8e1323536e16dcfc90c9674d7ad32116a69aMathias Agopian// ---------------------------------------------------------------------------
122875d8e1323536e16dcfc90c9674d7ad32116a69aMathias Agopian
123875d8e1323536e16dcfc90c9674d7ad32116a69aMathias Agopian#endif /* SF_RENDERENGINE_H_ */
124