blob: 99532091171b1a4020f88d9992aaf742e34ffbdc [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>
33#include <utils/Condition.h>
34#include <utils/Mutex.h>
Ashish Singhi196e5bd2013-04-17 18:26:37 -070035#include "IFrameServer.h"
Andy Qiu8a427142013-04-05 17:41:58 -070036
37namespace android {
38namespace intel {
39
40class Hwcomposer;
41class DisplayPlaneManager;
Robert Crabtree2e984ef2013-05-07 14:27:47 -070042class IVideoPayloadManager;
Andy Qiu177b44e2013-11-07 18:03:02 -080043class SoftVsyncObserver;
Andy Qiu8a427142013-04-05 17:41:58 -070044
Ashish Singhi196e5bd2013-04-17 18:26:37 -070045class VirtualDevice : public IDisplayDevice, public BnFrameServer {
Ashish Singhi77b747d2013-04-26 14:30:05 -070046protected:
Robert Crabtree2e984ef2013-05-07 14:27:47 -070047 struct CachedBuffer : public android::RefBase {
mamatha balgurid2483962013-07-11 13:38:48 -070048 CachedBuffer(BufferManager *mgr, uint32_t handle);
Robert Crabtree2e984ef2013-05-07 14:27:47 -070049 ~CachedBuffer();
50 BufferManager *manager;
Robert Crabtree2e984ef2013-05-07 14:27:47 -070051 BufferMapper *mapper;
52 };
mamatha balgurid2483962013-07-11 13:38:48 -070053 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 Singhi77b747d2013-04-26 14:30:05 -070065 struct Configuration {
66 sp<IFrameTypeChangeListener> typeChangeListener;
67 sp<IFrameListener> frameListener;
68 FrameProcessingPolicy policy;
69 bool extendedModeEnabled;
Robert Crabtree7d844a22013-08-27 14:00:15 -070070 bool forceNotifyFrameType;
71 bool forceNotifyBufferInfo;
Ashish Singhi77b747d2013-04-26 14:30:05 -070072 };
73 Mutex mConfigLock;
74 Configuration mCurrentConfig;
75 Configuration mNextConfig;
mamatha balgurid2483962013-07-11 13:38:48 -070076 size_t mLayerToSend;
Ashish Singhi77b747d2013-04-26 14:30:05 -070077
78 uint32_t mExtLastKhandle;
79 int64_t mExtLastTimestamp;
80
mamatha balgurid2483962013-07-11 13:38:48 -070081 int64_t mRenderTimestamp;
Robert Crabtree2e984ef2013-05-07 14:27:47 -070082
mamatha balgurid2483962013-07-11 13:38:48 -070083 // colorspace conversion
84 Mutex mCscLock;
85 android::List<uint32_t> mAvailableCscBuffers;
86 int mCscBuffersToCreate;
87 uint32_t mCscWidth;
88 uint32_t mCscHeight;
89
Brian Rogersc40736e2014-03-31 14:40:11 -070090 // async blit info
91 DECLARE_THREAD(WidiBlitThread, VirtualDevice);
92 Condition mRequestQueued;
93 Condition mRequestProcessed;
94 uint32_t mBlitSrcHandle;
95 uint32_t mBlitDestHandle;
96 uint32_t mBlitCropWidth;
97 uint32_t mBlitCropHeight;
98 bool mDoBlit;
99 // async onFrameReady info
100 int64_t mFrameReadyRenderTs;
101 bool mDoOnFrameReady;
102 bool mCancelOnFrameReady;
103
mamatha balgurid2483962013-07-11 13:38:48 -0700104 FrameInfo mLastInputFrameInfo;
105 FrameInfo mLastOutputFrameInfo;
106
Robert Crabtreec2a96b12013-10-22 18:18:15 -0700107 int32_t mVideoFramerate;
108
mamatha balgurid2483962013-07-11 13:38:48 -0700109 android::KeyedVector<uint32_t, android::sp<CachedBuffer> > mMappedBufferCache;
Robert Crabtree2e984ef2013-05-07 14:27:47 -0700110 android::Mutex mHeldBuffersLock;
mamatha balgurid2483962013-07-11 13:38:48 -0700111 android::KeyedVector<uint32_t, android::sp<android::RefBase> > mHeldBuffers;
Robert Crabtree2e984ef2013-05-07 14:27:47 -0700112
113private:
mamatha balgurid2483962013-07-11 13:38:48 -0700114 android::sp<CachedBuffer> getMappedBuffer(uint32_t handle);
Robert Crabtree54565822013-12-10 17:02:03 -0800115 void sendToWidi(const hwc_layer_1_t& layer, bool isProtected);
Robert Crabtree2e984ef2013-05-07 14:27:47 -0700116
Andy Qiu8a427142013-04-05 17:41:58 -0700117public:
118 VirtualDevice(Hwcomposer& hwc, DisplayPlaneManager& dpm);
119 virtual ~VirtualDevice();
120
121public:
122 virtual bool prePrepare(hwc_display_contents_1_t *display);
123 virtual bool prepare(hwc_display_contents_1_t *display);
124 virtual bool commit(hwc_display_contents_1_t *display,
Andy Qiu4b834ce2013-04-09 18:23:20 -0700125 IDisplayContext *context);
Andy Qiu8a427142013-04-05 17:41:58 -0700126
Andy Qiueb726af2013-05-31 11:51:49 +0800127 virtual bool vsyncControl(bool enabled);
128 virtual bool blank(bool blank);
Andy Qiu0131f122013-07-19 14:51:20 -0700129 virtual bool getDisplaySize(int *width, int *height);
Andy Qiu8a427142013-04-05 17:41:58 -0700130 virtual bool getDisplayConfigs(uint32_t *configs,
131 size_t *numConfigs);
132 virtual bool getDisplayAttributes(uint32_t config,
133 const uint32_t *attributes,
134 int32_t *values);
135 virtual bool compositionComplete();
136 virtual bool initialize();
fu jine2ad4c02013-05-28 13:47:51 -0700137 virtual void deinitialize();
Andy Qiu8a427142013-04-05 17:41:58 -0700138 virtual bool isConnected() const;
139 virtual const char* getName() const;
140 virtual int getType() const;
Andy Qiu177b44e2013-11-07 18:03:02 -0800141 virtual void onVsync(int64_t timestamp);
Andy Qiu8a427142013-04-05 17:41:58 -0700142 virtual void dump(Dump& d);
143
Ashish Singhi196e5bd2013-04-17 18:26:37 -0700144 // IFrameServer methods
Arindam Roy82757462013-07-29 17:10:44 -0700145 virtual android::status_t start(sp<IFrameTypeChangeListener> frameTypeChangeListener);
Ashish Singhi196e5bd2013-04-17 18:26:37 -0700146 virtual android::status_t stop(bool isConnected);
147 virtual android::status_t notifyBufferReturned(int index);
Ashish Singhi77b747d2013-04-26 14:30:05 -0700148 virtual android::status_t setResolution(const FrameProcessingPolicy& policy, android::sp<IFrameListener> listener);
Andy Qiu8a427142013-04-05 17:41:58 -0700149protected:
Robert Crabtree2e984ef2013-05-07 14:27:47 -0700150 virtual IVideoPayloadManager* createVideoPayloadManager() = 0;
Andy Qiu8a427142013-04-05 17:41:58 -0700151
152protected:
153 bool mInitialized;
Andy Qiu177b44e2013-11-07 18:03:02 -0800154 bool mConnected;
Ashish Singhi1f64ce62014-02-04 17:31:01 -0800155 bool mCloneModeStarted;
Andy Qiu8a427142013-04-05 17:41:58 -0700156 Hwcomposer& mHwc;
157 DisplayPlaneManager& mDisplayPlaneManager;
Robert Crabtree2e984ef2013-05-07 14:27:47 -0700158 IVideoPayloadManager *mPayloadManager;
Andy Qiu177b44e2013-11-07 18:03:02 -0800159 SoftVsyncObserver *mVsyncObserver;
Ashish Singhi3895d9b2013-11-04 14:43:33 -0800160 uint32_t mOrigContentWidth;
161 uint32_t mOrigContentHeight;
Robert Crabtree54565822013-12-10 17:02:03 -0800162 bool mFirstVideoFrame;
ljia58f33db82014-02-19 16:49:16 +0800163 uint32_t mCachedBufferCapcity;
Andy Qiu8a427142013-04-05 17:41:58 -0700164};
165
166}
167}
168
169#endif /* VIRTUAL_DEVICE_H */