~compiz-team/compiz/0.9.12

« back to all changes in this revision

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

MergeĀ GLESĀ support

Show diffs side-by-side

added added

removed removed

Lines of Context:
26
26
 * Particle system added by : (C) 2006 Dennis Kasprzyk
27
27
 * E-mail                   : onestone@beryl-project.org
28
28
 *
 
29
 * Ported to GLES by : Travis Watkins
 
30
 *                     (C) 2011 Linaro Limited
 
31
 * E-mail            : travis.watkins@linaro.org
 
32
 *
29
33
 * This program is free software; you can redistribute it and/or
30
34
 * modify it under the terms of the GNU General Public License
31
35
 * as published by the Free Software Foundation; either version 2
80
84
 *
81
85
 */
82
86
 
83
 
#include <GL/glu.h>
84
87
#include <core/atoms.h>
 
88
#include <core/core.h>
 
89
#include <opengl/opengl.h>
85
90
#include <sys/time.h>
86
91
#include <assert.h>
87
92
#include "private.h"
101
106
#define FAKE_ICON_SIZE 4
102
107
 
103
108
const char *eventNames[AnimEventNum] =
104
 
{"Open", "Close", "Minimize", "Shade", "Focus"};
 
109
{"Open", "Close", "Minimize", "Shade", "UnMinimize", "Focus"};
105
110
 
106
111
int chosenEffectOptionIds[AnimEventNum] =
107
112
{
109
114
    AnimationOptions::CloseEffects,
110
115
    AnimationOptions::MinimizeEffects,
111
116
    AnimationOptions::ShadeEffects,
112
 
    AnimationOptions::FocusEffects
 
117
    AnimationOptions::UnminimizeEffects,
 
118
    AnimationOptions::FocusEffects,
113
119
};
114
120
 
115
121
int randomEffectOptionIds[AnimEventNum] =
118
124
    AnimationOptions::CloseRandomEffects,
119
125
    AnimationOptions::MinimizeRandomEffects,
120
126
    AnimationOptions::ShadeRandomEffects,
 
127
    AnimationOptions::UnminimizeRandomEffects,
121
128
    -1
122
129
};
123
130
 
127
134
    AnimationOptions::CloseOptions,
128
135
    AnimationOptions::MinimizeOptions,
129
136
    AnimationOptions::ShadeOptions,
 
137
    AnimationOptions::UnminimizeOptions,
130
138
    AnimationOptions::FocusOptions
131
139
};
132
140
 
136
144
    AnimationOptions::CloseMatches,
137
145
    AnimationOptions::MinimizeMatches,
138
146
    AnimationOptions::ShadeMatches,
 
147
    AnimationOptions::UnminimizeMatches,
139
148
    AnimationOptions::FocusMatches
140
149
};
141
150
 
145
154
    AnimationOptions::CloseDurations,
146
155
    AnimationOptions::MinimizeDurations,
147
156
    AnimationOptions::ShadeDurations,
 
157
    AnimationOptions::UnminimizeDurations,
148
158
    AnimationOptions::FocusDurations
149
159
};
150
160
 
541
551
}
542
552
 
543
553
// Assumes events in the metadata are in
544
 
// [Open, Close, Minimize, Focus, Shade] order
 
554
// [Open, Close, Minimize, Shade, UnMinimize, Focus] order
545
555
// and effects among those are in alphabetical order
546
556
// but with "(Event) None" first and "(Event) Random" last.
547
557
AnimEffect
802
812
                       coordsTransformed[GLVector::y]);
803
813
}
804
814
 
 
815
static bool
 
816
project (float objx, float objy, float objz, 
 
817
         const float modelview[16], const float projection[16],
 
818
         const GLint viewport[4],
 
819
         float *winx, float *winy, float *winz)
 
820
{
 
821
    unsigned int i;
 
822
    float in[4];
 
823
    float out[4];
 
824
 
 
825
    in[0] = objx;
 
826
    in[1] = objy;
 
827
    in[2] = objz;
 
828
    in[3] = 1.0;
 
829
 
 
830
    for (i = 0; i < 4; i++) {
 
831
        out[i] = 
 
832
            in[0] * modelview[i] +
 
833
            in[1] * modelview[4  + i] +
 
834
            in[2] * modelview[8  + i] +
 
835
            in[3] * modelview[12 + i];
 
836
    }
 
837
 
 
838
    for (i = 0; i < 4; i++) {
 
839
        in[i] = 
 
840
            out[0] * projection[i] +
 
841
            out[1] * projection[4  + i] +
 
842
            out[2] * projection[8  + i] +
 
843
            out[3] * projection[12 + i];
 
844
    }
 
845
 
 
846
    if (in[3] == 0.0)
 
847
        return false;
 
848
 
 
849
    in[0] /= in[3];
 
850
    in[1] /= in[3];
 
851
    in[2] /= in[3];
 
852
    /* Map x, y and z to range 0-1 */
 
853
    in[0] = in[0] * 0.5 + 0.5;
 
854
    in[1] = in[1] * 0.5 + 0.5;
 
855
    in[2] = in[2] * 0.5 + 0.5;
 
856
 
 
857
    /* Map x,y to viewport */
 
858
    in[0] = in[0] * viewport[2] + viewport[0];
 
859
    in[1] = in[1] * viewport[3] + viewport[1];
 
860
 
 
861
    *winx = in[0];
 
862
    *winy = in[1];
 
863
    *winz = in[2];
 
864
    return true;
 
865
}
 
866
 
805
867
/// Either points or objects should be non-0.
806
868
bool
807
869
AnimWindow::expandBBWithPoints3DTransform (CompOutput     &output,
810
872
                                           GridAnim::GridModel::GridObject *objects,
811
873
                                           unsigned int   nPoints)
812
874
{
813
 
    GLdouble dModel[16];
814
 
    GLdouble dProjection[16];
815
 
    GLdouble x, y, z;
816
 
    for (unsigned int i = 0; i < 16; i++)
817
 
    {
818
 
        dModel[i] = transform[i];
819
 
        dProjection[i] = GLScreen::get (::screen)->projectionMatrix ()[i];
820
 
    }
 
875
    GLfloat x, y, z;
821
876
    GLint viewport[4] =
822
877
        {output.region ()->extents.x1,
823
878
         output.region ()->extents.y1,
824
879
         output.width (),
825
880
         output.height ()};
826
881
 
 
882
    const float *projection =
 
883
        GLScreen::get (::screen)->projectionMatrix ()->getMatrix ();
 
884
 
827
885
    if (points) // use points
828
886
    {
829
887
        for (; nPoints; nPoints--, points += 3)
830
888
        {
831
 
            if (!gluProject (points[0], points[1], points[2],
832
 
                             dModel, dProjection, viewport,
833
 
                             &x, &y, &z))
 
889
            if (!project (points[0], points[1], points[2],
 
890
                          transform.getMatrix (), projection,
 
891
                          viewport,
 
892
                          &x, &y, &z))
834
893
                return false;
835
894
 
836
895
            expandBBWithPoint (x + 0.5, (::screen->height () - y) + 0.5);
841
900
        GridAnim::GridModel::GridObject *object = objects;
842
901
        for (; nPoints; nPoints--, object++)
843
902
        {
844
 
            if (!gluProject (object->position ().x (),
845
 
                             object->position ().y (),
846
 
                             object->position ().z (),
847
 
                             dModel, dProjection, viewport,
848
 
                             &x, &y, &z))
 
903
            if (!project (object->position ().x (),
 
904
                          object->position ().y (),
 
905
                          object->position ().z (),
 
906
                          transform.getMatrix (), projection,
 
907
                          viewport,
 
908
                          &x, &y, &z))
849
909
                return false;
850
910
 
851
911
            expandBBWithPoint (x + 0.5, (::screen->height () - y) + 0.5);
901
961
void
902
962
PrivateAnimWindow::damageThisAndLastStepRegion ()
903
963
{
904
 
#ifdef COMPIZ_OPENGL_SWAPBUFFERS_ALWAYS   // when LP: #901097 is fixed
905
964
    // Find union of the regions for this step and last step
906
965
    CompRegion totalRegionToDamage (mStepRegion + mLastStepRegion);
907
966
 
908
967
    mPAScreen->cScreen->damageRegion (totalRegionToDamage);
909
 
#else
910
 
    // Ugly fix for LP: #930192 while LP: #901097 is not resolved
911
 
    mPAScreen->cScreen->damageScreen ();
912
 
#endif
913
968
}
914
969
 
915
970
CompOutput &
1430
1485
{
1431
1486
    gWindow->glPaintSetEnabled (this, enabling);
1432
1487
    gWindow->glAddGeometrySetEnabled (this, enabling);
1433
 
    gWindow->glDrawGeometrySetEnabled (this, enabling);
 
1488
    //gWindow->glDrawGeometrySetEnabled (this, enabling);
1434
1489
    gWindow->glDrawTextureSetEnabled (this, enabling);
1435
1490
}
1436
1491
 
1504
1559
 
1505
1560
void
1506
1561
PrivateAnimWindow::glDrawTexture (GLTexture          *texture,
1507
 
                                  GLFragment::Attrib &attrib,
 
1562
                                  const GLMatrix     &transform,
 
1563
                                  const GLWindowPaintAttrib &attrib,
1508
1564
                                  unsigned int       mask)
1509
1565
{
1510
1566
    if (mCurAnimation)
1512
1568
        mCurAnimation->setCurPaintAttrib (attrib);
1513
1569
    }
1514
1570
 
1515
 
    gWindow->glDrawTexture (texture, attrib, mask);
 
1571
    gWindow->glDrawTexture (texture, transform, attrib, mask);
1516
1572
}
1517
1573
 
 
1574
#if 0 // Not ported yet
1518
1575
void
1519
1576
PrivateAnimWindow::glDrawGeometry ()
1520
1577
{
1528
1585
        gWindow->glDrawGeometry ();
1529
1586
    }
1530
1587
}
 
1588
#endif
1531
1589
 
1532
1590
void
1533
1591
Animation::drawTexture (GLTexture          *texture,
1534
 
                        GLFragment::Attrib &attrib,
 
1592
                        const GLWindowPaintAttrib &attrib,
1535
1593
                        unsigned int       mask)
1536
1594
{
1537
1595
    mCurPaintAttrib = attrib;
1540
1598
void
1541
1599
Animation::drawGeometry ()
1542
1600
{
 
1601
#if 0 // Not ported yet
1543
1602
    mAWindow->priv->gWindow->glDrawGeometry ();
 
1603
#endif
1544
1604
}
1545
1605
 
1546
1606
bool
1609
1669
 
1610
1670
    if (mCurAnimation->postPaintWindowUsed ())
1611
1671
    {
 
1672
#if 0 // Not ported yet
1612
1673
        // Transform to make post-paint coincide with the window
1613
1674
        glPushMatrix ();
1614
1675
        glLoadMatrixf (wTransform.getMatrix ());
1615
 
 
 
1676
#endif
1616
1677
        mCurAnimation->postPaintWindow ();
1617
1678
 
 
1679
#if 0 // Not ported yet
1618
1680
        glPopMatrix ();
 
1681
#endif
1619
1682
    }
1620
1683
 
1621
1684
    return status;
2168
2231
 
2169
2232
    int duration = 200;
2170
2233
    AnimEffect chosenEffect =
2171
 
        getMatchingAnimSelection (w, AnimEventMinimize, &duration);
 
2234
        getMatchingAnimSelection (w, AnimEventUnMinimize, &duration);
2172
2235
 
2173
2236
    aw->mNewState = NormalState;
2174
2237
 
2202
2265
        if (startingNew)
2203
2266
        {
2204
2267
            AnimEffect effectToBePlayed =
2205
 
                getActualEffect (chosenEffect, AnimEventMinimize);
 
2268
                getActualEffect (chosenEffect, AnimEventUnMinimize);
2206
2269
 
2207
2270
            // handle empty random effect list
2208
2271
            if (effectToBePlayed == AnimEffectNone)
2444
2507
    return gScreen->glPaintOutput (attrib, matrix, region, output, mask);
2445
2508
}
2446
2509
 
 
2510
AnimEffectUsedFor AnimEffectUsedFor::all ()
 
2511
{
 
2512
  AnimEffectUsedFor usedFor;
 
2513
  usedFor.open = usedFor.close = usedFor.minimize = 
 
2514
  usedFor.shade = usedFor.unMinimize = usedFor.focus = true;
 
2515
  return usedFor;
 
2516
}
 
2517
 
 
2518
AnimEffectUsedFor AnimEffectUsedFor::none ()
 
2519
{
 
2520
  AnimEffectUsedFor usedFor;  
 
2521
  usedFor.open = usedFor.close = usedFor.minimize = 
 
2522
  usedFor.shade = usedFor.unMinimize = usedFor.focus = true;
 
2523
  return usedFor;
 
2524
}
 
2525
 
 
2526
AnimEffectUsedFor& AnimEffectUsedFor::exclude (AnimEvent event)
 
2527
{
 
2528
  switch (event) {
 
2529
    case AnimEventOpen: open = false; break;
 
2530
    case AnimEventClose: close = false; break;
 
2531
    case AnimEventMinimize: minimize = false; break;
 
2532
    case AnimEventShade: shade = false; break;
 
2533
    case AnimEventUnMinimize: unMinimize = false; break;
 
2534
    case AnimEventFocus: focus = false; break;
 
2535
    default: break;
 
2536
  }
 
2537
  return *this;
 
2538
}
 
2539
 
 
2540
AnimEffectUsedFor& AnimEffectUsedFor::include (AnimEvent event)
 
2541
{
 
2542
  switch (event) {
 
2543
    case AnimEventOpen: open = true; break;
 
2544
    case AnimEventClose: close = true; break;
 
2545
    case AnimEventMinimize: minimize = true; break;
 
2546
    case AnimEventShade: shade = true; break;
 
2547
    case AnimEventUnMinimize: unMinimize = true; break;
 
2548
    case AnimEventFocus: focus = true; break;
 
2549
    default: break;
 
2550
  }
 
2551
  return *this;
 
2552
}
 
2553
 
2447
2554
AnimEffectInfo::AnimEffectInfo (const char *name,
2448
 
                                bool usedO, bool usedC, bool usedM,
2449
 
                                bool usedS, bool usedF,
 
2555
                               AnimEffectUsedFor usedFor,
2450
2556
                                CreateAnimFunc create,
2451
2557
                                bool isRestackAnim) :
2452
2558
    name (name),
2453
2559
    create (create),
2454
2560
    isRestackAnim (isRestackAnim)
2455
2561
{
2456
 
    usedForEvents[AnimEventOpen] = usedO;
2457
 
    usedForEvents[AnimEventClose] = usedC;
2458
 
    usedForEvents[AnimEventMinimize] = usedM;
2459
 
    usedForEvents[AnimEventShade] = usedS;
2460
 
    usedForEvents[AnimEventFocus] = usedF;
 
2562
    usedForEvents[AnimEventOpen] = usedFor.open;
 
2563
    usedForEvents[AnimEventClose] = usedFor.close;
 
2564
    usedForEvents[AnimEventMinimize] = usedFor.minimize;
 
2565
    usedForEvents[AnimEventShade] = usedFor.shade;
 
2566
    usedForEvents[AnimEventUnMinimize] = usedFor.unMinimize;
 
2567
    usedForEvents[AnimEventFocus] = usedFor.focus;
2461
2568
}
2462
2569
 
2463
2570
bool
2577
2684
PrivateAnimScreen::initAnimationList ()
2578
2685
{
2579
2686
    int i = 0;
 
2687
 
2580
2688
    animEffects[i++] = AnimEffectNone =
2581
2689
        new AnimEffectInfo ("animation:None",
2582
 
                            true, true, true, true, true, 0);
 
2690
                            AnimEffectUsedFor::all(),
 
2691
                            0);
 
2692
 
2583
2693
    animEffects[i++] = AnimEffectRandom =
2584
2694
        new AnimEffectInfo ("animation:Random",
2585
 
                            true, true, true, true, false, 0);
 
2695
                           AnimEffectUsedFor::all().exclude(AnimEventFocus),
 
2696
                           0);
 
2697
 
2586
2698
    animEffects[i++] = AnimEffectCurvedFold =
2587
2699
        new AnimEffectInfo ("animation:Curved Fold",
2588
 
                            true, true, true, true, false,
 
2700
                           AnimEffectUsedFor::all().exclude(AnimEventFocus),
2589
2701
                            &createAnimation<CurvedFoldAnim>);
 
2702
        
2590
2703
    animEffects[i++] = AnimEffectDodge =
2591
 
        new AnimEffectInfo ("animation:Dodge",
2592
 
                            false, false, false, false, true,
 
2704
        new AnimEffectInfo ("animation:Dodge", 
 
2705
                           AnimEffectUsedFor::none().include(AnimEventFocus),
2593
2706
                            &createAnimation<DodgeAnim>,
2594
2707
                            true);
 
2708
        
2595
2709
    animEffects[i++] = AnimEffectDream =
2596
 
        new AnimEffectInfo ("animation:Dream",
2597
 
                            true, true, true, false, false,
 
2710
        new AnimEffectInfo ("animation:Dream", 
 
2711
                           AnimEffectUsedFor::all().exclude(AnimEventFocus).exclude(AnimEventShade),
2598
2712
                            &createAnimation<DreamAnim>);
 
2713
 
2599
2714
    animEffects[i++] = AnimEffectFade =
2600
2715
        new AnimEffectInfo ("animation:Fade",
2601
 
                            true, true, true, false, false,
 
2716
                           AnimEffectUsedFor::all().exclude(AnimEventFocus).exclude(AnimEventShade),
2602
2717
                            &createAnimation<FadeAnim>);
 
2718
        
2603
2719
    animEffects[i++] = AnimEffectFocusFade =
2604
 
        new AnimEffectInfo ("animation:Focus Fade",
2605
 
                            false, false, false, false, true,
 
2720
        new AnimEffectInfo ("animation:Focus Fade", 
 
2721
                           AnimEffectUsedFor::none().include(AnimEventFocus),
2606
2722
                            &createAnimation<FocusFadeAnim>,
2607
2723
                            true);
 
2724
        
2608
2725
    animEffects[i++] = AnimEffectGlide1 =
2609
2726
        new AnimEffectInfo ("animation:Glide 1",
2610
 
                            true, true, true, false, false,
 
2727
                           AnimEffectUsedFor::all().exclude(AnimEventFocus).exclude(AnimEventShade),
2611
2728
                            &createAnimation<GlideAnim>);
 
2729
        
2612
2730
    animEffects[i++] = AnimEffectGlide2 =
2613
2731
        new AnimEffectInfo ("animation:Glide 2",
2614
 
                            true, true, true, false, false,
 
2732
                           AnimEffectUsedFor::all().exclude(AnimEventFocus).exclude(AnimEventShade),
2615
2733
                            &createAnimation<Glide2Anim>);
 
2734
        
2616
2735
    animEffects[i++] = AnimEffectHorizontalFolds =
2617
2736
        new AnimEffectInfo ("animation:Horizontal Folds",
2618
 
                            true, true, true, true, false,
 
2737
                           AnimEffectUsedFor::all().exclude(AnimEventFocus),
2619
2738
                            &createAnimation<HorizontalFoldsAnim>);
 
2739
        
2620
2740
    animEffects[i++] = AnimEffectMagicLamp =
2621
2741
        new AnimEffectInfo ("animation:Magic Lamp",
2622
 
                            true, true, true, false, false,
 
2742
                           AnimEffectUsedFor::all().exclude(AnimEventFocus).exclude(AnimEventShade),
2623
2743
                            &createAnimation<MagicLampAnim>);
 
2744
        
2624
2745
    animEffects[i++] = AnimEffectMagicLampWavy =
2625
2746
        new AnimEffectInfo ("animation:Magic Lamp Wavy",
2626
 
                            true, true, true, false, false,
 
2747
                           AnimEffectUsedFor::all().exclude(AnimEventFocus).exclude(AnimEventShade),
2627
2748
                            &createAnimation<MagicLampWavyAnim>);
 
2749
        
2628
2750
    animEffects[i++] = AnimEffectRollUp =
2629
2751
        new AnimEffectInfo ("animation:Roll Up",
2630
 
                            false, false, false, true, false,
 
2752
                           AnimEffectUsedFor::none().include(AnimEventShade),
2631
2753
                            &createAnimation<RollUpAnim>);
 
2754
        
2632
2755
    animEffects[i++] = AnimEffectSidekick =
2633
2756
        new AnimEffectInfo ("animation:Sidekick",
2634
 
                            true, true, true, false, false,
 
2757
                           AnimEffectUsedFor::all().exclude(AnimEventFocus).exclude(AnimEventShade),
2635
2758
                            &createAnimation<SidekickAnim>);
 
2759
        
2636
2760
    animEffects[i++] = AnimEffectWave =
2637
2761
        new AnimEffectInfo ("animation:Wave",
2638
 
                            true, true, true, false, true,
 
2762
                           AnimEffectUsedFor::all().exclude(AnimEventShade),
2639
2763
                            &createAnimation<WaveAnim>);
 
2764
    
2640
2765
    animEffects[i++] = AnimEffectZoom =
2641
 
        new AnimEffectInfo ("animation:Zoom",
2642
 
                            true, true, true, false, false,
 
2766
        new AnimEffectInfo ("animation:Zoom", 
 
2767
                           AnimEffectUsedFor::all().exclude(AnimEventFocus).exclude(AnimEventShade),
2643
2768
                            &createAnimation<ZoomAnim>);
2644
2769
 
2645
2770
    animExtensionPluginInfo.effectOptions = &getOptions ();