Steve Kondik | 55db053 | 2017-06-12 11:27:18 -0700 | [diff] [blame] | 1 | /* |
| 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 Kondik | 55db053 | 2017-06-12 11:27:18 -0700 | [diff] [blame] | 20 | #include <gui/BufferQueue.h> |
Steve Kondik | ef4e865 | 2017-06-14 15:07:54 -0700 | [diff] [blame^] | 21 | #include <gui/CpuConsumer.h> |
Steve Kondik | 55db053 | 2017-06-12 11:27:18 -0700 | [diff] [blame] | 22 | #include <gui/IGraphicBufferProducer.h> |
| 23 | #include <ui/DisplayInfo.h> |
| 24 | #include <utils/Thread.h> |
| 25 | |
Steve Kondik | dda1100 | 2017-06-13 08:20:27 -0700 | [diff] [blame] | 26 | #include <rfb/rfb.h> |
Steve Kondik | 55db053 | 2017-06-12 11:27:18 -0700 | [diff] [blame] | 27 | |
| 28 | #define NUM_PBO 2 |
| 29 | |
| 30 | namespace android { |
| 31 | |
| 32 | /* |
| 33 | * Support for "frames" output format. |
| 34 | */ |
Steve Kondik | ef4e865 | 2017-06-14 15:07:54 -0700 | [diff] [blame^] | 35 | class VirtualDisplay : public CpuConsumer::FrameAvailableListener, Thread { |
Steve Kondik | 55db053 | 2017-06-12 11:27:18 -0700 | [diff] [blame] | 36 | public: |
Steve Kondik | ef4e865 | 2017-06-14 15:07:54 -0700 | [diff] [blame^] | 37 | VirtualDisplay(rfbScreenInfoPtr vncScreen, Mutex *updateMutex) : Thread(false), |
Steve Kondik | dda1100 | 2017-06-13 08:20:27 -0700 | [diff] [blame] | 38 | mVNCScreen(vncScreen), |
Steve Kondik | ef4e865 | 2017-06-14 15:07:54 -0700 | [diff] [blame^] | 39 | mUpdateMutex(updateMutex), |
Steve Kondik | 55db053 | 2017-06-12 11:27:18 -0700 | [diff] [blame] | 40 | mThreadResult(UNKNOWN_ERROR), |
Steve Kondik | ef4e865 | 2017-06-14 15:07:54 -0700 | [diff] [blame^] | 41 | mState(UNINITIALIZED) |
Steve Kondik | 55db053 | 2017-06-12 11:27:18 -0700 | [diff] [blame] | 42 | {} |
| 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 Kondik | 7225c7f | 2017-06-14 00:06:16 -0700 | [diff] [blame] | 47 | virtual status_t start(const DisplayInfo& mainDpyInfo); |
Steve Kondik | 55db053 | 2017-06-12 11:27:18 -0700 | [diff] [blame] | 48 | |
Steve Kondik | dda1100 | 2017-06-13 08:20:27 -0700 | [diff] [blame] | 49 | virtual status_t stop(); |
Steve Kondik | 55db053 | 2017-06-12 11:27:18 -0700 | [diff] [blame] | 50 | |
| 51 | static bool isDeviceRotated(int orientation); |
| 52 | |
| 53 | private: |
| 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 Kondik | dda1100 | 2017-06-13 08:20:27 -0700 | [diff] [blame] | 80 | rfbScreenInfoPtr mVNCScreen; |
Steve Kondik | ef4e865 | 2017-06-14 15:07:54 -0700 | [diff] [blame^] | 81 | Mutex *mUpdateMutex; |
Steve Kondik | dda1100 | 2017-06-13 08:20:27 -0700 | [diff] [blame] | 82 | |
Steve Kondik | 55db053 | 2017-06-12 11:27:18 -0700 | [diff] [blame] | 83 | uint32_t mHeight, mWidth; |
| 84 | bool mRotate; |
| 85 | |
Steve Kondik | 55db053 | 2017-06-12 11:27:18 -0700 | [diff] [blame] | 86 | // 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 Kondik | 7225c7f | 2017-06-14 00:06:16 -0700 | [diff] [blame] | 94 | |
Steve Kondik | 55db053 | 2017-06-12 11:27:18 -0700 | [diff] [blame] | 95 | // 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 Kondik | ef4e865 | 2017-06-14 15:07:54 -0700 | [diff] [blame^] | 108 | sp<CpuConsumer> mCpuConsumer; |
Steve Kondik | 55db053 | 2017-06-12 11:27:18 -0700 | [diff] [blame] | 109 | |
| 110 | sp<IBinder> mDpy; |
| 111 | }; |
| 112 | |
| 113 | }; // namespace android |
| 114 | |
| 115 | #endif /* VDS_H */ |