RenderEngine.h revision 458197de008be8fe561286b09f4edddb2f5c540a
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;
35875d8e1323536e16dcfc90c9674d7ad32116a69aMathias Agopian
36875d8e1323536e16dcfc90c9674d7ad32116a69aMathias Agopianclass RenderEngine {
37875d8e1323536e16dcfc90c9674d7ad32116a69aMathias Agopian    enum GlesVersion {
38875d8e1323536e16dcfc90c9674d7ad32116a69aMathias Agopian        GLES_VERSION_1_0    = 0x10000,
39875d8e1323536e16dcfc90c9674d7ad32116a69aMathias Agopian        GLES_VERSION_1_1    = 0x10001,
40875d8e1323536e16dcfc90c9674d7ad32116a69aMathias Agopian        GLES_VERSION_2_0    = 0x20000,
41875d8e1323536e16dcfc90c9674d7ad32116a69aMathias Agopian        GLES_VERSION_3_0    = 0x30000,
42875d8e1323536e16dcfc90c9674d7ad32116a69aMathias Agopian    };
43875d8e1323536e16dcfc90c9674d7ad32116a69aMathias Agopian    static GlesVersion parseGlesVersion(const char* str);
44875d8e1323536e16dcfc90c9674d7ad32116a69aMathias Agopian
45875d8e1323536e16dcfc90c9674d7ad32116a69aMathias Agopian    EGLContext mEGLContext;
46875d8e1323536e16dcfc90c9674d7ad32116a69aMathias Agopian    void setEGLContext(EGLContext ctxt);
47875d8e1323536e16dcfc90c9674d7ad32116a69aMathias Agopian
48458197de008be8fe561286b09f4edddb2f5c540aMathias Agopian    virtual void bindImageAsFramebuffer(EGLImageKHR image, uint32_t* texName, uint32_t* fbName, uint32_t* status) = 0;
49458197de008be8fe561286b09f4edddb2f5c540aMathias Agopian    virtual void unbindFramebuffer(uint32_t texName, uint32_t fbName) = 0;
50458197de008be8fe561286b09f4edddb2f5c540aMathias Agopian
51875d8e1323536e16dcfc90c9674d7ad32116a69aMathias Agopianprotected:
52875d8e1323536e16dcfc90c9674d7ad32116a69aMathias Agopian    RenderEngine();
53875d8e1323536e16dcfc90c9674d7ad32116a69aMathias Agopian    virtual ~RenderEngine() = 0;
54875d8e1323536e16dcfc90c9674d7ad32116a69aMathias Agopian
55875d8e1323536e16dcfc90c9674d7ad32116a69aMathias Agopianpublic:
56875d8e1323536e16dcfc90c9674d7ad32116a69aMathias Agopian    static RenderEngine* create(EGLDisplay display, EGLConfig config);
57875d8e1323536e16dcfc90c9674d7ad32116a69aMathias Agopian
58458197de008be8fe561286b09f4edddb2f5c540aMathias Agopian    // dump the extension strings. always call the base class.
59458197de008be8fe561286b09f4edddb2f5c540aMathias Agopian    virtual void dump(String8& result);
60458197de008be8fe561286b09f4edddb2f5c540aMathias Agopian
613f84483382be2d528918cc1a6fbc6a7d68e0b181Mathias Agopian    // helpers
623f84483382be2d528918cc1a6fbc6a7d68e0b181Mathias Agopian    void clearWithColor(float red, float green, float blue, float alpha);
633f84483382be2d528918cc1a6fbc6a7d68e0b181Mathias Agopian    void fillRegionWithColor(const Region& region, uint32_t height,
643f84483382be2d528918cc1a6fbc6a7d68e0b181Mathias Agopian            float red, float green, float blue, float alpha);
653f84483382be2d528918cc1a6fbc6a7d68e0b181Mathias Agopian
663f84483382be2d528918cc1a6fbc6a7d68e0b181Mathias Agopian    // common to all GL versions
673f84483382be2d528918cc1a6fbc6a7d68e0b181Mathias Agopian    void setScissor(uint32_t left, uint32_t bottom, uint32_t right, uint32_t top);
683f84483382be2d528918cc1a6fbc6a7d68e0b181Mathias Agopian    void disableScissor();
693f84483382be2d528918cc1a6fbc6a7d68e0b181Mathias Agopian    void genTextures(size_t count, uint32_t* names);
703f84483382be2d528918cc1a6fbc6a7d68e0b181Mathias Agopian    void deleteTextures(size_t count, uint32_t const* names);
713f84483382be2d528918cc1a6fbc6a7d68e0b181Mathias Agopian
723f84483382be2d528918cc1a6fbc6a7d68e0b181Mathias Agopian    class BindImageAsFramebuffer {
733f84483382be2d528918cc1a6fbc6a7d68e0b181Mathias Agopian        RenderEngine& mEngine;
74458197de008be8fe561286b09f4edddb2f5c540aMathias Agopian        uint32_t mTexName, mFbName;
75458197de008be8fe561286b09f4edddb2f5c540aMathias Agopian        uint32_t mStatus;
763f84483382be2d528918cc1a6fbc6a7d68e0b181Mathias Agopian    public:
773f84483382be2d528918cc1a6fbc6a7d68e0b181Mathias Agopian        BindImageAsFramebuffer(RenderEngine& engine, EGLImageKHR image);
783f84483382be2d528918cc1a6fbc6a7d68e0b181Mathias Agopian        ~BindImageAsFramebuffer();
793f84483382be2d528918cc1a6fbc6a7d68e0b181Mathias Agopian        int getStatus() const;
803f84483382be2d528918cc1a6fbc6a7d68e0b181Mathias Agopian    };
81875d8e1323536e16dcfc90c9674d7ad32116a69aMathias Agopian
823f84483382be2d528918cc1a6fbc6a7d68e0b181Mathias Agopian    // set-up
833f84483382be2d528918cc1a6fbc6a7d68e0b181Mathias Agopian    virtual void checkErrors() const;
843f84483382be2d528918cc1a6fbc6a7d68e0b181Mathias Agopian    virtual void setViewportAndProjection(size_t vpw, size_t vph, size_t w, size_t h, bool yswap) = 0;
85875d8e1323536e16dcfc90c9674d7ad32116a69aMathias Agopian    virtual void setupLayerBlending(bool premultipliedAlpha, bool opaque, int alpha) = 0;
86875d8e1323536e16dcfc90c9674d7ad32116a69aMathias Agopian    virtual void setupDimLayerBlending(int alpha) = 0;
87875d8e1323536e16dcfc90c9674d7ad32116a69aMathias Agopian    virtual void setupLayerTexturing(size_t textureName, bool useFiltering, const float* textureMatrix) = 0;
88875d8e1323536e16dcfc90c9674d7ad32116a69aMathias Agopian    virtual void setupLayerBlackedOut() = 0;
89875d8e1323536e16dcfc90c9674d7ad32116a69aMathias Agopian
90875d8e1323536e16dcfc90c9674d7ad32116a69aMathias Agopian    virtual void disableTexturing() = 0;
91875d8e1323536e16dcfc90c9674d7ad32116a69aMathias Agopian    virtual void disableBlending() = 0;
92875d8e1323536e16dcfc90c9674d7ad32116a69aMathias Agopian
933f84483382be2d528918cc1a6fbc6a7d68e0b181Mathias Agopian    // drawing
943f84483382be2d528918cc1a6fbc6a7d68e0b181Mathias Agopian    virtual void fillWithColor(const Mesh& mesh, float r, float g, float b, float a) = 0;
953f84483382be2d528918cc1a6fbc6a7d68e0b181Mathias Agopian    virtual void drawMesh(const Mesh& mesh) = 0;
96875d8e1323536e16dcfc90c9674d7ad32116a69aMathias Agopian
973f84483382be2d528918cc1a6fbc6a7d68e0b181Mathias Agopian    // queries
98875d8e1323536e16dcfc90c9674d7ad32116a69aMathias Agopian    virtual size_t getMaxTextureSize() const = 0;
99875d8e1323536e16dcfc90c9674d7ad32116a69aMathias Agopian    virtual size_t getMaxViewportDims() const = 0;
100875d8e1323536e16dcfc90c9674d7ad32116a69aMathias Agopian
1013f84483382be2d528918cc1a6fbc6a7d68e0b181Mathias Agopian
1023f84483382be2d528918cc1a6fbc6a7d68e0b181Mathias Agopian
103875d8e1323536e16dcfc90c9674d7ad32116a69aMathias Agopian    EGLContext getEGLContext() const;
104875d8e1323536e16dcfc90c9674d7ad32116a69aMathias Agopian};
105875d8e1323536e16dcfc90c9674d7ad32116a69aMathias Agopian
106875d8e1323536e16dcfc90c9674d7ad32116a69aMathias Agopian// ---------------------------------------------------------------------------
107875d8e1323536e16dcfc90c9674d7ad32116a69aMathias Agopian}; // namespace android
108875d8e1323536e16dcfc90c9674d7ad32116a69aMathias Agopian// ---------------------------------------------------------------------------
109875d8e1323536e16dcfc90c9674d7ad32116a69aMathias Agopian
110875d8e1323536e16dcfc90c9674d7ad32116a69aMathias Agopian#endif /* SF_RENDERENGINE_H_ */
111