blob: a156d7bc5ed32bcdbedfbf3a9d50484bb6cfd672 [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;
Robert Crabtree7d844a22013-08-27 14:00:15 -070066 bool forceNotifyFrameType;
67 bool forceNotifyBufferInfo;
Ashish Singhi77b747d2013-04-26 14:30:05 -070068 };
69 Mutex mConfigLock;
70 Configuration mCurrentConfig;
71 Configuration mNextConfig;
mamatha balgurid2483962013-07-11 13:38:48 -070072 size_t mLayerToSend;
Ashish Singhi77b747d2013-04-26 14:30:05 -070073
74 uint32_t mExtLastKhandle;
75 int64_t mExtLastTimestamp;
76
mamatha balgurid2483962013-07-11 13:38:48 -070077 int64_t mRenderTimestamp;
Robert Crabtree2e984ef2013-05-07 14:27:47 -070078
mamatha balgurid2483962013-07-11 13:38:48 -070079 // colorspace conversion
80 Mutex mCscLock;
81 android::List<uint32_t> mAvailableCscBuffers;
82 int mCscBuffersToCreate;
83 uint32_t mCscWidth;
84 uint32_t mCscHeight;
85
86 FrameInfo mLastInputFrameInfo;
87 FrameInfo mLastOutputFrameInfo;
88
Robert Crabtreec2a96b12013-10-22 18:18:15 -070089 int32_t mVideoFramerate;
90
mamatha balgurid2483962013-07-11 13:38:48 -070091 android::KeyedVector<uint32_t, android::sp<CachedBuffer> > mMappedBufferCache;
Robert Crabtree2e984ef2013-05-07 14:27:47 -070092 android::Mutex mHeldBuffersLock;
mamatha balgurid2483962013-07-11 13:38:48 -070093 android::KeyedVector<uint32_t, android::sp<android::RefBase> > mHeldBuffers;
Robert Crabtree2e984ef2013-05-07 14:27:47 -070094
95private:
mamatha balgurid2483962013-07-11 13:38:48 -070096 android::sp<CachedBuffer> getMappedBuffer(uint32_t handle);
Ashish Singhi3895d9b2013-11-04 14:43:33 -080097 void sendToWidi(const hwc_layer_1_t& layer, bool rotating, bool isProtected);
Robert Crabtree2e984ef2013-05-07 14:27:47 -070098
Andy Qiu8a427142013-04-05 17:41:58 -070099public:
100 VirtualDevice(Hwcomposer& hwc, DisplayPlaneManager& dpm);
101 virtual ~VirtualDevice();
102
103public:
104 virtual bool prePrepare(hwc_display_contents_1_t *display);
105 virtual bool prepare(hwc_display_contents_1_t *display);
106 virtual bool commit(hwc_display_contents_1_t *display,
Andy Qiu4b834ce2013-04-09 18:23:20 -0700107 IDisplayContext *context);
Andy Qiu8a427142013-04-05 17:41:58 -0700108
Andy Qiueb726af2013-05-31 11:51:49 +0800109 virtual bool vsyncControl(bool enabled);
110 virtual bool blank(bool blank);
Andy Qiu0131f122013-07-19 14:51:20 -0700111 virtual bool getDisplaySize(int *width, int *height);
Andy Qiu8a427142013-04-05 17:41:58 -0700112 virtual bool getDisplayConfigs(uint32_t *configs,
113 size_t *numConfigs);
114 virtual bool getDisplayAttributes(uint32_t config,
115 const uint32_t *attributes,
116 int32_t *values);
117 virtual bool compositionComplete();
118 virtual bool initialize();
fu jine2ad4c02013-05-28 13:47:51 -0700119 virtual void deinitialize();
Andy Qiu8a427142013-04-05 17:41:58 -0700120 virtual bool isConnected() const;
121 virtual const char* getName() const;
122 virtual int getType() const;
123 virtual void dump(Dump& d);
124
Ashish Singhi196e5bd2013-04-17 18:26:37 -0700125 // IFrameServer methods
Arindam Roy82757462013-07-29 17:10:44 -0700126 virtual android::status_t start(sp<IFrameTypeChangeListener> frameTypeChangeListener);
Ashish Singhi196e5bd2013-04-17 18:26:37 -0700127 virtual android::status_t stop(bool isConnected);
128 virtual android::status_t notifyBufferReturned(int index);
Ashish Singhi77b747d2013-04-26 14:30:05 -0700129 virtual android::status_t setResolution(const FrameProcessingPolicy& policy, android::sp<IFrameListener> listener);
Andy Qiu8a427142013-04-05 17:41:58 -0700130protected:
Robert Crabtree2e984ef2013-05-07 14:27:47 -0700131 virtual IVideoPayloadManager* createVideoPayloadManager() = 0;
Andy Qiu8a427142013-04-05 17:41:58 -0700132
133protected:
134 bool mInitialized;
135 Hwcomposer& mHwc;
136 DisplayPlaneManager& mDisplayPlaneManager;
Robert Crabtree2e984ef2013-05-07 14:27:47 -0700137 IVideoPayloadManager *mPayloadManager;
Ashish Singhi3895d9b2013-11-04 14:43:33 -0800138 uint32_t mOrigContentWidth;
139 uint32_t mOrigContentHeight;
Andy Qiu8a427142013-04-05 17:41:58 -0700140};
141
142}
143}
144
145#endif /* VIRTUAL_DEVICE_H */