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 <utils/String8.h> 27 28 #include <ui/ANativeObjectBase.h> 29 #include <ui/Rect.h> 30 31 #define MIN_NUM_FRAME_BUFFERS 2 32 #define MAX_NUM_FRAME_BUFFERS 3 33 34 extern "C" EGLNativeWindowType android_createDisplaySurface(void); 35 36 // --------------------------------------------------------------------------- 37 namespace android { 38 // --------------------------------------------------------------------------- 39 40 class Surface; 41 class NativeBuffer; 42 43 // --------------------------------------------------------------------------- 44 45 class FramebufferNativeWindow 46 : public ANativeObjectBase< 47 ANativeWindow, 48 FramebufferNativeWindow, 49 LightRefBase<FramebufferNativeWindow> > 50 { 51 public: 52 FramebufferNativeWindow(); 53 54 framebuffer_device_t const * getDevice() const { return fbDev; } 55 56 bool isUpdateOnDemand() const { return mUpdateOnDemand; } 57 status_t setUpdateRectangle(const Rect& updateRect); 58 status_t compositionComplete(); 59 60 void dump(String8& result); 61 62 // for debugging only 63 int getCurrentBufferIndex() const; 64 65 private: 66 friend class LightRefBase<FramebufferNativeWindow>; 67 ~FramebufferNativeWindow(); // this class cannot be overloaded 68 static int setSwapInterval(ANativeWindow* window, int interval); 69 static int dequeueBuffer(ANativeWindow* window, ANativeWindowBuffer** buffer, int* fenceFd); 70 static int queueBuffer(ANativeWindow* window, ANativeWindowBuffer* buffer, int fenceFd); 71 static int query(const ANativeWindow* window, int what, int* value); 72 static int perform(ANativeWindow* window, int operation, ...); 73 74 static int dequeueBuffer_DEPRECATED(ANativeWindow* window, ANativeWindowBuffer** buffer); 75 static int queueBuffer_DEPRECATED(ANativeWindow* window, ANativeWindowBuffer* buffer); 76 static int lockBuffer_DEPRECATED(ANativeWindow* window, ANativeWindowBuffer* buffer); 77 78 framebuffer_device_t* fbDev; 79 alloc_device_t* grDev; 80 81 sp<NativeBuffer> buffers[MAX_NUM_FRAME_BUFFERS]; 82 sp<NativeBuffer> front; 83 84 mutable Mutex mutex; 85 Condition mCondition; 86 int32_t mNumBuffers; 87 int32_t mNumFreeBuffers; 88 int32_t mBufferHead; 89 int32_t mCurrentBufferIndex; 90 bool mUpdateOnDemand; 91 }; 92 93 // --------------------------------------------------------------------------- 94 }; // namespace android 95 // --------------------------------------------------------------------------- 96 97 #endif // ANDROID_FRAMEBUFFER_NATIVE_WINDOW_H 98 99