LayerManagerCommands: log screen/layer/surface IDs in decimal and hex
[profile/ivi/layer-management.git] / LayerManagerCommands / src / SurfaceSetChromaKeyCommand.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 "SurfaceSetChromaKeyCommand.h"
21 #include "ICommandExecutor.h"
22 #include "Scene.h"
23 #include "Log.h"
24
25 SurfaceSetChromaKeyCommand::~SurfaceSetChromaKeyCommand()
26 {
27     delete[] m_array;
28 }
29
30 ExecutionResult SurfaceSetChromaKeyCommand::execute(ICommandExecutor* executor)
31 {
32     Scene& scene = *(executor->getScene());
33
34     ExecutionResult result = ExecutionFailed;
35
36     Surface* surface = scene.getSurface(m_surfaceid);
37
38     if (NULL == m_array)
39     {
40         if (surface)
41         {
42             LOG_DEBUG("SurfaceSetChromaKeyCommand","new chromakey disable for id: " << m_surfaceid);
43             result = surface->setChromaKeyEnabled(false) ? ExecutionSuccessRedraw : ExecutionSuccess;
44         }
45     }
46     else
47     {
48         if (surface)
49         {
50             LOG_DEBUG("SurfaceSetChromaKeyCommand","new chromakey (" << m_array[0] << ", " << m_array[1] << ", " << m_array[2] << ") for id: " << m_surfaceid);
51             bool ansSetEnabled = surface->setChromaKeyEnabled(true);
52             bool ansSetValues = surface->setChromaKey((unsigned char)m_array[0], (unsigned char)m_array[1], (unsigned char)m_array[2]);
53             if ((true == ansSetEnabled) | (true == ansSetValues))
54             {
55                 result = ExecutionSuccessRedraw;
56             }
57             else
58             {
59                 result = ExecutionSuccess;
60             }
61         }
62     }
63
64     return result;
65 }
66
67 const std::string SurfaceSetChromaKeyCommand::getString()
68 {
69     std::stringstream description;
70     description << "SurfaceSetChromaKeyCommand("
71                 << "surfaceid=" << m_surfaceid << "(0x" << std::hex << m_surfaceid << ")" << std::dec
72                 << ", m_array=[";
73
74     for (unsigned int i = 0; i < m_length; ++i)
75     {
76         description << m_array[i] << ",";
77     }
78     description << "], m_length=" << m_length
79                 << ")";
80     return description.str();
81 }