RenderEngine.h 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137
  1. /*
  2. * Copyright 2013 The Android Open Source Project
  3. *
  4. * Licensed under the Apache License, Version 2.0 (the "License");
  5. * you may not use this file except in compliance with the License.
  6. * You may obtain a copy of the License at
  7. *
  8. * http://www.apache.org/licenses/LICENSE-2.0
  9. *
  10. * Unless required by applicable law or agreed to in writing, software
  11. * distributed under the License is distributed on an "AS IS" BASIS,
  12. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  13. * See the License for the specific language governing permissions and
  14. * limitations under the License.
  15. */
  16. #ifndef SF_RENDERENGINE_H_
  17. #define SF_RENDERENGINE_H_
  18. #include <stdint.h>
  19. #include <sys/types.h>
  20. #include <EGL/egl.h>
  21. #include <EGL/eglext.h>
  22. #include <ui/mat4.h>
  23. #include <Transform.h>
  24. #define EGL_NO_CONFIG ((EGLConfig)0)
  25. // ---------------------------------------------------------------------------
  26. namespace android {
  27. // ---------------------------------------------------------------------------
  28. class String8;
  29. class Rect;
  30. class Region;
  31. class Mesh;
  32. class Texture;
  33. class RenderEngine {
  34. enum GlesVersion {
  35. GLES_VERSION_1_0 = 0x10000,
  36. GLES_VERSION_1_1 = 0x10001,
  37. GLES_VERSION_2_0 = 0x20000,
  38. GLES_VERSION_3_0 = 0x30000,
  39. };
  40. static GlesVersion parseGlesVersion(const char* str);
  41. EGLConfig mEGLConfig;
  42. EGLContext mEGLContext;
  43. void setEGLHandles(EGLConfig config, EGLContext ctxt);
  44. virtual void bindImageAsFramebuffer(EGLImageKHR image, uint32_t* texName,
  45. uint32_t* fbName, uint32_t* status, bool useReadPixels, int reqWidth,
  46. int reqHeight) = 0;
  47. virtual void unbindFramebuffer(uint32_t texName, uint32_t fbName,
  48. bool useReadPixels) = 0;
  49. protected:
  50. RenderEngine();
  51. virtual ~RenderEngine() = 0;
  52. public:
  53. static RenderEngine* create(EGLDisplay display, int hwcFormat);
  54. static EGLConfig chooseEglConfig(EGLDisplay display, int format);
  55. // dump the extension strings. always call the base class.
  56. virtual void dump(String8& result);
  57. // helpers
  58. void flush();
  59. void clearWithColor(float red, float green, float blue, float alpha);
  60. void fillRegionWithColor(const Region& region, uint32_t height,
  61. float red, float green, float blue, float alpha);
  62. // common to all GL versions
  63. void setScissor(uint32_t left, uint32_t bottom, uint32_t right, uint32_t top);
  64. void disableScissor();
  65. void genTextures(size_t count, uint32_t* names);
  66. void deleteTextures(size_t count, uint32_t const* names);
  67. void readPixels(size_t l, size_t b, size_t w, size_t h, uint32_t* pixels);
  68. class BindImageAsFramebuffer {
  69. RenderEngine& mEngine;
  70. uint32_t mTexName, mFbName;
  71. uint32_t mStatus;
  72. bool mUseReadPixels;
  73. public:
  74. BindImageAsFramebuffer(RenderEngine& engine, EGLImageKHR image,
  75. bool useReadPixels, int reqWidth, int reqHeight);
  76. ~BindImageAsFramebuffer();
  77. int getStatus() const;
  78. };
  79. // set-up
  80. virtual void checkErrors() const;
  81. virtual void setViewportAndProjection(size_t vpw, size_t vph,
  82. Rect sourceCrop, size_t hwh, bool yswap, Transform::orientation_flags rotation) = 0;
  83. virtual void setupLayerBlending(bool premultipliedAlpha, bool opaque, int alpha) = 0;
  84. virtual void setupDimLayerBlending(int alpha) = 0;
  85. virtual void setupLayerTexturing(const Texture& texture) = 0;
  86. virtual void setupLayerBlackedOut() = 0;
  87. virtual void setupFillWithColor(float r, float g, float b, float a) = 0;
  88. virtual mat4 setupColorTransform(const mat4& /* colorTransform */) {
  89. return mat4();
  90. }
  91. virtual void disableTexturing() = 0;
  92. virtual void disableBlending() = 0;
  93. virtual void setupLayerMasking(const Texture& maskTexture, float alphaThreshold) = 0;
  94. virtual void disableLayerMasking() = 0;
  95. // drawing
  96. virtual void drawMesh(const Mesh& mesh) = 0;
  97. // queries
  98. virtual size_t getMaxTextureSize() const = 0;
  99. virtual size_t getMaxViewportDims() const = 0;
  100. virtual bool getProjectionYSwap() { return 0; }
  101. virtual size_t getViewportWidth() const { return 1; }
  102. virtual size_t getViewportHeight() const { return 1; }
  103. virtual Rect getProjectionSourceCrop() const { return Rect(0, 0, 1, 1); }
  104. virtual Transform::orientation_flags getProjectionRotation() const { return Transform::ROT_0; }
  105. EGLConfig getEGLConfig() const;
  106. EGLContext getEGLContext() const;
  107. };
  108. // ---------------------------------------------------------------------------
  109. }; // namespace android
  110. // ---------------------------------------------------------------------------
  111. #endif /* SF_RENDERENGINE_H_ */