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