summaryrefslogtreecommitdiff
path: root/LayerManagerPlugins/SceneProvider/ExampleSceneProvider/src/ExampleSceneProvider.cpp
blob: 9e02d03075a18e2f81f33db5d2772a42d69493a8 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
/***************************************************************************
 *
 * Copyright 2010,2011 BMW Car IT GmbH
 *
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *        http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 *
 ****************************************************************************/

#include "ExampleSceneProvider.h"
#include "ICommandExecutor.h"
#include "CommitCommand.h"
#include "LayerCreateCommand.h"
#include "LayerSetDestinationRectangleCommand.h"
#include "LayerSetSourceRectangleCommand.h"
#include "LayerSetVisibilityCommand.h"
#include "LayerSetOpacityCommand.h"
#include "ScreenSetRenderOrderCommand.h"
#include "ExampleAppIds.h"
#include "SurfaceCreateCommand.h"
#include "SurfaceSetVisibilityCommand.h"
#include "SurfaceSetOpacityCommand.h"
#include "Configuration.h"
#include <unistd.h>

ExampleSceneProvider::ExampleSceneProvider(ICommandExecutor& executor, Configuration& config)
: ISceneProvider(&executor)
, PluginBase(executor, config, SceneProvider_Api_v1)
, mExecutor(executor)
, mConfiguration(config)
{
}

typedef struct t_layerScene
{
    unsigned int layer;
    bool visibility;
    float opacity;
} layerScene;

typedef struct t_surfaceScene
{
    unsigned int surface;
    bool visibility;
    float opacity;
} surfaceScene;


static layerScene gInitialLayerScene[] =
{
    { LAYER_EXAMPLE_VIDEO_APPLICATIONS, true, 1.0 },
    { LAYER_EXAMPLE_GLES_APPLICATIONS, true, 1.0 },
    { LAYER_EXAMPLE_X_APPLICATIONS, true, 1.0 }
};

static surfaceScene gInitialSurfaceScene[] =
{
    { SURFACE_EXAMPLE_EGLX11_APPLICATION, false, 1.0 },
    { SURFACE_EXAMPLE_GDTESTENV_APPLICATION_1, false, 1.0 },
    { SURFACE_EXAMPLE_GDTESTENV_APPLICATION_2, false, 1.0 },
    { SURFACE_EXAMPLE_GDTESTENV_APPLICATION_3, false, 1.0 },
    { SURFACE_EXAMPLE_GDTESTENV_APPLICATION_4, false, 1.0 },
    { SURFACE_EXAMPLE_GDTESTENV_APPLICATION_5, false, 1.0 },
    { SURFACE_EXAMPLE_GDTESTENV_APPLICATION_6, false, 1.0 },
    { SURFACE_EXAMPLE_GDTESTENV_APPLICATION_7, false, 1.0 },
    { SURFACE_EXAMPLE_GDTESTENV_APPLICATION_8, false, 1.0 },
    { SURFACE_EXAMPLE_GDTESTENV_APPLICATION_9, false, 1.0 },
    { SURFACE_EXAMPLE_GLXX11_APPLICATION, false, 1.0 },
    { SURFACE_EXAMPLE_EGLRAW_APPLICATION, false, 1.0 },
    { SURFACE_EXAMPLE_VIDEO_APPLICATION, false, 1.0 }
};


bool ExampleSceneProvider::delegateScene()
{
    bool result = true;
    pid_t layermanagerPid = getpid();
    int i = 0;
    int numberOfLayers = sizeof(gInitialLayerScene) / sizeof(layerScene);
    int numberOfSurfaces = sizeof(gInitialSurfaceScene) / sizeof(surfaceScene);
    unsigned int *renderOrder = new unsigned int [numberOfLayers];
    unsigned int* screenResolution = mExecutor.getScreenResolution(0);
    if (numberOfLayers > 0)
    {
        /* setup inital layer scenery */
        for (i = 0; i<numberOfLayers; i++)
        {
            result &= mExecutor.execute(new LayerCreateCommand(layermanagerPid,
                                                               screenResolution[0],
                                                               screenResolution[1],
                                                               &(gInitialLayerScene[i].layer)));
            result &= mExecutor.execute(new LayerSetSourceRectangleCommand(layermanagerPid,
                                                                           gInitialLayerScene[i].layer,
                                                                           0, 0,
                                                                           screenResolution[0],
                                                                           screenResolution[1]));
            result &= mExecutor.execute(new LayerSetDestinationRectangleCommand(layermanagerPid,
                                                                                gInitialLayerScene[i].layer,
                                                                                0, 0,
                                                                                screenResolution[0],
                                                                                screenResolution[1]));
            result &= mExecutor.execute(new LayerSetOpacityCommand(layermanagerPid,
                                                                   gInitialLayerScene[i].layer,
                                                                   gInitialLayerScene[i].opacity));
            result &= mExecutor.execute(new LayerSetVisibilityCommand(layermanagerPid,
                                                                      gInitialLayerScene[i].layer,
                                                                      gInitialLayerScene[i].visibility));
            result &= mExecutor.execute(new CommitCommand(layermanagerPid));
            renderOrder[i]=gInitialLayerScene[i].layer;
        }
        /* Finally set the first executed renderorder */
        result &= mExecutor.execute(new ScreenSetRenderOrderCommand(layermanagerPid, 0, renderOrder, numberOfLayers));
        result &= mExecutor.execute(new CommitCommand(layermanagerPid));
    }

    if (numberOfSurfaces > 0)
    {
        /* setup inital surface scenery */
        for (i = 0; i<numberOfSurfaces; i++)
        {
            result &= mExecutor.execute(new SurfaceCreateCommand(layermanagerPid,
                                                                 &(gInitialSurfaceScene[i].surface)));
            result &= mExecutor.execute(new SurfaceSetOpacityCommand(layermanagerPid,
                                                                     gInitialSurfaceScene[i].surface,
                                                                     gInitialSurfaceScene[i].opacity));
            result &= mExecutor.execute(new SurfaceSetVisibilityCommand(layermanagerPid,
                                                                        gInitialSurfaceScene[i].surface,
                                                                        gInitialSurfaceScene[i].visibility));
            result &= mExecutor.execute(new CommitCommand(layermanagerPid));
        }
        /* Finally set the first executed renderorder */
    }
    return result;
}

t_ilm_const_string ExampleSceneProvider::pluginGetName() const
{
    return "ExampleSceneProvider";
}

int ExampleSceneProvider::getIterationCounter()
{
    // this plugin is one-shot and is not monitored.
    static int dummyValue = 0;
    return ++dummyValue;
}

DECLARE_LAYERMANAGEMENT_PLUGIN(ExampleSceneProvider)