Android P系统输出图像镜像翻转实现

特殊需求,对Android的输出图像做镜像翻转。

Screen convert

翻转x修改

源码:frameworks/native/services/surfaceflinger/RenderEngine/ProgramCache.cpp

  String8 ProgramCache::generateVertexShader(const Key& needs) {
      Formatter vs;
      if (needs.isTexturing()) {
          vs << "attribute vec4 texCoords;"
             << "varying vec2 outTexCoords;";
      }
      vs << "attribute vec4 position;"
         << "uniform mat4 projection;"
         << "uniform mat4 texture;"
         << "void main(void) {" << indent << "gl_Position = projection * position;"
         << "gl_Position.x = float(0) - gl_Position.x;";									// 修改内容
      if (needs.isTexturing()) {
          vs << "outTexCoords = (texture * texCoords).st;";
      }
      vs << dedent << "}";
      return vs.getString();
  }
  • diff
  diff --git a/android9.0.0/frameworks/native/services/surfaceflinger/RenderEngine/ProgramCache.cpp b/android9.0.0/frameworks/native/services/surfaceflinger/RenderEngine/ProgramCache.cpp
  index 9dc6858566..45545665b6 100644
  --- a/android9.0.0/frameworks/native/services/surfaceflinger/RenderEngine/ProgramCache.cpp
  +++ b/android9.0.0/frameworks/native/services/surfaceflinger/RenderEngine/ProgramCache.cpp
  @@ -523,7 +523,8 @@ String8 ProgramCache::generateVertexShader(const Key& needs) {
       vs << "attribute vec4 position;"
          << "uniform mat4 projection;"
          << "uniform mat4 texture;"
  -       << "void main(void) {" << indent << "gl_Position = projection * position;";
  +       << "void main(void) {" << indent << "gl_Position = projection * position;"
  +       << "gl_Position.x = float(0) - gl_Position.x;";
       if (needs.isTexturing()) {
           vs << "outTexCoords = (texture * texCoords).st;";
       }

你可能感兴趣的:(android,p系统架构)