blob: 16117adca92a74240d64637bf13b0e26890c742c [file] [log] [blame]
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001/*
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
Mathias Agopiandff8e582009-05-04 14:17:04 -070017#ifndef ANDROID_FRAMEBUFFER_NATIVE_WINDOW_H
18#define ANDROID_FRAMEBUFFER_NATIVE_WINDOW_H
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080019
20#include <stdint.h>
21#include <sys/types.h>
Mathias Agopian1473f462009-04-10 14:24:30 -070022
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080023#include <EGL/egl.h>
Mathias Agopian1473f462009-04-10 14:24:30 -070024
25#include <utils/threads.h>
Erik Gilling94720d72010-12-01 16:38:01 -080026#include <utils/String8.h>
Mathias Agopian1473f462009-04-10 14:24:30 -070027#include <ui/Rect.h>
28
29#include <pixelflinger/pixelflinger.h>
30
Mathias Agopianac2523b2009-05-05 18:11:11 -070031#include <ui/egl/android_natives.h>
32
Rodrigo Obregon84043432010-11-03 15:16:18 -050033#define NUM_FRAME_BUFFERS 2
Mathias Agopian1473f462009-04-10 14:24:30 -070034
35extern "C" EGLNativeWindowType android_createDisplaySurface(void);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080036
37// ---------------------------------------------------------------------------
38namespace android {
39// ---------------------------------------------------------------------------
40
41class Surface;
Mathias Agopianac2523b2009-05-05 18:11:11 -070042class NativeBuffer;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080043
Mathias Agopian1473f462009-04-10 14:24:30 -070044// ---------------------------------------------------------------------------
45
46class FramebufferNativeWindow
47 : public EGLNativeBase<
Dianne Hackborn8b49bd12010-06-30 13:56:17 -070048 ANativeWindow,
Mathias Agopian1473f462009-04-10 14:24:30 -070049 FramebufferNativeWindow,
50 LightRefBase<FramebufferNativeWindow> >
51{
52public:
53 FramebufferNativeWindow();
54
55 framebuffer_device_t const * getDevice() const { return fbDev; }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080056
Mathias Agopian97b80562009-05-07 17:40:23 -070057 bool isUpdateOnDemand() const { return mUpdateOnDemand; }
58 status_t setUpdateRectangle(const Rect& updateRect);
Mathias Agopianb1a18742009-09-17 16:18:16 -070059 status_t compositionComplete();
Erik Gilling94720d72010-12-01 16:38:01 -080060
61 void dump(String8& result);
62
Mathias Agopian04262e92010-09-13 22:57:58 -070063 // for debugging only
64 int getCurrentBufferIndex() const;
65
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080066private:
Mathias Agopian1473f462009-04-10 14:24:30 -070067 friend class LightRefBase<FramebufferNativeWindow>;
68 ~FramebufferNativeWindow(); // this class cannot be overloaded
Dianne Hackborn8b49bd12010-06-30 13:56:17 -070069 static int setSwapInterval(ANativeWindow* window, int interval);
70 static int dequeueBuffer(ANativeWindow* window, android_native_buffer_t** buffer);
71 static int lockBuffer(ANativeWindow* window, android_native_buffer_t* buffer);
72 static int queueBuffer(ANativeWindow* window, android_native_buffer_t* buffer);
73 static int query(ANativeWindow* window, int what, int* value);
74 static int perform(ANativeWindow* window, int operation, ...);
Mathias Agopian1473f462009-04-10 14:24:30 -070075
Mathias Agopian1473f462009-04-10 14:24:30 -070076 framebuffer_device_t* fbDev;
77 alloc_device_t* grDev;
78
Rodrigo Obregon84043432010-11-03 15:16:18 -050079 sp<NativeBuffer> buffers[NUM_FRAME_BUFFERS];
Mathias Agopian1473f462009-04-10 14:24:30 -070080 sp<NativeBuffer> front;
81
Mathias Agopian1473f462009-04-10 14:24:30 -070082 mutable Mutex mutex;
83 Condition mCondition;
84 int32_t mNumBuffers;
85 int32_t mNumFreeBuffers;
86 int32_t mBufferHead;
Mathias Agopian04262e92010-09-13 22:57:58 -070087 int32_t mCurrentBufferIndex;
Mathias Agopian97b80562009-05-07 17:40:23 -070088 bool mUpdateOnDemand;
Mathias Agopiancbc4c9f2009-06-23 21:11:43 -070089};
90
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080091// ---------------------------------------------------------------------------
92}; // namespace android
93// ---------------------------------------------------------------------------
94
Mathias Agopiandff8e582009-05-04 14:17:04 -070095#endif // ANDROID_FRAMEBUFFER_NATIVE_WINDOW_H
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080096