summaryrefslogtreecommitdiff
path: root/recipes/xorg-xserver/xserver-xorg/0002-dri2-No-need-to-blit-from-front-on-DRI2GetBuffers-if.patch
blob: 25c073b81e3b88a00bc7f5630c19f8a6688fe74f (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
From 2723b7a678e75e0a070e90ec223309c9b739d24b Mon Sep 17 00:00:00 2001
From: Francisco Jerez <currojerez@riseup.net>
Date: Fri, 22 Jan 2010 06:29:35 -0800
Subject: [PATCH 2/5] dri2: No need to blit from front on DRI2GetBuffers if they're just being reused.

It can be quite an expensive operation, so we're better off not doing
it unless it's totally required.

Signed-off-by: Francisco Jerez <currojerez@riseup.net>
---
 hw/xfree86/dri2/dri2.c |   42 +++++++++++++++++++++++-------------------
 1 files changed, 23 insertions(+), 19 deletions(-)

diff --git a/hw/xfree86/dri2/dri2.c b/hw/xfree86/dri2/dri2.c
index cd69ca0..48618e1 100644
--- a/hw/xfree86/dri2/dri2.c
+++ b/hw/xfree86/dri2/dri2.c
@@ -202,27 +202,25 @@ find_attachment(DRI2DrawablePtr pPriv, unsigned attachment)
     return -1;
 }
 
-static DRI2BufferPtr
+static Bool
 allocate_or_reuse_buffer(DrawablePtr pDraw, DRI2ScreenPtr ds,
 			 DRI2DrawablePtr pPriv,
 			 unsigned int attachment, unsigned int format,
-			 int dimensions_match)
+			 int dimensions_match, DRI2BufferPtr *buffer)
 {
-    DRI2BufferPtr buffer;
-    int old_buf;
-
-    old_buf = find_attachment(pPriv, attachment);
+    int old_buf = find_attachment(pPriv, attachment);
 
     if ((old_buf < 0)
 	|| !dimensions_match
 	|| (pPriv->buffers[old_buf]->format != format)) {
-	buffer = (*ds->CreateBuffer)(pDraw, attachment, format);
+	*buffer = (*ds->CreateBuffer)(pDraw, attachment, format);
+	return TRUE;
+
     } else {
-	buffer = pPriv->buffers[old_buf];
+	*buffer = pPriv->buffers[old_buf];
 	pPriv->buffers[old_buf] = NULL;
+	return FALSE;
     }
-
-    return buffer;
 }
 
 static DRI2BufferPtr *
@@ -238,6 +236,7 @@ do_get_buffers(DrawablePtr pDraw, int *width, int *height,
     int have_fake_front = 0;
     int front_format = 0;
     int dimensions_match;
+    int buffers_changed = 0;
     int i;
 
     if (!pPriv) {
@@ -256,8 +255,10 @@ do_get_buffers(DrawablePtr pDraw, int *width, int *height,
 	const unsigned attachment = *(attachments++);
 	const unsigned format = (has_format) ? *(attachments++) : 0;
 
-	buffers[i] = allocate_or_reuse_buffer(pDraw, ds, pPriv, attachment,
-					      format, dimensions_match);
+	if (allocate_or_reuse_buffer(pDraw, ds, pPriv, attachment,
+				     format, dimensions_match,
+				     &buffers[i]))
+		buffers_changed = 1;
 
 	/* If the drawable is a window and the front-buffer is requested,
 	 * silently add the fake front-buffer to the list of requested
@@ -287,15 +288,18 @@ do_get_buffers(DrawablePtr pDraw, int *width, int *height,
     }
 
     if (need_real_front > 0) {
-	buffers[i++] = allocate_or_reuse_buffer(pDraw, ds, pPriv,
-						DRI2BufferFrontLeft,
-						front_format, dimensions_match);
+	if (allocate_or_reuse_buffer(pDraw, ds, pPriv, DRI2BufferFrontLeft,
+				     front_format, dimensions_match,
+				     &buffers[i++]))
+	    buffers_changed = 1;
     }
 
     if (need_fake_front > 0) {
-	buffers[i++] = allocate_or_reuse_buffer(pDraw, ds, pPriv,
-						DRI2BufferFakeFrontLeft,
-						front_format, dimensions_match);
+	if (allocate_or_reuse_buffer(pDraw, ds, pPriv, DRI2BufferFakeFrontLeft,
+				     front_format, dimensions_match,
+				     &buffers[i++]))
+	    buffers_changed = 1;
+
 	have_fake_front = 1;
     }
 
@@ -324,7 +328,7 @@ do_get_buffers(DrawablePtr pDraw, int *width, int *height,
      * contents of the real front-buffer.  This ensures correct operation of
      * applications that call glXWaitX before calling glDrawBuffer.
      */
-    if (have_fake_front) {
+    if (have_fake_front && buffers_changed) {
 	BoxRec box;
 	RegionRec region;
 
-- 
1.7.0