blob: 7df74435d821f471e67a2f6158f561175d8abc7c [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 Qiu8a427142013-04-05 17:41:58 -070040
Ashish Singhi196e5bd2013-04-17 18:26:37 -070041class VirtualDevice : public IDisplayDevice, public BnFrameServer {
Ashish Singhi77b747d2013-04-26 14:30:05 -070042protected:
Robert Crabtree2e984ef2013-05-07 14:27:47 -070043 struct CachedBuffer : public android::RefBase {
mamatha balgurid2483962013-07-11 13:38:48 -070044 CachedBuffer(BufferManager *mgr, uint32_t handle);
Robert Crabtree2e984ef2013-05-07 14:27:47 -070045 ~CachedBuffer();
46 BufferManager *manager;
Robert Crabtree2e984ef2013-05-07 14:27:47 -070047 BufferMapper *mapper;
48 };
mamatha balgurid2483962013-07-11 13:38:48 -070049 struct HeldCscBuffer : public android::RefBase {
50 HeldCscBuffer(const android::sp<VirtualDevice>& vd, uint32_t handle);
51 virtual ~HeldCscBuffer();
52 android::sp<VirtualDevice> vd;
53 uint32_t handle;
54 };
55 struct HeldDecoderBuffer : public android::RefBase {
56 HeldDecoderBuffer(const sp<VirtualDevice>& vd, const android::sp<CachedBuffer>& cachedBuffer);
57 virtual ~HeldDecoderBuffer();
58 android::sp<VirtualDevice> vd;
59 android::sp<CachedBuffer> cachedBuffer;
60 };
Ashish Singhi77b747d2013-04-26 14:30:05 -070061 struct Configuration {
62 sp<IFrameTypeChangeListener> typeChangeListener;
63 sp<IFrameListener> frameListener;
64 FrameProcessingPolicy policy;
65 bool extendedModeEnabled;
66 bool forceNotify;
67 };
68 Mutex mConfigLock;
69 Configuration mCurrentConfig;
70 Configuration mNextConfig;
mamatha balgurid2483962013-07-11 13:38:48 -070071 size_t mLayerToSend;
Ashish Singhi77b747d2013-04-26 14:30:05 -070072
73 uint32_t mExtLastKhandle;
74 int64_t mExtLastTimestamp;
75
mamatha balgurid2483962013-07-11 13:38:48 -070076 int64_t mRenderTimestamp;
Robert Crabtree2e984ef2013-05-07 14:27:47 -070077
mamatha balgurid2483962013-07-11 13:38:48 -070078 // colorspace conversion
79 Mutex mCscLock;
80 android::List<uint32_t> mAvailableCscBuffers;
81 int mCscBuffersToCreate;
82 uint32_t mCscWidth;
83 uint32_t mCscHeight;
84
85 FrameInfo mLastInputFrameInfo;
86 FrameInfo mLastOutputFrameInfo;
87
Robert Crabtreec2a96b12013-10-22 18:18:15 -070088 int32_t mVideoFramerate;
89
mamatha balgurid2483962013-07-11 13:38:48 -070090 android::KeyedVector<uint32_t, android::sp<CachedBuffer> > mMappedBufferCache;
Robert Crabtree2e984ef2013-05-07 14:27:47 -070091 android::Mutex mHeldBuffersLock;
mamatha balgurid2483962013-07-11 13:38:48 -070092 android::KeyedVector<uint32_t, android::sp<android::RefBase> > mHeldBuffers;
Robert Crabtree2e984ef2013-05-07 14:27:47 -070093
94private:
mamatha balgurid2483962013-07-11 13:38:48 -070095 android::sp<CachedBuffer> getMappedBuffer(uint32_t handle);
96 void sendToWidi(const hwc_layer_1_t& layer);
Robert Crabtree2e984ef2013-05-07 14:27:47 -070097
Andy Qiu8a427142013-04-05 17:41:58 -070098public:
99 VirtualDevice(Hwcomposer& hwc, DisplayPlaneManager& dpm);
100 virtual ~VirtualDevice();
101
102public:
103 virtual bool prePrepare(hwc_display_contents_1_t *display);
104 virtual bool prepare(hwc_display_contents_1_t *display);
105 virtual bool commit(hwc_display_contents_1_t *display,
Andy Qiu4b834ce2013-04-09 18:23:20 -0700106 IDisplayContext *context);
Andy Qiu8a427142013-04-05 17:41:58 -0700107
Andy Qiueb726af2013-05-31 11:51:49 +0800108 virtual bool vsyncControl(bool enabled);
109 virtual bool blank(bool blank);
Andy Qiu0131f122013-07-19 14:51:20 -0700110 virtual bool getDisplaySize(int *width, int *height);
Andy Qiu8a427142013-04-05 17:41:58 -0700111 virtual bool getDisplayConfigs(uint32_t *configs,
112 size_t *numConfigs);
113 virtual bool getDisplayAttributes(uint32_t config,
114 const uint32_t *attributes,
115 int32_t *values);
116 virtual bool compositionComplete();
117 virtual bool initialize();
fu jine2ad4c02013-05-28 13:47:51 -0700118 virtual void deinitialize();
Andy Qiu8a427142013-04-05 17:41:58 -0700119 virtual bool isConnected() const;
120 virtual const char* getName() const;
121 virtual int getType() const;
122 virtual void dump(Dump& d);
123
Ashish Singhi196e5bd2013-04-17 18:26:37 -0700124 // IFrameServer methods
Arindam Roy82757462013-07-29 17:10:44 -0700125 virtual android::status_t start(sp<IFrameTypeChangeListener> frameTypeChangeListener);
Ashish Singhi196e5bd2013-04-17 18:26:37 -0700126 virtual android::status_t stop(bool isConnected);
127 virtual android::status_t notifyBufferReturned(int index);
Ashish Singhi77b747d2013-04-26 14:30:05 -0700128 virtual android::status_t setResolution(const FrameProcessingPolicy& policy, android::sp<IFrameListener> listener);
Andy Qiu8a427142013-04-05 17:41:58 -0700129protected:
Robert Crabtree2e984ef2013-05-07 14:27:47 -0700130 virtual IVideoPayloadManager* createVideoPayloadManager() = 0;
Andy Qiu8a427142013-04-05 17:41:58 -0700131
132protected:
133 bool mInitialized;
134 Hwcomposer& mHwc;
135 DisplayPlaneManager& mDisplayPlaneManager;
Robert Crabtree2e984ef2013-05-07 14:27:47 -0700136 IVideoPayloadManager *mPayloadManager;
Andy Qiu8a427142013-04-05 17:41:58 -0700137};
138
139}
140}
141
142#endif /* VIRTUAL_DEVICE_H */