blob: 2774f89cb54c465bacc83c19240aff5c313701a8 [file] [log] [blame]
Fedor Kudasova8871162019-07-04 12:54:28 +01001/*
2 * Copyright (C) 2019 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_GUI_SURFACE_H
18#define ANDROID_GUI_SURFACE_H
19
Jerome Gaillard52f95ff2024-04-23 12:58:59 +010020#include <system/window.h>
Fedor Kudasova8871162019-07-04 12:54:28 +010021#include <ui/ANativeObjectBase.h>
22#include <utils/RefBase.h>
Jerome Gaillard52f95ff2024-04-23 12:58:59 +010023
24#include "gui/IGraphicBufferProducer.h"
Fedor Kudasova8871162019-07-04 12:54:28 +010025
26namespace android {
27
28class Surface : public ANativeObjectBase<ANativeWindow, Surface, RefBase> {
29public:
Jerome Gaillard52f95ff2024-04-23 12:58:59 +010030 explicit Surface(const sp<IGraphicBufferProducer>& bufferProducer, bool controlledByApp = false)
Jerome Gaillardc935f272024-04-23 14:26:29 +010031 : mBufferProducer(bufferProducer) {
Fedor Kudasova8871162019-07-04 12:54:28 +010032 ANativeWindow::perform = hook_perform;
Jerome Gaillard52f95ff2024-04-23 12:58:59 +010033 ANativeWindow::dequeueBuffer = hook_dequeueBuffer;
34 ANativeWindow::query = hook_query;
Fedor Kudasova8871162019-07-04 12:54:28 +010035 }
Jerome Gaillardc935f272024-04-23 14:26:29 +010036
37 static bool isValid(const sp<Surface>& surface) {
38 return surface != nullptr;
39 }
40
Fedor Kudasova8871162019-07-04 12:54:28 +010041 void allocateBuffers() {}
42
Jerome Gaillardc935f272024-04-23 14:26:29 +010043 uint64_t getNextFrameNumber() const {
44 return 0;
45 }
Fedor Kudasova8871162019-07-04 12:54:28 +010046
Jerome Gaillardc935f272024-04-23 14:26:29 +010047 int setScalingMode(int mode) {
48 return 0;
49 }
Fedor Kudasova8871162019-07-04 12:54:28 +010050
51 virtual int disconnect(int api,
52 IGraphicBufferProducer::DisconnectMode mode =
53 IGraphicBufferProducer::DisconnectMode::Api) {
54 return 0;
55 }
56
57 virtual int lock(ANativeWindow_Buffer* outBuffer, ARect* inOutDirtyBounds) {
58 // TODO: implement this
59 return 0;
60 }
Jerome Gaillard52f95ff2024-04-23 12:58:59 +010061
Jerome Gaillardc935f272024-04-23 14:26:29 +010062 virtual int unlockAndPost() {
63 return 0;
64 }
Jerome Gaillard52f95ff2024-04-23 12:58:59 +010065
Jerome Gaillardc935f272024-04-23 14:26:29 +010066 virtual int query(int what, int* value) const {
67 return mBufferProducer->query(what, value);
68 }
69
70 status_t setDequeueTimeout(nsecs_t timeout) {
71 return OK;
72 }
73
74 nsecs_t getLastDequeueStartTime() const {
75 return 0;
76 }
Fedor Kudasova8871162019-07-04 12:54:28 +010077
Jerome Gaillard8db3da52021-09-10 10:46:28 +010078 virtual void destroy() {}
79
Jerome Gaillardc935f272024-04-23 14:26:29 +010080 int getBuffersDataSpace() {
81 return 0;
82 }
Jerome Gaillardda745d22024-04-16 14:06:37 +010083
Fedor Kudasova8871162019-07-04 12:54:28 +010084protected:
85 virtual ~Surface() {}
86
Jerome Gaillard52f95ff2024-04-23 12:58:59 +010087 static int hook_perform(ANativeWindow* window, int operation, ...) {
88 va_list args;
89 va_start(args, operation);
90 Surface* c = getSelf(window);
91 int result = c->perform(operation, args);
92 va_end(args);
93 return result;
94 }
95
96 static int hook_query(const ANativeWindow* window, int what, int* value) {
97 const Surface* c = getSelf(window);
98 return c->query(what, value);
99 }
100
101 static int hook_dequeueBuffer(ANativeWindow* window, ANativeWindowBuffer** buffer,
102 int* fenceFd) {
103 Surface* c = getSelf(window);
104 return c->dequeueBuffer(buffer, fenceFd);
105 }
106
107 virtual int dequeueBuffer(ANativeWindowBuffer** buffer, int* fenceFd) {
108 mBufferProducer->requestBuffer(0, &mBuffer);
109 *buffer = mBuffer.get();
110 return OK;
111 }
Jerome Gaillardc935f272024-04-23 14:26:29 +0100112
113 virtual int cancelBuffer(ANativeWindowBuffer* buffer, int fenceFd) {
114 return 0;
115 }
116
117 virtual int queueBuffer(ANativeWindowBuffer* buffer, int fenceFd) {
118 return 0;
119 }
120
121 virtual int perform(int operation, va_list args) {
122 return 0;
123 }
124
125 virtual int setSwapInterval(int interval) {
126 return 0;
127 }
128
129 virtual int setBufferCount(int bufferCount) {
130 return 0;
131 }
Fedor Kudasova8871162019-07-04 12:54:28 +0100132
133private:
134 // can't be copied
135 Surface& operator=(const Surface& rhs);
Jerome Gaillardc935f272024-04-23 14:26:29 +0100136
Fedor Kudasova8871162019-07-04 12:54:28 +0100137 Surface(const Surface& rhs);
Jerome Gaillard52f95ff2024-04-23 12:58:59 +0100138
139 const sp<IGraphicBufferProducer> mBufferProducer;
140 sp<GraphicBuffer> mBuffer;
Fedor Kudasova8871162019-07-04 12:54:28 +0100141};
142
143} // namespace android
144
Jerome Gaillardc935f272024-04-23 14:26:29 +0100145#endif // ANDROID_GUI_SURFACE_H