| 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> |
| 33 | #include <utils/Condition.h> |
| 34 | #include <utils/Mutex.h> |
| Ashish Singhi | 196e5bd | 2013-04-17 18:26:37 -0700 | [diff] [blame] | 35 | #include "IFrameServer.h" |
| Andy Qiu | 8a42714 | 2013-04-05 17:41:58 -0700 | [diff] [blame] | 36 | |
| 37 | namespace android { |
| 38 | namespace intel { |
| 39 | |
| 40 | class Hwcomposer; |
| 41 | class DisplayPlaneManager; |
| Robert Crabtree | 2e984ef | 2013-05-07 14:27:47 -0700 | [diff] [blame] | 42 | class IVideoPayloadManager; |
| Andy Qiu | 177b44e | 2013-11-07 18:03:02 -0800 | [diff] [blame] | 43 | class SoftVsyncObserver; |
| Andy Qiu | 8a42714 | 2013-04-05 17:41:58 -0700 | [diff] [blame] | 44 | |
| Ashish Singhi | 196e5bd | 2013-04-17 18:26:37 -0700 | [diff] [blame] | 45 | class VirtualDevice : public IDisplayDevice, public BnFrameServer { |
| Ashish Singhi | 77b747d | 2013-04-26 14:30:05 -0700 | [diff] [blame] | 46 | protected: |
| Robert Crabtree | 2e984ef | 2013-05-07 14:27:47 -0700 | [diff] [blame] | 47 | struct CachedBuffer : public android::RefBase { |
| mamatha balguri | d248396 | 2013-07-11 13:38:48 -0700 | [diff] [blame] | 48 | CachedBuffer(BufferManager *mgr, uint32_t handle); |
| Robert Crabtree | 2e984ef | 2013-05-07 14:27:47 -0700 | [diff] [blame] | 49 | ~CachedBuffer(); |
| 50 | BufferManager *manager; |
| Robert Crabtree | 2e984ef | 2013-05-07 14:27:47 -0700 | [diff] [blame] | 51 | BufferMapper *mapper; |
| 52 | }; |
| mamatha balguri | d248396 | 2013-07-11 13:38:48 -0700 | [diff] [blame] | 53 | struct HeldCscBuffer : public android::RefBase { |
| 54 | HeldCscBuffer(const android::sp<VirtualDevice>& vd, uint32_t handle); |
| 55 | virtual ~HeldCscBuffer(); |
| 56 | android::sp<VirtualDevice> vd; |
| 57 | uint32_t handle; |
| 58 | }; |
| 59 | struct HeldDecoderBuffer : public android::RefBase { |
| 60 | HeldDecoderBuffer(const sp<VirtualDevice>& vd, const android::sp<CachedBuffer>& cachedBuffer); |
| 61 | virtual ~HeldDecoderBuffer(); |
| 62 | android::sp<VirtualDevice> vd; |
| 63 | android::sp<CachedBuffer> cachedBuffer; |
| 64 | }; |
| Ashish Singhi | 77b747d | 2013-04-26 14:30:05 -0700 | [diff] [blame] | 65 | struct Configuration { |
| 66 | sp<IFrameTypeChangeListener> typeChangeListener; |
| 67 | sp<IFrameListener> frameListener; |
| 68 | FrameProcessingPolicy policy; |
| Brian Rogers | f24ae21 | 2014-04-30 14:50:24 -0700 | [diff] [blame] | 69 | bool frameServerActive; |
| Ashish Singhi | 77b747d | 2013-04-26 14:30:05 -0700 | [diff] [blame] | 70 | bool extendedModeEnabled; |
| Robert Crabtree | 7d844a2 | 2013-08-27 14:00:15 -0700 | [diff] [blame] | 71 | bool forceNotifyFrameType; |
| 72 | bool forceNotifyBufferInfo; |
| Ashish Singhi | 77b747d | 2013-04-26 14:30:05 -0700 | [diff] [blame] | 73 | }; |
| Brian Rogers | f24ae21 | 2014-04-30 14:50:24 -0700 | [diff] [blame] | 74 | struct ied_block { |
| 75 | uint8_t data[16]; |
| 76 | }; |
| 77 | ied_block mBlackY; |
| 78 | ied_block mBlackUV; |
| 79 | |
| Ashish Singhi | 77b747d | 2013-04-26 14:30:05 -0700 | [diff] [blame] | 80 | Mutex mConfigLock; |
| 81 | Configuration mCurrentConfig; |
| 82 | Configuration mNextConfig; |
| mamatha balguri | d248396 | 2013-07-11 13:38:48 -0700 | [diff] [blame] | 83 | size_t mLayerToSend; |
| Ashish Singhi | 77b747d | 2013-04-26 14:30:05 -0700 | [diff] [blame] | 84 | |
| 85 | uint32_t mExtLastKhandle; |
| 86 | int64_t mExtLastTimestamp; |
| 87 | |
| mamatha balguri | d248396 | 2013-07-11 13:38:48 -0700 | [diff] [blame] | 88 | int64_t mRenderTimestamp; |
| Robert Crabtree | 2e984ef | 2013-05-07 14:27:47 -0700 | [diff] [blame] | 89 | |
| mamatha balguri | d248396 | 2013-07-11 13:38:48 -0700 | [diff] [blame] | 90 | // colorspace conversion |
| 91 | Mutex mCscLock; |
| 92 | android::List<uint32_t> mAvailableCscBuffers; |
| 93 | int mCscBuffersToCreate; |
| 94 | uint32_t mCscWidth; |
| 95 | uint32_t mCscHeight; |
| 96 | |
| Brian Rogers | c40736e | 2014-03-31 14:40:11 -0700 | [diff] [blame] | 97 | // async blit info |
| 98 | DECLARE_THREAD(WidiBlitThread, VirtualDevice); |
| 99 | Condition mRequestQueued; |
| 100 | Condition mRequestProcessed; |
| 101 | uint32_t mBlitSrcHandle; |
| 102 | uint32_t mBlitDestHandle; |
| 103 | uint32_t mBlitCropWidth; |
| 104 | uint32_t mBlitCropHeight; |
| 105 | bool mDoBlit; |
| 106 | // async onFrameReady info |
| 107 | int64_t mFrameReadyRenderTs; |
| 108 | bool mDoOnFrameReady; |
| 109 | bool mCancelOnFrameReady; |
| 110 | |
| Brian Rogers | f24ae21 | 2014-04-30 14:50:24 -0700 | [diff] [blame] | 111 | bool mProtectedMode; |
| 112 | |
| mamatha balguri | d248396 | 2013-07-11 13:38:48 -0700 | [diff] [blame] | 113 | FrameInfo mLastInputFrameInfo; |
| 114 | FrameInfo mLastOutputFrameInfo; |
| 115 | |
| Robert Crabtree | c2a96b1 | 2013-10-22 18:18:15 -0700 | [diff] [blame] | 116 | int32_t mVideoFramerate; |
| 117 | |
| mamatha balguri | d248396 | 2013-07-11 13:38:48 -0700 | [diff] [blame] | 118 | android::KeyedVector<uint32_t, android::sp<CachedBuffer> > mMappedBufferCache; |
| Robert Crabtree | 2e984ef | 2013-05-07 14:27:47 -0700 | [diff] [blame] | 119 | android::Mutex mHeldBuffersLock; |
| mamatha balguri | d248396 | 2013-07-11 13:38:48 -0700 | [diff] [blame] | 120 | android::KeyedVector<uint32_t, android::sp<android::RefBase> > mHeldBuffers; |
| Robert Crabtree | 2e984ef | 2013-05-07 14:27:47 -0700 | [diff] [blame] | 121 | |
| 122 | private: |
| Brian Rogers | f24ae21 | 2014-04-30 14:50:24 -0700 | [diff] [blame] | 123 | void clearCscBuffers(); |
| mamatha balguri | d248396 | 2013-07-11 13:38:48 -0700 | [diff] [blame] | 124 | android::sp<CachedBuffer> getMappedBuffer(uint32_t handle); |
| Sandeep Ramankutty | f10fc73 | 2014-04-04 19:47:17 -0700 | [diff] [blame] | 125 | bool sendToWidi(const hwc_layer_1_t& layer, bool isProtected); |
| Robert Crabtree | 2e984ef | 2013-05-07 14:27:47 -0700 | [diff] [blame] | 126 | |
| Brian Rogers | f24ae21 | 2014-04-30 14:50:24 -0700 | [diff] [blame] | 127 | static void fill(uint8_t* ptr, const ied_block& data, size_t len); |
| 128 | void copyVideo(buffer_handle_t videoHandle, uint8_t* destPtr, uint32_t destWidth, uint32_t destHeight); |
| 129 | bool vanillaPrepare(hwc_display_contents_1_t *display); |
| 130 | bool vanillaCommit(hwc_display_contents_1_t *display); |
| 131 | |
| Andy Qiu | 8a42714 | 2013-04-05 17:41:58 -0700 | [diff] [blame] | 132 | public: |
| 133 | VirtualDevice(Hwcomposer& hwc, DisplayPlaneManager& dpm); |
| 134 | virtual ~VirtualDevice(); |
| 135 | |
| 136 | public: |
| 137 | virtual bool prePrepare(hwc_display_contents_1_t *display); |
| 138 | virtual bool prepare(hwc_display_contents_1_t *display); |
| 139 | virtual bool commit(hwc_display_contents_1_t *display, |
| Andy Qiu | 4b834ce | 2013-04-09 18:23:20 -0700 | [diff] [blame] | 140 | IDisplayContext *context); |
| Andy Qiu | 8a42714 | 2013-04-05 17:41:58 -0700 | [diff] [blame] | 141 | |
| Andy Qiu | eb726af | 2013-05-31 11:51:49 +0800 | [diff] [blame] | 142 | virtual bool vsyncControl(bool enabled); |
| 143 | virtual bool blank(bool blank); |
| Andy Qiu | 0131f12 | 2013-07-19 14:51:20 -0700 | [diff] [blame] | 144 | virtual bool getDisplaySize(int *width, int *height); |
| Andy Qiu | 8a42714 | 2013-04-05 17:41:58 -0700 | [diff] [blame] | 145 | virtual bool getDisplayConfigs(uint32_t *configs, |
| 146 | size_t *numConfigs); |
| 147 | virtual bool getDisplayAttributes(uint32_t config, |
| 148 | const uint32_t *attributes, |
| 149 | int32_t *values); |
| 150 | virtual bool compositionComplete(); |
| 151 | virtual bool initialize(); |
| fu jin | e2ad4c0 | 2013-05-28 13:47:51 -0700 | [diff] [blame] | 152 | virtual void deinitialize(); |
| Andy Qiu | 8a42714 | 2013-04-05 17:41:58 -0700 | [diff] [blame] | 153 | virtual bool isConnected() const; |
| 154 | virtual const char* getName() const; |
| 155 | virtual int getType() const; |
| Andy Qiu | 177b44e | 2013-11-07 18:03:02 -0800 | [diff] [blame] | 156 | virtual void onVsync(int64_t timestamp); |
| Andy Qiu | 8a42714 | 2013-04-05 17:41:58 -0700 | [diff] [blame] | 157 | virtual void dump(Dump& d); |
| 158 | |
| Ashish Singhi | 196e5bd | 2013-04-17 18:26:37 -0700 | [diff] [blame] | 159 | // IFrameServer methods |
| Arindam Roy | 8275746 | 2013-07-29 17:10:44 -0700 | [diff] [blame] | 160 | virtual android::status_t start(sp<IFrameTypeChangeListener> frameTypeChangeListener); |
| Ashish Singhi | 196e5bd | 2013-04-17 18:26:37 -0700 | [diff] [blame] | 161 | virtual android::status_t stop(bool isConnected); |
| 162 | virtual android::status_t notifyBufferReturned(int index); |
| Ashish Singhi | 77b747d | 2013-04-26 14:30:05 -0700 | [diff] [blame] | 163 | virtual android::status_t setResolution(const FrameProcessingPolicy& policy, android::sp<IFrameListener> listener); |
| Andy Qiu | 8a42714 | 2013-04-05 17:41:58 -0700 | [diff] [blame] | 164 | protected: |
| Robert Crabtree | 2e984ef | 2013-05-07 14:27:47 -0700 | [diff] [blame] | 165 | virtual IVideoPayloadManager* createVideoPayloadManager() = 0; |
| Andy Qiu | 8a42714 | 2013-04-05 17:41:58 -0700 | [diff] [blame] | 166 | |
| 167 | protected: |
| 168 | bool mInitialized; |
| 169 | Hwcomposer& mHwc; |
| 170 | DisplayPlaneManager& mDisplayPlaneManager; |
| Robert Crabtree | 2e984ef | 2013-05-07 14:27:47 -0700 | [diff] [blame] | 171 | IVideoPayloadManager *mPayloadManager; |
| Andy Qiu | 177b44e | 2013-11-07 18:03:02 -0800 | [diff] [blame] | 172 | SoftVsyncObserver *mVsyncObserver; |
| Ashish Singhi | 3895d9b | 2013-11-04 14:43:33 -0800 | [diff] [blame] | 173 | uint32_t mOrigContentWidth; |
| 174 | uint32_t mOrigContentHeight; |
| Robert Crabtree | 5456582 | 2013-12-10 17:02:03 -0800 | [diff] [blame] | 175 | bool mFirstVideoFrame; |
| ljia5 | 8f33db8 | 2014-02-19 16:49:16 +0800 | [diff] [blame] | 176 | uint32_t mCachedBufferCapcity; |
| Andy Qiu | 8a42714 | 2013-04-05 17:41:58 -0700 | [diff] [blame] | 177 | }; |
| 178 | |
| 179 | } |
| 180 | } |
| 181 | |
| 182 | #endif /* VIRTUAL_DEVICE_H */ |