blob: ccfb718877aa9e81fac0f5ca83086c1cdf3a9385 [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
30
31#define NUM_PBO 2
32
33namespace android {
34
35/*
36 * Support for "frames" output format.
37 */
38class VirtualDisplay : public GLConsumer::FrameAvailableListener, Thread {
39public:
40 VirtualDisplay() : Thread(false),
41 mThreadResult(UNKNOWN_ERROR),
42 mState(UNINITIALIZED),
43 mIndex(0)
44 {}
45
46 // Create an "input surface", similar in purpose to a MediaCodec input
47 // surface, that the virtual display can send buffers to. Also configures
48 // EGL with a pbuffer surface on the current thread.
49 status_t start(const DisplayInfo& mainDpyInfo, EventQueue *queue);
50
51 status_t stop();
52
53 static bool isDeviceRotated(int orientation);
54
55private:
56 VirtualDisplay(const VirtualDisplay&);
57 VirtualDisplay& operator=(const VirtualDisplay&);
58
59 // Destruction via RefBase.
60 virtual ~VirtualDisplay() {
61 assert(mState == UNINITIALIZED || mState == STOPPED);
62 }
63
64 virtual status_t setDisplayProjection(const sp<IBinder>& dpy,
65 const DisplayInfo& mainDpyInfo);
66
67 // (overrides GLConsumer::FrameAvailableListener method)
68 virtual void onFrameAvailable(const BufferItem& item);
69
70 // (overrides Thread method)
71 virtual bool threadLoop();
72
73 // One-time setup (essentially object construction on the overlay thread).
74 status_t setup_l();
75
76 // Release all resources held.
77 void release_l();
78
79 // Process a frame received from the virtual display.
80 void* processFrame_l();
81
82 uint32_t mHeight, mWidth;
83 bool mRotate;
84
85 EventQueue *mQueue;
86
87 // Used to wait for the FrameAvailableListener callback.
88 Mutex mMutex;
89
90 // Initialization gate.
91 Condition mStartCond;
92
93 // Thread status, mostly useful during startup.
94 status_t mThreadResult;
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
108 // as an external texture.
109 sp<GLConsumer> mGlConsumer;
110
111 // EGL display / context / surface.
112 EglWindow mEglWindow;
113
114 // GL rendering support.
115 Program mExtTexProgram;
116
117 // External texture, updated by GLConsumer.
118 GLuint mExtTextureName;
119
120 // Pixel data buffers.
121 size_t mBufSize;
122 GLuint* mPBO;
123 unsigned int mIndex;
124
125 sp<IBinder> mDpy;
126};
127
128}; // namespace android
129
130#endif /* VDS_H */