~linaro-graphics-wg/compiz-plugins-main/oneiric-gles2

« back to all changes in this revision

Viewing changes to staticswitcher/src/staticswitcher.cpp

  • Committer: Travis Watkins
  • Date: 2011-10-20 08:48:04 UTC
  • Revision ID: travis.watkins@linaro.org-20111020084804-116tyyy0dqt7k1zd
add code from GLES2 port

Show diffs side-by-side

added added

removed removed

Lines of Context:
793
793
}
794
794
 
795
795
void
796
 
StaticSwitchScreen::paintRect (CompRect &box,
797
 
                               int offset,
798
 
                               unsigned short *color,
799
 
                               int opacity)
 
796
StaticSwitchScreen::paintRect (const GLMatrix &transform,
 
797
                               CompRect       &box,
 
798
                               int             offset,
 
799
                               unsigned short *color,
 
800
                               int             opacity)
800
801
{
801
 
    glColor4us (color[0], color[1], color[2], color[3] * opacity / 100);
802
 
    glBegin (GL_LINE_LOOP);
803
 
    glVertex2i (box.x1 () + offset, box.y1 () + offset);
804
 
    glVertex2i (box.x2 () - offset, box.y1 () + offset);
805
 
    glVertex2i (box.x2 () - offset, box.y2 () - offset);
806
 
    glVertex2i (box.x1 () + offset, box.y2 () - offset);
807
 
    glEnd ();
 
802
    GLushort colorData[4] = {
 
803
        color[0],
 
804
        color[1],
 
805
        color[2],
 
806
        color[3] * opacity / 100
 
807
    };
 
808
 
 
809
    GLfloat vertexData[12] = {
 
810
        box.x1 () + offset, box.y1 () + offset, 0,
 
811
        box.x2 () - offset, box.y1 () + offset, 0,
 
812
        box.x2 () - offset, box.y2 () - offset, 0,
 
813
        box.x1 () + offset, box.y2 () - offset, 0
 
814
    };
 
815
 
 
816
    GLVertexBuffer *streamingBuffer = GLVertexBuffer::streamingBuffer ();
 
817
    streamingBuffer->begin (GL_LINE_LOOP);
 
818
 
 
819
    streamingBuffer->addColors (1, colorData);
 
820
    streamingBuffer->addVertices (4, vertexData);
 
821
 
 
822
    streamingBuffer->end ();
 
823
    streamingBuffer->render (transform);
808
824
}
809
825
 
810
826
bool
874
890
 
875
891
            sTransform.toScreenSpace (output, -DEFAULT_Z_CAMERA);
876
892
 
877
 
            glPushMatrix ();
878
 
            glLoadMatrixf (sTransform.getMatrix ());
879
 
 
880
893
            if (mode == HighlightModeShowRectangle)
881
894
            {
882
895
                CompWindow *w;
891
904
                    if (getPaintRectangle (w, box, &opacity))
892
905
                    {
893
906
                        unsigned short *color;
894
 
                        GLushort       r, g, b, a;
895
 
 
896
 
                        glEnable (GL_BLEND);
 
907
                        GLushort        colorData[4];
 
908
                        GLfloat         vertexData[12];
 
909
                        GLVertexBuffer *streamingBuffer = GLVertexBuffer::streamingBuffer ();
897
910
 
898
911
                        /* fill rectangle */
899
 
                        r = optionGetHighlightColorRed ();
900
 
                        g = optionGetHighlightColorGreen ();
901
 
                        b = optionGetHighlightColorBlue ();
902
 
                        a = optionGetHighlightColorAlpha ();
903
 
                        a = a * opacity / 100;
904
 
 
905
 
                        glColor4us (r, g, b, a);
906
 
                        glRecti (box.x1 (), box.y2 (), box.x2 (), box.y1 ());
 
912
                        colorData[0] = optionGetHighlightColorRed ();
 
913
                        colorData[1] = optionGetHighlightColorGreen ();
 
914
                        colorData[2] = optionGetHighlightColorBlue ();
 
915
                        colorData[3] = optionGetHighlightColorAlpha ();
 
916
                        colorData[3] = colorData[3] * opacity / 100;
 
917
 
 
918
                        vertexData[0]  = box.x1 ();
 
919
                        vertexData[1]  = box.y2 ();
 
920
                        vertexData[2]  = 0.0f;
 
921
                        vertexData[3]  = box.x1 ();
 
922
                        vertexData[4]  = box.y1 ();
 
923
                        vertexData[5]  = 0.0f;
 
924
                        vertexData[6]  = box.x2 ();
 
925
                        vertexData[7]  = box.y2 ();
 
926
                        vertexData[8]  = 0.0f;
 
927
                        vertexData[9]  = box.x2 ();
 
928
                        vertexData[10] = box.y1 ();
 
929
                        vertexData[11] = 0.0f;
 
930
 
 
931
                        streamingBuffer->begin (GL_TRIANGLE_STRIP);
 
932
                        streamingBuffer->addColors (1, colorData);
 
933
                        streamingBuffer->addVertices (4, vertexData);
 
934
                        streamingBuffer->end ();
 
935
                        streamingBuffer->render (sTransform);
907
936
 
908
937
                        /* draw outline */
909
938
                        glLineWidth (1.0);
910
 
                        glDisable (GL_LINE_SMOOTH);
911
939
 
912
940
                        color = optionGetHighlightBorderColor ();
913
 
                        paintRect (box, 0, color, opacity);
914
 
                        paintRect (box, 2, color, opacity);
 
941
                        paintRect (sTransform, box, 0, color, opacity);
 
942
                        paintRect (sTransform, box, 2, color, opacity);
915
943
                        color = optionGetHighlightBorderInlayColor ();
916
 
                        paintRect (box, 1, color, opacity);
917
 
 
918
 
                        /* clean up */
919
 
                        glColor4usv (defaultColor);
920
 
                        glDisable (GL_BLEND);
 
944
                        paintRect (sTransform, box, 1, color, opacity);
921
945
                    }
922
946
                }
923
947
            }
934
958
                                          sTransform, infiniteRegion, 0);
935
959
                }
936
960
            }
937
 
 
938
 
            glPopMatrix ();
939
961
        }
940
962
    }
941
963
    else
978
1000
}
979
1001
 
980
1002
void
981
 
StaticSwitchScreen::paintSelectionRect (int          x,
982
 
                                        int          y,
983
 
                                        float        dx,
984
 
                                        float        dy,
985
 
                                        unsigned int opacity)
 
1003
StaticSwitchScreen::paintSelectionRect (const GLMatrix &transform,
 
1004
                                        int             x,
 
1005
                                        int             y,
 
1006
                                        float           dx,
 
1007
                                        float           dy,
 
1008
                                        unsigned int    opacity)
986
1009
{
987
 
    float color[4], op;
 
1010
    GLVertexBuffer *streamingBuffer = GLVertexBuffer::streamingBuffer ();
 
1011
    GLushort        colorData[4];
 
1012
    GLfloat         vertexData[18];
 
1013
    GLMatrix        sTransform (transform);
 
1014
    float op;
988
1015
    int   w, h;
989
1016
    int   count = windows.size ();
990
1017
 
991
1018
    w = previewWidth + previewBorder;
992
1019
    h = previewHeight + previewBorder;
993
1020
 
994
 
    glEnable (GL_BLEND);
995
 
 
996
1021
    if (dx > xCount - 1)
997
1022
        op = 1.0 - MIN (1.0, dx - (xCount - 1));
998
1023
    else if (dx + (dy * xCount) > count - 1)
1003
1028
        op = 1.0;
1004
1029
 
1005
1030
    for (unsigned int i = 0; i < 4; i++)
1006
 
        color[i] = (float)fgColor[i] * opacity * op / 0xffffffff;
1007
 
 
1008
 
    glColor4fv (color);
1009
 
    glPushMatrix ();
1010
 
    glTranslatef (x + previewBorder / 2 + (dx * w),
1011
 
                  y + previewBorder / 2 + (dy * h), 0.0f);
1012
 
 
1013
 
    glBegin (GL_QUADS);
1014
 
    glVertex2i (-1, -1);
1015
 
    glVertex2i (-1, 1);
1016
 
    glVertex2i (w + 1, 1);
1017
 
    glVertex2i (w + 1, -1);
1018
 
    glVertex2i (-1, h - 1);
1019
 
    glVertex2i (-1, h + 1);
1020
 
    glVertex2i (w + 1, h + 1);
1021
 
    glVertex2i (w + 1, h - 1);
1022
 
    glVertex2i (-1, 1);
1023
 
    glVertex2i (-1, h - 1);
1024
 
    glVertex2i (1, h - 1);
1025
 
    glVertex2i (1, 1);
1026
 
    glVertex2i (w - 1, 1);
1027
 
    glVertex2i (w - 1, h - 1);
1028
 
    glVertex2i (w + 1, h - 1);
1029
 
    glVertex2i (w + 1, 1);
1030
 
    glEnd ();
1031
 
 
1032
 
    glPopMatrix ();
1033
 
    glColor4usv (defaultColor);
1034
 
    glDisable (GL_BLEND);
 
1031
        colorData[i] = (float)fgColor[i] * opacity * op / 0xffffffff;
 
1032
 
 
1033
    sTransform.translate (x + previewBorder / 2 + (dx * w),
 
1034
                                       y + previewBorder / 2 + (dy * h), 0.0f);
 
1035
 
 
1036
    streamingBuffer->begin (GL_TRIANGLE_STRIP);
 
1037
 
 
1038
    vertexData[0]  = -1;
 
1039
    vertexData[1]  = -1;
 
1040
    vertexData[2]  = 0;
 
1041
    vertexData[3]  = -1;
 
1042
    vertexData[4]  = 1;
 
1043
    vertexData[5]  = 0;
 
1044
    vertexData[6]  = w + 1;
 
1045
    vertexData[7]  = -1;
 
1046
    vertexData[8]  = 0;
 
1047
    vertexData[9]  = w + 1;
 
1048
    vertexData[10] = 1;
 
1049
    vertexData[11] = 0;
 
1050
 
 
1051
    streamingBuffer->addColors (1, colorData);
 
1052
    streamingBuffer->addVertices (4, vertexData);
 
1053
 
 
1054
    streamingBuffer->end ();
 
1055
    streamingBuffer->render (sTransform);
 
1056
 
 
1057
 
 
1058
    streamingBuffer->begin (GL_TRIANGLE_STRIP);
 
1059
 
 
1060
    vertexData[0]  = -1;
 
1061
    vertexData[1]  = h - 1;
 
1062
    vertexData[2]  = 0;
 
1063
    vertexData[3]  = -1;
 
1064
    vertexData[4]  = h + 1;
 
1065
    vertexData[5]  = 0;
 
1066
    vertexData[6]  = w + 1;
 
1067
    vertexData[7]  = h - 1;
 
1068
    vertexData[8]  = 0;
 
1069
    vertexData[9]  = w + 1;
 
1070
    vertexData[10] = h + 1;
 
1071
    vertexData[11] = 0;
 
1072
 
 
1073
    streamingBuffer->addColors (1, colorData);
 
1074
    streamingBuffer->addVertices (4, vertexData);
 
1075
 
 
1076
    streamingBuffer->end ();
 
1077
    streamingBuffer->render (sTransform);
 
1078
 
 
1079
 
 
1080
    streamingBuffer->begin (GL_TRIANGLE_STRIP);
 
1081
 
 
1082
    vertexData[0]  = -1;
 
1083
    vertexData[1]  = 1;
 
1084
    vertexData[2]  = 0;
 
1085
    vertexData[3]  = -1;
 
1086
    vertexData[4]  = h - 1;
 
1087
    vertexData[5]  = 0;
 
1088
    vertexData[6]  = 1;
 
1089
    vertexData[7]  = 1;
 
1090
    vertexData[8]  = 0;
 
1091
    vertexData[9]  = 1;
 
1092
    vertexData[10] = h - 1;
 
1093
    vertexData[11] = 0;
 
1094
 
 
1095
    streamingBuffer->addColors (1, colorData);
 
1096
    streamingBuffer->addVertices (4, vertexData);
 
1097
 
 
1098
    streamingBuffer->end ();
 
1099
    streamingBuffer->render (sTransform);
 
1100
 
 
1101
 
 
1102
    streamingBuffer->begin (GL_TRIANGLE_STRIP);
 
1103
 
 
1104
    vertexData[0]  = w - 1;
 
1105
    vertexData[1]  = 1;
 
1106
    vertexData[2]  = 0;
 
1107
    vertexData[3]  = w - 1;
 
1108
    vertexData[4]  = h - 1;
 
1109
    vertexData[5]  = 0;
 
1110
    vertexData[6]  = w + 1;
 
1111
    vertexData[7]  = 1;
 
1112
    vertexData[8]  = 0;
 
1113
    vertexData[9]  = w + 1;
 
1114
    vertexData[10] = h - 1;
 
1115
    vertexData[11] = 0;
 
1116
 
 
1117
    streamingBuffer->addColors (1, colorData);
 
1118
    streamingBuffer->addVertices (4, vertexData);
 
1119
 
 
1120
    streamingBuffer->end ();
 
1121
    streamingBuffer->render (sTransform);
1035
1122
}
1036
1123
 
1037
1124
bool
1157
1244
        if (!(mask & PAINT_WINDOW_TRANSFORMED_MASK) && region.isEmpty ())
1158
1245
            return true;
1159
1246
 
1160
 
        glPushAttrib (GL_SCISSOR_BIT);
1161
 
 
1162
1247
        glEnable (GL_SCISSOR_TEST);
1163
1248
        glScissor (g.x (), 0, g.width (), ::screen->height ());
1164
1249
 
1181
1266
        if (pos > count - 1)
1182
1267
        {
1183
1268
            px = fmod (pos - count, sScreen->xCount);
1184
 
            sScreen->paintSelectionRect (g.x (), g.y (), px, 0.0,
 
1269
            sScreen->paintSelectionRect (transform, g.x (), g.y (), px, 0.0,
1185
1270
                                         gWindow->lastPaintAttrib ().opacity);
1186
1271
 
1187
1272
            px = fmod (pos, sScreen->xCount);
1188
 
            sScreen->paintSelectionRect (g.x () + offX, g.y (),
 
1273
            sScreen->paintSelectionRect (transform, g.x () + offX, g.y (),
1189
1274
                                         px, py,
1190
1275
                                         gWindow->lastPaintAttrib ().opacity);
1191
1276
        }
1192
1277
        if (px > sScreen->xCount - 1)
1193
1278
        {
1194
 
            sScreen->paintSelectionRect (g.x (), g.y (), px, py,
 
1279
            sScreen->paintSelectionRect (transform, g.x (), g.y (), px, py,
1195
1280
                                         gWindow->lastPaintAttrib ().opacity);
1196
1281
 
1197
1282
            py = fmod (py + 1, ceil ((double) count / sScreen->xCount));
1198
1283
            offX = sScreen->getRowXOffset (py);
1199
1284
 
1200
 
            sScreen->paintSelectionRect (g.x () + offX, g.y (),
 
1285
            sScreen->paintSelectionRect (transform, g.x () + offX, g.y (),
1201
1286
                                         px - sScreen->xCount, py,
1202
1287
                                         gWindow->lastPaintAttrib ().opacity);
1203
1288
        }
1204
1289
        else
1205
1290
        {
1206
 
            sScreen->paintSelectionRect (g.x () + offX, g.y (),
 
1291
            sScreen->paintSelectionRect (transform, g.x () + offX, g.y (),
1207
1292
                                         px, py,
1208
1293
                                         gWindow->lastPaintAttrib ().opacity);
1209
1294
        }
1210
1295
        glDisable (GL_SCISSOR_TEST);
1211
 
        glPopAttrib ();
1212
1296
    }
1213
1297
    /* Adjust opacity/brightness/saturation of windows that are
1214
1298
     * not selected