FramebufferNativeWindow.h revision cb6b9041647b4f080324742eee5ce709960ff610
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
25#include <utils/threads.h>
26#include <ui/Rect.h>
27
28#include <pixelflinger/pixelflinger.h>
29
30#include <ui/egl/android_natives.h>
31
32
33extern "C" EGLNativeWindowType android_createDisplaySurface(void);
34
35// ---------------------------------------------------------------------------
36namespace android {
37// ---------------------------------------------------------------------------
38
39class Surface;
40class NativeBuffer;
41
42// ---------------------------------------------------------------------------
43
44class FramebufferNativeWindow
45    : public EGLNativeBase<
46        android_native_window_t,
47        FramebufferNativeWindow,
48        LightRefBase<FramebufferNativeWindow> >
49{
50public:
51    FramebufferNativeWindow();
52
53    framebuffer_device_t const * getDevice() const { return fbDev; }
54
55    bool isUpdateOnDemand() const { return mUpdateOnDemand; }
56    status_t setUpdateRectangle(const Rect& updateRect);
57
58private:
59    friend class LightRefBase<FramebufferNativeWindow>;
60    ~FramebufferNativeWindow(); // this class cannot be overloaded
61    static int setSwapInterval(android_native_window_t* window, int interval);
62    static int dequeueBuffer(android_native_window_t* window, android_native_buffer_t** buffer);
63    static int lockBuffer(android_native_window_t* window, android_native_buffer_t* buffer);
64    static int queueBuffer(android_native_window_t* window, android_native_buffer_t* buffer);
65    static int query(android_native_window_t* window, int what, int* value);
66
67    framebuffer_device_t* fbDev;
68    alloc_device_t* grDev;
69
70    sp<NativeBuffer> buffers[2];
71    sp<NativeBuffer> front;
72
73    mutable Mutex mutex;
74    Condition mCondition;
75    int32_t mNumBuffers;
76    int32_t mNumFreeBuffers;
77    int32_t mBufferHead;
78    bool mUpdateOnDemand;
79};
80
81// ---------------------------------------------------------------------------
82}; // namespace android
83// ---------------------------------------------------------------------------
84
85#endif // ANDROID_FRAMEBUFFER_NATIVE_WINDOW_H
86
87