Merge "DALi Version 1.2.52" into devel/master
[platform/core/uifw/dali-adaptor.git] / adaptors / wayland / compositor-output-region / compositor-output.cpp
1 /*
2  * Copyright (c) 2016 Samsung Electronics Co., Ltd.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  *
16  */
17
18 // CLASS HEADER
19 #include "compositor-output.h"
20
21 // EXTERNAL INCLUDES
22 #include <dali/integration-api/debug.h>
23
24
25 namespace Dali
26 {
27
28 namespace Internal
29 {
30
31 namespace Adaptor
32 {
33
34 namespace
35 {
36
37 #if defined(DEBUG_ENABLED)
38 Debug::Filter* gLogFilter = Debug::Filter::New(Debug::NoLogging, false, "LOG_MONITOR_INFO");
39 #endif
40
41 const float MILLIMETRE_TO_INCH = 1.f / 25.4f;
42
43 unsigned int gDpiHorizontal = 75;
44 unsigned int gDpiVertical = 75;
45
46
47 void OutputGeometryCallback( void *data,
48      struct wl_output *wl_output,
49      int32_t x,
50      int32_t y,
51      int32_t physical_width,
52      int32_t physical_height,
53      int32_t subpixel,
54      const char *make,
55      const char *model,
56      int32_t transform)
57 {
58   CompositorOutput* output = static_cast< CompositorOutput* >( data );
59   output->SetMonitorDimensions( physical_width, physical_height );
60
61   DALI_LOG_INFO( gLogFilter, Debug::General, "Monitor width: %d mm, height: %d mm\n",physical_width, physical_height  );
62 }
63
64 void OutputModeCallback( void *data,
65        struct wl_output *wl_output,
66        uint32_t flags,
67        int32_t width,
68        int32_t height,
69        int32_t refresh )
70 {
71
72   if (flags & WL_OUTPUT_MODE_CURRENT)
73   {
74     CompositorOutput* output = static_cast< CompositorOutput* >( data );
75     output->SetMonitorResolution( width, height );
76
77     DALI_LOG_INFO( gLogFilter, Debug::General, "Monitor refresh rate: %f Hz, resolution: %d x %d\n", static_cast<float>(refresh)/ 1000.f, width, height );
78   }
79 }
80
81 void  OutputCallbackDone(void *data,
82        struct wl_output *wl_output)
83 {
84   CompositorOutput* output = static_cast< CompositorOutput* >( data );
85   output->CallbacksDone();
86 }
87
88 void OutputCallbackScale(void *data,
89         struct wl_output *wl_output,
90         int32_t factor)
91 {
92   // Need to understand if we need to support output scaling and what impact it has on input handling etc.
93 }
94
95
96
97 //output typically corresponds to a monitor
98 const struct wl_output_listener OutputListener =
99 {
100    OutputGeometryCallback,
101    OutputModeCallback,
102    OutputCallbackDone,
103    OutputCallbackScale
104 };
105 }
106 CompositorOutput::CompositorOutput()
107 :mOutput( NULL ),
108  mXresolution( 0 ),
109  mYresolution( 0 ),
110  mMonitorWidth( 0.f ),
111  mMonitorHeight( 0.f ),
112  mDataReady( false )
113 {
114
115 }
116
117 CompositorOutput::~CompositorOutput()
118 {
119   if( mOutput )
120   {
121     wl_output_destroy( mOutput );
122   }
123 }
124
125 void CompositorOutput::AddListener( WlOutput* outputInterface )
126 {
127   mOutput = outputInterface;
128
129   wl_output_add_listener( mOutput , &OutputListener, this);
130 }
131
132 void CompositorOutput::GetDpi( unsigned int& dpiHorizontal, unsigned int& dpiVertical )
133 {
134   dpiHorizontal = gDpiHorizontal;
135   dpiVertical = gDpiVertical;
136 }
137
138 bool CompositorOutput::DataReady() const
139 {
140   return mDataReady;
141 }
142
143 void CompositorOutput::SetMonitorDimensions( unsigned int width, unsigned int height )
144 {
145   mMonitorHeight = static_cast<float> ( height ) * MILLIMETRE_TO_INCH;
146   mMonitorWidth = static_cast<float>( width ) * MILLIMETRE_TO_INCH;
147 }
148
149 void CompositorOutput::SetMonitorResolution( unsigned int width, unsigned int height )
150 {
151   mXresolution = width;
152   mYresolution = height;
153 }
154
155 void CompositorOutput::CallbacksDone()
156 {
157   mDataReady = true;
158
159   // formula for DPI is screen resolution / physical size in inches
160   gDpiHorizontal =  (static_cast<float>( mXresolution) / mMonitorWidth) + 0.5f;
161   gDpiVertical =  (static_cast<float>( mYresolution )/ mMonitorHeight) +0.5f;
162
163   DALI_LOG_INFO( gLogFilter, Debug::General, "Monitor DPI %d x %d\n", gDpiHorizontal, gDpiVertical );
164 }
165
166
167
168
169 } // Internal
170 } // Adaptor
171 } // Dali