The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 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_EGL_NATIVE_WINDOW_SURFACE_H |
| 18 | #define ANDROID_EGL_NATIVE_WINDOW_SURFACE_H |
| 19 | |
| 20 | #include <stdint.h> |
| 21 | #include <sys/types.h> |
Mathias Agopian | 076b1cc | 2009-04-10 14:24:30 -0700 | [diff] [blame^] | 22 | |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 23 | #include <EGL/egl.h> |
Mathias Agopian | 076b1cc | 2009-04-10 14:24:30 -0700 | [diff] [blame^] | 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 | |
| 32 | extern "C" EGLNativeWindowType android_createDisplaySurface(void); |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 33 | |
| 34 | // --------------------------------------------------------------------------- |
| 35 | namespace android { |
| 36 | // --------------------------------------------------------------------------- |
| 37 | |
| 38 | class Surface; |
| 39 | |
Mathias Agopian | 076b1cc | 2009-04-10 14:24:30 -0700 | [diff] [blame^] | 40 | |
| 41 | class NativeBuffer |
| 42 | : public EGLNativeBase< |
| 43 | android_native_buffer_t, |
| 44 | NativeBuffer, |
| 45 | LightRefBase<NativeBuffer> > |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 46 | { |
| 47 | public: |
Mathias Agopian | 076b1cc | 2009-04-10 14:24:30 -0700 | [diff] [blame^] | 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 | } |
| 55 | public: |
| 56 | buffer_handle_t handle; |
| 57 | private: |
| 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 | }; |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 65 | |
Mathias Agopian | 076b1cc | 2009-04-10 14:24:30 -0700 | [diff] [blame^] | 66 | // --------------------------------------------------------------------------- |
| 67 | |
| 68 | class FramebufferNativeWindow |
| 69 | : public EGLNativeBase< |
| 70 | android_native_window_t, |
| 71 | FramebufferNativeWindow, |
| 72 | LightRefBase<FramebufferNativeWindow> > |
| 73 | { |
| 74 | public: |
| 75 | FramebufferNativeWindow(); |
| 76 | |
| 77 | framebuffer_device_t const * getDevice() const { return fbDev; } |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 78 | |
| 79 | private: |
Mathias Agopian | 076b1cc | 2009-04-10 14:24:30 -0700 | [diff] [blame^] | 80 | friend class LightRefBase<FramebufferNativeWindow>; |
| 81 | ~FramebufferNativeWindow(); // this class cannot be overloaded |
| 82 | static void connect(android_native_window_t* window); |
| 83 | static void disconnect(android_native_window_t* window); |
| 84 | static int setSwapInterval(android_native_window_t* window, int interval); |
| 85 | static int setSwapRectangle(android_native_window_t* window, |
| 86 | int l, int t, int w, int h); |
| 87 | static int dequeueBuffer(android_native_window_t* window, android_native_buffer_t** buffer); |
| 88 | static int lockBuffer(android_native_window_t* window, android_native_buffer_t* buffer); |
| 89 | static int queueBuffer(android_native_window_t* window, android_native_buffer_t* buffer); |
| 90 | |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 91 | |
Mathias Agopian | 076b1cc | 2009-04-10 14:24:30 -0700 | [diff] [blame^] | 92 | static inline FramebufferNativeWindow* getSelf( |
| 93 | android_native_window_t* window) { |
| 94 | FramebufferNativeWindow* self = |
| 95 | static_cast<FramebufferNativeWindow*>(window); |
| 96 | return self; |
| 97 | } |
| 98 | |
| 99 | static inline FramebufferNativeWindow* getSelf( |
| 100 | android_native_base_t* window) { |
| 101 | return getSelf(reinterpret_cast<android_native_window_t*>(window)); |
| 102 | } |
| 103 | |
| 104 | |
| 105 | framebuffer_device_t* fbDev; |
| 106 | alloc_device_t* grDev; |
| 107 | |
| 108 | sp<NativeBuffer> buffers[2]; |
| 109 | sp<NativeBuffer> front; |
| 110 | |
| 111 | Rect mDirty; |
| 112 | |
| 113 | mutable Mutex mutex; |
| 114 | Condition mCondition; |
| 115 | int32_t mNumBuffers; |
| 116 | int32_t mNumFreeBuffers; |
| 117 | int32_t mBufferHead; |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 118 | }; |
| 119 | |
| 120 | // --------------------------------------------------------------------------- |
| 121 | }; // namespace android |
| 122 | // --------------------------------------------------------------------------- |
| 123 | |
| 124 | #endif // ANDROID_EGL_NATIVE_WINDOW_SURFACE_H |
| 125 | |