blob: 5ec738f33e64c5802b5708b63cc1b2d1b31953f3 [file] [log] [blame]
The Android Open Source Projectedbf3b62009-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 Agopian0926f502009-05-04 14:17:04 -070017#ifndef ANDROID_FRAMEBUFFER_NATIVE_WINDOW_H
18#define ANDROID_FRAMEBUFFER_NATIVE_WINDOW_H
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -080019
20#include <stdint.h>
21#include <sys/types.h>
Mathias Agopian076b1cc2009-04-10 14:24:30 -070022
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -080023#include <EGL/egl.h>
Mathias Agopian076b1cc2009-04-10 14:24:30 -070024
25#include <utils/threads.h>
Erik Gilling1d21a9c2010-12-01 16:38:01 -080026#include <utils/String8.h>
Mathias Agopian5f2165f2012-02-24 18:25:41 -080027
28#include <ui/ANativeObjectBase.h>
Mathias Agopian076b1cc2009-04-10 14:24:30 -070029#include <ui/Rect.h>
30
Naseer Ahmed0bc64be2012-06-29 12:02:32 -070031#define MIN_NUM_FRAME_BUFFERS 2
32#define MAX_NUM_FRAME_BUFFERS 3
Mathias Agopian076b1cc2009-04-10 14:24:30 -070033
34extern "C" EGLNativeWindowType android_createDisplaySurface(void);
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -080035
36// ---------------------------------------------------------------------------
37namespace android {
38// ---------------------------------------------------------------------------
39
40class Surface;
Mathias Agopian7189c002009-05-05 18:11:11 -070041class NativeBuffer;
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -080042
Mathias Agopian076b1cc2009-04-10 14:24:30 -070043// ---------------------------------------------------------------------------
44
45class FramebufferNativeWindow
Mathias Agopian5f2165f2012-02-24 18:25:41 -080046 : public ANativeObjectBase<
Dianne Hackborn4b5e91e2010-06-30 13:56:17 -070047 ANativeWindow,
Mathias Agopian076b1cc2009-04-10 14:24:30 -070048 FramebufferNativeWindow,
49 LightRefBase<FramebufferNativeWindow> >
50{
51public:
52 FramebufferNativeWindow();
53
54 framebuffer_device_t const * getDevice() const { return fbDev; }
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -080055
Mathias Agopian1e16b132009-05-07 17:40:23 -070056 bool isUpdateOnDemand() const { return mUpdateOnDemand; }
57 status_t setUpdateRectangle(const Rect& updateRect);
Mathias Agopian74faca22009-09-17 16:18:16 -070058 status_t compositionComplete();
Erik Gilling1d21a9c2010-12-01 16:38:01 -080059
60 void dump(String8& result);
61
Mathias Agopian35b48d12010-09-13 22:57:58 -070062 // for debugging only
63 int getCurrentBufferIndex() const;
64
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -080065private:
Mathias Agopian076b1cc2009-04-10 14:24:30 -070066 friend class LightRefBase<FramebufferNativeWindow>;
67 ~FramebufferNativeWindow(); // this class cannot be overloaded
Dianne Hackborn4b5e91e2010-06-30 13:56:17 -070068 static int setSwapInterval(ANativeWindow* window, int interval);
Jamie Gennisd8e812c2012-06-13 16:32:25 -070069 static int dequeueBuffer(ANativeWindow* window, ANativeWindowBuffer** buffer, int* fenceFd);
70 static int queueBuffer(ANativeWindow* window, ANativeWindowBuffer* buffer, int fenceFd);
Iliyan Malchev41abd672011-04-14 16:54:38 -070071 static int query(const ANativeWindow* window, int what, int* value);
Dianne Hackborn4b5e91e2010-06-30 13:56:17 -070072 static int perform(ANativeWindow* window, int operation, ...);
Jamie Gennisd8e812c2012-06-13 16:32:25 -070073
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
Mathias Agopian076b1cc2009-04-10 14:24:30 -070078 framebuffer_device_t* fbDev;
79 alloc_device_t* grDev;
80
Naseer Ahmed0bc64be2012-06-29 12:02:32 -070081 sp<NativeBuffer> buffers[MAX_NUM_FRAME_BUFFERS];
Mathias Agopian076b1cc2009-04-10 14:24:30 -070082 sp<NativeBuffer> front;
83
Mathias Agopian076b1cc2009-04-10 14:24:30 -070084 mutable Mutex mutex;
85 Condition mCondition;
86 int32_t mNumBuffers;
87 int32_t mNumFreeBuffers;
88 int32_t mBufferHead;
Mathias Agopian35b48d12010-09-13 22:57:58 -070089 int32_t mCurrentBufferIndex;
Mathias Agopian1e16b132009-05-07 17:40:23 -070090 bool mUpdateOnDemand;
Mathias Agopian69029eb2009-06-23 21:11:43 -070091};
92
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -080093// ---------------------------------------------------------------------------
94}; // namespace android
95// ---------------------------------------------------------------------------
96
Mathias Agopian0926f502009-05-04 14:17:04 -070097#endif // ANDROID_FRAMEBUFFER_NATIVE_WINDOW_H
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -080098