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