2 * Copyright (c) 2016 Samsung Electronics Co., Ltd.
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
8 * http://www.apache.org/licenses/LICENSE-2.0
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.
19 #include "compositor-output.h"
22 #include <dali/integration-api/debug.h>
37 #if defined(DEBUG_ENABLED)
38 Debug::Filter* gLogFilter = Debug::Filter::New(Debug::NoLogging, false, "LOG_MONITOR_INFO");
41 const float MILLIMETRE_TO_INCH = 1.f / 25.4f;
43 unsigned int gDpiHorizontal = 75;
44 unsigned int gDpiVertical = 75;
47 void OutputGeometryCallback( void *data,
48 struct wl_output *wl_output,
51 int32_t physical_width,
52 int32_t physical_height,
58 CompositorOutput* output = static_cast< CompositorOutput* >( data );
59 output->SetMonitorDimensions( physical_width, physical_height );
61 DALI_LOG_INFO( gLogFilter, Debug::General, "Monitor width: %d mm, height: %d mm\n",physical_width, physical_height );
64 void OutputModeCallback( void *data,
65 struct wl_output *wl_output,
72 if (flags & WL_OUTPUT_MODE_CURRENT)
74 CompositorOutput* output = static_cast< CompositorOutput* >( data );
75 output->SetMonitorResolution( width, height );
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 );
81 void OutputCallbackDone(void *data,
82 struct wl_output *wl_output)
84 CompositorOutput* output = static_cast< CompositorOutput* >( data );
85 output->CallbacksDone();
88 void OutputCallbackScale(void *data,
89 struct wl_output *wl_output,
92 // Need to understand if we need to support output scaling and what impact it has on input handling etc.
97 //output typically corresponds to a monitor
98 const struct wl_output_listener OutputListener =
100 OutputGeometryCallback,
106 CompositorOutput::CompositorOutput()
110 mMonitorWidth( 0.f ),
111 mMonitorHeight( 0.f ),
117 CompositorOutput::~CompositorOutput()
121 wl_output_destroy( mOutput );
125 void CompositorOutput::AddListener( WlOutput* outputInterface )
127 mOutput = outputInterface;
129 wl_output_add_listener( mOutput , &OutputListener, this);
132 void CompositorOutput::GetDpi( unsigned int& dpiHorizontal, unsigned int& dpiVertical )
134 dpiHorizontal = gDpiHorizontal;
135 dpiVertical = gDpiVertical;
138 bool CompositorOutput::DataReady() const
143 void CompositorOutput::SetMonitorDimensions( unsigned int width, unsigned int height )
145 mMonitorHeight = static_cast<float> ( height ) * MILLIMETRE_TO_INCH;
146 mMonitorWidth = static_cast<float>( width ) * MILLIMETRE_TO_INCH;
149 void CompositorOutput::SetMonitorResolution( unsigned int width, unsigned int height )
151 mXresolution = width;
152 mYresolution = height;
155 void CompositorOutput::CallbacksDone()
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;
163 DALI_LOG_INFO( gLogFilter, Debug::General, "Monitor DPI %d x %d\n", gDpiHorizontal, gDpiVertical );