blob: 90f1138f8392edac5d35007d8b44ff20f2fd8452 [file] [log] [blame]
Steve Kondik55db0532017-06-12 11:27:18 -07001/*
2 * Copyright 2014 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 VDS_H
18#define VDS_H
19
Steve Kondik55db0532017-06-12 11:27:18 -070020#include "Program.h"
21#include "EglWindow.h"
22
23#include <gui/BufferQueue.h>
24#include <gui/GLConsumer.h>
25#include <gui/IGraphicBufferProducer.h>
26#include <ui/DisplayInfo.h>
27#include <utils/Thread.h>
28
Steve Kondikdda11002017-06-13 08:20:27 -070029#include <rfb/rfb.h>
Steve Kondik55db0532017-06-12 11:27:18 -070030
31#define NUM_PBO 2
32
33namespace android {
34
35/*
36 * Support for "frames" output format.
37 */
38class VirtualDisplay : public GLConsumer::FrameAvailableListener, Thread {
39public:
Steve Kondikdda11002017-06-13 08:20:27 -070040 VirtualDisplay(rfbScreenInfoPtr vncScreen) : Thread(false),
41 mVNCScreen(vncScreen),
Steve Kondik55db0532017-06-12 11:27:18 -070042 mThreadResult(UNKNOWN_ERROR),
43 mState(UNINITIALIZED),
44 mIndex(0)
45 {}
46
47 // Create an "input surface", similar in purpose to a MediaCodec input
48 // surface, that the virtual display can send buffers to. Also configures
49 // EGL with a pbuffer surface on the current thread.
Steve Kondik7225c7f2017-06-14 00:06:16 -070050 virtual status_t start(const DisplayInfo& mainDpyInfo);
Steve Kondik55db0532017-06-12 11:27:18 -070051
Steve Kondikdda11002017-06-13 08:20:27 -070052 virtual status_t stop();
Steve Kondik55db0532017-06-12 11:27:18 -070053
54 static bool isDeviceRotated(int orientation);
55
56private:
57 VirtualDisplay(const VirtualDisplay&);
58 VirtualDisplay& operator=(const VirtualDisplay&);
59
60 // Destruction via RefBase.
61 virtual ~VirtualDisplay() {
62 assert(mState == UNINITIALIZED || mState == STOPPED);
63 }
64
65 virtual status_t setDisplayProjection(const sp<IBinder>& dpy,
66 const DisplayInfo& mainDpyInfo);
67
68 // (overrides GLConsumer::FrameAvailableListener method)
69 virtual void onFrameAvailable(const BufferItem& item);
70
71 // (overrides Thread method)
72 virtual bool threadLoop();
73
74 // One-time setup (essentially object construction on the overlay thread).
75 status_t setup_l();
76
77 // Release all resources held.
78 void release_l();
79
80 // Process a frame received from the virtual display.
81 void* processFrame_l();
82
Steve Kondikdda11002017-06-13 08:20:27 -070083 rfbScreenInfoPtr mVNCScreen;
84
Steve Kondik55db0532017-06-12 11:27:18 -070085 uint32_t mHeight, mWidth;
86 bool mRotate;
87
Steve Kondik55db0532017-06-12 11:27:18 -070088 // Used to wait for the FrameAvailableListener callback.
89 Mutex mMutex;
90
91 // Initialization gate.
92 Condition mStartCond;
93
94 // Thread status, mostly useful during startup.
95 status_t mThreadResult;
Steve Kondik7225c7f2017-06-14 00:06:16 -070096
Steve Kondik55db0532017-06-12 11:27:18 -070097 // Overlay thread state. States advance from left to right; object may
98 // not be restarted.
99 enum { UNINITIALIZED, INIT, RUNNING, STOPPING, STOPPED } mState;
100
101 // Event notification. Overlay thread sleeps on this until a frame
102 // arrives or it's time to shut down.
103 Condition mEventCond;
104
105 // Producer side of queue, passed into the virtual display.
106 // The consumer end feeds into our GLConsumer.
107 sp<IGraphicBufferProducer> mProducer;
108
109 // This receives frames from the virtual display and makes them available
110 // as an external texture.
111 sp<GLConsumer> mGlConsumer;
112
113 // EGL display / context / surface.
114 EglWindow mEglWindow;
115
116 // GL rendering support.
117 Program mExtTexProgram;
118
119 // External texture, updated by GLConsumer.
120 GLuint mExtTextureName;
121
122 // Pixel data buffers.
123 size_t mBufSize;
Steve Kondik55db0532017-06-12 11:27:18 -0700124 GLuint* mPBO;
125 unsigned int mIndex;
126
127 sp<IBinder> mDpy;
128};
129
130}; // namespace android
131
132#endif /* VDS_H */