blob: 16474b8af05698ba097c678fcba42cf81250543c [file] [log] [blame]
Andy Qiu8a427142013-04-05 17:41:58 -07001/*
2 * Copyright © 2012 Intel Corporation
3 * All rights reserved.
4 *
5 * Permission is hereby granted, free of charge, to any person obtaining a
6 * copy of this software and associated documentation files (the "Software"),
7 * to deal in the Software without restriction, including without limitation
8 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
9 * and/or sell copies of the Software, and to permit persons to whom the
10 * Software is furnished to do so, subject to the following conditions:
11 *
12 * The above copyright notice and this permission notice (including the next
13 * paragraph) shall be included in all copies or substantial portions of the
14 * Software.
15 *
16 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
19 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
21 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
22 * IN THE SOFTWARE.
23 *
24 * Authors:
25 * Jackie Li <yaodong.li@intel.com>
26 *
27 */
28#ifndef VIRTUAL_DEVICE_H
29#define VIRTUAL_DEVICE_H
30
Andy Qiu8a427142013-04-05 17:41:58 -070031#include <IDisplayDevice.h>
Brian Rogersc40736e2014-03-31 14:40:11 -070032#include <SimpleThread.h>
Brian Rogers1384af52014-05-21 12:13:17 -070033#include <IVideoPayloadManager.h>
Brian Rogersc40736e2014-03-31 14:40:11 -070034#include <utils/Condition.h>
35#include <utils/Mutex.h>
Brian Rogers1384af52014-05-21 12:13:17 -070036#include <utils/Vector.h>
37
Ashish Singhi196e5bd2013-04-17 18:26:37 -070038#include "IFrameServer.h"
Andy Qiu8a427142013-04-05 17:41:58 -070039
Brian Rogers1384af52014-05-21 12:13:17 -070040#include <va/va.h>
41#include <va/va_vpp.h>
42
Andy Qiu8a427142013-04-05 17:41:58 -070043namespace android {
44namespace intel {
45
46class Hwcomposer;
47class DisplayPlaneManager;
Robert Crabtree2e984ef2013-05-07 14:27:47 -070048class IVideoPayloadManager;
Andy Qiu177b44e2013-11-07 18:03:02 -080049class SoftVsyncObserver;
Andy Qiu8a427142013-04-05 17:41:58 -070050
Ashish Singhi196e5bd2013-04-17 18:26:37 -070051class VirtualDevice : public IDisplayDevice, public BnFrameServer {
Ashish Singhi77b747d2013-04-26 14:30:05 -070052protected:
Brian Rogers1384af52014-05-21 12:13:17 -070053 class VAMappedHandle;
Robert Crabtree2e984ef2013-05-07 14:27:47 -070054 struct CachedBuffer : public android::RefBase {
mamatha balgurid2483962013-07-11 13:38:48 -070055 CachedBuffer(BufferManager *mgr, uint32_t handle);
Robert Crabtree2e984ef2013-05-07 14:27:47 -070056 ~CachedBuffer();
57 BufferManager *manager;
Robert Crabtree2e984ef2013-05-07 14:27:47 -070058 BufferMapper *mapper;
Brian Rogers1384af52014-05-21 12:13:17 -070059 VAMappedHandle *vaMappedHandle;
Robert Crabtree2e984ef2013-05-07 14:27:47 -070060 };
mamatha balgurid2483962013-07-11 13:38:48 -070061 struct HeldCscBuffer : public android::RefBase {
62 HeldCscBuffer(const android::sp<VirtualDevice>& vd, uint32_t handle);
63 virtual ~HeldCscBuffer();
64 android::sp<VirtualDevice> vd;
65 uint32_t handle;
66 };
67 struct HeldDecoderBuffer : public android::RefBase {
68 HeldDecoderBuffer(const sp<VirtualDevice>& vd, const android::sp<CachedBuffer>& cachedBuffer);
69 virtual ~HeldDecoderBuffer();
70 android::sp<VirtualDevice> vd;
71 android::sp<CachedBuffer> cachedBuffer;
72 };
Ashish Singhi77b747d2013-04-26 14:30:05 -070073 struct Configuration {
74 sp<IFrameTypeChangeListener> typeChangeListener;
75 sp<IFrameListener> frameListener;
76 FrameProcessingPolicy policy;
Brian Rogersf24ae212014-04-30 14:50:24 -070077 bool frameServerActive;
Ashish Singhi77b747d2013-04-26 14:30:05 -070078 bool extendedModeEnabled;
Robert Crabtree7d844a22013-08-27 14:00:15 -070079 bool forceNotifyFrameType;
80 bool forceNotifyBufferInfo;
Ashish Singhi77b747d2013-04-26 14:30:05 -070081 };
Brian Rogers1384af52014-05-21 12:13:17 -070082 struct Task;
83 struct RenderTask;
84 struct ComposeTask;
85 struct DisableVspTask;
86 struct BlitTask;
87 struct FrameTypeChangedTask;
88 struct BufferInfoChangedTask;
89 struct OnFrameReadyTask;
Brian Rogersf24ae212014-04-30 14:50:24 -070090 struct ied_block {
91 uint8_t data[16];
92 };
93 ied_block mBlackY;
94 ied_block mBlackUV;
95
Ashish Singhi77b747d2013-04-26 14:30:05 -070096 Mutex mConfigLock;
97 Configuration mCurrentConfig;
98 Configuration mNextConfig;
Brian Rogers1384af52014-05-21 12:13:17 -070099 ssize_t mRgbLayer;
100 ssize_t mYuvLayer;
101 bool mProtectedMode;
Ashish Singhi77b747d2013-04-26 14:30:05 -0700102
103 uint32_t mExtLastKhandle;
104 int64_t mExtLastTimestamp;
105
mamatha balgurid2483962013-07-11 13:38:48 -0700106 int64_t mRenderTimestamp;
Robert Crabtree2e984ef2013-05-07 14:27:47 -0700107
mamatha balgurid2483962013-07-11 13:38:48 -0700108 // colorspace conversion
109 Mutex mCscLock;
110 android::List<uint32_t> mAvailableCscBuffers;
111 int mCscBuffersToCreate;
112 uint32_t mCscWidth;
113 uint32_t mCscHeight;
114
Brian Rogers1384af52014-05-21 12:13:17 -0700115 // fence info
116 int mSyncTimelineFd;
117 unsigned mNextSyncPoint;
118
Brian Rogersc40736e2014-03-31 14:40:11 -0700119 // async blit info
120 DECLARE_THREAD(WidiBlitThread, VirtualDevice);
121 Condition mRequestQueued;
Brian Rogers1384af52014-05-21 12:13:17 -0700122 Condition mRequestDequeued;
123 Vector< sp<Task> > mTasks;
Brian Rogersf24ae212014-04-30 14:50:24 -0700124
mamatha balgurid2483962013-07-11 13:38:48 -0700125 FrameInfo mLastInputFrameInfo;
126 FrameInfo mLastOutputFrameInfo;
127
Robert Crabtreec2a96b12013-10-22 18:18:15 -0700128 int32_t mVideoFramerate;
129
mamatha balgurid2483962013-07-11 13:38:48 -0700130 android::KeyedVector<uint32_t, android::sp<CachedBuffer> > mMappedBufferCache;
Robert Crabtree2e984ef2013-05-07 14:27:47 -0700131 android::Mutex mHeldBuffersLock;
mamatha balgurid2483962013-07-11 13:38:48 -0700132 android::KeyedVector<uint32_t, android::sp<android::RefBase> > mHeldBuffers;
Robert Crabtree2e984ef2013-05-07 14:27:47 -0700133
Brian Rogers1384af52014-05-21 12:13:17 -0700134 // VSP
135 bool mVspInUse;
136 bool mVspEnabled;
137 VADisplay va_dpy;
138 VAConfigID va_config;
139 VAContextID va_context;
140 VASurfaceID va_video_in;
141
142 // scaling info
143 uint32_t mLastScaleWidth;
144 uint32_t mLastScaleHeight;
145
Robert Crabtree2e984ef2013-05-07 14:27:47 -0700146private:
Brian Rogers1384af52014-05-21 12:13:17 -0700147 uint32_t getCscBuffer(uint32_t width, uint32_t height);
Brian Rogersf24ae212014-04-30 14:50:24 -0700148 void clearCscBuffers();
mamatha balgurid2483962013-07-11 13:38:48 -0700149 android::sp<CachedBuffer> getMappedBuffer(uint32_t handle);
Brian Rogers1384af52014-05-21 12:13:17 -0700150
151 bool sendToWidi(hwc_display_contents_1_t *display);
152 bool queueCompose(hwc_display_contents_1_t *display);
153 bool queueColorConvert(hwc_display_contents_1_t *display);
154 bool handleExtendedMode(hwc_display_contents_1_t *display);
155 bool queueVideoCopy(hwc_display_contents_1_t *display);
156
157 void queueFrameTypeInfo(const FrameInfo& inputFrameInfo);
158 void queueBufferInfo(const FrameInfo& outputFrameInfo);
Robert Crabtree2e984ef2013-05-07 14:27:47 -0700159
Brian Rogersf24ae212014-04-30 14:50:24 -0700160 static void fill(uint8_t* ptr, const ied_block& data, size_t len);
Brian Rogers1384af52014-05-21 12:13:17 -0700161 void copyVideo(uint8_t* srcPtr, uint32_t srcWidth, uint32_t srcHeight, uint32_t srcStride,
162 uint8_t* destPtr, uint32_t destWidth, uint32_t destHeight,
163 uint32_t outX, uint32_t outY, uint32_t width, uint32_t height);
Brian Rogersfc3539e2014-05-19 20:16:21 -0700164 void colorSwap(buffer_handle_t src, buffer_handle_t dest, uint32_t pixelCount);
Brian Rogers1384af52014-05-21 12:13:17 -0700165 void vspEnable(uint32_t width, uint32_t height);
166 void vspDisable();
167 void vspCompose(VASurfaceID videoIn, VASurfaceID rgbIn, VASurfaceID videoOut);
Brian Rogersf24ae212014-04-30 14:50:24 -0700168
Andy Qiu8a427142013-04-05 17:41:58 -0700169public:
170 VirtualDevice(Hwcomposer& hwc, DisplayPlaneManager& dpm);
171 virtual ~VirtualDevice();
172
173public:
174 virtual bool prePrepare(hwc_display_contents_1_t *display);
175 virtual bool prepare(hwc_display_contents_1_t *display);
176 virtual bool commit(hwc_display_contents_1_t *display,
Andy Qiu4b834ce2013-04-09 18:23:20 -0700177 IDisplayContext *context);
Andy Qiu8a427142013-04-05 17:41:58 -0700178
Andy Qiueb726af2013-05-31 11:51:49 +0800179 virtual bool vsyncControl(bool enabled);
180 virtual bool blank(bool blank);
Andy Qiu0131f122013-07-19 14:51:20 -0700181 virtual bool getDisplaySize(int *width, int *height);
Andy Qiu8a427142013-04-05 17:41:58 -0700182 virtual bool getDisplayConfigs(uint32_t *configs,
183 size_t *numConfigs);
184 virtual bool getDisplayAttributes(uint32_t config,
185 const uint32_t *attributes,
186 int32_t *values);
187 virtual bool compositionComplete();
188 virtual bool initialize();
fu jine2ad4c02013-05-28 13:47:51 -0700189 virtual void deinitialize();
Andy Qiu8a427142013-04-05 17:41:58 -0700190 virtual bool isConnected() const;
191 virtual const char* getName() const;
192 virtual int getType() const;
Andy Qiu177b44e2013-11-07 18:03:02 -0800193 virtual void onVsync(int64_t timestamp);
Andy Qiu8a427142013-04-05 17:41:58 -0700194 virtual void dump(Dump& d);
195
Ashish Singhi196e5bd2013-04-17 18:26:37 -0700196 // IFrameServer methods
Arindam Roy82757462013-07-29 17:10:44 -0700197 virtual android::status_t start(sp<IFrameTypeChangeListener> frameTypeChangeListener);
Ashish Singhi196e5bd2013-04-17 18:26:37 -0700198 virtual android::status_t stop(bool isConnected);
199 virtual android::status_t notifyBufferReturned(int index);
Ashish Singhi77b747d2013-04-26 14:30:05 -0700200 virtual android::status_t setResolution(const FrameProcessingPolicy& policy, android::sp<IFrameListener> listener);
Andy Qiu8a427142013-04-05 17:41:58 -0700201protected:
Robert Crabtree2e984ef2013-05-07 14:27:47 -0700202 virtual IVideoPayloadManager* createVideoPayloadManager() = 0;
Andy Qiu8a427142013-04-05 17:41:58 -0700203
204protected:
205 bool mInitialized;
206 Hwcomposer& mHwc;
207 DisplayPlaneManager& mDisplayPlaneManager;
Robert Crabtree2e984ef2013-05-07 14:27:47 -0700208 IVideoPayloadManager *mPayloadManager;
Andy Qiu177b44e2013-11-07 18:03:02 -0800209 SoftVsyncObserver *mVsyncObserver;
Ashish Singhi3895d9b2013-11-04 14:43:33 -0800210 uint32_t mOrigContentWidth;
211 uint32_t mOrigContentHeight;
Robert Crabtree54565822013-12-10 17:02:03 -0800212 bool mFirstVideoFrame;
Brian Rogers1384af52014-05-21 12:13:17 -0700213 bool mLastConnectionStatus;
ljia58f33db82014-02-19 16:49:16 +0800214 uint32_t mCachedBufferCapcity;
Andy Qiu8a427142013-04-05 17:41:58 -0700215};
216
217}
218}
219
220#endif /* VIRTUAL_DEVICE_H */