blob: f628c6b94dae96ccac57af83ce00df3a8088f2ce [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;
Brian Rogersf24ae212014-04-30 14:50:24 -070069 bool frameServerActive;
Ashish Singhi77b747d2013-04-26 14:30:05 -070070 bool extendedModeEnabled;
Robert Crabtree7d844a22013-08-27 14:00:15 -070071 bool forceNotifyFrameType;
72 bool forceNotifyBufferInfo;
Ashish Singhi77b747d2013-04-26 14:30:05 -070073 };
Brian Rogersf24ae212014-04-30 14:50:24 -070074 struct ied_block {
75 uint8_t data[16];
76 };
77 ied_block mBlackY;
78 ied_block mBlackUV;
79
Ashish Singhi77b747d2013-04-26 14:30:05 -070080 Mutex mConfigLock;
81 Configuration mCurrentConfig;
82 Configuration mNextConfig;
mamatha balgurid2483962013-07-11 13:38:48 -070083 size_t mLayerToSend;
Ashish Singhi77b747d2013-04-26 14:30:05 -070084
85 uint32_t mExtLastKhandle;
86 int64_t mExtLastTimestamp;
87
mamatha balgurid2483962013-07-11 13:38:48 -070088 int64_t mRenderTimestamp;
Robert Crabtree2e984ef2013-05-07 14:27:47 -070089
mamatha balgurid2483962013-07-11 13:38:48 -070090 // colorspace conversion
91 Mutex mCscLock;
92 android::List<uint32_t> mAvailableCscBuffers;
93 int mCscBuffersToCreate;
94 uint32_t mCscWidth;
95 uint32_t mCscHeight;
96
Brian Rogersc40736e2014-03-31 14:40:11 -070097 // 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 Rogersf24ae212014-04-30 14:50:24 -0700111 bool mProtectedMode;
112
mamatha balgurid2483962013-07-11 13:38:48 -0700113 FrameInfo mLastInputFrameInfo;
114 FrameInfo mLastOutputFrameInfo;
115
Robert Crabtreec2a96b12013-10-22 18:18:15 -0700116 int32_t mVideoFramerate;
Zhu,Tianyangc3439ed2014-05-08 16:05:49 +0800117 bool mDScalingEnabled;
Robert Crabtreec2a96b12013-10-22 18:18:15 -0700118
mamatha balgurid2483962013-07-11 13:38:48 -0700119 android::KeyedVector<uint32_t, android::sp<CachedBuffer> > mMappedBufferCache;
Robert Crabtree2e984ef2013-05-07 14:27:47 -0700120 android::Mutex mHeldBuffersLock;
mamatha balgurid2483962013-07-11 13:38:48 -0700121 android::KeyedVector<uint32_t, android::sp<android::RefBase> > mHeldBuffers;
Robert Crabtree2e984ef2013-05-07 14:27:47 -0700122
123private:
Brian Rogersf24ae212014-04-30 14:50:24 -0700124 void clearCscBuffers();
mamatha balgurid2483962013-07-11 13:38:48 -0700125 android::sp<CachedBuffer> getMappedBuffer(uint32_t handle);
Sandeep Ramankuttyf10fc732014-04-04 19:47:17 -0700126 bool sendToWidi(const hwc_layer_1_t& layer, bool isProtected);
Robert Crabtree2e984ef2013-05-07 14:27:47 -0700127
Brian Rogersf24ae212014-04-30 14:50:24 -0700128 static void fill(uint8_t* ptr, const ied_block& data, size_t len);
129 void copyVideo(buffer_handle_t videoHandle, uint8_t* destPtr, uint32_t destWidth, uint32_t destHeight);
130 bool vanillaPrepare(hwc_display_contents_1_t *display);
131 bool vanillaCommit(hwc_display_contents_1_t *display);
Zhu,Tianyangc3439ed2014-05-08 16:05:49 +0800132 status_t setDownScaling(int width, int height,
133 int offX, int offY, int bufWidth, int bufHeight);
Brian Rogersf24ae212014-04-30 14:50:24 -0700134
Andy Qiu8a427142013-04-05 17:41:58 -0700135public:
136 VirtualDevice(Hwcomposer& hwc, DisplayPlaneManager& dpm);
137 virtual ~VirtualDevice();
138
139public:
140 virtual bool prePrepare(hwc_display_contents_1_t *display);
141 virtual bool prepare(hwc_display_contents_1_t *display);
142 virtual bool commit(hwc_display_contents_1_t *display,
Andy Qiu4b834ce2013-04-09 18:23:20 -0700143 IDisplayContext *context);
Andy Qiu8a427142013-04-05 17:41:58 -0700144
Andy Qiueb726af2013-05-31 11:51:49 +0800145 virtual bool vsyncControl(bool enabled);
146 virtual bool blank(bool blank);
Andy Qiu0131f122013-07-19 14:51:20 -0700147 virtual bool getDisplaySize(int *width, int *height);
Andy Qiu8a427142013-04-05 17:41:58 -0700148 virtual bool getDisplayConfigs(uint32_t *configs,
149 size_t *numConfigs);
150 virtual bool getDisplayAttributes(uint32_t config,
151 const uint32_t *attributes,
152 int32_t *values);
153 virtual bool compositionComplete();
154 virtual bool initialize();
fu jine2ad4c02013-05-28 13:47:51 -0700155 virtual void deinitialize();
Andy Qiu8a427142013-04-05 17:41:58 -0700156 virtual bool isConnected() const;
157 virtual const char* getName() const;
158 virtual int getType() const;
Andy Qiu177b44e2013-11-07 18:03:02 -0800159 virtual void onVsync(int64_t timestamp);
Andy Qiu8a427142013-04-05 17:41:58 -0700160 virtual void dump(Dump& d);
161
Ashish Singhi196e5bd2013-04-17 18:26:37 -0700162 // IFrameServer methods
Arindam Roy82757462013-07-29 17:10:44 -0700163 virtual android::status_t start(sp<IFrameTypeChangeListener> frameTypeChangeListener);
Ashish Singhi196e5bd2013-04-17 18:26:37 -0700164 virtual android::status_t stop(bool isConnected);
165 virtual android::status_t notifyBufferReturned(int index);
Ashish Singhi77b747d2013-04-26 14:30:05 -0700166 virtual android::status_t setResolution(const FrameProcessingPolicy& policy, android::sp<IFrameListener> listener);
Andy Qiu8a427142013-04-05 17:41:58 -0700167protected:
Robert Crabtree2e984ef2013-05-07 14:27:47 -0700168 virtual IVideoPayloadManager* createVideoPayloadManager() = 0;
Andy Qiu8a427142013-04-05 17:41:58 -0700169
170protected:
171 bool mInitialized;
172 Hwcomposer& mHwc;
173 DisplayPlaneManager& mDisplayPlaneManager;
Robert Crabtree2e984ef2013-05-07 14:27:47 -0700174 IVideoPayloadManager *mPayloadManager;
Andy Qiu177b44e2013-11-07 18:03:02 -0800175 SoftVsyncObserver *mVsyncObserver;
Ashish Singhi3895d9b2013-11-04 14:43:33 -0800176 uint32_t mOrigContentWidth;
177 uint32_t mOrigContentHeight;
Robert Crabtree54565822013-12-10 17:02:03 -0800178 bool mFirstVideoFrame;
ljia58f33db82014-02-19 16:49:16 +0800179 uint32_t mCachedBufferCapcity;
Andy Qiu8a427142013-04-05 17:41:58 -0700180};
181
182}
183}
184
185#endif /* VIRTUAL_DEVICE_H */