2 * Copyright © 2012 Collabora, Ltd.
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.
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.
25 #include "android-framebuffer.h"
29 #include <ui/FramebufferNativeWindow.h>
31 class AndroidFramebuffer {
35 struct android_framebuffer fb_;
38 android::sp<android::FramebufferNativeWindow> nativefb_;
41 int AndroidFramebuffer::init()
43 struct ANativeWindow *window;
44 const framebuffer_device_t *fbdev;
47 nativefb_ = new android::FramebufferNativeWindow();
48 fbdev = nativefb_->getDevice();
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;
63 if (ret1 != android::NO_ERROR ||
64 ret2 != android::NO_ERROR ||
65 ret3 != android::NO_ERROR)
68 fb_.native_window = reinterpret_cast<EGLNativeWindowType>(window);
73 android_framebuffer_destroy(struct android_framebuffer *fb)
75 AndroidFramebuffer *afb = static_cast<AndroidFramebuffer*>(fb->priv);
80 struct android_framebuffer *
81 android_framebuffer_create(void)
83 AndroidFramebuffer *afb = new AndroidFramebuffer;
85 if (afb->init() < 0) {