DummyDevice.cpp revision 452fbc109a9c585737bcac18f19aff40574c3d79
1/*
2// Copyright (c) 2014 Intel Corporation 
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#include <common/utils/HwcTrace.h>
17#include <Hwcomposer.h>
18#include <DisplayQuery.h>
19#include <common/observers/SoftVsyncObserver.h>
20#include <DummyDevice.h>
21
22namespace android {
23namespace intel {
24DummyDevice::DummyDevice(Hwcomposer& hwc)
25    : mInitialized(false),
26      mConnected(false),
27      mBlank(false),
28      mHwc(hwc),
29      mVsyncObserver(NULL),
30      mName("Dummy")
31{
32    CTRACE();
33}
34
35DummyDevice::~DummyDevice()
36{
37    WARN_IF_NOT_DEINIT();
38}
39
40bool DummyDevice::prePrepare(hwc_display_contents_1_t *display)
41{
42    RETURN_FALSE_IF_NOT_INIT();
43
44    if (!display) {
45        return true;
46    }
47
48    // nothing need to do for dummy display
49    return true;
50}
51
52bool DummyDevice::prepare(hwc_display_contents_1_t *display)
53{
54    RETURN_FALSE_IF_NOT_INIT();
55
56    if (!display) {
57        return true;
58    }
59
60    // skip all layers composition on dummy display
61    if (display->flags & HWC_GEOMETRY_CHANGED) {
62        for (size_t i=0; i < display->numHwLayers-1; i++) {
63            hwc_layer_1 * player = &display->hwLayers[i];
64            player->compositionType = HWC_OVERLAY;
65            player->flags &= ~HWC_SKIP_LAYER;
66        }
67    }
68
69    return true;
70}
71
72bool DummyDevice::commit(hwc_display_contents_1_t *display, IDisplayContext *context)
73{
74    RETURN_FALSE_IF_NOT_INIT();
75
76    if (!display || !context)
77        return true;
78
79    // nothing need to do for dummy display
80    return true;
81}
82
83bool DummyDevice::vsyncControl(bool enabled)
84{
85    RETURN_FALSE_IF_NOT_INIT();
86    return mVsyncObserver->control(enabled);
87}
88
89bool DummyDevice::blank(bool blank)
90{
91    RETURN_FALSE_IF_NOT_INIT();
92
93    mBlank = blank;
94
95    return true;
96}
97
98bool DummyDevice::getDisplaySize(int *width, int *height)
99{
100    RETURN_FALSE_IF_NOT_INIT();
101    if (!width || !height) {
102        ETRACE("invalid parameters");
103        return false;
104    }
105
106    // TODO: make this platform specifc
107    *width = 1280;//720;
108    *height = 720;//1280;
109    return true;
110}
111
112bool DummyDevice::getDisplayConfigs(uint32_t *configs,
113                                         size_t *numConfigs)
114{
115    RETURN_FALSE_IF_NOT_INIT();
116    if (!configs || !numConfigs) {
117        ETRACE("invalid parameters");
118        return false;
119    }
120
121    if (!mConnected) {
122        ITRACE("dummy device is not connected");
123        return false;
124    }
125
126    *configs = 0;
127    *numConfigs = 1;
128
129    return true;
130}
131
132bool DummyDevice::getDisplayAttributes(uint32_t configs,
133                                            const uint32_t *attributes,
134                                            int32_t *values)
135{
136    RETURN_FALSE_IF_NOT_INIT();
137
138    if ((configs > 0) || !attributes || !values) {
139        ETRACE("invalid parameters");
140        return false;
141    }
142
143    if (!mConnected) {
144        ITRACE("dummy device is not connected");
145        return false;
146    }
147
148    int i = 0;
149    while (attributes[i] != HWC_DISPLAY_NO_ATTRIBUTE) {
150        switch (attributes[i]) {
151        case HWC_DISPLAY_VSYNC_PERIOD:
152            values[i] = 1e9 / 60;
153            break;
154        case HWC_DISPLAY_WIDTH:
155            values[i] = 1280;
156            break;
157        case HWC_DISPLAY_HEIGHT:
158            values[i] = 720;
159            break;
160        case HWC_DISPLAY_DPI_X:
161            values[i] = 0;
162            break;
163        case HWC_DISPLAY_DPI_Y:
164            values[i] = 0;
165            break;
166        default:
167            ETRACE("unknown attribute %d", attributes[i]);
168            break;
169        }
170        i++;
171    }
172
173    return true;
174}
175
176bool DummyDevice::compositionComplete()
177{
178    RETURN_FALSE_IF_NOT_INIT();
179    return true;
180}
181
182bool DummyDevice::initialize()
183{
184    mInitialized = true;
185
186    mVsyncObserver = new SoftVsyncObserver(*this);
187    if (!mVsyncObserver || !mVsyncObserver->initialize()) {
188        DEINIT_AND_RETURN_FALSE("Failed to create Soft Vsync Observer");
189        mInitialized = false;
190    }
191
192    return mInitialized;
193}
194
195bool DummyDevice::isConnected() const
196{
197    return mConnected;
198}
199
200const char* DummyDevice::getName() const
201{
202    return "Dummy";
203}
204
205int DummyDevice::getType() const
206{
207    return DEVICE_DUMMY;
208}
209
210void DummyDevice::onVsync(int64_t timestamp)
211{
212    mHwc.vsync(DEVICE_DUMMY, timestamp);
213}
214
215void DummyDevice::dump(Dump& d)
216{
217    d.append("-------------------------------------------------------------\n");
218    d.append("Device Name: %s (%s)\n", mName,
219            mConnected ? "connected" : "disconnected");
220}
221
222void DummyDevice::deinitialize()
223{
224    DEINIT_AND_DELETE_OBJ(mVsyncObserver);
225    mInitialized = false;
226}
227
228bool DummyDevice::setPowerMode(int /*mode*/)
229{
230    return true;
231}
232
233int DummyDevice::getActiveConfig()
234{
235    return 0;
236}
237
238bool DummyDevice::setActiveConfig(int /*index*/)
239{
240    return false;
241}
242
243bool DummyDevice::setCursorPositionAsync(int /*x*/, int /*y*/)
244{
245    return false;
246}
247
248} // namespace intel
249} // namespace android
250