blob: 0d810370c47c2aa09d995c0a223296a6601d79e6 [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)
31 : 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 }
36 static bool isValid(const sp<Surface>& surface) { return surface != nullptr; }
37 void allocateBuffers() {}
38
39 uint64_t getNextFrameNumber() const { return 0; }
40
41 int setScalingMode(int mode) { return 0; }
42
43 virtual int disconnect(int api,
44 IGraphicBufferProducer::DisconnectMode mode =
45 IGraphicBufferProducer::DisconnectMode::Api) {
46 return 0;
47 }
48
49 virtual int lock(ANativeWindow_Buffer* outBuffer, ARect* inOutDirtyBounds) {
50 // TODO: implement this
51 return 0;
52 }
53 virtual int unlockAndPost() { return 0; }
Jerome Gaillard52f95ff2024-04-23 12:58:59 +010054 virtual int query(int what, int* value) const { return mBufferProducer->query(what, value); }
55
56 status_t setDequeueTimeout(nsecs_t timeout) { return OK; }
57
58 nsecs_t getLastDequeueStartTime() const { return 0; }
Fedor Kudasova8871162019-07-04 12:54:28 +010059
Jerome Gaillard8db3da52021-09-10 10:46:28 +010060 virtual void destroy() {}
61
Jerome Gaillardda745d22024-04-16 14:06:37 +010062 int getBuffersDataSpace() { return 0; }
63
Fedor Kudasova8871162019-07-04 12:54:28 +010064protected:
65 virtual ~Surface() {}
66
Jerome Gaillard52f95ff2024-04-23 12:58:59 +010067 static int hook_perform(ANativeWindow* window, int operation, ...) {
68 va_list args;
69 va_start(args, operation);
70 Surface* c = getSelf(window);
71 int result = c->perform(operation, args);
72 va_end(args);
73 return result;
74 }
75
76 static int hook_query(const ANativeWindow* window, int what, int* value) {
77 const Surface* c = getSelf(window);
78 return c->query(what, value);
79 }
80
81 static int hook_dequeueBuffer(ANativeWindow* window, ANativeWindowBuffer** buffer,
82 int* fenceFd) {
83 Surface* c = getSelf(window);
84 return c->dequeueBuffer(buffer, fenceFd);
85 }
86
87 virtual int dequeueBuffer(ANativeWindowBuffer** buffer, int* fenceFd) {
88 mBufferProducer->requestBuffer(0, &mBuffer);
89 *buffer = mBuffer.get();
90 return OK;
91 }
92 virtual int cancelBuffer(ANativeWindowBuffer* buffer, int fenceFd) { return 0; }
93 virtual int queueBuffer(ANativeWindowBuffer* buffer, int fenceFd) { return 0; }
94 virtual int perform(int operation, va_list args) { return 0; }
95 virtual int setSwapInterval(int interval) { return 0; }
96 virtual int setBufferCount(int bufferCount) { return 0; }
Fedor Kudasova8871162019-07-04 12:54:28 +010097
98private:
99 // can't be copied
100 Surface& operator=(const Surface& rhs);
101 Surface(const Surface& rhs);
Jerome Gaillard52f95ff2024-04-23 12:58:59 +0100102
103 const sp<IGraphicBufferProducer> mBufferProducer;
104 sp<GraphicBuffer> mBuffer;
Fedor Kudasova8871162019-07-04 12:54:28 +0100105};
106
107} // namespace android
108
109#endif // ANDROID_GUI_SURFACE_H