Merge lp:~mc-return/compiz/compiz.merge-cube-speed-improvements into lp:compiz/0.9.10

Proposed by MC Return
Status: Merged
Approved by: Sam Spilsbury
Approved revision: 3750
Merged at revision: 3776
Proposed branch: lp:~mc-return/compiz/compiz.merge-cube-speed-improvements
Merge into: lp:compiz/0.9.10
Diff against target: 808 lines (+200/-178)
1 file modified
plugins/cube/src/cube.cpp (+200/-178)
To merge this branch: bzr merge lp:~mc-return/compiz/compiz.merge-cube-speed-improvements
Reviewer Review Type Date Requested Status
Sam Spilsbury Approve
PS Jenkins bot (community) continuous-integration Approve
MC Return Needs Resubmitting
Review via email: mp+166848@code.launchpad.net

Commit message

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)

To post a comment you must log in.
Revision history for this message
Sam Spilsbury (smspillaz) wrote :

149 - memset (mCleared, 0, sizeof (Bool) * screen->outputDevs ().size ());
150 + memset (mCleared, 0, sizeof (Bool) * screen->outputDevs ().size ());

283 - if (xMoveAdd < -hsize / 2)
284 + if (xMoveAdd < -halfHsize)
285 xMoveAdd += hsize;

473 GLScreenPaintAttrib sa = sAttrib;
474 - sa.xRotate += xRotate;
475 - sa.vRotate += vRotate;
476 + sa.xRotate += xRotate;
477 + sa.vRotate += vRotate;

While whitespace alignment can sometimes be helpful, use it judicially. Typically, it makes a lot of sense in mutliple-assignment type scenarios. Otherwise it can become distracting. I've picked out some examples where I think such alignment hurts more than it helps.

490 - /* distance we move the camera back when unfolding the cube.
491 + /* TODO: Distance we move the camera back when unfolding the cube.
492 currently hardcoded to 1.5 but it should probably be optional. */

The relevant todo is the fact that it could be optional, not the distance the cube is being moved.

The other changes are mostly fine for now.

Something to keep in mind: The linked bug report about the redundant state changes goes more towards the fundamental architecture of compiz rather than something that can be fixed on a case by case basis. Currently the only mechanism that we have in order to avoid such calls into OpenGL is effectively more calls into OpenGL by querying the state, which in some cases can actually be worse than the state change because it requires looking up the current state of the pipeline as it might have been modified internally.

In this case, it doesn't really matter too much - we check to see if a particular state was enabled or disabled before doing both (eg, if enabled, leave it enabled and don't disable it later, if not enabled, disable it later).

Revision history for this message
MC Return (mc-return) wrote :
Download full text (3.2 KiB)

Ups - somehow I missed this review...

> 149 - memset (mCleared, 0, sizeof (Bool) * screen->outputDevs ().size
> ());
> 150 + memset (mCleared, 0, sizeof (Bool) * screen->outputDevs
> ().size ());
>
This is really badly aligned. Will fix it.

> 283 - if (xMoveAdd < -hsize / 2)
> 284 + if (xMoveAdd < -halfHsize)
> 285 xMoveAdd += hsize;
>
This has to be viewed together with the else part to make sense, but
I agree it could look better, but in this case really helps readability:

 if (xMoveAdd < -halfHsize)
     xMoveAdd += hsize;
 else if (xMoveAdd > halfHsize)
     xMoveAdd -= hsize;

> 473 GLScreenPaintAttrib sa = sAttrib;
> 474 - sa.xRotate += xRotate;
> 475 - sa.vRotate += vRotate;
> 476 + sa.xRotate += xRotate;
> 477 + sa.vRotate += vRotate;
>

I will revert the 47x changes, they really do not help much.

> While whitespace alignment can sometimes be helpful, use it judicially.
> Typically, it makes a lot of sense in mutliple-assignment type scenarios.
> Otherwise it can become distracting. I've picked out some examples where I
> think such alignment hurts more than it helps.
>

Yes, sometimes I try to be too perfectionistic, but I try my best to judge
carefully between useful and useless aligning.

> 490 - /* distance we move the camera back when unfolding the cube.
> 491 + /* TODO: Distance we move the camera back when unfolding the
> cube.
> 492 currently hardcoded to 1.5 but it should probably be
> optional. */
>
> The relevant todo is the fact that it could be optional, not the distance the
> cube is being moved.
>
Yes, you are right -> this could be misinterpreted... I'll fix it.

> The other changes are mostly fine for now.
>
+1. Thanks for your review.

> Something to keep in mind: The linked bug report about the redundant state
> changes goes more towards the fundamental architecture of compiz rather than
> something that can be fixed on a case by case basis. Currently the only
> mechanism that we have in order to avoid such calls into OpenGL is effectively
> more calls into OpenGL by querying the state, which in some cases can actually
> be worse than the state change because it requires looking up the current
> state of the pipeline as it might have been modified internally.
>
Well, I have not found a better way to do that faster...

> In this case, it doesn't really matter too much - we check to see if a
> particular state was enabled or disabled before doing both (eg, if enabled,
> leave it enabled and don't disable it later, if not enabled, disable it
> later).

This should be the fastest and our only way to do it correctly...
The plan of course is to do that for all global OpenGL state changes, not only
for GL_BLEND...
But GL_BLEND is a state that is often used by multiple plugins at the same time,
especially when activating the cube, so instead of enabling/disabling blending
redundantly in each plugin (for example: cube+cubeaddon+gears+rotate) we just do
it once and skip the other state changes...
I think this should be much more efficient, but if you have ot...

Read more...

Revision history for this message
MC Return (mc-return) wrote :

All issues fixed in r3735.

review: Needs Resubmitting
Revision history for this message
MC Return (mc-return) wrote :

Ping ?

Revision history for this message
Sam Spilsbury (smspillaz) wrote :

I'll get to this in a few days, busy with exam related stuff at the moment.

On Thu, Jun 13, 2013 at 2:18 PM, MC Return <email address hidden> wrote:
> Ping ?
> --
> https://code.launchpad.net/~mc-return/compiz/compiz.merge-cube-speed-improvements/+merge/166848
> Your team Compiz Maintainers is subscribed to branch lp:compiz.

--
Sam Spilsbury

Revision history for this message
MC Return (mc-return) wrote :

I have upgraded this MP with a few more speedups now (see r3737).

Revision history for this message
MC Return (mc-return) wrote :
Revision history for this message
MC Return (mc-return) wrote :

*and r3740

Revision history for this message
Sam Spilsbury (smspillaz) wrote :

>
> > The other changes are mostly fine for now.
> >
> +1. Thanks for your review.
>
> > Something to keep in mind: The linked bug report about the redundant state
> > changes goes more towards the fundamental architecture of compiz rather than
> > something that can be fixed on a case by case basis. Currently the only
> > mechanism that we have in order to avoid such calls into OpenGL is
> effectively
> > more calls into OpenGL by querying the state, which in some cases can
> actually
> > be worse than the state change because it requires looking up the current
> > state of the pipeline as it might have been modified internally.
> >
> Well, I have not found a better way to do that faster...
>
> > In this case, it doesn't really matter too much - we check to see if a
> > particular state was enabled or disabled before doing both (eg, if enabled,
> > leave it enabled and don't disable it later, if not enabled, disable it
> > later).
>
> This should be the fastest and our only way to do it correctly...
> The plan of course is to do that for all global OpenGL state changes, not only
> for GL_BLEND...
> But GL_BLEND is a state that is often used by multiple plugins at the same
> time,
> especially when activating the cube, so instead of enabling/disabling blending
> redundantly in each plugin (for example: cube+cubeaddon+gears+rotate) we just
> do
> it once and skip the other state changes...
> I think this should be much more efficient, but if you have other ideas I
> would
> be happy to hear those...

I was thinking of something like this:

http://code.google.com/p/gamekit/source/browse/trunk/Ogre-1.9a/RenderSystems/GLES2/src/StateCacheManager/OgreGLES2StateCacheManagerImp.cpp?r=1213

Revision history for this message
Sam Spilsbury (smspillaz) wrote :

The follow up changes are on the right track, I think these two variables could be renamed:

        float hInvert;
        float oPtrWidth = outputPtr->width ();
        float oPtrHeight = outputPtr->height ();

They're a bit confusing as is. How about:

    float normalizedInversion;
    float outputWidth;
    float outputHeight;

Revision history for this message
MC Return (mc-return) wrote :

> The follow up changes are on the right track, I think these two variables
> could be renamed:
>
> float hInvert;
> float oPtrWidth = outputPtr->width ();
> float oPtrHeight = outputPtr->height ();
>
> They're a bit confusing as is. How about:
>
> float normalizedInversion;
> float outputWidth;
> float outputHeight;

Roger.

Revision history for this message
MC Return (mc-return) wrote :

>
> I was thinking of something like this:
>
> http://code.google.com/p/gamekit/source/browse/trunk/Ogre-1.9a/RenderSystems/G
> LES2/src/StateCacheManager/OgreGLES2StateCacheManagerImp.cpp?r=1213

Yeah a StateCacheManager would really be useful, especially in our case with having multiple plugins with their own GL code drawing and switching states simultaneously...

I think some fast implementation of this would be great to have. :)

Revision history for this message
MC Return (mc-return) wrote :

> The follow up changes are on the right track, I think these two variables
> could be renamed:
>
> float hInvert;
> float oPtrWidth = outputPtr->width ();
> float oPtrHeight = outputPtr->height ();
>
> They're a bit confusing as is. How about:
>
> float normalizedInversion;
> float outputWidth;
> float outputHeight;

Done in r3743.
Note:
I used normInvert instead of normalizedInversion, as the function's input variable is called invert.

review: Needs Resubmitting
Revision history for this message
MC Return (mc-return) wrote :

I think I will need to improve the GL filter code here as well, but I'll wait until the Expo version of it is approved to not have to do things twice if some change is needed there...

Revision history for this message
Sam Spilsbury (smspillaz) wrote :
Download full text (3.8 KiB)

241 + memset (mCleared, 0, sizeof (Bool) * screen->outputDevs ().size ());
291 + vPoints.push_back (GLVector (0.0, 0.5, pointZ, 1.0));
292 + vPoints.push_back (GLVector ( 0.0, 0.0, pointZ, 1.0));
339 + origXMoveAdd = halfHsize;
340 + iFirstSign = 1;
375 + if (xMoveAdd < -halfHsize)
376 xMoveAdd += hsize;
377 - else if (xMoveAdd > hsize / 2)
378 + else if (xMoveAdd > halfHsize)
552 - int cullNorm;
553 + int cullNorm;
681 - cubeScreen->cubePaintTop (sa, transform, outputPtr, hsize, GLVector (0.0f, 1.0f, 0.0f, 1.0f));
682 + cubeScreen->cubePaintTop (sa, transform, outputPtr, hsize, GLVector (0.0f, 1.0f, 0.0f, 1.0f));
683 cubeScreen->cubePaintInside (sa, transform, outputPtr, hsize, GLVector (0.0f, 0.0f, -1.0f, 1.0f));
684 }
685
686 @@ -1459,9 +1492,9 @@
687 }
688 else if (allCaps)
689 {
690 - cubeScreen->cubePaintTop (sa, transform, outputPtr, hsize, GLVector (0.0f, 1.0f, 0.0f, 1.0f));
691 - cubeScreen->cubePaintBottom (sa, transform, outputPtr, hsize, GLVector (0.0f, -1.0f, 0.0f, 1.0f));
692 - cubeScreen->cubePaintInside (sa, transform, outputPtr, hsize, GLVector (0.0f, 0.0f, -1.0f, 1.0f));
693 + cubeScreen->cubePaintTop (sa, transform, outputPtr, hsize, GLVector (0.0f, 1.0f, 0.0f, 1.0f));
694 + cubeScreen->cubePaintBottom (sa, transform, outputPtr, hsize, GLVector (0.0f, -1.0f, 0.0f, 1.0f));
695 + cubeScreen->cubePaintInside (sa, transform, outputPtr, hsize, GLVector (0.0f, 0.0f, -1.0f, 1.0f));
732 - cScreen (CompositeScreen::get (s)),
733 - gScreen (GLScreen::get (s)),
734 - cubeScreen (CubeScreen::get (s))
735 + cScreen (CompositeScreen::get (s)),
736 + gScreen (GLScreen::get (s)),
737 + cubeScreen (CubeScreen::get (s)),
738 + mInvert (1),
739 + mXRotations (0),
740 + mPaintOrder (BTF),
741 + mRotationState (CubeScreen::RotationNone),
742 + mPaintAllViewports (false),
743 + mDistance (0.0f),
744 + mGrabIndex (0),
745 + mSrcOutput (0),
746 + mUnfolded (false),
747 + mUnfold (0.0f),
748 + mUnfoldVelocity (0.0f),
749 + mVertices (NULL),
750 + mNVertices (0),
751 + mSkyListId (0),
752 + mPw (0),
753 + mPh (0),
754 + mSkySize (0, 0),
755 + mTexture (0),
756 + mSky (0),
757 + mImgCurFile (0),
758 + mFullscreenOutput (true),
759 + mOutputXScale (1.0f),
760 + mOutputYScale (1.0f),
761 + mOutputXOffset (0.0f),
762 + mOutputYOffset (0.0f),
763 + mDesktopOpacity (OPAQUE),
764 + mToOpacity (OPAQUE),
765 + mLastOpacityIndex (CubeOptions::InactiveOpacity),
766 + mRecalcOutput (false),
767 + mReversedWindowList (0)
826 + window (w),
827 + cWindow (CompositeWindow::get (w)),
828 + gWindow (GLWindow::get (w)),

The use of whitespacing for alignment here doesn't make any sense.

There's no specific rule about alignment in the compiz code, generally do it where it is tastefu...

Read more...

Revision history for this message
MC Return (mc-return) wrote :
Download full text (5.3 KiB)

> 241 + memset (mCleared, 0, sizeof (Bool) * screen->outputDevs
> ().size ());
> 291 + vPoints.push_back (GLVector (0.0, 0.5, pointZ, 1.0));
> 292 + vPoints.push_back (GLVector ( 0.0, 0.0, pointZ, 1.0));
> 339 + origXMoveAdd = halfHsize;
> 340 + iFirstSign = 1;
> 375 + if (xMoveAdd < -halfHsize)
> 376 xMoveAdd += hsize;
> 377 - else if (xMoveAdd > hsize / 2)
> 378 + else if (xMoveAdd > halfHsize)
> 552 - int cullNorm;
> 553 + int cullNorm;
> 681 - cubeScreen->cubePaintTop (sa, transform, outputPtr,
> hsize, GLVector (0.0f, 1.0f, 0.0f, 1.0f));
> 682 + cubeScreen->cubePaintTop (sa, transform, outputPtr,
> hsize, GLVector (0.0f, 1.0f, 0.0f, 1.0f));
> 683 cubeScreen->cubePaintInside (sa, transform, outputPtr,
> hsize, GLVector (0.0f, 0.0f, -1.0f, 1.0f));
> 684 }
> 685
> 686 @@ -1459,9 +1492,9 @@
> 687 }
> 688 else if (allCaps)
> 689 {
> 690 - cubeScreen->cubePaintTop (sa, transform, outputPtr, hsize,
> GLVector (0.0f, 1.0f, 0.0f, 1.0f));
> 691 - cubeScreen->cubePaintBottom (sa, transform, outputPtr,
> hsize, GLVector (0.0f, -1.0f, 0.0f, 1.0f));
> 692 - cubeScreen->cubePaintInside (sa, transform, outputPtr,
> hsize, GLVector (0.0f, 0.0f, -1.0f, 1.0f));
> 693 + cubeScreen->cubePaintTop (sa, transform, outputPtr,
> hsize, GLVector (0.0f, 1.0f, 0.0f, 1.0f));
> 694 + cubeScreen->cubePaintBottom (sa, transform, outputPtr,
> hsize, GLVector (0.0f, -1.0f, 0.0f, 1.0f));
> 695 + cubeScreen->cubePaintInside (sa, transform, outputPtr,
> hsize, GLVector (0.0f, 0.0f, -1.0f, 1.0f));
> 732 - cScreen (CompositeScreen::get (s)),
> 733 - gScreen (GLScreen::get (s)),
> 734 - cubeScreen (CubeScreen::get (s))
> 735 + cScreen (CompositeScreen::get (s)),
> 736 + gScreen (GLScreen::get (s)),
> 737 + cubeScreen (CubeScreen::get (s)),
> 738 + mInvert (1),
> 739 + mXRotations (0),
> 740 + mPaintOrder (BTF),
> 741 + mRotationState (CubeScreen::RotationNone),
> 742 + mPaintAllViewports (false),
> 743 + mDistance (0.0f),
> 744 + mGrabIndex (0),
> 745 + mSrcOutput (0),
> 746 + mUnfolded (false),
> 747 + mUnfold (0.0f),
> 748 + mUnfoldVelocity (0.0f),
> 749 + mVertices (NULL),
> 750 + mNVertices (0),
> 751 + mSkyListId (0),
> 752 + mPw (0),
> 753 + mPh (0),
> 754 + mSkySize (0, 0),
> 755 + mTexture (0),
> 756 + mSky (0),
> 757 + mImgCurFile (0),
> 758 + mFullscreenOutput (true),
> 759 + mOutputXScale (1.0f),
> 760 + mOutputYScale (1.0f),
> 761 + mOutputXOffset (0.0f),
> 762 + mOutputYOffset (0.0f)...

Read more...

review: Needs Resubmitting
Revision history for this message
Sam Spilsbury (smspillaz) wrote :
Download full text (6.0 KiB)

1417 /* check the actual filtering */
1418 oldFilter = gScreen->textureFilter ();

This still needs to be removed.

> Well, I also like to align other things, because it helps the brain to analyze and especially order things faster. > One of the common things that massively improve readability is alignment of mathematical equations, for example:

> int width = w->width () + w->border ().left + w->border ().right;
> int height = w->height () + w->border ().top + w->border ().bottom;

> is much better to read than:

> int width = w->width () + w->border ().right + w->border ().left;
> int height = w->height () + w->border ().bottom + w->border ().top;

Like I mentioned beforehand, whitespace alignment is only useful when it is used tastefully. That's generally only where there might be some structural similarity in between lines.

Alignment like this:

Foo::Foo () :
    bar (0),
    baz (1),
    aReallyReallyReallyReallyReallyLongVariableName (2)
{
}

Does not help at all.

For one, there's probably not much of a relationship between the third member and the second/first. Secondly, that's a ridiculous amount of whitespacing for the sake of aligning unrelated things. The tighter structural relationship is really between the variable and the value it is being initialized with and not between the variable and other variables.

I should explain a little bit as to why whitespace alignment is used in the cases that it is currently used, as that might help in understanding where not to use it.

In variable declarations and assignments, it might be the case where you have a lot of data that needs to be declared and assigned in one section. For example:

int left = 0;
int right = 1;
int top = 2;
int bottom = 3;

The reason for the alignment here is to divide the chunk of assignments into a single mental block. This mental block shows that all the data is related. If I tried to whitespace align everything, the block might become misleading:

int left = 0;
int right = 0;
int top = 0;
int bottom = 0;
bool earlyReturn = false;

Quickly reading this in the context of the other code, you might be forgiven for thinking that "left, right, top, bottom" had something to do with "earlyReturn". But in fact, they don't have anything to do with it at all, and the formatting becomes misleading in that aspect.

A far better alternative is to use vertical whitespacing as a divider:

int left = 0;
int right = 1;
int top = 2;
int bottom = 3;

bool earlyReturn = false;

Likewise, for function arguments, all the arguments that come in are related to the function itself.

The same thing doesn't really apply to multiple compound statements. The reason for that is that the relationship is not between other variables which are not part of that statement, but instead variables inside the statement itself. For example:

int left = leftBorder * leftScale;
int right = rightBorder * cos (15);
int top = topBorder * abs (-1.0);
int bottom = bottomBorder * sqrt (4);

In this example, we are expressing that there *is* a rel...

Read more...

review: Needs Fixing
Revision history for this message
MC Return (mc-return) wrote :
Download full text (5.7 KiB)

> 1417 /* check the actual filtering */
> 1418 oldFilter = gScreen->textureFilter ();
>
> This still needs to be removed.
>
Why ? Don't we need to set back the filter to the old state if we changed it ?

>
> Alignment like this:
>
> Foo::Foo () :
> bar (0),
> baz (1),
> aReallyReallyReallyReallyReallyLongVariableName (2)
> {
> }
>
> Does not help at all.
>

The problem in your example seems to be the aReallyReallyReallyReallyReallyLongVariableName, which maybe should be shortened ;)

> For one, there's probably not much of a relationship between the third member
> and the second/first. Secondly, that's a ridiculous amount of whitespacing for
> the sake of aligning unrelated things. The tighter structural relationship is
> really between the variable and the value it is being initialized with and not
> between the variable and other variables.
>
> I should explain a little bit as to why whitespace alignment is used in the
> cases that it is currently used, as that might help in understanding where not
> to use it.
>
> In variable declarations and assignments, it might be the case where you have
> a lot of data that needs to be declared and assigned in one section. For
> example:
>
> int left = 0;
> int right = 1;
> int top = 2;
> int bottom = 3;
>
> The reason for the alignment here is to divide the chunk of assignments into a
> single mental block. This mental block shows that all the data is related. If
> I tried to whitespace align everything, the block might become misleading:
>
> int left = 0;
> int right = 0;
> int top = 0;
> int bottom = 0;
> bool earlyReturn = false;
>
> Quickly reading this in the context of the other code, you might be forgiven
> for thinking that "left, right, top, bottom" had something to do with
> "earlyReturn". But in fact, they don't have anything to do with it at all, and
> the formatting becomes misleading in that aspect.
>
Well, maybe this block simply has the context "Reset all values", then the second
block would be IMHO okay.

> A far better alternative is to use vertical whitespacing as a divider:
>
> int left = 0;
> int right = 1;
> int top = 2;
> int bottom = 3;
>
> bool earlyReturn = false;
>
I agree. In this case it really depends on the context.

> Likewise, for function arguments, all the arguments that come in are related
> to the function itself.
>
> The same thing doesn't really apply to multiple compound statements. The
> reason for that is that the relationship is not between other variables which
> are not part of that statement, but instead variables inside the statement
> itself. For example:
>
> int left = leftBorder * leftScale;
> int right = rightBorder * cos (15);
> int top = topBorder * abs (-1.0);
> int bottom = bottomBorder * sqrt (4);
>
> In this example, we are expressing that there *is* a relationship between
> left, right, top and bottom. But we are also expressing (through closer
> whitespacing) that there is a tight relationship between rightBorder and cos
> (15) etc. However, if we were to align it, ...

Read more...

Revision history for this message
MC Return (mc-return) wrote :

Hopefully this is okay now :)

review: Needs Resubmitting
Revision history for this message
PS Jenkins bot (ps-jenkins) wrote :
review: Approve (continuous-integration)
Revision history for this message
MC Return (mc-return) wrote :

> Hopefully this is okay now :)

Jenkins at least thinks so ;)

Revision history for this message
MC Return (mc-return) wrote :

Note:
This MP also fixes Cube Deformation sometimes failing, at least I have not seen it fail since I have this running locally, but I did not file a bug about the issue.
It seems that initializing all the class member variables in the constructor was a good idea to not get undefined states of variables when executing the code...

review: Needs Resubmitting
Revision history for this message
MC Return (mc-return) wrote :

I filed and linked a bug report now.

Revision history for this message
PS Jenkins bot (ps-jenkins) wrote :
review: Needs Fixing (continuous-integration)
Revision history for this message
MC Return (mc-return) wrote :

Hmm, the Jenkins error seems unrelated:

The following tests FAILED:
 1267 - DecorPixmapProtocol.PostDeleteCausesClientMessage (Failed)
-- Processing memory checking output: ##########
Memory checking results:
Uninitialized Memory Conditional - 2060
Uninitialized Memory Read - 548
        Errors while running CTest

Revision history for this message
PS Jenkins bot (ps-jenkins) wrote :
review: Approve (continuous-integration)
Revision history for this message
Sam Spilsbury (smspillaz) wrote :

248 + memset (mCleared, 0, sizeof (Bool) * screen->outputDevs ().size ());
249 memset (mCapsPainted, 0, sizeof (Bool) * screen->outputDevs ().size ());
250

382 + if (xMoveAdd < -halfHsize)
383 xMoveAdd += hsize;
384 - else if (xMoveAdd > hsize / 2)
385 + else if (xMoveAdd > halfHsize)

All else is fine, but please fix these (over)-alignment problems.

review: Needs Fixing
Revision history for this message
MC Return (mc-return) wrote :

> 248 + memset (mCleared, 0, sizeof (Bool) * screen->outputDevs
> ().size ());
> 249 memset (mCapsPainted, 0, sizeof (Bool) * screen->outputDevs
> ().size ());
> 250
>
> 382 + if (xMoveAdd < -halfHsize)
> 383 xMoveAdd += hsize;
> 384 - else if (xMoveAdd > hsize / 2)
> 385 + else if (xMoveAdd > halfHsize)
>
> All else is fine, but please fix these (over)-alignment problems.

Done. Thanks a lot for the review.

review: Needs Resubmitting
Revision history for this message
PS Jenkins bot (ps-jenkins) wrote :
review: Approve (continuous-integration)
Revision history for this message
Sam Spilsbury (smspillaz) :
review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'plugins/cube/src/cube.cpp'
2--- plugins/cube/src/cube.cpp 2013-05-31 10:56:27 +0000
3+++ plugins/cube/src/cube.cpp 2013-07-21 14:31:25 +0000
4@@ -30,7 +30,7 @@
5 #include <X11/Xatom.h>
6 #include <X11/Xproto.h>
7
8-#include <privates.h>
9+#include "privates.h"
10
11 class CubePluginVTable :
12 public CompPlugin::VTableForScreenAndWindow<CubeScreen, PrivateCubeWindow, COMPIZ_CUBE_ABI>
13@@ -238,19 +238,27 @@
14 PrivateCubeScreen::updateGeometry (int sides,
15 int invert)
16 {
17+ /* This will never happen, but we want to calm down the static code analyzer
18+ * Coverity
19+ * See: https://bugs.launchpad.net/compiz/+bug/1101541 for details
20+ */
21+ if (!sides)
22+ return false;
23+
24+ sides *= mNOutput;
25+
26+ GLfloat mps = M_PI / sides;
27+ GLfloat tmps = 2 * mps;
28+ GLfloat distance = 0.5f / tanf (mps);
29+ GLfloat radius = 0.5f / sinf (mps);
30+ GLfloat normInvert = 0.5f * invert;
31+ int i, n = (sides + 2) * 2;
32 GLfloat *v;
33- int i;
34-
35- sides *= mNOutput;
36-
37- GLfloat distance = 0.5f / tanf (M_PI / sides);
38- GLfloat radius = 0.5f / sinf (M_PI / sides);
39-
40- int n = (sides + 2) * 2;
41
42 if (mNVertices != n)
43 {
44 v = (GLfloat *) realloc (mVertices, sizeof (GLfloat) * n * 3);
45+
46 if (!v)
47 return false;
48
49@@ -261,14 +269,14 @@
50 v = mVertices;
51
52 *v++ = 0.0f;
53- *v++ = 0.5 * invert;
54+ *v++ = normInvert;
55 *v++ = 0.0f;
56
57 for (i = 0; i <= sides; ++i)
58 {
59- *v++ = radius * sinf (i * 2 * M_PI / sides + M_PI / sides);
60- *v++ = 0.5 * invert;
61- *v++ = radius * cosf (i * 2 * M_PI / sides + M_PI / sides);
62+ *v++ = radius * sinf (i * tmps + mps);
63+ *v++ = normInvert;
64+ *v++ = radius * cosf (i * tmps + mps);
65 }
66
67 *v++ = 0.0f;
68@@ -277,9 +285,9 @@
69
70 for (i = sides; i >= 0; --i)
71 {
72- *v++ = radius * sinf (i * 2 * M_PI / sides + M_PI / sides);
73- *v++ = -0.5 * invert;
74- *v++ = radius * cosf (i * 2 * M_PI / sides + M_PI / sides);
75+ *v++ = radius * sinf (i * tmps + mps);
76+ *v++ = -normInvert;
77+ *v++ = radius * cosf (i * tmps + mps);
78 }
79
80 mInvert = invert;
81@@ -381,12 +389,10 @@
82
83 mNOutput = j;
84
85- if (mNOutput == 1)
86- {
87- if (screen->outputDevs ()[0].width () != screen->width () ||
88- screen->outputDevs ()[0].height () != screen->height ())
89- mFullscreenOutput = true;
90- }
91+ if (mNOutput == 1 &&
92+ (screen->outputDevs ()[0].width () != screen->width () ||
93+ screen->outputDevs ()[0].height () != screen->height ()))
94+ mFullscreenOutput = true;
95 }
96
97 void
98@@ -407,13 +413,13 @@
99 (std::numeric_limits <unsigned short>::max ());
100 GLfloat aaafTextureData[128][128][3];
101
102- GLfloat fRStart = optionGetSkydomeGradientStartColorRed () / MaxUShortFloat;
103+ GLfloat fRStart = optionGetSkydomeGradientStartColorRed () / MaxUShortFloat;
104 GLfloat fGStart = optionGetSkydomeGradientStartColorGreen () / MaxUShortFloat;
105- GLfloat fBStart = optionGetSkydomeGradientStartColorBlue () / MaxUShortFloat;
106+ GLfloat fBStart = optionGetSkydomeGradientStartColorBlue () / MaxUShortFloat;
107
108- GLfloat fREnd = optionGetSkydomeGradientEndColorRed () / MaxUShortFloat;
109+ GLfloat fREnd = optionGetSkydomeGradientEndColorRed () / MaxUShortFloat;
110 GLfloat fGEnd = optionGetSkydomeGradientEndColorGreen () / MaxUShortFloat;
111- GLfloat fBEnd = optionGetSkydomeGradientEndColorBlue () / MaxUShortFloat;
112+ GLfloat fBEnd = optionGetSkydomeGradientEndColorBlue () / MaxUShortFloat;
113
114 GLfloat fRStep = (fREnd - fRStart) / 128.0f;
115 GLfloat fGStep = (fGEnd - fGStart) / 128.0f;
116@@ -522,10 +528,11 @@
117 GLfloat fStepX = 1.0 / (GLfloat) (iSlicesEnd - iSlicesStart);
118 GLfloat fStepY = 1.0 / (GLfloat) (iStacksEnd - iStacksStart);
119
120- if (!mSky.size ())
121- return;
122+ GLfloat oneMinusFStepX = 1.0f - fStepX;
123+ GLfloat oneMinusFStepY = 1.0f - fStepY;
124
125- if (!fillCircleTable (&sint1, &cost1, -iSlices))
126+ if (!mSky.size () ||
127+ !fillCircleTable (&sint1, &cost1, -iSlices))
128 return;
129
130 if (!fillCircleTable (&sint2, &cost2, iStacks * 2))
131@@ -536,10 +543,10 @@
132 }
133
134 afTexCoordX[0] = 1.0f;
135- afTexCoordY[0] = 1.0f - fStepY;
136- afTexCoordX[1] = 1.0f - fStepX;
137- afTexCoordY[1] = 1.0f - fStepY;
138- afTexCoordX[2] = 1.0f - fStepX;
139+ afTexCoordY[0] = oneMinusFStepY;
140+ afTexCoordX[1] = oneMinusFStepX;
141+ afTexCoordY[1] = oneMinusFStepY;
142+ afTexCoordX[2] = oneMinusFStepX;
143 afTexCoordY[2] = 1.0f;
144 afTexCoordX[3] = 1.0f;
145 afTexCoordY[3] = 1.0f;
146@@ -551,13 +558,16 @@
147
148 mSky[0]->enable (GLTexture::Good);
149
150+ GLfloat mSkyWidth = mSkySize.width ();
151+ GLfloat mSkyHeight = mSkySize.height ();
152+
153 glBegin (GL_QUADS);
154
155 for (int i = iStacksStart; i < iStacksEnd; ++i)
156 {
157 afTexCoordX[0] = 1.0f;
158- afTexCoordX[1] = 1.0f - fStepX;
159- afTexCoordX[2] = 1.0f - fStepX;
160+ afTexCoordX[1] = oneMinusFStepX;
161+ afTexCoordX[2] = oneMinusFStepX;
162 afTexCoordX[3] = 1.0f;
163
164 for (int j = iSlicesStart; j < iSlicesEnd; ++j)
165@@ -569,8 +579,8 @@
166 y = sint1[j];
167
168 glTexCoord2f (
169- COMP_TEX_COORD_X (mSky[0]->matrix (), afTexCoordX[3] * mSkySize.width ()),
170- COMP_TEX_COORD_Y (mSky[0]->matrix (), afTexCoordY[3] * mSkySize.height ()));
171+ COMP_TEX_COORD_X (mSky[0]->matrix (), afTexCoordX[3] * mSkyWidth),
172+ COMP_TEX_COORD_Y (mSky[0]->matrix (), afTexCoordY[3] * mSkyHeight));
173 glVertex3f (x * r * fRadius, y * r * fRadius, z * fRadius);
174
175 /* top-right */
176@@ -580,8 +590,8 @@
177 y = sint1[j];
178
179 glTexCoord2f (
180- COMP_TEX_COORD_X (mSky[0]->matrix (), afTexCoordX[0] * mSkySize.width ()),
181- COMP_TEX_COORD_Y (mSky[0]->matrix (), afTexCoordY[0] * mSkySize.height ()));
182+ COMP_TEX_COORD_X (mSky[0]->matrix (), afTexCoordX[0] * mSkyWidth),
183+ COMP_TEX_COORD_Y (mSky[0]->matrix (), afTexCoordY[0] * mSkyHeight));
184 glVertex3f (x * r * fRadius, y * r * fRadius, z * fRadius);
185
186 /* top-left */
187@@ -591,8 +601,8 @@
188 y = sint1[j + 1];
189
190 glTexCoord2f (
191- COMP_TEX_COORD_X (mSky[0]->matrix (), afTexCoordX[1] * mSkySize.width ()),
192- COMP_TEX_COORD_Y (mSky[0]->matrix (), afTexCoordY[1] * mSkySize.height ()));
193+ COMP_TEX_COORD_X (mSky[0]->matrix (), afTexCoordX[1] * mSkyWidth),
194+ COMP_TEX_COORD_Y (mSky[0]->matrix (), afTexCoordY[1] * mSkyHeight));
195 glVertex3f (x * r * fRadius, y * r * fRadius, z * fRadius);
196
197 /* bottom-left */
198@@ -602,8 +612,8 @@
199 y = sint1[j + 1];
200
201 glTexCoord2f (
202- COMP_TEX_COORD_X (mSky[0]->matrix (), afTexCoordX[2] * mSkySize.width ()),
203- COMP_TEX_COORD_Y (mSky[0]->matrix (), afTexCoordY[2] * mSkySize.height ()));
204+ COMP_TEX_COORD_X (mSky[0]->matrix (), afTexCoordX[2] * mSkyWidth),
205+ COMP_TEX_COORD_Y (mSky[0]->matrix (), afTexCoordY[2] * mSkyHeight));
206 glVertex3f (x * r * fRadius, y * r * fRadius, z * fRadius);
207
208 afTexCoordX[0] -= fStepX;
209@@ -628,7 +638,6 @@
210 free (cost1);
211 free (sint2);
212 free (cost2);
213-
214 #endif
215 }
216
217@@ -640,7 +649,7 @@
218 bool rv = CubeOptions::setOption (name, value);
219
220 if (!rv || !CompOption::findOption (getOptions (), name, &index))
221- return false;
222+ return false;
223
224 switch (index)
225 {
226@@ -697,8 +706,8 @@
227 void
228 PrivateCubeScreen::preparePaint (int msSinceLastPaint)
229 {
230- int opt;
231- float x, progress;
232+ int opt;
233+ float x, progress;
234 unsigned short *topColor, *bottomColor;
235
236 if (mGrabIndex)
237@@ -730,6 +739,7 @@
238
239 mUnfold = 0.0f;
240 }
241+
242 break;
243 }
244 }
245@@ -755,20 +765,19 @@
246 if (mDesktopOpacity != mToOpacity ||
247 (progress > 0.0 && progress < 1.0))
248 {
249- mDesktopOpacity =
250- (optionGetInactiveOpacity () -
251- ((optionGetInactiveOpacity () -
252- mOptions[mLastOpacityIndex].value ().f ()) * progress))
253- / 100.0f * OPAQUE;
254+ float inactiveOpacity = optionGetInactiveOpacity ();
255
256+ mDesktopOpacity = (inactiveOpacity -
257+ ((inactiveOpacity - mOptions[mLastOpacityIndex].value ().f ()) *
258+ progress)) / 100.0f * OPAQUE;
259 }
260
261 topColor = optionGetTopColor ();
262 bottomColor = optionGetBottomColor ();
263
264 mPaintAllViewports = (mDesktopOpacity != OPAQUE ||
265- topColor[3] != OPAQUE ||
266- bottomColor[3] != OPAQUE);
267+ topColor[3] != OPAQUE ||
268+ bottomColor[3] != OPAQUE);
269
270 cScreen->preparePaint (msSinceLastPaint);
271 }
272@@ -838,7 +847,7 @@
273 sTransform.translate (priv->mOutputXOffset, -priv->mOutputYOffset, 0.0f);
274 sTransform.scale (priv->mOutputXScale, priv->mOutputYScale, 1.0f);
275
276- GLMatrix mvp = pm * sTransform;
277+ GLMatrix mvp = pm * sTransform;
278
279 GLVector pntA = mvp * points[0];
280
281@@ -876,11 +885,11 @@
282 {
283 WRAPABLE_HND_FUNCTN_RETURN (bool, cubeShouldPaintViewport, sAttrib, transform, output, order)
284
285- float pointZ = priv->mInvert * priv->mDistance;
286+ float pointZ = priv->mInvert * priv->mDistance;
287 std::vector<GLVector> vPoints;
288 vPoints.push_back (GLVector (-0.5, 0.0, pointZ, 1.0));
289- vPoints.push_back (GLVector (0.0, 0.5, pointZ, 1.0));
290- vPoints.push_back (GLVector (0.0, 0.0, pointZ, 1.0));
291+ vPoints.push_back (GLVector (0.0, 0.5, pointZ, 1.0));
292+ vPoints.push_back (GLVector ( 0.0, 0.0, pointZ, 1.0));
293
294 bool ftb = cubeCheckOrientation (sAttrib, transform, output, vPoints);
295
296@@ -895,8 +904,7 @@
297 PaintOrder paintOrder,
298 int dx)
299 {
300- if (!cubeScreen->cubeShouldPaintViewport (sAttrib, transform, outputPtr,
301- paintOrder))
302+ if (!cubeScreen->cubeShouldPaintViewport (sAttrib, transform, outputPtr, paintOrder))
303 return;
304
305 int output = ((unsigned int) outputPtr->id () != (unsigned int) ~0) ?
306@@ -910,12 +918,12 @@
307 int cubeOutput = mOutputMask[output];
308
309 /* convert from window movement to viewport movement */
310- int dView = -dx;
311-
312- cubeOutput += dView;
313-
314- dView = cubeOutput / mNOutput;
315- cubeOutput = cubeOutput % mNOutput;
316+ int dView = -dx;
317+
318+ cubeOutput += dView;
319+
320+ dView = cubeOutput / mNOutput;
321+ cubeOutput = cubeOutput % mNOutput;
322
323 if (cubeOutput < 0)
324 {
325@@ -966,6 +974,7 @@
326 int origXMoveAdd = 0; // dx for the viewport we start painting with (back-most).
327 int iFirstSign; /* 1 if we do xMove += i first and
328 -1 if we do xMove -= i first. */
329+ float halfHsize = hsize / 2.0;
330
331 if (mInvert == 1)
332 {
333@@ -977,12 +986,12 @@
334 if ((sa.xRotate < 0.0f && hsize % 2 == 1) ||
335 (sa.xRotate > 0.0f && hsize % 2 == 0))
336 {
337- origXMoveAdd = hsize / 2;
338- iFirstSign = 1;
339+ origXMoveAdd = halfHsize;
340+ iFirstSign = 1;
341 }
342 else
343 {
344- origXMoveAdd = -hsize / 2;
345+ origXMoveAdd = -halfHsize;
346 iFirstSign = -1;
347 }
348 }
349@@ -992,15 +1001,16 @@
350 if (sa.xRotate > 0.0f)
351 iFirstSign = -1;
352 else
353- iFirstSign = 1;
354+ iFirstSign = 1;
355 }
356
357- int xMoveAdd;
358+ int xMoveAdd;
359+ float tsSize = 360.0f / size;
360
361- for (int i = 0; i <= hsize / 2; ++i)
362+ for (int i = 0; i <= halfHsize; ++i)
363 {
364 /* move to the correct viewport (back to front). */
365- xMoveAdd = origXMoveAdd; /* move to farthest viewport. */
366+ xMoveAdd = origXMoveAdd; /* move to farthest viewport. */
367 xMoveAdd += iFirstSign * i; /* move i more viewports to
368 the right / left. */
369
370@@ -1008,18 +1018,17 @@
371 We paint the viewports around xMove viewport.
372 Adding or subtracting hsize from xMove has no effect on
373 what viewport we paint, but can make shorter paths. */
374- if (xMoveAdd < -hsize / 2)
375+ if (xMoveAdd < -halfHsize)
376 xMoveAdd += hsize;
377- else if (xMoveAdd > hsize / 2)
378+ else if (xMoveAdd > halfHsize)
379 xMoveAdd -= hsize;
380
381 /* Paint the viewport. */
382 xMove += xMoveAdd;
383
384- sa.yRotate -= mInvert * xMoveAdd * 360.0f / size;
385- moveViewportAndPaint (sa, transform, outputPtr, mask,
386- paintOrder, xMove);
387- sa.yRotate += mInvert * xMoveAdd * 360.0f / size;
388+ sa.yRotate -= mInvert * xMoveAdd * tsSize;
389+ moveViewportAndPaint (sa, transform, outputPtr, mask, paintOrder, xMove);
390+ sa.yRotate += mInvert * xMoveAdd * tsSize;
391
392 xMove -= xMoveAdd;
393
394@@ -1027,22 +1036,22 @@
395 if (i == 0 || i * 2 == hsize)
396 continue;
397
398- xMoveAdd = origXMoveAdd; /* move to farthest viewport. */
399+ xMoveAdd = origXMoveAdd; /* move to farthest viewport. */
400 xMoveAdd -= iFirstSign * i; /* move i more viewports to the
401 left / right (opposite side
402 from the one chosen first) */
403
404- if (xMoveAdd < -hsize / 2)
405+ if (xMoveAdd < -halfHsize)
406 xMoveAdd += hsize;
407- else if (xMoveAdd > hsize / 2)
408+ else if (xMoveAdd > halfHsize)
409 xMoveAdd -= hsize;
410
411 xMove += xMoveAdd;
412
413- sa.yRotate -= mInvert * xMoveAdd * 360.0f / size;
414+ sa.yRotate -= mInvert * xMoveAdd * tsSize;
415 moveViewportAndPaint (sa, transform, outputPtr, mask,
416 paintOrder, xMove);
417- sa.yRotate += mInvert * xMoveAdd * 360.0f / size;
418+ sa.yRotate += mInvert * xMoveAdd * tsSize;
419
420 xMove -= xMoveAdd;
421 }
422@@ -1066,7 +1075,7 @@
423 {
424 WRAPABLE_HND_FUNCTN (cubeClearTargetOutput, xRotate, vRotate)
425
426- if (priv->mSky.size () > 0)
427+ if (!priv->mSky.empty ())
428 {
429 priv->gScreen->setLighting (false);
430 #ifndef USE_GLES
431@@ -1098,15 +1107,16 @@
432 {
433 WRAPABLE_HND_FUNCTN (cubePaintTop, sAttrib, transform, output, size, normal)
434
435- GLScreenPaintAttrib sa = sAttrib;
436- GLMatrix sTransform = transform;
437+ GLScreenPaintAttrib sa = sAttrib;
438+ GLMatrix sTransform = transform;
439+ GLboolean glBlendEnabled = glIsEnabled (GL_BLEND);
440
441 priv->gScreen->setLighting (true);
442
443- unsigned short *color = priv->optionGetTopColor ();
444- int opacity = priv->mDesktopOpacity * color[3] / 0xffff;
445+ unsigned short *color = priv->optionGetTopColor ();
446+ int opacity = priv->mDesktopOpacity * color[3] / 0xffff;
447
448- GLVertexBuffer *streamingBuffer = GLVertexBuffer::streamingBuffer ();
449+ GLVertexBuffer *streamingBuffer = GLVertexBuffer::streamingBuffer ();
450 std::vector <GLushort> colorData;
451
452 colorData.push_back (color[0] * opacity / 0xffff);
453@@ -1126,7 +1136,10 @@
454 #ifndef USE_GLES
455 priv->gScreen->setTexEnvMode (GL_MODULATE);
456 #endif
457- glEnable (GL_BLEND);
458+ // just enable blending if it is disabled
459+ if (!glBlendEnabled)
460+ glEnable (GL_BLEND);
461+
462 glBlendFunc (GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
463 }
464
465@@ -1150,7 +1163,11 @@
466 priv->mTexture[0]->disable ();
467
468 priv->gScreen->setTexEnvMode (GL_REPLACE);
469- glDisable (GL_BLEND);
470+
471+ // just disable blending if it was disabled before
472+ if (!glBlendEnabled)
473+ glDisable (GL_BLEND);
474+
475 glBlendFunc (GL_ONE, GL_ONE_MINUS_SRC_ALPHA);
476 }
477
478@@ -1163,8 +1180,9 @@
479 {
480 WRAPABLE_HND_FUNCTN (cubePaintBottom, sAttrib, transform, output, size, normal)
481
482- GLScreenPaintAttrib sa = sAttrib;
483- GLMatrix sTransform = transform;
484+ GLScreenPaintAttrib sa = sAttrib;
485+ GLMatrix sTransform = transform;
486+ GLboolean glBlendEnabled = glIsEnabled (GL_BLEND);
487
488 priv->gScreen->setLighting (true);
489
490@@ -1191,7 +1209,10 @@
491 #ifndef USE_GLES
492 priv->gScreen->setTexEnvMode (GL_MODULATE);
493 #endif
494- glEnable (GL_BLEND);
495+ // just enable blending if it is disabled
496+ if (!glBlendEnabled)
497+ glEnable (GL_BLEND);
498+
499 glBlendFunc (GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
500 }
501
502@@ -1206,7 +1227,11 @@
503 streamingBuffer->render (sTransform);
504
505 priv->gScreen->setTexEnvMode (GL_REPLACE);
506- glDisable (GL_BLEND);
507+
508+ // just disable blending if it was disabled before
509+ if (!glBlendEnabled)
510+ glDisable (GL_BLEND);
511+
512 glBlendFunc (GL_ONE, GL_ONE_MINUS_SRC_ALPHA);
513 }
514
515@@ -1234,12 +1259,14 @@
516 glTranslatef (mOutputXOffset, -mOutputYOffset, 0.0f);
517 glScalef (mOutputXScale, mOutputYScale, 1.0f);
518
519+ GLdouble mDist2 = 0.5 / mDistance;
520+
521 if (mInvert == 1)
522 {
523- GLdouble clipPlane0[] = { 1.0, 0.0, 0.5 / mDistance, 0.0 };
524- GLdouble clipPlane1[] = { -1.0, 0.0, 0.5 / mDistance, 0.0 };
525- GLdouble clipPlane2[] = { 0.0, -1.0, 0.5 / mDistance, 0.0 };
526- GLdouble clipPlane3[] = { 0.0, 1.0, 0.5 / mDistance, 0.0 };
527+ GLdouble clipPlane0[] = { 1.0, 0.0, mDist2, 0.0 };
528+ GLdouble clipPlane1[] = { -1.0, 0.0, mDist2, 0.0 };
529+ GLdouble clipPlane2[] = { 0.0, -1.0, mDist2, 0.0 };
530+ GLdouble clipPlane3[] = { 0.0, 1.0, mDist2, 0.0 };
531 glClipPlane (GL_CLIP_PLANE0, clipPlane0);
532 glClipPlane (GL_CLIP_PLANE1, clipPlane1);
533 glClipPlane (GL_CLIP_PLANE2, clipPlane2);
534@@ -1247,10 +1274,10 @@
535 }
536 else
537 {
538- GLdouble clipPlane0[] = { -1.0, 0.0, -0.5 / mDistance, 0.0 };
539- GLdouble clipPlane1[] = { 1.0, 0.0, -0.5 / mDistance, 0.0 };
540- GLdouble clipPlane2[] = { 0.0, 1.0, -0.5 / mDistance, 0.0 };
541- GLdouble clipPlane3[] = { 0.0, -1.0, -0.5 / mDistance, 0.0 };
542+ GLdouble clipPlane0[] = { -1.0, 0.0, -mDist2, 0.0 };
543+ GLdouble clipPlane1[] = { 1.0, 0.0, -mDist2, 0.0 };
544+ GLdouble clipPlane2[] = { 0.0, 1.0, -mDist2, 0.0 };
545+ GLdouble clipPlane3[] = { 0.0, -1.0, -mDist2, 0.0 };
546 glClipPlane (GL_CLIP_PLANE0, clipPlane0);
547 glClipPlane (GL_CLIP_PLANE1, clipPlane1);
548 glClipPlane (GL_CLIP_PLANE2, clipPlane2);
549@@ -1304,7 +1331,7 @@
550 updateGeometry (screen->vpSize ().width (), mInvert);
551 }
552
553- int cullNorm;
554+ int cullNorm;
555 glGetIntegerv (GL_CULL_FACE_MODE, &cullNorm);
556
557 int cullInv = (cullNorm == GL_BACK)? GL_FRONT : GL_BACK;
558@@ -1312,17 +1339,17 @@
559
560 if (!mFullscreenOutput)
561 {
562- mOutputXScale = (float) screen->width () / outputPtr->width ();
563- mOutputYScale = (float) screen->height () / outputPtr->height ();
564+ float outputWidth = outputPtr->width ();
565+ float outputHeight = outputPtr->height ();
566+
567+ mOutputXScale = (float) screen->width () / outputWidth;
568+ mOutputYScale = (float) screen->height () / outputHeight;
569
570 mOutputXOffset = (screen->width () / 2.0f -
571- (outputPtr->x1 () + outputPtr->x2 ()) / 2.0f) /
572- (float) outputPtr->width ();
573+ (outputPtr->x1 () + outputPtr->x2 ()) / 2.0f) / outputWidth;
574
575 mOutputYOffset = (screen->height () / 2.0f -
576- (outputPtr->y1 () +
577- outputPtr->y2 ()) / 2.0f) /
578- (float) outputPtr->height ();
579+ (outputPtr->y1 () + outputPtr->y2 ()) / 2.0f) / outputHeight;
580 }
581 else
582 {
583@@ -1341,7 +1368,7 @@
584
585 if (!mCleared[output])
586 {
587- float rRotate = xRotate - ((screen->vp ().x () *360.0f) /
588+ float rRotate = xRotate - ((screen->vp ().x () * 360.0f) /
589 screen->vpSize ().width ());
590
591 cubeScreen->cubeClearTargetOutput (rRotate, vRotate);
592@@ -1363,8 +1390,8 @@
593
594 sa.zTranslate = -mInvert * (0.5f / tanf (M_PI / size));
595
596- /* distance we move the camera back when unfolding the cube.
597- currently hardcoded to 1.5 but it should probably be optional. */
598+ /* Distance we move the camera back when unfolding the cube.
599+ TODO: Currently hardcoded to 1.5, make this configurable via CCSM. */
600 sa.zCamera -= mUnfold * 1.5f;
601 }
602 else
603@@ -1389,6 +1416,8 @@
604
605 sa.xRotate = sa.xRotate / size * hsize;
606
607+ GLenum oldFilter = gScreen->textureFilter ();
608+
609 if (mGrabIndex && optionGetMipmap ())
610 gScreen->setTextureFilter (GL_LINEAR_MIPMAP_LINEAR);
611
612@@ -1400,8 +1429,7 @@
613 paintOrder = FTB;
614 glCullFace (cullInv);
615 }
616- else
617- /* Inside cube - start with BTF faces */
618+ else /* Inside cube - start with BTF faces */
619 paintOrder = BTF;
620
621 if (mInvert == -1 || cubeScreen->cubeShouldPaintAllViewports ())
622@@ -1413,10 +1441,10 @@
623 if (wasCulled && cubeScreen->cubeShouldPaintAllViewports ())
624 glDisable (GL_CULL_FACE);
625
626- bool paintCaps = !mGrabIndex && (hsize > 2) && !mCapsPainted[output] &&
627+ bool paintCaps = !mGrabIndex && hsize > 2 && !mCapsPainted[output] &&
628 (mInvert != 1 || mDesktopOpacity != OPAQUE ||
629- cubeScreen->cubeShouldPaintAllViewports () || sa.vRotate != 0.0f ||
630- sa.yTranslate != 0.0f);
631+ cubeScreen->cubeShouldPaintAllViewports () || sa.vRotate != 0.0f ||
632+ sa.yTranslate != 0.0f);
633
634 if (paintCaps)
635 {
636@@ -1430,19 +1458,19 @@
637 bottom.push_back (GLVector (0.0, -0.5, -0.5, 1.0));
638 bottom.push_back (GLVector (0.0, -0.5, 0.0, 1.0));
639
640- Bool topDir = cubeScreen->cubeCheckOrientation (sa, transform, outputPtr, top);
641- Bool bottomDir = cubeScreen->cubeCheckOrientation (sa, transform, outputPtr, bottom);
642-
643- mCapsPainted[output] = TRUE;
644-
645- Bool allCaps = cubeScreen->cubeShouldPaintAllViewports () || mInvert != 1;
646+ bool topDir = cubeScreen->cubeCheckOrientation (sa, transform, outputPtr, top);
647+ bool bottomDir = cubeScreen->cubeCheckOrientation (sa, transform, outputPtr, bottom);
648+
649+ mCapsPainted[output] = true;
650+
651+ bool allCaps = cubeScreen->cubeShouldPaintAllViewports () || mInvert != 1;
652
653 if (topDir && bottomDir)
654 {
655 if (allCaps)
656 {
657- cubeScreen->cubePaintBottom (sa, transform, outputPtr, hsize, GLVector (0.0f, -1.0f, 0.0f, 1.0f));
658- cubeScreen->cubePaintInside (sa, transform, outputPtr, hsize, GLVector (0.0f, 0.0f, -1.0f, 1.0f));
659+ cubeScreen->cubePaintBottom (sa, transform, outputPtr, hsize, GLVector (0.0f, -1.0f, 0.0f, 1.0f));
660+ cubeScreen->cubePaintInside (sa, transform, outputPtr, hsize, GLVector (0.0f, 0.0f, -1.0f, 1.0f));
661 }
662
663 cubeScreen->cubePaintTop (sa, transform, outputPtr, hsize, GLVector (0.0f, -1.0f, 0.0f, 1.0f));
664@@ -1451,7 +1479,7 @@
665 {
666 if (allCaps)
667 {
668- cubeScreen->cubePaintTop (sa, transform, outputPtr, hsize, GLVector (0.0f, 1.0f, 0.0f, 1.0f));
669+ cubeScreen->cubePaintTop (sa, transform, outputPtr, hsize, GLVector (0.0f, 1.0f, 0.0f, 1.0f));
670 cubeScreen->cubePaintInside (sa, transform, outputPtr, hsize, GLVector (0.0f, 0.0f, -1.0f, 1.0f));
671 }
672
673@@ -1459,9 +1487,9 @@
674 }
675 else if (allCaps)
676 {
677- cubeScreen->cubePaintTop (sa, transform, outputPtr, hsize, GLVector (0.0f, 1.0f, 0.0f, 1.0f));
678- cubeScreen->cubePaintBottom (sa, transform, outputPtr, hsize, GLVector (0.0f, -1.0f, 0.0f, 1.0f));
679- cubeScreen->cubePaintInside (sa, transform, outputPtr, hsize, GLVector (0.0f, 0.0f, -1.0f, 1.0f));
680+ cubeScreen->cubePaintTop (sa, transform, outputPtr, hsize, GLVector (0.0f, 1.0f, 0.0f, 1.0f));
681+ cubeScreen->cubePaintBottom (sa, transform, outputPtr, hsize, GLVector (0.0f, -1.0f, 0.0f, 1.0f));
682+ cubeScreen->cubePaintInside (sa, transform, outputPtr, hsize, GLVector (0.0f, 0.0f, -1.0f, 1.0f));
683 }
684 }
685
686@@ -1484,14 +1512,13 @@
687
688 glCullFace (cullNorm);
689
690- GLenum filter = gScreen->textureFilter ();
691- gScreen->setTextureFilter (filter);
692+ gScreen->setTextureFilter (oldFilter);
693 }
694
695 bool
696 PrivateCubeWindow::glPaint (const GLWindowPaintAttrib &attrib,
697 const GLMatrix &transform,
698- const CompRegion &region,
699+ const CompRegion &region,
700 unsigned int mask)
701 {
702
703@@ -1499,8 +1526,7 @@
704 (attrib.opacity != cubeScreen->priv->mDesktopOpacity))
705 {
706 GLWindowPaintAttrib wAttrib = attrib;
707-
708- wAttrib.opacity = cubeScreen->priv->mDesktopOpacity;
709+ wAttrib.opacity = cubeScreen->priv->mDesktopOpacity;
710
711 return gWindow->glPaint (wAttrib, transform, region, mask);
712 }
713@@ -1616,50 +1642,47 @@
714 PrivateCubeScreen::PrivateCubeScreen (CompScreen *s) :
715 cScreen (CompositeScreen::get (s)),
716 gScreen (GLScreen::get (s)),
717- cubeScreen (CubeScreen::get (s))
718+ cubeScreen (CubeScreen::get (s)),
719+ mInvert (1),
720+ mXRotations (0),
721+ mPaintOrder (BTF),
722+ mRotationState (CubeScreen::RotationNone),
723+ mPaintAllViewports (false),
724+ mDistance (0.0f),
725+ mTc (),
726+ mGrabIndex (0),
727+ mSrcOutput (0),
728+ mUnfolded (false),
729+ mUnfold (0.0f),
730+ mUnfoldVelocity (0.0f),
731+ mVertices (NULL),
732+ mNVertices (0),
733+ mSkyListId (0),
734+ mPw (0),
735+ mPh (0),
736+ mSkySize (0, 0),
737+ mTexture (0),
738+ mSky (0),
739+ mImgCurFile (0),
740+ mNOutput (1),
741+ mOutput (),
742+ mOutputMask (),
743+ mCleared (),
744+ mCapsPainted (),
745+ mFullscreenOutput (true),
746+ mOutputXScale (1.0f),
747+ mOutputYScale (1.0f),
748+ mOutputXOffset (0.0f),
749+ mOutputYOffset (0.0f),
750+ mDesktopOpacity (OPAQUE),
751+ mToOpacity (OPAQUE),
752+ mLastOpacityIndex (CubeOptions::InactiveOpacity),
753+ mRecalcOutput (false),
754+ mReversedWindowList (0)
755 {
756- mPw = 0;
757- mPh = 0;
758-
759- mInvert = 1;
760-
761 for (int i = 0; i < 8; ++i)
762 mTc[i] = 0.0f;
763
764- mNVertices = 0;
765- mVertices = NULL;
766-
767- mGrabIndex = 0;
768-
769- mSrcOutput = 0;
770-
771- mSkyListId = 0;
772-
773- mImgCurFile = 0;
774-
775- mUnfolded = false;
776- mUnfold = 0.0f;
777-
778- mUnfoldVelocity = 0.0f;
779-
780- mPaintAllViewports = false;
781- mFullscreenOutput = true;
782-
783- mOutputXScale = 1.0f;
784- mOutputYScale = 1.0f;
785- mOutputXOffset = 0.0f;
786- mOutputYOffset = 0.0f;
787-
788- mRotationState = CubeScreen::RotationNone;
789-
790- mDesktopOpacity = OPAQUE;
791- mPaintOrder = BTF;
792-
793- mLastOpacityIndex = CubeOptions::InactiveOpacity;
794-
795-
796- mRecalcOutput = false;
797-
798 memset (mCleared, 0, sizeof (mCleared));
799
800 updateOutputs ();
801@@ -1685,7 +1708,6 @@
802 #endif
803 }
804
805-
806 template class PluginClassHandler<PrivateCubeWindow, CompWindow, COMPIZ_CUBE_ABI>;
807
808 PrivateCubeWindow::PrivateCubeWindow (CompWindow *w) :

Subscribers

People subscribed via source and target branches

to all changes: