blob: dd4b5f98c91a3936f0c7f9ab4bfbaf9e7dba8ce1 [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>
Ashish Singhi196e5bd2013-04-17 18:26:37 -070032#include "IFrameServer.h"
Andy Qiu8a427142013-04-05 17:41:58 -070033
34namespace android {
35namespace intel {
36
37class Hwcomposer;
38class DisplayPlaneManager;
Robert Crabtree2e984ef2013-05-07 14:27:47 -070039class IVideoPayloadManager;
Andy Qiu177b44e2013-11-07 18:03:02 -080040class SoftVsyncObserver;
Andy Qiu8a427142013-04-05 17:41:58 -070041
Ashish Singhi196e5bd2013-04-17 18:26:37 -070042class VirtualDevice : public IDisplayDevice, public BnFrameServer {
Ashish Singhi77b747d2013-04-26 14:30:05 -070043protected:
Robert Crabtree2e984ef2013-05-07 14:27:47 -070044 struct CachedBuffer : public android::RefBase {
mamatha balgurid2483962013-07-11 13:38:48 -070045 CachedBuffer(BufferManager *mgr, uint32_t handle);
Robert Crabtree2e984ef2013-05-07 14:27:47 -070046 ~CachedBuffer();
47 BufferManager *manager;
Robert Crabtree2e984ef2013-05-07 14:27:47 -070048 BufferMapper *mapper;
49 };
mamatha balgurid2483962013-07-11 13:38:48 -070050 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 Singhi77b747d2013-04-26 14:30:05 -070062 struct Configuration {
63 sp<IFrameTypeChangeListener> typeChangeListener;
64 sp<IFrameListener> frameListener;
65 FrameProcessingPolicy policy;
66 bool extendedModeEnabled;
Robert Crabtree7d844a22013-08-27 14:00:15 -070067 bool forceNotifyFrameType;
68 bool forceNotifyBufferInfo;
Ashish Singhi77b747d2013-04-26 14:30:05 -070069 };
70 Mutex mConfigLock;
71 Configuration mCurrentConfig;
72 Configuration mNextConfig;
mamatha balgurid2483962013-07-11 13:38:48 -070073 size_t mLayerToSend;
Ashish Singhi77b747d2013-04-26 14:30:05 -070074
75 uint32_t mExtLastKhandle;
76 int64_t mExtLastTimestamp;
77
mamatha balgurid2483962013-07-11 13:38:48 -070078 int64_t mRenderTimestamp;
Robert Crabtree2e984ef2013-05-07 14:27:47 -070079
mamatha balgurid2483962013-07-11 13:38:48 -070080 // 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 Crabtreec2a96b12013-10-22 18:18:15 -070090 int32_t mVideoFramerate;
91
mamatha balgurid2483962013-07-11 13:38:48 -070092 android::KeyedVector<uint32_t, android::sp<CachedBuffer> > mMappedBufferCache;
Robert Crabtree2e984ef2013-05-07 14:27:47 -070093 android::Mutex mHeldBuffersLock;
mamatha balgurid2483962013-07-11 13:38:48 -070094 android::KeyedVector<uint32_t, android::sp<android::RefBase> > mHeldBuffers;
Robert Crabtree2e984ef2013-05-07 14:27:47 -070095
96private:
mamatha balgurid2483962013-07-11 13:38:48 -070097 android::sp<CachedBuffer> getMappedBuffer(uint32_t handle);
Robert Crabtree54565822013-12-10 17:02:03 -080098 void sendToWidi(const hwc_layer_1_t& layer, bool isProtected);
Robert Crabtree2e984ef2013-05-07 14:27:47 -070099
Andy Qiu8a427142013-04-05 17:41:58 -0700100public:
101 VirtualDevice(Hwcomposer& hwc, DisplayPlaneManager& dpm);
102 virtual ~VirtualDevice();
103
104public:
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 Qiu4b834ce2013-04-09 18:23:20 -0700108 IDisplayContext *context);
Andy Qiu8a427142013-04-05 17:41:58 -0700109
Andy Qiueb726af2013-05-31 11:51:49 +0800110 virtual bool vsyncControl(bool enabled);
111 virtual bool blank(bool blank);
Andy Qiu0131f122013-07-19 14:51:20 -0700112 virtual bool getDisplaySize(int *width, int *height);
Andy Qiu8a427142013-04-05 17:41:58 -0700113 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 jine2ad4c02013-05-28 13:47:51 -0700120 virtual void deinitialize();
Andy Qiu8a427142013-04-05 17:41:58 -0700121 virtual bool isConnected() const;
122 virtual const char* getName() const;
123 virtual int getType() const;
Andy Qiu177b44e2013-11-07 18:03:02 -0800124 virtual void onVsync(int64_t timestamp);
Andy Qiu8a427142013-04-05 17:41:58 -0700125 virtual void dump(Dump& d);
126
Ashish Singhi196e5bd2013-04-17 18:26:37 -0700127 // IFrameServer methods
Arindam Roy82757462013-07-29 17:10:44 -0700128 virtual android::status_t start(sp<IFrameTypeChangeListener> frameTypeChangeListener);
Ashish Singhi196e5bd2013-04-17 18:26:37 -0700129 virtual android::status_t stop(bool isConnected);
130 virtual android::status_t notifyBufferReturned(int index);
Ashish Singhi77b747d2013-04-26 14:30:05 -0700131 virtual android::status_t setResolution(const FrameProcessingPolicy& policy, android::sp<IFrameListener> listener);
Andy Qiu8a427142013-04-05 17:41:58 -0700132protected:
Robert Crabtree2e984ef2013-05-07 14:27:47 -0700133 virtual IVideoPayloadManager* createVideoPayloadManager() = 0;
Andy Qiu8a427142013-04-05 17:41:58 -0700134
135protected:
136 bool mInitialized;
Andy Qiu177b44e2013-11-07 18:03:02 -0800137 bool mConnected;
Ashish Singhi1f64ce62014-02-04 17:31:01 -0800138 bool mCloneModeStarted;
Andy Qiu8a427142013-04-05 17:41:58 -0700139 Hwcomposer& mHwc;
140 DisplayPlaneManager& mDisplayPlaneManager;
Robert Crabtree2e984ef2013-05-07 14:27:47 -0700141 IVideoPayloadManager *mPayloadManager;
Andy Qiu177b44e2013-11-07 18:03:02 -0800142 SoftVsyncObserver *mVsyncObserver;
Ashish Singhi3895d9b2013-11-04 14:43:33 -0800143 uint32_t mOrigContentWidth;
144 uint32_t mOrigContentHeight;
Robert Crabtree54565822013-12-10 17:02:03 -0800145 bool mFirstVideoFrame;
Andy Qiu8a427142013-04-05 17:41:58 -0700146};
147
148}
149}
150
151#endif /* VIRTUAL_DEVICE_H */