surfaceflinger: use Vulkan coordinate system
In Vulkan coordinate system, (0, 0) always maps to memory address 0.
In GL coordinate system, (0, 0) maps to the bottom-left corner. The
two agree when doing offscreen rendering. But when rendering to a
window, GL maps (0, 0) to memory address (winHeight-1)*rowStride,
because that is where the bottom-left pixel is.
Let's pick the simpler one for RenderEngine in preparation for
multiple backends. As a result, we don't need yswap when rendering
to offscreen buffers (it is hidden behind the RenderEngine API). It
also makes no sense to flip Y coordinate for both vertex postions
and the viewing volume.
Test: chrome, youtube, camera, screen rotation, screenshots, recents
Change-Id: I6d6317bac3de6f208700a67e518011362c600ced
diff --git a/services/surfaceflinger/RenderEngine/gl/GLES20RenderEngine.cpp b/services/surfaceflinger/RenderEngine/gl/GLES20RenderEngine.cpp
index e0f1850..42d4887 100644
--- a/services/surfaceflinger/RenderEngine/gl/GLES20RenderEngine.cpp
+++ b/services/surfaceflinger/RenderEngine/gl/GLES20RenderEngine.cpp
@@ -160,21 +160,15 @@
}
void GLES20RenderEngine::setViewportAndProjection(size_t vpw, size_t vph, Rect sourceCrop,
- size_t hwh, bool yswap,
ui::Transform::orientation_flags rotation) {
int32_t l = sourceCrop.left;
int32_t r = sourceCrop.right;
-
- // In GL, (0, 0) is the bottom-left corner, so flip y coordinates
- int32_t t = hwh - sourceCrop.top;
- int32_t b = hwh - sourceCrop.bottom;
-
- mat4 m;
- if (yswap) {
- m = mat4::ortho(l, r, t, b, 0, 1);
- } else {
- m = mat4::ortho(l, r, b, t, 0, 1);
+ int32_t b = sourceCrop.bottom;
+ int32_t t = sourceCrop.top;
+ if (mRenderToFbo) {
+ std::swap(t, b);
}
+ mat4 m = mat4::ortho(l, r, b, t, 0, 1);
// Apply custom rotation to the projection.
float rot90InRadians = 2.0f * static_cast<float>(M_PI) / 4.0f;
@@ -284,9 +278,13 @@
*status = glCheckFramebufferStatus(GL_FRAMEBUFFER);
*texName = tname;
*fbName = name;
+
+ mRenderToFbo = true;
}
void GLES20RenderEngine::unbindFramebuffer(uint32_t texName, uint32_t fbName) {
+ mRenderToFbo = false;
+
glBindFramebuffer(GL_FRAMEBUFFER, 0);
glDeleteFramebuffers(1, &fbName);
glDeleteTextures(1, &texName);
diff --git a/services/surfaceflinger/RenderEngine/gl/GLES20RenderEngine.h b/services/surfaceflinger/RenderEngine/gl/GLES20RenderEngine.h
index c830184..e6a7a00 100644
--- a/services/surfaceflinger/RenderEngine/gl/GLES20RenderEngine.h
+++ b/services/surfaceflinger/RenderEngine/gl/GLES20RenderEngine.h
@@ -62,8 +62,8 @@
protected:
virtual void dump(String8& result);
- virtual void setViewportAndProjection(size_t vpw, size_t vph, Rect sourceCrop, size_t hwh,
- bool yswap, ui::Transform::orientation_flags rotation);
+ virtual void setViewportAndProjection(size_t vpw, size_t vph, Rect sourceCrop,
+ ui::Transform::orientation_flags rotation);
virtual void setupLayerBlending(bool premultipliedAlpha, bool opaque, bool disableTexture,
const half4& color) override;
@@ -108,6 +108,8 @@
// with PQ or HLG transfer function.
bool isHdrDataSpace(const ui::Dataspace dataSpace) const;
bool needsXYZTransformMatrix() const;
+
+ bool mRenderToFbo = false;
};
} // namespace gl
diff --git a/services/surfaceflinger/RenderEngine/include/renderengine/RenderEngine.h b/services/surfaceflinger/RenderEngine/include/renderengine/RenderEngine.h
index c532adc..a363cd4 100644
--- a/services/surfaceflinger/RenderEngine/include/renderengine/RenderEngine.h
+++ b/services/surfaceflinger/RenderEngine/include/renderengine/RenderEngine.h
@@ -96,14 +96,15 @@
virtual void deleteTextures(size_t count, uint32_t const* names) = 0;
virtual void bindExternalTextureImage(uint32_t texName, const renderengine::Image& image) = 0;
virtual void readPixels(size_t l, size_t b, size_t w, size_t h, uint32_t* pixels) = 0;
+ // When binding a native buffer, it must be done before setViewportAndProjection
virtual void bindNativeBufferAsFrameBuffer(ANativeWindowBuffer* buffer,
BindNativeBufferAsFramebuffer* bindHelper) = 0;
virtual void unbindNativeBufferAsFrameBuffer(BindNativeBufferAsFramebuffer* bindHelper) = 0;
// set-up
virtual void checkErrors() const;
- virtual void setViewportAndProjection(size_t vpw, size_t vph, Rect sourceCrop, size_t hwh,
- bool yswap, ui::Transform::orientation_flags rotation) = 0;
+ virtual void setViewportAndProjection(size_t vpw, size_t vph, Rect sourceCrop,
+ ui::Transform::orientation_flags rotation) = 0;
virtual void setupLayerBlending(bool premultipliedAlpha, bool opaque, bool disableTexture,
const half4& color) = 0;
virtual void setupLayerTexturing(const Texture& texture) = 0;