1 /****************************************************************************
3 ** Copyright (C) 2012 Digia Plc and/or its subsidiary(-ies).
4 ** Contact: http://www.qt-project.org/legal
6 ** This file is part of the plugins of the Qt Toolkit.
8 ** $QT_BEGIN_LICENSE:LGPL$
9 ** Commercial License Usage
10 ** Licensees holding valid commercial Qt licenses may use this file in
11 ** accordance with the commercial license agreement provided with the
12 ** Software or, alternatively, in accordance with the terms contained in
13 ** a written agreement between you and Digia. For licensing terms and
14 ** conditions see http://qt.digia.com/licensing. For further information
15 ** use the contact form at http://qt.digia.com/contact-us.
17 ** GNU Lesser General Public License Usage
18 ** Alternatively, this file may be used under the terms of the GNU Lesser
19 ** General Public License version 2.1 as published by the Free Software
20 ** Foundation and appearing in the file LICENSE.LGPL included in the
21 ** packaging of this file. Please review the following information to
22 ** ensure the GNU Lesser General Public License version 2.1 requirements
23 ** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
25 ** In addition, as a special exception, Digia gives you certain additional
26 ** rights. These rights are described in the Digia Qt LGPL Exception
27 ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
29 ** GNU General Public License Usage
30 ** Alternatively, this file may be used under the terms of the GNU
31 ** General Public License version 3.0 as published by the Free Software
32 ** Foundation and appearing in the file LICENSE.GPL included in the
33 ** packaging of this file. Please review the following information to
34 ** ensure the GNU General Public License version 3.0 requirements will be
35 ** met: http://www.gnu.org/copyleft/gpl.html.
40 ****************************************************************************/
42 #include "qopenwfdport.h"
44 #include "qopenwfdportmode.h"
45 #include "qopenwfdscreen.h"
47 #include <QtCore/QDebug>
49 QOpenWFDPort::QOpenWFDPort(QOpenWFDDevice *device, WFDint portEnumeration)
51 , mPortId(portEnumeration)
53 , mPipelineId(WFD_INVALID_PIPELINE_ID)
54 , mPipeline(WFD_INVALID_HANDLE)
56 mPort = wfdCreatePort(device->handle(),portEnumeration,0);
57 WFDint isPortAttached = wfdGetPortAttribi(device->handle(),mPort,WFD_PORT_ATTACHED);
63 QOpenWFDPort::~QOpenWFDPort()
67 wfdDestroyPort(mDevice->handle(),mPort);
70 void QOpenWFDPort::attach()
76 //just forcing port to be on
77 wfdSetPortAttribi(mDevice->handle(), mPort, WFD_PORT_POWER_MODE, WFD_POWER_MODE_ON);
79 int numberOfPortModes = wfdGetPortModes(mDevice->handle(),mPort,0,0);
80 WFDPortMode portModes[numberOfPortModes];
81 int actualNumberOfPortModes = wfdGetPortModes(mDevice->handle(),mPort,portModes,numberOfPortModes);
82 Q_ASSERT(actualNumberOfPortModes == numberOfPortModes);
84 if (!actualNumberOfPortModes) {
85 qDebug() << "didn't find any available port modes";
89 for (int i = 0; i < actualNumberOfPortModes; i++) {
90 if (portModes[i] != WFD_INVALID_HANDLE) {
91 mPortModes.append(QOpenWFDPortMode(this,portModes[i]));
92 qDebug() << "PortModeAdded:" << mPortModes.at(mPortModes.size()-1);
97 mPixelSize = setNativeResolutionMode();
98 if (mPixelSize.isEmpty()) {
99 qDebug() << "Could not set native resolution mode in QOpenWFPort";
102 WFDfloat physicalWFDSize[2];
103 wfdGetPortAttribfv(mDevice->handle(),mPort,WFD_PORT_PHYSICAL_SIZE,2,physicalWFDSize);
104 mPhysicalSize = QSizeF(physicalWFDSize[0],physicalWFDSize[1]);
106 WFDint numAvailablePipelines = wfdGetPortAttribi(mDevice->handle(),mPort,WFD_PORT_PIPELINE_ID_COUNT);
107 if (!numAvailablePipelines) {
108 qFatal("Not possible to make screen that is not possible to create WFPort with no pipline");
111 WFDint pipeIds[numAvailablePipelines];
112 wfdGetPortAttribiv(mDevice->handle(),mPort,WFD_PORT_BINDABLE_PIPELINE_IDS,numAvailablePipelines,pipeIds);
114 for (int i = 0; i < numAvailablePipelines; i++) {
115 if (pipeIds[i] != WFD_INVALID_PIPELINE_ID && !mDevice->isPipelineUsed(pipeIds[i])) {
116 mPipelineId = pipeIds[i];
117 mDevice-> addToUsedPipelineSet(mPipelineId,this);
119 mPipeline = wfdCreatePipeline(mDevice->handle(),mPipelineId,WFD_NONE);
120 if (mPipeline == WFD_INVALID_HANDLE) {
121 qFatal("Failed to create pipeline for port %p", this);
127 if (mPipeline == WFD_INVALID_HANDLE) {
128 qWarning("Failed to create pipeline and cant bind it to port");
131 WFDint geomerty[] = { 0, 0, mPixelSize.width(), mPixelSize.height() };
133 wfdSetPipelineAttribiv(mDevice->handle(),mPipeline, WFD_PIPELINE_SOURCE_RECTANGLE, 4, geomerty);
134 wfdSetPipelineAttribiv(mDevice->handle(),mPipeline, WFD_PIPELINE_DESTINATION_RECTANGLE, 4, geomerty);
136 wfdBindPipelineToPort(mDevice->handle(),mPort,mPipeline);
138 mScreen = new QOpenWFDScreen(this);
139 mDevice->integration()->addScreen(mScreen);
143 void QOpenWFDPort::detach()
153 wfdDestroyPipeline(mDevice->handle(),mPipeline);
154 mPipelineId = WFD_INVALID_PIPELINE_ID;
155 mPipeline = WFD_INVALID_HANDLE;
158 bool QOpenWFDPort::attached() const
163 QSize QOpenWFDPort::setNativeResolutionMode()
165 WFDint nativePixelSize[2];
166 wfdGetPortAttribiv(device()->handle(),mPort,WFD_PORT_NATIVE_RESOLUTION,2,nativePixelSize);
167 QSize nativeSize(nativePixelSize[0],nativePixelSize[1]);
169 for (int i = 0; i < mPortModes.size(); i++) {
170 const QOpenWFDPortMode &mode = mPortModes.at(i);
171 if (nativeSize == mode.size()) {
172 wfdSetPortMode(device()->handle(),mPort,mode.handle());
179 QSize QOpenWFDPort::pixelSize() const
184 QSizeF QOpenWFDPort::physicalSize() const
186 return mPhysicalSize;
189 QOpenWFDDevice * QOpenWFDPort::device() const
194 WFDPort QOpenWFDPort::handle() const
199 WFDint QOpenWFDPort::portId() const
204 WFDPipeline QOpenWFDPort::pipeline() const
209 QOpenWFDScreen * QOpenWFDPort::screen() const