blob: 70a94fcab994055cfd10d52bdc1beb6ac2c6d52b [file] [log] [blame]
The Android Open Source Projecte09fd9e2008-12-17 18:05:43 -08001/*
2 * Copyright (C) 2008 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_SIM_EGL_SURFACE_H
18#define ANDROID_SIM_EGL_SURFACE_H
19
20#include <stdint.h>
21#include <errno.h>
22#include <sys/types.h>
23
24#include <GLES/eglnatives.h>
25
26#include <linux/fb.h>
27
28typedef struct {
29 ssize_t version; // always set to sizeof(GGLSurface)
30 uint32_t width; // width in pixels
31 uint32_t height; // height in pixels
32 int32_t stride; // stride in pixels
33 uint8_t* data; // pointer to the bits
34 uint8_t format; // pixel format
35 uint8_t rfu[3]; // must be zero
36 void* reserved;
37} GGLSurface;
38
39// ---------------------------------------------------------------------------
40namespace android {
41// ---------------------------------------------------------------------------
42
43template <class TYPE>
44class EGLNativeSurface : public egl_native_window_t
45{
46public:
47 EGLNativeSurface() : mCount(0) {
48 memset(egl_native_window_t::reserved, 0,
49 sizeof(egl_native_window_t::reserved));
50 memset(egl_native_window_t::reserved_proc, 0,
51 sizeof(egl_native_window_t::reserved_proc));
52 memset(egl_native_window_t::oem, 0,
53 sizeof(egl_native_window_t::oem));
54 }
55 inline void incStrong(void*) const {
56 /* in a real implementation, the inc must be atomic */
57 mCount++;
58 }
59 inline void decStrong(void*) const {
60 /* in a real implementation, the dec must be atomic */
61 if (--mCount == 1) {
62 delete static_cast<const TYPE*>(this);
63 }
64 }
65protected:
66 EGLNativeSurface& operator = (const EGLNativeSurface& rhs);
67 EGLNativeSurface(const EGLNativeSurface& rhs);
68 inline ~EGLNativeSurface() { };
69 mutable volatile int32_t mCount;
70};
71
72
73class EGLDisplaySurface : public EGLNativeSurface<EGLDisplaySurface>
74{
75public:
76 EGLDisplaySurface();
77 ~EGLDisplaySurface();
78
79 int32_t getPageFlipCount() const;
80
81private:
82 static void hook_incRef(NativeWindowType window);
83 static void hook_decRef(NativeWindowType window);
84 static uint32_t hook_swapBuffers(NativeWindowType window);
85 static void hook_setSwapRectangle(NativeWindowType window, int l, int t, int w, int h);
86 static uint32_t hook_nextBuffer(NativeWindowType window);
87
88 uint32_t swapBuffers();
89 uint32_t nextBuffer();
90 void setSwapRectangle(int l, int t, int w, int h);
91
92 int mapFrameBuffer();
93
94 enum {
95 PAGE_FLIP = 0x00000001
96 };
97 GGLSurface mFb[2];
98 int mIndex;
99 uint32_t mFlags;
100 size_t mSize;
101 fb_var_screeninfo mInfo;
102 fb_fix_screeninfo mFinfo;
103 int32_t mPageFlipCount;
104 int32_t mSwapCount;
105 uint32_t mFeatureFlags;
106};
107
108// ---------------------------------------------------------------------------
109}; // namespace android
110// ---------------------------------------------------------------------------
111
112#endif // ANDROID_SIM_EGL_SURFACE_H
113