LayerManagerCommands: log screen/layer/surface IDs in decimal and hex
[profile/ivi/layer-management.git] / LayerManagerCommands / src / ScreenSetRenderOrderCommand.cpp
1 /***************************************************************************
2  *
3  * Copyright 2010,2011 BMW Car IT GmbH
4  * Copyright (C) 2012 DENSO CORPORATION and Robert Bosch Car Multimedia Gmbh
5  *
6  *
7  * Licensed under the Apache License, Version 2.0 (the "License");
8  * you may not use this file except in compliance with the License.
9  * You may obtain a copy of the License at
10  *
11  *        http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing, software
14  * distributed under the License is distributed on an "AS IS" BASIS,
15  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16  * See the License for the specific language governing permissions and
17  * limitations under the License.
18  *
19  ****************************************************************************/
20 #include "ScreenSetRenderOrderCommand.h"
21 #include "ICommandExecutor.h"
22 #include "Scene.h"
23 #include "Log.h"
24
25 ScreenSetRenderOrderCommand::~ScreenSetRenderOrderCommand()
26 {
27     delete[] m_array;
28 }
29
30 ExecutionResult ScreenSetRenderOrderCommand::execute(ICommandExecutor* executor)
31 {
32     Scene& scene = *(executor->getScene());
33     ExecutionResult result = ExecutionFailed;
34
35     // check for doubles
36     for (unsigned int i = 0; i < m_length; i++)
37     {
38         for (unsigned int c = i + 1; c < m_length; c++)
39         {
40             if (m_array[i] == m_array[c])
41             {
42                 // doubles not allowed here
43                 return ExecutionFailed;
44             }
45         }
46     }
47
48     // taken out because other software currently expects partial execution of command,
49     // i.e. the layers that exist are added to the render order
50
51     //        // check that all layers to be added exist
52     //        for (unsigned int i=0;i<length;i++){
53     //            Layer* l = layerlist.getLayer(array[i]);
54     //            if (NULL==l)
55     //                return false;
56     //        } // TODO insert again later
57
58     if (scene.getCurrentRenderOrder(m_screenID).size() != 0)
59     {
60         IRenderer* renderer = *((executor->getRendererList())->begin());
61         renderer->forceCompositionWindowSystem();
62         result = ExecutionSuccessRedraw;
63     }
64
65     scene.getCurrentRenderOrder(m_screenID).clear();
66
67     LOG_DEBUG("ScreenSetRenderOrderCommand", "Length to set: " << m_length);
68
69     if (m_length == 0)
70     {
71         result = ExecutionSuccessRedraw;
72     }
73
74     for (unsigned int i = 0; i < m_length; i++)
75     {
76         LOG_DEBUG("ScreenSetRenderOrderCommand", "Trying to add layer: " << m_array[i] << " to current render order");
77         Layer* layer = scene.getLayer(m_array[i]);
78         if (layer)
79         {
80             LOG_DEBUG("ScreenSetRenderOrderCommand", "Adding Layer: " << m_array[i] << " to current render order");
81             scene.getCurrentRenderOrder(m_screenID).push_back(layer);
82             result = ExecutionSuccessRedraw;
83         }
84     }
85
86     return result;
87 }
88
89 const std::string ScreenSetRenderOrderCommand::getString()
90 {
91     std::stringstream description;
92     description << "ScreenSetRenderOrderCommand("
93                 << "m_screenID=" << m_screenID << "(0x" << std::hex << m_screenID << ")" << std::dec
94                 << ", m_array=[";
95
96     for (unsigned int i = 0; i < m_length; ++i)
97     {
98         description << m_array[i] << ",";
99     }
100     description << "], m_length=" << m_length
101                 << ")";
102     return description.str();
103 }