1/*
2 * Copyright (C) 2007 Apple Inc.  All rights reserved.
3 * Copyright (C) 2008 Nokia Corporation and/or its subsidiary(-ies)
4 * Copyright (C) 2008 Holger Hans Peter Freyther
5 * Copyright (C) 2008 INdT - Instituto Nokia de Tecnologia
6 * Copyright (C) 2009-2010 ProFUSION embedded systems
7 * Copyright (C) 2009-2010 Samsung Electronics
8 * Copyright (C) 2012 Intel Corporation. All rights reserved.
9 *
10 * Redistribution and use in source and binary forms, with or without
11 * modification, are permitted provided that the following conditions
12 * are met:
13 *
14 * 1.  Redistributions of source code must retain the above copyright
15 *     notice, this list of conditions and the following disclaimer.
16 * 2.  Redistributions in binary form must reproduce the above copyright
17 *     notice, this list of conditions and the following disclaimer in the
18 *     documentation and/or other materials provided with the distribution.
19 * 3.  Neither the name of Apple Inc. ("Apple") nor the names of
20 *     its contributors may be used to endorse or promote products derived
21 *     from this software without specific prior written permission.
22 *
23 * THIS SOFTWARE IS PROVIDED BY APPLE AND ITS CONTRIBUTORS "AS IS" AND ANY
24 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
25 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
26 * DISCLAIMED. IN NO EVENT SHALL APPLE OR ITS CONTRIBUTORS BE LIABLE FOR ANY
27 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
28 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
29 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
30 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
31 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
32 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
33 */
34
35#include "config.h"
36#include "PlatformScreen.h"
37
38#include "FloatRect.h"
39#include "NotImplemented.h"
40#include "Widget.h"
41
42#include <Ecore_Evas.h>
43#include <wtf/text/CString.h>
44#include <wtf/text/WTFString.h>
45
46#ifdef HAVE_ECORE_X
47#include <Ecore_X.h>
48#endif
49
50namespace WebCore {
51
52int screenDepth(Widget*)
53{
54#ifdef HAVE_ECORE_X
55    return ecore_x_default_depth_get(ecore_x_display_get(), ecore_x_default_screen_get());
56#else
57    return 24;
58#endif
59}
60
61int screenDepthPerComponent(Widget* widget)
62{
63    if (!widget)
64        return 8;
65
66    int depth = screenDepth(widget);
67
68    switch (depth) {
69    // Special treat 0 as an error, and return 8 bit per component.
70    case 0:
71    case 24:
72    case 32:
73        return 8;
74    case 8:
75        return 2;
76    default:
77        return depth / 3;
78    }
79}
80
81bool screenIsMonochrome(Widget* widget)
82{
83    return screenDepth(widget) < 2;
84}
85
86FloatRect screenRect(Widget* widget)
87{
88#ifdef HAVE_ECORE_X
89    UNUSED_PARAM(widget);
90    // Fallback to realistic values if the EcoreX call fails
91    // and we cannot accurately detect the screen size.
92    int width = 800;
93    int height = 600;
94    ecore_x_screen_size_get(ecore_x_default_screen_get(), &width, &height);
95    return FloatRect(0, 0, width, height);
96#else
97    if (!widget || !widget->evas())
98        return FloatRect();
99
100    int x, y, w, h;
101    ecore_evas_screen_geometry_get(ecore_evas_ecore_evas_get(widget->evas()), &x, &y, &w, &h);
102    return FloatRect(x, y, w, h);
103#endif
104}
105
106FloatRect screenAvailableRect(Widget* widget)
107{
108    notImplemented();
109    return screenRect(widget);
110}
111
112}
113