evdev: Update axis notifications to follow protocol
[profile/ivi/weston.git] / src / android-framebuffer.cpp
1 /*
2  * Copyright © 2012 Collabora, Ltd.
3  *
4  * Permission to use, copy, modify, distribute, and sell this software and
5  * its documentation for any purpose is hereby granted without fee, provided
6  * that the above copyright notice appear in all copies and that both that
7  * copyright notice and this permission notice appear in supporting
8  * documentation, and that the name of the copyright holders not be used in
9  * advertising or publicity pertaining to distribution of the software
10  * without specific, written prior permission.  The copyright holders make
11  * no representations about the suitability of this software for any
12  * purpose.  It is provided "as is" without express or implied warranty.
13  *
14  * THE COPYRIGHT HOLDERS DISCLAIM ALL WARRANTIES WITH REGARD TO THIS
15  * SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND
16  * FITNESS, IN NO EVENT SHALL THE COPYRIGHT HOLDERS BE LIABLE FOR ANY
17  * SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER
18  * RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF
19  * CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN
20  * CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
21  */
22
23 #include <cstdlib>
24
25 #include "android-framebuffer.h"
26
27 #ifdef ANDROID
28
29 #include <ui/FramebufferNativeWindow.h>
30
31 class AndroidFramebuffer {
32 public:
33         int init();
34
35         struct android_framebuffer fb_;
36
37 private:
38         android::sp<android::FramebufferNativeWindow> nativefb_;
39 };
40
41 int AndroidFramebuffer::init()
42 {
43         struct ANativeWindow *window;
44         const framebuffer_device_t *fbdev;
45         int ret1, ret2, ret3;
46
47         nativefb_ = new android::FramebufferNativeWindow();
48         fbdev = nativefb_->getDevice();
49
50         if (!fbdev)
51                 return -1;
52
53         fb_.priv = this;
54
55         window = nativefb_.get();
56         ret1 = window->query(window, NATIVE_WINDOW_WIDTH, &fb_.width);
57         ret2 = window->query(window, NATIVE_WINDOW_HEIGHT, &fb_.height);
58         ret3 = window->query(window, NATIVE_WINDOW_FORMAT, &fb_.format);
59         fb_.xdpi = window->xdpi;
60         fb_.ydpi = window->ydpi;
61         fb_.refresh_rate = fbdev->fps;
62
63         if (ret1 != android::NO_ERROR ||
64             ret2 != android::NO_ERROR ||
65             ret3 != android::NO_ERROR)
66                 return -1;
67
68         fb_.native_window = reinterpret_cast<EGLNativeWindowType>(window);
69         return 0;
70 }
71
72 void
73 android_framebuffer_destroy(struct android_framebuffer *fb)
74 {
75         AndroidFramebuffer *afb = static_cast<AndroidFramebuffer*>(fb->priv);
76
77         delete afb;
78 }
79
80 struct android_framebuffer *
81 android_framebuffer_create(void)
82 {
83         AndroidFramebuffer *afb = new AndroidFramebuffer;
84
85         if (afb->init() < 0) {
86                 delete afb;
87                 return NULL;
88         }
89
90         return &afb->fb_;
91 }
92
93 #endif /* ANDROID */