blob: 9a78b99762202454de54e71635949875a7283424 [file] [log] [blame]
The Android Open Source Project7c1b96a2008-10-21 07:00:00 -07001/*
2 * Copyright (C) 2008 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_GPU_HARDWARE_H
18#define ANDROID_GPU_HARDWARE_H
19
20#include <stdint.h>
21#include <sys/types.h>
22
23#include <utils/RefBase.h>
24#include <utils/threads.h>
25
26namespace android {
27
28// ---------------------------------------------------------------------------
29
30class GPUHardwareInterface : public RefBase
31{
32public:
33 virtual void revoke(int pid) = 0;
34 virtual sp<MemoryDealer> request(int pid) = 0;
35 virtual status_t request(const sp<IGPUCallback>& callback,
36 ISurfaceComposer::gpu_info_t* gpu) = 0;
37
38 virtual status_t friendlyRevoke() = 0;
39 virtual void unconditionalRevoke() = 0;
40
41 // used for debugging only...
42 virtual sp<SimpleBestFitAllocator> getAllocator() const = 0;
43 virtual pid_t getOwner() const = 0;
44};
45
46// ---------------------------------------------------------------------------
47
48class IMemory;
49class MemoryHeapPmem;
50class PMemHeap;
51
52class GPUHardware : public GPUHardwareInterface
53{
54public:
55 GPUHardware();
56 virtual ~GPUHardware();
57
58 virtual void revoke(int pid);
59 virtual sp<MemoryDealer> request(int pid);
60 virtual status_t request(const sp<IGPUCallback>& callback,
61 ISurfaceComposer::gpu_info_t* gpu);
62
63 virtual status_t friendlyRevoke();
64 virtual void unconditionalRevoke();
65
66 // used for debugging only...
67 virtual sp<SimpleBestFitAllocator> getAllocator() const;
68 virtual pid_t getOwner() const { return mOwner; }
69
70private:
71 enum {
72 NO_OWNER = -1,
73 SURFACE_FAILED = -2
74 };
75
76 void requestLocked();
77 void releaseLocked(bool dispose = false);
78 void takeBackGPULocked();
79
80 class GPUPart
81 {
82 public:
83 bool surface;
84 size_t reserved;
85 GPUPart();
86 ~GPUPart();
87 const sp<PMemHeapInterface>& getHeap() const;
88 const sp<MemoryHeapPmem>& getClientHeap() const;
89 bool isValid() const;
90 void clear();
91 void set(const sp<PMemHeapInterface>& heap);
92 bool promote();
93 sp<IMemory> map(bool clear = false);
94 void release(bool dispose);
95 private:
96 sp<PMemHeapInterface> mHeap;
97 wp<PMemHeapInterface> mHeapWeak;
98 sp<MemoryHeapPmem> mClientHeap;
99 };
100
101 mutable Mutex mLock;
102 GPUPart mHeap0; // SMI
103 GPUPart mHeap1; // EBI1
104 GPUPart mHeapR;
105 sp<MemoryDealer> mAllocator;
106 pid_t mOwner;
107 sp<IGPUCallback> mCallback;
108 wp<SimpleBestFitAllocator> mAllocatorDebug;
109
110 Condition mCondition;
111};
112
113// ---------------------------------------------------------------------------
114}; // namespace android
115
116#endif // ANDROID_GPU_HARDWARE_H