~townsend/compiz/fix-auto-vp-switch-0.9.10

« back to all changes in this revision

Viewing changes to plugins/text/src/text.cpp

Text, speed improvements:

Introduced
const float halfPi    = PI / 2.0f; and
const float triHalfPi = halfPi * 3;
and used those to draw the rounded background.
Introduced
GLfloat xPlusWidth   = x + width; and
GLfloat yMinusHeight = y - height;
and used those coordinates for the vertexData array.

Text, cleanup:

Declaration of local variables outside of loops.
Fixed indentation.

Approved by PS Jenkins bot, Sam Spilsbury.

Show diffs side-by-side

added added

removed removed

Lines of Context:
109
109
 * Draw a rounded rectangle path
110
110
 */
111
111
void
112
 
TextSurface::drawBackground (int     x,
113
 
                             int     y,
114
 
                             int     width,
115
 
                             int     height,
116
 
                             int     radius)
 
112
TextSurface::drawBackground (int x,
 
113
                             int y,
 
114
                             int width,
 
115
                             int height,
 
116
                             int radius)
117
117
{
118
118
    int x0 = x;
119
119
    int y0 = y;
120
120
    int x1 = x + width;
121
121
    int y1 = y + height;
122
122
 
 
123
    const float halfPi    = PI / 2.0f;
 
124
    const float triHalfPi = halfPi * 3;
 
125
 
123
126
    cairo_new_path (cr);
124
 
    cairo_arc (cr, x0 + radius, y1 - radius, radius, PI / 2, PI);
 
127
    cairo_arc (cr, x0 + radius, y1 - radius, radius, halfPi, PI);
125
128
    cairo_line_to (cr, x0, y0 + radius);
126
 
    cairo_arc (cr, x0 + radius, y0 + radius, radius, PI, 3 * PI / 2);
 
129
    cairo_arc (cr, x0 + radius, y0 + radius, radius, PI, triHalfPi);
127
130
    cairo_line_to (cr, x1 - radius, y0);
128
 
    cairo_arc (cr, x1 - radius, y0 + radius, radius, 3 * PI / 2, 2 * PI);
 
131
    cairo_arc (cr, x1 - radius, y0 + radius, radius, triHalfPi, 2 * PI);
129
132
    cairo_line_to (cr, x1, y1 - radius);
130
 
    cairo_arc (cr, x1 - radius, y1 - radius, radius, 0, PI / 2);
 
133
    cairo_arc (cr, x1 - radius, y1 - radius, radius, 0, halfPi);
131
134
    cairo_close_path (cr);
132
135
}
133
136
 
502
505
 
503
506
    glBlendFunc (GL_ONE, GL_ONE_MINUS_SRC_ALPHA);
504
507
 
505
 
    GLushort       colorData[4];
506
 
    GLfloat        textureData[8];
507
 
    GLfloat        vertexData[12];
508
 
    GLVertexBuffer *streamingBuffer = GLVertexBuffer::streamingBuffer ();
 
508
    GLushort          colorData[4];
 
509
    GLfloat           textureData[8];
 
510
    GLfloat           vertexData[12];
 
511
    GLVertexBuffer    *streamingBuffer = GLVertexBuffer::streamingBuffer ();
 
512
    GLTexture         *tex;
 
513
    GLTexture::Matrix m;
 
514
    GLfloat           xPlusWidth   = x + width;
 
515
    GLfloat           yMinusHeight = y - height;
509
516
 
510
517
    colorData[0] = alpha * 65535;
511
518
    colorData[1] = alpha * 65535;
514
521
 
515
522
    for (unsigned int i = 0; i < texture.size (); ++i)
516
523
    {
517
 
        GLTexture         *tex = texture[i];
518
 
        GLTexture::Matrix m = tex->matrix ();
 
524
        tex = texture[i];
 
525
        m = tex->matrix ();
519
526
 
520
527
        tex->enable (GLTexture::Good);
521
528
 
522
529
        streamingBuffer->begin (GL_TRIANGLE_STRIP);
523
530
 
524
531
        vertexData[0]  = x;
525
 
        vertexData[1]  = y - height;
 
532
        vertexData[1]  = yMinusHeight;
526
533
        vertexData[2]  = 0;
527
534
        vertexData[3]  = x;
528
535
        vertexData[4]  = y;
529
536
        vertexData[5]  = 0;
530
 
        vertexData[6]  = x + width;
531
 
        vertexData[7]  = y - height;
 
537
        vertexData[6]  = xPlusWidth;
 
538
        vertexData[7]  = yMinusHeight;
532
539
        vertexData[8]  = 0;
533
 
        vertexData[9]  = x + width;
 
540
        vertexData[9]  = xPlusWidth;
534
541
        vertexData[10] = y;
535
542
        vertexData[11] = 0;
536
543