blob: 57c2c928bcb7aac8ef8233338c1205cbad3b3cd9 [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 <gui/BufferQueue.h>
Steve Kondikef4e8652017-06-14 15:07:54 -070021#include <gui/CpuConsumer.h>
Steve Kondik55db0532017-06-12 11:27:18 -070022#include <gui/IGraphicBufferProducer.h>
23#include <ui/DisplayInfo.h>
24#include <utils/Thread.h>
25
Steve Kondikdda11002017-06-13 08:20:27 -070026#include <rfb/rfb.h>
Steve Kondik55db0532017-06-12 11:27:18 -070027
28#define NUM_PBO 2
29
30namespace android {
31
32/*
33 * Support for "frames" output format.
34 */
Steve Kondikef4e8652017-06-14 15:07:54 -070035class VirtualDisplay : public CpuConsumer::FrameAvailableListener, Thread {
Steve Kondik55db0532017-06-12 11:27:18 -070036public:
Steve Kondikef4e8652017-06-14 15:07:54 -070037 VirtualDisplay(rfbScreenInfoPtr vncScreen, Mutex *updateMutex) : Thread(false),
Steve Kondikdda11002017-06-13 08:20:27 -070038 mVNCScreen(vncScreen),
Steve Kondikef4e8652017-06-14 15:07:54 -070039 mUpdateMutex(updateMutex),
Steve Kondik55db0532017-06-12 11:27:18 -070040 mThreadResult(UNKNOWN_ERROR),
Steve Kondikef4e8652017-06-14 15:07:54 -070041 mState(UNINITIALIZED)
Steve Kondik55db0532017-06-12 11:27:18 -070042 {}
43
44 // Create an "input surface", similar in purpose to a MediaCodec input
45 // surface, that the virtual display can send buffers to. Also configures
46 // EGL with a pbuffer surface on the current thread.
Steve Kondik7225c7f2017-06-14 00:06:16 -070047 virtual status_t start(const DisplayInfo& mainDpyInfo);
Steve Kondik55db0532017-06-12 11:27:18 -070048
Steve Kondikdda11002017-06-13 08:20:27 -070049 virtual status_t stop();
Steve Kondik55db0532017-06-12 11:27:18 -070050
51 static bool isDeviceRotated(int orientation);
52
53private:
54 VirtualDisplay(const VirtualDisplay&);
55 VirtualDisplay& operator=(const VirtualDisplay&);
56
57 // Destruction via RefBase.
58 virtual ~VirtualDisplay() {
59 assert(mState == UNINITIALIZED || mState == STOPPED);
60 }
61
62 virtual status_t setDisplayProjection(const sp<IBinder>& dpy,
63 const DisplayInfo& mainDpyInfo);
64
65 // (overrides GLConsumer::FrameAvailableListener method)
66 virtual void onFrameAvailable(const BufferItem& item);
67
68 // (overrides Thread method)
69 virtual bool threadLoop();
70
71 // One-time setup (essentially object construction on the overlay thread).
72 status_t setup_l();
73
74 // Release all resources held.
75 void release_l();
76
77 // Process a frame received from the virtual display.
78 void* processFrame_l();
79
Steve Kondikdda11002017-06-13 08:20:27 -070080 rfbScreenInfoPtr mVNCScreen;
Steve Kondikef4e8652017-06-14 15:07:54 -070081 Mutex *mUpdateMutex;
Steve Kondikdda11002017-06-13 08:20:27 -070082
Steve Kondik55db0532017-06-12 11:27:18 -070083 uint32_t mHeight, mWidth;
84 bool mRotate;
85
Steve Kondik55db0532017-06-12 11:27:18 -070086 // Used to wait for the FrameAvailableListener callback.
87 Mutex mMutex;
88
89 // Initialization gate.
90 Condition mStartCond;
91
92 // Thread status, mostly useful during startup.
93 status_t mThreadResult;
Steve Kondik7225c7f2017-06-14 00:06:16 -070094
Steve Kondik55db0532017-06-12 11:27:18 -070095 // Overlay thread state. States advance from left to right; object may
96 // not be restarted.
97 enum { UNINITIALIZED, INIT, RUNNING, STOPPING, STOPPED } mState;
98
99 // Event notification. Overlay thread sleeps on this until a frame
100 // arrives or it's time to shut down.
101 Condition mEventCond;
102
103 // Producer side of queue, passed into the virtual display.
104 // The consumer end feeds into our GLConsumer.
105 sp<IGraphicBufferProducer> mProducer;
106
107 // This receives frames from the virtual display and makes them available
Steve Kondikef4e8652017-06-14 15:07:54 -0700108 sp<CpuConsumer> mCpuConsumer;
Steve Kondik55db0532017-06-12 11:27:18 -0700109
110 sp<IBinder> mDpy;
111};
112
113}; // namespace android
114
115#endif /* VDS_H */