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