FramebufferNativeWindow.h revision b2dd686d06a608ee40285b93bc0217cf26c2b035
1/*
2 * Copyright (C) 2007 The Android Open Source Project
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
17#ifndef ANDROID_FRAMEBUFFER_NATIVE_WINDOW_H
18#define ANDROID_FRAMEBUFFER_NATIVE_WINDOW_H
19
20#include <stdint.h>
21#include <sys/types.h>
22
23#include <EGL/egl.h>
24#include <EGL/android_natives.h>
25
26#include <utils/threads.h>
27#include <ui/Rect.h>
28
29#include <pixelflinger/pixelflinger.h>
30
31
32extern "C" EGLNativeWindowType android_createDisplaySurface(void);
33
34// ---------------------------------------------------------------------------
35namespace android {
36// ---------------------------------------------------------------------------
37
38class Surface;
39
40
41class NativeBuffer
42    : public EGLNativeBase<
43        android_native_buffer_t,
44        NativeBuffer,
45        LightRefBase<NativeBuffer>  >
46{
47public:
48    NativeBuffer(int w, int h, int f, int u) : BASE() {
49        android_native_buffer_t::width  = w;
50        android_native_buffer_t::height = h;
51        android_native_buffer_t::format = f;
52        android_native_buffer_t::usage  = u;
53        android_native_buffer_t::getHandle = getHandle;
54    }
55public:
56    buffer_handle_t handle;
57private:
58    friend class LightRefBase<NativeBuffer>;
59    ~NativeBuffer() { }; // this class cannot be overloaded
60    static int getHandle(android_native_buffer_t const * base, buffer_handle_t* handle) {
61        *handle = getSelf(base)->handle;
62        return 0;
63    }
64};
65
66// ---------------------------------------------------------------------------
67
68class FramebufferNativeWindow
69    : public EGLNativeBase<
70        android_native_window_t,
71        FramebufferNativeWindow,
72        LightRefBase<FramebufferNativeWindow> >
73{
74public:
75    FramebufferNativeWindow();
76
77    framebuffer_device_t const * getDevice() const { return fbDev; }
78
79private:
80    friend class LightRefBase<FramebufferNativeWindow>;
81    ~FramebufferNativeWindow(); // this class cannot be overloaded
82    static int setSwapInterval(android_native_window_t* window, int interval);
83    static int dequeueBuffer(android_native_window_t* window, android_native_buffer_t** buffer);
84    static int lockBuffer(android_native_window_t* window, android_native_buffer_t* buffer);
85    static int queueBuffer(android_native_window_t* window, android_native_buffer_t* buffer);
86
87    framebuffer_device_t* fbDev;
88    alloc_device_t* grDev;
89
90    sp<NativeBuffer> buffers[2];
91    sp<NativeBuffer> front;
92
93    mutable Mutex mutex;
94    Condition mCondition;
95    int32_t mNumBuffers;
96    int32_t mNumFreeBuffers;
97    int32_t mBufferHead;
98};
99
100// ---------------------------------------------------------------------------
101}; // namespace android
102// ---------------------------------------------------------------------------
103
104#endif // ANDROID_FRAMEBUFFER_NATIVE_WINDOW_H
105
106