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