Blame SOURCES/0004-cogl-Relax-formats-on-glBlitFramebuffer.patch

657d8e
From 6c6c6ad5412f5bb13592630d7cb3b7aed25d159b Mon Sep 17 00:00:00 2001
657d8e
From: Pekka Paalanen <pekka.paalanen@collabora.com>
657d8e
Date: Mon, 6 May 2019 14:09:16 +0300
657d8e
Subject: [PATCH 04/12] cogl: Relax formats on glBlitFramebuffer
657d8e
657d8e
Depends on: "cogl: Replace ANGLE with GLES3 and NV framebuffer_blit"
657d8e
657d8e
As a possible ANGLE implementation is not longer limiting the pixel format
657d8e
matching, lift the requirement of having the same pixel format.
657d8e
657d8e
We still cannot do a premult <-> non-premult conversion during a blit, so guard
657d8e
against that.
657d8e
657d8e
This will be useful in follow-up work to copy from onscreen primary GPU
657d8e
framebuffer to an offscreen secondary GPU framebuffer if the formats do not
657d8e
match exactly.
657d8e
657d8e
https://gitlab.gnome.org/GNOME/mutter/merge_requests/615
657d8e
657d8e
(cherry picked from commit 6df34eb4b7c65210f4066f7eb9bd462278b7279b)
657d8e
---
657d8e
 cogl/cogl/cogl-blit.c                | 10 ++++++----
657d8e
 cogl/cogl/cogl-framebuffer-private.h |  8 ++++++--
657d8e
 cogl/cogl/cogl-framebuffer.c         |  6 ++++--
657d8e
 3 files changed, 16 insertions(+), 8 deletions(-)
657d8e
657d8e
diff --git a/cogl/cogl/cogl-blit.c b/cogl/cogl/cogl-blit.c
657d8e
index 74f404f3d..a61eb66d2 100644
657d8e
--- a/cogl/cogl/cogl-blit.c
657d8e
+++ b/cogl/cogl/cogl-blit.c
657d8e
@@ -4,6 +4,7 @@
657d8e
  * A Low Level GPU Graphics and Utilities API
657d8e
  *
657d8e
  * Copyright (C) 2011 Intel Corporation.
657d8e
+ * Copyright (C) 2019 DisplayLink (UK) Ltd.
657d8e
  *
657d8e
  * Permission is hereby granted, free of charge, to any person
657d8e
  * obtaining a copy of this software and associated documentation
657d8e
@@ -152,10 +153,11 @@ _cogl_blit_framebuffer_begin (CoglBlitData *data)
657d8e
   CoglFramebuffer *dst_fb, *src_fb;
657d8e
   CoglError *ignore_error = NULL;
657d8e
 
657d8e
-  /* We can only blit between FBOs if both textures are the same
657d8e
-     format and the blit framebuffer extension is supported */
657d8e
-  if ((_cogl_texture_get_format (data->src_tex) & ~COGL_A_BIT) !=
657d8e
-      (_cogl_texture_get_format (data->dst_tex) & ~COGL_A_BIT) ||
657d8e
+  /* We can only blit between FBOs if both textures have the same
657d8e
+     premult convention and the blit framebuffer extension is
657d8e
+     supported. */
657d8e
+  if ((_cogl_texture_get_format (data->src_tex) & COGL_PREMULT_BIT) !=
657d8e
+      (_cogl_texture_get_format (data->dst_tex) & COGL_PREMULT_BIT) ||
657d8e
       !_cogl_has_private_feature (ctx, COGL_PRIVATE_FEATURE_OFFSCREEN_BLIT))
657d8e
     return FALSE;
657d8e
 
657d8e
diff --git a/cogl/cogl/cogl-framebuffer-private.h b/cogl/cogl/cogl-framebuffer-private.h
657d8e
index 3aab852c4..b06fbaee1 100644
657d8e
--- a/cogl/cogl/cogl-framebuffer-private.h
657d8e
+++ b/cogl/cogl/cogl-framebuffer-private.h
657d8e
@@ -381,8 +381,12 @@ _cogl_push_framebuffers (CoglFramebuffer *draw_buffer,
657d8e
  * This blits a region of the color buffer of the source buffer
657d8e
  * to the destination buffer. This function should only be
657d8e
  * called if the COGL_PRIVATE_FEATURE_OFFSCREEN_BLIT feature is
657d8e
- * advertised. The two buffers must both be offscreen and have the
657d8e
- * same format.
657d8e
+ * advertised. The two buffers must both be offscreen.
657d8e
+ *
657d8e
+ * The two buffers must have the same value types (e.g. floating-point,
657d8e
+ * unsigned int, signed int, or fixed-point), but color formats do not
657d8e
+ * need to match. This limitation comes from OpenGL ES 3.0 definition
657d8e
+ * of glBlitFramebuffer.
657d8e
  *
657d8e
  * Note that this function differs a lot from the glBlitFramebuffer
657d8e
  * function provided by the GL_EXT_framebuffer_blit extension. Notably
657d8e
diff --git a/cogl/cogl/cogl-framebuffer.c b/cogl/cogl/cogl-framebuffer.c
657d8e
index bd8a7fa42..0bc225945 100644
657d8e
--- a/cogl/cogl/cogl-framebuffer.c
657d8e
+++ b/cogl/cogl/cogl-framebuffer.c
657d8e
@@ -4,6 +4,7 @@
657d8e
  * A Low Level GPU Graphics and Utilities API
657d8e
  *
657d8e
  * Copyright (C) 2007,2008,2009,2012 Intel Corporation.
657d8e
+ * Copyright (C) 2019 DisplayLink (UK) Ltd.
657d8e
  *
657d8e
  * Permission is hereby granted, free of charge, to any person
657d8e
  * obtaining a copy of this software and associated documentation
657d8e
@@ -1468,8 +1469,9 @@ _cogl_blit_framebuffer (CoglFramebuffer *src,
657d8e
      support this */
657d8e
   _COGL_RETURN_IF_FAIL (cogl_is_offscreen (src));
657d8e
   _COGL_RETURN_IF_FAIL (cogl_is_offscreen (dest));
657d8e
-  /* The buffers must be the same format */
657d8e
-  _COGL_RETURN_IF_FAIL (src->internal_format == dest->internal_format);
657d8e
+  /* The buffers must use the same premult convention */
657d8e
+  _COGL_RETURN_IF_FAIL ((src->internal_format & COGL_PREMULT_BIT) ==
657d8e
+                        (dest->internal_format & COGL_PREMULT_BIT));
657d8e
 
657d8e
   /* Make sure the current framebuffers are bound. We explicitly avoid
657d8e
      flushing the clip state so we can bind our own empty state */
657d8e
-- 
657d8e
2.21.0
657d8e