| Andy Qiu | 8a42714 | 2013-04-05 17:41:58 -0700 | [diff] [blame] | 1 | /* |
| 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 Qiu | 8a42714 | 2013-04-05 17:41:58 -0700 | [diff] [blame] | 31 | #include <IDisplayDevice.h> |
| Brian Rogers | c40736e | 2014-03-31 14:40:11 -0700 | [diff] [blame] | 32 | #include <SimpleThread.h> |
| Brian Rogers | 1384af5 | 2014-05-21 12:13:17 -0700 | [diff] [blame^] | 33 | #include <IVideoPayloadManager.h> |
| Brian Rogers | c40736e | 2014-03-31 14:40:11 -0700 | [diff] [blame] | 34 | #include <utils/Condition.h> |
| 35 | #include <utils/Mutex.h> |
| Brian Rogers | 1384af5 | 2014-05-21 12:13:17 -0700 | [diff] [blame^] | 36 | #include <utils/Vector.h> |
| 37 | |
| Ashish Singhi | 196e5bd | 2013-04-17 18:26:37 -0700 | [diff] [blame] | 38 | #include "IFrameServer.h" |
| Andy Qiu | 8a42714 | 2013-04-05 17:41:58 -0700 | [diff] [blame] | 39 | |
| Brian Rogers | 1384af5 | 2014-05-21 12:13:17 -0700 | [diff] [blame^] | 40 | #include <va/va.h> |
| 41 | #include <va/va_vpp.h> |
| 42 | |
| Andy Qiu | 8a42714 | 2013-04-05 17:41:58 -0700 | [diff] [blame] | 43 | namespace android { |
| 44 | namespace intel { |
| 45 | |
| 46 | class Hwcomposer; |
| 47 | class DisplayPlaneManager; |
| Robert Crabtree | 2e984ef | 2013-05-07 14:27:47 -0700 | [diff] [blame] | 48 | class IVideoPayloadManager; |
| Andy Qiu | 177b44e | 2013-11-07 18:03:02 -0800 | [diff] [blame] | 49 | class SoftVsyncObserver; |
| Andy Qiu | 8a42714 | 2013-04-05 17:41:58 -0700 | [diff] [blame] | 50 | |
| Ashish Singhi | 196e5bd | 2013-04-17 18:26:37 -0700 | [diff] [blame] | 51 | class VirtualDevice : public IDisplayDevice, public BnFrameServer { |
| Ashish Singhi | 77b747d | 2013-04-26 14:30:05 -0700 | [diff] [blame] | 52 | protected: |
| Brian Rogers | 1384af5 | 2014-05-21 12:13:17 -0700 | [diff] [blame^] | 53 | class VAMappedHandle; |
| Robert Crabtree | 2e984ef | 2013-05-07 14:27:47 -0700 | [diff] [blame] | 54 | struct CachedBuffer : public android::RefBase { |
| mamatha balguri | d248396 | 2013-07-11 13:38:48 -0700 | [diff] [blame] | 55 | CachedBuffer(BufferManager *mgr, uint32_t handle); |
| Robert Crabtree | 2e984ef | 2013-05-07 14:27:47 -0700 | [diff] [blame] | 56 | ~CachedBuffer(); |
| 57 | BufferManager *manager; |
| Robert Crabtree | 2e984ef | 2013-05-07 14:27:47 -0700 | [diff] [blame] | 58 | BufferMapper *mapper; |
| Brian Rogers | 1384af5 | 2014-05-21 12:13:17 -0700 | [diff] [blame^] | 59 | VAMappedHandle *vaMappedHandle; |
| Robert Crabtree | 2e984ef | 2013-05-07 14:27:47 -0700 | [diff] [blame] | 60 | }; |
| mamatha balguri | d248396 | 2013-07-11 13:38:48 -0700 | [diff] [blame] | 61 | 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 Singhi | 77b747d | 2013-04-26 14:30:05 -0700 | [diff] [blame] | 73 | struct Configuration { |
| 74 | sp<IFrameTypeChangeListener> typeChangeListener; |
| 75 | sp<IFrameListener> frameListener; |
| 76 | FrameProcessingPolicy policy; |
| Brian Rogers | f24ae21 | 2014-04-30 14:50:24 -0700 | [diff] [blame] | 77 | bool frameServerActive; |
| Ashish Singhi | 77b747d | 2013-04-26 14:30:05 -0700 | [diff] [blame] | 78 | bool extendedModeEnabled; |
| Robert Crabtree | 7d844a2 | 2013-08-27 14:00:15 -0700 | [diff] [blame] | 79 | bool forceNotifyFrameType; |
| 80 | bool forceNotifyBufferInfo; |
| Ashish Singhi | 77b747d | 2013-04-26 14:30:05 -0700 | [diff] [blame] | 81 | }; |
| Brian Rogers | 1384af5 | 2014-05-21 12:13:17 -0700 | [diff] [blame^] | 82 | struct Task; |
| 83 | struct RenderTask; |
| 84 | struct ComposeTask; |
| 85 | struct DisableVspTask; |
| 86 | struct BlitTask; |
| 87 | struct FrameTypeChangedTask; |
| 88 | struct BufferInfoChangedTask; |
| 89 | struct OnFrameReadyTask; |
| Brian Rogers | f24ae21 | 2014-04-30 14:50:24 -0700 | [diff] [blame] | 90 | struct ied_block { |
| 91 | uint8_t data[16]; |
| 92 | }; |
| 93 | ied_block mBlackY; |
| 94 | ied_block mBlackUV; |
| 95 | |
| Ashish Singhi | 77b747d | 2013-04-26 14:30:05 -0700 | [diff] [blame] | 96 | Mutex mConfigLock; |
| 97 | Configuration mCurrentConfig; |
| 98 | Configuration mNextConfig; |
| Brian Rogers | 1384af5 | 2014-05-21 12:13:17 -0700 | [diff] [blame^] | 99 | ssize_t mRgbLayer; |
| 100 | ssize_t mYuvLayer; |
| 101 | bool mProtectedMode; |
| Ashish Singhi | 77b747d | 2013-04-26 14:30:05 -0700 | [diff] [blame] | 102 | |
| 103 | uint32_t mExtLastKhandle; |
| 104 | int64_t mExtLastTimestamp; |
| 105 | |
| mamatha balguri | d248396 | 2013-07-11 13:38:48 -0700 | [diff] [blame] | 106 | int64_t mRenderTimestamp; |
| Robert Crabtree | 2e984ef | 2013-05-07 14:27:47 -0700 | [diff] [blame] | 107 | |
| mamatha balguri | d248396 | 2013-07-11 13:38:48 -0700 | [diff] [blame] | 108 | // colorspace conversion |
| 109 | Mutex mCscLock; |
| 110 | android::List<uint32_t> mAvailableCscBuffers; |
| 111 | int mCscBuffersToCreate; |
| 112 | uint32_t mCscWidth; |
| 113 | uint32_t mCscHeight; |
| 114 | |
| Brian Rogers | 1384af5 | 2014-05-21 12:13:17 -0700 | [diff] [blame^] | 115 | // fence info |
| 116 | int mSyncTimelineFd; |
| 117 | unsigned mNextSyncPoint; |
| 118 | |
| Brian Rogers | c40736e | 2014-03-31 14:40:11 -0700 | [diff] [blame] | 119 | // async blit info |
| 120 | DECLARE_THREAD(WidiBlitThread, VirtualDevice); |
| 121 | Condition mRequestQueued; |
| Brian Rogers | 1384af5 | 2014-05-21 12:13:17 -0700 | [diff] [blame^] | 122 | Condition mRequestDequeued; |
| 123 | Vector< sp<Task> > mTasks; |
| Brian Rogers | f24ae21 | 2014-04-30 14:50:24 -0700 | [diff] [blame] | 124 | |
| mamatha balguri | d248396 | 2013-07-11 13:38:48 -0700 | [diff] [blame] | 125 | FrameInfo mLastInputFrameInfo; |
| 126 | FrameInfo mLastOutputFrameInfo; |
| 127 | |
| Robert Crabtree | c2a96b1 | 2013-10-22 18:18:15 -0700 | [diff] [blame] | 128 | int32_t mVideoFramerate; |
| 129 | |
| mamatha balguri | d248396 | 2013-07-11 13:38:48 -0700 | [diff] [blame] | 130 | android::KeyedVector<uint32_t, android::sp<CachedBuffer> > mMappedBufferCache; |
| Robert Crabtree | 2e984ef | 2013-05-07 14:27:47 -0700 | [diff] [blame] | 131 | android::Mutex mHeldBuffersLock; |
| mamatha balguri | d248396 | 2013-07-11 13:38:48 -0700 | [diff] [blame] | 132 | android::KeyedVector<uint32_t, android::sp<android::RefBase> > mHeldBuffers; |
| Robert Crabtree | 2e984ef | 2013-05-07 14:27:47 -0700 | [diff] [blame] | 133 | |
| Brian Rogers | 1384af5 | 2014-05-21 12:13:17 -0700 | [diff] [blame^] | 134 | // 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 Crabtree | 2e984ef | 2013-05-07 14:27:47 -0700 | [diff] [blame] | 146 | private: |
| Brian Rogers | 1384af5 | 2014-05-21 12:13:17 -0700 | [diff] [blame^] | 147 | uint32_t getCscBuffer(uint32_t width, uint32_t height); |
| Brian Rogers | f24ae21 | 2014-04-30 14:50:24 -0700 | [diff] [blame] | 148 | void clearCscBuffers(); |
| mamatha balguri | d248396 | 2013-07-11 13:38:48 -0700 | [diff] [blame] | 149 | android::sp<CachedBuffer> getMappedBuffer(uint32_t handle); |
| Brian Rogers | 1384af5 | 2014-05-21 12:13:17 -0700 | [diff] [blame^] | 150 | |
| 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 Crabtree | 2e984ef | 2013-05-07 14:27:47 -0700 | [diff] [blame] | 159 | |
| Brian Rogers | f24ae21 | 2014-04-30 14:50:24 -0700 | [diff] [blame] | 160 | static void fill(uint8_t* ptr, const ied_block& data, size_t len); |
| Brian Rogers | 1384af5 | 2014-05-21 12:13:17 -0700 | [diff] [blame^] | 161 | 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 Rogers | fc3539e | 2014-05-19 20:16:21 -0700 | [diff] [blame] | 164 | void colorSwap(buffer_handle_t src, buffer_handle_t dest, uint32_t pixelCount); |
| Brian Rogers | 1384af5 | 2014-05-21 12:13:17 -0700 | [diff] [blame^] | 165 | void vspEnable(uint32_t width, uint32_t height); |
| 166 | void vspDisable(); |
| 167 | void vspCompose(VASurfaceID videoIn, VASurfaceID rgbIn, VASurfaceID videoOut); |
| Brian Rogers | f24ae21 | 2014-04-30 14:50:24 -0700 | [diff] [blame] | 168 | |
| Andy Qiu | 8a42714 | 2013-04-05 17:41:58 -0700 | [diff] [blame] | 169 | public: |
| 170 | VirtualDevice(Hwcomposer& hwc, DisplayPlaneManager& dpm); |
| 171 | virtual ~VirtualDevice(); |
| 172 | |
| 173 | public: |
| 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 Qiu | 4b834ce | 2013-04-09 18:23:20 -0700 | [diff] [blame] | 177 | IDisplayContext *context); |
| Andy Qiu | 8a42714 | 2013-04-05 17:41:58 -0700 | [diff] [blame] | 178 | |
| Andy Qiu | eb726af | 2013-05-31 11:51:49 +0800 | [diff] [blame] | 179 | virtual bool vsyncControl(bool enabled); |
| 180 | virtual bool blank(bool blank); |
| Andy Qiu | 0131f12 | 2013-07-19 14:51:20 -0700 | [diff] [blame] | 181 | virtual bool getDisplaySize(int *width, int *height); |
| Andy Qiu | 8a42714 | 2013-04-05 17:41:58 -0700 | [diff] [blame] | 182 | 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 jin | e2ad4c0 | 2013-05-28 13:47:51 -0700 | [diff] [blame] | 189 | virtual void deinitialize(); |
| Andy Qiu | 8a42714 | 2013-04-05 17:41:58 -0700 | [diff] [blame] | 190 | virtual bool isConnected() const; |
| 191 | virtual const char* getName() const; |
| 192 | virtual int getType() const; |
| Andy Qiu | 177b44e | 2013-11-07 18:03:02 -0800 | [diff] [blame] | 193 | virtual void onVsync(int64_t timestamp); |
| Andy Qiu | 8a42714 | 2013-04-05 17:41:58 -0700 | [diff] [blame] | 194 | virtual void dump(Dump& d); |
| 195 | |
| Ashish Singhi | 196e5bd | 2013-04-17 18:26:37 -0700 | [diff] [blame] | 196 | // IFrameServer methods |
| Arindam Roy | 8275746 | 2013-07-29 17:10:44 -0700 | [diff] [blame] | 197 | virtual android::status_t start(sp<IFrameTypeChangeListener> frameTypeChangeListener); |
| Ashish Singhi | 196e5bd | 2013-04-17 18:26:37 -0700 | [diff] [blame] | 198 | virtual android::status_t stop(bool isConnected); |
| 199 | virtual android::status_t notifyBufferReturned(int index); |
| Ashish Singhi | 77b747d | 2013-04-26 14:30:05 -0700 | [diff] [blame] | 200 | virtual android::status_t setResolution(const FrameProcessingPolicy& policy, android::sp<IFrameListener> listener); |
| Andy Qiu | 8a42714 | 2013-04-05 17:41:58 -0700 | [diff] [blame] | 201 | protected: |
| Robert Crabtree | 2e984ef | 2013-05-07 14:27:47 -0700 | [diff] [blame] | 202 | virtual IVideoPayloadManager* createVideoPayloadManager() = 0; |
| Andy Qiu | 8a42714 | 2013-04-05 17:41:58 -0700 | [diff] [blame] | 203 | |
| 204 | protected: |
| 205 | bool mInitialized; |
| 206 | Hwcomposer& mHwc; |
| 207 | DisplayPlaneManager& mDisplayPlaneManager; |
| Robert Crabtree | 2e984ef | 2013-05-07 14:27:47 -0700 | [diff] [blame] | 208 | IVideoPayloadManager *mPayloadManager; |
| Andy Qiu | 177b44e | 2013-11-07 18:03:02 -0800 | [diff] [blame] | 209 | SoftVsyncObserver *mVsyncObserver; |
| Ashish Singhi | 3895d9b | 2013-11-04 14:43:33 -0800 | [diff] [blame] | 210 | uint32_t mOrigContentWidth; |
| 211 | uint32_t mOrigContentHeight; |
| Robert Crabtree | 5456582 | 2013-12-10 17:02:03 -0800 | [diff] [blame] | 212 | bool mFirstVideoFrame; |
| Brian Rogers | 1384af5 | 2014-05-21 12:13:17 -0700 | [diff] [blame^] | 213 | bool mLastConnectionStatus; |
| ljia5 | 8f33db8 | 2014-02-19 16:49:16 +0800 | [diff] [blame] | 214 | uint32_t mCachedBufferCapcity; |
| Andy Qiu | 8a42714 | 2013-04-05 17:41:58 -0700 | [diff] [blame] | 215 | }; |
| 216 | |
| 217 | } |
| 218 | } |
| 219 | |
| 220 | #endif /* VIRTUAL_DEVICE_H */ |