Add helper function to calculate the area of the intersection of two rectangles.
authorMichel Dänzer <michel@daenzer.net>
Thu, 28 Sep 2006 14:08:38 +0000 (14:08 +0000)
committerMichel Dänzer <michel@daenzer.net>
Thu, 28 Sep 2006 14:08:38 +0000 (14:08 +0000)
src/mesa/drivers/dri/common/utils.c
src/mesa/drivers/dri/common/utils.h

index 74ed299a628235d5c41bea56051a6a8093ce2d90..6a189e728582ba3876c9807bcc72465a7f5665c5 100644 (file)
@@ -421,6 +421,19 @@ driCheckDriDdxDrmVersions2(const char * driver_name,
 
 
 
+GLint
+driIntersectArea( drm_clip_rect_t rect1, drm_clip_rect_t rect2 )
+{
+   if (rect2.x1 > rect1.x1) rect1.x1 = rect2.x1;
+   if (rect2.x2 < rect1.x2) rect1.x2 = rect2.x2;
+   if (rect2.y1 > rect1.y1) rect1.y1 = rect2.y1;
+   if (rect2.y2 < rect1.y2) rect1.y2 = rect2.y2;
+
+   if (rect1.x1 > rect1.x2 || rect1.y1 > rect1.y2) return 0;
+
+   return (rect1.x2 - rect1.x1) * (rect1.y2 - rect1.y1);
+}
+
 GLboolean driClipRectToFramebuffer( const GLframebuffer *buffer,
                                    GLint *x, GLint *y,
                                    GLsizei *width, GLsizei *height )
index 26d178f7478e019f3d57aced556fa3ef13dbcdce..b2bab86e66c69b4d105f1e464e36fad203e36a9e 100644 (file)
@@ -106,6 +106,8 @@ extern GLboolean driCheckDriDdxDrmVersions3(const char * driver_name,
     const __DRIversion * ddxActual, const __DRIutilversion2 * ddxExpected,
     const __DRIversion * drmActual, const __DRIversion * drmExpected);
 
+extern GLint driIntersectArea( drm_clip_rect_t rect1, drm_clip_rect_t rect2 );
+
 extern GLboolean driClipRectToFramebuffer( const GLframebuffer *buffer,
                                           GLint *x, GLint *y,
                                           GLsizei *width, GLsizei *height );