+ /* Only use quad-based clearing for the renderbuffers which cannot
+ * use pipe->clear. We want to always use pipe->clear for the other
+ * renderbuffers, because it's likely to be faster.
+ */
+ if (clear_buffers) {
+ const struct gl_scissor_rect *scissor = &ctx->Scissor.ScissorArray[0];
+ struct pipe_scissor_state scissor_state = {
+ .minx = MAX2(scissor->X, 0),
+ .miny = MAX2(scissor->Y, 0),
+ .maxx = MAX2(scissor->X + scissor->Width, 0),
+ .maxy = MAX2(scissor->Y + scissor->Height, 0),
+
+ };
+
+ /* Now invert Y if needed.
+ * Gallium drivers use the convention Y=0=top for surfaces.
+ */
+ if (st->state.fb_orientation == Y_0_TOP) {
+ const struct gl_framebuffer *fb = ctx->DrawBuffer;
+ /* use intermediate variables to avoid uint underflow */
+ GLint miny, maxy;
+ miny = fb->Height - scissor_state.maxy;
+ maxy = fb->Height - scissor_state.miny;
+ scissor_state.miny = MAX2(miny, 0);
+ scissor_state.maxy = MAX2(maxy, 0);
+ }
+ /* We can't translate the clear color to the colorbuffer format,
+ * because different colorbuffers may have different formats.
+ */
+ st->pipe->clear(st->pipe, clear_buffers, have_scissor_buffers ? &scissor_state : NULL,
+ (union pipe_color_union*)&ctx->Color.ClearColor,