~ps-jenkins/compiz/latestsnapshot-10.9.10+13.10.20131004-0ubuntu1

« back to all changes in this revision

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

cube.cpp, code cleanup:

#include "privates.h", not <privates.h>.
Merged if condition checks.
Declaration of variables, where you need them to improve
the code structure and readability.
Use C++ standard bool for topDir, bottomDir, allCaps and
mCapsPainted[output] (bool true/false instead Bool TRUE/FALSE).
Initialize all of the class member variables in the constructor.
Replaced if (priv->mSky.size () > 0) with if (!priv->mSky.empty ()).
Removed redundant brackets.
Fixed indentation.
Added TODO.

cube.cpp, code speedup:

Do not call optionGetInactiveOpacity () twice, instead save
the value as float inactiveOpacity and use this variable in
the following calculation.
Introduced the variables float halfHsize  = hsize / 2.0; and
float tsSize = 360.0f / size; and used those in following
calculations to not have to recalculate those values multiple
times.
Do not calculate M_PI / sides and 2 * M_PI / sides multiple times
in loops, instead save those values in the GLfloats mps and tmps
and use those values inside the loops.
Use GLdouble mDist2 = 0.5 / mDistance; in the GLdouble clipPlane*
arrays, instead of recalculating this value multiple times.
Use GLfloat oneMinusFStepX = 1.0f - fStepX; and
GLfloat oneMinusFStepY = 1.0f - fStepY; instead of calculating
those values multiple times.
Use float outputWidth = outputPtr->width (); and float outputHeight =
outputPtr->height (); instead of calling the functions multiple
times.
Introduced the GLfloat normInvert = 0.5f * invert; and used this
variable instead of recalculating this value multiple times.
Introduced the GLfloats mSkyWidth and mSkyHeight and used those
in the following loops instead of calling mSkySize.width () and
mSkySize.height () multiple times.
Try to avoid redundant GL_BLEND state changes, because OpenGL
will blindly change the global state, no matter what it currently
is set to and that state change is expensive. So we query and
save the actual blending state in the variable GLboolean
glBlendEnabled = glIsEnabled (GL_BLEND); and just enable it if
it isn't already and just disable it, if it was disabled before.

(LP: #1101422, LP: #1195977)

cube.cpp, other fixes:

Return false in function PrivateCubeScreen::updateGeometry (int, int)
if sides should ever be 0, which should never happen, but should make
Coverity happy.

(LP: #1101541)

Initialize all class member variables in the PrivateCubeScreen::
PrivateCubeScreen (CompScreen *) constructor.
(mTc, mNOutput, mOutput, mOutputMask, mCleared, mCapsPainted)

(LP: #1101575). Fixes: https://bugs.launchpad.net/bugs/1101422, https://bugs.launchpad.net/bugs/1101541, https://bugs.launchpad.net/bugs/1101575.

Approved by Sam Spilsbury, PS Jenkins bot.

Show diffs side-by-side

added added

removed removed

Lines of Context:
30
30
#include <X11/Xatom.h>
31
31
#include <X11/Xproto.h>
32
32
 
33
 
#include <privates.h>
 
33
#include "privates.h"
34
34
 
35
35
class CubePluginVTable :
36
36
    public CompPlugin::VTableForScreenAndWindow<CubeScreen, PrivateCubeWindow, COMPIZ_CUBE_ABI>
238
238
PrivateCubeScreen::updateGeometry (int sides,
239
239
                                   int invert)
240
240
{
 
241
    /* This will never happen, but we want to calm down the static code analyzer
 
242
     * Coverity
 
243
     * See: https://bugs.launchpad.net/compiz/+bug/1101541 for details
 
244
     */
 
245
    if (!sides)
 
246
        return false;
 
247
 
 
248
    sides *= mNOutput;
 
249
 
 
250
    GLfloat mps        = M_PI / sides;
 
251
    GLfloat tmps       = 2 * mps;
 
252
    GLfloat distance   = 0.5f / tanf (mps);
 
253
    GLfloat radius     = 0.5f / sinf (mps);
 
254
    GLfloat normInvert = 0.5f * invert;
 
255
    int     i, n       = (sides + 2) * 2;
241
256
    GLfloat *v;
242
 
    int     i;
243
 
 
244
 
    sides *= mNOutput;
245
 
 
246
 
    GLfloat distance = 0.5f / tanf (M_PI / sides);
247
 
    GLfloat radius   = 0.5f / sinf (M_PI / sides);
248
 
 
249
 
    int n = (sides + 2) * 2;
250
257
 
251
258
    if (mNVertices != n)
252
259
    {
253
260
        v = (GLfloat *) realloc (mVertices, sizeof (GLfloat) * n * 3);
 
261
 
254
262
        if (!v)
255
263
            return false;
256
264
 
261
269
        v = mVertices;
262
270
 
263
271
    *v++ = 0.0f;
264
 
    *v++ = 0.5 * invert;
 
272
    *v++ = normInvert;
265
273
    *v++ = 0.0f;
266
274
 
267
275
    for (i = 0; i <= sides; ++i)
268
276
    {
269
 
        *v++ = radius * sinf (i * 2 * M_PI / sides + M_PI / sides);
270
 
        *v++ = 0.5 * invert;
271
 
        *v++ = radius * cosf (i * 2 * M_PI / sides + M_PI / sides);
 
277
        *v++ = radius * sinf (i * tmps + mps);
 
278
        *v++ = normInvert;
 
279
        *v++ = radius * cosf (i * tmps + mps);
272
280
    }
273
281
 
274
282
    *v++ = 0.0f;
277
285
 
278
286
    for (i = sides; i >= 0; --i)
279
287
    {
280
 
        *v++ = radius * sinf (i * 2 * M_PI / sides + M_PI / sides);
281
 
        *v++ = -0.5 * invert;
282
 
        *v++ = radius * cosf (i * 2 * M_PI / sides + M_PI / sides);
 
288
        *v++ = radius * sinf (i * tmps + mps);
 
289
        *v++ = -normInvert;
 
290
        *v++ = radius * cosf (i * tmps + mps);
283
291
    }
284
292
 
285
293
    mInvert   = invert;
381
389
 
382
390
    mNOutput = j;
383
391
 
384
 
    if (mNOutput == 1)
385
 
    {
386
 
        if (screen->outputDevs ()[0].width ()  != screen->width () ||
387
 
            screen->outputDevs ()[0].height () != screen->height ())
388
 
            mFullscreenOutput = true;
389
 
    }
 
392
    if (mNOutput == 1 &&
 
393
        (screen->outputDevs ()[0].width ()  != screen->width () ||
 
394
         screen->outputDevs ()[0].height () != screen->height ()))
 
395
        mFullscreenOutput = true;
390
396
}
391
397
 
392
398
void
407
413
                                 (std::numeric_limits <unsigned short>::max ());
408
414
        GLfloat aaafTextureData[128][128][3];
409
415
 
410
 
        GLfloat fRStart = optionGetSkydomeGradientStartColorRed () / MaxUShortFloat;
 
416
        GLfloat fRStart = optionGetSkydomeGradientStartColorRed ()   / MaxUShortFloat;
411
417
        GLfloat fGStart = optionGetSkydomeGradientStartColorGreen () / MaxUShortFloat;
412
 
        GLfloat fBStart = optionGetSkydomeGradientStartColorBlue () / MaxUShortFloat;
 
418
        GLfloat fBStart = optionGetSkydomeGradientStartColorBlue ()  / MaxUShortFloat;
413
419
 
414
 
        GLfloat fREnd   = optionGetSkydomeGradientEndColorRed () / MaxUShortFloat;
 
420
        GLfloat fREnd   = optionGetSkydomeGradientEndColorRed ()   / MaxUShortFloat;
415
421
        GLfloat fGEnd   = optionGetSkydomeGradientEndColorGreen () / MaxUShortFloat;
416
 
        GLfloat fBEnd   = optionGetSkydomeGradientEndColorBlue () / MaxUShortFloat;
 
422
        GLfloat fBEnd   = optionGetSkydomeGradientEndColorBlue ()  / MaxUShortFloat;
417
423
 
418
424
        GLfloat fRStep  = (fREnd - fRStart) / 128.0f;
419
425
        GLfloat fGStep  = (fGEnd - fGStart) / 128.0f;
522
528
    GLfloat fStepX = 1.0 / (GLfloat) (iSlicesEnd - iSlicesStart);
523
529
    GLfloat fStepY = 1.0 / (GLfloat) (iStacksEnd - iStacksStart);
524
530
 
525
 
    if (!mSky.size ())
526
 
        return;
 
531
    GLfloat oneMinusFStepX = 1.0f - fStepX;
 
532
    GLfloat oneMinusFStepY = 1.0f - fStepY;
527
533
 
528
 
    if (!fillCircleTable (&sint1, &cost1, -iSlices))
 
534
    if (!mSky.size () ||
 
535
        !fillCircleTable (&sint1, &cost1, -iSlices))
529
536
        return;
530
537
 
531
538
    if (!fillCircleTable (&sint2, &cost2, iStacks * 2))
536
543
    }
537
544
 
538
545
    afTexCoordX[0] = 1.0f;
539
 
    afTexCoordY[0] = 1.0f - fStepY;
540
 
    afTexCoordX[1] = 1.0f - fStepX;
541
 
    afTexCoordY[1] = 1.0f - fStepY;
542
 
    afTexCoordX[2] = 1.0f - fStepX;
 
546
    afTexCoordY[0] = oneMinusFStepY;
 
547
    afTexCoordX[1] = oneMinusFStepX;
 
548
    afTexCoordY[1] = oneMinusFStepY;
 
549
    afTexCoordX[2] = oneMinusFStepX;
543
550
    afTexCoordY[2] = 1.0f;
544
551
    afTexCoordX[3] = 1.0f;
545
552
    afTexCoordY[3] = 1.0f;
551
558
 
552
559
    mSky[0]->enable (GLTexture::Good);
553
560
 
 
561
    GLfloat mSkyWidth  = mSkySize.width ();
 
562
    GLfloat mSkyHeight = mSkySize.height ();
 
563
 
554
564
    glBegin (GL_QUADS);
555
565
 
556
566
    for (int i = iStacksStart; i < iStacksEnd; ++i)
557
567
    {
558
568
        afTexCoordX[0] = 1.0f;
559
 
        afTexCoordX[1] = 1.0f - fStepX;
560
 
        afTexCoordX[2] = 1.0f - fStepX;
 
569
        afTexCoordX[1] = oneMinusFStepX;
 
570
        afTexCoordX[2] = oneMinusFStepX;
561
571
        afTexCoordX[3] = 1.0f;
562
572
 
563
573
        for (int j = iSlicesStart; j < iSlicesEnd; ++j)
569
579
            y = sint1[j];
570
580
 
571
581
            glTexCoord2f (
572
 
                COMP_TEX_COORD_X (mSky[0]->matrix (), afTexCoordX[3] * mSkySize.width ()),
573
 
                COMP_TEX_COORD_Y (mSky[0]->matrix (), afTexCoordY[3] * mSkySize.height ()));
 
582
                COMP_TEX_COORD_X (mSky[0]->matrix (), afTexCoordX[3] * mSkyWidth),
 
583
                COMP_TEX_COORD_Y (mSky[0]->matrix (), afTexCoordY[3] * mSkyHeight));
574
584
            glVertex3f (x * r * fRadius, y * r * fRadius, z * fRadius);
575
585
 
576
586
            /* top-right */
580
590
            y = sint1[j];
581
591
 
582
592
            glTexCoord2f (
583
 
                COMP_TEX_COORD_X (mSky[0]->matrix (), afTexCoordX[0] * mSkySize.width ()),
584
 
                COMP_TEX_COORD_Y (mSky[0]->matrix (), afTexCoordY[0] * mSkySize.height ()));
 
593
                COMP_TEX_COORD_X (mSky[0]->matrix (), afTexCoordX[0] * mSkyWidth),
 
594
                COMP_TEX_COORD_Y (mSky[0]->matrix (), afTexCoordY[0] * mSkyHeight));
585
595
            glVertex3f (x * r * fRadius, y * r * fRadius, z * fRadius);
586
596
 
587
597
            /* top-left */
591
601
            y = sint1[j + 1];
592
602
 
593
603
            glTexCoord2f (
594
 
                COMP_TEX_COORD_X (mSky[0]->matrix (), afTexCoordX[1] * mSkySize.width ()),
595
 
                COMP_TEX_COORD_Y (mSky[0]->matrix (), afTexCoordY[1] * mSkySize.height ()));
 
604
                COMP_TEX_COORD_X (mSky[0]->matrix (), afTexCoordX[1] * mSkyWidth),
 
605
                COMP_TEX_COORD_Y (mSky[0]->matrix (), afTexCoordY[1] * mSkyHeight));
596
606
            glVertex3f (x * r * fRadius, y * r * fRadius, z * fRadius);
597
607
 
598
608
            /* bottom-left */
602
612
            y = sint1[j + 1];
603
613
 
604
614
            glTexCoord2f (
605
 
                COMP_TEX_COORD_X (mSky[0]->matrix (), afTexCoordX[2] * mSkySize.width ()),
606
 
                COMP_TEX_COORD_Y (mSky[0]->matrix (), afTexCoordY[2] * mSkySize.height ()));
 
615
                COMP_TEX_COORD_X (mSky[0]->matrix (), afTexCoordX[2] * mSkyWidth),
 
616
                COMP_TEX_COORD_Y (mSky[0]->matrix (), afTexCoordY[2] * mSkyHeight));
607
617
            glVertex3f (x * r * fRadius, y * r * fRadius, z * fRadius);
608
618
 
609
619
            afTexCoordX[0] -= fStepX;
628
638
    free (cost1);
629
639
    free (sint2);
630
640
    free (cost2);
631
 
 
632
641
#endif
633
642
}
634
643
 
640
649
    bool         rv = CubeOptions::setOption (name, value);
641
650
 
642
651
    if (!rv || !CompOption::findOption (getOptions (), name, &index))
643
 
        return false;
 
652
        return false;
644
653
 
645
654
    switch (index)
646
655
    {
697
706
void
698
707
PrivateCubeScreen::preparePaint (int msSinceLastPaint)
699
708
{
700
 
    int   opt;
701
 
    float x, progress;
 
709
    int            opt;
 
710
    float          x, progress;
702
711
    unsigned short *topColor, *bottomColor;
703
712
 
704
713
    if (mGrabIndex)
730
739
 
731
740
                    mUnfold = 0.0f;
732
741
                }
 
742
 
733
743
                break;
734
744
            }
735
745
        }
755
765
    if (mDesktopOpacity != mToOpacity ||
756
766
        (progress > 0.0 && progress < 1.0))
757
767
    {
758
 
        mDesktopOpacity = 
759
 
            (optionGetInactiveOpacity () - 
760
 
            ((optionGetInactiveOpacity () -
761
 
             mOptions[mLastOpacityIndex].value ().f ()) * progress))
762
 
            / 100.0f * OPAQUE;
 
768
        float inactiveOpacity = optionGetInactiveOpacity ();
763
769
 
 
770
        mDesktopOpacity = (inactiveOpacity -
 
771
                           ((inactiveOpacity - mOptions[mLastOpacityIndex].value ().f ()) *
 
772
                            progress)) / 100.0f * OPAQUE;
764
773
    }
765
774
 
766
775
    topColor    = optionGetTopColor ();
767
776
    bottomColor = optionGetBottomColor ();
768
777
 
769
778
    mPaintAllViewports = (mDesktopOpacity != OPAQUE ||
770
 
                          topColor[3] != OPAQUE ||
771
 
                          bottomColor[3] != OPAQUE);
 
779
                          topColor[3]     != OPAQUE ||
 
780
                          bottomColor[3]  != OPAQUE);
772
781
 
773
782
    cScreen->preparePaint (msSinceLastPaint);
774
783
}
838
847
    sTransform.translate (priv->mOutputXOffset, -priv->mOutputYOffset, 0.0f);
839
848
    sTransform.scale (priv->mOutputXScale, priv->mOutputYScale, 1.0f);
840
849
 
841
 
    GLMatrix mvp = pm * sTransform;
 
850
    GLMatrix mvp  = pm * sTransform;
842
851
 
843
852
    GLVector pntA = mvp * points[0];
844
853
 
876
885
{
877
886
    WRAPABLE_HND_FUNCTN_RETURN (bool, cubeShouldPaintViewport, sAttrib, transform, output, order)
878
887
 
879
 
    float pointZ = priv->mInvert * priv->mDistance;
 
888
    float                 pointZ = priv->mInvert * priv->mDistance;
880
889
    std::vector<GLVector> vPoints;
881
890
    vPoints.push_back (GLVector (-0.5, 0.0, pointZ, 1.0));
882
 
    vPoints.push_back (GLVector (0.0, 0.5, pointZ, 1.0));
883
 
    vPoints.push_back (GLVector (0.0, 0.0, pointZ, 1.0));
 
891
    vPoints.push_back (GLVector  (0.0, 0.5, pointZ, 1.0));
 
892
    vPoints.push_back (GLVector ( 0.0, 0.0, pointZ, 1.0));
884
893
 
885
894
    bool ftb = cubeCheckOrientation (sAttrib, transform, output, vPoints);
886
895
 
895
904
                                         PaintOrder                paintOrder,
896
905
                                         int                       dx)
897
906
{
898
 
    if (!cubeScreen->cubeShouldPaintViewport (sAttrib, transform, outputPtr,
899
 
                                              paintOrder))
 
907
    if (!cubeScreen->cubeShouldPaintViewport (sAttrib, transform, outputPtr, paintOrder))
900
908
        return;
901
909
 
902
910
    int output = ((unsigned int) outputPtr->id () != (unsigned int) ~0) ?
910
918
        int cubeOutput = mOutputMask[output];
911
919
 
912
920
        /* convert from window movement to viewport movement */
913
 
        int dView = -dx;
914
 
 
915
 
        cubeOutput += dView;
916
 
 
917
 
        dView      = cubeOutput / mNOutput;
918
 
        cubeOutput = cubeOutput % mNOutput;
 
921
        int dView      = -dx;
 
922
 
 
923
        cubeOutput    += dView;
 
924
 
 
925
        dView          = cubeOutput / mNOutput;
 
926
        cubeOutput     = cubeOutput % mNOutput;
919
927
 
920
928
        if (cubeOutput < 0)
921
929
        {
966
974
    int origXMoveAdd = 0; // dx for the viewport we start painting with (back-most).
967
975
    int iFirstSign;       /* 1 if we do xMove += i first and
968
976
                            -1 if we do xMove -= i first. */
 
977
    float halfHsize  = hsize / 2.0;
969
978
 
970
979
    if (mInvert == 1)
971
980
    {
977
986
        if ((sa.xRotate < 0.0f && hsize % 2 == 1) ||
978
987
            (sa.xRotate > 0.0f && hsize % 2 == 0))
979
988
        {
980
 
            origXMoveAdd = hsize / 2;
981
 
            iFirstSign = 1;
 
989
            origXMoveAdd =  halfHsize;
 
990
            iFirstSign =  1;
982
991
        }
983
992
        else
984
993
        {
985
 
            origXMoveAdd = -hsize / 2;
 
994
            origXMoveAdd = -halfHsize;
986
995
            iFirstSign = -1;
987
996
        }
988
997
    }
992
1001
        if (sa.xRotate > 0.0f)
993
1002
            iFirstSign = -1;
994
1003
        else
995
 
            iFirstSign = 1;
 
1004
            iFirstSign =  1;
996
1005
    }
997
1006
 
998
 
    int xMoveAdd;
 
1007
    int   xMoveAdd;
 
1008
    float tsSize = 360.0f / size;
999
1009
 
1000
 
    for (int i = 0; i <= hsize / 2; ++i)
 
1010
    for (int i = 0; i <= halfHsize; ++i)
1001
1011
    {
1002
1012
        /* move to the correct viewport (back to front). */
1003
 
        xMoveAdd = origXMoveAdd;        /* move to farthest viewport. */
 
1013
        xMoveAdd  = origXMoveAdd;       /* move to farthest viewport. */
1004
1014
        xMoveAdd += iFirstSign * i;     /* move i more viewports to
1005
1015
                                           the right / left. */
1006
1016
 
1008
1018
           We paint the viewports around xMove viewport.
1009
1019
           Adding or subtracting hsize from xMove has no effect on
1010
1020
           what viewport we paint, but can make shorter paths. */
1011
 
        if (xMoveAdd < -hsize / 2)
 
1021
        if (xMoveAdd < -halfHsize)
1012
1022
            xMoveAdd += hsize;
1013
 
        else if (xMoveAdd > hsize / 2)
 
1023
        else if (xMoveAdd >  halfHsize)
1014
1024
            xMoveAdd -= hsize;
1015
1025
 
1016
1026
        /* Paint the viewport. */
1017
1027
        xMove += xMoveAdd;
1018
1028
 
1019
 
        sa.yRotate -= mInvert * xMoveAdd * 360.0f / size;
1020
 
        moveViewportAndPaint (sa, transform, outputPtr, mask,
1021
 
                              paintOrder, xMove);
1022
 
        sa.yRotate += mInvert * xMoveAdd * 360.0f / size;
 
1029
        sa.yRotate -= mInvert * xMoveAdd * tsSize;
 
1030
        moveViewportAndPaint (sa, transform, outputPtr, mask, paintOrder, xMove);
 
1031
        sa.yRotate += mInvert * xMoveAdd * tsSize;
1023
1032
 
1024
1033
        xMove -= xMoveAdd;
1025
1034
 
1027
1036
        if (i == 0 || i * 2 == hsize)
1028
1037
            continue;
1029
1038
 
1030
 
        xMoveAdd = origXMoveAdd;        /* move to farthest viewport. */
 
1039
        xMoveAdd  = origXMoveAdd;       /* move to farthest viewport. */
1031
1040
        xMoveAdd -= iFirstSign * i;     /* move i more viewports to the
1032
1041
                                           left / right (opposite side
1033
1042
                                           from the one chosen first) */
1034
1043
 
1035
 
        if (xMoveAdd < -hsize / 2)
 
1044
        if (xMoveAdd < -halfHsize)
1036
1045
            xMoveAdd += hsize;
1037
 
        else if (xMoveAdd > hsize / 2)
 
1046
        else if (xMoveAdd >  halfHsize)
1038
1047
            xMoveAdd -= hsize;
1039
1048
 
1040
1049
        xMove += xMoveAdd;
1041
1050
 
1042
 
        sa.yRotate -= mInvert * xMoveAdd * 360.0f / size;
 
1051
        sa.yRotate -= mInvert * xMoveAdd * tsSize;
1043
1052
        moveViewportAndPaint (sa, transform, outputPtr, mask,
1044
1053
                              paintOrder, xMove);
1045
 
        sa.yRotate += mInvert * xMoveAdd * 360.0f / size;
 
1054
        sa.yRotate += mInvert * xMoveAdd * tsSize;
1046
1055
 
1047
1056
        xMove -= xMoveAdd;
1048
1057
    }
1066
1075
{
1067
1076
    WRAPABLE_HND_FUNCTN (cubeClearTargetOutput, xRotate, vRotate)
1068
1077
 
1069
 
    if (priv->mSky.size () > 0)
 
1078
    if (!priv->mSky.empty ())
1070
1079
    {
1071
1080
        priv->gScreen->setLighting (false);
1072
1081
#ifndef USE_GLES
1098
1107
{
1099
1108
    WRAPABLE_HND_FUNCTN (cubePaintTop, sAttrib, transform, output, size, normal)
1100
1109
 
1101
 
    GLScreenPaintAttrib sa         = sAttrib;
1102
 
    GLMatrix            sTransform = transform;
 
1110
    GLScreenPaintAttrib sa             = sAttrib;
 
1111
    GLMatrix            sTransform     = transform;
 
1112
    GLboolean           glBlendEnabled = glIsEnabled (GL_BLEND);
1103
1113
 
1104
1114
    priv->gScreen->setLighting (true);
1105
1115
 
1106
 
    unsigned short *color  = priv->optionGetTopColor ();
1107
 
    int            opacity = priv->mDesktopOpacity * color[3] / 0xffff;
 
1116
    unsigned short         *color           = priv->optionGetTopColor ();
 
1117
    int                    opacity          = priv->mDesktopOpacity * color[3] / 0xffff;
1108
1118
 
1109
 
    GLVertexBuffer *streamingBuffer = GLVertexBuffer::streamingBuffer ();
 
1119
    GLVertexBuffer         *streamingBuffer = GLVertexBuffer::streamingBuffer ();
1110
1120
    std::vector <GLushort> colorData;
1111
1121
 
1112
1122
    colorData.push_back (color[0] * opacity / 0xffff);
1126
1136
#ifndef USE_GLES
1127
1137
        priv->gScreen->setTexEnvMode (GL_MODULATE);
1128
1138
#endif
1129
 
        glEnable (GL_BLEND);
 
1139
        // just enable blending if it is disabled
 
1140
        if (!glBlendEnabled)
 
1141
            glEnable (GL_BLEND);
 
1142
 
1130
1143
        glBlendFunc (GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
1131
1144
    }
1132
1145
 
1150
1163
        priv->mTexture[0]->disable ();
1151
1164
 
1152
1165
    priv->gScreen->setTexEnvMode (GL_REPLACE);
1153
 
    glDisable (GL_BLEND);
 
1166
 
 
1167
    // just disable blending if it was disabled before
 
1168
    if (!glBlendEnabled)
 
1169
        glDisable (GL_BLEND);
 
1170
 
1154
1171
    glBlendFunc (GL_ONE, GL_ONE_MINUS_SRC_ALPHA);
1155
1172
}
1156
1173
 
1163
1180
{
1164
1181
    WRAPABLE_HND_FUNCTN (cubePaintBottom, sAttrib, transform, output, size, normal)
1165
1182
 
1166
 
    GLScreenPaintAttrib sa         = sAttrib;
1167
 
    GLMatrix            sTransform = transform;
 
1183
    GLScreenPaintAttrib sa             = sAttrib;
 
1184
    GLMatrix            sTransform     = transform;
 
1185
    GLboolean           glBlendEnabled = glIsEnabled (GL_BLEND);
1168
1186
 
1169
1187
    priv->gScreen->setLighting (true);
1170
1188
 
1191
1209
#ifndef USE_GLES
1192
1210
        priv->gScreen->setTexEnvMode (GL_MODULATE);
1193
1211
#endif
1194
 
        glEnable (GL_BLEND);
 
1212
        // just enable blending if it is disabled
 
1213
        if (!glBlendEnabled)
 
1214
            glEnable (GL_BLEND);
 
1215
 
1195
1216
        glBlendFunc (GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
1196
1217
    }
1197
1218
 
1206
1227
    streamingBuffer->render (sTransform);
1207
1228
 
1208
1229
    priv->gScreen->setTexEnvMode (GL_REPLACE);
1209
 
    glDisable (GL_BLEND);
 
1230
 
 
1231
    // just disable blending if it was disabled before
 
1232
    if (!glBlendEnabled)
 
1233
        glDisable (GL_BLEND);
 
1234
 
1210
1235
    glBlendFunc (GL_ONE, GL_ONE_MINUS_SRC_ALPHA);
1211
1236
}
1212
1237
 
1234
1259
        glTranslatef (mOutputXOffset, -mOutputYOffset, 0.0f);
1235
1260
        glScalef (mOutputXScale, mOutputYScale, 1.0f);
1236
1261
 
 
1262
        GLdouble mDist2 = 0.5 / mDistance;
 
1263
 
1237
1264
        if (mInvert == 1)
1238
1265
        {
1239
 
            GLdouble clipPlane0[] = {  1.0, 0.0, 0.5 / mDistance, 0.0 };
1240
 
            GLdouble clipPlane1[] = {  -1.0,  0.0, 0.5 / mDistance, 0.0 };
1241
 
            GLdouble clipPlane2[] = {  0.0,  -1.0, 0.5 / mDistance, 0.0 };
1242
 
            GLdouble clipPlane3[] = { 0.0,  1.0, 0.5 / mDistance, 0.0 };
 
1266
            GLdouble clipPlane0[] = {  1.0,  0.0, mDist2, 0.0 };
 
1267
            GLdouble clipPlane1[] = { -1.0,  0.0, mDist2, 0.0 };
 
1268
            GLdouble clipPlane2[] = {  0.0, -1.0, mDist2, 0.0 };
 
1269
            GLdouble clipPlane3[] = {  0.0,  1.0, mDist2, 0.0 };
1243
1270
            glClipPlane (GL_CLIP_PLANE0, clipPlane0);
1244
1271
            glClipPlane (GL_CLIP_PLANE1, clipPlane1);
1245
1272
            glClipPlane (GL_CLIP_PLANE2, clipPlane2);
1247
1274
        }
1248
1275
        else
1249
1276
        {
1250
 
            GLdouble clipPlane0[] = {  -1.0, 0.0, -0.5 / mDistance, 0.0 };
1251
 
            GLdouble clipPlane1[] = {  1.0,  0.0, -0.5 / mDistance, 0.0 };
1252
 
            GLdouble clipPlane2[] = {  0.0,  1.0, -0.5 / mDistance, 0.0 };
1253
 
            GLdouble clipPlane3[] = { 0.0,  -1.0, -0.5 / mDistance, 0.0 };
 
1277
            GLdouble clipPlane0[] = { -1.0,  0.0, -mDist2, 0.0 };
 
1278
            GLdouble clipPlane1[] = {  1.0,  0.0, -mDist2, 0.0 };
 
1279
            GLdouble clipPlane2[] = {  0.0,  1.0, -mDist2, 0.0 };
 
1280
            GLdouble clipPlane3[] = {  0.0, -1.0, -mDist2, 0.0 };
1254
1281
            glClipPlane (GL_CLIP_PLANE0, clipPlane0);
1255
1282
            glClipPlane (GL_CLIP_PLANE1, clipPlane1);
1256
1283
            glClipPlane (GL_CLIP_PLANE2, clipPlane2);
1304
1331
        updateGeometry (screen->vpSize ().width (), mInvert);
1305
1332
    }
1306
1333
 
1307
 
    int cullNorm;
 
1334
    int  cullNorm;
1308
1335
    glGetIntegerv (GL_CULL_FACE_MODE, &cullNorm);
1309
1336
 
1310
1337
    int  cullInv   = (cullNorm == GL_BACK)? GL_FRONT : GL_BACK;
1312
1339
 
1313
1340
    if (!mFullscreenOutput)
1314
1341
    {
1315
 
        mOutputXScale = (float) screen->width () / outputPtr->width ();
1316
 
        mOutputYScale = (float) screen->height () / outputPtr->height ();
 
1342
        float outputWidth  = outputPtr->width ();
 
1343
        float outputHeight = outputPtr->height ();
 
1344
 
 
1345
        mOutputXScale = (float) screen->width ()  / outputWidth;
 
1346
        mOutputYScale = (float) screen->height () / outputHeight;
1317
1347
 
1318
1348
        mOutputXOffset = (screen->width () / 2.0f -
1319
 
                          (outputPtr->x1 () + outputPtr->x2 ()) / 2.0f) /
1320
 
                         (float) outputPtr->width ();
 
1349
                          (outputPtr->x1 () + outputPtr->x2 ()) / 2.0f) / outputWidth;
1321
1350
 
1322
1351
        mOutputYOffset = (screen->height () / 2.0f -
1323
 
                          (outputPtr->y1 () +
1324
 
                           outputPtr->y2 ()) / 2.0f) /
1325
 
                         (float) outputPtr->height ();
 
1352
                          (outputPtr->y1 () + outputPtr->y2 ()) / 2.0f) / outputHeight;
1326
1353
    }
1327
1354
    else
1328
1355
    {
1341
1368
 
1342
1369
    if (!mCleared[output])
1343
1370
    {
1344
 
        float rRotate = xRotate - ((screen->vp ().x () *360.0f) /
 
1371
        float rRotate = xRotate - ((screen->vp ().x () * 360.0f) /
1345
1372
                                   screen->vpSize ().width ());
1346
1373
 
1347
1374
        cubeScreen->cubeClearTargetOutput (rRotate, vRotate);
1363
1390
 
1364
1391
        sa.zTranslate = -mInvert * (0.5f / tanf (M_PI / size));
1365
1392
 
1366
 
        /* distance we move the camera back when unfolding the cube.
1367
 
           currently hardcoded to 1.5 but it should probably be optional. */
 
1393
        /* Distance we move the camera back when unfolding the cube.
 
1394
           TODO: Currently hardcoded to 1.5, make this configurable via CCSM. */
1368
1395
        sa.zCamera -= mUnfold * 1.5f;
1369
1396
    }
1370
1397
    else
1389
1416
 
1390
1417
    sa.xRotate = sa.xRotate / size * hsize;
1391
1418
 
 
1419
    GLenum oldFilter = gScreen->textureFilter ();
 
1420
 
1392
1421
    if (mGrabIndex && optionGetMipmap ())
1393
1422
        gScreen->setTextureFilter (GL_LINEAR_MIPMAP_LINEAR);
1394
1423
 
1400
1429
        paintOrder = FTB;
1401
1430
        glCullFace (cullInv);
1402
1431
    }
1403
 
    else
1404
 
        /* Inside cube - start with BTF faces */
 
1432
    else /* Inside cube - start with BTF faces */
1405
1433
        paintOrder = BTF;
1406
1434
 
1407
1435
    if (mInvert == -1 || cubeScreen->cubeShouldPaintAllViewports ())
1413
1441
    if (wasCulled && cubeScreen->cubeShouldPaintAllViewports ())
1414
1442
        glDisable (GL_CULL_FACE);
1415
1443
 
1416
 
    bool paintCaps = !mGrabIndex && (hsize > 2) && !mCapsPainted[output] &&
 
1444
    bool paintCaps = !mGrabIndex && hsize > 2 && !mCapsPainted[output] &&
1417
1445
                     (mInvert != 1 || mDesktopOpacity != OPAQUE ||
1418
 
                     cubeScreen->cubeShouldPaintAllViewports () || sa.vRotate != 0.0f ||
1419
 
                     sa.yTranslate != 0.0f);
 
1446
                      cubeScreen->cubeShouldPaintAllViewports () || sa.vRotate != 0.0f ||
 
1447
                      sa.yTranslate != 0.0f);
1420
1448
 
1421
1449
    if (paintCaps)
1422
1450
    {
1430
1458
        bottom.push_back (GLVector (0.0, -0.5, -0.5, 1.0));
1431
1459
        bottom.push_back (GLVector (0.0, -0.5,  0.0, 1.0));
1432
1460
 
1433
 
        Bool topDir    = cubeScreen->cubeCheckOrientation (sa, transform, outputPtr, top);
1434
 
        Bool bottomDir = cubeScreen->cubeCheckOrientation (sa, transform, outputPtr, bottom);
1435
 
 
1436
 
        mCapsPainted[output] = TRUE;
1437
 
 
1438
 
        Bool allCaps = cubeScreen->cubeShouldPaintAllViewports () || mInvert != 1;
 
1461
        bool topDir    = cubeScreen->cubeCheckOrientation (sa, transform, outputPtr, top);
 
1462
        bool bottomDir = cubeScreen->cubeCheckOrientation (sa, transform, outputPtr, bottom);
 
1463
 
 
1464
        mCapsPainted[output] = true;
 
1465
 
 
1466
        bool allCaps = cubeScreen->cubeShouldPaintAllViewports () || mInvert != 1;
1439
1467
 
1440
1468
        if (topDir && bottomDir)
1441
1469
        {
1442
1470
            if (allCaps)
1443
1471
            {
1444
 
                cubeScreen->cubePaintBottom (sa, transform, outputPtr, hsize, GLVector (0.0f, -1.0f, 0.0f, 1.0f));
1445
 
                cubeScreen->cubePaintInside (sa, transform, outputPtr, hsize, GLVector (0.0f, 0.0f, -1.0f, 1.0f));
 
1472
                cubeScreen->cubePaintBottom (sa, transform, outputPtr, hsize, GLVector (0.0f, -1.0f,  0.0f, 1.0f));
 
1473
                cubeScreen->cubePaintInside (sa, transform, outputPtr, hsize, GLVector (0.0f,  0.0f, -1.0f, 1.0f));
1446
1474
            }
1447
1475
 
1448
1476
            cubeScreen->cubePaintTop (sa, transform, outputPtr, hsize, GLVector (0.0f, -1.0f, 0.0f, 1.0f));
1451
1479
        {
1452
1480
            if (allCaps)
1453
1481
            {
1454
 
                cubeScreen->cubePaintTop (sa, transform, outputPtr, hsize, GLVector (0.0f, 1.0f, 0.0f, 1.0f));
 
1482
                cubeScreen->cubePaintTop    (sa, transform, outputPtr, hsize, GLVector (0.0f, 1.0f,  0.0f, 1.0f));
1455
1483
                cubeScreen->cubePaintInside (sa, transform, outputPtr, hsize, GLVector (0.0f, 0.0f, -1.0f, 1.0f));
1456
1484
            }
1457
1485
 
1459
1487
        }
1460
1488
        else if (allCaps)
1461
1489
        {
1462
 
            cubeScreen->cubePaintTop (sa, transform, outputPtr, hsize, GLVector (0.0f, 1.0f, 0.0f, 1.0f));
1463
 
            cubeScreen->cubePaintBottom (sa, transform, outputPtr, hsize, GLVector (0.0f, -1.0f, 0.0f, 1.0f));
1464
 
            cubeScreen->cubePaintInside (sa, transform, outputPtr, hsize, GLVector (0.0f, 0.0f, -1.0f, 1.0f));
 
1490
            cubeScreen->cubePaintTop    (sa, transform, outputPtr, hsize, GLVector (0.0f,  1.0f,  0.0f, 1.0f));
 
1491
            cubeScreen->cubePaintBottom (sa, transform, outputPtr, hsize, GLVector (0.0f, -1.0f,  0.0f, 1.0f));
 
1492
            cubeScreen->cubePaintInside (sa, transform, outputPtr, hsize, GLVector (0.0f,  0.0f, -1.0f, 1.0f));
1465
1493
        }
1466
1494
    }
1467
1495
 
1484
1512
 
1485
1513
    glCullFace (cullNorm);
1486
1514
 
1487
 
    GLenum filter = gScreen->textureFilter ();
1488
 
    gScreen->setTextureFilter (filter);
 
1515
    gScreen->setTextureFilter (oldFilter);
1489
1516
}
1490
1517
 
1491
1518
bool 
1492
1519
PrivateCubeWindow::glPaint (const GLWindowPaintAttrib &attrib, 
1493
1520
                            const GLMatrix            &transform,
1494
 
                            const CompRegion          &region, 
 
1521
                            const CompRegion          &region,
1495
1522
                            unsigned int              mask)
1496
1523
{
1497
1524
 
1499
1526
        (attrib.opacity != cubeScreen->priv->mDesktopOpacity))
1500
1527
    {
1501
1528
        GLWindowPaintAttrib wAttrib = attrib;
1502
 
 
1503
 
        wAttrib.opacity = cubeScreen->priv->mDesktopOpacity;
 
1529
        wAttrib.opacity             = cubeScreen->priv->mDesktopOpacity;
1504
1530
 
1505
1531
        return gWindow->glPaint (wAttrib, transform, region, mask);
1506
1532
    }
1616
1642
PrivateCubeScreen::PrivateCubeScreen (CompScreen *s) :
1617
1643
    cScreen (CompositeScreen::get (s)),
1618
1644
    gScreen (GLScreen::get (s)),
1619
 
    cubeScreen (CubeScreen::get (s))
 
1645
    cubeScreen (CubeScreen::get (s)),
 
1646
    mInvert (1),
 
1647
    mXRotations (0),
 
1648
    mPaintOrder (BTF),
 
1649
    mRotationState (CubeScreen::RotationNone),
 
1650
    mPaintAllViewports (false),
 
1651
    mDistance (0.0f),
 
1652
    mTc (),
 
1653
    mGrabIndex (0),
 
1654
    mSrcOutput (0),
 
1655
    mUnfolded (false),
 
1656
    mUnfold (0.0f),
 
1657
    mUnfoldVelocity (0.0f),
 
1658
    mVertices (NULL),
 
1659
    mNVertices (0),
 
1660
    mSkyListId (0),
 
1661
    mPw (0),
 
1662
    mPh (0),
 
1663
    mSkySize (0, 0),
 
1664
    mTexture (0),
 
1665
    mSky (0),
 
1666
    mImgCurFile (0),
 
1667
    mNOutput (1),
 
1668
    mOutput (),
 
1669
    mOutputMask (),
 
1670
    mCleared (),
 
1671
    mCapsPainted (),
 
1672
    mFullscreenOutput (true),
 
1673
    mOutputXScale (1.0f),
 
1674
    mOutputYScale (1.0f),
 
1675
    mOutputXOffset (0.0f),
 
1676
    mOutputYOffset (0.0f),
 
1677
    mDesktopOpacity (OPAQUE),
 
1678
    mToOpacity (OPAQUE),
 
1679
    mLastOpacityIndex (CubeOptions::InactiveOpacity),
 
1680
    mRecalcOutput (false),
 
1681
    mReversedWindowList (0)
1620
1682
{
1621
 
    mPw = 0;
1622
 
    mPh = 0;
1623
 
 
1624
 
    mInvert = 1;
1625
 
 
1626
1683
    for (int i = 0; i < 8; ++i)
1627
1684
        mTc[i] = 0.0f;
1628
1685
 
1629
 
    mNVertices = 0;
1630
 
    mVertices  = NULL;
1631
 
 
1632
 
    mGrabIndex = 0;
1633
 
 
1634
 
    mSrcOutput = 0;
1635
 
 
1636
 
    mSkyListId = 0;
1637
 
 
1638
 
    mImgCurFile = 0;
1639
 
 
1640
 
    mUnfolded = false;
1641
 
    mUnfold   = 0.0f;
1642
 
 
1643
 
    mUnfoldVelocity = 0.0f;
1644
 
 
1645
 
    mPaintAllViewports = false;
1646
 
    mFullscreenOutput  = true;
1647
 
 
1648
 
    mOutputXScale  = 1.0f;
1649
 
    mOutputYScale  = 1.0f;
1650
 
    mOutputXOffset = 0.0f;
1651
 
    mOutputYOffset = 0.0f;
1652
 
 
1653
 
    mRotationState = CubeScreen::RotationNone;
1654
 
 
1655
 
    mDesktopOpacity = OPAQUE;
1656
 
    mPaintOrder = BTF;
1657
 
 
1658
 
    mLastOpacityIndex = CubeOptions::InactiveOpacity;
1659
 
 
1660
 
 
1661
 
    mRecalcOutput = false;
1662
 
 
1663
1686
    memset (mCleared, 0, sizeof (mCleared));
1664
1687
 
1665
1688
    updateOutputs ();
1685
1708
#endif
1686
1709
}
1687
1710
 
1688
 
 
1689
1711
template class PluginClassHandler<PrivateCubeWindow, CompWindow, COMPIZ_CUBE_ABI>;
1690
1712
 
1691
1713
PrivateCubeWindow::PrivateCubeWindow (CompWindow *w) :